Jump to content

Know position of a mesh on the canvas (x,y)


Leenzur
 Share

Recommended Posts

Hi everybody and welcome to my first topic in this forum !  :lol: 

Firstly, a lot of thanks for babylon's js developpers.

Secondly, I'm a french newbie in developpment, 3D and in english language, so please, use not too much complicated words :wacko: .

My question is... is there a solution to know 2D position of a 3D mesh rendered on the canvas ?

My aim is to render a sprite on the screen which represent a circle of selection around the mesh after picked it. Maybe a better solution than sprites already exists and i'm open to suggestions.

 

In advance, thank you for your replies  :) .

Link to comment
Share on other sites

Hi,

 

welcome. You can pick which allows you to retrieve the item click a ground for example

 

 

var pickInfo = ground.pick(evt.clientX, evt.clientY);var x = pickInfo.pickedPoint.x;var y = pickInfo.pickedPoint.y;var z = pickInfo.pickedPoint.z;sprite.position = new BABYLON.Vector3(x, y, z);
In 2D you just need x and y
Link to comment
Share on other sites

I just tried your code dad72 and it works very well, thank you :D.

This result brings me to an other question.
I'm in a 3D scene, and i would like the sprite always render in 2D independently of the 3D scene, like a layer 'on' the canvas and not 'in' the 3D scene. Or just always make if face the camera (even if i think this method could be very difficult to make or calculate with matrices). Difficult for me to explain :unsure: sorry, but have you any idea ?

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