Skip to content

Commit 2de4051

Browse files
author
Asad M. Zaman
committed
incorporated new method to getWeights from cluster. the nurbSurface getweights is not tested though! hopefully it will work.
1 parent f96ddb1 commit 2de4051

File tree

1 file changed

+99
-46
lines changed

1 file changed

+99
-46
lines changed

pandatool/src/mayaegg/mayaToEggConverter.cxx

Lines changed: 99 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
#include <maya/MFnMesh.h>
5252
#include <maya/MFnMeshData.h>
5353
#include <maya/MItMeshPolygon.h>
54+
#include <maya/MItMeshVertex.h>
55+
#include <maya/MItSurfaceCV.h>
5456
#include <maya/MFnPlugin.h>
5557
#include <maya/MItDag.h>
5658
#include <maya/MLibrary.h>
@@ -1948,7 +1950,7 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
19481950
// creates the mesh is named "inMesh"
19491951
//
19501952
MObject attr = mesh.attribute("inMesh");
1951-
1953+
19521954
// Create the plug to the "inMesh" attribute then use the
19531955
// DG iterator to walk through the DG, at the node level.
19541956
//
@@ -1963,6 +1965,7 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
19631965
// spot a skinCluster node.
19641966
//
19651967
MObject c_node = it.thisNode();
1968+
//mayaegg_cat.info() << "thisNode type: " << c_node.apiTypeStr() << endl;
19661969
if (c_node.hasFn(MFn::kSkinClusterFilter)) {
19671970
// We've found the cluster handle. Try to get the weight
19681971
// data.
@@ -1973,47 +1976,73 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
19731976
return false;
19741977
}
19751978

1979+
mayaegg_cat.info() << "getting weights of mesh: " << dag_path.fullPathName() << endl;
1980+
mayaegg_cat.info() << "and cluster: " << cluster.name() << endl;
1981+
19761982
// Get the set of objects that influence the vertices of this
19771983
// mesh. Hopefully these will all be joints.
19781984
MDagPathArray influence_objects;
1979-
cluster.influenceObjects(influence_objects, &status);
1985+
cluster.influenceObjects(influence_objects, &status);
19801986
if (!status) {
19811987
status.perror("MFnSkinCluster::influenceObjects");
19821988

19831989
} else {
19841990
// Fill up the vector with the corresponding table of egg
19851991
// groups for each joint.
19861992
joints.clear();
1993+
int numWeights = 0;
19871994
for (unsigned oi = 0; oi < influence_objects.length(); oi++) {
19881995
MDagPath joint_dag_path = influence_objects[oi];
1996+
//mayaegg_cat.info() << "influence joint[" << oi << "]:" << joint_dag_path.partialPathName() <<endl;
19891997
MayaNodeDesc *joint_node_desc = _tree.build_node(joint_dag_path);
19901998
EggGroup *joint = _tree.get_egg_group(joint_node_desc);
19911999
joints.push_back(joint);
19922000
}
1993-
2001+
19942002
// Now use a component object to retrieve all of the weight
19952003
// data in one API call.
1996-
MFnSingleIndexedComponent sic;
1997-
MObject sic_object = sic.create(MFn::kMeshVertComponent);
1998-
sic.setCompleteData(mesh.numVertices());
1999-
unsigned influence_count;
2000-
2001-
status = cluster.getWeights(dag_path, sic_object,
2002-
weights, influence_count);
2003-
if (!status) {
2004-
status.perror("MFnSkinCluster::getWeights");
2005-
} else {
2006-
if (influence_count != influence_objects.length()) {
2007-
mayaegg_cat.error()
2008-
<< "MFnSkinCluster::influenceObjects() returns "
2009-
<< influence_objects.length()
2010-
<< " objects, but MFnSkinCluster::getWeights() reports "
2011-
<< influence_count << " objects.\n";
2012-
2013-
} else {
2014-
// We've got the weights and the set of objects. That's all
2015-
// we need.
2016-
return true;
2004+
// To get a handle to the mesh verices component create an MItMeshVertex
2005+
MItMeshVertex mvIt(dag_path, MObject::kNullObj , &status );
2006+
if (!status)
2007+
status.perror("MItMeshVertex::constructor");
2008+
else {
2009+
MObject component = mvIt.vertex(&status);
2010+
if (!status)
2011+
status.perror("MItMeshVertex::vertex");
2012+
else {
2013+
MFnSingleIndexedComponent sic(component, &status);
2014+
if (!status)
2015+
status.perror("MFnSingleIndexedComponent::constructor");
2016+
else {
2017+
int numVertices;
2018+
numVertices = mvIt.count(&status);
2019+
if (!status)
2020+
status.perror("MItMeshVertex::count");
2021+
else {
2022+
mayaegg_cat.info() << "numVertices in Mesh: " << numVertices << endl;
2023+
sic.setCompleteData(numVertices);
2024+
unsigned influence_count;
2025+
status = cluster.getWeights(dag_path, sic.object(),
2026+
weights, influence_count);
2027+
if (!status)
2028+
status.perror("MFnSkinCluster::getWeights");
2029+
else {
2030+
if (influence_count != influence_objects.length()) {
2031+
mayaegg_cat.error()
2032+
<< "MFnSkinCluster::influenceObjects() returns "
2033+
<< influence_objects.length()
2034+
<< " objects, but MFnSkinCluster::getWeights() reports "
2035+
<< influence_count << " objects.\n";
2036+
} else {
2037+
// We've got the weights and the set of objects. That's all
2038+
// we need.
2039+
mayaegg_cat.info() << "influence_count :" << influence_count << endl;
2040+
mayaegg_cat.info() << "number of weights :" << weights.length() << endl;
2041+
return true;
2042+
}
2043+
}
2044+
}
2045+
}
20172046
}
20182047
}
20192048
}
@@ -2086,35 +2115,59 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
20862115

20872116
// Now use a component object to retrieve all of the weight
20882117
// data in one API call.
2089-
MFnDoubleIndexedComponent dic;
2090-
MObject dic_object = dic.create(MFn::kSurfaceCVComponent);
2091-
dic.setCompleteData(surface.numCVsInU(), surface.numCVsInV());
2092-
unsigned influence_count;
2093-
2094-
status = cluster.getWeights(dag_path, dic_object,
2095-
weights, influence_count);
2096-
if (!status) {
2097-
status.perror("MFnSkinCluster::getWeights");
2098-
} else {
2099-
if (influence_count != influence_objects.length()) {
2100-
mayaegg_cat.error()
2101-
<< "MFnSkinCluster::influenceObjects() returns "
2102-
<< influence_objects.length()
2103-
<< " objects, but MFnSkinCluster::getWeights() reports "
2104-
<< influence_count << " objects.\n";
2105-
2106-
} else {
2107-
// We've got the weights and the set of objects. That's all
2108-
// we need.
2109-
return true;
2118+
// To get a handle to the surface cvs component create an MItSurfaceCV
2119+
MItSurfaceCV scvIt(dag_path, MObject::kNullObj , true, &status );
2120+
if (!status)
2121+
status.perror("MItSurfaceCV::constructor");
2122+
else {
2123+
MObject component = scvIt.cv(&status);
2124+
if (!status)
2125+
status.perror("MItSurfaceCV::cv");
2126+
else {
2127+
MFnDoubleIndexedComponent dic(component,&status);
2128+
if (!status)
2129+
status.perror("MFnDoubleIndexedComponent::constructor");
2130+
else {
2131+
int numUCVs, numVCVs;
2132+
status = scvIt.getIndex(numUCVs, numVCVs);
2133+
if (!status)
2134+
status.perror("mItSurfaceCV::getIndex");
2135+
else {
2136+
mayaegg_cat.info() << "numCVs in U: " << numUCVs << endl;
2137+
mayaegg_cat.info() << "numCVs in V: " << numVCVs << endl;
2138+
mayaegg_cat.info() << "numCVs in U from surface: " << surface.numCVsInU() << endl;
2139+
mayaegg_cat.info() << "numCVs in V from surface: " << surface.numCVsInV() << endl;
2140+
//dic.setCompleteData(surface.numCVsInU(), surface.numCVsInV());
2141+
dic.setCompleteData(numUCVs, numVCVs);
2142+
unsigned influence_count;
2143+
status = cluster.getWeights(dag_path, dic.object(),
2144+
weights, influence_count);
2145+
if (!status) {
2146+
status.perror("MFnSkinCluster::getWeights");
2147+
} else {
2148+
if (influence_count != influence_objects.length()) {
2149+
mayaegg_cat.error()
2150+
<< "MFnSkinCluster::influenceObjects() returns "
2151+
<< influence_objects.length()
2152+
<< " objects, but MFnSkinCluster::getWeights() reports "
2153+
<< influence_count << " objects.\n";
2154+
} else {
2155+
// We've got the weights and the set of objects. That's all
2156+
// we need.
2157+
mayaegg_cat.info() << "influence_count :" << influence_count << endl;
2158+
mayaegg_cat.info() << "number of weights :" << weights.length() << endl;
2159+
return true;
2160+
}
2161+
}
2162+
}
2163+
}
21102164
}
21112165
}
21122166
}
21132167
}
21142168

21152169
it.next();
21162170
}
2117-
21182171
// The surface was not soft-skinned.
21192172
return false;
21202173
}

0 commit comments

Comments
 (0)