Smuggler/MeshPart.cs

48 lines
1.5 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Smuggler
{
public class MeshPart
{
public IndexBuffer IndexBuffer { get; }
public VertexBuffer VertexBuffer { get; }
public VertexPositionNormalTexture[] Vertices { get; } /* should we parameterize this by vertex type? */
public Triangle[] Triangles { get; }
public BasicEffect Effect { get; }
public MeshPart(VertexBuffer vertexBuffer, IndexBuffer indexBuffer, VertexPositionNormalTexture[] vertices, Triangle[] triangles, BasicEffect effect)
{
VertexBuffer = vertexBuffer;
IndexBuffer = indexBuffer;
Vertices = vertices;
Triangles = triangles;
Effect = effect;
}
public void Draw(GraphicsDevice graphicsDevice, Matrix world, Matrix view, Matrix projection)
{
graphicsDevice.SetVertexBuffer(VertexBuffer);
graphicsDevice.Indices = IndexBuffer;
Effect.World = world;
Effect.View = view;
Effect.Projection = projection;
foreach (var pass in Effect.CurrentTechnique.Passes)
{
pass.Apply();
graphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
VertexBuffer.VertexCount,
0,
Triangles.Length
);
}
}
}
}