Adding on to a mesh

I’d like to create a mesh that grows over time, something like a time-lapse animation of a knitted blanket. I can’t pre-create it and reveal it, because the data is dynamic. I have to add on in real time.

When I tried to add on to the mesh, I got an error on this line:

[java]m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));[/java]

Partial stacktrace:

java.lang.UnsupportedOperationException: Data has already been sent. Cannot setupData again.
at com.jme3.scene.VertexBuffer.setupData(
at com.jme3.scene.Mesh.setBuffer(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(
at xref.XrefController$_closure2.doCall(XrefController.groovy:102)

What is the right way to do this?


Just use setScale(float scale); ???

Sorry that was unclear. When I said “grow,” I didn’t mean the mesh scales up. I meant I want to add new vertices to the mesh. So I’m looking for a way to add on to the mesh.

Yep, I’ve seen that, but it doesn’t address my question.

How do I update a mesh? Or is there no way to update it?

Do I have to detach the existing one and rebuild/attach a new one from scratch each time I add new vertices?

Use updateData instead of setupData/setBuffer.