Touch / Click events on sketchfab iframe?

(Farisk) #1


I have a Sketchfab iframe showing using the Viewer API.

I’m trying to get some get some basic javascript / jquery touch (and click) events to work when a user touches or drag on the sketchfab viewer.

I cant seem to get anything working and i think its because of the iframe.
Because If i overlay a html div over the view it, i’ll actually get some output of it it.

Is there some sketchfab events where i can detect when a user is interacting with the viewer with touch (dragging, swiping etc) and click events?

Any help is appreciated. Thanks


We do have a click event that is not in the documentation yet:

api.addEventListener( 'click', function(e){
    // Do stuff
} );


e.position3D is the coordinates of the click in 3D space
e.position2D is the coordinates of the click in the 2D canvas
e.normal is the vector of the normal at that point
e.instanceID is the clicked geometry node’s ID
e.material is the clicked material object

And there is also getWorldToScreenCoordinates()

(Farisk) #3

thanks for the reply. Noted on the click event.
I read the documentation about getWorldToScreenCoordinates(), but not quite sure how to use it?

so i assume there are no touch related events, yes?


I don’t know for sure, but I imagine touch should be the same as click.

I’m also not sure what the use case for getWorldToScreenCoordinates() is, but I think @klaasnienhuis had some ideas.

(Klaasnienhuis) #5

getWorldToScreenCoordinates() is very useful to overlay your own frontend on the 3D model. Kind of an alternative for annotations.
Assume you’re building a configurator and you want to pop up a menu with choices where you click on the model. We already had access to the 3D coordinates from the click event. With the getWorldToScreenCoordinates()method it’s possible to make the menu stick to the model (while staying on top) when orbiting.