Prevent zooming


(Empe2301) #1

Hello, I'm using 3d model in my website using viewer api . Is it possible to prevent zooming (I mean zoom to min/max some distance from object), because my client wants to disable looking at inside model and disable too much distance from model. I'm trying to catch jQuery event on change view and prevent area that I can move (it can be hard because I need to use mathematical formula to define all points and stop moving when the point is out of the range.


#2

Quick and dirty solution is to add scrollwheel: 0 to your initialization options, but zooming is still possible with Control + Click/Drag.

For more control over a near point and far point, I have a Viewer API demo here: https://forum.sketchfab.com/t/viewer-api-zoom-demo/3524

We're working on proper camera constraint features and hope to release something in the near future.


(Empe2301) #3

Thanks James, this is helpfully for me, but I still have problem with this task.
Now I don't know how get a event from iframe. When I write this script:

  var iframe = document.getElementById('api-frame');
  var version = '1.0.0';
  var urlid = '';
  var client = new Sketchfab(version, iframe);

  client.init(urlid, {

      success: function onSuccess(api) {
          api.start(function() {

              $('body').mousemove(function(event) {

                  api.getCameraLookAt(function(err, camera) {

                      var currentPos = camera.position;
                      var currentTarg = camera.target;
                      z = currentPos[2];
                      if (z < 0) {
                          api.lookat(
                              [currentPos[0], currentPos[1], 0], [currentTarg[0], currentTarg[1], 0],
                              0
                          );

                      }
                  });
              });
              console.log('Viewer is ready');
          });
      },
      error: function onError() {
          console.log('Viewer error');
      }
  });

model back to right position but only when I move the mouse outside of the iframe.
I tried use $('#api-frame').contents() but I get answer: 'Error: Permission denied to access property "document" '.

So my problem is: how can I get event from iframe?


#4

At the moment, the only events are viewerready, annotationfocus, and annotationblur. You'll need to poll the camera position continuously: cameraPolling.html (1.9 KB)

Sorry the full demo link was broken in that thread, I just replaced it.


Is it possible to control the view of an object?
(Empe2301) #5

Thanks James! This information is very helpfully for me, and finally I could move with the solution :slight_smile:


#6

Happy to help :slight_smile: