[Bf-extensions-cvs] [8db785ea] master: glTF exporter: avoid error when parent scale is 0

Julien Duroure noreply at git.blender.org
Sat Feb 29 16:12:12 CET 2020


Commit: 8db785ea740bcb64b613aee3fa6d8519c9e543ae
Author: Julien Duroure
Date:   Sat Feb 29 16:11:30 2020 +0100
Branches: master
https://developer.blender.org/rBA8db785ea740bcb64b613aee3fa6d8519c9e543ae

glTF exporter: avoid error when parent scale is 0

===================================================================

M	io_scene_gltf2/__init__.py
M	io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 4ea83c25..e7a6c212 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 2, 32),
+    "version": (1, 2, 33),
     'blender': (2, 82, 7),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
index 22a5e492..2eaf56f5 100755
--- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
+++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py
@@ -29,6 +29,7 @@ from ..com.gltf2_blender_extras import generate_extras
 from io_scene_gltf2.io.com import gltf2_io
 from io_scene_gltf2.io.com import gltf2_io_extensions
 from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
+from io_scene_gltf2.io.com.gltf2_io_debug import print_console
 
 
 def gather_node(blender_object, blender_scene, export_settings):
@@ -188,7 +189,10 @@ def __gather_children(blender_object, blender_scene, export_settings):
             if trans is None:
                 trans = [0, 0, 0]
             # bones go down their local y axis
-            bone_tail = [0, blender_bone.length / blender_bone.matrix.to_scale()[1], 0]
+            if blender_bone.matrix.to_scale()[1] >= 1e-6:
+                bone_tail = [0, blender_bone.length / blender_bone.matrix.to_scale()[1], 0]
+            else:
+                bone_tail = [0,0,0] # If scale is 0, tail == head
             child_node.translation = [trans[idx] + bone_tail[idx] for idx in range(3)]
 
             parent_joint.children.append(child_node)
@@ -341,7 +345,19 @@ def __gather_trans_rot_scale(blender_object, export_settings):
     else:
         # matrix_local = matrix_parent_inverse*location*rotation*scale
         # Decomposing matrix_local gives less accuracy, but is needed if matrix_parent_inverse is not the identity.
-        trans, rot, sca = gltf2_blender_extract.decompose_transition(blender_object.matrix_local, export_settings)
+
+
+        if blender_object.matrix_local[3][3] != 0.0:
+            trans, rot, sca = gltf2_blender_extract.decompose_transition(blender_object.matrix_local, export_settings)
+        else:
+            # Some really weird cases, scale is null (if parent is null when evaluation is done)
+            print_console('WARNING', 'Some nodes are 0 scaled during evaluation. Result can be wrong')
+            trans = blender_object.location
+            if blender_object.rotation_mode in ['QUATERNION', 'AXIS_ANGLE']:
+                rot = blender_object.rotation_quaternion
+            else:
+                rot = blender_object.rotation_euler.to_quaternion()
+            sca = blender_object.scale
 
     trans = gltf2_blender_extract.convert_swizzle_location(trans, None, None, export_settings)
     rot = gltf2_blender_extract.convert_swizzle_rotation(rot, export_settings)



More information about the Bf-extensions-cvs mailing list