#Parsing GLTF File
1 messages · Page 1 of 1 (latest)
according to specs, its an integer
the same goes for byteLenth, byteOffset, bufferViewIndex and count
I get this error if I don't make it anything other than float.
'Invalid type assertion from Value to i64, actual type:
f64'
So I get it as a float and cast it. This is just get an index in the JSON
ah, you are casting to int. Can you try casing to u32 instead of int and check?
and if that doesn't work then unmarshalling the json file is the only solution. It is a well implemented working solution too. The Integer values from glTF specs corelates to u32 in odin, not int, which is register sized and is usually u64 by default.
the same result. plus I still need to cast to int on this line
mem.copy(&dst^[0], &byteData^[byteOffset], int(byteLength))
so, basically, indices offset and length is wrong, right?
and that must be the 4th buffer view
which happens to be this
{
"buffer": 0,
"byteLength": 72,
"byteOffset": 768,
"target": 34963
}
for me when I exported blender cube
I'm getting the right values from the .gltf file
every function other than get_indices is working right
so, since the result you posted in OP has 36 indices, which totally might be the case if we consider two triangles per face and 6 faces for a cube.
and if we consider indices to be of u16, that would be 2 bytes per index. so the total length of the indices(byteLength) would be 72, which also seems to be right
the only thing that can go wrong now is the byteOffset
is it possible to share your cube gltf file?
Here you go
strange. My result when I run your code is
[1, 13, 19, 1, 19, 7, 9, 6, 18, 9, 18, 21, 23, 20, 14, 23, 14, 17, 16, 4, 10, 16, 10, 22, 5, 2, 8, 5, 8, 11, 15, 12, 0, 15, 0, 3] ```
not what you got 
oh sorry its this one. I move 1 of the vertices.
when I import this in blender and run this to see how its handling indices
import bpy
obj = bpy.context.active_object
mesh = obj.data
mesh = obj.evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh()
mesh.calc_loop_triangles()
indices = [i for tri in mesh.loop_triangles for i in tri.vertices]
print(indices)
# Clean up the temporary mesh
obj.to_mesh_clear()
I got [1, 13, 19, 1, 19, 7, 9, 6, 18, 9, 18, 21, 23, 20, 14, 23, 14, 17, 16, 4, 10, 16, 10, 22, 5, 2, 8, 5, 8, 11, 15, 12, 0, 15, 0, 3] as the result
so, yeah, the second file you shared happens to give correct indices when imported inside blender but its strangely going a bit off while manually reading it
we probably are completely missing something
I created an obj loader and this is the type of data I successfully parsed. So I can tell that the values I'm getting for the gltf are wrong for the indices. So yea for the position indices there is something very wrong.
f 5/1/1 3/2/1 1/3/1
f 3/3/2 8/4/2 4/2/2
f 7/1/3 6/2/3 8/4/3
f 2/3/4 8/4/4 6/1/4
f 2/2/5 3/1/5 4/4/5
f 5/1/6 2/2/6 6/4/6
f 5/1/1 7/4/1 3/2/1
f 3/3/2 7/1/2 8/4/2
f 7/1/3 5/3/3 6/2/3
f 2/3/4 4/2/4 8/4/4
f 2/2/7 1/3/7 3/1/7
f 5/1/8 1/3/8 2/2/8
so... this is how the second cube looks when I import it inside glTF viewer after stripping away the textures and material data from the file
I think what we your code is reading is accurate and blender might have done some correction(CW vs CCW or front vs back face) while importing
I don't think thats it this is what I get in render doc
here are the files I used for glTF viewer where I removed the textures.
the whole thing is messed up maybe there is a blender export option i'm missing
one export option I could think of that influenced this is this
"name":"Scene"
it looks like blender exported the entire scene
would that matter if there is one object?
but when you export while selecting the option "Selected Objects" then blender will only export the objects that are selected in the scene.
ah, blender only exported cube in your files so this isn't worth considering atm
nvm
apart from texture and material, I did not find any additional scene data related to camera or light