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(VertexBuffer.java:296)
at com.jme3.scene.Mesh.setBuffer(Mesh.java:497)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132)
at xref.XrefController$_closure2.doCall(XrefController.groovy:102)


What is the right way to do this?

Thanks,
Lee

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.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:custom_meshes

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.