incorporated new method to getWeights from cluster. the nurbSurface getweights is not tested though! hopefully it will work.

This commit is contained in:
Asad M. Zaman 2004-12-23 00:42:43 +00:00
parent f96ddb1420
commit 2de4051fea

View File

@ -51,6 +51,8 @@
#include <maya/MFnMesh.h>
#include <maya/MFnMeshData.h>
#include <maya/MItMeshPolygon.h>
#include <maya/MItMeshVertex.h>
#include <maya/MItSurfaceCV.h>
#include <maya/MFnPlugin.h>
#include <maya/MItDag.h>
#include <maya/MLibrary.h>
@ -1963,6 +1965,7 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
// spot a skinCluster node.
//
MObject c_node = it.thisNode();
//mayaegg_cat.info() << "thisNode type: " << c_node.apiTypeStr() << endl;
if (c_node.hasFn(MFn::kSkinClusterFilter)) {
// We've found the cluster handle. Try to get the weight
// data.
@ -1973,6 +1976,9 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
return false;
}
mayaegg_cat.info() << "getting weights of mesh: " << dag_path.fullPathName() << endl;
mayaegg_cat.info() << "and cluster: " << cluster.name() << endl;
// Get the set of objects that influence the vertices of this
// mesh. Hopefully these will all be joints.
MDagPathArray influence_objects;
@ -1984,8 +1990,10 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
// Fill up the vector with the corresponding table of egg
// groups for each joint.
joints.clear();
int numWeights = 0;
for (unsigned oi = 0; oi < influence_objects.length(); oi++) {
MDagPath joint_dag_path = influence_objects[oi];
//mayaegg_cat.info() << "influence joint[" << oi << "]:" << joint_dag_path.partialPathName() <<endl;
MayaNodeDesc *joint_node_desc = _tree.build_node(joint_dag_path);
EggGroup *joint = _tree.get_egg_group(joint_node_desc);
joints.push_back(joint);
@ -1993,31 +2001,52 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
// Now use a component object to retrieve all of the weight
// data in one API call.
MFnSingleIndexedComponent sic;
MObject sic_object = sic.create(MFn::kMeshVertComponent);
sic.setCompleteData(mesh.numVertices());
// To get a handle to the mesh verices component create an MItMeshVertex
MItMeshVertex mvIt(dag_path, MObject::kNullObj , &status );
if (!status)
status.perror("MItMeshVertex::constructor");
else {
MObject component = mvIt.vertex(&status);
if (!status)
status.perror("MItMeshVertex::vertex");
else {
MFnSingleIndexedComponent sic(component, &status);
if (!status)
status.perror("MFnSingleIndexedComponent::constructor");
else {
int numVertices;
numVertices = mvIt.count(&status);
if (!status)
status.perror("MItMeshVertex::count");
else {
mayaegg_cat.info() << "numVertices in Mesh: " << numVertices << endl;
sic.setCompleteData(numVertices);
unsigned influence_count;
status = cluster.getWeights(dag_path, sic_object,
status = cluster.getWeights(dag_path, sic.object(),
weights, influence_count);
if (!status) {
if (!status)
status.perror("MFnSkinCluster::getWeights");
} else {
else {
if (influence_count != influence_objects.length()) {
mayaegg_cat.error()
<< "MFnSkinCluster::influenceObjects() returns "
<< influence_objects.length()
<< " objects, but MFnSkinCluster::getWeights() reports "
<< influence_count << " objects.\n";
} else {
// We've got the weights and the set of objects. That's all
// we need.
mayaegg_cat.info() << "influence_count :" << influence_count << endl;
mayaegg_cat.info() << "number of weights :" << weights.length() << endl;
return true;
}
}
}
}
}
}
}
}
it.next();
}
@ -2086,12 +2115,32 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
// Now use a component object to retrieve all of the weight
// data in one API call.
MFnDoubleIndexedComponent dic;
MObject dic_object = dic.create(MFn::kSurfaceCVComponent);
dic.setCompleteData(surface.numCVsInU(), surface.numCVsInV());
// To get a handle to the surface cvs component create an MItSurfaceCV
MItSurfaceCV scvIt(dag_path, MObject::kNullObj , true, &status );
if (!status)
status.perror("MItSurfaceCV::constructor");
else {
MObject component = scvIt.cv(&status);
if (!status)
status.perror("MItSurfaceCV::cv");
else {
MFnDoubleIndexedComponent dic(component,&status);
if (!status)
status.perror("MFnDoubleIndexedComponent::constructor");
else {
int numUCVs, numVCVs;
status = scvIt.getIndex(numUCVs, numVCVs);
if (!status)
status.perror("mItSurfaceCV::getIndex");
else {
mayaegg_cat.info() << "numCVs in U: " << numUCVs << endl;
mayaegg_cat.info() << "numCVs in V: " << numVCVs << endl;
mayaegg_cat.info() << "numCVs in U from surface: " << surface.numCVsInU() << endl;
mayaegg_cat.info() << "numCVs in V from surface: " << surface.numCVsInV() << endl;
//dic.setCompleteData(surface.numCVsInU(), surface.numCVsInV());
dic.setCompleteData(numUCVs, numVCVs);
unsigned influence_count;
status = cluster.getWeights(dag_path, dic_object,
status = cluster.getWeights(dag_path, dic.object(),
weights, influence_count);
if (!status) {
status.perror("MFnSkinCluster::getWeights");
@ -2102,19 +2151,23 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
<< influence_objects.length()
<< " objects, but MFnSkinCluster::getWeights() reports "
<< influence_count << " objects.\n";
} else {
// We've got the weights and the set of objects. That's all
// we need.
mayaegg_cat.info() << "influence_count :" << influence_count << endl;
mayaegg_cat.info() << "number of weights :" << weights.length() << endl;
return true;
}
}
}
}
}
}
}
}
it.next();
}
// The surface was not soft-skinned.
return false;
}