@ifiwas/standard-view 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/.prettierignore +67 -0
  2. package/.prettierrc +12 -0
  3. package/CHANGELOG.md +42 -0
  4. package/LICENSE +8 -0
  5. package/README.md +199 -0
  6. package/debug-storybook.log +179 -0
  7. package/declarations.d.ts +17 -0
  8. package/dist/standard-view.es.js +9522 -0
  9. package/dist/standard-view.es.js.map +1 -0
  10. package/dist/standard-view.umd.js +41 -0
  11. package/dist/standard-view.umd.js.map +1 -0
  12. package/fonts/gentilis.bold.typeface.json +1 -0
  13. package/fonts/gentilis.typeface.json +1 -0
  14. package/fonts/helvetiker.bold.typeface.json +1 -0
  15. package/fonts/helvetiker.typeface.json +1 -0
  16. package/fonts/optimer.bold.typeface.json +1 -0
  17. package/fonts/optimer.typeface.json +1 -0
  18. package/images.d.ts +7 -0
  19. package/index.js +10 -0
  20. package/lib/controls/OrbitControls.d.ts +9 -0
  21. package/lib/controls/OrbitControls.js +761 -0
  22. package/lib/controls/index.d.ts +1 -0
  23. package/lib/controls/index.js +18 -0
  24. package/lib/groups/Arrow.d.ts +19 -0
  25. package/lib/groups/Arrow.js +134 -0
  26. package/lib/groups/Axis.d.ts +20 -0
  27. package/lib/groups/Axis.js +147 -0
  28. package/lib/groups/BoundingBox.d.ts +9 -0
  29. package/lib/groups/BoundingBox.js +143 -0
  30. package/lib/groups/Camera.d.ts +32 -0
  31. package/lib/groups/Camera.js +477 -0
  32. package/lib/groups/Capsule.d.ts +9 -0
  33. package/lib/groups/Capsule.js +112 -0
  34. package/lib/groups/FBX.d.ts +9 -0
  35. package/lib/groups/FBX.js +213 -0
  36. package/lib/groups/GLTF.d.ts +9 -0
  37. package/lib/groups/GLTF.js +198 -0
  38. package/lib/groups/Group.d.ts +63 -0
  39. package/lib/groups/Group.js +426 -0
  40. package/lib/groups/OBJ.d.ts +11 -0
  41. package/lib/groups/OBJ.js +252 -0
  42. package/lib/groups/PCD.d.ts +9 -0
  43. package/lib/groups/PCD.js +82 -0
  44. package/lib/groups/Path.d.ts +19 -0
  45. package/lib/groups/Path.js +160 -0
  46. package/lib/groups/index.d.ts +11 -0
  47. package/lib/groups/index.js +91 -0
  48. package/lib/index.d.ts +6 -0
  49. package/lib/index.js +298 -0
  50. package/lib/lights/AmbientLight.d.ts +8 -0
  51. package/lib/lights/AmbientLight.js +37 -0
  52. package/lib/lights/DirectionalLight.d.ts +8 -0
  53. package/lib/lights/DirectionalLight.js +43 -0
  54. package/lib/lights/HemisphereLight.d.ts +13 -0
  55. package/lib/lights/HemisphereLight.js +108 -0
  56. package/lib/lights/LightWithShadows.d.ts +24 -0
  57. package/lib/lights/LightWithShadows.js +188 -0
  58. package/lib/lights/PointLight.d.ts +9 -0
  59. package/lib/lights/PointLight.js +47 -0
  60. package/lib/lights/RectAreaLight.d.ts +13 -0
  61. package/lib/lights/RectAreaLight.js +177 -0
  62. package/lib/lights/SpotLight.d.ts +10 -0
  63. package/lib/lights/SpotLight.js +49 -0
  64. package/lib/lights/index.d.ts +6 -0
  65. package/lib/lights/index.js +48 -0
  66. package/lib/primitives/Box.d.ts +6 -0
  67. package/lib/primitives/Box.js +43 -0
  68. package/lib/primitives/Circle.d.ts +10 -0
  69. package/lib/primitives/Circle.js +85 -0
  70. package/lib/primitives/Cylinder.d.ts +15 -0
  71. package/lib/primitives/Cylinder.js +180 -0
  72. package/lib/primitives/Label.d.ts +18 -0
  73. package/lib/primitives/Label.js +189 -0
  74. package/lib/primitives/Line.d.ts +19 -0
  75. package/lib/primitives/Line.js +173 -0
  76. package/lib/primitives/Mesh.d.ts +72 -0
  77. package/lib/primitives/Mesh.js +642 -0
  78. package/lib/primitives/Plane.d.ts +7 -0
  79. package/lib/primitives/Plane.js +47 -0
  80. package/lib/primitives/Polygon.d.ts +8 -0
  81. package/lib/primitives/Polygon.js +75 -0
  82. package/lib/primitives/Quad.d.ts +9 -0
  83. package/lib/primitives/Quad.js +110 -0
  84. package/lib/primitives/Sphere.d.ts +14 -0
  85. package/lib/primitives/Sphere.js +92 -0
  86. package/lib/primitives/Text.d.ts +20 -0
  87. package/lib/primitives/Text.js +285 -0
  88. package/lib/primitives/Triangle.d.ts +8 -0
  89. package/lib/primitives/Triangle.js +83 -0
  90. package/lib/primitives/index.d.ts +12 -0
  91. package/lib/primitives/index.js +90 -0
  92. package/lib/shaders/index.d.ts +0 -0
  93. package/lib/shaders/index.js +2 -0
  94. package/lib/types/three-jsx.d.js +5 -0
  95. package/lib/utils/constants.js +181 -0
  96. package/lib/utils/events.d.ts +22 -0
  97. package/lib/utils/events.js +98 -0
  98. package/lib/utils/hooks.d.ts +8 -0
  99. package/lib/utils/hooks.js +96 -0
  100. package/lib/utils/index.d.ts +3 -0
  101. package/lib/utils/index.js +110 -0
  102. package/lib/utils/interfaces.d.ts +9 -0
  103. package/lib/utils/interfaces.js +5 -0
  104. package/lib/utils/math.d.ts +12 -0
  105. package/lib/utils/math.js +31 -0
  106. package/lib/utils/performance.d.ts +7 -0
  107. package/lib/utils/performance.js +114 -0
  108. package/lib/utils/styles.js +10 -0
  109. package/lib/utils/util.d.ts +76 -0
  110. package/lib/utils/util.js +290 -0
  111. package/lib/views/ContextBridge.d.ts +23 -0
  112. package/lib/views/ContextBridge.js +98 -0
  113. package/lib/views/SceneCamera.d.ts +7 -0
  114. package/lib/views/SceneCamera.js +52 -0
  115. package/lib/views/SetBackground.d.ts +9 -0
  116. package/lib/views/SetBackground.js +90 -0
  117. package/lib/views/SetControls.d.ts +19 -0
  118. package/lib/views/SetControls.js +173 -0
  119. package/lib/views/SetRenderer.d.ts +25 -0
  120. package/lib/views/SetRenderer.js +66 -0
  121. package/lib/views/SetShadows.d.ts +7 -0
  122. package/lib/views/SetShadows.js +48 -0
  123. package/lib/views/View3D.d.ts +21 -0
  124. package/lib/views/View3D.js +289 -0
  125. package/lib/views/ViewContext.d.ts +23 -0
  126. package/lib/views/ViewContext.js +55 -0
  127. package/lib/views/index.d.ts +2 -0
  128. package/lib/views/index.js +20 -0
  129. package/netlify.toml +15 -0
  130. package/package.json +110 -0
  131. package/tsconfig.json +42 -0
  132. package/tsconfig.prod.json +3 -0
  133. package/tsconfig.test.json +6 -0
  134. package/vite.config.ts +37 -0
@@ -0,0 +1,761 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MapControls = MapControls;
7
+ exports.OrbitControls = OrbitControls;
8
+ var _three = require("three");
9
+ // OrbitControls.tsx
10
+ // Adapted from three/examples/jsm/controls/OrbitControls.js
11
+
12
+ // This set of controls performs orbiting, dollying (zooming), and panning.
13
+ // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
14
+ //
15
+ // Orbit - left mouse / touch: one-finger move
16
+ // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
17
+ // Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
18
+
19
+ function OrbitControls(object, domElement) {
20
+ var initialPolarAngle = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
21
+ var initialAzimuthAngle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
22
+ //
23
+ // internals
24
+ //
25
+
26
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */
27
+ var scope = this;
28
+ var changeEvent = {
29
+ type: "change"
30
+ };
31
+ var startEvent = {
32
+ type: "start"
33
+ };
34
+ var endEvent = {
35
+ type: "end"
36
+ };
37
+ var STATE = {
38
+ NONE: -1,
39
+ ROTATE: 0,
40
+ DOLLY: 1,
41
+ PAN: 2,
42
+ TOUCH_ROTATE: 3,
43
+ TOUCH_PAN: 4,
44
+ TOUCH_DOLLY_PAN: 5,
45
+ TOUCH_DOLLY_ROTATE: 6
46
+ };
47
+ var state = STATE.NONE;
48
+ var EPS = 0.000001;
49
+
50
+ // current position in spherical coordinates
51
+ var spherical = new _three.Spherical();
52
+ var sphericalDelta = new _three.Spherical();
53
+ var scale = 1;
54
+ var panOffset = new _three.Vector3();
55
+ var zoomChanged = false;
56
+ var rotateStart = new _three.Vector2();
57
+ var rotateEnd = new _three.Vector2();
58
+ var rotateDelta = new _three.Vector2();
59
+ var panStart = new _three.Vector2();
60
+ var panEnd = new _three.Vector2();
61
+ var panDelta = new _three.Vector2();
62
+ var dollyStart = new _three.Vector2();
63
+ var dollyEnd = new _three.Vector2();
64
+ var dollyDelta = new _three.Vector2();
65
+
66
+ //
67
+ // public
68
+ //
69
+
70
+ this.rotateLeft = function RotateLeft(angle) {
71
+ sphericalDelta.theta -= angle;
72
+ };
73
+ this.rotateUp = function RotateUp(angle) {
74
+ sphericalDelta.phi -= angle;
75
+ };
76
+
77
+ //
78
+ // internal
79
+ //
80
+
81
+ function getAutoRotationAngle() {
82
+ return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
83
+ }
84
+ function getZoomScale() {
85
+ return Math.pow(0.95, scope.zoomSpeed);
86
+ }
87
+ var panLeft = function panLeft() {
88
+ var v = new _three.Vector3();
89
+ return function PanLeft(distance, objectMatrix) {
90
+ v.setFromMatrixColumn(objectMatrix, 0); // get X column of objectMatrix
91
+ v.multiplyScalar(-distance);
92
+ panOffset.add(v);
93
+ };
94
+ }();
95
+ var panUp = function panUp() {
96
+ var v = new _three.Vector3();
97
+ return function PanUp(distance, objectMatrix) {
98
+ if (scope.screenSpacePanning === true) {
99
+ v.setFromMatrixColumn(objectMatrix, 1);
100
+ } else {
101
+ v.setFromMatrixColumn(objectMatrix, 0);
102
+ v.crossVectors(scope.object.up, v);
103
+ }
104
+ v.multiplyScalar(distance);
105
+ panOffset.add(v);
106
+ };
107
+ }();
108
+
109
+ // deltaX and deltaY are in pixels; right and down are positive
110
+ var pan = function pan() {
111
+ var offset = new _three.Vector3();
112
+ return function Pan(deltaX, deltaY) {
113
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
114
+ if (scope.object.isPerspectiveCamera) {
115
+ // perspective
116
+ var position = scope.object.position;
117
+ offset.copy(position).sub(scope.target);
118
+ var targetDistance = offset.length();
119
+
120
+ // half of the fov is center to top of screen
121
+ targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180.0);
122
+
123
+ // we use only clientHeight here so aspect ratio does not distort speed
124
+ panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
125
+ panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
126
+ } else if (scope.object.isOrthographicCamera) {
127
+ // orthographic
128
+ panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
129
+ panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
130
+ } else {
131
+ // camera neither orthographic nor perspective
132
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
133
+ scope.enablePan = false;
134
+ }
135
+ };
136
+ }();
137
+ function dollyIn(dollyScale) {
138
+ if (scope.object.isPerspectiveCamera) {
139
+ scale /= dollyScale;
140
+ } else if (scope.object.isOrthographicCamera) {
141
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
142
+ scope.object.updateProjectionMatrix();
143
+ zoomChanged = true;
144
+ } else {
145
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
146
+ scope.enableZoom = false;
147
+ }
148
+ }
149
+ function dollyOut(dollyScale) {
150
+ if (scope.object.isPerspectiveCamera) {
151
+ scale *= dollyScale;
152
+ } else if (scope.object.isOrthographicCamera) {
153
+ scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
154
+ scope.object.updateProjectionMatrix();
155
+ zoomChanged = true;
156
+ } else {
157
+ console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
158
+ scope.enableZoom = false;
159
+ }
160
+ }
161
+
162
+ //
163
+ // event callbacks - update the object state
164
+ //
165
+
166
+ function handleMouseDownRotate(event) {
167
+ rotateStart.set(event.clientX, event.clientY);
168
+ }
169
+ function handleMouseDownDolly(event) {
170
+ dollyStart.set(event.clientX, event.clientY);
171
+ }
172
+ function handleMouseDownPan(event) {
173
+ panStart.set(event.clientX, event.clientY);
174
+ }
175
+ function handleMouseMoveRotate(event) {
176
+ rotateEnd.set(event.clientX, event.clientY);
177
+ rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
178
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
179
+ scope.rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); // yes, height
180
+
181
+ scope.rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
182
+ rotateStart.copy(rotateEnd);
183
+ scope.update();
184
+ }
185
+ function handleMouseMoveDolly(event) {
186
+ dollyEnd.set(event.clientX, event.clientY);
187
+ dollyDelta.subVectors(dollyEnd, dollyStart);
188
+ if (dollyDelta.y > 0) {
189
+ dollyIn(getZoomScale());
190
+ } else if (dollyDelta.y < 0) {
191
+ dollyOut(getZoomScale());
192
+ }
193
+ dollyStart.copy(dollyEnd);
194
+ scope.update();
195
+ }
196
+ function handleMouseMovePan(event) {
197
+ panEnd.set(event.clientX, event.clientY);
198
+ panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
199
+ pan(panDelta.x, panDelta.y);
200
+ panStart.copy(panEnd);
201
+ scope.update();
202
+ }
203
+ function handleMouseUp() {
204
+ // no-op
205
+ }
206
+ function handleMouseWheel(event) {
207
+ if (event.deltaY < 0) {
208
+ dollyOut(getZoomScale());
209
+ } else if (event.deltaY > 0) {
210
+ dollyIn(getZoomScale());
211
+ }
212
+ scope.update();
213
+ }
214
+ function handleKeyDown(event) {
215
+ var needsUpdate = false;
216
+ switch (event.keyCode) {
217
+ case scope.keys.UP:
218
+ pan(0, scope.keyPanSpeed);
219
+ needsUpdate = true;
220
+ break;
221
+ case scope.keys.BOTTOM:
222
+ pan(0, -scope.keyPanSpeed);
223
+ needsUpdate = true;
224
+ break;
225
+ case scope.keys.LEFT:
226
+ pan(scope.keyPanSpeed, 0);
227
+ needsUpdate = true;
228
+ break;
229
+ case scope.keys.RIGHT:
230
+ pan(-scope.keyPanSpeed, 0);
231
+ needsUpdate = true;
232
+ break;
233
+ default:
234
+ }
235
+ if (needsUpdate) {
236
+ // prevent the browser from scrolling on cursor keys
237
+ event.preventDefault();
238
+ scope.update();
239
+ }
240
+ }
241
+ function handleTouchStartRotate(event) {
242
+ if (event.touches.length === 1) {
243
+ rotateStart.set(event.touches[0].pageX, event.touches[0].pageY);
244
+ } else {
245
+ var x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX);
246
+ var y = 0.5 * (event.touches[0].pageY + event.touches[1].pageY);
247
+ rotateStart.set(x, y);
248
+ }
249
+ }
250
+ function handleTouchStartPan(event) {
251
+ if (event.touches.length === 1) {
252
+ panStart.set(event.touches[0].pageX, event.touches[0].pageY);
253
+ } else {
254
+ var x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX);
255
+ var y = 0.5 * (event.touches[0].pageY + event.touches[1].pageY);
256
+ panStart.set(x, y);
257
+ }
258
+ }
259
+ function handleTouchStartDolly(event) {
260
+ var dx = event.touches[0].pageX - event.touches[1].pageX;
261
+ var dy = event.touches[0].pageY - event.touches[1].pageY;
262
+ var distance = Math.sqrt(dx * dx + dy * dy);
263
+ dollyStart.set(0, distance);
264
+ }
265
+ function handleTouchStartDollyPan(event) {
266
+ if (scope.enableZoom) handleTouchStartDolly(event);
267
+ if (scope.enablePan) handleTouchStartPan(event);
268
+ }
269
+ function handleTouchStartDollyRotate(event) {
270
+ if (scope.enableZoom) handleTouchStartDolly(event);
271
+ if (scope.enableRotate) handleTouchStartRotate(event);
272
+ }
273
+ function handleTouchMoveRotate(event) {
274
+ if (event.touches.length === 1) {
275
+ rotateEnd.set(event.touches[0].pageX, event.touches[0].pageY);
276
+ } else {
277
+ var x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX);
278
+ var y = 0.5 * (event.touches[0].pageY + event.touches[1].pageY);
279
+ rotateEnd.set(x, y);
280
+ }
281
+ rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
282
+ var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
283
+ scope.rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); // yes, height
284
+
285
+ scope.rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
286
+ rotateStart.copy(rotateEnd);
287
+ }
288
+ function handleTouchMovePan(event) {
289
+ if (event.touches.length === 1) {
290
+ panEnd.set(event.touches[0].pageX, event.touches[0].pageY);
291
+ } else {
292
+ var x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX);
293
+ var y = 0.5 * (event.touches[0].pageY + event.touches[1].pageY);
294
+ panEnd.set(x, y);
295
+ }
296
+ panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
297
+ pan(panDelta.x, panDelta.y);
298
+ panStart.copy(panEnd);
299
+ }
300
+ function handleTouchMoveDolly(event) {
301
+ var dx = event.touches[0].pageX - event.touches[1].pageX;
302
+ var dy = event.touches[0].pageY - event.touches[1].pageY;
303
+ var distance = Math.sqrt(dx * dx + dy * dy);
304
+ dollyEnd.set(0, distance);
305
+ dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
306
+ dollyIn(dollyDelta.y);
307
+ dollyStart.copy(dollyEnd);
308
+ }
309
+ function handleTouchMoveDollyPan(event) {
310
+ if (scope.enableZoom) handleTouchMoveDolly(event);
311
+ if (scope.enablePan) handleTouchMovePan(event);
312
+ }
313
+ function handleTouchMoveDollyRotate(event) {
314
+ if (scope.enableZoom) handleTouchMoveDolly(event);
315
+ if (scope.enableRotate) handleTouchMoveRotate(event);
316
+ }
317
+ function handleTouchEnd() {
318
+ // no-op
319
+ }
320
+
321
+ //
322
+ // event handlers - FSM: listen for events and reset state
323
+ //
324
+
325
+ function onMouseMove(event) {
326
+ if (scope.enabled === false) return;
327
+ event.preventDefault();
328
+ switch (state) {
329
+ case STATE.ROTATE:
330
+ if (scope.enableRotate === false) return;
331
+ handleMouseMoveRotate(event);
332
+ break;
333
+ case STATE.DOLLY:
334
+ if (scope.enableZoom === false) return;
335
+ handleMouseMoveDolly(event);
336
+ break;
337
+ case STATE.PAN:
338
+ if (scope.enablePan === false) return;
339
+ handleMouseMovePan(event);
340
+ break;
341
+ default:
342
+ }
343
+ }
344
+ function onMouseUp() {
345
+ if (scope.enabled === false) return;
346
+ handleMouseUp();
347
+ document.removeEventListener("mousemove", onMouseMove, false);
348
+ document.removeEventListener("mouseup", onMouseUp, false);
349
+ scope.dispatchEvent(endEvent);
350
+ state = STATE.NONE;
351
+ }
352
+ function onMouseDown(event) {
353
+ if (scope.enabled === false) return;
354
+
355
+ // Prevent the browser from scrolling.
356
+
357
+ event.preventDefault();
358
+
359
+ // Manually set the focus since calling preventDefault above
360
+ // prevents the browser from setting it automatically.
361
+
362
+ if (scope.domElement.focus) {
363
+ scope.domElement.focus();
364
+ } else {
365
+ window.focus();
366
+ }
367
+ switch (event.button) {
368
+ case 0:
369
+ switch (scope.mouseButtons.LEFT) {
370
+ case _three.MOUSE.ROTATE:
371
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
372
+ if (scope.enablePan === false) return;
373
+ handleMouseDownPan(event);
374
+ state = STATE.PAN;
375
+ } else {
376
+ if (scope.enableRotate === false) return;
377
+ handleMouseDownRotate(event);
378
+ state = STATE.ROTATE;
379
+ }
380
+ break;
381
+ case _three.MOUSE.PAN:
382
+ if (event.ctrlKey || event.metaKey || event.shiftKey) {
383
+ if (scope.enableRotate === false) return;
384
+ handleMouseDownRotate(event);
385
+ state = STATE.ROTATE;
386
+ } else {
387
+ if (scope.enablePan === false) return;
388
+ handleMouseDownPan(event);
389
+ state = STATE.PAN;
390
+ }
391
+ break;
392
+ default:
393
+ state = STATE.NONE;
394
+ }
395
+ break;
396
+ case 1:
397
+ switch (scope.mouseButtons.MIDDLE) {
398
+ case _three.MOUSE.DOLLY:
399
+ if (scope.enableZoom === false) return;
400
+ handleMouseDownDolly(event);
401
+ state = STATE.DOLLY;
402
+ break;
403
+ default:
404
+ state = STATE.NONE;
405
+ }
406
+ break;
407
+ case 2:
408
+ switch (scope.mouseButtons.RIGHT) {
409
+ case _three.MOUSE.ROTATE:
410
+ if (scope.enableRotate === false) return;
411
+ handleMouseDownRotate(event);
412
+ state = STATE.ROTATE;
413
+ break;
414
+ case _three.MOUSE.PAN:
415
+ if (scope.enablePan === false) return;
416
+ handleMouseDownPan(event);
417
+ state = STATE.PAN;
418
+ break;
419
+ default:
420
+ state = STATE.NONE;
421
+ }
422
+ break;
423
+ default:
424
+ }
425
+ if (state !== STATE.NONE) {
426
+ document.addEventListener("mousemove", onMouseMove, false);
427
+ document.addEventListener("mouseup", onMouseUp, false);
428
+ scope.dispatchEvent(startEvent);
429
+ }
430
+ }
431
+ function onMouseWheel(event) {
432
+ if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE && state !== STATE.ROTATE) return;
433
+ event.preventDefault();
434
+ event.stopPropagation();
435
+ scope.dispatchEvent(startEvent);
436
+ handleMouseWheel(event);
437
+ scope.dispatchEvent(endEvent);
438
+ }
439
+ function onKeyDown(event) {
440
+ if (scope.enabled === false || scope.enableKeys === false || scope.enablePan === false) return;
441
+ handleKeyDown(event);
442
+ }
443
+ function onTouchStart(event) {
444
+ if (scope.enabled === false) return;
445
+ event.preventDefault();
446
+ switch (event.touches.length) {
447
+ case 1:
448
+ switch (scope.touches.ONE) {
449
+ case _three.TOUCH.ROTATE:
450
+ if (scope.enableRotate === false) return;
451
+ handleTouchStartRotate(event);
452
+ state = STATE.TOUCH_ROTATE;
453
+ break;
454
+ case _three.TOUCH.PAN:
455
+ if (scope.enablePan === false) return;
456
+ handleTouchStartPan(event);
457
+ state = STATE.TOUCH_PAN;
458
+ break;
459
+ default:
460
+ state = STATE.NONE;
461
+ }
462
+ break;
463
+ case 2:
464
+ switch (scope.touches.TWO) {
465
+ case _three.TOUCH.DOLLY_PAN:
466
+ if (scope.enableZoom === false && scope.enablePan === false) return;
467
+ handleTouchStartDollyPan(event);
468
+ state = STATE.TOUCH_DOLLY_PAN;
469
+ break;
470
+ case _three.TOUCH.DOLLY_ROTATE:
471
+ if (scope.enableZoom === false && scope.enableRotate === false) return;
472
+ handleTouchStartDollyRotate(event);
473
+ state = STATE.TOUCH_DOLLY_ROTATE;
474
+ break;
475
+ default:
476
+ state = STATE.NONE;
477
+ }
478
+ break;
479
+ default:
480
+ state = STATE.NONE;
481
+ }
482
+ if (state !== STATE.NONE) {
483
+ scope.dispatchEvent(startEvent);
484
+ }
485
+ }
486
+ function onTouchMove(event) {
487
+ if (scope.enabled === false) return;
488
+ event.preventDefault();
489
+ event.stopPropagation();
490
+ switch (state) {
491
+ case STATE.TOUCH_ROTATE:
492
+ if (scope.enableRotate === false) return;
493
+ handleTouchMoveRotate(event);
494
+ scope.update();
495
+ break;
496
+ case STATE.TOUCH_PAN:
497
+ if (scope.enablePan === false) return;
498
+ handleTouchMovePan(event);
499
+ scope.update();
500
+ break;
501
+ case STATE.TOUCH_DOLLY_PAN:
502
+ if (scope.enableZoom === false && scope.enablePan === false) return;
503
+ handleTouchMoveDollyPan(event);
504
+ scope.update();
505
+ break;
506
+ case STATE.TOUCH_DOLLY_ROTATE:
507
+ if (scope.enableZoom === false && scope.enableRotate === false) return;
508
+ handleTouchMoveDollyRotate(event);
509
+ scope.update();
510
+ break;
511
+ default:
512
+ state = STATE.NONE;
513
+ }
514
+ }
515
+ function onTouchEnd() {
516
+ if (scope.enabled === false) return;
517
+ handleTouchEnd();
518
+ scope.dispatchEvent(endEvent);
519
+ state = STATE.NONE;
520
+ }
521
+ function onContextMenu(event) {
522
+ if (scope.enabled === false) return;
523
+ event.preventDefault();
524
+ }
525
+
526
+ //
527
+ // public
528
+ //
529
+
530
+ this.object = object;
531
+ this.domElement = domElement !== undefined ? domElement : document;
532
+
533
+ // Set to false to disable this control
534
+ this.enabled = true;
535
+
536
+ // "target" sets the location of focus, where the object orbits around
537
+ this.target = this.object.target || new _three.Vector3();
538
+
539
+ // How far you can dolly in and out ( PerspectiveCamera only )
540
+ this.minDistance = 0;
541
+ this.maxDistance = Infinity;
542
+
543
+ // How far you can zoom in and out ( OrthographicCamera only )
544
+ this.minZoom = 0;
545
+ this.maxZoom = Infinity;
546
+
547
+ // How far you can orbit vertically, upper and lower limits.
548
+ // Range is 0 to Math.PI radians.
549
+ this.minPolarAngle = 0; // radians
550
+ this.maxPolarAngle = Math.PI; // radians
551
+
552
+ // How far you can orbit horizontally, upper and lower limits.
553
+ // If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
554
+ this.minAzimuthAngle = -Infinity; // radians
555
+ this.maxAzimuthAngle = Infinity; // radians
556
+
557
+ // Set to true to enable damping (inertia)
558
+ // If damping is enabled, you must call controls.update() in your animation loop
559
+ this.enableDamping = false;
560
+ this.dampingFactor = 0.05;
561
+
562
+ // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
563
+ // Set to false to disable zooming
564
+ this.enableZoom = true;
565
+ this.zoomSpeed = 1.0;
566
+
567
+ // Set to false to disable rotating
568
+ this.enableRotate = true;
569
+ this.rotateSpeed = 1.0;
570
+
571
+ // Set to false to disable panning
572
+ this.enablePan = true;
573
+ this.panSpeed = 1.0;
574
+ this.screenSpacePanning = false; // if true, pan in screen-space
575
+ this.keyPanSpeed = 7.0; // pixels moved per arrow key push
576
+
577
+ // Set to true to automatically rotate around the target
578
+ // If auto-rotate is enabled, you must call controls.update() in your animation loop
579
+ this.autoRotate = false;
580
+ this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
581
+
582
+ // Set to false to disable use of the keys
583
+ this.enableKeys = true;
584
+
585
+ // The four arrow keys
586
+ this.keys = {
587
+ LEFT: 37,
588
+ UP: 38,
589
+ RIGHT: 39,
590
+ BOTTOM: 40
591
+ };
592
+
593
+ // Mouse buttons
594
+ this.mouseButtons = {
595
+ LEFT: _three.MOUSE.ROTATE,
596
+ MIDDLE: _three.MOUSE.DOLLY,
597
+ RIGHT: _three.MOUSE.PAN
598
+ };
599
+
600
+ // Touch fingers
601
+ this.touches = {
602
+ ONE: _three.TOUCH.ROTATE,
603
+ TWO: _three.TOUCH.DOLLY_PAN
604
+ };
605
+
606
+ // for reset
607
+ this.target0 = this.target.clone();
608
+ this.position0 = this.object.position.clone();
609
+ this.zoom0 = this.object.zoom;
610
+
611
+ //
612
+ // public methods
613
+ //
614
+
615
+ this.getPolarAngle = function getPolarAngle() {
616
+ return spherical.phi;
617
+ };
618
+ this.getAzimuthalAngle = function getAzimuthalAngle() {
619
+ return spherical.theta;
620
+ };
621
+ this.saveState = function saveState() {
622
+ scope.target0.copy(scope.target);
623
+ scope.position0.copy(scope.object.position);
624
+ scope.zoom0 = scope.object.zoom;
625
+ };
626
+ this.reset = function reset() {
627
+ scope.target.copy(scope.target0);
628
+ scope.object.position.copy(scope.position0);
629
+ scope.object.zoom = scope.zoom0;
630
+ scope.object.updateProjectionMatrix();
631
+ scope.dispatchEvent(changeEvent);
632
+ scope.update();
633
+ state = STATE.NONE;
634
+ };
635
+
636
+ // this method is exposed, but perhaps it would be better if we can make it private...
637
+ this.update = function update() {
638
+ var offset = new _three.Vector3();
639
+
640
+ // so camera.up is the orbit axis
641
+ var quat = new _three.Quaternion().setFromUnitVectors(object.up, new _three.Vector3(0, 1, 0));
642
+ var quatInverse = quat.clone().invert();
643
+ var lastPosition = new _three.Vector3();
644
+ var lastQuaternion = new _three.Quaternion();
645
+ return function Update() {
646
+ var position = scope.object.position;
647
+ offset.copy(position).sub(scope.target);
648
+
649
+ // rotate offset to "y-axis-is-up" space
650
+ offset.applyQuaternion(quat);
651
+
652
+ // angle from z-axis around y-axis
653
+ spherical.setFromVector3(offset);
654
+ if (scope.autoRotate && state === STATE.NONE) {
655
+ scope.rotateLeft(getAutoRotationAngle());
656
+ }
657
+ if (scope.enableDamping) {
658
+ spherical.theta += sphericalDelta.theta * scope.dampingFactor;
659
+ spherical.phi += sphericalDelta.phi * scope.dampingFactor;
660
+ } else {
661
+ spherical.theta += sphericalDelta.theta;
662
+ spherical.phi += sphericalDelta.phi;
663
+ }
664
+
665
+ // restrict theta to be between desired limits
666
+ spherical.theta = Math.max(scope.minAzimuthAngle, Math.min(scope.maxAzimuthAngle, spherical.theta));
667
+
668
+ // restrict phi to be between desired limits
669
+ spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
670
+ spherical.makeSafe();
671
+ spherical.radius *= scale;
672
+
673
+ // restrict radius to be between desired limits
674
+ spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius));
675
+
676
+ // move target to panned location
677
+
678
+ if (scope.enableDamping === true) {
679
+ scope.target.addScaledVector(panOffset, scope.dampingFactor);
680
+ } else {
681
+ scope.target.add(panOffset);
682
+ }
683
+ offset.setFromSpherical(spherical);
684
+
685
+ // rotate offset back to "camera-up-vector-is-up" space
686
+ offset.applyQuaternion(quatInverse);
687
+ position.copy(scope.target).add(offset);
688
+ scope.object.lookAt(scope.target);
689
+ if (scope.enableDamping === true) {
690
+ sphericalDelta.theta *= 1 - scope.dampingFactor;
691
+ sphericalDelta.phi *= 1 - scope.dampingFactor;
692
+ panOffset.multiplyScalar(1 - scope.dampingFactor);
693
+ } else {
694
+ sphericalDelta.set(0, 0, 0);
695
+ panOffset.set(0, 0, 0);
696
+ }
697
+ scale = 1;
698
+
699
+ // update condition is:
700
+ // min(camera displacement, camera rotation in radians)^2 > EPS
701
+ // using small-angle approximation cos(x/2) = 1 - x^2 / 8
702
+
703
+ if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
704
+ scope.dispatchEvent(changeEvent);
705
+ lastPosition.copy(scope.object.position);
706
+ lastQuaternion.copy(scope.object.quaternion);
707
+ zoomChanged = false;
708
+ return true;
709
+ }
710
+ return false;
711
+ };
712
+ }();
713
+ this.dispose = function dispose() {
714
+ scope.domElement.removeEventListener("contextmenu", onContextMenu, false);
715
+ scope.domElement.removeEventListener("mousedown", onMouseDown, false);
716
+ scope.domElement.removeEventListener("wheel", onMouseWheel, false);
717
+ scope.domElement.removeEventListener("touchstart", onTouchStart, false);
718
+ scope.domElement.removeEventListener("touchend", onTouchEnd, false);
719
+ scope.domElement.removeEventListener("touchmove", onTouchMove, false);
720
+ document.removeEventListener("mousemove", onMouseMove, false);
721
+ document.removeEventListener("mouseup", onMouseUp, false);
722
+ window.removeEventListener("keydown", onKeyDown, false);
723
+
724
+ // scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
725
+ };
726
+
727
+ //
728
+
729
+ scope.domElement.addEventListener("contextmenu", onContextMenu, false);
730
+ scope.domElement.addEventListener("mousedown", onMouseDown, false);
731
+ scope.domElement.addEventListener("wheel", onMouseWheel, false);
732
+ scope.domElement.addEventListener("touchstart", onTouchStart, false);
733
+ scope.domElement.addEventListener("touchend", onTouchEnd, false);
734
+ scope.domElement.addEventListener("touchmove", onTouchMove, false);
735
+ window.addEventListener("keydown", onKeyDown, false);
736
+
737
+ // force an update at start
738
+ this.rotateLeft(initialPolarAngle);
739
+ this.rotateUp(initialAzimuthAngle);
740
+ this.update();
741
+ }
742
+ OrbitControls.prototype = Object.create(_three.EventDispatcher.prototype);
743
+ OrbitControls.prototype.constructor = OrbitControls;
744
+
745
+ // This set of controls performs orbiting, dollying (zooming), and panning.
746
+ // Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
747
+ // This is very similar to OrbitControls, another set of touch behavior
748
+ //
749
+ // Orbit - right mouse, or left mouse + ctrl/meta/shiftKey / touch: two-finger rotate
750
+ // Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
751
+ // Pan - left mouse, or arrow keys / touch: one-finger move
752
+
753
+ function MapControls(object, domElement) {
754
+ OrbitControls.call(this, object, domElement);
755
+ this.mouseButtons.LEFT = _three.MOUSE.PAN;
756
+ this.mouseButtons.RIGHT = _three.MOUSE.ROTATE;
757
+ this.touches.ONE = _three.TOUCH.PAN;
758
+ this.touches.TWO = _three.TOUCH.DOLLY_ROTATE;
759
+ }
760
+ MapControls.prototype = Object.create(_three.EventDispatcher.prototype);
761
+ MapControls.prototype.constructor = MapControls;