#Code Review Request: struggling to export mesh as a gltf.

19 messages · Page 1 of 1 (latest)

charred remnant
#

I have a mesh generated in bevy which i'd like to convert into a GLTF, but I'm running into issues with adding support for the mesh's indices to it.

The gltf generates, but when i test importing it into blender I get index out of bounds errors from blender, telling me that this file is malformed.

Anyone familiar with gltf files able to point to what I could be doing wrong?

#

error:

urban knot
#

that error looks like it is a generic multidimensional-array indexing error, not referring to indices in the mesh sense

#

so the problem could be things that are not mesh indices

#

though this sounds plausibly that data which is not a proper index is being interpreted as an index

#

since a cube mesh has 24 vertices

#

oh, your fn to_padded_byte_vector<T>(vec: Vec<T>) -> Vec<u8> is unsound. this probably isn't the actual bug, but if you want to reinterpret data like this, you should use bytemuck or zerocopy, instead of writing your own unsafe code

charred remnant
# urban knot oh, your `fn to_padded_byte_vector<T>(vec: Vec<T>) -> Vec<u8>` is unsound. this ...

I don't know what it does, or why its there. I copied it from this example from the gltf crate example page:
https://github.com/gltf-rs/gltf/blob/main/examples/export/main.rs

It looks like you made a commit to this example though. what does turning it into a padded byte vector do?

GitHub

A crate for loading glTF 2.0. Contribute to gltf-rs/gltf development by creating an account on GitHub.

urban knot
#

my commit was completely unrelated to that part 😅

#

the point of that function is to turn a vector of numbers into a vector of the bytes that represent those numbers

#

but it is doing it very badly. probably in a way which won't corrupt your data, but still, incorrect

charred remnant
urban knot
#

yes, bytemuck::bytes_of() is a safe, sound function that can be used as the main part of a correct solution

charred remnant
urban knot
#

yeah that's good

#

well, it doesn't pad anything but you may or may not need padding

charred remnant
charred remnant
#

Does anyone have a codebase that serializes a mesh to gltf? I'm drawing blanks on how to solve these errors and nothing comes to mind as immediately wrong.