respect -a for animate

This commit is contained in:
David Rose 2005-10-06 18:04:42 +00:00
parent 6e8a686ef9
commit ea17cc3fc0
4 changed files with 59 additions and 13 deletions

View File

@ -32,6 +32,9 @@
#include <maya/MString.h> #include <maya/MString.h>
#include <maya/MFnPlugin.h> #include <maya/MFnPlugin.h>
#include <maya/MFileIO.h> #include <maya/MFileIO.h>
#include <maya/MArgParser.h>
#include <maya/MArgList.h>
#include <maya/MSyntax.h>
#include "post_maya_include.h" #include "post_maya_include.h"
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -49,13 +52,30 @@ MayaPview() {
// Description: Called when the plugin command is invoked. // Description: Called when the plugin command is invoked.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
MStatus MayaPview:: MStatus MayaPview::
doIt(const MArgList &) { doIt(const MArgList &args) {
MStatus result;
// First, parse the plugin arguments.
MSyntax syntax;
syntax.addFlag("a", "animate");
MArgParser parser(syntax, args, &result);
if (!result) {
result.perror("arguments");
return result;
}
bool animate = parser.isFlagSet("a", &result);
if (!result) {
result.perror("isFlagSet");
return result;
}
// Maya seems to run each invocation of the plugin in a separate // Maya seems to run each invocation of the plugin in a separate
// thread. To minimize conflict in our // thread. To minimize conflict in our
// not-yet-completely-thread-safe Panda, we'll create a separate // not-yet-completely-thread-safe Panda, we'll create a separate
// PandaFramework for each invocation, even though in principle we // PandaFramework for each invocation, even though in principle we
// could be sharing one framework for all of them. // 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;
@ -93,7 +113,7 @@ doIt(const MArgList &) {
window->setup_trackball(); window->setup_trackball();
framework.get_models().instance_to(window->get_render()); framework.get_models().instance_to(window->get_render());
if (!convert(framework.get_models())) { if (!convert(framework.get_models(), animate)) {
nout << "failure in conversion.\n"; nout << "failure in conversion.\n";
return MS::kFailure; return MS::kFailure;
} }
@ -125,7 +145,7 @@ creator() {
// geometry, and parents it to the indicated NodePath. // geometry, and parents it to the indicated NodePath.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
bool MayaPview:: bool MayaPview::
convert(const NodePath &parent) { convert(const NodePath &parent, bool animate) {
// Now make a converter to get all the Maya structures. // Now make a converter to get all the Maya structures.
MayaToEggConverter converter("plug-in"); MayaToEggConverter converter("plug-in");
@ -133,8 +153,10 @@ convert(const NodePath &parent) {
// results. // results.
converter._polygon_output = true; converter._polygon_output = true;
// We also want to get the animation if there is any. if (animate) {
converter.set_animation_convert(AC_both); // We also want to get the animation if there is any.
converter.set_animation_convert(AC_both);
}
PathReplace *path_replace = converter.get_path_replace(); PathReplace *path_replace = converter.get_path_replace();

View File

@ -37,12 +37,12 @@
class MayaPview : public MPxCommand { class MayaPview : public MPxCommand {
public: public:
MayaPview(); MayaPview();
virtual MStatus doIt(const MArgList &); virtual MStatus doIt(const MArgList &args);
static void *creator(); static void *creator();
private: private:
bool convert(const NodePath &parent); bool convert(const NodePath &parent, bool animate);
}; };
EXPCL_MISC MStatus initializePlugin(MObject obj); EXPCL_MISC MStatus initializePlugin(MObject obj);

View File

@ -21,6 +21,9 @@
#include <maya/MString.h> #include <maya/MString.h>
#include <maya/MFnPlugin.h> #include <maya/MFnPlugin.h>
#include <maya/MFileIO.h> #include <maya/MFileIO.h>
#include <maya/MArgParser.h>
#include <maya/MArgList.h>
#include <maya/MSyntax.h>
#include <stdlib.h> #include <stdlib.h>
@ -43,10 +46,26 @@ MayaSavePview() {
// Description: Called when the plugin command is invoked. // Description: Called when the plugin command is invoked.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
MStatus MayaSavePview:: MStatus MayaSavePview::
doIt(const MArgList &) { doIt(const MArgList &args) {
MStatus result; MStatus result;
// First, parse the plugin arguments.
MSyntax syntax;
syntax.addFlag("a", "animate");
MArgParser parser(syntax, args, &result);
if (!result) {
result.perror("arguments");
return result;
}
bool animate = parser.isFlagSet("a", &result);
if (!result) {
result.perror("isFlagSet");
return result;
}
// First, make sure the current buffer is saved. // Now make sure the current buffer is saved.
result = MFileIO::save(false); result = MFileIO::save(false);
if (result != MS::kSuccess) { if (result != MS::kSuccess) {
return result; return result;
@ -54,12 +73,17 @@ doIt(const MArgList &) {
MString filename = MFileIO::currentFile(); MString filename = MFileIO::currentFile();
MString pview_args = "-cl";
if (animate) {
pview_args = "-cla";
}
#ifdef WIN32_VC #ifdef WIN32_VC
// On Windows, we use the spawn function to run pview // On Windows, we use the spawn function to run pview
// asynchronously. // asynchronously.
MString quoted = MString("\"") + filename + MString("\""); MString quoted = MString("\"") + filename + MString("\"");
int retval = _spawnlp(_P_DETACH, "pview", int retval = _spawnlp(_P_DETACH, "pview",
"pview", "-cla", quoted.asChar(), NULL); "pview", pview_args.asChar(), quoted.asChar(), NULL);
if (retval == -1) { if (retval == -1) {
return MS::kFailure; return MS::kFailure;
} }
@ -68,7 +92,7 @@ doIt(const MArgList &) {
// On non-Windows (e.g. Unix), we just use the system function, // On non-Windows (e.g. Unix), we just use the system function,
// which runs synchronously. We could fork a process, but no one's // which runs synchronously. We could fork a process, but no one's
// asked for this yet. // asked for this yet.
MString command = MString("pview -cla \"") + filename + MString("\""); MString command = MString("pview " + pview_args + MString(" \"") + filename + MString("\"");
int command_result = system(command.asChar()); int command_result = system(command.asChar());
if (command_result != 0) { if (command_result != 0) {

View File

@ -64,7 +64,7 @@
class MayaSavePview : public MPxCommand { class MayaSavePview : public MPxCommand {
public: public:
MayaSavePview(); MayaSavePview();
virtual MStatus doIt(const MArgList &); virtual MStatus doIt(const MArgList &args);
static void *creator(); static void *creator();
}; };