Mesh

csharp
public sealed class Mesh : Asset

Namespace NodeWorld.Flux.

A mesh: from the scene (a field, MeshFilter.sharedMesh), or made by the script (new Mesh()), on the model of Unity's. The arrays a script gives (vertices, normals, UVs, indices...) stay in the memory of the world: the client reads them there, without a copy, and hands them to Unity. A script fills them from any thread (Parallel.For); the calls that change the mesh run on the main thread. A mesh made by a script is destroyed with its world, or by Object.Destroy. Client only: the server has no meshes (no rendering, no physics).

Constructors

Mesh

csharp
public Mesh() : base(NW.Call(0, (int)CallKind.Mesh_Create, null, 0, null))

A new empty mesh of the world (16-bit indices, no vertex), as Unity's new Mesh().

Properties

vertexCount

csharp
public int vertexCount { get; }

The count of vertices.

subMeshCount

csharp
public int subMeshCount { get; set; }

The count of submeshes (each with its indices and its material slot).

indexFormat

csharp
public IndexFormat indexFormat { get; set; }

16 or 32-bit indices: set UInt32 before giving more than 65 535 vertices.

isReadable

csharp
public bool isReadable { get; }

The script can read the mesh's data back (a mesh made by a script always can).

bounds

csharp
public Bounds bounds { get; set; }

The box around the vertices, in the mesh's own space (recalculated when the vertices or indices change).

vertices

csharp
public Vector3[] vertices { get; set; }

The positions of the vertices (a new array; setting it is SetVertices).

normals

csharp
public Vector3[] normals { get; set; }

The normals of the vertices (empty if the mesh has none).

tangents

csharp
public Vector4[] tangents { get; set; }

The tangents of the vertices (empty if the mesh has none).

colors

csharp
public Color[] colors { get; set; }

The colors of the vertices (empty if the mesh has none).

uv

csharp
public Vector2[] uv { get; set; }

UV channel 0.

uv2

csharp
public Vector2[] uv2 { get; set; }

UV channel 1.

uv3

csharp
public Vector2[] uv3 { get; set; }

UV channel 2.

uv4

csharp
public Vector2[] uv4 { get; set; }

UV channel 3.

uv5

csharp
public Vector2[] uv5 { get; set; }

UV channel 4.

uv6

csharp
public Vector2[] uv6 { get; set; }

UV channel 5.

uv7

csharp
public Vector2[] uv7 { get; set; }

UV channel 6.

uv8

csharp
public Vector2[] uv8 { get; set; }

UV channel 7.

triangles

csharp
public int[] triangles { get; set; }

The triangles of every submesh, one after the other; setting them makes one submesh of them (as Unity's Mesh.triangles).

Methods

Clear

csharp
public void Clear(bool keepVertexLayout = true)

Removes the vertices and indices (and the vertex layout unless keepVertexLayout).

MarkDynamic

csharp
public void MarkDynamic()

The mesh changes often: Unity keeps it in memory made for that.

SetVertices

csharp
public void SetVertices(Vector3[] inVertices)

The positions of the vertices (the vertex count becomes their count).

csharp
public void SetVertices(Vector3[] inVertices, int start, int length)

The positions of the vertices: length of them from start.

csharp
public void SetVertices(List<Vector3> inVertices)

The positions of the vertices.

SetNormals

csharp
public void SetNormals(Vector3[] inNormals)

The normals of the vertices (one per vertex).

csharp
public void SetNormals(Vector3[] inNormals, int start, int length)

The normals of the vertices: length of them from start.

csharp
public void SetNormals(List<Vector3> inNormals)

The normals of the vertices.

SetTangents

csharp
public void SetTangents(Vector4[] inTangents)

The tangents of the vertices (w: the sign of the bitangent, 1 or -1).

csharp
public void SetTangents(Vector4[] inTangents, int start, int length)

The tangents of the vertices: length of them from start.

csharp
public void SetTangents(List<Vector4> inTangents)

The tangents of the vertices.

SetColors

csharp
public void SetColors(Color[] inColors)

The colors of the vertices.

csharp
public void SetColors(Color[] inColors, int start, int length)

The colors of the vertices: length of them from start.

csharp
public void SetColors(List<Color> inColors)

The colors of the vertices.

SetUVs

csharp
public void SetUVs(int channel, Vector2[] uvs)

The UVs of a channel (0 to 7), two values per vertex.

csharp
public void SetUVs(int channel, Vector2[] uvs, int start, int length)

The UVs of a channel: length of them from start.

csharp
public void SetUVs(int channel, Vector3[] uvs)

The UVs of a channel, three values per vertex.

csharp
public void SetUVs(int channel, Vector3[] uvs, int start, int length)

The UVs of a channel: length of them from start.

csharp
public void SetUVs(int channel, Vector4[] uvs)

The UVs of a channel, four values per vertex.

csharp
public void SetUVs(int channel, Vector4[] uvs, int start, int length)

The UVs of a channel: length of them from start.

csharp
public void SetUVs(int channel, List<Vector2> uvs)

The UVs of a channel, two values per vertex.

csharp
public void SetUVs(int channel, List<Vector3> uvs)

The UVs of a channel, three values per vertex.

csharp
public void SetUVs(int channel, List<Vector4> uvs)

The UVs of a channel, four values per vertex.

GetVertices

csharp
public void GetVertices(List<Vector3> vertices)

Fills the list with the positions of the vertices.

GetNormals

csharp
public void GetNormals(List<Vector3> normals)

Fills the list with the normals of the vertices.

GetTangents

csharp
public void GetTangents(List<Vector4> tangents)

Fills the list with the tangents of the vertices.

GetColors

csharp
public void GetColors(List<Color> colors)

Fills the list with the colors of the vertices.

GetUVs

csharp
public void GetUVs(int channel, List<Vector2> uvs)

Fills the list with the UVs of a channel (two values each).

csharp
public void GetUVs(int channel, List<Vector3> uvs)

Fills the list with the UVs of a channel (three values each).

csharp
public void GetUVs(int channel, List<Vector4> uvs)

Fills the list with the UVs of a channel (four values each).

SetTriangles

csharp
public void SetTriangles(int[] triangles, int submesh, bool calculateBounds = true, int baseVertex = 0)

The triangles of a submesh: three vertex indices per triangle (baseVertex added to each).

csharp
public void SetTriangles(int[] triangles, int trianglesStart, int trianglesLength, int submesh, bool calculateBounds = true, int baseVertex = 0)

The triangles of a submesh: length indices from start.

csharp
public void SetTriangles(List<int> triangles, int submesh, bool calculateBounds = true, int baseVertex = 0)

The triangles of a submesh.

SetIndices

csharp
public void SetIndices(int[] indices, MeshTopology topology, int submesh, bool calculateBounds = true, int baseVertex = 0)

The indices of a submesh with their topology (baseVertex added to each).

csharp
public void SetIndices(int[] indices, int indicesStart, int indicesLength, MeshTopology topology, int submesh, bool calculateBounds = true, int baseVertex = 0)

The indices of a submesh: length of them from start.

csharp
public void SetIndices(List<int> indices, MeshTopology topology, int submesh, bool calculateBounds = true, int baseVertex = 0)

The indices of a submesh with their topology.

GetIndices

csharp
public int[] GetIndices(int submesh, bool applyBaseVertex = true)

The indices of a submesh (with its baseVertex added if applyBaseVertex).

csharp
public void GetIndices(List<int> indices, int submesh, bool applyBaseVertex = true)

Fills the list with the indices of a submesh.

GetTriangles

csharp
public int[] GetTriangles(int submesh, bool applyBaseVertex = true)

The triangles of a submesh (its indices; empty if its topology is not triangles).

csharp
public void GetTriangles(List<int> triangles, int submesh, bool applyBaseVertex = true)

Fills the list with the triangles of a submesh.

GetTopology

csharp
public MeshTopology GetTopology(int submesh)

How the indices of a submesh are joined.

GetIndexCount

csharp
public uint GetIndexCount(int submesh)

The count of indices of a submesh.

GetIndexStart

csharp
public uint GetIndexStart(int submesh)

The first index of a submesh in the index buffer.

GetBaseVertex

csharp
public uint GetBaseVertex(int submesh)

The vertex added to the indices of a submesh.

RecalculateNormals

csharp
public void RecalculateNormals()

The normals from the triangles (smooth where vertices are shared).

RecalculateTangents

csharp
public void RecalculateTangents()

The tangents from the normals and UV channel 0.

RecalculateBounds

csharp
public void RecalculateBounds()

The bounds from the vertices.

SetVertexBufferParams

csharp
public void SetVertexBufferParams(int vertexCount, params VertexAttributeDescriptor[] attributes)

The vertex layout: vertexCount vertices with these attributes (formats, dimensions, streams 0 to 3).

SetVertexBufferData<T>

csharp
public void SetVertexBufferData<T>(T[] data, int dataStart, int meshBufferStart, int count, int stream = 0, MeshUpdateFlags flags = MeshUpdateFlags.Default)
    where T : unmanaged

Writes count vertices of data (from dataStart) into a stream of the vertex buffer, from its vertex meshBufferStart. T is the struct of one vertex of that stream, laid out as SetVertexBufferParams said.

SetIndexBufferParams

csharp
public void SetIndexBufferParams(int indexCount, IndexFormat format)

The index buffer: indexCount indices of 16 or 32 bits.

SetIndexBufferData<T>

csharp
public void SetIndexBufferData<T>(T[] data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default)
    where T : unmanaged

Writes count indices of data (from dataStart: ushort for 16 bits, int or uint for 32 bits) into the index buffer from meshBufferStart.

SetSubMesh

csharp
public void SetSubMesh(int index, SubMeshDescriptor desc, MeshUpdateFlags flags = MeshUpdateFlags.Default)

A submesh as a range of the index buffer (subMeshCount must include index).