jkuhlmann / cgltf

:diamond_shape_with_a_dot_inside: Single-file glTF 2.0 loader and writer written in C99
MIT License
1.44k stars 136 forks source link

glb binary texture data #188

Open quirinpa opened 1 year ago

quirinpa commented 1 year ago

I'm trying to combine cgltf and stb_image to be able to import textures and render them on my 3D model using OpenGL. The code is available here. I was hoping that the binary texture data would be under primitive->material->normal_texture.texture->buffer_view, but unfortunately "texture" is NULL.

Here is the call I was hoping to use to load the binary information about the images: m->texture.data = stbi_load_from_memory(tview->buffer->data + tview->offset, tview->size, &m->texture.w, &m->texture.h, &m->texture.channels, 3);

But this does not work. Can you please help me out?

I know cgltf is not concerned with loading images, but couldn't it at least load the binary image data in the glb file? The binary information only, it doesn't need to understand or process it.

prideout commented 1 year ago

If the texture field is null, then it's likely that the asset simply doesn't have a normal map for that primitive. They're optional.

( However if the data field is null, then you might have forgotten to call cgltf_load_buffers first. )

quirinpa commented 1 year ago

Oh.. I see.. The normal map. I was looking for the main texture, where is it located in the data structure?

prideout commented 1 year ago

Keep in mind that some primitives might have no textures whatsoever, but you could look in base_color_texture if you already know that it has a baseColorTexture.

quirinpa commented 1 year ago

Thank you so much @prideout, it appears I was looking in the wrong place. Now I can see the textures.