Example usage for javax.media.j3d Shape3D ALLOW_GEOMETRY_WRITE

List of usage examples for javax.media.j3d Shape3D ALLOW_GEOMETRY_WRITE

Introduction

In this page you can find the example usage for javax.media.j3d Shape3D ALLOW_GEOMETRY_WRITE.

Prototype

int ALLOW_GEOMETRY_WRITE

To view the source code for javax.media.j3d Shape3D ALLOW_GEOMETRY_WRITE.

Click Source Link

Document

Specifies that the node allows write access to its geometry information.

Usage

From source file:ExText.java

public Group buildScene() {
    // Get the current font attributes
    Font font = (Font) fonts[currentFont].value;
    String textString = (String) fonts[currentFont].name;

    // Turn on the example headlight
    setHeadlightEnable(true);//w  w  w  .j a  v a 2 s  .c om

    // Build the scene group
    scene = new Group();
    scene.setCapability(Group.ALLOW_CHILDREN_EXTEND);
    scene.setCapability(Group.ALLOW_CHILDREN_WRITE);

    // Build a branch group to hold the text shape
    // (this allows us to remove the text shape later,
    // change it, then put it back, all under menu control)
    textGroup = new BranchGroup();
    textGroup.setCapability(BranchGroup.ALLOW_DETACH);
    scene.addChild(textGroup);

    // BEGIN EXAMPLE TOPIC
    // Create a font extrusion with a default extrusion shape
    extrusion = new FontExtrusion();

    // Define a 3D font with a default extrusion path
    Font3D font3d = new Font3D(font, extrusion);

    // Build 3D text geometry using the 3D font
    Text3D tex = new Text3D();
    tex.setFont3D(font3d);
    tex.setString(textString);
    tex.setAlignment(Text3D.ALIGN_CENTER);

    // Define a generic shaded appearance
    Appearance app = new Appearance();
    Material mat = new Material();
    mat.setLightingEnable(true);
    app.setMaterial(mat);

    // Assemble geometry and appearance into a shape
    // and add it to the scene
    shape = new Shape3D(tex, app);
    shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    textGroup.addChild(shape);
    // END EXAMPLE TOPIC

    return scene;
}

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);/*from w  w  w. j a v a2s.com*/
    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:GeometryByReferenceNIOBuffer.java

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

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

    transp = new TransparencyAttributes();
    transp.setTransparency(0.5f);//from w  w  w  .ja  v a  2s . com
    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: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  w w .  ja  va  2s  .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);/* w ww  . j  av a  2s  . 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);

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

From source file:ExBackgroundImage.java

private void rebuild() {
    // Build a shape
    if (shape == null) {
        shape = new Shape3D();
        shape.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
        shape.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
        shape.setAppearance(mainAppearance);
        addChild(shape);/*from  w w  w .  j a  v  a2  s .c  o m*/
    } else {
        shape.setAppearance(mainAppearance);
    }

    if (xDimension < 2 || zDimension < 2 || heights == null || heights.length < 4) {
        tristrip = null;
        shape.setGeometry(null);
        return;
    }

    // Create a list of coordinates, one per grid row/column
    double[] coordinates = new double[xDimension * zDimension * 3];
    double x, z;
    int n = 0, k = 0;
    z = ((double) (zDimension - 1)) * zSpacing / 2.0; // start at front edge
    for (int i = 0; i < zDimension; i++) {
        x = -((double) (xDimension - 1)) * xSpacing / 2.0;// start at left
        // edge
        for (int j = 0; j < xDimension; j++) {
            coordinates[n++] = x;
            coordinates[n++] = heights[k++];
            coordinates[n++] = z;
            x += xSpacing;
        }
        z -= zSpacing;
    }

    // Create a list of normals, one per grid row/column
    float[] normals = new float[xDimension * zDimension * 3];
    Vector3f one = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f two = new Vector3f(0.0f, 0.0f, 0.0f);
    Vector3f norm = new Vector3f(0.0f, 0.0f, 0.0f);
    n = 0;
    k = 0;
    for (int i = 0; i < zDimension - 1; i++) {
        for (int j = 0; j < xDimension - 1; j++) {
            // Vector to right in X
            one.set((float) xSpacing, (float) (heights[k + 1] - heights[k]), 0.0f);

            // Vector back in Z
            two.set(0.0f, (float) (heights[k + xDimension] - heights[k]), (float) -zSpacing);

            // Cross them to get the normal
            norm.cross(one, two);
            normals[n++] = norm.x;
            normals[n++] = norm.y;
            normals[n++] = norm.z;
            k++;
        }

        // Last normal in row is a copy of the previous one
        normals[n] = normals[n - 3]; // X
        normals[n + 1] = normals[n - 2]; // Y
        normals[n + 2] = normals[n - 1]; // Z
        n += 3;
        k++;
    }

    // Last row of normals is a copy of the previous row
    for (int j = 0; j < xDimension; j++) {
        normals[n] = normals[n - xDimension * 3]; // X
        normals[n + 1] = normals[n - xDimension * 3 + 1]; // Y
        normals[n + 2] = normals[n - xDimension * 3 + 2]; // Z
        n += 3;
    }

    // Create a list of texture coordinates, one per grid row/column
    float[] texcoordinates = new float[xDimension * zDimension * 2];
    float deltaS = 1.0f / (float) (xDimension - 1);
    float deltaT = 1.0f / (float) (zDimension - 1);
    float s = 0.0f;
    float t = 0.0f;
    n = 0;
    for (int i = 0; i < zDimension; i++) {
        s = 0.0f;
        for (int j = 0; j < xDimension; j++) {
            texcoordinates[n++] = s;
            texcoordinates[n++] = t;
            s += deltaS;
        }
        t += deltaT;
    }

    // Create a list of triangle strip indexes. Each strip goes
    // down one row (X direction) of the elevation grid.
    int[] indexes = new int[xDimension * (zDimension - 1) * 2];
    int[] stripCounts = new int[zDimension - 1];
    n = 0;
    k = 0;
    for (int i = 0; i < zDimension - 1; i++) {
        stripCounts[i] = xDimension * 2;
        for (int j = 0; j < xDimension; j++) {
            indexes[n++] = k + xDimension;
            indexes[n++] = k;
            k++;
        }
    }

    // Create geometry for collection of triangle strips, one
    // strip per row of the elevation grid
    tristrip = new IndexedTriangleStripArray(coordinates.length,
            GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2,
            indexes.length, stripCounts);
    tristrip.setCoordinates(0, coordinates);
    tristrip.setNormals(0, normals);
    tristrip.setTextureCoordinates(0, texcoordinates);
    tristrip.setCoordinateIndices(0, indexes);
    tristrip.setNormalIndices(0, indexes);
    tristrip.setTextureCoordinateIndices(0, indexes);

    // Set the geometry for the shape
    shape.setGeometry(tristrip);
}

From source file:TextureByReference.java

public Tetrahedron(boolean byRef) {
    if (byRef) {//  w w w.  j  av a  2  s . c  o  m
        createGeometryByRef();
        this.setGeometry(geometryByRef);
    } else {
        createGeometryByCopy();
        this.setGeometry(geometryByCopy);
    }
    this.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    this.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    setAppearance(new Appearance());
}

From source file:FourByFour.java

public Cube(Appearance appearance) {

    QuadArray quadArray = new QuadArray(24,
            QuadArray.COORDINATES | QuadArray.NORMALS | QuadArray.TEXTURE_COORDINATE_2);
    quadArray.setCoordinates(0, verts);//  ww  w  .  ja  va  2 s .  com
    quadArray.setNormals(0, normals);

    shape3D = new Shape3D(quadArray, appearance);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}

From source file:FourByFour.java

public Cube(Appearance appearance, float size) {

    QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS);
    for (int i = 0; i < 72; i++)
        verts[i] *= size;//from  w  w  w  . j ava 2  s.  co m

    quadArray.setCoordinates(0, verts);
    quadArray.setNormals(0, normals);

    shape3D = new Shape3D(quadArray, appearance);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}

From source file:FourByFour.java

public BigCube(Appearance appearance) {

    QuadArray quadArray = new QuadArray(24, QuadArray.COORDINATES | QuadArray.NORMALS);
    quadArray.setCoordinates(0, verts);//from  w  w w. j ava  2  s .  c  o m
    quadArray.setNormals(0, normals);

    shape3D = new Shape3D(quadArray, appearance);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_READ);
    shape3D.setCapability(Shape3D.ALLOW_GEOMETRY_WRITE);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
    shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);
}