Thanks to those who responded to my question.
I must be dense, but I'm still not getting it. I just can't figure out
why the code below doesn't work. There's not much to it, just a block, a
background, a light or two, and the required objects for it to show up
on the screen. (I've even removed all applet functions)
Can someone please look it over and tell me where I've gone wrong?
//------[snip here]--------------------------
import com.sun.j3d.utils.behaviors.mouse.MouseRotate;
import com.sun.j3d.utils.behaviors.mouse.MouseZoom;
import com.sun.j3d.utils.behaviors.mouse.MouseTranslate;
import java.applet.*;
import java.awt.*;
import java.lang.Float;
import java.io.*;
import java.net.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import java.util.Enumeration;
import com.sun.j3d.utils.image.TextureLoader;
public class NewWorld001 extends Applet implements ActionListener
{
TransformGroup moveView = new TransformGroup();
public BranchGroup objectGraph()
{
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f diffuseRed = new Color3f(0.75f, 0.0f, 0.0f);
Color3f specularRed = new Color3f(1.0f, 0.2f, 0.3f);
Color3f ambientRed = new Color3f(0.35f, 0.0f, 0.0f);
// Create the branch group
BranchGroup branchGroup = new BranchGroup();
// Create a Transformgroup to scale all objects so they appear in the
scene.
TransformGroup objScale = new TransformGroup();
objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D t3d = new Transform3D();
t3d.setScale(0.1);
objScale.setTransform(t3d);
branchGroup.addChild(objScale);
// Create the bounding leaf node
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
100.0);
BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);
objScale.addChild(boundingLeaf);
// Create the red appearance node
Material redMaterial = new Material(ambientRed, black, diffuseRed,
specularRed, 100.0f);
redMaterial.setLightingEnable(true);
Appearance redAppearance = new Appearance();
redAppearance.setMaterial(redMaterial);
// Create the transform node
TransformGroup transformGroup = new TransformGroup();
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Box bx = new Box(1.0f,1.0f,1.0f, redAppearance);
transformGroup.addChild(bx);
objScale.addChild(transformGroup);
// Create the drag behavior node
MouseRotate behavior = new MouseRotate();
behavior.setTransformGroup(moveView);
moveView.addChild(behavior);
behavior.setSchedulingBounds(bounds);
// Create the zoom behavior node
MouseZoom behavior2 = new MouseZoom();
behavior2.setTransformGroup(moveView);
moveView.addChild(behavior2);
behavior2.setSchedulingBounds(bounds);
// Create the translate behavior node
MouseTranslate behavior3 = new MouseTranslate();
behavior3.setTransformGroup(moveView);
moveView.addChild(behavior3);
behavior3.setSchedulingBounds(bounds);
moveView.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
moveView.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
branchGroup.addChild(moveView);
// Let Java 3D perform optimizations on this scene graph.
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);
branchGroup.compile();
return branchGroup;
}
public BranchGroup createSceneGraph()
{
// Define colors
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Color3f bgColor = new Color3f(0.8f, 0.8f, 0.2f);
// Create the branch group
BranchGroup branchGroup = new BranchGroup();
// Create a Transformgroup to scale all objects so they appear in the
scene.
TransformGroup objScale = new TransformGroup();
objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
objScale.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D t3d = new Transform3D();
t3d.setScale(0.04);
objScale.setTransform(t3d);
branchGroup.addChild(objScale);
// Create the bounding leaf node
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0),
100.0);
BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);
objScale.addChild(boundingLeaf);
// Get the texture
TextureLoader texl = new TextureLoader("out001.jpg", this);
ImageComponent2D tex = texl.getImage();
// Set up the background
Background bg = new Background(bgColor);
bg.setApplicationBounds(bounds);
bg.setImage(tex);
objScale.addChild(bg);
// Create the ambient light
AmbientLight ambLight = new AmbientLight(white);
ambLight.setInfluencingBounds(bounds);
objScale.addChild(ambLight);
// Create the directional light
Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);
DirectionalLight dirLight = new DirectionalLight(white, dir);
dirLight.setInfluencingBounds(bounds);
objScale.addChild(dirLight);
// Create the point light
Point3f pos = new Point3f(10.0f, 15.0f, 10.0f);
PointLight ptLight = new PointLight();
ptLight.setPosition(pos);
objScale.addChild(ptLight);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
return branchGroup;
}
BranchGroup scene;
public void init()
{
// Set the layout manager
setLayout(new BorderLayout());
// Create the 3D canvas
Canvas3D canvas = new Canvas3D(null);
add("Center", canvas);
// Create the scene branch graph
scene = createSceneGraph();
scene.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
scene.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
BranchGroup scene2 = objectGraph();
scene.addChild(scene2);
scene.compile();
// Create the Universe, the Locale, and the view branch graph
SimpleUniverse u = new SimpleUniverse(canvas);
// This will move the ViewPlatform back a bit so the objects in the
scene can be viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
//---------------------------------------------------
TransformGroup t = u.getViewingPlatform().getViewPlatformTransform();
Transform3D trans = new Transform3D();
t.getTransform(trans);
Transform3D holder2 = new Transform3D();
moveView.getTransform(holder2);
t.setTransform(holder2);
//---------------------------------------------------
frame = new Frame("Drag the mouse in the window");
frame.setSize(480,480);
frame.add("Center", newWorld001);
frame.addWindowListener(new killAdapter());
frame.setVisible(true);
}
// Inner class used to "kill" the window when running as an
application.
static class killAdapter extends WindowAdapter
{
public void windowClosing(WindowEvent event)
{
System.exit(0);
}
}
/**
* Used when running as an application.
*/
public void actionPerformed(ActionEvent ev)
{
}
public static NewWorld001 newWorld001;
public static Frame frame;
public static void main(String[] args)
{
newWorld001 = new NewWorld001();
//NewWorld001.setAppletFlag(false);
newWorld001.init();
}
}
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/