Пример #1
0
 public static void Save(string file, ImportInfo ii)
 {
     using (FileStream fs = File.OpenWrite(file))
     {
         fs.SetLength(0);
         new XmlSerializer(Type).Serialize(fs, ii);
     }
 }
Пример #2
0
        bool DoLoadXml(string importinfo_file)
        {
            // XML読み込み
            ii = ImportInfo.Load(importinfo_file);

            // 使用マテリアル一覧取得
            materials = new Dictionary <string, MaterialInfo>();
            bool validmap = true;

            foreach (MqoMaterial i in mqo.Materials)
            {
                MaterialInfo mi = new MaterialInfo(dir, i, ii.GetMaterial(i.name));
                validmap &= mi.Valid;
                materials.Add(i.name, mi);
            }

            if (!validmap || config.ShowMaterials)
            {
                if (config.cui)
                {
                    throw new Exception("マテリアルの設定が無効です");
                }

                FormMaterial dlg = new FormMaterial();
                dlg.materials = materials;

                if (dlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                {
                    return(false);
                }
            }

            // 使用テクスチャ一覧の取得
            textures = new Dictionary <string, TextureInfo>();

            foreach (MaterialInfo i in materials.Values)
            {
                string color_tex_name = Path.GetFileNameWithoutExtension(i.ColorTexture);

                if (color_tex_name != null && !textures.ContainsKey(color_tex_name))
                {
                    textures.Add(color_tex_name, new TextureInfo(color_tex_name, i.ColorTexture));
                }

                string shade_tex_name = Path.GetFileNameWithoutExtension(i.ShadeTexture);

                if (shade_tex_name != null && !textures.ContainsKey(shade_tex_name))
                {
                    textures.Add(shade_tex_name, new TextureInfo(shade_tex_name, i.ShadeTexture));
                }
            }

            return(true);
        }
Пример #3
0
        protected virtual bool DoCleanup()
        {
            dir       = null;
            tsoref    = null;
            meshes    = null;
            mqo       = null;
            ii        = null;
            bw        = null;
            materials = null;
            textures  = null;

            System.GC.Collect();
            return(true);
        }
Пример #4
0
        public void Generate(string tso_file, string out_path, bool mqx_enabled)
        {
            string tso_filename = Path.GetFileName(tso_file);
            string mqo_file     = Path.Combine(out_path, Path.ChangeExtension(tso_filename, ".mqo"));
            string xml_file     = Path.Combine(out_path, Path.ChangeExtension(tso_filename, ".xml"));

            // モデル、テクスチャの作成
            using (MqoWriter mqo = new MqoWriter(mqo_file))
            {
                TSOFile tso = LoadTSO(tso_file);
                tso.SwitchBoneIndicesOnMesh();

                mqo.MqxEnabled = mqx_enabled;

                mqo.Write(tso);
                mqo.Close();

                ImportInfo ii = new ImportInfo();

                // テクスチャ情報
                foreach (TSOTex tex in tso.textures)
                {
                    ii.textures.Add(new ImportTextureInfo(tex));
                }

                // エフェクトの作成
                foreach (TSOEffect effect in tso.effects)
                {
                    ii.effects.Add(new ImportEffectInfo(effect));
                    File.WriteAllText(Path.Combine(out_path, effect.Name), effect.code, Encoding.Default);
                }

                // マテリアルの作成
                foreach (TSOMaterial mat in tso.materials)
                {
                    ii.materials.Add(new ImportMaterialInfo(mat));
                    File.WriteAllText(Path.Combine(out_path, mat.Name), mat.code, Encoding.Default);
                }

                ImportInfo.Save(xml_file, ii);
            }
        }
Пример #5
0
        public override void PostLoad(ImportInfo owner)
        {
            base.PostLoad(owner);

            string dir      = Path.GetDirectoryName(owner.filename);
            string codefile = Path.Combine(dir, Name);

            if (System.IO.File.Exists(codefile))
            {
                TSOMaterialCode code = TSOMaterialCode.GenerateFromFile(codefile);
                TSOParameter    p;

                if (code.TryGetValue("ColorTex", out p))
                {
                    color = owner.GetTexture(p.Value);
                }

                if (code.TryGetValue("ShadeTex", out p))
                {
                    shadow = owner.GetTexture(p.Value);
                }
            }
        }
Пример #6
0
 bool DoSaveXml(string importinfo_file)
 {
     // 結果を保存しておく
     ImportInfo.Save(importinfo_file, ii);
     return(true);
 }
Пример #7
0
 public virtual void PostLoad(ImportInfo owner)
 {
     this.Owner = owner;
 }
Пример #8
0
        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!";
            }
        }