Chapter 17. Using a Lathe to Make Shapes
I've run 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
classes. One way of getting past this limitation is to use Java 3D's GeometryArray
(or one of its subclasses) to specify a geometry in terms of separate arrays of positional coordinates, colors, normals, and texture coordinates. This is pretty daunting, and I like to avoid it if possible.
An alternative to this low-level shape building is to follow the approach outlined in Chapter 16: create the shape in a 3D modeling package and load it into Java 3D. The drawback is that you need to learn the modeling software. Most of these packages have so many bells and whistles that it's hard to get what you need done.
This chapter describes a compromise between the complexity of Java 3D GeometryArrays
and the loading of ready-made models. The edge of a shape is defined in terms of straight lines and simple curves. This edge (or lathe curve) is rotated around the y-axis to create a 3D volume, called a lathe shape. This approach, often called surface or sweep revolution, is packaged up in a LatheShape3D
class.
Color or texture information can be added easily. A lathe shape is pink by default, but this can be changed to a different color or texture. In both cases, the shape will reflect light (i.e., a shape's faces always have normals). A color is defined using two Color3f
objects: one for ambient illumination ...
Get Killer Game Programming in Java now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.