Jump to content

Picking objects of a loaded mesh


MauJovi
 Share

Recommended Posts

Hi everyone, i'm a newbie playing with Babylon.js, so be nice. haha

I already saw a lot of picking meshes codes, onmousehover, onmouseout and stuff, but I wanted to use it in a loaded mesh. Especifically an .obj file.

I have a 3DS exported file with a lot of shapes, and I've already achieved some part of my objective using the code below, that returns me the name of my shape(nice!).

window.addEventListener("click", function () {
    var pickResult = scene.pick(scene.pointerX, scene.pointerY);
    console.log(pickResult.pickedMesh.id);
});

Now I want some hover and selected effect, but I haven't seen something like that on the internet.

I've tried to implement raanan's suggestion with jquery, but i wasn't successful.

What can i do?

Thanks in advance

Link to comment
Share on other sites

Hi!

10 hours ago, MauJovi said:

Hi everyone, i'm a newbie playing with Babylon.js, so be nice. haha

We'll do out best!

My jQuery extension can be found here - https://github.com/BabylonJSX/Native-JS-Events , along with explanation of how to use it. This was more targeted towards web agencies that just need an embedded webgl frame but still use jquery for the rest of the site. Using jquery on your babylonjs window only for that will be redundant :)

Another way would be to use the onPointerMove event. The second variable of this callback is the picking info. So the job is done for you :)

Answering your question, I found a small bug with the onPointerMove function :) but it is fixable, for sure. anyhow, here is a playground to get you started

http://www.babylonjs-playground.com/#1YHPTN

enjoy Babylon!

Link to comment
Share on other sites

1 hour ago, MauJovi said:

It was easier than I thought! Thank you.

Btw, as I can see on my researches about babylon, you and other contributors are doing a great job. It was certainly the main reason to me to choose this framework. Congrats! :D

Thanks! Always wonderful to hear.

I made a remark about a bug - well, it isn't. I simply forgot about the conditions for picking...

Here is an updated version, without making a second pick call : http://www.babylonjs-playground.com/#1YHPTN#1 

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