From b63e567d49ed62584d1b4def91c9ebe29019fa8f Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 27 Jan 2003 22:57:03 +0000 Subject: [PATCH] egg object types in maya2egg --- pandatool/src/maya/maya_funcs.cxx | 48 +++++++++++++++++++- pandatool/src/maya/maya_funcs.h | 4 ++ pandatool/src/mayaegg/mayaToEggConverter.cxx | 16 +++++-- pandatool/src/mayaegg/mayaToEggConverter.h | 3 +- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/pandatool/src/maya/maya_funcs.cxx b/pandatool/src/maya/maya_funcs.cxx index 82c44a2245..c025fb00b4 100644 --- a/pandatool/src/maya/maya_funcs.cxx +++ b/pandatool/src/maya/maya_funcs.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include "post_maya_include.h" //////////////////////////////////////////////////////////////////// @@ -47,7 +48,7 @@ get_maya_plug(MObject &node, const string &attribute_name, MPlug &plug) { MObject attr = node_fn.attribute(attribute_name.c_str(), &status); if (!status) { - maya_cat.error() + maya_cat.debug() << "Object " << node_fn.name() << " does not support attribute " << attribute_name << "\n"; return false; @@ -177,6 +178,49 @@ get_vec2d_attribute(MObject &node, const string &attribute_name, return true; } +//////////////////////////////////////////////////////////////////// +// Function: get_enum_attribute +// Description: Extracts the enum attribute from the MObject as a +// string value. +//////////////////////////////////////////////////////////////////// +bool +get_enum_attribute(MObject &node, const string &attribute_name, + string &value) { + MStatus status; + + MPlug plug; + if (!get_maya_plug(node, attribute_name.c_str(), plug)) { + return false; + } + + MFnEnumAttribute enum_attrib(plug.attribute(), &status); + if (!status) { + maya_cat.error() + << "Not an enum attribute: " << attribute_name << "\n"; + return false; + } + + short index; + status = plug.getValue(index); + if (!status) { + maya_cat.error() + << "Could not get numeric value of " << attribute_name << "\n"; + status.perror("MPlug::getValue(short)"); + return false; + } + + MString name = enum_attrib.fieldName(index, &status); + if (!status) { + maya_cat.error() + << "Invalid value for " << attribute_name << ": " << index << "\n"; + status.perror("MFnEnumAttribute::fieldName()"); + return false; + } + + value = name.asChar(); + return true; +} + //////////////////////////////////////////////////////////////////// // Function: get_string_attribute // Description: Extracts the named string attribute from the @@ -376,7 +420,7 @@ list_maya_attributes(MObject &node) { MPlugArray connections; status = node_fn.getConnections(connections); if (!status) { - status.perror("MFnDependencyNode::getConnections\n"); + status.perror("MFnDependencyNode::getConnections"); return; } diff --git a/pandatool/src/maya/maya_funcs.h b/pandatool/src/maya/maya_funcs.h index 92a94bcbab..ce430219c3 100644 --- a/pandatool/src/maya/maya_funcs.h +++ b/pandatool/src/maya/maya_funcs.h @@ -64,6 +64,10 @@ bool get_vec2d_attribute(MObject &node, const string &attribute_name, LVecBase2d &value); +bool +get_enum_attribute(MObject &node, const string &attribute_name, + string &value); + bool get_string_attribute(MObject &node, const string &attribute_name, string &value); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index fdab63df1b..a41f08b2ee 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -1415,16 +1415,17 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh, //////////////////////////////////////////////////////////////////// EggGroup *MayaToEggConverter:: get_egg_group(const MDagPath &dag_path, EggGroupNode *egg_root) { - return get_egg_group(dag_path.fullPathName().asChar(), egg_root); + return r_get_egg_group(dag_path.fullPathName().asChar(), dag_path, egg_root); } //////////////////////////////////////////////////////////////////// -// Function: MayaToEggConverter::get_egg_group +// Function: MayaToEggConverter::r_get_egg_group // Access: Private // Description: The recursive implementation of get_egg_group(). //////////////////////////////////////////////////////////////////// EggGroup *MayaToEggConverter:: -get_egg_group(const string &name, EggGroupNode *egg_root) { +r_get_egg_group(const string &name, const MDagPath &dag_path, + EggGroupNode *egg_root) { // If we have already encountered this pathname, return the // corresponding EggGroup immediately. Groups::const_iterator gi = _groups.find(name); @@ -1453,7 +1454,8 @@ get_egg_group(const string &name, EggGroupNode *egg_root) { local_name = name; } - EggGroup *parent_egg_group = get_egg_group(parent_name, egg_root); + EggGroup *parent_egg_group = + r_get_egg_group(parent_name, dag_path, egg_root); egg_group = new EggGroup(local_name); if (parent_egg_group != (EggGroup *)NULL) { @@ -1461,6 +1463,12 @@ get_egg_group(const string &name, EggGroupNode *egg_root) { } else { egg_root->add_child(egg_group); } + + // Check for an object type setting, from Oliver's plug-in. + string object_type; + if (get_enum_attribute(dag_path.node(), "eggObjectTypes", object_type)) { + egg_group->add_object_type(object_type); + } } _groups.insert(Groups::value_type(name, egg_group)); diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 9adee93c7d..5665794457 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -113,7 +113,8 @@ private: }; EggGroup *get_egg_group(const MDagPath &dag_path, EggGroupNode *egg_root); - EggGroup *get_egg_group(const string &name, EggGroupNode *egg_root); + EggGroup *r_get_egg_group(const string &name, const MDagPath &dag_path, + EggGroupNode *egg_root); JointAnim *get_egg_table(const MDagPath &dag_path, EggGroupNode *egg_root); JointAnim *get_egg_table(const string &name, EggGroupNode *egg_root); void set_shader_attributes(EggPrimitive &primitive,