PSV Animate Fisheye

by mistic100

HTML

<script src="https://cdn.jsdelivr.net/npm/uevent@2/browser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photo-sphere-viewer@4/dist/photo-sphere-viewer.css">
<div id="photosphere"></div>

CSS

html, body, #photosphere {
  margin: 0;
  width: 100%;
  height: 100%;
  font-family: sans-serif;
}

JavaScript

const viewer = new PhotoSphereViewer.Viewer({
  panorama: 'https://photo-sphere-viewer-data.netlify.app/assets/sphere.jpg',
  container: 'photosphere',
  caption: 'Parc national du Mercantour <b>&copy; Damien Sorel</b>',
  loadingImg: 'https://photo-sphere-viewer.js.org/assets/photosphere-logo.gif',
  defaultLat: -Math.PI / 2,
  defaultLong: Math.PI,
  defaultZoomLvl: 0,
  fisheye: 4,
  navbar: [
    'zoom',
    {
      content: 'Rerun&nbsp;animation',
      onClick: intro,
    },
    'caption',
    'fullscreen'
  ]
});

viewer.on('ready', intro);

function intro() {
  // default far plane is too close to render fisheye=4
  // you can also skip this line and start with fisheye=2
  viewer.renderer.camera.far *= 2;

  new PhotoSphereViewer.utils.Animation({
    properties: {
      lat: { start: -Math.PI / 2, end: 0.2 },
      long: { start: Math.PI, end: 0 },
      zoom: { start: 0, end: 50 },
      fisheye: { start: 4, end: 0 },
    },
    duration: 2000,
    easing: 'inOutQuad',
    onTick: (properties) => {
      viewer.setOption('fisheye', properties.fisheye);
      viewer.rotate({ longitude: properties.long, latitude: properties.lat });
      viewer.zoom(properties.zoom);
    }
  });
}