Example usage for javax.media.j3d BranchGroup compile

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

Introduction

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

Prototype

public void compile() 

Source Link

Document

Compiles the source BranchGroup associated with this object and creates and caches a compiled scene graph.

Usage

From source file:CompileTest.java

private BranchGroup createColorCubes() {
    BranchGroup bg = new BranchGroup();

    final int kNumCubes = 1000;

    for (int n = 0; n < kNumCubes; n++) {
        ColorCube cube1 = new ColorCube(1.0);

        // switch off pickable attribute so we can compile
        cube1.setPickable(false);/*  w  ww. ja v  a 2  s.  co m*/
        bg.addChild(cube1);
    }

    bg.compile();

    return bg;
}

From source file:MouseRotateApp.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);
    objRotate.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objRotate);/*from w  ww. j ava  2  s  . c om*/
    objRotate.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objRotate);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

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

    return objRoot;
}

From source file:PrintFromButton.java

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

    // spin object has composited transformation matrix
    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 4.0d);/*  w ww  .java  2s.c o  m*/
    tempspin.rotY(Math.PI / 5.0d);
    spin.mul(tempspin);
    spin.setScale(0.7);
    spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0));

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

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objTrans.addChild(new ColorCube(0.4));

    //Create a raster obj
    Shape3D shape = new Shape3D(drawRaster);
    objRoot.addChild(shape);

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

    return objRoot;
}

From source file:OffScreenTest.java

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

    // spin object has composited transformation matrix
    Transform3D spin = new Transform3D();
    Transform3D tempspin = new Transform3D();

    spin.rotX(Math.PI / 4.0d);/* w w w  .  j a v  a2  s .c om*/
    tempspin.rotY(Math.PI / 5.0d);
    spin.mul(tempspin);
    spin.setScale(0.7);
    spin.setTranslation(new Vector3d(-0.4, 0.3, 0.0));

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

    // Create a simple shape leaf node, add it to the scene graph.
    // ColorCube is a Convenience Utility class
    objTrans.addChild(new ColorCube(0.4));

    //Create a raster
    Shape3D shape = new Shape3D(drawRaster);
    objRoot.addChild(shape);

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

    return objRoot;
}

From source file:IntersectTest.java

public void init() {
    setLayout(new BorderLayout());

    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    // Create a simple scene and attach it to the virtual universe
    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);

    // Add picking behavior
    IntersectInfoBehavior behavior = new IntersectInfoBehavior(c, scene, 0.05f);
    behavior.setSchedulingBounds(bounds);
    scene.addChild(behavior);/*from  ww w .ja v  a  2  s  . c  o m*/

    TransformGroup vpTrans = u.getViewingPlatform().getViewPlatformTransform();

    KeyNavigatorBehavior keybehavior = new KeyNavigatorBehavior(vpTrans);
    keybehavior.setSchedulingBounds(bounds);
    scene.addChild(keybehavior);
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.compile();
    u.addBranchGraph(scene);

    View view = u.getViewer().getView();
    view.setBackClipDistance(100000);

}

From source file:BackgroundGeometry.java

public void init() {

    if (bgImage == null) {
        // the path to the image for an applet
        try {//ww  w.  j a v a 2 s .  co m
            bgImage = new java.net.URL(getCodeBase().toString() + "/bg.jpg");
        } catch (java.net.MalformedURLException ex) {
            System.out.println(ex.getMessage());
            System.exit(1);
        }
    }
    setLayout(new BorderLayout());
    GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();

    Canvas3D c = new Canvas3D(config);
    add("Center", c);

    BranchGroup scene = createSceneGraph();
    u = new SimpleUniverse(c);

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

    TransformGroup viewTrans = u.getViewingPlatform().getViewPlatformTransform();

    // Create the rotate behavior node
    MouseRotate behavior1 = new MouseRotate(viewTrans);
    scene.addChild(behavior1);
    behavior1.setSchedulingBounds(bounds);

    // Create the zoom behavior node
    MouseZoom behavior2 = new MouseZoom(viewTrans);
    scene.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    // Create the translate behavior node
    MouseTranslate behavior3 = new MouseTranslate(viewTrans);
    scene.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

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

    u.addBranchGraph(scene);
}

From source file:DoorApp.java

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

    TransformGroup doorTG = new TransformGroup();
    doorTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    doorTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    OpenBehavior openObject = new OpenBehavior(doorTG);
    CloseBehavior closeObject = new CloseBehavior(doorTG);

    //prepare the behavior objects
    openObject.setBehaviorObjectPartner(closeObject);
    closeObject.setBehaviorObjectPartner(openObject);

    // set scheduling bounds for behavior objects
    BoundingSphere bounds = new BoundingSphere();
    openObject.setSchedulingBounds(bounds);
    closeObject.setSchedulingBounds(bounds);

    // assemble scene graph
    objRoot.addChild(openObject);/*  w w w.  j a  v  a 2  s.  c o  m*/
    objRoot.addChild(closeObject);
    objRoot.addChild(doorTG);
    doorTG.addChild(new ColorCube(0.4));

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

    return objRoot;
}

From source file:ConeYoyoApp.java

public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();

    // 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);

    objRoot.addChild(objSpin);/*  ww w .ja va2  s  .  c om*/
    objSpin.addChild(new ConeYoyo().getBG());

    // 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);
    objSpin.addChild(rotator);

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

    return objRoot;
}

From source file:YoyoPointApp.java

public BranchGroup createSceneGraph() {

    BranchGroup objRoot = new BranchGroup();

    // 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);

    objRoot.addChild(objSpin);//from  w ww  .j  a  v  a2 s .  co m

    objSpin.addChild(new Yoyo());

    // 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);
    objSpin.addChild(rotator);

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

    return objRoot;
}

From source file:MouseBehaviorApp.java

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

    TransformGroup objTransform = new TransformGroup();
    objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTransform.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(objTransform);/*from  w  w  w.jav a2s  . co  m*/
    objTransform.addChild(new ColorCube(0.4));
    objRoot.addChild(new Axis());

    MouseRotate myMouseRotate = new MouseRotate();
    myMouseRotate.setTransformGroup(objTransform);
    myMouseRotate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseRotate);

    MouseTranslate myMouseTranslate = new MouseTranslate();
    myMouseTranslate.setTransformGroup(objTransform);
    myMouseTranslate.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseTranslate);

    MouseZoom myMouseZoom = new MouseZoom();
    myMouseZoom.setTransformGroup(objTransform);
    myMouseZoom.setSchedulingBounds(new BoundingSphere());
    objRoot.addChild(myMouseZoom);

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

    return objRoot;
}