Class MeshWriteData
A class that represents the vertex and index data allocated for drawing the content of a VisualElement.
Namespace: UnityEngine.UIElements
Syntax
public class MeshWriteData : object
Remarks
You can use this object to fill the values for the vertices and indices only during a callback to the generateVisualContent delegate. Do not store the passed MeshWriteData outside the scope of generateVisualContent as Unity could recycle it for other callbacks.
Properties
indexCount
The number of indices successfully allocated for VisualElement content drawing.
Declaration
public int indexCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
uvRegion
A rectangle describing the UV region holding the texture passed to Allocate(Int32, Int32, Texture).
Declaration
public Rect uvRegion { get; }
Property Value
Type | Description |
---|---|
Rect |
Remarks
Internally, the texture passed to Allocate(Int32, Int32, Texture) may either be used directly or is automatically integrated within a larger atlas. It is therefore required to use this property to scale and offset the UVs for the generated vertices in order to sample the correct texels.
Correct use of uvRegion is simple: given an input UV in [0,1] range, multiply the UV by (
vertexCount
The number of vertices successfully allocated for VisualElement content drawing.
Declaration
public int vertexCount { get; }
Property Value
Type | Description |
---|---|
Int32 |
Methods
SetAllIndices(NativeSlice<UInt16>)
Fills the values of the allocated indices with values copied directly from an array. Each 3 consecutive indices form a single triangle.
Declaration
public void SetAllIndices(NativeSlice<UInt16> indices)
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<UInt16> | indices | The array of indices to copy from. The length of the array must match the allocated index count. |
Remarks
When this method is called, it is not possible to use SetNextIndex(UInt16) to fill the indices.
SetAllIndices(UInt16[])
Fills the values of the allocated indices with values copied directly from an array. Each 3 consecutive indices form a single triangle.
Declaration
public void SetAllIndices(UInt16[] indices)
Parameters
Type | Name | Description |
---|---|---|
UInt16[] | indices | The array of indices to copy from. The length of the array must match the allocated index count. |
Remarks
When this method is called, it is not possible to use SetNextIndex(UInt16) to fill the indices.
SetAllVertices(NativeSlice<Vertex>)
Fills the values of the allocated vertices with values copied directly from an array. When this method is called, it is not possible to use SetNextVertex(Vertex) to fill the allocated vertices array.
Declaration
public void SetAllVertices(NativeSlice<Vertex> vertices)
Parameters
Type | Name | Description |
---|---|---|
NativeSlice<Vertex> | vertices | The array of vertices to copy from. The length of the array must match the allocated vertex count. |
Remarks
When this method is called, it is not possible to use SetNextVertex(Vertex) to fill the vertices.
SetAllVertices(Vertex[])
Fills the values of the allocated vertices with values copied directly from an array. When this method is called, it is not possible to use SetNextVertex(Vertex) to fill the allocated vertices array.
Declaration
public void SetAllVertices(Vertex[] vertices)
Parameters
Type | Name | Description |
---|---|---|
Vertex[] | vertices | The array of vertices to copy from. The length of the array must match the allocated vertex count. |
Remarks
When this method is called, it is not possible to use SetNextVertex(Vertex) to fill the vertices.
Examples
public class MyVisualElement : VisualElement
{
void MyGenerateVisualContent(MeshGenerationContext mgc)
{
var meshWriteData = mgc.Allocate(4, 6);
// meshWriteData has been allocated with 6 indices for 2 triangles
// ... set the vertices
// Set indices for the first triangle
meshWriteData.SetNextIndex(0);
meshWriteData.SetNextIndex(1);
meshWriteData.SetNextIndex(2);
// Set indices for the second triangle
meshWriteData.SetNextIndex(2);
meshWriteData.SetNextIndex(1);
meshWriteData.SetNextIndex(3);
}
}
SetNextIndex(UInt16)
Assigns the value of the next index of the allocated indices list.
Declaration
public void SetNextIndex(UInt16 index)
Parameters
Type | Name | Description |
---|---|---|
UInt16 | index | The value of the next index. |
Remarks
Used to iteratively fill the values of the allocated indices via repeated calls to this function until all values have been provided. This way of filling index data is mutually exclusive with the use of SetAllIndices(UInt16[]). After each invocation to this function, the internal counter for the next index is automatically incremented. When this method is called, it is not possible to use SetAllIndices(UInt16[]) to fill the indices. The index values provided refer directly to the vertices allocated in the same MeshWriteData object. Thus, an index of 0 means the first vertex and index 1 means the second vertex and so on.
SetNextVertex(Vertex)
Assigns the value of the next vertex of the allocated vertices list.
Declaration
public void SetNextVertex(Vertex vertex)
Parameters
Type | Name | Description |
---|---|---|
Vertex | vertex | The value of the next vertex. |
Remarks
Used to iteratively fill the values of the allocated vertices via repeated calls to this function until all values have been provided. This way of filling vertex data is mutually exclusive with the use of SetAllVertices(Vertex[]). After each invocation to this function, the internal counter for the next vertex is automatically incremented. When this method is called, it is not possible to use SetAllVertices(Vertex[]) to fill the vertices.
Note that calling SetNextVertex(Vertex) fewer times than the allocated number of vertices will leave the remaining vertices with random values as Allocate(Int32, Int32, Texture) does not initialize the returned data to 0 to avoid redundant work.