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;
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations