DZI Openseadragon in combination with three.js creates a stunning spherical image

I successfully transformed the flat image into a spherical image using the provided 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>

I have also converted a high-resolution image to a deep zoom image format. Currently, I have a folder containing processed (split) images and a dzi format file (image folder and image.dzi files).

Next, I am looking to integrate the openseadragon library for better performance when zooming in on the image. This will allow the rendering of tile images from the folder at specific coordinates.

If you have any suggestions on how to achieve this integration, please share them with me.

Thank you in advance.

Answer №1

Expanding on the solution provided by iangilman, here is a functional example demonstrating how to utilize the canvas from openseadragon as a texture for a threejs geometry.

    <!DOCTYPE html>
    <html>
    <head>
      <meta charset="utf-8">
      <title>Interactive Demo</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 initialize() {
        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 animateScene() {
        requestAnimationFrame(animateScene);

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

    initialize();
    animateScene();
    </script>
    </body>
    </html>

Answer №2

Marriage between the OpenSeadragon canvas and the THREE.js material seems necessary. To access the canvas DOM element on the OSD side, utilize viewer.drawer.canvas. However, implementing this connection on the THREE.js side remains unknown to me.

Furthermore, controlling when the viewer zooms in and out (potentially located offscreen) is crucial. This can be achieved using either viewer.viewport.zoomTo or viewer.viewport.zoomBy.

I regret not being able to offer more assistance, but I hope these snippets prove helpful.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Exploring the Depths of a Room in ThreeJS

I am currently working on creating a room in ThreeJS, and here is the progress I have made so far: http://jsfiddle.net/7oyq4yqz/ var camera, scene, renderer, geometry, material, mesh, focus; init(); animate(); function init() { scene = new THREE.S ...

Modify the state of a separate component in React when an onClick event occurs

I am attempting to pass state through props and I am looking to reverse it when I click an element in another component. Is this achievable? Header Component: class Header extends Component { constructor(props) { super(props); this.state = { ...

Exploring Next.js: Comparing data fetching in getInitialProps(): server-side versus client-side

Currently, I'm working with Next.js and have set up a custom server using Express. One of my pages needs to retrieve data from the database. When getInitialProps() is executed on the server side, it easily retrieves the necessary data from the databa ...

Exploring the metadata of images using the Google Streetview Image API

Since November 2016, the Google Streetview Image API has enabled JSON query for metadata of images. Is there a way to extract the status from the image URL using Javascript? ...

Can anyone explain how to successfully implement AJAX data in a PHP file?

I've been struggling to transfer data from my JavaScript file to a PHP variable. I've spent hours searching for solutions, but none seem to apply to my unique code. Here's the JavaScript code I'm working with... $(function(){ ...

Tips for interpreting information from a JSON array that has been stringified, looping through the data, and utilizing it effectively

I'm currently exploring Node JS packages and I need some guidance. Here is an example of the JSON data that I have: [{ "name":"SpiderMan", "description":"Superhero", "head_id":"29", "domain_name":"spiderman.com" }] I am trying to figure out how to ...

Both position absolute and position relative are failing to work effectively

Whenever I click on a div called "test", another div named "outside" appears, along with a div named "inside" that has a higher z-index. The problem arises when I try to set the position of "inside" to absolute, as I am unable to assign a margin-bottom. A ...

JavaScript: displaying the value of a checked checkbox

Here is the HTML code snippet I am working with: <form id="my form"> <input type="checkbox" name="interest" value="swim"/> <input type="checkbox" name="interest" value="baseball"/> <input type="checkbox" name="interest" value="basketb ...

Can Angular JS handle Object Logging?

Exploring the possibility of using Angular JS with MVC 5.0, I am looking for a way to log the complete class Object into a database whenever an Insert/Edit/Delete operation is performed. Is there a library available in Angular JS that can help serialize ...

When a user clicks on buttons other than the submit button, the input field redirects to another page

A helpful user named Vittore assisted me in displaying the first 5 list items of the unordered list and implementing page navigation with next and previous buttons flawlessly. The issue arises with an input field, which functions correctly by navigating ...

Numerous Ajax calls made to Flask-Python endpoint - Yet, only one was successful

i'm attempting to iterate through several forms with input file type and employ Ajax to send them to Flask This is how the javascript looks like :- I have a list of forms stored in the variable var upFC = document.getElementsByClassName('upload ...

Styling material-ui textfield: Tips and tricks

I've been grappling with figuring out how to customize a material-ui TextField component. <TextField id="email" label="Email" className={classes.textField} value={this.state.form_email} onChange={this.handle_change('form_e ...

Issue with Mongoose Promise failing to transfer data to the following chain

When querying MongoDB using mongoose with promises, I encounter an issue where the result is only accessible in the initial .then(function(results){ // can send the result from here..}). However, when I manipulate the results and attempt to pass them to th ...

Uncovering components generated by React JS with BeautifulSoup

My goal is to extract anchor links with the class "_1UoZlX" from the search results on a specific page - After analyzing the page, I realized that the search results are dynamically generated by React JS and not readily available in the page source or HTM ...

Activate a function to focus on an input field once ngIf condition becomes true and the input is revealed

I am currently attempting to focus the cursor on a specific input field that is only displayed when the condition of the surrounding ngIf directive is true. Here is an example of the HTML code structure: <div> <button (click)="showFirst = ...

Exclude files from all folders except one in gulp source

This is the structure of my folders: views | - core | | | -core.module.js | core.controller.js | some.js | - home | -home.module.js home.controller.js somemore.js ... ... In my gulp file, I am looking to include all js files from the views ...

unable to insert logo into HTML

I am customizing an HTML template, but the dimensions of the logo in the template are smaller than my logo. Despite adding my logo to the template, it is not showing up. @media (max-width: 673px) { #logo { margin-left: 20px; } } #header #logo ...

Error in Charts API - [draw function failed to render for one or more participants]

Currently encountering an error on the client side where one or more participants failed to draw. I am able to successfully output data in the drawVisualization call, indicating that the issue lies within the JavaScript code. Despite following examples, I ...

Performing JSON data extraction and conversion using JavaScript

Hello! I'm working with a script that converts data into an array, but I want to enhance it so that I can extract and convert data for each object (arb, astar, aurora, avax, baba, bsc, etc.), as shown in the screenshot. Here is the current script tha ...

Remove duplicate elements from a JSON array

How can I add each item in an array for each duplicate? Transform: [ { "uuid":"EE877ABD-932F-4B4C-AB23-B324363B0B60", "planning":[ { "uuid":"6D680178-9B05-4744-A004-163D4B3E1E84", "star ...