Skip to content

Commit b27590f

Browse files
committed
Fix dtype bug in gltf loader
1 parent 5aa432c commit b27590f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

demosys/scene/loaders/gltf.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,18 @@
3636

3737
# numpy dtype mapping
3838
NP_COMPONENT_DTYPE = {
39-
5121: numpy.dtype(numpy.uint8), # GL_UNSIGNED_BYTE
40-
5123: numpy.dtype(numpy.uint16), # GL_UNSIGNED_SHORT
41-
5125: numpy.dtype(numpy.uint32), # GL_UNSIGNED_INT
42-
5126: numpy.dtype(numpy.float32), # GL_FLOAT
39+
5121: numpy.uint8, # GL_UNSIGNED_BYTE
40+
5123: numpy.uint16, # GL_UNSIGNED_SHORT
41+
5125: numpy.uint32, # GL_UNSIGNED_INT
42+
5126: numpy.float32, # GL_FLOAT
43+
}
44+
45+
# dtype to moderngl buffer format
46+
DTYPE_BUFFER_TYPE = {
47+
numpy.uint8: 'u1', # GL_UNSIGNED_BYTE
48+
numpy.uint16: 'u2', # GL_UNSIGNED_SHORT
49+
numpy.uint32: 'u4', # GL_UNSIGNED_INT
50+
numpy.float32: 'f4', # GL_FLOAT
4351
}
4452

4553
ACCESSOR_TYPE = {
@@ -381,7 +389,7 @@ def load(self, materials):
381389
dtype, buffer = vbo_info.create()
382390
vao.buffer(
383391
buffer,
384-
" ".join(["{}f".format(attr[1]) for attr in vbo_info.attributes]),
392+
" ".join(["{}{}".format(attr[1], DTYPE_BUFFER_TYPE[dtype]) for attr in vbo_info.attributes]),
385393
[name_map[attr[0]] for attr in vbo_info.attributes],
386394
)
387395

@@ -444,6 +452,7 @@ def __init__(self, buffer=None, buffer_view=None, target=None,
444452
self.component_type = component_type # Datatype of each component
445453
self.components = components
446454
self.count = count # number of elements of the component type size
455+
447456
# list of (name, components) tuples
448457
self.attributes = []
449458

0 commit comments

Comments
 (0)