Well I'm not a user of 3D Studio Max and so I'm not familiar with exactly what is supported by its X file exporter, but once you get a Model imported into an XNA project, and assuming each ModelMeshPart within your Model has a valid Effect (FX file) associated with it, you can access the HLSL global parameters of the effect (which is what I assume you are referring to) by making a call similar to the following:
MyModel.Meshes[0].MeshParts[0].Effect.Parameters["WorldViewProj"].SetValue(worldViewProjection);
In the above example, WorldViewProj is the HLSL global variable name and worldViewProjection is the Matrix in your XNA project that you want to assign to the HLSL variable.
If you Model does not have effects automatically associated with it after import, you can use the Content Pipeline to manually load in each Effect (FX file) and then associate each effect with each MeshPart similar to:
Effect MyEffect = MyContentManager.Load<Effect>("MyEffect");
MyModel.Meshes[0].MeshParts[0].Effect = MyEffect;
If you load the effect in this way, you have a direct reference for the effect, so you can also set parameters with just:
MyEffect.Parameters["WorldViewProj"].SetValue(worldViewProjection);
You also need to set the Effect.CurrentTechnique property for each Effect, and then to draw each ModelMeshPart (using its associated Effect) within a given ModelMesh on your Model, call:
MyModel.Meshes[0].Draw();
There is no need to manually iterate through the passes of each Effect. As I understand it, the Draw() call should take care of it.
kyle_w
| Wed, 05 Sep 2007 10:04:00 GMT |