Trouble with a custom mesh

Hi,



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.nio.FloatBuffer.array(FloatBuffer.java:957)


[java]VertexBuffer v = mesh.getBuffer(Type.Position);
Buffer b = v.getData();
System.out.println(b.hasArray());[/java]

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(FloatBuffer.java:957)

at java.nio.FloatBuffer.array(FloatBuffer.java:257)[/java]



What is wrong with that ?

From: http://docs.oracle.com/javase/1.5.0/docs/api/java/nio/FloatBuffer.html#array()

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: