Example usage for javax.media.j3d Appearance ALLOW_TEXTURE_UNIT_STATE_WRITE

List of usage examples for javax.media.j3d Appearance ALLOW_TEXTURE_UNIT_STATE_WRITE

Introduction

In this page you can find the example usage for javax.media.j3d Appearance ALLOW_TEXTURE_UNIT_STATE_WRITE.

Prototype

int ALLOW_TEXTURE_UNIT_STATE_WRITE

To view the source code for javax.media.j3d Appearance ALLOW_TEXTURE_UNIT_STATE_WRITE.

Click Source Link

Document

Specifies that this Appearance object allows writing its texture unit state component information.

Usage

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);/*w ww . j  a  v  a2  s.c o  m*/
    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:InterleavedNIOBuffer.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  w w  . j a  va 2  s.  co  m
    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);

    createInterleavedBuffers();

    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;
}