Chapter 17.   Using a Lathe to Make Shapes


[Lathe Shapes PIC] I've come up against the lack of useful shapes in Java 3D many times -- there's only so much that can be done with the Box, Cone, Cylinder, and Sphere utilities, and then it's quite a large step to building with geometry arrays.

One solution is to follow the route used in Chapter 16: create the shape in a 3D modeling package, and load it into Java 3D. The drawback is the need to learn the modeling software, and most are so fully featured that this endeavor is only for the stout-hearted.

The LatheShape3D class developed in this chapter aims at the middle ground: it allows a wide range of complicated looking shapes to be defined very easily, in terms of a few (x,y) coordinates, and colour or texture information. Internally it uses QuadArrays, Hermite curves, texture coordinates, etc., but these are all hidden.

Since LatheShape3D is a subclass of Shape3D, its objects can be readily integrated into the rest of a Java 3D application (e.g. moved, rotated).

The image on this page shows a range of LatheShape3D objects. The text below the shapes is not part of their definitions; it was added to help distinguish between them.

A lathe shape is created in two stages: first the user defines a lathe curve, and this is automatically rotated around the y-axis to make the shape.

A lathe curve is a sequence of (x,y) points defining a series of curve segments and straight lines. When the curve is rotated, each point moves in a circular orbit back to its starting position. However, it is possible to modify the orbit to create an ellipse, or more complicated paths.

A lathe shape is pink by default, but this can be changed to a different colour or texture. In both cases, the shape will reflect light (i.e. a shape's faces always have normals).

A colour is defined using two Color3f objects: one for ambient illumination (typically a dark hue), the other for diffuse lighting.

A texture is wrapped round the shape starting from the middle of its back, continuing counter-clockwise round the front, and ending at its back again. The texture is also stretched in the y-direction so that it covers the shape vertically.

This chapter illustrates the following features:




Dr. Andrew Davison
Back to my home page