Sketchfab Forum

Material Selection through Viewer

(Sputn1kolas) #1


Has anyone figured out how to get picking/material selection to work with the Viewer API?

I would like to allow users to directly click on parts of the model, and have information displayed about it.

I've seen material selection used successfully in both SketchFab's 3D settings, where you can select materials on the page, and in one of the Sketchfab experiments:

In the experiment, double clicking on parts of the model selects that object, using computeNearestIntersection2D() and onTrianglePick() to select it. However the rest of the file is minified/obfuscated and reasonably complicated so it's difficult to parse this out.

(Mauricesvay) #2

There's an undocumented 'click' event in the Viewer API.

api.addEventListener('click', function(event) {

The event will be triggered every time the user clicks on the model. The event will carry data on the material, object, etc that was clicked.
I'm not sure if the code for this is stable already, but when it is, we'll add it to the documentation.

(Sputn1kolas) #3

Works like a charm! Thank you!

I think I need to increase the size of some of the models, to increase the hit rate, but otherwise works great :slight_smile: