• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision226 (tree)
Zeit2010-05-04 00:10:22
Autorwilfrem

Log Message

スフィアマップをAccessoryEffectにとりあえず統合

Ändern Zusammenfassung

Diff

--- trunk/MMDImporter/Accessory/AccessoryProcessor.cs (revision 225)
+++ trunk/MMDImporter/Accessory/AccessoryProcessor.cs (revision 226)
@@ -39,7 +39,7 @@
3939 BasicMaterialContent basicMaterial = material as BasicMaterialContent;
4040 if (basicMaterial != null)
4141 {
42- List<string> SpecialTexKeys = new List<string>();
42+ /*List<string> SpecialTexKeys = new List<string>();
4343 foreach (var i in basicMaterial.Textures)
4444 {
4545 if (Path.GetExtension(i.Value.Filename).ToLower() == ".sph" || Path.GetExtension(i.Value.Filename).ToLower() == ".spa")
@@ -149,31 +149,66 @@
149149 throw new NotImplementedException();
150150 }
151151 else
152+ {*/
153+ EffectMaterialContent effectMaterial = new EffectMaterialContent();
154+ //extディレクトリ作成
155+ string IntDir = "ext";
156+ if (!Directory.Exists(IntDir))
157+ Directory.CreateDirectory(IntDir);
158+ //エフェクトをリソースから作成
159+ FileStream fs = new FileStream(Path.Combine(IntDir, "AccessoryEffect.fx"), FileMode.Create);
160+ BinaryWriter bw = new BinaryWriter(fs);
161+ bw.Write(Resource1.AccessoryEffect);
162+ bw.Close();
163+ effectMaterial.Effect = new ExternalReference<EffectContent>(Path.Combine(IntDir, "AccessoryEffect.fx"));
164+ //データのコピー
165+ string Spheremap = "";
166+ foreach (var i in basicMaterial.OpaqueData)
152167 {
153- EffectMaterialContent effectMaterial = new EffectMaterialContent();
154- //extディレクトリ作成
155- string IntDir = "ext";
156- if (!Directory.Exists(IntDir))
157- Directory.CreateDirectory(IntDir);
158- //エフェクトをリソースから作成
159- FileStream fs = new FileStream(Path.Combine(IntDir, "AccessoryEffect.fx"), FileMode.Create);
160- BinaryWriter bw = new BinaryWriter(fs);
161- bw.Write(Resource1.AccessoryEffect);
162- bw.Close();
163- effectMaterial.Effect = new ExternalReference<EffectContent>(Path.Combine(IntDir, "AccessoryEffect.fx"));
164- //データのコピー
165- foreach (var i in basicMaterial.OpaqueData)
168+ if (i.Key == "SphereTexture")
169+ Spheremap = (string)i.Value;
170+ else
171+ effectMaterial.OpaqueData.Add(i.Key, i.Value);
172+ }
173+ //スフィアマップ処理
174+ if (Spheremap != "")
175+ {
176+ string spherePath = Path.GetFullPath(Spheremap);
177+ if (!File.Exists(spherePath))
178+ throw new InvalidContentException(
179+ "Cannot find sphere file:" + spherePath);
180+ //スフィアマップの拡張子判別
181+ string intFilePath = Path.Combine(IntDir, Path.GetFileName(spherePath));
182+ Image sphere = null;
183+ try
166184 {
167- effectMaterial.OpaqueData.Add(i.Key, i.Value);
185+ sphere = new Bitmap(spherePath);
168186 }
169- effectMaterial.Name = basicMaterial.Name;
170- effectMaterial.Identity = basicMaterial.Identity;
171- foreach (var i in basicMaterial.Textures)
187+ catch (OutOfMemoryException)
172188 {
173- effectMaterial.Textures.Add(i.Key, i.Value);
189+ //ここで読めないのはtga型
190+ intFilePath += ".tga";
191+ File.Copy(spherePath, intFilePath, true);//上書きありでコピー
174192 }
175- return base.ConvertMaterial(effectMaterial, context);
193+ //型判別
194+ if (sphere != null)
195+ {
196+ string Extention;
197+ ImageExtAnalyzer.Analyze(sphere, out Extention);
198+ intFilePath += Extention;
199+ File.Copy(spherePath, intFilePath, true);
200+ }
201+ //スフィアマップの貼付け
202+ effectMaterial.Textures.Add("SphereTexture", new ExternalReference<TextureContent>(intFilePath));
176203 }
204+ effectMaterial.Name = basicMaterial.Name;
205+ effectMaterial.Identity = basicMaterial.Identity;
206+ foreach (var i in basicMaterial.Textures)
207+ {
208+ effectMaterial.Textures.Add(i.Key, i.Value);
209+ }
210+ return base.ConvertMaterial(effectMaterial, context);
211+ //}
177212 }
178213 else
179214 {//EffectMaterialContentが来る場合ってあるの?
@@ -193,7 +228,7 @@
193228 protected override void ProcessGeometryUsingMaterial(MaterialContent material, IEnumerable<GeometryContent> geometryCollection, ContentProcessorContext context)
194229 {
195230 //スフィアマップでテクスチャ座標設定サボリ対策
196- if (material.Textures.Count > 0)
231+ /*if (material.Textures.Count > 0)
197232 {
198233 foreach (var i in geometryCollection)
199234 {
@@ -217,7 +252,7 @@
217252 material.Textures.Clear();
218253 }
219254 }
220- }
255+ }*/
221256 //どのエフェクトを使うのかの種別判定
222257 foreach (var i in geometryCollection)
223258 {
@@ -235,13 +270,37 @@
235270 {
236271 if (Path.GetFileName(j.Value.Filename) == "screen.bmp" &&
237272 !File.Exists(j.Value.Filename))
238- Special = 1;
273+ {
274+ if (Special == 0)
275+ Special = 1;
276+ else
277+ throw new InvalidContentException("特殊テクスチャを1マテリアルに2種類以上貼り付けることはできません");
278+ }
239279 }
240280 }
241281 else if (channel.Name == VertexChannelNames.Color(0))
242282 Color = true;
243283 else if (channel.Name == VertexChannelNames.Normal(0))
284+ {
244285 Normal = true;
286+ foreach (var j in i.Material.Textures)
287+ {
288+ if (Path.GetExtension(j.Value.Filename) == ".sph")
289+ {
290+ if (Special == 0)
291+ Special = 2;
292+ else
293+ throw new InvalidContentException("特殊テクスチャを1マテリアルに2種類以上貼り付けることはできません");
294+ }
295+ else if (Path.GetExtension(j.Value.Filename) == ".spa")
296+ {
297+ if (Special == 0)
298+ Special = 3;
299+ else
300+ throw new InvalidContentException("特殊テクスチャを1マテリアルに2種類以上貼り付けることはできません");
301+ }
302+ }
303+ }
245304 }
246305 int ShaderIndex=0;
247306 switch (Special)
@@ -272,9 +331,49 @@
272331 ++ShaderIndex;
273332 }
274333 break;
334+ case 2:
335+ case 3:
336+ {//スフィアマップ
337+ if (i.Material.Textures.Count > 2)
338+ throw new InvalidContentException(string.Format(
339+ "AccessoryProcessorはスフィアマップが指定されているマテリアルにおいて合計テクスチャー2枚まで、" +
340+ "それ以外のマテリアルにおいてテクスチャを合計2枚までサポートします" +
341+ "入力メッシュはテクスチャー{0}枚を使用しています。", i.Material.Textures.Count));
342+ //スフィアマップを不透明データに退避
343+ string SphKey = "";
344+ foreach (var j in i.Material.Textures)
345+ {
346+ if (Path.GetExtension(j.Value.Filename) == ".sph" ||
347+ Path.GetExtension(j.Value.Filename) == ".spa")
348+ {
349+ i.Material.OpaqueData.Add("SphereTexture", j.Value.Filename);
350+ if (SphKey != "")
351+ throw new InvalidContentException("スフィアマップを1つのマテリアルに二つ以上指定することはできません");
352+ SphKey = j.Key;
353+ }
354+ }
355+ //スフィアマップを削除
356+ i.Material.Textures.Remove(SphKey);
357+ //スフィアマップの種別を登録
358+ i.Material.OpaqueData.Add("SphereType", Special - 1);
359+ ShaderIndex = 12;
360+ if (Color)
361+ ++ShaderIndex;
362+ if (UseTexture)
363+ ShaderIndex += 2;
364+
365+ }
366+ break;
275367 default:
276368 throw new NotImplementedException();
277369 }
370+ //スフィアマップの処理残しのチェック
371+ foreach (var j in i.Material.Textures)
372+ {
373+ if (Path.GetExtension(j.Value.Filename) == ".sph" ||
374+ Path.GetExtension(j.Value.Filename) == ".spa")
375+ throw new InvalidContentException("スフィアマップを処理できませんでした。アクセサリに法線が無い可能性があります");
376+ }
278377 i.Material.OpaqueData.Add("ShaderIndex", ShaderIndex);
279378 }
280379
Show on old repository browser