1

我已使用以下源代码(三个 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>

此外,我已将高分辨率图像转换为深度缩放图像格式。所以目前我有一个包含处理(分割)图像和 dzi 格式文件(图像文件夹和 image.dzi 文件)的文件夹。

现在我需要集成 openseadragon 库以在缩放图像后获得更好的性能。这将在特定坐标中渲染文件夹中的平铺图像。

请给我一个建议,我们该如何做到这一点。

提前致谢。

4

2 回答 2

3

基于 iangilman 的回答,这里有一个工作示例,将 openseadragon 的画布显示为 threejs 几何体的纹理。

    <!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>
于 2016-09-07T03:20:16.407 回答
0

大概您需要将 OpenSeadragon 画布与 THREE.js 材料结合起来。在 OSD 端,您可以使用viewer.drawer.canvas. 我不知道如何做 THREE.js 方面。

另一个方面是告诉观众(大概你会在屏幕外)何时放大和缩小。这可以用viewer.viewport.zoomTo或来处理viewer.viewport.zoomBy

抱歉,我没有更多帮助,但我认为至少添加这些位是值得的。

于 2015-10-26T16:44:55.327 回答