We now export animations.

This commit is contained in:
antc13
2016-01-08 16:47:04 +01:00
parent eb5fca898f
commit 1667358e0c
5 changed files with 318 additions and 206 deletions
@@ -22,7 +22,7 @@ static const uint qt_meta_data_Menu[] = {
6, // revision
0, // classname
0, 0, // classinfo
7, 14, // methods
9, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@@ -33,17 +33,20 @@ static const uint qt_meta_data_Menu[] = {
14, 6, 5, 5, 0x08,
35, 5, 5, 5, 0x08,
59, 5, 5, 5, 0x08,
75, 5, 5, 5, 0x08,
95, 5, 5, 5, 0x08,
116, 5, 5, 5, 0x08,
137, 5, 5, 5, 0x08,
80, 5, 5, 5, 0x08,
104, 5, 5, 5, 0x08,
120, 5, 5, 5, 0x08,
140, 5, 5, 5, 0x08,
161, 5, 5, 5, 0x08,
182, 5, 5, 5, 0x08,
0 // eod
};
static const char qt_meta_stringdata_Menu[] = {
"Menu\0\0checked\0ExportSelected(bool)\0"
"ExportPathClicked(bool)\0ExportAll(bool)\0"
"ExportPathClicked(bool)\0AddClipClicked(bool)\0"
"RemoveClipClicked(bool)\0ExportAll(bool)\0"
"CancelClicked(bool)\0Button1Clicked(bool)\0"
"Button2Clicked(bool)\0Button3Clicked(bool)\0"
};
@@ -56,11 +59,13 @@ void Menu::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void *
switch (_id) {
case 0: _t->ExportSelected((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 1: _t->ExportPathClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 2: _t->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 3: _t->CancelClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 4: _t->Button1Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 5: _t->Button2Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 6: _t->Button3Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 2: _t->AddClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 3: _t->RemoveClipClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 4: _t->ExportAll((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 5: _t->CancelClicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 6: _t->Button1Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 7: _t->Button2Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
case 8: _t->Button3Clicked((*reinterpret_cast< bool(*)>(_a[1]))); break;
default: ;
}
}
@@ -98,9 +103,9 @@ int Menu::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 7)
if (_id < 9)
qt_static_metacall(this, _c, _id, _a);
_id -= 7;
_id -= 9;
}
return _id;
}
+21 -42
View File
@@ -72,7 +72,7 @@ Menu::Menu(QDialog* dialog)
endLabel->setText("End:");
//exportLabel->setText("Export Path:");
midLayout->addWidget(optionsBox);
topLayout->addWidget(exportLabel);
@@ -119,7 +119,7 @@ void Menu::ExportSelected(bool checked)
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 < selected.length(); i++) {
MObject object;
selected.getDependNode(i, object);
MFnDependencyNode thisNode(object);
@@ -177,7 +177,7 @@ void Menu::RemoveClipClicked(bool)
QLayoutItem* tempWidget;// = m_ClipLayout->itemAt(0);
for (unsigned int i = 0; i < layouts.size(); i++) {
while ((tempWidget = layouts[layouts.size()-1]->takeAt(0)) != 0) {
while ((tempWidget = layouts[layouts.size() - 1]->takeAt(0)) != 0) {
delete tempWidget->widget();
delete tempWidget;
}
@@ -185,7 +185,7 @@ void Menu::RemoveClipClicked(bool)
m_ClipLayout->removeItem(tempWidget);
m_ClipLayout->update();
layouts.pop_back();
m_StartFrameLines.pop_back();
m_EndFrameLines.pop_back();
@@ -195,10 +195,10 @@ void Menu::RemoveClipClicked(bool)
void Menu::ExportAll(bool)
{
MDagPath path;
// Loop through all nodes in the scene
MItDependencyNodes it(MFn::kInvalid);
for (;!it.isDone();it.next()) {
for (; !it.isDone(); it.next()) {
MObject node = it.thisNode();
if (node.hasFn(MFn::kMesh)) {
MFnDependencyNode thisNode(node);
@@ -218,7 +218,7 @@ void Menu::ExportAll(bool)
m_File.ASCIIFilePath("C:/Users/Nickelodion/Desktop/coolASCII.txt");
m_File.binaryFilePath("C:/Users/Nickelodion/Desktop/coolSoptunz.bin");
if(m_ExportAnimationsButton->isChecked())
if (m_ExportAnimationsButton->isChecked())
GetSkeletonData();
}
@@ -267,7 +267,7 @@ void Menu::GetMaterialData()
// Access the colorR component of one material (example)
cout << AllMaterials->at(0).Color[0] << endl;
MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]);
MGlobal::displayInfo(MString() + AllMaterials->at(0).Color[0]);
}
void Menu::GetSkeletonData()
@@ -277,10 +277,10 @@ void Menu::GetSkeletonData()
MGlobal::displayError(MString() + "Please change to 60 FPS under Preferences/Settings!");
return;
}
std::vector<std::vector<SkeletonNode>> allSkeletons;
std::vector<BindPoseSkeletonNode> allBindPoses;
std::vector<Animation> allAnimations;
allBindPoses = m_SkeletonHandler->GetBindPoses();
for (unsigned int j = 0; j < m_StartFrameLines.size(); j++) {
@@ -291,24 +291,19 @@ void Menu::GetSkeletonData()
int startFrame = m_StartFrameLines[j]->text().toInt();
int endFrame = m_EndFrameLines[j]->text().toInt();
std::string animationName = m_AnimationClipName[j]->text().toAscii().constData();
for (int i = startFrame; i < endFrame;++i)
{
MAnimControl::setCurrentTime(MTime(i, MTime::kNTSCField));
MTime time = MAnimControl::currentTime();
allAnimations.push_back(m_SkeletonHandler->GetAnimData(animationName, startFrame, endFrame));
}
m_File.OpenFiles();
// Traverse scene and return vector with all materials
allSkeletons.push_back(m_SkeletonHandler->DoIt());
}
//print out all bind poses
m_File.OpenFiles();
for (auto aBindPose : allBindPoses)
{
for (auto aBindPose : allBindPoses){
m_File.writeToFiles(&aBindPose);
MGlobal::displayInfo(MString() + "BindPose Skeleton name: " + aBindPose.Name.c_str());
for (int i = 0; i < aBindPose.Joints.size(); i++)
{
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]);
@@ -316,25 +311,9 @@ void Menu::GetSkeletonData()
//MGlobal::displayInfo(MString() + aBindPose.Joints[i].Scale[0] + " " + aBindPose.Joints[i].Scale[1] + " " + aBindPose.Joints[i].Scale[2]);
}
}
//Print out all skeletons for all frames
MGlobal::displayInfo(MString() + allSkeletons.size());
for (auto frameSkeletons : allSkeletons)
{
for (auto aSkeleton : frameSkeletons)
{
MGlobal::displayInfo(MString() + aSkeleton.Name.c_str());
//m_File.writeToFiles(&aSkeleton);
for (auto joint : aSkeleton.Joints)
{
//m_File.writeToFiles(&joint);
//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]);
}
}
}
//print out all animations
for (auto aAnimation : allAnimations) {
m_File.writeToFiles(&aAnimation);
}
m_File.CloseFiles();
}
+8 -9
View File
@@ -34,7 +34,6 @@ void Mesh::GetMeshData(MObject object)
mesh.getTangents(biTangents, MSpace::kObject, NULL);
mesh.getBinormals(biNormals, MSpace::kObject, NULL);
MGlobal::displayInfo("Befor Loop");
MItMeshFaceVertex faceVert(object);
int intDummy = 0;
for (MItMeshPolygon meshPolyIter(object); !meshPolyIter.isDone(); meshPolyIter.next()) {
@@ -43,10 +42,10 @@ void Mesh::GetMeshData(MObject object)
meshPolyIter.getTriangles(dummy, triangleList);
UINT indexOffset = verticesData.size();
MGlobal::displayInfo("Befor Second Loop");
//MGlobal::displayInfo("Befor Second Loop");
for (UINT i = 0; i < vertices.length(); i++) {
faceVert.setIndex(meshPolyIter.index(), i, intDummy, intDummy);
MGlobal::displayInfo("In Second Loop");
//MGlobal::displayInfo("In Second Loop");
faceVert.position().get(thisVertex.Pos);
faceVert.getNormal(normal);
thisVertex.Normal[0] = normal[0];
@@ -73,13 +72,13 @@ void Mesh::GetMeshData(MObject object)
verticesData.push_back(thisVertex);
localVertexToGlobalIndex.push_back(vertexIndex);
cout << "Pos: " << thisVertex.Pos[0] << "/" << thisVertex.Pos[1] << "/" << thisVertex.Pos[2] << endl;
cout << "Normals: " << thisVertex.Normal[0] << "/" << thisVertex.Normal[1] << "/" << thisVertex.Normal[2] << endl;
cout << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl;
cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl;
cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl;
//cout << "Pos: " << thisVertex.Pos[0] << "/" << thisVertex.Pos[1] << "/" << thisVertex.Pos[2] << endl;
//cout << "Normals: " << thisVertex.Normal[0] << "/" << thisVertex.Normal[1] << "/" << thisVertex.Normal[2] << endl;
//cout << "Bi-Normals: " << thisVertex.BiNormal[0] << "/" << thisVertex.BiNormal[1] << "/" << thisVertex.BiNormal[2] << endl;
//cout << "Bi-Tangents: " << thisVertex.BiTangent[0] << "/" << thisVertex.BiTangent[1] << "/" << thisVertex.BiTangent[2] << endl;
//cout << "UV: " << thisVertex.Uv[0] << "/" << thisVertex.Uv[1] << endl;
}
MGlobal::displayInfo("Befor Third Loop");
//MGlobal::displayInfo("Befor Third Loop");
//for (UINT i = 0; i < triangleList.length(); i++) {
// UINT k = 0;
+203 -93
View File
@@ -3,33 +3,225 @@
std::vector<SkeletonNode> Skeleton::DoIt()
//std::vector<SkeletonNode> Skeleton::DoIt()
//{
// std::vector<SkeletonNode> m_AllSkeletons;
//
// MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
// SkeletonNode SkeletonStorage;
//
// while (!jointIt.isDone()) {
// MFnTransform TransformNode(jointIt.currentItem());
// Joint NewJoint;
//
// if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") {
// if (SkeletonStorage.Joints.size() != 0) {
// m_AllSkeletons.push_back(SkeletonStorage);
//
// SkeletonStorage.Joints.clear();
// SkeletonStorage.Name.clear();
// }
//
// SkeletonStorage.Name = TransformNode.name().asChar();
//
// //NewJoint.ParentIndex = -1; // This joint is root
// }
//
// //NewJoint.Name = TransformNode.name().asChar();
//
// 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 j = 0; j < 4; j++) {
// NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
// }
// }
//
// SkeletonStorage.Joints.push_back(NewJoint);
//
// jointIt.next();
// }
//
// m_AllSkeletons.push_back(SkeletonStorage);
//
// return m_AllSkeletons;
//}
std::string attr[9] = { "scaleX", "scaleY", "scaleZ", "translateX", "translateY", "translateZ", "rotateX", "rotateY", "rotateZ" };
Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int endFrame)
{
std::vector<SkeletonNode> m_AllSkeletons;
Animation returnData;
double oneDivSixty = 1 / 60.0;
returnData.Name = animationName;
returnData.Duration = (endFrame - startFrame) * oneDivSixty;
std::vector<MObject> animatedJoints;
std::vector<MObject> m_Hierarchy;
MItDag jointIt(MItDag::TraversalType::kDepthFirst, MFn::kJoint);
SkeletonNode SkeletonStorage;
while (!jointIt.isDone())
{
m_Hierarchy.push_back(jointIt.item());
MFnDependencyNode depNode(jointIt.item());
for (int i = 0; i < 9; i++)
{
MStatus tmp;
MPlug plug = depNode.findPlug(attr[i].c_str(), &tmp);
MPlugArray connections;
plug.connectedTo(connections, true, false, 0);
for (int j = 0; j != connections.length(); j++) {
MObject connected = connections[j].node();
if (connected.hasFn(MFn::kAnimCurve)) {
MFnAnimCurve jointAnim(connected);
unsigned int startKeyFrameIndex = jointAnim.findClosest(MTime(startFrame, MTime::kNTSCField), &tmp);
if (tmp == MStatus::kFailure)
MGlobal::displayInfo(MString() + "Fail :c");
if (startFrame * oneDivSixty <= jointAnim.time(startKeyFrameIndex).value() && jointAnim.time(startKeyFrameIndex).value() <= endFrame * oneDivSixty) {
animatedJoints.push_back(jointIt.item());
i = 9;
break;
}
unsigned int endKeyFrameIndex = jointAnim.findClosest(MTime(endFrame, MTime::kNTSCField));
MGlobal::displayInfo(MString() + startKeyFrameIndex + " " + endKeyFrameIndex);
if (startFrame * oneDivSixty <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame * oneDivSixty || endKeyFrameIndex - startKeyFrameIndex > 0) {
animatedJoints.push_back(jointIt.item());
i = 9;
break;
}
MFnTransform MayaJoint(jointIt.item());
MPlug BindPose = MayaJoint.findPlug("bindPose");
MDataHandle DataHandle;
BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data());
MMatrix BindPoseMatrix = MartixFn.matrix();
if (BindPoseMatrix != MayaJoint.transformationMatrix())
{
MGlobal::displayError(MString() + animationName.c_str() + " is using a joint 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");
}
}
}
}
jointIt.next();
}
int currentFrame = startFrame;
while (currentFrame != endFrame) {
Animation::Keyframe thisKeyFrame;
thisKeyFrame.Index = currentFrame - startFrame;
thisKeyFrame.Time = thisKeyFrame.Index * oneDivSixty;
MAnimControl::setCurrentTime(MTime(currentFrame, MTime::kNTSCField));
MTime time = MAnimControl::currentTime();
for (auto aJoint : animatedJoints){
MFnTransform thisJoint(aJoint);
Animation::Keyframe::JointProperty joint;
auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), thisJoint.object());
if (it != m_Hierarchy.end()) {
joint.ID = it - m_Hierarchy.begin();
}
else {
MGlobal::displayError(MString() + "Could not find joint ID for: " + thisJoint.name());
}
MMatrix Matrix = thisJoint.transformationMatrix();
double tmp[4];
thisJoint.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
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);
joint.Position[0] = tmp[0];
joint.Position[1] = tmp[1];
joint.Position[2] = tmp[2];
thisJoint.getScale(tmp);
joint.Scale[0] = tmp[0];
joint.Scale[1] = tmp[1];
joint.Scale[2] = tmp[2];
thisKeyFrame.JointProperties.push_back(joint);
}
returnData.Keyframes.push_back(thisKeyFrame);
currentFrame++;
}
return returnData;
}
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 TransformNode(jointIt.currentItem());
Joint NewJoint;
MFnTransform MayaJoint(jointIt.currentItem());
BindPoseSkeletonNode::BindPoseJoint NewJoint;
if (MFnDependencyNode(TransformNode.parent(0)).name() == "world") {
if (MFnDependencyNode(MayaJoint.parent(0)).name() == "world") {
if (SkeletonStorage.Joints.size() != 0) {
m_AllSkeletons.push_back(SkeletonStorage);
SkeletonStorage.Joints.clear();
SkeletonStorage.Name.clear();
}
SkeletonStorage.Name = std::string(MayaJoint.name().asChar());
NewJoint.ParentID = -1; // This joint is root
}
else {
auto it = std::find(m_Hierarchy.begin(), m_Hierarchy.end(), MayaJoint.parent(0));
if (it != m_Hierarchy.end()) {
NewJoint.ParentID = it - m_Hierarchy.begin();
}
else {
MGlobal::displayError(MString() + "Could not find joint parent for: " + MayaJoint.name());
}
}
m_Hierarchy.push_back(MayaJoint.object());
SkeletonStorage.Name = TransformNode.name().asChar();
MPlug BindPose = MayaJoint.findPlug("bindPose");
MDataHandle DataHandle;
BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data());
MMatrix Matrix = MartixFn.matrix();
//NewJoint.ParentIndex = -1; // This joint is root
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
}
}
//NewJoint.Name = TransformNode.name().asChar();
MMatrix Matrix = TransformNode.transformationMatrix();
NewJoint.Name = MayaJoint.name().asChar();
//double tmp[3];
//((MTransformationMatrix)Matrix).eulerRotation().asVector().get(tmp);
@@ -44,89 +236,7 @@ std::vector<SkeletonNode> Skeleton::DoIt()
//NewJoint.Translation[0] = tmp[0];
//NewJoint.Translation[1] = tmp[1];
//NewJoint.Translation[2] = tmp[2];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
NewJoint.OffsetMatrix[i][j] = Matrix.matrix[i][j];
}
}
SkeletonStorage.Joints.push_back(NewJoint);
jointIt.next();
}
m_AllSkeletons.push_back(SkeletonStorage);
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();
}
+68 -49
View File
@@ -6,68 +6,81 @@
#include <algorithm>
#include "MayaIncludes.h"
#include "OutputData.h"
class Joint : public OutputData{
class Animation : public OutputData {
public:
//Joint() : OutputData((Joint)*this)
//{};
//int ParentIndex;
//std::array<float, 3> Rotation;
//std::array<float, 3> Translation;
//std::array<float, 3> Scale;
//std::array<std::array<float, 4>, 4> OffsetMatrix;
float OffsetMatrix[4][4];
virtual void WriteBinary(std::ostream& out)
struct Keyframe
{
out.write((char*)OffsetMatrix, 4 * 4 * sizeof(float));
}
virtual void WriteASCII(std::ostream& out) const
{
for (int i = 0; i < 4; i++)
struct JointProperty
{
for (int k = 0; k < 4; k++)
out << this->OffsetMatrix[i][k] << " ";
out << endl;
}
};
};
int ID;
float Position[3];
float Rotation[4];
float Scale[3];
};
int Index;
double Time;
std::vector<JointProperty> JointProperties;
};
class SkeletonNode : public OutputData {
public:
std::string Name;
std::vector<Joint> Joints;
double Duration;
std::vector<Keyframe> Keyframes;
virtual void WriteBinary(std::ostream& out)
{
out.write(Name.c_str(), Name.size());
for (auto aJoint : Joints)
{
aJoint.WriteBinary(out);
out.write(Name.c_str(), Name.size() + 1);
out.write((char*)&Duration, sizeof(double));
for (auto aKeyframe : Keyframes) {
out.write((char*)&aKeyframe.Index, sizeof(int));
out.write((char*)&aKeyframe.Time, sizeof(double));
for (auto aJoint : aKeyframe.JointProperties) {
out.write((char*)&aJoint.ID, sizeof(int));
out.write((char*)aJoint.Position, sizeof(float) * 3);
out.write((char*)aJoint.Rotation, sizeof(float) * 4);
out.write((char*)aJoint.Scale, sizeof(float) * 3);
}
}
}
virtual void WriteASCII(std::ostream& out) const
{
out << "Skeleton: " << Name << endl;
for (auto aJoint : Joints)
{
aJoint.WriteASCII(out);
out << "Animation Name: " << Name << endl;
out << "Duration: " << Duration << endl;
for (auto aKeyframe : Keyframes) {
out << "Frame: " << aKeyframe.Index << endl;
out << "Time: " << aKeyframe.Time << endl;
for (auto aJoint : aKeyframe.JointProperties) {
out << "Joint ID: " << aJoint.ID << endl;
out << aJoint.Position[0] << " " << aJoint.Position[1] << " " << aJoint.Position[2] << endl;
out << aJoint.Rotation[0] << " " << aJoint.Rotation[1] << " " << aJoint.Rotation[2] << " " << aJoint.Rotation[3] << endl;
out << aJoint.Scale[0] << " " << aJoint.Scale[1] << " " << aJoint.Scale[2] << endl;
}
}
};
}
};
class BindPoseSkeletonNode : public SkeletonNode {
class BindPoseSkeletonNode : public OutputData {
public:
std::vector<int> ParentIDs;
std::vector<std::string> JointNames;
struct BindPoseJoint
{
int ParentID;
std::string Name;
float OffsetMatrix[4][4];
};
std::string Name;
std::vector<BindPoseJoint> Joints;
virtual void WriteBinary(std::ostream& out)
{
out.write(Name.c_str(), Name.size());
for (int i = 0; i < Joints.size(); i++)
{
out.write((char*)&ParentIDs[i],sizeof(int));
Joints[i].WriteBinary(out);
out.write(JointNames[i].c_str(), JointNames[i].size());
out.write(Name.c_str(), Name.size() + 1);
for (auto Joint:Joints)
{
out.write(Joint.Name.c_str(), Joint.Name.size() + 1);
out.write((char*)&Joint.OffsetMatrix, sizeof(float) * 4 * 4);
out.write((char*)&Joint.ParentID, sizeof(int));
}
}
@@ -75,18 +88,24 @@ public:
virtual void WriteASCII(std::ostream& out) const
{
out << "Bind Pose: " << Name << endl;
for (int i = 0; i < Joints.size(); i++)
for (auto Joint : Joints)
{
out << ParentIDs[i] << endl;
Joints[i].WriteASCII(out);
out << JointNames[i] << endl;
out << 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.ParentID << endl;
}
};
};
class Skeleton {
public:
std::vector<SkeletonNode> DoIt();
//std::vector<SkeletonNode> DoIt();
Animation GetAnimData(std::string animationName, int startFrame, int endFrame);
std::vector<BindPoseSkeletonNode> GetBindPoses();
private:
};