public TSOFile LoadTSO(string file) { TSOFile tso = new TSOFile(file); tso.ReadAll(); return(tso); }
private void AddMergeTso(string[] files) { foreach (string i in files) { if (Path.GetExtension(files[0]).ToUpper() != ".TSO") { continue; } if (tvMerge.Nodes.Find(i, false).Length == 0) { TreeNode node = tvMerge.Nodes.Add(i); node.Name = i; node.Checked = true; TSOFile tso = new TSOFile(i); tso.ReadAll(); foreach (TSOMesh j in tso.meshes) { TreeNode mesh = node.Nodes.Add(j.Name); mesh.Name = j.Name; mesh.Checked = true; } } } }
private void btnRefresh_Click(object sender, EventArgs e) { try { // 一旦現状を保存 SaveAssign(); // オブジェクト MqoFile mqo = new MqoFile(); mqo.Load(tbMqoFile.Text); lvObjects.Items.Clear(); foreach (MqoObject i in mqo.Objects) { ListViewItem item = lvObjects.Items.Add(i.name); item.Tag = i; string bone; if (Config.Instance.object_bone_map.TryGetValue(i.name, out bone)) { item.SubItems.Add(bone); } else { item.SubItems.Add(""); } } // ボーン構造 TSOFile tso = new TSOFile(tbTsoFileRef.Text); tso.ReadAll(); tvBones.Visible = false; tvBones.Nodes.Clear(); BuildBoneTree(tvBones.Nodes, tso.nodes[0]); tvBones.ExpandAll(); tvBones.Nodes[0].EnsureVisible(); } catch (Exception ex) { Util.ProcessError(ex); } finally { tvBones.Visible = true; } }
private void btnMerge_Click(object sender, EventArgs e) { Color c = tabPage2.BackColor; try { tabPage2.BackColor = Color.Tomato; List <TSOMesh> meshes = new List <TSOMesh>(); Dictionary <string, Pair <TSOMaterial, int> > materialmap = new Dictionary <string, Pair <TSOMaterial, int> >(); Dictionary <string, TSOTex> textures = new Dictionary <string, TSOTex>(); TSOFile last = null; foreach (TreeNode i in tvMerge.Nodes) { TSOFile tso = new TSOFile(i.Text); last = tso; ulong mtls = 0; ulong mask = 1; tso.ReadAll(); foreach (TSOMesh j in tso.meshes) { TreeNode[] found = i.Nodes.Find(j.Name, false); if (found.Length == 0 || !found[0].Checked) { continue; } foreach (TSOSubMesh k in j.sub) { mtls |= 1ul << k.spec; } meshes.Add(j); } foreach (TSOMaterial j in tso.materials) { if ((mask & mtls) != 0) { if (!materialmap.ContainsKey(j.Name)) { Pair <TSOMaterial, int> value = new Pair <TSOMaterial, int>(j, materialmap.Count); materialmap.Add(j.Name, value); if (!textures.ContainsKey(j.ColorTex)) { TSOTex tex = tso.texturemap[j.ColorTex]; textures.Add(tex.Name, tex); } if (!textures.ContainsKey(j.ShadeTex)) { TSOTex tex = tso.texturemap[j.ShadeTex]; textures.Add(tex.Name, tex); } } } mask <<= 1; } } using (FileStream fs = File.OpenWrite(tbMergeTso.Text)) { fs.SetLength(0); List <TSOTex> texlist = new List <TSOTex>(textures.Values); TSOMaterial[] mtllist = new TSOMaterial[materialmap.Count]; foreach (var i in materialmap.Values) { mtllist[i.Second] = i.First; } foreach (TSOMesh i in meshes) { foreach (TSOSubMesh j in i.sub) { TSOMaterial mtl = i.file.materials[j.spec]; j.spec = materialmap[mtl.Name].Second; } } foreach (TSOTex i in texlist) { TSOFile.ExchangeChannel(i.data, i.depth); } BinaryWriter bw = new BinaryWriter(fs); TSOWriter.WriteHeader(bw); TSOWriter.Write(bw, last.nodes); TSOWriter.Write(bw, texlist.ToArray()); TSOWriter.Write(bw, last.effects); TSOWriter.Write(bw, mtllist); TSOWriter.Write(bw, meshes.ToArray()); } } catch (Exception ex) { Util.ProcessError(ex); } finally { tabPage2.BackColor = c; } }
private void OpenTSOFile(string file) { string dir = OutPath; if (cbMakeSub.Checked) { dir = Path.Combine(dir, Path.GetFileNameWithoutExtension(file)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } string mqo_path = Path.Combine(dir, Path.ChangeExtension(Path.GetFileName(file), ".mqo")); string importinfo_path = Path.Combine(dir, Path.ChangeExtension(Path.GetFileName(file), ".xml")); try { label2.BackColor = Color.Tomato; label2.ForeColor = Color.White; label2.Text = "Processing"; label2.Invalidate(); label2.Update(); // モデル、テクスチャの作成 using (MqoWriter mqo = new MqoWriter(mqo_path)) { TSOFile tso = new TSOFile(file); tso.ReadAll(); if (rbBoneRokDeBone.Checked) { mqo.BoneMode = MqoBoneMode.RokDeBone; } mqo.Write(tso); mqo.Close(); ImportInfo ii = new ImportInfo(); // テクスチャ情報 foreach (TSOTex i in tso.textures) { ii.textures.Add(new ImportTextureInfo(i)); } // エフェクトの作成 foreach (TSOEffect i in tso.effects) { ii.effects.Add(new ImportEffectInfo(i)); File.WriteAllText(Path.Combine(dir, i.Name), i.code, Encoding.Default); } // マテリアルの作成 foreach (TSOMaterial i in tso.materials) { ii.materials.Add(new ImportMaterialInfo(i)); File.WriteAllText(Path.Combine(dir, i.Name), i.code, Encoding.Default); } ImportInfo.Save(importinfo_path, ii); } if (cbCopyTSO.Checked) { string tso_path = Path.Combine(dir, Path.GetFileName(file)); if (file != tso_path) { File.Copy(file, tso_path, true); } } } finally { label2.BackColor = SystemColors.Control; label2.BackColor = label2.Parent.BackColor; label2.ForeColor = SystemColors.ControlText; label2.Text = "Drop TSO File Here!"; } }