Table of Contents

Class MeshBuilder

Namespace
Stride.CommunityToolkit.Rendering.Utilities
Assembly
Stride.CommunityToolkit.dll

A utility class for building meshes by defining vertex elements with different data types and primitives types.

public class MeshBuilder : IDisposable
Inheritance
MeshBuilder
Implements

Properties

IndexCount

The current index count

public int IndexCount { get; }

Property Value

int

IndexType

The selected index type (default: None)

public IndexingType IndexType { get; init; }

Property Value

IndexingType

PrimitiveType

The selected primitive type (default: TriangleList)

public PrimitiveType PrimitiveType { get; init; }

Property Value

PrimitiveType

VertexCount

The current vertex count

public int VertexCount { get; }

Property Value

int

VertexElements

The vertex elements including offsets

public IReadOnlyList<VertexElementWithOffset> VertexElements { get; }

Property Value

IReadOnlyList<VertexElementWithOffset>

Methods

AddIndex(int)

Adds a new vertex index

public void AddIndex(int vertexIndex)

Parameters

vertexIndex int

The vertex index

Exceptions

ArgumentOutOfRangeException

The vertex index was outside the range of the currently added vertices

ArgumentOutOfRangeException

The vertex index was outside the range of the selected indexing mode

InvalidOperationException

The mesh builder isn't configured to use indices

AddVertex()

Adds a new vertex

public int AddVertex()

Returns

int

The vertex index (Can be used in GetElement<T>(int, int) and SetElement<T>(int, int, T))

Clear()

Clears all buffers and elements configured in this instance

public void Clear()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

GetElement<T>(int)

Gets the value for the specified element index

public T GetElement<T>(int elementIndex) where T : unmanaged

Parameters

elementIndex int

The element index

Returns

T

The element at the element index

Type Parameters

T

The element type to retrieve

Remarks

This overload always target's the last vertex index and is a convenience version of GetElement<T>(int, int)

Exceptions

ArgumentOutOfRangeException

The vertex index was outside the range of the currently added vertices

ArgumentOutOfRangeException

The element index was outside the range of the currently added elements

ArgumentException

The size of T does not match the type used when defining this element

GetElement<T>(int, int)

Gets the value for the specified element index

public T GetElement<T>(int vertexIndex, int elementIndex) where T : unmanaged

Parameters

vertexIndex int

The vertex index

elementIndex int

The element index

Returns

T

The element at the element index

Type Parameters

T

The element type to retrieve

Exceptions

ArgumentOutOfRangeException

The vertex index was outside the range of the currently added vertices

ArgumentOutOfRangeException

The element index was outside the range of the currently added elements

ArgumentException

The size of T does not match the type used when defining this element

SetElement<T>(int, int, T)

Sets the value for the specified element index

public void SetElement<T>(int vertexIndex, int elementIndex, T value) where T : unmanaged

Parameters

vertexIndex int

The vertex index

elementIndex int

The element index

value T

The value to set

Type Parameters

T

The element type to retrieve

Exceptions

ArgumentOutOfRangeException

The vertex index was outside the range of the currently added vertices

ArgumentOutOfRangeException

The element index was outside the range of the currently added elements

ArgumentException

The size of T does not match the type used when defining this element

SetElement<T>(int, T)

Sets the value for the specified element index

public void SetElement<T>(int elementIndex, T value) where T : unmanaged

Parameters

elementIndex int

The element index

value T

The value to set

Type Parameters

T

The element type to retrieve

Remarks

This overload always target's the last vertex index and is a convenience version of SetElement<T>(int, int, T)

Exceptions

ArgumentOutOfRangeException

The vertex index was outside the range of the currently added vertices

ArgumentOutOfRangeException

The element index was outside the range of the currently added elements

ArgumentException

The size of T does not match the type used when defining this element

ToMeshDraw(GraphicsDevice, bool)

Creates a new mesh draw instance

public MeshDraw ToMeshDraw(GraphicsDevice device, bool clear = true)

Parameters

device GraphicsDevice

The graphics device

clear bool

Determines if the mesh builder should be reset after this call

Returns

MeshDraw

A mesh draw instance

Exceptions

InvalidOperationException

The primitive type was not set to a valid value

WithBiTangent<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithBiTangent<T>(int semanticIndex = 0, string semanticName = "BITANGENT", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithColor<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithColor<T>(int semanticIndex = 0, string semanticName = "COLOR", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithElement<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithElement<T>(int semanticIndex, string semanticName, PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithIndexType(IndexingType)

Changes the selected indexing type.

public void WithIndexType(IndexingType indexingType)

Parameters

indexingType IndexingType

The selected indexing type

Exceptions

InvalidOperationException

If vertices were already added changing the indexing type is no longer allowed

WithNormal<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithNormal<T>(int semanticIndex = 0, string semanticName = "NORMAL", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithPositionTransformed<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithPositionTransformed<T>(int semanticIndex = 0, string semanticName = "SV_POSITION", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithPosition<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithPosition<T>(int semanticIndex = 0, string semanticName = "POSITION", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithPrimitiveType(PrimitiveType)

Changes the selected primitive type.

public void WithPrimitiveType(PrimitiveType primitiveType)

Parameters

primitiveType PrimitiveType

The selected primitive type

Exceptions

InvalidOperationException

If vertices were already added changing the primitive type is no longer allowed

WithTangent<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithTangent<T>(int semanticIndex = 0, string semanticName = "TANGENT", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element

WithTextureCoordinate<T>(int, string, PixelFormat)

Registers a new vertex element

public int WithTextureCoordinate<T>(int semanticIndex = 0, string semanticName = "TEXCOORD", PixelFormat pixelFormat = PixelFormat.None) where T : unmanaged

Parameters

semanticIndex int

The semantic index

semanticName string

The semantic name

pixelFormat PixelFormat

The pixel format (use None to auto-detect)

Returns

int

The element index used in GetElement<T>(int) and SetElement<T>(int, T)

Type Parameters

T

The type of the position element