Is there a way to dynamically update a mesh, and have the change show up in the scene graph without detaching/re-attaching it? I am using the updateModelBound calls on the mesh, and it’s parent geometry, but the rendered version does not change without re-attaching. I do not want chunks of terrain to disappear/reappear like I have it working now.
Of course you can dynamically update a mesh. See JME’s Quad for example where you can update it without issue.
So there must be something else wrong with your code. I update meshes all the time.
I figured it was possible. Can you point me at some sample code for doing that?
Create a BasicGame project.
Use this method to alter the blue box’s size on update or something: http://hub.jmonkeyengine.org/javadoc/com/jme3/scene/shape/AbstractBox.html#updateGeometry(com.jme3.math.Vector3f,%20float,%20float,%20float)
See it work or post the code here so we can show you what’s missing.
I took a look at the source for the Quad class.
updateGeometry updates the underlying buffers, and the calls updateBound.
In my case, I do not use JME shapes, and instead build custom meshes.
@adrian-maggio said: I took a look at the source for the Quad class. updateGeometry updates the underlying buffers, and the calls updateBound.In my case, I do not use JME shapes, and instead build custom meshes.
It does not matter. Updating the mesh is the same.
What I meant to add to my post is that I am doing essentially the same thing as the updateGeometry method is, to my custom meshes.
I’ll try to extract the relevant parts of my code and post it here.
Thus far, what I have been doing is detaching a chunk’s mesh when it falls outside a certain “view limit”, and rebuilding the mesh and then attaching it when it should be visible.
For terrain-modification, a similar detach/rebuild/attach cycle happens. This is not acceptable way of doing it, since the terrain chunk disappears temporarily.
Thanks for your help on this.
This is the code
[java]
Geometry chunkGeom = (Geometry)( ChunkStore.getInstance().peekChunk( chunkId ).getGeometry() );
Mesh chunkMesh = chunkGeom.getMesh();
chunkMesh.setBuffer( VertexBuffer.Type.Index, 1, BufferUtils.createIntBuffer( indexBuf ) );
chunkMesh.setBuffer( VertexBuffer.Type.Position, 3, BufferUtils.createFloatBuffer( vertBuf ) );
chunkMesh.setBuffer( VertexBuffer.Type.TexCoord, 2, BufferUtils.createFloatBuffer( texBuf ) );
chunkMesh.setBuffer( VertexBuffer.Type.Normal, 3, BufferUtils.createFloatBuffer( vertNormBuf ) );
TangentBinormalGenerator.generate( chunkMesh, false, false );
chunkMesh.updateBound();
chunkGeom.updateModelBound();
[/java]
@adrian-maggio said: What I meant to add to my post is that I am doing essentially the same thing as the updateGeometry method is, to my custom meshes.
Well, something is different in your approach. Go back and recheck assumptions. One way works and the other doesn’t… change one (or both) until they meet in the middle.
For me, looking at just the little snippet provided, I’d have to make 100 assumptions just to look at the code. For example, I can’t tell from here if that code is even run or if the geometry is even reattached. There could be 1000 non-mesh-related things going on.
It is in your best interest to reduce the problem to a simple test case. Then when that works fine you can figure out what you did differently. If in the off chance that it still doesn’t work fine then you can post it and we can tell you what you did wrong.
Bottom line: if you update a displayed mesh to something different then the rendering will change. No real way to avoid it. So either you aren’t really changing the mesh, or your are changing a different mesh, or something similar to that.
I’m not sure what else you are looking for. What I posted is the only piece of code that matters to the problem I am debugging.
I must be modifying a copy of the mesh. When attaching a geometry to the scene graph, is a copy made internally to JME?
It’s looking like I would need to query the scene graph each time I need to modify, which means I need to assign unique user data, and keep track these unique names. Not what I wanted to do, since I already have a system in place that starts from my picking code, and allows me to reference the specific chunk, and voxel in question.
Will post my results here.
Thanks again for the help.
@adrian-maggio said: I'm not sure what else you are looking for. What I posted is the only piece of code that matters to the problem I am debugging.
Well, the code provided is fine. It will work.
@adrian-maggio said: I must be modifying a copy of the mesh. When attaching a geometry to the scene graph, is a copy made internally to JME? It's looking like I would need to query the scene graph each time I need to modify, which means I need to assign unique user data, and keep track these unique names. Not what I wanted to do, since I already have a system in place that starts from my picking code, and allows me to reference the specific chunk, and voxel in question.Will post my results here.
Thanks again for the help.
Nothing is copied by JME. I cannot write the simple test case for you because it would do me no good. The simple test case is for YOUR benefit.
Write one. See that it works. Figure out what’s different.
Ok, I solved the original problem. It was elsewhere in my code.
What I want to do now, is also update the RigidBodyControl for each chunk mesh, so that when the mesh geometry changes, so does the rigid body. I do not see a way to do this.