2013-04-26 35 views
0

我對Java3D中的燈具有以下代碼。我的場景創建完成後,我有一個單獨的線程可以關閉燈光。當我的代碼調用:禁用PointLight拋出CapabilityNotSetException

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

有人知道爲什麼會發生這種情況嗎?我也應該使用行爲來與場景交互?

回答

相關問題