Meshclass

A mesh is a basic version of a `Sandbox.Model`, containing a set of vertices and indices which make up faces that make up a shape. A set of meshes can be used to create a `Sandbox.Model` via the `Sandbox.ModelBuilder` class.

objectMesh
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public class Sandbox.Mesh

Constructors3

Showing 3 constructors

Methods27

Showing 27 methods

public Sandbox.Mesh AddMorph(string name, System.ReadOnlySpan`1<Sandbox.MorphDelta> deltas)PUBLIC

ParameterTypeDescription
namestring
deltasReadOnlySpan<MorphDelta>
Returns:Mesh

public Sandbox.Mesh AddSubMesh(Sandbox.Material material, int startIndex, int indexCount, int startVertex = 0, int vertexCount = 0)PUBLIC

Add a sub mesh, drawing a range of the index buffer with its own `material`. Create the vertex and index buffers before adding sub meshes.

ParameterTypeDescription
materialMaterialMaterial to draw this range with.
startIndexintFirst index of the range to draw.
indexCountintNumber of indices to draw.
startVertex = 0intBase vertex offset. Defaults to the whole vertex buffer when zero.
vertexCount = 0intNumber of vertices referenced. Defaults to the whole vertex buffer when zero.
Returns:Mesh

public void CreateBuffers(Sandbox.VertexBuffer vb, bool calculateBounds = True)PUBLIC

Create vertex and index buffers.

ParameterTypeDescription
vbVertexBufferInput vertex buffer. If it is indexed (`Sandbox.VertexBuffer.Indexed`), then index buffer will also be created.
calculateBounds = TrueboolWhether to recalculate bounds from the vertex buffer.
Returns:void

protected virtual override void Finalize()PROTECTEDVIRTUALOVERRIDE

Returns:void

public void SetIndexBufferSize(int elementCount)PUBLIC

Resize the index buffer.

ParameterTypeDescription
elementCountint
Returns:void

public void SetIndexRange(int start, int count)PUBLIC

Set how many indices this mesh draws

ParameterTypeDescription
startint
countint
Returns:void

public void SetVertexBufferSize(int elementCount)PUBLIC

Resize the vertex buffer

ParameterTypeDescription
elementCountint
Returns:void

public void SetVertexRange(int start, int count)PUBLIC

Set how many vertices this mesh draws (if there's no index buffer)

ParameterTypeDescription
startint
countint
Returns:void

public static System.Span`1<int> TriangulatePolygon(System.Span`1<Vector3> vertices)PUBLICSTATIC

ParameterTypeDescription
verticesSpan<Vector3>
Returns:Span<int>

Properties9

Showing 9 properties

public BBox Sandbox.Mesh.Bounds { get; set; }PUBLICGETSET

Sets AABB bounds for this mesh.

Returns:BBox

public bool Sandbox.Mesh.HasIndexBuffer { get; set; }PUBLICGETSET

Whether this mesh has an index buffer.

Returns:bool

public bool Sandbox.Mesh.HasVertexBuffer { get; set; }PUBLICGETSET

Whether this mesh has a vertex buffer.

Returns:bool

public int Sandbox.Mesh.IndexCount { get; set; }PUBLICGETSET

Number of indices this mesh has.

Returns:int

public virtual sealed bool Sandbox.Mesh.IsValid { get; set; }PUBLICVIRTUALGETSET

Returns:bool

public float Sandbox.Mesh.UvDensity { get; set; }PUBLICGETSET

Used to calculate texture size for texture streaming.

Returns:float

public int Sandbox.Mesh.VertexCount { get; set; }PUBLICGETSET

Number of vertices this mesh has.

Returns:int

On this page

Constructorspublic Mesh()public Mesh(Sandbox.Material material, Sandbox.MeshPrimitiveType primType = 3)public Mesh(System.String name, Sandbox.Material material, Sandbox.MeshPrimitiveType primType = 3)Methodspublic Sandbox.Mesh AddMorph(System.String name, System.ReadOnlySpan`1<Sandbox.MorphDelta> deltas)public Sandbox.Mesh AddSubMesh(Sandbox.Material material, System.Int32 startIndex, System.Int32 indexCount, System.Int32 startVertex = 0, System.Int32 vertexCount = 0)public System.Void CreateBuffers(Sandbox.VertexBuffer vb, System.Boolean calculateBounds = True)public System.Void CreateIndexBuffer()public System.Void CreateIndexBuffer(System.Int32 indexCount, System.Collections.Generic.List`1<System.Int32> data)public System.Void CreateIndexBuffer(System.Int32 indexCount, System.Span`1<System.Int32> data = null)public System.Void CreateVertexBuffer(Sandbox.VertexAttribute[] layout)public System.Void CreateVertexBuffer(System.Int32 vertexCount, Sandbox.VertexAttribute[] layout, System.Collections.Generic.List`1<T> data)public System.Void CreateVertexBuffer(System.Int32 vertexCount, Sandbox.VertexAttribute[] layout, System.Span`1<T> data = null)public System.Void CreateVertexBuffer(System.Int32 vertexCount, System.Collections.Generic.List`1<T> data)public System.Void CreateVertexBuffer(System.Int32 vertexCount, System.Span`1<T> data = null)protected virtual override System.Void Finalize()public System.Void LockIndexBuffer(Sandbox.Mesh.IndexBufferLockHandler handler)public System.Void LockIndexBuffer(System.Int32 elementCount, Sandbox.Mesh.IndexBufferLockHandler handler)public System.Void LockIndexBuffer(System.Int32 elementOffset, System.Int32 elementCount, Sandbox.Mesh.IndexBufferLockHandler handler)public System.Void LockVertexBuffer(Sandbox.Mesh.VertexBufferLockHandler`1<T> handler)public System.Void LockVertexBuffer(System.Int32 elementCount, Sandbox.Mesh.VertexBufferLockHandler`1<T> handler)public System.Void LockVertexBuffer(System.Int32 elementOffset, System.Int32 elementCount, Sandbox.Mesh.VertexBufferLockHandler`1<T> handler)public System.Void SetIndexBufferData(System.Collections.Generic.List`1<System.Int32> data, System.Int32 elementOffset = 0)public System.Void SetIndexBufferData(System.Span`1<System.Int32> data, System.Int32 elementOffset = 0)public System.Void SetIndexBufferSize(System.Int32 elementCount)public System.Void SetIndexRange(System.Int32 start, System.Int32 count)public System.Void SetVertexBufferData(System.Collections.Generic.List`1<T> data, System.Int32 elementOffset = 0)public System.Void SetVertexBufferData(System.Span`1<T> data, System.Int32 elementOffset = 0)public System.Void SetVertexBufferSize(System.Int32 elementCount)public System.Void SetVertexRange(System.Int32 start, System.Int32 count)public static System.Span`1<System.Int32> TriangulatePolygon(System.Span`1<Vector3> vertices)Propertiespublic BBox Sandbox.Mesh.Bounds { get; set; }public System.Boolean Sandbox.Mesh.HasIndexBuffer { get; set; }public System.Boolean Sandbox.Mesh.HasVertexBuffer { get; set; }public System.Int32 Sandbox.Mesh.IndexCount { get; set; }public virtual sealed System.Boolean Sandbox.Mesh.IsValid { get; set; }public Sandbox.Material Sandbox.Mesh.Material { get; set; }public Sandbox.MeshPrimitiveType Sandbox.Mesh.PrimitiveType { get; set; }public System.Single Sandbox.Mesh.UvDensity { get; set; }public System.Int32 Sandbox.Mesh.VertexCount { get; set; }Metadata