00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00027
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
00038
00039
00040
00041 MayaPview::
00042 MayaPview() {
00043 }
00044
00045
00046
00047
00048
00049
00050 MStatus MayaPview::
00051 doIt(const MArgList &) {
00052
00053
00054
00055
00056
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
00069 nout << "Couldn't open a window!\n";
00070 return MS::kFailure;
00071 }
00072
00073
00074
00075
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
00087
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
00112
00113
00114
00115 void *MayaPview::
00116 creator() {
00117 return new MayaPview;
00118 }
00119
00120
00121
00122
00123
00124
00125
00126 bool MayaPview::
00127 convert(const NodePath &parent) {
00128
00129 MayaToEggConverter converter("plug-in");
00130
00131
00132
00133 converter._polygon_output = true;
00134
00135 PathReplace *path_replace = converter.get_path_replace();
00136
00137
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
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
00157
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
00175
00176
00177 EXPCL_MISC MStatus
00178 initializePlugin(MObject obj) {
00179
00180
00181
00182
00183
00184
00185
00186
00187
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
00202
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 }