0% found this document useful (0 votes)
119 views25 pages

Report

This document describes a process for procedurally generating 3D creature meshes in Unity based on input parameters without using pre-made assets. It involves using metaballs and the marching cubes algorithm to generate the mesh from parameter-defined creature points for different body parts. The body parts are stored in dictionaries to allow easy resizing and different spreading behaviors. Legs, arms, tails and heads are generated based on rotation algorithms to provide variation. The goal is to eventually generate creatures in real-time for potential use in games.

Uploaded by

api-360448338
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views25 pages

Report

This document describes a process for procedurally generating 3D creature meshes in Unity based on input parameters without using pre-made assets. It involves using metaballs and the marching cubes algorithm to generate the mesh from parameter-defined creature points for different body parts. The body parts are stored in dictionaries to allow easy resizing and different spreading behaviors. Legs, arms, tails and heads are generated based on rotation algorithms to provide variation. The goal is to eventually generate creatures in real-time for potential use in games.

Uploaded by

api-360448338
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Procedural Creature Generation

Emma Parsley - 40206111

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

2.1 Metaballs and Marching Cubes


The mesh generation for the creatures was based of the way bodies where generated within
spore (Hecker, 2011). These body were created from multiple metaballs intersecting. To
generate the mesh for these metaballs the Marching Cubes algorithm will be used. This
was not the algorithm used in Spore, however Hecker admits to being unsure if this would
have been faster or slower, so Marching Cubes was chosen for this project.
For this algorithm initially the area for the creature needed to be split into grid
segments (see fig 1). The grid genarated for the creature was made to contain all points

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

2.2 Creature Generation


2.2.1 Creature Storage

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.

2.2.2 Legs Generation

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.

2.2.3 Multiple Arms

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).

2.2.4 Multiple Tails and Heads

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:

(xCos(θ) − ySin(θ), xSin(θ) − yCos(θ)) (3)

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

Figure 14: Three monkey tails as outputted by algorithm

13
Figure 15: 3 Headed Creature with XL Mammal legs

2.2.5 Tail loops

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

2.3 Random Creatures


Randomly generating the creatures was pretty simple. All the parameters for the creature
are stored as either ints or enums (which are easily cast to ints). So a random number
between the lowest reasonable value and the highest reasonable value for each parameter
is chosen.
The parameters for the enums were the amount of values within the enum. Heads
and Legs had a minimum value of 1 as these seemed like the basic building blocks of
a creature. Everything else has a minimum value of 0. The maximum parameters for
Heads and Tails were 5 and 7 respectively as this is the highest value that stops them
looking crushed. Leg and arm pairs have a max value of 4 as 8 legs is enough to make
a creature like a spider and this seemed like a reasonable stopping point for the arms as
well. The neck, torso and tail length had a maximum size of 20 as this let creatures seem
unreasonably large while also not taking too long to process.
In order to make sure the random creatures looked reasonable when they were gener-
ated and not broken, specific conditions were added. One to make sure the neck was long
enough to stop clipping if there were multiple heads. And another to make sure arms
don’t intersect with insect legs by making the torso longer.

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

Name of Student: Emma Parsley

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

Week 5-9: Generating Creature Flesh


The aim of this part of development is to write an algorithm that displays
metaballs around a few predefined creature base shapes. The body will appear
smooth and be recognisable as some sort of creature.

Week 10-15: Procedural Creature Forms


The aim of this stage of development is to create a final application that
generates a creature based on user defined parameters. The user will be able to
manipulate multiple sliders to change the form of the creature. Each generated
creature should have distinct recognisable features (legs, arms, tail, etc.)

Assessment

Deliverable 1: Generating Creature Flesh


• A Unity application where metaballs are used to form the shape of at least 3
different predefined creature structures.
o Creature should have distinct recognisable features (legs, arms, tail,
etc.)
o Creatures should appear smooth despite being made of metaballs
• Submission: end of Week 9
• Artefacts:
o A standalone executable
o Source code
o A demonstration of the application in the lab in week 9
• Out of: 40 marks
• Assessment Criteria
o Scope: How functional is the application? Does the effort required to
produce it equate to the allocated time?
o Quality: How elegant, clever, informed is the approach and its
implementation?

Deliverable 2: Procedural Creature Forms


• A Unity application that allows the user to enter parameters that will generate
a creature. The creature’s form will be generated by the code created in part
one.
• Submission: end of Week 15
• Artefacts:
o A standalone executable
o Source code
o A demonstration of program in the lab on week 15
• Out of: 40 marks
• Assessment Criteria
o Scope: How functional is the application? Does the effort required to
produce it equate to the allocated time?
o Code Quality: Is the code clear and well commented? Is the code
separated into functions where appropriate?
o Application Quality: Does the application work as intended? Does it
meet the specs for deliverable 2? Is it reliable (does it consistently work
well)?
Creating Procedurally Generated Creatures

Initial Look into Creature generation

Interpretive generation, as explained in Kate Compton’s (2017) GDC talk is


interpreting a complex structure onto a basic one. For example, taking the simple
structure of a curve and creating a brush stroke look along the curve, as it done in
programs like Tilt Brush.
Parametric is a form of generation made from parameters that can be changed
(Compton, 2017). Using both this and interpretive generation interesting creatures
can be created. The basic structure of a creature can be generated using parametric
generation to define the parts of the creature, for example how many arms, legs, tails
etc it has. This basic structure can then be interpreted using metaballs, like is done
for the spore bodies (Hecker, 2011, para. 10) to make a fully fleshed out creature.

An alternate method to create creatures would be that used by games such as No


Man’s Sky. For this generation there are many pre-created assets with descriptors
telling them what part of a creature it is. These creature parts are then assembled by
an algorithm into many different and interesting animals (Alexandra, 2016, para. 3).
This method can create more detailed intricate creatures than can be created by
metaballs but requires many premade assets to make a range of varied creatures.
For this project it makes sense to look into the interpretive method as it can be done
without the acquisition of pre-made models.

Creature Base Generation

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

Alexandra, H. (2016). A Look at How No Man’s Sky’s Procedural Generation Works.


Retrieved October 5, 2018 from https://kotaku.com/a-look-at-how-no-mans-skys-
procedural-generation-works-1787928446

Compton, K. (2017). Practical Procedural Generation for Everyone. Retrieved


October 8, 2018 from https://www.gdcvault.com/play/1024213/Practical-Procedural-
Generation-for

Hecker, C. (2011). My Linear Notes for Spore. Retrieved October 8, 2018 from
http://chrishecker.com/My_liner_notes_for_spore

Hudson, J. (2013). Creature Generation using Genetic Algorithms and Auto-Rigging.


NCCA

Moore, D. & Warren, J. (1995). Mesh Displacement: An Improved Contouring


Method for Trivariate Data. Rice University

Triquet, F., Meseure, P. & Chaillou, C. (2001). Fast Polygonization of Implicit


Surfaces. Labortoire d’Informatique Fondamentale de Lille

Wong J. (2014). Metaballs and Marching Squares. Retrieved October 9, 2018 from
http://jamie-wong.com/2014/08/19/metaballs-and-marching-squares/

You might also like