This discussion is archived
9 Replies Latest reply: Oct 18, 2010 11:41 AM by 806264 RSS

Changing appearance on live objects, can't figure out the proper capability

843799 Newbie
Currently Being Moderated
I've been trying to change the appearance of given objects in my scene graph (Box objects) in response to being picked. However, I keep getting a:

Shape3D: no capability to set appearance

error, and can't seem to figure out what capability I must set the Box objects to allow. Here is the pertinent code so far,

(within the class that creates a Box)
          box.setCapability(Box.ALLOW_PICKABLE_READ);
          box.setCapability(Box.ALLOW_PICKABLE_WRITE);
          box.setCapability(Box.ENABLE_APPEARANCE_MODIFY);
          box.setCapability(Box.ENABLE_PICK_REPORTING);

(within the picking class)

public class PickingListener extends MouseAdapter {
     
private PickCanvas pickCanvas;
private Box p;
     
     public PickingListener(PickCanvas pickCanvasArg) {
          pickCanvas = pickCanvasArg;
     }
          
     public void mouseClicked(MouseEvent e)     {
pickCanvas.setShapeLocation(e);
PickResult result = pickCanvas.pickClosest();
if (result == null) {
System.out.println("Nothing picked");
} else {
p = (Box)result.getNode(PickResult.PRIMITIVE);
if (p != null) {
     setSelectedColor();
System.out.println(p.getClass().getName());
System.out.println((((BarInformation)p.getUserData()).toString()));
} else{
System.out.println("null");
}
}
     }
     
     private void setSelectedColor() {
          Appearance barAppearance = new Appearance();
          ColoringAttributes barCA = new ColoringAttributes();
          barCA.setColor(ColorConstants.SELECTED);
          barAppearance.setColoringAttributes(barCA);
          p.setAppearance(barAppearance);
     }

Being unable to set the objects color/appearance after going live has been very frustrating. Any help offered will be greatly appreciated!

-Adrian
  • 1. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    Box is not a Shape3D, but its components are.
    I believe that Box.getShape( eg Box.BACK) for each side of the box will be more appropriate if you want to update the Color (though I have`nt used it). That returns a shape, which you can set the capability bits of.

    regards
  • 2. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    I set the Box's capability to ENABLE_APPEARANCE_MODIFY, which is supposed to allow the Box's Geometry child node have Appearance objects be read from/written to. It doesn't seem reasonable that I would be forced to set the Appearance of each of the six faces. For some reason, I think it should be simpler than that.

    Thank you for your assistance,

    -Adrian
  • 3. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    yes its the appearance settings you should be dealing with as well as the pick settings.

    i have:
    Appearance app = new Appearance();
            app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
            app.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    cola = new ColoringAttributes();
            cola.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
            cola.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
    which seems to do the trick.
  • 4. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    Still did not work with the following capabilities set:

    Appearance barAppearance = ...;
    ColoringAttributes barCA = ...;
    Box bar = ...;
    barAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ); barAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

    barCA.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
    barCA.setCapability(ColoringAttributes.ALLOW_COLOR_READ);

              bar.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
              bar.setCapability(Box.ALLOW_PICKABLE_READ);
              bar.setCapability(Box.ALLOW_PICKABLE_WRITE);
              bar.setCapability(Box.ENABLE_APPEARANCE_MODIFY);
              bar.setCapability(Box.ENABLE_PICK_REPORTING);

    -Adrian
  • 5. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    Sorry about that last post, setting the capability of the Appearance and ColoringAttributes objects did the trick, thank you very much!

    -Adrian
  • 6. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    hi
    i just ran into the same problem but can't figure out what i did wrong...
    private void createBox() {
              Appearance ap = new Appearance();
              ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_READ);
              ap.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);
    
              ColoringAttributes ca = new ColoringAttributes();
              ca.setCapability(ColoringAttributes.ALLOW_COLOR_READ);
              ca.setCapability(ColoringAttributes.ALLOW_COLOR_WRITE);
              ap.setColoringAttributes(ca);
    
              PolygonAttributes pa = new PolygonAttributes();
              pa.setCullFace(PolygonAttributes.CULL_NONE);
              pa.setPolygonMode(PolygonAttributes.POLYGON_LINE);
              ap.setPolygonAttributes(pa);
    
              box = new Box(sideLength / 2, sideLength / 2, sideLength / 2, ap);
              box.setCapability(Box.ALLOW_CHILDREN_WRITE);
              box.setCapability(Box.ALLOW_CHILDREN_READ);
              box.setCapability(Box.ENABLE_APPEARANCE_MODIFY);          
    
              TransformGroup boxGroup = new TransformGroup();
              Transform3D trans = new Transform3D();
              trans.setTranslation(new Vector3d(0.0, sideLength / 2, 0));
              boxGroup.setTransform(trans);
    
              parent.addChild(boxGroup);
              boxGroup.addChild(box);
         }
    
         public void setColor(Color c) {
              Appearance ap = box.getAppearance();
              ColoringAttributes ca = ap.getColoringAttributes();
              ca.setColor(new Color3f(c));
              ap.setColoringAttributes(ca);
              box.setAppearance(ap);
         }
    looks fine to me.
    i also tried different methods for setColor() (new appearance, global saved appearance etc...) but nothing worked.
    i always get the same error.

    Exception in thread "AWT-EventQueue-0" javax.media.j3d.CapabilityNotSetException: Shape3D: no capability to set appearance
         at javax.media.j3d.Shape3D.setAppearance(Shape3D.java:488)

    any clue someone?
  • 7. Re: Changing appearance on live objects, can't figure out the proper capabi
    843799 Newbie
    Currently Being Moderated
    Hello,

    first of all I know that this thread is quite old. Please refrain from noting that replying to an old thread doesn't make any sense, because it does.
    I don't know why the mentioned solution works for the thread opener. It does not for me. And it apparently doesn't work for anyone else.


    Apparently the following line of code doesn't seem to do anything:

    box.setCapability(ENABLE_APPEARANCE_MODIFY);

    So I guess, ENABLE_APPEARANCE_MODIFY cannot be set by setCapability. Maybe this even isn't a capability at all.


    Instead you have to use this constant as a primflag when you're instantiating the Primitive.

    box = new Box(size, size, size, ENABLE_APPEARANCE_MODIFY, ap);


    You can still set the capability bits of the Appearance objects. But this is only necessary if you really want to alter these objects. You don't have to set these bits if you only want to swap appearances.


    Please correct me! Thank you.
  • 8. Re: Changing appearance on live objects, can't figure out the proper capabi
    PhHein Guru Moderator
    Currently Being Moderated
    Don'zt post to old threads, please. Locking.
  • 9. Re: Changing appearance on live objects, can't figure out the proper capabi
    806264 Newbie
    Currently Being Moderated
    How else are new comers suppose to figure out there errors if we just stop talking about the solution.


    It makes this forum pretty dumb in my opinion. People are suppose to find answers to questions people before them have figured out