Jump to content

Interaction with model in Canvas2D


aaronmck
 Share

Recommended Posts

Hi all,

So I'm working on a project where I need to be able to click on a mesh and have information about that mesh appear on the screen.

I was told I should use Canvas2D but I'm still pretty new with this and it is simply going above my head, I haven't a clue where to start with this. 

Could anyone be kind enough to help me with this?

I have attached a playground with what I'm looking to do.

Basically I will have multiple meshes on screen and when I click / double click on one of the meshes it will display info for that particular mesh. 

http://babylonjs-playground.com/#BPV7F

Thanks in advance!

Link to comment
Share on other sites

Hello,

You first need to attach the control to the canvas (html one not the 2d feature), but this was probably throwing due to name conflict (the canvas2d was also named canvas in your scene).

Once done the controls are working, then you can use the action manager to reference an action when the mesh is clicked.

This action happens on pick and set the property "text" of the text2d element to the chosen text... (agree it is a lot of texts and canvases...) You can check the code here:

http://babylonjs-playground.com/#BPV7F#9

The easiest would be to read the doc for the action manager and the other pg samples:

https://doc.babylonjs.com/tutorials/How_to_use_Actions

 

Link to comment
Share on other sites

Hey @Sebavan

This is great, very helpful.

Just one issue. I have some of my models load on a button click and others that do not. 

The canvas 2d panel works on the models that don't load on button click but doesn't work on the models that do load on button click.

Do you know why this is?

Thanks!

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