At 02:50 11/06/99 PDT, you wrote:
>Dear All,
>
>I am still miffed at why I cannot modify the Appearance of the 
>utils.geometry Sphere class during execution. The CREATE SPHERES section 
>below shows my basic arrangement for creating a number of Spheres and 
>setting all capabilities to read and write. The MODIFY COLOUR section is the 
>method I use to modify the Appearance objects during execution. I keep 
>getting a
>
>javax.media.j3d.CapabilityNotSetException: Shape3D: no capability to
>
>set appearance
>        at javax.media.j3d.Shape3D.setAppearance(Compiled Code)
>        at com.sun.j3d.utils.geometry.Sphere.setAppearance(Compiled Code)
>        at appearance.ColourSchemeManager.process(Compiled Code)
>        at 
>appearance.AppearanceManager.setColourScheme(AppearanceManager.java:7
>
>exception when calling the MODIFY COLOUR part of the code. Strangely enouogh 
>if I use the COLORCUBE subclass of SHAPE3D then it all works fine. Is this 
>somethng to do with Sphere's superclass being PRIMITIVE???
>
>Any help REALLY appreciated.
>
>Cheers,
>
>Allistair Crossley
>
>CREATE SPHERES CODE

Part of the code from one of my trials Allistair.

M is a variable defined globally within the object so it can be accessed
anywhere in the object:

    ...
    M.setCapability(Material.ALLOW_COMPONENT_WRITE);
    app.setMaterial(M);
    Primitive ch1 = new Sphere((float)rad, Sphere.GENERATE_NORMALS |
Sphere.GENERATE_TEXTURE_COORDS, 20, app);
    ...

  public boolean changeColour(String s) {
    if (colourState.equals("Red")) {
      colourState = "Blue";
      M.setAmbientColor(blue);
      M.setEmissiveColor(darkblue);
      M.setDiffuseColor(blue);
      M.setSpecularColor(paleblue);
      return(true);
    }
    else {
      colourState = "Red";
      M.setAmbientColor(red);
      M.setEmissiveColor(darkred);
      M.setDiffuseColor(red);
      M.setSpecularColor(pink);
      return(true);
    }

Because of the setCapability ALLOW_COMPONENT_WRITE I can change the colour
of the sphere material.

    Box l2 = new Box(6.125f, 0.25f,
0.125f,Primitive.GENERATE_TEXTURE_COORDS|Primitive.GENERATE_NORMALS, app);    
    l2.setCapability(Box.ALLOW_COLLISION_BOUNDS_READ); 
    l2.setCapability(Box.ALLOW_COLLISION_BOUNDS_WRITE); 
    Shape3D sh2 = l2.getShape(l2.FRONT);
    sh2.setAppearance(ap1);
    sh2 = l2.getShape(l2.TOP);
    sh2.setAppearance(ap1);

Here I've created a green box (app is green though it doesn't show here).
I've got the front of the box and given it a different appearance (oak -
this is part of a snooker table).  If I'd set the capabilities, then I
could change appearances during execution, and different faces could change
at different times.

Hope this is of some use.

Tony

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to