Browse Source

add -bface to maya2egg

David Rose 22 years ago
parent
commit
54047ea893

+ 4 - 1
pandatool/src/mayaegg/mayaEggGroupUserData.I

@@ -25,6 +25,7 @@
 INLINE MayaEggGroupUserData::
 MayaEggGroupUserData() {
   _vertex_color = false;
+  _double_sided = false;
 }
 
 
@@ -36,7 +37,8 @@ MayaEggGroupUserData() {
 INLINE MayaEggGroupUserData::
 MayaEggGroupUserData(const MayaEggGroupUserData &copy) : 
   EggUserData(copy),
-  _vertex_color(copy._vertex_color)
+  _vertex_color(copy._vertex_color),
+  _double_sided(copy._double_sided)
 {
 }
 
@@ -50,4 +52,5 @@ INLINE void MayaEggGroupUserData::
 operator = (const MayaEggGroupUserData &copy) {
   EggUserData::operator = (copy);
   _vertex_color = copy._vertex_color;
+  _double_sided = copy._double_sided;
 }

+ 1 - 0
pandatool/src/mayaegg/mayaEggGroupUserData.h

@@ -35,6 +35,7 @@ public:
   INLINE void operator = (const MayaEggGroupUserData &copy);
 
   bool _vertex_color;
+  bool _double_sided;
 
 public:
   static TypeHandle get_class_type() {

+ 8 - 3
pandatool/src/mayaegg/mayaNodeTree.cxx

@@ -276,13 +276,18 @@ get_egg_group(MayaNodeDesc *node_desc) {
         egg_group->set_model_flag(true);
       }
       
-      // And "vertex-color" has meaning only to this converter.
+      // And "vertex-color" and "double-sided" have meaning only to
+      // this converter.
+      MayaEggGroupUserData *user_data = new MayaEggGroupUserData;
       if (egg_group->has_object_type("vertex-color")) {
         egg_group->remove_object_type("vertex-color");
-        MayaEggGroupUserData *user_data = new MayaEggGroupUserData;
         user_data->_vertex_color = true;
-        egg_group->set_user_data(user_data);
       }
+      if (egg_group->has_object_type("double-sided")) {
+        egg_group->remove_object_type("double-sided");
+        user_data->_double_sided = true;
+      }
+      egg_group->set_user_data(user_data);
     }
 
     node_desc->_egg_group = egg_group;

+ 11 - 6
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -87,6 +87,7 @@ MayaToEggConverter(const string &program_name) :
   _from_selection = false;
   _polygon_output = false;
   _polygon_tolerance = 0.01;
+  _respect_maya_double_sided = true;
   _transform_type = TT_model;
 }
 
@@ -1219,8 +1220,8 @@ make_polyset(const MDagPath &dag_path, const MFnMesh &mesh,
   string name = mesh.name().asChar();
 
   MObject mesh_object = mesh.object();
-  bool double_sided = false;
-  get_bool_attribute(mesh_object, "doubleSided", double_sided);
+  bool maya_double_sided = false;
+  get_bool_attribute(mesh_object, "doubleSided", maya_double_sided);
 
   if (mayaegg_cat.is_spam()) {
     mayaegg_cat.spam()
@@ -1281,14 +1282,18 @@ make_polyset(const MDagPath &dag_path, const MFnMesh &mesh,
   // will be different from world space.
   LMatrix4d vertex_frame_inv = egg_group->get_vertex_frame_inv();
 
-  // Save this modeling flag for the vertex color check later (see the
-  // comment below).
+  // Save these modeling flag for the a check below.
   bool egg_vertex_color = false;
+  bool egg_double_sided = false;
   if (egg_group->has_user_data(MayaEggGroupUserData::get_class_type())) {
-    egg_vertex_color = 
-      DCAST(MayaEggGroupUserData, egg_group->get_user_data())->_vertex_color;
+    MayaEggGroupUserData *user_data = 
+      DCAST(MayaEggGroupUserData, egg_group->get_user_data());
+    egg_vertex_color = user_data->_vertex_color;
+    egg_double_sided = user_data->_double_sided;
   }
 
+  bool double_sided = _respect_maya_double_sided ? maya_double_sided : egg_double_sided;
+
   while (!pi.isDone()) {
     EggPolygon *egg_poly = new EggPolygon;
     egg_group->add_child(egg_poly);

+ 1 - 0
pandatool/src/mayaegg/mayaToEggConverter.h

@@ -132,6 +132,7 @@ public:
 
   bool _polygon_output;
   double _polygon_tolerance;
+  bool _respect_maya_double_sided;
 
   enum TransformType {
     TT_invalid,

+ 12 - 0
pandatool/src/mayaprogs/mayaToEgg.cxx

@@ -54,6 +54,17 @@ MayaToEgg() :
      "0.01.",
      &MayaToEgg::dispatch_double, NULL, &_polygon_tolerance);
 
+  add_option
+    ("bface", "", 0,
+     "Respect the Maya \"double sided\" rendering flag to indicate whether "
+     "polygons should be double-sided or single-sided.  Since this flag "
+     "is set to double-sided by default in Maya, it is often better to "
+     "ignore this flag (unless your modelers are diligent in turning it "
+     "off where it is not desired).  If this flag is not specified, the "
+     "default is to treat all polygons as single-sided, unless an "
+     "egg object type of \"double-sided\" is set.",
+     &MayaToEgg::dispatch_none, &_respect_maya_double_sided);
+
   add_option
     ("trans", "type", 0,
      "Specifies which transforms in the Maya file should be converted to "
@@ -108,6 +119,7 @@ run() {
   // Copy in the command-line parameters.
   converter._polygon_output = _polygon_output;
   converter._polygon_tolerance = _polygon_tolerance;
+  converter._respect_maya_double_sided = _respect_maya_double_sided;
   converter._transform_type = _transform_type;
 
   // Copy in the path and animation parameters.

+ 1 - 0
pandatool/src/mayaprogs/mayaToEgg.h

@@ -39,6 +39,7 @@ protected:
   int _verbose;
   bool _polygon_output;
   double _polygon_tolerance;
+  bool _respect_maya_double_sided;
   MayaToEggConverter::TransformType _transform_type;
 };