diff --git a/pandatool/src/mayaegg/mayaToEggConverter.cxx b/pandatool/src/mayaegg/mayaToEggConverter.cxx index 23c08fb449..661ef71424 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.cxx +++ b/pandatool/src/mayaegg/mayaToEggConverter.cxx @@ -81,6 +81,7 @@ MayaToEggConverter:: MayaToEggConverter(const string &program_name) : _program_name(program_name) { + _from_selection = false; _polygon_output = false; _polygon_tolerance = 0.01; _ignore_transforms = false; @@ -167,7 +168,7 @@ convert_file(const Filename &filename) { _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 // Description: Fills up the egg_data structure according to the // 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:: -convert_maya() { +convert_maya(bool from_selection) { + _from_selection = from_selection; _textures.clear(); _shaders.clear(); _groups.clear(); @@ -485,16 +489,52 @@ bool MayaToEggConverter:: convert_hierarchy(EggGroupNode *egg_root) { 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); if (!status) { status.perror("MItDag constructor"); 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. - + bool all_ok = true; while (!dag_iterator.isDone()) { MDagPath dag_path; @@ -506,10 +546,10 @@ convert_hierarchy(EggGroupNode *egg_root) { all_ok = false; } } - + dag_iterator.next(); } - + 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); + // 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; } diff --git a/pandatool/src/mayaegg/mayaToEggConverter.h b/pandatool/src/mayaegg/mayaToEggConverter.h index 5665794457..d7f8d4c6ae 100644 --- a/pandatool/src/mayaegg/mayaToEggConverter.h +++ b/pandatool/src/mayaegg/mayaToEggConverter.h @@ -69,7 +69,7 @@ public: virtual string get_extension() const; virtual bool convert_file(const Filename &filename); - bool convert_maya(); + bool convert_maya(bool from_selection); bool open_api(); void close_api(); @@ -127,6 +127,7 @@ private: Tables _tables; string _program_name; + bool _from_selection; public: MayaShaders _shaders; diff --git a/pandatool/src/mayaprogs/mayaPview.cxx b/pandatool/src/mayaprogs/mayaPview.cxx index 9d722721d9..8f29f83485 100755 --- a/pandatool/src/mayaprogs/mayaPview.cxx +++ b/pandatool/src/mayaprogs/mayaPview.cxx @@ -49,6 +49,12 @@ MayaPview() { //////////////////////////////////////////////////////////////////// MStatus MayaPview:: 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; char **argv = NULL; PandaFramework framework; @@ -64,13 +70,7 @@ doIt(const MArgList &) { 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. NodePath aspect_2d = window->get_aspect_2d(); @@ -82,6 +82,10 @@ doIt(const MArgList &) { loading->set_shadow(0.04f, 0.04f); loading->set_align(TextNode::A_center); 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(); window->enable_keyboard(); @@ -93,6 +97,7 @@ doIt(const MArgList &) { } loading_np.remove_node(); + window->center_trackball(framework.get_models()); window->loop_animations(); 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 // 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(); @@ -145,7 +145,7 @@ convert(const NodePath &parent) { EggData egg_data; converter.set_egg_data(&egg_data, false); - if (!converter.convert_maya()) { + if (!converter.convert_maya(true)) { nout << "Errors in conversion.\n"; return false; } diff --git a/pandatool/src/mayaprogs/mayaToEgg.cxx b/pandatool/src/mayaprogs/mayaToEgg.cxx index 6ced8a7fd0..7fb4f717cd 100644 --- a/pandatool/src/mayaprogs/mayaToEgg.cxx +++ b/pandatool/src/mayaprogs/mayaToEgg.cxx @@ -67,6 +67,8 @@ MayaToEgg() : ("v", "", 0, "Increase verbosity. More v's means more verbose.", &MayaToEgg::dispatch_count, NULL, &_verbose); + + _polygon_tolerance = 0.01; _verbose = 0; }