本文整理汇总了C++中MFileObject类的典型用法代码示例。如果您正苦于以下问题:C++ MFileObject类的具体用法?C++ MFileObject怎么用?C++ MFileObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MFileObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: writer
MStatus FileTranslator::writer ( const MFileObject& file,
const MString& options,
MPxFileTranslator::FileAccessMode mode )
{
MStatus status = MStatus::kFailure;
try
{
// Extract the filename
#if defined (OSMac_)
char nameBuffer[MAXPATHLEN];
strcpy ( nameBuffer, file.fullName().asChar() );
const MString fileName ( nameBuffer );
#else
const MString fileName = file.fullName();
#endif // OSMac
// TODO Export the referenced files!
// Maya forces the write of all the references, on export.
// Intentionally skip known reference file paths.
for ( MItDependencyNodes it ( MFn::kReference ); !it.isDone(); it.next() )
{
MObject refNode = it.item();
MString refNodeName = MFnDependencyNode ( refNode ).name();
MString refNodeFilename;
MGlobal::executeCommand ( MString ( "reference -rfn \"" ) + refNodeName + MString ( "\" -q -filename" ),
refNodeFilename );
if ( refNodeFilename == fileName ) return MStatus::kSuccess;
if ( ExportOptions::exportXRefs() )
{
// TODO Open file export dialog ( !? HOW ?! ) to get a DAE filename
// to export the referenced file.
}
}
// Parse the export options
ExportOptions::set ( options );
// Check, if we should just export the selected Objects
exportSelection = mode == MPxFileTranslator::kExportActiveAccessMode;
// Do the actual export now
status = exportIntoFile ( fileName, exportSelection );
}
catch ( COLLADASW::StreamWriterException* swException )
{
String message = "StreamWriterException: " + swException->getMessage();
MGlobal::displayError ( message.c_str() );
}
catch ( ... )
{
MGlobal::displayError ( "ColladaMaya has thrown an exception!" );
}
return status;
}
示例2: fileNamePlug
// returns the list of files to archive.
MStringArray AlembicNode::getFilesToArchive(
bool /* shortName */,
bool unresolvedName,
bool /* markCouldBeImageSequence */) const
{
MStringArray files;
MStatus status = MS::kSuccess;
MPlug fileNamePlug(thisMObject(), mAbcFileNameAttr);
MString fileName = fileNamePlug.asString(MDGContext::fsNormal, &status);
if (status == MS::kSuccess && fileName.length() > 0) {
if(unresolvedName)
{
files.append(fileName);
}
else
{
//unresolvedName is false, resolve the path via MFileObject.
MFileObject fileObject;
fileObject.setRawFullName(fileName);
files.append(fileObject.resolvedFullName());
}
}
return files;
}
示例3: writer
MStatus ObjTranslator::writer ( const MFileObject& file,
const MString& options,
FileAccessMode mode )
{
MStatus status;
MString mname = file.fullName(), unitName;
//just pass in the filename
#if defined (OSMac_)
char fname[256];//MAXPATHLEN];
strcpy (fname, file.fullName().asChar());
// fp = fopen(fname,"wb");//MAYAMACTODO
#else
const char *fname = mname.asChar();
// fp = fopen(fname,"w");
#endif
shared_ptr<solver_impl_t> solv = solver_t::get_solver();
solv->export_collada_file(fname);
return status;
}
示例4: layerFilenamesPlug
// returns the list of files to archive.
MStringArray AlembicNode::getFilesToArchive(
bool /* shortName */,
bool unresolvedName,
bool /* markCouldBeImageSequence */) const
{
MStringArray files;
MStatus status = MS::kSuccess;
MPlug layerFilenamesPlug(thisMObject(), mAbcLayerFileNamesAttr);
MFnStringArrayData fnSAD( layerFilenamesPlug.asMObject() );
MStringArray layerFilenames = fnSAD.array();
for( unsigned int i = 0; i < layerFilenames.length(); i++ )
{
MString fileName = layerFilenames[i];
if (status == MS::kSuccess && fileName.length() > 0) {
if(unresolvedName)
{
files.append(fileName);
}
else
{
//unresolvedName is false, resolve the path via MFileObject.
MFileObject fileObject;
fileObject.setRawFullName(fileName);
files.append(fileObject.resolvedFullName());
}
}
}
return files;
}
示例5: cgfxGetFxIncludePath
void
cgfxGetFxIncludePath( const MString &fxFile, MStringArray &pathOptions )
{
// Append the path of the cgfx file as a possible include search path
//
MString option;
if (fxFile.length())
{
MFileObject fobject;
fobject.setRawFullName( fxFile );
option = MString("-I") + fobject.resolvedPath();
pathOptions.append( option );
}
// Add in "standard" cgfx search for cgfx files as a possible include
// search path
//
char * cgfxRoot = getenv("CGFX_ROOT");
if (cgfxRoot)
{
option = MString("-I") + MString(cgfxRoot);
pathOptions.append( option );
option = MString("-I") + MString(cgfxRoot) + MString("/CgFX");
pathOptions.append( option );
}
// Add in Maya's Cg directory
char * mayaLocation = getenv("MAYA_LOCATION");
if (mayaLocation)
{
MString mayaCgLocation(MString(mayaLocation) + MString("/bin/Cg/"));
option = MString("-I") + mayaCgLocation;
pathOptions.append( option );
}
}
示例6: writer
MStatus polyExporter::writer(const MFileObject& file,
const MString& /*options*/,
MPxFileTranslator::FileAccessMode mode)
//Summary: saves a file of a type supported by this translator by traversing
// the all or selected objects (depending on mode) in the current
// Maya scene, and writing a representation to the given file
//Args : file - object containing the pathname of the file to be written to
// options - a string representation of any file options
// mode - the method used to write the file - export, or export active
// are valid values; method will fail for any other values
//Returns: MStatus::kSuccess if the export was successful;
// MStatus::kFailure otherwise
{
#if defined (OSMac_)
char nameBuffer[MAXPATHLEN];
strcpy (nameBuffer, file.fullName().asChar());
const MString fileName(nameBuffer);
#else
const MString fileName = file.fullName();
#endif
ofstream newFile(fileName.asChar(), ios::out);
if (!newFile) {
MGlobal::displayError(fileName + ": could not be opened for reading");
return MS::kFailure;
}
newFile.setf(ios::unitbuf);
writeHeader(newFile);
//check which objects are to be exported, and invoke the corresponding
//methods; only 'export all' and 'export selection' are allowed
//
if (MPxFileTranslator::kExportAccessMode == mode) {
if (MStatus::kFailure == exportAll(newFile)) {
return MStatus::kFailure;
}
} else if (MPxFileTranslator::kExportActiveAccessMode == mode) {
if (MStatus::kFailure == exportSelection(newFile)) {
return MStatus::kFailure;
}
} else {
return MStatus::kFailure;
}
writeFooter(newFile);
newFile.flush();
newFile.close();
MGlobal::displayInfo("Export to " + fileName + " successful!");
return MS::kSuccess;
}
示例7: reader
MStatus FileTranslator::reader ( const MFileObject& file,
const MString& options,
MPxFileTranslator::FileAccessMode mode )
{
MStatus status ( MS::kSuccess );
try
{
#if MAYA_API_VERSION >= 800
if ( mode == MPxFileTranslator::kReferenceAccessMode )
{
int optionValue;
MGlobal::executeCommand ( "optionVar -q \"referenceOptionsSharedReference\";", optionValue );
if ( optionValue != 0 )
{
#ifdef WIN32
MessageBox ( NULL, "Maya may now hang. Do disable the reference option named: \"Shared Reference Nodes\".", "POSSIBLE HANG", MB_OK );
#endif
}
}
#endif // Maya 8.0 and 8.5
#if defined (OSMac_)
char nameBuffer[MAXPATHLEN];
strcpy ( nameBuffer, file.fullName().asChar() );
const MString filename ( nameBuffer );
#else
const MString filename = file.fullName();
#endif // OSMac
// Process the import options
ImportOptions::set ( options, mode );
if (ImportOptions::hasError()) status = MStatus::kFailure;
// Import the COLLADA DAE file
status = importFromFile ( filename.asChar() );
}
catch ( COLLADABU::Exception* exception )
{
MGlobal::displayWarning ( exception->getMessage().c_str() );
}
catch ( ... )
{
MGlobal::displayWarning ( "ColladaMaya has thrown an exception!" );
}
return status;
}
示例8: reader
MStatus metro_model_translator::reader(const MFileObject &file, const MString &optionsString, FileAccessMode mode)
{
m2033::file_system fs;
m2033::model model;
bool res = MStatus::kFailure;
fs.set_root_from_fname( file.expandedFullName().asChar() );
res = model.load( file.expandedFullName().asChar() );
if( !res ) {
return MStatus::kFailure;
}
return read( model );
}
示例9: writer
//
// Maya calls this method to have the translator write out a file.
//
MStatus colorTransformDataTranslator::writer(
const MFileObject& file,
const MString& /* options */,
MPxFileTranslator::FileAccessMode mode
)
{
//
// For simplicity, we only do full saves/exports.
//
if ((mode != kSaveAccessMode) && (mode != kExportAccessMode))
return MS::kNotImplemented;
//
// Let's see if we can open the output file.
//
fstream output(file.fullName().asChar(), ios::out | ios::trunc);
if (!output.good()) return MS::kNotFound;
writeColorSpaceForNodes(output);
writeOutputTransformId(output);
writeColorTransformData(output);
output.close();
return MS::kSuccess;
}
示例10: identifyFile
// *****************************************************************************
MPxFileTranslator::MFileKind GtoIO::identifyFile( const MFileObject &file,
const char *magic,
short magicSize ) const
{
if( magicSize < 4 )
{
return MPxFileTranslator::kNotMyFileType;
}
const unsigned int magicInt = *((unsigned int *)magic );
if( magicInt == Gto::Header::Magic
|| magicInt == Gto::Header::Cigam )
{
return MPxFileTranslator::kIsMyFileType;
}
const char gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
if( magic[0] == gz_magic[0] && magic[1] == gz_magic[1] )
{
if( strstr( file.name().asChar(), ".gto" ) )
{
return MPxFileTranslator::kIsMyFileType;
}
}
return MPxFileTranslator::kNotMyFileType;
}
示例11: writer
MStatus CXRayObjectExport::writer ( const MFileObject& file, const MString& options, FileAccessMode mode )
{
MStatus status= MS::kFailure;
//move default extesion here..
MString mname = file.fullName()+".object";
LPCSTR fname = mname.asChar();
Log("Export object: ",fname);
CEditableObject* OBJECT = new CEditableObject(fname);
OBJECT->SetVersionToCurrent(TRUE,TRUE);
if((mode==MPxFileTranslator::kExportAccessMode)||(mode==MPxFileTranslator::kSaveAccessMode)){
status = ExportAll(OBJECT)?MS::kSuccess:MS::kFailure;
}else if(mode==MPxFileTranslator::kExportActiveAccessMode){
status = ExportSelected(OBJECT)?MS::kSuccess:MS::kFailure;
}
if (MS::kSuccess==status){
OBJECT->Optimize ();
OBJECT->SaveObject (fname);
Log("Object succesfully exported.");
Msg("%d vertices, %d faces", OBJECT->GetVertexCount(), OBJECT->GetFaceCount());
}else{
Log("! Export failed.");
}
xr_delete(OBJECT);
return status;
}
示例12: writer
MStatus writer (const MFileObject& file, const MString& optionsString, MPxFileTranslator::FileAccessMode mode)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CMayaInterface mayaInterface;
if (!mayaInterface.Create (mode == MPxFileTranslator::kExportActiveAccessMode))
{
MGlobal::displayError("Failed to initialize cal3d CMayaInterface.");
return MS::kFailure;
}
// create an exporter instance
if(!theExporter.Create(&mayaInterface))
{
MGlobal::displayError(theExporter.GetLastError().c_str());
return MS::kFailure;
}
if (!theExporter.ExportSkeleton (file.fullName().asChar()))
{
MGlobal::displayError(theExporter.GetLastError().c_str());
return MS::kFailure;
}
return MS::kSuccess;
}
示例13: identifyFile
MPxFileTranslator::MFileKind NifTranslator::identifyFile(const MFileObject& fileName, const char* buffer, short size) const
{
MString fName = fileName.name();
if (fName.toUpperCase() != "NIF" && fName.toUpperCase() != "KF")
return kNotMyFileType;
return kIsMyFileType;
}
示例14: reader
MStatus BinMeshTranslator::reader(const MFileObject& file,
const MString& opts,
MPxFileTranslator::FileAccessMode mode)
{
options = opts;
#if defined (OSMac_)
char nameBuffer[MAXPATHLEN];
strcpy (nameBuffer, file.fullName().asChar());
fileName(nameBuffer);
#else
fileName = file.fullName();
#endif
MGlobal::displayInfo("Options " + options);
return this->importObjects();
}
示例15: writer
MStatus DCTranslator::writer(
const MFileObject &file,
const MString &,
MPxFileTranslator::FileAccessMode mode)
{
MString fileName = file.fullName();
m_ExportPath = file.path();
MString pathInfo = "Export Model Path: ";
MGlobal::displayInfo(pathInfo + m_ExportPath);
MGlobal::displayInfo("Exporting Mesh...\n");
m_MeshFilePtr = GetIODevice<File>();
//m_PhysxAssetFilePtr = GetIODevice<File>();
if (m_MeshFilePtr->Open(fileName.asChar(), IOWrite)) {
//m_PhysxAssetFilePtr->Open((fileName+".pxasset").asChar(), IOWrite);
m_MeshArch = new Archive;
m_MeshArch->SetIODevice(m_MeshFilePtr);
////// write the header ///////
MeshHeader header;
header.Version = VERSION_1_1;
//////
(*m_MeshArch) << header;
if ((mode == MPxFileTranslator::kExportAccessMode) ||
(mode == MPxFileTranslator::kSaveAccessMode))
{
exportAll();
}
else if (mode == MPxFileTranslator::kExportActiveAccessMode)
{
exportSelected();
}
char EndCode[64] = "End";
m_MeshFilePtr->Write(EndCode, 64);
m_MeshFilePtr->Close();
delete m_MeshFilePtr;
m_MeshFilePtr = 0;
return MS::kSuccess;
}
else {
return MStatus::kFailure;
}
}