Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/mayaprogs/mayaPview.cxx

Go to the documentation of this file.
00001 // Filename: mayaPview.cxx
00002 // Created by:  drose (10Mar03)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "mayaPview.h"
00020 #include "mayaToEggConverter.h"
00021 #include "eggData.h"
00022 #include "load_egg_file.h"
00023 #include "config_util.h"
00024 #include "textNode.h"
00025 
00026 // We must define this to prevent Maya from doubly-declaring its
00027 // MApiVersion string in this file as well as in libmayaegg.
00028 #define _MApiVersion
00029 
00030 #include "pre_maya_include.h"
00031 #include <maya/MString.h>
00032 #include <maya/MFnPlugin.h>
00033 #include <maya/MFileIO.h>
00034 #include "post_maya_include.h"
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //     Function: MayaPview::Constructor
00038 //       Access: Public
00039 //  Description:
00040 ////////////////////////////////////////////////////////////////////
00041 MayaPview::
00042 MayaPview() {
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: MayaPview::doIt
00047 //       Access: Public, Virtual
00048 //  Description: Called when the plugin command is invoked.
00049 ////////////////////////////////////////////////////////////////////
00050 MStatus MayaPview::
00051 doIt(const MArgList &) {
00052   // Maya seems to run each invocation of the plugin in a separate
00053   // thread.  To minimize conflict in our
00054   // not-yet-completely-thread-safe Panda, we'll create a separate
00055   // PandaFramework for each invocation, even though in principle we
00056   // could be sharing one framework for all of them.
00057 
00058   int argc = 0;
00059   char **argv = NULL;
00060   PandaFramework framework;
00061   framework.open_framework(argc, argv);
00062   framework.set_window_title("Panda Viewer");
00063   framework.enable_default_keys();
00064 
00065   PT(WindowFramework) window;
00066   window = framework.open_window();
00067   if (window == (WindowFramework *)NULL) {
00068     // Couldn't open a window.
00069     nout << "Couldn't open a window!\n";
00070     return MS::kFailure;
00071   }
00072 
00073   // We've successfully opened a window.
00074 
00075   // Put up a "loading" message for the user's benefit.
00076   NodePath aspect_2d = window->get_aspect_2d();
00077   PT(TextNode) loading = new TextNode("loading");
00078   NodePath loading_np = aspect_2d.attach_new_node(loading);
00079   loading_np.set_scale(0.125f);
00080   loading->set_text_color(1.0f, 1.0f, 1.0f, 1.0f);
00081   loading->set_shadow_color(0.0f, 0.0f, 0.0f, 1.0f);
00082   loading->set_shadow(0.04f, 0.04f);
00083   loading->set_align(TextNode::A_center);
00084   loading->set_text("Loading...");
00085 
00086   // Allow a couple of frames to go by so the window will be fully
00087   // created and the text will be visible.
00088   framework.do_frame();
00089   framework.do_frame();
00090 
00091   window->enable_keyboard();
00092   window->setup_trackball();
00093   framework.get_models().instance_to(window->get_render());
00094 
00095   if (!convert(framework.get_models())) {
00096     nout << "failure in conversion.\n";
00097     return MS::kFailure;
00098   }
00099 
00100   nout << "successfully converted.\n";
00101 
00102   loading_np.remove_node();
00103   window->center_trackball(framework.get_models());
00104   window->loop_animations();
00105 
00106   framework.main_loop();
00107   return MS::kSuccess;
00108 }
00109 
00110 ////////////////////////////////////////////////////////////////////
00111 //     Function: MayaPview::creator
00112 //       Access: Public, Static
00113 //  Description: This is used to create a new instance of the plugin.
00114 ////////////////////////////////////////////////////////////////////
00115 void *MayaPview::
00116 creator() {
00117   return new MayaPview;
00118 }
00119 
00120 ////////////////////////////////////////////////////////////////////
00121 //     Function: MayaPview::convert
00122 //       Access: Private
00123 //  Description: Actually converts the Maya selection to Panda
00124 //               geometry, and parents it to the indicated NodePath.
00125 ////////////////////////////////////////////////////////////////////
00126 bool MayaPview::
00127 convert(const NodePath &parent) {
00128   // Now make a converter to get all the Maya structures.
00129   MayaToEggConverter converter("plug-in");
00130 
00131   // We always want polygon output since we want to be able to see the
00132   // results.
00133   converter._polygon_output = true;
00134 
00135   PathReplace *path_replace = converter.get_path_replace();
00136 
00137   // Accept relative pathnames in the Maya file.
00138   Filename source_file = 
00139     Filename::from_os_specific(MFileIO::currentFile().asChar());
00140   string source_dir = source_file.get_dirname();
00141   if (!source_dir.empty()) {
00142     path_replace->_path.append_directory(source_dir);
00143   }
00144 
00145   // Also search along the model path.
00146   path_replace->_path.append_path(get_model_path());
00147 
00148   EggData egg_data;
00149   converter.set_egg_data(&egg_data, false);
00150 
00151   if (!converter.convert_maya(true)) {
00152     nout << "Errors in conversion.\n";
00153     return false;
00154   }
00155 
00156   // Now the converter has filled up our egg structure with data, so
00157   // convert this egg data to Panda data for immediate viewing.
00158   egg_data.set_coordinate_system(CS_default);
00159   PT(PandaNode) result = load_egg_data(egg_data);
00160 
00161   if (result == (PandaNode *)NULL) {
00162     nout << "Unable to load converted egg data.\n";
00163     return false;
00164   }
00165 
00166   parent.attach_new_node(result);
00167   return true;
00168 }
00169 
00170 
00171 
00172 
00173 ////////////////////////////////////////////////////////////////////
00174 //     Function: initializePlugin
00175 //  Description: Called by Maya when the plugin is loaded.
00176 ////////////////////////////////////////////////////////////////////
00177 EXPCL_MISC MStatus 
00178 initializePlugin(MObject obj) {
00179   // This code is just for debugging, to cause Notify to write its
00180   // output to a log file we can inspect, so we can see the error
00181   // messages output by DX7 or DX8 just before it does a panic exit
00182   // (and thereby shuts down Maya and its output window).
00183   /*
00184   MultiplexStream *local_nout = new MultiplexStream();
00185   Notify::ptr()->set_ostream_ptr(local_nout, 0);
00186   local_nout->add_file(Filename("/c/Cygwin/home/drose/foo.log"));
00187   local_nout->add_standard_output();
00188   */
00189 
00190   MFnPlugin plugin(obj, "VR Studio", "1.0");
00191   MStatus status;
00192   status = plugin.registerCommand("pview", MayaPview::creator);
00193   if (!status) {
00194     status.perror("registerCommand");
00195   }
00196 
00197   return status;
00198 }
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function: uninitializePlugin
00202 //  Description: Called by Maya when the plugin is unloaded.
00203 ////////////////////////////////////////////////////////////////////
00204 EXPCL_MISC MStatus
00205 uninitializePlugin(MObject obj) {
00206   MFnPlugin plugin(obj);
00207   MStatus status;
00208   status = plugin.deregisterCommand("pview");
00209 
00210   if (!status) {
00211     status.perror("deregisterCommand");
00212   }
00213   return status;
00214 }

Generated on Fri May 2 03:21:26 2003 for Panda-Tool by doxygen1.3