Univ Insubria
scene composition:
the Scene Graph
Marco Tarini
Recap:
3D Spatial Trasforms
Math functions
input: 3D point / 3D vector
output: 3D point / 3D vector
E.g.:
Translation, scaling, rotation, various deformations…
They model:
movement (traslation)
re-orient in space (rotation)
Scaling things up / down (scaling)
isotropiche (uniformi) o anisotropiche (che deformano)
etc:
Flattening (from an object to its shadow), deforations…
Thus, can be applied to e.g 3D models (apply it to evey vertex position and normal…)
These are “rigid”
(aka “isometries”)
Recap: how to represent a 3D Spatial Trasforms
Many different possible internal representations:
(4x4 matrices, quaternions, axis+angle, Euler angles)
Things to remember:
Super-light in memory (few 10s of bytes)
Quick to apply to entire models (thanks to the GPU)
Done on-the-fly during rendering
We can efficiently:
Interpolate between two (aka “blend” / “mix” / “lerp”)
invert (find the opposite transform)
cumulate (find A*B)(«they are closed w.r.t. = composition»)
Can be seen as a change of Coordinate System
(at least, the ones we are interested in: “affine” ones)
Composite Scenes:
Meta objects made of many 3D models
In games: the virtual 3D environment
E.g.: a city, a room, the, etc.
ma non solo: un personaggio (modelli 3D per vestiti, accessori), un arnese (modelli 3D per sottopezzi)
Scena composta da molteplici istanze dello stesso modello
idea: evitare di replicare in memoria lo stesso modello
associare una trasformazione diversa ad ogni istanza
Compositing scenes
spazio mondo (globale) spazio oggetto ruota 1 spazio oggetto automobile
Scene graph
T0
T1 T2
T3 T4 T5 T6
Positioning of the red car (w.r.t. the world)
Positioning of the 1st wheel (w.r.t the red car)
Nella scena:
- 3 istanze dello stesso modello 3D di auto - 3x4 istanze dello stesso
modello 3D di ruota
Scene graph
T0
T1 T2
T3 T4 T5 T6 Positioning of the red car (w.r.t. the world)
Positioning of the 1st wheel (w.r.t the red car)
spazio mondo
Scene graph
spazio ogg. 1
spazio
ogg. 4 spazio ogg. 5
spazio ogg. 6
spazio ogg. 7 T0
T1 T2
T3 T4 T5 T6
spazio ogg 3 spazio
ogg 2
world frame
Scene graph
Obj frame
Obj
frame Obj frame
Obj frame
Obj frame T0
T1 T2
T3 T4 T5 T6
Obj frame Obj
Frame T0*T3
T0
T1 T2
T3 T4 T5 T6
Scene graph:
a node with the camera
World space
V
View space
= ( T2 x T8 )-1
= ( T8 )-1 x ( T2 )-1
camera T8
Example
world
B
E F
G
T0 T1 T2
T3
T4
T5
T6
C D
H L
T7
Scene Graph : la struttura dati
Nodo camera:
nodo che determina la posizione della camera
sua trasf globale = inversa della matrice vista
Mutare dinamicamente le trasformazioni?
es tramite script
animazione “cinematica” (ci torneremo)
Scene graph
Struttura ad albero (cioè gerarchica)
Nei nodi
(istanze di) modelli 3D
es: riferimenti a modelli
o anche: luci, telecamera…
Negli archi:
trasformazioni
Modellare una scena 3D in un game 1/3
Es, parte del level design nei games
Separazione task:
modellatori di «scene props»
producono i modelli 3D da comporre, es le case, muri
(+ texutres etc)
«sceners» modellatori di scenes
compongono i modelli in uno Scene Graph (assegnando una trasformazione x nodo)
[ DEMO ]
Modellare una scena 3D in un game 2/3
Asset addizionali produrre
la Collision Mesh (un Geometry Proxy)
per ogni scene-prop!
automatizzabile? non bene
per: motore fisico,
(ma anche: visibility computation, gameplay…)
la Navigation Mesh (aka AI mesh)
1 per ogni scena
per: AI
automatizzabile? non bene
Modellare una scena 3D in un game 3/3
Asset addizionali produrre
Scripts ?
task del level designer
Sky box ,
Outer terrain
mesh…
…
come struttura dati
Ogni engine / libreria, la propria soluzione
No standards
ma Ǝ formati files che possono includere scene graphs: es. COLLADA
Idee ricorrenti:
classe nodo:
contiene trasformazione (locale) al padre
e links (es. puntatori) a padre/figli/assets
trasformazioni globali computate al volo
camera come nodo speciale
ottimizz per sotto-alberi ripetuti (varie soluz)
Es: una tavola imbandita
Avendo “prop” Meshes:
piatti, forchette, coltelli
sedie
tavoli
parete
lampadari
Scenegraph da editare
con istanze ripetute per i sottographi
Es: una tavola imbandita
Mondo (scena)
Coppia
di Piatti Coltello Bicchiere Forchetta … Sedia Coperto
Tavolo
Tavolata Stanza
Posto
a Tavola Posto a
Tavola …
Tavolata
Fila
di luci Sei
pareti Fila
di luci
LuceLuce Luce …
Es: una tavola imbandita
In Unity:
class Transform
Represents one Node of the SceneGraph and the associated Transfromation
It stores:
1. Pointers
to father, to children (array),…
2. The Spatial Transformation itself, stored as a:
Translation / Position “position” (a vector)
Rotation / Orientation “rotation” (a quaternion)
Scaling / Size “scale” (a vector: non-uniform!)
3.
Flags, ect e.g: “has Changed”
In Unity:
class Transform
The Spatial Transformation itself can be accessed directly accessing to its fields
“localPosition”, “localRotation”, “localScale”
trasfromation to father, what is actually stored
the GLOBAL transformation can also be accessed
“position”, “rotation”, “scale”
(feels like setting / reading a field, but it is acutally invoking setters/getters)
what does it do really?
wait, it doesn’t work for “scale”!
why? (because anisotropy of course)
In Unity:
shared subtrees
They are called “prefabs”
See Demo
class Transform
It is a component of a GameObject
(“GameObject” = just a container for components)
Anything associated to that node is other components of that game-objects
“Meshes” (to display at this nodes) animated or static,
“Cameras”: they can produce a rendering
“RigidBodies”: objects controlled by the physics
“Colliders”: Collision Proxies
“Particle systems” : (the “emitters” of particles)
Sound producers / receivers
… Script etc etc