Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glb binary texture data #188

Open
quirinpa opened this issue Sep 14, 2022 · 4 comments
Open

glb binary texture data #188

quirinpa opened this issue Sep 14, 2022 · 4 comments

Comments

@quirinpa
Copy link

quirinpa commented Sep 14, 2022

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
Copy link
Contributor

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
Copy link
Author

quirinpa commented Sep 14, 2022

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

@prideout
Copy link
Contributor

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants