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

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

[1806 byte] By [Sorbetsa] at [2007-9-25]
# 1
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
messengersa at 2007-7-15 > top of java,Security,Cryptography...
# 2

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

Sorbetsa at 2007-7-15 > top of java,Security,Cryptography...
# 3

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.

Jammy@Javaa at 2007-7-15 > top of java,Security,Cryptography...
# 4

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

Sorbetsa at 2007-7-15 > top of java,Security,Cryptography...
# 5
Sorry about that last post, setting the capability of the Appearance and ColoringAttributes objects did the trick, thank you very much!-Adrian
Sorbetsa at 2007-7-15 > top of java,Security,Cryptography...
# 6

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?

jreuscha at 2007-7-15 > top of java,Security,Cryptography...