diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 15:25:38 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-14 15:36:34 +0100 |
commit | 3e97b30a194907cede7a230e618f82ffb516b329 (patch) | |
tree | afef7fc2c7154e929c2be0270ff16325fbfe61bd | |
parent | Set GL_PACK_ALIGNMENT before saving texture to fit buffer correctly (diff) | |
download | ilt-3e97b30a194907cede7a230e618f82ffb516b329.tar.bz2 ilt-3e97b30a194907cede7a230e618f82ffb516b329.tar.xz ilt-3e97b30a194907cede7a230e618f82ffb516b329.zip |
Create texture fragments from materials
-rw-r--r-- | assetFactory/assimp.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/assetFactory/assimp.cpp b/assetFactory/assimp.cpp index bab052e..9a49717 100644 --- a/assetFactory/assimp.cpp +++ b/assetFactory/assimp.cpp @@ -62,13 +62,11 @@ public: const auto vhs = AIRANGE(amesh, Vertices) * [&mesh](auto && v) { return mesh.add_vertex(*v); }; - const auto & m = *scene->mMaterials[amesh->mMaterialIndex]; + const auto & m = scene->mMaterials[amesh->mMaterialIndex]->GetName(); GLuint material {}; if (auto mf = Persistence::ParseBase::getShared<AssetFactory>("assetFactory")) { - aiString path; - m.Get(AI_MATKEY_TEXTURE_DIFFUSE(0), path); - material = mf->getMaterialIndex(path.C_Str()); + material = mf->getMaterialIndex(m.C_Str()); } for (const auto & f : AIRANGE(amesh, Faces)) { @@ -101,12 +99,15 @@ AssImp::postLoad() root.begin(), root.end(), std::inserter(mf->shapes, mf->shapes.end()), [&scene](const aiNode * m) { return AssetFactory::Shapes::value_type {m->mName.C_Str(), std::make_shared<AssImpNode>(scene, m)}; }); - const auto textures = AIRANGE(scene, Textures); - std::transform(textures.begin(), textures.end(), - std::inserter(mf->textureFragments, mf->textureFragments.end()), [](auto && t) { + const auto materials = AIRANGE(scene, Materials); + std::transform(materials.begin(), materials.end(), + std::inserter(mf->textureFragments, mf->textureFragments.end()), [&scene](const aiMaterial * m) { + aiString path; + m->Get(AI_MATKEY_TEXTURE_DIFFUSE(0), path); auto texture = std::make_shared<TextureFragment>(); - texture->id = texture->path = t->mFilename.C_Str(); - texture->image = Worker::addWork([t]() { + texture->id = m->GetName().C_Str(); + texture->path = path.C_Str(); + texture->image = Worker::addWork([t = scene->GetEmbeddedTexture(path.C_Str())]() { return std::make_unique<Image>( std::span {reinterpret_cast<unsigned char *>(t->pcData), t->mWidth}, STBI_rgb_alpha); }); |