private void smd_export_show_warnings(RenderBase.OModelGroup model, string fileName, int modelIndex, int skeletalAnimationIndex = -1) { var warnings = SMD.export(model, fileName, modelIndex, skeletalAnimationIndex); foreach (var warning in warnings) { MessageBox.Show(warning, "SMD Exporter", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static void AddService( string method, Dictionary <string, Type> parameters, Dictionary <string, object> defaultValues, Delegate dele, SMD smd) { SMDService smdService = new SMDService(smd.transport, "JSON-RPC-2.0", parameters, defaultValues, dele); smd.Services.Add(method, smdService); }
public static SMD getSMD(System.Data.Common.DbDataReader reader) { SMD SMD = new SMD(); SMD.StoreName = reader.GetString(reader.GetOrdinal("StoreName")); SMD.MD_ = reader.GetString(reader.GetOrdinal("MD#")); SMD.SMDURL = reader.GetString(reader.GetOrdinal("SMDURL")); SMD.SMDPrice = reader.GetInt32(reader.GetOrdinal("SMDPrice")); return(SMD); }
protected override void OnStrategyInit() { Portfolio.Account.Deposit(AllocationPerInstrument, CurrencyId.USD, "Initial allocation"); bars60 = new BarSeries("Bars60"); bars86400 = new BarSeries("Bars86400"); smd30 = new SMD(bars86400, length); lbd = new LookBackDays(smd30, lookBackDays, floorAmt, ceilingAmt); AddGroups(); }
public static void ExportIOModelAsSMD(string FileName, IOModel Model) { SMD file = new SMD(); if (Model.HasSkeleton) { var bonelist = new List <SBBone>(Model.Skeleton.Bones); var frame = new SMDSkeletonFrame(); file.skeleton.Add(frame); frame.time = 0; foreach (var bone in bonelist) { file.nodes.Add(new SMDNode() { Name = bone.Name, ID = bonelist.IndexOf(bone), ParentID = bonelist.IndexOf(bone.Parent) }); frame.skeletons.Add(new SMDSkeleton() { BoneID = bonelist.IndexOf(bone), Position = bone.Translation, Rotation = bone.RotationEuler }); } } if (Model.HasMeshes) { Dictionary <string, int> UniqueMeshNames = new Dictionary <string, int>(); foreach (var mesh in Model.Meshes) { if (!UniqueMeshNames.ContainsKey(mesh.Name)) { UniqueMeshNames.Add(mesh.Name, 0); } string Name = mesh.Name + (UniqueMeshNames[mesh.Name] == 0 ? "" : "_" + UniqueMeshNames[mesh.Name]); UniqueMeshNames[mesh.Name]++; for (int i = 0; i < mesh.Indices.Count; i += 3) { var triangle = new SMDTriangle(); triangle.Material = Name; triangle.vertex1 = IOVertexToSMDVertex(mesh.Vertices[(int)mesh.Indices[i + 0]]); triangle.vertex2 = IOVertexToSMDVertex(mesh.Vertices[(int)mesh.Indices[i + 1]]); triangle.vertex3 = IOVertexToSMDVertex(mesh.Vertices[(int)mesh.Indices[i + 2]]); file.triangles.Add(triangle); } } } file.Save(FileName); }
public void ExportSBAnimation(string FileName, SBAnimation animation, SBSkeleton skeleton) { SMD file = new SMD(); var bonelist = new List <SBBone>(skeleton.Bones); foreach (var bone in bonelist) { file.nodes.Add(new SMDNode() { Name = bone.Name, ID = bonelist.IndexOf(bone), ParentID = bonelist.IndexOf(bone.Parent) }); } for (int i = 0; i < animation.FrameCount; i++) { var group = new SMDSkeletonFrame(); group.time = i; file.skeleton.Add(group); foreach (var bone in bonelist) { bool found = false; foreach (var animbone in animation.TransformNodes) { if (animbone.Name.Equals(bone.Name)) { var tempBone = new SBBone(); tempBone.Transform = animbone.GetTransformAt(i, skeleton); group.skeletons.Add(new SMDSkeleton() { BoneID = bonelist.IndexOf(bone), Position = tempBone.Translation, Rotation = tempBone.RotationEuler }); found = true; break; } } if (!found) { group.skeletons.Add(new SMDSkeleton() { BoneID = bonelist.IndexOf(bone), Position = bone.Translation, Rotation = bone.RotationEuler }); } } } file.Save(FileName); }
public SBAnimation ImportSBAnimation(string FileName, SBSkeleton skeleton) { SMD smd = new SMD(); smd.Open(FileName); SBAnimation animation = new SBAnimation(); animation.Name = Path.GetFileNameWithoutExtension(FileName); Dictionary <int, SBTransformAnimation> idToAnim = new Dictionary <int, SBTransformAnimation>(); foreach (var node in smd.nodes) { var nodeAnim = new SBTransformAnimation() { Name = node.Name }; idToAnim.Add(node.ID, nodeAnim); animation.TransformNodes.Add(nodeAnim); } var frameCount = 0; foreach (var v in smd.skeleton) { frameCount = Math.Max(v.time, frameCount); foreach (var node in v.skeletons) { var animNode = idToAnim[node.BoneID]; animNode.AddKey(v.time, node.Position.X, SBTrackType.TranslateX); animNode.AddKey(v.time, node.Position.Y, SBTrackType.TranslateY); animNode.AddKey(v.time, node.Position.Z, SBTrackType.TranslateZ); animNode.AddKey(v.time, node.Rotation.X, SBTrackType.RotateX); animNode.AddKey(v.time, node.Rotation.Y, SBTrackType.RotateY); animNode.AddKey(v.time, node.Rotation.Z, SBTrackType.RotateZ); } } animation.FrameCount = frameCount; return(animation); }
private void ExportAllAction(object sender, EventArgs args) { OnExpand(); List <string> Formats = new List <string>(); Formats.Add("SMD (.smd)"); Formats.Add("SEANIM (.seanim)"); FolderSelectDialog sfd = new FolderSelectDialog(); if (sfd.ShowDialog() == DialogResult.OK) { string folderPath = sfd.SelectedPath; BatchFormatExport form = new BatchFormatExport(Formats); if (form.ShowDialog() == DialogResult.OK) { foreach (TreeNode node in Nodes) { Console.WriteLine($"node {node}"); if (!(node is IAnimationContainer)) { continue; } var anim = ((IAnimationContainer)node).AnimationController; string name = Path.GetFileNameWithoutExtension(node.Text); if (form.Index == 0) { SMD.Save((STSkeletonAnimation)anim, $"{folderPath}/{name}.smd"); } if (form.Index == 1) { SEANIM.Save((STSkeletonAnimation)anim, $"{folderPath}/{name}.seanim"); } } } } }
public static void ExportSkeletalAnimations(this RenderBase.OModelGroup model_group, int model_index, string out_directory) { var duplicate_anim_name_counters = model_group.skeletalAnimation.GroupBy((v) => v.name).Where(g => g.Count() > 1).Select(g => g.Key).ToDictionary(name => name, name => 0); for (int i = 0; i < model_group.skeletalAnimation.Count; i++) { var anim = model_group.skeletalAnimation[i]; var name = anim.name; if (duplicate_anim_name_counters.ContainsKey(name)) { duplicate_anim_name_counters[name] += 1; name = String.Format("{0} ({1})", name, duplicate_anim_name_counters[name]); } string path = Path.Combine(out_directory, name + ".anim.smd"); Console.WriteLine("Exporting " + path); var warnings = SMD.export(model_group, path, model_index, i); foreach (var warning in warnings) { Console.Error.WriteLine("Warning when exporting " + name + ": " + warning); } } }
public override void OnStrategyStart() { base.OnStrategyStart(); // 测试用,自定义交易时间,仿真或实盘时可删除 base.TimeHelper = new TimeHelper(new int[] { 0, 2400 }, 2100, 1458); base.TargetPosition = 0; base.DualPosition.Long.Qty = 0; base.DualPosition.Short.Qty = 0; bars86400 = GetBars(BarType.Time, 86400); smd30 = new SMD(bars86400, 30); lbd = new LookBackDays(smd30, lookBackDays, floorAmt, ceilingAmt); dbbu = new DynamicBBU(lbd, bars86400, bolBandTrig, BarData.Close); Draw(smd30, 2); Draw(lbd, 3); Draw(dbbu.SMA, 0); Draw(dbbu.BBL, 0); Draw(dbbu, 0); upBandSeries = new TimeSeries("upBandSeries"); dnBandSeries = new TimeSeries("dnBandSeries"); buyPointSeries = new TimeSeries("buyPointSeries"); sellPointSeries = new TimeSeries("sellPointSeries"); upBandSeries.Color = Color.Red; dnBandSeries.Color = Color.Red; Draw(upBandSeries, 0); Draw(dnBandSeries, 0); Draw(buyPointSeries, 0); Draw(sellPointSeries, 0); base.OnStrategyStart(); }
/// <summary> /// Exports a file of a given type. /// Formats available to export will depend on the type of the data. /// </summary> /// <param name="type">Type of the data to be exported</param> /// <param name="data">The data</param> /// <param name="arguments">Optional arguments to be used by the exporter</param> public static void export(FileIO.fileType type, object data, params int[] arguments) { using (SaveFileDialog saveDlg = new SaveFileDialog()) { switch (type) { case FileIO.fileType.model: OModelExportForm exportMdl = new OModelExportForm((RenderBase.OModelGroup)data, arguments[0]); exportMdl.Show(); break; case FileIO.fileType.texture: OTextureExportForm exportTex = new OTextureExportForm((RenderBase.OModelGroup)data, arguments[0]); exportTex.Show(); break; case FileIO.fileType.skeletalAnimation: saveDlg.Title = "Export Skeletal Animation"; saveDlg.Filter = "Source Model|*.smd"; if (saveDlg.ShowDialog() == DialogResult.OK) { switch (saveDlg.FilterIndex) { case 1: var warnings = SMD.export((RenderBase.OModelGroup)data, saveDlg.FileName, arguments[0], arguments[1]); foreach (var warning in warnings) { MessageBox.Show(warning, "SMD Exporter", MessageBoxButtons.OK, MessageBoxIcon.Error); } break; } } break; } } }
private bool create() { if (!File.Exists(TxtInModel.Text)) { return(false); } RenderBase.OModelGroup models; switch (Path.GetExtension(TxtInModel.Text).ToLower()) { case ".obj": models = OBJ.import(TxtInModel.Text); break; case ".smd": models = SMD.import(TxtInModel.Text); break; default: MessageBox.Show("Unsupported model format!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } RenderBase.OModel model = models.model[0]; using (MemoryStream output = new MemoryStream()) { BinaryWriter writer = new BinaryWriter(output); writer.Write((ushort)5); writer.Write((ushort)0xffff); writer.Write((uint)4); writer.Write((uint)0); writer.Write(model.mesh.Count); List <mesh> meshes = new List <mesh>(); foreach (RenderBase.OMesh mesh in model.mesh) { meshes.Add(createMesh(mesh)); } foreach (mesh m in meshes) { //Face writer.Write((uint)1); //Faces count writer.Write(m.descriptor.nodes.Count); foreach (uint n in m.descriptor.nodes) { writer.Write(n); } writer.Write(m.indexBuffer.Length / 2); //Vertex writer.Write(m.descriptor.attributes.Count); foreach (attributeDescriptor att in m.descriptor.attributes) { writer.Write(att.type); writer.Write(att.format); writer.Write(att.scale); } writer.Write(m.vertexBuffer.Length); } align(output); foreach (mesh m in meshes) { writer.Write(m.vertexBuffer); align(output); writer.Write(m.indexBuffer); align(output); } File.WriteAllBytes(TxtOutModel.Text, output.ToArray()); } return(true); }
/// <summary> /// Exports a file of a given type. /// Formats available to export will depend on the type of the data. /// </summary> /// <param name="type">Type of the data to be exported</param> /// <param name="data">The data</param> /// <param name="arguments">Optional arguments to be used by the exporter</param> public static void export(fileType type, object data, params int[] arguments) { string fileName = null; switch (type) { case fileType.container: foreach (OContainer.fileEntry file in ((OContainer)data).content) { Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name); fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((OContainer)data).name, file.name); string dir = Path.GetDirectoryName(fileName); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } byte[] buffer; if (file.loadFromDisk) { buffer = new byte[file.fileLength]; ((OContainer)data).data.Seek(file.fileOffset, SeekOrigin.Begin); ((OContainer)data).data.Read(buffer, 0, buffer.Length); } else { buffer = file.data; } if (file.doDecompression) { buffer = LZSS_Ninty.decompress(buffer); } File.WriteAllBytes(fileName, buffer); Console.WriteLine("Extracted file: " + fileName); } break; case fileType.model: for (int i = 0; i < ((RenderBase.OModelGroup)data).model.Count; i++) { fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[i].name); switch (arguments[0]) { case 0: DAE.export(((RenderBase.OModelGroup)data), fileName + ".dae", i); break; case 1: SMD.export(((RenderBase.OModelGroup)data), fileName + ".smd", i); break; case 2: OBJ.export(((RenderBase.OModelGroup)data), fileName + ".obj", i); break; case 3: CMDL.export(((RenderBase.OModelGroup)data), fileName + ".cmdl", i); break; } Console.WriteLine("Extracted file: " + fileName); } break; case fileType.texture: if (data.GetType().Equals(typeof(RenderBase.OModelGroup))) //if extracting textures from a model { Directory.CreateDirectory(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex"); foreach (RenderBase.OTexture tex in ((RenderBase.OModelGroup)data).texture) { fileName = Path.Combine(System.Environment.CurrentDirectory + "\\" + ((RenderBase.OModelGroup)data).model[0].name + "_tex", tex.name + ".png"); tex.texture.Save(fileName); Console.WriteLine("Extracted file: " + fileName); } } else // not a model { fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OTexture)data).name + ".png"); ((RenderBase.OTexture)data).texture.Save(fileName); Console.WriteLine("Extracted file: " + fileName); } break; case fileType.skeletalAnimation: fileName = Path.Combine(System.Environment.CurrentDirectory, ((RenderBase.OModelGroup)data).model[0].name); SMD.export((RenderBase.OModelGroup)data, fileName, arguments[0], arguments[1]); Console.WriteLine("Extracted file: " + fileName); break; } Console.WriteLine("Extracting files completed!"); }
public override void Export(string FileName) { string ext = Utils.GetExtension(FileName); if (ext == ".bfska") { if (GetResFileU() != null) { SkeletalAnimU.Export(FileName, GetResFileU()); } else { SkeletalAnim.Export(FileName, GetResFile()); } } else if (ext == ".chr0") { STSkeleton skeleton = GetActiveSkeleton(); if (SkeletalAnimU != null) { BrawlboxHelper.FSKAConverter.Fska2Chr0(BfresPlatformConverter.FSKAConvertWiiUToSwitch(SkeletalAnimU), FileName); } else { BrawlboxHelper.FSKAConverter.Fska2Chr0(SkeletalAnim, FileName); } } else if (ext == ".smd") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { SMD.Save(this, skeleton, FileName); } else { throw new Exception("No skeleton found to assign!"); } } else if (ext == ".anim") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { ANIM.CreateANIM(FileName, this, skeleton); } else { throw new Exception("No skeleton found to assign!"); } } else if (ext == ".seanim") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { SEANIM.SaveAnimation(FileName, this, skeleton); } else { throw new Exception("No skeleton found to assign!"); } } else if (ext == ".json") { if (SkeletalAnimU != null) { System.IO.File.WriteAllText(FileName, Newtonsoft.Json.JsonConvert.SerializeObject(SkeletalAnimU, Newtonsoft.Json.Formatting.Indented)); } else { System.IO.File.WriteAllText(FileName, Newtonsoft.Json.JsonConvert.SerializeObject(SkeletalAnim, Newtonsoft.Json.Formatting.Indented)); } } }
private void Open(string infile) { FileAttributes fileAttributes = File.GetAttributes(infile); if (fileAttributes.HasFlag(FileAttributes.Directory)) { if (ModifierKeys == Keys.Control) { AddLine(richTextBox1, $"Building Arc from {Path.GetFileName(infile)}..."); FEArc.PackArc(infile, Alignment, enablePaddingToolStripMenuItem.Checked); AddLine(richTextBox1, "Done"); } else if (ModifierKeys == Keys.Shift) { AddLine(richTextBox1, $"Building BCH from {Path.GetFileName(infile)}..."); if (infile.EndsWith("_")) { infile = infile.Substring(0, infile.Length - "_".Length); } if (File.Exists(infile + ".bch")) { File.Delete(infile + ".bch"); } List <string> files = Directory.GetFiles(infile, "*.*", SearchOption.AllDirectories).ToList(); H3D Scene = new H3D(); Scene.ConverterVersion = 44139; Scene.BackwardCompatibility = 34; Scene.ForwardCompatibility = 35; foreach (string file in files) { Bitmap texture; try { texture = (Bitmap)Bitmap.FromFile(file); } catch (OutOfMemoryException) { Console.WriteLine("invalid image format, skipping"); continue; } Scene.Textures.Add(new H3DTexture(Path.GetFileNameWithoutExtension(file), texture, SPICA.PICA.Commands.PICATextureFormat.RGBA8)); } if (Scene.Textures.Count <= 0) { AddLine(richTextBox1, "Error"); AddLine(richTextBox1, $"No images found in {Path.GetFileName(infile)}"); } else { H3D.Save($"{infile}.bch", Scene); AddLine(richTextBox1, "Done"); } return; } else if (ModifierKeys == Keys.Alt) { AddLine(richTextBox1, $"Building CTPK from {Path.GetFileName(infile)}..."); CTPK.MakeCTPK(infile); AddLine(richTextBox1, "Done"); } else { foreach (string p in (new DirectoryInfo(infile)).GetFiles().Select(f => f.FullName)) { Open(p); } foreach (string p in (new DirectoryInfo(infile)).GetDirectories().Select(f => f.FullName)) { Open(p); } } } else { byte[] data = File.ReadAllBytes(infile); string magic = FEIO.GetMagic(data); string ext = Path.GetExtension(infile); string outpath = ext.Length == 0 ? infile : infile.Replace(ext, ""); if (ModifierKeys == Keys.Control || batchCompressToolStripMenuItem.Checked) // Compression Method { byte[] cmp; if (lZ10CompressionToolStripMenuItem.Checked) { AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz10..."); try { cmp = FEIO.LZ10Compress(data); } catch (Exception ex) { AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}"); return; } File.WriteAllBytes(infile + ".lz", cmp); AddLine(richTextBox1, "Done"); } else if (lZ11ToolStripMenuItem.Checked) { AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz11..."); try { cmp = FEIO.LZ11Compress(data); } catch (Exception ex) { AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}"); return; } File.WriteAllBytes(infile + ".lz", cmp); AddLine(richTextBox1, "Done"); } else if (lZ13ToolStripMenuItem.Checked) { AddLine(richTextBox1, $"Compressing {Path.GetFileName(infile)} to {Path.GetFileName(infile)}.lz using lz13..."); try { cmp = FEIO.LZ13Compress(data); } catch (Exception ex) { AddLine(richTextBox1, $"\nUnable to automatically Compress {Path.GetFileName(infile)}"); return; } File.WriteAllBytes(infile + ".lz", cmp); AddLine(richTextBox1, "Done"); } else { AddLine(richTextBox1, "No Compression Method Selected, How did this even happen?"); } } else if (ext == ".lz" || magic == "Yaz0" || ext == ".cms" || ext == ".cmp") // Decompress Method { byte[] dcmp; if (data[0] == 0x10) { AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz10..."); try { dcmp = FEIO.LZ10Decompress(data); } catch (Exception e) { AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}"); return; } File.WriteAllBytes(infile.Replace(".lz", ""), dcmp); AddLine(richTextBox1, "Done"); } //LZ10 else if (data[0] == 0x11) { AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz11..."); try { dcmp = FEIO.LZ11Decompress(data); } catch (Exception e) { AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}"); return; } File.WriteAllBytes(infile.Replace(".lz", ""), dcmp); AddLine(richTextBox1, "Done"); } //LZ11 else if (data[0] == 0x13 && data[4] == 0x11) { AddLine(richTextBox1, $"Decompressing {Path.GetFileName(infile)} using lz13..."); try { dcmp = FEIO.LZ13Decompress(data); } catch (Exception e) { AddLine(richTextBox1, $"\nUnable to automatically Decompress {Path.GetFileName(infile)}"); return; } File.WriteAllBytes(infile.Replace(".lz", ""), dcmp); AddLine(richTextBox1, "Done"); } //LZ13 else if (magic == "Yaz0") { AddLine(richTextBox1, "Yaz0 Method not implemented"); return; } //Yaz0 if (File.Exists(infile.Replace(".lz", "")) && autoExtractToolStripMenuItem.Checked) { Open(infile.Replace(".lz", "")); } } else if (ext == ".arc") //Archive file { AddLine(richTextBox1, $"Extract Files from {Path.GetFileName(infile)}..."); FEArc.ExtractArc(outpath, data); AddLine(richTextBox1, "Done"); } else if (magic == "BCH" || magic == "CGFX") //BCH / Bcres file { H3D Scene = new H3D(); if (magic == "CGFX") { Scene = Gfx.Open(infile).ToH3D(); } else { Scene = H3D.Open(data); } if (Directory.Exists(outpath)) { Directory.Delete(outpath, true); } if (File.Exists(outpath)) { outpath = outpath + "_"; } //Export method for textures, this is always enabled by default if (Scene.Textures.Count > 0) { AddLine(richTextBox1, $"Extracting Textures from {Path.GetFileName(infile)}..."); if (!Directory.Exists(outpath)) { Directory.CreateDirectory(outpath); } foreach (var texture in Scene.Textures) { Image img = texture.ToBitmap(); img.Save($"{outpath}\\{texture.Name}.png", System.Drawing.Imaging.ImageFormat.Png); } AddLine(richTextBox1, "Done"); } if (exportDaeToolStripMenuItem.Checked || exportSMDToolStripMenuItem.Checked && Scene.Models.Count > 0) { AddLine(richTextBox1, $"Extracting Models from {Path.GetFileName(infile)}..."); if (!Directory.Exists(outpath)) { Directory.CreateDirectory(outpath); } for (int i = 0; i < Scene.Models.Count; i++) { if (exportDaeToolStripMenuItem.Checked) { DAE dae = new DAE(Scene, i); dae.Save($"{outpath}\\{Scene.Models[i].Name}.dae"); } if (exportSMDToolStripMenuItem.Checked) { SMD smd = new SMD(Scene, i); smd.Save($"{outpath}\\{Scene.Models[i].Name}.smd"); } } AddLine(richTextBox1, "Done"); } } else if (magic == "CTPK") //CTPK file { AddLine(richTextBox1, $"Extract Textures from {Path.GetFileName(infile)}..."); CTPK.ExtractCTPK(infile); AddLine(richTextBox1, "Done"); } else if (ext == ".bin") { if (FEIO.ReadStringFromArray(data, Encoding.UTF8, 0x20).Contains("MESS_ARCHIVE")) { AddLine(richTextBox1, $"Extracting Message Archive {Path.GetFileName(infile)}..."); FEMessage.ExtractMessage(infile.Replace(ext, ".txt"), data); AddLine(richTextBox1, "Done"); } else if (enableBinDecomplingToolStripMenuItem.Checked) { AddLine(richTextBox1, $"Decompiling {Path.GetFileName(infile)} to txt..."); FEBin.ExtractBin(infile); AddLine(richTextBox1, "Done"); } } if (deleteAfterProcessingToolStripMenuItem.Checked) { File.Delete(infile); } } }
public override void Export(string FileName) { string ext = Utils.GetExtension(FileName); if (ext == ".bfska") { if (GetResFileU() != null) { SkeletalAnimU.Export(FileName, GetResFileU()); } else { SkeletalAnim.Export(FileName, GetResFile()); } } else if (ext == ".chr0") { STSkeleton skeleton = GetActiveSkeleton(); if (SkeletalAnimU != null) { BrawlboxHelper.FSKAConverter.Fska2Chr0(BfresPlatformConverter.FSKAConvertWiiUToSwitch(SkeletalAnimU), FileName); } else { BrawlboxHelper.FSKAConverter.Fska2Chr0(SkeletalAnim, FileName); } // BrawlboxHelper.FSKAConverter.Fska2Chr0(this, skeleton, FileName); } else if (ext == ".smd") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { SMD.Save(this, skeleton, FileName); } else { throw new Exception("No skeleton found to assign!"); } } else if (ext == ".anim") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { ANIM.CreateANIM(FileName, this, skeleton); } else { throw new Exception("No skeleton found to assign!"); } } else if (ext == ".seanim") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { SEANIM.SaveAnimation(FileName, this, skeleton); } else { throw new Exception("No skeleton found to assign!"); } } }
private void ok() { if (!Directory.Exists(TxtOutFolder.Text)) { MessageBox.Show("Invalid output directory!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } Settings.Default.meOutFolder = TxtOutFolder.Text; int format = 0; if (RadioSMD.Checked) { format = 1; } else if (RadioOBJ.Checked) { format = 2; } else if (RadioCMDL.Checked) { format = 3; } Settings.Default.meFormat = format; Settings.Default.meExportAllMdls = ChkExportAllModels.Checked; Settings.Default.meExportAllAnms = ChkExportAllAnimations.Checked; Settings.Default.Save(); if (ChkExportAllModels.Checked && !ChkExportAllAnimations.Checked) { for (int i = 0; i < mdls.model.Count; i++) { string fileName = Path.Combine(TxtOutFolder.Text, mdls.model[i].name); switch (format) { case 0: DAE.export(mdls, fileName + ".dae", i); break; case 1: SMD.export(mdls, fileName + ".smd", i); break; case 2: OBJ.export(mdls, fileName + ".obj", i); break; case 3: CMDL.export(mdls, fileName + ".cmdl", i); break; } } } else if (mdlIndex > -1) { string fileName = Path.Combine(TxtOutFolder.Text, TxtModelName.Text); switch (format) { case 0: DAE.export(mdls, fileName + ".dae", mdlIndex); break; case 1: SMD.export(mdls, fileName + ".smd", mdlIndex); if (ChkExportAllAnimations.Checked) { for (int i = 0; i < mdls.skeletalAnimation.list.Count; i++) { string name = mdls.skeletalAnimation.list[i].name + ".smd"; SMD.export(mdls, Path.Combine(TxtOutFolder.Text, name), mdlIndex, i); } } break; case 2: OBJ.export(mdls, fileName + ".obj", mdlIndex); break; case 3: CMDL.export(mdls, fileName + ".cmdl", mdlIndex); break; } } Close(); }
protected override void OnStrategyStart() { smd = new SMD(Bars, 30); lookBackDays = new LookBackDays(smd, 20, 20, 60); AddGroups(); }
public void Replace(string FileName, ResFile resFileNX, ResU.ResFile resFileU) { string ext = Utils.GetExtension(FileName); if (ext == ".bfska") { bool IsSwitch = BfresUtilies.IsSubSectionSwitch(FileName); if (resFileU != null) { //If it's a switch animation try to conver it to wii u if (IsSwitch) { var ska = new SkeletalAnim(); ska.Import(FileName); SkeletalAnimU = BfresPlatformConverter.FSKAConvertSwitchToWiiU(ska); SkeletalAnimU.Name = Text; LoadAnim(SkeletalAnimU); } else { SkeletalAnimU.Import(FileName, resFileU); SkeletalAnimU.Name = Text; LoadAnim(SkeletalAnimU); } } else { if (IsSwitch) { SkeletalAnim.Import(FileName); SkeletalAnim.Name = Text; LoadAnim(SkeletalAnim); } else { //Create a new wii u skeletal anim and try to convert it instead var ska = new ResU.SkeletalAnim(); ska.Import(FileName, new ResU.ResFile()); SkeletalAnim = BfresPlatformConverter.FSKAConvertWiiUToSwitch(ska); SkeletalAnim.Name = Text; LoadAnim(SkeletalAnim); } } } else if (ext == ".anim") { FromAnim(FileName); } else if (ext == ".seanim") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { var ska = FromGeneric(SEANIM.Read(FileName, skeleton)); ska.Loop = this.CanLoop; UpdateAnimation(ska); } else { STErrorDialog.Show("No matching skeleton bones found to assign!", "Skeleton Importer", ""); } } else if (ext == ".smd") { STSkeleton skeleton = GetActiveSkeleton(); if (skeleton != null) { var ska = FromGeneric(SMD.Read(FileName, skeleton)); ska.Loop = this.CanLoop; UpdateAnimation(ska); } else { STErrorDialog.Show("No matching skeleton bones found to assign!", "Skeleton Importer", ""); } } else if (ext == ".chr0") { FromChr0(FileName, resFileU != null); } else if (ext == ".dae") { // FromAssimp(FileName, resFileU != null); } else if (ext == ".fbx") { // FromAssimp(FileName, resFileU != null); } }
private void load_materials() { /* * // adds material based on the triangle groups (for this model part) * // this method is wrong, should take all Main.model.materials_List instead, and write the material id (0 ,1, 2 ,3 etc) in the triangle group * if (Main.model.Model_Parts_header_List[20].triangle_groups_List.Count > 0) * { * List<DataFormats.JSRF.MDLB.triangle_group> tg = Main.model.Model_Parts_header_List[20].triangle_groups_List; * * for (int i = 0; i < tg.Count; i++) * { * add_material_inspector(Main.model.materials_List[tg[i].material_ID]); * } * }*/ // load materials list from original model (last part) for (int i = 0; i < Main.current_model.materials_List.Count; i++) { add_material_inspector(Main.current_model.materials_List[i]); } // if model hast materials after triangle groups return; if (Main.current_model.materials_List.Count > 0) { return; } /* * * * int vtx_mat_count = 0; * // TODO * if(Main.model.header.materials_count == 0) * { * List<DataFormats.JSRF.MDLB.material> mats = Main.model.Model_Parts_header_List[Main.model.Model_Parts_header_List.Count - 1].vtx_buffer_materials; * * foreach (var m in mats) * { * vtx_mat_count++; * add_material_inspector(m); * } * * } * */ //int vtx_mat_count = 0; // TODO if (Main.current_model.header.materials_count == 0) { List <DataFormats.JSRF.MDLB.material> mats = Main.current_model.Model_Parts_header_List[Main.current_model.Model_Parts_header_List.Count - 1].vtx_buffer_materials; foreach (var m in mats) { // vtx_mat_count++; add_material_inspector(m); } } // if (vtx_mat_count > 0) { return; } // TODO if Main.model.materials_List.Count == 0 // load materials after vtx_tri_headers #region load materials from SMD // else load materials list from SMD (last part) // if original model doesn't have a materials list after the triangles groups // materials are stored after vertex_triangles_buffers_header // so we get those original materials and try to find matching materials from the SMD mat_id to the original's //List<DataFormats.JSRF.MDLB.material> mat_list_ori = Main.model.Model_Parts_header_List[Main.model.Model_Parts_header_List.Count - 1].vtx_buffer_materials; return; SMD main_smd = new SMD(main_SMD_filepath); DataFormats.JSRF.MDLB.material mat = null; // for each material/triangles group in SMD (last part) file for (int i = 0; i < main_smd.mat_groups_list.Count; i++) { mat = null; // get material number (mat_x) for this material group int mat_num = 0; if (main_smd.mat_groups_list[i].material_name.Contains("mat_")) { string[] args = main_smd.mat_groups_list[i].material_name.Split('_'); if (args.Length > 1) { mat_num = Convert.ToInt32(args[1]); } } /* * // if material number inferior original model materials count * // set material * if(mat_num < mat_list_ori.Count) * { * mat = mat_list_ori[mat_num]; * } */ // if material not found // add generic material if (mat == null) { add_material_inspector(); continue; } // else add corresponding material by id add_material_inspector(mat); } #endregion }
static int Main(string[] args) { string dir, filename; if (HasFlag(args, "/u")) { //Unpack filename = GetArg(args, "/u", null); dir = GetArg(args, "/d", ".\\"); if (File.Exists(filename)) { if (!Directory.Exists(dir)) { PrintError("Directory not found!"); } List <SMD.Section> sections = SMD.GetSections(filename); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Partition name NAND off N size ROM off R size Part. ID Type Status"); Console.ResetColor(); foreach (SMD.Section part in sections) { Console.Write(part.Name.PadRight(17)); Console.Write("{0:X8} {1:X8} {2:X8} {3:X8} ", part.ROMOffset, part.ROMLength, part.FileOffset, part.FileLength); Console.Write("{0:X8} {1:X8} [ .... ]", part.ID, part.FS); if (part.Extract(filename, dir)) { Console.CursorLeft -= 7; Console.ForegroundColor = ConsoleColor.Green; Console.Write(" OK "); Console.ResetColor(); Console.CursorLeft += 1; } else { Console.CursorLeft -= 7; Console.ForegroundColor = ConsoleColor.Red; Console.Write("Failed"); Console.ResetColor(); Console.CursorLeft += 1; } Console.WriteLine(); } return(0); } else { PrintError("SMD file not found!"); return(-1); } } if (HasFlag(args, "/p")) { //Pack filename = GetArg(args, "/p", null); string template = GetArg(args, "/t", null); SMD.Pack(filename, template); return(-1); } if (HasFlag(args, "/info")) { filename = GetArg(args, "/info", null); //Parse header if (File.Exists(filename)) { List <SMD.Section> sections = SMD.GetSections(filename); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Partition name NAND off N size ROM off R size Part. ID Type Status"); Console.ResetColor(); foreach (SMD.Section part in sections) { Console.Write(part.Name.PadRight(17)); Console.Write("{0:X8} {1:X8} {2:X8} {3:X8} ", part.ROMOffset, part.ROMLength, part.FileOffset, part.FileLength); Console.Write("{0:X8} {1:X8} [ .... ]", part.ID, part.FS); if ((part.IsPresent) & (part.FileOffset != 0) & (part.FileLength != 0)) { Console.CursorLeft -= 7; Console.ForegroundColor = ConsoleColor.Green; Console.Write(" OK "); Console.ResetColor(); Console.CursorLeft += 1; } else { Console.CursorLeft -= 7; Console.ForegroundColor = ConsoleColor.Red; Console.Write("NoData"); Console.ResetColor(); Console.CursorLeft += 1; } Console.WriteLine(); } return(0); } else { PrintError("SMD file not found!"); return(-1); } } //Unknown arguments PrintHelp(); return(-1); }
private void buttonImport_Click(object sender, EventArgs e) { SMD smd = new SMD(ModelSrc); DatJOBJ[] Bones = DOBJ.GetRoot().Root.GetJOBJinOrder(); VBN RenderBones = DOBJ.GetRoot().RenderBones; RenderBones.reset(); RenderBones.update(); VBN ImportedBones = smd.Bones; GXAttribGroup AttrGroup = null; if (listBox1.SelectedIndex != -1) { AttrGroup = DOBJ.GetRoot().Root.Attributes[listBox1.SelectedIndex]; } else { MessageBox.Show("Please select an attribute group"); return; } DOBJ.ClearPolygons(null, null); int Flags = 0x8000; if (comboBoxBoneType.SelectedIndex == 0) { MessageBox.Show("Warning: no binds"); } if (comboBoxBoneType.SelectedIndex == 1) { Flags = 0xA001; } if (comboBoxBoneType.SelectedIndex == 2) // Rigged - needs to create bonelist { Flags = 0xA001; } DatPolygon p = new DatPolygon(); p.AttributeGroup = AttrGroup; p.Flags = Flags; p.ParentDOBJ = DOBJ.DOBJ; DOBJ.VertsToImport = new List <GXVertex[]>(); List <GXVertex> vert = new List <GXVertex>(); DatJOBJ parent = DOBJ.DOBJ.Parent; if (comboBoxBoneType.SelectedIndex == 1) { ImportedBones = RenderBones; } foreach (SMDTriangle t in smd.Triangles) { if (comboBoxBoneType.SelectedIndex == 1) { // single bind t.v1.Bones = new int[] { CBBone.SelectedIndex }; t.v1.Weights = new float[] { 1 }; t.v2.Bones = new int[] { CBBone.SelectedIndex }; t.v2.Weights = new float[] { 1 }; t.v3.Bones = new int[] { CBBone.SelectedIndex }; t.v3.Weights = new float[] { 1 }; } List <DatBoneWeight> bwl1 = CreateWeightList(t.v1.Bones, t.v1.Weights, Bones, ImportedBones); List <DatBoneWeight> bwl2 = CreateWeightList(t.v2.Bones, t.v2.Weights, Bones, ImportedBones); List <DatBoneWeight> bwl3 = CreateWeightList(t.v3.Bones, t.v3.Weights, Bones, ImportedBones); int bid1 = GetWeightListIndex(p.BoneWeightList, bwl1); int bid2 = GetWeightListIndex(p.BoneWeightList, bwl2); int bid3 = GetWeightListIndex(p.BoneWeightList, bwl3); int wc = p.BoneWeightList.Count; if (bid1 == -1) { wc++; } if (bid2 == -1) { wc++; } if (bid3 == -1) { wc++; } if (wc >= 10) // need new polygon { DOBJ.VertsToImport.Add(vert.ToArray()); vert.Clear(); p = new DatPolygon(); p.AttributeGroup = AttrGroup; p.Flags = Flags; p.ParentDOBJ = DOBJ.DOBJ; } bid1 = GetWeightListIndex(p.BoneWeightList, bwl1); bid2 = GetWeightListIndex(p.BoneWeightList, bwl2); bid3 = GetWeightListIndex(p.BoneWeightList, bwl3); if (bid1 == -1) { p.BoneWeightList.Add(bwl1); } if (bid2 == -1) { p.BoneWeightList.Add(bwl2); } if (bid3 == -1) { p.BoneWeightList.Add(bwl3); } bid1 = GetWeightListIndex(p.BoneWeightList, bwl1); bid2 = GetWeightListIndex(p.BoneWeightList, bwl2); bid3 = GetWeightListIndex(p.BoneWeightList, bwl3); GXVertex v = SMDVertexToGXVertex(t.v1); v.PMXID = GetWeightListIndex(p.BoneWeightList, bwl1); RigVertex(ref v, RenderBones, p.BoneWeightList[v.PMXID / 3], Bones, parent); GXVertex v2 = SMDVertexToGXVertex(t.v2); v2.PMXID = GetWeightListIndex(p.BoneWeightList, CreateWeightList(t.v2.Bones, t.v2.Weights, Bones, ImportedBones)); RigVertex(ref v2, RenderBones, p.BoneWeightList[v2.PMXID / 3], Bones, parent); GXVertex v3 = SMDVertexToGXVertex(t.v3); v3.PMXID = GetWeightListIndex(p.BoneWeightList, CreateWeightList(t.v3.Bones, t.v3.Weights, Bones, ImportedBones)); RigVertex(ref v3, RenderBones, p.BoneWeightList[v3.PMXID / 3], Bones, parent); vert.Add(v); vert.Add(v2); vert.Add(v3); } DOBJ.VertsToImport.Add(vert.ToArray()); exitStatus = ExitStatus.Opened; Close(); }