Merge branch 'MemoryOptimization' into Importer
# Conflicts: # include/Engine/Rendering/Model.h # src/Engine/Collision/Collision.cpp # src/Engine/Collision/CollisionSystem.cpp # src/Engine/Collision/TriggerSystem.cpp # src/Game/Systems/SpawnerSystem.cpp
This commit is contained in:
@@ -48,13 +48,13 @@ bool RayVsTriangle(const Ray& ray,
|
||||
bool trueOnNegativeDistance = false);
|
||||
//Return true if the ray hits any of the triangles in the model. Stops checking when a hit is detected.
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix);
|
||||
//Return true if the ray hits any of the triangles in the model.
|
||||
//Also returns the position of the intersection point. Will loop through all the whole model indices.
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
glm::vec3& outHitPosition);
|
||||
@@ -62,7 +62,7 @@ bool RayVsModel(const Ray& ray,
|
||||
//Also returns the distance from the ray origin to the closest
|
||||
//intersection point, and the barycentric u,v-coordinates. Will loop through all the whole model indices.
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
float& outDistance,
|
||||
@@ -70,7 +70,7 @@ bool RayVsModel(const Ray& ray,
|
||||
float& outVCoord);
|
||||
|
||||
bool AABBvsTriangles(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
glm::vec3& boxVelocity,
|
||||
@@ -80,7 +80,7 @@ bool AABBvsTriangles(const AABB& box,
|
||||
|
||||
//Detects collision, but does not resolve.
|
||||
bool AABBvsTriangles(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix);
|
||||
|
||||
@@ -92,7 +92,7 @@ enum Output
|
||||
};
|
||||
//Detects intersection and containment.
|
||||
Output AABBvsTrianglesWContainment(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix);
|
||||
|
||||
|
||||
@@ -16,21 +16,24 @@ private:
|
||||
|
||||
public:
|
||||
~Model();
|
||||
const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_RawModel->m_Materials; }
|
||||
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; }
|
||||
const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_Materials; }
|
||||
//const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
|
||||
unsigned int NumberOfVertices() const { return m_Vertices.size(); }
|
||||
//size_t NumberOfVertices() const { return m_RawModel->NumVertices(); }
|
||||
//const std::vector<unsigned int>& Indices() const { return m_RawModel->Indices(); }
|
||||
|
||||
const RawModel::RenderVertex* Vertices() const { return m_RawModel->Vertices(); }
|
||||
size_t NumberOfVertices() const { return m_RawModel->NumVertices(); }
|
||||
const std::vector<unsigned int>& Indices() const { return m_RawModel->Indices(); }
|
||||
|
||||
const RawModel::Vertex* CollisionVertices() const { return m_RawModel->CollisionVertices(); }
|
||||
const std::vector<unsigned int>& CollisionIndices() const { return m_RawModel->CollisionIndices(); }
|
||||
//const RawModel::Vertex* CollisionVertices() const { return m_RawModel->CollisionVertices(); }
|
||||
//const std::vector<unsigned int>& CollisionIndices() const { return m_RawModel->CollisionIndices(); }
|
||||
|
||||
const AABB& Box() const { return m_Box; }
|
||||
bool IsSkinned() const { return m_RawModel->IsSkinned(); }
|
||||
bool IsSkinned() const { return m_IsSkinned; }
|
||||
GLuint VAO;
|
||||
GLuint ElementBuffer;
|
||||
RawModel* m_RawModel;
|
||||
//RawModel* m_RawModel;
|
||||
|
||||
Skeleton* m_Skeleton = nullptr;
|
||||
std::vector<glm::vec3> m_Vertices;
|
||||
std::vector<unsigned int> m_Indices;
|
||||
|
||||
private:
|
||||
AABB m_Box;
|
||||
@@ -40,6 +43,9 @@ private:
|
||||
GLuint TangentNormalsBuffer;
|
||||
GLuint BiTangentNormalsBuffer;
|
||||
GLuint TextureCoordBuffer;
|
||||
|
||||
std::vector<RawModel::MaterialProperties> m_Materials;
|
||||
bool m_IsSkinned;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -110,7 +110,7 @@ struct ModelJob : RenderJob
|
||||
}
|
||||
|
||||
if (model->IsSkinned()) {
|
||||
Skeleton = Model->m_RawModel->m_Skeleton;
|
||||
Skeleton = Model->m_Skeleton;
|
||||
|
||||
if (Skeleton != nullptr) {
|
||||
EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
#include <boost/endian/buffers.hpp>
|
||||
#include "../Common.h"
|
||||
#include "../GLM.h"
|
||||
#include "../Core/ResourceManager.h"
|
||||
@@ -20,14 +21,10 @@
|
||||
#include "Skeleton.h"
|
||||
#include "ShaderProgram.h"
|
||||
|
||||
#include "boost\endian\buffers.hpp"
|
||||
|
||||
|
||||
|
||||
class RawModelCustom : public Resource
|
||||
{
|
||||
friend class ResourceManager;
|
||||
|
||||
friend class Model;
|
||||
protected:
|
||||
RawModelCustom(std::string fileName);
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Events/ESpawnerSpawn.h"
|
||||
#include "Core/TransformSystem.h"
|
||||
#include "Core/EntityFile.h"
|
||||
#include "Rendering/Model.h"
|
||||
|
||||
class SpawnerSystem : public System
|
||||
{
|
||||
|
||||
@@ -146,18 +146,14 @@ bool RayVsTriangle(const Ray& ray,
|
||||
}
|
||||
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix)
|
||||
{
|
||||
if (!modelVertices) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 0; i < modelIndices.size();) {
|
||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||
if (RayVsTriangle(ray, v0, v1, v2)) {
|
||||
return true;
|
||||
}
|
||||
@@ -198,23 +194,19 @@ bool RayVsTriangle(const Ray& ray,
|
||||
}
|
||||
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
float& outDistance,
|
||||
float& outUCoord,
|
||||
float& outVCoord)
|
||||
{
|
||||
if (!modelVertices) {
|
||||
return false;
|
||||
}
|
||||
|
||||
outDistance = INFINITY;
|
||||
bool hit = false;
|
||||
for (int i = 0; i < modelIndices.size();) {
|
||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||
float dist = outDistance;
|
||||
float u;
|
||||
float v;
|
||||
@@ -229,15 +221,11 @@ bool RayVsModel(const Ray& ray,
|
||||
}
|
||||
|
||||
bool RayVsModel(const Ray& ray,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
glm::vec3& outHitPosition)
|
||||
{
|
||||
if (!modelVertices) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float u;
|
||||
float v;
|
||||
float dist;
|
||||
@@ -560,7 +548,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
||||
}
|
||||
|
||||
Output AABBvsTriangles(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
glm::vec3& boxVelocity,
|
||||
@@ -569,9 +557,6 @@ Output AABBvsTriangles(const AABB& box,
|
||||
glm::vec3& outResolutionVector,
|
||||
bool resolveCollision)
|
||||
{
|
||||
if (!modelVertices) {
|
||||
return Output::OutSeparated;
|
||||
}
|
||||
bool intersect = false;
|
||||
Output out = Output::OutContained;
|
||||
bool everHitTheGround = false;
|
||||
@@ -580,9 +565,9 @@ Output AABBvsTriangles(const AABB& box,
|
||||
glm::vec3 originalBoxVelocity(boxVelocity);
|
||||
for (int i = 0; i < modelIndices.size(); ) {
|
||||
std::array<glm::vec3, 3> triVertices = {
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix)
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix),
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix),
|
||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix)
|
||||
};
|
||||
glm::vec3 outVec;
|
||||
bool collideWithGround = isOnGround;
|
||||
@@ -610,7 +595,7 @@ Output AABBvsTriangles(const AABB& box,
|
||||
}
|
||||
|
||||
bool AABBvsTriangles(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix,
|
||||
glm::vec3& boxVelocity,
|
||||
@@ -630,7 +615,7 @@ bool AABBvsTriangles(const AABB& box,
|
||||
}
|
||||
|
||||
bool AABBvsTriangles(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix)
|
||||
{
|
||||
@@ -648,7 +633,7 @@ bool AABBvsTriangles(const AABB& box,
|
||||
}
|
||||
|
||||
Output AABBvsTrianglesWContainment(const AABB& box,
|
||||
const RawModel::Vertex* modelVertices,
|
||||
const std::vector<glm::vec3>& modelVertices,
|
||||
const std::vector<unsigned int>& modelIndices,
|
||||
const glm::mat4& modelMatrix)
|
||||
{
|
||||
@@ -756,7 +741,7 @@ boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<Enti
|
||||
continue;
|
||||
}
|
||||
float u, v;
|
||||
if (RayVsModel(ray, model->CollisionVertices(), model->CollisionIndices(), TransformSystem::ModelMatrix(entityBox.Entity), outDistance, u, v)) {
|
||||
if (RayVsModel(ray, model->m_Vertices, model->m_Indices, TransformSystem::ModelMatrix(entityBox.Entity), outDistance, u, v)) {
|
||||
outIntersectPos = ray.Origin() + outDistance * ray.Direction();
|
||||
return entityBox;
|
||||
}
|
||||
|
||||
@@ -41,15 +41,15 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
// Don't collide against invisible models.
|
||||
continue;
|
||||
}
|
||||
RawModel* model;
|
||||
Model* model;
|
||||
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
|
||||
try {
|
||||
model = ResourceManager::Load<RawModel, true>(res);
|
||||
model = ResourceManager::Load<Model, true>(res);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
float u, v;
|
||||
hit = Collision::RayVsModel(ray, model->CollisionVertices(), model->CollisionIndices(), TransformSystem::ModelMatrix(boxB.Entity), dist, u, v);
|
||||
hit = Collision::RayVsModel(ray, model->m_Vertices, model->m_Indices, TransformSystem::ModelMatrix(boxB.Entity), dist, u, v);
|
||||
} else {
|
||||
hit = Collision::RayVsAABB(ray, boxB, dist);
|
||||
}
|
||||
@@ -86,9 +86,9 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
// Don't collide against invisible models.
|
||||
continue;
|
||||
}
|
||||
RawModel* model;
|
||||
Model* model;
|
||||
try {
|
||||
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]);
|
||||
model = ResourceManager::Load<Model, true>(boxB.Entity["Model"]["Resource"]);
|
||||
} catch (const std::exception&) {
|
||||
continue;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
||||
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
||||
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
||||
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
||||
if (Collision::AABBvsTriangles(boxA, model->CollisionVertices(), model->CollisionIndices(), modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
|
||||
if (Collision::AABBvsTriangles(boxA, model->m_Vertices, model->m_Indices, modelMatrix, inOutVelocity, verticalStepHeight, isOnGround, resolutionVector)) {
|
||||
//Move the position to previous position if it is not moving in the xz-plane, else resolve with the resolution vector.
|
||||
(Field<glm::vec3>)cTransform["Position"] += resolutionVector;
|
||||
boxA = *Collision::EntityAbsoluteAABB(entity);
|
||||
|
||||
@@ -10,11 +10,11 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
||||
return;
|
||||
}
|
||||
|
||||
RawModel* triggerModel = nullptr;
|
||||
Model* triggerModel = nullptr;
|
||||
glm::mat4 triggerModelMat;
|
||||
if (triggerEntity.HasComponent("Model")) {
|
||||
try {
|
||||
triggerModel = ResourceManager::Load<RawModel, true>(triggerEntity["Model"]["Resource"]);
|
||||
triggerModel = ResourceManager::Load<Model, true>(triggerEntity["Model"]["Resource"]);
|
||||
triggerModelMat = TransformSystem::ModelMatrix(triggerEntity);
|
||||
} catch (const std::exception&) {
|
||||
}
|
||||
@@ -38,8 +38,8 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
||||
? Collision::Output::OutContained
|
||||
: Collision::AABBvsTrianglesWContainment(
|
||||
colliderBox,
|
||||
triggerModel->CollisionVertices(),
|
||||
triggerModel->CollisionIndices(),
|
||||
triggerModel->m_Vertices,
|
||||
triggerModel->m_Indices,
|
||||
triggerModelMat);
|
||||
|
||||
if (colliderFitsInTrigger && Collision::AABBVsAABB(completelyInsideBox, colliderBox) && out == Collision::Output::OutContained) {
|
||||
|
||||
@@ -37,7 +37,7 @@ void AnimationSystem::CreateBlendTrees()
|
||||
continue;;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ void AnimationSystem::UpdateAnimations(double dt)
|
||||
continue;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
continue;
|
||||
}
|
||||
@@ -177,7 +177,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
LOG_ERROR("%s, RootNode skeleton invalid %s", e.NodeName, e.RootNode.Name().c_str());
|
||||
return false;
|
||||
@@ -300,7 +300,7 @@ bool AnimationSystem::OnEntityDeleted(Events::EntityDeleted& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
return false;
|
||||
}
|
||||
@@ -331,7 +331,7 @@ bool AnimationSystem::OnSetBlendWeight(Events::SetBlendWeight& e)
|
||||
return false;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
|
||||
return;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ bool AutoBlendQueue::HasActiveBlendJob()
|
||||
return HasActiveBlendJob();
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
m_BlendQueue.pop_front();
|
||||
return HasActiveBlendJob();
|
||||
@@ -173,7 +173,7 @@ std::shared_ptr<BlendTree> AutoBlendQueue::GetBlendTree()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
if (skeleton == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
||||
return;
|
||||
}
|
||||
|
||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
||||
Skeleton* skeleton = model->m_Skeleton;
|
||||
|
||||
if(skeleton == nullptr) {
|
||||
return;
|
||||
|
||||
@@ -624,7 +624,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
} else {
|
||||
} else if (modelJob->Skeleton != nullptr) {
|
||||
frameBones = modelJob->Skeleton->GetTPose();
|
||||
}
|
||||
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
Model::Model(std::string fileName)
|
||||
{
|
||||
//fileName = "Models/Core/ScreenQuad.mesh";
|
||||
//Try loading the model asyncronously, if it throws any exceptions then let it propagate back to caller.
|
||||
m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
|
||||
auto m_RawModel = ResourceManager::Load<RawModel, true>(fileName);
|
||||
//throw FailedLoadingException("Test");
|
||||
|
||||
for (auto& materialProperty : m_RawModel->m_Materials) {
|
||||
switch (materialProperty.type) {
|
||||
@@ -99,14 +101,24 @@ Model::Model(std::string fileName)
|
||||
|
||||
glm::vec3 mini(INFINITY);
|
||||
glm::vec3 maxi(-INFINITY);
|
||||
|
||||
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) {
|
||||
const auto& v = m_RawModel->Vertices()[i];
|
||||
mini = glm::min(mini, v.Position);
|
||||
maxi = glm::max(maxi, v.Position);
|
||||
}
|
||||
|
||||
m_Box = AABB(mini, maxi);
|
||||
|
||||
//m_Skeleton = m_RawModel->m_Skeleton;
|
||||
delete m_RawModel->m_Skeleton;
|
||||
m_Materials = m_RawModel->m_Materials;
|
||||
//m_Indices = m_RawModel->m_Indices;
|
||||
m_IsSkinned = m_RawModel->IsSkinned();
|
||||
// Copy vertex positions for collisions later
|
||||
for (auto& v : m_RawModel->m_Vertices) {
|
||||
//m_Vertices.push_back(v.Position);
|
||||
}
|
||||
|
||||
ResourceManager::Release("RawModel", fileName);
|
||||
}
|
||||
|
||||
Model::~Model()
|
||||
|
||||
@@ -115,7 +115,7 @@ void PickingPass::Draw(RenderScene& scene)
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
} else {
|
||||
} else if (modelJob->Skeleton != nullptr) {
|
||||
frameBones = modelJob->Skeleton->GetTPose();
|
||||
}
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
@@ -572,12 +572,13 @@ const RawModelCustom::Vertex* RawModelCustom::ConstructCollisionList()
|
||||
|
||||
RawModelCustom::~RawModelCustom()
|
||||
{
|
||||
if (m_Skeleton != nullptr) {
|
||||
delete m_Skeleton;
|
||||
}
|
||||
for (auto material : m_Materials) {
|
||||
delete material.material;
|
||||
}
|
||||
// Ownership of skeleton and materials get transferred to Model
|
||||
// if (m_Skeleton != nullptr) {
|
||||
// delete m_Skeleton;
|
||||
// }
|
||||
//for (auto material : m_Materials) {
|
||||
// delete material.material;
|
||||
//}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -259,7 +259,7 @@ void ShadowPass::Draw(RenderScene & scene)
|
||||
std::vector<glm::mat4> frameBones;
|
||||
if (modelJob->BlendTree != nullptr) {
|
||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||
} else {
|
||||
} else if (modelJob->Skeleton != nullptr) {
|
||||
frameBones = modelJob->Skeleton->GetTPose();
|
||||
}
|
||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||
|
||||
@@ -112,16 +112,16 @@ bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, Entity
|
||||
if (!spawnedBox.Entity.HasComponent("Model")) {
|
||||
return true;
|
||||
}
|
||||
RawModel* model = nullptr;
|
||||
Model* model = nullptr;
|
||||
try {
|
||||
model = ResourceManager::Load<RawModel, true>(otherEntity["Model"]["Resource"]);
|
||||
model = ResourceManager::Load<Model, true>(otherEntity["Model"]["Resource"]);
|
||||
} catch (const std::exception&) {
|
||||
}
|
||||
|
||||
if (model != nullptr && Collision::AABBvsTriangles(
|
||||
spawnedBox,
|
||||
model->CollisionVertices(),
|
||||
model->CollisionIndices(),
|
||||
model->m_Vertices,
|
||||
model->m_Indices,
|
||||
TransformSystem::ModelMatrix(otherEntity))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user