Report
Report
December 2018
Abstract
A detailed report of the generation of creatures within Unity based on param-
eters with no previously created assets. This is not yet suitable for use in video
games but could be looked into further to eventually have fully computer generated
creatures in real time.
1 Introduction
The aim of this project is to generate a creature based on input parameters. The creature
mesh will be generated using metaballs and the marching cubes algorithm (Long &
Nagamune, 2015). The program will be made using the Unity3D engine and coded using
C# (Unity, 2018).
The creatures outputted by this project should consist of no pre-made assets but rather
be entirely generated by the program itself. The possibilities of using this to generate
creatures for a game will be looked into analysing aesthetics and time to generate.
2 Methodology
1
Figure 1: Points from grid created for Marching Cubes
within the creature with a little excess for the radius of the metaballs. Which points
within this grid are inside the metaball are then need to be calculated using the radius
of the metaball and its spread. Each point is given a score, Points within the radius of
the primitive sphere plus the spread of the metaball are scored using the equation:
distance − r 2
(1 − ) (1)
spread
Where distance is the distance from the center of the metaball to a grid point, r is the
radius of the primitive sphere and spread is how far the metaball spreads out. The results
from this equation are added together for each individual grid point and if a grid points
score is one or over it is deemed within the metaball.
The output for a single metaball from this algorithm can be seen in figure 2. Each
metaball is mapped to a creature point as can be seen from figure 3.
The mesh then needed to be created for the metaballs. A simpler 2D version of the
Marching Cubes algorithm, Marching squares, was referenced to get an idea of how the
2
Figure 2: Points for a single metaball shown in green in grid of black points
3
Figure 3: Points for metaballs around creature points
4
Figure 4: Creature Shapes used for testing metaballs
algorithm works at a basic level (Wong, 2014). In order to test this stage, three different
arrangements of points were hard coded in the shape of creatures (see fig 4).
Each cube of points in the grid is looked at separately to see which points within
it are in the shape. If all or none of the points are within the shape this cube can be
ignored as these will have no mesh within them. What the mesh looks like in the other
will depend on the number of points in them that are in the mesh. Cubes that have n
number of points within the shape will be almost the same as cubes with n number of
points outwith the shape except the direction is reversed.
Originally figure 5 was created as reference to how the mesh should look in each cube
shape. However soon became obvious that this didn’t cover the areas properly and would
create a very holy output. So the reference image in (Long & Nagamune, 2015) was used
instead.
To debug this algorithm as single metaball was rendered (see fig 6) to see where holes
where happening, then the points causing these holes were recreated with a single cube
and changed so the triangles where all drawn the right way (see fig 7. In the end the
program output results like figure 8. However when given more complicated geometry
there were some holes, this is probably caused by ambiguities in the Marching cubes
algorithm.
5
Figure 5: Reference made to help with mesh generation (does not work)
6
Figure 6: Image of singular metaball mesh before program was fully working
7
Figure 7: Single cube with 3 points within the shape
8
Figure 8: 2 metaballs very close together with working mesh
In order so make it easier to change the size and spread of the metaballs for different
body parts the creature’s points were stored in a Dictionary that contains a List of Lists
of vector3s. This means That not only can each body part be separated into a dictionary
key of the part name, each individual part can be in a separate list. For example all
legs will be in the Dictionary[”Leg”], and each individual leg will be in a separate list
within that. This was to allow for the possibility of looking into stopping metaballs from
spreading towards certain other body parts in a hierarchical fashion. So legs, head and
tails wouldn’t spread towards each other.
Each value in the legs parameter accounts for two legs as it is assumed that there will
never be asymmetrical legs. For every set of Legs except from the first the spine is
extended backwards to accommodate for these legs. The leg points are then brought
outward from the spine and mirrored on both sides.
To provide more variation to the creatures there is an option to choose between
mammal and insect legs. This is inspired by the legs in Hudson’s thesis (Hudson, 2013)
9
Figure 9: Royalty free image of a grasshopper
that are different dependent on whether the creature is quadrupedal or bipedal. The
mammal legs are fairly straight forward going pretty much straight down with a slight
bend and a larger area at the feet. The insect legs were based on the back legs of a
grasshopper (see fig 9) sloping up and then down again. The results of both versions can
be seen in figure 10.
The Arms were created in a similar way to the legs except the shoulders for the arms to
connect to are created within the torso code. A regular torso section contains only one
metaball, but if a torso section is going to be connected to arms it will be 2 metaballs
wide as it becomes a chest and shoulder section.
There will be a chest and shoulder section on the torso even if the creature has no
arms to make sure the creature is complete. If there is no torso the chest and shoulder
sections will still be created for every pair of arms there is so they have something to
connect to.
Arms are created bent with a slight downward slope to make them look somewhat
natural. The arms end in slight claw shapes as hands to add some visual interest (see fig
10
Figure 10: Left: Mammal Legs, Right: Insect Legs
11).
When adding multiple tails or heads to a creature they need to spread around an origin
point so each one is separate. This should look something like the tails on the Ninetails
model from Pokémon Lets Go Eevee (see fig 12).
Although working in 3D the parts only really need to rotate on the 2D x and y plane.
Starting in the direction (1, 0) The tails and necks were rotated anti clockwise by the
angle θ, which is calculated using the equation:
π
θ= (n + 1) (2)
tot + 1
where tot is the total number of tails or heads and n is the current one. The actual
rotation was calculated using:
This gives us the direction that the current tail. A diagram of how this should work
for three tails is shown in figure 13. The actual output for 3 tails can be seen in figure
14.
Because the direction is only being calculated in 2D space the loops on the end of
the monkey and cat tails slightly deform one the outside tails but the variation looks
nice aesthetically so this is kept. The heads are attached to the end on the rotated necks
without any rotation themselves as these should be positioned straight forward, so these
do not have any deformation as can be seen in figure 15.
11
Figure 11: Pictures showing of creature arms
Figure 12: Pictures of Ninetails from Pokeḿon Lets Go Eevee taken on my Nintendo
Switch
12
Figure 13: Diagram of angles being calculated for 3 tails or heads
13
Figure 15: 3 Headed Creature with XL Mammal legs
Three different types of tails were implement in the program. Horse, Dog, Monkey and
Cat. With horse tails pretty much going straight down and dog tails going straight up.
Monkey and Cat tails are also very similar with monkey tails spiraling forward and cat
tails spiraling backwards.
This spiral was created using the function for a general Archimedean spiral:
1
r = a + bθ c (4)
a = 1, b = n/9, θ = 2 ∗ π + pi n9
where n is the number through the loop. To change the spiral size depending on tail
length r is multiplied by the tail length over 50. All the points need to be moved by the
first point calculated in order to have them line up properly with the end of the tail.
The z value for the tail is equal to rCos(θ) and the y value is rSin(θ). This will fully
create the spiral (see fig 14) the only difference between Monkey and Cat tails is whether
the z value is added to or taken away from.
14
Figure 16: A creature generated using the random function
15
Figure 17: An image of the Creature Generator program with UI
2.4 UI
A UI was added creatures could be continually generated within the program. It’s a
pretty simply UI with sliders and drop down menus representing all the parameters.
The Parameters have the same limits as the random function, but they don’t have the
conditions to stop ugly clipping. When the random function is used, the values are copied
over to the sliders and drop down menus so it is possible to see the values output by the
random. It is also possible from this menu to change the marching cubes grid size and
thus make more or less detailed creatures. This ranges between 0.1 and 1 as below, 0.1
and there can start to be some out of memory errors for bigger creatures and above 1 the
creature is virtually unrecognizable.
3 Conclusion
While it is certainly possible to create creatures with recognisable features using this
method it takes a long time to create them and they aren’t very detailed. The time taken
to generate the creature and the mesh is far to long to be useful in a game scenario,
however it may be possible to speed this up, perhaps using an algorithm other than
marching cubes, or using parallel programming. The big issue with the marching cubes
mesh is the holes within it, although these are not easily fixable it will be possible.
Aesthetically the creatures look fine, they might perhaps fit in a very stylized old looking
16
3d game. Because of the limitations with the size of the grid and also the fact the there
each body part only has one size of metaball not a lot of detail can be achieved. Overall
this may be a good place to get creature inspiration from but at this stage would not be
able to be used in it’s entirety.
4 Future Work
There are many ways to continue this project. Another algorithm for building the mesh
could be looked into, such as marching tetrahedrons, which is similar to marching cubes
but has no ambiguities which should stop there being any holes. Parallelism could be
used to speed up the overall process of creating the creature. The creature could be rigged
and animated, allowing it to be used in animations, or if the process overall process can
be sped up, video games. A shader could be created to attempt to make the blocky
texture look more smooth. Or an algorithm could be created to procedurally texture the
generated creatures.
17
References
Hecker, C. (2011). My liner notes for spore. Retrieved 2018-10-08, from
http://chrishecker.com/My liner notes for spore#cite ref-4
Hudson, J. (2013). Creature generation using genetic algorithms and auto-rigging (Un-
published doctoral dissertation). Msc. Thesis, NCCA.
Long, Z., & Nagamune, K. (2015). A marching cubes algorithm: application for three-
dimensional surface reconstruction based on endoscope and optical fiber. Informa-
tion, 18 (4), 1425–1437.
Unity. (2018). Unity. Retrieved 2018-12-19, from https://unity3d.com/
Wong, J. (2014). Metaballs and marching squares. Retrieved 2018-10-09, from
http://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/
18
Appendices
A Online Project Diary
https://printinglines.weebly.com/agediary
B Learning Agreement
19
SET10110 - Advanced Games Engineering project
Learning Agreement
Study Title:
Creating Procedurally Generated Creatures
Rationale
I am personally interested in procedural content generation. I have spent a lot of
time in the spore creature creator and I have become interested in how it works.
Other procedurally generated creatures such as those in No Man’s Sky and
Starbound use many pre-created assets for different parts of creatures and
combine them to create new creatures. While to an extent Spore does this also,
the main body of the creature is formed with metaballs. I think it will be interesting
to try and create full creatures with no pre-created assets in a similar way to how
Spore creates its creature’s bodies.
Aims
My general aim is to use parametric generation to create a creature base and
then interpretative generation to give that base volume.
Preliminary work
During the exploratory phase, I investigated how other people had gone about
procedural creature generation, particularly into how Spore generated its
creatures. From that I developed an idea of what I thought would be an
interesting way to generate creatures. My report (attached) gives details on what I
found out from my research and also gives details on the specific algorithms I
looked into that will be helpful for my work. Also I followed a Unity tutorial
(https://catlikecoding.com/unity/tutorials/) on how to create my own meshes in
unity so I will be able to begin implementing metaball code.
Plan
Assessment
Work has been done previously on how to generate creatures from given
parameters. Hudson (2013) uses Houdini and python to generate creatures based
on many given parameters. Parameters include what kind of creature limb it is
creating (e.g. bipedal, insectoid), this adds an extra layer of interest and variation, so
creatures are more believable.
Each creature described in Hudson’s (2013, p.12) paper is made of multiple
segments. These segments are aligned based on the positioning of the other
relevant body parts.
The creatures made by this generator are displayed using primitive spheres and
tubes. These shaped are resized by the algorithm so they arrange to form a good
base for the creature. These models are then taken to a 3D modelling program to
create more detailed interesting meshes based on the base generated (Hudson,
2013, p. 25).
MetaBall Generation
Spore creates its creature bodies using metaballs. Chris Hecker wrote a blog post
detailing his contributions to spore including his work with metaballs. Hecker used
metaballs to create what he calls the creature skin (Hecker, 2011, para. 6). Despite
being made up of metaballs, which are individually very round, Hecker managed to
create quite smooth looking creatures (see fig. 1).
Figure 1: Hecker, 2011, Textured Spore Frog
Hecker comments that metaballs lack the control you can get from regular 3D
modelling, but this was better for spore as it made the creature creator simpler to
use.
Papers that were helpful in Hecker’s (2011, para. 10) metaball use were Triquet,
Meseure and Chaillou (2001) and Moore and Warren (1995). The former wrote a
paper investigating creating polygons for implicit surfaces quickly. This paper works
with Marching Cubes, an algorithm that quickly works out the direction of surfaces
based on what edges of a grid of cube are inside the shape. This creates a
reasonably smooth looking surface to shapes in real time.
The paper by Moore and Warren (1995) helped Hecker (2011) create good quality
triangle meshes without any unneeded excess geometry.
Marching cubes seems like it would be a helpful algorithm to look into for working
with metaballs. Spore doesn’t use this algorithm as when work began on the
creature bodies there was a patent preventing the use of Marching Cubes. Jamie
Wong (2014) made a blog post explaining the maths behind metaballs in 2D
including the Marching Squares algorithm. Understanding how this works in 2D gives
the base for how to expand to work in 3D with Marching Cubes.
The main issue with the Marching cubes algorithm is the ambiguity you can get with
the separations calculated within the cubes. This ambiguity is well explained in the
paper Fast Polygonization of Implicit Surfaces (Triquet et al. 2001).
References
Hecker, C. (2011). My Linear Notes for Spore. Retrieved October 8, 2018 from
http://chrishecker.com/My_liner_notes_for_spore
Wong J. (2014). Metaballs and Marching Squares. Retrieved October 9, 2018 from
http://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/