Search in sources :

Example 51 with IntBuffer

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

the class BinaryInputCapsule method readIntBuffer.

// int buffer
protected IntBuffer readIntBuffer(byte[] content) throws IOException {
    int length = readInt(content);
    if (length == BinaryOutputCapsule.NULL_OBJECT)
        return null;
    if (BinaryImporter.canUseFastBuffers()) {
        ByteBuffer value = BufferUtils.createByteBuffer(length * 4);
        value.put(content, index, length * 4).rewind();
        index += length * 4;
        return value.asIntBuffer();
    } else {
        IntBuffer value = BufferUtils.createIntBuffer(length);
        for (int x = 0; x < length; x++) {
            value.put(readIntForBuffer(content));
        }
        value.rewind();
        return value;
    }
}
Also used : IntBuffer(java.nio.IntBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 52 with IntBuffer

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

the class LwjglALC method createALC.

public void createALC() {
    device = ALC10.alcOpenDevice((ByteBuffer) null);
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    context = ALC10.alcCreateContext(device, (IntBuffer) null);
    ALC10.alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
Also used : ALCCapabilities(org.lwjgl.openal.ALCCapabilities) IntBuffer(java.nio.IntBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 53 with IntBuffer

use of java.nio.IntBuffer 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 54 with IntBuffer

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

the class TerrainPatch method generateLodEntropies.

/**
     * This calculation is slow, so don't use it often.
     */
public void generateLodEntropies() {
    float[] entropies = new float[getMaxLod() + 1];
    for (int i = 0; i <= getMaxLod(); i++) {
        int curLod = (int) Math.pow(2, i);
        IndexBuffer idxB = geomap.writeIndexArrayLodDiff(curLod, false, false, false, false, totalSize);
        Buffer ib;
        if (idxB.getBuffer() instanceof IntBuffer)
            ib = (IntBuffer) idxB.getBuffer();
        else
            ib = (ShortBuffer) idxB.getBuffer();
        entropies[i] = EntropyComputeUtil.computeLodEntropy(mesh, ib);
    }
    lodEntropy = entropies;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) VertexBuffer(com.jme3.scene.VertexBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IntBuffer(java.nio.IntBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 55 with IntBuffer

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

the class EntropyComputeUtil method computeLodEntropy.

public static float computeLodEntropy(Mesh terrainBlock, Buffer lodIndices) {
    // Bounding box for the terrain block
    BoundingBox bbox = (BoundingBox) terrainBlock.getBound();
    // Vertex positions for the block
    FloatBuffer positions = terrainBlock.getFloatBuffer(Type.Position);
    // Prepare to cast rays
    Vector3f pos = new Vector3f();
    Vector3f dir = new Vector3f(0, -1, 0);
    Ray ray = new Ray(pos, dir);
    // Prepare collision results
    CollisionResults results = new CollisionResults();
    // Set the LOD indices on the block
    VertexBuffer originalIndices = terrainBlock.getBuffer(Type.Index);
    terrainBlock.clearBuffer(Type.Index);
    if (lodIndices instanceof IntBuffer)
        terrainBlock.setBuffer(Type.Index, 3, (IntBuffer) lodIndices);
    else if (lodIndices instanceof ShortBuffer) {
        terrainBlock.setBuffer(Type.Index, 3, (ShortBuffer) lodIndices);
    }
    // Recalculate collision mesh
    terrainBlock.createCollisionData();
    float entropy = 0;
    for (int i = 0; i < positions.limit() / 3; i++) {
        BufferUtils.populateFromBuffer(pos, positions, i);
        float realHeight = pos.y;
        pos.addLocal(0, bbox.getYExtent(), 0);
        ray.setOrigin(pos);
        results.clear();
        terrainBlock.collideWith(ray, Matrix4f.IDENTITY, bbox, results);
        if (results.size() > 0) {
            Vector3f contactPoint = results.getClosestCollision().getContactPoint();
            float delta = Math.abs(realHeight - contactPoint.y);
            entropy = Math.max(delta, entropy);
        }
    }
    // Restore original indices
    terrainBlock.clearBuffer(Type.Index);
    terrainBlock.setBuffer(originalIndices);
    return entropy;
}
Also used : CollisionResults(com.jme3.collision.CollisionResults) VertexBuffer(com.jme3.scene.VertexBuffer) BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) IntBuffer(java.nio.IntBuffer) FloatBuffer(java.nio.FloatBuffer) Ray(com.jme3.math.Ray) ShortBuffer(java.nio.ShortBuffer)

Aggregations

IntBuffer (java.nio.IntBuffer)286 ByteBuffer (java.nio.ByteBuffer)97 FloatBuffer (java.nio.FloatBuffer)47 ShortBuffer (java.nio.ShortBuffer)36 Test (org.junit.Test)35 Bitmap (android.graphics.Bitmap)18 DoubleBuffer (java.nio.DoubleBuffer)18 IOException (java.io.IOException)14 BaseTest (org.apache.jena.atlas.junit.BaseTest)14 FileOutputStream (java.io.FileOutputStream)13 CharBuffer (java.nio.CharBuffer)11 LongBuffer (java.nio.LongBuffer)11 UTF8CodePointDecoder (org.antlr.v4.runtime.UTF8CodePointDecoder)11 ArrayList (java.util.ArrayList)10 File (java.io.File)9 Buffer (java.nio.Buffer)9 VertexBuffer (com.jme3.scene.VertexBuffer)7 IndexBuffer (com.jme3.scene.mesh.IndexBuffer)6 BufferOverflowException (java.nio.BufferOverflowException)6 FileChannel (java.nio.channels.FileChannel)6