当前顶点声明不包括当前顶点着色器所需的所有元素.颜色0不见了.(画网格)

本文关键字:顶点 不见 网格 颜色 不包括 声明 元素 | 更新日期: 2023-09-27 17:53:41

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);
    }

这是我用来绘制3D对象的代码。问题发生在mesh.Draw();

错误是:当前顶点声明不包括当前顶点着色器所需的所有元素。缺少Color0

我试图弄清楚发生了什么事,但无济于事。即使你能告诉我去哪里找,这将是一个巨大的帮助!编辑:.fx文件在这里

当前顶点声明不包括当前顶点着色器所需的所有元素.颜色0不见了.(画网格)

我需要使用VertexPositionNormalTexture,而不是VertexPositionColorNormal。网格不能处理颜色,但可以处理纹理。