Merge pull request #137 from teamfisk/Importer

Export and import of collision meshes
This commit is contained in:
Adam Byléhn
2016-03-14 04:26:50 +01:00
23 changed files with 368 additions and 225 deletions
+6 -6
View File
@@ -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);
+12 -6
View File
@@ -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; } unsigned int NumberOfVertices() const { return m_Vertices.size(); }
const RawModel::Vertex* Vertices() const { return m_RawModel->Vertices(); }
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
+1 -1
View File
@@ -110,7 +110,7 @@ struct ModelJob : RenderJob
} }
if (model->IsSkinned()) { if (model->IsSkinned()) {
Skeleton = Model->m_RawModel->m_Skeleton; Skeleton = Model->m_Skeleton;
if (Skeleton != nullptr) { if (Skeleton != nullptr) {
EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID); EntityWrapper entityWrapper = EntityWrapper(world, modelComponent.EntityID);
+39 -16
View File
@@ -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,22 +21,17 @@
#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);
public: public:
~RawModelCustom(); ~RawModelCustom();
struct Vertex struct RenderVertex {
{
glm::vec3 Position; glm::vec3 Position;
glm::vec3 Normal; glm::vec3 Normal;
glm::vec3 Tangent; glm::vec3 Tangent;
@@ -43,7 +39,7 @@ public:
glm::vec2 TextureCoords; glm::vec2 TextureCoords;
}; };
struct SkinedVertex : public Vertex { struct SkinedVertex : public RenderVertex {
glm::vec4 BoneIndices; glm::vec4 BoneIndices;
glm::vec4 BoneWeights; glm::vec4 BoneWeights;
}; };
@@ -91,7 +87,7 @@ public:
unsigned int ShaderID = 0; unsigned int ShaderID = 0;
}; };
const Vertex* Vertices() const { const RenderVertex* Vertices() const {
if (hasSkin) { if (hasSkin) {
return m_SkinedVertices.data(); return m_SkinedVertices.data();
} else { } else {
@@ -99,16 +95,16 @@ public:
} }
}; };
unsigned int VertexSize() const { unsigned int VertexSize() const {
if (hasSkin) { if (hasSkin) {
return sizeof(SkinedVertex); return sizeof(SkinedVertex);
} }
else { else {
return sizeof(Vertex); return sizeof(RenderVertex);
} }
}; };
unsigned int NumVertices() const { size_t NumVertices() const {
if (hasSkin) { if (hasSkin) {
return m_SkinedVertices.size(); return m_SkinedVertices.size();
} else { } else {
@@ -116,17 +112,39 @@ public:
} }
}; };
const std::vector<unsigned int>& Indices() const {
return m_Indices;
}
bool IsSkinned() const { return hasSkin; }; bool IsSkinned() const { return hasSkin; };
const std::vector<glm::vec3>& CollisionVertices();
size_t NumCollisionVertices() const {
return m_CollisionVertices.size();
};
const std::vector<unsigned int>& CollisionIndices() const {
if (hasCollisionMesh) {
return m_CollisionIndices;
} else {
return m_Indices;
}
};
std::vector<MaterialProperties> m_Materials; std::vector<MaterialProperties> m_Materials;
std::vector<unsigned int> m_Indices;
Skeleton* m_Skeleton = nullptr; Skeleton* m_Skeleton = nullptr;
glm::mat4 m_Matrix; glm::mat4 m_Matrix;
private: private:
bool hasSkin; bool hasSkin;
std::vector<Vertex> m_Vertices; bool hasCollisionMesh = false;
std::vector<unsigned int> m_Indices;
std::vector<unsigned int> m_CollisionIndices;
std::vector<glm::vec3> m_CollisionVertices;
std::vector<RenderVertex> m_Vertices;
std::vector<SkinedVertex> m_SkinedVertices; std::vector<SkinedVertex> m_SkinedVertices;
void ReadMeshFile(std::string filePath); void ReadMeshFile(std::string filePath);
@@ -149,7 +167,12 @@ private:
void ReadAnimationClips(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int numberOfClips); void ReadAnimationClips(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int numberOfClips);
void ReadAnimationClipSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int clipIndex); void ReadAnimationClipSingle(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, unsigned int clipIndex);
void ReadAnimationKeyFrame(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation); void ReadAnimationKeyFrame(std::size_t& offset, char* fileData, const unsigned int& fileByteSize, std::vector<Skeleton::Animation::Keyframe>& animation);
void ReadCollisionFile(std::string filePath);
void ReadCollisionFileData(std::size_t& offset, char* fileData, const unsigned int& fileByteSize);
const std::vector<glm::vec3>& ConstructCollisionList();
//void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID); //void CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID);
}; };
+1
View File
@@ -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
{ {
+17 -17
View File
@@ -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;
} }
+6 -6
View File
@@ -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);
+3 -3
View File
@@ -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);
+5 -5
View File
@@ -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)
continue; continue;
} }
Skeleton* skeleton = model->m_RawModel->m_Skeleton; Skeleton* skeleton = model->m_Skeleton;
if (skeleton == nullptr) { if (skeleton == nullptr) {
continue; continue;
} }
@@ -177,7 +177,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) {
LOG_ERROR("%s, RootNode skeleton invalid %s", e.NodeName, e.RootNode.Name().c_str()); LOG_ERROR("%s, RootNode skeleton invalid %s", e.NodeName, e.RootNode.Name().c_str());
return false; return false;
@@ -300,7 +300,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;
} }
@@ -331,7 +331,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;
} }
+3 -3
View File
@@ -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;
+3 -17
View File
@@ -332,14 +332,6 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
glClearStencil(0x00); glClearStencil(0x00);
glClear(GL_STENCIL_BUFFER_BIT); glClear(GL_STENCIL_BUFFER_BIT);
//Fill depth buffer
state->Enable(GL_STENCIL_TEST);
state->StencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
state->StencilFunc(GL_ALWAYS, 1, 0xFF);
state->StencilMask(0xFF);
state->DepthMask(GL_FALSE);
//DrawToDepthStencilBuffer(scene.Jobs.ShieldObjects, scene);
state->DepthMask(GL_TRUE);
//Draw Opaque shielded objects //Draw Opaque shielded objects
state->Disable(GL_STENCIL_TEST); state->Disable(GL_STENCIL_TEST);
@@ -354,10 +346,10 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
GLERROR("OpaqueObjects"); GLERROR("OpaqueObjects");
//state->Disable(GL_STENCIL_TEST); //state->Disable(GL_STENCIL_TEST);
//Draw Transparen Shielded objects //Draw Transparen objects
state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing DrawModelRenderQueuesWithShieldCheck(scene.Jobs.TransparentObjects, scene); //might need changing
GLERROR("Shielded Transparent objects"); GLERROR("Transparent objects");
//Generate blur texture. //Generate blur texture.
delete state; delete state;
@@ -379,12 +371,6 @@ void DrawFinalPass::Draw(RenderScene& scene, BlurHUD* blurHUDPass)
} else { } else {
stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle()); stateSprite = new DrawFinalPassState(m_FinalPassFrameBuffer->GetHandle());
} }
//Draw Transparen objects
//state->BlendFunc(GL_ONE, GL_ONE);
//state->StencilFunc(GL_EQUAL, 1, 0xFF);
//DrawModelRenderQueues(scene.Jobs.TransparentObjects, scene);
GLERROR("TransparentObjects");
//state->BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
stateSprite->Enable(GL_DEPTH_TEST); stateSprite->Enable(GL_DEPTH_TEST);
//stateSprite->AlphaFunc(GL_GEQUAL, 0.05f); //stateSprite->AlphaFunc(GL_GEQUAL, 0.05f);
//stateSprite->Enable(GL_ALPHA_TEST); //stateSprite->Enable(GL_ALPHA_TEST);
@@ -638,7 +624,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]));
+24 -12
View File
@@ -3,9 +3,9 @@
Model::Model(std::string fileName) Model::Model(std::string fileName)
{ {
//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 rawModel = ResourceManager::Load<RawModel, true>(fileName);
for (auto& materialProperty : m_RawModel->m_Materials) { for (auto& materialProperty : rawModel->m_Materials) {
switch (materialProperty.type) { switch (materialProperty.type) {
case RawModel::MaterialType::SingleTextures: case RawModel::MaterialType::SingleTextures:
{ {
@@ -46,11 +46,11 @@ Model::Model(std::string fileName)
glGenBuffers(1, &buffer); glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, m_RawModel->NumVertices() * m_RawModel->VertexSize(), m_RawModel->Vertices(), GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, rawModel->NumVertices() * rawModel->VertexSize(), rawModel->Vertices(), GL_STATIC_DRAW);
glGenBuffers(1, &ElementBuffer); glGenBuffers(1, &ElementBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ElementBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_RawModel->m_Indices.size() * sizeof(unsigned int), &m_RawModel->m_Indices[0], GL_STATIC_DRAW); glBufferData(GL_ELEMENT_ARRAY_BUFFER, rawModel->Indices().size() * sizeof(unsigned int), rawModel->Indices().data(), GL_STATIC_DRAW);
glGenVertexArrays(1, &VAO); glGenVertexArrays(1, &VAO);
glBindVertexArray(VAO); glBindVertexArray(VAO);
@@ -58,7 +58,7 @@ Model::Model(std::string fileName)
glBindBuffer(GL_ARRAY_BUFFER, buffer); glBindBuffer(GL_ARRAY_BUFFER, buffer);
std::vector<int> structSizes; std::vector<int> structSizes;
if (m_RawModel->IsSkinned()) { if (rawModel->IsSkinned()) {
structSizes = { 3, 3, 3, 3, 2, 4, 4 }; structSizes = { 3, 3, 3, 3, 2, 4, 4 };
} else { } else {
structSizes = { 3, 3, 3, 3, 2 }; structSizes = { 3, 3, 3, 3, 2 };
@@ -77,7 +77,7 @@ Model::Model(std::string fileName)
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
if (m_RawModel->IsSkinned()) { if (rawModel->IsSkinned()) {
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++; glVertexAttribPointer(element, structSizes[element], GL_FLOAT, GL_FALSE, stride, (GLvoid*)(sizeof(GLfloat) * (offset += structSizes[element - 1]))); element++;
} }
@@ -89,7 +89,7 @@ Model::Model(std::string fileName)
glEnableVertexAttribArray(2); glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3); glEnableVertexAttribArray(3);
glEnableVertexAttribArray(4); glEnableVertexAttribArray(4);
if (m_RawModel->IsSkinned()) { if (rawModel->IsSkinned()) {
glEnableVertexAttribArray(5); glEnableVertexAttribArray(5);
glEnableVertexAttribArray(6); glEnableVertexAttribArray(6);
} }
@@ -99,17 +99,29 @@ 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 < rawModel->NumVertices(); i++) {
for (unsigned int i = 0; i < m_RawModel->NumVertices(); i++) { const auto& v = 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 = rawModel->m_Skeleton;
m_Materials = rawModel->m_Materials;
m_Indices = rawModel->CollisionIndices();
m_IsSkinned = rawModel->IsSkinned();
// Copy vertex positions for collisions later
m_Vertices = rawModel->CollisionVertices();
ResourceManager::Release("RawModel", fileName);
} }
Model::~Model() Model::~Model()
{ {
if (m_Skeleton != nullptr) {
delete m_Skeleton;
}
for (auto material : m_Materials) {
delete material.material;
}
} }
+1 -1
View File
@@ -115,7 +115,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]));
+86 -9
View File
@@ -11,6 +11,7 @@ RawModelCustom::RawModelCustom(std::string fileName)
ReadMeshFile(fileName); ReadMeshFile(fileName);
ReadMaterialFile(fileName); ReadMaterialFile(fileName);
ReadAnimationFile(fileName); ReadAnimationFile(fileName);
ReadCollisionFile(fileName);
} }
void RawModelCustom::ReadMeshFile(std::string filePath) void RawModelCustom::ReadMeshFile(std::string filePath)
@@ -71,11 +72,11 @@ void RawModelCustom::ReadVertices(std::size_t& offset, char* fileData, const uns
memcpy(&m_SkinedVertices[0], fileData + offset, m_SkinedVertices.size() * sizeof(SkinedVertex)); memcpy(&m_SkinedVertices[0], fileData + offset, m_SkinedVertices.size() * sizeof(SkinedVertex));
offset += m_SkinedVertices.size() * sizeof(SkinedVertex); offset += m_SkinedVertices.size() * sizeof(SkinedVertex);
} else { } else {
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) { if (offset + m_Vertices.size() * sizeof(RenderVertex) > fileByteSize) {
throw Resource::FailedLoadingException("Reading vertices failed"); throw Resource::FailedLoadingException("Reading vertices failed");
} }
memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(Vertex)); memcpy(&m_Vertices[0], fileData + offset, m_Vertices.size() * sizeof(RenderVertex));
offset += m_Vertices.size() * sizeof(Vertex); offset += m_Vertices.size() * sizeof(RenderVertex);
} }
#else #else
#endif #endif
@@ -491,14 +492,90 @@ void RawModelCustom::ReadAnimationKeyFrame(std::size_t& offset, char* fileData,
} }
void RawModelCustom::ReadCollisionFile(std::string filePath) {
char* fileData;
filePath += ".colli";
std::ifstream in(filePath.c_str(), std::ios_base::binary | std::ios_base::ate);
if (!in.is_open()) {
return;
}
unsigned int fileByteSize = static_cast<unsigned int>(in.tellg());
in.seekg(0, std::ios_base::beg);
fileData = new char[fileByteSize];
in.read(fileData, fileByteSize);
in.close();
std::size_t offset = 0;
if (fileByteSize > 0) {
ReadCollisionFileData(offset, fileData, fileByteSize);
}
hasCollisionMesh = true;
delete[] fileData;
}
const std::vector<glm::vec3>& RawModelCustom::CollisionVertices() {
if (hasCollisionMesh) {
return m_CollisionVertices;
}
else if (hasSkin) {
// We don't do collisions against skinned meshes now.
m_CollisionVertices = std::vector<glm::vec3>();
return m_CollisionVertices;
}
else {
return ConstructCollisionList();
}
};
void RawModelCustom::ReadCollisionFileData(std::size_t& offset, char* fileData, const unsigned int& fileByteSize){
m_CollisionVertices.resize(static_cast<std::size_t>(*(unsigned int*)(fileData + offset)));
offset += sizeof(unsigned int);
m_CollisionIndices.resize(static_cast<std::size_t>(*(unsigned int*)(fileData + offset)));
offset += sizeof(unsigned int);
if (offset + m_CollisionVertices.size() * sizeof(glm::vec3) > fileByteSize) {
throw Resource::FailedLoadingException("Reading collision vertices failed");
}
memcpy(&m_CollisionVertices[0], fileData + offset, m_CollisionVertices.size() * sizeof(glm::vec3));
offset += m_CollisionVertices.size() * sizeof(glm::vec3);
if (offset + m_CollisionIndices.size() * sizeof(unsigned int) > fileByteSize) {
throw Resource::FailedLoadingException("Reading collision indices failed");
}
memcpy(&m_CollisionIndices[0], fileData + offset, m_CollisionIndices.size() * sizeof(unsigned int));
offset += m_CollisionIndices.size() * sizeof(unsigned int);
}
const std::vector<glm::vec3>& RawModelCustom::ConstructCollisionList()
{
if (!hasCollisionMesh && m_CollisionVertices.size() == 0) {
if (hasSkin) {
m_CollisionVertices.reserve(m_SkinedVertices.size());
for (const auto& vertex : m_SkinedVertices) {
m_CollisionVertices.push_back(vertex.Position);
}
} else {
m_CollisionVertices.reserve(m_Vertices.size());
for (const auto& vertex : m_Vertices) {
m_CollisionVertices.push_back(vertex.Position);
}
}
}
return m_CollisionVertices;
}
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
+1 -1
View File
@@ -261,7 +261,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]));
+3 -3
View File
@@ -112,15 +112,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;
+22 -5
View File
@@ -5,7 +5,7 @@ Export::Export()
} }
bool Export::Meshes(std::string pathName, bool selectedOnly) bool Export::Meshes(std::string pathName, bool selectedOnly, bool isCollision)
{ {
MStatus status; MStatus status;
if (pathName.empty()) { if (pathName.empty()) {
@@ -92,8 +92,14 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
Objects.append(node); Objects.append(node);
} }
} }
GetMeshData(Objects); GetMeshData(Objects, isCollision);
WriteMeshData(pathName);
if (!isCollision) {
WriteMeshData(pathName);
} else {
WriteCollisionData(pathName);
}
MGlobal::displayInfo(MString() + "Enabling IKSolvers"); MGlobal::displayInfo(MString() + "Enabling IKSolvers");
status = MGlobal::executeCommand("doEnableNodeItems true all;"); status = MGlobal::executeCommand("doEnableNodeItems true all;");
if (status != MS::kSuccess) { if (status != MS::kSuccess) {
@@ -144,9 +150,9 @@ bool Export::Animations(std::string pathName, std::vector<AnimationInfo> animInf
return true; return true;
} }
bool Export::GetMeshData(MObjectArray object) bool Export::GetMeshData(MObjectArray object, bool collision)
{ {
meshes = m_MeshHandler.GetMeshData(object); meshes = m_MeshHandler.GetMeshData(object, collision);
return true; return true;
} }
@@ -185,6 +191,17 @@ void Export::WriteMeshData(std::string pathName)
m_MeshFile.CloseFiles(); m_MeshFile.CloseFiles();
} }
void Export::WriteCollisionData(std::string pathName) {
m_ColliFile.ASCIIFilePath(pathName + "_colli.txt");
m_ColliFile.binaryFilePath(pathName + ".colli");
m_ColliFile.OpenFiles();
m_ColliFile.writeToFiles((OutputData*)&meshes);
m_ColliFile.CloseFiles();
}
void Export::WriteAnimData(std::string pathName) void Export::WriteAnimData(std::string pathName)
{ {
if (allBindPoses.size() > 0) { if (allBindPoses.size() > 0) {
+4 -2
View File
@@ -22,18 +22,19 @@ public:
int End; int End;
}; };
bool Meshes(std::string pathName, bool selectedOnly = false); bool Meshes(std::string pathName, bool selectedOnly = false, bool isCollision = false);
bool Materials(std::string pathName); bool Materials(std::string pathName);
bool Animations(std::string pathName, std::vector<AnimationInfo> animInfo); bool Animations(std::string pathName, std::vector<AnimationInfo> animInfo);
private: private:
bool GetMeshData(MObjectArray object); bool GetMeshData(MObjectArray object, bool collision);
bool GetMaterialData(); bool GetMaterialData();
bool GetAnimationData(AnimationInfo info); bool GetAnimationData(AnimationInfo info);
void WriteMeshData(std::string pathName); void WriteMeshData(std::string pathName);
void WriteAnimData(std::string pathName); void WriteAnimData(std::string pathName);
void WriteMaterialData(std::string pathName); void WriteMaterialData(std::string pathName);
void WriteCollisionData(std::string pathName);
Material m_MaterialHandler; Material m_MaterialHandler;
Skeleton m_SkeletonHandler; Skeleton m_SkeletonHandler;
@@ -44,6 +45,7 @@ private:
WriteToFile m_MeshFile; WriteToFile m_MeshFile;
WriteToFile m_AnimFile; WriteToFile m_AnimFile;
WriteToFile m_MtrlFile; WriteToFile m_MtrlFile;
WriteToFile m_ColliFile;
//Mesh Data //Mesh Data
Mesh meshes; Mesh meshes;
+35 -30
View File
@@ -25,6 +25,7 @@ Menu::Menu(QDialog* dialog)
m_ExportSelectedButton = new QCheckBox(tr("&Export Selected")); m_ExportSelectedButton = new QCheckBox(tr("&Export Selected"));
m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations")); m_ExportAnimationsButton = new QCheckBox(tr("&Export Animations"));
m_ExportMaterialButton = new QCheckBox(tr("&Export Material"));; m_ExportMaterialButton = new QCheckBox(tr("&Export Material"));;
m_IsCollision = new QCheckBox(tr("&Export as collision mesh"));
m_ExportAnimationsButton->setChecked(true); m_ExportAnimationsButton->setChecked(true);
m_ExportMaterialButton->setChecked(true); m_ExportMaterialButton->setChecked(true);
@@ -32,6 +33,7 @@ Menu::Menu(QDialog* dialog)
vbox->addWidget(m_ExportSelectedButton); vbox->addWidget(m_ExportSelectedButton);
vbox->addWidget(m_ExportAnimationsButton); vbox->addWidget(m_ExportAnimationsButton);
vbox->addWidget(m_ExportMaterialButton); vbox->addWidget(m_ExportMaterialButton);
vbox->addWidget(m_IsCollision);
vbox->addStretch(1); vbox->addStretch(1);
optionsBox->setLayout(vbox); optionsBox->setLayout(vbox);
@@ -46,6 +48,7 @@ Menu::Menu(QDialog* dialog)
connect(m_ExportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); connect(m_ExportSelectedButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); connect(m_ExportAnimationsButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_ExportMaterialButton, SIGNAL(clicked(bool)), this, SLOT(NULL)); connect(m_ExportMaterialButton, SIGNAL(clicked(bool)), this, SLOT(NULL));
connect(m_IsCollision, SIGNAL(clicked(bool)), this, SLOT(NULL));
// Creating several layouts, adding widgets & adding them to one layout in the end // Creating several layouts, adding widgets & adding them to one layout in the end
QHBoxLayout* topLayout = new QHBoxLayout; QHBoxLayout* topLayout = new QHBoxLayout;
@@ -163,40 +166,42 @@ void Menu::RemoveClipClicked(bool)
void Menu::ExportAll(bool) void Menu::ExportAll(bool)
{ {
if (m_ExportPath->text().isEmpty()) { if (m_ExportPath->text().isEmpty()) {
MGlobal::displayError(MString() + "Please select a folder."); MGlobal::displayError(MString() + "Please select a folder.");
return; return;
} }
//Export meshes //Export meshes
if (!m_Export.Meshes(m_ExportPath->text().toLocal8Bit().constData(), m_ExportSelectedButton->isChecked())) { if (!m_Export.Meshes(m_ExportPath->text().toLocal8Bit().constData(), m_ExportSelectedButton->isChecked(), m_IsCollision->isChecked())) {
MGlobal::displayError(MString() + "Could not export mesh"); MGlobal::displayError(MString() + "Could not export mesh");
return; return;
} }
if (m_ExportMaterialButton->isChecked()) { if (!m_IsCollision->isChecked()){
if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())) { if (m_ExportMaterialButton->isChecked()) {
MGlobal::displayError(MString() + "Could not export materials"); if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())) {
return; MGlobal::displayError(MString() + "Could not export materials");
} return;
} }
}
std::vector<Export::AnimationInfo> animations; std::vector<Export::AnimationInfo> animations;
for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) { for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) {
Export::AnimationInfo thisClip; Export::AnimationInfo thisClip;
thisClip.Name = std::string(m_AnimationClipName[i]->text().toLocal8Bit().constData()); thisClip.Name = std::string(m_AnimationClipName[i]->text().toLocal8Bit().constData());
thisClip.Start = m_StartFrameLines[i]->text().toInt(); thisClip.Start = m_StartFrameLines[i]->text().toInt();
thisClip.End = m_EndFrameLines[i]->text().toInt(); thisClip.End = m_EndFrameLines[i]->text().toInt();
animations.push_back(thisClip); animations.push_back(thisClip);
} }
if (m_ExportAnimationsButton->isChecked()) { if (m_ExportAnimationsButton->isChecked()) {
//Export Animations //Export Animations
if (!m_Export.Animations(m_ExportPath->text().toLocal8Bit().constData(), animations)) { if (!m_Export.Animations(m_ExportPath->text().toLocal8Bit().constData(), animations)) {
MGlobal::displayError(MString() + "Could not export animations"); MGlobal::displayError(MString() + "Could not export animations");
return; return;
} }
} }
}
} }
void Menu::CancelClicked(bool) void Menu::CancelClicked(bool)
+1
View File
@@ -66,6 +66,7 @@ private:
QCheckBox* m_ExportSelectedButton = nullptr; QCheckBox* m_ExportSelectedButton = nullptr;
QCheckBox* m_ExportAnimationsButton = nullptr; QCheckBox* m_ExportAnimationsButton = nullptr;
QCheckBox* m_ExportMaterialButton = nullptr; QCheckBox* m_ExportMaterialButton = nullptr;
QCheckBox* m_IsCollision = nullptr;
QLineEdit* m_ExportPath = nullptr; QLineEdit* m_ExportPath = nullptr;
QFileDialog* m_FileDialog = nullptr; QFileDialog* m_FileDialog = nullptr;
+62 -58
View File
@@ -94,33 +94,37 @@ MeshClass::MeshClass()
// return weightMap; // return weightMap;
//} //}
Mesh MeshClass::GetMeshData(MObjectArray object) Mesh MeshClass::GetMeshData(MObjectArray object, bool collision)
{ {
MS status; MS status;
Mesh newMesh; Mesh newMesh;
newMesh.isCollison = collision;
vector<VertexLayout>& vertexList = newMesh.Vertices; vector<VertexLayout>& vertexList = newMesh.Vertices;
map<string, vector<int>>& indexLists = newMesh.Indices; map<string, vector<int>>& indexLists = newMesh.Indices;
for (int ObjectID = 0; ObjectID < object.length(); ObjectID++) { for (int ObjectID = 0; ObjectID < object.length(); ObjectID++) {
if (!object[ObjectID].hasFn(MFn::kMesh)) if (!object[ObjectID].hasFn(MFn::kMesh))
continue; continue;
MObject node = object[ObjectID]; MObject node = object[ObjectID];
MFnDependencyNode thisNode(node); MFnDependencyNode thisNode(node);
MPlugArray connections; MPlugArray connections;
thisNode.findPlug("inMesh").connectedTo(connections, true, true); thisNode.findPlug("inMesh").connectedTo(connections, true, true);
MPlug weightList, weights; MPlug weightList, weights;
MObject weightListObject; MObject weightListObject;
for (unsigned int i = 0; i < connections.length(); i++) {
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
MFnSkinCluster skinCluster(connections[i].node());
weightList = skinCluster.findPlug("weightList", &status);
weightListObject = weightList.attribute();
weights = skinCluster.findPlug("weights");
newMesh.hasSkin = true;
break;
}
}
if (!collision) {
for (unsigned int i = 0; i < connections.length(); i++) {
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
MFnSkinCluster skinCluster(connections[i].node());
weightList = skinCluster.findPlug("weightList", &status);
weightListObject = weightList.attribute();
weights = skinCluster.findPlug("weights");
newMesh.hasSkin = true;
break;
}
}
}
// In here, we retrieve triangulated polygons from the mesh // In here, we retrieve triangulated polygons from the mesh
MFnMesh mesh(object[ObjectID]); MFnMesh mesh(object[ObjectID]);
@@ -257,62 +261,62 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
thisVertex.Pos[0] = pos.x; thisVertex.Pos[0] = pos.x;
thisVertex.Pos[1] = pos.y; thisVertex.Pos[1] = pos.y;
thisVertex.Pos[2] = pos.z; thisVertex.Pos[2] = pos.z;
thisVertex.isCollision = collision;
status = faceVert.getNormal(normal, MSpace::kObject); if (!collision) {
if (status != MS::kSuccess) { status = faceVert.getNormal(normal, MSpace::kObject);
MGlobal::displayError(MString() + "faceVert.getNormal() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName()); if (status != MS::kSuccess) {
break; MGlobal::displayError(MString() + "faceVert.getNormal() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName());
} break;
}
thisVertex.Normal[0] = normal[0]; thisVertex.Normal[0] = normal[0];
thisVertex.Normal[1] = normal[1]; thisVertex.Normal[1] = normal[1];
thisVertex.Normal[2] = normal[2]; thisVertex.Normal[2] = normal[2];
MFloatVector Tangent = Tangents[faceVert.tangentId()]; MFloatVector Tangent = Tangents[faceVert.tangentId()];
//MVector tmp = faceVert.getTangent(MSpace::kObject, NULL); //MVector tmp = faceVert.getTangent(MSpace::kObject, NULL);
//tmp.get(biTangent); //tmp.get(biTangent);
thisVertex.Tangent[0] = Tangent[0]; thisVertex.Tangent[0] = Tangent[0];
thisVertex.Tangent[1] = Tangent[1]; thisVertex.Tangent[1] = Tangent[1];
thisVertex.Tangent[2] = Tangent[2]; thisVertex.Tangent[2] = Tangent[2];
MFloatVector biNormal = biNormals[faceVert.tangentId()]; MFloatVector biNormal = biNormals[faceVert.tangentId()];
//faceVert.getBinormal().get(biNormal); //faceVert.getBinormal().get(biNormal);
thisVertex.BiNormal[0] = biNormal[0]; thisVertex.BiNormal[0] = biNormal[0];
thisVertex.BiNormal[1] = biNormal[1]; thisVertex.BiNormal[1] = biNormal[1];
thisVertex.BiNormal[2] = biNormal[2]; thisVertex.BiNormal[2] = biNormal[2];
status = faceVert.getUV(UV); status = faceVert.getUV(UV);
if (status != MS::kSuccess) { if (status != MS::kSuccess) {
MGlobal::displayError(MString() + " faceVert.getUV() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName()); MGlobal::displayError(MString() + " faceVert.getUV() ERROR: " + status.errorString() + "for local vertex " + i + " in " + faceID + " in mesh " + thisMeshPath.fullPathName());
break; break;
} }
thisVertex.Uv[0] = UV[0]; thisVertex.Uv[0] = UV[0];
thisVertex.Uv[1] = UV[1]; thisVertex.Uv[1] = UV[1];
if (newMesh.hasSkin) { if (newMesh.hasSkin) {
thisVertex.useWeights = true; thisVertex.useWeights = true;
float totalWeight = 0.0f; float totalWeight = 0.0f;
unsigned int totalBones = 0; unsigned int totalBones = 0;
MIntArray jointIDs /* ??? */; MIntArray jointIDs /* ??? */;
weights.selectAncestorLogicalIndex(vertexIndex, weightListObject); weights.selectAncestorLogicalIndex(vertexIndex, weightListObject);
weights.getExistingArrayAttributeIndices(jointIDs); weights.getExistingArrayAttributeIndices(jointIDs);
for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) { for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) {
if (weights[i].asFloat() > 0.001f) { if (weights[i].asFloat() > 0.001f) {
thisVertex.BoneIndices[totalBones] = jointIDs[i]; thisVertex.BoneIndices[totalBones] = jointIDs[i];
thisVertex.BoneWeights[totalBones] = weights[i].asFloat(); thisVertex.BoneWeights[totalBones] = weights[i].asFloat();
totalWeight = totalWeight + weights[i].asFloat(); totalWeight = totalWeight + weights[i].asFloat();
totalBones++; totalBones++;
} }
} }
for (unsigned int i = 0; i < 4; i++) { for (unsigned int i = 0; i < 4; i++) {
//thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight; //thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight;
} }
} else { }
thisVertex.useWeights = false;
} }
//float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; //float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3];
//if (totalWeight > 0.0001f) { //if (totalWeight > 0.0001f) {
// thisVertex.BoneWeights[0] /= totalWeight; // thisVertex.BoneWeights[0] /= totalWeight;
+32 -23
View File
@@ -11,7 +11,8 @@
class VertexLayout : public OutputData class VertexLayout : public OutputData
{ {
public: public:
bool useWeights = true; bool isCollision = false;
bool useWeights = false;
float Pos[3]{ 0 }; float Pos[3]{ 0 };
float Normal[3]{ 0 }; float Normal[3]{ 0 };
float Tangent[3]{ 0 }; float Tangent[3]{ 0 };
@@ -23,28 +24,31 @@ public:
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
{ {
out.write((char*)&Pos, sizeof(float) * 3); out.write((char*)&Pos, sizeof(float) * 3);
out.write((char*)&Normal, sizeof(float) * 3); if (!isCollision) {
out.write((char*)&Tangent, sizeof(float) * 3); out.write((char*)&Normal, sizeof(float) * 3);
out.write((char*)&BiNormal, sizeof(float) * 3); out.write((char*)&Tangent, sizeof(float) * 3);
out.write((char*)&Uv, sizeof(float) * 2); out.write((char*)&BiNormal, sizeof(float) * 3);
if (useWeights) { out.write((char*)&Uv, sizeof(float) * 2);
out.write((char*)&BoneIndices, sizeof(float) * 4); if (useWeights) {
out.write((char*)&BoneWeights, sizeof(float) * 4); out.write((char*)&BoneIndices, sizeof(float) * 4);
out.write((char*)&BoneWeights, sizeof(float) * 4);
}
} }
} }
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
{ {
out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl; out << Pos[0] << " " << Pos[1] << " " << Pos[2] << endl;
out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl; if (!isCollision) {
out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl; out << Normal[0] << " " << Normal[1] << " " << Normal[2] << endl;
out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl; out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl;
out << Uv[0] << " " << Uv[1] << endl; out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl;
if (useWeights) { out << Uv[0] << " " << Uv[1] << endl;
out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl; if (useWeights) {
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl; out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl;
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl;
}
} }
} }
bool operator==(const VertexLayout& right) bool operator==(const VertexLayout& right)
{ {
@@ -62,6 +66,7 @@ public:
class Mesh : public OutputData { class Mesh : public OutputData {
public: public:
bool isCollison = false;
bool hasSkin = false; bool hasSkin = false;
unsigned int NumVertices; unsigned int NumVertices;
unsigned int NumIndices; unsigned int NumIndices;
@@ -70,7 +75,9 @@ public:
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
{ {
out.write((char*)&hasSkin, sizeof(bool)); if (!isCollison) {
out.write((char*)&hasSkin, sizeof(bool));
}
out.write((char*)&NumVertices, sizeof(int)); out.write((char*)&NumVertices, sizeof(int));
out.write((char*)&NumIndices, sizeof(int)); out.write((char*)&NumIndices, sizeof(int));
for (auto aVertex : Vertices) { for (auto aVertex : Vertices) {
@@ -86,11 +93,13 @@ public:
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
{ {
out << "New Mesh _ not in binary" << endl; out << "New Mesh _ not in binary" << endl;
out << "hasSkin: "; if (!isCollison) {
if(hasSkin) out << "hasSkin: ";
out << "true" << endl; if (hasSkin)
else out << "true" << endl;
out << "false" << endl; else
out << "false" << endl;
}
out << "Number of vertices: " << NumVertices << endl; out << "Number of vertices: " << NumVertices << endl;
out << "number of indices: " << NumIndices << endl; out << "number of indices: " << NumIndices << endl;
int vertexNumber = 0; int vertexNumber = 0;
@@ -115,7 +124,7 @@ class MeshClass
{ {
public: public:
MeshClass(); MeshClass();
Mesh GetMeshData(MObjectArray Object); Mesh GetMeshData(MObjectArray Object, bool collision = false);
~MeshClass(); ~MeshClass();
private: private:
struct WeightInfo { struct WeightInfo {