Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Capability Not Set Exception

843799Nov 16 2006 — edited Nov 20 2006
Hi i was just wondering could anybody help me with my first Java 3d program, The program runs but it throws a capability not set exception even though I have set them in the program!!!!

I include the program below, the error is as follows:

Exception occurred during Behavior execution:
javax.media.j3d.CapabilityNotSetException: Group: no capability to set transform

at javax.media.j3d.TransformGroup.setTransform(TransformGroup.java:115)
at javax.media.j3d.TransformInterpolator.processStimulus(TransformInterp
olator.java:156)
at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
at javax.media.j3d.J3dThread.run(J3dThread.java:250)
Exception occurred during Behavior execution:
javax.media.j3d.CapabilityNotSetException: Group: no capability to set transform

at javax.media.j3d.TransformGroup.setTransform(TransformGroup.java:115)
at javax.media.j3d.TransformInterpolator.processStimulus(TransformInterp
olator.java:156)
at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
at javax.media.j3d.J3dThread.run(J3dThread.java:250)
Exception occurred during Behavior execution:
javax.media.j3d.CapabilityNotSetException: Group: no capability to set transform

at javax.media.j3d.TransformGroup.setTransform(TransformGroup.java:115)
at javax.media.j3d.TransformInterpolator.processStimulus(TransformInterp
olator.java:156)
at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
at javax.media.j3d.J3dThread.run(J3dThread.java:250)
Exception occurred during Behavior execution:
javax.media.j3d.CapabilityNotSetException: Group: no capability to set transform

at javax.media.j3d.TransformGroup.setTransform(TransformGroup.java:115)
at javax.media.j3d.TransformInterpolator.processStimulus(TransformInterp
olator.java:156)
at javax.media.j3d.BehaviorScheduler.doWork(BehaviorScheduler.java:172)
at javax.media.j3d.J3dThread.run(J3dThread.java:250)










The program is here:

import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.GraphicsConfiguration;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.image.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.Container;
import java.io.Serializable;


public class HelloUniverse extends Applet
{
private SimpleUniverse u = null;
public BranchGroup createSceneGraph()
{

/****************************************************************************************
Declarations
****************************************************************************************/

BranchGroup objRoot = new BranchGroup();
BoundingSphere bounds = new BoundingSphere(new Point3d (0.0, 0.0, 0.0), 100.0);
Point3f attenuation = new Point3f(-6.0f,-6.0f,-6.0f);
Vector3f light1Direction = new Vector3f(0.0f, 0.0f, 0.0f);
Point3f position = new Point3f(6.0f,6.0f,6.0f);
Color3f light1Color = new Color3f(1.0f, 1.f, 1.f);
Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
TextureAttributes texAttributes = new TextureAttributes();
int primflags = Primitive.GENERATE_NORMALS + Primitive.GENERATE_TEXTURE_COORDS;

/****************************************************************************************
Background
****************************************************************************************/

TextureLoader backgroundTexture = new TextureLoader("stars.jpg", this);
Background background = new Background(backgroundTexture.getImage());
background.setApplicationBounds(bounds);
objRoot.addChild(background);

/****************************************************************************************
Earth
****************************************************************************************/

TextureLoader earthTexture = new TextureLoader("earth.jpg", this);
Texture earthTex = earthTexture.getTexture();
Appearance appEarth = new Appearance();
appEarth.setTextureAttributes(texAttributes);
appEarth.setTexture(earthTex);
appEarth.setMaterial(new Material(white, black, white, black, 128.0f));
Sphere earth = new Sphere(0.13f, primflags, 80,appEarth);
TransformGroup objTransEarth = new TransformGroup();
objTransEarth.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransEarth.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
Transform3D transformEarth = new Transform3D();
Vector3f vectorEarth = new Vector3f(0.0f, 0.0f, 0.86f);
transformEarth.set(vectorEarth);
TransformGroup earthT = new TransformGroup(transformEarth);

objTransEarth.addChild(earthT);
earthT.addChild(earth);
objRoot.addChild(objTransEarth);

/****************************************************************************************
Sun
****************************************************************************************/

TextureLoader sunTexture = new TextureLoader("sun.jpg", this);
Texture sunTex = sunTexture.getTexture();
Appearance appSun = new Appearance();
texAttributes.setTextureMode(TextureAttributes.MODULATE);
appSun.setTextureAttributes(texAttributes);
appSun.setTexture(sunTex);
//appSun.setMaterial(new Material(white, black, white, black, 128.0f));
Sphere sun = new Sphere(0.2f, primflags, 80, appSun);
TransformGroup objTransSun = new TransformGroup();
objTransSun.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransSun.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
Transform3D transformSun = new Transform3D();
Vector3f vectorSun = new Vector3f(0.0f, 0.0f, 0.0f);
transformSun.set(vectorSun);
TransformGroup sunT = new TransformGroup(transformSun);
objTransSun.addChild(sunT);
sunT.addChild(sun);
objRoot.addChild(objTransSun);

/****************************************************************************************
Moon
****************************************************************************************/

TextureLoader moonTexture = new TextureLoader("moon.jpg", this);
Texture moonTex= moonTexture.getTexture();
Appearance appMoon = new Appearance();
texAttributes.setTextureMode(TextureAttributes.MODULATE);
appMoon.setTextureAttributes(texAttributes);
appMoon.setTexture(moonTex);
appMoon.setMaterial(new Material(white, black, white, black, 128.0f));
Sphere moon = new Sphere(0.06f, primflags, 80, appMoon);
TransformGroup objTransMoon = new TransformGroup();
objTransMoon.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransMoon.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
Transform3D transformMoon = new Transform3D();
Vector3f vectorMoon = new Vector3f(0.15f, 0.2f, 0.2f);
transformMoon.set(vectorMoon);
TransformGroup moonT = new TransformGroup(transformMoon);
objTransMoon.addChild(moonT);
moonT.addChild(moon);
objRoot.addChild(objTransMoon);

/****************************************************************************************
Saturn
****************************************************************************************/

Material shine = new Material();
shine.setShininess(128.0f);
TextureLoader saturnTexture = new TextureLoader("saturn.jpg", this);
Texture saturnTex= saturnTexture.getTexture();
Appearance appSaturn = new Appearance();
texAttributes.setTextureMode(TextureAttributes.MODULATE);
appSaturn.setTextureAttributes(texAttributes);
appSaturn.setTexture(saturnTex);
appSaturn.setMaterial(new Material(white, black, white, black, 128.0f));
Sphere saturn = new Sphere(0.1f,primflags, 80, appSaturn);
TransformGroup objTransSaturn = new TransformGroup();
objTransSaturn.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransSaturn.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
Transform3D transformSaturn = new Transform3D();
Vector3f vectorSaturn= new Vector3f(0.0f, 0.5f, 1.0f);
transformSaturn.set(vectorSaturn);
TransformGroup saturnT = new TransformGroup(transformSaturn);

objTransSaturn.addChild(saturnT);
saturnT.addChild(saturn);
appSaturn.setMaterial(shine);
objRoot.addChild(objTransSaturn);

/****************************************************************************************
Neptune
****************************************************************************************/


TextureLoader neptuneTexture = new TextureLoader("neptune.jpg", this);
Texture neptuneTex= neptuneTexture.getTexture();
Appearance appNeptune = new Appearance();
texAttributes.setTextureMode(TextureAttributes.MODULATE);
appNeptune.setTextureAttributes(texAttributes);
appNeptune.setTexture(neptuneTex);
appNeptune.setMaterial(new Material(white, black, white, black, 128.0f));
Sphere neptune = new Sphere(0.1f,primflags, 80, appNeptune);
TransformGroup objTransNeptune = new TransformGroup();
objTransNeptune.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
objTransNeptune.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
Transform3D transformNeptune = new Transform3D();
Vector3f vectorNeptune= new Vector3f(1.0f, 0.0f, 0.86f);
transformNeptune.set(vectorNeptune);
TransformGroup neptuneT = new TransformGroup(transformNeptune);
objTransNeptune.addChild(neptuneT);
neptuneT.addChild(neptune);
appNeptune.setMaterial(shine);
objRoot.addChild(objTransNeptune);

/****************************************************************************************
Lights
****************************************************************************************/

PointLight light1 = new PointLight();
light1.setEnable(true);
light1.setColor(light1Color);
light1.setPosition(position);
light1.setAttenuation(attenuation);
light1.setInfluencingBounds(bounds);
light1.setCapability(Light.ALLOW_STATE_WRITE);
objRoot.addChild(light1);

/*PointLight light1 = new PointLight();
TransformGroup objTransLight = new TransformGroup();
objTransLight.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
light1.setEnable(true);
light1.setColor(light1Color);
light1.setPosition(position);
light1.setAttenuation(attenuation);
light1.setInfluencingBounds(bounds);
objTransLight.addChild(light1);
objRoot.addChild(objTransLight);*/

/****************************************************************************************
Rotator Declarations
****************************************************************************************/

Alpha rotationAlpha = new Alpha(-1, 6000);
Alpha rotationSunAlpha = new Alpha(-1, 20000);
Alpha rotor2Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE,0, 0,1000, 0, 0, 0, 0, 0);
Alpha rotor3Alpha = new Alpha(-1, Alpha.INCREASING_ENABLE,0, 0,4000, 0, 0, 0, 0, 0);

/****************************************************************************************
Earth Rotator
****************************************************************************************/

Transform3D yAxisEarth = new Transform3D();
RotationInterpolator earthRotator = new RotationInterpolator(rotationAlpha, objTransEarth, yAxisEarth, 0.0f,(float) Math.PI*2.0f);
earthRotator.setSchedulingBounds(bounds);
objTransEarth.addChild(earthRotator);
RotationInterpolator earthRotator2 = new RotationInterpolator(rotor2Alpha, earthT, yAxisEarth, 0.0f, 0.0f);
earthRotator2.setSchedulingBounds(bounds);
objTransEarth.addChild(earthRotator2);

/****************************************************************************************
Sun Rotator
****************************************************************************************/

Transform3D yAxisSun = new Transform3D();
RotationInterpolator sunRotator = new RotationInterpolator(rotationSunAlpha, objTransSun, yAxisSun, 0.0f,(float) Math.PI*2.0f);
sunRotator.setSchedulingBounds(bounds);
objTransSun.addChild(sunRotator);

/****************************************************************************************
Moon Rotator
****************************************************************************************/

Transform3D yAxisMoon = new Transform3D();
RotationInterpolator moonRotator = new RotationInterpolator(rotationAlpha, objTransMoon, yAxisMoon, 0.0f,(float) Math.PI*2.0f);
moonRotator.setSchedulingBounds(bounds);
objTransMoon.addChild(moonRotator);
RotationInterpolator moonRotator2 = new RotationInterpolator(rotor2Alpha, moonT, yAxisMoon, 0.0f, 0.0f);
moonRotator2.setSchedulingBounds(bounds);
objTransMoon.addChild(moonRotator2);

/****************************************************************************************
Saturn Rotator
****************************************************************************************/

Transform3D yAxisSaturn = new Transform3D();
Transform3D yAxisSaturn2 = new Transform3D();
yAxisSaturn.rotZ(-(Math.PI/2.0d));
RotationInterpolator saturnRotator = new RotationInterpolator(rotor3Alpha,objTransSaturn, yAxisSaturn, 0.0f,(float) Math.PI*2.0f);
saturnRotator.setSchedulingBounds(bounds);
objTransSaturn.addChild(saturnRotator);
RotationInterpolator saturnRotator2 = new RotationInterpolator(rotor2Alpha, saturnT, yAxisSaturn2, 0.0f, 0.0f);
saturnRotator2.setSchedulingBounds(bounds);
objTransSaturn.addChild(saturnRotator2);

/****************************************************************************************
Neptune Rotator
****************************************************************************************/

Transform3D yAxisNeptune = new Transform3D();
Transform3D yAxisNeptune2 = new Transform3D();
yAxisNeptune.rotZ((Math.PI*3.0d));
RotationInterpolator neptuneRotator = new RotationInterpolator(rotor3Alpha,objTransNeptune, yAxisNeptune, 0.0f,(float) Math.PI*2.0f);
neptuneRotator.setSchedulingBounds(bounds);
objTransNeptune.addChild(neptuneRotator);
RotationInterpolator neptuneRotator2 = new RotationInterpolator(rotor2Alpha, neptuneT, yAxisNeptune2, 0.0f, 0.0f);
neptuneRotator2.setSchedulingBounds(bounds);
objTransNeptune.addChild(neptuneRotator2);

/****************************************************************************************
Light Rotator
****************************************************************************************/

/*Transform3D yAxisLight = new Transform3D();
RotationInterpolator lightRotator = new RotationInterpolator(rotationAlpha, objTransLight, yAxisLight, 0.0f,(float) Math.PI*2.0f);
lightRotator.setSchedulingBounds(bounds);
objTransLight.addChild(lightRotator);
RotationInterpolator lightRotator2 = new RotationInterpolator(rotor2Alpha, objTransLight, yAxisLight, 0.0f, 0.0f);
lightRotator2.setSchedulingBounds(bounds);
objTransLight.addChild(lightRotator2);*/

objRoot.compile();
return objRoot;
}

public HelloUniverse()
{
}
public void init()
{
setLayout(new BorderLayout());
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
Canvas3D c = new Canvas3D(config);
add ("Center", c);
// Creat simple scene and attach it to virtual universe
BranchGroup scene = createSceneGraph();
u = new SimpleUniverse(c);
// Set ViewPlatform a bit back so objects in scene can be
//viewed.
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);

}
public void destroy()
{
u.removeAllLocales();
}
// Add main so it can be run as an application as well as an
//applet
public static void main(String args[])
{
new MainFrame(new HelloUniverse(), 800, 700);
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2006
Added on Nov 16 2006
6 comments
1,093 views