#Parsing GLTF File

1 messages · Page 1 of 1 (latest)

dusky wagon
#

one thing I could point out is in line 77, you are reading primitive's indices values as a float

#

the same goes for byteLenth, byteOffset, bufferViewIndex and count

jaunty venture
dusky wagon
#

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.

jaunty venture
#

the same result. plus I still need to cast to int on this line

mem.copy(&dst^[0], &byteData^[byteOffset], int(byteLength))

dusky wagon
#

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

jaunty venture
#

every function other than get_indices is working right

dusky wagon
#

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?

dusky wagon
#

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 ![thinkingBill](https://cdn.discordapp.com/emojis/670054639885877249.webp?size=128 "thinkingBill")
jaunty venture
dusky wagon
# jaunty venture 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

jaunty venture
#

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

dusky wagon
#

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

jaunty venture
dusky wagon
jaunty venture
dusky wagon
#

one export option I could think of that influenced this is this
"name":"Scene"

#

it looks like blender exported the entire scene

jaunty venture
#

would that matter if there is one object?

dusky wagon
#

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

jaunty venture
#

thank you so much for trying to help.

#

I have to go to bed soon.

dusky wagon
#

ayy. I got no idea what exactly is wrong but... yeah

#

we tried