Splatmapping now working.
Rendering pipleline now support 3 different types of Material: Basic: a material with a single color on every property (diffuse, specular, ect). SingleTextures: a material with a single texture in all or any property. Have a single color on the rest. SplatMapping: has a SplatMap and 0 to 5 different textures to every property. Properties with o texture uses a single color insted. All materials with a texture has a UVRepeat, telling how many time to till in U and in V. modelJobs now uses ShadeID, ModelID and TextureID for the Hash insted of only Texture MayaExported exports 3 differnt types of material, the same as the piplen now supports.
This commit is contained in:
@@ -88,14 +88,30 @@ bool Material::findColorTexture(MaterialNode& material_node, MFnDependencyNode&
|
||||
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
|
||||
newTexture.FileNameLength = newTexture.FileName.length() + 1;
|
||||
|
||||
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat();
|
||||
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
|
||||
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
|
||||
|
||||
uvRepeatFile.connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
|
||||
MFnDependencyNode place2DTexture(AllConnections[i].node());
|
||||
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
|
||||
|
||||
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
|
||||
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
|
||||
}
|
||||
}
|
||||
|
||||
material_node.ColorMaps.push_back(newTexture);
|
||||
if(material_node.type == MaterialNode::MaterialType::Basic)
|
||||
material_node.type = MaterialNode::MaterialType::SingleTextures;
|
||||
return true;
|
||||
|
||||
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
|
||||
MGlobal::displayInfo(MString() + "find splat map");
|
||||
return findSplatTextures(material_node, material_node.ColorMaps, MFnDependencyNode(AllConnections[i].node()));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -130,11 +146,25 @@ bool Material::findNormalTexture(MaterialNode& material_node, MFnDependencyNode&
|
||||
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
|
||||
newTexture.FileNameLength = newTexture.FileName.length() + 1;
|
||||
|
||||
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat();
|
||||
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
|
||||
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
|
||||
|
||||
uvRepeatFile.connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
|
||||
MFnDependencyNode place2DTexture(AllConnections[i].node());
|
||||
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
|
||||
|
||||
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
|
||||
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
|
||||
}
|
||||
}
|
||||
|
||||
material_node.NormalMaps.push_back(newTexture);
|
||||
return true;
|
||||
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
|
||||
MGlobal::displayInfo(MString() + "find splat map");
|
||||
return findSplatTextures(material_node, material_node.NormalMaps, MFnDependencyNode(AllConnections[i].node()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,11 +198,28 @@ bool Material::findSpecularTexture(MaterialNode& material_node, MFnDependencyNod
|
||||
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
|
||||
newTexture.FileNameLength = newTexture.FileName.length() + 1;
|
||||
|
||||
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat();
|
||||
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
|
||||
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
|
||||
|
||||
uvRepeatFile.connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
|
||||
//C:\Users\kamisama\Desktop\TacticalZ\assets\test
|
||||
MFnDependencyNode place2DTexture(AllConnections[i].node());
|
||||
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
|
||||
|
||||
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
|
||||
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
|
||||
}
|
||||
}
|
||||
|
||||
material_node.SpecularMaps.push_back(newTexture);
|
||||
if (material_node.type == MaterialNode::MaterialType::Basic)
|
||||
material_node.type = MaterialNode::MaterialType::SingleTextures;
|
||||
return true;
|
||||
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
|
||||
MGlobal::displayInfo(MString() + "find splat map");
|
||||
return findSplatTextures(material_node, material_node.SpecularMaps, MFnDependencyNode(AllConnections[i].node()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -203,21 +250,133 @@ bool Material::findIncandescenceTexture(MaterialNode& material_node, MFnDependen
|
||||
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
|
||||
newTexture.FileNameLength = newTexture.FileName.length() + 1;
|
||||
|
||||
newTexture.UVTiling[0] = TextureNode.findPlug("RepeatU").asFloat();
|
||||
newTexture.UVTiling[1] = TextureNode.findPlug("RepeatV").asFloat();
|
||||
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
|
||||
|
||||
uvRepeatFile.connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
|
||||
MFnDependencyNode place2DTexture(AllConnections[i].node());
|
||||
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
|
||||
|
||||
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
|
||||
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
|
||||
}
|
||||
}
|
||||
|
||||
material_node.IncandescenceMaps.push_back(newTexture);
|
||||
if (material_node.type == MaterialNode::MaterialType::Basic)
|
||||
material_node.type = MaterialNode::MaterialType::SingleTextures;
|
||||
return true;
|
||||
|
||||
} else if (AllConnections[i].node().hasFn(MFn::kLayeredTexture)) {
|
||||
return findSplatTextures(material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node()));
|
||||
MGlobal::displayInfo(MString() + "find splat map");
|
||||
return findSplatTextures(material_node, material_node.IncandescenceMaps, MFnDependencyNode(AllConnections[i].node()));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Material::findSplatTextures(std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node) {
|
||||
return false;
|
||||
//C:\Users\kamisama\Desktop\TacticalZ\assets\test
|
||||
|
||||
bool Material::findSplatTextures(MaterialNode& material_node, std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node) {
|
||||
//Get all Inputs in LayeredTexture
|
||||
MPlug inputs = node.findPlug("inputs");
|
||||
MGlobal::displayInfo(MString() + "inputs.numElements(): " + inputs.numElements());
|
||||
|
||||
MPlugArray AllConnections;
|
||||
MStatus test;
|
||||
//Try to find splat texture if using custom splatmap build up.
|
||||
inputs[0].child(1).connectedTo(AllConnections, true, false);
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kMultiplyDivide)) {
|
||||
MGlobal::displayInfo(MString() + "found kMultiplyDivide");
|
||||
MFnDependencyNode multiplyDivide(AllConnections[i].node());
|
||||
multiplyDivide.findPlug("input1", &test).child(0).connectedTo(AllConnections, true, false);;
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kFileTexture)) {
|
||||
MFnDependencyNode TextureNode(AllConnections[i].node());
|
||||
|
||||
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
|
||||
m_TexturePaths.push_back(FullPath);
|
||||
|
||||
MString workspace;
|
||||
MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"),
|
||||
workspace);
|
||||
FullPath = FullPath.substr(workspace.length());
|
||||
FullPath = FullPath.substr(FullPath.find_first_of("/") + 1);
|
||||
|
||||
MaterialNode::Texture newTexture;
|
||||
|
||||
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
|
||||
newTexture.FileNameLength = newTexture.FileName.length() + 1;
|
||||
|
||||
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
|
||||
|
||||
uvRepeatFile.connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
|
||||
MFnDependencyNode place2DTexture(AllConnections[i].node());
|
||||
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
|
||||
|
||||
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
|
||||
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
|
||||
}
|
||||
}
|
||||
material_node.SplatMap = newTexture;
|
||||
material_node.type = MaterialNode::MaterialType::SplatMapping;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < inputs.numElements(); i++) {
|
||||
//Get connections to color in input[i]
|
||||
inputs[i].child(0).connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kFileTexture)) {
|
||||
MFnDependencyNode TextureNode(AllConnections[i].node());
|
||||
|
||||
std::string FullPath = TextureNode.findPlug("ftn").asString().asChar();
|
||||
m_TexturePaths.push_back(FullPath);
|
||||
|
||||
MString workspace;
|
||||
MStatus status = MGlobal::executeCommand(MString("workspace -q -rd;"),
|
||||
workspace);
|
||||
FullPath = FullPath.substr(workspace.length());
|
||||
FullPath = FullPath.substr(FullPath.find_first_of("/") + 1);
|
||||
|
||||
MaterialNode::Texture newTexture;
|
||||
|
||||
newTexture.FileName = FullPath.erase(FullPath.find_last_of("."), FullPath.find_last_of(".") - FullPath.size());
|
||||
newTexture.FileNameLength = newTexture.FileName.length() + 1;
|
||||
|
||||
MPlug uvRepeatFile = TextureNode.findPlug("repeatUV");
|
||||
|
||||
uvRepeatFile.connectedTo(AllConnections, true, false);
|
||||
|
||||
for (int i = 0; i < AllConnections.length(); i++) {
|
||||
if (AllConnections[i].node().hasFn(MFn::kPlace2dTexture)) {
|
||||
MFnDependencyNode place2DTexture(AllConnections[i].node());
|
||||
MPlug uvRepeat = place2DTexture.findPlug("repeatUV");
|
||||
|
||||
newTexture.UVTiling[0] = uvRepeat.child(0).asFloat();
|
||||
newTexture.UVTiling[1] = uvRepeat.child(1).asFloat();
|
||||
}
|
||||
}
|
||||
textureVector.push_back(newTexture);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (AllConnections.length() == 0) {
|
||||
MaterialNode::Texture newTexture;
|
||||
newTexture.FileNameLength = 0;
|
||||
textureVector.push_back(newTexture);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Returns the absolute path for all textures. Use for copying texture files.
|
||||
@@ -244,8 +403,6 @@ std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
|
||||
meshHasMaterial = true;
|
||||
MaterialStorage.IndexStart = totalIndices;
|
||||
MaterialStorage.IndexEnd = totalIndices + aMeshMaterial.second.size() - 1;
|
||||
MGlobal::displayInfo("Oh noes, breaking in material");
|
||||
break;
|
||||
}
|
||||
totalIndices += aMeshMaterial.second.size();
|
||||
}
|
||||
@@ -262,7 +419,10 @@ std::vector<MaterialNode>* Material::DoIt(Mesh mesh)
|
||||
MaterialStorage.ReflectionFactor = 0.0f;
|
||||
MaterialStorage.SpecularExponent = 0.0f;
|
||||
}
|
||||
|
||||
MaterialStorage.NumColorMaps = MaterialStorage.ColorMaps.size();
|
||||
MaterialStorage.NumNormalMaps = MaterialStorage.NormalMaps.size();
|
||||
MaterialStorage.NumSpecularMaps = MaterialStorage.SpecularMaps.size();
|
||||
MaterialStorage.NumIncandescenceMaps = MaterialStorage.IncandescenceMaps.size();
|
||||
m_AllMaterials.push_back(MaterialStorage);
|
||||
}
|
||||
matIt.next();
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
//#define NormalMapSplat 1 << 2
|
||||
//#define IncandescenceMapSplat 1 << 3
|
||||
|
||||
|
||||
|
||||
class MaterialNode : public OutputData
|
||||
{
|
||||
public:
|
||||
@@ -41,6 +43,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
enum class MaterialType { Basic = 1, SplatMapping, SingleTextures };
|
||||
|
||||
MaterialType type = MaterialType::Basic;
|
||||
|
||||
std::string Name;
|
||||
|
||||
float ReflectionFactor;
|
||||
@@ -53,11 +59,11 @@ public:
|
||||
unsigned int IndexStart;
|
||||
unsigned int IndexEnd;
|
||||
|
||||
char NumColormaps = 0;
|
||||
char NumSpecularMap = 0;
|
||||
char NumNormalMap = 0;
|
||||
char NumIncandescenceMap = 0;
|
||||
|
||||
unsigned char NumColorMaps = 0;
|
||||
unsigned char NumSpecularMaps = 0;
|
||||
unsigned char NumNormalMaps = 0;
|
||||
unsigned char NumIncandescenceMaps = 0;
|
||||
Texture SplatMap;
|
||||
std::vector<Texture> ColorMaps;
|
||||
std::vector<Texture> SpecularMaps;
|
||||
std::vector<Texture> NormalMaps;
|
||||
@@ -65,6 +71,8 @@ public:
|
||||
|
||||
virtual void WriteBinary(std::ostream& out)
|
||||
{
|
||||
|
||||
out.write((char*)&type, sizeof(MaterialType));
|
||||
out.write((char*)&SpecularExponent, sizeof(float));
|
||||
out.write((char*)&ReflectionFactor, sizeof(float));
|
||||
|
||||
@@ -74,30 +82,52 @@ public:
|
||||
|
||||
out.write((char*)&IndexStart, sizeof(unsigned int));
|
||||
out.write((char*)&IndexEnd, sizeof(unsigned int));
|
||||
if (type != MaterialType::Basic) {
|
||||
if (type == MaterialType::SplatMapping) {
|
||||
SplatMap.WriteBinary(out);
|
||||
}
|
||||
out.write((char*)&NumColorMaps, sizeof(unsigned char));
|
||||
out.write((char*)&NumSpecularMaps, sizeof(unsigned char));
|
||||
out.write((char*)&NumNormalMaps, sizeof(unsigned char));
|
||||
out.write((char*)&NumIncandescenceMaps, sizeof(unsigned char));
|
||||
}
|
||||
|
||||
out.write((char*)&NumColormaps, sizeof(char));
|
||||
out.write((char*)&NumSpecularMap, sizeof(char));
|
||||
out.write((char*)&NumNormalMap, sizeof(char));
|
||||
out.write((char*)&NumIncandescenceMap, sizeof(char));
|
||||
|
||||
for(auto aTexture : ColorMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
for (auto aTexture : SpecularMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
for (auto aTexture : NormalMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
for (auto aTexture : IncandescenceMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
if (type != MaterialType::Basic) {
|
||||
for (auto aTexture : ColorMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
for (auto aTexture : SpecularMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
for (auto aTexture : NormalMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
for (auto aTexture : IncandescenceMaps) {
|
||||
aTexture.WriteBinary(out);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void WriteASCII(std::ostream& out) const
|
||||
{
|
||||
out << "New Material _ not in binary" << endl;
|
||||
out << "number of indices: " << Name << " _ not in binary" << endl;
|
||||
|
||||
out << "MaterialType(enum): ";
|
||||
switch (type) {
|
||||
case MaterialType::Basic:
|
||||
out << "Basic";
|
||||
break;
|
||||
case MaterialType::SplatMapping:
|
||||
out << "SplatMapping";
|
||||
break;
|
||||
case MaterialType::SingleTextures:
|
||||
out << "SingleTextures";
|
||||
break;
|
||||
};
|
||||
|
||||
out << endl;
|
||||
|
||||
out << "Material Name: " << Name << " _ not in binary" << endl;
|
||||
|
||||
out << "SpecularExponent: " << SpecularExponent << endl;
|
||||
out << "ReflectionFactor: " << ReflectionFactor << endl;
|
||||
@@ -107,37 +137,38 @@ public:
|
||||
out << "IndexStart: " << IndexStart << endl;
|
||||
out << "IndexEnd: " << IndexEnd << endl;
|
||||
|
||||
if (NumColormaps > 0)
|
||||
out << "NumColormaps: " << NumColormaps << endl;
|
||||
switch (type) {
|
||||
case MaterialType::SplatMapping:
|
||||
out << "SplatMap _ not in binary " << endl;
|
||||
SplatMap.WriteASCII(out);
|
||||
//Intended fall trought
|
||||
case MaterialType::SingleTextures:
|
||||
out << "NumColormaps (is unsigned char in Binary): " << ((unsigned int)NumColorMaps) << endl;
|
||||
out << "NumSpecularMap (is unsigned char in Binary): " << ((unsigned int)NumSpecularMaps) << endl;
|
||||
out << "NumNormalMap (is unsigned char in Binary): " << ((unsigned int)NumNormalMaps) << endl;
|
||||
out << "NumIncandescenceMap (is unsigned char in Binary): " << ((unsigned int)NumIncandescenceMaps )<< endl;
|
||||
|
||||
if (NumSpecularMap > 0)
|
||||
out << "NumSpecularMap: " << NumSpecularMap << endl;
|
||||
|
||||
if (NumNormalMap > 0)
|
||||
out << "NumNormalMap: " << NumNormalMap << endl;
|
||||
|
||||
if (NumIncandescenceMap > 0)
|
||||
out << "NumIncandescenceMap: " << NumIncandescenceMap << endl;
|
||||
out << "ColorMaps _ not in binary " << endl;
|
||||
for (auto aTexture : ColorMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
|
||||
out << "ColorMaps _ not in binary " << endl;
|
||||
for (auto aTexture : ColorMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
out << "SpecularMaps _ not in binary " << endl;
|
||||
for (auto aTexture : SpecularMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
|
||||
out << "SpecularMaps _ not in binary " << endl;
|
||||
for (auto aTexture : SpecularMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
out << "NormalMaps _ not in binary " << endl;
|
||||
for (auto aTexture : NormalMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
|
||||
out << "NormalMaps _ not in binary " << endl;
|
||||
for (auto aTexture : NormalMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
|
||||
out << "IncandescenceMaps _ not in binary " << endl;
|
||||
for (auto aTexture : IncandescenceMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
out << "IncandescenceMaps _ not in binary " << endl;
|
||||
for (auto aTexture : IncandescenceMaps) {
|
||||
aTexture.WriteASCII(out);
|
||||
}
|
||||
break;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -158,7 +189,7 @@ private:
|
||||
bool findNormalTexture(MaterialNode& material_node, MFnDependencyNode& node);
|
||||
bool findSpecularTexture(MaterialNode& material_node, MFnDependencyNode& node);
|
||||
bool findIncandescenceTexture(MaterialNode& material_node, MFnDependencyNode& node);
|
||||
bool findSplatTextures(std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node);
|
||||
bool findSplatTextures(MaterialNode& material_node, std::vector<MaterialNode::Texture>& textureVector, MFnDependencyNode& node);
|
||||
void grabLambertProperties(MaterialNode& material_node, MFnDependencyNode& node);
|
||||
void grabBlinnProperties(MaterialNode& material_node, MFnDependencyNode& node);
|
||||
void grabPhongProperties(MaterialNode& material_node, MFnDependencyNode& node);
|
||||
|
||||
@@ -8,91 +8,91 @@ MeshClass::MeshClass()
|
||||
|
||||
}
|
||||
|
||||
std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
|
||||
{
|
||||
MS status;
|
||||
map<int, WeightInfo> weightMap;
|
||||
|
||||
MItDependencyNodes it(MFn::kSkinClusterFilter);
|
||||
|
||||
while (!it.isDone()) {
|
||||
|
||||
MObject object = it.thisNode(&status);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + " it.thisNode() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
MFnSkinCluster skinCluster(object, &status);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + "skinCluster() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
MDagPathArray influences;
|
||||
|
||||
unsigned int nrOfInfluences = skinCluster.influenceObjects(influences,&status);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + "skinCluster.influenceObjects() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
|
||||
unsigned int index;
|
||||
index = skinCluster.indexForOutputConnection(0,&status);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + "skinCluster.indexForOutputConnection() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
MDagPath skinPath;
|
||||
status = skinCluster.getPathAtIndex(index, skinPath);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + "skinCluster.getPathAtIndex() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
|
||||
MItGeometry geomIter(skinPath);
|
||||
//for (unsigned int i = 0; i < nrOfInfluences; i++) {
|
||||
// MGlobal::displayInfo(MString() + " Influence object name: " + influences[i].partialPathName().asChar());
|
||||
//}
|
||||
WeightInfo weightInfo;
|
||||
|
||||
while (!geomIter.isDone()) {
|
||||
MObject comp = geomIter.component(&status);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + "geomIter.component() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
MFloatArray weights;
|
||||
unsigned int influenceCount;
|
||||
status = skinCluster.getWeights(skinPath, comp, weights, influenceCount);
|
||||
if (status != MS::kSuccess) {
|
||||
MGlobal::displayError(MString() + "skinCluster.getWeights() ERROR: " + status.errorString());
|
||||
break;
|
||||
}
|
||||
MFnDependencyNode test(comp);
|
||||
unsigned int nrOfWeights = 0;
|
||||
|
||||
for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) {
|
||||
if (weights[j] > 0.00001) {
|
||||
weightInfo.BoneWeights[nrOfWeights] = weights[j];
|
||||
weightInfo.BoneIndices[nrOfWeights] = j;
|
||||
nrOfWeights++;
|
||||
}
|
||||
}
|
||||
|
||||
float totalWeight = 0.0f;
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
totalWeight += weightInfo.BoneWeights[i];
|
||||
}
|
||||
for (unsigned int i = 0; i < 4; i++) {
|
||||
weightInfo.BoneWeights[i] /= totalWeight;
|
||||
}
|
||||
weightMap[geomIter.index()] = weightInfo;
|
||||
|
||||
geomIter.next();
|
||||
}
|
||||
it.next();
|
||||
}
|
||||
return weightMap;
|
||||
}
|
||||
//std::map<int, MeshClass::WeightInfo> MeshClass::GetWeightData()
|
||||
//{
|
||||
// MS status;
|
||||
// map<int, WeightInfo> weightMap;
|
||||
//
|
||||
// MItDependencyNodes it(MFn::kSkinClusterFilter);
|
||||
//
|
||||
// while (!it.isDone()) {
|
||||
//
|
||||
// MObject object = it.thisNode(&status);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + " it.thisNode() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
// MFnSkinCluster skinCluster(object, &status);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + "skinCluster() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
// MDagPathArray influences;
|
||||
//
|
||||
// unsigned int nrOfInfluences = skinCluster.influenceObjects(influences,&status);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + "skinCluster.influenceObjects() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// unsigned int index;
|
||||
// index = skinCluster.indexForOutputConnection(0,&status);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + "skinCluster.indexForOutputConnection() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
// MDagPath skinPath;
|
||||
// status = skinCluster.getPathAtIndex(index, skinPath);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + "skinCluster.getPathAtIndex() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// MItGeometry geomIter(skinPath);
|
||||
// //for (unsigned int i = 0; i < nrOfInfluences; i++) {
|
||||
// // MGlobal::displayInfo(MString() + " Influence object name: " + influences[i].partialPathName().asChar());
|
||||
// //}
|
||||
// WeightInfo weightInfo;
|
||||
//
|
||||
// while (!geomIter.isDone()) {
|
||||
// MObject comp = geomIter.component(&status);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + "geomIter.component() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
// MFloatArray weights;
|
||||
// unsigned int influenceCount;
|
||||
// status = skinCluster.getWeights(skinPath, comp, weights, influenceCount);
|
||||
// if (status != MS::kSuccess) {
|
||||
// MGlobal::displayError(MString() + "skinCluster.getWeights() ERROR: " + status.errorString());
|
||||
// break;
|
||||
// }
|
||||
// MFnDependencyNode test(comp);
|
||||
// unsigned int nrOfWeights = 0;
|
||||
//
|
||||
// for (unsigned int j = 0; j < weights.length() && nrOfWeights != 4; j++) {
|
||||
// if (weights[j] > 0.00001) {
|
||||
// weightInfo.BoneWeights[nrOfWeights] = weights[j];
|
||||
// weightInfo.BoneIndices[nrOfWeights] = j;
|
||||
// nrOfWeights++;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// float totalWeight = 0.0f;
|
||||
// for (unsigned int i = 0; i < 4; i++) {
|
||||
// totalWeight += weightInfo.BoneWeights[i];
|
||||
// }
|
||||
// for (unsigned int i = 0; i < 4; i++) {
|
||||
// weightInfo.BoneWeights[i] /= totalWeight;
|
||||
// }
|
||||
// weightMap[geomIter.index()] = weightInfo;
|
||||
//
|
||||
// geomIter.next();
|
||||
// }
|
||||
// it.next();
|
||||
// }
|
||||
// return weightMap;
|
||||
//}
|
||||
|
||||
Mesh MeshClass::GetMeshData(MObjectArray object)
|
||||
{
|
||||
@@ -317,7 +317,7 @@ Mesh MeshClass::GetMeshData(MObjectArray object)
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
|
||||
class Mesh : public OutputData {
|
||||
public:
|
||||
bool hasSkin = false;
|
||||
bool hasSkin = true; //Should be false by default... Have it true now since pipeline only support skinned vertecies
|
||||
unsigned int NumVertices;
|
||||
unsigned int NumIndices;
|
||||
std::vector<VertexLayout> Vertices;
|
||||
|
||||
@@ -230,7 +230,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
MTime time = MAnimControl::currentTime();
|
||||
|
||||
MFnTransform thisJoint(jointIt.currentItem());
|
||||
MTransformationMatrix TransformationMatrix = thisJoint.transformationMatrix();
|
||||
MTransformationMatrix transformationMatrix = thisJoint.transformationMatrix();
|
||||
|
||||
double doubleMat[4][4];
|
||||
|
||||
@@ -256,7 +256,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
|
||||
MMatrix LastJointMatrix(doubleMat);
|
||||
//Is same as last KeyFrame
|
||||
if (LastJointMatrix.isEquivalent(transformationMatrix)) {
|
||||
if (LastJointMatrix.isEquivalent(transformationMatrix.asMatrix())) {
|
||||
//jointID++;
|
||||
//jointIt.next();
|
||||
currentFrame++;
|
||||
@@ -264,7 +264,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
continue;
|
||||
} else if(!haxBool){
|
||||
haxBool = true;
|
||||
MTransformationMatrix TransformationMatrix = LastJointMatrix;
|
||||
MTransformationMatrix LastJointTransformationMatrix = LastJointMatrix;
|
||||
MObject jointOrientObj = thisJoint.attribute("jointOrient");
|
||||
MFnNumericAttribute jointOrient(jointOrientObj);
|
||||
double jointOrientDouble[3];
|
||||
@@ -279,7 +279,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
MQuaternion jo = joEuler.asQuaternion();
|
||||
|
||||
double tmp[4];
|
||||
TransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||
LastJointTransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||
MQuaternion rotation(tmp);
|
||||
|
||||
rotation = rotation * jo;
|
||||
@@ -294,11 +294,11 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
previousKeyFrame.Rotation[1] = tmp[1];
|
||||
previousKeyFrame.Rotation[2] = tmp[2];
|
||||
previousKeyFrame.Rotation[3] = tmp[3];
|
||||
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||
LastJointTransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||
previousKeyFrame.Position[0] = tmp[0];
|
||||
previousKeyFrame.Position[1] = tmp[1];
|
||||
previousKeyFrame.Position[2] = tmp[2];
|
||||
TransformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||
LastJointTransformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||
previousKeyFrame.Scale[0] = tmp[0];
|
||||
previousKeyFrame.Scale[1] = tmp[1];
|
||||
previousKeyFrame.Scale[2] = tmp[2];
|
||||
@@ -307,7 +307,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
}
|
||||
}
|
||||
|
||||
transformationMatrix.get(doubleMat);
|
||||
transformationMatrix.asMatrix().get(doubleMat);
|
||||
|
||||
//Save transformationMatrix to joinCheckMap
|
||||
joinCheckMap[thisJoint.name().asChar()][0][0] = doubleMat[0][0];
|
||||
@@ -327,8 +327,6 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
joinCheckMap[thisJoint.name().asChar()][3][2] = doubleMat[3][2];
|
||||
joinCheckMap[thisJoint.name().asChar()][3][3] = doubleMat[3][3];
|
||||
|
||||
MTransformationMatrix TransformationMatrix = thisJoint.transformation();
|
||||
|
||||
if (currentFrame == startFrame) {
|
||||
MPlug thisJointBindPose = thisJoint.findPlug("bindPose");
|
||||
MDataHandle DataHandle;
|
||||
@@ -348,7 +346,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
thisJointBindPoseMatrix = thisJointBindPoseMatrix * parentBindPoseMatrix.inverse();
|
||||
}
|
||||
|
||||
if (thisJointBindPoseMatrix.isEquivalent(TransformationMatrix.asMatrix())) {
|
||||
if (thisJointBindPoseMatrix.isEquivalent(transformationMatrix.asMatrix())) {
|
||||
//jointID++;
|
||||
//jointIt.next();
|
||||
currentFrame++;
|
||||
@@ -372,7 +370,7 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
MQuaternion jo = joEuler.asQuaternion();
|
||||
|
||||
double tmp[4];
|
||||
TransformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||
transformationMatrix.getRotationQuaternion(tmp[0], tmp[1], tmp[2], tmp[3]);
|
||||
MQuaternion rotation(tmp);
|
||||
|
||||
rotation = rotation * jo;
|
||||
@@ -386,11 +384,11 @@ Animation Skeleton::GetAnimData(std::string animationName, int startFrame, int e
|
||||
thisKeyFrame.Rotation[1] = tmp[1];
|
||||
thisKeyFrame.Rotation[2] = tmp[2];
|
||||
thisKeyFrame.Rotation[3] = tmp[3];
|
||||
TransformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||
transformationMatrix.getTranslation(MSpace::kTransform).get(tmp);
|
||||
thisKeyFrame.Position[0] = tmp[0];
|
||||
thisKeyFrame.Position[1] = tmp[1];
|
||||
thisKeyFrame.Position[2] = tmp[2];
|
||||
TransformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||
transformationMatrix.getScale(tmp, MSpace::kTransform);
|
||||
thisKeyFrame.Scale[0] = tmp[0];
|
||||
thisKeyFrame.Scale[1] = tmp[1];
|
||||
thisKeyFrame.Scale[2] = tmp[2];
|
||||
|
||||
Reference in New Issue
Block a user