我已使用以下源代码(三个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 lib以在缩放图像后获得更好的性能。这将以特定坐标呈现文件夹中的图块图像。
请给我一个建议,我们怎么能这样做。
提前致谢。
答案 0 :(得分:2)
根据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>
答案 1 :(得分:0)
据推测,您需要将OpenSeadragon画布与THREE.js材质相结合。在OSD端,您可以使用viewer.drawer.canvas
访问canvas DOM元素。我不知道如何做THREE.js方面。
另一个方面是告诉观众(大概你会有屏幕外)何时放大和缩小。这可以使用viewer.viewport.zoomTo
或viewer.viewport.zoomBy
来处理。
抱歉,我没有更多的帮助,但我认为至少要添加这些内容是值得的。