Skip to content

Commit 35ccc27

Browse files
committed
Mesh: Handle faces and indices
1 parent c57f8ea commit 35ccc27

File tree

2 files changed

+18
-1
lines changed
  • src
    • private/Core/GameObject/Component
    • public/Core/GameObject/Component

2 files changed

+18
-1
lines changed

src/private/Core/GameObject/Component/Mesh.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ void Mesh::UploadVertices() {
3636
ComPtr<ID3D12Resource> VBO;
3737
d3d12->CreateBuffer(&object.second[0], object.second.size() * sizeof(Vertex), VBO);
3838
VBO->SetName(L"StaticMesh VBO");
39-
spdlog::debug("{0}: {1:d} vertices uploaded for mesh {2:d}", this->m_name, object.second.size(), object.first);
39+
spdlog::info("{0}: {1:d} vertices uploaded for mesh {2:d}", this->m_name, object.second.size(), object.first);
40+
41+
this->m_VBOs[object.first] = VBO;
4042
}
4143

4244
spdlog::debug("{0}: Vertex Buffer Object initialized", this->m_name);
@@ -92,6 +94,20 @@ void Mesh::LoadModel(std::string filename) {
9294
vertices.push_back(vert);
9395
}
9496

97+
if (mesh->HasFaces()) {
98+
std::vector<UINT> indices;
99+
for (int x = 0; x < mesh->mNumFaces; x++) {
100+
const aiFace& face = mesh->mFaces[x];
101+
UINT nNumIndices = face.mNumIndices;
102+
103+
for (int f = 0; f < nNumIndices; f++) {
104+
indices.push_back(face.mIndices[f]);
105+
}
106+
107+
}
108+
this->m_indices[i] = indices;
109+
}
110+
95111
this->m_vertices[i] = vertices;
96112

97113
aiString texPath;

src/public/Core/GameObject/Component/Mesh.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Mesh : public Component {
3535
bool m_bMeshLoaded;
3636

3737
std::map<UINT, std::vector<Vertex>> m_vertices;
38+
std::map<UINT, std::vector<UINT>> m_indices;
3839
std::map <UINT, ComPtr<ID3D12Resource>> m_textures;
3940

4041
std::map<UINT, ComPtr<ID3D12Resource>> m_VBOs;

0 commit comments

Comments
 (0)