Animations PROBABLY works fine if all joints got keyframes.

This commit is contained in:
antc13
2016-01-23 18:02:42 +01:00
parent c984f76b2f
commit f1835fd89c
21 changed files with 325 additions and 84 deletions
+2 -2
View File
@@ -10,8 +10,8 @@
#include "../Core/Ray.h"
#include "../Core/AABB.h"
//#include "Engine/Rendering/RawModelAssimp.h"
#include "Engine/Rendering/RawModelCustom.h"
#include "Rendering/RawModelCustom.h"
//#include "Rendering/RawModelAssimp.h"
#include "../Core/Transform.h"
#include "../Core/Entity.h"
#include "../Core/EntityWrapper.h"
@@ -61,6 +61,6 @@ public:
protected:
glm::vec3 m_Position = 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;
};
+2 -1
View File
@@ -1,7 +1,8 @@
#ifndef Model_h__
#define Model_h__
#include "RawModelCustom.h"
#include "Rendering/RawModelCustom.h"
//#include "Rendering/RawModelAssimp.h"
#include "../OpenGL.h"
class Model : public ThreadUnsafeResource
+8 -3
View File
@@ -1,6 +1,8 @@
#ifndef RawModelAssimp_h__
#define RawModelAssimp_h__
#ifdef USING_ASSIMP_AS_IMPORTER
#include <fstream>
#include <iostream>
#include <sstream>
@@ -18,15 +20,17 @@
#include "Texture.h"
#include "Skeleton.h"
class RawModel : public Resource
#define RawModel RawModelAssimp
class RawModelAssimp : public Resource
{
friend class ResourceManager;
protected:
RawModel(std::string fileName);
RawModelAssimp(std::string fileName);
public:
~RawModel();
~RawModelAssimp();
struct Vertex
{
@@ -72,3 +76,4 @@ private:
};
#endif
#endif
+14 -3
View File
@@ -1,6 +1,10 @@
#ifndef RawModelCustom_h__
#define RawModelCustom_h__
#ifndef USING_ASSIMP_AS_IMPORTER
#define RawModel RawModelCustom
#include <fstream>
#include <iostream>
#include <sstream>
@@ -17,15 +21,17 @@
#include "boost\endian\buffers.hpp"
class RawModel : public Resource
class RawModelCustom : public Resource
{
friend class ResourceManager;
protected:
RawModel(std::string fileName);
RawModelCustom(std::string fileName);
public:
~RawModel();
~RawModelCustom();
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);
};
#else
#include "RawModelAssimp.h"
#endif
#endif
+1
View File
@@ -4,6 +4,7 @@
#include <sstream>
#include "Common.h"
#include "../GLM.h"
#include <glm/gtx/matrix_decompose.hpp>
//struct Bone
//{
+1 -1
View File
@@ -19,7 +19,7 @@
<Entity>
<Components>
<c:Model>
<Resource>models/Baljj.mesh</Resource>
<Resource>models/animTest.mesh</Resource>
</c:Model>
<c:Transform/>
</Components>
+11 -2
View File
@@ -3,6 +3,7 @@
uniform mat4 M;
uniform mat4 V;
uniform mat4 P;
uniform mat4 Bones[100];
layout(location = 0) in vec3 Position;
layout(location = 1) in vec3 Normal;
@@ -20,9 +21,17 @@ out VertexData{
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.Normal = vec3(M * vec4(Normal, 0.0));
}
+12
View File
@@ -292,21 +292,33 @@ void EditorSystem::createWidget()
m_WidgetPlaneX = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneX, "Transform");
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
#endif
m_WidgetY = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetY, "Transform");
m_World->AttachComponent(m_WidgetY, "Model");
m_WidgetPlaneY = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneY, "Transform");
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
#endif
m_WidgetZ = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetZ, "Transform");
m_World->AttachComponent(m_WidgetZ, "Model");
m_WidgetPlaneZ = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetPlaneZ, "Transform");
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
#endif
m_WidgetOrigin = m_World->CreateEntity(m_Widget);
m_World->AttachComponent(m_WidgetOrigin, "Transform");
m_World->AttachComponent(m_WidgetOrigin, "Model");
+19 -1
View File
@@ -22,6 +22,8 @@ void DrawFinalPass::InitializeShaderPrograms()
m_ForwardPlusProgram->Link();
}
static double tempFrameCounter = 6.348;
void DrawFinalPass::Draw(RenderScene& scene)
{
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()));
glUniform2f(glGetUniformLocation(shaderHandle, "ScreenDimensions"), m_Renderer->Resolution().Width, m_Renderer->Resolution().Height);
//tempFrameCounter += 0.01;
//TODO: Render: Add code for more jobs than modeljobs.
for (auto &job : scene.ForwardJobs) {
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);
}
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);
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)));
@@ -61,4 +79,4 @@ void DrawFinalPass::Draw(RenderScene& scene)
}
GLERROR("DrawFinalPass::Draw: END");
}
}
+3
View File
@@ -15,6 +15,9 @@ Model::Model(std::string fileName)
if (!group.SpecularMapPath.empty()) {
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
+8 -3
View File
@@ -1,6 +1,8 @@
#include "Rendering/RawModelAssimp.h"
RawModel::RawModel(std::string fileName)
#ifdef USING_ASSIMP_AS_IMPORTER
RawModelAssimp::RawModelAssimp(std::string fileName)
{
Assimp::Importer importer;
const aiScene* scene = importer.ReadFile(fileName, aiProcess_CalcTangentSpace | aiProcess_Triangulate);
@@ -271,16 +273,17 @@ RawModel::RawModel(std::string fileName)
m_Skeleton->Animations[animationName] = skelAnim;
}
int k = 0;
}
RawModel::~RawModel()
RawModelAssimp::~RawModelAssimp()
{
if (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();
@@ -300,3 +303,5 @@ void RawModel::CreateSkeleton(std::vector<std::tuple<std::string, glm::mat4>> &b
CreateSkeleton(boneInfo, boneNameMapping, child, parentID);
}
}
#endif
+26 -20
View File
@@ -1,6 +1,8 @@
#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());
ReadMeshFile(fileName);
@@ -9,7 +11,7 @@ RawModel::RawModel(std::string fileName)
int k = 0;
}
void RawModel::ReadMeshFile(std::string filePath)
void RawModelCustom::ReadMeshFile(std::string filePath)
{
char* fileData;
filePath += ".mesh";
@@ -33,7 +35,7 @@ void RawModel::ReadMeshFile(std::string filePath)
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
m_Vertices.resize(*(unsigned int*)(fileData + offset));
@@ -44,13 +46,13 @@ void RawModel::ReadMeshFileHeader(unsigned int& offset, char* fileData, unsigned
#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);
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
if (offset + m_Vertices.size() * sizeof(Vertex) > fileByteSize) {
@@ -63,7 +65,7 @@ void RawModel::ReadVertices(unsigned int& offset, char* fileData, unsigned int&
#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
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
}
void RawModel::ReadMaterialFile(std::string filePath)
void RawModelCustom::ReadMaterialFile(std::string filePath)
{
char* fileData;
filePath += ".mtrl";
@@ -100,7 +102,7 @@ void RawModel::ReadMaterialFile(std::string filePath)
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
unsigned int* numMaterials = (unsigned int*)(fileData);
@@ -114,7 +116,7 @@ void RawModel::ReadMaterials(unsigned int& offset, char* fileData, unsigned int&
#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;
@@ -189,7 +191,7 @@ void RawModel::ReadMaterialSingle(unsigned int &offset, char* fileData, unsigned
MaterialGroups.push_back(newMaterial);
}
void RawModel::ReadAnimationFile(std::string filePath)
void RawModelCustom::ReadAnimationFile(std::string filePath)
{
char* fileData;
filePath += ".anim";
@@ -214,7 +216,7 @@ void RawModel::ReadAnimationFile(std::string filePath)
#ifdef BOOST_LITTLE_ENDIAN
unsigned int numBindPoses = *(unsigned int*)(fileData);
offset += sizeof(unsigned int);
unsigned int numAnimations = *(unsigned int*)(fileData);
unsigned int numAnimations = *(unsigned int*)(fileData + offset);
offset += sizeof(unsigned int);
#else
#endif
@@ -225,7 +227,7 @@ void RawModel::ReadAnimationFile(std::string filePath)
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
unsigned int* numBones = (unsigned int*)(fileData + offset);
@@ -238,7 +240,7 @@ void RawModel::ReadAnimationBindPoses(unsigned int &offset, char* fileData, unsi
#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
if (offset + sizeof(unsigned int) > fileByteSize) {
@@ -259,7 +261,7 @@ void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned
glm::mat4 offsetMatrix;
memcpy(&offsetMatrix, fileData + offset, sizeof(float) * 4 * 4);
offset += sizeof(float) * 4 * 4;
if (offset + sizeof(int) > fileByteSize) {
throw Resource::FailedLoadingException("Reading Joint ID failed");
}
@@ -280,14 +282,14 @@ void RawModel::ReadAnimationJoint(unsigned int &offset, char* fileData, unsigned
#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++) {
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
Skeleton::Animation newAnimation;
@@ -332,7 +334,7 @@ void RawModel::ReadAnimationClipSingle(unsigned int &offset, char* fileData, uns
#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;
@@ -356,12 +358,16 @@ void RawModel::ReadAnimationKeyFrame(unsigned int &offset, char* fileData, unsig
for (unsigned int i = 0; i < nrOfJoints; i++) {
memcpy(&newBone, (fileData + 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);
}
RawModel::~RawModel()
RawModelCustom::~RawModelCustom()
{
if (m_Skeleton != nullptr) {
delete m_Skeleton;
}
}
}
#endif
+8
View File
@@ -96,10 +96,18 @@ void RenderSystem::fillModels(std::list<std::shared_ptr<RenderJob>>& jobs, World
model = ResourceManager::Load<::Model, true>(resource);
} catch (const Resource::StillLoadingException&) {
//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
#endif
} catch (const std::exception&) {
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
#endif
} catch (const std::exception&) {
continue;
}
+7 -2
View File
@@ -68,7 +68,7 @@ std::vector<glm::mat4> Skeleton::GetFrameBones(const Animation& animation, doubl
void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyframe &currentFrame, 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()) {
Animation::Keyframe::BoneProperty currentBoneProperty = currentFrame.BoneProperties.at(bone->ID);
@@ -84,10 +84,14 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf
positionInterp.z = 0;
}
boneMatrix = parentMatrix * (glm::translate(positionInterp) * glm::toMat4(rotationInterp) * glm::scale(scaleInterp));
boneMatrices[bone->ID] = boneMatrix * bone->OffsetMatrix;
int k = 0;
} 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;
}
@@ -95,6 +99,7 @@ void Skeleton::AccumulateBoneTransforms(bool noRootMotion, const Animation::Keyf
std::string name = child->Name;
AccumulateBoneTransforms(noRootMotion, currentFrame, nextFrame, progress, boneMatrices, child, boneMatrix);
}
}
int Skeleton::GetBoneID(std::string name)
+3 -1
View File
@@ -27,7 +27,9 @@ using boost::unit_test_framework::test_case;
void RayTest(std::string fileName) {
//simple box test
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");
auto unitBox = ResourceManager::Load<RawModel>(fileName);
BOOST_REQUIRE(unitBox != nullptr);
+52 -7
View File
@@ -7,26 +7,56 @@ Export::Export()
bool Export::Meshes(std::string pathName, bool selectedOnly)
{
MStatus status;
if (pathName.empty()) {
MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file");
return false;
}
MSelectionList 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;
if (selectedOnly) {
// Retrieving the objects we currently have selected
MSelectionList selected;
MGlobal::getActiveSelectionList(selected);
// 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;
selected.getDependNode(i, object);
selectedOnStart.getDependNode(i, object);
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);
}
}
@@ -42,7 +72,9 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
for (unsigned int i = 0; i < connections.length(); i++) {
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
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);
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;
}
@@ -42,6 +42,9 @@
#include <maya/MItGeometry.h>
#include <maya/MItMeshVertex.h>
#include <maya/MFnWeightGeometryFilter.h>
#include <maya/MItDependencyGraph.h>
#include <maya/MQuaternion.h>
#include <maya/MFnNumericAttribute.h>
// Wrappers
+8 -8
View File
@@ -60,7 +60,7 @@ Menu::Menu(QDialog* dialog)
m_ExportPath = new QLineEdit;
m_FileDialog = new QFileDialog;
QString tmpPath("C:/Users/Nickelodion/Desktop/Baljj");
QString tmpPath("C:/Users/Nickelodion/Desktop/animTest");
m_ExportPath->setText(tmpPath);
QLabel* exportLabel = new QLabel;
exportLabel->setText("Export Path:");
@@ -175,6 +175,13 @@ void Menu::ExportAll(bool)
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;
for (unsigned int i = 0; i < m_AnimationClipName.size(); i++) {
Export::AnimationInfo thisClip;
@@ -191,13 +198,6 @@ void Menu::ExportAll(bool)
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)
+39 -22
View File
@@ -68,7 +68,6 @@ std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
break;
}
MFnDependencyNode test(comp);
unsigned int nrOfWeights = 0;
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++) {
//MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]);
MGlobal::displayInfo(MString() + "influence: " + weightInfo.BoneIndices[k] + " weight: " + weightInfo.BoneWeights[k]);
}
geomIter.next();
}
@@ -109,6 +108,26 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
if (!object[ObjectID].hasFn(MFn::kMesh))
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
MFnMesh mesh(object[ObjectID]);
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);
if (status != MS::kSuccess) {
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[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 (totalWeight < 1.00f && totalWeight > 0.01f) {
thisVertex.BoneWeights[0] /= totalWeight;
thisVertex.BoneWeights[1] /= totalWeight;
thisVertex.BoneWeights[2] /= totalWeight;
thisVertex.BoneWeights[3] /= totalWeight;
if (hasSkin) {
MIntArray jointIDs /* ??? */;
weights.selectAncestorLogicalIndex(vertexIndex, weightListObject);
weights.getExistingArrayAttributeIndices(jointIDs);
for (unsigned int i = 0; i < jointIDs.length() && i < 4; i++) {
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);
array<unsigned int, 2> tmp;
if (it != vertexList.end()) {
+97 -7
View File
@@ -64,6 +64,7 @@ std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY"
Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame)
{
MStatus status;
std::vector<MObject> animatedJoints;
std::vector<MObject> m_Hierarchy;
@@ -121,7 +122,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
MFnMatrixData MartixFn(DataHandle.data());
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");
}
@@ -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());
}
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];
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[1] = tmp[1];
joint.Rotation[2] = tmp[2];
joint.Rotation[3] = tmp[3];
thisJoint.getTranslation(MSpace::kPreTransform).get(tmp);
Matrix.getTranslation(MSpace::kTransform).get(tmp);
joint.Position[0] = tmp[0];
joint.Position[1] = tmp[1];
joint.Position[2] = tmp[2];
thisJoint.getScale(tmp);
Matrix.getScale(tmp, MSpace::kTransform);
joint.Scale[0] = tmp[0];
joint.Scale[1] = tmp[1];
joint.Scale[2] = tmp[2];
@@ -184,6 +209,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
{
MStatus status;
std::vector<BindPoseSkeletonNode> m_AllSkeletons;
std::vector<MObject> m_Hierarchy;
@@ -214,12 +240,76 @@ std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
}
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;
BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data());
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 j = 0; j < 4; j++) {
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];