我有以下代码用于 Java3D 中的灯光。创建场景后,我有一个单独的线程应该关闭灯。当我的代码调用时:
setEnable(true);
我收到以下错误:
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)
这是我的灯光代码:
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;
}
而我的主要:
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();
有谁知道为什么会这样?我还应该使用行为与场景进行交互吗?