Example usage for javax.media.j3d TransformGroup ALLOW_TRANSFORM_WRITE

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

Introduction

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

Prototype

int ALLOW_TRANSFORM_WRITE

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

Click Source Link

Document

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

Usage

From source file:BehaviorTest.java

public void addBehaviorToParentGroup(Group nodeParentGroup) {
    nodeParentGroup.addChild(this);

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

    m_BoundsSwitch = new Switch();
    m_BoundsSwitch.setCapability(Switch.ALLOW_SWITCH_WRITE);

    Appearance app = new Appearance();

    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    app.setPolygonAttributes(polyAttrbutes);

    m_BoundsSwitch.addChild(new Sphere(1, app));

    ColorCube cube = new ColorCube();
    cube.setAppearance(app);//from  ww  w  .  j  av a 2s .c om

    Group g = new Group();
    g.addChild(cube);
    m_BoundsSwitch.addChild(g);

    m_BoundsSwitch.setWhichChild(Switch.CHILD_NONE);

    m_TransformGroup.addChild(m_BoundsSwitch);
    nodeParentGroup.addChild(m_TransformGroup);
}

From source file:TransformExplorer.java

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

    // Create a TransformGroup to scale the scene down by 3.5x
    TransformGroup objScale = new TransformGroup();
    Transform3D scaleTrans = new Transform3D();
    scaleTrans.set(1 / 3.5f); // scale down by 3.5x
    objScale.setTransform(scaleTrans);//w  ww  .  j  a  va  2  s. c o  m
    objRoot.addChild(objScale);

    // Create a TransformGroup and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // the mouse behaviors 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 the primitives to the scene
    objTrans.addChild(createConeTransformGroup()); // the cone
    rotAxis = new RotAxis(rotAxisLength); // the axis
    objTrans.addChild(rotAxis);
    coordSys = new CoordSys(coordSysLength); // the coordSys
    objTrans.addChild(coordSys);

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

    // The book used a white background for the figures
    //Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    //bg.setApplicationBounds(bounds);
    //objTrans.addChild(bg);

    // 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, 1.0f);
    Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f);

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

    return objRoot;
}

From source file:ExAppearance.java

private Group createObject(Appearance app, double scale, double xpos, double ypos) {

    // Create a transform group node to scale and position the object.
    Transform3D t = new Transform3D();
    t.set(scale, new Vector3d(xpos, ypos, 0.0));
    TransformGroup objTrans = new TransformGroup(t);

    // Create a second 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 spinTg = new TransformGroup();
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Create a simple shape leaf node and set the appearance
    Shape3D shape = new Tetrahedron();
    shape.setAppearance(app);/* w w w  . jav a  2  s.  c o m*/

    // add it to the scene graph.
    spinTg.addChild(shape);

    // 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, Alpha.INCREASING_ENABLE, 0, 0, 5000, 0, 0, 0, 0, 0);

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

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

    rotator.setSchedulingBounds(bounds);

    // Add the behavior and the transform group to the object
    objTrans.addChild(rotator);
    objTrans.addChild(spinTg);

    return objTrans;
}

From source file:TickTockPicking.java

private Group createObject(Appearance app, double scale, double xpos, double ypos) {

    // Create a transform group node to scale and position the object.
    Transform3D t = new Transform3D();
    t.set(scale, new Vector3d(xpos, ypos, 0.0));
    TransformGroup objTrans = new TransformGroup(t);

    // Create a second 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 spinTg = new TransformGroup();
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    spinTg.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    // Create a simple shape leaf node and set the appearance
    Shape3D shape = new Tetrahedron();
    shape.setAppearance(app);/*from   ww  w .ja  v a 2  s  .  co m*/
    shape.setCapability(shape.ALLOW_APPEARANCE_READ);
    shape.setCapability(shape.ALLOW_APPEARANCE_WRITE);

    // add it to the scene graph.
    spinTg.addChild(shape);

    // 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, Alpha.INCREASING_ENABLE, 0, 0, 5000, 0, 0, 0, 0, 0);

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

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

    rotator.setSchedulingBounds(bounds);

    // Add the behavior and the transform group to the object
    objTrans.addChild(rotator);
    objTrans.addChild(spinTg);

    return objTrans;
}

From source file:TextureByReference.java

public BranchGroup createSceneGraph() {

    // create the root of the branch group
    BranchGroup objRoot = new BranchGroup();

    // create the transform group node and initialize it
    // enable the TRANSFORM_WRITE capability so that it can be modified
    // at runtime. Add it to the root of the subgraph
    Transform3D rotate = new Transform3D();
    TransformGroup objTrans = new TransformGroup(rotate);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objRoot.addChild(objTrans);//from  w w  w .  j  av  a2  s . c om

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

    // set up some light
    Color3f lColor1 = new Color3f(0.7f, 0.7f, 0.7f);
    Vector3f lDir1 = new Vector3f(-1.0f, -0.5f, -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);

    Appearance appearance = new Appearance();

    // enable the TEXTURE_WRITE so we can modify it at runtime
    appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);

    // load the first texture
    TextureLoader loader = new TextureLoader(urls[0], TextureLoader.BY_REFERENCE | TextureLoader.Y_UP, this);
    // get the texture from the loader
    Texture2D tex = (Texture2D) loader.getTexture();

    // get the BufferedImage to convert to TYPE_4BYTE_ABGR and flip
    // get the ImageComponent because we need it anyway
    ImageComponent2D imageComp = (ImageComponent2D) tex.getImage(0);
    BufferedImage bImage = imageComp.getImage();
    // convert the image
    bImage = ImageOps.convertImage(bImage, BufferedImage.TYPE_4BYTE_ABGR);
    // flip the image
    ImageOps.flipImage(bImage);
    imageComp.set(bImage);

    tex.setCapability(Texture.ALLOW_IMAGE_WRITE);
    tex.setBoundaryModeS(Texture.CLAMP);
    tex.setBoundaryModeT(Texture.CLAMP);
    tex.setBoundaryColor(1.0f, 1.0f, 1.0f, 1.0f);

    // set the image of the texture
    tex.setImage(0, imageComp);

    // set the texture on the appearance
    appearance.setTexture(tex);

    // set texture attributes
    TextureAttributes texAttr = new TextureAttributes();
    texAttr.setTextureMode(TextureAttributes.MODULATE);
    appearance.setTextureAttributes(texAttr);

    // set material properties
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    appearance.setMaterial(new Material(white, black, white, black, 1.0f));

    // create a scale transform
    Transform3D scale = new Transform3D();
    scale.set(.6);
    TransformGroup objScale = new TransformGroup(scale);
    objTrans.addChild(objScale);

    tetra = new Tetrahedron(true);
    tetra.setAppearance(appearance);
    objScale.addChild(tetra);

    // create the behavior
    animate = new AnimateTexturesBehavior(tex, urls, appearance, this);
    animate.setSchedulingBounds(bounds);

    objTrans.addChild(animate);

    // add a rotation behavior so we can see all sides of the tetrahedron
    Transform3D yAxis = new Transform3D();
    Alpha rotorAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 4000, 0, 0, 0, 0, 0);
    RotationInterpolator rotator = new RotationInterpolator(rotorAlpha, objTrans, yAxis, 0.0f,
            (float) Math.PI * 2.0f);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    // have java3d perform optimizations on this scene graph
    objRoot.compile();

    return objRoot;
}

From source file:Demo3D.java

/**
 * Create the ViewBranch//from w  w w  . j a v  a 2  s . c om
 * 
 * @return javax.media.j3d.BranchGroup vbBrGr - the root of the ViewBranch
 */
public BranchGroup myViewBranch() {
    // Create the minimal PhysicalBody and PhysicalEnvironnement
    // instances with default parameters.
    body = new PhysicalBody();
    environment = new PhysicalEnvironment();

    // Create a View instance and attach the Canvas3D, the PhysicalBody
    // and the PhysicalEnvironment to it.
    view = new View();
    view.setFrontClipDistance(0.02); // Default value is 0.1 m
    view.setBackClipDistance(40.0); // Default value is 10 m
    // Rem.: BackClipDistance / FrontClipDistance = 2000 > 1000 but < 3000
    view.addCanvas3D(canvas3D);
    view.setPhysicalBody(body);
    view.setPhysicalEnvironment(environment);
    /*
     * // Choices of the projection type. They are 2 possibilities, namely: //
     * PERSPECTIVE_PROJECTION and PARALLEL_PROJECTION. // Note: the default
     * value is PERSPECTIVE_PROJECTION
     * view.setProjectionPolicy(View.PARALLEL_PROJECTION);
     */
    // Create a ViewPlatform instance and bind it with the View instance.
    viewPlat = new ViewPlatform();
    viewPlat.setActivationRadius(40.0f); // Default value is 62 m
    view.attachViewPlatform(viewPlat);

    // Create the action volume for the camera's navigation.
    cameraBounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Create the two necessary TransformGroups for the ViewPlatform's
    // motion (6 translations and 4 rotations).
    vpTrGrKeys_Rot_Up_Down = new TransformGroup();
    vpTrGrKeys_Transl_Turn = new TransformGroup();

    // With the ALLOW_TRANSFORM_READ and ALLOW_TRANSFORM_WRITE
    // capabilities, we allow the modification of the TransformGroup's
    // code by the Behavior's code at run time.
    vpTrGrKeys_Transl_Turn.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    vpTrGrKeys_Transl_Turn.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    vpTrGrKeys_Rot_Up_Down.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    vpTrGrKeys_Rot_Up_Down.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // Attach the ViewPlatform to the vpTrGrKeys_Rot_Up_Down node.
    vpTrGrKeys_Rot_Up_Down.addChild(viewPlat);

    // Create and attach an aimer to the TransformGroup node
    // vpTrGrKeys_Rot_Up_Down.
    aimer = new Aimer(1.5f);
    vpTrGrKeys_Rot_Up_Down.addChild(aimer.myAimer());

    // View-platform's motion ==> camera's navigation: 6 translations and 4
    // rotations.

    // Create and attach the camera's rotation on the vpTrGrKeys_Rot_Up_Down
    // node.
    camera_Rot_Up_Down = new Camera_Rot_Up_Down(vpTrGrKeys_Rot_Up_Down);
    camera_Rot_Up_Down.setSchedulingBounds(cameraBounds);
    vpTrGrKeys_Rot_Up_Down.addChild(camera_Rot_Up_Down);

    // Create and attach the camera's translation and rotation instances
    // on the vpTrGrKeys_Transl_Turn node.
    camera_Transl_Turn = new Camera_Transl_Turn(vpTrGrKeys_Transl_Turn);
    camera_Transl_Turn.setSchedulingBounds(cameraBounds);
    vpTrGrKeys_Transl_Turn.addChild(camera_Transl_Turn);

    // Attach the vpTrGrKeys_Rot_Up_Down node to the vpTrGrKeys_Transl_Turn
    // node.
    vpTrGrKeys_Transl_Turn.addChild(vpTrGrKeys_Rot_Up_Down);

    // Give the starting position of the ViewPlatform.
    trStart = new Transform3D(); // Identity matrix
    trStart.set(new Vector3f(0.0f, 0.0f, 10.0f)); // Translation of the
    // camera (0,0,10)

    // Create the TransformGroup node for the ViewPlatform's
    // starting position.
    vpTrGrStart = new TransformGroup(trStart);

    // Attach the vpTrGrKeys_Transl_Turn node to the TransformGroup
    // node vpTrGrStart.
    vpTrGrStart.addChild(vpTrGrKeys_Transl_Turn);

    // Add the TransformGroup node vpTrGrStart to the view
    // BranchGroup node vbBrGr.
    vbBrGr = new BranchGroup();
    vbBrGr.addChild(vpTrGrStart);

    // Compile the ViewBranch to optimize the performances.
    vbBrGr.compile();

    // Return the final version of the view branch BranchGroup node vbBrGr.
    return vbBrGr;
}

From source file:HiResCoordTest.java

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

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

    Transform3D yAxis = new Transform3D();
    yAxis.rotZ(0.2);/*ww  w . jav a2 s.  c  o  m*/
    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);

    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), m_TranslateSunZ);
    rotator.setSchedulingBounds(bounds);
    objTrans.addChild(rotator);

    Transform3D t3d = new Transform3D();
    t3d.setScale(m_EarthRadius);

    objTrans.addChild(createPlanet("Earth", new Color3f(0, 0.1f, 1), t3d, "earth.jpg"));
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:AvatarTest.java

public CarSteering(TransformGroup tg) {
    m_TransformGroup = tg;//from   w ww. jav a 2  s  .c om

    try {
        m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        m_TransformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    } catch (Exception e) {
    }

    wakeupOne = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    wakeupArray[0] = wakeupOne;
    wakeupCondition = new WakeupOr(wakeupArray);
}

From source file:Human1.java

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

    // Create a TransformGroup to scale the scene down by 3.5x
    // TODO: move view platform instead of scene using orbit behavior
    TransformGroup objScale = new TransformGroup();
    Transform3D scaleTrans = new Transform3D();
    scaleTrans.set(1 / 3.5f); // scale down by 3.5x
    objScale.setTransform(scaleTrans);/*from   www .j av a  2  s.  c  o  m*/
    objRoot.addChild(objScale);

    // Create a TransformGroup and initialize it to the
    // identity. Enable the TRANSFORM_WRITE capability so that
    // the mouse behaviors 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 the primitives to the scene
    createHuman(); // the human
    objTrans.addChild(Human_body);

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

    Background bg = new Background(new Color3f(1.0f, 1.0f, 1.0f));
    bg.setApplicationBounds(bounds);
    objTrans.addChild(bg);

    // set up the mouse rotation behavior
    MouseRotate mr = new MouseRotate();
    mr.setTransformGroup(objTrans);
    mr.setSchedulingBounds(bounds);
    mr.setFactor(0.007);
    objTrans.addChild(mr);

    // 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, 1.0f);
    Vector3f light1Direction = new Vector3f(0.0f, -0.2f, -1.0f);

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

    return objRoot;
}

From source file:GeomInfoApp.java

public BranchGroup createSceneGraph(boolean wireFrame) {
    int total = 0;

    System.out.println("\n --- geometry debug information --- \n");

    float[] coordinateData = null;
    coordinateData = createCoordinateData();
    int[] stripCount = { 17, 17, 5, 5, 5, 5, 5, 5, 5 }; // ******
    //        int[] stripCount = {17,17,17}; // ******

    for (int i = 0; i < stripCount.length; i++) {
        System.out.println("stripCount[" + i + "] = " + stripCount[i]);
        total += stripCount[i];//from www.j ava 2 s .c  om
    }

    if (total != coordinateData.length / 3) {
        System.out.println("  coordinateData vertex count: " + coordinateData.length / 3);
        System.out.println("stripCount total vertex count: " + total);
    }

    GeometryInfo gi = new GeometryInfo(GeometryInfo.POLYGON_ARRAY);
    gi.setCoordinates(coordinateData);
    gi.setStripCounts(stripCount);

    Triangulator tr = new Triangulator();
    //        Triangulator tr = new Triangulator(1);
    System.out.println("begin triangulation");
    tr.triangulate(gi);
    System.out.println("  END triangulation");
    gi.recomputeIndices();

    NormalGenerator ng = new NormalGenerator();
    ng.generateNormals(gi);
    gi.recomputeIndices();

    Stripifier st = new Stripifier();
    st.stripify(gi);
    gi.recomputeIndices();

    Shape3D part = new Shape3D();
    if (wireFrame == true)
        part.setAppearance(createWireFrameAppearance());
    else
        part.setAppearance(createMaterialAppearance());
    part.setGeometry(gi.getGeometryArray());

    /////////////////////////////

    BranchGroup contentRoot = new BranchGroup();

    // Create the transform group node and initialize it to the
    // identity. Add it to the root of the subgraph.
    TransformGroup objSpin = new TransformGroup();
    objSpin.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    contentRoot.addChild(objSpin);

    objSpin.addChild(part);

    ////////////////////////
    LineStripArray lineArray = new LineStripArray(69, LineArray.COORDINATES, stripCount); //*****
    //        LineStripArray lineArray = new LineStripArray(51,
    // LineArray.COORDINATES, stripCount); //*****
    lineArray.setCoordinates(0, coordinateData);
    Appearance blueColorAppearance = new Appearance();
    ColoringAttributes blueColoring = new ColoringAttributes();
    blueColoring.setColor(0.0f, 0.0f, 1.0f);
    blueColorAppearance.setColoringAttributes(blueColoring);
    LineAttributes lineAttrib = new LineAttributes();
    lineAttrib.setLineWidth(2.0f);
    blueColorAppearance.setLineAttributes(lineAttrib);
    objSpin.addChild(new Shape3D(lineArray, blueColorAppearance));

    Alpha rotationAlpha = new Alpha(-1, 16000);

    RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objSpin);

    // a bounding sphere specifies a region a behavior is active
    // create a sphere centered at the origin with radius of 1
    BoundingSphere bounds = new BoundingSphere();
    rotator.setSchedulingBounds(bounds);
    objSpin.addChild(rotator);

    DirectionalLight lightD = new DirectionalLight();
    lightD.setDirection(new Vector3f(0.0f, -0.7f, -0.7f));
    lightD.setInfluencingBounds(bounds);
    contentRoot.addChild(lightD);

    AmbientLight lightA = new AmbientLight();
    lightA.setInfluencingBounds(bounds);
    contentRoot.addChild(lightA);

    Background background = new Background();
    background.setColor(1.0f, 1.0f, 1.0f);
    background.setApplicationBounds(bounds);
    contentRoot.addChild(background);

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

    return contentRoot;
}