First of all, this is for a clinical simulator, not a video game.
The Setup:
I have a mesh that is being deformed by a soft body deformation model. I am colliding a ray against the geometry, and the mesh is being deformed based on user interactions, controlling the ray.
One iteration can be ( roughly ) broken down to:
I cast a ray onto the mesh
The ray produces a localized force on the soft body model
The soft body model updates
The mesh is updated to reflect the deformation.
The Problem:
All my physics are working fine, and the mesh deformation is visually correct, but it seems the collision model of the mesh is not updating. When I do great deformations, I am still colliding with the undeformed mesh. ( So there is a difference between what I touch and what I see. )
My guess is that the collision model will need an update, but how do I tell jMonkeyEngine to rebuild the collision model?
well he can call recalculatePhysicSHape himself each frame/each deformation. Probably not the fastest way, but should be fine for a limited amount of meshes.
Sorry, I don’t think I phrased my self very clearly.
@zarch I am using the build in BIHTree used by Mesh implementing Collidable
@normen It is softbody physics, I have implemented them myself. I do a lot of physics on my day job. I have done Mass Spring Models, Embedded Hexahedral FEM, Cosserat Rods and Cosserat Surfaces, so to me they are very much available.
@Empire Phoenix Is that from jBullet? Sorry, I am using custom physics with the standard BIHTree
I found the answer to my question. Mesh.createCollisionData() completely recreates the BIHTree, though I would have prefered reusing the model, rather than completely recreating it. With the update it runs at about 250 fps, which is the same as without the update. So the recalculation seems to be efficient.
Yeah, you should have mentioned you use your own physics based on the BIH tree… Then the solution you found would have been presented right away ^^ Still my answer is correct in that the data doesn’t update. Regenerating it seems like a bad solution though as you basically just update the data and probably wouldn’t need to recreate it completely…?
Yes, I would really prefer not to recreate it all. From what I can see the BIHTree does not have any methods to update itself. It works with my current ( rather simple ) mesh, but I imagine that processing and GC is going to take up resources if I increase the resolution of my dynamic mesh.
If you implement that we wouldn’t mind you posting it here Maybe it can help people with similar issues or even help improving the updating in the engine.
Sure, I will make sure to submit my implementation if and when I end up doing it. I will not be looking at optimizations until I hit a performance bottle-neck, though; but once I do ( and I expect I will ) this will probably be at the top of my list.
One question I wonder about, why did you decide to do your own implementation, instead of extending the native bullet binding and use their softbody physics?
Well, several reasons, but the main reason is that I had to extend the physics with several functionalities, such as cutting, suturing, dynamic update of physical parameters, intrinsic bend. So since I needed very specific functionality I first decided on which specific deformation models I needed, then had a look for existing implementations, not finding any I implemented them myself.
So in short, instead of looking at what is available and using that, I looked at what I needed and made it available.
Besides that when it comes to soft body physics, I think Sofa Framework is a more extensive library than bullet. But Sofa did not have the functionality I needed either, though they do have a Hexahedral FEM model, which I have been using as a reference for my implementation. ( Sofa uses a lot of abstractions and generalizations, making it quite hard to extend, so again, I wrote my own )
Edit: Also, I didn’t start out using jME, I have been through 2 other graphics engines that did not directly support jBullet.
Thank you @nihal, I found this to be a solution for one of my TerrainQuad modification problems: ((Geometry)my_terrain_patch).getMesh().createCollisionData();