1
votes

I have converted the flat image into spherical image by using the below source code(three js).

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Spherical image conversion</title>
    <style>
        body { margin: 0; overflow: hidden; background-color: #000; }
    </style>    
</head>
<body>
    <div id="container">
        <div id="openseadragon1" style="width: 100%; height: 100%;"></div>
        <div id="sphere"></div>
        </div>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r71/three.min.js"></script>
    <script src="js/OrbitControls.js"></script> 
    <script src="js/Detector.js"></script>      

    <script src="./openseadragon_2.0/openseadragon.min.js"></script>
    <script type="text/javascript">
            var viewer = OpenSeadragon({
                id: "openseadragon1",
                wrapHorizontal: "true",
                wrapVertical: "true",
                constrainDuringPan:"true",
                defaultZoomLevel: 1,
                visibilityRatio: 1,
                minZoomLevel: 1,
                prefixUrl: "openseadragon_2.0/images/",
                tileSources: "spherical.dzi"
            });
        </script>

    <script>

        var sphereContainer = document.getElementById('sphere');

        var width  = window.innerWidth,
            height = window.innerHeight;

        var scene = new THREE.Scene();

        var camera = new THREE.PerspectiveCamera(75, width / height, 1, 1000);
        camera.position.x = 0.1;

        var renderer = Detector.webgl ? new THREE.WebGLRenderer() : new THREE.CanvasRenderer();
        renderer.setSize(width, height);

        var sphere = new THREE.Mesh(
            new THREE.SphereGeometry(100, 20, 20),
            new THREE.MeshBasicMaterial({
                map: THREE.ImageUtils.loadTexture('spherical-image.jpg')
            })
        );
        sphere.scale.x = -1;
        scene.add(sphere);

        var controls = new THREE.OrbitControls(camera);
        controls.noPan = true;
        controls.noZoom = true; 

        sphereContainer.appendChild(renderer.domElement);

        render();

        function render() {
            controls.update();
            requestAnimationFrame(render);
            renderer.render(scene, camera);
        }

        function onMouseWheel(event) {
            event.preventDefault();

            if (event.wheelDeltaY) { // WebKit
                camera.fov -= event.wheelDeltaY * 0.05;
            } else if (event.wheelDelta) {  // Opera / IE9
                camera.fov -= event.wheelDelta * 0.05;
            } else if (event.detail) { // Firefox
                camera.fov += event.detail * 1.0;
            }

            camera.fov = Math.max(40, Math.min(100, camera.fov));
            camera.updateProjectionMatrix();
        }

        document.addEventListener('mousewheel', onMouseWheel, false);
        document.addEventListener('DOMMouseScroll', onMouseWheel, false);

    </script>
</body>
</html>

Also i have converted the high resolution image to deep zoom image format.So currently i have a folder containing processed (split) images and dzi format file (image folder and image.dzi files).

Now i need to integrate the openseadragon lib to get the better performance after zoom the image.That will render the tile images from the folder in a specific coordinates.

Please give me a suggestion how can we done this.

Thanks in advance.

2

2 Answers

3
votes

Building on the answer from iangilman, here is a working example that displays the canvas from openseadragon as a texture of a threejs geometry.

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>JS Bin</title>
    </head>
    <body style="background:#fff;">
    <div id="seadragon-viewer" style="width:800px; height:200px;"></div>
    <script src="http://openseadragon.github.io/openseadragon/openseadragon.min.js"></script>
    <script src="http://cdnjs.cloudflare.com/ajax/libs/three.js/r68/three.min.js"></script>
    <canvas id="canvas"></canvas>
    <script id="jsbin-javascript">
    var duomo = {
        Image: {
            xmlns: "http://schemas.microsoft.com/deepzoom/2008",
            Url: "http://localhost:8000/images/duomo/duomo_files/",
            Format: "jpg",
            Overlap: "2",
            TileSize: "256",
            Size: {
                Width:  "13920",
                Height: "10200"
            }
        }
    };

    var viewer = OpenSeadragon({
        id: "seadragon-viewer",
        prefixUrl: "http://openseadragon.github.io/openseadragon/images/",
        tileSources: duomo
    });
    var width = window.innerWidth, height = window.innerHeight / 2;
    var size = 256;
    var canvas = document.getElementById('canvas'),
        ctx = canvas.getContext('2d');

    var camera, scene, renderer, geometry, texture, mesh;



    function init() {
        renderer = new THREE.WebGLRenderer();
        renderer.setSize(width, height);
        document.body.appendChild(renderer.domElement);

      scene = new THREE.Scene();

        camera = new THREE.PerspectiveCamera(70, width / height, 1, 1000);
        camera.position.z = 500;
        scene.add(camera);

        texture = new THREE.Texture(viewer.drawer.canvas);
        var material = new THREE.MeshBasicMaterial({ map: texture });
        geometry = new THREE.BoxGeometry( 300, 300, 300 );
        mesh = new THREE.Mesh( geometry, material );
        scene.add( mesh );

    }

    function animate() {
        requestAnimationFrame(animate);

        texture.needsUpdate = true;
        mesh.rotation.y += 0.01;
        renderer.render(scene, camera);
    }

    init();
    animate();
    </script>
    </body>
    </html>
0
votes

Presumably you would need to marry the OpenSeadragon canvas to the THREE.js material. On the OSD side, you can access the canvas DOM element with viewer.drawer.canvas. I don't know how to do the THREE.js side.

The other aspect would be telling the viewer (which presumably you would have offscreen) when to zoom in and out. This can be handled with viewer.viewport.zoomTo or viewer.viewport.zoomBy.

Sorry I don't have more help, but I figured it was worth at least adding those bits.