gorgar Posted June 27, 2018 Share Posted June 27, 2018 Just got a quick question demonstrated in the following example: http://www.babylonjs-playground.com/#IK3V1A#6 Q1. You can see a sphere mesh being constructed with a diameter of 4, yet the bounding sphere of said mesh has a radius of '3.4641016151377544'. Shouldn't it be ~2? Q2. I may be misunderstanding BoundingSphere.intersectsPoint, but after picking a mesh from the scene, an additional check is done to see if said point exists within the bounding sphere. This returns true even when dragging across the plane, far away from the sphere. Why is this happening? Snippet of BoundingSphere.intersectsPoint // pick from scene, ignore ray helper, don't use fast pick const pick = scene.pick(scene.pointerX, scene.pointerY, m => m.name !== 'ray', false) // if we have a hit and the point exists within bounding sphere if (pick.hit && bs.intersectsPoint(pick.pickedPoint)) { ... } Thank you! Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 http://www.babylonjs-playground.com/#IK3V1A#8 He is right, there is some error in this calculation. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 http://www.babylonjs-playground.com/#IK3V1A#9 what is happening is we are relying on a distance calculation that for some reason is not doing it here is a work around. var min = Number.POSITIVE_INFINITY; var max = Number.NEGATIVE_INFINITY; var va = ['x','y','z']; for(var i=0; i<3; i++){ if(bs.minimum[va[i]]<min){ min=bs.minimum[va[i]]; } if(bs.maximum[va[i]]>max){ max=bs.maximum[va[i]]; } } var distance = max-min; var radius = distance*0.5; console.log(radius, "real Radius"); Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 https://github.com/BabylonJS/Babylon.js/pull/4620 Arte 1 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 Could also do this: var radi = (bs.maximum.subtract(bs.minimum)).scale(0.5); console.log(radi); if its not truly spherical and want the radius per axis. Quote Link to comment Share on other sites More sharing options...
gorgar Posted June 27, 2018 Author Share Posted June 27, 2018 Thanks for the quick response and details Pryme8! Doesn't this mean that each operation performance against the Bounding Sphere is potentially incorrect? EG intersectsPoint, isInFrustum. Assuming they depend on the internal radius, not 'realRadius'. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 ehhhhh, maybe honestly... I mean it kinda would seem that way. The distance.length() calc seems to be the problem. but Im not sure if everything else is working correctly, thats why I left the old stuff and just did a secondary calc. When I get back from lunch Ill dig more into this math. Quote Link to comment Share on other sites More sharing options...
jerome Posted June 27, 2018 Share Posted June 27, 2018 Q1 : I guess there's a misunderstanding about what is the bounding sphere of a mesh here, of any mesh (a sphere or a box, or anything). The bounding sphere is simply the sphere embedding the mesh bounding box ! In the particular case where the mesh itself is a sphere, well, it is contained in a bounding box greater than it, this bounding box being contained in its bounding sphere greater than the bounding box. That's why the bounding sphere radius is always greater than the contained spherical mesh radius. If you want a better explanation, please have a read at the part starting by "As you may know, a mesh -so a solid particle- is inside its bounding ..." here : http://doc.babylonjs.com/how_to/solid_particle_system#particle-intersections In the case of spherical mesh the ratio between the bounding sphere radius and the contained sphere radius is sqrt(3) GameMonetize, gorgar and Pryme8 3 Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 soooo: var r = BABYLON.Vector3.Distance(bs.maximum, bs.minimum); r /= Math.sqrt(3); r*=0.5; console.log(r, "real Radius"); I had to divide it in half as well, cause ratio of sqrt 3 just gave me the diameter. Quote Link to comment Share on other sites More sharing options...
Pryme8 Posted June 27, 2018 Share Posted June 27, 2018 https://github.com/BabylonJS/Babylon.js/pull/4621 better? Quote Link to comment Share on other sites More sharing options...
gorgar Posted June 27, 2018 Author Share Posted June 27, 2018 Thanks for the explanation jerome! Quote Link to comment Share on other sites More sharing options...
gorgar Posted June 28, 2018 Author Share Posted June 28, 2018 So about question two. I've reformatted the demo: see link http://www.babylonjs-playground.com/#IK3V1A#13 If you use the boundingSphere, it always returns true for intersects points, even if you use a very small bounding sphere. I've implemented a difference version of intersectsPoint, which gives the results I was expecting. Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 this one works right? http://www.babylonjs-playground.com/#IK3V1A#14 Perhaps I don't get what the problem is Quote Link to comment Share on other sites More sharing options...
gorgar Posted June 28, 2018 Author Share Posted June 28, 2018 const min = new BABYLON.Vector3(-0.5, -0.5, -0.5) const max = new BABYLON.Vector3(0.5, 0.5, 0.5) const pnt = new BABYLON.Vector3(50, 50, 50) const boundingSphere = new BABYLON.BoundingSphere(min, max) // result is true const result = boundingSphere.intersectsPoint(pnt) The bounding sphere check above always returns true, although the point doesn't exist within the boundingSphere. http://www.babylonjs-playground.com/#IK3V1A#16 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 This is a yacky bug I'll fix that now next commit will contain the fix Thank you for the heads up Pryme8 1 Quote Link to comment Share on other sites More sharing options...
Guest Posted June 28, 2018 Share Posted June 28, 2018 Fixed: http://www.babylonjs-playground.com/#IK3V1A#16 gorgar 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.