Example usage for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ

List of usage examples for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ

Introduction

In this page you can find the example usage for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ.

Prototype

int ALLOW_TRANSFORM_READ

To view the source code for javax.media.j3d TransformGroup ALLOW_TRANSFORM_READ.

Click Source Link

Document

Specifies that the node allows access to its object's transform information.

Usage

From source file:LoaderTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    // create a TransformGroup to flip the hand onto its end and enlarge it.
    TransformGroup objTrans1 = new TransformGroup();
    Transform3D tr = new Transform3D();
    objTrans1.getTransform(tr);/*from w  w  w.  ja va2 s.c  o m*/
    tr.rotX(90.0 * Math.PI / 180.0);
    tr.setScale(10.0);
    objTrans1.setTransform(tr);

    // create a TransformGroup to rotate the hand
    TransformGroup objTrans2 = new TransformGroup();
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

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

    // create a RotationInterpolator behavior to rotate the hand
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans2, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans2.addChild(rotator);

    // Set up the global 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);

    AmbientLight aLgt = new AmbientLight(alColor);
    aLgt.setInfluencingBounds(bounds);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    lgt1.setInfluencingBounds(bounds);

    objRoot.addChild(aLgt);
    objRoot.addChild(lgt1);

    // load the object file
    Scene scene = null;
    Shape3D shape = null;

    // read in the geometry information from the data file
    ObjectFile objFileloader = new ObjectFile(ObjectFile.RESIZE);

    try {
        scene = objFileloader.load("hand1.obj");
    } catch (Exception e) {
        scene = null;
        System.err.println(e);
    }

    if (scene == null)
        System.exit(1);

    // retrieve the Shape3D object from the scene
    BranchGroup branchGroup = scene.getSceneGroup();
    shape = (Shape3D) branchGroup.getChild(0);

    // create an Appearance and Material
    Appearance app = new Appearance();
    Color3f objColor = new Color3f(1.0f, 0.7f, 0.8f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    app.setMaterial(new Material(objColor, black, objColor, black, 80.0f));

    // assign the appearance to the Shape
    shape.setAppearance(app);

    // connect the scenegraph
    objTrans2.addChild(scene.getSceneGroup());
    objTrans1.addChild(objTrans2);
    objRoot.addChild(objTrans1);

    return objRoot;
}

From source file:OrientedTest.java

public BranchGroup createSceneGraph() {

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

    TransformGroup objScale = new TransformGroup();
    Transform3D textMat = new Transform3D();
    // Assuming uniform size chars, set scale to fit string in view
    textMat.setScale(1.2 / sl);//  www . j a  v a 2 s.c o m
    objScale.setTransform(textMat);

    // 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 objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRoot.addChild(objTrans);

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

    Appearance apText = new Appearance();
    Material m = new Material();
    m.setLightingEnable(true);
    apText.setMaterial(m);

    Appearance apEarth = new Appearance();
    Material mm = new Material();
    mm.setLightingEnable(true);
    apEarth.setMaterial(mm);

    Appearance apStone = new Appearance();
    apStone.setMaterial(mm);

    // create 3D text
    Font3D f3d = new Font3D(new Font(fontName, Font.PLAIN, 2), new FontExtrusion());
    Text3D txt = new Text3D(f3d, textString, new Point3f(-sl / 2.0f, 3.0f, 0.0f));
    OrientedShape3D textShape = new OrientedShape3D();
    textShape.setGeometry(txt);
    textShape.setAppearance(apText);
    textShape.setAlignmentAxis(0.0f, 1.0f, 0.0f);
    objScale.addChild(textShape);

    // Create a simple shape leaf node, add it to the scene graph.

    Transform3D cubeMat = new Transform3D();
    TransformGroup cubeTrans = new TransformGroup(cubeMat);
    cubeMat.set(new Vector3d(0.9, 0.0, -1.0));
    cubeTrans.setTransform(cubeMat);
    cubeTrans.addChild(new ColorCube(0.3));
    objTrans.addChild(cubeTrans);

    TextureLoader stoneTex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (stoneTex != null)
        apStone.setTexture(stoneTex.getTexture());

    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    apStone.setTextureAttributes(texAttr);

    Transform3D coneMat = new Transform3D();
    TransformGroup coneTrans = new TransformGroup(coneMat);
    coneMat.set(new Vector3d(0.0, 0.0, 0.0));
    coneTrans.setTransform(coneMat);
    coneTrans.addChild(new Cone(.2f, 0.8f, Cone.GENERATE_NORMALS | Cone.GENERATE_TEXTURE_COORDS, apStone));
    objTrans.addChild(coneTrans);

    TextureLoader earthTex = new TextureLoader(earthImage, new String("RGB"), this);
    if (earthTex != null)
        apEarth.setTexture(earthTex.getTexture());

    apEarth.setTextureAttributes(texAttr);

    Transform3D cylinderMat = new Transform3D();
    TransformGroup cylinderTrans = new TransformGroup(cylinderMat);
    cylinderMat.set(new Vector3d(-0.9, 0.5, -1.0));
    cylinderTrans.setTransform(cylinderMat);
    cylinderTrans.addChild(
            new Cylinder(.35f, 2.0f, Cylinder.GENERATE_NORMALS | Cylinder.GENERATE_TEXTURE_COORDS, apEarth));
    objTrans.addChild(cylinderTrans);

    objTrans.addChild(objScale);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

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

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -1.0f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    apText.setMaterial(mm);

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

    return objRoot;
}

From source file:Drag.java

/**
 *  Create the scenegraph for this program.
 *//*from   w  ww.j  a  v  a 2s .com*/
public BranchGroup createSceneGraph() {

    // Define colors
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f red = new Color3f(0.80f, 0.20f, 0.2f);
    Color3f ambientRed = new Color3f(0.2f, 0.05f, 0.0f);
    Color3f ambient = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f diffuse = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f specular = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    // Create the branch group
    BranchGroup branchGroup = new BranchGroup();

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);
    objScale.setTransform(t3d);
    branchGroup.addChild(objScale);

    // Create the bounding leaf node
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    BoundingLeaf boundingLeaf = new BoundingLeaf(bounds);
    objScale.addChild(boundingLeaf);

    // Set up the background
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    // Create the ambient light
    AmbientLight ambLight = new AmbientLight(white);
    ambLight.setInfluencingBounds(bounds);
    objScale.addChild(ambLight);

    // Create the directional light
    Vector3f dir = new Vector3f(-1.0f, -1.0f, -1.0f);
    DirectionalLight dirLight = new DirectionalLight(white, dir);
    dirLight.setInfluencingBounds(bounds);
    objScale.addChild(dirLight);

    // Create the red appearance node
    Material redMaterial = new Material(ambientRed, black, red, specular, 75.0f);
    redMaterial.setLightingEnable(true);
    Appearance redAppearance = new Appearance();
    redAppearance.setMaterial(redMaterial);

    // Create the white appearance node
    Material whiteMaterial = new Material(ambient, black, diffuse, specular, 75.0f);
    whiteMaterial.setLightingEnable(true);
    Appearance whiteAppearance = new Appearance();
    whiteAppearance.setMaterial(whiteMaterial);

    // Create the transform node
    TransformGroup transformGroup = new TransformGroup();
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    transformGroup.addChild(new Cube(redAppearance).getChild());
    //   transformGroup.addChild(new Corners(whiteAppearance).getChild());
    objScale.addChild(transformGroup);

    // Create the drag behavior node
    MouseRotate behavior = new MouseRotate();
    behavior.setTransformGroup(transformGroup);
    transformGroup.addChild(behavior);
    behavior.setSchedulingBounds(bounds);

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

    // Create the zoom behavior node
    MouseTranslate behavior3 = new MouseTranslate();
    behavior3.setTransformGroup(transformGroup);
    transformGroup.addChild(behavior3);
    behavior3.setSchedulingBounds(bounds);

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

    return branchGroup;
}

From source file:cgview.java

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.7);//from  ww w .  j a  v  a 2s.c om
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // 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 objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objScale.addChild(objTrans);

    // Add compressed geometry to the scene graph.
    CompressedGeometryHeader hdr = new CompressedGeometryHeader();
    cg.getCompressedGeometryHeader(hdr);

    // There isn't really enough information in the compressed geometry
    // header to unamiguously determine the proper rendering attributes.
    // The bufferDataPresent field specifies whether or not normals are
    // bundled with vertices, but the compressed buffer can still contain
    // normals that should be lit. Assume that any surface geometry
    // should be lit and that lines and points should not unless the
    // header contains the NORMAL_IN_BUFFER bit.
    Material m = new Material();
    if ((hdr.bufferType == hdr.TRIANGLE_BUFFER) || ((hdr.bufferDataPresent & hdr.NORMAL_IN_BUFFER) == 1))
        m.setLightingEnable(true);
    else
        m.setLightingEnable(false);

    Appearance a = new Appearance();
    a.setMaterial(m);

    objTrans.addChild(new Shape3D(cg, a));

    // Create mouse behavior scheduling bounds.
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.5f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objRoot.addChild(bgNode);

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

    // Set up the directional lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(1.0f, 1.0f, 1.0f);
    Color3f light2Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light2Direction = new Vector3f(-1.0f, -1.0f, -0.9f);

    DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
    light1.setInfluencingBounds(bounds);
    objRoot.addChild(light1);

    DirectionalLight light2 = new DirectionalLight(light2Color, light2Direction);
    light2.setInfluencingBounds(bounds);
    objRoot.addChild(light2);

    return objRoot;
}

From source file:PickText3DGeometry.java

public BranchGroup createSceneGraph(Canvas3D canvas) {
    Color3f eColor = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f sColor = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f objColor = new Color3f(0.6f, 0.6f, 0.6f);
    Color3f lColor1 = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f lColor2 = new Color3f(0.0f, 1.0f, 0.0f);
    Color3f alColor = new Color3f(0.2f, 0.2f, 0.2f);
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);

    Transform3D t;//from   w  w w  .  j  av a 2 s .  c  o  m

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create a bounds for the background and lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Set up the background
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    Material m = new Material(objColor, eColor, objColor, sColor, 100.0f);
    Appearance a = new Appearance();
    m.setLightingEnable(true);
    a.setMaterial(m);
    Font3D f3d = new Font3D(new Font("TestFont", Font.PLAIN, 1), new FontExtrusion());

    Text3D text3D = new Text3D(f3d, new String("TEXT3D"), new Point3f(-2.0f, 0.7f, 0.0f));
    text3D.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D1 = new Shape3D();
    s3D1.setGeometry(text3D);
    s3D1.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg1 = new TransformGroup();
    spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg1.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg1.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg1.addChild(s3D1);
    objScale.addChild(spinTg1);

    Text3D pick = new Text3D(f3d, new String("Pick me"), new Point3f(-2.0f, -0.7f, 0.0f));
    pick.setCapability(Geometry.ALLOW_INTERSECT);
    Shape3D s3D2 = new Shape3D();
    s3D2.setGeometry(pick);
    s3D2.setAppearance(a);

    // Create a transform group node and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime.
    TransformGroup spinTg2 = new TransformGroup();
    spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg2.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    spinTg2.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    spinTg2.addChild(s3D2);
    objScale.addChild(spinTg2);

    // Create the transform group node for the each light and initialize
    // it to the identity. Enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime. Add them to the root
    // of the subgraph.

    // Create transformations for the positional lights
    t = new Transform3D();
    Vector3d lPos1 = new Vector3d(0.0, 0.0, 2.0);
    t.set(lPos1);
    TransformGroup l1Trans = new TransformGroup(t);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l1Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l1Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l1Trans);

    t = new Transform3D();
    Vector3d lPos2 = new Vector3d(0.5, 1.2, 2.0);
    t.set(lPos2);
    TransformGroup l2Trans = new TransformGroup(t);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    l2Trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    l2Trans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(l2Trans);

    // Create Geometry for point lights
    ColoringAttributes caL1 = new ColoringAttributes();
    ColoringAttributes caL2 = new ColoringAttributes();
    caL1.setColor(lColor1);
    caL2.setColor(lColor2);
    Appearance appL1 = new Appearance();
    Appearance appL2 = new Appearance();
    appL1.setColoringAttributes(caL1);
    appL2.setColoringAttributes(caL2);
    l1Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL1));
    l2Trans.addChild(new Sphere(0.05f, Sphere.GENERATE_NORMALS | Sphere.ENABLE_GEOMETRY_PICKING, 15, appL2));

    // Create lights
    AmbientLight aLgt = new AmbientLight(alColor);

    Light lgt1;
    Light lgt2;

    Point3f lPoint = new Point3f(0.0f, 0.0f, 0.0f);
    Point3f atten = new Point3f(1.0f, 0.0f, 0.0f);
    lgt1 = new PointLight(lColor1, lPoint, atten);
    lgt2 = new PointLight(lColor2, lPoint, atten);

    // Set the influencing bounds
    aLgt.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);

    // Add the lights into the scene graph
    objScale.addChild(aLgt);
    l1Trans.addChild(lgt1);
    l2Trans.addChild(lgt2);

    PickRotateBehavior behavior1 = new PickRotateBehavior(objRoot, canvas, bounds);
    behavior1.setMode(PickTool.GEOMETRY);
    behavior1.setTolerance(0.0f);
    objRoot.addChild(behavior1);

    PickZoomBehavior behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
    behavior2.setMode(PickTool.GEOMETRY);
    behavior2.setTolerance(0.0f);
    objRoot.addChild(behavior2);

    PickTranslateBehavior behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
    behavior3.setMode(PickTool.GEOMETRY);
    behavior3.setTolerance(0.0f);
    objRoot.addChild(behavior3);

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

    return objRoot;
}

From source file:SimpleGeometry.java

PlatformGeometry createAimer() {

    PlatformGeometry pg = new PlatformGeometry();

    // This TransformGroup will be used by the MouseTranslate
    // utiltiy to move the cylinder around the canvas. when the
    // the user holds down mouse button 3.
    TransformGroup moveTG = new TransformGroup();
    moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    moveTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    MouseTranslate mouseT = new MouseTranslate(moveTG);
    moveTG.addChild(mouseT);/*www . j a  va 2 s .c  o  m*/
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
    mouseT.setSchedulingBounds(bounds);
    pg.addChild(moveTG);

    // This TransformGroup is used to place the cylinder in the scene.
    // The cylinder will be rotated 90 degrees so it will appear as
    // a circle on the screen (could be made into a nice gun site...).
    // The cylinder is also displaced a little in Z so it is in front
    // of the viewer.
    Transform3D xForm = new Transform3D();
    xForm.rotX(Math.PI / 2.0);
    xForm.setTranslation(new Vector3d(0.0, 0.0, -0.7));
    TransformGroup placementTG = new TransformGroup(xForm);
    moveTG.addChild(placementTG);

    // Create the cylinder - make it thin and transparent.
    Appearance cylinderAppearance = new Appearance();
    TransparencyAttributes transAttrs = new TransparencyAttributes(TransparencyAttributes.FASTEST, 0.5f);
    //        cylinderAppearance.setTransparencyAttributes(transAttrs);
    Cylinder aimer = new Cylinder(0.06f, 0.005f, 0, cylinderAppearance);
    placementTG.addChild(aimer);

    return pg;
}

From source file:ModelClipTest2.java

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);//from   w  w w .  j  a  va2s .c  o  m
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    // Create lights
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    //Shine it with two colored lights.
    Color3f lColor0 = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f lColor1 = new Color3f(0.5f, 0.0f, 0.5f);
    Color3f lColor2 = new Color3f(0.7f, 0.7f, 0.0f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, 1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);

    AmbientLight lgt0 = new AmbientLight(true, lColor2);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt0.setInfluencingBounds(bounds);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt0);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

    // Create a Transformgroup for the geometry
    TransformGroup objRot = new TransformGroup();
    Transform3D t3d1 = new Transform3D();
    AxisAngle4f rot1 = new AxisAngle4f(0.0f, 1.0f, 0.0f, 45.0f);
    t3d1.setRotation(rot1);
    objRot.setTransform(t3d1);
    objScale.addChild(objRot);

    //Create a cylinder
    PolygonAttributes attr = new PolygonAttributes();
    attr.setCullFace(PolygonAttributes.CULL_NONE);
    Appearance ap = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    ap.setMaterial(mat);
    ap.setPolygonAttributes(attr);

    Cylinder CylinderObj = new Cylinder(0.5f, 2.2f, ap);
    objRot.addChild(CylinderObj);

    //Create a box
    Box BoxObj = new Box(0.8f, 0.8f, 0.8f, ap);
    objRot.addChild(BoxObj);

    // This Transformgroup is used by the mouse manipulators to
    // move the model clip planes.
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objRot.addChild(objTrans);

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

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

    //Create Model Clip
    ModelClip mc = new ModelClip();
    boolean enables[] = { false, false, false, false, false, false };
    Vector4d eqn = new Vector4d(0.0, 1.0, 1.0, 0.0);
    mc.setEnables(enables);
    mc.setPlane(1, eqn);
    mc.setEnable(1, true);
    mc.setInfluencingBounds(bounds);
    objTrans.addChild(mc);

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

    return objRoot;
}

From source file:BoundsTest.java

protected BranchGroup createSceneBranchGroup() {
    BranchGroup objRoot = super.createSceneBranchGroup();

    // do NOT auto compute bounds for this node
    objRoot.setBoundsAutoCompute(false);

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

    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);

    rotator.setSchedulingBounds(createApplicationBounds());
    objTrans.addChild(rotator);//from w w w  . j av a  2  s.  c o m

    objTrans.addChild(createColorCubes());
    objTrans.addChild(createPoints());

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:MultiTextureTest.java

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

    // Create a Transformgroup to scale all objects so they
    // appear in the scene.
    TransformGroup objScale = new TransformGroup();
    Transform3D t3d = new Transform3D();
    t3d.setScale(0.4);/*ww  w  .  j  a v  a 2 s  .c  o m*/
    objScale.setTransform(t3d);
    objRoot.addChild(objScale);

    TransformGroup objTrans = new TransformGroup();
    //write-enable for behaviors
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);
    objScale.addChild(objTrans);

    Appearance ap = new Appearance();

    // load textures
    TextureAttributes texAttr1 = new TextureAttributes();
    texAttr1.setTextureMode(TextureAttributes.DECAL);
    TextureAttributes texAttr2 = new TextureAttributes();
    texAttr2.setTextureMode(TextureAttributes.MODULATE);

    TextureLoader tex = new TextureLoader(stoneImage, new String("RGB"), this);
    if (tex == null)
        return null;
    stoneTex = tex.getTexture();

    tex = new TextureLoader(skyImage, new String("RGB"), this);
    if (tex == null)
        return null;
    skyTex = tex.getTexture();

    lightTex = createLightMap();

    textureUnitState[0] = new TextureUnitState(stoneTex, texAttr1, null);
    textureUnitState[0].setCapability(TextureUnitState.ALLOW_STATE_WRITE);

    textureUnitState[1] = new TextureUnitState(lightTex, texAttr2, null);
    textureUnitState[1].setCapability(TextureUnitState.ALLOW_STATE_WRITE);

    ap.setTextureUnitState(textureUnitState);

    //Create a Box
    Box BoxObj = new Box(1.5f, 1.5f, 0.8f, Box.GENERATE_NORMALS | Box.GENERATE_TEXTURE_COORDS, ap, 2);
    // add it to the scene graph.
    objTrans.addChild(BoxObj);

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

    //Shine it with two lights.
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Color3f lColor2 = new Color3f(0.2f, 0.2f, 0.1f);
    Vector3f lDir1 = new Vector3f(-1.0f, -1.0f, -1.0f);
    Vector3f lDir2 = new Vector3f(0.0f, 0.0f, -1.0f);
    DirectionalLight lgt1 = new DirectionalLight(lColor1, lDir1);
    DirectionalLight lgt2 = new DirectionalLight(lColor2, lDir2);
    lgt1.setInfluencingBounds(bounds);
    lgt2.setInfluencingBounds(bounds);
    objScale.addChild(lgt1);
    objScale.addChild(lgt2);

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

    return objRoot;
}

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);//  ww w  .j a  va2 s  . c o  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;
}