Search in sources :

Example 26 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 27 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 28 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)

Example 29 with IntBuffer

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

the class LODGeomap method createMesh.

public Mesh createMesh(Vector3f scale, Vector2f tcScale, Vector2f tcOffset, float offsetAmount, int totalSize, boolean center, int lod, boolean rightLod, boolean topLod, boolean leftLod, boolean bottomLod) {
    FloatBuffer pb = writeVertexArray(null, scale, center);
    FloatBuffer texb = writeTexCoordArray(null, tcOffset, tcScale, offsetAmount, totalSize);
    FloatBuffer nb = writeNormalArray(null, scale);
    Buffer ib;
    IndexBuffer idxB = writeIndexArrayLodDiff(lod, rightLod, topLod, leftLod, bottomLod, totalSize);
    if (idxB.getBuffer() instanceof IntBuffer)
        ib = (IntBuffer) idxB.getBuffer();
    else
        ib = (ShortBuffer) idxB.getBuffer();
    FloatBuffer bb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    FloatBuffer tanb = BufferUtils.createFloatBuffer(getWidth() * getHeight() * 3);
    writeTangentArray(nb, tanb, bb, texb, scale);
    Mesh m = new Mesh();
    m.setMode(Mode.TriangleStrip);
    m.setBuffer(Type.Position, 3, pb);
    m.setBuffer(Type.Normal, 3, nb);
    m.setBuffer(Type.Tangent, 3, tanb);
    m.setBuffer(Type.Binormal, 3, bb);
    m.setBuffer(Type.TexCoord, 2, texb);
    if (ib instanceof IntBuffer)
        m.setBuffer(Type.Index, 3, (IntBuffer) ib);
    else if (ib instanceof ShortBuffer)
        m.setBuffer(Type.Index, 3, (ShortBuffer) ib);
    m.setStatic();
    m.updateBound();
    return m;
}
Also used : FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IntBuffer(java.nio.IntBuffer) Buffer(java.nio.Buffer) IndexBuffer(com.jme3.scene.mesh.IndexBuffer) IntBuffer(java.nio.IntBuffer) Mesh(com.jme3.scene.Mesh) FloatBuffer(java.nio.FloatBuffer) ShortBuffer(java.nio.ShortBuffer)

Example 30 with IntBuffer

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

the class GeoMap method createMesh.

public Mesh createMesh(Vector3f scale, Vector2f tcScale, boolean center) {
    FloatBuffer pb = writeVertexArray(null, scale, center);
    FloatBuffer tb = writeTexCoordArray(null, Vector2f.ZERO, tcScale);
    FloatBuffer nb = writeNormalArray(null, scale);
    IntBuffer ib = writeIndexArray(null);
    Mesh m = new Mesh();
    m.setBuffer(Type.Position, 3, pb);
    m.setBuffer(Type.Normal, 3, nb);
    m.setBuffer(Type.TexCoord, 2, tb);
    m.setBuffer(Type.Index, 3, ib);
    m.setStatic();
    m.updateBound();
    return m;
}
Also used : IntBuffer(java.nio.IntBuffer) Mesh(com.jme3.scene.Mesh) FloatBuffer(java.nio.FloatBuffer)

Aggregations

IntBuffer (java.nio.IntBuffer)283 ByteBuffer (java.nio.ByteBuffer)95 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