using System.Collections.Generic; using Microsoft.Xna.Framework.Graphics; namespace Kav { public static class Renderer { public static void Render(GraphicsDevice graphicsDevice, Camera camera, IEnumerable models, IEnumerable pointLights) { var view = camera.View; var projection = camera.Projection; foreach (var model in models) { foreach (var modelMesh in model.Meshes) { foreach (var meshPart in modelMesh.MeshParts) { graphicsDevice.SetVertexBuffer(meshPart.VertexBuffer); graphicsDevice.Indices = meshPart.IndexBuffer; if (meshPart.Effect is TransformEffect transformEffect) { transformEffect.View = view; transformEffect.Projection = projection; } if (meshPart.Effect is PointLightEffect pointLightEffect) { int i = 0; foreach (var pointLight in pointLights) { if (i > pointLightEffect.MaxPointLights) { break; } pointLightEffect.PointLights[i] = pointLight; i++; } } foreach (var pass in meshPart.Effect.CurrentTechnique.Passes) { pass.Apply(); graphicsDevice.DrawIndexedPrimitives( PrimitiveType.TriangleList, 0, 0, meshPart.VertexBuffer.VertexCount, 0, meshPart.Triangles.Length ); } } } } } } }