Interactive Kitchen (Java3D)

The requirement for this project was:

Without using a 3D modelling tool or a Loader, build a Java3D scene that demonstrates lighting, shading and texturing.

Running Application

Click here, or the above image to run the application right from your browser with no setup neccessary. However, Java3D applications must be signed to run via Java Web Start, so you’ll have to accept my unverified digital certificate which I used to sign the JAR. Alternatively, you may download the source below and compile/run yourself.

Note: click and drag the left/right mouse buttons to rotate/pan, and use the mouse scroller to zoom in and out.

Scene Design

The rendered scene contains a picture, a light, a table, five chairs, a carpet, and stone walls, resembling a kitchen. Furthermore, there are two lights: one from the lampshade, and a directional light shining from the botton left corner of the room, diagnoally through it.

Several textures are used to texture the table top, the picture, the walls, and the carpet.

The table top has a laminated shiny look, while the chairs have plastic feel with painted legs.

By moving around the scene you can see the lighting and shading in action.


I have attempted to demonstrate a solid and thorough understanding of the major components and funtionality of Java3D. The code is commented well and should provide a better demonstration of this.

Class Summary


Extends: nothing

  • Kitchen()
  • createSceneGraph ()
  • createLightedSceneGraph ()
  • init()
  • destroy()
  • main(String [])

Kitchen is the runnable class; it creates an instance of the universe and adds the scene to it.

createLightedSceneGraph() is responsible for calling createSceneGraph(), which itself creates all the objects in the world. createScenceGraph() creates and transforms many shapes; some of these are based on my custom classes, others are just simple Java3D Primitives.

An example of a custom class is Chair. This is instantiated and added to a SharedGroup and re-used five times. Similarly, the classes Table, Picture, and LightShade are instantiated and added to the scene. createSceneGraph() also creates the walls and floor and applies textures to these.

The walls are created using a ShardGroup containing a Wall. They are transparent, making use of the TransparencyAttributes.BLENDED flag, so the texture blends in the with colour of the wall.

The floor is textured with a carpet-like image, so TextureAttributes.REPLACE is used so as to ensure no reflection comes from it.

When createSceneGraph() is finished, it hands the scene back to createLightedScene() which then adds various lighting to the world.

Finally, Kitchen adds an OrbitBehavior to the ViewingPlatform to allow the user to rotate, zoom, and straff around the scene.


Extends: Group

  • BasicSeat()
  • BasicSeat(Material, Material)
  • BasicSeat(Appearance, Appearance)
  • createSceneGraph ()
  • setAppearance()
  • getCAppearance()
  • getCAppearance()

BasicSeat is a Java3D Primitive. It is not actually used anywhere by itself, although it could be (as a backless chair; a stool).

Its job is to represent a four-legged backless seat. This is achieved by using Java3D’s Box (also a Primitive), twice. One acts as a leg, the other acts as a support-piece. These are added to a SharedGroup, which is re-used three more times, and tranformed accordingly so as to create a seat-like structure.

BasicSeat is subclassed by Chair, and also utilised in Table.


Extends: BasicSeat

  • Chair()
  • Chair(Material, Material)
  • Chair(Appearance, Appearance)
  • createSceneGraph ()

Chair extends BasicSeat, and therefore is aJava3D Primitive. As most of the work is done by BasicSeat, all Chair does is create the back of the chair, then calls BasicSeat’s constructor to do the rest.


Extends: Group

  • Table()
  • Table(Material , Material)
  • Table(Appearance, Appearance)
  • createSceneGraph(BasicSeat)

As Table extends Group, it is a Java3D Primitive. The table consists of four legs, a textured table-top, and drawer, and a knob on the drawer.

The drawer is made from Primitives, whereas the legs and top are from BasicSeat. The method createSceneGraph(BasicSeat) is handed a BasicSeat, which is then scaled up to the size of a table. The texture is a wood-like image, and so is created with the TextureAttributes.MODULATE flag set, so as to interact with light.


Extends: Group

  • createSceneGraph()
  • Picture(String)

Picture’s job is to represent a picture and a picture frame.

It uses GeometryInfo with the GeometryInfo.QUAD_ARRAY flag set. There are two arrays passed into GeometryInfo: one consisting of the shape’s coordinates, and the other with the texture coordindates.

A PolygonAttributes node is applied, and the following methods are called:

  • calledsetCullFace(PolygonAttributes.CULL_NONE) – render all of the object, not just the bits that can initially be seen.
  • setBackFaceNormalFlip(true) – create normals for the back of the surface, so it reacts with lighting.

The texure’s filename is handed in with the contructor, and when being applied, the method setPerspectiveCorrectionMode(TextureAttributes.NICEST) is called on the TextureAttributes node for the nicest quality texture mapping perspective correction.


Extends: Shape3D

  • LightShade()
  • LightShade(Material appearance)
  • LightShade(Appearance appearance)
  • createShape3D()

LightShade is a Shape3D. Its job is represent a light shade. It uses GeometryInfo and the GeometryInfo.TRIANGLE_FAN_ARRAY to do this.

A PolygonAttributes node is applied, and the following methods are called:

  • calledsetCullFace(PolygonAttributes.CULL_NONE) – render all of the object, not just the bits that can initially be seen.
  • setBackFaceNormalFlip(true) – create normals for the back of the surface, so it reacts with lighting.

After calculating the coordinates of 17 triangles (which is the interesting bit), it then proceeds to generate the normals for these, thus, giving us a realistic light shade, which is realistically light up on the inside.

The code to create the coordinates of the 17 triangles is as follows:

for(a = 0,n = 0, counter = 1; n < N; a = 2.0*Math.PI/(N-1) * ++n, counter++) {
        x = (float) (width * Math.cos(a));
        y = (float) (width * Math.sin(a));
        coords[0*(N+1)+n+1] = new Point3f(x, y, height);


Extends: nothing




None; an abstract class.

ColourConstants is a utility class consisting of static Color3f objects. It serves no purpose other than to provide easy access to pre-defined colours to the rest of the project.


Files and Running

Or click here to download them all.

To run, simply compile all classes (ensuring the Java3D JARs are on your classpath) and run Kitchen.