Models and Scene Graphs - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Models and Scene Graphs

Description:

... this scene? Scene Graphs. Items in a Scene Graph. Geometry ... Collection of geometry that moves together. Bones. Representation of the Hierarchical Structure ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 17
Provided by: cbo4
Category:

less

Transcript and Presenter's Notes

Title: Models and Scene Graphs


1
Models and Scene Graphs
  • Modeling for Games
  • Scene Graphs
  • Model Manipulation and XNA
  • Bones
  • Rendering

2
Models and Scene Graphs
How might you describe this scene?
3
Scene Graphs
4
Items in a Scene Graph
  • Geometry
  • May be instances
  • Transformations
  • Place geometry where we want it
  • Groups
  • Group geometry together
  • Lights
  • Cameras

It looks like a tree in 3DS Max, but its
actually a graph, since instances are really
the same graphical object. Scene graphs organize
our data into a structure.
5
What XNA does (by default)
.FBX File with scene graph structure
Content processing
Model
Meshes Collection of geometry that moves together
Bones Representation of the Hierarchical Structure
The model is flattened to a single list of
meshes. The bones retain the tree structure from
the scene graph. Later well do our own content
processing and maybe do this differently.
6
What a Bone is
  • Each Node gets a ModelBone
  • Each has a transform that places the node
    contents relative to its parent This is called
    the local transform
  • The Absolute Transform for a Lamp Shade
  • Product of 4 transformation matrices
  • LampShade TableLamp Furniture Bedroom

The absolute transforms transforms the model part
to the model coordinate system
TT
7
Bones
Parent
Name
ModelBone
Transform
Child (ModelBone)
Child (ModelBone)
Meshes
public void CopyAbsoluteBoneTransformsTo(M
atrix destinationBoneTransforms)
int count this.bones.Count
for (int i 0 i lt count i)
ModelBone bone this.bonesi
if (bone.Parent null)
destinationBoneTransformsi
bone.transform
else
destinationBoneTransformsi bone.transform
destinationBoneTransformsbone.Parent.Index

Microsoft conveniently provides the bones in
topological order
8
Our DrawModel function
private void DrawModel(GraphicsDeviceManag
er graphics, Model model, Matrix world)
Matrix transforms new
Matrixmodel.Bones.Count
model.CopyAbsoluteBoneTransformsTo(transforms)
foreach (ModelMesh mesh in
model.Meshes)
foreach (BasicEffect effect in mesh.Effects)

effect.EnableDefaultLighting()
effect.World transformsmesh.ParentBone.Index
world effect.View
game.Camera.View
effect.Projection game.Camera.Projection
mesh.Draw()

9
Why do we care?
  • What if I want to manipulate part of a model?
  • I have rotated the two wings into attack
    configuration

transformswing1 Matrix.CreateRotationY(wingAn
gle) transformswing1 transformsw
ing2 Matrix.CreateRotationY(-wingAngle)
transformswing2
10
Manipulating Part of the Model
  • Simple Version
  • Works only if bone has no children

transformswing1 Matrix.CreateRotationY(wingAn
gle) transformswing1
int count model.Bones.Count
for (int i 0 i lt count i)
if (i wing1)
transformsi Matrix.CreateRotationY(wingAng
le) else
transformsi Matrix.Identity
ModelBone bone model.Bonesi
if (bone.Parent null)
transformsi bone.Transform
else
transformsi
bone.Transform transformsbone.Parent.Index
  • Full Traversal Version
  • Transforming the bone also transforms its
    children
  • Other ways are possible that do less runtime work

11
Another way to manipulate the model
// Member variables private Model digger private
ModelBone armBase private Matrix
armBaseBind private float angle 0 private
float rate 0.25f // In LoadContent armBase
digger.Bones"Arm1-base" armBaseBind
armBase.Transform // In Update double delta
(float)gameTime.ElapsedGameTime.TotalSeconds ang
le (float)(2 Math.PI rate
delta) armBase.Transform Matrix.CreateRotationZ
(angle) armBaseBind
12
Digger
z
z
x
x
z
x
(translate) z
TT
13
What to rotate around
14
Later
  • Well do our own content processing
  • We can deal with the structure any way we want
  • Things we might do
  • Extracting things that dont actually display
  • Dealing with transparency
  • Custom rendering effects
  • Flexible objects
  • Visibility determination

15
Model, ModelMesh, and MeshParts
Model
Name
ParentBone
Bones (ModelBone)
Meshes (ModelMesh)
BoundingSphere
MeshParts (ModelMeshPart)
Effects
Vertices
Vertex Indexes (Triangles)
Effect
An Effect controls how a primitive is drawn on
the screen. It sets colors, textures, etc.
16
Our DrawModel function
private void DrawModel(GraphicsDeviceManag
er graphics, Model model, Matrix world)
Matrix transforms new
Matrixmodel.Bones.Count
model.CopyAbsoluteBoneTransformsTo(transforms)
foreach (ModelMesh mesh in
model.Meshes)
foreach (BasicEffect effect in mesh.Effects)

effect.EnableDefaultLighting()
effect.World transformsmesh.ParentBone.Index
world effect.View
game.Camera.View
effect.Projection game.Camera.Projection
mesh.Draw()
Write a Comment
User Comments (0)
About PowerShow.com