-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathdeepZoom.js
More file actions
143 lines (106 loc) · 3.59 KB
/
deepZoom.js
File metadata and controls
143 lines (106 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import {
Scene,
WebGLRenderer,
PerspectiveCamera,
OrthographicCamera,
} from 'three';
import { EnvironmentControls, TilesRenderer, CameraTransitionManager } from '3d-tiles-renderer';
import { UpdateOnChangePlugin, DeepZoomOverlay, GeneratedSurfacePlugin } from '3d-tiles-renderer/plugins';
import { GUI } from 'three/addons/libs/lil-gui.module.min.js';
let controls, scene, renderer;
let tiles, transition;
const params = {
errorTarget: 1,
orthographic: false,
};
init();
render();
function init() {
// renderer
renderer = new WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0x111111 );
document.body.appendChild( renderer.domElement );
// scene
scene = new Scene();
// set up cameras and ortho / perspective transition
transition = new CameraTransitionManager(
new PerspectiveCamera( 60, window.innerWidth / window.innerHeight, 0.001, 10000 ),
new OrthographicCamera( - 1, 1, 1, - 1, 0, 4000 ),
);
transition.camera.position.set( 0, 0, 1.5 );
transition.camera.lookAt( 0, 0, 0 );
transition.autoSync = false;
transition.addEventListener( 'camera-change', ( { camera, prevCamera } ) => {
tiles.deleteCamera( prevCamera );
tiles.setCamera( camera );
controls.setCamera( camera );
} );
// tiles
tiles = new TilesRenderer();
tiles.registerPlugin( new GeneratedSurfacePlugin( {
overlay: new DeepZoomOverlay( {
url: 'https://openseadragon.github.io/example-images/duomo/duomo.dzi',
} ),
applyOverlayTexture: true,
} ) );
tiles.registerPlugin( new UpdateOnChangePlugin() );
tiles.fetchOptions.mode = 'cors';
tiles.lruCache.minSize = 900;
tiles.lruCache.maxSize = 1300;
tiles.errorTarget = 1;
tiles.setCamera( transition.camera );
scene.add( tiles.group );
// controls
controls = new EnvironmentControls( scene, transition.camera, renderer.domElement );
controls.minZoomDistance = 2;
controls.minDistance = 0.01;
controls.maxDistance = 1000;
controls.cameraRadius = 0;
controls.enableDamping = true;
controls.fallbackPlane.normal.set( 0, 0, 1 );
controls.up.set( 0, 0, 1 );
// events
onWindowResize();
window.addEventListener( 'resize', onWindowResize, false );
// gui initialization
const gui = new GUI();
gui.add( params, 'orthographic' ).onChange( v => {
transition.fixedPoint.copy( controls.pivotPoint );
// adjust the camera before the transition begins
transition.syncCameras();
controls.adjustCamera( transition.perspectiveCamera );
controls.adjustCamera( transition.orthographicCamera );
transition.toggle();
} );
gui.add( params, 'errorTarget', 1, 100 ).onChange( () => {
tiles.getPluginByName( 'UPDATE_ON_CHANGE_PLUGIN' ).needsUpdate = true;
} );
gui.open();
}
function onWindowResize() {
const { perspectiveCamera, orthographicCamera } = transition;
const aspect = window.innerWidth / window.innerHeight;
orthographicCamera.bottom = - 40;
orthographicCamera.top = 40;
orthographicCamera.left = - 40 * aspect;
orthographicCamera.right = 40 * aspect;
orthographicCamera.updateProjectionMatrix();
perspectiveCamera.aspect = aspect;
perspectiveCamera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function render() {
requestAnimationFrame( render );
controls.enabled = ! transition.animating;
controls.update();
transition.update();
const camera = transition.camera;
camera.updateMatrixWorld();
tiles.errorTarget = params.errorTarget;
tiles.setCamera( camera );
tiles.setResolutionFromRenderer( camera, renderer );
tiles.update();
renderer.render( scene, camera );
}