Example usage for javax.media.j3d BranchGroup addChild

List of usage examples for javax.media.j3d BranchGroup addChild

Introduction

In this page you can find the example usage for javax.media.j3d BranchGroup addChild.

Prototype

public void addChild(Node child) 

Source Link

Document

Appends the specified child node to this group node's list of children.

Usage

From source file:AxisClassDemoApp.java

public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();
    objRoot.addChild(new Axis());

    // Create the transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add it to the
    // root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, 4000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    rotator.setSchedulingBounds(bounds);

    Transform3D trans = new Transform3D();
    trans.set(new Vector3f(0.5f, 0.0f, 0.0f));
    TransformGroup objTrans = new TransformGroup(trans);
    objRoot.addChild(objSpin);/*w w  w.j av  a 2  s.c  o  m*/
    objSpin.addChild(objTrans);
    objSpin.addChild(rotator);
    objTrans.addChild(new ColorCube(0.1));

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:SimpleBehaviorApp.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();

    TransformGroup objRotate = new TransformGroup();
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    objRoot.addChild(objRotate);
    objRotate.addChild(new ColorCube(0.4));

    SimpleBehavior myRotationBehavior = new SimpleBehavior(objRotate);
    myRotationBehavior.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myRotationBehavior);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();/*from   w w  w. j a  va  2s .  c  om*/

    return objRoot;
}

From source file:MaterialApp.java

public MaterialApp() {
    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(null);
    add("Center", c);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);

    BranchGroup scene = new BranchGroup();

    TransformGroup trans11 = createTG(-0.7f, 0.7f, -0.5f);
    scene.addChild(trans11);
    trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 0.0f)));

    TransformGroup trans12 = createTG(0.0f, 0.7f, -0.5f);
    scene.addChild(trans12);//  w ww.  j  a  v a 2  s. co m
    trans12.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1.0f)));

    TransformGroup trans13 = createTG(0.7f, 0.7f, -0.5f);
    scene.addChild(trans13);
    trans13.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 2.0f)));

    TransformGroup trans21 = createTG(-0.7f, 0.0f, -0.5f);
    scene.addChild(trans21);
    trans21.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 5.0f)));

    TransformGroup trans22 = createTG(0.0f, 0.0f, -0.5f);
    scene.addChild(trans22);
    trans22.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 10.0f)));

    TransformGroup trans23 = createTG(0.7f, 0.0f, -0.5f);
    scene.addChild(trans23);
    trans23.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 20.0f)));

    TransformGroup trans31 = createTG(-0.7f, -0.7f, -0.5f);
    scene.addChild(trans31);
    trans31.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 50.0f)));

    TransformGroup trans32 = createTG(0.0f, -0.7f, -0.5f);
    scene.addChild(trans32);
    trans32.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 100.0f)));

    TransformGroup trans33 = createTG(0.7f, -0.7f, -0.5f);
    scene.addChild(trans33);
    trans33.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction = new Vector3f(-1.0f, -1.0f, -1.0f);
    direction.normalize();
    lightD1.setDirection(direction);
    lightD1.setColor(new Color3f(1.0f, 1.0f, 1.0f));
    scene.addChild(lightD1);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere());
    background.setColor(1.0f, 1.0f, 1.0f);
    scene.addChild(background);

    SimpleUniverse u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    // setLocalEyeViewing
    u.getViewer().getView().setLocalEyeLightingEnable(true);

    u.addBranchGraph(scene);
}

From source file:BouncingBall.java

public BranchGroup createSceneGraph() {
    // Create the root of the branch graph
    BranchGroup objRoot = new BranchGroup();
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);

    // Create a simple shape leaf node, add it to the scene graph.
    Sphere sphere = new Sphere(0.25f);
    objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    Transform3D pos1 = new Transform3D();
    pos1.setTranslation(new Vector3f(0.0f, 0.0f, 0.0f));
    objTrans.setTransform(pos1);//from w ww . ja va2  s. c  o  m
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    Color3f light1Color = new Color3f(1.0f, 0.0f, 0.2f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    // Set up the ambient light
    Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objRoot.addChild(ambientLightNode);

    return objRoot;
}

From source file:SimpleCylinder.java

/**
 * This builds the content branch of our scene graph. It uses the Cylinder
 * utility class to create the actual shape, adding to to the transform
 * group so that the shape is slightly tilted to reveal its 3D shape.
 * /*from   w w w. j  ava  2s  .c o m*/
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch() {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    //Create the shape and add it to the branch
    rotationGroup.addChild(new Cylinder(1.0f, 1.0f, new Appearance()));
    return contentBranch;
}

From source file:LocalEyeApp.java

public LocalEyeApp() {
    setLayout(new BorderLayout());
    Canvas3D c = new Canvas3D(null);
    add("Center", c);

    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f blue = new Color3f(0.0f, 0.0f, 1.0f);

    BranchGroup scene = new BranchGroup();

    TransformGroup trans11 = createTG(-0.7f, 0.7f, -0.5f);
    scene.addChild(trans11);
    trans11.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans12 = createTG(0.0f, 0.7f, -0.5f);
    scene.addChild(trans12);/*from w w  w.j  a  v  a  2  s .  co  m*/
    trans12.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans13 = createTG(0.7f, 0.7f, -0.5f);
    scene.addChild(trans13);
    trans13.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans21 = createTG(-0.7f, 0.0f, -0.5f);
    scene.addChild(trans21);
    trans21.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans22 = createTG(0.0f, 0.0f, -0.5f);
    scene.addChild(trans22);
    trans22.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans23 = createTG(0.7f, 0.0f, -0.5f);
    scene.addChild(trans23);
    trans23.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans31 = createTG(-0.7f, -0.7f, -0.5f);
    scene.addChild(trans31);
    trans31.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans32 = createTG(0.0f, -0.7f, -0.5f);
    scene.addChild(trans32);
    trans32.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    TransformGroup trans33 = createTG(0.7f, -0.7f, -0.5f);
    scene.addChild(trans33);
    trans33.addChild(new Sphere(0.3f, Sphere.GENERATE_NORMALS, 60, createMatAppear(blue, white, 1000.0f)));

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(new BoundingSphere());
    scene.addChild(lightA);

    DirectionalLight lightD1 = new DirectionalLight();
    lightD1.setInfluencingBounds(new BoundingSphere());
    Vector3f direction = new Vector3f(0.0f, 0.0f, -1.0f);
    direction.normalize();
    lightD1.setDirection(direction);
    lightD1.setColor(red);
    scene.addChild(lightD1);

    PointLight lightP1 = new PointLight();
    lightP1.setInfluencingBounds(new BoundingSphere());
    Point3f position = new Point3f(0.0f, 0.0f, 1.0f);
    lightP1.setPosition(position);
    scene.addChild(lightP1);

    Background background = new Background();
    background.setApplicationBounds(new BoundingSphere());
    background.setColor(white);
    scene.addChild(background);

    SimpleUniverse u = new SimpleUniverse(c);

    // This will move the ViewPlatform back a bit so the
    // objects in the scene can be viewed.
    u.getViewingPlatform().setNominalViewingTransform();

    //Enable Local Eye Lighting
    u.getViewer().getView().setLocalEyeLightingEnable(true);

    u.addBranchGraph(scene);
}

From source file:SimpleCone.java

/**
 * This builds the content branch of our scene graph. It uses the buildShape
 * function to create the actual shape, adding to to the transform group so
 * that the shape is slightly tilted to reveal its 3D shape.
 * /*from  ww w.  j  av a2  s  .com*/
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch() {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    rotationGroup.addChild(new Cone(1.0f, 2.0f, 0, new Appearance()));
    return contentBranch;
}

From source file:KeyNavigatorApp.java

public BranchGroup createSceneGraph(SimpleUniverse su) {
    // Create the root of the branch graph
    TransformGroup vpTrans = null;/*from w w w.j  a v  a  2 s .  c  o m*/

    BranchGroup objRoot = new BranchGroup();

    Vector3f translate = new Vector3f();
    Transform3D T3D = new Transform3D();
    TransformGroup TG = null;

    objRoot.addChild(createLand());

    SharedGroup share = new SharedGroup();
    share.addChild(createPyramid());

    float[][] position = { { 0.0f, 0.0f, -3.0f }, { 6.0f, 0.0f, 0.0f }, { 6.0f, 0.0f, 6.0f },
            { 3.0f, 0.0f, -10.0f }, { 13.0f, 0.0f, -30.0f }, { -13.0f, 0.0f, 30.0f }, { -13.0f, 0.0f, 23.0f },
            { 13.0f, 0.0f, 3.0f } };

    for (int i = 0; i < position.length; i++) {
        translate.set(position[i]);
        T3D.setTranslation(translate);
        TG = new TransformGroup(T3D);
        TG.addChild(new Link(share));
        objRoot.addChild(TG);
    }
    vpTrans = su.getViewingPlatform().getViewPlatformTransform();
    translate.set(0.0f, 0.3f, 0.0f);
    T3D.setTranslation(translate);
    vpTrans.setTransform(T3D);
    KeyNavigatorBehavior keyNavBeh = new KeyNavigatorBehavior(vpTrans);
    keyNavBeh.setSchedulingBounds(new BoundingSphere(new Point3d(), 1000.0));
    objRoot.addChild(keyNavBeh);

    // Let Java 3D perform optimizations on this scene graph.
    objRoot.compile();

    return objRoot;
}

From source file:SimpleWire.java

/**
 * This builds the content branch of our scene graph. It uses the buildCube
 * function to create the actual shape, adding to to the transform group so
 * that the shape is slightly tilted to reveal its 3D shape.
 * //from  ww w. j  a  v  a 2 s.c om
 * @param shape
 *            Node that represents the geometry for the content
 * @return BranchGroup that is the root of the content branch
 */
protected BranchGroup buildContentBranch(Node shape) {
    BranchGroup contentBranch = new BranchGroup();
    Transform3D rotateCube = new Transform3D();
    rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
    TransformGroup rotationGroup = new TransformGroup(rotateCube);
    contentBranch.addChild(rotationGroup);
    rotationGroup.addChild(shape);
    return contentBranch;
}

From source file:BooksDemo.java

public void createScene() {
    BufferedImage image = new BufferedImage(xpanel.getWidth(), xpanel.getHeight(), BufferedImage.TYPE_INT_RGB);
    getContentPane().paint(image.getGraphics());

    BufferedImage subImage = new BufferedImage(CANVAS3D_WIDTH, CANVAS3D_HEIGHT, BufferedImage.TYPE_INT_RGB);
    ((Graphics2D) subImage.getGraphics()).drawImage(image, null, -c3d.getX(), -c3d.getY());

    Background bg = new Background(new ImageComponent2D(ImageComponent2D.FORMAT_RGB, subImage));
    BoundingSphere bounds = new BoundingSphere();
    bounds.setRadius(100.0);//from  w  w w.j  a  v a 2  s. com
    bg.setApplicationBounds(bounds);

    BranchGroup objRoot = new BranchGroup();
    objRoot.addChild(bg);

    TransformGroup objTg = new TransformGroup();
    objTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    Transform3D yAxis = new Transform3D();
    rotor1Alpha = new Alpha(1, 400);
    rotator1 = new RotationInterpolator(rotor1Alpha, objTg, yAxis, (float) Math.PI * 1.0f,
            (float) Math.PI * 2.0f);
    rotator1.setSchedulingBounds(bounds);

    textures.put("pages_top", createTexture("pages_top.jpg"));
    textures.put("pages", createTexture("amazon.jpg"));
    textures.put("amazon", createTexture("amazon.jpg"));
    textures.put("cover1", createTexture("cover1.jpg"));
    textures.put("cover2", createTexture("cover2.jpg"));
    textures.put("cover3", createTexture("cover3.jpg"));

    book = new com.sun.j3d.utils.geometry.Box(0.5f, 0.7f, 0.15f,
            com.sun.j3d.utils.geometry.Box.GENERATE_TEXTURE_COORDS, new Appearance());
    book.getShape(book.TOP).setAppearance((Appearance) textures.get("pages_top"));
    book.getShape(book.RIGHT).setAppearance((Appearance) textures.get("pages"));
    book.getShape(book.LEFT).setAppearance((Appearance) textures.get("amazon"));
    book.getShape(book.FRONT).setAppearance((Appearance) textures.get("cover1"));

    book.getShape(book.BACK).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    book.getShape(book.FRONT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // book.getShape(book.LEFT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    // book.getShape(book.RIGHT).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

    objTg.addChild(book);
    objTg.addChild(rotator1);

    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 8.0d);
    tempspin.rotY(Math.PI / 7.0d);
    spin.mul(tempspin);

    TransformGroup objTrans = new TransformGroup(spin);
    objTrans.addChild(objTg);

    objRoot.addChild(objTrans);

    SimpleUniverse u = new SimpleUniverse(c3d);
    u.getViewingPlatform().setNominalViewingTransform();
    u.addBranchGraph(objRoot);

    View view = u.getViewer().getView();
    view.setSceneAntialiasingEnable(true);
}