26 #include <sys/types.h>
28 #include "dtoolbase.h"
34 #include "pre_maya_include.h"
35 #include <maya/MStatus.h>
36 #include <maya/MPxCommand.h>
37 #include <maya/MString.h>
38 #include <maya/MStringArray.h>
39 #include <maya/MArgList.h>
40 #include <maya/MGlobal.h>
41 #include <maya/MFnPlugin.h>
42 #include <maya/MObject.h>
43 #include <maya/MPlug.h>
44 #include <maya/MPxFileTranslator.h>
45 #include "post_maya_include.h"
47 #include "mayaEggLoader.h"
48 #include "notifyCategoryProxy.h"
57 static void* creator();
59 MStatus reader (
const MFileObject& file,
60 const MString& optionsString,
63 MStatus writer (
const MFileObject& file,
64 const MString& optionsString,
65 FileAccessMode mode );
67 bool haveReadMethod ()
const {
return true; }
68 bool haveWriteMethod ()
const {
return false; }
69 MString defaultExtension ()
const {
return "egg"; }
70 MFileKind identifyFile (
const MFileObject& fileName,
76 void* MayaEggImporter::creator()
81 MStatus MayaEggImporter::reader (
const MFileObject& file,
82 const MString& options,
85 MString fileName = file.fullName();
89 if (options.length() > 0) {
90 const MString flagModel(
"model");
91 const MString flagAnim(
"anim");
95 MStringArray optionList;
96 MStringArray theOption;
97 options.split(
';', optionList);
99 unsigned nOptions = optionList.length();
100 for (
unsigned i = 0; i < nOptions; i++) {
103 optionList[i].split(
'=', theOption);
104 if (theOption.length() < 1) {
108 if (theOption[0] == flagModel && theOption.length() > 1) {
109 model = atoi(theOption[1].asChar()) ?
true:
false;
110 }
else if (theOption[0] == flagAnim && theOption.length() > 1) {
111 anim = atoi(theOption[1].asChar()) ?
true:
false;
116 if ((mode != kImportAccessMode)&&(mode != kOpenAccessMode))
119 bool merge = (mode == kImportAccessMode);
120 std::ostringstream log;
122 bool ok = MayaLoadEggFile(fileName.asChar(), merge, model, anim,
false);
123 string txt = log.str();
125 MGlobal::displayError(txt.c_str());
127 if (!ok) MGlobal::displayError(
"Cannot import Egg file, unknown reason");
129 return ok ? MS::kSuccess : MS::kFailure;
132 MStatus MayaEggImporter::writer (
const MFileObject& file,
133 const MString& options,
134 FileAccessMode mode )
137 fprintf(stderr,
"MayaEggImporter::writer called in error\n");
141 MPxFileTranslator::MFileKind MayaEggImporter::identifyFile (
142 const MFileObject& fileName,
146 const char * name = fileName.name().asChar();
147 int nameLength = strlen(name);
149 if ((nameLength > 4) && !strcmp(name+nameLength-4,
".egg"))
150 return kCouldBeMyFileType;
152 return kNotMyFileType;
155 EXPCL_MISC MStatus initializePlugin( MObject obj )
157 MFnPlugin plugin( obj,
"Alias",
"3.0",
"Any");
160 return plugin.registerFileTranslator(
"Panda3D Egg Import",
"none",
161 MayaEggImporter::creator,
164 "merge=1;model=1;anim=0;");
167 EXPCL_MISC MStatus uninitializePlugin( MObject obj )
169 MFnPlugin plugin( obj );
170 return plugin.deregisterFileTranslator(
"Panda3D Egg Import" );
static Notify * ptr()
Returns the pointer to the global Notify object.
void set_ostream_ptr(ostream *ostream_ptr, bool delete_later)
Changes the ostream that all subsequent Notify messages will be written to.