Skip to content

Commit

Permalink
Solved mesh instantiation bug, added plane mesh.
Browse files Browse the repository at this point in the history
  • Loading branch information
Guriva committed May 8, 2018
1 parent a7514cd commit a73aab6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 20 deletions.
9 changes: 6 additions & 3 deletions LCSEngine/GameObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -991,9 +991,12 @@ void GameObject::updateComponents()
switch ((*it)->typeComponent)
{
case MESH:
aabb.Enclose(&((MeshComponent*)(*it))->verticesVBO[0], ((MeshComponent*)(*it))->verticesVBO.size());
obb = aabb.ToOBB();
obb.Transform(id.Transposed());
if (((MeshComponent*)(*it))->validMesh)
{
aabb.Enclose(&((MeshComponent*)(*it))->verticesVBO[0], ((MeshComponent*)(*it))->verticesVBO.size());
obb = aabb.ToOBB();
obb.Transform(id.Transposed());
}
break;
case CAMERA:
((CameraComponent*)(*it))->frustum.pos = id.Transposed().TranslatePart();
Expand Down
36 changes: 20 additions & 16 deletions LCSEngine/MeshComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "SaveLoadManager.h"

static int selected_preset = 1;
const char* presets[] = { "House", "Cube", "Sphere" };
const char* presets[] = { "Plane", "Cube", "Sphere", "Model" };

MeshComponent::MeshComponent(GameObject* gameObject, bool isEnable, bool isUnique) : Component(gameObject, isEnable, isUnique)
{
Expand All @@ -33,9 +33,13 @@ void MeshComponent::setPreset(PresetType type)
void MeshComponent::loadPreset()
{
verticesVBO.clear();
currentPreset = MODEL;
switch (currentPreset)
{
case PLANE:
{
loadPlane();
break;
}
case CUBE:
{
loadCube();
Expand Down Expand Up @@ -124,20 +128,7 @@ void MeshComponent::drawGUI()
if (ImGui::Selectable(presets[i]))
{
selected_preset = i;
//Set Mesh of preset selected
if (i == 0)
{
currentPreset = PresetType::MODEL;
}
else if (i == 1)
{
currentPreset = PresetType::CUBE;
}
else if (i == 2)
{
currentPreset = PresetType::SPHERE;
}
loadPreset();
setPreset((PresetType)selected_preset);
}
}
ImGui::EndPopup();
Expand Down Expand Up @@ -237,6 +228,19 @@ void MeshComponent::loadCube()
4, 6, 7, 4, 5, 6 };
}

void MeshComponent::loadPlane()
{
verticesVBO.reserve(4);
indicesVAO.reserve(6);
normalsVBO.reserve(4);
texCoordsVBO.reserve(4);

verticesVBO = { float3(-0.5f, 0.5f, 0.f), float3(0.5f, 0.5f, 0.f), float3(0.5f, -0.5f, 0.f), float3(-0.5f, -0.5f, 0.f) };
indicesVAO = { 1, 3, 2, 1, 0, 3 };
normalsVBO = { float3(0.f, 0.f, 1.f), float3(0.f, 0.f, 1.f), float3(0.f, 0.f, 1.f), float3(0.f, 0.f, 1.f) };
texCoordsVBO = { float2(0.f, 0.f), float2(1.f, 0.f), float2(1.f, 1.f), float2(0.f, 1.f) };
}

void MeshComponent::loadModel()
{
for (unsigned i = 0; i < model->scene->mRootNode->mNumChildren; ++i)
Expand Down
3 changes: 2 additions & 1 deletion LCSEngine/MeshComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

enum PresetType
{
TRIANGLE = 1,
PLANE,
CUBE,
SPHERE,
MODEL
Expand Down Expand Up @@ -71,6 +71,7 @@ class MeshComponent : public Component
void loadModel();
void loadSphere();
void loadCube();
void loadPlane();
};

#endif //__MESHCOMPONENT_H__

0 comments on commit a73aab6

Please sign in to comment.