Hi, I’m a newbie at BabylonJS, and I’m hesitant to call a ‘bug’ when it is likely my own ignorance. But I’ve worked at this for two days, have read everything I could find, and still can’t make it work.ing to
I’m trying to bounce oblong spheres with a physics engine. It works perfectly from every axis when the sphere has not been rotated. So the physics engine understands that spheres have (a,b,c) dimensions. (change the shape of the sphere and the top collision still works every time).
But add a little rotation and the collisions no longer take place at the right time. The physics engine understands the rotation and correctly transfers angular rotation from one body to another. But it is as if the physics engine rotates the mesh while the imposter sphere itself doesn’t rotate.
Pretty sure Bullet/Ammo can handle rotations. I’m going to try to figure this out myself. I’ve pulled down the BJS code from Github. It’s crazy hard for a newbie, but that’s how we learn and move up.
neat idea, but lots of setup. collisions of rotating objects should just “work”. let me dig into Bullet/Ammo.
also, if the spheres don’t collide but slip past, two objects could get ‘hooked together’.
also might be very slow if lots of spheres. but the idea is interesting. might be easier to distribute a set of approximately evenly-spaced points on the surface of a object (maybe with a Fibonacci lattice?). it’s easy to check whether a point is inside or outside a regular solid, but slow to check EVERY point.
Thanks Necips. But I don’t want to write my own physics engine, just want to dig in and figure out what is going on in the Ammo interface. And learn from studying other people’s code.
Were you driving home in a vehicle? If so, I’d check it for exhaust leaks, if I were you.
How many light/photon-receptors intersect functions can you find in BJS? zero. Okay, maybe ray-casting is somewhat similar to light rays/photons, but not much.
I’m not sure real life uses photon-receptors to do collision/intersect-checking, either. Did you read about some new discovery? Do tell.
I think real life uses molecular bonds, right? I think real collisions happen at a molecular level, and not really at an atomic level. But, I’m sure no expert in such things. Google knows more, I bet.
Ok, back to actual issue, the physics impostors are not sizing/scaling to fit the elongated sphere. There’s a bug somewhere… in Ammo plugin or physicsImpostor classes.
Testing playground. I changed from MeshBuilder.CreateSphere… to Mesh.CreateSphere… and tried to use scaling = size, instead.
Lines 92/93 - SHOULD work, but they crash the playground or something. Error: uncaught exception: abort(20). Build with -s ASSERTIONS=1 for more info.
Line 85 (the scaling)… seems to be ignored by the lines 87-90 impostor creation (just like the MeshBuilder sizing method gets ignored). hmm.
Lines 95-99 was a failed attempt to wait for “impostor init” a bit longer… before asking it to reshape itself to egg-shaped. Failed.
Ammo seems to be making a perfectly spherical impostor, no matter how we try to make it egg-shaped. I hear @trevordev is a primary contact on such matters, so maybe he will visit soon and try to help. Stay tuned.
Thank you Wingnut !! That’s exactly what I expected. Amazing and wonderful that you took the time to find a workaround.
But I’m still going to poke at this and see if I can fix the problem (and learn as I go). I’m just figuring out how to build the environment and run the VScode debugger (I still cannot compile the full system without errors, but I can get my colliding asteroids working).
My pleasure… and may I say that it takes a special kind of “chutzpah” to keep digging for more information… after a work-around solution is found. Very cool! I look forward to your findings/reports, and I hope you are able to maintain your beefy stamina.
I learned about MeshImpostors back when CannonJS physics engine arrived at BJS. It was a God-send for making a terrain heightMap… be physics-active… a highly-used feature in webGL, especially for Perplexus-like games, and for golf games.
Speaking of golf, with CannonJS physics… MeshImpostors can ONLY collide-with sphereImpostors. Just for fun, let’s try another test… to see if AmmoJS has the same limitations:
Bullet / Ammo’s ‘btSphereShape’ is always only a uniform sphere for performance reasons. There is no equivalent for a Babylon-style ellipsoid. Uniform sphere collision tests can be done in nanoseconds, and that’s Bullet’s priority.
The second answer, thanks to Wingnut, is a workaround using Meshimposters. That may become very slow when the number of spheres increases.
So the third answer is to use ‘btMultiSphereShape’ and populate it with a few spheres. We can create an approximation something like this but expanding against all three axis.
It might be fun to implement multiSphere and check the performance of using a 9-, 12- or 15-sphere ellipsoid vs the meshImposters approach. Or even make the number of spheres variable (like IcoSphere). I think multiSphere will be MUCH faster, indistinguishable from a uniform sphere. We can also test whether the Babylon sphere is uniform and fall back to ‘btSphereShape’
At a minimum, we should test the sphere in ammoJSPlugin.ts and slip in a meshImposter instead of a sphereImposter if it is an ellipsoid, so that Babylon works properly. The coding for MultiSphere doesn’t look difficult, need to define ‘btMultiSphereShape’ in AmmoTypeDecls.ts and then fix the sphere code in ammoJSPlugin.ts. Of course, everything looks easy until you try it.
I’d be happy to give both approaches a try and run a performance test. Comments?
Yes, to create an ellipsoid you can use the btMultiSphereShape with just one sphere and set the non-uniform scaling on that shape, using setLocalScale(…).
I’m learning TS by studying BJS which is awesome. but I am baffled by the tool chain and multiple opaque transpiling steps for my local build. Finally figured how to configure Babel to handle decorations, and now I’m stuck on some island that doesn’t know about get-set properties. I need to build a test case for my configuration ?!? I suspect everyone has to start this way.
The ammoJSPlugin code needs a bit of love and some careful testing. I’m good at that and would love to work on it. Real soon.
When I look at the status of the Github Pull Request Update Ammo.js library and AmmoJS plugin to support ellipsoid then I get the impression that the logic for Ellipsoid as a single solid impostor/shape has been implemented in at least Ammo.js Physics Engine. Is that correct?
How can I choose the Ellipsoid (which is not a stacked Spheres but a real solid convex Ellipsoid) as the Impostor now for a Mesh?
I am looking for a way to translate the ellipsoid & ellipsoidOffset properties of a Mesh that the BabylonJS Collision Engine uses to the same settings but then for the Physics Engine.
Yo @Cedric … What does this mean… can you give a small example on creating a ellipsoid like shape using btMultiSphereShape with a none homogenous extend sphere … Pretty please