From 26869342b8ebf29ad602d21ce60c567e8ca018b5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Wed, 12 Nov 2003 18:53:43 +0000 Subject: [PATCH] support hard-skinning --- .../src/eggcharbase/eggJointNodePointer.cxx | 2 +- pandatool/src/maya/maya_funcs.cxx | 24 ++++++++++- pandatool/src/maya/maya_funcs.h | 3 ++ pandatool/src/mayaegg/mayaNodeDesc.cxx | 40 +++++++++++++++++++ pandatool/src/mayaegg/mayaToEggConverter.cxx | 34 +++++++--------- pandatool/src/mayaegg/mayaToEggConverter.h | 3 +- 6 files changed, 84 insertions(+), 22 deletions(-) diff --git a/pandatool/src/eggcharbase/eggJointNodePointer.cxx b/pandatool/src/eggcharbase/eggJointNodePointer.cxx index 84a2642366..eba29d492b 100644 --- a/pandatool/src/eggcharbase/eggJointNodePointer.cxx +++ b/pandatool/src/eggcharbase/eggJointNodePointer.cxx @@ -208,7 +208,7 @@ expose(EggGroup::DCSType dcs_type) { bool EggJointNodePointer:: has_vertices() const { if (_joint != (EggGroup *)NULL) { - return (_joint->vref_size() != 0); + return (_joint->vref_size() != 0) || _joint->has_primitives(); } return false; diff --git a/pandatool/src/maya/maya_funcs.cxx b/pandatool/src/maya/maya_funcs.cxx index 5476c6d0d5..a2ed5347be 100644 --- a/pandatool/src/maya/maya_funcs.cxx +++ b/pandatool/src/maya/maya_funcs.cxx @@ -65,6 +65,21 @@ get_maya_plug(MObject &node, const string &attribute_name, MPlug &plug) { return true; } +//////////////////////////////////////////////////////////////////// +// Function: is_connected +// Description: Returns true if the named connection exists on the +// node and is connected to anything, false otherwise. +//////////////////////////////////////////////////////////////////// +bool +is_connected(MObject &node, const string &attribute_name) { + MPlug plug; + if (!get_maya_plug(node, attribute_name, plug)) { + return false; + } + + return plug.isConnected(); +} + //////////////////////////////////////////////////////////////////// // Function: has_attribute // Description: Returns true if the node has the indicated attribute, @@ -559,10 +574,17 @@ list_maya_attributes(MObject &node) { << name << " has " << connections.length() << " connections.\n"; for (i = 0; i < connections.length(); i++) { MPlug plug = connections[i]; + maya_cat.info(false) << " " << i << ". " << plug.name().asChar() << ", " << plug.attribute().apiTypeStr() << ", " - << plug.node().apiTypeStr() << "\n"; + << plug.node().apiTypeStr(); + if (plug.isConnected()) { + maya_cat.info(false) + << " (*)"; + } + maya_cat.info(false) + << "\n"; } } diff --git a/pandatool/src/maya/maya_funcs.h b/pandatool/src/maya/maya_funcs.h index 635ade773f..2343edaa55 100644 --- a/pandatool/src/maya/maya_funcs.h +++ b/pandatool/src/maya/maya_funcs.h @@ -38,6 +38,9 @@ class MObject; bool get_maya_plug(MObject &node, const string &attribute_name, MPlug &plug); +bool +is_connected(MObject &node, const string &attribute_name); + template bool get_maya_attribute(MObject &node, const string &attribute_name, diff --git a/pandatool/src/mayaegg/mayaNodeDesc.cxx b/pandatool/src/mayaegg/mayaNodeDesc.cxx index 820536e7fc..8f4e7c7fa1 100755 --- a/pandatool/src/mayaegg/mayaNodeDesc.cxx +++ b/pandatool/src/mayaegg/mayaNodeDesc.cxx @@ -17,9 +17,24 @@ //////////////////////////////////////////////////////////////////// #include "mayaNodeDesc.h" +#include "maya_funcs.h" TypeHandle MayaNodeDesc::_type_handle; +// This is a list of the names of Maya connections that count as a +// transform. +static const char *transform_connections[] = { + "translate", + "translateX", + "translateY", + "translateZ", + "rotate", + "rotateX", + "rotateY", + "rotateZ", +}; +static const int num_transform_connections = sizeof(transform_connections) / sizeof(const char *); + //////////////////////////////////////////////////////////////////// // Function: MayaNodeDesc::Constructor // Access: Public @@ -72,6 +87,31 @@ from_dag_path(const MDagPath &dag_path) { if (_parent != (MayaNodeDesc *)NULL) { _parent->mark_joint_parent(); } + + } else { + // The node is not a joint, but maybe its transform is + // controlled by connected inputs. If so, we should treat it + // like a joint. + bool transform_connected = false; + + MStatus status; + MObject node = dag_path.node(&status); + if (status) { + for (int i = 0; + i < num_transform_connections && !transform_connected; + i++) { + if (is_connected(node, transform_connections[i])) { + transform_connected = true; + } + } + } + + if (transform_connected) { + _joint_type = JT_joint; + if (_parent != (MayaNodeDesc *)NULL) { + _parent->mark_joint_parent(); + } + } } } } diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 4677f99517..54d09ad648 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -662,15 +662,7 @@ process_model_node(MayaNodeDesc *node_desc) { mayaegg_cat.debug(false) << "\n"; } - if (node_desc->is_joint()) { - // Don't bother with joints unless we're getting an animatable - // model. - if (_animation_convert == AC_model) { - EggGroup *egg_group = _tree.get_egg_group(node_desc); - get_joint_transform(dag_path, egg_group); - } - - } else if (dag_node.inUnderWorld()) { + if (dag_node.inUnderWorld()) { if (mayaegg_cat.is_debug()) { mayaegg_cat.debug() << "Ignoring underworld node " << path @@ -700,7 +692,7 @@ process_model_node(MayaNodeDesc *node_desc) { } else if (dag_path.hasFn(MFn::kNurbsSurface)) { EggGroup *egg_group = _tree.get_egg_group(node_desc); - get_transform(dag_path, egg_group); + get_transform(node_desc, dag_path, egg_group); MFnNurbsSurface surface(dag_path, &status); if (!status) { @@ -718,7 +710,7 @@ process_model_node(MayaNodeDesc *node_desc) { // things in them. if (_animation_convert != AC_model) { EggGroup *egg_group = _tree.get_egg_group(node_desc); - get_transform(dag_path, egg_group); + get_transform(node_desc, dag_path, egg_group); MFnNurbsCurve curve(dag_path, &status); if (!status) { @@ -732,7 +724,7 @@ process_model_node(MayaNodeDesc *node_desc) { } else if (dag_path.hasFn(MFn::kMesh)) { EggGroup *egg_group = _tree.get_egg_group(node_desc); - get_transform(dag_path, egg_group); + get_transform(node_desc, dag_path, egg_group); MFnMesh mesh(dag_path, &status); if (!status) { @@ -761,13 +753,13 @@ process_model_node(MayaNodeDesc *node_desc) { // locators within character models may not be meaningful. egg_group->set_dcs_type(EggGroup::DC_net); } - get_transform(dag_path, egg_group); + get_transform(node_desc, dag_path, egg_group); make_locator(dag_path, dag_node, egg_group); } else { // Just a generic node. EggGroup *egg_group = _tree.get_egg_group(node_desc); - get_transform(dag_path, egg_group); + get_transform(node_desc, dag_path, egg_group); } return true; @@ -780,10 +772,15 @@ process_model_node(MayaNodeDesc *node_desc) { // and applies it to the corresponding Egg node. //////////////////////////////////////////////////////////////////// void MayaToEggConverter:: -get_transform(const MDagPath &dag_path, EggGroup *egg_group) { +get_transform(MayaNodeDesc *node_desc, const MDagPath &dag_path, + EggGroup *egg_group) { if (_animation_convert == AC_model) { // When we're getting an animated model, we only get transforms - // for joints. + // for joints, and they get converted in a special way. + + if (node_desc->is_joint()) { + get_joint_transform(dag_path, egg_group); + } return; } @@ -1768,9 +1765,8 @@ get_vertex_weights(const MDagPath &dag_path, const MFnMesh &mesh, it.next(); } - - mayaegg_cat.error() - << "Unable to find a cluster handle for the DG node.\n"; + + // The mesh was not soft-skinned. return false; } diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 23a120c16c..b8a31855fe 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -97,7 +97,8 @@ private: bool convert_hierarchy(EggGroupNode *egg_root); bool process_model_node(MayaNodeDesc *node_desc); - void get_transform(const MDagPath &dag_path, EggGroup *egg_group); + void get_transform(MayaNodeDesc *node_desc, const MDagPath &dag_path, + EggGroup *egg_group); void get_joint_transform(const MDagPath &dag_path, EggGroup *egg_group); // I ran into core dumps trying to pass around a MFnMesh object by