17#include <maya/MObject.h>
18#include <maya/MAngle.h>
19#include <maya/MFnDependencyNode.h>
20#include <maya/MStatus.h>
21#include <maya/MFnStringData.h>
22#include <maya/MFnNumericData.h>
23#include <maya/MPlugArray.h>
24#include <maya/MPlug.h>
25#include <maya/MFnAttribute.h>
26#include <maya/MFnTypedAttribute.h>
27#include <maya/MFnNumericAttribute.h>
28#include <maya/MFnEnumAttribute.h>
29#include <maya/MFnCompoundAttribute.h>
30#include <maya/MFnMatrixData.h>
31#include <maya/MMatrix.h>
41get_maya_plug(MObject &node,
const string &attribute_name, MPlug &plug) {
43 MFnDependencyNode node_fn(node, &status);
46 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
50 MObject attr = node_fn.attribute(attribute_name.c_str(), &status);
55 MFnAttribute attr_fn(attr, &status);
58 <<
"Attribute " << attribute_name <<
" on " << node_fn.name().asChar()
59 <<
" is a " << attr.apiTypeStr() <<
", not an Attribute.\n";
63 plug = MPlug(node, attr);
78 return plug.isConnected();
87 MFnDependencyNode node_fn(node, &status);
90 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
94 node_fn.attribute(attribute_name.c_str(), &status);
109 MFnDependencyNode node_fn(node, &status);
112 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
116 MObject attr = node_fn.attribute(attribute_name.c_str(), &status);
125 MFnAttribute attr_fn(attr, &status);
128 <<
"Attribute " << attribute_name <<
" on " << node_fn.name().asChar()
129 <<
" is a " << attr.apiTypeStr() <<
", not an Attribute.\n";
134 MFnDependencyNode::MAttrClass type = node_fn.attributeClass(attr, &status);
137 <<
"Couldn't get class of attribute " << attribute_name <<
" on "
138 << node_fn.name().asChar() <<
".\n";
142 status = node_fn.removeAttribute(attr, type);
145 <<
"Couldn't remove attribute " << attribute_name <<
" from "
146 << node_fn.name().asChar() <<
".\n";
165 if (!get_maya_attribute(node, attribute_name, value)) {
167 <<
"Attribute " << attribute_name
168 <<
" does not have a bool value.\n";
182 if (!get_maya_attribute(node, attribute_name, maya_value)) {
184 <<
"Attribute " << attribute_name
185 <<
" does not have an angle value.\n";
189 value = maya_value.asDegrees();
202 if (!get_maya_attribute(node, attribute_name, vec2_object)) {
204 <<
"Attribute " << attribute_name
205 <<
" does not have a vec2 object value.\n";
210 MFnNumericData data(vec2_object, &status);
213 <<
"Attribute " << attribute_name <<
" is of type "
214 << vec2_object.apiTypeStr() <<
", not a NumericData.\n";
218 status = data.getData(value[0], value[1]);
221 <<
"Unable to extract 2 floats from " << attribute_name
222 <<
", of type " << vec2_object.apiTypeStr() <<
"\n";
237 if (!get_maya_attribute(node, attribute_name, vec3_object)) {
239 <<
"Attribute " << attribute_name
240 <<
" does not have a vec3 object value.\n";
245 MFnNumericData data(vec3_object, &status);
248 <<
"Attribute " << attribute_name <<
" is of type "
249 << vec3_object.apiTypeStr() <<
", not a NumericData.\n";
253 status = data.getData(value[0], value[1], value[2]);
256 <<
"Unable to extract 3 floats from " << attribute_name
257 <<
", of type " << vec3_object.apiTypeStr() <<
"\n";
271 MObject vec2d_object;
272 if (!get_maya_attribute(node, attribute_name, vec2d_object)) {
274 <<
"Attribute " << attribute_name
275 <<
" does not have a vec2d object value.\n";
280 MFnNumericData data(vec2d_object, &status);
283 <<
"Attribute " << attribute_name <<
" is of type "
284 << vec2d_object.apiTypeStr() <<
", not a NumericData.\n";
288 status = data.getData(value[0], value[1]);
291 <<
"Unable to extract 2 doubles from " << attribute_name
292 <<
", of type " << vec2d_object.apiTypeStr() <<
"\n";
306 MObject vec3d_object;
307 if (!get_maya_attribute(node, attribute_name, vec3d_object)) {
309 <<
"Attribute " << attribute_name
310 <<
" does not have a vec3d object value.\n";
315 MFnNumericData data(vec3d_object, &status);
318 <<
"Attribute " << attribute_name <<
" is of type "
319 << vec3d_object.apiTypeStr() <<
", not a NumericData.\n";
323 status = data.getData(value[0], value[1], value[2]);
326 <<
"Unable to extract 3 doubles from " << attribute_name
327 <<
", of type " << vec3d_object.apiTypeStr() <<
"\n";
341 if (!get_maya_attribute(node, attribute_name, matrix)) {
345 MFnMatrixData matrix_data(matrix, &status);
348 <<
"Attribute " << attribute_name <<
" is of type "
349 << node.apiTypeStr() <<
", not a Matrix.\n";
353 const MMatrix &mat = matrix_data.matrix();
354 for (
int i = 0; i < 4; i++) {
355 for (
int j = 0; j < 4; j++) {
356 value(i, j) = mat(i, j);
369 MFnDependencyNode node_fn(node, &status);
372 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
376 string name = node_fn.name().asChar();
379 for (i = 0; i < node_fn.attributeCount(); i++) {
380 MObject attr = node_fn.attribute(i, &status);
382 MFnAttribute attrib(attr, &status);
384 string attribute_name = attrib.name().asChar();
385 if (attribute_name.find(
"tag", 0) != string::npos) {
386 maya_cat.info() <<
":" << name <<
":" <<
" is tagged with <"
387 << attribute_name <<
">" << endl;
388 tag_names.push_back(attribute_name);
407 MObject attrib = plug.attribute();
408 MFnEnumAttribute enum_attrib(attrib, &status);
411 <<
"Not an enum attribute: " << attribute_name <<
"\n";
416 status = plug.getValue(index);
419 <<
"Could not get numeric value of " << attribute_name <<
"\n";
420 status.perror(
"MPlug::getValue(short)");
424 MString name = enum_attrib.fieldName(index, &status);
427 <<
"Invalid value for " << attribute_name <<
": " << index <<
"\n";
428 status.perror(
"MFnEnumAttribute::fieldName()");
432 value = name.asChar();
444 MObject string_object;
445 if (!get_maya_attribute(node, attribute_name, string_object)) {
447 <<
"Attribute " << attribute_name
448 <<
" does not have an string object value.\n";
453 MFnStringData data(string_object, &status);
456 <<
"Attribute " << attribute_name <<
" is of type "
457 << string_object.apiTypeStr() <<
", not a StringData.\n";
461 value = data.string().asChar();
470 const string &value) {
474 MObject string_object;
475 if (!get_maya_attribute(node, attribute_name, string_object)) {
477 <<
"Attribute " << attribute_name
478 <<
" does not have a string object value.\n";
483 MFnStringData data(string_object, &status);
486 <<
"Attribute " << attribute_name <<
" is of type "
487 << string_object.apiTypeStr() <<
", not a StringData.\n";
491 MString mstring_value(value.data(), value.length());
492 status = data.set(mstring_value);
494 status.perror(attribute_name.c_str());
499 if (!set_maya_attribute(node, attribute_name, string_object)) {
501 <<
"Attribute " << attribute_name
502 <<
" suddenly does not have a string object value.\n";
516 MFnCompoundAttribute comp_attr(node, &status);
518 maya_cat.info() <<
"comp_attr has:" << comp_attr.numChildren() <<
" children" << endl;
519 for (
size_t i = 0; i < comp_attr.numChildren(); i++) {
520 MObject child = comp_attr.child(i, &status);
521 if (child.apiType() == MFn::kAttribute3Float){
529 else if (child.apiType() == MFn::kNumericAttribute) {
530 MFnNumericAttribute numeric(child, &status);
532 switch(numeric.unitType()) {
533 case MFnNumericData::kFloat :
535 status = numeric.getDefault(alpha);
536 maya_cat.info() <<
"found a float :" << alpha << endl;
538 case MFnNumericData::kBoolean :
540 status = numeric.getDefault(v);
541 maya_cat.info() <<
"found a bool :" << v << endl;
543 maya_cat.info() << numeric.unitType() << endl;
547 else if (child.apiType() == MFn::kEnumAttribute) {
548 MFnEnumAttribute enu(child, &status);
551 status = enu.getDefault(blah);
552 maya_cat.info() <<
"found a string :" << blah.asChar() << endl;
553 MPlug plug = MPlug(node, child);
554 maya_cat.info() <<
"plug name" << plug.name().asChar() << endl;
567 MFnDependencyNode node_fn(node, &status);
570 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
574 MObject attr = node_fn.attribute(attribute_name.c_str(), &status);
577 <<
"Object " << node_fn.name().asChar() <<
" does not support attribute "
578 << attribute_name <<
"\n";
583 <<
"Attribute " << attribute_name <<
" on object "
584 << node_fn.name().asChar() <<
" has type " << attr.apiTypeStr() <<
"\n";
588string_mfndata_type(MFnData::Type type) {
590 case MFnData::kInvalid:
593 case MFnData::kNumeric:
596 case MFnData::kPlugin:
599 case MFnData::kPluginGeometry:
600 return "kPluginGeometry";
602 case MFnData::kString:
605 case MFnData::kMatrix:
608 case MFnData::kStringArray:
609 return "kStringArray";
611 case MFnData::kDoubleArray:
612 return "kDoubleArray";
614 case MFnData::kIntArray:
617 case MFnData::kPointArray:
618 return "kPointArray";
620 case MFnData::kVectorArray:
621 return "kVectorArray";
623 case MFnData::kComponentList:
624 return "kComponentList";
629 case MFnData::kLattice:
632 case MFnData::kNurbsCurve:
633 return "kNurbsCurve";
635 case MFnData::kNurbsSurface:
636 return "kNurbsSurface";
638 case MFnData::kSphere:
641 case MFnData::kDynArrayAttrs:
642 return "kDynArrayAttrs";
644 case MFnData::kDynSweptGeometry:
645 return "kDynSweptGeometry";
647 case MFnData::kSubdSurface:
648 return "kSubdSurface";
655 return "**invalid**";
666 MFnDependencyNode node_fn(node, &status);
669 <<
"Object is a " << node.apiTypeStr() <<
", not a DependencyNode.\n";
673 string name = node_fn.name().asChar();
676 MPlugArray connections;
677 status = node_fn.getConnections(connections);
679 status.perror(
"MFnDependencyNode::getConnections");
683 << name <<
" has " << connections.length() <<
" connections.\n";
684 for (i = 0; i < connections.length(); i++) {
685 MPlug plug = connections[i];
688 <<
" " << i <<
". " << plug.name().asChar() <<
", "
689 << plug.attribute().apiTypeStr() <<
", "
690 << plug.node().apiTypeStr();
691 if (plug.attribute().apiType() == MFn::kCompoundAttribute) {
695 if (plug.isConnected()) {
705 << name <<
" has " << node_fn.attributeCount() <<
" attributes.\n";
706 for (i = 0; i < node_fn.attributeCount(); i++) {
707 MObject attr = node_fn.attribute(i, &status);
709 MFnTypedAttribute typed_attrib(attr, &status);
713 <<
" " << i <<
". " << typed_attrib.name().asChar()
714 <<
" [" << attr.apiTypeStr() <<
", "
715 << string_mfndata_type(typed_attrib.attrType()) <<
"]\n";
717 MFnAttribute attrib(attr, &status);
721 <<
" " << i <<
". " << attrib.name().asChar()
722 <<
" [" << attr.apiTypeStr() <<
"]\n";
726 <<
" " << i <<
". [" << attr.apiTypeStr() <<
"]\n";
This is our own Panda specialization on the default STL vector.
bool remove_attribute(MObject &node, const string &attribute_name)
Removes the named attribute from the indicated Maya node.
bool get_maya_plug(MObject &node, const string &attribute_name, MPlug &plug)
Gets the named MPlug associated, if any.
bool get_vec3d_attribute(MObject &node, const string &attribute_name, LVecBase3d &value)
Extracts the named three-component vector from the MObject.
bool get_string_attribute(MObject &node, const string &attribute_name, string &value)
Extracts the named string attribute from the MObject.
void get_tag_attribute_names(MObject &node, pvector< string > &tag_names)
artists should be able to set arbitrary tags.
bool get_angle_attribute(MObject &node, const string &attribute_name, double &value)
Extracts the named angle in degrees from the MObject.
bool set_string_attribute(MObject &node, const string &attribute_name, const string &value)
Sets the named string attribute on the MObject.
void list_maya_attributes(MObject &node)
Writes some info output showing all the attributes on the given dependency node.
bool is_connected(MObject &node, const string &attribute_name)
Returns true if the named connection exists on the node and is connected to anything,...
void describe_maya_attribute(MObject &node, const string &attribute_name)
Writes some warning output about the indicated Maya attribute.
bool get_vec3_attribute(MObject &node, const string &attribute_name, LVecBase3 &value)
Extracts the named three-component vector from the MObject.
bool get_enum_attribute(MObject &node, const string &attribute_name, string &value)
Extracts the enum attribute from the MObject as a string value.
bool has_attribute(MObject &node, const string &attribute_name)
Returns true if the node has the indicated attribute, false otherwise.
bool get_mat4d_attribute(MObject &node, const string &attribute_name, LMatrix4d &value)
Extracts the named 4x4 matrix from the MObject.
bool get_vec2d_attribute(MObject &node, const string &attribute_name, LVecBase2d &value)
Extracts the named two-component vector from the MObject.
bool describe_compound_attribute(MObject &node)
Extracts the children of this attribute from the MObject.
bool get_vec2_attribute(MObject &node, const string &attribute_name, LVecBase2 &value)
Extracts the named two-component vector from the MObject.
bool get_bool_attribute(MObject &node, const string &attribute_name, bool &value)
Extracts the named boolean attribute from the MObject.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.