#need help with hashmaps

4 messages · Page 1 of 1 (latest)

dull ledge
#

i need some help when it comes to hashmaps and the russimp library https://crates.io/crates/russimp
i have gone ahead with using learnopengl.com's model loading tutorial, properly rewriting most of the code to at least mimic the behaviour.
but i am having trouble at one specific line https://learnopengl.com/code_viewer_gh.php?code=includes/learnopengl/model.h

    vector<Texture> loadMaterialTextures(aiMaterial *mat, aiTextureType type, string typeName)
    {
        vector<Texture> textures;
        for(unsigned int i = 0; i < mat->GetTextureCount(type); i++)
        {...}
...}

the russimp library doesn't implement many of the QOL functions in Assimp, which is fine and until now hasn't caused issues, but i am having issues with aiMaterial::GetTextureCount()
in russimp when i look at russimp::material::Material (aiMaterial)

pub struct Material {
    pub properties: Vec<MaterialProperty>,
    pub textures: HashMap<TextureType, Rc<RefCell<Texture>>>,
}

TextureType is an Enum
i am not experienced with Rc at all, but i was told hashmaps can have only one value per key.
looking at assimp c++ docs: https://assimp.sourceforge.net/lib_html/structai_material.html#ad619f2bc4400c19caede1ef68b483ff4
it returns an unsigned int
my question is, how should i go about rewriting the c++ code? am i missing something?

sonic aspen
dull ledge
#

https://github.com/assimp/assimp/blob/a2c2b64877657447fd9f0118d278de18d0c0e8f1/code/Material/MaterialSystem.cpp#L317

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;
}
``` found the original c++ code
also found aiMaterialProperty
https://github.com/assimp/assimp/blob/33c32b6b3598a3464c6cae350a18384f6c759222/include/assimp/material.h#L622