Animations PROBABLY works fine if all joints got keyframes.
This commit is contained in:
@@ -10,8 +10,8 @@
|
|||||||
|
|
||||||
#include "../Core/Ray.h"
|
#include "../Core/Ray.h"
|
||||||
#include "../Core/AABB.h"
|
#include "../Core/AABB.h"
|
||||||
//#include "Engine/Rendering/RawModelAssimp.h"
|
#include "Rendering/RawModelCustom.h"
|
||||||
#include "Engine/Rendering/RawModelCustom.h"
|
//#include "Rendering/RawModelAssimp.h"
|
||||||
#include "../Core/Transform.h"
|
#include "../Core/Transform.h"
|
||||||
#include "../Core/Entity.h"
|
#include "../Core/Entity.h"
|
||||||
#include "../Core/EntityWrapper.h"
|
#include "../Core/EntityWrapper.h"
|
||||||
|
|||||||
@@ -61,6 +61,6 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
glm::vec3 m_Position = glm::vec3(0, 0, 0);
|
glm::vec3 m_Position = glm::vec3(0, 0, 0);
|
||||||
glm::vec3 m_Velocity = glm::vec3(0, 0, 0);
|
glm::vec3 m_Velocity = glm::vec3(0, 0, 0);
|
||||||
float m_BaseSpeed = 2.0f;
|
float m_BaseSpeed = 50.0f;//2.0f;
|
||||||
float m_Speed = m_BaseSpeed;
|
float m_Speed = m_BaseSpeed;
|
||||||
};
|
};
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#ifndef Model_h__
|
#ifndef Model_h__
|
||||||
#define Model_h__
|
#define Model_h__
|
||||||
|
|
||||||
#include "RawModelCustom.h"
|
#include "Rendering/RawModelCustom.h"
|
||||||
|
//#include "Rendering/RawModelAssimp.h"
|
||||||
#include "../OpenGL.h"
|
#include "../OpenGL.h"
|
||||||
|
|
||||||
class Model : public ThreadUnsafeResource
|
class Model : public ThreadUnsafeResource
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#ifndef RawModelAssimp_h__
|
#ifndef RawModelAssimp_h__
|
||||||
#define RawModelAssimp_h__
|
#define RawModelAssimp_h__
|
||||||
|
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -18,15 +20,17 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Skeleton.h"
|
#include "Skeleton.h"
|
||||||
|
|
||||||
class RawModel : public Resource
|
#define RawModel RawModelAssimp
|
||||||
|
|
||||||
|
class RawModelAssimp : public Resource
|
||||||
{
|
{
|
||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RawModel(std::string fileName);
|
RawModelAssimp(std::string fileName);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~RawModel();
|
~RawModelAssimp();
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
@@ -72,3 +76,4 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,10 @@
|
|||||||
#ifndef RawModelCustom_h__
|
#ifndef RawModelCustom_h__
|
||||||
#define RawModelCustom_h__
|
#define RawModelCustom_h__
|
||||||
|
|
||||||
|
#ifndef USING_ASSIMP_AS_IMPORTER
|
||||||
|
|
||||||
|
#define RawModel RawModelCustom
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
@@ -17,15 +21,17 @@
|
|||||||
|
|
||||||
#include "boost\endian\buffers.hpp"
|
#include "boost\endian\buffers.hpp"
|
||||||
|
|
||||||
class RawModel : public Resource
|
|
||||||
|
|
||||||
|
class RawModelCustom : public Resource
|
||||||
{
|
{
|
||||||
friend class ResourceManager;
|
friend class ResourceManager;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RawModel(std::string fileName);
|
RawModelCustom(std::string fileName);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
~RawModel();
|
~RawModelCustom();
|
||||||
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
@@ -85,4 +91,9 @@ private:
|
|||||||
//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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
#include "RawModelAssimp.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
#include "../GLM.h"
|
#include "../GLM.h"
|
||||||
|
#include <glm/gtx/matrix_decompose.hpp>
|
||||||
|
|
||||||
//struct Bone
|
//struct Bone
|
||||||
//{
|
//{
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
<Entity>
|
<Entity>
|
||||||
<Components>
|
<Components>
|
||||||
<c:Model>
|
<c:Model>
|
||||||
<Resource>models/Baljj.mesh</Resource>
|
<Resource>models/animTest.mesh</Resource>
|
||||||
</c:Model>
|
</c:Model>
|
||||||
<c:Transform/>
|
<c:Transform/>
|
||||||
</Components>
|
</Components>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
uniform mat4 M;
|
uniform mat4 M;
|
||||||
uniform mat4 V;
|
uniform mat4 V;
|
||||||
uniform mat4 P;
|
uniform mat4 P;
|
||||||
|
uniform mat4 Bones[100];
|
||||||
|
|
||||||
layout(location = 0) in vec3 Position;
|
layout(location = 0) in vec3 Position;
|
||||||
layout(location = 1) in vec3 Normal;
|
layout(location = 1) in vec3 Normal;
|
||||||
@@ -20,9 +21,17 @@ out VertexData{
|
|||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = P*V*M * vec4(Position, 1.0);
|
|
||||||
|
|
||||||
Output.Position = Position;
|
|
||||||
|
mat4 boneTransform = mat4(1);
|
||||||
|
boneTransform = BoneWeights[0] * Bones[int(BoneIndices[0])]
|
||||||
|
+ BoneWeights[1] * Bones[int(BoneIndices[1])]
|
||||||
|
+ BoneWeights[2] * Bones[int(BoneIndices[2])]
|
||||||
|
+ BoneWeights[3] * Bones[int(BoneIndices[3])];
|
||||||
|
|
||||||
|
gl_Position = P*V*M*boneTransform * vec4(Position, 1.0);
|
||||||
|
|
||||||
|
Output.Position = (boneTransform * vec4(Position, 1.0)).xyz;
|
||||||
Output.TextureCoordinate = TextureCoords;
|
Output.TextureCoordinate = TextureCoords;
|
||||||
Output.Normal = vec3(M * vec4(Normal, 0.0));
|
Output.Normal = vec3(M * vec4(Normal, 0.0));
|
||||||
}
|
}
|
||||||
@@ -292,21 +292,33 @@ void EditorSystem::createWidget()
|
|||||||
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
|
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
|
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetPlaneX, "Model");
|
m_World->AttachComponent(m_WidgetPlaneX, "Model");
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneX
|
||||||
|
#else
|
||||||
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneX
|
m_World->GetComponent(m_WidgetPlaneX, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneX
|
||||||
|
#endif
|
||||||
m_WidgetY = m_World->CreateEntity(m_Widget);
|
m_WidgetY = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetY, "Transform");
|
m_World->AttachComponent(m_WidgetY, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetY, "Model");
|
m_World->AttachComponent(m_WidgetY, "Model");
|
||||||
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
|
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
|
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetPlaneY, "Model");
|
m_World->AttachComponent(m_WidgetPlaneY, "Model");
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneY
|
||||||
|
#else
|
||||||
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneY
|
m_World->GetComponent(m_WidgetPlaneY, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneY
|
||||||
|
#endif
|
||||||
m_WidgetZ = m_World->CreateEntity(m_Widget);
|
m_WidgetZ = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetZ, "Transform");
|
m_World->AttachComponent(m_WidgetZ, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetZ, "Model");
|
m_World->AttachComponent(m_WidgetZ, "Model");
|
||||||
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
|
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
|
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
|
m_World->AttachComponent(m_WidgetPlaneZ, "Model");
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/WidgetPlaneZ.obj"; // 360NoScope widgetPlaneZ
|
||||||
|
#else
|
||||||
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneZ
|
m_World->GetComponent(m_WidgetPlaneZ, "Model")["Resource"] = "Models/coolCube.mesh"; // 360NoScope widgetPlaneZ
|
||||||
|
#endif
|
||||||
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
|
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
|
||||||
m_World->AttachComponent(m_WidgetOrigin, "Transform");
|
m_World->AttachComponent(m_WidgetOrigin, "Transform");
|
||||||
m_World->AttachComponent(m_WidgetOrigin, "Model");
|
m_World->AttachComponent(m_WidgetOrigin, "Model");
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ void DrawFinalPass::InitializeShaderPrograms()
|
|||||||
m_ForwardPlusProgram->Link();
|
m_ForwardPlusProgram->Link();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static double tempFrameCounter = 6.348;
|
||||||
|
|
||||||
void DrawFinalPass::Draw(RenderScene& scene)
|
void DrawFinalPass::Draw(RenderScene& scene)
|
||||||
{
|
{
|
||||||
GLERROR("DrawFinalPass::Draw: Pre");
|
GLERROR("DrawFinalPass::Draw: Pre");
|
||||||
@@ -38,6 +40,7 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
|||||||
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "P"), 1, GL_FALSE, glm::value_ptr(m_Renderer->Camera()->ProjectionMatrix()));
|
||||||
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
|
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
|
||||||
|
|
||||||
|
//tempFrameCounter += 0.01;
|
||||||
//TODO: Render: Add code for more jobs than modeljobs.
|
//TODO: Render: Add code for more jobs than modeljobs.
|
||||||
for (auto &job : scene.ForwardJobs) {
|
for (auto &job : scene.ForwardJobs) {
|
||||||
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
auto modelJob = std::dynamic_pointer_cast<ModelJob>(job);
|
||||||
@@ -54,6 +57,21 @@ void DrawFinalPass::Draw(RenderScene& scene)
|
|||||||
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
glBindTexture(GL_TEXTURE_2D, m_WhiteTexture->m_Texture);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (modelJob->Model->m_RawModel->m_Skeleton != nullptr) {
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("combinedAnim_0");
|
||||||
|
#else
|
||||||
|
auto animation = modelJob->Model->m_RawModel->m_Skeleton->GetAnimation("running");
|
||||||
|
#endif
|
||||||
|
if (animation != nullptr) {
|
||||||
|
std::vector<glm::mat4> frameBones = modelJob->Model->m_RawModel->m_Skeleton->GetFrameBones(
|
||||||
|
*animation,
|
||||||
|
tempFrameCounter
|
||||||
|
);
|
||||||
|
glUniformMatrix4fv(glGetUniformLocation(shaderHandle, "Bones"), frameBones.size(), GL_FALSE, glm::value_ptr(frameBones[0]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// -3 - 9
|
||||||
glBindVertexArray(modelJob->Model->VAO);
|
glBindVertexArray(modelJob->Model->VAO);
|
||||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, modelJob->Model->ElementBuffer);
|
||||||
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
|
glDrawElements(GL_TRIANGLES, modelJob->EndIndex - modelJob->StartIndex + 1, GL_UNSIGNED_INT, (void*)(modelJob->StartIndex * sizeof(unsigned int)));
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ Model::Model(std::string fileName)
|
|||||||
if (!group.SpecularMapPath.empty()) {
|
if (!group.SpecularMapPath.empty()) {
|
||||||
group.SpecularMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.SpecularMapPath));
|
group.SpecularMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.SpecularMapPath));
|
||||||
}
|
}
|
||||||
|
if (!group.IncandescenceMapPath.empty()) {
|
||||||
|
group.IncandescenceMap = std::shared_ptr<Texture>(ResourceManager::Load<Texture>(group.IncandescenceMapPath));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate GL buffers
|
// Generate GL buffers
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "Rendering/RawModelAssimp.h"
|
#include "Rendering/RawModelAssimp.h"
|
||||||
|
|
||||||
RawModel::RawModel(std::string fileName)
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
|
||||||
|
RawModelAssimp::RawModelAssimp(std::string fileName)
|
||||||
{
|
{
|
||||||
Assimp::Importer importer;
|
Assimp::Importer importer;
|
||||||
const aiScene* scene = importer.ReadFile(fileName, aiProcess_CalcTangentSpace | aiProcess_Triangulate);
|
const aiScene* scene = importer.ReadFile(fileName, aiProcess_CalcTangentSpace | aiProcess_Triangulate);
|
||||||
@@ -271,16 +273,17 @@ RawModel::RawModel(std::string fileName)
|
|||||||
|
|
||||||
m_Skeleton->Animations[animationName] = skelAnim;
|
m_Skeleton->Animations[animationName] = skelAnim;
|
||||||
}
|
}
|
||||||
|
int k = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RawModel::~RawModel()
|
RawModelAssimp::~RawModelAssimp()
|
||||||
{
|
{
|
||||||
if (m_Skeleton) {
|
if (m_Skeleton) {
|
||||||
delete m_Skeleton;
|
delete m_Skeleton;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID)
|
void RawModelAssimp::CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &boneInfo, std::map<std::string, int> &boneNameMapping, aiNode* node, int parentID)
|
||||||
{
|
{
|
||||||
std::string nodeName = node->mName.C_Str();
|
std::string nodeName = node->mName.C_Str();
|
||||||
|
|
||||||
@@ -300,3 +303,5 @@ void RawModel::CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &b
|
|||||||
CreateSkeleton(boneInfo, boneNameMapping, child, parentID);
|
CreateSkeleton(boneInfo, boneNameMapping, child, parentID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#include "Rendering/RawModelCustom.h"
|
#include "Rendering/RawModelCustom.h"
|
||||||
|
|
||||||
RawModel::RawModel(std::string fileName)
|
#ifndef USING_ASSIMP_AS_IMPORTER
|
||||||
|
|
||||||
|
RawModelCustom::RawModelCustom(std::string fileName)
|
||||||
{
|
{
|
||||||
fileName = fileName.erase(fileName.find_last_of("."), fileName.find_last_of(".") - fileName.size());
|
fileName = fileName.erase(fileName.find_last_of("."), fileName.find_last_of(".") - fileName.size());
|
||||||
ReadMeshFile(fileName);
|
ReadMeshFile(fileName);
|
||||||
@@ -9,7 +11,7 @@ RawModel::RawModel(std::string fileName)
|
|||||||
int k = 0;
|
int k = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadMeshFile(std::string filePath)
|
void RawModelCustom::ReadMeshFile(std::string filePath)
|
||||||
{
|
{
|
||||||
char* fileData;
|
char* fileData;
|
||||||
filePath += ".mesh";
|
filePath += ".mesh";
|
||||||
@@ -33,7 +35,7 @@ void RawModel::ReadMeshFile(std::string filePath)
|
|||||||
delete fileData;
|
delete fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
m_Vertices.resize(*(unsigned int*)(fileData + offset));
|
m_Vertices.resize(*(unsigned int*)(fileData + offset));
|
||||||
@@ -44,13 +46,13 @@ void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadMesh(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
ReadVertices(offset, fileData, fileByteSize);
|
ReadVertices(offset, fileData, fileByteSize);
|
||||||
ReadIndices(offset, fileData, fileByteSize);
|
ReadIndices(offset, fileData, fileByteSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadVertices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
|
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
|
||||||
@@ -63,7 +65,7 @@ void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int&
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadIndices(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) {
|
if (offset + m_Indices.size() * sizeof(unsigned int) > fileByteSize) {
|
||||||
@@ -77,7 +79,7 @@ void RawModel::ReadIndices(unsigned int& offset, char* fileData, unsigned int& f
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadMaterialFile(std::string filePath)
|
void RawModelCustom::ReadMaterialFile(std::string filePath)
|
||||||
{
|
{
|
||||||
char* fileData;
|
char* fileData;
|
||||||
filePath += ".mtrl";
|
filePath += ".mtrl";
|
||||||
@@ -100,7 +102,7 @@ void RawModel::ReadMaterialFile(std::string filePath)
|
|||||||
delete fileData;
|
delete fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadMaterials(unsigned int& offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
unsigned int* numMaterials = (unsigned int*)(fileData);
|
unsigned int* numMaterials = (unsigned int*)(fileData);
|
||||||
@@ -114,7 +116,7 @@ void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int&
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
MaterialGroup newMaterial;
|
MaterialGroup newMaterial;
|
||||||
|
|
||||||
@@ -189,7 +191,7 @@ void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned
|
|||||||
MaterialGroups.push_back(newMaterial);
|
MaterialGroups.push_back(newMaterial);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadAnimationFile(std::string filePath)
|
void RawModelCustom::ReadAnimationFile(std::string filePath)
|
||||||
{
|
{
|
||||||
char* fileData;
|
char* fileData;
|
||||||
filePath += ".anim";
|
filePath += ".anim";
|
||||||
@@ -214,7 +216,7 @@ void RawModel::ReadAnimationFile(std::string filePath)
|
|||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
unsigned int numBindPoses = *(unsigned int*)(fileData);
|
unsigned int numBindPoses = *(unsigned int*)(fileData);
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
unsigned int numAnimations = *(unsigned int*)(fileData);
|
unsigned int numAnimations = *(unsigned int*)(fileData + offset);
|
||||||
offset += sizeof(unsigned int);
|
offset += sizeof(unsigned int);
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
@@ -225,7 +227,7 @@ void RawModel::ReadAnimationFile(std::string filePath)
|
|||||||
delete fileData;
|
delete fileData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
unsigned int* numBones = (unsigned int*)(fileData + offset);
|
unsigned int* numBones = (unsigned int*)(fileData + offset);
|
||||||
@@ -238,7 +240,7 @@ void RawModel::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsi
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
void RawModelCustom::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned int& fileByteSize)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
if (offset + sizeof(unsigned int) > fileByteSize) {
|
if (offset + sizeof(unsigned int) > fileByteSize) {
|
||||||
@@ -280,14 +282,14 @@ void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips)
|
void RawModelCustom::ReadAnimationClips(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int numberOfClips)
|
||||||
{
|
{
|
||||||
for (unsigned int i = 0; i < numberOfClips; i++) {
|
for (unsigned int i = 0; i < numberOfClips; i++) {
|
||||||
ReadAnimationClipSingle(offset, fileData, fileByteSize, i);
|
ReadAnimationClipSingle(offset, fileData, fileByteSize, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex)
|
void RawModelCustom::ReadAnimationClipSingle(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int clipIndex)
|
||||||
{
|
{
|
||||||
#ifdef BOOST_LITTLE_ENDIAN
|
#ifdef BOOST_LITTLE_ENDIAN
|
||||||
Skeleton::Animation newAnimation;
|
Skeleton::Animation newAnimation;
|
||||||
@@ -332,7 +334,7 @@ void RawModel::ReadAnimationClipSingle(unsigned int &offset, char* fileData, uns
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void RawModel::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation)
|
void RawModelCustom::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsigned int& fileByteSize, unsigned int nrOfJoints, Skeleton::Animation& animation)
|
||||||
{
|
{
|
||||||
Skeleton::Animation::Keyframe newKeyFrame;
|
Skeleton::Animation::Keyframe newKeyFrame;
|
||||||
|
|
||||||
@@ -356,12 +358,16 @@ void RawModel::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsig
|
|||||||
for (unsigned int i = 0; i < nrOfJoints; i++) {
|
for (unsigned int i = 0; i < nrOfJoints; i++) {
|
||||||
memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
|
memcpy(&newBone, (fileData + offset), sizeof(Skeleton::Animation::Keyframe::BoneProperty));
|
||||||
offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty);
|
offset += sizeof(Skeleton::Animation::Keyframe::BoneProperty);
|
||||||
newKeyFrame.BoneProperties[i] = newBone;
|
newKeyFrame.BoneProperties[newBone.ID] = newBone;
|
||||||
}
|
}
|
||||||
animation.Keyframes.push_back(newKeyFrame);
|
animation.Keyframes.push_back(newKeyFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
RawModel::~RawModel()
|
RawModelCustom::~RawModelCustom()
|
||||||
{
|
{
|
||||||
|
if (m_Skeleton != nullptr) {
|
||||||
|
delete m_Skeleton;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -96,10 +96,18 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
|
|||||||
model = ResourceManager::Load<::Model, true>(resource);
|
model = ResourceManager::Load<::Model, true>(resource);
|
||||||
} catch (const Resource::StillLoadingException&) {
|
} catch (const Resource::StillLoadingException&) {
|
||||||
//continue;
|
//continue;
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope StillLoading mesh
|
||||||
|
#else
|
||||||
model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope StillLoading mesh
|
model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope StillLoading mesh
|
||||||
|
#endif
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
try {
|
try {
|
||||||
|
#ifdef USING_ASSIMP_AS_IMPORTER
|
||||||
|
model = ResourceManager::Load<::Model>("Models/WidgetPlaneZ.obj"); // 360NoScope Error mesh
|
||||||
|
#else
|
||||||
model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope Error mesh
|
model = ResourceManager::Load<::Model>("Models/coolCube.mesh"); // 360NoScope Error mesh
|
||||||
|
#endif
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ std::vector<glm::mat4> Skeleton::GetFrameBones(const Animation& animation, doubl
|
|||||||
|
|
||||||
void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe ¤tFrame, const Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, const Bone* bone, glm::mat4 parentMatrix)
|
void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe ¤tFrame, const Animation::Keyframe &nextFrame, float progress, std::map<int, glm::mat4> &boneMatrices, const Bone* bone, glm::mat4 parentMatrix)
|
||||||
{
|
{
|
||||||
glm::mat4 boneMatrix;
|
glm::mat4 boneMatrix;
|
||||||
|
|
||||||
if (currentFrame.BoneProperties.find(bone->ID) != currentFrame.BoneProperties.end() || nextFrame.BoneProperties.find(bone->ID) != nextFrame.BoneProperties.end()) {
|
if (currentFrame.BoneProperties.find(bone->ID) != currentFrame.BoneProperties.end() || nextFrame.BoneProperties.find(bone->ID) != nextFrame.BoneProperties.end()) {
|
||||||
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties.at(bone->ID);
|
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties.at(bone->ID);
|
||||||
@@ -84,10 +84,14 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf
|
|||||||
positionInterp.z = 0;
|
positionInterp.z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
boneMatrix = parentMatrix * (glm::translate(positionInterp) * glm::toMat4(rotationInterp) * glm::scale(scaleInterp));
|
boneMatrix = parentMatrix * (glm::translate(positionInterp) * glm::toMat4(rotationInterp) * glm::scale(scaleInterp));
|
||||||
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
|
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
|
||||||
|
int k = 0;
|
||||||
} else {
|
} else {
|
||||||
boneMatrix = parentMatrix * bone->Parent->OffsetMatrix; // * glm::inverse(bone->OffsetMatrix);
|
if (bone->Parent) {
|
||||||
|
boneMatrix = parentMatrix * bone->Parent->OffsetMatrix * glm::translate(glm::vec3(1.718, 0, 0)); // * glm::inverse(bone->OffsetMatrix);
|
||||||
|
}
|
||||||
boneMatrices[bone->ID] = boneMatrix; // * bone->OffsetMatrix;
|
boneMatrices[bone->ID] = boneMatrix; // * bone->OffsetMatrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +99,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf
|
|||||||
std::string name = child->Name;
|
std::string name = child->Name;
|
||||||
AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, progress, boneMatrices, child, boneMatrix);
|
AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, progress, boneMatrices, child, boneMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Skeleton::GetBoneID(std::string name)
|
int Skeleton::GetBoneID(std::string name)
|
||||||
|
|||||||
@@ -27,7 +27,9 @@ using boost::unit_test_framework::test_case;
|
|||||||
void RayTest(std::string fileName) {
|
void RayTest(std::string fileName) {
|
||||||
//simple box test
|
//simple box test
|
||||||
Ray ray(glm::vec3(-50, 0, 0), glm::vec3(1, 0, 0));
|
Ray ray(glm::vec3(-50, 0, 0), glm::vec3(1, 0, 0));
|
||||||
//using a rawmodel here, else we have to init the renderingsystem
|
//using a
|
||||||
|
|
||||||
|
here, else we have to init the renderingsystem
|
||||||
ResourceManager::RegisterType<RawModel>("RawModel");
|
ResourceManager::RegisterType<RawModel>("RawModel");
|
||||||
auto unitBox = ResourceManager::Load<RawModel>(fileName);
|
auto unitBox = ResourceManager::Load<RawModel>(fileName);
|
||||||
BOOST_REQUIRE(unitBox != nullptr);
|
BOOST_REQUIRE(unitBox != nullptr);
|
||||||
|
|||||||
@@ -7,26 +7,56 @@ Export::Export()
|
|||||||
|
|
||||||
bool Export::Meshes(std::string pathName, bool selectedOnly)
|
bool Export::Meshes(std::string pathName, bool selectedOnly)
|
||||||
{
|
{
|
||||||
|
MStatus status;
|
||||||
if (pathName.empty()) {
|
if (pathName.empty()) {
|
||||||
MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file");
|
MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
MSelectionList selectedOnStart;
|
MSelectionList selectedOnStart;
|
||||||
MGlobal::getActiveSelectionList(selectedOnStart);
|
MGlobal::getActiveSelectionList(selectedOnStart);
|
||||||
|
if (selectedOnStart.length() > 0) {
|
||||||
|
for (int i = 0; i < selectedOnStart.length(); i++) {
|
||||||
|
MObject item;
|
||||||
|
selectedOnStart.getDependNode(i, item);
|
||||||
|
MGlobal::unselect(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MGlobal::displayInfo(MString() + "Disabel IKSolvers");
|
||||||
|
status = MGlobal::executeCommand("doEnableNodeItems false all;");
|
||||||
|
if (status != MS::kSuccess) {
|
||||||
|
MGlobal::displayError(MString() + "EnableNodeItems false all failed: " + status.errorString());
|
||||||
|
}
|
||||||
|
MGlobal::displayInfo(MString() + "Has disabel IKSolvers");
|
||||||
MObjectArray Objects;
|
MObjectArray Objects;
|
||||||
if (selectedOnly) {
|
if (selectedOnly) {
|
||||||
// Retrieving the objects we currently have selected
|
// Retrieving the objects we currently have selected
|
||||||
MSelectionList selected;
|
|
||||||
MGlobal::getActiveSelectionList(selected);
|
|
||||||
|
|
||||||
// Loop through or list of selection(s)
|
// Loop through or list of selection(s)
|
||||||
for (unsigned int i = 0; i < selected.length(); i++) {
|
for (unsigned int i = 0; i < selectedOnStart.length(); i++) {
|
||||||
MObject object;
|
MObject object;
|
||||||
selected.getDependNode(i, object);
|
selectedOnStart.getDependNode(i, object);
|
||||||
|
|
||||||
if (object.hasFn(MFn::kMesh)) {
|
if (object.hasFn(MFn::kMesh)) {
|
||||||
MFnDependencyNode thisNode(object);
|
MFnMesh shape(object);
|
||||||
|
|
||||||
|
for (unsigned int k = 0; k < shape.parentCount(); k++) {
|
||||||
|
MFnDependencyNode thisNode(object);
|
||||||
|
MPlugArray connections;
|
||||||
|
thisNode.findPlug("inMesh").connectedTo(connections, true, true);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < connections.length(); i++) {
|
||||||
|
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
|
||||||
|
MGlobal::select(shape.parent(i), MGlobal::kReplaceList);
|
||||||
|
MGlobal::displayInfo(MString() + "Moving " + thisNode.name() + " to bindPose.");
|
||||||
|
status = MGlobal::executeCommand("GoToBindPose;");
|
||||||
|
if (status != MS::kSuccess) {
|
||||||
|
MGlobal::displayError(MString() + "GoToBindPose: " + status.errorString());
|
||||||
|
}
|
||||||
|
MGlobal::displayInfo(MString() + "Has moved " + thisNode.name() + " to bindPose.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Objects.append(object);
|
Objects.append(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -42,7 +72,9 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
|||||||
for (unsigned int i = 0; i < connections.length(); i++) {
|
for (unsigned int i = 0; i < connections.length(); i++) {
|
||||||
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
|
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
|
||||||
MGlobal::select(node);
|
MGlobal::select(node);
|
||||||
MGlobal::executeCommand("gotoBindPose");
|
MGlobal::displayInfo(MString() + "Moving " + thisNode.name() + " to bindPose.");
|
||||||
|
MGlobal::executeCommand("GoToBindPose");
|
||||||
|
MGlobal::displayInfo(MString() + "Has moved " + thisNode.name() + " to bindPose.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +83,19 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
|||||||
}
|
}
|
||||||
GetMeshData(Objects);
|
GetMeshData(Objects);
|
||||||
WriteMeshData(pathName);
|
WriteMeshData(pathName);
|
||||||
|
MGlobal::displayInfo(MString() + "Enabling IKSolvers");
|
||||||
|
status = MGlobal::executeCommand("doEnableNodeItems true all;");
|
||||||
|
if (status != MS::kSuccess) {
|
||||||
|
MGlobal::displayError(MString() + "doEnableNodeItems true all: " + status.errorString());
|
||||||
|
}
|
||||||
|
MGlobal::displayInfo(MString() + "Has enabling IKSolvers");
|
||||||
|
if (selectedOnStart.length() > 0) {
|
||||||
|
for (int i = 0; i < selectedOnStart.length(); i++) {
|
||||||
|
MObject item;
|
||||||
|
selectedOnStart.getDependNode(i, item);
|
||||||
|
MGlobal::select(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,9 @@
|
|||||||
#include <maya/MItGeometry.h>
|
#include <maya/MItGeometry.h>
|
||||||
#include <maya/MItMeshVertex.h>
|
#include <maya/MItMeshVertex.h>
|
||||||
#include <maya/MFnWeightGeometryFilter.h>
|
#include <maya/MFnWeightGeometryFilter.h>
|
||||||
|
#include <maya/MItDependencyGraph.h>
|
||||||
|
#include <maya/MQuaternion.h>
|
||||||
|
#include <maya/MFnNumericAttribute.h>
|
||||||
|
|
||||||
|
|
||||||
// Wrappers
|
// Wrappers
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ Menu::Menu(QDialog* dialog)
|
|||||||
|
|
||||||
m_ExportPath = new QLineEdit;
|
m_ExportPath = new QLineEdit;
|
||||||
m_FileDialog = new QFileDialog;
|
m_FileDialog = new QFileDialog;
|
||||||
QString tmpPath("C:/Users/Nickelodion/Desktop/Baljj");
|
QString tmpPath("C:/Users/Nickelodion/Desktop/animTest");
|
||||||
m_ExportPath->setText(tmpPath);
|
m_ExportPath->setText(tmpPath);
|
||||||
QLabel* exportLabel = new QLabel;
|
QLabel* exportLabel = new QLabel;
|
||||||
exportLabel->setText("Export Path:");
|
exportLabel->setText("Export Path:");
|
||||||
@@ -175,6 +175,13 @@ void Menu::ExportAll(bool)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_ExportMaterialButton->isChecked()) {
|
||||||
|
if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())) {
|
||||||
|
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;
|
||||||
@@ -191,13 +198,6 @@ void Menu::ExportAll(bool)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_ExportMaterialButton->isChecked()) {
|
|
||||||
if (!m_Export.Materials(m_ExportPath->text().toLocal8Bit().constData())){
|
|
||||||
MGlobal::displayError(MString() + "Could not export materials");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Menu::CancelClicked(bool)
|
void Menu::CancelClicked(bool)
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
MFnDependencyNode test(comp);
|
MFnDependencyNode test(comp);
|
||||||
|
|
||||||
unsigned int nrOfWeights = 0;
|
unsigned int nrOfWeights = 0;
|
||||||
|
|
||||||
for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) {
|
for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) {
|
||||||
@@ -90,7 +89,7 @@ std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
|
|||||||
|
|
||||||
|
|
||||||
for (unsigned int k = 0; k!=nrOfWeights; k++) {
|
for (unsigned int k = 0; k!=nrOfWeights; k++) {
|
||||||
//MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]);
|
MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]);
|
||||||
}
|
}
|
||||||
geomIter.next();
|
geomIter.next();
|
||||||
}
|
}
|
||||||
@@ -109,6 +108,26 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
|
|||||||
if (!object[ObjectID].hasFn(MFn::kMesh))
|
if (!object[ObjectID].hasFn(MFn::kMesh))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
MObject node = object[ObjectID];
|
||||||
|
MFnDependencyNode thisNode(node);
|
||||||
|
MPlugArray connections;
|
||||||
|
thisNode.findPlug("inMesh").connectedTo(connections, true, true);
|
||||||
|
MGlobal::displayInfo(MString() + "inMesh");
|
||||||
|
bool hasSkin = false;
|
||||||
|
MPlug weightList, weights;
|
||||||
|
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");
|
||||||
|
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]);
|
||||||
MDagPathArray dagPaths;
|
MDagPathArray dagPaths;
|
||||||
@@ -178,7 +197,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
map<int, WeightInfo> vertexWeights = GetWeightData();
|
// map<int, WeightInfo> vertexWeights = GetWeightData();
|
||||||
status = mesh.getTangents(Tangents, MSpace::kObject);
|
status = mesh.getTangents(Tangents, MSpace::kObject);
|
||||||
if (status != MS::kSuccess) {
|
if (status != MS::kSuccess) {
|
||||||
MGlobal::displayError(MString() + "mesh.getTangents ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName());
|
MGlobal::displayError(MString() + "mesh.getTangents ERROR: " + status.errorString() + " for " + thisMeshPath.fullPathName());
|
||||||
@@ -288,27 +307,25 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
|
|||||||
thisVertex.Uv[0] = UV[0];
|
thisVertex.Uv[0] = UV[0];
|
||||||
thisVertex.Uv[1] = UV[1];
|
thisVertex.Uv[1] = UV[1];
|
||||||
|
|
||||||
thisVertex.BoneIndices[0] = vertexWeights[faceVert.vertId()].BoneIndices[0];
|
|
||||||
thisVertex.BoneIndices[1] = vertexWeights[faceVert.vertId()].BoneIndices[1];
|
|
||||||
thisVertex.BoneIndices[2] = vertexWeights[faceVert.vertId()].BoneIndices[2];
|
|
||||||
thisVertex.BoneIndices[3] = vertexWeights[faceVert.vertId()].BoneIndices[3];
|
|
||||||
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[0]) > 0.0001)
|
|
||||||
thisVertex.BoneWeights[0] = vertexWeights[faceVert.vertId()].BoneWeights[0];
|
|
||||||
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[1]) > 0.0001)
|
|
||||||
thisVertex.BoneWeights[1] = vertexWeights[faceVert.vertId()].BoneWeights[1];
|
|
||||||
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[2]) > 0.0001)
|
|
||||||
thisVertex.BoneWeights[2] = vertexWeights[faceVert.vertId()].BoneWeights[2];
|
|
||||||
if (abs(vertexWeights[faceVert.vertId()].BoneWeights[3]) > 0.0001)
|
|
||||||
thisVertex.BoneWeights[3] = vertexWeights[faceVert.vertId()].BoneWeights[3];
|
|
||||||
|
|
||||||
float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3];
|
if (hasSkin) {
|
||||||
if (totalWeight < 1.00f && totalWeight > 0.01f) {
|
MIntArray jointIDs /* ??? */;
|
||||||
thisVertex.BoneWeights[0] /= totalWeight;
|
weights.selectAncestorLogicalIndex(vertexIndex, weightListObject);
|
||||||
thisVertex.BoneWeights[1] /= totalWeight;
|
weights.getExistingArrayAttributeIndices(jointIDs);
|
||||||
thisVertex.BoneWeights[2] /= totalWeight;
|
for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) {
|
||||||
thisVertex.BoneWeights[3] /= totalWeight;
|
thisVertex.BoneIndices[i] = jointIDs[i];
|
||||||
|
thisVertex.BoneWeights[i] = weights[i].asFloat();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3];
|
||||||
|
//if (totalWeight > 0.0001f) {
|
||||||
|
// thisVertex.BoneWeights[0] /= totalWeight;
|
||||||
|
// thisVertex.BoneWeights[1] /= totalWeight;
|
||||||
|
// thisVertex.BoneWeights[2] /= totalWeight;
|
||||||
|
// thisVertex.BoneWeights[3] /= totalWeight;
|
||||||
|
//}
|
||||||
|
|
||||||
std::vector<VertexLayout>::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex);
|
std::vector<VertexLayout>::iterator it = std::find(vertexList.begin(), vertexList.end(), thisVertex);
|
||||||
array<unsigned int, 2> tmp;
|
array<unsigned int, 2> tmp;
|
||||||
if (it != vertexList.end()) {
|
if (it != vertexList.end()) {
|
||||||
|
|||||||
@@ -64,6 +64,7 @@ std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY"
|
|||||||
|
|
||||||
Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame)
|
Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame)
|
||||||
{
|
{
|
||||||
|
MStatus status;
|
||||||
std::vector<MObject> animatedJoints;
|
std::vector<MObject> animatedJoints;
|
||||||
std::vector<MObject> m_Hierarchy;
|
std::vector<MObject> m_Hierarchy;
|
||||||
|
|
||||||
@@ -121,7 +122,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
MFnMatrixData MartixFn(DataHandle.data());
|
MFnMatrixData MartixFn(DataHandle.data());
|
||||||
MMatrix BindPoseMatrix = MartixFn.matrix();
|
MMatrix BindPoseMatrix = MartixFn.matrix();
|
||||||
|
|
||||||
if (BindPoseMatrix != MayaJoint.transformationMatrix())
|
if (!BindPoseMatrix.isEquivalent(MayaJoint.transformationMatrix()))
|
||||||
{
|
{
|
||||||
MGlobal::displayError(MString() + animationName.c_str() + " is using " + MayaJoint.name() + " that is not in bind pose nor is it key framed in the animation, the exported animation will NOT correspond to the animation in Maya");
|
MGlobal::displayError(MString() + animationName.c_str() + " is using " + MayaJoint.name() + " that is not in bind pose nor is it key framed in the animation, the exported animation will NOT correspond to the animation in Maya");
|
||||||
}
|
}
|
||||||
@@ -153,19 +154,43 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
MGlobal::displayError(MString() + "Could not find joint ID for: " + thisJoint.name());
|
MGlobal::displayError(MString() + "Could not find joint ID for: " + thisJoint.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
MMatrix Matrix = thisJoint.transformationMatrix();
|
MTransformationMatrix Matrix = thisJoint.transformation();
|
||||||
|
MPlug BindPose = thisJoint.findPlug("bindPose");
|
||||||
|
MDataHandle DataHandle;
|
||||||
|
BindPose.getValue(DataHandle);
|
||||||
|
MFnMatrixData MartixFn(DataHandle.data());
|
||||||
|
MMatrix BindPoseMatrix = MartixFn.matrix();
|
||||||
|
Matrix = Matrix.asMatrix();
|
||||||
|
|
||||||
|
MObject jointOrientObj = thisJoint.attribute("jointOrient");
|
||||||
|
MFnNumericAttribute jointOrient(jointOrientObj);
|
||||||
|
double jointOrientDouble[3];
|
||||||
|
jointOrient.getDefault(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]);
|
||||||
|
//MGlobal::displayError(MString() + "Joint Matrix: ");
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[0][0] + " " + Matrix.asMatrix()[0][1] + " " + Matrix.asMatrix()[0][2] + " " + Matrix.asMatrix()[0][3]);
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[1][0] + " " + Matrix.asMatrix()[1][1] + " " + Matrix.asMatrix()[1][2] + " " + Matrix.asMatrix()[1][3]);
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[2][0] + " " + Matrix.asMatrix()[2][1] + " " + Matrix.asMatrix()[2][2] + " " + Matrix.asMatrix()[2][3]);
|
||||||
|
//MGlobal::displayError(MString() + Matrix.asMatrix()[3][0] + " " + Matrix.asMatrix()[3][1] + " " + Matrix.asMatrix()[3][2] + " " + Matrix.asMatrix()[3][3]);
|
||||||
|
|
||||||
|
MEulerRotation joEuler(jointOrientDouble[0], jointOrientDouble[1], jointOrientDouble[2]);
|
||||||
|
MQuaternion jo = joEuler.asQuaternion();
|
||||||
|
|
||||||
double tmp[4];
|
double tmp[4];
|
||||||
thisJoint.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
Matrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||||
|
MQuaternion rotation(tmp);
|
||||||
|
|
||||||
|
rotation = rotation * jo;
|
||||||
|
rotation.get(tmp);
|
||||||
|
|
||||||
joint.Rotation[0] = tmp[0];
|
joint.Rotation[0] = tmp[0];
|
||||||
joint.Rotation[1] = tmp[1];
|
joint.Rotation[1] = tmp[1];
|
||||||
joint.Rotation[2] = tmp[2];
|
joint.Rotation[2] = tmp[2];
|
||||||
joint.Rotation[3] = tmp[3];
|
joint.Rotation[3] = tmp[3];
|
||||||
thisJoint.getTranslation(MSpace::kPreTransform).get(tmp);
|
Matrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||||
joint.Position[0] = tmp[0];
|
joint.Position[0] = tmp[0];
|
||||||
joint.Position[1] = tmp[1];
|
joint.Position[1] = tmp[1];
|
||||||
joint.Position[2] = tmp[2];
|
joint.Position[2] = tmp[2];
|
||||||
thisJoint.getScale(tmp);
|
Matrix.getScale(tmp, MSpace::kTransform);
|
||||||
joint.Scale[0] = tmp[0];
|
joint.Scale[0] = tmp[0];
|
||||||
joint.Scale[1] = tmp[1];
|
joint.Scale[1] = tmp[1];
|
||||||
joint.Scale[2] = tmp[2];
|
joint.Scale[2] = tmp[2];
|
||||||
@@ -184,6 +209,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
|||||||
|
|
||||||
std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
||||||
{
|
{
|
||||||
|
MStatus status;
|
||||||
std::vector<BindPoseSkeletonNode> m_AllSkeletons;
|
std::vector<BindPoseSkeletonNode> m_AllSkeletons;
|
||||||
std::vector<MObject> m_Hierarchy;
|
std::vector<MObject> m_Hierarchy;
|
||||||
|
|
||||||
@@ -214,12 +240,76 @@ std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
|||||||
}
|
}
|
||||||
m_Hierarchy.push_back(MayaJoint.object());
|
m_Hierarchy.push_back(MayaJoint.object());
|
||||||
|
|
||||||
MPlug BindPose = MayaJoint.findPlug("bindPose");
|
MPlug BindPose = MayaJoint.findPlug("bindPose", &status);
|
||||||
|
if (status != MS::kSuccess) {
|
||||||
|
MGlobal::displayError(MString() + "Could not find bindPose plug: " + status.errorString());
|
||||||
|
}
|
||||||
MDataHandle DataHandle;
|
MDataHandle DataHandle;
|
||||||
BindPose.getValue(DataHandle);
|
BindPose.getValue(DataHandle);
|
||||||
MFnMatrixData MartixFn(DataHandle.data());
|
MFnMatrixData MartixFn(DataHandle.data());
|
||||||
MMatrix Matrix = MartixFn.matrix();
|
MMatrix Matrix = MartixFn.matrix();
|
||||||
|
|
||||||
|
|
||||||
|
MVector tmp = MayaJoint.transformation().getTranslation(MSpace::kObject);
|
||||||
|
MGlobal::displayError(MString() + "translation befor: " + tmp[0] + " " + tmp[1] + " " + tmp[2]);
|
||||||
|
//Matrix[3][0] *= -1;
|
||||||
|
//Matrix[3][2] *= -1;
|
||||||
|
//Matrix[3][1] *= -1;
|
||||||
|
|
||||||
|
double test[3];
|
||||||
|
MayaJoint.transformation().getScale(test, MSpace::kObject);
|
||||||
|
MGlobal::displayError(MString() + "scale: " + test[0] + " " + test[1] + " " + test[2]);
|
||||||
|
|
||||||
|
MTransformationMatrix::RotationOrder order = MTransformationMatrix::RotationOrder::kXYZ;
|
||||||
|
MayaJoint.transformation().getRotation(test, order);
|
||||||
|
MGlobal::displayError(MString() + "rotation: " + test[0] + " " + test[1] + " " + test[2]);
|
||||||
|
|
||||||
|
//----- test
|
||||||
|
|
||||||
|
|
||||||
|
//MDataHandle DataHandle;
|
||||||
|
//MObject jointObject(jointIt.currentItem());
|
||||||
|
//MFnDependencyNode jointDependNode(jointObject);
|
||||||
|
//MPlug worldMatrixArray(jointObject, jointDependNode.attribute("worldMatrix"));
|
||||||
|
|
||||||
|
//MMatrix Matrix;
|
||||||
|
//for (int i = 0; i < worldMatrixArray.numElements(); i++) {
|
||||||
|
// MPlugArray connections;
|
||||||
|
|
||||||
|
// MPlug element = worldMatrixArray[i];
|
||||||
|
// unsigned int logicalIndex = element.logicalIndex();
|
||||||
|
|
||||||
|
// MItDependencyGraph it(element, MFn::kSkinClusterFilter);
|
||||||
|
|
||||||
|
// for (; !it.isDone(); it.next()) {
|
||||||
|
// MFnSkinCluster skinCluster(it.thisNode());
|
||||||
|
|
||||||
|
// MPlug bindPreMatrixArrayPlug =
|
||||||
|
// skinCluster.findPlug("bindPreMatrix", &status);
|
||||||
|
|
||||||
|
// if (status != MS::kSuccess) {
|
||||||
|
// MGlobal::displayError(MString() + "Could not find bindPreMatrix plug: " + status.errorString());
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// MPlug bindPreMatrixPlug =
|
||||||
|
// bindPreMatrixArrayPlug.elementByLogicalIndex(logicalIndex);
|
||||||
|
// MObject dataObject;
|
||||||
|
// bindPreMatrixPlug.getValue(dataObject);
|
||||||
|
|
||||||
|
// MFnMatrixData matDataFn(dataObject);
|
||||||
|
|
||||||
|
// MMatrix invMat = matDataFn.matrix();
|
||||||
|
// Matrix = invMat.inverse();
|
||||||
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
//----- end test
|
||||||
|
|
||||||
|
|
||||||
|
Matrix = Matrix.inverse();
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
for (int j = 0; j < 4; j++) {
|
for (int j = 0; j < 4; j++) {
|
||||||
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
|
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
|
||||||
|
|||||||
Reference in New Issue
Block a user