MeshBuilder Class

Summary

Encapsulates lists of vertices, normals, etc. to simplify the procedural generation of meshes.

To use: simply add elements to the lists (Weaver.MeshBuilder.Vertices, Weaver.MeshBuilder.Indices, Weaver.MeshBuilder.UVs, etc.) then call any of the Compile() overloads. You can also implicitly cast a Weaver.MeshBuilder to a UnityEngine.Mesh.

You can efficiently reuse a Weaver.MeshBuilder by calling Weaver.MeshBuilder.Clear.
Assembly
Weaver.dll
Namespace
Weaver
Base Types
  • Object
graph BT Type-->Base0["Object"] Type["MeshBuilder"] class Type type-node

Syntax

public class MeshBuilder

Constructors

Name Summary
MeshBuilder(int, int) Constructs a mesh builder with UVs and Normals using UnityEngine.MeshTopology.Triangles.
MeshBuilder(int, int[]) Constructs a mesh builder with UVs and Normals using UnityEngine.MeshTopology.Triangles.
MeshBuilder(MeshBuilder.MeshChannel, MeshTopology) Constructs a mesh builder with a specific set of data channels and topology.
MeshBuilder(MeshBuilder.MeshChannel, MeshTopology, int, int[]) Constructs a mesh builder with a specific set of data channels and topology.
MeshBuilder(MeshTopology) Constructs a mesh builder with UVs and Normals using the specified `topology`.

Fields

Name Constant Value Summary
Colors
The vertex colors which will be used for UnityEngine.Mesh.colors.
Indices
The mesh indices which will be used for UnityEngine.Mesh.triangles (though the topology isn't necessarily triangles).
Normals
The vertex normals which will be used for UnityEngine.Mesh.normals.
Tangents
The vertex tangents which will be used for UnityEngine.Mesh.tangents.
UVs
The UV coordinates which will be used for UnityEngine.Mesh.uv.
UVs2
The UV coordinates which will be used for UnityEngine.Mesh.uv2.
UVs3
The UV coordinates which will be used for UnityEngine.Mesh.uv3.
UVs4
The UV coordinates which will be used for UnityEngine.Mesh.uv4.
Vertices
The vertex positions which will be used for UnityEngine.Mesh.vertices.

Properties

Name Value Summary
IndexCount0 int
The number of indices which have currently been built in the first sub mesh.
Indices0 List<int>
The indices of the first sub-mesh.
SubMeshCount int
The number of sub meshes.
Topology MeshTopology
The UnityEngine.MeshTopology with which the UnityEngine.Mesh will be compiled.
VertexCount int
The number of vertices which have currently been built.

Methods

Name Value Summary
Clear() void
Clears this Weaver.MeshBuilder to be ready for reuse.
Compile(Mesh) void
Assigns the data from this Weaver.MeshBuilder to `mesh`.
Compile(Mesh) void
Creates a new UnityEngine.Mesh if it is null and assigns the data from this Weaver.MeshBuilder to it.
Compile(MeshCollider) void
Assigns the data from this Weaver.MeshBuilder to `meshCollider.mesh`.
Compile(MeshFilter) void
Assigns the data from this Weaver.MeshBuilder to `meshFilter.mesh`.
Compile(string) Mesh
Assigns the data from this Weaver.MeshBuilder to a new UnityEngine.Mesh.
FillIncrementalIndices(int) void
Fills all the indices for the specified sub mesh such that 'Indices[subMesh][i] == i' up to the capacity of that sub mesh.
Index2Triangles(int) void
Adds indices for 2 triangles starting at the current vertex count: [+0][+1][+2] and [+0][+2][+3].

You will generally want to call this method before adding the associated vertices.
Index2Triangles(int, int, int, int, int) void
Adds the specified indices to the specified sub mesh.
Index3Triangles(int) void
Adds indices for 3 triangles in a fan starting at the current vertex count: [+0][+1][+2] and [+0][+2][+3] and [+0][+3][+4].

You will generally want to call this method before adding the associated vertices.
Index3Triangles(int, int, int, int, int, int) void
Adds the specified indices to the specified sub mesh.
IndexLine(int) void
Adds a pair of indices for a line starting at the current vertex count: [+0][+1].

You will generally want to call this method before adding the associated vertices.
IndexTriangle(int) void
Adds indices for a triangle starting at the current vertex count: [+0][+1][+2].

You will generally want to call this method before adding the associated vertices.
IndexTriangle(int, int, int, int) void
Adds the specified indices to the specified sub mesh.
LogData(string) void
Logs all the mesh data in this Weaver.MeshBuilder. Also puts the message in the system copy buffer so you can paste it into a text editor because Unity's console truncates messages that are too long.

Operators

Name Value Summary
implicit operator Mesh(MeshBuilder) Mesh