This is a demo for a Unity script that allows people to procedurally generate 3D meshes of clean cut gemstones, hence it's called the Gemstone Generator. This was developed for PROCJAM 2015.

In the demo you have an example mesh generated, and you can mess around with the values above, which are the parameters of the generator.

Use the fields above to change the parameters, the coordinates field requires you to separate each number with commas (e.g. "0.5,1,1,0.5").

The shader and material come from the Gem Shader pack provided by the Unity Asset Store.

How it works

The algorithm works by taking a set of 2D Coordinates with a Y component [-1,1] and X component [0,1], and set them as vertices multiple times depending on the number of lines of symmetry.

This is achieved by working out the angle between two corners in the gemstone (360/Symmetery*2), then iterating from 0 to (Symmetry*2), setting the vertices and UVs using the coordinates rotated by the angle, and then increasing the angle. By the time it reaches (Symmetry * 2), the algorithm would have gone a complete circle, with vertices at each angle.

These vertices are then mapped by going through each symmetry again, except creating triangles going top to bottom, using the vertices of one line with the line adjacent to it.

Most of the other parameters allow extra modification of the transformation if needed (like scaling or rotating the vertices before being applied to the mesh), however the Slice Point parameter changes the shape of the mesh by creating slices that are not made from going through the symmetries normally. Instead it creates two sets of vertices, both before and after the set angle at an amount based on the size of the Slice Point [0,1].

Download

Download
Gemstone.cs 7 kB

Install instructions

The generation itself takes place in the C-Sharp Script, Gemstone.cs. Simply add it to a GameObject with a MeshFilter and MeshRenderer component, apply materials and transforms as you would any other render able object, set the parameters and then run the game. If you want to update the gemstone model at runtime, then you can do so through the Gemstone Component, as long as you call the UpdateValues() and Generate() functions afterwards for the updates to be applied to the mesh.

Comments

Log in with itch.io to leave a comment.

(+1)

The gems are really pretty! I included it in my ProcJam compilation video series, if you'd like to take a look :) https://youtu.be/afEMYQpjWBU