public TMOFile CreateTmo(TMOAnimItem item) { TMOFile tmo = new TMOFile(); if (item == null) { return(tmo); } string png_file = item.GetPngPath(); string tmo_file = item.GetTmoPath(); if (File.Exists(png_file)) { Console.WriteLine("Load File: " + png_file); tmo = LoadPNGFile(png_file); } else if (File.Exists(tmo_file)) { Console.WriteLine("Load File: " + tmo_file); tmo.Load(tmo_file); } tmo.TruncateFrame(0); // forced pose return(tmo); }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("TMOVise.exe <tmo file>"); return; } string source_file = args[0]; TMOFile tmo = new TMOFile(); tmo.Load(source_file); TMOConstraint constraint = TMOConstraint.Load(@"angle-GRABIA-xyz.xml"); foreach (TMONode node in tmo.nodes) { TMOMat mat = node.matrices[0]; string name = node.Name; Vector3 scaling; Vector3 translation = TMOMat.DecomposeMatrix(ref mat.m, out scaling); Vector3 angle = TMOMat.ToAngleXYZ(mat.m); TMOConstraintItem item = constraint.GetItem(name); if (angle.X < item.Min.X) { angle.X = item.Min.X; } if (angle.X > item.Max.X) { angle.X = item.Max.X; } if (angle.Y < item.Min.Y) { angle.Y = item.Min.Y; } if (angle.Y > item.Max.Y) { angle.Y = item.Max.Y; } if (angle.Z < item.Min.Z) { angle.Z = item.Min.Z; } if (angle.Z > item.Max.Z) { angle.Z = item.Max.Z; } Quaternion q = TMOMat.ToQuaternionXYZ(angle); mat.m = Matrix.Scaling(scaling) * Matrix.RotationQuaternion(q) * Matrix.Translation(translation); } tmo.Save(@"out.tmo"); }
public Program(string defo_file, string prop_file) { tmo_defo = new TMOFile(); tmo_defo.Load(defo_file); tmo_prop = new TMOFile(); tmo_prop.Load(prop_file); nodes_length = tmo_defo.nodes.Length; Debug.Assert(nodes_length == tmo_prop.nodes.Length, "nodes length mismatch between base_a and base_b."); tmo_defo.LoadTransformationMatrixFromFrame(0); tmo_prop.LoadTransformationMatrixFromFrame(0); }
public bool Process(string source_file) { TMOFile tmo = new TMOFile(); tmo.Load(source_file); if (tmo.nodes[0].Path == "|W_Hips") { tmo_Transform(tmo); } string dest_file = source_file + ".tmp"; Console.WriteLine("Save File: " + dest_file); tmo.Save(dest_file); File.Delete(source_file); File.Move(dest_file, source_file); Console.WriteLine("updated " + source_file); return(true); }
public static TMOFile LoadPNGFile(string source_file) { TMOFile tmo = new TMOFile(); if (File.Exists(source_file)) { try { PNGFile png = new PNGFile(); png.Ftmo += delegate(Stream dest, int extract_length) { tmo.Load(dest); }; png.Load(source_file); } catch (Exception ex) { Console.WriteLine("Error: " + ex); } } return(tmo); }
public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("TMOFlip.exe <tmo file>"); return; } string source_file = args[0]; TMOFile tmo = new TMOFile(); tmo.Load(source_file); TDCG.TMOFlip.TMOFlipProcessor processor = new TDCG.TMOFlip.TMOFlipProcessor(); processor.Process(tmo); string dest_path = Path.GetDirectoryName(source_file); string dest_file = Path.GetFileNameWithoutExtension(source_file) + @".new.tmo"; dest_path = Path.Combine(dest_path, dest_file); Console.WriteLine("Save File: " + dest_path); tmo.Save(dest_path); }
public bool Process(string source_file) { List <TSOFigure> fig_list = new List <TSOFigure>(); Console.WriteLine("Load File: " + source_file); PNGFile source = new PNGFile(); string source_type = ""; try { TSOFigure fig = null; TMOFile tmo = null; source.Hsav += delegate(string type) { source_type = type; fig = new TSOFigure(); fig_list.Add(fig); }; source.Pose += delegate(string type) { source_type = type; }; source.Scne += delegate(string type) { source_type = type; }; source.Cami += delegate(Stream dest, int extract_length) { cami = new byte[extract_length]; dest.Read(cami, 0, extract_length); }; source.Lgta += delegate(Stream dest, int extract_length) { byte[] lgta = new byte[extract_length]; dest.Read(lgta, 0, extract_length); fig = new TSOFigure(); fig.lgta = lgta; fig_list.Add(fig); }; source.Ftmo += delegate(Stream dest, int extract_length) { tmo = new TMOFile(); tmo.Load(dest); fig.tmo = tmo; }; source.Figu += delegate(Stream dest, int extract_length) { byte[] figu = new byte[extract_length]; dest.Read(figu, 0, extract_length); fig.figu = figu; }; source.Ftso += delegate(Stream dest, int extract_length, byte[] opt1) { byte[] ftso = new byte[extract_length]; dest.Read(ftso, 0, extract_length); TSOData tso = new TSOData(); tso.opt1 = BitConverter.ToUInt32(opt1, 0); tso.ftso = ftso; fig.TSOList.Add(tso); }; source.Load(source_file); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } foreach (TSOFigure fig in fig_list) { TSOFigureList.Add(fig); } TDCG.TMOFlip.TMOFlipProcessor processor = new TDCG.TMOFlip.TMOFlipProcessor(); foreach (TSOFigure fig in TSOFigureList) { if (fig.tmo != null) { if (fig.tmo.nodes[0].Path == "|W_Hips") { processor.Process(fig.tmo); } } } string dest_path = Path.GetDirectoryName(source_file); string dest_file = Path.GetFileNameWithoutExtension(source_file) + @".new.png"; Console.WriteLine("Save File: " + dest_file); source.WriteTaOb += delegate(BinaryWriter bw) { PNGWriter pw = new PNGWriter(bw); switch (source_type) { case "HSAV": WriteHsav(pw); break; case "POSE": WritePose(pw); break; case "SCNE": WriteScne(pw); break; } }; source.Save(dest_file); return(true); }
public static void Main(string[] args) { if (args.Length < 2) { Console.WriteLine("TSODeform.exe <tso file> <tmo file> [fig file]"); return; } string tso_file = args[0]; string tmo_file = args[1]; string fig_file = null; if (args.Length > 2) { fig_file = args[2]; } TSOFile tso = new TSOFile(); tso.Load(tso_file); TMOFile tmo = new TMOFile(); tmo.Load(tmo_file); Figure fig = new Figure(); fig.TSOList.Add(tso); fig.Tmo = tmo; if (fig_file != null) { List <float> ratios = ReadFloats(fig_file); /* * ◆FIGU * スライダの位置。値は float型で 0.0 .. 1.0 * 0: 姉妹 * 1: うで * 2: あし * 3: 胴まわり * 4: おっぱい * 5: つり目たれ目 * 6: やわらか */ fig.slider_matrix.TallRatio = ratios[0]; fig.slider_matrix.ArmRatio = ratios[1]; fig.slider_matrix.LegRatio = ratios[2]; fig.slider_matrix.WaistRatio = ratios[3]; fig.slider_matrix.BustRatio = ratios[4]; fig.slider_matrix.EyeRatio = ratios[5]; } fig.UpdateNodeMap(); if (fig_file != null) { fig.UpdateBoneMatrices(true); } else { fig.UpdateBoneMatricesWithoutSlider(true); } foreach (TSOMesh mesh in tso.meshes) { foreach (TSOSubMesh sub in mesh.sub_meshes) { Matrix[] clipped_boneMatrices = fig.ClipBoneMatrices(sub); for (int i = 0; i < sub.vertices.Length; i++) { CalcSkindeform(ref sub.vertices[i], clipped_boneMatrices); } } } foreach (TSONode tso_node in tso.nodes) { TMONode tmo_node; if (fig.nodemap.TryGetValue(tso_node, out tmo_node)) { tso_node.TransformationMatrix = tmo_node.matrices[0].m; } } tso.Save(@"out.tso"); }
private void bwCompress_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; Encrypter encrypter = new Encrypter(); encrypter.SourcePath = @"."; Dictionary <string, TAHEntry> entries = new Dictionary <string, TAHEntry>(); foreach (TAHEntry entry in decrypter.Entries) { string file_name = entry.file_name; if (entry.flag % 2 == 1) { file_name += TAHFileUtils.GetExtensionFromMagic(decrypter.ExtractResource(entry)); } string ext = Path.GetExtension(file_name).ToLower(); if (ext == ".tmo") { string true_file_name = Path.Combine(encrypter.SourcePath, file_name.Replace("/", @"\")); entries[true_file_name] = entry; encrypter.Add(true_file_name); } else if (ext == ".png") { string true_file_name = Path.Combine(encrypter.SourcePath, file_name.Replace("/", @"\")); entries[true_file_name] = entry; encrypter.Add(true_file_name); } } int entries_count = encrypter.Count; int current_index = 0; encrypter.GetFileEntryStream = delegate(string true_file_name) { Console.WriteLine("compressing {0}", true_file_name); TAHEntry entry = entries[true_file_name]; string ext = Path.GetExtension(true_file_name).ToLower(); Stream ret_stream = null; if (ext == ".tmo") { TMOFile tmo = new TMOFile(); MemoryStream tmo_stream = new MemoryStream(decrypter.ExtractResource(entry)); tmo.Load(tmo_stream); if (tmo.nodes[0].Path == "|W_Hips") { tmo_Transform(tmo); tmo_stream.Seek(0, SeekOrigin.Begin); tmo.Save(tmo_stream); } tmo_stream.Seek(0, SeekOrigin.Begin); ret_stream = tmo_stream; } else if (ext == ".png") { MemoryStream png_stream = new MemoryStream(decrypter.ExtractResource(entry)); ret_stream = new MemoryStream(); Process(png_stream, ret_stream); ret_stream.Seek(0, SeekOrigin.Begin); } current_index++; int percent = current_index * 100 / entries_count; worker.ReportProgress(percent); return(ret_stream); }; encrypter.Save(@"tmo-" + Path.GetFileName(source_file)); }
public bool Process(Stream png_stream, Stream ret_stream) { List <TSOFigure> fig_list = new List <TSOFigure>(); PNGFile png = new PNGFile(); string source_type = ""; { TSOFigure fig = null; TMOFile tmo = null; png.Hsav += delegate(string type) { source_type = type; fig = new TSOFigure(); fig_list.Add(fig); }; png.Pose += delegate(string type) { source_type = type; }; png.Scne += delegate(string type) { source_type = type; }; png.Cami += delegate(Stream dest, int extract_length) { cami = new byte[extract_length]; dest.Read(cami, 0, extract_length); }; png.Lgta += delegate(Stream dest, int extract_length) { byte[] lgta = new byte[extract_length]; dest.Read(lgta, 0, extract_length); fig = new TSOFigure(); fig.lgta = lgta; fig_list.Add(fig); }; png.Ftmo += delegate(Stream dest, int extract_length) { tmo = new TMOFile(); tmo.Load(dest); if (fig == null) { source_type = "PTMO"; fig = new TSOFigure(); fig.lgta = null; fig_list.Add(fig); } fig.tmo = tmo; }; png.Figu += delegate(Stream dest, int extract_length) { byte[] figu = new byte[extract_length]; dest.Read(figu, 0, extract_length); fig.figu = figu; }; png.Ftso += delegate(Stream dest, int extract_length, byte[] opt1) { byte[] ftso = new byte[extract_length]; dest.Read(ftso, 0, extract_length); TSOData tso = new TSOData(); tso.opt1 = BitConverter.ToUInt32(opt1, 0); tso.ftso = ftso; fig.TSOList.Add(tso); }; png.Load(png_stream); png_stream.Close(); } foreach (TSOFigure fig in fig_list) { TSOFigureList.Add(fig); } foreach (TSOFigure fig in TSOFigureList) { if (fig.tmo != null) { if (fig.tmo.nodes[0].Path == "|W_Hips") { tmo_Transform(fig.tmo); } } } png.WriteTaOb += delegate(BinaryWriter bw) { PNGWriter pw = new PNGWriter(bw); switch (source_type) { case "HSAV": WriteHsav(pw); break; case "POSE": WritePose(pw); break; case "SCNE": WriteScne(pw); break; case "PTMO": WritePtmo(pw); break; } }; png.Save(ret_stream); TSOFigureList.Clear(); return(true); }
public bool CopyNode(string source_file, string motion_file, string node_name) { List <TSOFigure> fig_list = new List <TSOFigure>(); Console.WriteLine("Load File: " + source_file); PNGFile source = new PNGFile(); string source_type = ""; try { TSOFigure fig = null; TMOFile tmo = null; source.Hsav += delegate(string type) { source_type = type; fig = new TSOFigure(); fig_list.Add(fig); }; source.Pose += delegate(string type) { source_type = type; }; source.Scne += delegate(string type) { source_type = type; }; source.Cami += delegate(Stream dest, int extract_length) { cami = new byte[extract_length]; dest.Read(cami, 0, extract_length); }; source.Lgta += delegate(Stream dest, int extract_length) { byte[] lgta = new byte[extract_length]; dest.Read(lgta, 0, extract_length); fig = new TSOFigure(); fig.lgta = lgta; fig_list.Add(fig); }; source.Ftmo += delegate(Stream dest, int extract_length) { tmo = new TMOFile(); tmo.Load(dest); fig.tmo = tmo; }; source.Figu += delegate(Stream dest, int extract_length) { byte[] figu = new byte[extract_length]; dest.Read(figu, 0, extract_length); fig.figu = figu; }; source.Ftso += delegate(Stream dest, int extract_length, byte[] opt1) { byte[] ftso = new byte[extract_length]; dest.Read(ftso, 0, extract_length); TSOData tso = new TSOData(); tso.opt1 = BitConverter.ToUInt32(opt1, 0); tso.ftso = ftso; fig.TSOList.Add(tso); }; source.Load(source_file); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } foreach (TSOFigure fig in fig_list) { TSOFigureList.Add(fig); } Console.WriteLine("Load File: " + motion_file); PNGFile motion = new PNGFile(); TMOFile motion_tmo = null; try { motion.Ftmo += delegate(Stream dest, int extract_length) { motion_tmo = new TMOFile(); motion_tmo.Load(dest); }; motion.Load(motion_file); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } if (motion_tmo != null) { foreach (TSOFigure fig in TSOFigureList) { if (fig.tmo != null) { fig.tmo.CopyNodeFrom(motion_tmo, node_name); } } } string dest_file = source_file + ".tmp"; Console.WriteLine("Save File: " + dest_file); source.WriteTaOb += delegate(BinaryWriter bw) { PNGWriter pw = new PNGWriter(bw); switch (source_type) { case "HSAV": WriteHsav(pw); break; case "POSE": WritePose(pw); break; case "SCNE": WriteScne(pw); break; } }; source.Save(dest_file); File.Delete(source_file); File.Move(dest_file, source_file); Console.WriteLine("updated " + source_file); return(true); }