Browse Source

more refinements to mayapview

David Rose 23 years ago
parent
commit
3ba5267982

+ 60 - 9
pandatool/src/mayaegg/mayaToEggConverter.cxx

@@ -81,6 +81,7 @@ MayaToEggConverter::
 MayaToEggConverter(const string &program_name) :
 MayaToEggConverter(const string &program_name) :
   _program_name(program_name)
   _program_name(program_name)
 {
 {
+  _from_selection = false;
   _polygon_output = false;
   _polygon_output = false;
   _polygon_tolerance = 0.01;
   _polygon_tolerance = 0.01;
   _ignore_transforms = false;
   _ignore_transforms = false;
@@ -167,7 +168,7 @@ convert_file(const Filename &filename) {
     _character_name = filename.get_basename_wo_extension();
     _character_name = filename.get_basename_wo_extension();
   }
   }
 
 
-  return convert_maya();
+  return convert_maya(false);
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -175,10 +176,13 @@ convert_file(const Filename &filename) {
 //       Access: Public
 //       Access: Public
 //  Description: Fills up the egg_data structure according to the
 //  Description: Fills up the egg_data structure according to the
 //               global maya model data.  Returns true if successful,
 //               global maya model data.  Returns true if successful,
-//               false if there is an error.
+//               false if there is an error.  If from_selection is
+//               true, the converted geometry is based on that which
+//               is selected; otherwise, it is the entire Maya scene.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool MayaToEggConverter::
 bool MayaToEggConverter::
-convert_maya() {
+convert_maya(bool from_selection) {
+  _from_selection = from_selection;
   _textures.clear();
   _textures.clear();
   _shaders.clear();
   _shaders.clear();
   _groups.clear();
   _groups.clear();
@@ -485,16 +489,52 @@ bool MayaToEggConverter::
 convert_hierarchy(EggGroupNode *egg_root) {
 convert_hierarchy(EggGroupNode *egg_root) {
   MStatus status;
   MStatus status;
 
 
+  if (_from_selection) {
+    // Get only the selected geometry.
+    MSelectionList selection;
+    status = MGlobal::getActiveSelectionList(selection);
+    if (!status) {
+      status.perror("MGlobal::getActiveSelectionList");
+      return false;
+    }
+
+    // Get the selected geometry only if the selection is nonempty;
+    // otherwise, get the whole scene anyway.
+    if (!selection.isEmpty()) {
+      bool all_ok = true;
+      unsigned int length = selection.length();
+      for (unsigned int i = 0; i < length; i++) {
+        MDagPath dag_path;
+        status = selection.getDagPath(i, dag_path);
+        if (!status) {
+          status.perror("MSelectionList::getDagPath");
+        } else {
+          if (!process_model_node(dag_path, egg_root)) {
+            all_ok = false;
+          }
+        }
+      }
+      return all_ok;
+
+    } else {
+      mayaegg_cat.info()
+        << "Selection list is empty.\n";
+      // Fall through.
+    }
+  }
+
+  // Get the entire Maya scene.
+  
   MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
   MItDag dag_iterator(MItDag::kDepthFirst, MFn::kTransform, &status);
   if (!status) {
   if (!status) {
     status.perror("MItDag constructor");
     status.perror("MItDag constructor");
     return false;
     return false;
   }
   }
-
-  // This while loop walks through the entire Maya hierarchy, one node
-  // at a time.  Maya's MItDag object automatically performs a
+  
+  // This while loop walks through the entire Maya hierarchy, one
+  // node at a time.  Maya's MItDag object automatically performs a
   // depth-first traversal of its scene graph.
   // depth-first traversal of its scene graph.
-
+  
   bool all_ok = true;
   bool all_ok = true;
   while (!dag_iterator.isDone()) {
   while (!dag_iterator.isDone()) {
     MDagPath dag_path;
     MDagPath dag_path;
@@ -506,10 +546,10 @@ convert_hierarchy(EggGroupNode *egg_root) {
         all_ok = false;
         all_ok = false;
       }
       }
     }
     }
-
+    
     dag_iterator.next();
     dag_iterator.next();
   }
   }
-
+  
   return all_ok;
   return all_ok;
 }
 }
 
 
@@ -819,6 +859,17 @@ make_nurbs_surface(const MDagPath &dag_path, MFnNurbsSurface &surface,
     }
     }
     make_polyset(polyset_path, polyset_fn, egg_group, egg_root, shader);
     make_polyset(polyset_path, polyset_fn, egg_group, egg_root, shader);
 
 
+    // Now remove the polyset we created.
+    MFnDagNode parent_node(polyset_parent, &status);
+    if (!status) {
+      status.perror("MFnDagNode constructor");
+      return;
+    }
+    status = parent_node.removeChild(polyset);
+    if (!status) {
+      status.perror("MFnDagNode::removeChild");
+    }
+
     return;
     return;
   }
   }
 
 

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

@@ -69,7 +69,7 @@ public:
   virtual string get_extension() const;
   virtual string get_extension() const;
 
 
   virtual bool convert_file(const Filename &filename);
   virtual bool convert_file(const Filename &filename);
-  bool convert_maya();
+  bool convert_maya(bool from_selection);
 
 
   bool open_api();
   bool open_api();
   void close_api();
   void close_api();
@@ -127,6 +127,7 @@ private:
   Tables _tables;
   Tables _tables;
 
 
   string _program_name;
   string _program_name;
+  bool _from_selection;
 
 
 public:
 public:
   MayaShaders _shaders;
   MayaShaders _shaders;

+ 14 - 14
pandatool/src/mayaprogs/mayaPview.cxx

@@ -49,6 +49,12 @@ MayaPview() {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 MStatus MayaPview::
 MStatus MayaPview::
 doIt(const MArgList &) {
 doIt(const MArgList &) {
+  // Maya seems to run each invocation of the plugin in a separate
+  // thread.  To minimize conflict in our
+  // not-yet-completely-thread-safe Panda, we'll create a separate
+  // PandaFramework for each invocation, even though in principle we
+  // could be sharing one framework for all of them.
+
   int argc = 0;
   int argc = 0;
   char **argv = NULL;
   char **argv = NULL;
   PandaFramework framework;
   PandaFramework framework;
@@ -64,13 +70,7 @@ doIt(const MArgList &) {
     return MS::kFailure;
     return MS::kFailure;
   }
   }
 
 
-  // We've successfully opened a window.  Let a couple of frames go by
-  // to ensure the window is fully open and ready before we try to
-  // render anything.  This is a kludge for now until we settle on
-  // what the appropriate startup behavior should be for these
-  // windows.
-  framework.do_frame();
-  framework.do_frame();
+  // We've successfully opened a window.
 
 
   // Put up a "loading" message for the user's benefit.
   // Put up a "loading" message for the user's benefit.
   NodePath aspect_2d = window->get_aspect_2d();
   NodePath aspect_2d = window->get_aspect_2d();
@@ -82,6 +82,10 @@ doIt(const MArgList &) {
   loading->set_shadow(0.04f, 0.04f);
   loading->set_shadow(0.04f, 0.04f);
   loading->set_align(TextNode::A_center);
   loading->set_align(TextNode::A_center);
   loading->set_text("Loading...");
   loading->set_text("Loading...");
+
+  // Allow a couple of frames to go by so the window will be fully
+  // created and the text will be visible.
+  framework.do_frame();
   framework.do_frame();
   framework.do_frame();
 
 
   window->enable_keyboard();
   window->enable_keyboard();
@@ -93,6 +97,7 @@ doIt(const MArgList &) {
   }
   }
 
 
   loading_np.remove_node();
   loading_np.remove_node();
+  window->center_trackball(framework.get_models());
   window->loop_animations();
   window->loop_animations();
 
 
   framework.main_loop();
   framework.main_loop();
@@ -122,12 +127,7 @@ convert(const NodePath &parent) {
 
 
   // We always want polygon output since we want to be able to see the
   // We always want polygon output since we want to be able to see the
   // results.
   // results.
-
-  // Actually, for now we'll leave this false, because the nurbs
-  // tesselation code in MayaToEggConverter is destructive to the
-  // original nurbs.
-  //  converter._polygon_output = true;
-  converter._polygon_output = false;
+  converter._polygon_output = true;
 
 
   PathReplace *path_replace = converter.get_path_replace();
   PathReplace *path_replace = converter.get_path_replace();
 
 
@@ -145,7 +145,7 @@ convert(const NodePath &parent) {
   EggData egg_data;
   EggData egg_data;
   converter.set_egg_data(&egg_data, false);
   converter.set_egg_data(&egg_data, false);
 
 
-  if (!converter.convert_maya()) {
+  if (!converter.convert_maya(true)) {
     nout << "Errors in conversion.\n";
     nout << "Errors in conversion.\n";
     return false;
     return false;
   }
   }

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

@@ -67,6 +67,8 @@ MayaToEgg() :
     ("v", "", 0,
     ("v", "", 0,
      "Increase verbosity.  More v's means more verbose.",
      "Increase verbosity.  More v's means more verbose.",
      &MayaToEgg::dispatch_count, NULL, &_verbose);
      &MayaToEgg::dispatch_count, NULL, &_verbose);
+
+  _polygon_tolerance = 0.01;
   _verbose = 0;
   _verbose = 0;
 }
 }