One of the most common reasons you may want to create a procedural asset is to generate a
Mesh using code. Weaver allows you to easily and efficiently create procedural meshes using the
Kybernetik.MeshBuilder class, both to efficiently generate and regenerate a dynamic mesh at runtime as well as to generate a procedural asset in the Unity Editor:
- The Building Example demonstrates how to generate a simple procedural mesh.
- Construct a
new MeshBuilderby specifying the initial vertex and index capacity. These values are simply the starting size for the internal lists which will expand as needed.
- By default, a
MeshBuilderwill contain UVs and Normals. If you want any other channels such as UVs2 or Colors, you must specify the
MeshChannelsin the constructor.
- If you wish to use a
Trianglesyou can specify it in the constructor or set the
topologyfield at any time.
- To build your mesh, you simply call
builder.Vertices.Add(...)(remembering to always add the same number of values to all mesh channels) followed by either adding values to the
builder.Indices0list or calling any of the
- Once you are finished building, you can either implicitly cast your
Meshor use any of the
- If you wish to reuse your
MeshBuilderyou can simply call
Clearbetween each use.
- Note that the source code of the
MeshBuilderclass is included in Weaver Lite.