Example usage for javax.media.j3d Shape3D Shape3D

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

Introduction

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

Prototype

public Shape3D(Geometry geometry) 

Source Link

Document

Constructs and initializes a Shape3D node with the specified geometry component and a null appearance component.

Usage

From source file:CuboidTest.java

/**
 * Constructs a Cuboid of a given dimension, flags, and appearance.
 * /*from   w  ww. j  a v  a  2s.  co 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);
}