private void DrawModel()
{
Matrix worldMatrix = Matrix.CreateScale(0.0005f, 0.0005f, 0.0005f) * Matrix.CreateRotationZ(MathHelper.Pi) * Matrix.CreateTranslation(new Vector3(19, 12, -5));
Matrix[] modelTransforms = new Matrix[testModel.Bones.Count];
testModel.CopyAbsoluteBoneTransformsTo(modelTransforms);
foreach (ModelMesh mesh in testModel.Meshes)
{
foreach (Effect currentEffect in mesh.Effects)
{
currentEffect.CurrentTechnique = currentEffect.Techniques["Colored"];
currentEffect.Parameters["xWorld"].SetValue(modelTransforms[mesh.ParentBone.Index] * worldMatrix);
currentEffect.Parameters["xView"].SetValue(viewMatrix);
currentEffect.Parameters["xProjection"].SetValue(projectionMatrix);
}
mesh.Draw();
}
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
DepthStencilState depthBufferState = new DepthStencilState();
depthBufferState.DepthBufferEnable = true;
GraphicsDevice.DepthStencilState = depthBufferState;
RasterizerState rs = new RasterizerState();
if (wireframeMode)
rs.FillMode = FillMode.WireFrame;
if (showAllTriangles)
rs.CullMode = CullMode.None;//DO NOT INCLUDE IN FINAL PRODUCT--DRAWS ALL TRIANGLES
GraphicsDevice.RasterizerState = rs;
Matrix worldMatrix = Matrix.CreateTranslation(-terrainWidth / 2.0f, -terrainHeight / 2.0f, 0) * Matrix.CreateRotationZ(angle);
effect.CurrentTechnique = effect.Techniques["Colored"];
effect.Parameters["xView"].SetValue(viewMatrix);
effect.Parameters["xProjection"].SetValue(projectionMatrix);
effect.Parameters["xWorld"].SetValue(worldMatrix);
//lighting (ambient)
Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f);
lightDirection.Normalize();
effect.Parameters["xLightDirection"].SetValue(lightDirection);
effect.Parameters["xAmbient"].SetValue(0.1f);
effect.Parameters["xEnableLighting"].SetValue(true);
//drawing
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
}
GraphicsDevice.Indices = indexBuffer;
GraphicsDevice.SetVertexBuffer(vertexBuffer);
GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertices.Length, 0, indices.Length / 3);
DrawModel();
base.Draw(gameTime);
}
This is the code I am using to draw a 3D object. The problem occurs on mesh.Draw();
The error is: The current vertex declaration does not include all the elements required by the current vertex shader. Color0 is missing.
I have tried to figure out what is going on, to no avail. Even if you can just tell me where to look, it will be a massive help!
EDIT: the .fx file is here.