|
|
@@ -16,30 +16,45 @@
|
|
|
//
|
|
|
////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
-#include "pandaFramework.h"
|
|
|
+#include "mayaPview.h"
|
|
|
+#include "mayaToEggConverter.h"
|
|
|
+#include "eggData.h"
|
|
|
+#include "load_egg_file.h"
|
|
|
+
|
|
|
+// We must define this to prevent Maya from doubly-declaring its
|
|
|
+// MApiVersion string in this file as well as in libmayaegg.
|
|
|
+#define _MApiVersion
|
|
|
|
|
|
#include "pre_maya_include.h"
|
|
|
-#include <maya/MSimple.h>
|
|
|
+#include <maya/MString.h>
|
|
|
+#include <maya/MFnPlugin.h>
|
|
|
#include "post_maya_include.h"
|
|
|
|
|
|
-static PandaFramework framework;
|
|
|
-static bool opened_framework = false;
|
|
|
-
|
|
|
-// This Maya macro sets up a class that meets the plug-in requirements
|
|
|
-// for a simple command.
|
|
|
-DeclareSimpleCommand(MayaPview, "VR Studio", "1.0");
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MayaPview::Constructor
|
|
|
+// Access: Public
|
|
|
+// Description:
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+MayaPview::
|
|
|
+MayaPview() {
|
|
|
+}
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MayaPview::doIt
|
|
|
+// Access: Public, Virtual
|
|
|
+// Description: Called when the plugin command is invoked.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
MStatus MayaPview::
|
|
|
doIt(const MArgList &) {
|
|
|
- if (!opened_framework) {
|
|
|
- int argc = 0;
|
|
|
- char **argv = NULL;
|
|
|
- framework.open_framework(argc, argv);
|
|
|
- framework.set_window_title("Panda Viewer");
|
|
|
- framework.enable_default_keys();
|
|
|
- }
|
|
|
+ int argc = 0;
|
|
|
+ char **argv = NULL;
|
|
|
+ PandaFramework framework;
|
|
|
+ framework.open_framework(argc, argv);
|
|
|
+ framework.set_window_title("Panda Viewer");
|
|
|
+ framework.enable_default_keys();
|
|
|
|
|
|
- WindowFramework *window = framework.open_window();
|
|
|
+ PT(WindowFramework) window;
|
|
|
+ window = framework.open_window();
|
|
|
if (window == (WindowFramework *)NULL) {
|
|
|
// Couldn't open a window.
|
|
|
nout << "Couldn't open a window!\n";
|
|
|
@@ -50,11 +65,96 @@ doIt(const MArgList &) {
|
|
|
|
|
|
window->enable_keyboard();
|
|
|
window->setup_trackball();
|
|
|
+ framework.get_models().instance_to(window->get_render());
|
|
|
+
|
|
|
+ if (!convert(framework.get_models())) {
|
|
|
+ return MS::kFailure;
|
|
|
+ }
|
|
|
|
|
|
- window->load_default_model(framework.get_models());
|
|
|
window->loop_animations();
|
|
|
|
|
|
- framework.clear_exit_flag();
|
|
|
framework.main_loop();
|
|
|
return MS::kSuccess;
|
|
|
}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MayaPview::creator
|
|
|
+// Access: Public, Static
|
|
|
+// Description: This is used to create a new instance of the plugin.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+void *MayaPview::
|
|
|
+creator() {
|
|
|
+ return new MayaPview;
|
|
|
+}
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// Function: MayaPview::convert
|
|
|
+// Access: Private
|
|
|
+// Description: Actually converts the Maya selection to Panda
|
|
|
+// geometry, and parents it to the indicated NodePath.
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+bool MayaPview::
|
|
|
+convert(const NodePath &parent) {
|
|
|
+ // Now make a converter to get all the Maya structures.
|
|
|
+ MayaToEggConverter converter("plug-in");
|
|
|
+
|
|
|
+ // We always want polygon output since we want to be able to see the
|
|
|
+ // results.
|
|
|
+ converter._polygon_output = true;
|
|
|
+
|
|
|
+ EggData egg_data;
|
|
|
+ converter.set_egg_data(&egg_data, false);
|
|
|
+
|
|
|
+ if (!converter.convert_maya()) {
|
|
|
+ nout << "Errors in conversion.\n";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Now the converter has filled up our egg structure with data, so
|
|
|
+ // convert this egg data to Panda data for immediate viewing.
|
|
|
+ egg_data.set_coordinate_system(CS_default);
|
|
|
+ PT(PandaNode) result = load_egg_data(egg_data);
|
|
|
+
|
|
|
+ if (result == (PandaNode *)NULL) {
|
|
|
+ nout << "Unable to load converted egg data.\n";
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ parent.attach_new_node(result);
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
+// 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("pview", MayaPview::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("pview");
|
|
|
+
|
|
|
+ if (!status) {
|
|
|
+ status.perror("deregisterCommand");
|
|
|
+ }
|
|
|
+ return status;
|
|
|
+}
|