google / model-viewer

Easily display interactive 3D models on the web and in AR!
https://modelviewer.dev
Apache License 2.0
6.76k stars 801 forks source link

How can I get the data-position & data-normal of where a user clicked? #4447

Closed Gamigre closed 10 months ago

Gamigre commented 10 months ago

Edit: I found how to use the methods described thanks to other files containing them in the repo.

I'm looking for a way to get the coordinates of the last point clicked by the user (clientside) on the model. My goal is to allow the user to place themselves their own hotspot-like annotations. I'd like to be able to grab these datas to manage various little thing on the UI side, and send these coordinates to a database with php. Until now I would place randomly a fixed number of hotspots with the editor and user's annotation were randomly dispatched to these hotspots every time the page was loaded, which were hidden if unused, but thta's not very convenient...

I've seen the positionAndNormalFromPoint and SurfaceFromPoint methods in the documentation but honestly I haven't been able to understand how I was supposed to use them, they show up as undefined in my IDE. The example links redirects either to the panning example or this one https://modelviewer.dev/examples/annotations/#animatedHotspots and neither of them use these methods in their code so i'm a bit lost. I'm far from a professionnal, especially in js.

Any help or code snippet showing the syntaxe would be appreciated, thanks!

Version

model-viewer: v3.2.1