Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Additional 3D Topics  Splitting polygons  Off screen rendering for capture of rendered images.  Sound in Java 3D scene graphs  Advanced textures.

Similar presentations


Presentation on theme: "1 Additional 3D Topics  Splitting polygons  Off screen rendering for capture of rendered images.  Sound in Java 3D scene graphs  Advanced textures."— Presentation transcript:

1 1 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

2 2 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

3 3 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.

4 4 Splitting a Convex Polygon  Given the vertex list (v 1, v 2, …, v n ) 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

5 5 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.

6 6 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

7 7 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

8 8 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

9 9 Off-Screen Rendering  Create off screen canvas using public Canvas3D(GraphicsConfiguration gc, boolean offScreen)‏  Attach to view view.addCanvas3D(canvas)‏  Capture images ImageComponent2D buffer = new ImageComponent2D(ImageComponent.FORMAT_RGB, bImage); canvas.setOffScreenBuffer(buffer); canvas.renderOffScreenBuffer(); canvas.waitForOffScreenRendering(); bImage = offScreenCanvas.getOffScreenBuffer().getImage();  OffScreen.java

10 10 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

11 11 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 graph BackgroundSound sound = new backgroundSound(); sound.setSoundData( mc); sound.setSchedulingBounds( bounds); root.addChild( sound);

12 12 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

13 13 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)

14 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

15 15 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.

16 16 Perlin Noise  Want a function that is smooth and random at the same time –noise(x) is a fractal sum

17 17 Example: Marble Texture  Create a marble texture using –sin(x + turbulence(p))‏

18 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 http://en.wikipedia.org/wiki/Bump_mapping

19 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

20 12/05/08 Global Illumination Models  Very complex  Not practical for real-time rendering  Examples –Ray-tracing –Luminosity

21 21 Artificial Shadows  Create a projection of each object to use for the shadow  Similar to a view projection

22 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

23 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

24 24 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)

25 25 Example: MovingShadows.java

26 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

27 12/05/08 Types of curves  Bezier curves  Spline –a sequence of smoothly-joined polynomial curves  B-spline –widely used in CG  Bicubic surfaces

28 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

29 29 Bezier Curves  General Bezier curve is specified by a set of n control points –B n,i (t) is the Bernstein basis  A third-order Bezier curve has 4 control points

30 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

31 31 deCasteljau Algorithm  Start with a sequence of control points p 0 0, p 1 0, p 2 0, p 3 0  Compute successively shorter sequences p i k = (1 - t) p i k-1 + t p i+1 k-1  Curve is s(t) = p 0 3

32 32 Subdivision

33 33 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

34 34 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

35 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

36 12/05/08 BezierSurface.java  Based on a bicubic spline  Create a polygon mesh from mxn points  Use a TriangleStripArray

37 37 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

38 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

39 12/05/08 B-Spline Curves  For B-spline of degree k have –n+1 control points (p 0, p 1, …, p n ) –n + k + 2 knots (t 0 <= t 1 <= …<= t n+k+1 )  N k,i are normalized B-spline blending functions  Curve only defined from [t 3 to t n+k-2 )

40 12/05/08 Cubic B-Spline  Extension of Bezier curves  Uniformly distributed knots –t i+1 - t i = 1, i = 3, 4, …, n  Duplicated knots at ends mean force endpoints to be on the curve –t 1 = t 2 = t 3 = t 4 –t n+1 = t n+2 = t n+3 = t n+4  For n=3, this is a cubic Bezier curve


Download ppt "1 Additional 3D Topics  Splitting polygons  Off screen rendering for capture of rendered images.  Sound in Java 3D scene graphs  Advanced textures."

Similar presentations


Ads by Google