Table of Contents

Class MeshData

Namespace
Vintagestory.API.Client
Assembly
VintagestoryAPI.dll

A data structure that can be used to upload mesh information onto the graphics card Please note, all arrays are used as a buffer. They do not tightly fit the data but are always sized as a multiple of 2 from the initial size.

public class MeshData
Inheritance
MeshData
Inherited Members
Extension Methods

Constructors

MeshData(bool)

Creates a new mesh data instance with no components initialized.

public MeshData(bool initialiseArrays = true)

Parameters

initialiseArrays bool

MeshData(int)

This constructor creates a basic MeshData with xyz, Uv, Rgba, Flags and Indices only; Indices to Vertices ratio is the default 6:4

public MeshData(int capacity)

Parameters

capacity int

MeshData(int, int, bool, bool, bool, bool)

Creates a new mesh data instance with given components, but you can also freely nullify or set individual components after initialization Any component that is null is ignored by UploadModel/UpdateModel

public MeshData(int capacityVertices, int capacityIndices, bool withNormals = false, bool withUv = true, bool withRgba = true, bool withFlags = true)

Parameters

capacityVertices int
capacityIndices int
withNormals bool
withUv bool
withRgba bool
withFlags bool

Fields

BaseSizeInBytes

public const int BaseSizeInBytes = 34

Field Value

int

ClimateColorMapIds

BlockShapeTesselator climate colormap ids. Required by TerrainChunkTesselator to determine whether to color a vertex by a color map or not. Should hold VerticesCount / 4 values. Set to 0 for no color mapping, set 1..n for color map 0..n-1

public byte[] ClimateColorMapIds

Field Value

byte[]

ColorMapIdsCount

Amount of assigned tint values

public int ColorMapIdsCount

Field Value

int

CustomBytes

Custom bytes buffer. Can be used to upload arbitrary amounts of byte values onto the graphics card

public CustomMeshDataPartByte CustomBytes

Field Value

CustomMeshDataPartByte

CustomFloats

Custom floats buffer. Can be used to upload arbitrary amounts of float values onto the graphics card

public CustomMeshDataPartFloat CustomFloats

Field Value

CustomMeshDataPartFloat

CustomInts

Custom ints buffer. Can be used to upload arbitrary amounts of int values onto the graphics card

public CustomMeshDataPartInt CustomInts

Field Value

CustomMeshDataPartInt

CustomShorts

Custom shorts buffer. Can be used to upload arbitrary amounts of short values onto the graphics card

public CustomMeshDataPartShort CustomShorts

Field Value

CustomMeshDataPartShort

Flags

The render flags buffer. This should hold VerticesCount*1 values.

public int[] Flags

Field Value

int[]

FlagsInstanced

When using instanced rendering, set this flag to have the flags instanced.

public bool FlagsInstanced

Field Value

bool

FlagsOffset

For offseting the data in the VBO. This field is used when updating a mesh.

public int FlagsOffset

Field Value

int

FlagsSize

the size of the flags.

public const int FlagsSize = 4

Field Value

int

FlagsStatic

flags vbo usage hints for the graphics card. Recommended to be set to false when this section of data changes often.

public bool FlagsStatic

Field Value

bool

HasAnyWindModeSet

True if the flags array contains any wind mode

public bool HasAnyWindModeSet

Field Value

bool

IndexSize

the size of the index.

public const int IndexSize = 4

Field Value

int

Indices

The indices buffer. This should hold IndicesCount values.

public int[] Indices

Field Value

int[]

IndicesCount

Amount of currently assigned indices

public int IndicesCount

Field Value

int

IndicesInstanced

When using instanced rendering, set this flag to have the indices instanced.

public bool IndicesInstanced

Field Value

bool

IndicesMax

Index buffer size

public int IndicesMax

Field Value

int

IndicesOffset

For offseting the data in the VBO. This field is used when updating a mesh.

public int IndicesOffset

Field Value

int

IndicesPerFace

public int IndicesPerFace

Field Value

int

IndicesStatic

indices vbo usage hints for the graphics card. Recommended to be set to false when this section of data changes often.

public bool IndicesStatic

Field Value

bool

NormalSize

The size of the normals.

public const int NormalSize = 4

Field Value

int

Normals

The normals buffer. This should hold VerticesCount*1 values. Currently unused by the engine. GL_INT_2_10_10_10_REV Format x: bits 0-9 (10 bit signed int) y: bits 10-19 (10 bit signed int) z: bits 20-29 (10 bit signed int) w: bits 30-31

public int[] Normals

Field Value

int[]

NormalsCount

Amount of currently assigned normals

public int NormalsCount

Field Value

int

NormalsOffset

For offseting the data in the VBO. This field is used when updating a mesh.

public int NormalsOffset

Field Value

int

Recyclable

If true, this MeshData was constructed from MeshDataRecycler

public bool Recyclable

Field Value

bool

Recycler

public static MeshDataRecycler Recycler

Field Value

MeshDataRecycler

RecyclingTime

The time this MeshData most recently entered the recycling system; the oldest may be garbage collected

public long RecyclingTime

Field Value

long

RenderPassCount

Amount of assigned render pass values

public int RenderPassCount

Field Value

int

RenderPassesAndExtraBits

BlockShapeTesselator renderpass. Required by TerrainChunkTesselator to determine in which mesh data pool each quad should land in. Should hold VerticesCount / 4 values.
Lower 10 bits = render pass
Upper 6 bits = extra bits for tesselators
Bit 10: DisableRandomDrawOffset

public short[] RenderPassesAndExtraBits

Field Value

short[]

Rgba

The vertex color buffer. This should hold VerticesCount*4 values.

public byte[] Rgba

Field Value

byte[]

Rgba2Instanced

When using instanced rendering, set this flag to have the rgba2 values instanced.

public bool Rgba2Instanced

Field Value

bool

Rgba2Offset

For offseting the data in the VBO. This field is used when updating a mesh.

public int Rgba2Offset

Field Value

int

Rgba2Static

rgba2 vbo usage hints for the graphics card. Recommended to be set to false when this section of data changes often.

public bool Rgba2Static

Field Value

bool

RgbaInstanced

When using instanced rendering, set this flag to have the rgba values instanced.

public bool RgbaInstanced

Field Value

bool

RgbaOffset

For offseting the data in the VBO. This field is used when updating a mesh.

public int RgbaOffset

Field Value

int

RgbaSize

The size of the color.

public const int RgbaSize = 4

Field Value

int

RgbaStatic

rgab vbo usage hints for the graphics card. Recommended to be set to false when this section of data changes often.

public bool RgbaStatic

Field Value

bool

SeasonColorMapIds

BlockShapeTesselator season colormap ids. Required by TerrainChunkTesselator to determine whether to color a vertex by a color map or not. Should hold VerticesCount / 4 values. Set to 0 for no color mapping, set 1..n for color map 0..n-1

public byte[] SeasonColorMapIds

Field Value

byte[]

StandardIndicesPerFace

public const int StandardIndicesPerFace = 6

Field Value

int

StandardVerticesPerFace

public const int StandardVerticesPerFace = 4

Field Value

int

TextureIds

public int[] TextureIds

Field Value

int[]

TextureIndices

Texture index per face, references to and index in the TextureIds array

public byte[] TextureIndices

Field Value

byte[]

TextureIndicesCount

public int TextureIndicesCount

Field Value

int

Uv

The uv buffer for texture coordinates. This should hold VerticesCount*2 values.

public float[] Uv

Field Value

float[]

UvInstanced

When using instanced rendering, set this flag to have the uv values instanced.

public bool UvInstanced

Field Value

bool

UvOffset

For offseting the data in the VBO. This field is used when updating a mesh.

public int UvOffset

Field Value

int

UvSize

The size of the Uv.

public const int UvSize = 8

Field Value

int

UvStatic

uv vbo usage hints for the graphics card. Recommended to be set to false when this section of data changes often.

public bool UvStatic

Field Value

bool

VerticesCount

Amount of currently assigned vertices

public int VerticesCount

Field Value

int

VerticesMax

Vertex buffer size

public int VerticesMax

Field Value

int

VerticesPerFace

public int VerticesPerFace

Field Value

int

XyzFaces

BlockShapeTesselator xyz faces. Required by TerrainChunkTesselator to determine vertex lightness. Should hold VerticesCount / 4 values. Set to 0 for no face, set to 1..8 for faces 0..7

public byte[] XyzFaces

Field Value

byte[]

XyzFacesCount

Amount of assigned xyz face values

public int XyzFacesCount

Field Value

int

XyzInstanced

When using instanced rendering, set this flag to have the xyz values instanced.

public bool XyzInstanced

Field Value

bool

XyzOffset

For offseting the data in the VBO. This field is used when updating a mesh.

public int XyzOffset

Field Value

int

XyzSize

The size of the position values.

public const int XyzSize = 12

Field Value

int

XyzStatic

xyz vbo usage hints for the graphics card. Recommended to be set to false when this section of data changes often.

public bool XyzStatic

Field Value

bool

mode

The meshes draw mode

public EnumDrawMode mode

Field Value

EnumDrawMode

xyz

The x/y/z coordinates buffer. This should hold VerticesCount*3 values.

public float[] xyz

Field Value

float[]

Properties

FlagsCount

returns VerticesCount

public int FlagsCount { get; }

Property Value

int

RenderPasses

[Obsolete("Use RenderPassesAndExtraBits instead")]
public short[] RenderPasses { get; }

Property Value

short[]

Rgba2Count

returns VerticesCount * 4

public int Rgba2Count { get; }

Property Value

int

RgbaCount

returns VerticesCount * 4

public int RgbaCount { get; }

Property Value

int

UvCount

returns VerticesCount * 2

public int UvCount { get; }

Property Value

int

XyzCount

returns VerticesCount * 3

public int XyzCount { get; }

Property Value

int

Methods

AddColorMapIndex(byte, byte)

public void AddColorMapIndex(byte climateMapIndex, byte seasonMapIndex)

Parameters

climateMapIndex byte
seasonMapIndex byte

AddIndex(int)

public void AddIndex(int index)

Parameters

index int

AddIndices(int, int, int, int, int, int)

Add 6 indices

public void AddIndices(int i1, int i2, int i3, int i4, int i5, int i6)

Parameters

i1 int
i2 int
i3 int
i4 int
i5 int
i6 int

AddIndices(int[])

public void AddIndices(int[] indices)

Parameters

indices int[]

AddMeshData(MeshData)

Add supplied mesh data to this mesh. If a given dataset is not set, it is not copied from the sourceMesh. Automatically adjusts the indices for you.

public void AddMeshData(MeshData sourceMesh)

Parameters

sourceMesh MeshData

AddMeshData(MeshData, float, float, float)

public void AddMeshData(MeshData sourceMesh, float xOffset, float yOffset, float zOffset)

Parameters

sourceMesh MeshData
xOffset float
yOffset float
zOffset float

AddMeshData(MeshData, EnumChunkRenderPass)

Add supplied mesh data to this mesh. If a given dataset is not set, it is not copied from the sourceMesh. Automatically adjusts the indices for you. Is filtered to only add mesh data for given render pass. A negative render pass value defaults to EnumChunkRenderPass.Opaque

public void AddMeshData(MeshData data, EnumChunkRenderPass filterByRenderPass)

Parameters

data MeshData
filterByRenderPass EnumChunkRenderPass

AddMeshData(MeshData, MeshDataFilterDelegate)

public void AddMeshData(MeshData data, MeshData.MeshDataFilterDelegate dele = null)

Parameters

data MeshData
dele MeshData.MeshDataFilterDelegate

AddNormal(float, float, float)

Adds a new normal to the mesh. Grows the normal buffer if necessary.

public void AddNormal(float normalizedX, float normalizedY, float normalizedZ)

Parameters

normalizedX float
normalizedY float
normalizedZ float

AddNormal(BlockFacing)

Adds a new normal to the mesh. Grows the normal buffer if necessary.

public void AddNormal(BlockFacing facing)

Parameters

facing BlockFacing

AddRenderPass(short)

public void AddRenderPass(short renderPass)

Parameters

renderPass short

AddTextureId(int)

public void AddTextureId(int textureId)

Parameters

textureId int

AddVertex(float, float, float, float, float)

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddVertex(float x, float y, float z, float u, float v)

Parameters

x float
y float
z float
u float
v float

AddVertex(float, float, float, float, float, byte[])

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddVertex(float x, float y, float z, float u, float v, byte[] color)

Parameters

x float
y float
z float
u float
v float
color byte[]

AddVertex(float, float, float, float, float, int)

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddVertex(float x, float y, float z, float u, float v, int color)

Parameters

x float
y float
z float
u float
v float
color int

AddVertexSkipTex(float, float, float, int)

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddVertexSkipTex(float x, float y, float z, int color = -1)

Parameters

x float
y float
z float
color int

AddVertexWithFlags(float, float, float, float, float, int, int)

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddVertexWithFlags(float x, float y, float z, float u, float v, int color, int flags)

Parameters

x float
y float
z float
u float
v float
color int
flags int

AddVertexWithFlagsSkipColor(float, float, float, float, float, int)

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddVertexWithFlagsSkipColor(float x, float y, float z, float u, float v, int flags)

Parameters

x float
y float
z float
u float
v float
flags int

AddVertexWithFlagsSkipTexture(float, float, float, float, float, int, int)

public void AddVertexWithFlagsSkipTexture(float x, float y, float z, float u, float v, int color, int flags)

Parameters

x float
y float
z float
u float
v float
color int
flags int

AddWithFlagsVertex(float, float, float, float, float, int, int)

Adds a new vertex to the mesh. Grows the vertex buffer if necessary.

public void AddWithFlagsVertex(float x, float y, float z, float u, float v, int color, int flags)

Parameters

x float
y float
z float
u float
v float
color int
flags int

AddXyzFace(byte)

public void AddXyzFace(byte faceIndex)

Parameters

faceIndex byte

Clear()

Sets the counts of all data to 0

public MeshData Clear()

Returns

MeshData

Clone()

Creates a compact, deep copy of the mesh

public MeshData Clone()

Returns

MeshData

CloneUsingRecycler()

public MeshData CloneUsingRecycler()

Returns

MeshData

CompactBuffers()

Resizes all buffers to tightly fit the data. Recommended to run this method for long-term in-memory storage of meshdata for meshes that won't get any new vertices added

public void CompactBuffers()

Dispose()

Allows meshdata object to be returned to the recycler

public void Dispose()

DisposeBasicData()

public void DisposeBasicData()

EmptyClone()

Creates an empty copy of the mesh

public MeshData EmptyClone()

Returns

MeshData

GetIndices()

public int[] GetIndices()

Returns

int[]

GetIndicesCount()

Gets the number of Indicices in this mesh.

public int GetIndicesCount()

Returns

int

The number of indicies in the mesh.

Remarks

..Shouldn't this be a property?

GetMode()

public EnumDrawMode GetMode()

Returns

EnumDrawMode

GetRgba()

public byte[] GetRgba()

Returns

byte[]

GetUv()

public float[] GetUv()

Returns

float[]

GetVerticesCount()

Gets the number of verticies in the the mesh.

public int GetVerticesCount()

Returns

int

The number of verticies in this mesh.

Remarks

..Shouldn't this be a property?

GetXyz()

public float[] GetXyz()

Returns

float[]

GrowIndexBuffer()

public void GrowIndexBuffer()

GrowIndexBuffer(int)

public void GrowIndexBuffer(int byAtLeastQuantity)

Parameters

byAtLeastQuantity int

GrowNormalsBuffer()

public void GrowNormalsBuffer()

GrowVertexBuffer()

Doubles the size of the xyz, uv, rgba, rgba2 and flags arrays

public void GrowVertexBuffer()

MatrixTransform(double[])

Apply given transformation on the mesh

public MeshData MatrixTransform(double[] matrix)

Parameters

matrix double[]

Returns

MeshData

MatrixTransform(float[])

Apply given transformation on the mesh

public MeshData MatrixTransform(float[] matrix)

Parameters

matrix float[]

Returns

MeshData

MatrixTransform(float[], float[], Vec3f)

Apply given transformation on the mesh - specifying two temporary vectors to work in (these can then be re-used for performance reasons)

public MeshData MatrixTransform(float[] matrix, float[] vec, Vec3f origin = null)

Parameters

matrix float[]
vec float[]

a re-usable float[4], values unimportant

origin Vec3f

origin point

Returns

MeshData

MatrixTransform(Span<float>, float[], Vec3f)

public MeshData MatrixTransform(Span<float> matrix, float[] vec, Vec3f origin = null)

Parameters

matrix Span<float>
vec float[]
origin Vec3f

Returns

MeshData

ModelTransform(ModelTransform)

Apply given transformation on the mesh

public MeshData ModelTransform(ModelTransform transform)

Parameters

transform ModelTransform

Returns

MeshData

RemoveIndex()

Removes the last index in the indices array

public void RemoveIndex()

RemoveVertex()

Removes the last vertex in the vertices array

public void RemoveVertex()

RemoveVertices(int)

Removes the last "count" vertices from the vertex array

public void RemoveVertices(int count)

Parameters

count int

Rotate(Vec3f, float, float, float)

Rotate the mesh by given angles around given origin

public MeshData Rotate(Vec3f origin, float radX, float radY, float radZ)

Parameters

origin Vec3f
radX float
radY float
radZ float

Returns

MeshData

Scale(Vec3f, float, float, float)

Scale the mesh by given values around given origin

public MeshData Scale(Vec3f origin, float scaleX, float scaleY, float scaleZ)

Parameters

origin Vec3f
scaleX float
scaleY float
scaleZ float

Returns

MeshData

SetIndices(int[])

public void SetIndices(int[] p)

Parameters

p int[]

SetIndicesCount(int)

Sets the number of indices in this mesh.

public void SetIndicesCount(int value)

Parameters

value int

The number of indices in this mesh.

SetMode(EnumDrawMode)

public void SetMode(EnumDrawMode p)

Parameters

p EnumDrawMode

SetRgba(byte[])

public void SetRgba(byte[] p)

Parameters

p byte[]

SetTexPos(TextureAtlasPosition)

Sets the uvs of this mesh to the specified TextureAtlasPosition, assuming the initial UVs range from 0..1, as they will be scaled by the texPos

public void SetTexPos(TextureAtlasPosition texPos)

Parameters

texPos TextureAtlasPosition

SetUv(float[])

public void SetUv(float[] p)

Parameters

p float[]

SetVertexFlags(int)

Applies a vertex flag to an existing MeshData (uses binary OR)

public void SetVertexFlags(int flag)

Parameters

flag int

SetVerticesCount(int)

Sets the number of verticies in this mesh.

public void SetVerticesCount(int value)

Parameters

value int

The number of verticies in this mesh

Remarks

..Shouldn't this be a property?

SetXyz(float[])

public void SetXyz(float[] p)

Parameters

p float[]

SizeInBytes()

public int SizeInBytes()

Returns

int

SplitByTextureId()

public MeshData[] SplitByTextureId()

Returns

MeshData[]

Translate(float, float, float)

Offset the mesh by given values

public MeshData Translate(float x, float y, float z)

Parameters

x float
y float
z float

Returns

MeshData

Translate(Vec3f)

Offset the mesh by given values

public MeshData Translate(Vec3f offset)

Parameters

offset Vec3f

Returns

MeshData

WithColorMaps()

Sets up the tints array for holding tint info

public MeshData WithColorMaps()

Returns

MeshData

WithNormals()

Sets up the renderPasses array for holding render pass info

public MeshData WithNormals()

Returns

MeshData

WithRenderpasses()

Sets up the renderPasses array for holding render pass info

public MeshData WithRenderpasses()

Returns

MeshData

WithTexPos(TextureAtlasPosition)

Returns a copy of this mesh with the uvs set to the specified TextureAtlasPosition

public MeshData WithTexPos(TextureAtlasPosition texPos)

Parameters

texPos TextureAtlasPosition

Returns

MeshData

WithXyzFaces()

Sets up the xyzfaces array for holding xyzfaces info

public MeshData WithXyzFaces()

Returns

MeshData

getTextureIndex(int)

public byte getTextureIndex(int textureId)

Parameters

textureId int

Returns

byte