feat: material-based embedded texture loading for assimp models#32
Open
gimploo wants to merge 2 commits into
Open
feat: material-based embedded texture loading for assimp models#32gimploo wants to merge 2 commits into
gimploo wants to merge 2 commits into
Conversation
Extend glmodel_t to load textures through Assimp materials using aiGetMaterialTexture, supporting both external file paths and embedded texture references (*N syntax) from scene->mTextures. Changes: - Extend gltexturetype enum with PBR texture types (DIFFUSE, SPECULAR, NORMALS, BASE_COLOR, METALNESS, etc.) mapped to aiTextureType values - Add model_texture_t struct pairing gltexture2d_t with aiTextureType - Replace scene-level load_alltextures with material-driven loading via aiGetMaterialTexture in processMaterial - Resolve embedded texture references (*N) back to scene->mTextures[N] - Deduplicate materials processed across multiple meshes in processScene - Update renderer to bind all PBR texture types as 2D textures
gimploo
commented
Jul 9, 2026
Comment on lines
+373
to
+380
| if (!(processed_materials & ((u64)1 << mesh->mMaterialIndex))) { | ||
| processed_materials |= (u64)1 << mesh->mMaterialIndex; | ||
| assimp__internal_glmesh_processMaterial( | ||
| self, | ||
| scene, | ||
| mesh->mMaterialIndex | ||
| ); | ||
| } |
Owner
Author
There was a problem hiding this comment.
explain the bitmask logic and the reason to bring in a comment
gimploo
commented
Jul 9, 2026
| str_t absolute_texture_path = str_join(self->arena, &self->directory_path, aitexture->mFilename.data); | ||
| texture = gltexture2d_init(absolute_texture_path.data); | ||
| gltexture2d_t assimp__internal_load_texture_from_path(glmodel_t *self, const struct aiScene *scene, const char *path) { | ||
| if (path[0] == '*') { |
Owner
Author
There was a problem hiding this comment.
replace the condition with a variable describing the comparison
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extends
glmodel_tto load textures through Assimp materials usingaiGetMaterialTexture, supporting both external file paths and embedded texture references (*Nsyntax) fromscene->mTextures.Previously, only scene-level embedded textures (
scene->mTextures) were loaded, but material textures (the primary source for formats like glTF/GLB) were completely ignored.Changes
1.
gfx/gl/texture_types.h— ExtendedgltexturetypeenumAdded PBR texture type variants (values 1–17 match
aiTextureTypefor direct casting):DIFFUSE,SPECULAR,AMBIENT,EMISSIVE,HEIGHT,NORMALS,SHININESS,OPACITY,DISPLACEMENT,LIGHTMAP,REFLECTION,BASE_COLOR,NORMAL_CAMERA,EMISSION_COLOR,METALNESS,DIFFUSE_ROUGHNESS,AMBIENT_OCCLUSION2.
gfx/model/assimp.h— Core model loading rewrite (based ondev)model_texture_tstruct pairsgltexture2d_twithaiTextureTypeassimp__internal_load_texture_from_pathhelper resolves texture paths:*N→ embedded reference →gltexture2d_embedded_initfromscene->mTextures[N]gltexture2d_initwith absolute path from model directoryprocessMaterialto iterate allaiTextureTypevalues, callaiGetMaterialTexture, load textures with type deduplicationprocessSceneusing bitmask (multiple meshes sharing same material processed once)load_alltextures— material-based loading supersedes scene-level scanningglmodel_get_texuturelistto mapaiTextureType→gltexturetypevia direct castglmodel_destroyfor new struct layout3.
gfx/glrenderer3d.h— Renderer bindingAll PBR texture types fall through to 2D texture bind path (same as
GL_TEXTURE_TYPE_NORMAL)Testing
res/towermodel.glb(GLB with embedded PNG baseColorTexture): model loads without errors