Date post: | 26-Dec-2015 |
Category: |
Documents |
Upload: | austin-walton |
View: | 228 times |
Download: | 0 times |
1Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Additional 3D Topics Splitting polygons Off screen rendering for capture of rendered
images. Sound in Java 3D scene graphs Advanced textures Simple shadows Dynamic geometry change 3D curves and surfaces
2Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Splitting Polygons
We can specify a 3D shape as a collection of polygon faces– In principle, can use any kind of polygon– With more that 3 vertexes, it is possible to have
something that isn't planar– Concave polygons don't necessarily fill
properly Usual practice is to use triangles
3Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Polygons
A convex polygon is one for which– all the interior angles are less than 180 degrees– the interior is entirely to one side of the infinite
extension of any edge– a line connecting any pair of interior points is inside
the polygon.
4Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Splitting a Convex Polygon
Given the vertex list (v1, v2, …, vn) where the vertexes are in counterclockwise order– Create a triangle from the first three vertexes– Remove the middle vertex from the list– Repeat until there are only 3 vertexes left– Create a triangle from the last three vertexes
5Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Concave Poygons Use the angle between each
successive pair of edges to determine if polygon is concave.
Treat each edge as a vector. – Vectors should go in counter-
clockwise Calculate the cross product
for each successive pair of edges.
If any cross product is negative, the polygon is concave.
6Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Splitting Concave Polygons
Find a convex triple in the vertex list by looking for a negative cross product
Extend the first edge of the pair of edges until it intersects another polygon edge. – Form a triangle from the
vertexes that form the second vector and the new point
– Remove the end of the second vector from the vertex list
Repeat until remaining vertexes form convex polygon
7Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Rotational Method for Splitting
For each vertex in order– Move vertex to the origin
– Rotate to put next vertex on x-axis
– If next vertex in sequence is below x-axis, split off a triangle and remove that vertex from list
– Repeat until remaining polygon is convex
8Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Off-Screen rendering What if you want to save or print a rendered scene? Canvas3D supports an off-screen rendering mode To use
– create off-screen canvas– stop the view– attach the off-screen canvas– start the view – render the off-screen buffer– when rendering completes
retrieve the image detach the off-screen buffer
9Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Off-Screen Rendering Create off screen canvas using
public Canvas3D(GraphicsConfiguration gc, boolean offScreen)
Attach to viewview.addCanvas3D(canvas)
Capture imagesImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB,
bImage);canvas.setOffScreenBuffer(buffer);canvas.renderOffScreenBuffer();canvas.waitForOffScreenRendering();bImage = offScreenCanvas.getOffScreenBuffer().getImage();
OffScreen.java
10Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Sound Sound is often used in applications that use
3D graphics– e.g. games
Java3D has classes to support sound– Added as leaf nodes in scene graphs– Similar to Light
11Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Using Sound: Sound3D.java Create an AudioDevice
su.getViewer.createAudioDevice(); Create a MediaContainer to hold sound data
MediaContainer mc = new MediaContainer(url);
Create a Sound object and add it to the scene graphBackgroundSound sound = new backgroundSound();
sound.setSoundData( mc);sound.setSchedulingBounds( bounds);root.addChild( sound);
12Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
3D Texture Mapping
2D texture maps put a 2D image onto a 3D surface– For some surfaces, this may not look very natural
Using a 3D volumetric texture source provides a more natural mapping
Usually use computer-generated textures for this– Procedural textures
There are a few sources of data that provide volumetric data– CAT scans
13Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
3D Texture Mapping
Consumes more computing resources in terms of generation and storage of 3D texture data
Realistic texture features of true 3D characteristics can be rendered with relatively simple mapping functions
Texture consists of a 3D array of pixel values Texture coordinates need three values (r, s, t)
12/05/08
Procedural textures
Often used to simulate natural textures such as marble or wood
Natural textures frequently have some periodic variation associated with them– Not perfectly periodic - need some randomness
imposed onto the periodic behavior
15Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Perlin Noise
Invented by Ken Perlin Widely used for things like fire, smoke, clouds A kind of gradient noise
– Uses a grid of random gradients (unit vectors)
Contribution to noise at x from each neighboring grid point is proportional to the dot product of the gradient and the vector from the grid point to x.
16Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Perlin Noise
Want a function that is smooth and random at the same time– noise(x) is a fractal sum
17Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Example: Marble Texture
Create a marble texture using– sin(x + turbulence(p))
12/05/08
Bump Mapping
Applying a 2D texture to a surface is not as realistic as a truly textured surface– the normal is constant across a face so the
interaction with light is different Bump mapping uses a varying surface
normal to simulate the effect of a rough surface
http://en.wikipedia.org/wiki/Bump_mapping
12/05/08
Shadows
Java3D API provides only a local illumination model– Illumination of any object depends only on the
lights and not on any other objects– No shadows or reflections
To compute these kinds of effects need a global illumination model
12/05/08
Global Illumination Models
Very complex Not practical for real-time rendering Examples
– Ray-tracing– Luminosity
21Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Artificial Shadows
Create a projection of each object to use for the shadow
Similar to a view projection
12/05/08
Shadow.java
Shadow of a Dodecahedron is projected onto a stone wall– Wall is a texture-mapped rectangle– Gray shadow is just in front of the wall– Shadow is computed when the scene graph is
built
12/05/08
GeometryChange
Occasionally need to be able to modify actual geometry while the scene graph is live– Shadow of a moving object needs to be
recomputed every time the object moves GeometryUpdater interface provides a
means to do this
24Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Dynamic Geometry Change
Create the geometry with BY_REFERENCE flag set.
Write a class implementing the GeometryUpdater interface. public void updateData(Geometry)
Implement a Behavior class. – Call the GeometryArray method to trigger the update.
public void updateData(GeometryUpdater)
25Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Example: MovingShadows.java
12/05/08
Curves and Curved Surfaces Java3D doesn't support curves or curved surfaces Parametric equations provide one way to generate
curves and curved surfaces based on a set of equations
More generally, curves and surfaces (in both 2D and 3D) can be specified by a set of points plus a procedure for interpolating between those points– Bezier curves– B-splines
12/05/08
Types of curves
Bezier curves Spline
– a sequence of smoothly-joined polynomial curves
B-spline – widely used in CG
Bicubic surfaces
12/05/08
Bezier curves
Bezier curves are defined by a set of control points– Quadratic curves in Java2D are second-order
Bezier curves– Cubic curves in Java2D are third-order Bezier
curves
29Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Bezier Curves General Bezier curve is specified by a set of n
control points
– Bn,i(t) is the Bernstein basis
A third-order Bezier curve has 4 control points
12/05/08
de Castlejau Algorithm
Allows you to compute a point on a Bezier curve using linear interpolation
Can also be used to subdivide a Bezier curve into segments
31Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
deCasteljau Algorithm Start with a sequence of control points
p00, p1
0, p20, p3
0
Compute successively shorter sequencespi
k = (1 - t) pik-1 + t pi+1
k-1
Curve iss(t) = p0
3
32Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Subdivision
33Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
BezierCurve.java
Create a LineStripArrary Use deCasteljau algorithm to subdivide the given curve
into shorter segments Subdivide recursively until segments are short enough to
be approximated by a line– Program uses a fixed level of subdivisions
– More generally, use a flatness test
34Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
Bezier Surfaces
Create surfaces by extending a Bezier curve along anotherr curve– Tensor product of Bezier curves
Bicubic Bezier surface is the common type– m = n = 3
deCasteljau algorithm can be applied
12/05/08
Bezier surfaces
Think of surface as family of Bezier curves For a particular value of u, S(v) is a Bezier
curve with control points– for j=0, 1, 2, 3
12/05/08
BezierSurface.java
Based on a bicubic spline Create a polygon mesh from mxn points Use a TriangleStripArray
37Zhang & Liang, Computer Graphics Using Java 2D and 3D (c) 2007 Pearson Education, Inc. All rights reserved.
The Utah Teapot
A famous object in computer graphics– Constructed by Martin Newell in 1975– Used to test rendering algorithms
Constructed with Bezier patches– Contains 306 vertices defining 32 bicubic
Bezier surface patches
12/05/08
B-Spline Curves Often used for modeling curved surfaces Also defined by a set of control points
– Doesn't always interpolate the points A set of knot values is used to control
smoothnes and continuity– Uniform B-spline has uniformly-spaced knot
values NURBS : Non-uniform rational B-spline
12/05/08
B-Spline Curves For B-spline of degree k have
– n+1 control points (p0, p1, …, pn)
– n + k + 2 knots (t0 <= t1 <= …<= tn+k+1)
Nk,i are normalized B-spline blending functions
Curve only defined from [t3 to tn+k-2)