Example usage for javax.media.j3d GeometryArray ALLOW_COORDINATE_WRITE

List of usage examples for javax.media.j3d GeometryArray ALLOW_COORDINATE_WRITE

Introduction

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

Prototype

int ALLOW_COORDINATE_WRITE

To view the source code for javax.media.j3d GeometryArray ALLOW_COORDINATE_WRITE.

Click Source Link

Document

Specifies that this GeometryArray allows writing the array of coordinates.

Usage

From source file:BehaviorTest.java

public WakeupCondition restart(Shape3D shape3D, int nElapsedTime, int nNumFrames, ExplosionListener listener) {
    System.out.println("Will explode after: " + nElapsedTime / 1000 + " secs.");

    m_Shape3D = shape3D;/*  w w  w  .j  a v  a  2 s.c  o m*/
    m_nElapsedTime = nElapsedTime;
    m_nNumFrames = nNumFrames;
    m_nFrameNumber = 0;

    // create the WakeupCriterion for the behavior
    m_InitialWakeupCondition = new WakeupOnElapsedTime(m_nElapsedTime);

    m_Listener = listener;

    // save the GeometryArray that we are modifying
    m_GeometryArray = (GeometryArray) m_Shape3D.getGeometry();

    if (m_Shape3D.isLive() == false && m_Shape3D.isCompiled() == false) {
        // set the capability bits that the behavior requires
        m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_READ);
        m_Shape3D.setCapability(Shape3D.ALLOW_APPEARANCE_WRITE);

        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POINT_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_POLYGON_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
        m_Shape3D.getAppearance().setCapability(Appearance.ALLOW_TEXTURE_WRITE);

        m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
        m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
        m_GeometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);
    }

    // make a copy of the object's original appearance
    m_Appearance = new Appearance();
    m_Appearance = (Appearance) m_Shape3D.getAppearance().cloneNodeComponent(true);

    // allocate an array for the model coordinates
    m_CoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];

    // make a copy of the models original coordinates
    m_OriginalCoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];
    m_GeometryArray.getCoordinates(0, m_OriginalCoordinateArray);

    // start (or restart) the behavior
    setEnable(true);

    return m_InitialWakeupCondition;
}

From source file:ExTexture.java

public QuadArray buildGeometry() {
    QuadArray cube = new QuadArray(24,
            GeometryArray.COORDINATES | GeometryArray.NORMALS | GeometryArray.TEXTURE_COORDINATE_2);
    cube.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
    cube.setCapability(GeometryArray.ALLOW_TEXCOORD_WRITE);

    VertexList vl = new VertexList(cube);

    float MAX = 1.0f;
    float MIN = 0.0f;

    //           Coordinate Normal Texture
    //             X Y Z I J K S T

    // Front/*  ww w. j  av a 2  s.co m*/
    vl.xyzijkst(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MIN, MIN);
    vl.xyzijkst(1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MAX, MIN);
    vl.xyzijkst(1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MAX, MAX);
    vl.xyzijkst(-1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, MIN, MAX);

    // Back
    vl.xyzijkst(1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MAX, MIN);
    vl.xyzijkst(-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MIN, MIN);
    vl.xyzijkst(-1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MIN, MAX);
    vl.xyzijkst(1.0f, 1.0f, -1.0f, 0.0f, 0.0f, -1.0f, MAX, MAX);

    // Right
    vl.xyzijkst(1.0f, -1.0f, 1.0f, 1.0f, 0.0f, 0.0f, MIN, MAX);
    vl.xyzijkst(1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, MIN, MIN);
    vl.xyzijkst(1.0f, 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, MAX, MIN);
    vl.xyzijkst(1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, MAX, MAX);

    // Left
    vl.xyzijkst(-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, MIN, MIN);
    vl.xyzijkst(-1.0f, -1.0f, 1.0f, -1.0f, 0.0f, 0.0f, MIN, MAX);
    vl.xyzijkst(-1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 0.0f, MAX, MAX);
    vl.xyzijkst(-1.0f, 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, MAX, MIN);

    // Top
    vl.xyzijkst(-1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, MIN, MAX);
    vl.xyzijkst(1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, MAX, MAX);
    vl.xyzijkst(1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, MAX, MIN);
    vl.xyzijkst(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, MIN, MIN);

    // Bottom
    vl.xyzijkst(-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, MIN, MIN);
    vl.xyzijkst(1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, MAX, MIN);
    vl.xyzijkst(1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, MAX, MAX);
    vl.xyzijkst(-1.0f, -1.0f, 1.0f, 0.0f, -1.0f, 0.0f, MIN, MAX);

    return cube;
}

From source file:BehaviorTest.java

public StretchBehavior(GeometryArray geomArray) {
    // save the GeometryArray that we are modifying
    m_GeometryArray = geomArray;/*from w w  w. j  a  va2  s . c  o  m*/

    // set the capability bits that the behavior requires
    m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_READ);
    m_GeometryArray.setCapability(GeometryArray.ALLOW_COORDINATE_WRITE);
    m_GeometryArray.setCapability(GeometryArray.ALLOW_COUNT_READ);

    // allocate an array for the model coordinates
    m_CoordinateArray = new float[3 * m_GeometryArray.getVertexCount()];

    // retrieve the models original coordinates - this defines
    // the relaxed length of the springs
    m_GeometryArray.getCoordinates(0, m_CoordinateArray);

    // allocate an array to store the relaxed length
    // of the springs from the origin to every vertex
    m_LengthArray = new float[m_GeometryArray.getVertexCount()];

    // allocate an array to store the mass of every vertex
    m_MassArray = new float[m_GeometryArray.getVertexCount()];

    // allocate an array to store the acceleration of every vertex
    m_AccelerationArray = new float[m_GeometryArray.getVertexCount()];

    // allocate a temporary vector
    m_Vector = new Vector3f();

    float x = 0;
    float y = 0;
    float z = 0;

    for (int n = 0; n < m_CoordinateArray.length; n += 3) {
        // calculate and store the relaxed spring length
        x = m_CoordinateArray[n];
        y = m_CoordinateArray[n + 1];
        z = m_CoordinateArray[n + 2];

        m_LengthArray[n / 3] = (x * x) + (y * y) + (z * z);

        // assign the mass for the vertex
        m_MassArray[n / 3] = (float) (50 + (5 * Math.random()));
    }

    // create the WakeupCriterion for the behavior
    WakeupCriterion criterionArray[] = new WakeupCriterion[2];
    criterionArray[0] = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
    criterionArray[1] = new WakeupOnElapsedFrames(1);

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