Example usage for javax.media.j3d Group ALLOW_CHILDREN_WRITE

List of usage examples for javax.media.j3d Group ALLOW_CHILDREN_WRITE

Introduction

In this page you can find the example usage for javax.media.j3d Group ALLOW_CHILDREN_WRITE.

Prototype

int ALLOW_CHILDREN_WRITE

To view the source code for javax.media.j3d Group ALLOW_CHILDREN_WRITE.

Click Source Link

Document

Specifies that this Group node allows writing its children.

Usage

From source file:ImageComponentByReferenceTest.java

public BranchGroup createSceneGraph() {
    objRoot = new BranchGroup();

    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);

    objRoot.addChild(objTrans);/*from w  ww .  ja v a2s.c  om*/

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    app.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    textureCube = new Box(0.4f, 0.4f, 0.4f, Box.GENERATE_TEXTURE_COORDS | Box.GENERATE_NORMALS, app);
    boxShape = textureCube.getShape(Box.FRONT);
    boxShape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
    objTrans.addChild(textureCube);

    checkBoard = new TiledImage();
    TextureLoader texLoader = new TextureLoader(texImage, this);
    ImageComponent2D oneImage = texLoader.getImage();
    bImage1 = oneImage.getImage();

    int index = 0;
    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, true);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, false, false);

    image[index++] = new ImageComponent2D(oneImage.getFormat(), (RenderedImage) bImage1, true, false);

    createRaster(objRoot);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, true);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, false, false);

    image[index++] = new ImageComponent2D(ImageComponent.FORMAT_RGBA, checkBoard, true, false);

    texOne = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[2].getWidth(), image[2].getHeight());

    texOne.setCapability(Texture.ALLOW_IMAGE_WRITE);
    texOne.setImage(0, image[2]);

    app.setTexture(texOne);

    texCheckBoard = new Texture2D(Texture.BASE_LEVEL, Texture.RGBA, image[4].getWidth(), image[4].getHeight());

    texCheckBoard.setCapability(Texture.ALLOW_IMAGE_WRITE);
    objRoot.compile();
    return objRoot;
}

From source file:ExText.java

public Group buildScene() {
    // Get the current font attributes
    Font font = (Font) fonts[currentFont].value;
    String textString = (String) fonts[currentFont].name;

    // Turn on the example headlight
    setHeadlightEnable(true);/*  w  w w. ja v a2 s.  co m*/

    // Build the scene group
    scene = new Group();
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.setCapability(Group.ALLOW_CHILDREN_WRITE);

    // Build a branch group to hold the text shape
    // (this allows us to remove the text shape later,
    // change it, then put it back, all under menu control)
    textGroup = new BranchGroup();
    textGroup.setCapability(BranchGroup.ALLOW_DETACH);
    scene.addChild(textGroup);

    // BEGIN EXAMPLE TOPIC
    // Create a font extrusion with a default extrusion shape
    extrusion = new FontExtrusion();

    // Define a 3D font with a default extrusion path
    Font3D font3d = new Font3D(font, extrusion);

    // Build 3D text geometry using the 3D font
    Text3D tex = new Text3D();
    tex.setFont3D(font3d);
    tex.setString(textString);
    tex.setAlignment(Text3D.ALIGN_CENTER);

    // Define a generic shaded appearance
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    app.setMaterial(mat);

    // Assemble geometry and appearance into a shape
    // and add it to the scene
    shape = new Shape3D(tex, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    textGroup.addChild(shape);
    // END EXAMPLE TOPIC

    return scene;
}

From source file:edu.uci.ics.jung.visualization3d.VisualizationViewer.java

public BranchGroup createSceneGraph(final Canvas3D canvas) {

    objRoot = new BranchGroup();
    objRoot.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    objRoot.setCapability(Group.ALLOW_CHILDREN_WRITE);

    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    //      t3d.setScale(0.05);
    objScale.setTransform(t3d);/*from   w w w  .j  ava2 s  .  co  m*/
    objRoot.addChild(objScale);

    Transform3D tt = new Transform3D();
    tt.setScale(.05);
    tt.setTranslation(new Vector3f(0, 0, -30.f));
    objTrans = new TransformGroup(tt);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
    objScale.addChild(objTrans);
    //      objRoot.addChild(objTrans);

    // Create Colors, Materials,  and Appearances.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f black = new Color3f(0.f, 0.f, 0.f);
    Color3f white = new Color3f(1.0f, 1.0f, 0.6f);
    Color3f gray = new Color3f(.2f, .2f, .2f);
    Color3f red = new Color3f(1.0f, 0, 0);
    Color3f yellow = new Color3f(1, 1, 0);

    Material objMaterial = new Material(objColor, black, objColor, white, 100.0f);
    Material blackMaterial = new Material(objColor, black, black, objColor, 10.0f);
    Material whiteMaterial = new Material(white, white, white, white, 100.0f);
    Material grayMaterial = new Material(gray, black, gray, gray, 100.0f);

    Material redMaterial = new Material(red, black, red, red, 100.0f);
    Material yellowMaterial = new Material(yellow, black, yellow, yellow, 100);

    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));
    Appearance blackLook = new Appearance();
    blackLook.setMaterial(blackMaterial);

    Appearance whiteLook = new Appearance();
    whiteLook.setMaterial(whiteMaterial);

    Appearance grayLook = new Appearance();
    grayLook.setMaterial(grayMaterial);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_READ);
    grayLook.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    final Appearance redLook = new Appearance();
    redLook.setMaterial(redMaterial);
    //      vertexLook = redLook;

    Appearance objLook = new Appearance();
    objLook.setMaterial(objMaterial);
    grayLook = objLook;
    final Appearance yellowLook = new Appearance();
    yellowLook.setMaterial(yellowMaterial);
    Bounds bounds = new BoundingSphere(new Point3d(), 300);

    MouseRotate behavior1 = new MouseRotate();
    behavior1.setTransformGroup(objTrans);
    objTrans.addChild(behavior1);
    behavior1.setSchedulingBounds(bounds);

    MouseWheelZoom behavior2 = new MouseWheelZoom();
    behavior2.setTransformGroup(objTrans);
    //      behavior2.setFactor(10);
    objTrans.addChild(behavior2);
    behavior2.setSchedulingBounds(bounds);

    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(objTrans);
    objTrans.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

    PickTranslateBehavior ptb = new PickTranslateBehavior(objRoot, canvas, bounds, PickTool.GEOMETRY);
    ptb.setSchedulingBounds(bounds);
    //      objTrans.addChild(ptb);
    ptb.setupCallback(new PickingCallback() {

        public void transformChanged(int type, TransformGroup tg) {
            if (tg == null)
                return;
            Transform3D t3d = new Transform3D();
            tg.getTransform(t3d);
            //            System.err.println(tg+" transformChanged \n"+t3d);
            Point3f p1 = new Point3f();
            V v = vertexMap.getKey(tg);
            //            Transform3D lvw = new Transform3D();
            //            tg.getLocalToVworld(lvw);
            //            System.err.println("lvw = \n"+lvw);
            //            lvw.invert();
            //            System.err.println("invert lvw = \n"+lvw);
            Point3f p0 = layout.transform(v);
            //            Transform3D vwip = new Transform3D();
            //            canvas.getVworldToImagePlate(vwip);
            //            System.err.println("vwip=\n"+vwip);
            //            t3d.mul(lvw);
            t3d.transform(p1);
            //            scale.transform(p1);
            System.err.println(
                    "change location for vertex " + v + ", transformGroup " + tg + " from " + p0 + " to " + p1);
            //            p1.set(p1.getX()*2,p1.getY()*2,p1.getZ()*2);
            //            layout.setLocation(v, p1);

        }
    });

    PickSphereBehavior psb = new PickSphereBehavior(objRoot, canvas, bounds);

    PickVertexBehavior pvb = new PickVertexBehavior(objRoot, canvas, bounds,
            renderContext.getPickedVertexState());
    objTrans.addChild(pvb);
    pvb.addChangeListener(new ChangeListener() {

        public void stateChanged(ChangeEvent e) {
            for (V v : graph.getVertices()) {
                VertexGroup<V> vg = vertexMap.get(v);
                Appearance look = redLook;
                if (renderContext.getPickedVertexState().isPicked(v)) {
                    look = yellowLook;
                }
                Node node = vg.getShape();
                if (node instanceof Primitive) {
                    ((Primitive) node).setAppearance(look);
                }
            }

        }
    });

    //Shine it with two colored lights.
    Color3f lColor1 = new Color3f(.5f, .5f, .5f);
    Color3f lColor2 = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(-1.0f, 0.0f, -1.0f);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    AmbientLight ambient = new AmbientLight(lColor1);
    lgt2.setInfluencingBounds(bounds);
    ambient.setInfluencingBounds(bounds);
    objRoot.addChild(lgt2);
    objRoot.addChild(ambient);

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

    //      VisRunner runner = new VisRunner((IterativeContext)elayout);
    //      runner.relax();

    return objRoot;
}

From source file:SwingTest.java

/**
 * Create the scene side of the scenegraph
 *//*from  w ww  . j a  va 2s.  co  m*/
protected BranchGroup createSceneBranchGroup() {
    // create the root of the scene side scenegraph
    BranchGroup objRoot = new BranchGroup();

    // create a TransformGroup to rotate the objects in the scene
    // set the capability bits on the TransformGroup so that it
    // can be modified at runtime
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // create a spherical bounding volume
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // create a 4x4 transformation matrix
    Transform3D yAxis = new Transform3D();

    // create an Alpha interpolator to automatically generate
    // modifications to the rotation component of the transformation matrix
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    // create a RotationInterpolator behavior to effect the TransformGroup
    rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f, (float) Math.PI * 2.0f);

    // set the scheduling bounds on the behavior
    rotator.setSchedulingBounds(bounds);

    // add the behavior to the scenegraph
    objTrans.addChild(rotator);

    // create the BranchGroup which contains the objects
    // we add/remove to and from the scenegraph
    sceneBranchGroup = new BranchGroup();

    // allow the BranchGroup to have children added at runtime
    sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_READ);
    sceneBranchGroup.setCapability(Group.ALLOW_CHILDREN_WRITE);

    // add both the cube and the sphere to the scenegraph
    sceneBranchGroup.addChild(createCube());
    sceneBranchGroup.addChild(createSphere());

    // create the colors for the lights
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);

    // create the ambient light
    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);

    // create the directional light
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);

    // add the lights to the scenegraph
    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // wire the scenegraph together
    objTrans.addChild(sceneBranchGroup);
    objRoot.addChild(objTrans);

    // return the root of the scene side of the scenegraph
    return objRoot;
}

From source file:Demo3D.java

/**
 * Create the subgraph #3/*ww  w.java  2 s  . com*/
 * 
 * @return javax.media.j3d.BranchGroup brGr3 - the root of the subgraph #3
 */
public BranchGroup mySubGraph3() {
    // Create the BranchGroup node brGr3, in other words the root of
    // the subgraph31 and subgraph32.
    brGr3 = new BranchGroup();

    // To allow the detach/add process of the subgraph 32 from the
    // BranchGroup node brGr3.
    brGr3.setCapability(Group.ALLOW_CHILDREN_READ);
    brGr3.setCapability(Group.ALLOW_CHILDREN_WRITE);
    brGr3.setCapability(Group.ALLOW_CHILDREN_EXTEND);

    // A BoundingSphere instance as picking bound region.
    pickBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 5.0);

    // A BoundingSphere instance as general bounding region.
    boundsGen = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Create and attach the subgraph31 with the tetrahedron
    // to the BranchGroup node brGr3.
    tetrahedron = new Tetrahedron(1.0f);
    sceneBuilder31 = new SceneBuilder31(tetrahedron.myTetrahedron());
    brGr3.addChild(sceneBuilder31.mySubGraph31());

    // Picking of the tetrahedron
    // Note:It's the instruction:
    //      trGr31.setCapability(TransformGroup.ENABLE_PICK_REPORTING)
    //      in the class SceneBuilder31 that determines if the
    //      tetrahedron is pickable or not.

    // Pick and translate the tetrahedron parallel to the z-axis if the
    // mouse pointer is over it.
    pickZoomBehavior = new PickZoomBehavior(brGr3, canvas3D, pickBounds);
    // pickZoomBehavior.setEnable(ctrlDown);
    brGr3.addChild(pickZoomBehavior);

    // Pick and translate the tetrahedron in the (x-y)-plane if the
    // mouse pointer is over it.
    pickTransBehavior = new PickTranslateBehavior(brGr3, canvas3D, pickBounds);
    // pickTransBehavior.setEnable(ctrlDown);
    brGr3.addChild(pickTransBehavior);

    // Pick and rotate the tetrahedron if the mouse pointer is over it.
    pickRotBehavior = new PickRotateBehavior(brGr3, canvas3D, pickBounds);
    // pickRotBehavior.setEnable(ctrlDown);
    brGr3.addChild(pickRotBehavior);

    // Create the subgraph32 ===> the earth in double rotation.
    sceneBuilder32 = new SceneBuilder32();
    brGr3.addChild(sceneBuilder32.mySubGraph32());

    // Create an instance of the AddDetachEarthBehavior class to
    // allow the detach/add process of the subgraph32.
    addDetachEarthBehavior = new AddDetachEarthBehavior(this, sceneBuilder32);
    addDetachEarthBehavior.setSchedulingBounds(boundsGen);
    brGr3.addChild(addDetachEarthBehavior);

    // Compile the subgraph to optimize the performances.
    brGr3.compile();

    // Return the final version of the BranchGroup node brGr3
    return brGr3;
}

From source file:ExSpotLight.java

public AnnotationArrow(float x, float y, float z, float x2, float y2, float z2) {
    super(x, y, z, x2, y2, z2);
    setLineWidth(lineWidth);/*w w w  .j a  va 2 s  . co  m*/

    // Compute the length and direction of the line
    float deltaX = x2 - x;
    float deltaY = y2 - y;
    float deltaZ = z2 - z;

    float theta = -(float) Math.atan2(deltaZ, deltaX);
    float phi = (float) Math.atan2(deltaY, deltaX);
    if (deltaX < 0.0f) {
        phi = (float) Math.PI - phi;
    }

    // Compute a matrix to rotate a cone to point in the line's
    // direction, then place the cone at the line's endpoint.
    Matrix4f mat = new Matrix4f();
    Matrix4f mat2 = new Matrix4f();
    mat.setIdentity();

    // Move to the endpoint of the line
    mat2.setIdentity();
    mat2.setTranslation(new Vector3f(x2, y2, z2));
    mat.mul(mat2);

    // Spin around Y
    mat2.setIdentity();
    mat2.rotY(theta);
    mat.mul(mat2);

    // Tilt up or down around Z
    mat2.setIdentity();
    mat2.rotZ(phi);
    mat.mul(mat2);

    // Tilt cone to point right
    mat2.setIdentity();
    mat2.rotZ(-1.571f);
    mat.mul(mat2);

    arrowTrans = new TransformGroup();
    arrowTrans.setCapability(Group.ALLOW_CHILDREN_WRITE);
    Transform3D trans = new Transform3D(mat);
    arrowTrans.setTransform(trans);

    // Create an appearance
    arrowAppearance = new Appearance();
    arrowAppearance.setCapability(Appearance.ALLOW_COLORING_ATTRIBUTES_WRITE);

    getLineColor(arrowColor);
    coloringAttributes = new ColoringAttributes();
    coloringAttributes.setColor(arrowColor);
    coloringAttributes.setShadeModel(ColoringAttributes.SHADE_FLAT);
    arrowAppearance.setColoringAttributes(coloringAttributes);

    // Build a cone for the arrow head
    arrowHead = new Cone(arrowRadius, // base radius
            arrowLength, // height
            0, // don't generate normals
            radialDivisions, // divisions radially
            sideDivisions, // divisions vertically
            arrowAppearance); // appearance

    arrowTrans.addChild(arrowHead);
    addChild(arrowTrans);
}