Jump to content

RayCasting


bser
 Share

Recommended Posts

Hello. We are trying to figure out how to do a Raycast from the camera, in order for a user to look at a mesh and be able to modify it. For example if we want a wall mesh to change into a heart mesh, we would want the user to look at the wall and it will change it to a heart mesh. How are you able to create this functionality? 

Link to comment
Share on other sites

Hi there... one quick way to do this is using observables... like so:

scene.onPointerObservable.add (function(evt) {
        var pi = evt.pickInfo;
    },BABYLON.PointerEventTypes.POINTERDOWN);

The pickInfo of the event contains a lot of information about the event (PickInfo)

You could also use scene.pick(), which takes X,Y coords you can grab from a standard mousedown event from addEventListener.

 

Link to comment
Share on other sites

  • 6 months later...

@bser I wanted to do the same thing, and came up with this demo.

http://www.babylonjs-playground.com/#1A7ZCT#4

The scene displays 4 spheres and continually creates rays using Ray.CreateNewFromTo()  from the camera's current position to a target (0,0,0).  If a ray intersects a sphere, a decal is drawn on the sphere.  We detect the intersection using scene.multiPickWithRay().  If multiple meshes are found, we choose the one that is closest to the camera.

 

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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