MSC Thesis: Crowd Simulation Implementation in Houdini FX Using Custom VEX Operators
MSC Thesis: Crowd Simulation Implementation in Houdini FX Using Custom VEX Operators
!
!
!
!
!
!
!
MSc!Thesis!
!
!Crowd!Simulation!&!Implementation!in!
Houdini!using!custom!VEX!SOPs!
!
!
!
(Nomish(Bhardwaj,(i7222320,(MSc(Computer(Animation(&(
Visual(Effects,(NCCA,(Bournemouth(University)(
(
(
(
(
(
December(2013(
INDEX&
&
&
Title&
!
&
!
&
!
Chapter&1&
&
!
&
1.1 Introduction!&!Abstract!
1.2 Related!Work! &
!
&
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
!
Page&
!
!!
!
!
!
01!
03!
!
!
!
!
Chapter&2&
!
!
!
2.1!Background!&!Theory!
07!
!!!!!!!!!2.1.1!Tools!of!Choice:!Houdini!&!VEX!
07!
!!!!!!!!!2.1.2!Overall!Implementation!of!System! 10!
!!!!!!!!!!!!!!!!!!!!I!Agents!
11!
!!!!!!!!!!!!!!!!!!!!I!Simulation!
12!
!!!!!!!!!!!!!!!!!!!!I!Geometries!
15!
!
!
2.2!Behaviors!&!Mind!Implementations!
16!
!!!!!!!!!2.2.1!Simple!Behaviors!
17!
!!!!!!!!!!!!!!!!!!!!I!Separation!
17!
!!!!!!!!!!!!!!!!!!!!I!Alignment!
18!
!!!!!!!!!!!!!!!!!!!!I!Cohesion!
19!
!
!
!!!!!!!!!2.2.2!Mind!Algorithms!
20!
!!!!!!!!!!!!!!!!!!!!I!Simple!Mind!
21!
!!!!!!!!!!!!!!!!!!!!I!Priority!Mind!
22!
!
!
!!!!!!!!!2.2.3!Advanced!Steering!Behaviors!
23!
!!!!!!!!!!!!!!!!!!!!I!Steer!Arrive!
23!
!!!!!!!!!!!!!!!!!!!!I!Steer!Wander!
24!
!!!!!!!!!!!!!!!!!!!!I!Obstacle!Avoidance!
25!
!!!!!!!!!!!!!!!!!!!!I!Steer!On!Surface!
26!
!!!!!!!!!!!!!!!!!!!!I!Path!Following!
27!
!
!
!
!
Conclusions&&&Future&Work&
28!
I Screenshots!
28!
I Future!Work!
30!
!
References&
!
!
!
ACKNOWLEDGEMENTS&
!
!
!
I!would!like!to!thank!Professor!Jon!Macey!for!providing!me!with!inspiration!and!
guidance!throughout!the!course!of!developing!this!project.!I!would!also!like!to!
thank!Professor!Phil!Spicer!for!providing!advice!that!helped!me!towards!the!
completion!of!this!project.!Finally,!I!would!like!to!thank!all!my!professors,!
classmates!and!friends!at!the!NCCA!who!have!been!a!support!along!the!duration!
of!MSc.!
1!
Chapter 1
2!
[Figure 1.2: Swarm of ants, courtesy Wikimedia] [Figure 1.3: Swarm of bees, courtesy BBC]
As can be observed from the above images (Figures 1.2 & 1.3), such simple
behaviors can also be observed in swarms of insects, even bees.
With the advancement in technology, there is a co-existing rise in demand to
emulate real life like behaviors in the virtual computer graphics environment.
With the technology available at hand, this can and has been made into a
reality. Various stand-alone off-the-shelf softwares such as MASSIVE do exist,
but nevertheless, large scale industries such as Moving Picture Company,
Double Negative, Industrial Light & Magic all build their own software for
simulating behaviors of crowd. This offers a much higher level of flexibility for
individual firms, also reducing the licensing and costs related with purchasing
proprietary software.
Simulating a crowd has numerous advantages as opposed to conventionally
animating every individual element of a crowd. The requirement of using a
crowd simulation comes in when a particular shot/scene needs a number of
characters animated, more than those that are viable to be individually worked
upon.
My masters project aims to simulate these crowd behaviors on a number of
agents, in Side Effects Houdini FX, using custom VEX operators being
cooked in a SOP Solver, within a DOP network. The following thesis will
provide the specifications and documentation of the same, further explaining
the idea, theory and algorithms behind the whole system.
The project was made on Side Effects Softwares Houdini 12.1.77, running on
a Mac OS X v10.9 platform.
3!
4!
5!
As can be seen in Figure 1.6, MASSIVE also employs a nodal tree network to
control agents and their behaviors.
Another software package, essentially a plug-in for Autodesk Maya exists by
the name of Golaem Crowd. A French-based company that goes by the same
name Golaem developed it. It was released in 2011 and has since then been
used in production for titles such as Asterix and Obelix: God Save Britannia
(2012) and for simulating zombie crowd in the film Warm Bodies (2013).
On similar lines, Basefount has developed a plug-in for Maya, named MiArmy,
for controlling crowd-based behavioral simulations and creature physical
simulation/rendering. Miarmy uses fuzzy logic with no requirement of
programming and/or complexities of connecting nodes and supports all popular
renderers such as Renderman, Mental Ray, V-Ray etc.
Crowd Simulation systems hold value outside of the animation/vfx industry as
well. Such systems are used to build numerous simulations such as crowd
evacuation models, to simulate pedestrians/traffic systems, in medical and
science research areas, etc. One such simulation system was developed in
Karlsruhe, Germany by PTV group (Planung Transport Verkehr AG). Named
PTV VISSIM, it uses the concept of micro-simulation, i.e. simulating each
element/agent individually, this includes all interactions and properties of
behaviors being simulated at an individual level. It is widely used to simulate
traffic, including vehicles (cars, trucks etc.), public transport (trains, trams,
buses), even two-wheelers/bicycles and pedestrian behavior. This holds
advantage in fields such as transport planning, simulating zebra
crossings/pedestrian behavior at traffic lights, urban planning, fire/emergency
escape planning etc.
6!
The above image (Figure 1.7) shows a simulation and behavioral interaction
between cars and pedestrians crossing a traffic signal.
7!
Chapter 2
[Figure 1.8: A nodal network view for procedurally generating a wall in Houdini]
8!
9!
10!
11!
Agents
Agents can simply be defined as a sole instance of an autonomous character
(Schnellhammer! 2011). These could range from something as small as
ants/insects to more complex human beings. These could also be swarms of
bats or a flock of birds or even vehicles. Different agents will behave
differently, by setting custom parameters and behaviors.
In our case, all agents are represented using geometric points. Our behavioral
algorithms are solved on these points and their movement is altered
accordingly. Geometry is then copied onto these points just as a final look. This
geometry can be replaced with imported BGEO geometries or a string of
geometries can be imported and time-shifted in such a way that it follows an
animation-cycle movement instead.
To generate geometry points for our agent, we start with scattering points over
a grid. Houdini provides with a scatter SOP that enables us to scatter points
over geometry, thereby converting the geometry into a set number of points (as
specified in the scatter SOP). This works well, but has a drawback to it; it does
not uniformly scatter points. For this I have used an external Houdini Digital
Asset called csUniformScatter (Schnellhammer 2010). Instead of utilizing an
external digital asset, we can also use the Compute Number of Points option
of the Scatter SOP but it is still advantageous to use the asset in order to have a
more even/uniform scatter by increasing the Distribution Iteration value of
the asset.
These scattered points are then projected onto the ground-plane using a Ray
SOP. Ray SOPs will scatter the primitives onto the specified input, ie., the
ground-plane in this case. Initial attributes are set using the AttribCreate SOP,
and also using a Point SOP, the initial velocity, scale and up-vector values are
set (Figure 2.2).
12!
Once we have the initial system of geometry points, this geometry is called into
a DOP Network, where the actual simulation happens.
Simulation
A DOP network was created for handling point manipulations and updating
positions, rather than a POP Network (as discussed earlier). Within the DOP
Network, the initial state of the agents, more specifically, the point geometry
created before, is imported into a SOP Solver using a SOP Geometry node
(Figure 2.3).
A SOP Solver DOP lets the DOP simulation use a SOP network to evolve an
objects geometry over time. (Side Effects Software 2011)
This means with the SOP Solver we can get the last time-step of our geometry,
modify it and then pass it to our next time step. (Schnellhammer!2011)
The SOP network in question, is nothing but a chain of SOPs, in this case, the
custom VEX SOPs coded in VEX, comprising of our Behaviour Network.
13!
The output of this is then called into our initial agent SOP network using a
DOP Import SOP. This is where different geometries are copied onto the
agents geometry points. (Figure 2.5)
14!
Once the geometry was copied onto each point, the new geometry moved on
the same position as that of the agent points, with their positions getting
updated simultaneously with those of the agent point positions. This does
simulate movement, however, the agents do not rotate with. For this reason, a
VOP SOP is created, used to add a rotation attribute to the geometry points
(Figure 2.6). As attributes created are at a global level, this can be accessed
within our simulation.
ALGORITHM:
! VEX function lookat is performed with its To Location set as heading
and passing Up vector
15!
16!
17!
In a crowd, the members of a crowd normally tend to not get really close to one
another, and steer away from each other if they get too close. They tend to
maintain a certain space around them, and keep a certain distance of separation.
As can be seen in (Figure 2.9), an average Steer Separation force is calculated,
comprising of an average steer force that moves away from the neighboring
agents, and this force is applied to the current agent. Also, without the
application of such a steering behavior, the agents will overlap positions, or if
used in combination with a behavior such as cohesion or point-of-arrival, they
would all swarm into one single point, creating a vortex like appearance.
Underlining the importance of this separation behavior, a VEX operator was
created.
ALGORITHM:
! Define a Search Radius around the current agent point position to
search for neighbours
! Get agent points with positions within that radius (using point cloud
lookup)
! Compute the difference between a found points position from the
current point position and negate it (since it will be an opposing steer
force)
! Divide this difference by the distance between the points (closer the
points, more the force and vice versa)
! Do same for all found agent points within the search radius and store
the sum of these steering forces
! Divide sum by the number of neighbour agents found, this is the average
steer Separation force
! Clamp/Contain forces accordingly
18!
Alignment:
The behavior of Alignment makes all the agents in the entire crowd steer in a
similar direction. Every agent within the crowd will have some defined
direction. In order to steer the crowd along a common direction, the agents
within a crowd try to align themselves with each other, according to the group
as a whole, or simply with the agents as seen within the field of view of the
current agent.
As (Figure 2.10) suggests, the current agent in action will calculate an average
direction of its neighbor agents and will steer towards the calculated average
direction.
ALGORITHM:
! Define field of view angle
! Get agents within the affected angle
! Sum up their velocities
! Divide sum by number of neighbor agents found
! Found result will be the average steer Alignment force. Clamp
accordingly.
19!
Cohesion:
If we observe crowds in real life, the behavior of cohesion is quite significant.
The members of a crowd show a grouping behavior, that makes the group act
as a single whole cohesive unit. Each member of the group is consciously
aware of not steering away too far from the group. This is done by maintaining
a cohesive force amongst all agents within the group. Cohesion behavior makes
every agent calculate an average cohesive steer force and steering towards a
direction with that force applied. This is simply done by checking the positions
of the nearby agents.
As can be seen in (Figure 2.1), the agent in question searches for neighboring
agents in a defined area around it, depending on the way it perceives the
environment, and steers towards an average position, closer to the found
neighbors thereby forming a group.
ALGORITHM:
! Define field of view angle
! Get agents within the affected angle
! Sum up their positions
! Divide sum by number of found agents
! Calculated result will be the average steer Cohesion force. This can be
clamped accordingly.
Furthermore, by adding a viewing-angle among the flocking behaviors, i.e., by
making the agents respond to flocking behaviors only within a field of view,
we get queuing behaviors. (Reynolds 1987)
20!
This is done by doing a simple vector addition of the current velocity with the
vector forces being applied to it. These vector forces are the computed behavior
forces calculated by the behavior nodes. Once the total steer force is calculated,
the position of the agent is updated on a per-frame basis, dividing the
calculated sum by the frame-rate-per-second (FPS) value and adding it to the
current position of the agent. Hence, the agent will accelerate towards the
direction of the steering force applied to it (Figure 2.12). Houdini provides us
with a variable, TimeInc, this variable provides us with the FPS value. (Side
Effects Software 2011).
Thats just the very basic level of calculating the applied forces, these forces
need to be sorted out according to different priorities. Prioritizing behaviors
help simulate real-world phenomena better, just what an actual mind or
conscience would do. As mentioned before, all calculated behaviors have been
provided with different priorities, Based on these priorities, our steerSolver
VEX SOP will compute a final steering force that it will in turn, apply to each
agent. VEX works in a Single Input Multiple Data (S.I.M.D) form, this means
one must work on the context of a single agent being compared with the rest
using point clouds to lookup, and using the mind algorithms to sort out the
application of behavioral steer forces after which Houdini does the separate
computations for all agents and applies these computations to them using the
behavioral algorithms defined. In order to compute steering forces based on
priorities, a simple mind calculation and a priority mind calculation is
21!
Simple Mind:
As every behavior has a priority attached to it, the simple mind calculates the
steering force by simply multiplying the calculated steering forces with their
respective priorities and computes a final sum value. If a steering force has a
higher priority, a larger amount of that force would be used, and vice-versa, if a
steering force has a lower priority, a lower amount of that steering force will be
used.
As can be seen in the above graph (Figure 2.13), a simple mind will compute
different behaviors depending on their priorities, even if the total priority count
goes beyond unity. Hence, this calculation will simply sum up the product of
steering force behaviors (Cohesion, Arrive, Separation) with their respective
priorities (0.3, 0.2, 0.6). Simple Mind in this way can calculate steering fores
based on different weights.
ALGORITHM:
! Find out the number of behaviours
! Get steer forces
! Get priority values
! Save sum of products of steer forces and priority values
22!
Priority Mind:
Unlike a simple mind, a priority mind sets a maximum priority and does not let
the priority calculation exceed this maximum priority. The priority mind sorts
through the priorities and gives a higher weight to higher priorities and vice
versa. This is done by stacking up the priorities in order of importance, (Figure
2.14); the priority mind calculation then cuts off the priority values of
behaviors that exceed the maximum priority limit. (Schnellhammer!2011)
As can be seen by the above figure, the priority value of Separation is greater
than that of Cohesion, with priority of Arrive being least. Hence if the sum of
priorities exceed the maximum limit (1 in this case), the behavior with the least
priority will have its priority cut-off.
ALGORITHM:
! Find out the number of behaviours
! Stack priorities with their respective steering forces
! Sort this stack (Using simple Bubble Sort) such that steering forces with
maximum priority placed first and least priority placed last
! Start adding consecutive priorities from starting position of stack
! Check if sum of priorities is greater than maximum priority, if yes do
nothing
! Check if sum of next priority with current sum of priorities is greater
than maximum priority, if yes, find out the remaining priority, and
assign this as the new priority for that particular behavior force
! If none of the conditions are true, it means we are within the maximum
priority limit, and steering calculations can be done normally as in the
simple mind
23!
24!
Steer Wander:
Each member of a crowd always has a certain tendency to wander away from
the course of the desired path; this is emulated with the Steer Wander behavior.
What Steer Wander does is, it provides a steering force pointing to a random
direction and steers the agent slightly towards that random direction.
At the first implementation of this behavior, the agents were showing a jittery
movement, as they were randomly being pointed in different directions. So
instead, a slightly more advanced approach was used wherein an agent would
determine its future position (similar to the way Craig Reynolds determines
future location in Offset Pursuit behavior) and a random point would be
chosen on a circle around the future position (Figure 2.16). This point is chosen
as the final wander point to be steered towards. (Buckland 2005)
ALGORITHM:
! Find future location by getting unit vector of our velocity (ie.
Normalized vel) and multiplying with a constant value (this will be the
distance of prediction)
! Project a circle with a desired radius around the future location
! Find a random point along the circumference
! Steer to that point location
Such a behavior avoids the jittering associated with a wander movement and
makes the wandering movement smoother.
25!
Obstacle Avoidance:
In important behavior in crowd systems, obstacle avoidance ensures that the
agents avoid the obstacle objects within the environment. Obstacle avoidance is
a behavior that steers a vehicle to avoid obstacles lying in its path. (Buckland
2005)
For this purpose, obstacles of walls and columns were procedurally modeled
within Houdini. (Figure 2.17)
In order to achieve this, we fire a test-ray, (our velocity in this case) from our
agent in question, to the obstacle geometries. (Figure 2.18) Under normal
circumstances this would make our computations really slow as we compute
for all obstacle geometries, but as Houdini caches the simulations, no matter
how long it takes, the cached simulation can be played back at a real-time.
We can simply project this testing vector back on the polygon of the intersected
obstacle. This projected vector is our steering vector. (Schnellhammer!2011)
In such a scenario, if we are closer to the obstacle, the steering force will be
stronger and vice-versa, almost light a ray reflecting upon a mirror.
26!
ALGORITHM:
! Fire a test vector
! Using Houdini VEX function intersect, check for intersection point on
the obstacle. This function saves the primitive number of the obstacle.
! Use this prim number to calculate the primitive normal, using
prim_normal VEX function
! Project this test vector on the obstacle polygon using scalar projection
(ie. Dot product)
! Do same test in multiple directions
! Calculate maximum steering force between obstacles. The max steering
force would be received from the nearest obstacle
! Apply force as necessary
Steer on Surface:
In order to base our crowd agents over a ground plane, or a terrain, we need
them to have velocities projected on that ground plane. This is an important
feature in a crowd system where the agents are land-based. We do this by
projecting all positions and forces onto the ground surface.
ALGORITHM:
! Fire a test vector towards ground geometry and use intersect function to
determine the intersected points
! Do cross product of forward with primitives normal (found using
prim_normal) to get side vector
! Do cross product of side vector with normal to get a vector with
direction opposite to normal, this is the tangent vector
! To project velocity onto tangent, do scalar projection on the tangent, i.e,
calculate dot product of forward vector and computed tangent vector
! Do same for all steering forces
! Use the found normal as new up vector
27!
ALGORITHM:
! Get future position of agent
! Check whether within path radius
! If not, calculate perpendicular normal to the line segment from current
position
! Do this for all the line segments within the path
! Select line segment with shortest perpendicular normal
! Do a scalar projection on the line segment to get origin point of
perpendicular normal
! Seek towards the found normal point
28!
29!
30!
FUTURE WORK
While the current system can be used t o implement basic crowd simulations
such as populating environments, simulating animals, birds, insects,
humans/pedestrians etc, with such a system, there is significant amount of
future scope and improvements by extending the system to incorporate
behaviours such as:
-
There are many vast extensions that can be implemented by adding new and
more complex behaviors and also different mind implementations.
Another important feature is to build the entire system in such a way that it can
be used as a single cohesive digital asset, rather than using only the behavior
VEX SOPs as digital assets.
In another context, the animations added to the simulations could be
procedurally animated on a per-frame basis, giving it a far more realistic look.
REFERENCES'&'RESOURCES'
!
!
"
"
!
"
A.!Bielik!(2005).!`Kingdom&of&Heaven:&MPCs&Sword&and&Sandal&Hat&
Trick'.!Available!From:!http://www.awn.com/![Accessed!15.10.2013].!
"
C.!Kolve!(2004).!!VFX&Work.!!HP!CARSTEN!KOLVE.!Available!from:!
http://www.kolve.com/vfxwork/vfxwork.htm![Accessed!15.10.2013]!
!
J.!Haddon!&!D.Griffiths,!The!Moving!Picture!Company!(2006).!A&
System&For&Crowd&rendering.!ACM!SIGGRAPH!2006!Sketches,!
SIGGRAPH!06,!New!York.![Accessed!19.10.2013].!
"
!
A.!Bielik!(2004).!`Troy:&Innovative&E&
ects&on&an&Epic&Scale'.!Available!From:!http://www.awn.com/!
[Accessed!15.10.2013].!
!
L.!Kermel!(2005).!`Crowds&in&Madagascar'.!In!ACM!SIGGRAPH!2005,!
Courses,!SIGGRAPH!'05,!New!York,!NY,!USA.!ACM.!
"
Gu,!E.,!2004.!Crowd&Simulation:&Implementation&on&Geometry,&
Animation&and&Behavior.!WPE!II!Paper!(PhD).!University!of!
Pennyslvania.!
"
Gary,!D.,!CMI!VFX!(2007).!!Houdini&VEX&Volume&1.!Video.!Available!
From:!http://cmivfx.com.![Accessed!20.10.2013]&
"
Kewlani,!T.,!2013.!Ant&Directed&Ant&Crowd&Simulation&in&Houdini.!
Thesis!(Masters).!Bournemouth!University.&
"
Reynolds!C.W.,!1987.!Flocks,&herds&and&schools:&A&distributed&behavioral&
model,!ACM!SIGGRAPH,!Computer!Graphics,!v.21!n.4,!p.25"34.&
"
Side!Effects!Software!(2013).!Houdini:&3D&Animation&Tools.!!Software.!
Available!from:!http://sidefx.com![Accessed!23.10.2013]!
"
Schnellhammer!C.,!2010.!Uniform&Scattering&in&Houdini.!Houdini!
Digital!Asset.!!Available!from:!
http://schnellhammer.net/blog/2010/06/uniform"scattering"in"
houdini/!![Accessed!09.11.2013]!
"
TF3DM,!2013.!High&Poly&Male.!OBJ!File.!Available!From:!
http://tf3dm.com/3d"model/high"poly"male"2014.html![Accessed!
20.11.2013]!
"
Tedin,!C.,!CMI!VFX!(2013).!!Houdini&Rigging&Animation&Fundamentals.!
Video.!Available!From:!http://cmivfx.com.![Accessed!22.11.2013]&
!
&
!
&
!
!!
!
&
&
"
Schnellhammer,!C.!"!CMI!VFX!(2011).!!Houdini&Flocking&Systems.!Video.!
Available!From:!http://cmivfx.com.![Accessed!20.11.2013]&
"
Shiffman!D.,!2012.!Nature&of&Code.!1st!Edition.!Magic!Book.!Available!
From:!http://natureofcode.com/book/!
"
Buckland!M.,!2005.!Programming&Game&AI&by&Example.!Texas:!
Wordware!Publishing.!
!
!
!
!
!
!
!
!
!
!
APPENDIX'
'
'
'
Videos:!
!
1. final.mov!:!Video!result!with!10,000!(approx.)!agents!simulated!with!
arrive!and!follow!path!turned!off!
2. fastarrive.mov:!Video!result!showing!arrival!and!queuing!
behaviours!with!high!Interpenetration!avoidance!(collisions)!
3. humanwalk.mov:!Representation!of!human!walk"cycle!
4. pathfollow.mov:!Video!result!showing!path"following!behavior!
5. POV.mov:!!Accelerated!point"of"view!of!an!agent!