OSDN Git Service

assign relative path for shade tex
[tdcgexplorer/tso2mqo.git] / MqoGenerator.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.Text;\r
4 using System.IO;\r
5 \r
6 namespace Tso2MqoGui\r
7 {\r
8     public class MqoGenerator\r
9     {\r
10         public void Generate(string tso_file, string out_path, MqoBoneMode bone_mode)\r
11         {\r
12             string tso_filename = Path.GetFileName(tso_file);\r
13             string mqo_file = Path.Combine(out_path, Path.ChangeExtension(tso_filename, ".mqo"));\r
14             string xml_file = Path.Combine(out_path, Path.ChangeExtension(tso_filename, ".xml"));\r
15 \r
16             // モデル、テクスチャの作成\r
17             using (MqoWriter mqo = new MqoWriter(mqo_file))\r
18             {\r
19                 TSOFile tso = new TSOFile(tso_file);\r
20                 tso.ReadAll();\r
21 \r
22                 mqo.BoneMode = bone_mode;\r
23 \r
24                 mqo.Write(tso);\r
25                 mqo.Close();\r
26 \r
27                 ImportInfo ii = new ImportInfo();\r
28 \r
29                 // テクスチャ情報\r
30                 foreach (TSOTex tex in tso.textures)\r
31                     ii.textures.Add(new ImportTextureInfo(tex));\r
32 \r
33                 // エフェクトの作成\r
34                 foreach (TSOEffect effect in tso.effects)\r
35                 {\r
36                     ii.effects.Add(new ImportEffectInfo(effect));\r
37                     File.WriteAllText(Path.Combine(out_path, effect.Name), effect.code, Encoding.Default);\r
38                 }\r
39 \r
40                 // マテリアルの作成\r
41                 foreach (TSOMaterial mat in tso.materials)\r
42                 {\r
43                     ii.materials.Add(new ImportMaterialInfo(mat));\r
44                     File.WriteAllText(Path.Combine(out_path, mat.Name), mat.code, Encoding.Default);\r
45                 }\r
46 \r
47                 ImportInfo.Save(xml_file, ii);\r
48             }\r
49         }\r
50     }\r
51 }\r