Skip to content

Latest commit

 

History

History
49 lines (30 loc) · 3.33 KB

004-cubes.md

File metadata and controls

49 lines (30 loc) · 3.33 KB

Creating Cubes

The natural progression after creating a sheet, is to create cubes. The MeshCubeGenerator (MCB) does just that. The basic steps in the MCB are:

First of all, the code makes several (hard-coded) assumptions about the setup of the vertices, uvs and triangles. For the scope of this section this is intentional but can changed easily.

The vertices are duplicated. Normally a cube can modelled with eight vertices, however if we want have unique UVs for each side of the cube we'll need to duplicate some of these vertices (for reasons).

The downside is that the size of Mesh is much more limited, the upside is... we can use textures.

The MeshDefinition now contains a color and texture which can be assigned to the material in the MeshGenerator. The assumption made here is that it will be assigned to the default Texture of the default material, known to Unity as "_MainTex". The name of this texture can be set in the MeshGenerator.

The implementation is pretty inefficient, all sides of all cubes are being drawn, even though they are not always visible.

Apart from the number mangling of the vertices and triangles, the code should be pretty straightforward.

The end result should look something like this:

Scope Creep

Possible next steps:

  • Draw a voxel shape from data rather than just fill a matrix of cubes.
  • Improve performance.
  • Deform the matrix using forces.

Credits

Top cover By Pablo Picasso - [1], PD-US, https://en.wikipedia.org/w/index.php?curid=38779722