Java 3D is a graph-based modelling application for the Java platform. It is unlike most 3D modelers as you do not create objects by dragging and dropping. In Java 3D, you code manually. Creating a solar system is time-consuming as each object must be coded individually.

  • Java 3D is a graph-based modelling application for the Java platform.
  • It is unlike most 3D modelers as you do not create objects by dragging and dropping.

Study Java and Java 3D coding. Purchase books on these topics and see the links under Resources.

Download, install and run solar system models. Look at the source code. Do not copy the code, as that is plagiarism.

Open the Java 3D application.

Create the sun, the central object of the solar system. Code in lighting to give it a 3D feel. Input the following code from the website Java3D to create a ball with light hitting it:

import com.sun.j3d.utils.geometry.*;

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

import com.sun.j3d.utils.universe.*;

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

import javax.media.j3d.*;

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

import javax.vecmath.*;

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

public class Ball {

public Ball() {

SimpleUniverse universe = new SimpleUniverse();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

BranchGroup group = new BranchGroup();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Sphere sphere = new Sphere(0.5f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

group.addChild(sphere);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Color3f light1Color = new Color3f(1.8f, 0.1f, 0.1f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

BoundingSphere bounds =

new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

DirectionalLight light 1


              = new DirectionalLight(light1Color, light1Direction);
            

light1.setInfluencingBounds(bounds);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

group.addChild(light1);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

universe.getViewingPlatform().setNominalViewingTransform();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

universe.addBranchGraph(group);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

}

public static void main(String[] args) { new Ball(); }

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

}

Place the sun in the middle. Typically the coordinates will be (0,0,0) unless you want your solar system angled.

Set the object's texture and colour. This makes the object look more realistic. Choose colours to mix with the following code:

Color3f black = new Color3f(0.0f, 0.0f, 0.0f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Color3f white = new Color3f(1.0f, 1.0f, 1.0f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Color3f yellow = new Color3f(0.7f, .15f, .15f);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

TextureLoader loader = new TextureLoader("K:\3d\Arizona.jpg",


              "LUMINANCE", new Container());
            

Texture texture = loader.getTexture();

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

texture.setBoundaryModeS(Texture.WRAP);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

texture.setBoundaryModeT(Texture.WRAP);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

texture.setBoundaryColor( new Color4f( 0.0f, 1.0f, 0.0f, 0.0f ) );

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Add code that alters the texture. There are four ways a texture can be displayed; blended, decaled, replaced or modulated. The modulated option provides the most realistic result. Here is sample code for modulating:

  • Add code that alters the texture.
  • There are four ways a texture can be displayed; blended, decaled, replaced or modulated.
  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

              TextureAttributes texAttr = new TextureAttributes();
            

texAttr.setTextureMode(TextureAttributes.MODULATE);

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

              Appearance ap = new Appearance();



ap.setTexture(texture);



ap.setTextureAttributes(texAttr);
            

ap.setMaterial(new Material(red, black, red, black, 1.0f));

  • import javax.media.j3d.
  • *;
  • Open the Java 3D application.
  • Input the following code from the website Java3D to create a ball with light hitting it: import com.sun.j3d.utils.geometry.
  • *;

Repeat Steps 4-7 for every object in the solar system.