Skip to content

Commit 3010aab

Browse files
committed
GLTF: Support meshes without index buffer
1 parent 2cd8fec commit 3010aab

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

demosys/scene/loaders/gltf.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,8 @@ def _link_data(self):
272272
# Link accessors to mesh primitives
273273
for mesh in self.meshes:
274274
for p in mesh.primitives:
275-
p.indices = self.accessors[p.indices]
275+
if getattr(p, "indices", None) is not None:
276+
p.indices = self.accessors[p.indices]
276277
for name, value in p.attributes.items():
277278
p.attributes[name] = self.accessors[value]
278279

@@ -346,7 +347,6 @@ def __init__(self, data):
346347

347348
def load(self):
348349
self.prepare_attrib_mapping()
349-
component_type, index_vbo = self.load_indices()
350350

351351
name_map = {
352352
'POSITION': 'in_position',
@@ -360,7 +360,12 @@ def load(self):
360360

361361
vbos = self.prepare_attrib_mapping()
362362
vao = VAO(self.name, mode=self.primitives[0].mode or GL.GL_TRIANGLES)
363-
vao.set_element_buffer(component_type.value, index_vbo)
363+
364+
# Index buffer
365+
component_type, index_vbo = self.load_indices()
366+
if index_vbo:
367+
vao.set_element_buffer(component_type.value, index_vbo)
368+
364369
attributes = {}
365370

366371
for vbo_info in vbos:
@@ -385,6 +390,9 @@ def load(self):
385390

386391
def load_indices(self):
387392
"""Loads the index buffer / polygon list"""
393+
if getattr(self.primitives[0], "indices") is None:
394+
return None, None
395+
388396
_, component_type, vbo = self.primitives[0].indices.read(target=GL.GL_ELEMENT_ARRAY_BUFFER)
389397
return component_type, vbo
390398

0 commit comments

Comments
 (0)