Real Time?

Hey all,

I’m having a bit of trouble getting started with Java 3D… I can get a BranchGroup to render and all, rotate a cube, etc. But after the scene is compiled (BranchGroup.compile()), I can’t set the Transform3D object on my TransformGroup object. Here’s my code:

[quote]import java.awt.;
import javax.swing.
;
import javax.media.j3d.;
import com.sun.j3d.utils.universe.
;
import com.sun.j3d.utils.geometry.*;

public class Test extends JFrame {
TransformGroup cubeTG = new TransformGroup();

public Test() {
	setSize(400, 300);
	setResizable(false);
	setDefaultCloseOperation(EXIT_ON_CLOSE);

	GraphicsConfiguration gc = SimpleUniverse.getPreferredConfiguration();
	Canvas3D c = new Canvas3D(gc);
	getContentPane().add(c);

	BranchGroup scene = new BranchGroup();

	scene.addChild(cubeTG);
	cubeTG.addChild(new ColorCube(0.4));

	scene.compile();

	SimpleUniverse su = new SimpleUniverse(c);
	su.getViewingPlatform().setNominalViewingTransform();
	su.addBranchGraph(scene);

	setVisible(true);

	while(true) {
		Transform3D t3d = new Transform3D();
		cubeTG.getTransform(t3d);

		t3d.rotY(Math.toRadians(1));

		cubeTG.setTransform(t3d);
	}
}

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

}
[/quote]
I recieve the following exception:

[quote]Exception in thread “main” javax.media.j3d.CapabilityNotSetException: Group: no
capability to set transform
at javax.media.j3d.TransformGroup.setTransform(TransformGroup.java:115)
at Test.(Test.java:38)
at Test.main(Test.java:43)
[/quote]
If I can’t set the transform on an object after the scene has been compiled, how can I render in real time (for 3D games…)?

You need to set ALLOW_TRANSFORM_WRITE as one of the attributes on your transformgroup before you compile it- basically compiling will allow Java3D to optimise your scene as much as possible, if it knows an object won’t be moved it can perform some optimisations that it couldn’t perform if the object will be moved, so you need to tell it ahead of time.

I wrote a tutorial on basic Java3D for games a few years back, I suspect it may be a little out of date by now but there will probably be some stuff there that is useful to you- you can find it here

Alright! Thanks so much, Breakfast. It works just as I wanted it to. I’ll have a look at your tutorial now too.