Hi,
I’m trying to generate my own meshes as descried in the wiki (https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes)
For clarification: I want to generate VBOs for some more polygon heavy things, therefore i plan to have a global direct FloatBuffer sitting around and every once in a while use that buffer to calculate a new mesh which gets transformed into an interleafed VBO so it should be possible to reuse the FloatBuffer afterwards.
And while this works for the case:
[java]mesh.setBuffer(Type.Position, 3, new float[]{0,0,0, 0,1,0, 1,1,0, 1,0,0}); [/java]
I’m not able to make it work when passing a FloatBuffer. One thing i believe to be a problem and a bug is the fact, that for calculating the amount of faces/vertices the buffers capacity is used instead of some other value (e.g. buffer.limit).
[java] vPos=ByteBuffer.allocateDirect(9000).asFloatBuffer();
vPos.put(new float[] {0,0,0, 0,1,0, 1,1,0, 1,0,0});
//…
vPos.rewind();
//…
vPos.limit(4*3);
//…
Mesh m = new Mesh();
m.setBuffer(Type.Position, 3, vPos);
[/java]
Will result in a mesh with a few thousand polygons.
is this a bug, or am i missing something?
Its a special buffer, create it with the utility like in the examples
Thanks, this did indeed solve some of the problems (i didn’t even mention^^), but the problem of way to many triangle becoming added when the buffer is bigger then the amount of data in it
[java]
//…
vPos=BufferUtils.createFloatBuffer(maxNumVerts3);
vNormal=BufferUtils.createFloatBuffer(maxNumVerts3);
fIndex=BufferUtils.createIntBuffer(maxNumFaces23);
//…
public static Mesh generateChunk(BlockWorld world, Vector3i chunkPos){
vPos.rewind();
vNormal.rewind();
vTexCoord.rewind();
fIndex.rewind();
vPos.put(new float[] {0,0,0, 0,1,0, 1,1,0, 1,0,0});
vNormal.put(new float[] {0,0,-1, 0,0,-1, 0,0,-1, 0,0,-1});
fIndex.put(new int[]{0,2,1, 0,3,2});
Mesh m = new Mesh();
vPos.flip();
vNormal.flip();
vTexCoord.flip();
fIndex.flip();
m.setBuffer(Type.Position, 3, vPos);
m.setBuffer(Type.Normal, 3, vNormal);
m.setBuffer(Type.Index, 1, fIndex);
m.setMode(Mesh.Mode.LineLoop);
m.setPointSize(2f);
m.updateBound();
m.setStatic();
return m;
[/java]
which will result in a single quad being rendered with som 100K points (which corresponds to the max number that can in theory be generated)
is there a better way to do this?