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
Fields
BaseSizeInBytes
public const int BaseSizeInBytes = 34
Field Value
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
CustomBytes
Custom bytes buffer. Can be used to upload arbitrary amounts of byte values onto the graphics card
public CustomMeshDataPartByte CustomBytes
Field Value
CustomFloats
Custom floats buffer. Can be used to upload arbitrary amounts of float values onto the graphics card
public CustomMeshDataPartFloat CustomFloats
Field Value
CustomInts
Custom ints buffer. Can be used to upload arbitrary amounts of int values onto the graphics card
public CustomMeshDataPartInt CustomInts
Field Value
CustomShorts
Custom shorts buffer. Can be used to upload arbitrary amounts of short values onto the graphics card
public CustomMeshDataPartShort CustomShorts
Field Value
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
FlagsOffset
For offseting the data in the VBO. This field is used when updating a mesh.
public int FlagsOffset
Field Value
FlagsSize
the size of the flags.
public const int FlagsSize = 4
Field Value
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
FrostableBits
public bool[] FrostableBits
Field Value
- bool[]
HasAnyWindModeSet
True if the flags array contains any wind mode
public bool HasAnyWindModeSet
Field Value
IndexSize
the size of the index.
public const int IndexSize = 4
Field Value
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
IndicesInstanced
When using instanced rendering, set this flag to have the indices instanced.
public bool IndicesInstanced
Field Value
IndicesMax
Index buffer size
public int IndicesMax
Field Value
IndicesOffset
For offseting the data in the VBO. This field is used when updating a mesh.
public int IndicesOffset
Field Value
IndicesPerFace
public int IndicesPerFace
Field Value
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
NormalSize
The size of the normals.
public const int NormalSize = 4
Field Value
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
NormalsOffset
For offseting the data in the VBO. This field is used when updating a mesh.
public int NormalsOffset
Field Value
Recyclable
If true, this MeshData was constructed from MeshDataRecycler
public bool Recyclable
Field Value
Recycler
public static MeshDataRecycler Recycler
Field Value
RecyclingTime
The time this MeshData most recently entered the recycling system; the oldest may be garbage collected
public long RecyclingTime
Field Value
RenderPassCount
Amount of assigned render pass values
public int RenderPassCount
Field Value
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
Rgba2Offset
For offseting the data in the VBO. This field is used when updating a mesh.
public int Rgba2Offset
Field Value
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
RgbaInstanced
When using instanced rendering, set this flag to have the rgba values instanced.
public bool RgbaInstanced
Field Value
RgbaOffset
For offseting the data in the VBO. This field is used when updating a mesh.
public int RgbaOffset
Field Value
RgbaSize
The size of the color.
public const int RgbaSize = 4
Field Value
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
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
StandardVerticesPerFace
public const int StandardVerticesPerFace = 4
Field Value
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
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
UvOffset
For offseting the data in the VBO. This field is used when updating a mesh.
public int UvOffset
Field Value
UvSize
The size of the Uv.
public const int UvSize = 8
Field Value
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
VerticesCount
Amount of currently assigned vertices
public int VerticesCount
Field Value
VerticesMax
Vertex buffer size
public int VerticesMax
Field Value
VerticesPerFace
public int VerticesPerFace
Field Value
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
XyzInstanced
When using instanced rendering, set this flag to have the xyz values instanced.
public bool XyzInstanced
Field Value
XyzOffset
For offseting the data in the VBO. This field is used when updating a mesh.
public int XyzOffset
Field Value
XyzSize
The size of the position values.
public const int XyzSize = 12
Field Value
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
mode
The meshes draw mode
public EnumDrawMode mode
Field Value
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
RenderPasses
[Obsolete("Use RenderPassesAndExtraBits instead")]
public short[] RenderPasses { get; }
Property Value
- short[]
Rgba2Count
returns VerticesCount * 4
public int Rgba2Count { get; }
Property Value
RgbaCount
returns VerticesCount * 4
public int RgbaCount { get; }
Property Value
UvCount
returns VerticesCount * 2
public int UvCount { get; }
Property Value
XyzCount
returns VerticesCount * 3
public int XyzCount { get; }
Property Value
Methods
AddColorMapIndex(byte, byte)
public void AddColorMapIndex(byte climateMapIndex, byte seasonMapIndex)
Parameters
AddColorMapIndex(byte, byte, bool)
public void AddColorMapIndex(byte climateMapIndex, byte seasonMapIndex, bool frostableBit)
Parameters
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
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
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
MeshDatafilterByRenderPass
EnumChunkRenderPass
AddMeshData(MeshData, MeshDataFilterDelegate)
public void AddMeshData(MeshData data, MeshData.MeshDataFilterDelegate dele = null)
Parameters
data
MeshDatadele
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
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
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
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
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
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
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
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
AddXyzFace(byte)
public void AddXyzFace(byte faceIndex)
Parameters
faceIndex
byte
Clear()
Sets the counts of all data to 0
public MeshData Clear()
Returns
Clone()
Creates a compact, deep copy of the mesh
public MeshData Clone()
Returns
CloneUsingRecycler()
public MeshData CloneUsingRecycler()
Returns
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
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
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
MatrixTransform(float[])
Apply given transformation on the mesh
public MeshData MatrixTransform(float[] matrix)
Parameters
matrix
float[]
Returns
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
Returns
MatrixTransform(Span<float>, float[], Vec3f)
public MeshData MatrixTransform(Span<float> matrix, float[] vec, Vec3f origin = null)
Parameters
Returns
ModelTransform(ModelTransform)
Apply given transformation on the mesh
public MeshData ModelTransform(ModelTransform transform)
Parameters
transform
ModelTransform
Returns
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
Returns
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
Returns
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
intThe number of indices in this mesh.
SetMode(EnumDrawMode)
public void SetMode(EnumDrawMode p)
Parameters
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
intThe 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
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
Returns
Translate(Vec3f)
Offset the mesh by given values
public MeshData Translate(Vec3f offset)
Parameters
offset
Vec3f
Returns
WithColorMaps()
Sets up the tints array for holding tint info
public MeshData WithColorMaps()
Returns
WithNormals()
Sets up the renderPasses array for holding render pass info
public MeshData WithNormals()
Returns
WithRenderpasses()
Sets up the renderPasses array for holding render pass info
public MeshData WithRenderpasses()
Returns
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
WithXyzFaces()
Sets up the xyzfaces array for holding xyzfaces info
public MeshData WithXyzFaces()
Returns
getTextureIndex(int)
public byte getTextureIndex(int textureId)
Parameters
textureId
int