private NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format, NJS_OBJECT parent, Dictionary <int, string> labels, Dictionary <int, Attach> attaches) { if (labels.ContainsKey(address)) { Name = labels[address]; } else { Name = "object_" + address.ToString("X8"); } ObjectFlags flags = (ObjectFlags)ByteConverter.ToInt32(file, address); RotateZYX = (flags & ObjectFlags.RotateZYX) == ObjectFlags.RotateZYX; Animate = (flags & ObjectFlags.NoAnimate) == 0; Morph = (flags & ObjectFlags.NoMorph) == 0; int tmpaddr = ByteConverter.ToInt32(file, address + 4); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); if (attaches != null && attaches.ContainsKey(tmpaddr)) { Attach = attaches[tmpaddr]; } else { Attach = Attach.Load(file, tmpaddr, imageBase, format, labels); attaches.Add(tmpaddr, Attach); } } Position = new Vertex(file, address + 8); Rotation = new Rotation(file, address + 0x14); Scale = new Vertex(file, address + 0x20); Parent = parent; children = new List <NJS_OBJECT>(); Children = new ReadOnlyCollection <NJS_OBJECT>(children); NJS_OBJECT child = null; tmpaddr = ByteConverter.ToInt32(file, address + 0x2C); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); child = new NJS_OBJECT(file, tmpaddr, imageBase, format, this, labels, attaches); } while (child != null) { children.Add(child); child = child.Sibling; } tmpaddr = ByteConverter.ToInt32(file, address + 0x30); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); Sibling = new NJS_OBJECT(file, tmpaddr, imageBase, format, parent, labels, attaches); } //Assimp.AssimpContext context = new AssimpContext(); //Scene scene = context.ImportFile("F:\\untitled.obj", PostProcessSteps.Triangulate); //AssimpLoad(scene, scene.RootNode); }
private void DrawExportAdvancedOptions() { bool wasEnabled = GUI.enabled; if (exportPreset == ExportPreset.Custom) { GUI.enabled = true; } else { GUI.enabled = false; } EditorGUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label("Models:", EditorStyles.miniBoldLabel); modelFormat = (ModelFormat)EditorGUILayout.EnumPopup("ModelFormat:", modelFormat); GUILayout.Label("Textures:", EditorStyles.miniBoldLabel); textureFormat = (TextureFormat)EditorGUILayout.EnumPopup("TextureFormat:", textureFormat); textureType = (TextureType)EditorGUILayout.EnumPopup("TextureType:", textureType); textureScaleMode = (MA_TextureUtils.TextureScaleMode)EditorGUILayout.EnumPopup("TextureScaleMode:", textureScaleMode); EditorGUILayout.EndVertical(); GUI.enabled = wasEnabled; }
public GeoAnimData(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, Dictionary <int, Attach> attaches) { ModelFormat mfmt = 0; switch (format) { case LandTableFormat.SA1: mfmt = ModelFormat.Basic; break; case LandTableFormat.SADX: mfmt = ModelFormat.BasicDX; break; case LandTableFormat.SA2: mfmt = ModelFormat.Chunk; break; } AnimationFrame = ByteConverter.ToSingle(file, address); AnimationSpeed = ByteConverter.ToSingle(file, address + 4); MaxFrame = ByteConverter.ToSingle(file, address + 8); Model = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address + 0xC) - imageBase), imageBase, mfmt, labels, attaches); int actionaddr = (int)(ByteConverter.ToUInt32(file, address + 0x10) - imageBase); TexlistPointer = ByteConverter.ToUInt32(file, address + 0x14); NJS_ACTION action = new NJS_ACTION(file, actionaddr, imageBase, mfmt, labels, attaches); Animation = action.Animation; }
public GeoAnimData(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, Dictionary <int, Attach> attaches) { ModelFormat mfmt = 0; switch (format) { case LandTableFormat.SA1: mfmt = ModelFormat.Basic; break; case LandTableFormat.SADX: mfmt = ModelFormat.BasicDX; break; case LandTableFormat.SA2: mfmt = ModelFormat.Chunk; break; } Unknown1 = ByteConverter.ToInt32(file, address); Unknown2 = ByteConverter.ToSingle(file, address + 4); Unknown3 = ByteConverter.ToSingle(file, address + 8); Model = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address + 0xC) - imageBase), imageBase, mfmt, labels, attaches); Animation = NJS_MOTION.ReadHeader(file, (int)(ByteConverter.ToUInt32(file, address + 0x10) - imageBase), imageBase, mfmt, labels, attaches); Unknown4 = ByteConverter.ToInt32(file, address + 0x14); }
public static IModelLoader Load(Stream stream, string filename, ModelFormat type) { IModelLoader modelLoader = null; try { switch (type) { case ModelFormat.PMX: modelLoader = new PmxReader(stream, filename); break; case ModelFormat.DAE: modelLoader = new ReaderDAE(stream, filename); break; case ModelFormat.LMD: modelLoader = new ReaderLMD(stream, filename); break; case ModelFormat.PMD: modelLoader = new PmdReader(stream, filename); break; } } catch (Exception e) { logger.Error(e.Message, e.TargetSite.Name); } return(modelLoader); }
public void LoadModel(string modelName) { try { string filePath = String.Format("{0} {1}", modelFolder, modelName); List <string> lines = File.ReadLines(filePath).ToList(); var vertexCountString = lines[0].Split(new char[] { ':' })[1].Trim(); int vertexCount = int.Parse(vertexCountString); modelObject = new ModelFormat[vertexCount]; int startLine = 4; for (int i = startLine; i < lines.Count && i < startLine + vertexCount; i++) { var modelArray = lines[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); modelObject[i - startLine] = new ModelFormat() { x = float.Parse(modelArray[0]), y = float.Parse(modelArray[1]), z = float.Parse(modelArray[2]), tu = float.Parse(modelArray[3]), tv = float.Parse(modelArray[4]), nx = float.Parse(modelArray[5]), ny = float.Parse(modelArray[6]), nz = float.Parse(modelArray[7]), }; } } catch (Exception) { throw; } }
public static IModelLoader Load(Stream stream, string filename) { string fileExtension = filename.Substring(filename.LastIndexOf('.') + 1); fileExtension = fileExtension.ToLower(); ModelFormat format = 0; switch (fileExtension) { case "pmx": format = ModelFormat.PMX; break; case "dae": format = ModelFormat.DAE; break; case "lmd": format = ModelFormat.LMD; break; case "pmd": format = ModelFormat.PMD; break; default: logger.Error("cant recognize file format", ""); break; } return(Load(stream, filename, format)); }
public EditorVM(ModelDoc document) { Document = document; Format = new ModelFormat(); FormatCommand = new RelayCommand(OpenStyleWindow); WrapCommand = new RelayCommand(ToogleWrap); }
public ModelExportEventArgs(string folder, string name, ModelFormat format, bool savePosition, bool saveTexture) { Folder = folder; Name = name; Format = format; SavePosition = savePosition; SaveTexture = saveTexture; }
public static Animation ReadHeader(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary <int, string> labels) { NJS_OBJECT Model = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address) - imageBase), imageBase, format); return(new Animation(file, (int)(ByteConverter.ToUInt32(file, address + 4) - imageBase), imageBase, Model.CountAnimated(), labels)); }
/// <summary> /// Parses and adds a new model to engine /// </summary> /// <remarks> /// Multiple models may be added. /// </remarks> public ApplicationEngine WithModel(string modelText, ModelFormat format) { var name = (_modelCount == 0) ? ScribanNamespaces.ModelPrefix : $"{ScribanNamespaces.ModelPrefix}{_modelCount}"; return(WithModel(name, modelText, format)); }
public ModelAnimations(string filename, string name, NJS_OBJECT model, ModelFormat format) { Filename = filename; Name = name; Model = model; Format = format; Animations = new List <string>(); }
private void _Save(string filepath, ModelFormat format, bool useExternalFilesToStoreParameters) { CNTKLibPINVOKE.Function__Save__SWIG_1(swigCPtr, filepath, (int)format, useExternalFilesToStoreParameters); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } }
private void _Save(string filepath, ModelFormat format) { CNTKLibPINVOKE.Function__Save__SWIG_2(swigCPtr, filepath, (int)format); if (CNTKLibPINVOKE.SWIGPendingException.Pending) { throw CNTKLibPINVOKE.SWIGPendingException.Retrieve(); } }
// Scan for Actions in a specific range static int ScanActions(uint addr, uint nummdl, ModelFormat modelfmt) { int count = 0; ByteConverter.BigEndian = BigEndian; if (nummdl == 0) { return(0); } for (uint address = addr; address < datafile.Length - 8; address += 1) { CurrentAddress = address; if (CancelScan) { break; } if (ByteConverter.ToUInt32(datafile, (int)address) != addr + ImageBase) { continue; } uint motaddr = ByteConverter.ToUInt32(datafile, (int)address + 4); if (motaddr < ImageBase) { continue; } try { NJS_MOTION mot = new NJS_MOTION(datafile, (int)(motaddr - ImageBase), ImageBase, (int)nummdl, null, false); if (mot.Models.Count == 0) { continue; } addresslist.Add(motaddr - ImageBase, "NJS_MOTION"); Console.WriteLine("\rMotion found for model {0} at address {1}", addr.ToString("X8"), (motaddr - ImageBase).ToString("X")); string fileOutputPath = Path.Combine(OutputFolder, "actions", (motaddr - ImageBase).ToString("X8")); if (SingleOutputFolder) { fileOutputPath = Path.Combine(OutputFolder, (motaddr - ImageBase).ToString("X8")); } mot.Save(fileOutputPath + ".saanim", NoMeta); uint[] arr = new uint[2]; arr[0] = addr; arr[1] = nummdl; actionlist.Add(motaddr - ImageBase, arr); AddAction(addr, motaddr - ImageBase); address += 7; count++; } catch (Exception) { continue; } } return(count); }
public void ImportModel(ModelFormat theFormat) { int aFormat = 10; OpenFileDialog anOpenDialog = new OpenFileDialog(); string aDataDir = ((Environment.GetEnvironmentVariable("CASROOT")) + "\\..\\data"); string aFilter = ""; switch (theFormat) { case ModelFormat.BREP: anOpenDialog.InitialDirectory = (aDataDir + "\\occ"); aFormat = 0; aFilter = "BREP Files (*.brep *.rle)|*.brep; *.rle"; break; case ModelFormat.CSFDB: aFormat = 1; aFilter = "CSFDB Files (*.csfdb)|*.csfdb"; break; case ModelFormat.STEP: anOpenDialog.InitialDirectory = (aDataDir + "\\step"); aFormat = 2; aFilter = "STEP Files (*.stp *.step)|*.stp; *.step"; break; case ModelFormat.IGES: anOpenDialog.InitialDirectory = (aDataDir + "\\iges"); aFormat = 3; aFilter = "IGES Files (*.igs *.iges)|*.igs; *.iges"; break; default: break; } anOpenDialog.Filter = aFilter + "|All files (*.*)|*.*"; if (anOpenDialog.ShowDialog() == DialogResult.OK) { string aFileName = anOpenDialog.FileName; if (aFileName == "") { return; } Cursor = System.Windows.Forms.Cursors.WaitCursor; if (!View.TranslateModel(aFileName, aFormat, true)) { MessageBox.Show("Cann't read this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } Cursor = System.Windows.Forms.Cursors.Default; } View.ZoomAllView(); }
public static Attach Load(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary<int, string> labels) { switch (format) { case ModelFormat.Basic: case ModelFormat.BasicDX: return new BasicAttach(file, address, imageBase, format == ModelFormat.BasicDX, labels); case ModelFormat.Chunk: return new ChunkAttach(file, address, imageBase, labels); } throw new ArgumentOutOfRangeException("format"); }
public static Attach Load(ModelFormat format) { switch (format) { case ModelFormat.Basic: case ModelFormat.BasicDX: return new BasicAttach(); case ModelFormat.Chunk: return new ChunkAttach(); } throw new ArgumentOutOfRangeException("format"); }
public static int Size(ModelFormat format) { switch (format) { case ModelFormat.Basic: return 0x28; case ModelFormat.BasicDX: return 0x2C; case ModelFormat.Chunk: return 0x18; } return -1; }
public static Attach Load(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary <int, string> labels) { switch (format) { case ModelFormat.Basic: case ModelFormat.BasicDX: return(new BasicAttach(file, address, imageBase, format == ModelFormat.BasicDX, labels)); case ModelFormat.Chunk: return(new ChunkAttach(file, address, imageBase, labels)); } throw new ArgumentOutOfRangeException("format"); }
public static Attach Load(ModelFormat format) { switch (format) { case ModelFormat.Basic: case ModelFormat.BasicDX: return(new BasicAttach()); case ModelFormat.Chunk: return(new ChunkAttach()); } throw new ArgumentOutOfRangeException("format"); }
public void RequestGenerate() { VisualizationController.OpenVisualizers(); m_latestModel = GenerationControler.Generate(ViewModel); LatestModelTemporaryFileFormat = ModelFormat.OBJ; m_latestModelTemporaryfile?.Dispose(); ExportController.ExportInStream(m_latestModel, new ExportParameters { ModelFormat = LatestModelTemporaryFileFormat }, out m_latestModelTemporaryfile); RequestVisualize(); }
public static string ToString(this ModelFormat format) { switch (format) { case ModelFormat.OBJ: return("obj"); case ModelFormat.STL: return("stl"); case ModelFormat.ThreeDS: return("3ds"); default: return(null); } }
public COL(byte[] file, int address, uint imageBase, LandTableFormat format, Dictionary <int, string> labels, bool?forceBasic) { Bounds = new BoundingSphere(file, address); ModelFormat mfmt = 0; switch (format) { case LandTableFormat.SA1: mfmt = ModelFormat.Basic; break; case LandTableFormat.SADX: mfmt = ModelFormat.BasicDX; break; case LandTableFormat.SA2: if (forceBasic.HasValue && forceBasic.Value) { mfmt = ModelFormat.Basic; } else { mfmt = ModelFormat.Chunk; } break; } switch (format) { case LandTableFormat.SA1: case LandTableFormat.SADX: Unknown1 = ByteConverter.ToInt32(file, address + 0x10); Unknown2 = ByteConverter.ToInt32(file, address + 0x14); uint tmpaddr = ByteConverter.ToUInt32(file, address + 0x18) - imageBase; Model = new NJS_OBJECT(file, (int)tmpaddr, imageBase, mfmt, labels); Unknown3 = ByteConverter.ToInt32(file, address + 0x1C); Flags = ByteConverter.ToInt32(file, address + 0x20); break; case LandTableFormat.SA2: Flags = ByteConverter.ToInt32(file, address + 0x1C); if (!forceBasic.HasValue) { mfmt = Flags < 0 ? ModelFormat.Chunk : ModelFormat.Basic; } tmpaddr = ByteConverter.ToUInt32(file, address + 0x10) - imageBase; Model = new NJS_OBJECT(file, (int)tmpaddr, imageBase, mfmt, labels); Unknown2 = ByteConverter.ToInt32(file, address + 0x14); Unknown3 = ByteConverter.ToInt32(file, address + 0x18); break; } }
public Settings() { mapFolder = dataFolder = classFilter = ""; permFilter = "base default standard"; pluginFolder = ".\\Plugins\\"; Flags = SettingsFlags.AutoUpdateCheck | SettingsFlags.BitmapAlpha | SettingsFlags.LoadSpecular | SettingsFlags.SortTags | SettingsFlags.UsePermFilter | SettingsFlags.UseClassFilter; ViewerColour = Color.CornflowerBlue; Language = Language.English; BitmFormat = 0; ModeFormat = 0; Snd_Format = 0; mapScale = 100; pakScale = 50; }
public static bool TryFormatFromString(string formatCode, out ModelFormat result) { switch (formatCode) { case "obj": result = ModelFormat.OBJ; break; case "stl": result = ModelFormat.STL; break; case "3ds": result = ModelFormat.ThreeDS; break; default: result = ModelFormat.OBJ; return(false); } return(true); }
public ModelFormat GetModelFormat() { // BasicAttach has no internal distinction between Basic and BasicDX ModelFormat result = ModelFormat.BasicDX; if (Attach is ChunkAttach) { result = ModelFormat.Chunk; } else if (Attach is GC.GCAttach) { result = ModelFormat.GC; } return(result); }
/// <summary> /// Sets the default model format. /// </summary> /// <param name="modelFormat">Model format.</param> public void SetDefaultModelFormat(ModelFormat modelFormat) { lock (this.ReadLock) { FileIniDataParser parser = new FileIniDataParser(); IniData data = parser.ReadFile(GetConfigurationFilePath()); data[Export][DefaultExportModelFormat] = ((int)modelFormat).ToString(); lock (this.WriteLock) { WriteConfig(parser, data); } } }
public static int Size(ModelFormat format) { switch (format) { case ModelFormat.Basic: return(0x28); case ModelFormat.BasicDX: return(0x2C); case ModelFormat.Chunk: return(0x18); } return(-1); }
public NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary <int, string> labels) { if (labels.ContainsKey(address)) { Name = labels[address]; } else { Name = "object_" + address.ToString("X8"); } ObjectFlags flags = (ObjectFlags)ByteConverter.ToInt32(file, address); RotateZYX = (flags & ObjectFlags.RotateZYX) == ObjectFlags.RotateZYX; Animate = (flags & ObjectFlags.NoAnimate) == 0; Morph = (flags & ObjectFlags.NoMorph) == 0; int tmpaddr = ByteConverter.ToInt32(file, address + 4); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); Attach = Attach.Load(file, tmpaddr, imageBase, format, labels); } Position = new Vertex(file, address + 8); Rotation = new Rotation(file, address + 0x14); Scale = new Vertex(file, address + 0x20); Children = new List <NJS_OBJECT>(); NJS_OBJECT child = null; tmpaddr = ByteConverter.ToInt32(file, address + 0x2C); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); child = new NJS_OBJECT(file, tmpaddr, imageBase, format, labels); } while (child != null) { Children.Add(child); child = child.Sibling; } tmpaddr = ByteConverter.ToInt32(file, address + 0x30); if (tmpaddr != 0) { tmpaddr = (int)unchecked ((uint)tmpaddr - imageBase); Sibling = new NJS_OBJECT(file, tmpaddr, imageBase, format, labels); } }
private void buttonOK_Click(object sender, EventArgs e) { if (radioButtonBasicModel.Checked) { Format = ModelFormat.BasicDX; } else if (radioButtonChunkModel.Checked) { Format = ModelFormat.Chunk; } else { Format = ModelFormat.GC; } ImportAsNodes = radioButtonNodes.Checked; ImportColladaRootNode = checkBoxImportColladaRootNode.Checked; LegacyOBJImport = checkBoxLegacyOBJ.Checked; }
public static void ExportAtlasModels(MA_TextureAtlasserProAtlas atlas, ModelFormat modelFormat, string savePath = EXPORTASSETPATH) { switch (modelFormat) { case ModelFormat.None: break; case ModelFormat.Obj: ExportAtlasObj(atlas, savePath); break; case ModelFormat.ReplaceObj: ModifyAtlasObj(atlas); break; default: break; } }
protected virtual T DeserializeModelFromString(string model) { string m = model.TrimStart(); if (m.StartsWith("<")) { modelFormat = ModelFormat.XML; return(Xml.FromXmlString <T>(model)); } else if (m.StartsWith("{")) { modelFormat = ModelFormat.JSON; return(StdJson.ObjectFromString <T>(model) ?? new T()); } else { throw new Exception($"Unknown file format for {modelFileName}: expected XML or JSON"); } }
public NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary<int, string> labels) { if (labels.ContainsKey(address)) Name = labels[address]; else Name = "object_" + address.ToString("X8"); ObjectFlags flags = (ObjectFlags)ByteConverter.ToInt32(file, address); RotateZYX = (flags & ObjectFlags.RotateZYX) == ObjectFlags.RotateZYX; Animate = (flags & ObjectFlags.NoAnimate) == 0; Morph = (flags & ObjectFlags.NoMorph) == 0; int tmpaddr = ByteConverter.ToInt32(file, address + 4); if (tmpaddr != 0) { tmpaddr = (int)unchecked((uint)tmpaddr - imageBase); Attach = Attach.Load(file, tmpaddr, imageBase, format, labels); } Position = new Vertex(file, address + 8); Rotation = new Rotation(file, address + 0x14); Scale = new Vertex(file, address + 0x20); Children = new List<NJS_OBJECT>(); NJS_OBJECT child = null; tmpaddr = ByteConverter.ToInt32(file, address + 0x2C); if (tmpaddr != 0) { tmpaddr = (int)unchecked((uint)tmpaddr - imageBase); child = new NJS_OBJECT(file, tmpaddr, imageBase, format, labels); } while (child != null) { Children.Add(child); child = child.Sibling; } tmpaddr = ByteConverter.ToInt32(file, address + 0x30); if (tmpaddr != 0) { tmpaddr = (int)unchecked((uint)tmpaddr - imageBase); Sibling = new NJS_OBJECT(file, tmpaddr, imageBase, format, labels); } }
public static void CreateFile(string filename, NJS_OBJECT model, string[] animationFiles, string[] morphFiles, string author, string description, string tool, Dictionary<uint, byte[]> metadata, ModelFormat format) { bool be = ByteConverter.BigEndian; ByteConverter.BigEndian = false; if (format == ModelFormat.BasicDX) format = ModelFormat.Basic; List<byte> file = new List<byte>(); ulong magic; switch (format) { case ModelFormat.Basic: case ModelFormat.BasicDX: magic = SA1MDLVer; break; case ModelFormat.Chunk: magic = SA2MDLVer; break; default: throw new ArgumentException("Cannot save " + format.ToString() + " format models to file!", "format"); } file.AddRange(ByteConverter.GetBytes(magic)); uint addr; Dictionary<string, uint> labels = new Dictionary<string, uint>(); byte[] mdl = model.GetBytes(0x10, false, labels, out addr); file.AddRange(ByteConverter.GetBytes(addr + 0x10)); file.AddRange(ByteConverter.GetBytes(mdl.Length + 0x10)); file.AddRange(mdl); if (labels.Count > 0) { List<byte> chunk = new List<byte>((labels.Count * 8) + 8); int straddr = (labels.Count * 8) + 8; List<byte> strbytes = new List<byte>(); foreach (KeyValuePair<string, uint> label in labels) { chunk.AddRange(ByteConverter.GetBytes(label.Value)); chunk.AddRange(ByteConverter.GetBytes(straddr + strbytes.Count)); strbytes.AddRange(Encoding.UTF8.GetBytes(label.Key)); strbytes.Add(0); strbytes.Align(4); } chunk.AddRange(ByteConverter.GetBytes(-1L)); chunk.AddRange(strbytes); file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Label)); file.AddRange(ByteConverter.GetBytes(chunk.Count)); file.AddRange(chunk); } if (animationFiles != null && animationFiles.Length > 0) { List<byte> chunk = new List<byte>((animationFiles.Length + 1) * 4); int straddr = (animationFiles.Length + 1) * 4; List<byte> strbytes = new List<byte>(); for (int i = 0; i < animationFiles.Length; i++) { chunk.AddRange(ByteConverter.GetBytes(straddr + strbytes.Count)); strbytes.AddRange(Encoding.UTF8.GetBytes(animationFiles[i])); strbytes.Add(0); strbytes.Align(4); } chunk.AddRange(ByteConverter.GetBytes(-1)); chunk.AddRange(strbytes); file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Animation)); file.AddRange(ByteConverter.GetBytes(chunk.Count)); file.AddRange(chunk); } if (morphFiles != null && morphFiles.Length > 0) { List<byte> chunk = new List<byte>((morphFiles.Length + 1) * 4); int straddr = (morphFiles.Length + 1) * 4; List<byte> strbytes = new List<byte>(); for (int i = 0; i < morphFiles.Length; i++) { chunk.AddRange(ByteConverter.GetBytes(straddr + strbytes.Count)); strbytes.AddRange(Encoding.UTF8.GetBytes(morphFiles[i])); strbytes.Add(0); strbytes.Align(4); } chunk.AddRange(ByteConverter.GetBytes(-1)); chunk.AddRange(strbytes); file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Morph)); file.AddRange(ByteConverter.GetBytes(chunk.Count)); file.AddRange(chunk); } if (!string.IsNullOrEmpty(author)) { List<byte> chunk = new List<byte>(author.Length + 1); chunk.AddRange(Encoding.UTF8.GetBytes(author)); chunk.Add(0); chunk.Align(4); file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Author)); file.AddRange(ByteConverter.GetBytes(chunk.Count)); file.AddRange(chunk); } if (!string.IsNullOrEmpty(description)) { List<byte> chunk = new List<byte>(description.Length + 1); chunk.AddRange(Encoding.UTF8.GetBytes(description)); chunk.Add(0); chunk.Align(4); file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Description)); file.AddRange(ByteConverter.GetBytes(chunk.Count)); file.AddRange(chunk); } if (!string.IsNullOrEmpty(tool)) { List<byte> chunk = new List<byte>(tool.Length + 1); chunk.AddRange(Encoding.UTF8.GetBytes(tool)); chunk.Add(0); chunk.Align(4); file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.Tool)); file.AddRange(ByteConverter.GetBytes(chunk.Count)); file.AddRange(chunk); } if (metadata != null) { foreach (KeyValuePair<uint, byte[]> item in metadata) { file.AddRange(ByteConverter.GetBytes(item.Key)); file.AddRange(ByteConverter.GetBytes(item.Value.Length)); file.AddRange(item.Value); } } file.AddRange(ByteConverter.GetBytes((uint)ChunkTypes.End)); file.AddRange(new byte[4]); File.WriteAllBytes(filename, file.ToArray()); ByteConverter.BigEndian = be; }
private bool LoadModel(string modelFormatFilename) { modelFormatFilename = SystemConfiguration.ModelFilePath + modelFormatFilename; List<string> lines = null; try { lines = File.ReadLines(modelFormatFilename).ToList(); var vertexCountString = lines[0].Split(new char[] { ':' })[1].Trim(); VertexCount = int.Parse(vertexCountString); IndexCount = VertexCount; ModelObject = new ModelFormat[VertexCount]; for (var i = 4; i < lines.Count && i < 4 + VertexCount; i++) { var modelArray = lines[i].Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); ModelObject[i - 4] = new ModelFormat() { x = float.Parse(modelArray[0]), y = float.Parse(modelArray[1]), z = float.Parse(modelArray[2]), tu = float.Parse(modelArray[3]), tv = float.Parse(modelArray[4]), nx = float.Parse(modelArray[5]), ny = float.Parse(modelArray[6]), nz = float.Parse(modelArray[7]) }; } return true; } catch (Exception) { return false; } }
public NJS_OBJECT(byte[] file, int address, uint imageBase, ModelFormat format) : this(file, address, imageBase, format, new Dictionary<int, string>()) { }
public void ExportModel(ModelFormat format) { int theformat=10; System.Windows.Forms.SaveFileDialog saveDialog = new SaveFileDialog(); string DataDir=((Environment.GetEnvironmentVariable("CASROOT")) + "\\..\\data"); string filter=""; switch (format) { case IE.ModelFormat.BREP: saveDialog.InitialDirectory = (DataDir + "\\occ"); theformat=0; filter= "BREP Files (*.brep *.rle)|*.brep; *.rle"; break; case IE.ModelFormat.CSFDB: theformat=1; filter= "CSFDB Files (*.csfdb)|*.csfdb"; break; case IE.ModelFormat.STEP: saveDialog.InitialDirectory = (DataDir + "\\step"); theformat=2; filter="STEP Files (*.stp *.step)|*.step; *.stp"; break; case IE.ModelFormat.IGES: saveDialog.InitialDirectory = (DataDir + "\\iges"); theformat=3; filter="IGES Files (*.igs *.iges)| *.iges; *.igs"; break; case IE.ModelFormat.VRML: saveDialog.InitialDirectory = (DataDir + "\\vrml"); theformat=4; filter="VRML Files (*.vrml)|*.vrml"; break; case IE.ModelFormat.STL: saveDialog.InitialDirectory = (DataDir + "\\stl"); theformat=5; filter="STL Files (*.stl)|*.stl"; break; case IE.ModelFormat.IMAGE: saveDialog.InitialDirectory = (DataDir + "\\images"); theformat=6; filter="Images Files (*.bmp *.gif *.xwd)| *.bmp; *.gif; *.xwd"; break; default: break; } saveDialog.Filter = filter; if(saveDialog.ShowDialog() == DialogResult.OK) { string filename = saveDialog.FileName; if ( filename=="") return; this.Cursor=System.Windows.Forms.Cursors.WaitCursor; if (!myView.TranslateModel(filename, theformat, false)) MessageBox.Show("Cann't write this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Cursor=System.Windows.Forms.Cursors.Default; } }
private bool SaveFile(string filename, ModelFormat format) { if (format == ModelFormat.UNKNOWN) { MessageBox.Show("�T�|�[�g����Ă��Ȃ��t�@�C���`���ł��B", "�G���[", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } this.Cursor=System.Windows.Forms.Cursors.WaitCursor; ViewForm curForm = (ViewForm) this.ActiveMdiChild; if (curForm == null) return false; bool result = curForm.Export(filename, Common.getFormatByExt(filename)); this.Cursor=System.Windows.Forms.Cursors.Default; if (!result) { MessageBox.Show("�t�@�C���̕ۑ��Ɏ��s���܂����B", "�G���[", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return result; }
private bool OpenFile(string filename, ModelFormat theformat) { if (theformat == ModelFormat.UNKNOWN) { MessageBox.Show("�T�|�[�g����Ă��Ȃ��t�@�C���`���ł��B", "�G���[", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } this.Cursor = System.Windows.Forms.Cursors.WaitCursor; NewFile(); ViewForm curForm = (ViewForm) this.ActiveMdiChild; bool result = curForm.Import(filename, theformat); this.Cursor = System.Windows.Forms.Cursors.Default; if (!result) { MessageBox.Show("�t�@�C���̓ǂݍ��݂Ɏ��s���܂����B", "�G���[", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } this.toolStripMain.Enabled = true; return true; }
private void LoadFile(string filename) { loaded = false; Environment.CurrentDirectory = Path.GetDirectoryName(filename); timer1.Stop(); modelFile = null; animation = null; animations = null; animnum = -1; animframe = 0; if (ModelFile.CheckModelFile(filename)) { modelFile = new ModelFile(filename); outfmt = modelFile.Format; model = modelFile.Model; animations = new Animation[modelFile.Animations.Count]; modelFile.Animations.CopyTo(animations, 0); } else { using (FileTypeDialog ftd = new FileTypeDialog()) { if (ftd.ShowDialog(this) != DialogResult.OK) return; byte[] file = File.ReadAllBytes(filename); if (Path.GetExtension(filename).Equals(".prs", StringComparison.OrdinalIgnoreCase)) file = FraGag.Compression.Prs.Decompress(file); if (ftd.typBinary.Checked) { modelinfo.ShowDialog(this); if (modelinfo.checkBox1.Checked) animations = new Animation[] { Animation.ReadHeader(file, (int)modelinfo.numericUpDown3.Value, (uint)modelinfo.numericUpDown2.Value, (ModelFormat)modelinfo.comboBox2.SelectedIndex) }; model = new NJS_OBJECT(file, (int)modelinfo.NumericUpDown1.Value, (uint)modelinfo.numericUpDown2.Value, (ModelFormat)modelinfo.comboBox2.SelectedIndex); switch ((ModelFormat)modelinfo.comboBox2.SelectedIndex) { case ModelFormat.Basic: case ModelFormat.BasicDX: outfmt = ModelFormat.Basic; break; case ModelFormat.Chunk: outfmt = ModelFormat.Chunk; break; } } else if (ftd.typSA2MDL.Checked | ftd.typSA2BMDL.Checked) { ModelFormat fmt = outfmt = ModelFormat.Chunk; ByteConverter.BigEndian = ftd.typSA2BMDL.Checked; using (SA2MDLDialog dlg = new SA2MDLDialog()) { int address = 0; SortedDictionary<int, NJS_OBJECT> sa2models = new SortedDictionary<int, NJS_OBJECT>(); int i = ByteConverter.ToInt32(file, address); while (i != -1) { sa2models.Add(i, new NJS_OBJECT(file, ByteConverter.ToInt32(file, address + 4), 0, fmt)); address += 8; i = ByteConverter.ToInt32(file, address); } foreach (KeyValuePair<int, NJS_OBJECT> item in sa2models) dlg.modelChoice.Items.Add(item.Key + ": " + item.Value.Name); dlg.ShowDialog(this); i = 0; foreach (KeyValuePair<int, NJS_OBJECT> item in sa2models) { if (i == dlg.modelChoice.SelectedIndex) { model = item.Value; break; } i++; } if (dlg.checkBox1.Checked) { using (OpenFileDialog anidlg = new OpenFileDialog() { DefaultExt = "bin", Filter = "Motion Files|*MTN.BIN;*MTN.PRS|All Files|*.*" }) { if (anidlg.ShowDialog(this) == DialogResult.OK) { byte[] anifile = File.ReadAllBytes(anidlg.FileName); if (Path.GetExtension(anidlg.FileName).Equals(".prs", StringComparison.OrdinalIgnoreCase)) anifile = FraGag.Compression.Prs.Decompress(anifile); address = 0; SortedDictionary<int, Animation> anis = new SortedDictionary<int, Animation>(); i = ByteConverter.ToInt32(file, address); while (i != -1) { anis.Add(i, new Animation(file, ByteConverter.ToInt32(file, address + 4), 0, model.CountAnimated())); address += 8; i = ByteConverter.ToInt32(file, address); } animations = new List<Animation>(anis.Values).ToArray(); } } } } } } } model.ProcessVertexData(); NJS_OBJECT[] models = model.GetObjects(); meshes = new Mesh[models.Length]; for (int i = 0; i < models.Length; i++) if (models[i].Attach != null) try { meshes[i] = models[i].Attach.CreateD3DMesh(d3ddevice); } catch { } treeView1.Nodes.Clear(); nodeDict = new Dictionary<NJS_OBJECT, TreeNode>(); AddTreeNode(model, treeView1.Nodes); loaded = saveToolStripMenuItem.Enabled = exportToolStripMenuItem.Enabled = findToolStripMenuItem.Enabled = true; selectedObject = model; SelectedItemChanged(); }
public static Attach Load(byte[] file, int address, uint imageBase, ModelFormat format) { return Load(file, address, imageBase, format, new Dictionary<int, string>()); }
public void ExportModel (ModelFormat theFormat) { int aFormat = 10; SaveFileDialog saveDialog = new SaveFileDialog (); string aDataDir = Environment.GetEnvironmentVariable ("CSF_OCCTDataPath"); string aFilter = ""; switch (theFormat) { case ModelFormat.BREP: saveDialog.InitialDirectory = (aDataDir + "\\occ"); aFormat = 0; aFilter = "BREP Files (*.brep *.rle)|*.brep; *.rle"; break; case ModelFormat.STEP: saveDialog.InitialDirectory = (aDataDir + "\\step"); aFormat = 1; aFilter = "STEP Files (*.stp *.step)|*.step; *.stp"; break; case ModelFormat.IGES: saveDialog.InitialDirectory = (aDataDir + "\\iges"); aFormat = 2; aFilter = "IGES Files (*.igs *.iges)| *.iges; *.igs"; break; case ModelFormat.VRML: saveDialog.InitialDirectory = (aDataDir + "\\vrml"); aFormat = 3; aFilter = "VRML Files (*.vrml)|*.vrml"; break; case ModelFormat.STL: saveDialog.InitialDirectory = (aDataDir + "\\stl"); aFormat = 4; aFilter = "STL Files (*.stl)|*.stl"; break; case ModelFormat.IMAGE: saveDialog.InitialDirectory = (aDataDir + "\\images"); aFormat = 5; aFilter = "Images Files (*.bmp)|*.bmp"; break; default: break; } saveDialog.Filter = aFilter; if (saveDialog.ShowDialog () == DialogResult.OK) { string aFileName = saveDialog.FileName; if (aFileName == "") { return; } if (!View.TranslateModel (aFileName, aFormat, false)) { MessageBox.Show ("Can not write this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void ReadHeader() { var headerStr = new string(_reader.ReadChars(4)); if (headerStr == "EMF1") { _modelFormat = ModelFormat.Emf1; } else if (headerStr == "EMF2") { _modelFormat = ModelFormat.Emf2; } else if (headerStr == "EMF3") { _modelFormat = ModelFormat.Emf3; } else if (headerStr == "EMF4") { _modelFormat = ModelFormat.Emf4; } else { throw new Exception(string.Format("Expected model to begin with header `EMF1` or `EMF2`. Got `{0}` instead", headerStr)); } }
/// <summary> /// �G�N�X�|�[�g /// </summary> /// <param name="filename"></param> /// <param name="format"></param> /// <returns></returns> public bool Export(string filename, ModelFormat format) { switch (format) { case ModelFormat.BREP: case ModelFormat.CSFDB: case ModelFormat.IGES: case ModelFormat.STEP: case ModelFormat.STL: case ModelFormat.VRML: case ModelFormat.IMAGE: return myViewer.TranslateModel(filename, (int)format, false); default: return false; } }
public static Animation ReadHeader(byte[] file, int address, uint imageBase, ModelFormat format) { return ReadHeader(file, address, imageBase, format, new Dictionary<int, string>()); }
public AnimationHeader(byte[] file, int address, uint imageBase, ModelFormat format) : this(file, address, imageBase, format, new Dictionary<int, string>()) { }
public void ImportModel (ModelFormat theFormat) { int aFormat = 10; OpenFileDialog anOpenDialog = new OpenFileDialog (); string aDataDir = Environment.GetEnvironmentVariable ("CSF_OCCTDataPath"); string aFilter = ""; switch (theFormat) { case ModelFormat.BREP: anOpenDialog.InitialDirectory = (aDataDir + "\\occ"); aFormat = 0; aFilter = "BREP Files (*.brep *.rle)|*.brep; *.rle"; break; case ModelFormat.STEP: anOpenDialog.InitialDirectory = (aDataDir + "\\step"); aFormat = 1; aFilter = "STEP Files (*.stp *.step)|*.stp; *.step"; break; case ModelFormat.IGES: anOpenDialog.InitialDirectory = (aDataDir + "\\iges"); aFormat = 2; aFilter = "IGES Files (*.igs *.iges)|*.igs; *.iges"; break; default: break; } anOpenDialog.Filter = aFilter + "|All files (*.*)|*.*"; if (anOpenDialog.ShowDialog () == DialogResult.OK) { string aFileName = anOpenDialog.FileName; if (aFileName == "") { return; } if (!View.TranslateModel (aFileName, aFormat, true)) { MessageBox.Show ("Cann't read this file", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } View.ZoomAllView (); }
public AnimationHeader(byte[] file, int address, uint imageBase, ModelFormat format, Dictionary<int, string> labels) { Model = new NJS_OBJECT(file, (int)(ByteConverter.ToUInt32(file, address) - imageBase), imageBase, format); Animation = new Animation(file, (int)(ByteConverter.ToUInt32(file, address + 4) - imageBase), imageBase, Model.CountAnimated(), labels); }