Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0516794db6 |
@@ -48,13 +48,13 @@ bool RayVsTriangle(const Ray& ray,
|
|||||||
bool trueOnNegativeDistance = false);
|
bool trueOnNegativeDistance = false);
|
||||||
//Return true if the ray hits any of the triangles in the model. Stops checking when a hit is detected.
|
//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,
|
bool RayVsModel(const Ray& ray,
|
||||||
const RawModel::Vertex* modelVertices,
|
const std::vector<glm::vec3>& modelVertices,
|
||||||
const std::vector<unsigned int>& modelIndices,
|
const std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix);
|
const glm::mat4& modelMatrix);
|
||||||
//Return true if the ray hits any of the triangles in the model.
|
//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.
|
//Also returns the position of the intersection point. Will loop through all the whole model indices.
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
glm::vec3& outHitPosition);
|
glm::vec3& outHitPosition);
|
||||||
@@ -62,7 +62,7 @@ bool RayVsModel(const Ray& ray,
|
|||||||
//Also returns the distance from the ray origin to the closest
|
//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.
|
//intersection point, and the barycentric u,v-coordinates. Will loop through all the whole model indices.
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
float& outDistance,
|
float& outDistance,
|
||||||
@@ -70,7 +70,7 @@ bool RayVsModel(const Ray& ray,
|
|||||||
float& outVCoord);
|
float& outVCoord);
|
||||||
|
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
glm::vec3& boxVelocity,
|
glm::vec3& boxVelocity,
|
||||||
@@ -80,7 +80,7 @@ bool AABBvsTriangles(const AABB& box,
|
|||||||
|
|
||||||
//Detects collision, but does not resolve.
|
//Detects collision, but does not resolve.
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix);
|
const glm::mat4& modelMatrix);
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ enum Output
|
|||||||
};
|
};
|
||||||
//Detects intersection and containment.
|
//Detects intersection and containment.
|
||||||
Output AABBvsTrianglesWContainment(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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix);
|
const glm::mat4& modelMatrix);
|
||||||
|
|
||||||
|
|||||||
@@ -16,15 +16,18 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
~Model();
|
~Model();
|
||||||
const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_RawModel->m_Materials; }
|
const std::vector<RawModel::MaterialProperties>& MaterialGroups() const { return m_Materials; }
|
||||||
const glm::mat4& Matrix() const { return m_RawModel->m_Matrix; }
|
//const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
|
||||||
const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
|
unsigned int NumberOfVertices() const { return m_Vertices.size(); }
|
||||||
unsigned int NumberOfVertices() const { return m_RawModel->NumVertices(); }
|
|
||||||
const AABB& Box() const { return m_Box; }
|
const AABB& Box() const { return m_Box; }
|
||||||
bool IsSkinned() const { return m_RawModel->IsSkinned(); }
|
bool IsSkinned() const { return m_IsSkinned; }
|
||||||
GLuint VAO;
|
GLuint VAO;
|
||||||
GLuint ElementBuffer;
|
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:
|
private:
|
||||||
AABB m_Box;
|
AABB m_Box;
|
||||||
@@ -34,6 +37,9 @@ private:
|
|||||||
GLuint TangentNormalsBuffer;
|
GLuint TangentNormalsBuffer;
|
||||||
GLuint BiTangentNormalsBuffer;
|
GLuint BiTangentNormalsBuffer;
|
||||||
GLuint TextureCoordBuffer;
|
GLuint TextureCoordBuffer;
|
||||||
|
|
||||||
|
std::vector<RawModel::MaterialProperties> m_Materials;
|
||||||
|
bool m_IsSkinned;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ struct ModelJob : RenderJob
|
|||||||
IsShielded = isShielded;
|
IsShielded = isShielded;
|
||||||
|
|
||||||
if (model->IsSkinned()) {
|
if (model->IsSkinned()) {
|
||||||
Skeleton = Model->m_RawModel->m_Skeleton;
|
Skeleton = Model->m_Skeleton;
|
||||||
|
|
||||||
if (Skeleton != nullptr) {
|
if (Skeleton != nullptr) {
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include <boost/filesystem/path.hpp>
|
#include <boost/filesystem/path.hpp>
|
||||||
|
|
||||||
|
#include <boost/endian/buffers.hpp>
|
||||||
#include "../Common.h"
|
#include "../Common.h"
|
||||||
#include "../GLM.h"
|
#include "../GLM.h"
|
||||||
#include "../Core/ResourceManager.h"
|
#include "../Core/ResourceManager.h"
|
||||||
@@ -20,14 +21,10 @@
|
|||||||
#include "Skeleton.h"
|
#include "Skeleton.h"
|
||||||
#include "ShaderProgram.h"
|
#include "ShaderProgram.h"
|
||||||
|
|
||||||
#include "boost\endian\buffers.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class RawModelCustom : public Resource
|
class RawModelCustom : public Resource
|
||||||
{
|
{
|
||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
|
friend class Model;
|
||||||
protected:
|
protected:
|
||||||
RawModelCustom(std::string fileName);
|
RawModelCustom(std::string fileName);
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#include "Events/ESpawnerSpawn.h"
|
#include "Events/ESpawnerSpawn.h"
|
||||||
#include "Core/TransformSystem.h"
|
#include "Core/TransformSystem.h"
|
||||||
#include "Core/EntityFile.h"
|
#include "Core/EntityFile.h"
|
||||||
|
#include "Rendering/Model.h"
|
||||||
|
|
||||||
class SpawnerSystem : public System
|
class SpawnerSystem : public System
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -146,14 +146,14 @@ bool RayVsTriangle(const Ray& ray,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix)
|
const glm::mat4& modelMatrix)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < modelIndices.size();) {
|
for (int i = 0; i < modelIndices.size();) {
|
||||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||||
if (RayVsTriangle(ray, v0, v1, v2)) {
|
if (RayVsTriangle(ray, v0, v1, v2)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ bool RayVsTriangle(const Ray& ray,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
float& outDistance,
|
float& outDistance,
|
||||||
@@ -204,9 +204,9 @@ bool RayVsModel(const Ray& ray,
|
|||||||
outDistance = INFINITY;
|
outDistance = INFINITY;
|
||||||
bool hit = false;
|
bool hit = false;
|
||||||
for (int i = 0; i < modelIndices.size();) {
|
for (int i = 0; i < modelIndices.size();) {
|
||||||
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
glm::vec3 v0 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||||
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
glm::vec3 v1 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||||
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix);
|
glm::vec3 v2 = TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix);
|
||||||
float dist = outDistance;
|
float dist = outDistance;
|
||||||
float u;
|
float u;
|
||||||
float v;
|
float v;
|
||||||
@@ -221,7 +221,7 @@ bool RayVsModel(const Ray& ray,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
glm::vec3& outHitPosition)
|
glm::vec3& outHitPosition)
|
||||||
@@ -548,7 +548,7 @@ BoxTriRes AABBvsTriangle(const AABB& box,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Output AABBvsTriangles(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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
glm::vec3& boxVelocity,
|
glm::vec3& boxVelocity,
|
||||||
@@ -565,9 +565,9 @@ Output AABBvsTriangles(const AABB& box,
|
|||||||
glm::vec3 originalBoxVelocity(boxVelocity);
|
glm::vec3 originalBoxVelocity(boxVelocity);
|
||||||
for (int i = 0; i < modelIndices.size(); ) {
|
for (int i = 0; i < modelIndices.size(); ) {
|
||||||
std::array<glm::vec3, 3> triVertices = {
|
std::array<glm::vec3, 3> triVertices = {
|
||||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix),
|
||||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix),
|
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix),
|
||||||
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]].Position, modelMatrix)
|
TransformSystem::TransformPoint(modelVertices[modelIndices[i++]], modelMatrix)
|
||||||
};
|
};
|
||||||
glm::vec3 outVec;
|
glm::vec3 outVec;
|
||||||
bool collideWithGround = isOnGround;
|
bool collideWithGround = isOnGround;
|
||||||
@@ -595,7 +595,7 @@ Output AABBvsTriangles(const AABB& box,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix,
|
const glm::mat4& modelMatrix,
|
||||||
glm::vec3& boxVelocity,
|
glm::vec3& boxVelocity,
|
||||||
@@ -615,7 +615,7 @@ bool AABBvsTriangles(const AABB& box,
|
|||||||
}
|
}
|
||||||
|
|
||||||
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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix)
|
const glm::mat4& modelMatrix)
|
||||||
{
|
{
|
||||||
@@ -633,7 +633,7 @@ bool AABBvsTriangles(const AABB& box,
|
|||||||
}
|
}
|
||||||
|
|
||||||
Output AABBvsTrianglesWContainment(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 std::vector<unsigned int>& modelIndices,
|
||||||
const glm::mat4& modelMatrix)
|
const glm::mat4& modelMatrix)
|
||||||
{
|
{
|
||||||
@@ -741,7 +741,7 @@ boost::optional<EntityAABB> EntityFirstHitByRay(const Ray& ray, std::vector<Enti
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float u, v;
|
float u, v;
|
||||||
if (RayVsModel(ray, model->Vertices(), model->m_RawModel->m_Indices, 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();
|
outIntersectPos = ray.Origin() + outDistance * ray.Direction();
|
||||||
return entityBox;
|
return entityBox;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,15 +41,15 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
// Don't collide against invisible models.
|
// Don't collide against invisible models.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RawModel* model;
|
Model* model;
|
||||||
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
|
std::string res = (std::string)boxB.Entity["Model"]["Resource"];
|
||||||
try {
|
try {
|
||||||
model = ResourceManager::Load<RawModel, true>(res);
|
model = ResourceManager::Load<Model, true>(res);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float u, v;
|
float u, v;
|
||||||
hit = Collision::RayVsModel(ray, model->Vertices(), model->m_Indices, 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 {
|
} else {
|
||||||
hit = Collision::RayVsAABB(ray, boxB, dist);
|
hit = Collision::RayVsAABB(ray, boxB, dist);
|
||||||
}
|
}
|
||||||
@@ -86,9 +86,9 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
// Don't collide against invisible models.
|
// Don't collide against invisible models.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
RawModel* model;
|
Model* model;
|
||||||
try {
|
try {
|
||||||
model = ResourceManager::Load<RawModel, true>(boxB.Entity["Model"]["Resource"]);
|
model = ResourceManager::Load<Model, true>(boxB.Entity["Model"]["Resource"]);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ void CollisionSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapper& c
|
|||||||
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
glm::vec3 inOutVelocity = (glm::vec3)cPhysics["Velocity"];
|
||||||
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
bool isOnGround = (bool)cPhysics["IsOnGround"];
|
||||||
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
float verticalStepHeight = (float)(double)cPhysics["VerticalStepHeight"];
|
||||||
if (Collision::AABBvsTriangles(boxA, model->Vertices(), model->m_Indices, 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.
|
//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;
|
(Field<glm::vec3>)cTransform["Position"] += resolutionVector;
|
||||||
boxA = *Collision::EntityAbsoluteAABB(entity);
|
boxA = *Collision::EntityAbsoluteAABB(entity);
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawModel* triggerModel = nullptr;
|
Model* triggerModel = nullptr;
|
||||||
glm::mat4 triggerModelMat;
|
glm::mat4 triggerModelMat;
|
||||||
if (triggerEntity.HasComponent("Model")) {
|
if (triggerEntity.HasComponent("Model")) {
|
||||||
try {
|
try {
|
||||||
triggerModel = ResourceManager::Load<RawModel, true>(triggerEntity["Model"]["Resource"]);
|
triggerModel = ResourceManager::Load<Model, true>(triggerEntity["Model"]["Resource"]);
|
||||||
triggerModelMat = TransformSystem::ModelMatrix(triggerEntity);
|
triggerModelMat = TransformSystem::ModelMatrix(triggerEntity);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ void TriggerSystem::UpdateComponent(EntityWrapper& triggerEntity, ComponentWrapp
|
|||||||
? Collision::Output::OutContained
|
? Collision::Output::OutContained
|
||||||
: Collision::AABBvsTrianglesWContainment(
|
: Collision::AABBvsTrianglesWContainment(
|
||||||
colliderBox,
|
colliderBox,
|
||||||
triggerModel->Vertices(),
|
triggerModel->m_Vertices,
|
||||||
triggerModel->m_Indices,
|
triggerModel->m_Indices,
|
||||||
triggerModelMat);
|
triggerModelMat);
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ void AnimationSystem::CreateBlendTrees()
|
|||||||
continue;;
|
continue;;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ void AnimationSystem::UpdateAnimations(double dt)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -175,7 +175,7 @@ bool AnimationSystem::OnAutoAnimationBlend(Events::AutoAnimationBlend& e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ bool AnimationSystem::OnEntityDeleted(Events::EntityDeleted& e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -325,7 +325,7 @@ bool AnimationSystem::OnSetBlendWeight(Events::SetBlendWeight& e)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ void AutoBlendQueue::Insert(AutoBlendJob autoBlendJob)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ bool AutoBlendQueue::HasActiveBlendJob()
|
|||||||
return HasActiveBlendJob();
|
return HasActiveBlendJob();
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
m_BlendQueue.pop_front();
|
m_BlendQueue.pop_front();
|
||||||
return HasActiveBlendJob();
|
return HasActiveBlendJob();
|
||||||
@@ -173,7 +173,7 @@ std::shared_ptr<BlendTree> AutoBlendQueue::GetBlendTree()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
if (skeleton == nullptr) {
|
if (skeleton == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ void BoneAttachmentSystem::UpdateComponent(EntityWrapper& entity, ComponentWrapp
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Skeleton* skeleton = model->m_RawModel->m_Skeleton;
|
Skeleton* skeleton = model->m_Skeleton;
|
||||||
|
|
||||||
if(skeleton == nullptr) {
|
if(skeleton == nullptr) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -530,7 +530,7 @@ void DrawFinalPass::DrawModelRenderQueues(std::list<std::shared_ptr<RenderJob>>&
|
|||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
if (modelJob->BlendTree != nullptr) {
|
if (modelJob->BlendTree != nullptr) {
|
||||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
} else {
|
} else if (modelJob->Skeleton != nullptr) {
|
||||||
frameBones = modelJob->Skeleton->GetTPose();
|
frameBones = modelJob->Skeleton->GetTPose();
|
||||||
}
|
}
|
||||||
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(forwardSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|||||||
@@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
Model::Model(std::string fileName)
|
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.
|
//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) {
|
for (auto& materialProperty : m_RawModel->m_Materials) {
|
||||||
switch (materialProperty.type) {
|
switch (materialProperty.type) {
|
||||||
@@ -99,14 +101,24 @@ Model::Model(std::string fileName)
|
|||||||
|
|
||||||
glm::vec3 mini(INFINITY);
|
glm::vec3 mini(INFINITY);
|
||||||
glm::vec3 maxi(-INFINITY);
|
glm::vec3 maxi(-INFINITY);
|
||||||
|
|
||||||
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) {
|
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) {
|
||||||
const auto& v = m_RawModel->Vertices()[i];
|
const auto& v = m_RawModel->Vertices()[i];
|
||||||
mini = glm::min(mini, v.Position);
|
mini = glm::min(mini, v.Position);
|
||||||
maxi = glm::max(maxi, v.Position);
|
maxi = glm::max(maxi, v.Position);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Box = AABB(mini, maxi);
|
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()
|
Model::~Model()
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ void PickingPass::Draw(RenderScene& scene)
|
|||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
if (modelJob->BlendTree != nullptr) {
|
if (modelJob->BlendTree != nullptr) {
|
||||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
} else {
|
} else if (modelJob->Skeleton != nullptr) {
|
||||||
frameBones = modelJob->Skeleton->GetTPose();
|
frameBones = modelJob->Skeleton->GetTPose();
|
||||||
}
|
}
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderSkinnedHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|||||||
@@ -493,12 +493,13 @@ void RawModelCustom::ReadAnimationKeyFrame(std::size_t& offset, char* fileData,
|
|||||||
|
|
||||||
RawModelCustom::~RawModelCustom()
|
RawModelCustom::~RawModelCustom()
|
||||||
{
|
{
|
||||||
if (m_Skeleton != nullptr) {
|
// Ownership of skeleton and materials get transferred to Model
|
||||||
delete m_Skeleton;
|
// if (m_Skeleton != nullptr) {
|
||||||
}
|
// delete m_Skeleton;
|
||||||
for (auto material : m_Materials) {
|
// }
|
||||||
delete material.material;
|
//for (auto material : m_Materials) {
|
||||||
}
|
// delete material.material;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -270,7 +270,7 @@ void ShadowPass::Draw(RenderScene & scene)
|
|||||||
std::vector<glm::mat4> frameBones;
|
std::vector<glm::mat4> frameBones;
|
||||||
if (modelJob->BlendTree != nullptr) {
|
if (modelJob->BlendTree != nullptr) {
|
||||||
frameBones = modelJob->BlendTree->GetFinalPose();
|
frameBones = modelJob->BlendTree->GetFinalPose();
|
||||||
} else {
|
} else if (modelJob->Skeleton != nullptr) {
|
||||||
frameBones = modelJob->Skeleton->GetTPose();
|
frameBones = modelJob->Skeleton->GetTPose();
|
||||||
}
|
}
|
||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
|||||||
@@ -103,15 +103,15 @@ bool SpawnerSystem::spawnedEntityIsColliding(EntityWrapper spawnedEntity, Entity
|
|||||||
if (!spawnedBox.Entity.HasComponent("Model")) {
|
if (!spawnedBox.Entity.HasComponent("Model")) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
RawModel* model = nullptr;
|
Model* model = nullptr;
|
||||||
try {
|
try {
|
||||||
model = ResourceManager::Load<RawModel, true>(otherEntity["Model"]["Resource"]);
|
model = ResourceManager::Load<Model, true>(otherEntity["Model"]["Resource"]);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model != nullptr && Collision::AABBvsTriangles(
|
if (model != nullptr && Collision::AABBvsTriangles(
|
||||||
spawnedBox,
|
spawnedBox,
|
||||||
model->Vertices(),
|
model->m_Vertices,
|
||||||
model->m_Indices,
|
model->m_Indices,
|
||||||
TransformSystem::ModelMatrix(otherEntity))) {
|
TransformSystem::ModelMatrix(otherEntity))) {
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user