1
Basic Modelling
2
Lecture ObjectivesLecture Objectives
To understand how 3D scenes can be modelled - in terms of geometry, appearance and behaviour - and rendered on a display
To understand how to deliver interactive animated 3D graphics over the Internet
To be able to create interactive 3D graphics applications using industry standard software (OpenGL and VRML)
3
The BasicsThe Basics
MODELLING– representing objects in 3D– transforming objects and composing scenes
VIEWING– projecting 3D scenes onto a 2D display
surface RENDERING
– illumination– shading– adding realism via textures, shadows
4
Basic ModellingBasic Modelling
x
y
z
objects representedas set of faces - iepolygons- and facesas a set of points
scenes composedby scaling, rotating,translating objects tocreate a 3D world
5
ViewingViewing
Clipping– selects a volume of interest– Projection– 3D scene is projected onto a 2D
plane
camera
6
RenderingRendering
shading:how do we use ourknowledge of illuminationto shade surfaces in ourworld?
illumination:how is light reflectedfrom surfaces?
7
RenderingRendering
texture
shadows
8
InternetInternet
VRML– ISO standard for 3D graphics over
the Web– allows modelling of geometry,
appearance and behaviour
9
Advanced RenderingAdvanced Rendering
ADVANCED RENDERING– direct versus global illumination
methods– ray tracing and radiosity
OTHER ADVANCED FEATURES– curve and surface modelling– image based rendering– non-photorealistic rendering
10
Advanced RenderingAdvanced Rendering
Advanced Rendering - global illumination– ray tracing
– radiositybased on physics of radioactive heat
transfer between surfaces
light
eye
screen
objects
11
Before we begin...mathematics!Before we begin...mathematics!
3D Co-ordinate Systems
LEFT RIGHT
x
yz
x
y
z
z points away z points toward
Align thumb with x, first finger with y, then second fingerof appropriate hand gives z direction. Common now touse a RIGHT HANDED system.
12
Points and VectorsPoints and Vectors
We shall write points as column vectors
xyz
P =
Difference of two points gives a direction vector:D = P2 - P1
x
y
z
P2
P1
x
y
z
P
Note: If P1 and P2are on a plane, thenD lies in the plane
13
Polygonal RepresentationPolygonal Representation
Any 3D object can be represented as a set of plane, polygonal surfaces
V1
V2V3
V4
V5V8
V7 V6
Note: each vertex part of severalpolygons
14
Polygonal RepresentationPolygonal Representation
Objects with curved surfaces can be approximated by polygons - improved approximation by more polygons
15
Scene OrganisationScene Organisation
Scene = list of objects Object = list of surfaces Surface = list of polygons Polygon = list of vertices
scene
objectsurfaces polygons
vertices
16
Polygon Data StructurePolygon Data Structure
V1
V2V3
V4
V5V8
V7 V6
P1
P2
Object Table
Obj1P1, P2, P3,P4, P5, P6
Object Obj1
Vertex Table
V1X1, Y1, Z1
V2X2, Y2, Z2
. ...
Polygon Table
P1 V1, V2, V3, V4
P2 V1, V5, V6, V2
. ...
17
Typical PrimitivesTypical Primitives
Graphics systems such as OpenGL typically support:– triangles, triangle strips and fans– quads, quad strips– polygons
Which way is front?– convention is that normal points
towards you if vertices are specified counter-clockwise
18
Modelling Regular ObjectsModelling Regular Objects
Sweeping
Spinning
2D Profilesweep axis
spinning axis
R1 R2
19
Sweeping a Circle to Generate a Cylinder as Polygons
Sweeping a Circle to Generate a Cylinder as Polygons
vertices at z=0
vertices at z=depthV1
V2
V3V4
V5
V6 V8
V7
V10
V9
V11
V12V13
V14
V15V16
V17
V18
V1[x] = R; V1[y] = 0; V1[z] = 0V2[x] = R cos ; V2[y] = R sin ; V2[z] = 0 (=/4)Vk[x] = R cos k; Vk[y] = R sin k; Vk[z] = 0wherek = 2 (k - 1 )/8, k=1,2,..8
20
Complex PrimitivesComplex Primitives
Some systems such as VRML have cylinders, cones, etc as primitives– polygonal representation calculated
automatically OpenGL has a utility library (GLU)
which contains various high-level primitives– again converted to polygons
For conventional graphics hardware:– POLYGONS RULE!
21
Automatic Generation of Polygonal Objects
Automatic Generation of Polygonal Objects
3D scanners - or laser rangers - are able to generate computer representations of objects– object sits on rotating table– contour outline generated for a
given height– scanner moves up a level and next
contour created– successive contours stitched
together to give polygonal representation
22
A PuzzleA Puzzle
23
Modelling Objects and Creating Worlds
Modelling Objects and Creating Worlds
We have seen how boundary boundary representations representations of simple objects can be created
Typically each object is created in its own co-ordinate systemco-ordinate system
To create a world, we need to understand how to transform objects so as to place them in the right place - translationtranslation, at the right size - scalingscaling, in the right orientation- rotationrotation
24
TransformationsTransformations
The basic linear transformations are:– translation: P = P + T, where T is
translation vector– scaling: P’ = S P, where S is a scaling
matrix– rotation: P’ = R P, where R is a rotation
matrix As in 2D graphics, we use
homogeneoushomogeneous co-ordinates in order to express all transformations as matrices and allow them to be combined easily
25
Homogeneous Co-ordinatesHomogeneous Co-ordinates
In homogeneous coordinates, a 3D point P = (x,y,z)T
is represented as:P = (x,y,z,1)T
That is, a point in 4D space, with its ‘extra’ co-ordinate equal to 1
NoteNote: in homogeneous co-ordinates, multiplication by a constant leaves point unchanged– ie (x, y, z, 1)T = (wx, wy, wz, w)T
26
TranslationTranslation
Suppose we want to translate P (x,y,z)T by a distance (Tx, Ty, Tz)T
We express P as (x, y, z, 1)T and form a translation matrix T as below
The translated point is P’
T P
x’y’z’1
P’ =
1 0 0 Tx0 1 0 Ty0 0 1 Tz0 0 0 1
xyz1
= x + Txy + Tyz + Tz1
=
27
ScalingScaling
Scaling by Sx, Sy, Sz relative to relative to the originthe origin:
x’y’z’1
Sx 0 0 00 Sy 0 00 0 Sz 00 0 0 1
xyz1
P’ = S P
= = Sx . xSy . ySz . z1
28
RotationRotation
Rotation is specified with with respect to an axis respect to an axis - easiest to start with co-ordinate axes
To rotate about the x-axis:
a positive angle corresponds to counter-clockwise direction lookingat origin from positive position on axis
x’y’z’1
= 1 0 0 00 cos -sin 00 sin cos 00 0 0 1
xyz1
P’ = Rz () P
29
Composite TransformationsComposite Transformations
The attraction of homogeneous co-ordinates is that a sequence of transformations may be encapsulated as a single matrix
For example, scaling with respect to a with respect to a fixed position (a,b,c) fixed position (a,b,c) can be achieved by:– translate fixed point to origin- say, T(-a,-b,-c)– scale- S– translate fixed point back to its starting
position- T(a,b,c) Thus: P’ = T(a,b,c) S T(-a,-b,-c) P = M P
30
Rotation about a Specified AxisRotation about a Specified Axis
It is useful to be able to rotate about any axis in 3D space
This is achieved by composing 7 elementary transformations
31
Rotation through about Specified Axis
Rotation through about Specified Axis
x
y
z
x
y
zrotate throughrequ’d angle,
x
y
z
x
y
z
P2
P1x
y
z
P2
P1x
y
z
initial positiontranslate P1to origin
rotate so that P2 lies on z-axis(2 rotations)
rotate axisto orig orientation
translate back
32
Inverse TransformationsInverse Transformations
As in this example, it is often useful to calculate the inverse of a transformation– ie the transformation that returns to
original state Translation: T-1 (a, b, c) = T (-a, -
b, -c) Scaling: S-1 ( Sx, Sy, Sz ) =
S ............ Rotation: R-1
z () = Rz (-)
33
Viewing - Projections
SEN 992 Computer Graphics ISEN 992 Computer Graphics I
34
ViewingViewing
Graphics display devices are 2D rectangular screens
Hence we need to understand how to transform our 3D world to a 2D surface
This involves:– selecting the observer position observer position (or
camera position)– selecting the view plane view plane (or camera film
plane)– selecting the type of projectionprojection
35
Perspective ProjectionsPerspective Projections
There are two types of projection: perspectiveperspective and parallelparallel
In a perspectiveperspective projection, object positions are projected onto the view plane along lines which converge at the observerP1
P2
P1’
P2’
view plane
camera
36
Parallel ProjectionParallel Projection
In a parallel projection, the observer position is at an infinite distance, so the projection lines are parallelP1
P2
view plane
37
Perspective and Parallel Projection
Perspective and Parallel Projection
Parallel projection preserves the relative proportions of objects, but does not give a realistic view
Perspective projection gives realistic views, but does not preserve proportions– Projections of distant objects are
smaller than projections of objects of the same size which are closer to the view plane
38
Perspective and Parallel Projection
Perspective and Parallel Projection
perspective parallel
39
Viewing Coordinate SystemViewing Coordinate System
Viewing is easier if we work in a viewing co-ordinate systemviewing co-ordinate system, where the observer or camera position is on the z-axis, looking along the negative z-direction
xV
yV
zV
Camera is positioned at:(0 , 0, zC)
40
View PlaneView Plane
We assume the view plane is perpendicular to the viewing direction
The view planeis positioned at:(0, 0, zVP)
Let d = zC - zVP be thedistance between thecamera and the plane
xv
yv
zv
41
Perspective Projection CalculationPerspective Projection Calculation
xv
yv
zv
zVview plane
Q
camerayV
zCzQ zVP
looking along x-axis
42
Perspective Projection CalculationPerspective Projection Calculation
zVview plane
Q
camerayV
P
By similar triangles, yP / yQ = (zC - zVP) / (zC - zQ)and soyP = yQ * (zC - zVP) / (zC - zQ)oryP = yQ * d / (zC - zQ)
zCzQ zVP
xP likewise
43
Transformation Matrix for Perspective
Transformation Matrix for Perspective
1 0 0 0
0 1 0 0
0 0 -zVP/d zVPzC/d
0 0 -1/d zC/d
xQ
yQ
zQ
1
xH
yH
zH
wH
=
Then xP = xH / wH
iexP = xH / ( (zC - zQ) / d )iexP = xQ / ( (zC - zQ) / d )
yP likewise
44
Note for LaterNote for Later
The original z co-ordinate of points is retained – we need relative depth in the scene
in order to sort out which faces are visible to the camera
45
Vanishing PointsVanishing Points
When a 3D object is projected onto a view plane using perspective, parallel lines in object NOT parallel to the view plane converge to a vanishing vanishing pointpoint
view plane
vanishing point
one-pointperspectiveprojectionof cube
46
One- and Two-Point Perspective Drawing
One- and Two-Point Perspective Drawing
47
One-point PerspectiveOne-point Perspective
Said to be the firstpainting in perspective
This is:Trinity with the Virgin,St John and Donors,by Mastaccio in 1427
48
Two-point PerspectiveTwo-point Perspective
EdwardHopperLighthouseat Two Lights
-seewww.postershop.com
49
Parallel Projection - Two typesParallel Projection - Two types
OrthographicOrthographic parallel projection has view plane perpendicular to direction of projection
ObliqueOblique parallel projection has view plane at an oblique angle to direction of projection
P1
P2
view plane
P1
P2
view plane
We shall only consider orthographic projectionorthographic projection
50
Parallel Projection Calculation
Parallel Projection Calculation
xv
yv
zv
zVview plane
Q
yV
zQ zVP
looking along x-axis
51
Parallel Projection CalculationParallel Projection Calculation
zVview plane
Q
yV
P
yP = yQ
and similarly xP = xQ
52
Parallel Projection CalculationParallel Projection Calculation
So this is much easier than perspective!– xP = xQ
– yP = yQ
– zP = zVP
The transformation matrix is simply1 0 0 0
0 1 0 00 0 zVP/zQ 00 0 0 1
53
View Volumes - View WindowView Volumes - View Window
Type of lens in a camera is one factor which determines how much of the view is captured– wide angle lens captures more than
regular lens Analogy in computer graphics is the
view windowview window, a rectangle in the view plane
xv
yv
zv
view window
54
View Volume - Front and Back Planes
View Volume - Front and Back Planes
We will also typically want to limit the view in the zV direction
We define two planes, each parallel to the view plane, to achieve this– front plane (or near plane)– back plane (or far plane)
front planeback plane
zV
55
View Frustum - Perspective Projection
View Frustum - Perspective Projection
view window
backplane
frontplane
camera
view frustum
zV
56
View Volume - Parallel ProjectionView Volume - Parallel Projection
view window
backplane
frontplane
zV
view volume
57
View VolumeView Volume
The front and back planes act as important clipping planesclipping planes
Can be used to select part of a scene we want to view
Front plane Front plane important in perspective to remove near objects which will swamp picture
58
VRML - An Introduction
SEN 992 Computer Graphics ISEN 992 Computer Graphics I
59
Good Ideas are SimpleGood Ideas are Simple
Realization 1:– Hypertext + Internet = World Wide Web
Realization 2:– Adding images makes pages more interesting
Realization 3:– Images are pictures taken by the publisher -
why not send 3D scenes and allow the user to take the picture!
VRML: Virtual Reality Modelling Language– a language to describe 3D worlds - for the
Web
60
World Wide Web PagesWorld Wide Web Pages
AUTHORINGPROCESS HTML
file
server
INTERNET
client
WEBBROWSER
text/html
.htmlMIMEtype
61
VRMLVRML
AUTHORINGPROCESS VRML
file
server
INTERNET
client
VRMLBROWSER
x-world/x-vrml
.wrl
Major browser:CosmoPlayer
62
Advantages of VRMLAdvantages of VRML
Transferring a 3D model - rather than a 2D image - to the browser has great advantages– viewer can choose how to look at
the model - or world– viewer can navigate the world– file size can often be much less
63
How Did It All Begin?How Did It All Begin?
Original brainwave– Mark Pesce and Tony Parisi - early 1994– vision of a VR interface to the Web
VRML 1.0– practical realisation based on Open
Inventor (Silicon Graphics toolkit - similar to OpenGL but higher level)
– Open Inventor file format PLUS hyperlinks
– static, non-interactive worlds– Gavin Bell (SGI) - late 1994
64
Where are we now?Where are we now?
VRML97– adds object behaviours and
interaction to allow creation of dynamicdynamic worlds
– ISO standard - December 1997– Gavin Bell, Rikk Carey (ex-SGI) and
Chris Marrin (SGI) 2000
– being reworked as XML (X3D)– many new developments
65
A VRML FileA VRML File
VRML file consists of:
header nodes
– objects such as cylinders and spheres
– operations such as transformations
fields– parameters of
nodes
#VRML V2.0 utf8Shape {
geometry Cylinder {
radius3height 6
}}
66
As Seen By A BrowserAs Seen By A Browser
#VRML V2.0 utf8
Shape {
geometry Cylinder {
radius2
height 4
}
}
67
Adding Color to the SceneAdding Color to the Scene
#VRML V2.0 utf8
Shape {
geometry Cylinder {
radius 2
height 4
}
appearance Appearance {
material Material {
diffuseColor 1 0 0
specularColor 1 1 1 }
}
}
68
Co-ordinate SystemsCo-ordinate Systems
Each node is drawn within its own local co-ordinate system..
x
z
y
69
Modelling TransformationsModelling Transformations
...and can be subjected to a modelling transformation to scale, rotate, translate
Transform is a VRML node - treated just like an object
It applies to a group of children nodes
#VRML V2.0 utf8
Transform{
scale 5.0 0.5 1.0
children [
Shape {
geometry Cylinder {
radius 2
height 4
}
appearance Appearance {
material Material {
diffuseColor 1 0 0
specularColor 1 1 1 }
} } ] }
70
Hierarchical StructureHierarchical Structure
#VRML V2.0 utf8
Transform{
scale 5.0 0.5 1.0
children [
Shape {
geometry Cylinder {
radius 2
height 4
}
appearance Appearance {
material Material {
diffuseColor 1 0 0
specularColor 1 1 1 }
} } ] }
TRANSFORM
SHAPE
parent
child
71
Hierarchical StructureHierarchical Structure
This generalises to allow nodes to appear in a hierarchy
This is known as the VRML scene scene graphgraph
TRANSFORM
SHAPE TRANSFORM
SHAPE SHAPE
72
TransformationsTransformations
Here we see Cylinder, Sphere and Cone nodes
Each has been subjected to a modelling transformation in order to position them
73
InstancesInstances
A node can be given a ‘name’ and then used multiple times - with different transformations applied to each
DEF kwb Shape {...} gives it a name
USE kwb allows it to be included at other points in the scene graph
74
AnchorsAnchors
A piece of geometry can act as a link to another URL
75
TexturesTextures
Texture mapping: Images can be mapped to geometry to provide texturing
VRML looks like:Shape{
geometry Sphere { }
appearance Appearance{
texture ImageTexture{
url “http://..../kwb.gif”}
76
Polygonal SurfacesPolygonal Surfaces
The general primitive for drawing polygonal surfaces is:
– IndexedFaceSet– coord field lists
the points– coordIndex
describes the polygons
Shape{geometry IndexedFaceSet {
coord Coordinate {point [ 17.5 11.2 -
1.2,17.5 15.0 -
1.2,… ]}
coordIndex [ 0 1 2 3 -1,4 1 0 5 -1,…]
}}
77
LightsLights
VRML includes:– DirectionalLight– PointLight– SpotLight
Note # sign is a comment
Example:
PointLight{
on TRUE
intensity 0.75
color 1 0 0 #red
location 0 0 0
radius 100
}
78
Viewing Viewing
Specified via the Viewpoint node
VRML file can have a number of Viewpoint nodes - browsers allow a user to jump from one viewpoint to another
Orientation = axis + angle of rotation
Example:
Viewpoint {
position 0 0 5
orientation 0 0 1 0.3
description“frontview”
}
79
Other Basic FeaturesOther Basic Features
Inline node– incorporate VRML code from
another url– this allows us to composecompose large
worlds from many smaller ones Level of Detail
– different geometric representations depending on distance
80
Information About VRMLInformation About VRML
Web3D Consortium– http://www.web3d.org– links to specifications and resources
Web3D Information– http://web3d.about.com/compute/web3d
Leeds University VRML/Java3D Information Centre – http://www.scs.leeds.ac.uk/vrmljava3d
VRML Repository– http://www.sdsc.edu/vrml/
81
Range of books now available– The VRML 2.0 Handbook (Addison Wesley)
Jed Hartman and Josie Wernecke
http://vrml.sgi.com/handbook– The Annotated VRML Reference Book (Addison
Wesley)
Rikk Carey and Gavin Bell
http://www.best.com/~rikk/Book/ Tutorials include:
– Floppy’s guide: www.vapourtech.com/vrmlguide
Books and TutorialsBooks and Tutorials