Пример #1
0
        public void Draw(Board board, Model chipModel, Matrix baseTransform,
                         Matrix[] chipTransforms)
        {
            Matrix world = OrientationMatrix * baseTransform;

            LightingEffect lightingEffect = board.LightingEffect;

            // Set model level render states
            lightingEffect.GlowScale.SetValue(GlowScale);
            lightingEffect.ColorOverride.SetValue(ColorOverride);
            lightingEffect.TexCoordScale.SetValue(TexCoordScale);

            foreach (ModelMesh mesh in chipModel.Meshes)
            {
                // Calculate matricies
                Matrix modelWorld               = chipTransforms[mesh.ParentBone.Index] * world;
                Matrix modelWorldView           = modelWorld * board.Camera.ViewMatrix;
                Matrix modelWorldViewProjection =
                    modelWorldView * board.Camera.ProjectionMatrix;

                // Set matricies
                lightingEffect.World.SetValue(modelWorld);
                lightingEffect.WorldView.SetValue(modelWorldView);
                lightingEffect.WorldViewProjection.SetValue(modelWorldViewProjection);

                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    // Get the material identifier out of the mesh part tag
                    bool   textureSet         = false;
                    string materialIdentifier = meshPart.Tag as string;
                    if (materialIdentifier != null)
                    {
                        // The material identifier is used to determine which textures
                        // to draw with
                        switch (materialIdentifier)
                        {
                        case "Front":
                            lightingEffect.TexCoordTranslation.SetValue(
                                this.TexCoordTranslationFront);

                            textureSet = SetTexture(board, 0);

                            break;

                        case "Back":
                            lightingEffect.TexCoordTranslation.SetValue(
                                this.TexCoordTranslationBack);

                            // Reuse the front side texture on single sided boards
                            if (board.TwoSided)
                            {
                                textureSet = SetTexture(board, 1);
                            }
                            else
                            {
                                textureSet = SetTexture(board, 0);
                            }

                            break;

                        default:
                            lightingEffect.DiffuseTexture.SetValue((Texture2D)null);
                            break;
                        }
                    }

                    // set the appropriate technique, depending on how many textures
                    // are being rendered
                    if (textureSet)
                    {
                        lightingEffect.Effect.CurrentTechnique =
                            lightingEffect.SingleTextureTechnique;
                    }
                    else
                    {
                        lightingEffect.Effect.CurrentTechnique =
                            lightingEffect.NoTextureTechnique;
                    }

                    // draw the mesh
                    lightingEffect.Effect.Begin();
                    DrawHelper.DrawMeshPart(mesh, meshPart, lightingEffect.Effect);
                    lightingEffect.Effect.End();
                }
            }
        }