Mesh
La référence est en anglais : elle est générée à partir des commentaires du code, écrits en anglais.
public sealed class Mesh : AssetNamespace 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
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
public int vertexCount { get; }The count of vertices.
subMeshCount
public int subMeshCount { get; set; }The count of submeshes (each with its indices and its material slot).
indexFormat
public IndexFormat indexFormat { get; set; }16 or 32-bit indices: set UInt32 before giving more than 65 535 vertices.
isReadable
public bool isReadable { get; }The script can read the mesh's data back (a mesh made by a script always can).
bounds
public Bounds bounds { get; set; }The box around the vertices, in the mesh's own space (recalculated when the vertices or indices change).
vertices
public Vector3[] vertices { get; set; }The positions of the vertices (a new array; setting it is SetVertices).
normals
public Vector3[] normals { get; set; }The normals of the vertices (empty if the mesh has none).
tangents
public Vector4[] tangents { get; set; }The tangents of the vertices (empty if the mesh has none).
colors
public Color[] colors { get; set; }The colors of the vertices (empty if the mesh has none).
uv
public Vector2[] uv { get; set; }UV channel 0.
uv2
public Vector2[] uv2 { get; set; }UV channel 1.
uv3
public Vector2[] uv3 { get; set; }UV channel 2.
uv4
public Vector2[] uv4 { get; set; }UV channel 3.
uv5
public Vector2[] uv5 { get; set; }UV channel 4.
uv6
public Vector2[] uv6 { get; set; }UV channel 5.
uv7
public Vector2[] uv7 { get; set; }UV channel 6.
uv8
public Vector2[] uv8 { get; set; }UV channel 7.
triangles
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
public void Clear(bool keepVertexLayout = true)Removes the vertices and indices (and the vertex layout unless keepVertexLayout).
MarkDynamic
public void MarkDynamic()The mesh changes often: Unity keeps it in memory made for that.
SetVertices
public void SetVertices(Vector3[] inVertices)The positions of the vertices (the vertex count becomes their count).
public void SetVertices(Vector3[] inVertices, int start, int length)The positions of the vertices: length of them from start.
public void SetVertices(List<Vector3> inVertices)The positions of the vertices.
SetNormals
public void SetNormals(Vector3[] inNormals)The normals of the vertices (one per vertex).
public void SetNormals(Vector3[] inNormals, int start, int length)The normals of the vertices: length of them from start.
public void SetNormals(List<Vector3> inNormals)The normals of the vertices.
SetTangents
public void SetTangents(Vector4[] inTangents)The tangents of the vertices (w: the sign of the bitangent, 1 or -1).
public void SetTangents(Vector4[] inTangents, int start, int length)The tangents of the vertices: length of them from start.
public void SetTangents(List<Vector4> inTangents)The tangents of the vertices.
SetColors
public void SetColors(Color[] inColors)The colors of the vertices.
public void SetColors(Color[] inColors, int start, int length)The colors of the vertices: length of them from start.
public void SetColors(List<Color> inColors)The colors of the vertices.
SetUVs
public void SetUVs(int channel, Vector2[] uvs)The UVs of a channel (0 to 7), two values per vertex.
public void SetUVs(int channel, Vector2[] uvs, int start, int length)The UVs of a channel: length of them from start.
public void SetUVs(int channel, Vector3[] uvs)The UVs of a channel, three values per vertex.
public void SetUVs(int channel, Vector3[] uvs, int start, int length)The UVs of a channel: length of them from start.
public void SetUVs(int channel, Vector4[] uvs)The UVs of a channel, four values per vertex.
public void SetUVs(int channel, Vector4[] uvs, int start, int length)The UVs of a channel: length of them from start.
public void SetUVs(int channel, List<Vector2> uvs)The UVs of a channel, two values per vertex.
public void SetUVs(int channel, List<Vector3> uvs)The UVs of a channel, three values per vertex.
public void SetUVs(int channel, List<Vector4> uvs)The UVs of a channel, four values per vertex.
GetVertices
public void GetVertices(List<Vector3> vertices)Fills the list with the positions of the vertices.
GetNormals
public void GetNormals(List<Vector3> normals)Fills the list with the normals of the vertices.
GetTangents
public void GetTangents(List<Vector4> tangents)Fills the list with the tangents of the vertices.
GetColors
public void GetColors(List<Color> colors)Fills the list with the colors of the vertices.
GetUVs
public void GetUVs(int channel, List<Vector2> uvs)Fills the list with the UVs of a channel (two values each).
public void GetUVs(int channel, List<Vector3> uvs)Fills the list with the UVs of a channel (three values each).
public void GetUVs(int channel, List<Vector4> uvs)Fills the list with the UVs of a channel (four values each).
SetTriangles
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).
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.
public void SetTriangles(List<int> triangles, int submesh, bool calculateBounds = true, int baseVertex = 0)The triangles of a submesh.
SetIndices
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).
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.
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
public int[] GetIndices(int submesh, bool applyBaseVertex = true)The indices of a submesh (with its baseVertex added if applyBaseVertex).
public void GetIndices(List<int> indices, int submesh, bool applyBaseVertex = true)Fills the list with the indices of a submesh.
GetTriangles
public int[] GetTriangles(int submesh, bool applyBaseVertex = true)The triangles of a submesh (its indices; empty if its topology is not triangles).
public void GetTriangles(List<int> triangles, int submesh, bool applyBaseVertex = true)Fills the list with the triangles of a submesh.
GetTopology
public MeshTopology GetTopology(int submesh)How the indices of a submesh are joined.
GetIndexCount
public uint GetIndexCount(int submesh)The count of indices of a submesh.
GetIndexStart
public uint GetIndexStart(int submesh)The first index of a submesh in the index buffer.
GetBaseVertex
public uint GetBaseVertex(int submesh)The vertex added to the indices of a submesh.
RecalculateNormals
public void RecalculateNormals()The normals from the triangles (smooth where vertices are shared).
RecalculateTangents
public void RecalculateTangents()The tangents from the normals and UV channel 0.
RecalculateBounds
public void RecalculateBounds()The bounds from the vertices.
SetVertexBufferParams
public void SetVertexBufferParams(int vertexCount, params VertexAttributeDescriptor[] attributes)The vertex layout: vertexCount vertices with these attributes (formats, dimensions, streams 0 to 3).
SetVertexBufferData<T>
public void SetVertexBufferData<T>(T[] data, int dataStart, int meshBufferStart, int count, int stream = 0, MeshUpdateFlags flags = MeshUpdateFlags.Default)
where T : unmanagedWrites 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
public void SetIndexBufferParams(int indexCount, IndexFormat format)The index buffer: indexCount indices of 16 or 32 bits.
SetIndexBufferData<T>
public void SetIndexBufferData<T>(T[] data, int dataStart, int meshBufferStart, int count, MeshUpdateFlags flags = MeshUpdateFlags.Default)
where T : unmanagedWrites count indices of data (from dataStart: ushort for 16 bits, int or uint for 32 bits) into the index buffer from meshBufferStart.
SetSubMesh
public void SetSubMesh(int index, SubMeshDescriptor desc, MeshUpdateFlags flags = MeshUpdateFlags.Default)A submesh as a range of the index buffer (subMeshCount must include index).
