16 #define __OPENTRANSPORTPROVIDERS__
19 #include "mayaPview.h"
20 #include "mayaToEggConverter.h"
22 #include "load_egg_file.h"
23 #include "config_util.h"
24 #include "config_chan.h"
25 #include "config_gobj.h"
27 #include "multiplexStream.h"
28 #include "distanceUnit.h"
29 #include "configVariableEnum.h"
35 #include "pre_maya_include.h"
36 #include <maya/MString.h>
37 #include <maya/MFnPlugin.h>
38 #include <maya/MFileIO.h>
39 #include <maya/MArgParser.h>
40 #include <maya/MArgList.h>
41 #include <maya/MSyntax.h>
42 #include <maya/MProgressWindow.h>
43 #include "post_maya_include.h"
50 #define SEPARATE_PVIEW 1
68 doIt(
const MArgList &args) {
73 syntax.addFlag(
"a",
"animate");
75 MArgParser parser(syntax, args, &result);
77 result.perror(
"arguments");
81 bool animate = parser.isFlagSet(
"a", &result);
83 result.perror(
"isFlagSet");
87 if (!MProgressWindow::reserve()) {
88 nout <<
"Couldn't reserve progress window.\n";
91 MProgressWindow::setTitle(
"Sending to pview");
92 MProgressWindow::setInterruptable(
false);
93 MProgressWindow::setProgressRange(0, 3);
94 MProgressWindow::setProgressStatus(
"Converting scene");
95 MProgressWindow::startProgress();
105 textures_header_only =
true;
108 if (!convert(root, animate)) {
109 nout <<
"failure in conversion.\n";
110 MProgressWindow::endProgress();
114 MProgressWindow::setProgressStatus(
"Writing bam file");
115 MProgressWindow::advanceProgress(1);
118 nout <<
"Couldn't write to " << bam_filename <<
".\n";
119 MProgressWindow::endProgress();
123 MProgressWindow::setProgressStatus(
"Spawning pview");
124 MProgressWindow::advanceProgress(1);
127 string pview_args =
"-clD";
129 pview_args =
"-clDa";
134 string quoted = string(
"\"") + bam_filename.
get_fullpath() + string(
"\"");
135 nout <<
"pview " << pview_args <<
" " << quoted <<
"\n";
136 int retval = _spawnlp(_P_DETACH,
"pview",
137 "pview", pview_args.c_str(), quoted.c_str(), NULL);
140 MProgressWindow::endProgress();
144 nout <<
"pview running.\n";
145 MProgressWindow::endProgress();
147 #else // SEPARATE_PVIEW
166 nout <<
"Couldn't open a window!\n";
167 MProgressWindow::endProgress();
174 NodePath aspect_2d = window->get_aspect_2d();
178 loading->set_text_color(1.0f, 1.0f, 1.0f, 1.0f);
179 loading->set_shadow_color(0.0f, 0.0f, 0.0f, 1.0f);
180 loading->set_shadow(0.04, 0.04);
181 loading->set_align(TextNode::A_center);
182 loading->set_text(
"Loading...");
189 window->enable_keyboard();
190 window->setup_trackball();
193 if (!convert(framework.
get_models(), animate)) {
194 nout <<
"failure in conversion.\n";
195 MProgressWindow::endProgress();
199 nout <<
"successfully converted.\n";
202 window->center_trackball(framework.
get_models());
203 window->loop_animations();
206 window->set_anim_controls(
true);
209 MProgressWindow::endProgress();
211 #endif // SEPARATE_PVIEW
233 convert(
const NodePath &parent,
bool animate) {
239 converter._polygon_output =
true;
240 converter._polygon_tolerance = 0.01;
244 converter.set_animation_convert(AC_both);
248 compress_channels =
false;
251 PathReplace *path_replace = converter.get_path_replace();
257 if (!source_dir.empty()) {
265 converter.set_egg_data(egg_data);
266 converter.set_from_selection(true);
267 converter.set_neutral_frame(-1);
269 if (!converter.convert_maya()) {
270 nout <<
"Errors in conversion.\n";
274 MProgressWindow::setProgressStatus(
"Converting to bam");
275 MProgressWindow::advanceProgress(1);
279 DistanceUnit input_units = converter.get_input_units();
281 if (input_units != DU_invalid && ptloader_units != DU_invalid &&
282 input_units != ptloader_units) {
286 <<
"Converting from " << format_long_unit(input_units)
287 <<
" to " << format_long_unit(ptloader_units) <<
"\n";
288 double scale = convert_units(input_units, ptloader_units);
292 egg_data->set_coordinate_system(CS_default);
293 PT(
PandaNode) result = load_egg_data(egg_data);
296 nout <<
"Unable to load converted egg data.\n";
312 initializePlugin(MObject obj) {
324 MFnPlugin plugin(obj,
"VR Studio",
"1.0");
328 status.perror(
"registerCommand");
339 uninitializePlugin(MObject obj) {
340 MFnPlugin plugin(obj);
342 status = plugin.deregisterCommand(
"pview");
345 status.perror(
"deregisterCommand");
string get_fullpath() const
Returns the entire filename: directory, basename, extension.
void set_extension(const string &s)
Replaces the file extension.
A basic node of the scene graph or data graph.
bool unlink() const
Permanently deletes the file associated with the filename, if possible.
void enable_default_keys()
Sets callbacks on the event handler to handle all of the normal viewer keys, like t to toggle texture...
NodePath & get_models()
Returns the root of the scene graph normally reserved for parenting models and such.
void set_scale(PN_stdfloat scale)
Sets the scale component of the transform, leaving translation and rotation untouched.
This encapsulates the data that is normally associated with a single window, or with a single display...
bool write_bam_file(const Filename &filename) const
Writes the contents of this node and below out to a bam file with the indicated filename.
static LMatrix4d scale_mat(const LVecBase3d &scale)
Returns a matrix that applies the indicated scale in each of the three axes.
string get_dirname() const
Returns the directory part of the filename.
void append_directory(const Filename &directory)
Adds a new directory to the end of the search list.
NodePath instance_to(const NodePath &other, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Adds the referenced node of the NodePath as a child of the referenced node of the indicated other Nod...
This is the primary interface into all the egg data, and the root of the egg file structure...
static Thread * get_current_thread()
Returns a pointer to the currently-executing Thread object.
void append_path(const string &path, const string &separator=string())
Adds all of the directories listed in the search path to the end of the search list.
static Filename temporary(const string &dirname, const string &prefix, const string &suffix=string(), Type type=T_general)
Generates a temporary filename within the indicated directory, using the indicated prefix...
This class serves as a plug-in to Maya to allow viewing the current Maya selection as it will be conv...
The name of a file, such as a texture file or an Egg file.
void main_loop()
Called to yield control to the panda framework.
This class specializes ConfigVariable as an enumerated type.
WindowFramework * open_window()
Opens a window on the default graphics pipe.
This class supervises the construction of an EggData structure from a single Maya file...
static void * creator()
This is used to create a new instance of the plugin.
void open_framework(int &argc, char **&argv)
Should be called once at the beginning of the application to initialize Panda (and the framework) for...
void remove_node(Thread *current_thread=Thread::get_current_thread())
Disconnects the referenced node from the scene graph.
This encapsulates the user's command-line request to replace existing, incorrect pathnames to models ...
The primary interface to this module.
void set_window_title(const string &title)
Specifies the title that is set for all subsequently created windows.
This class serves to provide a high-level framework for basic applications that use Panda in simple w...
virtual MStatus doIt(const MArgList &args)
Called when the plugin command is invoked.
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
NodePath attach_new_node(PandaNode *node, int sort=0, Thread *current_thread=Thread::get_current_thread()) const
Attaches a new node, with or without existing parents, to the scene graph below the referenced node o...
virtual bool do_frame(Thread *current_thread)
Renders one frame and performs all associated processing.
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).