diff --git a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py index 9503d1d3f..a213bda70 100644 --- a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py +++ b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py @@ -16,6 +16,7 @@ import bpy from mathutils import Matrix, Quaternion, Vector +from ...io.com.gltf2_io_debug import print_console from ...io.com import gltf2_io from ...io.com import gltf2_io_extensions from ...io.exp.gltf2_io_user_extensions import export_user_extensions @@ -191,7 +192,9 @@ def __gather_mesh(vnode, blender_object, export_settings): return None # Be sure that object is valid (no NaN for example) - blender_object.data.validate() + res = blender_object.data.validate() + if res is True: + print_console("WARNING", "Mesh " + blender_object.data.name + " is not valid, and may be exported wrongly") modifiers = blender_object.modifiers if len(modifiers) == 0: diff --git a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py index 3a09c505b..f5f4be94d 100644 --- a/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py +++ b/addons/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives_extract.py @@ -367,9 +367,16 @@ def populate_dots_data(self): def primitive_split(self): # Calculate triangles and sort them into primitives. - self.blender_mesh.calc_loop_triangles() - loop_indices = np.empty(len(self.blender_mesh.loop_triangles) * 3, dtype=np.uint32) - self.blender_mesh.loop_triangles.foreach_get('loops', loop_indices) + try: + self.blender_mesh.calc_loop_triangles() + loop_indices = np.empty(len(self.blender_mesh.loop_triangles) * 3, dtype=np.uint32) + self.blender_mesh.loop_triangles.foreach_get('loops', loop_indices) + except: + # For some not valid meshes, we can't get loops without errors + # We already displayed a Warning message after validate() check, so here + # we can return without a new one + self.prim_indices = {} + return self.prim_indices = {} # maps material index to TRIANGLES-style indices into dots