public override void DrawInstances(Renderer.DrawType technique)
        {
            GraphicsDevice GraphicsDevice = Renderer.Instance.GraphicsDevice;

            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset);
                    GraphicsDevice.Indices = meshPart.IndexBuffer;

                    // Set up the rendering effect.
                    SkinnedEffect effect = (SkinnedEffect)meshPart.Effect;
                    effect.CurrentTechnique = effect.Techniques[(int)technique];

                    if (technique == Renderer.DrawType.Draw)
                    {
                        effect.View = Renderer.Instance.view;
                        effect.Projection = Renderer.Instance.projection;
                        effect.DiffuseTexture = diffuse;
                        Renderer.Instance.sun.SetLights(ref effect);
                        effect.ReceivesShadows = ReceivesShadows;

                        if (effect is SkinnedBumpedEffect)
                        {
                            ((SkinnedBumpedEffect)effect).NormalMapTexture = bumpMap;
                        }

                        if (effect is SkinnedBumpedSpecularEffect)
                        {
                            ((SkinnedBumpedSpecularEffect)effect).SpecularMapTexture = specularMap;
                        }
                    }
                    else
                    {
                        Renderer.Instance.sun.SetLightViewProjection(ref effect);
                    }

                    for (int i = 0; i < DrawList.Count; i++)
                    {
                        SkinnedRModelInstance instance = (SkinnedRModelInstance)DrawList.Data[i];
                        Matrix translation;
                        Matrix.Multiply(ref instance.boneTransforms[mesh.ParentBone.Index], ref instance.RenderTransform, out translation);
                        effect.World = translation;
                        effect.SetBoneTransforms(instance.skeleton);

                        // draw the mesh
                        foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                        {
                            pass.Apply();

                            GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                                    meshPart.NumVertices, meshPart.StartIndex,
                                                                    meshPart.PrimitiveCount);
                        }
                    }
                }
            }
        }
        public override void DrawInstances(Renderer.DrawType technique)
        {
            if (technique == Renderer.DrawType.Draw)
            {
                GraphicsDevice GraphicsDevice = Renderer.Instance.GraphicsDevice;

                foreach (ModelMesh mesh in model.Meshes)
                {
                    foreach (ModelMeshPart meshPart in mesh.MeshParts)
                    {
                        GraphicsDevice.SetVertexBuffer(meshPart.VertexBuffer, meshPart.VertexOffset);
                        GraphicsDevice.Indices = meshPart.IndexBuffer;

                        // Set up the rendering effect.
                        Water effect = (Water)meshPart.Effect;
                        effect.CurrentTechnique = effect.Techniques[(int)technique];

                        effect.View = Renderer.Instance.view;
                        effect.Projection = Renderer.Instance.projection;
                        Renderer.Instance.sun.SetLights(ref effect);

                        for (int i = 0; i < DrawList.Count; i++)
                        {
                            // get the transform for the current instance
                            Matrix translation;
                            Matrix.Multiply(ref transforms[mesh.ParentBone.Index], ref DrawList.Data[i].RenderTransform, out translation);
                            effect.World = translation;

                            // draw the mesh
                            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
                            {
                                pass.Apply();

                                GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
                                                                        meshPart.NumVertices, meshPart.StartIndex,
                                                                        meshPart.PrimitiveCount);
                            }
                        }
                    }
                }
            }
        }
Example #3
0
        public Renderer(GraphicsDevice graphicsDevice)
        {
            this.graphicsDevice = graphicsDevice;

            instance = this;
        }
Example #4
0
 public virtual void DrawInstances(Renderer.DrawType technique)
 {
 }
 public override void DrawInstances(Renderer.DrawType technique)
 {
     // handled by the editor, we do nothing!
 }