Getting VertexBuffer info

Hello. I am attempting to port some terrain code to JME3 for speed benchmark purposes. However, I have run into a roadblock.



I want to get specific info out of the buffer



In jme2 I would just say



FloatBuffer f = mesh.getVertexBuffer();

and then to get my info I would just say

f.get(9); for example



now with the VertexBuffer object, I do not know how to get, say, position 9.

Namely, there is no get() function. How would I do this in JME3?



Thank you!

VertexBuffer index = mesh.getBuffer(Type.Position);

Sorry I prematurely hit 'Post' :stuck_out_tongue:

Um, I think you can use 'buffer.copyElement()'. Looking at the code I don't see an easy way. Maybe I will add something in for that tonight and submit a patch

After you get the VertexBuffer, just use the getData() method and cast it to a float buffer.

Position buffers will almost always be floatbuffers so you don't need to worry about it being a different type.

mesh.setBuffer(Type.Index,int,intbuffer);



makes JVM crash, does anyone else get this error?

Well I would say you cause an error in the opengl driver if you put wrong values there.

in basic it works, else we wouldn't be able to see anything at all.

Eggsworth said:

mesh.setBuffer(Type.Index,int,intbuffer);

makes JVM crash, does anyone else get this error?

If you get a JVM crash, it probably means you have a bad driver or something.
What kind of values are you putting in there anyway? I can imagine something like "-1" could crash a driver if it doesn't validate the data.

heh guys sorry, the JVM Crash was user error on my part.



What happened was I didnt understand the Component aspect of that function. It was my belief that that argument was equal to the number of entries in your buffer, when in reality it was meant to be the length of each "unit" hence the number of components per unit. So it thought my entire buffer was one unit long with thousands of components per unit.



Anyways, its fixed now, false alarm :slight_smile:



Also, casting to the floatbuffer from a buffer object worked perfectly, thanks for the help.

Momoko_Fan said:

After you get the VertexBuffer, just use the getData() method and cast it to a float buffer.
Position buffers will almost always be floatbuffers so you don't need to worry about it being a different type.

by the way this was very helpful information, which wasn't covered in any tutorial, but is necessary almost in every case when you deal with geometry.

Later on I will try to make a HelloMesh tutorial for JME3 so to cover this gap :)
Kay said:

Later on I will try to make a HelloMesh tutorial for JME3 so to cover this gap :)

Thats the spirit :)

Indeed, this piece of wisdom has to be in the docs. Very helpful.