Jump to content

intersectsMesh not working?


Recommended Posts

Hello, I'm sorry for the stupid question, but how do I detect an intersection? I followed the playground example, but it doesn't work for me. Here is the code:

var portal = BABYLON.Mesh.CreateBox("portal", 20, scene);
portal.position = new BABYLON.Vector3(0, -5, -30);
portal.rotation = new BABYLON.Vector3(0, 3.14, 0);
portal.showBoundingBox = true
if (ellipsoid.intersectsMesh(portal, false)) { //ellipsoid attached to the camera
alert("!!!"); //Message never appears


Link to comment
Share on other sites

Hi DiV, welcome to the forum.  It's not a stupid question at all.  Your code looks right.


There's a playground that might help.

What IS 'ellipsoid'?  It is a flat mesh?  Could it be backwards/upside-down?   (I'm not sure WHY that would matter, though.)

I don't know why it would matter, but maybe reverse the intersection tester line... like this...

if (portal.intersectsMesh(ellipsoid, false))

Anyway, those are just some quick checks.  If you can use our playground... to reproduce the problem, then make a save... and send us the URL herre in this thread, we can all see the issue.

It COULD be... related to the thickness of ellipsoid... if ellipsoid is flat.  Or reversed.  More info, please. 

Reproduce a test scene in playground, if possible,  thx. 

There are some sneaky ways to "thicken" the bounding box of a flat mesh/plane... without making the mesh BE thicker.  Our friend Adam once made a bounding box from a blank mesh.  In that playground, line 26 FORCES a boundingbox size... so I think we can figure out how to "thicken" something, as needed.  :)  Talk soon, report discoveries, please.  (thx)

Link to comment
Share on other sites

I think I found the solution. It attaches a box to my camera. May not be the best way to code it but it works, which is enough for me. Thank you!

var portal = BABYLON.Mesh.CreatePlane("portal", 20, scene);
portal.position = new BABYLON.Vector3(0, -5, -30);
portal.rotation = new BABYLON.Vector3(0, 3.14, 0);

let collider = BABYLON.MeshBuilder.CreateBox("collider", {size: 3}, scene);
collider.parent = camera;

collider.actionManager = new BABYLON.ActionManager(scene);
let action = new BABYLON.ExecuteCodeAction(
trigger: BABYLON.ActionManager.OnIntersectionEnterTrigger, 
parameter: { 
mesh: portal
(evt) => {


Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...