Smuggler/MeshPart.cs

48 lines
1.5 KiB
C#
Raw Normal View History

2020-07-28 09:08:13 +00:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
namespace Smuggler
{
public class MeshPart
{
public IndexBuffer IndexBuffer { get; }
public VertexBuffer VertexBuffer { get; }
public Triangle[] Triangles { get; }
public BasicEffect Effect { get; }
public Vector3[] Positions { get; }
2020-07-28 09:08:13 +00:00
public MeshPart(VertexBuffer vertexBuffer, IndexBuffer indexBuffer, Vector3[] positions, Triangle[] triangles, BasicEffect effect)
2020-07-28 09:08:13 +00:00
{
VertexBuffer = vertexBuffer;
IndexBuffer = indexBuffer;
Positions = positions;
2020-07-28 09:08:13 +00:00
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();
2020-07-28 09:36:20 +00:00
2020-07-28 09:08:13 +00:00
graphicsDevice.DrawIndexedPrimitives(
PrimitiveType.TriangleList,
0,
0,
VertexBuffer.VertexCount,
0,
Triangles.Length
);
}
}
}
}