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:GeometryByReferenceTest.java

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

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);// w w  w.  j  a v  a2s.  c o  m
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

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

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

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

    return objRoot;
}

From source file:KeyNavigateTest.java

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

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

    createMap(objTrans);/*w ww .  ja  v a  2  s .c  o  m*/
    createFloor(objTrans);
    createCeiling(objTrans);

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:J3dSwingFrame.java

public Camera() {
    hud_group = new Group();
    hud_group.setCapability(Group.ALLOW_CHILDREN_EXTEND);

    platform = new ViewPlatform();
    location = new Transform3D();

    root_tx_grp = new TransformGroup();
    root_tx_grp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    root_tx_grp.setTransform(location);/*from  ww w  .j a va  2  s .  c o m*/
    root_tx_grp.addChild(platform);
    root_tx_grp.addChild(hud_group);

    // now create the headlight
    headlight = new DirectionalLight();
    headlight.setCapability(Light.ALLOW_STATE_WRITE);
    headlight.setColor(White);
    headlight.setInfluencingBounds(LIGHT_BOUNDS);
    root_tx_grp.addChild(headlight);

    body = new PhysicalBody();
    env = new PhysicalEnvironment();

    view = new View();
    view.setBackClipDistance(BACK_CLIP_DISTANCE);
    view.setPhysicalBody(body);
    view.setPhysicalEnvironment(env);
    view.attachViewPlatform(platform);
}

From source file:GeometryByReferenceNIOBuffer.java

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

    // Set up attributes to render lines
    app = new Appearance();

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);/*  w ww  .j  a  v  a  2  s . c  o  m*/
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

    //create the direct nio buffer
    createJ3DBuffers();

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_READ);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

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

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

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

    return objRoot;
}

From source file:SimpleTest.java

public TransformGroup createBehaviors(BranchGroup bg) {
    // create a TransformGroup.
    ///*ww w  .  j av  a 2 s .  co  m*/
    // A TransformGroup is a Group node (can have children)
    // and contains a Transform3D member.
    //
    // The Transform3D member contains a 4x4 transformation matrix
    // that is applied during rendering to all the TransformGroup's
    // child nodes. The 4x4 matrix can describe:
    // scaling, translation and rotation in one neat package!

    // enable the TRANSFORM_WRITE capability so that
    // our behavior code can modify it at runtime
    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // create a new Transform3D that will describe
    // the direction we want to move.
    Transform3D xAxis = new Transform3D();

    // create an Alpha object.
    // The Alpha object describes a function against time.
    // The Alpha will output a value that ranges between 0 and 1
    // using the time parameters (in milliseconds).
    Alpha xAlpha = new Alpha(-1, Alpha.DECREASING_ENABLE | Alpha.INCREASING_ENABLE, 1000, 1000, 5000, 1000,
            1000, 10000, 2000, 4000);

    // create a PositionInterpolator
    // The PositionInterpolator will modify the translation components
    // of a TransformGroup's Transform3D (objTrans) based on the output
    // from the Alpha. In this case the movement will range from
    // -0.8 along the X-axis with Alpha=0 to X=0.8 when Alpha=1.
    PositionInterpolator posInt = new PositionInterpolator(xAlpha, objTrans, xAxis, -0.8f, 0.8f);

    // set the range of influence of the PositionInterpolator
    posInt.setSchedulingBounds(getBoundingSphere());

    // wire the PositionInterpolator into its parent
    // TransformGroup. Just like rendering nodes behaviors
    // must be added to the scenegraph.
    objTrans.addChild(posInt);

    // add the TransformGroup to its parent BranchGroup
    bg.addChild(objTrans);

    // we return the TransformGroup with the
    // behavior attached so that we can add nodes to it
    // (which will be effected by the PositionInterpolator).
    return objTrans;
}

From source file:MouseNavigateTest.java

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

    // note that we are creating a TG *above* the TG
    // the is being controlled by the mouse behaviors.
    // The SUN mouse translate behavior would fail in this
    // instance as all movement would be in the X-Y plane
    // irrespective of any TG above the object.
    // The TornadoMouseTranslate behavior always moves an object
    // parrallel to the image plane
    TransformGroup objTrans1 = new TransformGroup();
    Transform3D t3d = new Transform3D();
    objTrans1.getTransform(t3d);/* w w  w. java2 s. c o m*/
    t3d.setEuler(new Vector3d(0.9, 0.8, 0.3));
    objTrans1.setTransform(t3d);

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

    // create the mouse scale behavior and set limits
    TornadoMouseScale mouseScale = new TornadoMouseScale(5, 0.1f);
    mouseScale.setMinScale(new Point3d(0.5, 0.5, 0.5));
    mouseScale.setMaxScale(new Point3d(2, 2, 2));
    mouseScale.setObject(objTrans);
    mouseScale.setChangeListener(this);
    mouseScale.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(mouseScale);

    // create the mouse rotate behavior
    TornadoMouseRotate mouseRotate = new TornadoMouseRotate(0.001, 0.001);
    mouseRotate.setInvert(true);
    mouseRotate.setObject(objTrans);
    mouseRotate.setChangeListener(this);
    mouseRotate.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(mouseRotate);

    // create the mouse translate behavior and set limits
    TornadoMouseTranslate mouseTrans = new TornadoMouseTranslate(0.005f);
    mouseTrans.setObject(objTrans);
    mouseTrans.setChangeListener(this);
    mouseTrans.setMinTranslate(new Point3d(-4, -4, -4));
    mouseTrans.setMaxTranslate(new Point3d(4, 4, 4));
    mouseTrans.setSchedulingBounds(getApplicationBounds());
    objTrans.addChild(mouseTrans);

    objTrans.addChild(new ColorCube(0.5));

    // create some axis for the world to show it has been rotated
    ColorCube axis = new ColorCube(5.0);
    Appearance app = new Appearance();
    app.setPolygonAttributes(
            new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_NONE, 0));
    axis.setAppearance(app);
    objTrans1.addChild(axis);

    objTrans1.addChild(objTrans);
    objRoot.addChild(objTrans1);

    return objRoot;
}

From source file:AppearanceTest.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);//  ww  w.  j  a  v a2 s. c om

    // 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:InterleavedTest.java

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

    // Set up attributes to render lines
    app = new Appearance();
    app.setCapability(Appearance.ALLOW_TEXTURE_UNIT_STATE_WRITE);

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//from  w ww.  ja v a  2s .  c  om
    transp.setCapability(TransparencyAttributes.ALLOW_MODE_WRITE);
    transp.setTransparencyMode(TransparencyAttributes.NONE);
    app.setTransparencyAttributes(transp);

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

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

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

    textureUnitState[0] = new TextureUnitState(tex1, texAttr1, null);
    textureUnitState[1] = new TextureUnitState(tex2, texAttr2, null);

    tetraRegular = createGeometry(1);
    tetraStrip = createGeometry(2);
    tetraIndexed = createGeometry(3);
    tetraIndexedStrip = createGeometry(4);

    geoArrays[0] = tetraRegular;
    geoArrays[1] = tetraStrip;
    geoArrays[2] = tetraIndexed;
    geoArrays[3] = tetraIndexedStrip;

    shape = new Shape3D(tetraRegular, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);

    Transform3D t = new Transform3D();
    // move the object upwards
    t.set(new Vector3f(0.0f, 0.3f, 0.0f));

    // rotate the shape
    Transform3D temp = new Transform3D();
    temp.rotX(Math.PI / 4.0d);
    t.mul(temp);
    temp.rotY(Math.PI / 4.0d);
    t.mul(temp);

    // Shrink the object
    t.setScale(0.6);

    TransformGroup trans = new TransformGroup(t);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    trans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);

    objRoot.addChild(trans);
    trans.addChild(shape);

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

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

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

    return objRoot;
}

From source file:PickTest.java

private Group createObject(int index, double scale, double xpos, double ypos) {

    Shape3D shape = null;/*from w  w w  .ja  v a  2 s.  c  o m*/
    Geometry geom = null;

    // 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);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    objTrans.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    // 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);
    spinTg.setCapability(TransformGroup.ENABLE_PICK_REPORTING);

    Appearance appearance = new Appearance();

    switch (index) {
    case 0:
        geom = new GullCG();
        break;
    case 1:
        geom = new TetrahedronTA();
        break;
    case 2:
        geom = new OctahedronTFA();
        break;
    case 3:
        geom = new IcosahedronTSA();
        break;
    case 4:
        geom = new CubeIQA();
        break;
    case 5:
        geom = new TetrahedronITA();
        break;
    case 6:
        geom = new OctahedronITFA();
        break;
    case 7:
        geom = new IcosahedronITSA();
        break;
    case 8:
        geomMorph[0] = new ColorPyramidUp();
        geomMorph[1] = new ColorCube();
        geomMorph[2] = new ColorPyramidDown();
        break;
    case 9:
        geom = new TetrahedronLA();
        break;
    case 10:
        geom = new TetrahedronILA();
        break;
    case 11:
        geom = new TetrahedronLSA();
        break;
    case 12:
        geom = new TetrahedronILSA();
        break;
    case 13:
        geom = new TetrahedronPA();
        break;
    case 14:
        geom = new TetrahedronIPA();
        break;
    // TODO: other geo types, Text3D?
    case 15:
        geom = new TetrahedronTA();
        break;
    }

    Material m = new Material();

    if (index == 8) {
        m.setLightingEnable(false);
        appearance.setMaterial(m);
        morph = new Morph((GeometryArray[]) geomMorph, appearance);
        morph.setCapability(Morph.ALLOW_WEIGHTS_READ);
        morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE);
        PickTool.setCapabilities(morph, PickTool.INTERSECT_FULL);
        spinTg.addChild(morph);
    } else {
        // Geometry picking require this to be set.
        if (index == 0)
            m.setLightingEnable(true);
        else
            m.setLightingEnable(false);
        appearance.setMaterial(m);

        if ((index == 13) || (index == 14)) {
            PointAttributes pa = new PointAttributes();
            pa.setPointSize(4.0f);
            appearance.setPointAttributes(pa);
        }

        shape = new Shape3D(geom, appearance);
        shape.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        shape.setCapability(Shape3D.ENABLE_PICK_REPORTING);
        PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);
        spinTg.addChild(shape);
    }

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

    return objTrans;
}

From source file:SimpleGame.java

/**
 * This builds the ball that acts as the bullet for our gun. The ball is
 * created from a sphere primitive, and a transform group and interpolator
 * are added so that we can 'fire' the bullet.
 * //from w  w  w  .ja v a  2s. com
 * @return BranchGroup that is the root of the ball branch.
 */
protected BranchGroup buildBall() {
    BranchGroup theBall = new BranchGroup();

    Appearance ballApp = new Appearance();
    Color3f ambientColour = new Color3f(1.0f, 0.0f, 0.0f);
    Color3f emissiveColour = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f specularColour = new Color3f(1.0f, 1.0f, 1.0f);
    Color3f diffuseColour = new Color3f(1.0f, 0.0f, 0.0f);
    float shininess = 20.0f;
    ballApp.setMaterial(new Material(ambientColour, emissiveColour, diffuseColour, specularColour, shininess));

    Sphere ball = new Sphere(0.2f, ballApp);

    TransformGroup ballMovXfmGrp = new TransformGroup();
    ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
    ballMovXfmGrp.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    ballMovXfmGrp.addChild(ball);
    theBall.addChild(ballMovXfmGrp);

    ballAlpha = new Alpha(1, 0, 0, 500, 0, 0);
    Transform3D axis = new Transform3D();
    axis.rotY(Math.PI / 2);
    moveBall = new PositionInterpolator(ballAlpha, ballMovXfmGrp, axis, 0.0f, 50.0f);
    moveBall.setSchedulingBounds(bounds);
    theBall.addChild(moveBall);

    return theBall;

}