I've have been recently developing a maya plugin for import some meshes into maya. The meshes that I want to import are rigged and are partitioned into smaller meshes.
So to import the partitions I decided to use blinda data so I set up a blind data stored with faces per each mesh partition. My only problem is that it doesn't work. I have looked into a lot of examples and they all did it the same way. My code looks like this:
MStatus status;
MStringArray long_name;
MStringArray short_name;
MStringArray format_name;
MObject proper_shape;
MFnDagNode parent_node(parent);
MFnDagNode check;
for(int x = 0; x < parent_node.childCount(); x++) {
MObject child = parent_node.child(x);
check.setObject(child);
if(child.hasFn(MFn::kMesh) && !check.isIntermediateObject()) {
proper_shape = child;
}
}
MFnMesh blind_data_mesh;
if(!proper_shape.isNull()) {
blind_data_mesh.setObject(proper_shape);
}
blind_data_mesh.updateSurface();
long_name.append("dismemberValue");
short_name.append("dismemberValue");
format_name.append("int");
for(int x = 0; x < cs.GetDismemberPartitionsBodyParts().size(); x++) {
int blind_data_id = 100;
do {
blind_data_id++;
status = blind_data_mesh.createBlindDataType(blind_data_id, long_name, short_name, format_name);
} while(status == MStatus::kFailure);
MString name1 = blind_data_mesh.name();
MString name2 = meshFn.name();
vector dismember_faces = cs.GetDismemberPartitionsFaces();
for(int y = 0; y < dismember_faces.size(); y++) {
if(dismember_faces[y] == x) {
status = blind_data_mesh.setIntBlindData(y, MFn::kMeshPolygonComponent, blind_data_id, "dismemberValue", 10);
if(status == MStatus::kFailure) {
int a = 0;
a++;
}
}
}
if(blind_data_mesh.hasBlindData(blind_data_id,MFn::kMeshPolygonComponent)) {
int a = 0;
a++;
}
MPlug blind_data = meshFn.findPlug("blindDataNodes");
MPlug input_blind_message = blind_data.elementByPhysicalIndex(x);
MPlug output_blind_message = input_blind_message.connectionByPhysicalIndex(0);
MFnDependencyNode dismember_node;
dismember_node.create("nifDismemberPartition");
MPlug input_message_dismember = dismember_node.findPlug("targetFaces");
MDGModifier dg_modifier;
dg_modifier.connect(output_blind_message, input_message_dismember);
dg_modifier.doIt();
}
The last part of the code should theoretically connect a custom node to the blind data node. Now my problem is that the blind data type is created with the createBlindDataType method. But when I try to assign the blind data to the mesh it doesn't work at all. By not working I mean that it doesn't create a polyBlindData node and attach it to the shape object like it happens if you use the blind data editor inside maya. I also ran some tests to see if a blind data of the given id is attached to the shape node at it isn't. But the blind data type gets created and you can see it in the blind data editor inside maya with exactly the same attributes that I specified when I created the blind data.
In order to get the proper shape node I used to iterate through all the children of the transform node until I found the right shape node. In my case the meshes are rigged too and have a tweak node attached to the shape node. So in the attribute editor I have a transform node, a shape node, a tweak node, a phong shader node and skin cluster node. I believe because the mesh has a bit of history and materials attached to it, it fails to set the nodes.