禁用PointLight会抛出CapabilityNotSetException

时间:2013-04-26 23:08:51

标签: java java-3d scenegraph

我在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();

有人知道为什么会这样吗?我也应该使用行为来与场景互动吗?

1 个答案:

答案 0 :(得分:2)

您需要设置灯光的正确功能:

lampLight.setCapability(Light.ALLOW_STATE_WRITE);

Read more about Java 3D capabilities ...