Code: Select all
private void drawSingleModel(BaseModel model, List<Texture2D> textures, string tech)
{
Matrix[] modelTransforms = new Matrix[model.Model.Bones.Count];
Matrix entityWorld = Matrix.Identity;
if(model.Ent != null)
entityWorld = model.Ent.CollisionInformation.WorldTransform.Matrix;
model.Model.CopyAbsoluteBoneTransformsTo(modelTransforms);
int i = 0;
foreach(ModelMesh mesh in model.Model.Meshes)
{
foreach(Effect currentEffect in mesh.Effects)
{
currentEffect.CurrentTechnique = currentEffect.Techniques[tech];
currentEffect.Parameters["xCamerasViewProjection"].SetValue(Camera.ViewProj);
currentEffect.Parameters["xLightsViewProjection"].SetValue(lights.ViewProjection);
if(textures != null)
currentEffect.Parameters["xTexture"].SetValue(textures[i++]);
currentEffect.Parameters["xWorld"].SetValue(modelTransforms[mesh.ParentBone.Index] * entityWorld * Camera.World);
currentEffect.Parameters["xLightPos"].SetValue(lights.LightPosition);
currentEffect.Parameters["xLightPower"].SetValue(lights.LightPower);
currentEffect.Parameters["xAmbient"].SetValue(lights.AmbientPower);
currentEffect.Parameters["xShadowMap"].SetValue(shadowMap);
currentEffect.Parameters["xCarLightTexture"].SetValue(lights.LightMap);
currentEffect.Parameters["xColor"].SetValue(lights.LightColor);
}
mesh.Draw();
}
}