public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { string fullName = file.fullName; StreamWriter sWriter = new StreamWriter(fullName); sWriter.Write("# Simple text file of custom node information" + Environment.NewLine); MItDependencyNodes iterator = new MItDependencyNodes(); while (!iterator.isDone) { MObject obj = iterator.thisNode; try { MFnDependencyNode dnFn = new MFnDependencyNode(obj); MPxNode userNode = dnFn.userNode; if (userNode != null) sWriter.Write("# custom node: " + dnFn.name + Environment.NewLine); } catch (System.Exception) { } iterator.next(); } sWriter.Close(); return; }
public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { string fullName = file.fullName; StreamWriter sWriter = new StreamWriter(fullName); sWriter.Write("# Simple text file of custom node information" + Environment.NewLine); MItDependencyNodes iterator = new MItDependencyNodes(); while (!iterator.isDone) { MObject obj = iterator.thisNode; try { MFnDependencyNode dnFn = new MFnDependencyNode(obj); MPxNode userNode = dnFn.userNode; if (userNode != null) { sWriter.Write("# custom node: " + dnFn.name + Environment.NewLine); } } catch (System.Exception) { } iterator.next(); } sWriter.Close(); return; }
public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { // Prepare to export, pass it off if (file.fullName.ToUpper().EndsWith(".SIEGE_ANIM_SOURCE")) { CODXAnim.ExportXAnim(file.fullName, CODXAnim.XAnimType.SiegeAnimSource); } }
public override MFileKind identifyFile(MFileObject file, string buffer, short size) { string name = file.name; if (name.Length > 5 && string.Compare(name, name.Length - 5, defaultExtension(), 0, 5, true) == 0) return MFileKind.kIsMyFileType; return MFileKind.kNotMyFileType; }
public override MFileKind identifyFile(MFileObject file, string buffer, short size) { string name = file.name; if (name.Length > 5 && string.Compare(name, name.Length - 5, defaultExtension(), 0, 5, true) == 0) { return(MFileKind.kIsMyFileType); } return(MFileKind.kNotMyFileType); }
public override MPxFileTranslator.MFileKind identifyFile(MFileObject file, string buffer, short bufferLen) { // It's our file if (file.fullName.ToUpper().EndsWith(".XMODEL_EXPORT")) { return(MFileKind.kIsMyFileType); } // Failed return(MFileKind.kNotMyFileType); }
public override void writer(MFileObject file, string optionsString, FileAccessMode mode) { if (mode == FileAccessMode.kExportActiveAccessMode) { StaticObject scb = StaticObject.Create(); scb.WriteSCB(file.expandedFullName); } else { MGlobal.displayError("SCBExporter - Wrong File Access Mode: " + mode); } }
public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { string fullName = file.fullName; StreamReader sReader = new StreamReader(fullName); while (!sReader.EndOfStream) { string lineStr = sReader.ReadLine(); processLine(lineStr); } sReader.Close(); return; }
public override void reader(MFileObject file, string optionsString, FileAccessMode mode) { if (mode == FileAccessMode.kImportAccessMode) { string name = Path.GetFileNameWithoutExtension(file.expandedFullName).Replace('.', '_'); StaticObject scb = StaticObject.ReadSCB(file.expandedFullName); scb.Load(name); } else { throw new ArgumentException("SCBImporter:reader - Invalid File Access Mode: " + mode, "mode"); } }
/// <summary> /// Maya calls this method to find out if this translator is capable of /// handling the given file. /// </summary> /// <param name="file"></param> /// <param name="buffer"></param> /// <param name="bufferLen"></param> /// <returns></returns> public override MFileKind identifyFile(MFileObject file, string buffer, short bufferLen) { //TODO Check magic number if bufferLen >= 4 and the first characters are M,D,2,0 //Based on extension .m2 var fileName = file.name; var fileNameLen = fileName.Length; var startOfExtension = fileName.IndexOf('.') + 1; if ((startOfExtension > 0) && (startOfExtension < fileNameLen) && (fileName.Substring(startOfExtension, fileNameLen) == FExtension)) { return(MFileKind.kIsMyFileType); } return(MFileKind.kNotMyFileType); }
public override void writer(MFileObject file, string optionsString, FileAccessMode mode) { if (mode == FileAccessMode.kExportActiveAccessMode) { string sknPath = file.expandedFullName; string sklPath = Path.ChangeExtension(sknPath, ".skl"); SKLFile skl = new SKLFile(true); SKNFile skn = new SKNFile(skl); skl.Write(sklPath); skn.Write(sknPath); } else { MGlobal.displayError("SKNExporter - Wrong File Access Mode: " + mode); } }
public override void reader(MFileObject file, string optionsString, FileAccessMode mode) { if (mode == FileAccessMode.kImportAccessMode) { string pathWithoutExtension = file.expandedFullName.Substring(0, file.expandedFullName.LastIndexOf('.')); string name = Path.GetFileNameWithoutExtension(file.expandedFullName).Replace('.', '_'); SKNFile skn = new SKNFile(file.expandedFullName); SKLFile skl = new SKLFile(pathWithoutExtension + ".skl"); MGlobal.displayInfo("SKNImporter:reader - SKN Vertex Count: " + skn.Vertices.Count); MGlobal.displayInfo("SKNImporter:reader - SKN Index Count: " + skn.Indices.Count); MGlobal.displayInfo("SKNImporter:reader - SKN Submesh Count: " + skn.Submeshes.Count); skl.Load(); skn.Load(name, skl); } else { throw new ArgumentException("SKNImporter:reader - Invalid File Access Mode: " + mode, "mode"); } }
public override MFileKind identifyFile(MFileObject file, string buffer, short size) { string name = file.name; int namelength = name.Length; string tmpStr = ".aim"; if (namelength > 5 && string.Compare(name, namelength - 5, tmpStr, 0, 5, true) == 0) { return(MFileKind.kIsMyFileType); } // Check the buffer to see if this contains the correct keywords // to be a anim file. // tmpStr = "animVersion"; if (string.Compare(buffer, 0, tmpStr, 0, 11) == 0) { return(MFileKind.kIsMyFileType); } return(MFileKind.kNotMyFileType); }
/// <summary> /// Maya calls this method to have the translator write out a file. /// </summary> /// <param name="file"></param> /// <param name="options"></param> /// <param name="mode"></param> public override void writer(MFileObject file, string options, FileAccessMode mode) { if (mode == FileAccessMode.kExportActiveAccessMode) { throw new NotImplementedException("Exporting only selection is not supported yet. Use \"Export All\" instead"); } var expansion = ParseOptions(options); MGlobal.displayInfo("Exporting to M2 " + expansion + ".."); // Name is fileName without .m2 extension var wowModel = new M2 { Name = file.rawName.Substring(0, file.rawName.Length - 3) }; MayaToM2.ExtractModel(wowModel); using (var writer = new BinaryWriter(new FileStream(file.expandedFullName, FileMode.Create, FileAccess.Write))) { wowModel.Save(writer, expansion); } MGlobal.displayInfo("Done."); }
public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { // Prepare to export, pass it off if (file.fullName.ToUpper().EndsWith(".XMODEL_EXPORT")) { // Parse settings bool ExportSiegeModel = false; string Cosmetic = string.Empty; var SplitSettings = optionsString.Trim().Split(';'); foreach (var Setting in SplitSettings) { if (string.IsNullOrWhiteSpace(Setting)) { continue; } var SettingValue = Setting.Split('='); if (SettingValue.Length < 2) { continue; } if (SettingValue[0] == "exportsiege") { ExportSiegeModel = (SettingValue[1] == "1"); } else if (SettingValue[0] == "cosmeticroot") { Cosmetic = CODXModel.CleanNodeName((SettingValue[1].Trim())); } } // Export the model CODXModel.ExportXModel(file.fullName, CODXModel.XModelType.Export, ExportSiegeModel, Cosmetic); } }
public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { // Prepare to export, pass it off if (file.fullName.ToUpper().EndsWith(".XANIM_EXPORT")) { // Parse settings bool GrabNotes = true, EditNotes = false; var SplitSettings = optionsString.Trim().Split(';'); foreach (var Setting in SplitSettings) { if (string.IsNullOrWhiteSpace(Setting)) { continue; } var SettingValue = Setting.Split('='); if (SettingValue.Length < 2) { continue; } if (SettingValue[0] == "grabnotes") { GrabNotes = (SettingValue[1] == "1"); } else if (SettingValue[0] == "editnotes") { EditNotes = (SettingValue[1] == "1"); } } // Export anim CODXAnim.ExportXAnim(file.fullName, CODXAnim.XAnimType.Export, GrabNotes, EditNotes); } }
// // Maya calls this method to have the translator write out a file. // public override void writer(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { // // For simplicity, we only do full saves/exports. // if ((mode != MPxFileTranslator.FileAccessMode.kSaveAccessMode) && (mode != MPxFileTranslator.FileAccessMode.kExportAccessMode)) throw new System.NotImplementedException( "We only support support SaveAccessMode and ExportAccessMode"); // // Let's see if we can open the output file. // FileStream output = null; try { output = new FileStream(file.fullName, FileMode.Create, FileAccess.Write); } catch (ArgumentException ex) { MGlobal.displayInfo("File access invalid!"); if(output != null) output.Close(); throw ex; } // // Get some node flags to keep track of those nodes for which we // have already done various stages of processing. // fCreateFlag = MFnDependencyNode.allocateFlag(fPluginName); fAttrFlag = MFnDependencyNode.allocateFlag(fPluginName); fConnectionFlag = MFnDependencyNode.allocateFlag(fPluginName); // // Run through all of the nodes in the scene and clear their flags. // MItDependencyNodes nodesIter = new MItDependencyNodes(); for (; !nodesIter.isDone; nodesIter.next()) { MObject node = nodesIter.item; MFnDependencyNode nodeFn = new MFnDependencyNode(node); nodeFn.setFlag(fCreateFlag, false); nodeFn.setFlag(fAttrFlag, false); nodeFn.setFlag(fConnectionFlag, false); } // // Write out the various sections of the file. // writeHeader(output, file.name); writeFileInfo(output); writeReferences(output); writeRequirements(output); writeUnits(output); writeDagNodes(output); writeNonDagNodes(output); writeDefaultNodes(output); writeReferenceNodes(output); writeConnections(output); writeFooter(output, file.name); output.Close(); MFnDependencyNode.deallocateFlag(fPluginName, fCreateFlag); return; }
public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { throw new System.NotImplementedException("We only support support writer not reader"); }
// // Maya calls this method to find out if this translator is capable of // handling the given file. // public override MPxFileTranslator.MFileKind identifyFile(MFileObject file, string buffer, short bufferLen) { string tagStr = comment(fTranslatorName); int tagLen = tagStr.Length; // // If the buffer contains enough info to positively identify the file, // then use it. Otherwise we'll base the identification on the file // extension. // if (bufferLen >= tagLen) { string initialContents = buffer.Substring(0,bufferLen); MStringArray initialLines = new MStringArray(initialContents.Split('\n')); //initialLines = initialContents.Split('\n'); if (initialLines.length > 0) { if (((int)initialLines[0].Length >= tagLen) && (initialLines[0].Substring(0, tagLen-1) == tagStr)) { return MPxFileTranslator.MFileKind.kIsMyFileType; } } } else { string fileName = file.name; int fileNameLen = fileName.Length; int startOfExtension = fileName.IndexOf('.') + 1; if ((startOfExtension > 0) && (startOfExtension < fileNameLen) && (fileName.Substring(startOfExtension, fileNameLen) == fExtension)) { return MPxFileTranslator.MFileKind.kIsMyFileType; } } return MPxFileTranslator.MFileKind.kNotMyFileType; }
public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { throw new NotImplementedException("We only support support writer not reader"); }
protected override bool writesFileReference(MFileObject referenceFile) { return outputReferences; }
public override void writer(MFileObject file, string options, MPxFileTranslator.FileAccessMode mode) { string fileName = file.fullName; StreamWriter animFile = new StreamWriter(fileName); // Defaults. // string copyFlags = "copyKey -cb api -fea 1 "; int precision = kDefaultPrecision; bool nodeNames = true; bool verboseUnits = false; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // if (options.Length > 0) { const string flagPrecision = "precision"; const string flagNodeNames = "nodeNames"; const string flagVerboseUnits = "verboseUnits"; const string flagCopyKeyCmd = "copyKeyCmd"; // Start parsing. // string[] optionList = options.Split(new Char[] { ';' }); int nOptions = optionList.Length; for (int i = 0; i < nOptions; i++) { string[] theOption = optionList[i].Split(new Char[] { '=' }); if (theOption.Length < 1) { continue; } if (theOption[0] == flagPrecision && theOption.Length > 1) { precision = Convert.ToInt32(theOption[1]); } else if (theOption[0] == flagNodeNames && theOption.Length > 1) { if (Convert.ToInt32(theOption[1]) == 0) { nodeNames = false; } else { nodeNames = true; } } else if (theOption[0] == flagVerboseUnits && theOption.Length > 1) { if (Convert.ToInt32(theOption[1]) == 0) { verboseUnits = false; } else { verboseUnits = true; } } else if (theOption[0] == flagCopyKeyCmd && theOption.Length > 1) { // Replace any '>' characters with '"'. This is needed // since the file translator option boxes do not handle // escaped quotation marks. // string optStr = theOption[1]; string copyStr = ""; for (int j = 0; j < optStr.Length; j++) { if (optStr[j] == '>') { copyStr += '"'; } else { copyStr += optStr[j]; } } copyFlags += copyStr; } } } // Set the precision of the ofstream. // bool isExported = exportSelected(ref animFile, ref copyFlags, nodeNames, verboseUnits); animFile.Flush(); animFile.Close(); if (!isExported) { throw new ApplicationException("Exporting Anim Failed."); } return; }
public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { string fileName = file.fullName; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // if (optionsString.Length > 0) { // Set up the flags for the paste command. // const string flagTime = "time"; const string flagCopies = "copies"; const string flagOption = "option"; const string flagConnect = "connect"; string copyValue = ""; string flagValue = ""; string connectValue = ""; string timeValue = ""; // Start parsing. // string[] optionList = optionsString.Split(new Char[] { ';' }); int nOptions = optionList.Length; for (int i = 0; i < nOptions; i++) { string[] theOption = optionList[i].Split(new Char[] { '=' }); if (theOption.Length < 1) { continue; } if (theOption[0] == flagCopies && theOption.Length > 1) { copyValue = theOption[1];; } else if (theOption[0] == flagOption && theOption.Length > 1) { flagValue = theOption[1]; } else if (theOption[0] == flagConnect && theOption.Length > 1) { if (Convert.ToInt32(theOption[1]) != 0) { connectValue += theOption[1]; } } else if (theOption[0] == flagTime && theOption.Length > 1) { timeValue += theOption[1]; } } if (copyValue.Length > 0) { pasteFlags += " -copies "; pasteFlags += copyValue; pasteFlags += " "; } if (flagValue.Length > 0) { pasteFlags += " -option \""; pasteFlags += flagValue; pasteFlags += "\" "; } if (connectValue.Length > 0) { pasteFlags += " -connect "; pasteFlags += connectValue; pasteFlags += " "; } if (timeValue.Length > 0) { bool useQuotes = false; try { Convert.ToDouble(timeValue); } catch (System.Exception) { useQuotes = true; } pasteFlags += " -time "; if (useQuotes) { pasteFlags += "\""; } pasteFlags += timeValue; if (useQuotes) { pasteFlags += "\""; } pasteFlags += " "; } } bool isImported = false; if (mode == MPxFileTranslator.FileAccessMode.kImportAccessMode) { isImported = importAim(fileName, pasteFlags); } else { throw new ArgumentException("Invalid File Access mode.", "mode"); } if (!isImported) { throw new ApplicationException("Importing Anim Failed."); } return; }
public override MFileKind identifyFile(MFileObject file, string buffer, short size) { string name = file.name; int namelength = name.Length; string tmpStr = ".aim"; if (namelength > 5 && string.Compare(name, namelength - 5, tmpStr, 0, 5, true) == 0) return MFileKind.kIsMyFileType; // Check the buffer to see if this contains the correct keywords // to be a anim file. // tmpStr = "animVersion"; if (string.Compare(buffer, 0, tmpStr, 0, 11) == 0) return MFileKind.kIsMyFileType; return MFileKind.kNotMyFileType; }
protected override bool writesFileReference(MFileObject referenceFile) { return(outputReferences); }
public override void writer(MFileObject file, string options, MPxFileTranslator.FileAccessMode mode) { string fileName = file.fullName; StreamWriter animFile = new StreamWriter(fileName); // Defaults. // string copyFlags = "copyKey -cb api -fea 1 "; int precision = kDefaultPrecision; bool nodeNames = true; bool verboseUnits = false; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // if (options.Length > 0) { const string flagPrecision = "precision"; const string flagNodeNames = "nodeNames"; const string flagVerboseUnits = "verboseUnits"; const string flagCopyKeyCmd = "copyKeyCmd"; // Start parsing. // string[] optionList = options.Split(new Char[] { ';' }); int nOptions = optionList.Length; for (int i = 0; i < nOptions; i++) { string[] theOption = optionList[i].Split(new Char[] { '=' }); if (theOption.Length < 1) { continue; } if (theOption[0] == flagPrecision && theOption.Length > 1) { precision = Convert.ToInt32(theOption[1]); } else if (theOption[0] == flagNodeNames && theOption.Length > 1) { if (Convert.ToInt32(theOption[1]) == 0) nodeNames = false; else nodeNames = true; } else if (theOption[0] == flagVerboseUnits && theOption.Length > 1) { if (Convert.ToInt32(theOption[1]) == 0) verboseUnits = false; else verboseUnits = true; } else if (theOption[0] == flagCopyKeyCmd && theOption.Length > 1) { // Replace any '>' characters with '"'. This is needed // since the file translator option boxes do not handle // escaped quotation marks. // string optStr = theOption[1]; string copyStr = ""; for (int j = 0; j < optStr.Length; j++) { if (optStr[j] == '>') copyStr += '"'; else copyStr += optStr[j]; } copyFlags += copyStr; } } } // Set the precision of the ofstream. // bool isExported = exportSelected(ref animFile, ref copyFlags, nodeNames, verboseUnits); animFile.Flush(); animFile.Close(); if (!isExported) { throw new ApplicationException("Exporting Anim Failed."); } return; }
public override void reader(MFileObject file, string optionsString, MPxFileTranslator.FileAccessMode mode) { string fileName = file.fullName; // Parse the options. The options syntax is in the form of // "flag=val;flag1=val;flag2=val" // if (optionsString.Length > 0) { // Set up the flags for the paste command. // const string flagTime = "time"; const string flagCopies = "copies"; const string flagOption = "option"; const string flagConnect = "connect"; string copyValue = ""; string flagValue = ""; string connectValue = ""; string timeValue = ""; // Start parsing. // string[] optionList = optionsString.Split(new Char[] { ';' }); int nOptions = optionList.Length; for (int i = 0; i < nOptions; i++) { string[] theOption = optionList[i].Split(new Char[] { '=' }); if (theOption.Length < 1) continue; if (theOption[0] == flagCopies && theOption.Length > 1) { copyValue = theOption[1]; ; } else if (theOption[0] == flagOption && theOption.Length > 1) { flagValue = theOption[1]; } else if (theOption[0] == flagConnect && theOption.Length > 1) { if (Convert.ToInt32(theOption[1]) != 0) connectValue += theOption[1]; } else if (theOption[0] == flagTime && theOption.Length > 1) { timeValue += theOption[1]; } } if (copyValue.Length > 0) { pasteFlags += " -copies "; pasteFlags += copyValue; pasteFlags += " "; } if (flagValue.Length > 0) { pasteFlags += " -option \""; pasteFlags += flagValue; pasteFlags += "\" "; } if (connectValue.Length > 0) { pasteFlags += " -connect "; pasteFlags += connectValue; pasteFlags += " "; } if (timeValue.Length > 0) { bool useQuotes = false; try { Convert.ToDouble(timeValue); } catch (System.Exception) { useQuotes = true; } pasteFlags += " -time "; if (useQuotes) pasteFlags += "\""; pasteFlags += timeValue; if (useQuotes) pasteFlags += "\""; pasteFlags += " "; } } bool isImported = false; if (mode == MPxFileTranslator.FileAccessMode.kImportAccessMode) isImported = importAim(fileName, pasteFlags); else throw new ArgumentException("Invalid File Access mode.", "mode"); if (!isImported) { throw new ApplicationException("Importing Anim Failed."); } return; }