Skip to content

Commit

Permalink
converter: Put morph targets on separate GeomVertexArray
Browse files Browse the repository at this point in the history
These never need to be uploaded anyway--and this fixes a crash when the number of morph targets causes the array to exceed the maximum stride supported by OpenGL implementations, besides being more efficient

Fixes #117
  • Loading branch information
rdb committed Jan 31, 2023
1 parent 948d0e9 commit cd8387f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gltf/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,7 @@ def load_primitive(self, geom_node, gltf_primitive, gltf_mesh, gltf_data):
vformat = GeomVertexFormat()
varray_vert = GeomVertexArrayFormat()
varray_skin = GeomVertexArrayFormat()
varray_morph = GeomVertexArrayFormat()

skip_columns = (
InternalName.get_transform_index(),
Expand All @@ -948,9 +949,15 @@ def load_primitive(self, geom_node, gltf_primitive, gltf_mesh, gltf_data):
)
for arr in reg_format.get_arrays():
for column in arr.get_columns():
varray = varray_skin if column.get_name() in skip_columns else varray_vert
column_name = column.get_name()
if column_name in skip_columns:
varray = varray_skin
elif column_name.parent.basename == "morph":
varray = varray_morph
else:
varray = varray_vert
varray.add_column(
column.get_name(),
column_name,
column.get_num_components(),
column.get_numeric_type(),
column.get_contents()
Expand All @@ -969,6 +976,9 @@ def load_primitive(self, geom_node, gltf_primitive, gltf_mesh, gltf_data):
vformat.add_array(varray_blends)
vformat.add_array(varray_skin)

if targets:
vformat.add_array(varray_morph)

reg_format = GeomVertexFormat.register_format(vformat)
vdata = vdata.convert_to(reg_format)

Expand Down

0 comments on commit cd8387f

Please sign in to comment.