Trouble with a custom mesh


I’ve a small problem with a custom mesh.

I use a library to read PLY files, and build a Mesh. I read the data, fill float array, give them to a new mesh. I can render the mesh, it works perfectly.

Now, in another part of my program, I need to access those buffer, read them, and change them. Trying to access the position buffer give me this:

Exception in thread "main"
java.lang.UnsupportedOperationException at

[java]VertexBuffer v = mesh.getBuffer(Type.Position);
Buffer b = v.getData();

This print false.

Any idea ?

More exactly:

[java]Mesh mesh = new Mesh();

mesh.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(points));

float[] array = (float[]) mesh.getBuffer(Type.Position).getData().array();[/java]

[java]Exception in thread "main" java.lang.UnsupportedOperationException

at java.nio.FloatBuffer.array(

at java.nio.FloatBuffer.array([/java]

What is wrong with that ?


float[] array() Returns the float array that backs this buffer (optional operation).

Note: the optional operation part.

Also: Invoke the hasArray method before invoking this method in order to ensure that this buffer has an accessible backing array.

The problem:

Direct buffers (ie: native buffers) do not support modifying the underlying array directly because it is native memory and not Java managed memory. You have to go through the float buffer interface.

Well, thank you sir ! :slight_smile: