foreach (ModelAsset
m in Models)
{
foreach
(ModelMesh mesh
in
m.CrosswalkModel.Meshes)
{
foreach (ModelMeshPart
part in
mesh.MeshParts)
{
// エフェクトのクローンを作成する
Effect myEffect =
orgEffect.Clone(graphics.GraphicsDevice);
// エフェクトパラメータの引き継ぎ
foreach (EffectParameter
parameter in
part.Effect.Parameters)
{
if (parameter.Name
== "BasicTexture")
{
Texture2D texture =
parameter.GetValueTexture2D();
if (texture ==
null)
texture = albedoMap;
myEffect.Parameters["AlbedoMap"].SetValue(texture);
myEffect.Parameters["AmbientMap"].SetValue(ambientMap);
myEffect.Parameters["NormalMap"].SetValue(normalMap);
}
if (parameter.Name
== "AlbedoMap")
myEffect.Parameters["AlbedoMap"].SetValue(parameter.GetValueTexture2D());
if (parameter.Name
== "AmbientMap")
myEffect.Parameters["AmbientMap"].SetValue(parameter.GetValueTexture2D());
if (parameter.Name
== "NormalMap")
myEffect.Parameters["NormalMap"].SetValue(parameter.GetValueTexture2D());
if (parameter.Name
== "Alpha")
// HLSL側にグローバル変数が存在するかチェックし、OKの場合セットする(HLSL側にセマンティクス必須)
if (myEffect.Parameters.GetParameterBySemantic("Alpha")
!= null)
myEffect.Parameters["Alpha"].SetValue(parameter.GetValueSingle());
if (parameter.Name
== "AmbientLightColor")
myEffect.Parameters["AmbientColor"].SetValue(parameter.GetValueVector3());
if (parameter.Name
== "DiffuseColor")
myEffect.Parameters["DiffuseColor"].SetValue(parameter.GetValueVector3());
if (parameter.Name
== "SpecularColor")
// HLSL側にグローバル変数が存在するかチェックし、OKの場合セットする(HLSL側にセマンティクス必須)
if (myEffect.Parameters.GetParameterBySemantic("SpecularColor")
!= null)
myEffect.Parameters["SpecularColor"].SetValue(parameter.GetValueVector3());
if (parameter.Name
== "SpecularPower")
// HLSL側にグローバル変数が存在するかチェックし、OKの場合セットする(HLSL側にセマンティクス必須)
if (myEffect.Parameters.GetParameterBySemantic("SpecularPower")
!= null)
myEffect.Parameters["SpecularPower"].SetValue(parameter.GetValueSingle());
if (parameter.Name
== "World")
myEffect.Parameters["Model"].SetValue(parameter.GetValueMatrix());
if (parameter.Name
== "View")
myEffect.Parameters["View"].SetValue(parameter.GetValueMatrix());
if (parameter.Name
== "Projection")
myEffect.Parameters["Projection"].SetValue(parameter.GetValueMatrix());
if (parameter.Name
== "lightpos0")
myEffect.Parameters["lightpos0"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol0")
myEffect.Parameters["lightcol0"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos1")
myEffect.Parameters["lightpos1"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol1")
myEffect.Parameters["lightcol1"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos2")
myEffect.Parameters["lightpos2"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol2")
myEffect.Parameters["lightcol2"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos3")
myEffect.Parameters["lightpos3"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol3")
myEffect.Parameters["lightcol3"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos4")
myEffect.Parameters["lightpos4"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol4")
myEffect.Parameters["lightcol4"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos5")
myEffect.Parameters["lightpos5"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol5")
myEffect.Parameters["lightcol5"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos6")
myEffect.Parameters["lightpos6"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol6")
myEffect.Parameters["lightcol6"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos7")
myEffect.Parameters["lightpos7"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol7")
myEffect.Parameters["lightcol7"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos8")
myEffect.Parameters["lightpos8"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol8")
myEffect.Parameters["lightcol8"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightpos9")
myEffect.Parameters["lightpos9"].SetValue(parameter.GetValueVector4());
if (parameter.Name
== "lightcol9")
myEffect.Parameters["lightcol9"].SetValue(parameter.GetValueVector4());
}
// エフェクトを差し替える
part.Effect = myEffect;
}
}
}