I’ve been fiddling with integrating the Rapier physics engine with Babylon. Unfortunately while it seems tantalizingly close, I’m having trouble figuring out how to make proper Imposters that actually fit the geometry of the rendered scene.
I fiddled around with a playground to demonstrate my issue, along with links to what I used along the way to attempt to do the conversions. (Mostly this thread from 2020: Get total size of parent mesh - #7 by Evgeni_Popov )
I thought it was just about spot on but somehow positioned wrong, but then I moved the platform up (uncomment line 132) and realized the slope, or perhaps the size in general, is also wrong. Not sure what to try next, any physics or … geometry sizing(?) experts out there that have some ideas?
For an easier start I wanted to see if I could get it working with the much simpler scenario of creating the meshes in code and so already knowing the translations, sizes, etc to use for the colliders, rather than pretending to have imported arbitrary, unkown meshes. Here it is for reference.
Don’t use the bounding sphere to check the radius of the sphere impostor - this is wrong. The extend size of the bounding box will box what you are looking for. The bounding sphere is bounding the bounding box. so it is bigger than what you would want.
Also - make sure to compute the world matrix of the meshes before you are getting their bounding information - this is to stay safe (especially on the first frame, where it doesn’t happen automatically).
One last thing - quaternions cannot be just the euler angles with 1 at the end. The rotation you defined for the ground was incorrect. If you want to use the absolute rotation (great! :-)) do it, but use the entire quaternion
Thanks, Blake, that was a good debugging step for sure, but the root of my question is why I wasn’t getting the right dimensions back out for, say, an imported mesh which is my ultimate goal. Turns out this isn’t Rapier physics related at all, now that I think about it, what I really want is to be able to get back to those constants by interrogating the scene.
RaananW, thanks for those tips, spot on for what I wasn’t getting. I had tweaked and stared at it so long I’d forgotten that I’d removed the quaternions at some point for some of the rotation. That was in part because I wasn’t seeing anything but 0s so I thought the addRotation must not be creating an instant change. I’ll have to study your playground example, looks like you have it fully solved which is exciting! Now to try to wrap my head around it all. Much appreciated.