#include <maya/MStatus.h>
#include <maya/MObject.h>
#include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MVector.h>
#include <maya/MStringArray.h>
#include <maya/MPxFileTranslator.h>
#include <maya/MGlobal.h>
#include <maya/MItDag.h>
#include <maya/MObject.h>
#include <maya/MPlug.h>
#include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h>
#include <maya/MFileIO.h>
#include <maya/MFnTransform.h>
#include <maya/MNamespace.h>
#include <fstream>
#include <iostream>
#include <ios>
public:
LepTranslator () {};
~LepTranslator () override {};
static void* creator();
const char* buffer,
short size) const override;
private:
};
void* LepTranslator::creator()
{
return new LepTranslator();
}
MString const LepTranslator::magic(
"<LEP>");
{
const int maxLineSize = 1024;
char buf[maxLineSize];
std::ifstream inputfile(fname.
asChar(), std::ios::in);
if (!inputfile) {
std::cerr << fname << ": could not be opened for reading\n";
return MS::kFailure;
}
if (!inputfile.getline (buf, maxLineSize)) {
std::cerr << "file " << fname << " contained no lines ... aborting\n";
return MS::kFailure;
}
if (0 != strncmp(buf, magic.asChar(), magic.length())) {
std::cerr << "first line of file " << fname;
std::cerr <<
" did not contain " << magic.
asChar() <<
" ... aborting\n";
return MS::kFailure;
}
while (inputfile.getline (buf, maxLineSize)) {
rval = MS::kFailure;
}
inputfile.close();
return rval;
}
const char* primitiveStrings[] = {
"nurbsSphere",
"nurbsCone",
"nurbsCylinder",
};
const unsigned numPrimitives = sizeof(primitiveStrings) / sizeof(char*);
const char* primitiveCommands[] = {
"sphere",
"cone",
"cylinder",
};
{
bool showPositions = false;
unsigned int i;
std::ofstream newf(fname.
asChar(), std::ios::out);
if (!newf) {
std::cerr << fname << ": could not be opened for reading\n";
return MS::kFailure;
}
newf.setf(std::ios::unitbuf);
options.
split(
';', optionList);
for( i = 0; i < optionList.
length(); ++i ){
optionList[i].split( '=', theOption );
if( theOption[0] ==
MString(
"showPositions") &&
if( theOption[1].asInt() > 0 ){
showPositions = true;
}else{
showPositions = false;
}
}
}
}
newf << "<LEP>\n";
if ( !status) {
status.
perror (
"Failure in DAG iterator setup");
return MS::kFailure;
}
bool done = false;
while (true)
{
switch (mode)
{
if (dagIterator.isDone ())
done = true;
else {
currentNode = dagIterator.currentItem ();
dagIterator.next ();
}
break;
if (selIterator.isDone ())
done = true;
else {
selIterator.getDependNode (currentNode);
selIterator.next ();
}
break;
default:
std::cerr << "Unrecognized write mode: " << mode << std::endl;
break;
}
if (done)
break;
if ( status == MS::kSuccess )
{
for (i = 0; i < numPrimitives; ++i) {
if(nodeNameNoNamespace.
indexW(primitiveStrings[i]) >= 0){
newf << primitiveCommands[i] << " -n " << nodeNameNoNamespace << std::endl;
if (showPositions) {
newf <<
"move " << pos.
x <<
" " << pos.
y <<
" " << pos.
z << std::endl;
}
}
}
}
}
newf.close();
return MS::kSuccess;
}
MString LepTranslator::defaultExtension ()
const
{
return "lep";
}
const char* buffer,
short size) const
{
MFileKind rval = kNotMyFileType;
if ((size >= (short)magic.length()) &&
(0 == strncmp(buffer, magic.asChar(), magic.length())))
{
rval = kIsMyFileType;
}
return rval;
}
{
MFnPlugin plugin( obj, PLUGIN_COMPANY,
"3.0",
"Any");
status = plugin.registerFileTranslator( "Lep",
"lepTranslator.rgb",
LepTranslator::creator,
"lepTranslatorOpts",
"showPositions=1",
true );
if (!status)
{
status.
perror(
"registerFileTranslator");
return status;
}
return status;
}
{
status = plugin.deregisterFileTranslator( "Lep" );
if (!status)
{
status.
perror(
"deregisterFileTranslator");
return status;
}
return status;
}