mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-02 01:44:06 -04:00
incorporated new method to getWeights from cluster. the nurbSurface getweights is not tested though! hopefully it will work.
This commit is contained in:
parent
f96ddb1420
commit
2de4051fea
@ -51,6 +51,8 @@
|
|||||||
#include <maya/MFnMesh.h>
|
#include <maya/MFnMesh.h>
|
||||||
#include <maya/MFnMeshData.h>
|
#include <maya/MFnMeshData.h>
|
||||||
#include <maya/MItMeshPolygon.h>
|
#include <maya/MItMeshPolygon.h>
|
||||||
|
#include <maya/MItMeshVertex.h>
|
||||||
|
#include <maya/MItSurfaceCV.h>
|
||||||
#include <maya/MFnPlugin.h>
|
#include <maya/MFnPlugin.h>
|
||||||
#include <maya/MItDag.h>
|
#include <maya/MItDag.h>
|
||||||
#include <maya/MLibrary.h>
|
#include <maya/MLibrary.h>
|
||||||
@ -1963,6 +1965,7 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
|
|||||||
// spot a skinCluster node.
|
// spot a skinCluster node.
|
||||||
//
|
//
|
||||||
MObject c_node = it.thisNode();
|
MObject c_node = it.thisNode();
|
||||||
|
//mayaegg_cat.info() << "thisNode type: " << c_node.apiTypeStr() << endl;
|
||||||
if (c_node.hasFn(MFn::kSkinClusterFilter)) {
|
if (c_node.hasFn(MFn::kSkinClusterFilter)) {
|
||||||
// We've found the cluster handle. Try to get the weight
|
// We've found the cluster handle. Try to get the weight
|
||||||
// data.
|
// data.
|
||||||
@ -1973,6 +1976,9 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh,
|
|||||||
return false;
|
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
|
// Get the set of objects that influence the vertices of this
|
||||||
// mesh. Hopefully these will all be joints.
|
// mesh. Hopefully these will all be joints.
|
||||||
MDagPathArray influence_objects;
|
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
|
// Fill up the vector with the corresponding table of egg
|
||||||
// groups for each joint.
|
// groups for each joint.
|
||||||
joints.clear();
|
joints.clear();
|
||||||
|
int numWeights = 0;
|
||||||
for (unsigned oi = 0; oi < influence_objects.length(); oi++) {
|
for (unsigned oi = 0; oi < influence_objects.length(); oi++) {
|
||||||
MDagPath joint_dag_path = influence_objects[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);
|
MayaNodeDesc *joint_node_desc = _tree.build_node(joint_dag_path);
|
||||||
EggGroup *joint = _tree.get_egg_group(joint_node_desc);
|
EggGroup *joint = _tree.get_egg_group(joint_node_desc);
|
||||||
joints.push_back(joint);
|
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
|
// Now use a component object to retrieve all of the weight
|
||||||
// data in one API call.
|
// data in one API call.
|
||||||
MFnSingleIndexedComponent sic;
|
// To get a handle to the mesh verices component create an MItMeshVertex
|
||||||
MObject sic_object = sic.create(MFn::kMeshVertComponent);
|
MItMeshVertex mvIt(dag_path, MObject::kNullObj , &status );
|
||||||
sic.setCompleteData(mesh.numVertices());
|
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;
|
unsigned influence_count;
|
||||||
|
status = cluster.getWeights(dag_path, sic.object(),
|
||||||
status = cluster.getWeights(dag_path, sic_object,
|
|
||||||
weights, influence_count);
|
weights, influence_count);
|
||||||
if (!status) {
|
if (!status)
|
||||||
status.perror("MFnSkinCluster::getWeights");
|
status.perror("MFnSkinCluster::getWeights");
|
||||||
} else {
|
else {
|
||||||
if (influence_count != influence_objects.length()) {
|
if (influence_count != influence_objects.length()) {
|
||||||
mayaegg_cat.error()
|
mayaegg_cat.error()
|
||||||
<< "MFnSkinCluster::influenceObjects() returns "
|
<< "MFnSkinCluster::influenceObjects() returns "
|
||||||
<< influence_objects.length()
|
<< influence_objects.length()
|
||||||
<< " objects, but MFnSkinCluster::getWeights() reports "
|
<< " objects, but MFnSkinCluster::getWeights() reports "
|
||||||
<< influence_count << " objects.\n";
|
<< influence_count << " objects.\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// We've got the weights and the set of objects. That's all
|
// We've got the weights and the set of objects. That's all
|
||||||
// we need.
|
// we need.
|
||||||
|
mayaegg_cat.info() << "influence_count :" << influence_count << endl;
|
||||||
|
mayaegg_cat.info() << "number of weights :" << weights.length() << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it.next();
|
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
|
// Now use a component object to retrieve all of the weight
|
||||||
// data in one API call.
|
// data in one API call.
|
||||||
MFnDoubleIndexedComponent dic;
|
// To get a handle to the surface cvs component create an MItSurfaceCV
|
||||||
MObject dic_object = dic.create(MFn::kSurfaceCVComponent);
|
MItSurfaceCV scvIt(dag_path, MObject::kNullObj , true, &status );
|
||||||
dic.setCompleteData(surface.numCVsInU(), surface.numCVsInV());
|
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;
|
unsigned influence_count;
|
||||||
|
status = cluster.getWeights(dag_path, dic.object(),
|
||||||
status = cluster.getWeights(dag_path, dic_object,
|
|
||||||
weights, influence_count);
|
weights, influence_count);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
status.perror("MFnSkinCluster::getWeights");
|
status.perror("MFnSkinCluster::getWeights");
|
||||||
@ -2102,19 +2151,23 @@ get_vertex_weights(const MDagPath &dag_path, const MFnNurbsSurface &surface,
|
|||||||
<< influence_objects.length()
|
<< influence_objects.length()
|
||||||
<< " objects, but MFnSkinCluster::getWeights() reports "
|
<< " objects, but MFnSkinCluster::getWeights() reports "
|
||||||
<< influence_count << " objects.\n";
|
<< influence_count << " objects.\n";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// We've got the weights and the set of objects. That's all
|
// We've got the weights and the set of objects. That's all
|
||||||
// we need.
|
// we need.
|
||||||
|
mayaegg_cat.info() << "influence_count :" << influence_count << endl;
|
||||||
|
mayaegg_cat.info() << "number of weights :" << weights.length() << endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it.next();
|
it.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
// The surface was not soft-skinned.
|
// The surface was not soft-skinned.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user