You can detach the node if you set up the properties to allow you to do so
ahead of time, here is a small example program that does these things:
import java.applet.Applet;
import java.awt.event.*;
import javax.vecmath.*;
import javax.media.j3d.*;
import java.awt.*;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.geometry.*;
import java.util.Enumeration;
public class TestBed2 extends Applet implements ActionListener
{
TimerBehavior myBehavior = new TimerBehavior();
Behavior rotation = null;
BranchGroup timeBranch, mainBranch;
static public void main(String[] args)
{
new MainFrame(new TestBed2(), 300, 300);
}
TestBed2()
{
setLayout(new BorderLayout());
// Make the canvas. Use our derived canvas to compute frame rate.
GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
GraphicsConfiguration gcfg =
GraphicsEnvironment.getLocalGraphicsEnvironment().
getDefaultScreenDevice().getBestConfiguration(template);
Canvas3D canvas = new Canvas3D(gcfg);
canvas.setSize(300, 300);
add("Center", canvas);
// Make a button to toggle the behaviors.
Button button = new Button("PressMe");
add("East", button);
button.addActionListener(this);
// Create the universe.
SimpleUniverse universe = new SimpleUniverse(canvas);
// Create the main branch... add a rotating square for fun.
mainBranch = new BranchGroup();
mainBranch.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
mainBranch.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
RotatingSquare square = new RotatingSquare(0.0f, 0.0f);
mainBranch.addChild(square);
// Point to the rotation behavior so we can toggle it.
rotation = square.rotint;
// Add the timer behavior that will also be toggled.
timeBranch = new BranchGroup();
timeBranch.setCapability(BranchGroup.ALLOW_DETACH);
myBehavior.setSchedulingBounds(
new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0));
timeBranch.addChild(myBehavior);
mainBranch.addChild(timeBranch);
// Make the main branch live.
universe.addBranchGraph(mainBranch);
}
public void actionPerformed(ActionEvent event)
{
String command = event.getActionCommand();
if (command.equals("PressMe"))
{
boolean enabled = myBehavior.getEnable();
if (enabled) //myBehavior.setEnable();
timeBranch.detach();
else
mainBranch.addChild(timeBranch);
myBehavior.setEnable(!enabled);
rotation.setEnable(!rotation.getEnable());
}
}
} // END class TestBed2
class TimerBehavior extends Behavior
{
WakeupOnElapsedTime myWakeup = null;
int counter = 0;
public TimerBehavior()
{
}
public void initialize()
{
myWakeup = new WakeupOnElapsedTime(1000);
wakeupOn (myWakeup);
}
public void setEnable(boolean state)
{
super.setEnable(state);
System.out.println("state: " + state);
}
public void processStimulus(Enumeration criteria)
{
WakeupCriterion wakeup = null;
while(criteria.hasMoreElements())
{
wakeup = (WakeupCriterion)criteria.nextElement();
if (wakeup instanceof WakeupOnElapsedTime)
{
counter++;
System.out.println("I'm awake! " + counter);
}
} // END while
wakeupOn (myWakeup);
} // END processStimulus()
}
class RotatingSquare extends BranchGroup
{
public RotationInterpolator rotint = null;
RotatingSquare(float cx, float cy)
{
TransformGroup rotateGroup = new TransformGroup();
rotateGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Transform3D local = new Transform3D();
local.rotX(1.57); // this will move the axis of rotation from +Y to +Z
axis
local.setTranslation(new Vector3f(cx, cy, 0.0f));
Alpha alpha = new Alpha(-1, 6000);
rotint =
new RotationInterpolator(alpha, rotateGroup,
local, 0.0f, 6.28f);
rotint.setSchedulingBounds(
new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 1000.0));
Point3f[] coords = new Point3f[]
{
new Point3f(cx+-0.5f, cy+-0.5f, -20.0f),
new Point3f(cx+ 0.5f, cy+-0.5f, -20.0f),
new Point3f(cx+-0.5f, cy+ 0.5f, -20.0f),
new Point3f(cx+ 0.5f, cy+ 0.5f, -20.0f)
};
int[] stripVertexCounts = new int[1];
stripVertexCounts[0] = 4;
TriangleStripArray groundGeom =
new TriangleStripArray(4, GeometryArray.COORDINATES, stripVertexCounts);
groundGeom.setCoordinates(0, coords);
Appearance appearance = new Appearance();
Shape3D ground = new Shape3D(groundGeom, appearance);
rotateGroup.addChild(ground);
this.addChild(rotateGroup);
this.addChild(rotint);
}
}
-----Original Message-----
>From: Mohammed Akacem [mailto:[EMAIL PROTECTED]]
>Sent: Tuesday, May 30, 2000 7:14 AM
>To: [EMAIL PROTECTED]
>Subject: [JAVA3D] How to set Geometry of a shape3d at runtime.
>
>
>I am viewing a Shape3D object in an applet. I want to remove the shape3d
>
>object at runtime when I click a close button so I can later set the
>geoemtry of my shape3D object again to show another visuel object. How
>should I proceed.
>
>Thanks a lot
>
>Mohammed
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".