Saturday, 15 November 2014

Creating Meshes: Hexagonal & Square

For me the logical starting point of the project was creating the meshes that would represent my voxels. So far I have only created 2D meshes, as a way to learn the mesh class in unity, because I thought it would be easier to start building 2D meshes rather than jumping in at the deep end and building 3D meshes from the get go. Rather than starting out with creating a shape such as a hexagon, I decided it would be easier to build a square and then translate the methods over to building a hexagon.

I have created lists for storing the Vertex, Triangle and UV data. I am using lists as they dynamically resize, and there for I can add many different vertices, triangles and uv coordinates.


The first step to building the mesh was to define the vertices. 
Values for building a Square






Values for building a Hexagon 












After defining the vertices, I needed to build the triangles using the vertices I've just created. For the square, I only need 2 triangles [0,1,3] and [1,2,3]. 





However building the hexagon, needed 4 triangles([1,5,0], [1,4,5],[1,2,4] and [2,3,4])


To work out how to build the meshes, I created some 'sketches' in order to know the vertices and triangles that I would need when coding.
Shows the vertices & triangles that I used to create the square mesh

The vertices & triangles I used to create the hexagon mesh



After building the triangles, I needed to set the UV Coordinates. UV Coords are a type of mapping that define the application of a 2D texture to a 3D object. This is done by giving each vertex a position on the texture, and that position corresponds to the colour on the texture that vertex should be.  



--------------------------------------------------------------------------------------------------------------------------

Here is the square shown in the Scene screen in Unity. You can see how the triangles have been drawn




Here is the Hexagon shown in the Scene screen in Unity. You can see how the triangles have been drawn

These are the what I have produced so far. Next step is to create a flat plane of these meshes and then building upon the meshes further and creating a cube, and then following on from that and building the hexagonal prism that will be the foundation of my project.

No comments:

Post a Comment