jkvargas / russimp

Assimp bindings for Rust
Other
84 stars 27 forks source link

Why no aiGetMaterialTextureCount method is available? #38

Closed OsmanArjen closed 1 year ago

OsmanArjen commented 1 year ago

if there is a aiGetMaterialTextureCount method in assimp it means that a material can hold different textures with the same type why there isnt that feature in russimp?

im new to it so i need to ask would it make any difference? do most of the 3d objects consist of only one texture per types?

jkvargas commented 1 year ago

the idea with russimp is not to provide the same interface but the same functionality lets say.

this is the method that you want

unsigned int aiGetMaterialTextureCount(const C_STRUCT aiMaterial *pMat, C_ENUM aiTextureType type) {
    ai_assert(pMat != nullptr);

    // Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again)
    unsigned int max = 0;
    for (unsigned int i = 0; i < pMat->mNumProperties; ++i) {
        aiMaterialProperty *prop = pMat->mProperties[i];

        if (prop /* just a sanity check ... */
                && 0 == strcmp(prop->mKey.data, _AI_MATKEY_TEXTURE_BASE) && static_cast<aiTextureType>(prop->mSemantic) == type) {

            max = std::max(max, prop->mIndex + 1);
        }
    }
    return max;
}

I don't have access to my pc right now but I believe you can do something like the following. Pseudo code by the way.

scene.materials[your_material_index].properties.filter(|x| x.semantic.eq(TextureType::Diffuse)).collect().len()