Class GeometricMeshDataExtensions
Turns CPU mesh data into something a Mesh can draw.
public static class GeometricMeshDataExtensions
- Inheritance
-
GeometricMeshDataExtensions
Methods
Bounds(GeometricMeshData<VertexPositionNormalTexture>)
The box and the sphere around the vertices.
public static (BoundingBox Box, BoundingSphere Sphere) Bounds(this GeometricMeshData<VertexPositionNormalTexture> meshData)
Parameters
meshDataGeometricMeshData<VertexPositionNormalTexture>The mesh data.
Returns
- (BoundingBox Box, BoundingSphere Sphere)
The bounds; empty when there are no vertices.
Exceptions
- ArgumentNullException
The mesh data is null.
ToMesh(GeometricMeshData<VertexPositionNormalTexture>, GraphicsDevice, int)
Uploads the mesh data and wraps it in a Mesh with its bounds, which the renderer uses to cull it when it is off screen; a MeshDraw alone has none and is never culled.
public static Mesh ToMesh(this GeometricMeshData<VertexPositionNormalTexture> meshData, GraphicsDevice device, int materialIndex = 0)
Parameters
meshDataGeometricMeshData<VertexPositionNormalTexture>The mesh data.
deviceGraphicsDeviceThe graphics device the buffers are created on.
materialIndexintThe index of the material the mesh uses in its model.
Returns
- Mesh
The mesh; the caller owns its draw's buffers, see ToMeshDraw(GeometricMeshData<VertexPositionNormalTexture>, GraphicsDevice).
Exceptions
- ArgumentNullException
The mesh data or the device is null.
- ArgumentException
The mesh data is empty.
ToMeshDraw(GeometricMeshData<VertexPositionNormalTexture>, GraphicsDevice)
Uploads the vertices and indices to the GPU and wraps them in a MeshDraw.
public static MeshDraw ToMeshDraw(this GeometricMeshData<VertexPositionNormalTexture> meshData, GraphicsDevice device)
Parameters
meshDataGeometricMeshData<VertexPositionNormalTexture>The mesh data, such as a procedural model's or TextMesh's.
deviceGraphicsDeviceThe graphics device the buffers are created on.
Returns
Remarks
The caller owns the buffers: nothing tracks them, so dispose VertexBuffers and IndexBuffer when the mesh goes, or a mesh rebuilt every frame leaks a buffer pair per rebuild. ToMesh(GeometricMeshData<VertexPositionNormalTexture>, GraphicsDevice, int) adds the bounds a MeshDraw cannot carry.
Exceptions
- ArgumentNullException
The mesh data or the device is null.
- ArgumentException
The mesh data has no vertices or no indices: there is nothing to upload, and a GPU buffer cannot be empty. Remove the mesh instead.