A Java 3D API Tutorial
The Java 3D libraries allow programmers to manipulate shapes and images inside a virtual 3D environment complete with textures and lighting to simulate a true 3D experience. While jumping into the API is daunting, a few basic rules can help beginners understand the structure of a Java 3D program. By recognizing how to draw images, and that these images must be inserted into a "universe" or perspective that dictates how the 3D image appears to viewers, you can get a basic feel for how the Java 3D API works.
Instructions
-
-
1
Import the Java 3D libraries into your project:
import com.sun.j3d.*
public class 3DTest extends Applet{
-
2
Create a simple canvas in which images will exist:
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D canvas3D = new Canvas3D(config); -
-
3
Create a simple universe object:
add("Center", canvas3D);
BranchGroup scene = drawScene(); //method to create an image
scene.compile();SimpleUniverse simpleU = new SimpleUniverse(canvas3D);
-
4
Insert content into the local universe:
simpleU.getViewingPlatform().setNominalViewingTransform();
simpleU.addBranchGraph(scene); -
5
Define the "drawScene" method to draw "ColorCube" image in the created universe:
public BranchGroup drawScene() {
BranchGroup objRoot = new BranchGroup();objRoot.addChild(new ColorCube(0.4));
return objRoot;
}
-
1