I have the following code for a light in Java3D. After my scene has been created, I have a separate thread which should turn the light off. When the my code calls:
setEnable(true);
I get a get the following error:
Exception in thread "Thread-3" javax.media.j3d.CapabilityNotSetException: Light: no capability to set light's state
at javax.media.j3d.Light.setEnable(Light.java:281)
at LightOnOff.run(Main.java:335)
at java.lang.Thread.run(Unknown Source)
Here is my code for the light:
public class Lamp3D extends Group {
PointLight lampLight;
public Lamp3D() {
this.createSceneGraph();
}
public void createSceneGraph() {
TransformGroup transformGroup = new TransformGroup();
Transform3D transform = new Transform3D();
//Light
lampLight = new PointLight(true,new Color3f(1.0f, 1.0f, 1.0f), new Point3f(-0.0f,1.62f, -0.0f), new Point3f(.0f, .6f, .0f));
lampLight.setInfluencingBounds(new BoundingSphere(new Point3d(0f, 1.62f, -0.0f), 100));
this.addChild(lampLight);
}
public PointLight getLampLight() {
return lampLight;
}
And my main:
BranchGroup group = new BranchGroup();
TransformGroup transformGroup = new TransformGroup();
Transform3D transform = new Transform3D();
// LAMP
transformGroup = new TransformGroup();
transform.setTranslation(new Vector3f(4.25f, 0.1f, -3.5f));
transformGroup.setTransform(transform);
Lamp3D lamp3D = new Lamp3D();
transformGroup.addChild(lamp3D);
group.addChild(transformGroup);
universe.getViewingPlatform().setNominalViewingTransform();
// add the group of objects to the Universe
universe.addBranchGraph(group);
/*Viewing scene and moving around*/
Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
ViewingPlatform viewPlatform = universe.getViewingPlatform();
BoundingSphere boundingSphere = new BoundingSphere(new Point3d(0f, 0f, 0f), 100f);
OrbitBehavior orbitBehaviour = new OrbitBehavior(canvas,
OrbitBehavior.REVERSE_ALL | OrbitBehavior.STOP_ZOOM);
orbitBehaviour.setSchedulingBounds(boundingSphere);
viewPlatform.setViewPlatformBehavior(orbitBehaviour);
/*Viewing scene and moving around*/
Thread t = new Thread(new LightOnOff(lamp3D));
t.start();
Does anybody know why this is happening? Also should I be using behaviors to interact with the scene?
You need to set the proper capabilities of the light:
lampLight.setCapability(Light.ALLOW_STATE_WRITE);