Topics: Developer Forum, Project Management Forum, User Forum
Apr 18, 2007 at 3:25 AM
Edited Apr 18, 2007 at 3:33 AM
How and when should i use this method?

i got this new effect that i'd like to test on my model but i kept getting error

The effects on the model for a ModelAnimator were changed without calling ModelAnimator.InitializeEffectParams().

and the error occurred even before the model showed up. the flow is like this :

1. i load the model

myModel = content.Load<Model>(@"content/dwarfmodel");

2. set the effect for the model

Effect myEffect = content.Load<Effect>(@"content/tryHLSL");

foreach (ModelMesh mesh in myModel.Meshes)
foreach (ModelMeshPart part in mesh.MeshParts)
if (part.Effect is BasicPaletteEffect)
BasicPaletteEffect oldEffect = (BasicPaletteEffect)part.Effect;
Effect newEffect = myEffect.Clone(graphics.GraphicsDevice);

newEffect.CurrentTechnique = terrainEffect.Techniques"Simplest";

part.Effect = newEffect;

3. create the modelanimator using the model

myAnimator = new ModelAnimator(this, myModel);

4. setting the view parameter for the model's effect at Update() method

foreach (ModelMesh mesh in myAnimator.Model.Meshes)
foreach (Effect effect in mesh.Effects)

where should i put the myAnimator.InitializeEffectParams then?
Apr 18, 2007 at 3:31 AM
Edited Apr 18, 2007 at 3:34 AM
by the way, the fx file is something like this :


struct VertexToPixel
float4 Position : POSITION;
float2 TexCoords : TEXCOORD0;
float3 Normal : TEXCOORD1;
float3 Position3D : TEXCOORD2;

struct PixelToFrame
float4 Color : COLOR0;

float4x4 xView;
float4x4 xProjection;

float4x4 xWorld;
Texture xColoredTexture;
bool xUseBrownInsteadOfTextures;

float4 xLightPos;
float xLightPower;

sampler ColoredTextureSampler = sampler_state
texture = <xColoredTexture> ;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = mirror;
AddressV = mirror;

float DotProduct(float4 LightPos, float3 Pos3D, float3 Normal)
float3 LightDir = normalize(LightPos - Pos3D);
return dot(LightDir, Normal);

VertexToPixel SimplestVertexShader( float4 inPos : POSITION0, float3 inNormal: NORMAL0, float2 inTexCoords : TEXCOORD0)
VertexToPixel Output = (VertexToPixel)0;

float4x4 xWorldViewProjection = mul(xWorld,mul(xView,xProjection));

Output.Position = mul(inPos, xWorldViewProjection);
Output.TexCoords = inTexCoords;
Output.Normal = normalize(mul(inNormal, (float3x3)xWorld));
Output.Position3D = mul(inPos, xWorld);

if (xUseBrownInsteadOfTextures)
Output.TexCoords = (0,0);

return Output;

PixelToFrame OurFirstPixelShader(VertexToPixel PSIn)
PixelToFrame Output = (PixelToFrame)0;

float DiffuseLightingFactor = DotProduct(xLightPos, PSIn.Position3D, PSIn.Normal);

Output.Color = tex2D(ColoredTextureSampler, PSIn.TexCoords) * DiffuseLightingFactor * xLightPower;

return Output;

technique Simplest
pass Pass0
VertexShader = compile vs20 SimplestVertexShader();
PixelShader = compile ps20 OurFirstPixelShader();


i got it from riemer's site.
Apr 18, 2007 at 4:36 PM
Well, you'll need a World paramter and MatrixPalette parameter (if the model is skinned). Then you just call InitializeEffectParams after changing the effects on the model.
Apr 18, 2007 at 5:09 PM
ah yes.. that one i keep forgetting.. i'll try it out and let you know as soon as possible..
Apr 26, 2007 at 8:51 AM
I've been trying to solve this problem but i'm stuck. i'll send you my solution and hopefully you can help solve the problem.