Skip to content

Commit

Permalink
Merge pull request #1977 from KhronosGroup/fix_b104852
Browse files Browse the repository at this point in the history
Fix bad mesh export
  • Loading branch information
julienduroure authored Sep 6, 2023
2 parents 1f0cc5c + 897932f commit 7ec7125
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7ec7125

Please sign in to comment.