48 lines
1.5 KiB
C#
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 Triangle[] Triangles { get; }
|
|
public PBREffect Effect { get; }
|
|
public Vector3[] Positions { get; }
|
|
|
|
public MeshPart(VertexBuffer vertexBuffer, IndexBuffer indexBuffer, Vector3[] positions, Triangle[] triangles, PBREffect effect)
|
|
{
|
|
VertexBuffer = vertexBuffer;
|
|
IndexBuffer = indexBuffer;
|
|
Positions = positions;
|
|
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
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|