redhotmagma-visualization 1.28.3 → 1.29.1
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.
- package/AlignTargetProvider.js +129 -0
- package/CommonUtils/Deferred.js +135 -0
- package/CommonUtils/Observable.js +126 -0
- package/CommonUtils/PropertyObserver.js +61 -0
- package/CommonUtils/SyncCurrentFunction.js +59 -0
- package/CommonUtils/SyncObservableEvent.js +19 -0
- package/CommonUtils/pointerEvent.js +415 -0
- package/Constants.js +23 -0
- package/DevApp.js +1049 -0
- package/ExposedModules.js +26 -0
- package/FallbackVisualization.js +26 -0
- package/PrintingEffects/ColorEmbossingEffect.js +58 -0
- package/PrintingEffects/DomingEffect.js +150 -0
- package/PrintingEffects/EmbossingEffect.js +65 -0
- package/PrintingEffects/EmbroideryEffect.js +541 -0
- package/PrintingEffects/EngravingEffect.js +65 -0
- package/PrintingEffects/PrintingEffects.js +117 -0
- package/PrintingEffects/PrintingEffectsUtils.js +53 -0
- package/PrintingEffects/resources/embroidery_multiply.jpg +0 -0
- package/PrintingEffects/resources/embroidery_screen.jpg +0 -0
- package/README.md +11 -4
- package/React/ReactBase.js +111 -0
- package/Three/Controls/OrbitControls.js +745 -0
- package/Three/Exporters/glTFExporter.js +48 -0
- package/Three/Loaders/ColladaLoader.js +2916 -0
- package/Three/Loaders/MTLLoader.js +449 -0
- package/Three/Loaders/OBJLoader.js +548 -0
- package/Three/Three2D.js +1790 -0
- package/Three/Three2DLayers.js +504 -0
- package/Three/Three3D.js +1412 -0
- package/Three/Three3DScene.js +1432 -0
- package/Three/ThreeBase.js +724 -0
- package/Utils/DesignArea/getDesignAreaCanvasSize.js +32 -0
- package/Utils/TextureBuilder/createTextureBuilder.js +334 -0
- package/Utils/TextureBuilder/textureBuilderFunctions.js +87 -0
- package/Utils/alignToElement.js +58 -0
- package/Utils/createAlphaMapFromAlphaChannel.js +50 -0
- package/Utils/createCache.js +46 -0
- package/Utils/createCanvas.js +29 -0
- package/Utils/createImageRepository.js +124 -0
- package/Utils/disposeMaterial.js +41 -0
- package/Utils/getImageSize.js +15 -0
- package/Utils/imagePreloader.js +76 -0
- package/Utils/initTextureCanvas.js +49 -0
- package/Utils/isMobileDevice.js +19 -0
- package/Utils/optimizeTextureImage.js +73 -0
- package/Utils/rememberCameraViewOffset.js +21 -0
- package/Utils/removeObject.js +22 -0
- package/Utils/restrictCameraMovement.js +45 -0
- package/Utils/setOrthographicCameraSize.js +16 -0
- package/Utils/updateFitSizeToElement.js +39 -0
- package/VisualizationContainer.js +279 -0
- package/VisualizationInterface.js +298 -0
- package/VisualizationProvider.js +38 -0
- package/__mocks__/exportedSample.svg +45 -0
- package/index.js +16 -0
- package/package.json +10 -70
- package/scripts/cpPublic.js +9 -12
- package/scripts/cpPublicLocal.js +30 -0
- package/src/CommonUtils/Observable.js +1 -0
- package/src/CommonUtils/pointerEvent.js +2 -1
- package/src/DevApp.js +2 -1
- package/src/FallbackVisualization.js +1 -5
- package/src/PrintingEffects/DomingEffect.js +1 -0
- package/src/PrintingEffects/EmbroideryEffect.js +3 -2
- package/src/React/ReactBase.js +1 -1
- package/src/Three/Controls/OrbitControls.js +2 -0
- package/src/Three/Loaders/ColladaLoader.js +111 -294
- package/src/Three/Loaders/MTLLoader.js +2 -0
- package/src/Three/Loaders/OBJLoader.js +2 -0
- package/src/Three/Three2D.js +18 -11
- package/src/Three/Three3D.js +9 -1
- package/src/Three/ThreeBase.js +14 -2
- package/src/Utils/DesignArea/getDesignAreaCanvasSize.js +1 -0
- package/src/Utils/TextureBuilder/createTextureBuilder.js +2 -0
- package/src/Utils/imagePreloader.js +1 -0
- package/src/Utils/initTextureCanvas.js +3 -0
- package/src/Utils/isMobileDevice.js +2 -0
- package/src/Utils/optimizeTextureImage.js +1 -0
- package/src/VisualizationContainer.js +3 -1
- package/src/VisualizationInterface.js +10 -1
- package/visualizationAdapterCreator.js +76 -0
- package/babel.config.js +0 -41
- package/scripts/cpPath.js +0 -151
- package/scripts/moveLibToPackageRoot.js +0 -44
- package/scripts/utils/fileSystem.js +0 -69
- package/scripts/utils/process.js +0 -19
- package/tsconfig.json +0 -22
|
@@ -0,0 +1,745 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports["default"] = void 0;
|
|
9
|
+
|
|
10
|
+
var THREE_imp = _interopRequireWildcard(require("three"));
|
|
11
|
+
|
|
12
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
13
|
+
|
|
14
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
15
|
+
|
|
16
|
+
/* eslint-disable */
|
|
17
|
+
// original source: three/examples/js/controls/OrbitControls.js
|
|
18
|
+
var THREE = THREE_imp; // important: update file from here if needed
|
|
19
|
+
// important: be careful when updating, there is a custom updateQuat function inside the update function
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @author qiao / https://github.com/qiao
|
|
23
|
+
* @author mrdoob / http://mrdoob.com
|
|
24
|
+
* @author alteredq / http://alteredqualia.com/
|
|
25
|
+
* @author WestLangley / http://github.com/WestLangley
|
|
26
|
+
* @author erich666 / http://erichaines.com
|
|
27
|
+
*/
|
|
28
|
+
// This set of controls performs orbiting, dollying (zooming), and panning.
|
|
29
|
+
// Unlike TrackballControls, it maintains the "up" direction object.up (+Y by default).
|
|
30
|
+
//
|
|
31
|
+
// Orbit - left mouse / touch: one-finger move
|
|
32
|
+
// Zoom - middle mouse, or mousewheel / touch: two-finger spread or squish
|
|
33
|
+
// Pan - right mouse, or left mouse + ctrl/meta/shiftKey, or arrow keys / touch: two-finger move
|
|
34
|
+
|
|
35
|
+
THREE.OrbitControls = function (object, domElement) {
|
|
36
|
+
this.object = object;
|
|
37
|
+
this.domElement = domElement !== undefined ? domElement : document; // Set to false to disable this control
|
|
38
|
+
|
|
39
|
+
this.enabled = true; // "target" sets the location of focus, where the object orbits around
|
|
40
|
+
|
|
41
|
+
this.target = new THREE.Vector3(); // How far you can dolly in and out ( PerspectiveCamera only )
|
|
42
|
+
|
|
43
|
+
this.minDistance = 0;
|
|
44
|
+
this.maxDistance = Infinity; // How far you can zoom in and out ( OrthographicCamera only )
|
|
45
|
+
|
|
46
|
+
this.minZoom = 0;
|
|
47
|
+
this.maxZoom = Infinity; // How far you can orbit vertically, upper and lower limits.
|
|
48
|
+
// Range is 0 to Math.PI radians.
|
|
49
|
+
|
|
50
|
+
this.minPolarAngle = 0; // radians
|
|
51
|
+
|
|
52
|
+
this.maxPolarAngle = Math.PI; // radians
|
|
53
|
+
// How far you can orbit horizontally, upper and lower limits.
|
|
54
|
+
// If set, must be a sub-interval of the interval [ - Math.PI, Math.PI ].
|
|
55
|
+
|
|
56
|
+
this.minAzimuthAngle = -Infinity; // radians
|
|
57
|
+
|
|
58
|
+
this.maxAzimuthAngle = Infinity; // radians
|
|
59
|
+
// Set to true to enable damping (inertia)
|
|
60
|
+
// If damping is enabled, you must call controls.update() in your animation loop
|
|
61
|
+
|
|
62
|
+
this.enableDamping = false;
|
|
63
|
+
this.dampingFactor = 0.25; // This option actually enables dollying in and out; left as "zoom" for backwards compatibility.
|
|
64
|
+
// Set to false to disable zooming
|
|
65
|
+
|
|
66
|
+
this.enableZoom = true;
|
|
67
|
+
this.zoomSpeed = 1.0; // Set to false to disable rotating
|
|
68
|
+
|
|
69
|
+
this.enableRotate = true;
|
|
70
|
+
this.rotateSpeed = 1.0; // Set to false to disable panning
|
|
71
|
+
|
|
72
|
+
this.enablePan = true;
|
|
73
|
+
this.panSpeed = 1.0;
|
|
74
|
+
this.screenSpacePanning = false; // if true, pan in screen-space
|
|
75
|
+
|
|
76
|
+
this.keyPanSpeed = 7.0; // pixels moved per arrow key push
|
|
77
|
+
// Set to true to automatically rotate around the target
|
|
78
|
+
// If auto-rotate is enabled, you must call controls.update() in your animation loop
|
|
79
|
+
|
|
80
|
+
this.autoRotate = false;
|
|
81
|
+
this.autoRotateSpeed = 2.0; // 30 seconds per round when fps is 60
|
|
82
|
+
// Set to false to disable use of the keys
|
|
83
|
+
|
|
84
|
+
this.enableKeys = true; // The four arrow keys
|
|
85
|
+
|
|
86
|
+
this.keys = {
|
|
87
|
+
LEFT: 37,
|
|
88
|
+
UP: 38,
|
|
89
|
+
RIGHT: 39,
|
|
90
|
+
BOTTOM: 40
|
|
91
|
+
}; // Mouse buttons
|
|
92
|
+
|
|
93
|
+
this.mouseButtons = {
|
|
94
|
+
LEFT: THREE.MOUSE.LEFT,
|
|
95
|
+
MIDDLE: THREE.MOUSE.MIDDLE,
|
|
96
|
+
RIGHT: THREE.MOUSE.RIGHT
|
|
97
|
+
}; // for reset
|
|
98
|
+
|
|
99
|
+
this.target0 = this.target.clone();
|
|
100
|
+
this.position0 = this.object.position.clone();
|
|
101
|
+
this.zoom0 = this.object.zoom; //
|
|
102
|
+
// public methods
|
|
103
|
+
//
|
|
104
|
+
|
|
105
|
+
this.getPolarAngle = function () {
|
|
106
|
+
return spherical.phi;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
this.getAzimuthalAngle = function () {
|
|
110
|
+
return spherical.theta;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
this.saveState = function () {
|
|
114
|
+
scope.target0.copy(scope.target);
|
|
115
|
+
scope.position0.copy(scope.object.position);
|
|
116
|
+
scope.zoom0 = scope.object.zoom;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
this.reset = function () {
|
|
120
|
+
scope.target.copy(scope.target0);
|
|
121
|
+
scope.object.position.copy(scope.position0);
|
|
122
|
+
scope.object.zoom = scope.zoom0;
|
|
123
|
+
scope.object.updateProjectionMatrix();
|
|
124
|
+
scope.dispatchEvent(changeEvent);
|
|
125
|
+
scope.update();
|
|
126
|
+
state = STATE.NONE;
|
|
127
|
+
}; // this method is exposed, but perhaps it would be better if we can make it private...
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
this.update = function () {
|
|
131
|
+
var offset = new THREE.Vector3();
|
|
132
|
+
var up = object.up.clone(); // so camera.up is the orbit axis
|
|
133
|
+
|
|
134
|
+
var quat;
|
|
135
|
+
var quatInverse; // the up vector of the camera object can be changed by its rotation,
|
|
136
|
+
// to make sure the controls will continue to work the quaternions also have to be updated
|
|
137
|
+
|
|
138
|
+
function updateQuat(object) {
|
|
139
|
+
quat = new THREE.Quaternion().setFromUnitVectors(object.up, new THREE.Vector3(0, 1, 0));
|
|
140
|
+
quatInverse = quat.clone().invert();
|
|
141
|
+
up = object.up.clone();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
updateQuat(object);
|
|
145
|
+
var lastPosition = new THREE.Vector3();
|
|
146
|
+
var lastQuaternion = new THREE.Quaternion();
|
|
147
|
+
return function update() {
|
|
148
|
+
if (!up.equals(scope.object.up)) {
|
|
149
|
+
updateQuat(scope.object);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
var position = scope.object.position;
|
|
153
|
+
offset.copy(position).sub(scope.target); // rotate offset to "y-axis-is-up" space
|
|
154
|
+
|
|
155
|
+
offset.applyQuaternion(quat); // angle from z-axis around y-axis
|
|
156
|
+
|
|
157
|
+
spherical.setFromVector3(offset);
|
|
158
|
+
|
|
159
|
+
if (scope.autoRotate && state === STATE.NONE) {
|
|
160
|
+
rotateLeft(getAutoRotationAngle());
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
spherical.theta += sphericalDelta.theta;
|
|
164
|
+
spherical.phi += sphericalDelta.phi; // restrict theta to be between desired limits
|
|
165
|
+
|
|
166
|
+
spherical.theta = Math.max(scope.minAzimuthAngle, Math.min(scope.maxAzimuthAngle, spherical.theta)); // restrict phi to be between desired limits
|
|
167
|
+
|
|
168
|
+
spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi));
|
|
169
|
+
spherical.makeSafe();
|
|
170
|
+
spherical.radius *= scale; // restrict radius to be between desired limits
|
|
171
|
+
|
|
172
|
+
spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius)); // move target to panned location
|
|
173
|
+
|
|
174
|
+
scope.target.add(panOffset);
|
|
175
|
+
offset.setFromSpherical(spherical); // rotate offset back to "camera-up-vector-is-up" space
|
|
176
|
+
|
|
177
|
+
offset.applyQuaternion(quatInverse);
|
|
178
|
+
position.copy(scope.target).add(offset);
|
|
179
|
+
scope.object.lookAt(scope.target);
|
|
180
|
+
|
|
181
|
+
if (scope.enableDamping === true) {
|
|
182
|
+
sphericalDelta.theta *= 1 - scope.dampingFactor;
|
|
183
|
+
sphericalDelta.phi *= 1 - scope.dampingFactor;
|
|
184
|
+
panOffset.multiplyScalar(1 - scope.dampingFactor);
|
|
185
|
+
} else {
|
|
186
|
+
sphericalDelta.set(0, 0, 0);
|
|
187
|
+
panOffset.set(0, 0, 0);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
scale = 1; // update condition is:
|
|
191
|
+
// min(camera displacement, camera rotation in radians)^2 > EPS
|
|
192
|
+
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
|
|
193
|
+
|
|
194
|
+
if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) {
|
|
195
|
+
scope.dispatchEvent(changeEvent);
|
|
196
|
+
lastPosition.copy(scope.object.position);
|
|
197
|
+
lastQuaternion.copy(scope.object.quaternion);
|
|
198
|
+
zoomChanged = false;
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
return false;
|
|
203
|
+
};
|
|
204
|
+
}();
|
|
205
|
+
|
|
206
|
+
this.dispose = function () {
|
|
207
|
+
scope.domElement.removeEventListener("contextmenu", onContextMenu, false);
|
|
208
|
+
scope.domElement.removeEventListener("mousedown", onMouseDown, false);
|
|
209
|
+
scope.domElement.removeEventListener("wheel", onMouseWheel, false);
|
|
210
|
+
scope.domElement.removeEventListener("DOMMouseScroll", onMouseWheel, false);
|
|
211
|
+
scope.domElement.removeEventListener("touchstart", onTouchStart, false);
|
|
212
|
+
scope.domElement.removeEventListener("touchend", onTouchEnd, false);
|
|
213
|
+
scope.domElement.removeEventListener("touchmove", onTouchMove, false);
|
|
214
|
+
document.removeEventListener("mousemove", onMouseMove, false);
|
|
215
|
+
document.removeEventListener("mouseup", onMouseUp, false);
|
|
216
|
+
window.removeEventListener("keydown", onKeyDown, false); //scope.dispatchEvent( { type: 'dispose' } ); // should this be added here?
|
|
217
|
+
}; //
|
|
218
|
+
// internals
|
|
219
|
+
//
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
var scope = this;
|
|
223
|
+
var changeEvent = {
|
|
224
|
+
type: "change"
|
|
225
|
+
};
|
|
226
|
+
var startEvent = {
|
|
227
|
+
type: "start"
|
|
228
|
+
};
|
|
229
|
+
var endEvent = {
|
|
230
|
+
type: "end"
|
|
231
|
+
};
|
|
232
|
+
var STATE = {
|
|
233
|
+
NONE: -1,
|
|
234
|
+
ROTATE: 0,
|
|
235
|
+
DOLLY: 1,
|
|
236
|
+
PAN: 2,
|
|
237
|
+
TOUCH_ROTATE: 3,
|
|
238
|
+
TOUCH_DOLLY_PAN: 4
|
|
239
|
+
};
|
|
240
|
+
var state = STATE.NONE;
|
|
241
|
+
var EPS = 0.000001; // current position in spherical coordinates
|
|
242
|
+
|
|
243
|
+
var spherical = new THREE.Spherical();
|
|
244
|
+
var sphericalDelta = new THREE.Spherical();
|
|
245
|
+
var scale = 1;
|
|
246
|
+
var panOffset = new THREE.Vector3();
|
|
247
|
+
var zoomChanged = false;
|
|
248
|
+
var rotateStart = new THREE.Vector2();
|
|
249
|
+
var rotateEnd = new THREE.Vector2();
|
|
250
|
+
var rotateDelta = new THREE.Vector2();
|
|
251
|
+
var panStart = new THREE.Vector2();
|
|
252
|
+
var panEnd = new THREE.Vector2();
|
|
253
|
+
var panDelta = new THREE.Vector2();
|
|
254
|
+
var dollyStart = new THREE.Vector2();
|
|
255
|
+
var dollyEnd = new THREE.Vector2();
|
|
256
|
+
var dollyDelta = new THREE.Vector2();
|
|
257
|
+
|
|
258
|
+
function getAutoRotationAngle() {
|
|
259
|
+
return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function getZoomScale() {
|
|
263
|
+
return Math.pow(0.95, scope.zoomSpeed);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function rotateLeft(angle) {
|
|
267
|
+
sphericalDelta.theta -= angle;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function rotateUp(angle) {
|
|
271
|
+
sphericalDelta.phi -= angle;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
var panLeft = function () {
|
|
275
|
+
var v = new THREE.Vector3();
|
|
276
|
+
return function panLeft(distance, objectMatrix) {
|
|
277
|
+
v.setFromMatrixColumn(objectMatrix, 0); // get X column of objectMatrix
|
|
278
|
+
|
|
279
|
+
v.multiplyScalar(-distance);
|
|
280
|
+
panOffset.add(v);
|
|
281
|
+
};
|
|
282
|
+
}();
|
|
283
|
+
|
|
284
|
+
var panUp = function () {
|
|
285
|
+
var v = new THREE.Vector3();
|
|
286
|
+
return function panUp(distance, objectMatrix) {
|
|
287
|
+
if (scope.screenSpacePanning === true) {
|
|
288
|
+
v.setFromMatrixColumn(objectMatrix, 1);
|
|
289
|
+
} else {
|
|
290
|
+
v.setFromMatrixColumn(objectMatrix, 0);
|
|
291
|
+
v.crossVectors(scope.object.up, v);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
v.multiplyScalar(distance);
|
|
295
|
+
panOffset.add(v);
|
|
296
|
+
};
|
|
297
|
+
}(); // deltaX and deltaY are in pixels; right and down are positive
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
var pan = function () {
|
|
301
|
+
var offset = new THREE.Vector3();
|
|
302
|
+
return function pan(deltaX, deltaY) {
|
|
303
|
+
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
|
304
|
+
|
|
305
|
+
if (scope.object.isPerspectiveCamera) {
|
|
306
|
+
// perspective
|
|
307
|
+
var position = scope.object.position;
|
|
308
|
+
offset.copy(position).sub(scope.target);
|
|
309
|
+
var targetDistance = offset.length(); // half of the fov is center to top of screen
|
|
310
|
+
|
|
311
|
+
targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180.0); // we use only clientHeight here so aspect ratio does not distort speed
|
|
312
|
+
|
|
313
|
+
panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix);
|
|
314
|
+
panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix);
|
|
315
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
316
|
+
// orthographic
|
|
317
|
+
panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix);
|
|
318
|
+
panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix);
|
|
319
|
+
} else {
|
|
320
|
+
// camera neither orthographic nor perspective
|
|
321
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.");
|
|
322
|
+
scope.enablePan = false;
|
|
323
|
+
}
|
|
324
|
+
};
|
|
325
|
+
}();
|
|
326
|
+
|
|
327
|
+
function dollyIn(dollyScale) {
|
|
328
|
+
if (scope.object.isPerspectiveCamera) {
|
|
329
|
+
scale /= dollyScale;
|
|
330
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
331
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale));
|
|
332
|
+
scope.object.updateProjectionMatrix();
|
|
333
|
+
zoomChanged = true;
|
|
334
|
+
} else {
|
|
335
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
336
|
+
scope.enableZoom = false;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function dollyOut(dollyScale) {
|
|
341
|
+
if (scope.object.isPerspectiveCamera) {
|
|
342
|
+
scale *= dollyScale;
|
|
343
|
+
} else if (scope.object.isOrthographicCamera) {
|
|
344
|
+
scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale));
|
|
345
|
+
scope.object.updateProjectionMatrix();
|
|
346
|
+
zoomChanged = true;
|
|
347
|
+
} else {
|
|
348
|
+
console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.");
|
|
349
|
+
scope.enableZoom = false;
|
|
350
|
+
}
|
|
351
|
+
} //
|
|
352
|
+
// event callbacks - update the object state
|
|
353
|
+
//
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
function handleMouseDownRotate(event) {
|
|
357
|
+
//console.log( 'handleMouseDownRotate' );
|
|
358
|
+
rotateStart.set(event.clientX, event.clientY);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function handleMouseDownDolly(event) {
|
|
362
|
+
//console.log( 'handleMouseDownDolly' );
|
|
363
|
+
dollyStart.set(event.clientX, event.clientY);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function handleMouseDownPan(event) {
|
|
367
|
+
//console.log( 'handleMouseDownPan' );
|
|
368
|
+
panStart.set(event.clientX, event.clientY);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
function handleMouseMoveRotate(event) {
|
|
372
|
+
//console.log( 'handleMouseMoveRotate' );
|
|
373
|
+
rotateEnd.set(event.clientX, event.clientY);
|
|
374
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
375
|
+
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
|
376
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); // yes, height
|
|
377
|
+
|
|
378
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
379
|
+
rotateStart.copy(rotateEnd);
|
|
380
|
+
scope.update();
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
function handleMouseMoveDolly(event) {
|
|
384
|
+
//console.log( 'handleMouseMoveDolly' );
|
|
385
|
+
dollyEnd.set(event.clientX, event.clientY);
|
|
386
|
+
dollyDelta.subVectors(dollyEnd, dollyStart);
|
|
387
|
+
|
|
388
|
+
if (dollyDelta.y > 0) {
|
|
389
|
+
dollyIn(getZoomScale());
|
|
390
|
+
} else if (dollyDelta.y < 0) {
|
|
391
|
+
dollyOut(getZoomScale());
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
dollyStart.copy(dollyEnd);
|
|
395
|
+
scope.update();
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function handleMouseMovePan(event) {
|
|
399
|
+
//console.log( 'handleMouseMovePan' );
|
|
400
|
+
panEnd.set(event.clientX, event.clientY);
|
|
401
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
402
|
+
pan(panDelta.x, panDelta.y);
|
|
403
|
+
panStart.copy(panEnd);
|
|
404
|
+
scope.update();
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
function handleMouseUp(event) {// console.log( 'handleMouseUp' );
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function handleMouseWheel(event) {
|
|
411
|
+
// console.log( 'handleMouseWheel' );
|
|
412
|
+
if (event.deltaY < 0) {
|
|
413
|
+
dollyOut(getZoomScale());
|
|
414
|
+
} else if (event.deltaY > 0) {
|
|
415
|
+
dollyIn(getZoomScale());
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
scope.update();
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function handleKeyDown(event) {
|
|
422
|
+
//console.log( 'handleKeyDown' );
|
|
423
|
+
switch (event.keyCode) {
|
|
424
|
+
case scope.keys.UP:
|
|
425
|
+
pan(0, scope.keyPanSpeed);
|
|
426
|
+
scope.update();
|
|
427
|
+
break;
|
|
428
|
+
|
|
429
|
+
case scope.keys.BOTTOM:
|
|
430
|
+
pan(0, -scope.keyPanSpeed);
|
|
431
|
+
scope.update();
|
|
432
|
+
break;
|
|
433
|
+
|
|
434
|
+
case scope.keys.LEFT:
|
|
435
|
+
pan(scope.keyPanSpeed, 0);
|
|
436
|
+
scope.update();
|
|
437
|
+
break;
|
|
438
|
+
|
|
439
|
+
case scope.keys.RIGHT:
|
|
440
|
+
pan(-scope.keyPanSpeed, 0);
|
|
441
|
+
scope.update();
|
|
442
|
+
break;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function handleTouchStartRotate(event) {
|
|
447
|
+
//console.log( 'handleTouchStartRotate' );
|
|
448
|
+
rotateStart.set(event.touches[0].pageX, event.touches[0].pageY);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function handleTouchStartDollyPan(event) {
|
|
452
|
+
//console.log( 'handleTouchStartDollyPan' );
|
|
453
|
+
if (scope.enableZoom) {
|
|
454
|
+
var dx = event.touches[0].pageX - event.touches[1].pageX;
|
|
455
|
+
var dy = event.touches[0].pageY - event.touches[1].pageY;
|
|
456
|
+
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
457
|
+
dollyStart.set(0, distance);
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (scope.enablePan) {
|
|
461
|
+
var x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX);
|
|
462
|
+
var y = 0.5 * (event.touches[0].pageY + event.touches[1].pageY);
|
|
463
|
+
panStart.set(x, y);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function handleTouchMoveRotate(event) {
|
|
468
|
+
//console.log( 'handleTouchMoveRotate' );
|
|
469
|
+
rotateEnd.set(event.touches[0].pageX, event.touches[0].pageY);
|
|
470
|
+
rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed);
|
|
471
|
+
var element = scope.domElement === document ? scope.domElement.body : scope.domElement;
|
|
472
|
+
rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); // yes, height
|
|
473
|
+
|
|
474
|
+
rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight);
|
|
475
|
+
rotateStart.copy(rotateEnd);
|
|
476
|
+
scope.update();
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
function handleTouchMoveDollyPan(event) {
|
|
480
|
+
//console.log( 'handleTouchMoveDollyPan' );
|
|
481
|
+
if (scope.enableZoom) {
|
|
482
|
+
var dx = event.touches[0].pageX - event.touches[1].pageX;
|
|
483
|
+
var dy = event.touches[0].pageY - event.touches[1].pageY;
|
|
484
|
+
var distance = Math.sqrt(dx * dx + dy * dy);
|
|
485
|
+
dollyEnd.set(0, distance);
|
|
486
|
+
dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed));
|
|
487
|
+
dollyIn(dollyDelta.y);
|
|
488
|
+
dollyStart.copy(dollyEnd);
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (scope.enablePan) {
|
|
492
|
+
var x = 0.5 * (event.touches[0].pageX + event.touches[1].pageX);
|
|
493
|
+
var y = 0.5 * (event.touches[0].pageY + event.touches[1].pageY);
|
|
494
|
+
panEnd.set(x, y);
|
|
495
|
+
panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed);
|
|
496
|
+
pan(panDelta.x, panDelta.y);
|
|
497
|
+
panStart.copy(panEnd);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
scope.update();
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function handleTouchEnd(event) {//console.log( 'handleTouchEnd' );
|
|
504
|
+
} //
|
|
505
|
+
// event handlers - FSM: listen for events and reset state
|
|
506
|
+
//
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
function onMouseDown(event) {
|
|
510
|
+
if (scope.enabled === false) return;
|
|
511
|
+
event.preventDefault();
|
|
512
|
+
|
|
513
|
+
switch (event.button) {
|
|
514
|
+
case scope.mouseButtons.LEFT:
|
|
515
|
+
if (event.ctrlKey || event.metaKey || event.shiftKey) {
|
|
516
|
+
if (scope.enablePan === false) return;
|
|
517
|
+
handleMouseDownPan(event);
|
|
518
|
+
state = STATE.PAN;
|
|
519
|
+
} else {
|
|
520
|
+
if (scope.enableRotate === false) return;
|
|
521
|
+
handleMouseDownRotate(event);
|
|
522
|
+
state = STATE.ROTATE;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
break;
|
|
526
|
+
|
|
527
|
+
case scope.mouseButtons.MIDDLE:
|
|
528
|
+
if (scope.enableZoom === false) return;
|
|
529
|
+
handleMouseDownDolly(event);
|
|
530
|
+
state = STATE.DOLLY;
|
|
531
|
+
break;
|
|
532
|
+
|
|
533
|
+
case scope.mouseButtons.RIGHT:
|
|
534
|
+
if (scope.enablePan === false) return;
|
|
535
|
+
handleMouseDownPan(event);
|
|
536
|
+
state = STATE.PAN;
|
|
537
|
+
break;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
if (state !== STATE.NONE) {
|
|
541
|
+
document.addEventListener("mousemove", onMouseMove, false);
|
|
542
|
+
document.addEventListener("mouseup", onMouseUp, false);
|
|
543
|
+
scope.dispatchEvent(startEvent);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
function onMouseMove(event) {
|
|
548
|
+
if (scope.enabled === false) return;
|
|
549
|
+
event.preventDefault();
|
|
550
|
+
|
|
551
|
+
switch (state) {
|
|
552
|
+
case STATE.ROTATE:
|
|
553
|
+
if (scope.enableRotate === false) return;
|
|
554
|
+
handleMouseMoveRotate(event);
|
|
555
|
+
break;
|
|
556
|
+
|
|
557
|
+
case STATE.DOLLY:
|
|
558
|
+
if (scope.enableZoom === false) return;
|
|
559
|
+
handleMouseMoveDolly(event);
|
|
560
|
+
break;
|
|
561
|
+
|
|
562
|
+
case STATE.PAN:
|
|
563
|
+
if (scope.enablePan === false) return;
|
|
564
|
+
handleMouseMovePan(event);
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
function onMouseUp(event) {
|
|
570
|
+
if (scope.enabled === false) return;
|
|
571
|
+
handleMouseUp(event);
|
|
572
|
+
document.removeEventListener("mousemove", onMouseMove, false);
|
|
573
|
+
document.removeEventListener("mouseup", onMouseUp, false);
|
|
574
|
+
scope.dispatchEvent(endEvent);
|
|
575
|
+
state = STATE.NONE;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function onMouseWheel(event) {
|
|
579
|
+
if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE && state !== STATE.ROTATE) return;
|
|
580
|
+
event.preventDefault();
|
|
581
|
+
event.stopPropagation();
|
|
582
|
+
scope.dispatchEvent(startEvent);
|
|
583
|
+
handleMouseWheel(event);
|
|
584
|
+
scope.dispatchEvent(endEvent);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function onKeyDown(event) {
|
|
588
|
+
if (scope.enabled === false || scope.enableKeys === false || scope.enablePan === false) return;
|
|
589
|
+
handleKeyDown(event);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function onTouchStart(event) {
|
|
593
|
+
if (scope.enabled === false) return;
|
|
594
|
+
event.preventDefault();
|
|
595
|
+
|
|
596
|
+
switch (event.touches.length) {
|
|
597
|
+
case 1:
|
|
598
|
+
// one-fingered touch: rotate
|
|
599
|
+
if (scope.enableRotate === false) return;
|
|
600
|
+
handleTouchStartRotate(event);
|
|
601
|
+
state = STATE.TOUCH_ROTATE;
|
|
602
|
+
break;
|
|
603
|
+
|
|
604
|
+
case 2:
|
|
605
|
+
// two-fingered touch: dolly-pan
|
|
606
|
+
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
607
|
+
handleTouchStartDollyPan(event);
|
|
608
|
+
state = STATE.TOUCH_DOLLY_PAN;
|
|
609
|
+
break;
|
|
610
|
+
|
|
611
|
+
default:
|
|
612
|
+
state = STATE.NONE;
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
if (state !== STATE.NONE) {
|
|
616
|
+
scope.dispatchEvent(startEvent);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
function onTouchMove(event) {
|
|
621
|
+
if (scope.enabled === false) return;
|
|
622
|
+
event.preventDefault();
|
|
623
|
+
event.stopPropagation();
|
|
624
|
+
|
|
625
|
+
switch (event.touches.length) {
|
|
626
|
+
case 1:
|
|
627
|
+
// one-fingered touch: rotate
|
|
628
|
+
if (scope.enableRotate === false) return;
|
|
629
|
+
if (state !== STATE.TOUCH_ROTATE) return; // is this needed?
|
|
630
|
+
|
|
631
|
+
handleTouchMoveRotate(event);
|
|
632
|
+
break;
|
|
633
|
+
|
|
634
|
+
case 2:
|
|
635
|
+
// two-fingered touch: dolly-pan
|
|
636
|
+
if (scope.enableZoom === false && scope.enablePan === false) return;
|
|
637
|
+
if (state !== STATE.TOUCH_DOLLY_PAN) return; // is this needed?
|
|
638
|
+
|
|
639
|
+
handleTouchMoveDollyPan(event);
|
|
640
|
+
break;
|
|
641
|
+
|
|
642
|
+
default:
|
|
643
|
+
state = STATE.NONE;
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
function onTouchEnd(event) {
|
|
648
|
+
if (scope.enabled === false) return;
|
|
649
|
+
handleTouchEnd(event);
|
|
650
|
+
scope.dispatchEvent(endEvent);
|
|
651
|
+
state = STATE.NONE;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function onContextMenu(event) {
|
|
655
|
+
if (scope.enabled === false) return;
|
|
656
|
+
event.preventDefault();
|
|
657
|
+
} //
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
scope.domElement.addEventListener("contextmenu", onContextMenu, false);
|
|
661
|
+
scope.domElement.addEventListener("mousedown", onMouseDown, false);
|
|
662
|
+
scope.domElement.addEventListener("wheel", onMouseWheel, false);
|
|
663
|
+
scope.domElement.addEventListener("DOMMouseScroll", onMouseWheel, false);
|
|
664
|
+
scope.domElement.addEventListener("touchstart", onTouchStart, false);
|
|
665
|
+
scope.domElement.addEventListener("touchend", onTouchEnd, false);
|
|
666
|
+
scope.domElement.addEventListener("touchmove", onTouchMove, false);
|
|
667
|
+
window.addEventListener("keydown", onKeyDown, false); // force an update at start
|
|
668
|
+
|
|
669
|
+
this.update();
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
THREE.OrbitControls.prototype = Object.create(THREE.EventDispatcher.prototype);
|
|
673
|
+
THREE.OrbitControls.prototype.constructor = THREE.OrbitControls;
|
|
674
|
+
Object.defineProperties(THREE.OrbitControls.prototype, {
|
|
675
|
+
center: {
|
|
676
|
+
get: function get() {
|
|
677
|
+
console.warn("THREE.OrbitControls: .center has been renamed to .target");
|
|
678
|
+
return this.target;
|
|
679
|
+
}
|
|
680
|
+
},
|
|
681
|
+
// backward compatibility
|
|
682
|
+
noZoom: {
|
|
683
|
+
get: function get() {
|
|
684
|
+
console.warn("THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.");
|
|
685
|
+
return !this.enableZoom;
|
|
686
|
+
},
|
|
687
|
+
set: function set(value) {
|
|
688
|
+
console.warn("THREE.OrbitControls: .noZoom has been deprecated. Use .enableZoom instead.");
|
|
689
|
+
this.enableZoom = !value;
|
|
690
|
+
}
|
|
691
|
+
},
|
|
692
|
+
noRotate: {
|
|
693
|
+
get: function get() {
|
|
694
|
+
console.warn("THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.");
|
|
695
|
+
return !this.enableRotate;
|
|
696
|
+
},
|
|
697
|
+
set: function set(value) {
|
|
698
|
+
console.warn("THREE.OrbitControls: .noRotate has been deprecated. Use .enableRotate instead.");
|
|
699
|
+
this.enableRotate = !value;
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
noPan: {
|
|
703
|
+
get: function get() {
|
|
704
|
+
console.warn("THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.");
|
|
705
|
+
return !this.enablePan;
|
|
706
|
+
},
|
|
707
|
+
set: function set(value) {
|
|
708
|
+
console.warn("THREE.OrbitControls: .noPan has been deprecated. Use .enablePan instead.");
|
|
709
|
+
this.enablePan = !value;
|
|
710
|
+
}
|
|
711
|
+
},
|
|
712
|
+
noKeys: {
|
|
713
|
+
get: function get() {
|
|
714
|
+
console.warn("THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.");
|
|
715
|
+
return !this.enableKeys;
|
|
716
|
+
},
|
|
717
|
+
set: function set(value) {
|
|
718
|
+
console.warn("THREE.OrbitControls: .noKeys has been deprecated. Use .enableKeys instead.");
|
|
719
|
+
this.enableKeys = !value;
|
|
720
|
+
}
|
|
721
|
+
},
|
|
722
|
+
staticMoving: {
|
|
723
|
+
get: function get() {
|
|
724
|
+
console.warn("THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.");
|
|
725
|
+
return !this.enableDamping;
|
|
726
|
+
},
|
|
727
|
+
set: function set(value) {
|
|
728
|
+
console.warn("THREE.OrbitControls: .staticMoving has been deprecated. Use .enableDamping instead.");
|
|
729
|
+
this.enableDamping = !value;
|
|
730
|
+
}
|
|
731
|
+
},
|
|
732
|
+
dynamicDampingFactor: {
|
|
733
|
+
get: function get() {
|
|
734
|
+
console.warn("THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.");
|
|
735
|
+
return this.dampingFactor;
|
|
736
|
+
},
|
|
737
|
+
set: function set(value) {
|
|
738
|
+
console.warn("THREE.OrbitControls: .dynamicDampingFactor has been renamed. Use .dampingFactor instead.");
|
|
739
|
+
this.dampingFactor = value;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
}); // important: don't forget to export it
|
|
743
|
+
|
|
744
|
+
var _default = THREE.OrbitControls;
|
|
745
|
+
exports["default"] = _default;
|