block.numOfVertices = voxelCounter;
Vector3 center = basePosition;
double halfSize = pool.getLevel().getScale() * VoxelWorld.BLOCK_SIZE / 2.0;
center.addLocal(halfSize, halfSize, halfSize);
mesh.setModelBound(new BoundingBox(center, halfSize, halfSize, halfSize));
block.getVoxelNode().attachChild(mesh);
//////////GRASS///////////////////
if (pool.getLevel().getLevelID() == 0) {
int numOfGrasses = verticesWithGrass.size();
Mesh grassMesh = new Mesh();
MeshData grassMeshData = grassMesh.getMeshData();
FloatBuffer grassVertexBuffer = BufferUtils.createVector3Buffer(numOfGrasses * 4);
IntBuffer grassIndexBuffer = BufferUtils.createIntBuffer(numOfGrasses * 6);
FloatBuffer grassNormalBuffer = BufferUtils.createVector3Buffer(numOfGrasses * 4);
FloatBuffer grassTexCoordBuffer = BufferUtils.createVector2Buffer(numOfGrasses * 4);
//FloatBuffer grassBasePositionBuffer = BufferUtils.createVector2Buffer(numOfGrasses * 4);
for (int i=0, size = verticesWithGrass.size(); i<size; i++) {
int i3 = verticesWithGrass.get(i) * 3;
int i4 = i * 4;
float topY = 2.5f + (float) Math.random();
float bottomY = -0.1f;
float halfEidth = 1.5f + (float) Math.random();
//double alpha = Math.random()*Math.PI;
//float offsetX = (FastMath.sin(alpha) * halfEidth);
//float offsetZ = (float)(FastMath.cos(alpha) * halfEidth);
float offsetX = (float)Math.random()-0.5f;
float offsetZ = (float)Math.random()-0.5f;
grassVertexBuffer.put(vertexBuffer.get(i3 +0) + offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + bottomY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) + offsetZ);
grassVertexBuffer.put(vertexBuffer.get(i3 +0) + offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + topY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) + offsetZ);
grassVertexBuffer.put(vertexBuffer.get(i3 +0) + offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + topY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) + offsetZ);
grassVertexBuffer.put(vertexBuffer.get(i3 +0) + offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + bottomY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) + offsetZ);
/*grassVertexBuffer.put(vertexBuffer.get(i3 +0) + offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + bottomY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) + offsetZ);
grassVertexBuffer.put(vertexBuffer.get(i3 +0) + offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + topY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) + offsetZ);
grassVertexBuffer.put(vertexBuffer.get(i3 +0) - offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + topY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) - offsetZ);
grassVertexBuffer.put(vertexBuffer.get(i3 +0) - offsetX);
grassVertexBuffer.put(vertexBuffer.get(i3 +1) + bottomY);
grassVertexBuffer.put(vertexBuffer.get(i3 +2) - offsetZ);*/
float nx = normalBuffer.get(i3 +0);
float ny = normalBuffer.get(i3 +1);
float nz = normalBuffer.get(i3 +2);
grassNormalBuffer.put(nx);
grassNormalBuffer.put(ny);
grassNormalBuffer.put(nz);
grassNormalBuffer.put(nx);
grassNormalBuffer.put(ny);
grassNormalBuffer.put(nz);
grassNormalBuffer.put(nx);
grassNormalBuffer.put(ny);
grassNormalBuffer.put(nz);
grassNormalBuffer.put(nx);
grassNormalBuffer.put(ny);
grassNormalBuffer.put(nz);
grassTexCoordBuffer.put(0);
grassTexCoordBuffer.put(0);
grassTexCoordBuffer.put(0);
grassTexCoordBuffer.put(1);
grassTexCoordBuffer.put(1);
grassTexCoordBuffer.put(1);
grassTexCoordBuffer.put(1);
grassTexCoordBuffer.put(0);
grassIndexBuffer.put(i4);
grassIndexBuffer.put(i4+1);
grassIndexBuffer.put(i4+2);
grassIndexBuffer.put(i4);
grassIndexBuffer.put(i4+2);
grassIndexBuffer.put(i4+3);
}
//grassIndexBuffer.rewind();
//colorBuffer.flip();
grassMeshData.setVertexBuffer(grassVertexBuffer);
grassMeshData.setIndexBuffer(grassIndexBuffer);
grassMeshData.setNormalBuffer(grassNormalBuffer);
grassMeshData.setTextureBuffer(grassTexCoordBuffer,0);
grassMesh.setModelBound(new BoundingBox(center, halfSize, halfSize, halfSize));
block.getGrassNode().attachChild(grassMesh);
}