cgltf icon indicating copy to clipboard operation
cgltf copied to clipboard

glb binary texture data

Open quirinpa opened this issue 2 years ago • 4 comments

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.

quirinpa avatar Sep 14 '22 10:09 quirinpa

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. )

prideout avatar Sep 14 '22 16:09 prideout

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

quirinpa avatar Sep 14 '22 17:09 quirinpa

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.

prideout avatar Sep 14 '22 17:09 prideout

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

quirinpa avatar Sep 14 '22 18:09 quirinpa