Example usage for javax.media.j3d TransformGroup setCapability

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

Introduction

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

Prototype

public final void setCapability(int bit) 

Source Link

Document

Sets the specified capability bit.

Usage

From source file:AvatarTest.java

public TransformGroup addBehaviors(Group bgRoot) {
    // 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);

    Transform3D zAxis = new Transform3D();
    zAxis.rotY(Math.toRadians(90.0));

    Alpha zoomAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 20000, 0, 0, 0, 0, 0);

    PositionInterpolator posInt = new PositionInterpolator(zoomAlpha, objTrans, zAxis, 0, -160);

    posInt.setSchedulingBounds(getBoundingSphere());
    objTrans.addChild(posInt);/*from   w w w . j a  v  a  2  s.c  o  m*/

    bgRoot.addChild(objTrans);

    return objTrans;
}

From source file:CustomAlphaTest.java

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

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

    ColorCube cube = new ColorCube(2);
    objTrans.addChild(cube);/*from  w  ww .  j  av  a2  s.co  m*/

    FileAlpha fileAlpha = null;

    try {
        fileAlpha = new FileAlpha(new URL(getWorkingDirectory(), "values.xls"), this);
    } catch (Exception e) {
        e.toString();
    }

    PositionInterpolator posInterpolator = new PositionInterpolator(fileAlpha, objTrans, new Transform3D(), -6,
            6);
    posInterpolator.setSchedulingBounds(getApplicationBounds());

    objTrans.addChild(posInterpolator);
    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:CuboidTest.java

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

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

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

    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(bounds);
    objTrans.addChild(rotator);/*from  w w  w  .  j  a v a 2s.  c om*/

    // create an appearance
    Appearance ap = new Appearance();

    // render as a wireframe
    PolygonAttributes polyAttrbutes = new PolygonAttributes();
    polyAttrbutes.setPolygonMode(PolygonAttributes.POLYGON_LINE);
    polyAttrbutes.setCullFace(PolygonAttributes.CULL_NONE);
    ap.setPolygonAttributes(polyAttrbutes);

    objTrans.addChild(new Cuboid(50, 30, 20, ap));
    objTrans.addChild(new Box(25, 15, 10, ap));

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:BehaviorTest.java

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

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

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

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

    // create an Appearance and Material
    Appearance app = new Appearance();

    TextureLoader tex = new TextureLoader("earth.jpg", this);
    app.setTexture(tex.getTexture());/*from  ww  w  . j av a  2  s .  c o m*/

    Sphere sphere = new Sphere(3, Primitive.GENERATE_NORMALS | Primitive.GENERATE_TEXTURE_COORDS, 32, app);

    // connect the scenegraph
    objTrans.addChild(sphere);
    objRoot.addChild(objTrans);

    m_FpsBehavior = new FpsBehavior();
    m_FpsBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_FpsBehavior);

    m_BoundsBehavior = new BoundsBehavior(sphere);
    m_BoundsBehavior.setSchedulingBounds(getApplicationBounds());
    m_BoundsBehavior.addBehaviorToParentGroup(objTrans);

    m_StretchBehavior = new StretchBehavior((GeometryArray) sphere.getShape().getGeometry());
    m_StretchBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_StretchBehavior);
    m_StretchBehavior.setEnable(false);

    m_SizeBehavior = new ObjectSizeBehavior((GeometryArray) sphere.getShape().getGeometry());
    m_SizeBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_SizeBehavior);
    m_SizeBehavior.setEnable(false);

    m_ExplodeBehavior = new ExplodeBehavior(sphere.getShape(), 10000, 20, this);
    m_ExplodeBehavior.setSchedulingBounds(getApplicationBounds());
    objRoot.addChild(m_ExplodeBehavior);

    return objRoot;
}

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);//w  ww.j ava 2s. co  m

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

/**
 * Constructs a Cuboid of a given dimension, flags, and appearance.
 * //from www.  j  av  a2  s  .  c o  m
 * @param xdim
 *            X-dimension size.
 * @param ydim
 *            Y-dimension size.
 * @param zdim
 *            Z-dimension size.
 * @param primflags
 *            primitive flags.
 * @param ap
 *            Appearance
 */

public Cuboid(float xdim, float ydim, float zdim, int primflags, Appearance ap) {
    int i;
    double sign;

    xDim = xdim;
    yDim = ydim;
    zDim = zdim;
    flags = primflags;

    //Depending on whether normal inward bit is set.
    if ((flags & GENERATE_NORMALS_INWARD) != 0)
        sign = -1.0;
    else
        sign = 1.0;

    TransformGroup objTrans = new TransformGroup();
    objTrans.setCapability(ALLOW_CHILDREN_READ);
    this.addChild(objTrans);

    Shape3D shape[] = new Shape3D[6];

    for (i = FRONT; i <= BOTTOM; i++) {
        OldGeomBuffer gbuf = new OldGeomBuffer(4);

        gbuf.begin(OldGeomBuffer.QUAD_STRIP);
        for (int j = 0; j < 2; j++) {
            gbuf.normal3d((double) normals[i].x * sign, (double) normals[i].y * sign,
                    (double) normals[i].z * sign);
            gbuf.texCoord2d(tcoords[i * 8 + j * 2], tcoords[i * 8 + j * 2 + 1]);
            gbuf.vertex3d((double) verts[i * 12 + j * 3] * xdim, (double) verts[i * 12 + j * 3 + 1] * ydim,
                    (double) verts[i * 12 + j * 3 + 2] * zdim);
        }
        for (int j = 3; j > 1; j--) {
            gbuf.normal3d((double) normals[i].x * sign, (double) normals[i].y * sign,
                    (double) normals[i].z * sign);
            gbuf.texCoord2d(tcoords[i * 8 + j * 2], tcoords[i * 8 + j * 2 + 1]);
            gbuf.vertex3d((double) verts[i * 12 + j * 3] * xdim, (double) verts[i * 12 + j * 3 + 1] * ydim,
                    (double) verts[i * 12 + j * 3 + 2] * zdim);
        }
        gbuf.end();
        shape[i] = new Shape3D(gbuf.getGeom(flags));
        numVerts = gbuf.getNumVerts();
        numTris = gbuf.getNumTris();

        if ((flags & ENABLE_APPEARANCE_MODIFY) != 0) {
            (shape[i]).setCapability(Shape3D.ALLOW_APPEARANCE_READ);
            (shape[i]).setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        }

        objTrans.addChild(shape[i]);
    }

    if (ap == null) {
        setAppearance();
    } else
        setAppearance(ap);
}

From source file:LightTest.java

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

    // create the 4 lights - the actual creation
    // and UI managment is delegated to an object
    // that "shadows" (no pun intended) the functionality
    // of the particular light
    createLight(new AmbientLightObject(), objRoot);
    createLight(new PointLightObject(), objRoot);
    createLight(new DirectionalLightObject(), objRoot);
    createLight(new SpotLightObject(), objRoot);

    // rotate some of the spheres in the scene
    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(getApplicationBounds());
    objTrans.addChild(rotator);/*w  w  w  .jav  a2  s .co m*/

    // create a large sphere in the center of the
    // scene and the floor as staionary objects
    objRoot.addChild(createSphere(0, 0, 0, 2));
    objRoot.addChild(createFloor());

    // create a smaller sphere at the corners of a cube
    final int nCubeSize = 3;
    objTrans.addChild(createSphere(nCubeSize, nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(nCubeSize, nCubeSize, -nCubeSize, 1));
    objTrans.addChild(createSphere(nCubeSize, -nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(nCubeSize, -nCubeSize, -nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, nCubeSize, -nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, nCubeSize, 1));
    objTrans.addChild(createSphere(-nCubeSize, -nCubeSize, -nCubeSize, 1));

    // add some small spheres here and there to
    // make things interesting
    objRoot.addChild(createSphere(-6, -6, 2, 1));
    objRoot.addChild(createSphere(8, -5, 3, 1));
    objRoot.addChild(createSphere(6, 7, -1, 1));
    objRoot.addChild(createSphere(-5, 6, -3.5f, 0.5f));

    objRoot.addChild(objTrans);

    return objRoot;
}

From source file:NodesTest.java

public CollisionBehavior(BranchGroup pickRoot, TransformGroup collisionObject, Appearance app,
        Vector3d posVector, Vector3d incVector) {
    // save references to the objects
    this.pickRoot = pickRoot;
    this.collisionObject = collisionObject;
    this.objectAppearance = app;

    incrementVector = incVector;/* w  w  w .j av a 2 s  .  c  o  m*/
    positionVector = posVector;

    // create the WakeupCriterion for the behavior
    WakeupCriterion criterionArray[] = new WakeupCriterion[1];
    criterionArray[0] = new WakeupOnElapsedFrames(ELAPSED_FRAME_COUNT);

    objectAppearance.setCapability(Appearance.ALLOW_MATERIAL_WRITE);

    collisionObject.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    collisionObject.setCapability(Node.ALLOW_BOUNDS_READ);

    // save the WakeupCriterion for the behavior
    m_WakeupCondition = new WakeupOr(criterionArray);
}

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  v a2  s.co 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:ViewProj.java

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

    // 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);
    objRoot.addChild(objTrans);//from  w w w.  j  a va  2 s. co  m

    // Create a Sphere. We will display this as both wireframe and
    // solid to make a hidden line display
    // wireframe
    Appearance wireApp = new Appearance();
    ColoringAttributes ca = new ColoringAttributes(black, ColoringAttributes.SHADE_FLAT);
    wireApp.setColoringAttributes(ca);
    wirePa = new PolygonAttributes(PolygonAttributes.POLYGON_LINE, PolygonAttributes.CULL_BACK, 0.0f);
    wireApp.setPolygonAttributes(wirePa);
    Sphere outWireSphere = new Sphere(sphereRadius, 0, 10, wireApp);
    objTrans.addChild(outWireSphere);

    // solid
    ColoringAttributes outCa = new ColoringAttributes(red, ColoringAttributes.SHADE_FLAT);
    Appearance outSolid = new Appearance();
    outSolid.setColoringAttributes(outCa);
    solidPa = new PolygonAttributes(PolygonAttributes.POLYGON_FILL, PolygonAttributes.CULL_BACK, 0.0f);
    solidPa.setPolygonOffsetFactor(dynamicOffset);
    solidPa.setPolygonOffset(staticOffset);
    solidPa.setCapability(PolygonAttributes.ALLOW_OFFSET_WRITE);
    outSolid.setPolygonAttributes(solidPa);
    Sphere outSolidSphere = new Sphere(sphereRadius, 0, 10, outSolid);
    objTrans.addChild(outSolidSphere);

    innerTG = new TransformGroup();
    innerTG.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
    scale = new Transform3D();
    updateInnerScale();
    objTrans.addChild(innerTG);

    // Create a smaller sphere to go inside. This sphere has a different
    // tesselation and color
    Sphere inWireSphere = new Sphere(sphereRadius, 0, 15, wireApp);
    innerTG.addChild(inWireSphere);

    // inside solid
    ColoringAttributes inCa = new ColoringAttributes(blue, ColoringAttributes.SHADE_FLAT);
    Appearance inSolid = new Appearance();
    inSolid.setColoringAttributes(inCa);
    inSolid.setPolygonAttributes(solidPa);
    Sphere inSolidSphere = new Sphere(sphereRadius, 0, 15, inSolid);
    innerTG.addChild(inSolidSphere);

    // Create a new Behavior object that will perform the desired
    // operation on the specified transform object and add it into
    // the scene graph.
    AxisAngle4f axisAngle = new AxisAngle4f(0.0f, 0.0f, 1.0f, -(float) Math.PI / 2.0f);
    Transform3D yAxis = new Transform3D();
    Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE, 0, 0, 80000, 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), 100.0);
    rotator.setSchedulingBounds(bounds);
    //objTrans.addChild(rotator);

    Background bgWhite = new Background(white);
    bgWhite.setApplicationBounds(bounds);
    objTrans.addChild(bgWhite);

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

    return objRoot;
}