Example #1
0
        public TSOFile LoadTSO(string file)
        {
            TSOFile tso = new TSOFile();

            tso.Load(file);
            return(tso);
        }
Example #2
0
        private void AddMergeTso(string[] files)
        {
            foreach (string file in files)
            {
                if (Path.GetExtension(files[0]).ToUpper() != ".TSO")
                {
                    continue;
                }

                if (tvMerge.Nodes.Find(file, false).Length == 0)
                {
                    TreeNode node = tvMerge.Nodes.Add(file);
                    node.Name    = file;
                    node.Checked = true;

                    TSOFile tso = new TSOFile();
                    tso.Load(file);

                    foreach (TSOMesh j in tso.meshes)
                    {
                        TreeNode mesh = node.Nodes.Add(j.Name);
                        mesh.Name    = j.Name;
                        mesh.Checked = true;
                    }
                }
            }
        }
Example #3
0
        private void btnRefresh_Click(object sender, EventArgs e)
        {
            try
            {
                // 一旦現状を保存
                SaveAssign();

                // オブジェクト
                MqoReader mqo = new MqoReader();
                mqo.Load(tbMqoFile.Text);

                lvObjects.Items.Clear();
                foreach (MqoObject obj in mqo.Objects)
                {
                    ListViewItem item = lvObjects.Items.Add(obj.name);
                    item.Tag = obj;
                    string bone;

                    if (Config.Instance.object_bone_map.TryGetValue(obj.name, out bone))
                    {
                        item.SubItems.Add(bone);
                    }
                    else
                    {
                        item.SubItems.Add("");
                    }
                }

                // ボーン構造
                TSOFile tso = new TSOFile();
                tso.Load(tbTsoFileRef.Text);
                tvBones.Visible = false;
                tvBones.Nodes.Clear();
                BuildBoneTree(tvBones.Nodes, tso.nodes[0]);
                tvBones.ExpandAll();
                tvBones.Nodes[0].EnsureVisible();
            }
            catch (Exception exception)
            {
                Util.ProcessError(exception);
            }
            finally
            {
                tvBones.Visible = true;
            }
        }
Example #4
0
        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, KeyValuePair <TSOMaterial, int> > materialmap = new Dictionary <string, KeyValuePair <TSOMaterial, int> >();
                Dictionary <string, TSOTex> textures = new Dictionary <string, TSOTex>();
                TSOFile last = null;

                foreach (TreeNode node in tvMerge.Nodes)
                {
                    TSOFile tso = new TSOFile();
                    last = tso;
                    ulong mtls = 0;
                    ulong mask = 1;
                    tso.Load(node.Text);

                    foreach (TSOMesh mesh in tso.meshes)
                    {
                        TreeNode[] found = node.Nodes.Find(mesh.Name, false);

                        if (found.Length == 0 || !found[0].Checked)
                        {
                            continue;
                        }

                        foreach (TSOSubMesh k in mesh.sub_meshes)
                        {
                            mtls |= 1ul << k.spec;
                        }

                        meshes.Add(mesh);
                    }

                    foreach (TSOMaterial mat in tso.materials)
                    {
                        if ((mask & mtls) != 0)
                        {
                            if (!materialmap.ContainsKey(mat.Name))
                            {
                                materialmap.Add(mat.Name, new KeyValuePair <TSOMaterial, int>(mat, materialmap.Count));

                                if (!textures.ContainsKey(mat.ColorTex))
                                {
                                    TSOTex tex = tso.texturemap[mat.ColorTex];
                                    textures.Add(tex.Name, tex);
                                }

                                if (!textures.ContainsKey(mat.ShadeTex))
                                {
                                    TSOTex tex = tso.texturemap[mat.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.Value] = i.Key;
                    }

                    foreach (TSOMesh mesh in meshes)
                    {
                        foreach (TSOSubMesh sub in mesh.sub_meshes)
                        {
                            TSOMaterial spec = mesh.file.materials[sub.spec];
                            sub.spec = materialmap[spec.Name].Value;
                        }
                    }

                    foreach (TSOTex tex in texlist)
                    {
                        TSOFile.ExchangeChannel(tex.data, tex.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 exception)
            {
                Util.ProcessError(exception);
            }
            finally
            {
                tabPage2.BackColor = c;
            }
        }