Fixed Git's shitty merge in Skeleton.cpp and The Exporter now Exports meshes with and without skins

This commit is contained in:
Teejoon
2016-02-02 10:19:00 +01:00
parent bbbebe077b
commit 9573958a86
3 changed files with 41 additions and 27 deletions
+6 -4
View File
@@ -108,7 +108,6 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
MFnDependencyNode thisNode(node); MFnDependencyNode thisNode(node);
MPlugArray connections; MPlugArray connections;
thisNode.findPlug("inMesh").connectedTo(connections, true, true); thisNode.findPlug("inMesh").connectedTo(connections, true, true);
bool hasSkin = false;
MPlug weightList, weights; MPlug weightList, weights;
MObject weightListObject; MObject weightListObject;
for (unsigned int i = 0; i < connections.length(); i++) { for (unsigned int i = 0; i < connections.length(); i++) {
@@ -117,7 +116,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
weightList = skinCluster.findPlug("weightList", &status); weightList = skinCluster.findPlug("weightList", &status);
weightListObject = weightList.attribute(); weightListObject = weightList.attribute();
weights = skinCluster.findPlug("weights"); weights = skinCluster.findPlug("weights");
hasSkin = true; newMesh.hasSkin = true;
break; break;
} }
} }
@@ -301,7 +300,8 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
thisVertex.Uv[1] = UV[1]; thisVertex.Uv[1] = UV[1];
if (hasSkin) { if (newMesh.hasSkin) {
thisVertex.useWeights = true;
float totalWeight = 0.0f; float totalWeight = 0.0f;
unsigned int totalBones = 0; unsigned int totalBones = 0;
MIntArray jointIDs /* ??? */; MIntArray jointIDs /* ??? */;
@@ -319,7 +319,9 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
for (unsigned int i = 0; i < 4; i++) { for (unsigned int i = 0; i < 4; i++) {
thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight; thisVertex.BoneWeights[i] = thisVertex.BoneWeights[i] / totalWeight;
} }
} } else {
thisVertex.useWeights = false;
}
//float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3]; //float totalWeight = thisVertex.BoneWeights[0] + thisVertex.BoneWeights[1] + thisVertex.BoneWeights[2] + thisVertex.BoneWeights[3];
//if (totalWeight > 0.0001f) { //if (totalWeight > 0.0001f) {
+16 -4
View File
@@ -11,6 +11,7 @@
class VertexLayout : public OutputData class VertexLayout : public OutputData
{ {
public: public:
bool useWeights = true;
float Pos[3]{ 0 }; float Pos[3]{ 0 };
float Normal[3]{ 0 }; float Normal[3]{ 0 };
float Tangent[3]{ 0 }; float Tangent[3]{ 0 };
@@ -26,8 +27,10 @@ public:
out.write((char*)&Tangent, sizeof(float) * 3); out.write((char*)&Tangent, sizeof(float) * 3);
out.write((char*)&BiNormal, sizeof(float) * 3); out.write((char*)&BiNormal, sizeof(float) * 3);
out.write((char*)&Uv, sizeof(float) * 2); out.write((char*)&Uv, sizeof(float) * 2);
out.write((char*)&BoneIndices, sizeof(float) * 4); if (useWeights) {
out.write((char*)&BoneWeights, sizeof(float) * 4); out.write((char*)&BoneIndices, sizeof(float) * 4);
out.write((char*)&BoneWeights, sizeof(float) * 4);
}
} }
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
@@ -37,8 +40,10 @@ public:
out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl; out << Tangent[0] << " " << Tangent[1] << " " << Tangent[2] << endl;
out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl; out << BiNormal[0] << " " << BiNormal[1] << " " << BiNormal[2] << endl;
out << Uv[0] << " " << Uv[1] << endl; out << Uv[0] << " " << Uv[1] << endl;
out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl; if (useWeights) {
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl; out << BoneIndices[0] << " " << BoneIndices[1] << " " << BoneIndices[2] << " " << BoneIndices[3] << endl;
out << BoneWeights[0] << " " << BoneWeights[1] << " " << BoneWeights[2] << " " << BoneWeights[3] << endl;
}
} }
bool operator==(const VertexLayout& right) bool operator==(const VertexLayout& right)
@@ -57,6 +62,7 @@ public:
class Mesh : public OutputData { class Mesh : public OutputData {
public: public:
bool hasSkin = false;
unsigned int NumVertices; unsigned int NumVertices;
unsigned int NumIndices; unsigned int NumIndices;
std::vector<VertexLayout> Vertices; std::vector<VertexLayout> Vertices;
@@ -64,6 +70,7 @@ public:
virtual void WriteBinary(std::ostream& out) virtual void WriteBinary(std::ostream& out)
{ {
out.write((char*)&hasSkin, sizeof(bool));
out.write((char*)&NumVertices, sizeof(int)); out.write((char*)&NumVertices, sizeof(int));
out.write((char*)&NumIndices, sizeof(int)); out.write((char*)&NumIndices, sizeof(int));
for (auto aVertex : Vertices) { for (auto aVertex : Vertices) {
@@ -79,6 +86,11 @@ public:
virtual void WriteASCII(std::ostream& out) const virtual void WriteASCII(std::ostream& out) const
{ {
out << "New Mesh _ not in binary" << endl; out << "New Mesh _ not in binary" << endl;
out << "hasSkin: ";
if(hasSkin)
out << "true" << endl;
else
out << "false" << endl;
out << "Number of vertices: " << NumVertices << endl; out << "Number of vertices: " << NumVertices << endl;
out << "number of indices: " << NumIndices << endl; out << "number of indices: " << NumIndices << endl;
int vertexNumber = 0; int vertexNumber = 0;
+19 -19
View File
@@ -186,29 +186,29 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
/*MGlobal::displayInfo(MString() + "start keyfram index: " + startKeyFrameIndex + ". End keyfram index: " + endKeyFrameIndex + ".");*/ /*MGlobal::displayInfo(MString() + "start keyfram index: " + startKeyFrameIndex + ". End keyfram index: " + endKeyFrameIndex + ".");*/
if (startFrame <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame || endKeyFrameIndex - startKeyFrameIndex > 0) { // if (startFrame <= jointAnim.time(endKeyFrameIndex).value() && jointAnim.time(endKeyFrameIndex).value() <= endFrame || endKeyFrameIndex - startKeyFrameIndex > 0) {
animatedJoints.push_back(jointIt.item()); // animatedJoints.push_back(jointIt.item());
i = 9; // i = 9;
break; // break;
} // }
MFnTransform MayaJoint(jointIt.item()); // MFnTransform MayaJoint(jointIt.item());
MPlug BindPose = MayaJoint.findPlug("bindPose"); // MPlug BindPose = MayaJoint.findPlug("bindPose");
MDataHandle DataHandle; // MDataHandle DataHandle;
BindPose.getValue(DataHandle); // BindPose.getValue(DataHandle);
MFnMatrixData MartixFn(DataHandle.data()); // MFnMatrixData MartixFn(DataHandle.data());
MMatrix BindPoseMatrix = MartixFn.matrix(); // MMatrix BindPoseMatrix = MartixFn.matrix();
if (!BindPoseMatrix.isEquivalent(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");
} // }
} // }
} // }
}*/ // }
} // end of int i loop //} // end of int i loop
jointIt.next(); jointIt.next();
} }
jointIt.reset(); jointIt.reset();