Storing state info along with geometry in Scene?

I thought I could store info about my object (a ship in this case) in with the geometry in the scene graph.

I basically did:
public class Ship extends Cone {
public TransformGroup tg = null;

 // more code

}

When I pick the shape using a mouse behavior (WakeupOnAWTEvent) and do a node instanceof Ship, it returns false. It is a Shape3D, but it doesn’t associate with Ship, and a cast throws a ClassCastException.

I’m assuming that the scenegraph only retains the geometry info? (I’m obviously doing something wrong!) Should this work? Or is there a better way to associate state info with the scene graph objects?

its simply because Cone is not a Shape3D.
For your test to succeed, use
Shape3D pickedShape = ((Cone) node).getShape();

Oh, by the way, is there a problem using mouse listeners directly on Canvas3D, instead of AWTEvent behaviors?

We published a ‘userdata’ object deep into a subgraph to indentify game-related objects from a node.

And I have MouseListeners on the Canvas3D. Works as expected.

[quote] And I have MouseListeners on the Canvas3D. Works as expected.
[/quote]
That’s what i do, also and did notice no problems. Wondering why they crated those behaviors, then… Bah…

Thanks for the hint about the Cone. But the strange thing is I removed everything else from my scenegraph except the Ship, and I was still picking a Shape3D.

Doing a System.out.println of the sceneGraphPath I get back the following:
SceneGraphPath=javax.media.j3d.Locale@cdb06e : JavaMOO.Ship : javax.media.j3d.Shape3D

I thought I read somewhere that as of J3D vs 1.3 (or 1.3.1? or 1.3.1beta) that the Cone/Sphere/etc are now Shape3D’s. Of course now I can’t find that anywhere.

Here’s my whole definition of Ship:

public class Ship extends Cone {
public TransformGroup tg = null;

/** Creates new Ship */
public Ship(TransformGroup tg) {
    super(0.2f, 0.5f);
    this.tg = tg;

    Appearance a = new Appearance();
    Material m = new Material();
    a.setMaterial(m);
    setAppearance(a);

}

}

In the end, this returns the actual ship Node:
Node n0 = sceneGraphPath.getNode(0);

As for doing the AWT events myself, I’ll probably end up doing that, but for now I’m playing with all the behaviors and “automagic” stuff. Haven’t used J3D in about a year now, so getting back up to speed :slight_smile: