Changing appearance of live objects

Hi!
I have an universe with a few objects. I want to change the appearance of one of them in response to a user event. But what occurs is that the first time I call setAppearance on the object, the appearance changes, but subsequent calls have no effect.

The capability bit Shape3D.ALLOW_APPEARANCE_WRITE is set, but not setting it has the same result. Note that my scenegraph is not compiled.

I there something else to do to be able to change the appearance of a live object?

Here is a snippet of the code I use:
do
{
System.out.println(“red”);
theShape.setAppearance(theRed);
view.renderOnce();
view.renderOnce();
view.renderOnce();
view.renderOnce();
view.renderOnce();
Thread.sleep(1000);

  System.out.println("green");
  theShape.setAppearance(theGreen);
  view.renderOnce();
  Thread.sleep(1000);

} while (true);

The idea is that I have created a universe and added a Shape3D (theShape) to it. I also created two appearances, theRed and theGreen. Then I have a loop in which I switch between red and green appearances every second.
The multipe calls to view.renderOnce() are included to demonstrate that it is not the fact that the view has already been rendered that prevents the appearance to change, as in the first iteration of the loop the object indeed turns green. But afterwards it stays green forever, although the console keeps printing “red” and “green”, prooving that the loop is still being executed.

If needed I can file an issue and attache the complete test case.

Ran into the same problem myself;

theShape…setAtom(null);

does the trick, but I don’t know if that’s the correct way to do it.

Björn

Hi,

Well, this problem is an open issue for Xith3D renderer. Shape itself currently does not maintain changed flag and does not track the change of Appearance object, but lets Appearance to track its changes itself.

The easiest workaround is to call Appearance.setChanged(false), but in fact this will cause some performance loss. setAtom(null) will also work, but this should not be sued because of not guaranteed to be compatible with future releases.

What you can do is to change only modified components of your Appearance, such as ColoringAttributes, and this will work OK.

Anyway, we should check deeper how to add this check most efficient way. You can file an issue so we will have this fix on the list.

Yuri

Is this the same for visibility? I called setVisible (false) on a node but it had no effect.
Well thinking about it, it mustn’t be the same problem, as I call setVisible prior to adding the node to a parent.
Any idea what happens here?

{Edit:} Node.setLive() doesn’t work here, too.
My workaround is to use some Switch group (instead of normal Group) and use the Bitmask to make my models visible or hidden.
In case the model won’t have to show up again, I remove it from the scenegraph entirely.

RenderingAttributes.setVisible(false) should work for the Shape3Ds, and it works for me.

If it does not work for you, I need a test case [as always].

Yuri

P.S. Also note that capability bits have no effect in Xith3D and left there just for compatibility with Java3D source code.

[quote]RenderingAttributes.setVisible(false) should work for the Shape3Ds, and it works for me.

If it does not work for you, I need a test case [as always].
[/quote]
Sorry for the confusing, I meant Node.setLive(), not setVisibility. :expressionless: (I’ll edit my other article)
The RenderingAttributes.setVisibility I didn’t know yet, thanks for the hint.

[quote]P.S. Also note that capability bits have no effect in Xith3D and left there just for compatibility with Java3D source code.
[/quote]
I see.

I was trying to make a Group invisible; as Groups don’t have Appearance, they don’t have RenderingAttributes either.
So, the question is: is Group.setVisible expected to work?

You can use Group.setRenderable(false) to leave it (and its children) out of rendering process.

Yuri

Thanks! It works.