model-manager 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- package/administration/insert.js +179 -0
- package/administration/insert_one.js +33 -0
- package/administration/test_data.js +46 -0
- package/administration.html +76 -0
- package/app-update.yml +0 -0
- package/assets/css/admin.css +79 -0
- package/assets/css/basic.css +474 -0
- package/assets/css/checkout.css +517 -0
- package/assets/css/dialog.css +158 -0
- package/assets/css/dialog_checkout.css +156 -0
- package/assets/css/info.css +10 -0
- package/assets/logo.png +0 -0
- package/assets/partnerart.png +0 -0
- package/assets/spinner.gif +0 -0
- package/assets/three/GLTFLoader.js +4448 -0
- package/assets/three/ModelLoader.js +58 -0
- package/assets/three/OrbitControls.js +1252 -0
- package/assets/three/three.js +36819 -0
- package/assets/three/three.module.js +50708 -0
- package/assets/white/add_white_24dp.svg +1 -0
- package/assets/white/admin/person_add_FILL0_wght400_GRAD0_opsz48.svg +1 -0
- package/assets/white/admin/person_remove_FILL0_wght400_GRAD0_opsz48.svg +1 -0
- package/assets/white/admin.svg +1 -0
- package/assets/white/arrow_forward.svg +1 -0
- package/assets/white/brush_white_24dp.svg +1 -0
- package/assets/white/close_white_24dp.svg +1 -0
- package/assets/white/code_white_24dp.svg +1 -0
- package/assets/white/dashboard_white_24dp.svg +1 -0
- package/assets/white/done_white_24dp.svg +1 -0
- package/assets/white/emoji_people_white_24dp.svg +1 -0
- package/assets/white/filter_list_white_24dp.svg +1 -0
- package/assets/white/info_white_24dp.svg +1 -0
- package/assets/white/minimize_white_24dp.svg +1 -0
- package/assets/white/receipt_white_24dp.svg +1 -0
- package/assets/white/rocket_launch_white_24dp.svg +1 -0
- package/assets/white/search_black_24dp.svg +1 -0
- package/assets/white/search_white_24dp.svg +1 -0
- package/assets/white/settings_white_24dp.svg +1 -0
- package/assets/white/shopping_cart_white_24dp.svg +1 -0
- package/assets/white/store_white_24dp.svg +1 -0
- package/assets/white/timeline_white_24dp.svg +1 -0
- package/assets/white/view_in_ar_white_24dp.svg +1 -0
- package/checkout.html +131 -0
- package/checkout_admin.html +140 -0
- package/icon.png +0 -0
- package/imgs/armchair.png +0 -0
- package/imgs/arrow_tnt.png +0 -0
- package/imgs/bed_wnm.png +0 -0
- package/imgs/big_bed.png +0 -0
- package/imgs/birdscythe.png +0 -0
- package/imgs/blue_tnt.png +0 -0
- package/imgs/bull.png +0 -0
- package/imgs/carpet.png +0 -0
- package/imgs/chest.png +0 -0
- package/imgs/coin_stash.png +0 -0
- package/imgs/creeper_tnt.png +0 -0
- package/imgs/garbage_can.png +0 -0
- package/imgs/generator.png +0 -0
- package/imgs/golden_sword.png +0 -0
- package/imgs/highbed.png +0 -0
- package/imgs/jetpack1.png +0 -0
- package/imgs/jetpack2.png +0 -0
- package/imgs/jetpack3.png +0 -0
- package/imgs/jetpack4.png +0 -0
- package/imgs/jetpack5.png +0 -0
- package/imgs/jetpack6.png +0 -0
- package/imgs/karmincross.png +0 -0
- package/imgs/light_tnt.png +0 -0
- package/imgs/lucky_block.png +0 -0
- package/imgs/lucky_block_2.png +0 -0
- package/imgs/mega_tnt.png +0 -0
- package/imgs/modern_lamp.png +0 -0
- package/imgs/multiply_tnt.png +0 -0
- package/imgs/nuke.png +0 -0
- package/imgs/oak_tree.png +0 -0
- package/imgs/oak_tree_2.png +0 -0
- package/imgs/old_globe.png +0 -0
- package/imgs/scificannon_1.png +0 -0
- package/imgs/scificannon_10.png +0 -0
- package/imgs/scificannon_11.png +0 -0
- package/imgs/scificannon_12.png +0 -0
- package/imgs/scificannon_13.png +0 -0
- package/imgs/scificannon_14.png +0 -0
- package/imgs/scificannon_2.png +0 -0
- package/imgs/scificannon_3.png +0 -0
- package/imgs/scificannon_4.png +0 -0
- package/imgs/scificannon_5.png +0 -0
- package/imgs/scificannon_6.png +0 -0
- package/imgs/scificannon_7.png +0 -0
- package/imgs/scificannon_8.png +0 -0
- package/imgs/scificannon_9.png +0 -0
- package/imgs/simple_chair.png +0 -0
- package/imgs/small_car.png +0 -0
- package/imgs/small_modern_lamp.png +0 -0
- package/imgs/small_wardrobe.png +0 -0
- package/imgs/small_wooden_table.png +0 -0
- package/imgs/spike_sword.png +0 -0
- package/imgs/stone_holder.png +0 -0
- package/imgs/stone_sword.png +0 -0
- package/imgs/street_lamp.png +0 -0
- package/imgs/sword_1.png +0 -0
- package/imgs/sword_with_hole.png +0 -0
- package/imgs/testing.png +0 -0
- package/imgs/timer_tnt.png +0 -0
- package/imgs/tiny_tnt.png +0 -0
- package/imgs/tnt_cannon.png +0 -0
- package/imgs/wing_tnt.png +0 -0
- package/imgs/wooden_stool.png +0 -0
- package/imgs/wooden_wardrobe.png +0 -0
- package/index.html +178 -0
- package/index_admin.html +188 -0
- package/js/db/push_model.js +30 -0
- package/js/dialoges.js +23 -0
- package/js/item_functionality.js +7 -0
- package/js/load_cart.js +76 -0
- package/js/load_items.js +480 -0
- package/js/update.js +35 -0
- package/login.html +289 -0
- package/main.js +277 -0
- package/models/armchair.gltf +1 -0
- package/models/arrow_tnt.gltf +1 -0
- package/models/bedwnm.gltf +1 -0
- package/models/big_bed.gltf +1 -0
- package/models/birdscythe.gltf +1 -0
- package/models/blue_tnt.gltf +1 -0
- package/models/bull.gltf +1 -0
- package/models/carpet.gltf +1 -0
- package/models/chest.gltf +1 -0
- package/models/coin_stash.gltf +1 -0
- package/models/creeper_tnt.gltf +1 -0
- package/models/garbage_can.gltf +1 -0
- package/models/generator.gltf +1 -0
- package/models/golden_sword.gltf +1 -0
- package/models/highbed.gltf +1 -0
- package/models/jetpack1.gltf +1 -0
- package/models/jetpack2.gltf +1 -0
- package/models/jetpack3.gltf +1 -0
- package/models/jetpack4.gltf +1 -0
- package/models/jetpack5.gltf +1 -0
- package/models/jetpack6.gltf +1 -0
- package/models/karmincross.gltf +1 -0
- package/models/light_tnt.gltf +1 -0
- package/models/lucky_block.gltf +1 -0
- package/models/lucky_block_2.gltf +1 -0
- package/models/mega_tnt.gltf +1 -0
- package/models/modern_lamp.gltf +1 -0
- package/models/multiply_tnt.gltf +1 -0
- package/models/nuke.gltf +1 -0
- package/models/oak_tree.gltf +1 -0
- package/models/oak_tree_2.gltf +1 -0
- package/models/old globe.gltf +1 -0
- package/models/scificannon_1.gltf +1 -0
- package/models/scificannon_10.gltf +1 -0
- package/models/scificannon_11.gltf +1 -0
- package/models/scificannon_12.gltf +1 -0
- package/models/scificannon_13.gltf +1 -0
- package/models/scificannon_14.gltf +1 -0
- package/models/scificannon_2.gltf +1 -0
- package/models/scificannon_3.gltf +1 -0
- package/models/scificannon_4.gltf +1 -0
- package/models/scificannon_5.gltf +1 -0
- package/models/scificannon_6.gltf +1 -0
- package/models/scificannon_7.gltf +1 -0
- package/models/scificannon_8.gltf +1 -0
- package/models/scificannon_9.gltf +1 -0
- package/models/simple_chair.gltf +1 -0
- package/models/small_car.gltf +1 -0
- package/models/small_modern_lamp.gltf +1 -0
- package/models/small_wardrobe.gltf +1 -0
- package/models/small_wooden_table.gltf +1 -0
- package/models/spike_sword.gltf +1 -0
- package/models/stone_holder.gltf +1 -0
- package/models/stone_sword.gltf +1 -0
- package/models/street_lamp.gltf +1 -0
- package/models/sword_1.gltf +1 -0
- package/models/sword_with_hole.gltf +1 -0
- package/models/timer_tnt.gltf +1 -0
- package/models/tiny_tnt.gltf +1 -0
- package/models/tnt_cannon.gltf +1 -0
- package/models/wing_tnt.gltf +1 -0
- package/models/wooden_stool.gltf +1 -0
- package/models/wooden_wardrobe.gltf +1 -0
- package/package.json +47 -0
- package/preload.js +26 -0
- package/update.html +48 -0
@@ -0,0 +1,1252 @@
|
|
1
|
+
import {
|
2
|
+
EventDispatcher,
|
3
|
+
MOUSE,
|
4
|
+
Quaternion,
|
5
|
+
Spherical,
|
6
|
+
TOUCH,
|
7
|
+
Vector2,
|
8
|
+
Vector3
|
9
|
+
} from './three.module.js';
|
10
|
+
|
11
|
+
// This set of controls performs orbiting, dollying (zooming), and panning.
|
12
|
+
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
13
|
+
//
|
14
|
+
// Orbit - left mouse / touch: one-finger move
|
15
|
+
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
16
|
+
// Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
|
17
|
+
|
18
|
+
const _changeEvent = { type: 'change' };
|
19
|
+
const _startEvent = { type: 'start' };
|
20
|
+
const _endEvent = { type: 'end' };
|
21
|
+
|
22
|
+
class OrbitControls extends EventDispatcher {
|
23
|
+
|
24
|
+
constructor( object, domElement ) {
|
25
|
+
|
26
|
+
super();
|
27
|
+
|
28
|
+
if ( domElement === undefined ) console.warn( 'THREE.OrbitControls: The second parameter "domElement" is now mandatory.' );
|
29
|
+
if ( domElement === document ) console.error( 'THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.' );
|
30
|
+
|
31
|
+
this.object = object;
|
32
|
+
this.domElement = domElement;
|
33
|
+
this.domElement.style.touchAction = 'none'; // disable touch scroll
|
34
|
+
|
35
|
+
// Set to false to disable this control
|
36
|
+
this.enabled = true;
|
37
|
+
|
38
|
+
// "target" sets the location of focus, where the object orbits around
|
39
|
+
this.target = new Vector3();
|
40
|
+
|
41
|
+
// How far you can dolly in and out ( PerspectiveCamera only )
|
42
|
+
this.minDistance = 0;
|
43
|
+
this.maxDistance = Infinity;
|
44
|
+
|
45
|
+
// How far you can zoom in and out ( OrthographicCamera only )
|
46
|
+
this.minZoom = 0;
|
47
|
+
this.maxZoom = Infinity;
|
48
|
+
|
49
|
+
// How far you can orbit vertically, upper and lower limits.
|
50
|
+
// Range is 0 to Math.PI radians.
|
51
|
+
this.minPolarAngle = 0; // radians
|
52
|
+
this.maxPolarAngle = Math.PI; // radians
|
53
|
+
|
54
|
+
// How far you can orbit horizontally, upper and lower limits.
|
55
|
+
// If set, the interval [ min, max ] must be a sub-interval of [ - 2 PI, 2 PI ], with ( max - min < 2 PI )
|
56
|
+
this.minAzimuthAngle = - Infinity; // radians
|
57
|
+
this.maxAzimuthAngle = Infinity; // radians
|
58
|
+
|
59
|
+
// Set to true to enable damping (inertia)
|
60
|
+
// If damping is enabled, you must call controls.update() in your animation loop
|
61
|
+
this.enableDamping = false;
|
62
|
+
this.dampingFactor = 0.05;
|
63
|
+
|
64
|
+
// This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
|
65
|
+
// Set to false to disable zooming
|
66
|
+
this.enableZoom = true;
|
67
|
+
this.zoomSpeed = 1.0;
|
68
|
+
|
69
|
+
// Set to false to disable rotating
|
70
|
+
this.enableRotate = true;
|
71
|
+
this.rotateSpeed = 1.0;
|
72
|
+
|
73
|
+
// Set to false to disable panning
|
74
|
+
this.enablePan = true;
|
75
|
+
this.panSpeed = 1.0;
|
76
|
+
this.screenSpacePanning = true; // if false, pan orthogonal to world-space direction camera.up
|
77
|
+
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
|
78
|
+
|
79
|
+
// Set to true to automatically rotate around the target
|
80
|
+
// If auto-rotate is enabled, you must call controls.update() in your animation loop
|
81
|
+
this.autoRotate = false;
|
82
|
+
this.autoRotateSpeed = 2.0; // 30 seconds per orbit when fps is 60
|
83
|
+
|
84
|
+
// The four arrow keys
|
85
|
+
this.keys = { LEFT: 'ArrowLeft', UP: 'ArrowUp', RIGHT: 'ArrowRight', BOTTOM: 'ArrowDown' };
|
86
|
+
|
87
|
+
// Mouse buttons
|
88
|
+
this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN };
|
89
|
+
|
90
|
+
// Touch fingers
|
91
|
+
this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN };
|
92
|
+
|
93
|
+
// for reset
|
94
|
+
this.target0 = this.target.clone();
|
95
|
+
this.position0 = this.object.position.clone();
|
96
|
+
this.zoom0 = this.object.zoom;
|
97
|
+
|
98
|
+
// the target DOM element for key events
|
99
|
+
this._domElementKeyEvents = null;
|
100
|
+
|
101
|
+
//
|
102
|
+
// public methods
|
103
|
+
//
|
104
|
+
|
105
|
+
this.getPolarAngle = function () {
|
106
|
+
|
107
|
+
return spherical.phi;
|
108
|
+
|
109
|
+
};
|
110
|
+
|
111
|
+
this.getAzimuthalAngle = function () {
|
112
|
+
|
113
|
+
return spherical.theta;
|
114
|
+
|
115
|
+
};
|
116
|
+
|
117
|
+
this.getDistance = function () {
|
118
|
+
|
119
|
+
return this.object.position.distanceTo( this.target );
|
120
|
+
|
121
|
+
};
|
122
|
+
|
123
|
+
this.listenToKeyEvents = function ( domElement ) {
|
124
|
+
|
125
|
+
domElement.addEventListener( 'keydown', onKeyDown );
|
126
|
+
this._domElementKeyEvents = domElement;
|
127
|
+
|
128
|
+
};
|
129
|
+
|
130
|
+
this.saveState = function () {
|
131
|
+
|
132
|
+
scope.target0.copy( scope.target );
|
133
|
+
scope.position0.copy( scope.object.position );
|
134
|
+
scope.zoom0 = scope.object.zoom;
|
135
|
+
|
136
|
+
};
|
137
|
+
|
138
|
+
this.reset = function () {
|
139
|
+
|
140
|
+
scope.target.copy( scope.target0 );
|
141
|
+
scope.object.position.copy( scope.position0 );
|
142
|
+
scope.object.zoom = scope.zoom0;
|
143
|
+
|
144
|
+
scope.object.updateProjectionMatrix();
|
145
|
+
scope.dispatchEvent( _changeEvent );
|
146
|
+
|
147
|
+
scope.update();
|
148
|
+
|
149
|
+
state = STATE.NONE;
|
150
|
+
|
151
|
+
};
|
152
|
+
|
153
|
+
// this method is exposed, but perhaps it would be better if we can make it private...
|
154
|
+
this.update = function () {
|
155
|
+
|
156
|
+
const offset = new Vector3();
|
157
|
+
|
158
|
+
// so camera.up is the orbit axis
|
159
|
+
const quat = new Quaternion().setFromUnitVectors( object.up, new Vector3( 0, 1, 0 ) );
|
160
|
+
const quatInverse = quat.clone().invert();
|
161
|
+
|
162
|
+
const lastPosition = new Vector3();
|
163
|
+
const lastQuaternion = new Quaternion();
|
164
|
+
|
165
|
+
const twoPI = 2 * Math.PI;
|
166
|
+
|
167
|
+
return function update() {
|
168
|
+
|
169
|
+
const position = scope.object.position;
|
170
|
+
|
171
|
+
offset.copy( position ).sub( scope.target );
|
172
|
+
|
173
|
+
// rotate offset to "y-axis-is-up" space
|
174
|
+
offset.applyQuaternion( quat );
|
175
|
+
|
176
|
+
// angle from z-axis around y-axis
|
177
|
+
spherical.setFromVector3( offset );
|
178
|
+
|
179
|
+
if ( scope.autoRotate && state === STATE.NONE ) {
|
180
|
+
|
181
|
+
rotateLeft( getAutoRotationAngle() );
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
if ( scope.enableDamping ) {
|
186
|
+
|
187
|
+
spherical.theta += sphericalDelta.theta * scope.dampingFactor;
|
188
|
+
spherical.phi += sphericalDelta.phi * scope.dampingFactor;
|
189
|
+
|
190
|
+
} else {
|
191
|
+
|
192
|
+
spherical.theta += sphericalDelta.theta;
|
193
|
+
spherical.phi += sphericalDelta.phi;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
// restrict theta to be between desired limits
|
198
|
+
|
199
|
+
let min = scope.minAzimuthAngle;
|
200
|
+
let max = scope.maxAzimuthAngle;
|
201
|
+
|
202
|
+
if ( isFinite( min ) && isFinite( max ) ) {
|
203
|
+
|
204
|
+
if ( min < - Math.PI ) min += twoPI; else if ( min > Math.PI ) min -= twoPI;
|
205
|
+
|
206
|
+
if ( max < - Math.PI ) max += twoPI; else if ( max > Math.PI ) max -= twoPI;
|
207
|
+
|
208
|
+
if ( min <= max ) {
|
209
|
+
|
210
|
+
spherical.theta = Math.max( min, Math.min( max, spherical.theta ) );
|
211
|
+
|
212
|
+
} else {
|
213
|
+
|
214
|
+
spherical.theta = ( spherical.theta > ( min + max ) / 2 ) ?
|
215
|
+
Math.max( min, spherical.theta ) :
|
216
|
+
Math.min( max, spherical.theta );
|
217
|
+
|
218
|
+
}
|
219
|
+
|
220
|
+
}
|
221
|
+
|
222
|
+
// restrict phi to be between desired limits
|
223
|
+
spherical.phi = Math.max( scope.minPolarAngle, Math.min( scope.maxPolarAngle, spherical.phi ) );
|
224
|
+
|
225
|
+
spherical.makeSafe();
|
226
|
+
|
227
|
+
|
228
|
+
spherical.radius *= scale;
|
229
|
+
|
230
|
+
// restrict radius to be between desired limits
|
231
|
+
spherical.radius = Math.max( scope.minDistance, Math.min( scope.maxDistance, spherical.radius ) );
|
232
|
+
|
233
|
+
// move target to panned location
|
234
|
+
|
235
|
+
if ( scope.enableDamping === true ) {
|
236
|
+
|
237
|
+
scope.target.addScaledVector( panOffset, scope.dampingFactor );
|
238
|
+
|
239
|
+
} else {
|
240
|
+
|
241
|
+
scope.target.add( panOffset );
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
offset.setFromSpherical( spherical );
|
246
|
+
|
247
|
+
// rotate offset back to "camera-up-vector-is-up" space
|
248
|
+
offset.applyQuaternion( quatInverse );
|
249
|
+
|
250
|
+
position.copy( scope.target ).add( offset );
|
251
|
+
|
252
|
+
scope.object.lookAt( scope.target );
|
253
|
+
|
254
|
+
if ( scope.enableDamping === true ) {
|
255
|
+
|
256
|
+
sphericalDelta.theta *= ( 1 - scope.dampingFactor );
|
257
|
+
sphericalDelta.phi *= ( 1 - scope.dampingFactor );
|
258
|
+
|
259
|
+
panOffset.multiplyScalar( 1 - scope.dampingFactor );
|
260
|
+
|
261
|
+
} else {
|
262
|
+
|
263
|
+
sphericalDelta.set( 0, 0, 0 );
|
264
|
+
|
265
|
+
panOffset.set( 0, 0, 0 );
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
scale = 1;
|
270
|
+
|
271
|
+
// update condition is:
|
272
|
+
// min(camera displacement, camera rotation in radians)^2 > EPS
|
273
|
+
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
274
|
+
|
275
|
+
if ( zoomChanged ||
|
276
|
+
lastPosition.distanceToSquared( scope.object.position ) > EPS ||
|
277
|
+
8 * ( 1 - lastQuaternion.dot( scope.object.quaternion ) ) > EPS ) {
|
278
|
+
|
279
|
+
scope.dispatchEvent( _changeEvent );
|
280
|
+
|
281
|
+
lastPosition.copy( scope.object.position );
|
282
|
+
lastQuaternion.copy( scope.object.quaternion );
|
283
|
+
zoomChanged = false;
|
284
|
+
|
285
|
+
return true;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
return false;
|
290
|
+
|
291
|
+
};
|
292
|
+
|
293
|
+
}();
|
294
|
+
|
295
|
+
this.dispose = function () {
|
296
|
+
|
297
|
+
scope.domElement.removeEventListener( 'contextmenu', onContextMenu );
|
298
|
+
|
299
|
+
scope.domElement.removeEventListener( 'pointerdown', onPointerDown );
|
300
|
+
scope.domElement.removeEventListener( 'pointercancel', onPointerCancel );
|
301
|
+
scope.domElement.removeEventListener( 'wheel', onMouseWheel );
|
302
|
+
|
303
|
+
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
304
|
+
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
305
|
+
|
306
|
+
|
307
|
+
if ( scope._domElementKeyEvents !== null ) {
|
308
|
+
|
309
|
+
scope._domElementKeyEvents.removeEventListener( 'keydown', onKeyDown );
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
//scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
|
314
|
+
|
315
|
+
};
|
316
|
+
|
317
|
+
//
|
318
|
+
// internals
|
319
|
+
//
|
320
|
+
|
321
|
+
const scope = this;
|
322
|
+
|
323
|
+
const STATE = {
|
324
|
+
NONE: - 1,
|
325
|
+
ROTATE: 0,
|
326
|
+
DOLLY: 1,
|
327
|
+
PAN: 2,
|
328
|
+
TOUCH_ROTATE: 3,
|
329
|
+
TOUCH_PAN: 4,
|
330
|
+
TOUCH_DOLLY_PAN: 5,
|
331
|
+
TOUCH_DOLLY_ROTATE: 6
|
332
|
+
};
|
333
|
+
|
334
|
+
let state = STATE.NONE;
|
335
|
+
|
336
|
+
const EPS = 0.000001;
|
337
|
+
|
338
|
+
// current position in spherical coordinates
|
339
|
+
const spherical = new Spherical();
|
340
|
+
const sphericalDelta = new Spherical();
|
341
|
+
|
342
|
+
let scale = 1;
|
343
|
+
const panOffset = new Vector3();
|
344
|
+
let zoomChanged = false;
|
345
|
+
|
346
|
+
const rotateStart = new Vector2();
|
347
|
+
const rotateEnd = new Vector2();
|
348
|
+
const rotateDelta = new Vector2();
|
349
|
+
|
350
|
+
const panStart = new Vector2();
|
351
|
+
const panEnd = new Vector2();
|
352
|
+
const panDelta = new Vector2();
|
353
|
+
|
354
|
+
const dollyStart = new Vector2();
|
355
|
+
const dollyEnd = new Vector2();
|
356
|
+
const dollyDelta = new Vector2();
|
357
|
+
|
358
|
+
const pointers = [];
|
359
|
+
const pointerPositions = {};
|
360
|
+
|
361
|
+
function getAutoRotationAngle() {
|
362
|
+
|
363
|
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
function getZoomScale() {
|
368
|
+
|
369
|
+
return Math.pow( 0.95, scope.zoomSpeed );
|
370
|
+
|
371
|
+
}
|
372
|
+
|
373
|
+
function rotateLeft( angle ) {
|
374
|
+
|
375
|
+
sphericalDelta.theta -= angle;
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
function rotateUp( angle ) {
|
380
|
+
|
381
|
+
sphericalDelta.phi -= angle;
|
382
|
+
|
383
|
+
}
|
384
|
+
|
385
|
+
const panLeft = function () {
|
386
|
+
|
387
|
+
const v = new Vector3();
|
388
|
+
|
389
|
+
return function panLeft( distance, objectMatrix ) {
|
390
|
+
|
391
|
+
v.setFromMatrixColumn( objectMatrix, 0 ); // get X column of objectMatrix
|
392
|
+
v.multiplyScalar( - distance );
|
393
|
+
|
394
|
+
panOffset.add( v );
|
395
|
+
|
396
|
+
};
|
397
|
+
|
398
|
+
}();
|
399
|
+
|
400
|
+
const panUp = function () {
|
401
|
+
|
402
|
+
const v = new Vector3();
|
403
|
+
|
404
|
+
return function panUp( distance, objectMatrix ) {
|
405
|
+
|
406
|
+
if ( scope.screenSpacePanning === true ) {
|
407
|
+
|
408
|
+
v.setFromMatrixColumn( objectMatrix, 1 );
|
409
|
+
|
410
|
+
} else {
|
411
|
+
|
412
|
+
v.setFromMatrixColumn( objectMatrix, 0 );
|
413
|
+
v.crossVectors( scope.object.up, v );
|
414
|
+
|
415
|
+
}
|
416
|
+
|
417
|
+
v.multiplyScalar( distance );
|
418
|
+
|
419
|
+
panOffset.add( v );
|
420
|
+
|
421
|
+
};
|
422
|
+
|
423
|
+
}();
|
424
|
+
|
425
|
+
// deltaX and deltaY are in pixels; right and down are positive
|
426
|
+
const pan = function () {
|
427
|
+
|
428
|
+
const offset = new Vector3();
|
429
|
+
|
430
|
+
return function pan( deltaX, deltaY ) {
|
431
|
+
|
432
|
+
const element = scope.domElement;
|
433
|
+
|
434
|
+
if ( scope.object.isPerspectiveCamera ) {
|
435
|
+
|
436
|
+
// perspective
|
437
|
+
const position = scope.object.position;
|
438
|
+
offset.copy( position ).sub( scope.target );
|
439
|
+
let targetDistance = offset.length();
|
440
|
+
|
441
|
+
// half of the fov is center to top of screen
|
442
|
+
targetDistance *= Math.tan( ( scope.object.fov / 2 ) * Math.PI / 180.0 );
|
443
|
+
|
444
|
+
// we use only clientHeight here so aspect ratio does not distort speed
|
445
|
+
panLeft( 2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix );
|
446
|
+
panUp( 2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix );
|
447
|
+
|
448
|
+
} else if ( scope.object.isOrthographicCamera ) {
|
449
|
+
|
450
|
+
// orthographic
|
451
|
+
panLeft( deltaX * ( scope.object.right - scope.object.left ) / scope.object.zoom / element.clientWidth, scope.object.matrix );
|
452
|
+
panUp( deltaY * ( scope.object.top - scope.object.bottom ) / scope.object.zoom / element.clientHeight, scope.object.matrix );
|
453
|
+
|
454
|
+
} else {
|
455
|
+
|
456
|
+
// camera neither orthographic nor perspective
|
457
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.' );
|
458
|
+
scope.enablePan = false;
|
459
|
+
|
460
|
+
}
|
461
|
+
|
462
|
+
};
|
463
|
+
|
464
|
+
}();
|
465
|
+
|
466
|
+
function dollyOut( dollyScale ) {
|
467
|
+
|
468
|
+
if ( scope.object.isPerspectiveCamera ) {
|
469
|
+
|
470
|
+
scale /= dollyScale;
|
471
|
+
|
472
|
+
} else if ( scope.object.isOrthographicCamera ) {
|
473
|
+
|
474
|
+
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom * dollyScale ) );
|
475
|
+
scope.object.updateProjectionMatrix();
|
476
|
+
zoomChanged = true;
|
477
|
+
|
478
|
+
} else {
|
479
|
+
|
480
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
481
|
+
scope.enableZoom = false;
|
482
|
+
|
483
|
+
}
|
484
|
+
|
485
|
+
}
|
486
|
+
|
487
|
+
function dollyIn( dollyScale ) {
|
488
|
+
|
489
|
+
if ( scope.object.isPerspectiveCamera ) {
|
490
|
+
|
491
|
+
scale *= dollyScale;
|
492
|
+
|
493
|
+
} else if ( scope.object.isOrthographicCamera ) {
|
494
|
+
|
495
|
+
scope.object.zoom = Math.max( scope.minZoom, Math.min( scope.maxZoom, scope.object.zoom / dollyScale ) );
|
496
|
+
scope.object.updateProjectionMatrix();
|
497
|
+
zoomChanged = true;
|
498
|
+
|
499
|
+
} else {
|
500
|
+
|
501
|
+
console.warn( 'WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.' );
|
502
|
+
scope.enableZoom = false;
|
503
|
+
|
504
|
+
}
|
505
|
+
|
506
|
+
}
|
507
|
+
|
508
|
+
//
|
509
|
+
// event callbacks - update the object state
|
510
|
+
//
|
511
|
+
|
512
|
+
function handleMouseDownRotate( event ) {
|
513
|
+
|
514
|
+
rotateStart.set( event.clientX, event.clientY );
|
515
|
+
|
516
|
+
}
|
517
|
+
|
518
|
+
function handleMouseDownDolly( event ) {
|
519
|
+
|
520
|
+
dollyStart.set( event.clientX, event.clientY );
|
521
|
+
|
522
|
+
}
|
523
|
+
|
524
|
+
function handleMouseDownPan( event ) {
|
525
|
+
|
526
|
+
panStart.set( event.clientX, event.clientY );
|
527
|
+
|
528
|
+
}
|
529
|
+
|
530
|
+
function handleMouseMoveRotate( event ) {
|
531
|
+
|
532
|
+
rotateEnd.set( event.clientX, event.clientY );
|
533
|
+
|
534
|
+
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
535
|
+
|
536
|
+
const element = scope.domElement;
|
537
|
+
|
538
|
+
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
539
|
+
|
540
|
+
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
541
|
+
|
542
|
+
rotateStart.copy( rotateEnd );
|
543
|
+
|
544
|
+
scope.update();
|
545
|
+
|
546
|
+
}
|
547
|
+
|
548
|
+
function handleMouseMoveDolly( event ) {
|
549
|
+
|
550
|
+
dollyEnd.set( event.clientX, event.clientY );
|
551
|
+
|
552
|
+
dollyDelta.subVectors( dollyEnd, dollyStart );
|
553
|
+
|
554
|
+
if ( dollyDelta.y > 0 ) {
|
555
|
+
|
556
|
+
dollyOut( getZoomScale() );
|
557
|
+
|
558
|
+
} else if ( dollyDelta.y < 0 ) {
|
559
|
+
|
560
|
+
dollyIn( getZoomScale() );
|
561
|
+
|
562
|
+
}
|
563
|
+
|
564
|
+
dollyStart.copy( dollyEnd );
|
565
|
+
|
566
|
+
scope.update();
|
567
|
+
|
568
|
+
}
|
569
|
+
|
570
|
+
function handleMouseMovePan( event ) {
|
571
|
+
|
572
|
+
panEnd.set( event.clientX, event.clientY );
|
573
|
+
|
574
|
+
panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
|
575
|
+
|
576
|
+
pan( panDelta.x, panDelta.y );
|
577
|
+
|
578
|
+
panStart.copy( panEnd );
|
579
|
+
|
580
|
+
scope.update();
|
581
|
+
|
582
|
+
}
|
583
|
+
|
584
|
+
function handleMouseWheel( event ) {
|
585
|
+
|
586
|
+
if ( event.deltaY < 0 ) {
|
587
|
+
|
588
|
+
dollyIn( getZoomScale() );
|
589
|
+
|
590
|
+
} else if ( event.deltaY > 0 ) {
|
591
|
+
|
592
|
+
dollyOut( getZoomScale() );
|
593
|
+
|
594
|
+
}
|
595
|
+
|
596
|
+
scope.update();
|
597
|
+
|
598
|
+
}
|
599
|
+
|
600
|
+
function handleKeyDown( event ) {
|
601
|
+
|
602
|
+
let needsUpdate = false;
|
603
|
+
|
604
|
+
switch ( event.code ) {
|
605
|
+
|
606
|
+
case scope.keys.UP:
|
607
|
+
pan( 0, scope.keyPanSpeed );
|
608
|
+
needsUpdate = true;
|
609
|
+
break;
|
610
|
+
|
611
|
+
case scope.keys.BOTTOM:
|
612
|
+
pan( 0, - scope.keyPanSpeed );
|
613
|
+
needsUpdate = true;
|
614
|
+
break;
|
615
|
+
|
616
|
+
case scope.keys.LEFT:
|
617
|
+
pan( scope.keyPanSpeed, 0 );
|
618
|
+
needsUpdate = true;
|
619
|
+
break;
|
620
|
+
|
621
|
+
case scope.keys.RIGHT:
|
622
|
+
pan( - scope.keyPanSpeed, 0 );
|
623
|
+
needsUpdate = true;
|
624
|
+
break;
|
625
|
+
|
626
|
+
}
|
627
|
+
|
628
|
+
if ( needsUpdate ) {
|
629
|
+
|
630
|
+
// prevent the browser from scrolling on cursor keys
|
631
|
+
event.preventDefault();
|
632
|
+
|
633
|
+
scope.update();
|
634
|
+
|
635
|
+
}
|
636
|
+
|
637
|
+
|
638
|
+
}
|
639
|
+
|
640
|
+
function handleTouchStartRotate() {
|
641
|
+
|
642
|
+
if ( pointers.length === 1 ) {
|
643
|
+
|
644
|
+
rotateStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
|
645
|
+
|
646
|
+
} else {
|
647
|
+
|
648
|
+
const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
|
649
|
+
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
|
650
|
+
|
651
|
+
rotateStart.set( x, y );
|
652
|
+
|
653
|
+
}
|
654
|
+
|
655
|
+
}
|
656
|
+
|
657
|
+
function handleTouchStartPan() {
|
658
|
+
|
659
|
+
if ( pointers.length === 1 ) {
|
660
|
+
|
661
|
+
panStart.set( pointers[ 0 ].pageX, pointers[ 0 ].pageY );
|
662
|
+
|
663
|
+
} else {
|
664
|
+
|
665
|
+
const x = 0.5 * ( pointers[ 0 ].pageX + pointers[ 1 ].pageX );
|
666
|
+
const y = 0.5 * ( pointers[ 0 ].pageY + pointers[ 1 ].pageY );
|
667
|
+
|
668
|
+
panStart.set( x, y );
|
669
|
+
|
670
|
+
}
|
671
|
+
|
672
|
+
}
|
673
|
+
|
674
|
+
function handleTouchStartDolly() {
|
675
|
+
|
676
|
+
const dx = pointers[ 0 ].pageX - pointers[ 1 ].pageX;
|
677
|
+
const dy = pointers[ 0 ].pageY - pointers[ 1 ].pageY;
|
678
|
+
|
679
|
+
const distance = Math.sqrt( dx * dx + dy * dy );
|
680
|
+
|
681
|
+
dollyStart.set( 0, distance );
|
682
|
+
|
683
|
+
}
|
684
|
+
|
685
|
+
function handleTouchStartDollyPan() {
|
686
|
+
|
687
|
+
if ( scope.enableZoom ) handleTouchStartDolly();
|
688
|
+
|
689
|
+
if ( scope.enablePan ) handleTouchStartPan();
|
690
|
+
|
691
|
+
}
|
692
|
+
|
693
|
+
function handleTouchStartDollyRotate() {
|
694
|
+
|
695
|
+
if ( scope.enableZoom ) handleTouchStartDolly();
|
696
|
+
|
697
|
+
if ( scope.enableRotate ) handleTouchStartRotate();
|
698
|
+
|
699
|
+
}
|
700
|
+
|
701
|
+
function handleTouchMoveRotate( event ) {
|
702
|
+
|
703
|
+
if ( pointers.length == 1 ) {
|
704
|
+
|
705
|
+
rotateEnd.set( event.pageX, event.pageY );
|
706
|
+
|
707
|
+
} else {
|
708
|
+
|
709
|
+
const position = getSecondPointerPosition( event );
|
710
|
+
|
711
|
+
const x = 0.5 * ( event.pageX + position.x );
|
712
|
+
const y = 0.5 * ( event.pageY + position.y );
|
713
|
+
|
714
|
+
rotateEnd.set( x, y );
|
715
|
+
|
716
|
+
}
|
717
|
+
|
718
|
+
rotateDelta.subVectors( rotateEnd, rotateStart ).multiplyScalar( scope.rotateSpeed );
|
719
|
+
|
720
|
+
const element = scope.domElement;
|
721
|
+
|
722
|
+
rotateLeft( 2 * Math.PI * rotateDelta.x / element.clientHeight ); // yes, height
|
723
|
+
|
724
|
+
rotateUp( 2 * Math.PI * rotateDelta.y / element.clientHeight );
|
725
|
+
|
726
|
+
rotateStart.copy( rotateEnd );
|
727
|
+
|
728
|
+
}
|
729
|
+
|
730
|
+
function handleTouchMovePan( event ) {
|
731
|
+
|
732
|
+
if ( pointers.length === 1 ) {
|
733
|
+
|
734
|
+
panEnd.set( event.pageX, event.pageY );
|
735
|
+
|
736
|
+
} else {
|
737
|
+
|
738
|
+
const position = getSecondPointerPosition( event );
|
739
|
+
|
740
|
+
const x = 0.5 * ( event.pageX + position.x );
|
741
|
+
const y = 0.5 * ( event.pageY + position.y );
|
742
|
+
|
743
|
+
panEnd.set( x, y );
|
744
|
+
|
745
|
+
}
|
746
|
+
|
747
|
+
panDelta.subVectors( panEnd, panStart ).multiplyScalar( scope.panSpeed );
|
748
|
+
|
749
|
+
pan( panDelta.x, panDelta.y );
|
750
|
+
|
751
|
+
panStart.copy( panEnd );
|
752
|
+
|
753
|
+
}
|
754
|
+
|
755
|
+
function handleTouchMoveDolly( event ) {
|
756
|
+
|
757
|
+
const position = getSecondPointerPosition( event );
|
758
|
+
|
759
|
+
const dx = event.pageX - position.x;
|
760
|
+
const dy = event.pageY - position.y;
|
761
|
+
|
762
|
+
const distance = Math.sqrt( dx * dx + dy * dy );
|
763
|
+
|
764
|
+
dollyEnd.set( 0, distance );
|
765
|
+
|
766
|
+
dollyDelta.set( 0, Math.pow( dollyEnd.y / dollyStart.y, scope.zoomSpeed ) );
|
767
|
+
|
768
|
+
dollyOut( dollyDelta.y );
|
769
|
+
|
770
|
+
dollyStart.copy( dollyEnd );
|
771
|
+
|
772
|
+
}
|
773
|
+
|
774
|
+
function handleTouchMoveDollyPan( event ) {
|
775
|
+
|
776
|
+
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
777
|
+
|
778
|
+
if ( scope.enablePan ) handleTouchMovePan( event );
|
779
|
+
|
780
|
+
}
|
781
|
+
|
782
|
+
function handleTouchMoveDollyRotate( event ) {
|
783
|
+
|
784
|
+
if ( scope.enableZoom ) handleTouchMoveDolly( event );
|
785
|
+
|
786
|
+
if ( scope.enableRotate ) handleTouchMoveRotate( event );
|
787
|
+
|
788
|
+
}
|
789
|
+
|
790
|
+
//
|
791
|
+
// event handlers - FSM: listen for events and reset state
|
792
|
+
//
|
793
|
+
|
794
|
+
function onPointerDown( event ) {
|
795
|
+
|
796
|
+
if ( scope.enabled === false ) return;
|
797
|
+
|
798
|
+
if ( pointers.length === 0 ) {
|
799
|
+
|
800
|
+
scope.domElement.setPointerCapture( event.pointerId );
|
801
|
+
|
802
|
+
scope.domElement.addEventListener( 'pointermove', onPointerMove );
|
803
|
+
scope.domElement.addEventListener( 'pointerup', onPointerUp );
|
804
|
+
|
805
|
+
}
|
806
|
+
|
807
|
+
//
|
808
|
+
|
809
|
+
addPointer( event );
|
810
|
+
|
811
|
+
if ( event.pointerType === 'touch' ) {
|
812
|
+
|
813
|
+
onTouchStart( event );
|
814
|
+
|
815
|
+
} else {
|
816
|
+
|
817
|
+
onMouseDown( event );
|
818
|
+
|
819
|
+
}
|
820
|
+
|
821
|
+
}
|
822
|
+
|
823
|
+
function onPointerMove( event ) {
|
824
|
+
|
825
|
+
if ( scope.enabled === false ) return;
|
826
|
+
|
827
|
+
if ( event.pointerType === 'touch' ) {
|
828
|
+
|
829
|
+
onTouchMove( event );
|
830
|
+
|
831
|
+
} else {
|
832
|
+
|
833
|
+
onMouseMove( event );
|
834
|
+
|
835
|
+
}
|
836
|
+
|
837
|
+
}
|
838
|
+
|
839
|
+
function onPointerUp( event ) {
|
840
|
+
|
841
|
+
removePointer( event );
|
842
|
+
|
843
|
+
if ( pointers.length === 0 ) {
|
844
|
+
|
845
|
+
scope.domElement.releasePointerCapture( event.pointerId );
|
846
|
+
|
847
|
+
scope.domElement.removeEventListener( 'pointermove', onPointerMove );
|
848
|
+
scope.domElement.removeEventListener( 'pointerup', onPointerUp );
|
849
|
+
|
850
|
+
}
|
851
|
+
|
852
|
+
scope.dispatchEvent( _endEvent );
|
853
|
+
|
854
|
+
state = STATE.NONE;
|
855
|
+
|
856
|
+
}
|
857
|
+
|
858
|
+
function onPointerCancel( event ) {
|
859
|
+
|
860
|
+
removePointer( event );
|
861
|
+
|
862
|
+
}
|
863
|
+
|
864
|
+
function onMouseDown( event ) {
|
865
|
+
|
866
|
+
let mouseAction;
|
867
|
+
|
868
|
+
switch ( event.button ) {
|
869
|
+
|
870
|
+
case 0:
|
871
|
+
|
872
|
+
mouseAction = scope.mouseButtons.LEFT;
|
873
|
+
break;
|
874
|
+
|
875
|
+
case 1:
|
876
|
+
|
877
|
+
mouseAction = scope.mouseButtons.MIDDLE;
|
878
|
+
break;
|
879
|
+
|
880
|
+
case 2:
|
881
|
+
|
882
|
+
mouseAction = scope.mouseButtons.RIGHT;
|
883
|
+
break;
|
884
|
+
|
885
|
+
default:
|
886
|
+
|
887
|
+
mouseAction = - 1;
|
888
|
+
|
889
|
+
}
|
890
|
+
|
891
|
+
switch ( mouseAction ) {
|
892
|
+
|
893
|
+
case MOUSE.DOLLY:
|
894
|
+
|
895
|
+
if ( scope.enableZoom === false ) return;
|
896
|
+
|
897
|
+
handleMouseDownDolly( event );
|
898
|
+
|
899
|
+
state = STATE.DOLLY;
|
900
|
+
|
901
|
+
break;
|
902
|
+
|
903
|
+
case MOUSE.ROTATE:
|
904
|
+
|
905
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
906
|
+
|
907
|
+
if ( scope.enablePan === false ) return;
|
908
|
+
|
909
|
+
handleMouseDownPan( event );
|
910
|
+
|
911
|
+
state = STATE.PAN;
|
912
|
+
|
913
|
+
} else {
|
914
|
+
|
915
|
+
if ( scope.enableRotate === false ) return;
|
916
|
+
|
917
|
+
handleMouseDownRotate( event );
|
918
|
+
|
919
|
+
state = STATE.ROTATE;
|
920
|
+
|
921
|
+
}
|
922
|
+
|
923
|
+
break;
|
924
|
+
|
925
|
+
case MOUSE.PAN:
|
926
|
+
|
927
|
+
if ( event.ctrlKey || event.metaKey || event.shiftKey ) {
|
928
|
+
|
929
|
+
if ( scope.enableRotate === false ) return;
|
930
|
+
|
931
|
+
handleMouseDownRotate( event );
|
932
|
+
|
933
|
+
state = STATE.ROTATE;
|
934
|
+
|
935
|
+
} else {
|
936
|
+
|
937
|
+
if ( scope.enablePan === false ) return;
|
938
|
+
|
939
|
+
handleMouseDownPan( event );
|
940
|
+
|
941
|
+
state = STATE.PAN;
|
942
|
+
|
943
|
+
}
|
944
|
+
|
945
|
+
break;
|
946
|
+
|
947
|
+
default:
|
948
|
+
|
949
|
+
state = STATE.NONE;
|
950
|
+
|
951
|
+
}
|
952
|
+
|
953
|
+
if ( state !== STATE.NONE ) {
|
954
|
+
|
955
|
+
scope.dispatchEvent( _startEvent );
|
956
|
+
|
957
|
+
}
|
958
|
+
|
959
|
+
}
|
960
|
+
|
961
|
+
function onMouseMove( event ) {
|
962
|
+
|
963
|
+
if ( scope.enabled === false ) return;
|
964
|
+
|
965
|
+
switch ( state ) {
|
966
|
+
|
967
|
+
case STATE.ROTATE:
|
968
|
+
|
969
|
+
if ( scope.enableRotate === false ) return;
|
970
|
+
|
971
|
+
handleMouseMoveRotate( event );
|
972
|
+
|
973
|
+
break;
|
974
|
+
|
975
|
+
case STATE.DOLLY:
|
976
|
+
|
977
|
+
if ( scope.enableZoom === false ) return;
|
978
|
+
|
979
|
+
handleMouseMoveDolly( event );
|
980
|
+
|
981
|
+
break;
|
982
|
+
|
983
|
+
case STATE.PAN:
|
984
|
+
|
985
|
+
if ( scope.enablePan === false ) return;
|
986
|
+
|
987
|
+
handleMouseMovePan( event );
|
988
|
+
|
989
|
+
break;
|
990
|
+
|
991
|
+
}
|
992
|
+
|
993
|
+
}
|
994
|
+
|
995
|
+
function onMouseWheel( event ) {
|
996
|
+
|
997
|
+
if ( scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE ) return;
|
998
|
+
|
999
|
+
event.preventDefault();
|
1000
|
+
|
1001
|
+
scope.dispatchEvent( _startEvent );
|
1002
|
+
|
1003
|
+
handleMouseWheel( event );
|
1004
|
+
|
1005
|
+
scope.dispatchEvent( _endEvent );
|
1006
|
+
|
1007
|
+
}
|
1008
|
+
|
1009
|
+
function onKeyDown( event ) {
|
1010
|
+
|
1011
|
+
if ( scope.enabled === false || scope.enablePan === false ) return;
|
1012
|
+
|
1013
|
+
handleKeyDown( event );
|
1014
|
+
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
function onTouchStart( event ) {
|
1018
|
+
|
1019
|
+
trackPointer( event );
|
1020
|
+
|
1021
|
+
switch ( pointers.length ) {
|
1022
|
+
|
1023
|
+
case 1:
|
1024
|
+
|
1025
|
+
switch ( scope.touches.ONE ) {
|
1026
|
+
|
1027
|
+
case TOUCH.ROTATE:
|
1028
|
+
|
1029
|
+
if ( scope.enableRotate === false ) return;
|
1030
|
+
|
1031
|
+
handleTouchStartRotate();
|
1032
|
+
|
1033
|
+
state = STATE.TOUCH_ROTATE;
|
1034
|
+
|
1035
|
+
break;
|
1036
|
+
|
1037
|
+
case TOUCH.PAN:
|
1038
|
+
|
1039
|
+
if ( scope.enablePan === false ) return;
|
1040
|
+
|
1041
|
+
handleTouchStartPan();
|
1042
|
+
|
1043
|
+
state = STATE.TOUCH_PAN;
|
1044
|
+
|
1045
|
+
break;
|
1046
|
+
|
1047
|
+
default:
|
1048
|
+
|
1049
|
+
state = STATE.NONE;
|
1050
|
+
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
break;
|
1054
|
+
|
1055
|
+
case 2:
|
1056
|
+
|
1057
|
+
switch ( scope.touches.TWO ) {
|
1058
|
+
|
1059
|
+
case TOUCH.DOLLY_PAN:
|
1060
|
+
|
1061
|
+
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
1062
|
+
|
1063
|
+
handleTouchStartDollyPan();
|
1064
|
+
|
1065
|
+
state = STATE.TOUCH_DOLLY_PAN;
|
1066
|
+
|
1067
|
+
break;
|
1068
|
+
|
1069
|
+
case TOUCH.DOLLY_ROTATE:
|
1070
|
+
|
1071
|
+
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
1072
|
+
|
1073
|
+
handleTouchStartDollyRotate();
|
1074
|
+
|
1075
|
+
state = STATE.TOUCH_DOLLY_ROTATE;
|
1076
|
+
|
1077
|
+
break;
|
1078
|
+
|
1079
|
+
default:
|
1080
|
+
|
1081
|
+
state = STATE.NONE;
|
1082
|
+
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
break;
|
1086
|
+
|
1087
|
+
default:
|
1088
|
+
|
1089
|
+
state = STATE.NONE;
|
1090
|
+
|
1091
|
+
}
|
1092
|
+
|
1093
|
+
if ( state !== STATE.NONE ) {
|
1094
|
+
|
1095
|
+
scope.dispatchEvent( _startEvent );
|
1096
|
+
|
1097
|
+
}
|
1098
|
+
|
1099
|
+
}
|
1100
|
+
|
1101
|
+
function onTouchMove( event ) {
|
1102
|
+
|
1103
|
+
trackPointer( event );
|
1104
|
+
|
1105
|
+
switch ( state ) {
|
1106
|
+
|
1107
|
+
case STATE.TOUCH_ROTATE:
|
1108
|
+
|
1109
|
+
if ( scope.enableRotate === false ) return;
|
1110
|
+
|
1111
|
+
handleTouchMoveRotate( event );
|
1112
|
+
|
1113
|
+
scope.update();
|
1114
|
+
|
1115
|
+
break;
|
1116
|
+
|
1117
|
+
case STATE.TOUCH_PAN:
|
1118
|
+
|
1119
|
+
if ( scope.enablePan === false ) return;
|
1120
|
+
|
1121
|
+
handleTouchMovePan( event );
|
1122
|
+
|
1123
|
+
scope.update();
|
1124
|
+
|
1125
|
+
break;
|
1126
|
+
|
1127
|
+
case STATE.TOUCH_DOLLY_PAN:
|
1128
|
+
|
1129
|
+
if ( scope.enableZoom === false && scope.enablePan === false ) return;
|
1130
|
+
|
1131
|
+
handleTouchMoveDollyPan( event );
|
1132
|
+
|
1133
|
+
scope.update();
|
1134
|
+
|
1135
|
+
break;
|
1136
|
+
|
1137
|
+
case STATE.TOUCH_DOLLY_ROTATE:
|
1138
|
+
|
1139
|
+
if ( scope.enableZoom === false && scope.enableRotate === false ) return;
|
1140
|
+
|
1141
|
+
handleTouchMoveDollyRotate( event );
|
1142
|
+
|
1143
|
+
scope.update();
|
1144
|
+
|
1145
|
+
break;
|
1146
|
+
|
1147
|
+
default:
|
1148
|
+
|
1149
|
+
state = STATE.NONE;
|
1150
|
+
|
1151
|
+
}
|
1152
|
+
|
1153
|
+
}
|
1154
|
+
|
1155
|
+
function onContextMenu( event ) {
|
1156
|
+
|
1157
|
+
if ( scope.enabled === false ) return;
|
1158
|
+
|
1159
|
+
event.preventDefault();
|
1160
|
+
|
1161
|
+
}
|
1162
|
+
|
1163
|
+
function addPointer( event ) {
|
1164
|
+
|
1165
|
+
pointers.push( event );
|
1166
|
+
|
1167
|
+
}
|
1168
|
+
|
1169
|
+
function removePointer( event ) {
|
1170
|
+
|
1171
|
+
delete pointerPositions[ event.pointerId ];
|
1172
|
+
|
1173
|
+
for ( let i = 0; i < pointers.length; i ++ ) {
|
1174
|
+
|
1175
|
+
if ( pointers[ i ].pointerId == event.pointerId ) {
|
1176
|
+
|
1177
|
+
pointers.splice( i, 1 );
|
1178
|
+
return;
|
1179
|
+
|
1180
|
+
}
|
1181
|
+
|
1182
|
+
}
|
1183
|
+
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
function trackPointer( event ) {
|
1187
|
+
|
1188
|
+
let position = pointerPositions[ event.pointerId ];
|
1189
|
+
|
1190
|
+
if ( position === undefined ) {
|
1191
|
+
|
1192
|
+
position = new Vector2();
|
1193
|
+
pointerPositions[ event.pointerId ] = position;
|
1194
|
+
|
1195
|
+
}
|
1196
|
+
|
1197
|
+
position.set( event.pageX, event.pageY );
|
1198
|
+
|
1199
|
+
}
|
1200
|
+
|
1201
|
+
function getSecondPointerPosition( event ) {
|
1202
|
+
|
1203
|
+
const pointer = ( event.pointerId === pointers[ 0 ].pointerId ) ? pointers[ 1 ] : pointers[ 0 ];
|
1204
|
+
|
1205
|
+
return pointerPositions[ pointer.pointerId ];
|
1206
|
+
|
1207
|
+
}
|
1208
|
+
|
1209
|
+
//
|
1210
|
+
|
1211
|
+
scope.domElement.addEventListener( 'contextmenu', onContextMenu );
|
1212
|
+
|
1213
|
+
scope.domElement.addEventListener( 'pointerdown', onPointerDown );
|
1214
|
+
scope.domElement.addEventListener( 'pointercancel', onPointerCancel );
|
1215
|
+
scope.domElement.addEventListener( 'wheel', onMouseWheel, { passive: false } );
|
1216
|
+
|
1217
|
+
// force an update at start
|
1218
|
+
|
1219
|
+
this.update();
|
1220
|
+
|
1221
|
+
}
|
1222
|
+
|
1223
|
+
}
|
1224
|
+
|
1225
|
+
|
1226
|
+
// This set of controls performs orbiting, dollying (zooming), and panning.
|
1227
|
+
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
1228
|
+
// This is very similar to OrbitControls, another set of touch behavior
|
1229
|
+
//
|
1230
|
+
// Orbit - right mouse, or left mouse + ctrl/meta/shiftKey / touch: two-finger rotate
|
1231
|
+
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
1232
|
+
// Pan - left mouse, or arrow keys / touch: one-finger move
|
1233
|
+
|
1234
|
+
class MapControls extends OrbitControls {
|
1235
|
+
|
1236
|
+
constructor( object, domElement ) {
|
1237
|
+
|
1238
|
+
super( object, domElement );
|
1239
|
+
|
1240
|
+
this.screenSpacePanning = false; // pan orthogonal to world-space direction camera.up
|
1241
|
+
|
1242
|
+
this.mouseButtons.LEFT = MOUSE.PAN;
|
1243
|
+
this.mouseButtons.RIGHT = MOUSE.ROTATE;
|
1244
|
+
|
1245
|
+
this.touches.ONE = TOUCH.PAN;
|
1246
|
+
this.touches.TWO = TOUCH.DOLLY_ROTATE;
|
1247
|
+
|
1248
|
+
}
|
1249
|
+
|
1250
|
+
}
|
1251
|
+
|
1252
|
+
export { OrbitControls, MapControls };
|