Importing & Reading Custom animation data. TODO: Shaders.
This commit is contained in:
@@ -11,7 +11,9 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
||||
MGlobal::displayError(MString() + "Export::Meshes() got no pathName. Do not know where to write file");
|
||||
return false;
|
||||
}
|
||||
|
||||
MSelectionList selectedOnStart;
|
||||
MGlobal::getActiveSelectionList(selectedOnStart);
|
||||
|
||||
MObjectArray Objects;
|
||||
if (selectedOnly) {
|
||||
// Retrieving the objects we currently have selected
|
||||
@@ -36,18 +38,14 @@ bool Export::Meshes(std::string pathName, bool selectedOnly)
|
||||
MFnDependencyNode thisNode(node);
|
||||
MPlugArray connections;
|
||||
thisNode.findPlug("inMesh").connectedTo(connections, true, true);
|
||||
bool next = false;
|
||||
|
||||
for (unsigned int i = 0; i < connections.length(); i++) {
|
||||
if (connections[i].node().apiType() == MFn::kSkinClusterFilter) {
|
||||
next = true;
|
||||
break;
|
||||
MGlobal::select(node);
|
||||
MGlobal::executeCommand("gotoBindPose");
|
||||
}
|
||||
}
|
||||
|
||||
if (next)
|
||||
continue;
|
||||
|
||||
Objects.append(node);
|
||||
}
|
||||
}
|
||||
@@ -139,6 +137,7 @@ void Export::WriteAnimData(std::string pathName)
|
||||
int size = allBindPoses.size();
|
||||
m_AnimFile.writeToFiles(&size);
|
||||
|
||||
|
||||
size = allAnimations.size();
|
||||
m_AnimFile.writeToFiles(&size);
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
Animation returnData;
|
||||
double oneDivSixty = 1 / 60.0;
|
||||
returnData.Name = animationName;
|
||||
returnData.nameLength = animationName.size() + 1;
|
||||
returnData.Duration = (endFrame - startFrame) * oneDivSixty;
|
||||
|
||||
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||
@@ -132,7 +133,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
}
|
||||
|
||||
int currentFrame = startFrame;
|
||||
while (currentFrame != endFrame) {
|
||||
while (currentFrame != endFrame + 1) { // ANDREAS
|
||||
Animation::Keyframe thisKeyFrame;
|
||||
thisKeyFrame.Index = currentFrame - startFrame;
|
||||
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
|
||||
@@ -188,7 +189,6 @@ std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
||||
|
||||
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
|
||||
BindPoseSkeletonNode SkeletonStorage;
|
||||
|
||||
while (!jointIt.isDone()) {
|
||||
MFnTransform MayaJoint(jointIt.currentItem());
|
||||
BindPoseSkeletonNode::BindPoseJoint NewJoint;
|
||||
@@ -227,7 +227,8 @@ std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
||||
}
|
||||
|
||||
NewJoint.Name = MayaJoint.name().asChar();
|
||||
|
||||
NewJoint.NameLength = MayaJoint.name().length() + 1;
|
||||
NewJoint.ID = SkeletonStorage.Joints.size();
|
||||
//double tmp[3];
|
||||
//((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp);
|
||||
//NewJoint.Rotation[0] = tmp[0];
|
||||
@@ -242,9 +243,9 @@ std::vector<BindPoseSkeletonNode> Skeleton::GetBindPoses()
|
||||
//NewJoint.Translation[1] = tmp[1];
|
||||
//NewJoint.Translation[2] = tmp[2];
|
||||
SkeletonStorage.Joints.push_back(NewJoint);
|
||||
SkeletonStorage.numBones++;
|
||||
jointIt.next();
|
||||
}
|
||||
|
||||
m_AllSkeletons.push_back(SkeletonStorage);
|
||||
|
||||
return m_AllSkeletons;
|
||||
|
||||
@@ -13,32 +13,35 @@ public:
|
||||
{
|
||||
struct JointProperty
|
||||
{
|
||||
int ID;
|
||||
float Position[3];
|
||||
float Rotation[4];
|
||||
float Scale[3];
|
||||
int ID = 0;
|
||||
float Position[3]{ 0 };
|
||||
float Rotation[4]{ 0 };
|
||||
float Scale[3]{ 0 };
|
||||
};
|
||||
|
||||
int Index;
|
||||
double Time;
|
||||
int Index = 0;
|
||||
float Time = 0;
|
||||
std::vector<JointProperty> JointProperties;
|
||||
};
|
||||
|
||||
std::string Name;
|
||||
double Duration;
|
||||
int NumKeyFrames;
|
||||
int NumberOfJoints;
|
||||
int nameLength = 0;
|
||||
float Duration = 0;
|
||||
int NumKeyFrames = 0;
|
||||
int NumberOfJoints = 0;
|
||||
std::vector<Keyframe> Keyframes;
|
||||
|
||||
virtual void WriteBinary(std::ostream& out)
|
||||
{
|
||||
out.write((char*)&nameLength, sizeof(int));
|
||||
out.write(Name.c_str(), Name.size() + 1);
|
||||
out.write((char*)&Duration, sizeof(double));
|
||||
out.write((char*)&Duration, sizeof(float));
|
||||
out.write((char*)&NumKeyFrames, sizeof(int));
|
||||
out.write((char*)&NumberOfJoints, sizeof(int));
|
||||
//Här under loopas alla key frames igenom
|
||||
for (auto aKeyframe : Keyframes) {
|
||||
out.write((char*)&aKeyframe.Index, sizeof(int));
|
||||
out.write((char*)&aKeyframe.Time, sizeof(double));
|
||||
out.write((char*)&aKeyframe.Time, sizeof(float));
|
||||
for (auto aJoint : aKeyframe.JointProperties) {
|
||||
out.write((char*)&aJoint.ID, sizeof(int));
|
||||
out.write((char*)aJoint.Position, sizeof(float) * 3);
|
||||
@@ -72,20 +75,24 @@ class BindPoseSkeletonNode : public OutputData {
|
||||
public:
|
||||
struct BindPoseJoint
|
||||
{
|
||||
int ParentID;
|
||||
int NameLength;
|
||||
std::string Name;
|
||||
float OffsetMatrix[4][4];
|
||||
float OffsetMatrix[4][4]{ 0 };
|
||||
int ID = 0;
|
||||
int ParentID = 0;
|
||||
};
|
||||
|
||||
int numBones = 0;
|
||||
std::string Name;
|
||||
std::vector<BindPoseJoint> Joints;
|
||||
virtual void WriteBinary(std::ostream& out)
|
||||
{
|
||||
out.write(Name.c_str(), Name.size() + 1);
|
||||
out.write((char*)&numBones, sizeof(int));
|
||||
for (auto Joint:Joints)
|
||||
{
|
||||
out.write((char*)&Joint.NameLength, sizeof(int));
|
||||
out.write(Joint.Name.c_str(), Joint.Name.size() + 1);
|
||||
out.write((char*)&Joint.OffsetMatrix, sizeof(float) * 4 * 4);
|
||||
out.write((char*)&Joint.ID, sizeof(int));
|
||||
out.write((char*)&Joint.ParentID, sizeof(int));
|
||||
}
|
||||
|
||||
@@ -93,16 +100,19 @@ public:
|
||||
|
||||
virtual void WriteASCII(std::ostream& out) const
|
||||
{
|
||||
out << "Bind Pose: " << Name << endl;
|
||||
out << "Bind Pose: " << Name << " _ not in binary" << endl;
|
||||
out << "numberOfBones: " << numBones << endl;
|
||||
for (auto Joint : Joints)
|
||||
{
|
||||
out << Joint.Name << endl;
|
||||
out << "Joint NameLength " << Joint.NameLength << endl;
|
||||
out << "Joint name " << Joint.Name << endl;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
for (int j = 0; j < 4; j++){
|
||||
out << Joint.OffsetMatrix[i][j] << " ";
|
||||
}
|
||||
out << endl;
|
||||
}
|
||||
out << Joint.ID << endl;
|
||||
out << Joint.ParentID << endl;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user