Changed how we get skeletons. Made so that we could get the bind pose for each skeleton in the scene
This commit is contained in:
@@ -33,6 +33,9 @@
|
|||||||
#include <maya/MPlug.h>
|
#include <maya/MPlug.h>
|
||||||
#include <maya/MAnimControl.h>
|
#include <maya/MAnimControl.h>
|
||||||
#include <maya/MTime.h>
|
#include <maya/MTime.h>
|
||||||
|
#include <maya/MDataHandle.h>
|
||||||
|
#include <maya/MTransformationMatrix.h>
|
||||||
|
#include <maya/MFnMatrixData.h>
|
||||||
|
|
||||||
|
|
||||||
// Wrappers
|
// Wrappers
|
||||||
|
|||||||
@@ -190,25 +190,44 @@ void Menu::GetSkeletonData()
|
|||||||
MTime startFrame = MAnimControl::animationStartTime();
|
MTime startFrame = MAnimControl::animationStartTime();
|
||||||
MTime endFrame = MAnimControl::animationEndTime();
|
MTime endFrame = MAnimControl::animationEndTime();
|
||||||
|
|
||||||
std::vector<std::vector<SkeletonNode>*> AllSkeletons;
|
std::vector<std::vector<SkeletonNode>> allSkeletons;
|
||||||
|
|
||||||
|
std::vector<BindPoseSkeletonNode> allBindPoses;
|
||||||
|
allBindPoses = m_SkeletonHandler->GetBindPoses();
|
||||||
|
|
||||||
for (int i = startFrame.value(); i < endFrame.value();i++)
|
for (int i = startFrame.value(); i < endFrame.value();i++)
|
||||||
{
|
{
|
||||||
MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField));
|
MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField));
|
||||||
// Traverse scene and return vector with all materials
|
// Traverse scene and return vector with all materials
|
||||||
AllSkeletons.push_back(m_SkeletonHandler->DoIt());
|
allSkeletons.push_back(m_SkeletonHandler->DoIt());
|
||||||
|
}
|
||||||
|
|
||||||
|
//print out all bind poses
|
||||||
|
for (auto aBindPose : allBindPoses)
|
||||||
|
{
|
||||||
|
MGlobal::displayInfo(MString() + "BindPose Skeleton name: " + aBindPose.Name.c_str());
|
||||||
|
for (int i = 0; i < aBindPose.Joints.size(); i++)
|
||||||
|
{
|
||||||
|
//MGlobal::displayInfo(MString() + aBindPose.JointNames[i].c_str());
|
||||||
|
//MGlobal::displayInfo(MString() + aBindPose.ParentIDs[i]);
|
||||||
|
//MGlobal::displayInfo(MString() + aBindPose.Joints[i].Translation[0] + " " + aBindPose.Joints[i].Translation[1] + " " + aBindPose.Joints[i].Translation[2]);
|
||||||
|
//MGlobal::displayInfo(MString() + aBindPose.Joints[i].Rotation[0] + " " + aBindPose.Joints[i].Rotation[1] + " " + aBindPose.Joints[i].Rotation[2]);
|
||||||
|
//MGlobal::displayInfo(MString() + aBindPose.Joints[i].Scale[0] + " " + aBindPose.Joints[i].Scale[1] + " " + aBindPose.Joints[i].Scale[2]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MGlobal::displayInfo(MString() + AllSkeletons.size());
|
//Print out all skeletons for all frames
|
||||||
|
MGlobal::displayInfo(MString() + allSkeletons.size());
|
||||||
for (int i = 0; i < AllSkeletons.size(); i++)
|
for (auto frameSkeletons : allSkeletons)
|
||||||
{
|
{
|
||||||
std::vector<SkeletonNode>*& thisSkeleton = AllSkeletons.at(i);
|
for (auto aSkeleton : frameSkeletons)
|
||||||
for (int k = 0; k < thisSkeleton->size(); k++)
|
|
||||||
{
|
{
|
||||||
for (int j = 0; j < thisSkeleton->at(k).Joints.size(); j++)
|
MGlobal::displayInfo(MString() + aSkeleton.Name.c_str());
|
||||||
|
for (auto joint : aSkeleton.Joints)
|
||||||
{
|
{
|
||||||
MGlobal::displayInfo(MString() + thisSkeleton->at(k).Joints.at(j).Name.c_str());
|
//MGlobal::displayInfo(MString() + joint.Translation[0] + " " + joint.Translation[1] + " " + joint.Translation[2]);
|
||||||
|
//MGlobal::displayInfo(MString() + joint.Rotation[0] + " " + joint.Rotation[1] + " " + joint.Rotation[2]);
|
||||||
|
//MGlobal::displayInfo(MString() + joint.Scale[0] + " " + joint.Scale[1] + " " + joint.Scale[2]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
#include "Skeleton.h"
|
#include "Skeleton.h"
|
||||||
|
|
||||||
std::vector<SkeletonNode>* Skeleton::DoIt()
|
std::vector<SkeletonNode> Skeleton::DoIt()
|
||||||
{
|
{
|
||||||
MItDependencyNodes jointIt(MFn::kJoint);
|
std::vector<SkeletonNode> m_AllSkeletons;
|
||||||
|
|
||||||
|
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||||
SkeletonNode SkeletonStorage;
|
SkeletonNode SkeletonStorage;
|
||||||
|
|
||||||
while (!jointIt.isDone()) {
|
while (!jointIt.isDone()) {
|
||||||
MFnDependencyNode SkeletonFnDN(jointIt.thisNode());
|
MFnTransform TransformNode(jointIt.currentItem());
|
||||||
MFnTransform TransformNode(SkeletonFnDN.object());
|
|
||||||
Joint NewJoint;
|
Joint NewJoint;
|
||||||
|
|
||||||
if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") {
|
if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") {
|
||||||
@@ -20,24 +21,27 @@ std::vector<SkeletonNode>* Skeleton::DoIt()
|
|||||||
|
|
||||||
SkeletonStorage.Name = TransformNode.name().asChar();
|
SkeletonStorage.Name = TransformNode.name().asChar();
|
||||||
|
|
||||||
NewJoint.ParentIndex = -1; // This joint is root
|
//NewJoint.ParentIndex = -1; // This joint is root
|
||||||
}
|
|
||||||
else {
|
|
||||||
auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), TransformNode.parent(0));
|
|
||||||
if (it != m_Hierarchy.end()) {
|
|
||||||
NewJoint.ParentIndex = it - m_Hierarchy.begin();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
MGlobal::displayError(MString() + "Could not find joint parent for: " + TransformNode.name());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Hierarchy.push_back(TransformNode.object());
|
//NewJoint.Name = TransformNode.name().asChar();
|
||||||
|
|
||||||
NewJoint.Name = TransformNode.name().asChar();
|
|
||||||
|
|
||||||
MMatrix Matrix = TransformNode.transformationMatrix();
|
MMatrix Matrix = TransformNode.transformationMatrix();
|
||||||
|
|
||||||
|
//double tmp[3];
|
||||||
|
//((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp);
|
||||||
|
//NewJoint.Rotation[0] = tmp[0];
|
||||||
|
//NewJoint.Rotation[1] = tmp[1];
|
||||||
|
//NewJoint.Rotation[2] = tmp[2];
|
||||||
|
//((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform);
|
||||||
|
//NewJoint.Scale[0] = tmp[0];
|
||||||
|
//NewJoint.Scale[1] = tmp[1];
|
||||||
|
//NewJoint.Scale[2] = tmp[2];
|
||||||
|
//((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp);
|
||||||
|
//NewJoint.Translation[0] = tmp[0];
|
||||||
|
//NewJoint.Translation[1] = tmp[1];
|
||||||
|
//NewJoint.Translation[2] = tmp[2];
|
||||||
|
|
||||||
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];
|
||||||
@@ -51,5 +55,79 @@ std::vector<SkeletonNode>* Skeleton::DoIt()
|
|||||||
|
|
||||||
m_AllSkeletons.push_back(SkeletonStorage);
|
m_AllSkeletons.push_back(SkeletonStorage);
|
||||||
|
|
||||||
return &m_AllSkeletons;
|
return m_AllSkeletons;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
||||||
|
{
|
||||||
|
std::vector<BindPoseSkeletonNode> m_AllSkeletons;
|
||||||
|
std::vector<MObject> m_Hierarchy;
|
||||||
|
|
||||||
|
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||||
|
BindPoseSkeletonNode SkeletonStorage;
|
||||||
|
|
||||||
|
while (!jointIt.isDone()) {
|
||||||
|
MFnTransform MayaJoint(jointIt.currentItem());
|
||||||
|
|
||||||
|
if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") {
|
||||||
|
if (SkeletonStorage.Joints.size() != 0) {
|
||||||
|
m_AllSkeletons.push_back(SkeletonStorage);
|
||||||
|
|
||||||
|
SkeletonStorage.Joints.clear();
|
||||||
|
SkeletonStorage.Name.clear();
|
||||||
|
SkeletonStorage.ParentIDs.clear();
|
||||||
|
SkeletonStorage.Name.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
SkeletonStorage.Name = MayaJoint.name().asChar();
|
||||||
|
SkeletonStorage.ParentIDs.push_back(-1); // This joint is root
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0));
|
||||||
|
if (it != m_Hierarchy.end()) {
|
||||||
|
SkeletonStorage.ParentIDs.push_back(it - m_Hierarchy.begin());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Hierarchy.push_back(MayaJoint.object());
|
||||||
|
|
||||||
|
Joint NewJoint;
|
||||||
|
|
||||||
|
MPlug BindPose = MayaJoint.findPlug("bindPose");
|
||||||
|
MDataHandle DataHandle;
|
||||||
|
BindPose.getValue(DataHandle);
|
||||||
|
MFnMatrixData MartixFn(DataHandle.data());
|
||||||
|
MMatrix Matrix = MartixFn.matrix();
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
for (int j = 0; j < 4; j++) {
|
||||||
|
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*double tmp[3];
|
||||||
|
((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp);
|
||||||
|
NewJoint.Rotation[0] = tmp[0];
|
||||||
|
NewJoint.Rotation[1] = tmp[1];
|
||||||
|
NewJoint.Rotation[2] = tmp[2];
|
||||||
|
((MTransformationMatrix)Matrix).getScale(tmp, MSpace::Space::kTransform);
|
||||||
|
NewJoint.Scale[0] = tmp[0];
|
||||||
|
NewJoint.Scale[1] = tmp[1];
|
||||||
|
NewJoint.Scale[2] = tmp[2];
|
||||||
|
((MTransformationMatrix)Matrix).getTranslation(MSpace::Space::kTransform).get(tmp);
|
||||||
|
NewJoint.Translation[0] = tmp[0];
|
||||||
|
NewJoint.Translation[1] = tmp[1];
|
||||||
|
NewJoint.Translation[2] = tmp[2];*/
|
||||||
|
|
||||||
|
SkeletonStorage.Joints.push_back(NewJoint);
|
||||||
|
SkeletonStorage.JointNames.push_back(MayaJoint.name().asChar());
|
||||||
|
|
||||||
|
jointIt.next();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_AllSkeletons.push_back(SkeletonStorage);
|
||||||
|
|
||||||
|
return m_AllSkeletons;
|
||||||
}
|
}
|
||||||
@@ -7,12 +7,11 @@
|
|||||||
#include "MayaIncludes.h"
|
#include "MayaIncludes.h"
|
||||||
|
|
||||||
struct Joint {
|
struct Joint {
|
||||||
int ParentIndex;
|
//int ParentIndex;
|
||||||
//std::array<float, 3> Rotation;
|
//std::array<float, 3> Rotation;
|
||||||
//std::array<float, 3> Translation;
|
//std::array<float, 3> Translation;
|
||||||
//std::array<float, 3> Scale;
|
//std::array<float, 3> Scale;
|
||||||
std::array<std::array<float, 4>, 4> OffsetMatrix;
|
std::array<std::array<float, 4>, 4> OffsetMatrix;
|
||||||
std::string Name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SkeletonNode {
|
struct SkeletonNode {
|
||||||
@@ -20,12 +19,16 @@ struct SkeletonNode {
|
|||||||
std::vector<Joint> Joints;
|
std::vector<Joint> Joints;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BindPoseSkeletonNode : SkeletonNode {
|
||||||
|
std::vector<int> ParentIDs;
|
||||||
|
std::vector<std::string> JointNames;
|
||||||
|
};
|
||||||
|
|
||||||
class Skeleton {
|
class Skeleton {
|
||||||
public:
|
public:
|
||||||
std::vector<SkeletonNode>* DoIt();
|
std::vector<SkeletonNode> DoIt();
|
||||||
|
std::vector<BindPoseSkeletonNode> GetBindPoses();
|
||||||
private:
|
private:
|
||||||
std::vector<SkeletonNode> m_AllSkeletons;
|
|
||||||
std::vector<MObject> m_Hierarchy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //Skeleton_Skeleton_h__
|
#endif //Skeleton_Skeleton_h__
|
||||||
Reference in New Issue
Block a user