Advertisement
Zgragselus

Untitled

Jul 5th, 2023
936
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.19 KB | None | 0 0
  1.  
  2.     Engine::Entity* FromModel(const std::string& name, Engine::Model* mdl)
  3.     {
  4.         Engine::Entity* ent = new Engine::Entity(name);
  5.         Engine::SkinnedAnimatorComponent* anim = nullptr;
  6.  
  7.         if (mdl->GetSkeleton() != nullptr)
  8.         {
  9.             ent->GameObject().Add<Engine::SkinnedAnimatorComponent>(mdl);
  10.             anim = ent->GameObject().Get<Engine::SkinnedAnimatorComponent>();
  11.         }
  12.  
  13.         for (size_t i = 0; i < mdl->GetMeshesCount(); i++)
  14.         {
  15.             Engine::Mesh* m = mdl->GetMesh(i);
  16.             Engine::Texture* diffuseMap = mdl->GetTexture(i, 0);
  17.             Engine::Texture* normalsMap = mdl->GetTexture(i, 1);
  18.             Engine::Texture* heightMap = mdl->GetTexture(i, 2);
  19.             Engine::Texture* roughnessMap = mdl->GetTexture(i, 3);
  20.             Engine::Texture* metallicMap = mdl->GetTexture(i, 4);
  21.  
  22.             unsigned int materialID = mMaterialSystem->RequestMaterial();
  23.             SkyeCuillin::MaterialSystem::Material* material = mMaterialSystem->GetMaterial(materialID);
  24.             material->mDiffuseMap = diffuseMap->GetSRVIndex();
  25.             material->mNormalsMap = normalsMap->GetSRVIndex();
  26.             material->mMetallicMap = metallicMap->GetSRVIndex();
  27.             material->mRoughnessMap = roughnessMap->GetSRVIndex();
  28.             mMaterialSystem->UpdateMaterial(materialID);
  29.  
  30.             Engine::Entity* child = new Engine::Entity(mdl->GetMesh(i)->GetName(), ent);
  31.             //if (mdl->GetSkeleton() == nullptr)
  32.             {
  33.                 child->GameObject().Add<Engine::MeshComponent>(m, mMeshManager);
  34.             }
  35.             //else
  36.             //{
  37.             //  child->GameObject().Add<Engine::SkinnedMeshComponent>(m, mMeshManager);
  38.             //  child->GameObject().Get<Engine::SkinnedMeshComponent>()->SetAnimatorComponent(anim);
  39.             //}
  40.             child->GameObject().Add<Engine::MaterialComponent>(diffuseMap, normalsMap, metallicMap, roughnessMap, heightMap, mTextureManager, materialID);
  41.             child->Transformation().SetTranslation(mdl->GetTransformation(i));
  42.             child->Transformation().Update();
  43.  
  44.             int geom = mSceneBuffer->AddStaticGeometry(m->GetVertexBuffer()->Data(),
  45.                 m->GetVertexBuffer()->ElementSize(),
  46.                 m->GetVertexBuffer()->NumElements(),
  47.                 (unsigned int*)m->GetIndexBuffer()->Data(),
  48.                 m->GetIndexBuffer()->NumElements(),
  49.                 m->Bounds());
  50.             int instance = mSceneBuffer->AddInstance(child->Transformation().Get(), geom);
  51.         }
  52.  
  53.         return ent;
  54.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement