How can I convert an ArrayList<Vector3f> to a ByteBuffer?
I'm trying to create a TriangleIndexVertexArray with JBullet, but to do this I need to parse a ByteBuffer of all the vertices in the model.
I have got an ArrayList<Vector3f> of all the vertices in the model.
How can I parse this list of Vector3f's to a ByteBuffer?
You can do it as follow
Declaring your vertices
ArrayList<Vector3f> verticesnew = new ArrayList<Vector3f>();
Set your vertices
vertices.add( new Vector3f(someVertice) );
Get Float buffer from vertices:
// There are 3 floats needed for each vertex (x,y,z) int bufferSize = vertices.size() * 3 * Float.SIZE; FloatBuffer verticesBuffer = ByteBuffer.allocateDirect( bufferSize ).order( ByteOrder.nativeOrder() ).asFloatBuffer(); // Copy the values from the list to the direct float buffer for ( Vector3f v : vertices ) verticesBuffer.put( v.x ).put( v.y ).put( v.z );