diff --git a/pandatool/src/mayaprogs/Sources.pp b/pandatool/src/mayaprogs/Sources.pp index a671e00b6f..01ebee79a7 100644 --- a/pandatool/src/mayaprogs/Sources.pp +++ b/pandatool/src/mayaprogs/Sources.pp @@ -95,6 +95,18 @@ #end lib_target +#begin lib_target + #define USE_PACKAGES maya + #define TARGET mayasavepview + + #if $[WINDOWS_PLATFORM] + #define dlllib mll + #endif + + #define SOURCES \ + mayaSavePview.cxx mayaSavePview.h +#end lib_target + #begin lib_target #define USE_PACKAGES maya #define TARGET mayaloader diff --git a/pandatool/src/mayaprogs/mayaSavePview.cxx b/pandatool/src/mayaprogs/mayaSavePview.cxx new file mode 100644 index 0000000000..0c180144d6 --- /dev/null +++ b/pandatool/src/mayaprogs/mayaSavePview.cxx @@ -0,0 +1,104 @@ +// Filename: mayaSavePview.cxx +// Created by: drose (27Oct03) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "mayaSavePview.h" + +#include +#include +#include + +#include + +//////////////////////////////////////////////////////////////////// +// Function: MayaSavePview::Constructor +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +MayaSavePview:: +MayaSavePview() { +} + +//////////////////////////////////////////////////////////////////// +// Function: MayaSavePview::doIt +// Access: Public, Virtual +// Description: Called when the plugin command is invoked. +//////////////////////////////////////////////////////////////////// +MStatus MayaSavePview:: +doIt(const MArgList &) { + MStatus result; + + // First, make sure the current buffer is saved. + result = MFileIO::save(false); + if (result != MS::kSuccess) { + return result; + } + + MString filename = MFileIO::currentFile(); + MString command = MString("pview \"") + filename + MString("\""); + + int command_result = system(command.asChar()); + if (command_result != 0) { + return MS::kFailure; + } + + return MS::kSuccess; +} + +//////////////////////////////////////////////////////////////////// +// Function: MayaSavePview::creator +// Access: Public, Static +// Description: This is used to create a new instance of the plugin. +//////////////////////////////////////////////////////////////////// +void *MayaSavePview:: +creator() { + return new MayaSavePview; +} + + + +//////////////////////////////////////////////////////////////////// +// Function: initializePlugin +// Description: Called by Maya when the plugin is loaded. +//////////////////////////////////////////////////////////////////// +EXPCL_MISC MStatus +initializePlugin(MObject obj) { + MFnPlugin plugin(obj, "VR Studio", "1.0"); + MStatus status; + status = plugin.registerCommand("savePview", MayaSavePview::creator); + if (!status) { + status.perror("registerCommand"); + } + + return status; +} + +//////////////////////////////////////////////////////////////////// +// Function: uninitializePlugin +// Description: Called by Maya when the plugin is unloaded. +//////////////////////////////////////////////////////////////////// +EXPCL_MISC MStatus +uninitializePlugin(MObject obj) { + MFnPlugin plugin(obj); + MStatus status; + status = plugin.deregisterCommand("savePview"); + + if (!status) { + status.perror("deregisterCommand"); + } + return status; +} diff --git a/pandatool/src/mayaprogs/mayaSavePview.h b/pandatool/src/mayaprogs/mayaSavePview.h new file mode 100644 index 0000000000..fc3c2a21d3 --- /dev/null +++ b/pandatool/src/mayaprogs/mayaSavePview.h @@ -0,0 +1,75 @@ +// Filename: mayaSavePview.h +// Created by: drose (27Oct03) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#ifndef MAYASAVEPVIEW_H +#define MAYASAVEPVIEW_H + +// Maya will try to typedef bool unless this symbol is defined. +#ifndef _BOOL +#define _BOOL 1 +#endif + +#include +#include +#include + +// Even though we don't include any Panda headers, it's safe to +// include this one, since it only defines some macros that we need to +// make this program platform-independent. +#include "dtool_config.h" + + +//////////////////////////////////////////////////////////////////// +// Class : MayaSavePview +// Description : This class serves as a plug-in to Maya to save the +// scene and view it using the external pview program, +// rather than linking in any part of Panda to a Maya +// plugin. +// +// Since it does not link with any Panda code, and hence +// is a very lean plugin, it is less likely than +// MayaPview to cause interoperability problems within +// Maya. However, it does force a save-to-disk and a +// spawning of a separate executable, including a +// complete reloading of all of the Maya libraries, so +// it is quite a bit slower to execute. And the +// potential for interactive control is substantially +// reduced. +//////////////////////////////////////////////////////////////////// +class MayaSavePview : public MPxCommand { +public: + MayaSavePview(); + virtual MStatus doIt(const MArgList &); + + static void *creator(); +}; + +// Since we don't include any of the Panda headers (other than +// dtool_config.h), we have to define this macro ourselves, to tell +// Windows to export the following functions from the DLL. +#ifdef WIN32_VC + #define EXPCL_MISC __declspec(dllexport) +#else + #define EXPCL_MISC +#endif + +EXPCL_MISC MStatus initializePlugin(MObject obj); +EXPCL_MISC MStatus uninitializePlugin(MObject obj); + + +#endif