diff --git a/pandatool/src/mayaegg/mayaNodeDesc.cxx b/pandatool/src/mayaegg/mayaNodeDesc.cxx index 7eb04a2b74..29c4a4da29 100755 --- a/pandatool/src/mayaegg/mayaNodeDesc.cxx +++ b/pandatool/src/mayaegg/mayaNodeDesc.cxx @@ -19,6 +19,7 @@ #include "mayaNodeDesc.h" #include "mayaNodeTree.h" #include "mayaBlendDesc.h" +#include "mayaToEggConverter.h" #include "maya_funcs.h" #include "config_mayaegg.h" @@ -88,14 +89,24 @@ MayaNodeDesc:: // some Maya instance. //////////////////////////////////////////////////////////////////// void MayaNodeDesc:: -from_dag_path(const MDagPath &dag_path) { +from_dag_path(const MDagPath &dag_path, MayaToEggConverter *converter) { MStatus status; if (_dag_path == (MDagPath *)NULL) { _dag_path = new MDagPath(dag_path); - if (_dag_path->hasFn(MFn::kJoint)) { - // This node is a joint. + string name; + MFnDagNode dag_node(dag_path, &status); + if (!status) { + status.perror("MFnDagNode constructor"); + } else { + name = dag_node.name().asChar(); + cerr << "node " << name << "\n"; + } + + if (_dag_path->hasFn(MFn::kJoint) || converter->force_joint(name)) { + // This node is a joint, or the user specifically asked to treat + // it like a joint. _joint_type = JT_joint; if (_parent != (MayaNodeDesc *)NULL) { _parent->mark_joint_parent(); diff --git a/pandatool/src/mayaegg/mayaNodeDesc.h b/pandatool/src/mayaegg/mayaNodeDesc.h index ecac53a8e7..81f48ae4b5 100755 --- a/pandatool/src/mayaegg/mayaNodeDesc.h +++ b/pandatool/src/mayaegg/mayaNodeDesc.h @@ -31,6 +31,7 @@ #include #include "post_maya_include.h" +class MayaToEggConverter; class MayaNodeTree; class EggGroup; class EggTable; @@ -49,7 +50,7 @@ public: MayaNodeDesc *parent = NULL, const string &name = string()); ~MayaNodeDesc(); - void from_dag_path(const MDagPath &dag_path); + void from_dag_path(const MDagPath &dag_path, MayaToEggConverter *converter); bool has_dag_path() const; const MDagPath &get_dag_path() const; diff --git a/pandatool/src/mayaegg/mayaNodeTree.cxx b/pandatool/src/mayaegg/mayaNodeTree.cxx index 1ebfe90c6d..9533906104 100755 --- a/pandatool/src/mayaegg/mayaNodeTree.cxx +++ b/pandatool/src/mayaegg/mayaNodeTree.cxx @@ -63,7 +63,7 @@ MayaNodeTree(MayaToEggConverter *converter) : MayaNodeDesc *MayaNodeTree:: build_node(const MDagPath &dag_path) { MayaNodeDesc *node_desc = r_build_node(dag_path.fullPathName().asChar()); - node_desc->from_dag_path(dag_path); + node_desc->from_dag_path(dag_path, _converter); return node_desc; } diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 40e27a0824..7ebdd3ced0 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -111,6 +111,7 @@ MayaToEggConverter(const MayaToEggConverter ©) : _from_selection(copy._from_selection), _subsets(copy._subsets), _ignore_sliders(copy._ignore_sliders), + _force_joints(copy._force_joints), _tree(this), _maya(copy._maya), _polygon_output(copy._polygon_output), @@ -284,6 +285,52 @@ ignore_slider(const string &name) const { return false; } +//////////////////////////////////////////////////////////////////// +// Function: MayaToEggConverter::clear_force_joints +// Access: Public +// Description: Empties the list of force_joints added via +// add_force_joint(). No joints will be forced. +//////////////////////////////////////////////////////////////////// +void MayaToEggConverter:: +clear_force_joints() { + _force_joints.clear(); +} + +//////////////////////////////////////////////////////////////////// +// Function: MayaToEggConverter::add_force_joint +// Access: Public +// Description: Adds a name pattern to the list of force_joints. +// +// Any DAG node that matches a name on the list will be +// treated as if it were a joint during the conversion +// process; it will receive animation and position +// information. Normally, a true Maya joint, as well as +// any DAG nodes whose transforms are animated, will +// automatically be flagged as a Panda joint. +//////////////////////////////////////////////////////////////////// +void MayaToEggConverter:: +add_force_joint(const GlobPattern &glob) { + _force_joints.push_back(glob); +} + +//////////////////////////////////////////////////////////////////// +// Function: MayaToEggConverter::force_joint +// Access: Public +// Description: Returns true if the indicated name is on the list of +// DAG nodes to treat as a joint, false otherwise. +//////////////////////////////////////////////////////////////////// +bool MayaToEggConverter:: +force_joint(const string &name) const { + Globs::const_iterator gi; + for (gi = _force_joints.begin(); gi != _force_joints.end(); ++gi) { + if ((*gi).matches(name)) { + return true; + } + } + + return false; +} + //////////////////////////////////////////////////////////////////// // Function: MayaToEggConverter::set_from_selection // Access: Public diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 0df4b6ae2c..7e84cabe7f 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -84,6 +84,10 @@ public: void add_ignore_slider(const GlobPattern &glob); bool ignore_slider(const string &name) const; + void clear_force_joints(); + void add_force_joint(const GlobPattern &glob); + bool force_joint(const string &name) const; + void set_from_selection(bool from_selection); bool convert_maya(); @@ -144,6 +148,7 @@ private: typedef pvector Globs; Globs _subsets; Globs _ignore_sliders; + Globs _force_joints; MayaNodeTree _tree; diff --git a/pandatool/src/mayaprogs/mayaToEgg.cxx b/pandatool/src/mayaprogs/mayaToEgg.cxx index 86968dec41..7b21e13523 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg.cxx @@ -103,6 +103,13 @@ MayaToEgg() : "as needed.", &MayaToEgg::dispatch_vector_string, NULL, &_ignore_sliders); + add_option + ("force-joint", "name", 0, + "Specifies the name of a DAG node that maya2egg " + "should treat as a joint, even if it does not appear to be a Maya joint " + "and does not appear to be animated.", + &MayaToEgg::dispatch_vector_string, NULL, &_force_joints); + add_option ("v", "", 0, "Increase verbosity. More v's means more verbose.", @@ -174,6 +181,13 @@ run() { } } + if (!_force_joints.empty()) { + converter.clear_force_joints(); + for (si = _force_joints.begin(); si != _force_joints.end(); ++si) { + converter.add_force_joint(GlobPattern(*si)); + } + } + // Copy in the path and animation parameters. apply_parameters(converter); diff --git a/pandatool/src/mayaprogs/mayaToEgg.h b/pandatool/src/mayaprogs/mayaToEgg.h index 3eccab52a0..50a83971bc 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.h +++ b/pandatool/src/mayaprogs/mayaToEgg.h @@ -44,6 +44,7 @@ protected: MayaToEggConverter::TransformType _transform_type; vector_string _subsets; vector_string _ignore_sliders; + vector_string _force_joints; }; #endif