23 #include <sys/types.h>
32 #include <maya/MStatus.h>
33 #include <maya/MPxCommand.h>
34 #include <maya/MString.h>
35 #include <maya/MStringArray.h>
36 #include <maya/MArgList.h>
37 #include <maya/MGlobal.h>
38 #include <maya/MFnPlugin.h>
39 #include <maya/MObject.h>
40 #include <maya/MPlug.h>
41 #include <maya/MPxFileTranslator.h>
48 class MayaEggImporter :
public MPxFileTranslator
51 MayaEggImporter () {};
52 virtual ~MayaEggImporter () {};
53 static void* creator();
55 MStatus reader (
const MFileObject& file,
56 const MString& optionsString,
59 MStatus writer (
const MFileObject& file,
60 const MString& optionsString,
61 FileAccessMode mode );
63 bool haveReadMethod ()
const {
return true; }
64 bool haveWriteMethod ()
const {
return false; }
65 MString defaultExtension ()
const {
return "egg"; }
66 MFileKind identifyFile (
const MFileObject& fileName,
72 void* MayaEggImporter::creator()
74 return new MayaEggImporter();
77 MStatus MayaEggImporter::reader (
const MFileObject& file,
78 const MString& options,
81 MString fileName = file.fullName();
85 if (options.length() > 0) {
86 const MString flagModel(
"model");
87 const MString flagAnim(
"anim");
90 MStringArray optionList;
91 MStringArray theOption;
92 options.split(
';', optionList);
94 unsigned nOptions = optionList.length();
95 for (
unsigned i = 0; i < nOptions; i++) {
98 optionList[i].split(
'=', theOption);
99 if (theOption.length() < 1) {
103 if (theOption[0] == flagModel && theOption.length() > 1) {
104 model = atoi(theOption[1].asChar()) ?
true:
false;
105 }
else if (theOption[0] == flagAnim && theOption.length() > 1) {
106 anim = atoi(theOption[1].asChar()) ?
true:
false;
111 if ((mode != kImportAccessMode)&&(mode != kOpenAccessMode))
114 bool merge = (mode == kImportAccessMode);
115 std::ostringstream log;
117 bool ok = MayaLoadEggFile(fileName.asChar(), merge, model, anim,
false);
118 std::string txt = log.str();
120 MGlobal::displayError(txt.c_str());
122 if (!ok) MGlobal::displayError(
"Cannot import Egg file, unknown reason");
124 return ok ? MS::kSuccess : MS::kFailure;
127 MStatus MayaEggImporter::writer (
const MFileObject& file,
128 const MString& options,
129 FileAccessMode mode )
132 fprintf(stderr,
"MayaEggImporter::writer called in error\n");
136 MPxFileTranslator::MFileKind MayaEggImporter::identifyFile (
137 const MFileObject& fileName,
141 const char * name = fileName.name().asChar();
142 int nameLength = strlen(name);
144 if ((nameLength > 4) && !strcmp(name+nameLength-4,
".egg"))
145 return kCouldBeMyFileType;
147 return kNotMyFileType;
150 EXPCL_MISC MStatus initializePlugin( MObject obj )
152 MFnPlugin plugin( obj,
"Alias",
"3.0",
"Any");
155 return plugin.registerFileTranslator(
"Panda3D Egg Import",
"none",
156 MayaEggImporter::creator,
159 "merge=1;model=1;anim=0;");
162 EXPCL_MISC MStatus uninitializePlugin( MObject obj )
164 MFnPlugin plugin( obj );
165 return plugin.deregisterFileTranslator(
"Panda3D Egg Import" );