Skip to content

Commit

Permalink
Loaded our vertices to an array and saved on a map member (m_vertices…
Browse files Browse the repository at this point in the history
…) inside our Mesh component class
  • Loading branch information
PR3C14D0 committed Aug 14, 2024
1 parent b44771e commit c340d00
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
35 changes: 35 additions & 0 deletions src/private/Core/GameObject/Component/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,39 @@ void Mesh::LoadModel(std::string filename) {

Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(filename, NULL);

for (UINT i = 0; i < scene->mNumMeshes; i++) {
aiMesh* mesh = scene->mMeshes[i];
aiMaterial* material = scene->mMaterials[mesh->mMaterialIndex];
std::vector<Vertex> vertices;

for (UINT x = 0; x < mesh->mNumVertices; x++) {
aiVector3D vec = mesh->mVertices[x];
RGB pos = { vec.x, vec.y, vec.z };
RGB normal = { 0.f, 0.f, 0.f };
RG uv = { 0.f, 0.f };

if (mesh->HasNormals()) {
aiVector3D nml = mesh->mNormals[x];
normal[0] = nml.x;
normal[1] = nml.y;
normal[2] = nml.z;
}

if (mesh->HasTextureCoords(0)) {
aiVector3D texCoord = mesh->mTextureCoords[0][x];
uv[0] = texCoord.x;
uv[1] = texCoord.y;
}

Vertex vert = { {pos[0], pos[1], pos[2]}, {normal[0], normal[1], normal[2]}, {uv[0], uv[1]} };
vertices.push_back(vert);
}

this->m_vertices[i] = vertices;

aiString texPath;


}
}
11 changes: 6 additions & 5 deletions src/private/Core/Renderer/ScreenQuad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ void ScreenQuad::Init() {
this->m_renderer = this->m_core->GetRenderer();

this->m_vertices = {
{{-1.f, 1.f, 0.f}, {0.f, 0.f}},
{{1.f, 1.f, 0.f}, {1.f, 0.f}},
{{1.f, -1.f, 0.f}, {1.f, 1.f}},
{{-1.f, -1.f, 0.f}, {0.f, 1.f}},
{{-1.f, 1.f, 0.f}, {0.f, 0.f, 0.f}, {0.f, 0.f}},
{{1.f, 1.f, 0.f}, {0.f, 0.f, 0.f}, {1.f, 0.f}},
{{1.f, -1.f, 0.f}, {0.f, 0.f, 0.f}, {1.f, 1.f}},
{{-1.f, -1.f, 0.f}, {0.f, 0.f, 0.f}, {0.f, 1.f}},
};

this->m_indices = {
Expand Down Expand Up @@ -97,7 +97,8 @@ void ScreenQuad::D3D12Init(D3D12* renderer) {

D3D12_INPUT_ELEMENT_DESC elements[] = {
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, NULL },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, NULL}
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, NULL },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D12_INPUT_CLASSIFICATION_PER_VERTEX_DATA, NULL}
};

D3D12_GRAPHICS_PIPELINE_STATE_DESC plDesc = { };
Expand Down
4 changes: 4 additions & 0 deletions src/public/Core/GameObject/Component/Mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <assimp/scene.h>
#include <assimp/Importer.hpp>
#include <assimp/postprocess.h>
#include <map>
#include "Util.h"

#include "Core/GameObject/Component/Component.h"

Expand All @@ -31,6 +33,8 @@ class Mesh : public Component {
std::vector<ComPtr<ID3D12Resource>> m_buffers;

bool m_bMeshLoaded;

std::map<UINT, std::vector<Vertex>> m_vertices;
public:
Mesh(std::string name);

Expand Down
1 change: 1 addition & 0 deletions src/public/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ typedef float RG[2];

struct Vertex {
RGB xyz;
RGB normal;
RG uv;
};

Expand Down

0 comments on commit c340d00

Please sign in to comment.