How can I change shape of a cube by change position of its vertices?

how can I change shape of a cube by change position of its vertices?

I want to move top face of cube down a little using the code but I can’t access it…

I expect to be able to access and modify the array that specifies the position of the vertices, in this way:
VertexBuffer bff = mesh.getBuffer(VertexBuffer.Type.Position);

Yes, grab the buffer and modify it. Which part is tripping you up?

Edit: note that you are probably better off just making your own mesh so that you know where everything is rather than trying to modify JME’s Box mesh directly. If JME ever chose to reorder its vertexes or something then that would mess you up.

Edit 2: also what do you mean by ‘move the top face down’? Do you mean shrink the cube in one direction or move the top face down but leave the sides intact and strange?

1 Like

I want to crush it from top to bottom. Something like crushing a soda can.

Then just call box.updateGeometry() with the new size and stuff.

1 Like

when we make a custom mesh pass a Vector3f array as vertices and use BufferUtils.create FloatBuffer.
so can I reversely convert Type.Position buffer of mesh to vector3 array?

I don’t know. But you can put floats into the FloatBuffer, etc…

But if you just want to crush a cube then when not use JME’s Box and call updateGeometry(min, max) or updateGeometry(center, x, y, z) to crush it? Then you don’t have to worry about it.

1 Like

why I can’t get the float array of vertices using FloatBuffer.array() method?
and it throws an exception:

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
	at java.nio.FloatBuffer.array(
	at mygame.Main.simpleInitApp(
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(

you can also just use MorphShape manually, but need add it in Blender first.

thats how i did lipsync

1 Like

Using my “javadoc super powers”:

…and then reading between the lines. It’s because a native FloatBuffer doesn’t have a backing float[] array.

Also, shuffling the buffer from FloatBuffer to float[] and back is going to be the least efficient way of updating the float buffer because you will have to copy the entire buffer to Java heap and then end up copying it all back again to native heap.

Better just to learn to deal with the FloatBuffer in the end.