Search in sources :

Example 56 with FloatBuffer

use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.

the class TestTangentGen method createTriangleStripMesh.

private Mesh createTriangleStripMesh() {
    Mesh strip = new Mesh();
    strip.setMode(Mode.TriangleStrip);
    // 3 rows * 3 columns * 3 floats
    FloatBuffer vb = BufferUtils.createFloatBuffer(3 * 3 * 3);
    vb.rewind();
    vb.put(new float[] { 0, 2, 0 });
    vb.put(new float[] { 1, 2, 0 });
    vb.put(new float[] { 2, 2, 0 });
    vb.put(new float[] { 0, 1, 0 });
    vb.put(new float[] { 1, 1, 0 });
    vb.put(new float[] { 2, 1, 0 });
    vb.put(new float[] { 0, 0, 0 });
    vb.put(new float[] { 1, 0, 0 });
    vb.put(new float[] { 2, 0, 0 });
    FloatBuffer nb = BufferUtils.createFloatBuffer(3 * 3 * 3);
    nb.rewind();
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    nb.put(new float[] { 0, 0, 1 });
    FloatBuffer tb = BufferUtils.createFloatBuffer(3 * 3 * 2);
    tb.rewind();
    tb.put(new float[] { 0, 0 });
    tb.put(new float[] { 0.5f, 0 });
    tb.put(new float[] { 1, 0 });
    tb.put(new float[] { 0, 0.5f });
    tb.put(new float[] { 0.5f, 0.5f });
    tb.put(new float[] { 1, 0.5f });
    tb.put(new float[] { 0, 1 });
    tb.put(new float[] { 0.5f, 1 });
    tb.put(new float[] { 1, 1 });
    int[] indexes = new int[] { 0, 3, 1, 4, 2, 5, 5, 3, 3, 6, 4, 7, 5, 8 };
    IntBuffer ib = BufferUtils.createIntBuffer(indexes.length);
    ib.put(indexes);
    strip.setBuffer(Type.Position, 3, vb);
    strip.setBuffer(Type.Normal, 3, nb);
    strip.setBuffer(Type.TexCoord, 2, tb);
    strip.setBuffer(Type.Index, 3, ib);
    strip.updateBound();
    return strip;
}
Also used : IntBuffer(java.nio.IntBuffer) Mesh(com.jme3.scene.Mesh) FloatBuffer(java.nio.FloatBuffer)

Example 57 with FloatBuffer

use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.

the class FilteredBasis method clip.

public FloatBuffer clip(FloatBuffer buf, int origSize, int newSize, int offset) {
    FloatBuffer result = FloatBuffer.allocate(newSize * newSize);
    float[] orig = buf.array();
    for (int i = offset; i < offset + newSize; i++) {
        result.put(orig, i * origSize + offset, newSize);
    }
    return result;
}
Also used : FloatBuffer(java.nio.FloatBuffer)

Example 58 with FloatBuffer

use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.

the class AbstractFilter method doFilter.

@Override
public FloatBuffer doFilter(float sx, float sy, float base, FloatBuffer data, int size) {
    if (!this.isEnabled()) {
        return data;
    }
    FloatBuffer retval = data;
    for (Filter f : this.preFilters) {
        retval = f.doFilter(sx, sy, base, retval, size);
    }
    retval = this.filter(sx, sy, base, retval, size);
    for (Filter f : this.postFilters) {
        retval = f.doFilter(sx, sy, base, retval, size);
    }
    return retval;
}
Also used : Filter(com.jme3.terrain.noise.Filter) FloatBuffer(java.nio.FloatBuffer)

Example 59 with FloatBuffer

use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.

the class OSVR method getHMDMatrixProjectionLeftEye.

@Override
public Matrix4f getHMDMatrixProjectionLeftEye(Camera cam) {
    if (eyeLeftInfo == null)
        return cam.getProjectionMatrix();
    if (eyeMatrix[EYE_LEFT] == null) {
        FloatBuffer tfb = FloatBuffer.allocate(16);
        com.jme3.system.osvr.osvrdisplay.OsvrDisplayLibrary.osvrClientGetViewerEyeSurfaceProjectionMatrixf(displayConfig, 0, (byte) EYE_LEFT, 0, cam.getFrustumNear(), cam.getFrustumFar(), (short) 0, tfb);
        eyeMatrix[EYE_LEFT] = new Matrix4f();
        eyeMatrix[EYE_LEFT].set(tfb.get(0), tfb.get(4), tfb.get(8), tfb.get(12), tfb.get(1), tfb.get(5), tfb.get(9), tfb.get(13), tfb.get(2), tfb.get(6), tfb.get(10), tfb.get(14), tfb.get(3), tfb.get(7), tfb.get(11), tfb.get(15));
    }
    return eyeMatrix[EYE_LEFT];
}
Also used : Matrix4f(com.jme3.math.Matrix4f) FloatBuffer(java.nio.FloatBuffer)

Example 60 with FloatBuffer

use of java.nio.FloatBuffer in project jmonkeyengine by jMonkeyEngine.

the class TerrainPatch method setHeight.

protected void setHeight(List<LocationHeight> locationHeights, boolean overrideHeight) {
    final float[] heightArray = geomap.getHeightArray();
    final VertexBuffer vertexBuffer = mesh.getBuffer(Type.Position);
    final FloatBuffer floatBuffer = mesh.getFloatBuffer(Type.Position);
    for (LocationHeight lh : locationHeights) {
        if (lh.x < 0 || lh.z < 0 || lh.x >= size || lh.z >= size) {
            continue;
        }
        int idx = lh.z * size + lh.x;
        if (overrideHeight) {
            heightArray[idx] = lh.h;
        } else {
            float currentHeight = floatBuffer.get(idx * 3 + 1);
            heightArray[idx] = currentHeight + lh.h;
        }
    }
    floatBuffer.clear();
    geomap.writeVertexArray(floatBuffer, stepScale, false);
    vertexBuffer.setUpdateNeeded();
}
Also used : LocationHeight(com.jme3.terrain.geomipmap.TerrainQuad.LocationHeight) VertexBuffer(com.jme3.scene.VertexBuffer) FloatBuffer(java.nio.FloatBuffer)

Aggregations

FloatBuffer (java.nio.FloatBuffer)291 ByteBuffer (java.nio.ByteBuffer)82 IntBuffer (java.nio.IntBuffer)43 ShortBuffer (java.nio.ShortBuffer)39 Vector3f (com.jme3.math.Vector3f)27 VertexBuffer (com.jme3.scene.VertexBuffer)27 DoubleBuffer (java.nio.DoubleBuffer)17 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)16 LongBuffer (java.nio.LongBuffer)10 Mesh (com.jme3.scene.Mesh)9 CharBuffer (java.nio.CharBuffer)9 FrameBuffer2D (androidx.media.filterfw.FrameBuffer2D)8 OutputPort (androidx.media.filterfw.OutputPort)7 Matrix4f (com.jme3.math.Matrix4f)7 Buffer (java.nio.Buffer)7 TempVars (com.jme3.util.TempVars)6 IOException (java.io.IOException)6 BufferOverflowException (java.nio.BufferOverflowException)6 BufferUnderflowException (java.nio.BufferUnderflowException)6 ArrayList (java.util.ArrayList)6