Example usage for javax.media.j3d Transform3D setScale

List of usage examples for javax.media.j3d Transform3D setScale

Introduction

In this page you can find the example usage for javax.media.j3d Transform3D setScale.

Prototype

public final void setScale(Vector3d scale) 

Source Link

Document

Sets the possibly non-uniform scale component of the current transform; any existing scale is first factored out of the existing transform before the new scale is applied.

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);// ww w  .  j  a  va2 s .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:ffx.potential.bonded.RestraintBond.java

/**
 * <p>//from   w  ww  .  j a  v  a  2  s .co  m
 * setBondTransform3d</p>
 *
 * @param t3d a {@link javax.media.j3d.Transform3D} object.
 * @param pos an array of double.
 * @param orient an array of double.
 * @param len a double.
 * @param newRot a boolean.
 */
public void setBondTransform3d(Transform3D t3d, double[] pos, double[] orient, double len, boolean newRot) {
    // Bond Orientation
    if (newRot) {
        angle = angle(orient, y);
        cross(y, orient, bcross);
        bcross[3] = angle - Math.PI;
        axisAngle.set(bcross);
    }
    // Scale the orientation vector to be a fourth the bond length
    // and add it to the position vector of the of the first atom
    scalar(orient, len / 4.0d, cstart);
    sum(cstart, pos, cstart);
    pos3d.set(cstart);
    t3d.setTranslation(pos3d);
    t3d.setRotation(axisAngle);
    t3d.setScale(scale);
}

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  . j a v  a 2s  . 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:GearTest.java

public BranchGroup createSceneGraph(int toothCount) {
    // 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);//from  w  ww.  j av  a2  s. co  m
    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
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bgNode = new Background(bgColor);
    bgNode.setApplicationBounds(bounds);
    objScale.addChild(bgNode);

    // Set up the global lights
    Color3f light1Color = new Color3f(1.0f, 1.0f, 0.9f);
    Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
    Color3f light2Color = new Color3f(0.3f, 0.3f, 0.4f);
    Vector3f light2Direction = new Vector3f(-6.0f, -2.0f, -1.0f);
    Color3f ambientColor = new Color3f(0.1f, 0.1f, 0.1f);

    AmbientLight ambientLightNode = new AmbientLight(ambientColor);
    ambientLightNode.setInfluencingBounds(bounds);
    objScale.addChild(ambientLightNode);

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

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

    // 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);
    objScale.addChild(objTrans);

    // Create an Appearance.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));

    // Create a gear, add it to the scene graph.
    //   SpurGear gear = new SpurGear(toothCount, 1.0f, 0.2f,
    SpurGear gear = new SpurGearThinBody(toothCount, 1.0f, 0.2f, 0.05f, 0.05f, 0.3f, 0.28f, look);
    objTrans.addChild(gear);

    // Create a new Behavior object that will rotate the object and
    // add it into the scene graph.
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 8000, 0, 0, 0, 0, 0);

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

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

    return objRoot;
}

From source file:GearTest.java

public BranchGroup createGearBox(int toothCount) {
    Transform3D tempTransform = new Transform3D();

    // Create the root of the branch graph
    BranchGroup branchRoot = createBranchEnvironment();

    // 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);/*w ww .j  av a2s . c  o m*/
    branchRoot.addChild(objScale);

    // Create an Appearance.
    Appearance look = new Appearance();
    Color3f objColor = new Color3f(0.5f, 0.5f, 0.6f);
    Color3f black = new Color3f(0.0f, 0.0f, 0.0f);
    Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
    look.setMaterial(new Material(objColor, black, objColor, white, 100.0f));

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

    // Create a bounds for the mouse behavior methods
    BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

    // Define the shaft base information
    int shaftCount = 4;
    int secondsPerRevolution = 8000;

    // Create the Shaft(s)
    Shaft shafts[] = new Shaft[shaftCount];
    TransformGroup shaftTGs[] = new TransformGroup[shaftCount];
    Alpha shaftAlphas[] = new Alpha[shaftCount];
    RotationInterpolator shaftRotors[] = new RotationInterpolator[shaftCount];
    Transform3D shaftAxis[] = new Transform3D[shaftCount];

    // Note: the following arrays we're incorporated to make changing
    // the gearbox easier.
    float shaftRatios[] = new float[shaftCount];
    shaftRatios[0] = 1.0f;
    shaftRatios[1] = 0.5f;
    shaftRatios[2] = 0.75f;
    shaftRatios[3] = 5.0f;

    float shaftRadius[] = new float[shaftCount];
    shaftRadius[0] = 0.2f;
    shaftRadius[1] = 0.2f;
    shaftRadius[2] = 0.2f;
    shaftRadius[3] = 0.2f;

    float shaftLength[] = new float[shaftCount];
    shaftLength[0] = 1.8f;
    shaftLength[1] = 0.8f;
    shaftLength[2] = 0.8f;
    shaftLength[3] = 0.8f;

    float shaftDirection[] = new float[shaftCount];
    shaftDirection[0] = 1.0f;
    shaftDirection[1] = -1.0f;
    shaftDirection[2] = 1.0f;
    shaftDirection[3] = -1.0f;

    Vector3d shaftPlacement[] = new Vector3d[shaftCount];
    shaftPlacement[0] = new Vector3d(-0.75, -0.9, 0.0);
    shaftPlacement[1] = new Vector3d(0.75, -0.9, 0.0);
    shaftPlacement[2] = new Vector3d(0.75, 0.35, 0.0);
    shaftPlacement[3] = new Vector3d(-0.75, 0.60, -0.7);

    // Create the shafts.
    for (int i = 0; i < shaftCount; i++) {
        shafts[i] = new Shaft(shaftRadius[i], shaftLength[i], 25, look);
    }

    // Create a transform group node for placing each shaft
    for (int i = 0; i < shaftCount; i++) {
        shaftTGs[i] = new TransformGroup();
        gearboxTrans.addChild(shaftTGs[i]);
        shaftTGs[i].getTransform(tempTransform);
        tempTransform.setTranslation(shaftPlacement[i]);
        shaftTGs[i].setTransform(tempTransform);
        shaftTGs[i].addChild(shafts[i]);
    }

    // Add rotation interpolators to rotate the shaft in the appropriate
    // direction and at the appropriate rate
    for (int i = 0; i < shaftCount; i++) {
        shaftAlphas[i] = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0,
                (long) (secondsPerRevolution * shaftRatios[i]), 0, 0, 0, 0, 0);
        shaftAxis[i] = new Transform3D();
        shaftAxis[i].rotX(Math.PI / 2.0);
        shaftRotors[i] = new RotationInterpolator(shaftAlphas[i], shafts[i], shaftAxis[i], 0.0f,
                shaftDirection[i] * (float) Math.PI * 2.0f);
        shaftRotors[i].setSchedulingBounds(bounds);
        shaftTGs[i].addChild(shaftRotors[i]);
    }

    // Define the gear base information. Again, these arrays exist to
    // make the process of changing the GearBox via an editor faster
    int gearCount = 5;
    float valleyToCircularPitchRatio = .15f;
    float pitchCircleRadius = 1.0f;
    float addendum = 0.05f;
    float dedendum = 0.05f;
    float gearThickness = 0.3f;
    float toothTipThickness = 0.27f;

    // Create an array of gears and their associated information
    SpurGear gears[] = new SpurGear[gearCount];
    TransformGroup gearTGs[] = new TransformGroup[gearCount];

    int gearShaft[] = new int[gearCount];
    gearShaft[0] = 0;
    gearShaft[1] = 1;
    gearShaft[2] = 2;
    gearShaft[3] = 0;
    gearShaft[4] = 3;

    float ratio[] = new float[gearCount];
    ratio[0] = 1.0f;
    ratio[1] = 0.5f;
    ratio[2] = 0.75f;
    ratio[3] = 0.25f;
    ratio[4] = 1.25f;

    Vector3d placement[] = new Vector3d[gearCount];
    placement[0] = new Vector3d(0.0, 0.0, 0.0);
    placement[1] = new Vector3d(0.0, 0.0, 0.0);
    placement[2] = new Vector3d(0.0, 0.0, 0.0);
    placement[3] = new Vector3d(0.0, 0.0, -0.7);
    placement[4] = new Vector3d(0.0, 0.0, 0.0);

    // Create the gears.
    for (int i = 0; i < gearCount; i++) {
        gears[i] = new SpurGearThinBody(((int) ((float) toothCount * ratio[i])), pitchCircleRadius * ratio[i],
                shaftRadius[0], addendum, dedendum, gearThickness, toothTipThickness,
                valleyToCircularPitchRatio, look);
    }

    // Create a transform group node for arranging the gears on a shaft
    // and attach the gear to its associated shaft
    for (int i = 0; i < gearCount; i++) {
        gearTGs[i] = new TransformGroup();
        gearTGs[i].getTransform(tempTransform);
        tempTransform
                .rotZ((shaftDirection[gearShaft[i]] == -1.0) ? gears[i].getCircularPitchAngle() / -2.0f : 0.0f);
        tempTransform.setTranslation(placement[i]);
        gearTGs[i].setTransform(tempTransform);
        gearTGs[i].addChild(gears[i]);
        shafts[gearShaft[i]].addChild(gearTGs[i]);
    }

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

    return branchRoot;
}

From source file:KeyNavigateTest.java

public TransformGroup[] getViewTransformGroupArray() {
    TransformGroup[] tgArray = new TransformGroup[2];
    tgArray[0] = new TransformGroup();
    tgArray[1] = new TransformGroup();

    Transform3D t3d = new Transform3D();
    t3d.setScale(getScale());
    t3d.invert();//from ww  w .  ja va2  s.co  m
    tgArray[0].setTransform(t3d);

    // ensure the Behavior can access the TG
    tgArray[1].setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);

    // create the KeyBehavior and attach
    KeyCollisionBehavior keyBehavior = new KeyCollisionBehavior(tgArray[1], this);
    keyBehavior.setSchedulingBounds(getApplicationBounds());
    keyBehavior.setMovementRate(0.7);
    tgArray[1].addChild(keyBehavior);

    return tgArray;
}

From source file:KeyNavigateTest.java

public Group createObject(Appearance app, Vector3d position, Vector3d scale, String szTextureFile,
        String szSoundFile, String szCollisionSound) {
    m_TransformGroup = new TransformGroup();
    Transform3D t3d = new Transform3D();

    t3d.setScale(scale);
    t3d.setTranslation(position);/*from  w  w  w.j a va2s.c  o  m*/

    m_TransformGroup.setTransform(t3d);

    m_BehaviorTransformGroup = new TransformGroup();

    if ((m_nFlags & GEOMETRY) == GEOMETRY)
        m_BehaviorTransformGroup
                .addChild(createGeometryGroup(app, position, scale, szTextureFile, szSoundFile));

    if ((m_nFlags & SOUND) == SOUND) {
        MediaContainer media = loadSoundFile(szSoundFile);
        PointSound pointSound = new PointSound(media, getSoundInitialGain(false), 0, 0, 0);
        setSoundAttributes(pointSound, false);
        m_BehaviorTransformGroup.addChild(pointSound);
    }

    if ((m_nFlags & COLLISION) == COLLISION) {
        m_BehaviorTransformGroup.setCapability(Node.ENABLE_COLLISION_REPORTING);
        m_BehaviorTransformGroup.setCollidable(true);
        m_BehaviorTransformGroup.setCollisionBounds(getGeometryBounds());

        if ((m_nFlags & COLLISION_SOUND) == COLLISION_SOUND) {
            MediaContainer collideMedia = loadSoundFile(szCollisionSound);

            m_CollideSound = new BackgroundSound(collideMedia, 1);
            setSoundAttributes(m_CollideSound, true);
            m_TransformGroup.addChild(m_CollideSound);
        }

        CollisionBehavior collision = new CollisionBehavior(m_BehaviorTransformGroup, this);
        collision.setSchedulingBounds(getGeometryBounds());

        m_BehaviorTransformGroup.addChild(collision);
    }

    m_TransformGroup.addChild(m_BehaviorTransformGroup);
    m_ParentGroup.addChild(m_TransformGroup);

    return m_BehaviorTransformGroup;
}

From source file:PickTest.java

public BranchGroup createSceneGraph(Canvas3D canvas) {
    // 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(1.0);
    objScale.setTransform(t3d);//from  w w w  .  ja  va  2  s . co m
    objRoot.addChild(objScale);

    // Create a bunch of objects with a behavior and add them
    // into the scene graph.

    int row, col;
    int numRows = 4, numCols = 4;

    for (int i = 0; i < numRows; i++) {
        double ypos = (double) (i - numRows / 2) * 0.45 + 0.25;
        for (int j = 0; j < numCols; j++) {
            double xpos = (double) (j - numCols / 2) * 0.45 + 0.25;
            objScale.addChild(createObject(i * numCols + j, 0.1, xpos, ypos));
        }
    }

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

    // Add a light.
    Color3f lColor = new Color3f(1.0f, 1.0f, 1.0f);
    Vector3f lDir = new Vector3f(0.0f, 0.0f, -1.0f);

    DirectionalLight lgt = new DirectionalLight(lColor, lDir);
    lgt.setInfluencingBounds(bounds);
    objRoot.addChild(lgt);

    // Now create the Alpha object that controls the speed of the
    // morphing operation.
    Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 4000, 1000, 500,
            4000, 1000, 500);

    // Finally, create the morphing behavior
    MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph);
    mBeh.setSchedulingBounds(bounds);
    objRoot.addChild(mBeh);

    behavior1 = new PickRotateBehavior(objRoot, canvas, bounds);
    objRoot.addChild(behavior1);

    behavior2 = new PickZoomBehavior(objRoot, canvas, bounds);
    objRoot.addChild(behavior2);

    behavior3 = new PickTranslateBehavior(objRoot, canvas, bounds);
    objRoot.addChild(behavior3);

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

    return objRoot;
}

From source file:Morphing.java

private 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);
    objScale.setTransform(t3d);/*from  ww  w .  j a v  a 2 s  .c  o m*/
    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
    Color3f bgColor = new Color3f(0.05f, 0.05f, 0.2f);
    Background bg = new Background(bgColor);
    bg.setApplicationBounds(bounds);
    objScale.addChild(bg);

    // 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);
    objScale.addChild(aLgt);
    objScale.addChild(lgt1);

    //
    // Create the transform group nodes for the 3 original objects
    // and the morphed object. Add them to the root of the
    // branch graph.
    //
    TransformGroup objTrans[] = new TransformGroup[4];

    for (int i = 0; i < 4; i++) {
        objTrans[i] = new TransformGroup();
        objScale.addChild(objTrans[i]);
    }

    Transform3D tr = new Transform3D();
    Transform3D rotX90 = new Transform3D();
    rotX90.rotX(90.0 * Math.PI / 180.0);

    objTrans[0].getTransform(tr);
    tr.setTranslation(new Vector3d(-2.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[0].setTransform(tr);

    objTrans[1].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[1].setTransform(tr);

    objTrans[2].getTransform(tr);
    tr.setTranslation(new Vector3d(2.0, 1.5, -2.0));
    tr.mul(rotX90);
    objTrans[2].setTransform(tr);

    objTrans[3].getTransform(tr);
    tr.setTranslation(new Vector3d(0.0, -2.0, -2.0));
    tr.mul(rotX90);
    objTrans[3].setTransform(tr);

    // Now load the object files
    Scene s[] = new Scene[3];
    GeometryArray g[] = new GeometryArray[3];
    Shape3D shape[] = new Shape3D[3];
    ObjectFile loader = new ObjectFile(ObjectFile.RESIZE);
    for (int i = 0; i < 3; i++) {
        s[i] = null;
        g[i] = null;
        shape[i] = null;
    }

    for (int i = 0; i < 3; i++) {
        try {
            s[i] = loader.load(objFiles[i]);
        } catch (FileNotFoundException e) {
            System.err.println(e);
            System.exit(1);
        } catch (ParsingErrorException e) {
            System.err.println(e);
            System.exit(1);
        } catch (IncorrectFormatException e) {
            System.err.println(e);
            System.exit(1);
        }

        BranchGroup b = s[i].getSceneGroup();
        shape[i] = (Shape3D) b.getChild(0);
        g[i] = (GeometryArray) shape[i].getGeometry();

        shape[i].setGeometry(g[i]);
        objTrans[i].addChild(b);
    }

    //
    // Create a Morph node, and set the appearance and input geometry
    // arrays. Set the Morph node's capability bits to allow the weights
    // to be modified at runtime.
    //
    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));
    Morph morph = new Morph(g, app);
    morph.setCapability(Morph.ALLOW_WEIGHTS_READ);
    morph.setCapability(Morph.ALLOW_WEIGHTS_WRITE);

    objTrans[3].addChild(morph);

    // Now create the Alpha object that controls the speed of the
    // morphing operation.
    Alpha morphAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE | Alpha.DECREASING_ENABLE, 0, 0, 2000, 1000, 200,
            2000, 1000, 200);

    // Finally, create the morphing behavior
    MorphingBehavior mBeh = new MorphingBehavior(morphAlpha, morph);
    mBeh.setSchedulingBounds(bounds);
    objScale.addChild(mBeh);

    return objRoot;
}

From source file:ExTexture.java

public void checkboxChanged(CheckboxMenu menu, int check) {
    if (menu == imageMenu) {
        // Change the texture image
        currentImage = check;//from  www .  j  a va  2  s. c  o  m
        Texture tex = textureComponents[currentImage];
        int mode = ((Integer) boundaries[currentBoundary].value).intValue();
        Color3f color = (Color3f) colors[currentColor].value;
        int filter = ((Integer) filters[currentFilter].value).intValue();

        shape.setAppearance(dummyApp);
        tex.setEnable(textureOnOff);
        tex.setBoundaryModeS(mode);
        tex.setBoundaryModeT(mode);
        tex.setBoundaryColor(color.x, color.y, color.z, 0.0f);
        tex.setMagFilter(filter);
        tex.setMinFilter(filter);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == boundaryMenu) {
        // Change the texture boundary mode
        currentBoundary = check;
        Texture tex = textureComponents[currentImage];
        int mode = ((Integer) boundaries[currentBoundary].value).intValue();

        shape.setAppearance(dummyApp);
        tex.setBoundaryModeS(mode);
        tex.setBoundaryModeT(mode);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == colorMenu) {
        // Change the boundary color
        currentColor = check;
        Color3f color = (Color3f) colors[currentColor].value;
        Texture tex = textureComponents[currentImage];

        shape.setAppearance(dummyApp);
        tex.setBoundaryColor(color.x, color.y, color.z, 0.0f);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == filterMenu) {
        // Change the filter mode
        currentFilter = check;
        int filter = ((Integer) filters[currentFilter].value).intValue();
        Texture tex = textureComponents[currentImage];

        shape.setAppearance(dummyApp);
        tex.setMagFilter(filter);
        tex.setMinFilter(filter);
        app.setTexture(tex);
        shape.setAppearance(app);

        return;
    }

    if (menu == modeMenu) {
        // Change the texture mode
        currentMode = check;
        int mode = ((Integer) modes[currentMode].value).intValue();

        app.setTextureAttributes(dummyAtt);
        texatt.setTextureMode(mode);
        app.setTextureAttributes(texatt);

        return;
    }

    if (menu == blendColorMenu) {
        // Change the boundary color
        currentBlendColor = check;
        Color3f color = (Color3f) colors[currentBlendColor].value;

        app.setTextureAttributes(dummyAtt);
        texatt.setTextureBlendColor(color.x, color.y, color.z, 0.5f);
        app.setTextureAttributes(texatt);

        return;
    }

    if (menu == xformMenu) {
        // Change the texture transform
        currentXform = check;
        Transform3D tt = new Transform3D();
        switch (currentXform) {
        default:
        case 0:
            // Identity
            texatt.setTextureTransform(tt);
            return;

        case 1:
            // Scale by 2
            tt.setScale(2.0);
            texatt.setTextureTransform(tt);
            return;

        case 2:
            // Scale by 4
            tt.setScale(4.0);
            texatt.setTextureTransform(tt);
            return;

        case 3:
            // Z rotate by 45 degrees
            tt.rotZ(Math.PI / 4.0);
            texatt.setTextureTransform(tt);
            return;

        case 4:
            // Translate by 0.25
            tt.set(new Vector3f(0.25f, 0.0f, 0.0f));
            texatt.setTextureTransform(tt);
            return;
        }
    }

    // Handle all other checkboxes
    super.checkboxChanged(menu, check);
}