scene graphs in 3d graphics programming the structure used is a scene graph which is special tree...

31
Scene Graphs • In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene. • Typical elements include – geometries – positional information – lights – fog

Post on 19-Dec-2015

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Scene Graphs• In 3D Graphics programming the

structure used is a scene graph which is special tree structure designed to store information about a scene.

• Typical elements include– geometries– positional information– lights– fog

Page 2: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Recap

3D scene

Camera

2D picture

Content of 2D picture will depend on: • camera parameters (position,

direction, field of view, ...), • properties of scene objects, • illumination, ...

Camera paradigm for 3D viewing

• 3D viewing is similar to taking picture with camera:– 2D view of 3D scene

Page 3: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

IntroductionMain steps in 3D graphics viewing:

• Scene specification• View specification

– Specification of viewing parameters

– Projection: scene mapped onto 2D view window

– Clipping: removal of primitives that are outside

• Display

Page 4: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Coordinate Systems

• World coordinate system: reference frame for specification of (relative) position / orientation of viewer and scene objects (size?)

xw

zw

yw

Scene (head looking at bird)

xm

zm

ymHead model

xm

zm

ym

Bird model

Page 5: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Coordinate Systems• Viewing coordinate system: reference frame for

specification of scene from viewpoint of camera / viewer

xw

zw

yw

xm

zm

ym

xm

zm

ym

Taking a view of scene (head looking at bird)

Camera

yv

zv

xv

Page 6: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

xw

zw

yw

World coordinates

Viewing PipelineCoordinate transformations:

– generation of 3D view involves sequence (pipeline) of coordinate transformations

Camera

Modelling coordinates

3D object

2D picture

Device coordinates

xm

zm

ym

xmzm

ym

xm

zm

ym

xvzv

yv

Viewing coordinates

Page 7: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

A scene graph is a data structure used to hold the elements that make up a scene. It may be either a tree or a Directed AcyclicGraph (DAG).

The tree and DAG are similar, except that in the DAG the branches may possibly grow back together.

Page 8: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Trees

• Start at the root and move outward towards the leaves. Normally shown with the root at the top and the branches at the bottom.

• A node is a part of this tree that may have other nodes or leaves underneath it, a leaf cannot have other nodes or leaves under it.

• There is only one path from a leaf to the root of the tree. There are no "cycles", if you move outward along the branches, you never loop back around to end up at the root again.

Page 9: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Directed acyclic graph (DAG)• Directed means that the

parent-child relationship is one-way, Acyclic means that there can’t be loops, i.e. child cant be one of its own ancestors

• Like a tree, except maybe the branches grow back together sometimes, so that following a different sequence of branches outwards from the root might lead you to the exact same leaf.

• Branches never grow in a loop, though, so as long as you keep moving outwards, you always end up at a leaf eventually:

Page 10: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Nodes• The scene graph contains 'nodes' such as shape,

light, camera, etc. • The tree structure is important because it allows the

scope of influence of scene parameters to be clear and unambiguous.

• Nodes which have an unspecified number of children below them are known as Group nodes. One of the most important type of nodes is a Transform Group, this modifies all of the shapes below it by transforming them via a 4x4 matrix.

Page 11: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

The Scene Graph• The scene graph captures transformations and

object-object relationships in a suitable structure:

Robot

BodyHead

ArmTrunkLegEyeMouth

Objects

Instancing(i.e, a matrix)

Legend

World

Page 12: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Traversing the Scene Graph• Traverse the scene graph in depth-first order,

concatenating and undoing transforms:– For example, to render a robot

•Apply robot -to-head matrix•Apply head -to-mouth matrix

–Render mouth•Un-apply head-to-mouth matrix•Apply head-to-left eye matrix

–Render eye•Un-apply head-to-left eye matrix•Apply head-to-right eye matrix

–Render eye•Un-apply head-to-right eye matrix

•Un-apply robot-to-head matrix•Apply robot-to-body matrix

Page 13: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

The Scene Graph in OpenGL

• OpenGL maintains a matrix stack of modeling and viewing transformations:

ArmTrunkLegEyeMouth

Head Body

Robot

Foot

MatrixMatrixStackStack

VisitedVisited

UnvisitedUnvisited

ActiveActive

Page 14: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

OpenGL: The Matrix Stack

• The user can save the current transformation matrix by pushing it onto the stack with glPushMatrix()

• The user can later restore the most recently pushed matrix with glPopMatrix()

• These commands really only make sense when in GL_MODELVIEW matrix mode

Page 15: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

OpenGL: Matrix Stack ExampleglMatrixMode(GL_MODELVIEW);

glLoadIdentity();

glTranslatef(…);

// save translation matrix:

glPushMatrix();

glRotatef(…);

// render something translated & rotated:

glCallList(foo);

// restore pushed matrix, undoing rotation:

glPopMatrix();

// render something else, no rotation:

glCallList(bar);

Page 16: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures• Let’s have a look at the data structures

employed in more detail

• Selection of data structures for computer

graphics often driven by need for efficiency

– storage

– computation

• Trade-off between storage and

computational efficiency often applied

Page 17: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

• Data structures are required for:– scene specification

• object, polygon, point / vertex, ...

– mathematical manipulations• vector, matrix, …

– graphical display• buffer, ...

• Typical data structures: trees / scene graphs, linked lists, arrays

Page 18: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

Computer graphics often use hierarchical data structures, e.g.

Scene

Objects

Facets

Vertices

Linked list Linked list ofof objectsobjects

Linked lists Linked lists ofof facetsfacets

Linked lists Linked lists ofof verticesvertices

Structures Structures withwith xx, , yy, , zz

coordinatescoordinates

Note: other possible levels: object groups, facet groups (surfaces), edgesvertex may also link back to facets which share vertex (for shading)

Page 19: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

Possible architecture

Facet listsFacet lists

Facet MFacet 1

Vertex array

VerticesVertices

Object listObject list

Object 1 Object 2 Object N

Facet list and vertex array

Page 20: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

Possible structure for 3D point or vertex

/* 3D point or vertex with integer coordinates *//* 3D point or vertex with integer coordinates */typedef struct structTag3DiPointtypedef struct structTag3DiPoint {{ intint xCoordinate,xCoordinate, /* x coordinate *//* x coordinate */

yCoordinate,yCoordinate, /* y coordinate *//* y coordinate */

zCoordinate;zCoordinate; /* z coordinate *//* z coordinate */

}} int3DPointint3DPoint, , /* 3D point *//* 3D point */

* * pInt3DPointpInt3DPoint,, /* pointer to a 3D point *//* pointer to a 3D point */

int3DVertexint3DVertex, , /* 3D vertex *//* 3D vertex */

* * pInt3DVertexpInt3DVertex; ; /* pointer to a 3D vertex *//* pointer to a 3D vertex */

Page 21: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

Possible structure for polygon

/* Polygon in 3D space *//* Polygon in 3D space */typedef struct structTag3DiPolygontypedef struct structTag3DiPolygon {{ int3DVertexint3DVertex i3SidedPoly[3]; i3SidedPoly[3]; intint colour,colour,

visibilityFlag;visibilityFlag; floatfloat magNormal;magNormal; struct structTag3DiPolygon * link2NextPolygon;struct structTag3DiPolygon * link2NextPolygon; /* Other attributes can go here *//* Other attributes can go here */ }} int3DPolygonint3DPolygon, /* 3D Polygon */, /* 3D Polygon */ * * pInt3DPolygonpInt3DPolygon,, /* pointer to a 3D Polygon */ /* pointer to a 3D Polygon */ int3DFacetint3DFacet, /* 3D facet */, /* 3D facet */ * * pInt3DFacetpInt3DFacet; /* pointer to a 3D facet */; /* pointer to a 3D facet */

Page 22: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

Possible structure for 3D object

/* Object in 3D space *//* Object in 3D space */typedef struct structTag3DiObjecttypedef struct structTag3DiObject {{ pInt3DFacetpInt3DFacet pFacetList; pFacetList; pInt3DVertexpInt3DVertex pVertexArray; pVertexArray; intint numVertices;numVertices;

int3DPointint3DPoint worldPosition; worldPosition;

struct structTag3DiObject * struct structTag3DiObject * link2NextObject;link2NextObject;

/* Other attributes can go here *//* Other attributes can go here */ }} int3DObjectint3DObject, /* 3D Object */, /* 3D Object */ * * pInt3DObjectpInt3DObject;; /* pointer to a 3D Object */ /* pointer to a 3D Object */

Page 23: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

• To synthesise copies of an object

– master / instance architecture• master defines generic attributes of object

• instance defines attribute values of particular copy

MasterMaster

InstancesInstances

Page 24: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Data Structures

Possible architecture

MastersMasters

InstancesInstances

Object 1

tm att

Object 2

tmatt

Master 1

car

Facet listFacet list

Edge listEdge list

Vertex listVertex list

Object N

tmatt

tm: transf. matrixatt: attributes

Master M

ball

Facet listFacet list

Edge listEdge list

Vertex listVertex list

Page 25: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Tree structures to accommodate scene graphs

• Binary trees

• Quad trees

• Oct trees

• Child-sibling trees

Page 26: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Using Modelling Software

• Maya

• 3d Studio Max

• VRML generators

Page 27: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Features• Primitives

• Groups

• Complex , irregular shapes

• Lines, Points, Facets

• Curved surfaces

• Texture mapped surfaces

• Lighting and Shading

• Interactions and Behaviours

Page 28: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Primitives

• Facets constructed from known geometric relationships

• Uses polygons to map to standard mesh structure

• Scaling , shearing, rotation and translation used to modify vertex information, vertex ordering remains same

Page 29: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Complex or Irregular objects

• Manual construction– Lines and vertices positioned by hand/ eye– Modification of primitives– Extrusions

• Curved surfaces– B-splines– Bezier curves– Parametric meshes– etc

Page 30: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

Scene view

• Scene hierarchy required• Must have mechanism to store results• Output file structure must link to internal structure

– Hierarchy– Relationship between hierarchical nodes– Vertex list– Vertex ordering list– Lighting information– Texture mapping– May also hold recent viewing parameters

Page 31: Scene Graphs In 3D Graphics programming the structure used is a scene graph which is special tree structure designed to store information about a scene

3DS File structure

• May be ASCII output

• Tags outline structures

• Must read between Tags

• Comma delimitation usually to separate vertex list and ordering information