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?

Answers


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

Need Your Help

What should I put in the target directory?

java maven maven-plugin

I'm making a Maven plugin. I use another library that downloads files and put them in a directory if they don't exist, of if they are too old, then my code use the files.

How to decode TripleDESCryptoService string in php?

php vb.net tripledes

the following code decrypts a string in VB: