private void ExportMTL(string filename, ModelFile model) { var dir = Path.GetDirectoryName(filename); using(var w = new StreamWriter(filename, false, Encoding.Default)) { foreach(var i in model.Materials) { var maintex = GetTexFile(i.GetAs<ParamTex>("_MainTex")); var col = i.GetAs<ParamCol>("_Color"); var shine = i.GetAs<ParamF>("_Shininess"); if(null == col) col = new ParamCol() { R= 1, G= 1, B= 1 }; w.WriteLine("newmtl {0}", i.Descriptions[0]); w.WriteLine(" Ns {0:F8}", 10.0000f); w.WriteLine(" Ni {0:F8}", 1.5000f); w.WriteLine(" d {0:F8}", 1.0000f); w.WriteLine(" Tr {0:F8}", 0.0000f); w.WriteLine(" Tf {0:F8} {1:F8} {2:F8}", 1.0000f, 1.0000f, 1.0000f); w.WriteLine(" illum {0}", 2); w.WriteLine(" Ka {0:F8} {1:F8} {2:F8}", col.R, col.G, col.B); w.WriteLine(" Kd {0:F8} {1:F8} {2:F8}", 0.50f, 0.50f, 0.50f); w.WriteLine(" Ks {0:F8} {1:F8} {2:F8}", 0.00f, 0.00f, 0.00f); w.WriteLine(" Ke {0:F8} {1:F8} {2:F8}", 0.00f, 0.00f, 0.00f); if(null != maintex) { var texname = Path.GetFileName(maintex.AssetPath); maintex.GetImage().Save(Path.Combine(dir, texname)); //w.WriteLine(" map_Ka {0}", texname); //w.WriteLine(" map_Kd {0}", texname); w.WriteLine(" map_Ka {0}", Path.Combine(dir, texname)); w.WriteLine(" map_Kd {0}", Path.Combine(dir, texname)); } } } }
private void ExportOBJMTL() { if(null == data) return; var file = Path.ChangeExtension(data.FileName, ".mtl"); var dir = Path.GetDirectoryName(file); using(var w = new StreamWriter(file, false, Encoding.Default)) { foreach(var i in data.Materials) { var maintex = GetTexFile(i.GetAs<ParamTex>("_MainTex")); var col = i.GetAs<ParamCol>("_Color"); var shine = i.GetAs<ParamF>("_Shininess"); if(null == col) col = new ParamCol() { R= 1, G= 1, B= 1 }; /* Description: "Mizugi001" "CM3D2/Toony_Lighted_Outline" "CM3D2__Toony_Lighted_Outline" Params: _MainTex : texture SubType: tex2d TexName: Mizugi001 TexAsset: Assets/texture/texture/dress/mizugi/mizugi001/Mizugi001.png Color: 0.0000, 0.0000, 1.0000, 1.0000 _ToonRamp : texture SubType: tex2d TexName: toonBlueA1 TexAsset: Assets/texture/texture/toon/toonBlueA1.png Color: 0.0000, 0.0000, 1.0000, 1.0000 _ShadowTex : texture SubType: tex2d TexName: Mizugi001_shadow TexAsset: Assets/texture/texture/dress/mizugi/mizugi001/Mizugi001_shadow.png Color: 0.0000, 0.0000, 1.0000, 1.0000 _ShadowRateToon : texture SubType: tex2d TexName: toonDress_shadow TexAsset: Assets/texture/texture/toon/toonDress_shadow.png Color: 0.0000, 0.0000, 1.0000, 1.0000 _Color : color Color: 1.0000, 1.0000, 1.0000, 1.0000 _ShadowColor : color Color: 0.0574, 0.0000, 0.2868, 1.0000 _RimColor : color Color: 0.1228, 0.1190, 0.2279, 0.0000 _OutlineColor : color Color: 0.0256, 0.0221, 0.1250, 1.0000 _ShadowColor : color Color: 0.0574, 0.0000, 0.2868, 1.0000 _Shininess : float Value: 0.0000 _OutlineWidth : float Value: 0.0016 _RimPower : float Value: 23.0589 _RimShift : float Value: 0.0536 */ w.WriteLine("newmtl {0}", i.Descriptions[0]); w.WriteLine(" Ns {0:F8}", 10.0000f); w.WriteLine(" Ni {0:F8}", 1.5000f); w.WriteLine(" d {0:F8}", 1.0000f); w.WriteLine(" Tr {0:F8}", 0.0000f); w.WriteLine(" Tf {0:F8} {1:F8} {2:F8}", 1.0000f, 1.0000f, 1.0000f); w.WriteLine(" illum {0}", 2); w.WriteLine(" Ka {0:F8} {1:F8} {2:F8}", col.R, col.G, col.B); w.WriteLine(" Kd {0:F8} {1:F8} {2:F8}", 0.50f, 0.50f, 0.50f); w.WriteLine(" Ks {0:F8} {1:F8} {2:F8}", 0.00f, 0.00f, 0.00f); w.WriteLine(" Ke {0:F8} {1:F8} {2:F8}", 0.00f, 0.00f, 0.00f); if(null != maintex) { var texname = Path.GetFileName(maintex.AssetPath); maintex.GetImage().Save(Path.Combine(dir, texname)); //w.WriteLine(" map_Ka {0}", texname); //w.WriteLine(" map_Kd {0}", texname); w.WriteLine(" map_Ka {0}", Path.Combine(dir, texname)); w.WriteLine(" map_Kd {0}", Path.Combine(dir, texname)); } } } }