/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "InstancedSkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // Store a reference to our skinned mesh effect. string effectPath = Path.GetFullPath("SkinnedModelInstancing.fx"); effectMaterial.Effect = new ExternalReference<EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) effectMaterial.Textures.Add("Texture", basicMaterial.Texture); // Chain to the base ModelProcessor converter. return base.ConvertMaterial(effectMaterial, context); }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "SkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // Store a reference to our skinned mesh effect. string effectPath = Path.GetFullPath("SkinnedModel.fx"); effectMaterial.Effect = new ExternalReference <EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor converter. return(base.ConvertMaterial(effectMaterial, context)); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterialContent = material as BasicMaterialContent; bool texture = basicMaterialContent != null; if (texture) { EffectMaterialContent effectMaterialContent = new EffectMaterialContent(); string fullPath = Path.GetFullPath("SkinnedModel.fx"); effectMaterialContent.Effect = new ExternalReference<EffectContent>(fullPath); texture = basicMaterialContent.Texture == null; if (!texture) { effectMaterialContent.Textures.Add("Texture", basicMaterialContent.Texture); } MaterialContent materialContent = base.ConvertMaterial(effectMaterialContent, context); return materialContent; } else { throw new InvalidContentException(string.Format("SkinnedModelProcessor only supports BasicMaterialContent, but input mesh uses {0}.", material.GetType())); } }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> /// <param name="material"> /// The material. /// </param> /// <param name="context"> /// The context. /// </param> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { var basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException( string.Format( "SkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } var effectMaterial = new EffectMaterialContent(); // Store a reference to our skinned mesh effect. string effectPath = string.Empty; if (animationXML != null) { // get all animations XmlNodeList shaderList = animationXML.GetElementsByTagName("shader"); foreach (XmlNode shadernode in shaderList) { effectPath = Path.GetFullPath(shadernode.InnerText.Trim()); } } if (String.IsNullOrEmpty(effectPath)) { // Store a reference to our skinned mesh effect. effectPath = Path.GetFullPath("Effects\\ShadowMap.fx"); } effectMaterial.Effect = new ExternalReference <EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor converter. return(base.ConvertMaterial(effectMaterial, context)); }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; string effectPath = ""; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "SkinnedModelProcessor only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // StoreEffectMaterialContent effectMaterial = new EffectMaterialContent(); a reference to our skinned mesh effect. /* * StreamWriter w = new StreamWriter("test.txt"); * w.WriteLine(); * w.Close(); */ if (File.Exists("Models\\SkinnedModel.fx")) { effectPath = Path.GetFullPath("Models\\SkinnedModel.fx"); } if (effectPath == "") { return(base.ConvertMaterial(material, context)); } effectMaterial.Effect = new ExternalReference <EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } // Chain to the base ModelProcessor converter. return(base.ConvertMaterial(effectMaterial, context)); }
/// <summary> /// 全てのマテリアルがスキンモデル用のエフェクトを使うように変更する /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "SkinnedModelProcessorはBasicMaterialContentのみをサポートします"+ "入力メッシュは{0}を使用しています。",material.GetType())); } EffectMaterialContent effectMaterial = new EffectMaterialContent(); // スキンメッシュエフェクトを参照する string effectPath = Path.GetFullPath(@"Effect\SkinnedModel.fx"); effectMaterial.Effect = new ExternalReference<EffectContent>(effectPath); bool useTexture = UseTexture; // BasicMaterialContentのテクスチャを新しいマテリアルに設定する if (basicMaterial.Texture != null) { effectMaterial.Textures.Add("Texture", basicMaterial.Texture); } else { useTexture = false; } // マテリアルパラメータをエフェクトに設定 if (basicMaterial.DiffuseColor != null) effectMaterial.OpaqueData.Add("DiffuseColor", basicMaterial.DiffuseColor); if (basicMaterial.EmissiveColor != null) effectMaterial.OpaqueData.Add("EmissiveColor", basicMaterial.EmissiveColor); if (basicMaterial.SpecularColor != null) effectMaterial.OpaqueData.Add("SpecularColor", basicMaterial.SpecularColor); if (basicMaterial.SpecularPower != null) effectMaterial.OpaqueData.Add("SpecularPower", basicMaterial.SpecularPower); if (UseMaterial && useTexture) { effectMaterial.OpaqueData.Add("TechniqueName", "MaterialTextureTechnique"); } else if (UseMaterial) { effectMaterial.OpaqueData.Add("TechniqueName", "MaterialTechnique"); } else if (useTexture) { effectMaterial.OpaqueData.Add("TechniqueName", "TextureTechnique"); } else { effectMaterial.OpaqueData.Add("TechniqueName", "BasicTechnique"); } // ModelProcessorのConvertMaterialを呼ぶ return base.ConvertMaterial(effectMaterial, context); }
/// <summary> /// プロセッサ処理 /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { MaterialContent finalinput; if (context.TargetPlatform == TargetPlatform.WindowsPhone) { finalinput = input; } else { BasicMaterialContent basicinput = input as BasicMaterialContent; if (basicinput == null) throw new InvalidContentException(string.Format( "MMDProcessorはEffectMaterialContentのみをサポートします" + "入力メッシュは{0}を使用しています。", input.GetType())); ExternalReference<EffectContent> effect; //リソースからファイルを作成して読み込むという超セコイ方法…… if (!Directory.Exists("ext")) Directory.CreateDirectory("ext"); FileStream fs; fs = new FileStream(Path.Combine("ext", "MMDAccessoryEffect.fx"), FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(MMDXResource.AccessoryEffect); bw.Close(); effect = new ExternalReference<EffectContent>(Path.Combine("ext", "MMDAccessoryEffect.fx")); EffectMaterialContent effectcontent = new EffectMaterialContent(); effectcontent.Effect = effect; //パラメータコピー foreach (var data in basicinput.OpaqueData) { effectcontent.OpaqueData.Add(data.Key, data.Value); } //テクスチャのコピー if (basicinput.Textures.Count > 0) { foreach (var it in basicinput.Textures) { if (string.IsNullOrEmpty(it.Value.Filename)) continue; if (it.Value.Filename.IndexOf('*') != -1) { string[] files = it.Value.Filename.Split('*'); foreach(var file in files){ if (Path.GetExtension(file) == ".sph" || Path.GetExtension(file) == ".spa") { effectcontent.Textures.Add("Sphere", new ExternalReference<TextureContent>(CreateSpherePath(file))); } else { effectcontent.Textures.Add(it.Key, new ExternalReference<TextureContent>(file)); } } } else if (Path.GetExtension(it.Value.Filename) == ".sph" || Path.GetExtension(it.Value.Filename) == ".spa") { it.Value.Filename = CreateSpherePath(it.Value.Filename); effectcontent.Textures.Add("Sphere", it.Value); } else effectcontent.Textures.Add(it.Key, it.Value); } } //パラメータ設定 effectcontent.OpaqueData.Add("ShaderIndex", ShaderIndex); //データの渡し finalinput = effectcontent; } //事前アルファOff this.PremultiplyTextureAlpha = false; return base.Process(finalinput, context); }
/// <summary> /// Changes all the materials to use our skinned model effect. /// </summary> protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterial = material as BasicMaterialContent; if (basicMaterial == null) { throw new InvalidContentException(string.Format( "Reactor3D only supports BasicMaterialContent, " + "but input mesh uses {0}.", material.GetType())); } //EffectMaterialContent effectMaterial = new EffectMaterialContent(); // Store a reference to our skinned mesh effect. //string effectPath = Path.GetFullPath("Content/Actor.fx"); //EffectContent actor_effect = new EffectContent(); //actor_effect.EffectCode = Resource1.ActorBuildShader; //actor_effect //effectMaterial.Effect = new ExternalReference<EffectContent>(); //effectMaterial.Effect = new ExternalReference<EffectContent>(effectPath); // Copy texture settings from the input // BasicMaterialContent over to our new material. //if (basicMaterial.Texture != null) //effectMaterial.Textures.Add("Texture", basicMaterial.Texture); // Chain to the base ModelProcessor converter. return base.ConvertMaterial(basicMaterial, context); }
protected override MaterialContent ConvertMaterial(MaterialContent material, ContentProcessorContext context) { BasicMaterialContent basicMaterialContent = material as BasicMaterialContent; bool texture = basicMaterialContent != null; if (texture) { EffectMaterialContent effectMaterialContent = new EffectMaterialContent(); string fullPath = Path.GetFullPath("SkinnedModel.fx"); effectMaterialContent.Effect = new ExternalReference <EffectContent>(fullPath); texture = basicMaterialContent.Texture == null; if (!texture) { effectMaterialContent.Textures.Add("Texture", basicMaterialContent.Texture); } MaterialContent materialContent = base.ConvertMaterial(effectMaterialContent, context); return(materialContent); } else { throw new InvalidContentException(string.Format("SkinnedModelProcessor only supports BasicMaterialContent, but input mesh uses {0}.", material.GetType())); } }
/// <summary> /// プロセッサ処理 /// </summary> public override MaterialContent Process(MaterialContent input, ContentProcessorContext context) { MaterialContent finalinput; if (context.TargetPlatform == TargetPlatform.WindowsPhone) { finalinput = input; } else { BasicMaterialContent basicinput = input as BasicMaterialContent; if(basicinput==null) throw new InvalidContentException(string.Format( "MMDProcessorはEffectMaterialContentのみをサポートします" + "入力メッシュは{0}を使用しています。", input.GetType())); ExternalReference<EffectContent> effect; //リソースからファイルを作成して読み込むという超セコイ方法…… if (!Directory.Exists("ext")) Directory.CreateDirectory("ext"); FileStream fs; if (context.TargetPlatform == TargetPlatform.Windows) { fs = new FileStream(Path.Combine("ext", "MMDWinEffect.fx"), FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(MMDXResource.MMDWinEffect); bw.Close(); effect = new ExternalReference<EffectContent>(Path.Combine("ext", "MMDWinEffect.fx")); } else if (context.TargetPlatform == TargetPlatform.Xbox360) { fs = new FileStream(Path.Combine("ext", "MMDXBoxEffect.fx"), FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); bw.Write(MMDXResource.MMDXBoxEffect); bw.Close(); effect = new ExternalReference<EffectContent>(Path.Combine("ext", "MMDXBoxEffect.fx")); } else throw new NotImplementedException("ターゲットプラットフォーム:" + context.TargetPlatform.ToString() + " は対応していません"); EffectMaterialContent effectcontent = new EffectMaterialContent(); effectcontent.Effect = effect; //パラメータ設定 effectcontent.OpaqueData.Add("ShaderIndex", ShaderIndex); //パラメータコピー foreach (var data in basicinput.OpaqueData) { effectcontent.OpaqueData.Add(data.Key, data.Value); } //テクスチャのコピー if (basicinput.Textures.Count > 0) { foreach (var it in basicinput.Textures) { effectcontent.Textures.Add(it.Key, it.Value); } } //データの渡し finalinput = effectcontent; } //テクスチャの事前アルファ計算は無し this.PremultiplyTextureAlpha = false; return base.Process(finalinput, context); }