@2112-lab/central-plant 0.1.3 → 0.1.5

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 (119) hide show
  1. package/dist/bundle/index.js +1 -1
  2. package/dist/cjs/_virtual/_rollupPluginBabelHelpers.js +432 -1
  3. package/dist/cjs/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1448 -1
  4. package/dist/cjs/node_modules/three/examples/jsm/controls/OrbitControls.js +1853 -1
  5. package/dist/cjs/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3537 -0
  6. package/dist/cjs/node_modules/three/examples/jsm/exporters/OBJExporter.js +305 -0
  7. package/dist/cjs/node_modules/three/examples/jsm/exporters/PLYExporter.js +542 -0
  8. package/dist/cjs/node_modules/three/examples/jsm/exporters/STLExporter.js +218 -0
  9. package/dist/cjs/node_modules/three/examples/jsm/loaders/DRACOLoader.js +683 -0
  10. package/dist/cjs/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4811 -1
  11. package/dist/cjs/node_modules/three/examples/jsm/loaders/RGBELoader.js +480 -1
  12. package/dist/cjs/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +309 -0
  13. package/dist/cjs/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +120 -1
  14. package/dist/cjs/src/analysis/analysis.js +560 -0
  15. package/dist/cjs/src/analysis/testing.js +958 -0
  16. package/dist/cjs/src/core/centralPlant.js +1149 -0
  17. package/dist/cjs/src/core/debugLogger.js +175 -0
  18. package/dist/cjs/src/core/mathUtils.js +574 -0
  19. package/dist/cjs/src/core/nameUtils.js +93 -0
  20. package/dist/cjs/src/data/export.js +716 -0
  21. package/dist/cjs/src/data/import.js +380 -0
  22. package/dist/cjs/src/data/numerics.js +522 -0
  23. package/dist/cjs/src/helpers/sceneHelper.js +572 -0
  24. package/dist/cjs/src/index.js +69 -1
  25. package/dist/cjs/src/managers/components/animationManager.js +123 -0
  26. package/dist/cjs/src/managers/components/componentManager.js +332 -0
  27. package/dist/cjs/src/managers/components/pathfindingManager.js +1441 -0
  28. package/dist/cjs/src/managers/controls/TransformControls.js +1063 -0
  29. package/dist/cjs/src/managers/controls/cameraControlsManager.js +79 -0
  30. package/dist/cjs/src/managers/controls/dragDropManager.js +1026 -0
  31. package/dist/cjs/src/managers/controls/keyboardControlsManager.js +395 -0
  32. package/dist/cjs/src/managers/controls/transformControlsManager.js +1807 -0
  33. package/dist/cjs/src/managers/environment/environmentManager.js +714 -0
  34. package/dist/cjs/src/managers/environment/textureConfig.js +229 -0
  35. package/dist/cjs/src/managers/scene/sceneExportManager.js +264 -0
  36. package/dist/cjs/src/managers/scene/sceneInitializationManager.js +346 -0
  37. package/dist/cjs/src/managers/scene/sceneOperationsManager.js +1509 -0
  38. package/dist/cjs/src/managers/scene/sceneTooltipsManager.js +661 -0
  39. package/dist/cjs/src/managers/system/disposalManager.js +444 -0
  40. package/dist/cjs/src/managers/system/hotReloadManager.js +291 -0
  41. package/dist/cjs/src/managers/system/performanceMonitor.js +863 -0
  42. package/dist/cjs/src/rendering/modelPreloader.js +369 -0
  43. package/dist/cjs/src/rendering/rendering2D.js +631 -0
  44. package/dist/cjs/src/rendering/rendering3D.js +685 -0
  45. package/dist/esm/_virtual/_rollupPluginBabelHelpers.js +396 -1
  46. package/dist/esm/node_modules/@2112-lab/pathfinder/dist/index.esm.js +1444 -1
  47. package/dist/esm/node_modules/three/examples/jsm/controls/OrbitControls.js +1849 -1
  48. package/dist/esm/node_modules/three/examples/jsm/exporters/GLTFExporter.js +3533 -0
  49. package/dist/esm/node_modules/three/examples/jsm/exporters/OBJExporter.js +301 -0
  50. package/dist/esm/node_modules/three/examples/jsm/exporters/PLYExporter.js +538 -0
  51. package/dist/esm/node_modules/three/examples/jsm/exporters/STLExporter.js +214 -0
  52. package/dist/esm/node_modules/three/examples/jsm/loaders/DRACOLoader.js +679 -0
  53. package/dist/esm/node_modules/three/examples/jsm/loaders/GLTFLoader.js +4807 -1
  54. package/dist/esm/node_modules/three/examples/jsm/loaders/RGBELoader.js +476 -1
  55. package/dist/esm/node_modules/three/examples/jsm/renderers/CSS2DRenderer.js +304 -0
  56. package/dist/esm/node_modules/three/examples/jsm/utils/BufferGeometryUtils.js +116 -1
  57. package/dist/esm/src/analysis/analysis.js +536 -0
  58. package/dist/esm/src/analysis/testing.js +954 -0
  59. package/dist/esm/src/core/centralPlant.js +1144 -0
  60. package/dist/esm/src/core/debugLogger.js +167 -0
  61. package/dist/esm/src/core/mathUtils.js +570 -0
  62. package/dist/esm/src/core/nameUtils.js +87 -0
  63. package/dist/esm/src/data/export.js +712 -0
  64. package/dist/esm/src/data/import.js +356 -0
  65. package/dist/esm/src/data/numerics.js +518 -0
  66. package/dist/esm/src/helpers/sceneHelper.js +547 -0
  67. package/dist/esm/src/index.js +35 -1
  68. package/dist/esm/src/managers/components/animationManager.js +119 -0
  69. package/dist/esm/src/managers/components/componentManager.js +328 -0
  70. package/dist/esm/src/managers/components/pathfindingManager.js +1417 -0
  71. package/dist/esm/src/managers/controls/TransformControls.js +1057 -0
  72. package/dist/esm/src/managers/controls/cameraControlsManager.js +75 -0
  73. package/dist/esm/src/managers/controls/dragDropManager.js +1002 -0
  74. package/dist/esm/src/managers/controls/keyboardControlsManager.js +371 -0
  75. package/dist/esm/src/managers/controls/transformControlsManager.js +1782 -0
  76. package/dist/esm/src/managers/environment/environmentManager.js +690 -0
  77. package/dist/esm/src/managers/environment/textureConfig.js +202 -0
  78. package/dist/esm/src/managers/scene/sceneExportManager.js +260 -0
  79. package/dist/esm/src/managers/scene/sceneInitializationManager.js +322 -0
  80. package/dist/esm/src/managers/scene/sceneOperationsManager.js +1485 -0
  81. package/dist/esm/src/managers/scene/sceneTooltipsManager.js +637 -0
  82. package/dist/esm/src/managers/system/disposalManager.js +440 -0
  83. package/dist/esm/src/managers/system/hotReloadManager.js +287 -0
  84. package/dist/esm/src/managers/system/performanceMonitor.js +858 -0
  85. package/dist/esm/src/rendering/modelPreloader.js +364 -0
  86. package/dist/esm/src/rendering/rendering2D.js +627 -0
  87. package/dist/esm/src/rendering/rendering3D.js +661 -0
  88. package/dist/index.d.ts +52 -255
  89. package/package.json +3 -6
  90. package/dist/cjs/node_modules/three/examples/jsm/controls/TransformControls.js +0 -1
  91. package/dist/cjs/src/animationManager.js +0 -1
  92. package/dist/cjs/src/componentManager.js +0 -1
  93. package/dist/cjs/src/debugLogger.js +0 -1
  94. package/dist/cjs/src/disposalManager.js +0 -1
  95. package/dist/cjs/src/environmentManager.js +0 -1
  96. package/dist/cjs/src/hotReloadManager.js +0 -1
  97. package/dist/cjs/src/keyboardControlsManager.js +0 -1
  98. package/dist/cjs/src/nameUtils.js +0 -1
  99. package/dist/cjs/src/pathfindingManager.js +0 -1
  100. package/dist/cjs/src/performanceMonitor.js +0 -1
  101. package/dist/cjs/src/sceneExportManager.js +0 -1
  102. package/dist/cjs/src/sceneInitializationManager.js +0 -1
  103. package/dist/cjs/src/textureConfig.js +0 -1
  104. package/dist/cjs/src/transformControlsManager.js +0 -1
  105. package/dist/esm/node_modules/three/examples/jsm/controls/TransformControls.js +0 -1
  106. package/dist/esm/src/animationManager.js +0 -1
  107. package/dist/esm/src/componentManager.js +0 -1
  108. package/dist/esm/src/debugLogger.js +0 -1
  109. package/dist/esm/src/disposalManager.js +0 -1
  110. package/dist/esm/src/environmentManager.js +0 -1
  111. package/dist/esm/src/hotReloadManager.js +0 -1
  112. package/dist/esm/src/keyboardControlsManager.js +0 -1
  113. package/dist/esm/src/nameUtils.js +0 -1
  114. package/dist/esm/src/pathfindingManager.js +0 -1
  115. package/dist/esm/src/performanceMonitor.js +0 -1
  116. package/dist/esm/src/sceneExportManager.js +0 -1
  117. package/dist/esm/src/sceneInitializationManager.js +0 -1
  118. package/dist/esm/src/textureConfig.js +0 -1
  119. package/dist/esm/src/transformControlsManager.js +0 -1
@@ -0,0 +1,1063 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _rollupPluginBabelHelpers = require('../../../_virtual/_rollupPluginBabelHelpers.js');
6
+ var THREE = require('three');
7
+
8
+ var _raycaster = new THREE.Raycaster();
9
+ var _tempVector = new THREE.Vector3();
10
+ var _tempVector2 = new THREE.Vector3();
11
+ var _tempQuaternion = new THREE.Quaternion();
12
+ var _unit = {
13
+ X: new THREE.Vector3(1, 0, 0),
14
+ Y: new THREE.Vector3(0, 1, 0),
15
+ Z: new THREE.Vector3(0, 0, 1)
16
+ };
17
+ var _changeEvent = {
18
+ type: 'change'
19
+ };
20
+ var _mouseDownEvent = {
21
+ type: 'mouseDown'
22
+ };
23
+ var _mouseUpEvent = {
24
+ type: 'mouseUp',
25
+ mode: null
26
+ };
27
+ var _objectChangeEvent = {
28
+ type: 'objectChange'
29
+ };
30
+ var TransformControls = /*#__PURE__*/function (_Object3D) {
31
+ function TransformControls(camera, domElement) {
32
+ var _this;
33
+ _rollupPluginBabelHelpers.classCallCheck(this, TransformControls);
34
+ _this = _rollupPluginBabelHelpers.callSuper(this, TransformControls);
35
+ if (domElement === undefined) {
36
+ console.warn('THREE.TransformControls: The second parameter "domElement" is now mandatory.');
37
+ domElement = document;
38
+ }
39
+ _this.isTransformControls = true;
40
+ _this.visible = false;
41
+ _this.domElement = domElement;
42
+ _this.domElement.style.touchAction = 'none'; // disable touch scroll
43
+
44
+ var _gizmo = new TransformControlsGizmo();
45
+ _this._gizmo = _gizmo;
46
+ _this.add(_gizmo);
47
+ var _plane = new TransformControlsPlane();
48
+ _this._plane = _plane;
49
+ _this.add(_plane);
50
+ var scope = _this;
51
+
52
+ // Defined getter, setter and store for a property
53
+ function defineProperty(propName, defaultValue) {
54
+ var propValue = defaultValue;
55
+ Object.defineProperty(scope, propName, {
56
+ get: function get() {
57
+ return propValue !== undefined ? propValue : defaultValue;
58
+ },
59
+ set: function set(value) {
60
+ if (propValue !== value) {
61
+ propValue = value;
62
+ _plane[propName] = value;
63
+ _gizmo[propName] = value;
64
+ scope.dispatchEvent({
65
+ type: propName + '-changed',
66
+ value: value
67
+ });
68
+ scope.dispatchEvent(_changeEvent);
69
+ }
70
+ }
71
+ });
72
+ scope[propName] = defaultValue;
73
+ _plane[propName] = defaultValue;
74
+ _gizmo[propName] = defaultValue;
75
+ }
76
+
77
+ // Define properties with getters/setter
78
+ // Setting the defined property will automatically trigger change event
79
+ // Defined properties are passed down to gizmo and plane
80
+
81
+ defineProperty('camera', camera);
82
+ defineProperty('object', undefined);
83
+ defineProperty('enabled', true);
84
+ defineProperty('axis', null);
85
+ defineProperty('mode', 'translate');
86
+ defineProperty('translationSnap', null);
87
+ defineProperty('rotationSnap', null);
88
+ defineProperty('scaleSnap', null);
89
+ defineProperty('space', 'world');
90
+ defineProperty('size', 1);
91
+ defineProperty('dragging', false);
92
+ defineProperty('showX', true);
93
+ defineProperty('showY', true);
94
+ defineProperty('showZ', true);
95
+ defineProperty('showXY', true);
96
+ defineProperty('showYZ', true);
97
+ defineProperty('showXZ', true);
98
+
99
+ // Click timing delay configuration
100
+ _this.clickDelay = null;
101
+ _this.lastInteractionTime = 0;
102
+
103
+ // Reusable utility variables
104
+
105
+ var worldPosition = new THREE.Vector3();
106
+ var worldPositionStart = new THREE.Vector3();
107
+ var worldQuaternion = new THREE.Quaternion();
108
+ var worldQuaternionStart = new THREE.Quaternion();
109
+ var cameraPosition = new THREE.Vector3();
110
+ var cameraQuaternion = new THREE.Quaternion();
111
+ var pointStart = new THREE.Vector3();
112
+ var pointEnd = new THREE.Vector3();
113
+ var rotationAxis = new THREE.Vector3();
114
+ var rotationAngle = 0;
115
+ var eye = new THREE.Vector3();
116
+
117
+ // TODO: remove properties unused in plane and gizmo
118
+
119
+ defineProperty('worldPosition', worldPosition);
120
+ defineProperty('worldPositionStart', worldPositionStart);
121
+ defineProperty('worldQuaternion', worldQuaternion);
122
+ defineProperty('worldQuaternionStart', worldQuaternionStart);
123
+ defineProperty('cameraPosition', cameraPosition);
124
+ defineProperty('cameraQuaternion', cameraQuaternion);
125
+ defineProperty('pointStart', pointStart);
126
+ defineProperty('pointEnd', pointEnd);
127
+ defineProperty('rotationAxis', rotationAxis);
128
+ defineProperty('rotationAngle', rotationAngle);
129
+ defineProperty('eye', eye);
130
+ _this._offset = new THREE.Vector3();
131
+ _this._startNorm = new THREE.Vector3();
132
+ _this._endNorm = new THREE.Vector3();
133
+ _this._cameraScale = new THREE.Vector3();
134
+ _this._parentPosition = new THREE.Vector3();
135
+ _this._parentQuaternion = new THREE.Quaternion();
136
+ _this._parentQuaternionInv = new THREE.Quaternion();
137
+ _this._parentScale = new THREE.Vector3();
138
+ _this._worldScaleStart = new THREE.Vector3();
139
+ _this._worldQuaternionInv = new THREE.Quaternion();
140
+ _this._worldScale = new THREE.Vector3();
141
+ _this._positionStart = new THREE.Vector3();
142
+ _this._quaternionStart = new THREE.Quaternion();
143
+ _this._scaleStart = new THREE.Vector3();
144
+ _this._getPointer = getPointer.bind(_this);
145
+ _this._onPointerDown = onPointerDown.bind(_this);
146
+ _this._onPointerHover = onPointerHover.bind(_this);
147
+ _this._onPointerMove = onPointerMove.bind(_this);
148
+ _this._onPointerUp = onPointerUp.bind(_this);
149
+ _this.domElement.addEventListener('pointerdown', _this._onPointerDown);
150
+ _this.domElement.addEventListener('pointermove', _this._onPointerHover);
151
+ _this.domElement.addEventListener('pointerup', _this._onPointerUp);
152
+ return _this;
153
+ }
154
+
155
+ // updateMatrixWorld updates key transformation variables
156
+ _rollupPluginBabelHelpers.inherits(TransformControls, _Object3D);
157
+ return _rollupPluginBabelHelpers.createClass(TransformControls, [{
158
+ key: "updateMatrixWorld",
159
+ value: function updateMatrixWorld() {
160
+ if (this.object !== undefined) {
161
+ this.object.updateMatrixWorld();
162
+ if (this.object.parent === null) {
163
+ console.error('TransformControls: The attached 3D object must be a part of the scene graph.');
164
+ } else {
165
+ this.object.parent.matrixWorld.decompose(this._parentPosition, this._parentQuaternion, this._parentScale);
166
+ }
167
+ this.object.matrixWorld.decompose(this.worldPosition, this.worldQuaternion, this._worldScale);
168
+ this._parentQuaternionInv.copy(this._parentQuaternion).invert();
169
+ this._worldQuaternionInv.copy(this.worldQuaternion).invert();
170
+ }
171
+ this.camera.updateMatrixWorld();
172
+ this.camera.matrixWorld.decompose(this.cameraPosition, this.cameraQuaternion, this._cameraScale);
173
+ if (this.camera.isOrthographicCamera) {
174
+ this.camera.getWorldDirection(this.eye).negate();
175
+ } else {
176
+ this.eye.copy(this.cameraPosition).sub(this.worldPosition).normalize();
177
+ }
178
+ _rollupPluginBabelHelpers.superPropGet(TransformControls, "updateMatrixWorld", this, 3)([this]);
179
+ }
180
+ }, {
181
+ key: "pointerHover",
182
+ value: function pointerHover(pointer) {
183
+ if (this.object === undefined || this.dragging === true) return;
184
+
185
+ // Check if we should delay interactions based on click timing
186
+ if (this.clickDelay && this.clickDelay.doubleClickDelay) {
187
+ var currentTime = Date.now();
188
+ var timeSinceLastInteraction = currentTime - this.lastInteractionTime;
189
+
190
+ // If not enough time has passed since last interaction, ignore hover
191
+ if (timeSinceLastInteraction < this.clickDelay.doubleClickDelay) {
192
+ return;
193
+ }
194
+ }
195
+ _raycaster.setFromCamera(pointer, this.camera);
196
+ var intersect = intersectObjectWithRay(this._gizmo.picker[this.mode], _raycaster);
197
+ if (intersect) {
198
+ this.axis = intersect.object.name;
199
+ } else {
200
+ this.axis = null;
201
+ }
202
+ }
203
+ }, {
204
+ key: "pointerDown",
205
+ value: function pointerDown(pointer) {
206
+ if (this.object === undefined || this.dragging === true || pointer.button !== 0) return;
207
+
208
+ // Check if we should delay interactions based on click timing
209
+ if (this.clickDelay && this.clickDelay.doubleClickDelay) {
210
+ var currentTime = Date.now();
211
+ var timeSinceLastInteraction = currentTime - this.lastInteractionTime;
212
+
213
+ // If not enough time has passed since last interaction, ignore this input
214
+ if (timeSinceLastInteraction < this.clickDelay.doubleClickDelay) {
215
+ return;
216
+ }
217
+
218
+ // Update last interaction time
219
+ this.lastInteractionTime = currentTime;
220
+ }
221
+ if (this.axis !== null) {
222
+ _raycaster.setFromCamera(pointer, this.camera);
223
+ var planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true);
224
+ if (planeIntersect) {
225
+ this.object.updateMatrixWorld();
226
+ this.object.parent.updateMatrixWorld();
227
+ this._positionStart.copy(this.object.position);
228
+ this._quaternionStart.copy(this.object.quaternion);
229
+ this._scaleStart.copy(this.object.scale);
230
+ this.object.matrixWorld.decompose(this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart);
231
+ this.pointStart.copy(planeIntersect.point).sub(this.worldPositionStart);
232
+ }
233
+ this.dragging = true;
234
+ _mouseDownEvent.mode = this.mode;
235
+ this.dispatchEvent(_mouseDownEvent);
236
+ }
237
+ }
238
+ }, {
239
+ key: "pointerMove",
240
+ value: function pointerMove(pointer) {
241
+ var axis = this.axis;
242
+ var mode = this.mode;
243
+ var object = this.object;
244
+ var space = this.space;
245
+ if (mode === 'scale') {
246
+ space = 'local';
247
+ } else if (axis === 'E' || axis === 'XYZE' || axis === 'XYZ') {
248
+ space = 'world';
249
+ }
250
+ if (object === undefined || axis === null || this.dragging === false || pointer.button !== -1) return;
251
+ _raycaster.setFromCamera(pointer, this.camera);
252
+ var planeIntersect = intersectObjectWithRay(this._plane, _raycaster, true);
253
+ if (!planeIntersect) return;
254
+ this.pointEnd.copy(planeIntersect.point).sub(this.worldPositionStart);
255
+ if (mode === 'translate') {
256
+ // Apply translate
257
+
258
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
259
+ if (space === 'local' && axis !== 'XYZ') {
260
+ this._offset.applyQuaternion(this._worldQuaternionInv);
261
+ }
262
+ if (axis.indexOf('X') === -1) this._offset.x = 0;
263
+ if (axis.indexOf('Y') === -1) this._offset.y = 0;
264
+ if (axis.indexOf('Z') === -1) this._offset.z = 0;
265
+ if (space === 'local' && axis !== 'XYZ') {
266
+ this._offset.applyQuaternion(this._quaternionStart).divide(this._parentScale);
267
+ } else {
268
+ this._offset.applyQuaternion(this._parentQuaternionInv).divide(this._parentScale);
269
+ }
270
+ object.position.copy(this._offset).add(this._positionStart);
271
+
272
+ // Apply translation snap
273
+
274
+ if (this.translationSnap) {
275
+ if (space === 'local') {
276
+ object.position.applyQuaternion(_tempQuaternion.copy(this._quaternionStart).invert());
277
+ if (axis.search('X') !== -1) {
278
+ object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
279
+ }
280
+ if (axis.search('Y') !== -1) {
281
+ object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
282
+ }
283
+ if (axis.search('Z') !== -1) {
284
+ object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
285
+ }
286
+ object.position.applyQuaternion(this._quaternionStart);
287
+ }
288
+ if (space === 'world') {
289
+ if (object.parent) {
290
+ object.position.add(_tempVector.setFromMatrixPosition(object.parent.matrixWorld));
291
+ }
292
+ if (axis.search('X') !== -1) {
293
+ object.position.x = Math.round(object.position.x / this.translationSnap) * this.translationSnap;
294
+ }
295
+ if (axis.search('Y') !== -1) {
296
+ object.position.y = Math.round(object.position.y / this.translationSnap) * this.translationSnap;
297
+ }
298
+ if (axis.search('Z') !== -1) {
299
+ object.position.z = Math.round(object.position.z / this.translationSnap) * this.translationSnap;
300
+ }
301
+ if (object.parent) {
302
+ object.position.sub(_tempVector.setFromMatrixPosition(object.parent.matrixWorld));
303
+ }
304
+ }
305
+ }
306
+ } else if (mode === 'scale') {
307
+ if (axis.search('XYZ') !== -1) {
308
+ var d = this.pointEnd.length() / this.pointStart.length();
309
+ if (this.pointEnd.dot(this.pointStart) < 0) d *= -1;
310
+ _tempVector2.set(d, d, d);
311
+ } else {
312
+ _tempVector.copy(this.pointStart);
313
+ _tempVector2.copy(this.pointEnd);
314
+ _tempVector.applyQuaternion(this._worldQuaternionInv);
315
+ _tempVector2.applyQuaternion(this._worldQuaternionInv);
316
+ _tempVector2.divide(_tempVector);
317
+ if (axis.search('X') === -1) {
318
+ _tempVector2.x = 1;
319
+ }
320
+ if (axis.search('Y') === -1) {
321
+ _tempVector2.y = 1;
322
+ }
323
+ if (axis.search('Z') === -1) {
324
+ _tempVector2.z = 1;
325
+ }
326
+ }
327
+
328
+ // Apply scale
329
+
330
+ object.scale.copy(this._scaleStart).multiply(_tempVector2);
331
+ if (this.scaleSnap) {
332
+ if (axis.search('X') !== -1) {
333
+ object.scale.x = Math.round(object.scale.x / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
334
+ }
335
+ if (axis.search('Y') !== -1) {
336
+ object.scale.y = Math.round(object.scale.y / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
337
+ }
338
+ if (axis.search('Z') !== -1) {
339
+ object.scale.z = Math.round(object.scale.z / this.scaleSnap) * this.scaleSnap || this.scaleSnap;
340
+ }
341
+ }
342
+ } else if (mode === 'rotate') {
343
+ this._offset.copy(this.pointEnd).sub(this.pointStart);
344
+ var ROTATION_SPEED = 20 / this.worldPosition.distanceTo(_tempVector.setFromMatrixPosition(this.camera.matrixWorld));
345
+ if (axis === 'E') {
346
+ this.rotationAxis.copy(this.eye);
347
+ this.rotationAngle = this.pointEnd.angleTo(this.pointStart);
348
+ this._startNorm.copy(this.pointStart).normalize();
349
+ this._endNorm.copy(this.pointEnd).normalize();
350
+ this.rotationAngle *= this._endNorm.cross(this._startNorm).dot(this.eye) < 0 ? 1 : -1;
351
+ } else if (axis === 'XYZE') {
352
+ this.rotationAxis.copy(this._offset).cross(this.eye).normalize();
353
+ this.rotationAngle = this._offset.dot(_tempVector.copy(this.rotationAxis).cross(this.eye)) * ROTATION_SPEED;
354
+ } else if (axis === 'X' || axis === 'Y' || axis === 'Z') {
355
+ this.rotationAxis.copy(_unit[axis]);
356
+ _tempVector.copy(_unit[axis]);
357
+ if (space === 'local') {
358
+ _tempVector.applyQuaternion(this.worldQuaternion);
359
+ }
360
+ this.rotationAngle = this._offset.dot(_tempVector.cross(this.eye).normalize()) * ROTATION_SPEED;
361
+ }
362
+
363
+ // Apply rotation snap
364
+
365
+ if (this.rotationSnap) this.rotationAngle = Math.round(this.rotationAngle / this.rotationSnap) * this.rotationSnap;
366
+
367
+ // Apply rotate
368
+ if (space === 'local' && axis !== 'E' && axis !== 'XYZE') {
369
+ object.quaternion.copy(this._quaternionStart);
370
+ object.quaternion.multiply(_tempQuaternion.setFromAxisAngle(this.rotationAxis, this.rotationAngle)).normalize();
371
+ } else {
372
+ this.rotationAxis.applyQuaternion(this._parentQuaternionInv);
373
+ object.quaternion.copy(_tempQuaternion.setFromAxisAngle(this.rotationAxis, this.rotationAngle));
374
+ object.quaternion.multiply(this._quaternionStart).normalize();
375
+ }
376
+ }
377
+ this.dispatchEvent(_changeEvent);
378
+ this.dispatchEvent(_objectChangeEvent);
379
+ }
380
+ }, {
381
+ key: "pointerUp",
382
+ value: function pointerUp(pointer) {
383
+ if (pointer.button !== 0) return;
384
+ if (this.dragging && this.axis !== null) {
385
+ _mouseUpEvent.mode = this.mode;
386
+ this.dispatchEvent(_mouseUpEvent);
387
+ }
388
+ this.dragging = false;
389
+ this.axis = null;
390
+ }
391
+ }, {
392
+ key: "dispose",
393
+ value: function dispose() {
394
+ this.domElement.removeEventListener('pointerdown', this._onPointerDown);
395
+ this.domElement.removeEventListener('pointermove', this._onPointerHover);
396
+ this.domElement.removeEventListener('pointermove', this._onPointerMove);
397
+ this.domElement.removeEventListener('pointerup', this._onPointerUp);
398
+ this.traverse(function (child) {
399
+ if (child.geometry) child.geometry.dispose();
400
+ if (child.material) child.material.dispose();
401
+ });
402
+ }
403
+
404
+ // Set current object
405
+ }, {
406
+ key: "attach",
407
+ value: function attach(object) {
408
+ this.object = object;
409
+ this.visible = true;
410
+ return this;
411
+ }
412
+
413
+ // Detach from object
414
+ }, {
415
+ key: "detach",
416
+ value: function detach() {
417
+ this.object = undefined;
418
+ this.visible = false;
419
+ this.axis = null;
420
+ return this;
421
+ }
422
+ }, {
423
+ key: "reset",
424
+ value: function reset() {
425
+ if (!this.enabled) return;
426
+ if (this.dragging) {
427
+ this.object.position.copy(this._positionStart);
428
+ this.object.quaternion.copy(this._quaternionStart);
429
+ this.object.scale.copy(this._scaleStart);
430
+ this.dispatchEvent(_changeEvent);
431
+ this.dispatchEvent(_objectChangeEvent);
432
+ this.pointStart.copy(this.pointEnd);
433
+ }
434
+ }
435
+ }, {
436
+ key: "getRaycaster",
437
+ value: function getRaycaster() {
438
+ return _raycaster;
439
+ }
440
+
441
+ // TODO: deprecate
442
+ }, {
443
+ key: "getMode",
444
+ value: function getMode() {
445
+ return this.mode;
446
+ }
447
+ }, {
448
+ key: "setMode",
449
+ value: function setMode(mode) {
450
+ this.mode = mode;
451
+ }
452
+ }, {
453
+ key: "setTranslationSnap",
454
+ value: function setTranslationSnap(translationSnap) {
455
+ this.translationSnap = translationSnap;
456
+ }
457
+ }, {
458
+ key: "setRotationSnap",
459
+ value: function setRotationSnap(rotationSnap) {
460
+ this.rotationSnap = rotationSnap;
461
+ }
462
+ }, {
463
+ key: "setScaleSnap",
464
+ value: function setScaleSnap(scaleSnap) {
465
+ this.scaleSnap = scaleSnap;
466
+ }
467
+ }, {
468
+ key: "setSize",
469
+ value: function setSize(size) {
470
+ this.size = size;
471
+ }
472
+ }, {
473
+ key: "setSpace",
474
+ value: function setSpace(space) {
475
+ this.space = space;
476
+ }
477
+ }, {
478
+ key: "setDelay",
479
+ value: function setDelay(clickTiming) {
480
+ this.clickDelay = clickTiming;
481
+ }
482
+ }, {
483
+ key: "updateInteractionTime",
484
+ value: function updateInteractionTime() {
485
+ this.lastInteractionTime = Date.now();
486
+ }
487
+ }]);
488
+ }(THREE.Object3D); // mouse / touch event handlers
489
+ function getPointer(event) {
490
+ if (this.domElement.ownerDocument.pointerLockElement) {
491
+ return {
492
+ x: 0,
493
+ y: 0,
494
+ button: event.button
495
+ };
496
+ } else {
497
+ var rect = this.domElement.getBoundingClientRect();
498
+ return {
499
+ x: (event.clientX - rect.left) / rect.width * 2 - 1,
500
+ y: -(event.clientY - rect.top) / rect.height * 2 + 1,
501
+ button: event.button
502
+ };
503
+ }
504
+ }
505
+ function onPointerHover(event) {
506
+ if (!this.enabled) return;
507
+ switch (event.pointerType) {
508
+ case 'mouse':
509
+ case 'pen':
510
+ this.pointerHover(this._getPointer(event));
511
+ break;
512
+ }
513
+ }
514
+ function onPointerDown(event) {
515
+ if (!this.enabled) return;
516
+ if (!document.pointerLockElement) {
517
+ this.domElement.setPointerCapture(event.pointerId);
518
+ }
519
+ this.domElement.addEventListener('pointermove', this._onPointerMove);
520
+ this.pointerHover(this._getPointer(event));
521
+ this.pointerDown(this._getPointer(event));
522
+ }
523
+ function onPointerMove(event) {
524
+ if (!this.enabled) return;
525
+ this.pointerMove(this._getPointer(event));
526
+ }
527
+ function onPointerUp(event) {
528
+ if (!this.enabled) return;
529
+ this.domElement.releasePointerCapture(event.pointerId);
530
+ this.domElement.removeEventListener('pointermove', this._onPointerMove);
531
+ this.pointerUp(this._getPointer(event));
532
+ }
533
+ function intersectObjectWithRay(object, raycaster, includeInvisible) {
534
+ var allIntersections = raycaster.intersectObject(object, true);
535
+ for (var i = 0; i < allIntersections.length; i++) {
536
+ if (allIntersections[i].object.visible || includeInvisible) {
537
+ return allIntersections[i];
538
+ }
539
+ }
540
+ return false;
541
+ }
542
+
543
+ //
544
+
545
+ // Reusable utility variables
546
+
547
+ var _tempEuler = new THREE.Euler();
548
+ var _alignVector = new THREE.Vector3(0, 1, 0);
549
+ var _zeroVector = new THREE.Vector3(0, 0, 0);
550
+ var _lookAtMatrix = new THREE.Matrix4();
551
+ var _tempQuaternion2 = new THREE.Quaternion();
552
+ var _identityQuaternion = new THREE.Quaternion();
553
+ var _dirVector = new THREE.Vector3();
554
+ var _tempMatrix = new THREE.Matrix4();
555
+ var _unitX = new THREE.Vector3(1, 0, 0);
556
+ var _unitY = new THREE.Vector3(0, 1, 0);
557
+ var _unitZ = new THREE.Vector3(0, 0, 1);
558
+ var _v1 = new THREE.Vector3();
559
+ var _v2 = new THREE.Vector3();
560
+ var _v3 = new THREE.Vector3();
561
+ var TransformControlsGizmo = /*#__PURE__*/function (_Object3D2) {
562
+ function TransformControlsGizmo() {
563
+ var _this2;
564
+ _rollupPluginBabelHelpers.classCallCheck(this, TransformControlsGizmo);
565
+ _this2 = _rollupPluginBabelHelpers.callSuper(this, TransformControlsGizmo);
566
+ _this2.isTransformControlsGizmo = true;
567
+ _this2.type = 'TransformControlsGizmo';
568
+
569
+ // shared materials
570
+
571
+ var gizmoMaterial = new THREE.MeshBasicMaterial({
572
+ depthTest: false,
573
+ depthWrite: false,
574
+ fog: false,
575
+ toneMapped: false,
576
+ transparent: true
577
+ });
578
+ var gizmoLineMaterial = new THREE.LineBasicMaterial({
579
+ depthTest: false,
580
+ depthWrite: false,
581
+ fog: false,
582
+ toneMapped: false,
583
+ transparent: true
584
+ });
585
+
586
+ // Make unique material for each axis/color
587
+
588
+ var matInvisible = gizmoMaterial.clone();
589
+ matInvisible.opacity = 0.15;
590
+ var matHelper = gizmoLineMaterial.clone();
591
+ matHelper.opacity = 0.5;
592
+ var matRed = gizmoMaterial.clone();
593
+ matRed.color.setHex(0xff0000);
594
+ var matGreen = gizmoMaterial.clone();
595
+ matGreen.color.setHex(0x00ff00);
596
+ var matBlue = gizmoMaterial.clone();
597
+ matBlue.color.setHex(0x0000ff);
598
+ var matRedTransparent = gizmoMaterial.clone();
599
+ matRedTransparent.color.setHex(0xff0000);
600
+ matRedTransparent.opacity = 0.5;
601
+ var matGreenTransparent = gizmoMaterial.clone();
602
+ matGreenTransparent.color.setHex(0x00ff00);
603
+ matGreenTransparent.opacity = 0.5;
604
+ var matBlueTransparent = gizmoMaterial.clone();
605
+ matBlueTransparent.color.setHex(0x0000ff);
606
+ matBlueTransparent.opacity = 0.5;
607
+ var matWhiteTransparent = gizmoMaterial.clone();
608
+ matWhiteTransparent.opacity = 0.25;
609
+ var matYellowTransparent = gizmoMaterial.clone();
610
+ matYellowTransparent.color.setHex(0xffff00);
611
+ matYellowTransparent.opacity = 0.25;
612
+ var matYellow = gizmoMaterial.clone();
613
+ matYellow.color.setHex(0xffff00);
614
+ var matGray = gizmoMaterial.clone();
615
+ matGray.color.setHex(0x787878);
616
+
617
+ // reusable geometry
618
+
619
+ var arrowGeometry = new THREE.CylinderGeometry(0, 0.04, 0.1, 12);
620
+ arrowGeometry.translate(0, 0.05, 0);
621
+ var scaleHandleGeometry = new THREE.BoxGeometry(0.08, 0.08, 0.08);
622
+ scaleHandleGeometry.translate(0, 0.04, 0);
623
+ var lineGeometry = new THREE.BufferGeometry();
624
+ lineGeometry.setAttribute('position', new THREE.Float32BufferAttribute([0, 0, 0, 1, 0, 0], 3));
625
+ var lineGeometry2 = new THREE.CylinderGeometry(0.0075, 0.0075, 0.5, 3);
626
+ lineGeometry2.translate(0, 0.25, 0);
627
+ function CircleGeometry(radius, arc) {
628
+ var geometry = new THREE.TorusGeometry(radius, 0.0075, 3, 64, arc * Math.PI * 2);
629
+ geometry.rotateY(Math.PI / 2);
630
+ geometry.rotateX(Math.PI / 2);
631
+ return geometry;
632
+ }
633
+
634
+ // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
635
+
636
+ function TranslateHelperGeometry() {
637
+ var geometry = new THREE.BufferGeometry();
638
+ geometry.setAttribute('position', new THREE.Float32BufferAttribute([0, 0, 0, 1, 1, 1], 3));
639
+ return geometry;
640
+ }
641
+
642
+ // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
643
+
644
+ var gizmoTranslate = {
645
+ X: [[new THREE.Mesh(arrowGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]], [new THREE.Mesh(arrowGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]], [new THREE.Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]]],
646
+ Y: [[new THREE.Mesh(arrowGeometry, matGreen), [0, 0.5, 0]], [new THREE.Mesh(arrowGeometry, matGreen), [0, -0.5, 0], [Math.PI, 0, 0]], [new THREE.Mesh(lineGeometry2, matGreen)]],
647
+ Z: [[new THREE.Mesh(arrowGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]], [new THREE.Mesh(arrowGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]], [new THREE.Mesh(lineGeometry2, matBlue), null, [Math.PI / 2, 0, 0]]],
648
+ XYZ: [[new THREE.Mesh(new THREE.OctahedronGeometry(0.1, 0), matWhiteTransparent.clone()), [0, 0, 0]]],
649
+ XY: [[new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent.clone()), [0.15, 0.15, 0]]],
650
+ YZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.15, 0.01), matRedTransparent.clone()), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
651
+ XZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent.clone()), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]]
652
+ };
653
+ var pickerTranslate = {
654
+ X: [[new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]], [new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]],
655
+ Y: [[new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]], [new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]],
656
+ Z: [[new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]], [new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]],
657
+ XYZ: [[new THREE.Mesh(new THREE.OctahedronGeometry(0.2, 0), matInvisible)]],
658
+ XY: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]]],
659
+ YZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
660
+ XZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]]
661
+ };
662
+ var helperTranslate = {
663
+ START: [[new THREE.Mesh(new THREE.OctahedronGeometry(0.01, 2), matHelper), null, null, null, 'helper']],
664
+ END: [[new THREE.Mesh(new THREE.OctahedronGeometry(0.01, 2), matHelper), null, null, null, 'helper']],
665
+ DELTA: [[new THREE.Line(TranslateHelperGeometry(), matHelper), null, null, null, 'helper']],
666
+ X: [[new THREE.Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']],
667
+ Y: [[new THREE.Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']],
668
+ Z: [[new THREE.Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']]
669
+ };
670
+ var gizmoRotate = {
671
+ XYZE: [[new THREE.Mesh(CircleGeometry(0.5, 1), matGray), null, [0, Math.PI / 2, 0]]],
672
+ X: [[new THREE.Mesh(CircleGeometry(0.5, 0.5), matRed)]],
673
+ Y: [[new THREE.Mesh(CircleGeometry(0.5, 0.5), matGreen), null, [0, 0, -Math.PI / 2]]],
674
+ Z: [[new THREE.Mesh(CircleGeometry(0.5, 0.5), matBlue), null, [0, Math.PI / 2, 0]]],
675
+ E: [[new THREE.Mesh(CircleGeometry(0.75, 1), matYellowTransparent), null, [0, Math.PI / 2, 0]]]
676
+ };
677
+ var helperRotate = {
678
+ AXIS: [[new THREE.Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']]
679
+ };
680
+ var pickerRotate = {
681
+ XYZE: [[new THREE.Mesh(new THREE.SphereGeometry(0.25, 10, 8), matInvisible)]],
682
+ X: [[new THREE.Mesh(new THREE.TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, -Math.PI / 2, -Math.PI / 2]]],
683
+ Y: [[new THREE.Mesh(new THREE.TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [Math.PI / 2, 0, 0]]],
684
+ Z: [[new THREE.Mesh(new THREE.TorusGeometry(0.5, 0.1, 4, 24), matInvisible), [0, 0, 0], [0, 0, -Math.PI / 2]]],
685
+ E: [[new THREE.Mesh(new THREE.TorusGeometry(0.75, 0.1, 2, 24), matInvisible)]]
686
+ };
687
+ var gizmoScale = {
688
+ X: [[new THREE.Mesh(scaleHandleGeometry, matRed), [0.5, 0, 0], [0, 0, -Math.PI / 2]], [new THREE.Mesh(lineGeometry2, matRed), [0, 0, 0], [0, 0, -Math.PI / 2]], [new THREE.Mesh(scaleHandleGeometry, matRed), [-0.5, 0, 0], [0, 0, Math.PI / 2]]],
689
+ Y: [[new THREE.Mesh(scaleHandleGeometry, matGreen), [0, 0.5, 0]], [new THREE.Mesh(lineGeometry2, matGreen)], [new THREE.Mesh(scaleHandleGeometry, matGreen), [0, -0.5, 0], [0, 0, Math.PI]]],
690
+ Z: [[new THREE.Mesh(scaleHandleGeometry, matBlue), [0, 0, 0.5], [Math.PI / 2, 0, 0]], [new THREE.Mesh(lineGeometry2, matBlue), [0, 0, 0], [Math.PI / 2, 0, 0]], [new THREE.Mesh(scaleHandleGeometry, matBlue), [0, 0, -0.5], [-Math.PI / 2, 0, 0]]],
691
+ XY: [[new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.15, 0.01), matBlueTransparent), [0.15, 0.15, 0]]],
692
+ YZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.15, 0.01), matRedTransparent), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
693
+ XZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.15, 0.15, 0.01), matGreenTransparent), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]],
694
+ XYZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.1, 0.1, 0.1), matWhiteTransparent.clone())]]
695
+ };
696
+ var pickerScale = {
697
+ X: [[new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0.3, 0, 0], [0, 0, -Math.PI / 2]], [new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [-0.3, 0, 0], [0, 0, Math.PI / 2]]],
698
+ Y: [[new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0.3, 0]], [new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, -0.3, 0], [0, 0, Math.PI]]],
699
+ Z: [[new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, 0.3], [Math.PI / 2, 0, 0]], [new THREE.Mesh(new THREE.CylinderGeometry(0.2, 0, 0.6, 4), matInvisible), [0, 0, -0.3], [-Math.PI / 2, 0, 0]]],
700
+ XY: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0.15, 0]]],
701
+ YZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0, 0.15, 0.15], [0, Math.PI / 2, 0]]],
702
+ XZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.01), matInvisible), [0.15, 0, 0.15], [-Math.PI / 2, 0, 0]]],
703
+ XYZ: [[new THREE.Mesh(new THREE.BoxGeometry(0.2, 0.2, 0.2), matInvisible), [0, 0, 0]]]
704
+ };
705
+ var helperScale = {
706
+ X: [[new THREE.Line(lineGeometry, matHelper.clone()), [-1e3, 0, 0], null, [1e6, 1, 1], 'helper']],
707
+ Y: [[new THREE.Line(lineGeometry, matHelper.clone()), [0, -1e3, 0], [0, 0, Math.PI / 2], [1e6, 1, 1], 'helper']],
708
+ Z: [[new THREE.Line(lineGeometry, matHelper.clone()), [0, 0, -1e3], [0, -Math.PI / 2, 0], [1e6, 1, 1], 'helper']]
709
+ };
710
+
711
+ // Creates an Object3D with gizmos described in custom hierarchy definition.
712
+
713
+ function setupGizmo(gizmoMap) {
714
+ var gizmo = new THREE.Object3D();
715
+ for (var name in gizmoMap) {
716
+ for (var i = gizmoMap[name].length; i--;) {
717
+ var object = gizmoMap[name][i][0].clone();
718
+ var position = gizmoMap[name][i][1];
719
+ var rotation = gizmoMap[name][i][2];
720
+ var scale = gizmoMap[name][i][3];
721
+ var tag = gizmoMap[name][i][4];
722
+
723
+ // name and tag properties are essential for picking and updating logic.
724
+ object.name = name;
725
+ object.tag = tag;
726
+ if (position) {
727
+ object.position.set(position[0], position[1], position[2]);
728
+ }
729
+ if (rotation) {
730
+ object.rotation.set(rotation[0], rotation[1], rotation[2]);
731
+ }
732
+ if (scale) {
733
+ object.scale.set(scale[0], scale[1], scale[2]);
734
+ }
735
+ object.updateMatrix();
736
+ var tempGeometry = object.geometry.clone();
737
+ tempGeometry.applyMatrix4(object.matrix);
738
+ object.geometry = tempGeometry;
739
+ object.renderOrder = Infinity;
740
+ object.position.set(0, 0, 0);
741
+ object.rotation.set(0, 0, 0);
742
+ object.scale.set(1, 1, 1);
743
+ gizmo.add(object);
744
+ }
745
+ }
746
+ return gizmo;
747
+ }
748
+
749
+ // Gizmo creation
750
+
751
+ _this2.gizmo = {};
752
+ _this2.picker = {};
753
+ _this2.helper = {};
754
+ _this2.add(_this2.gizmo['translate'] = setupGizmo(gizmoTranslate));
755
+ _this2.add(_this2.gizmo['rotate'] = setupGizmo(gizmoRotate));
756
+ _this2.add(_this2.gizmo['scale'] = setupGizmo(gizmoScale));
757
+ _this2.add(_this2.picker['translate'] = setupGizmo(pickerTranslate));
758
+ _this2.add(_this2.picker['rotate'] = setupGizmo(pickerRotate));
759
+ _this2.add(_this2.picker['scale'] = setupGizmo(pickerScale));
760
+ _this2.add(_this2.helper['translate'] = setupGizmo(helperTranslate));
761
+ _this2.add(_this2.helper['rotate'] = setupGizmo(helperRotate));
762
+ _this2.add(_this2.helper['scale'] = setupGizmo(helperScale));
763
+
764
+ // Pickers should be hidden always
765
+
766
+ _this2.picker['translate'].visible = false;
767
+ _this2.picker['rotate'].visible = false;
768
+ _this2.picker['scale'].visible = false;
769
+ return _this2;
770
+ }
771
+
772
+ // updateMatrixWorld will update transformations and appearance of individual handles
773
+ _rollupPluginBabelHelpers.inherits(TransformControlsGizmo, _Object3D2);
774
+ return _rollupPluginBabelHelpers.createClass(TransformControlsGizmo, [{
775
+ key: "updateMatrixWorld",
776
+ value: function updateMatrixWorld(force) {
777
+ var _this3 = this;
778
+ var space = this.mode === 'scale' ? 'local' : this.space; // scale always oriented to local rotation
779
+
780
+ var quaternion = space === 'local' ? this.worldQuaternion : _identityQuaternion;
781
+
782
+ // Show only gizmos for current transform mode
783
+
784
+ this.gizmo['translate'].visible = this.mode === 'translate';
785
+ this.gizmo['rotate'].visible = this.mode === 'rotate';
786
+ this.gizmo['scale'].visible = this.mode === 'scale';
787
+ this.helper['translate'].visible = this.mode === 'translate';
788
+ this.helper['rotate'].visible = this.mode === 'rotate';
789
+ this.helper['scale'].visible = this.mode === 'scale';
790
+ var handles = [];
791
+ handles = handles.concat(this.picker[this.mode].children);
792
+ handles = handles.concat(this.gizmo[this.mode].children);
793
+ handles = handles.concat(this.helper[this.mode].children);
794
+ var _loop = function _loop() {
795
+ var handle = handles[i];
796
+
797
+ // hide aligned to camera
798
+
799
+ handle.visible = true;
800
+ handle.rotation.set(0, 0, 0);
801
+ handle.position.copy(_this3.worldPosition);
802
+ var factor;
803
+ if (_this3.camera.isOrthographicCamera) {
804
+ factor = (_this3.camera.top - _this3.camera.bottom) / _this3.camera.zoom;
805
+ } else {
806
+ factor = _this3.worldPosition.distanceTo(_this3.cameraPosition) * Math.min(1.9 * Math.tan(Math.PI * _this3.camera.fov / 360) / _this3.camera.zoom, 7);
807
+ }
808
+ handle.scale.set(1, 1, 1).multiplyScalar(factor * _this3.size / 4);
809
+
810
+ // TODO: simplify helpers and consider decoupling from gizmo
811
+
812
+ if (handle.tag === 'helper') {
813
+ handle.visible = false;
814
+ if (handle.name === 'AXIS') {
815
+ handle.visible = !!_this3.axis;
816
+ if (_this3.axis === 'X') {
817
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, 0, 0));
818
+ handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
819
+ if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) {
820
+ handle.visible = false;
821
+ }
822
+ }
823
+ if (_this3.axis === 'Y') {
824
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, 0, Math.PI / 2));
825
+ handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
826
+ if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) {
827
+ handle.visible = false;
828
+ }
829
+ }
830
+ if (_this3.axis === 'Z') {
831
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
832
+ handle.quaternion.copy(quaternion).multiply(_tempQuaternion);
833
+ if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) > 0.9) {
834
+ handle.visible = false;
835
+ }
836
+ }
837
+ if (_this3.axis === 'XYZE') {
838
+ _tempQuaternion.setFromEuler(_tempEuler.set(0, Math.PI / 2, 0));
839
+ _alignVector.copy(_this3.rotationAxis);
840
+ handle.quaternion.setFromRotationMatrix(_lookAtMatrix.lookAt(_zeroVector, _alignVector, _unitY));
841
+ handle.quaternion.multiply(_tempQuaternion);
842
+ handle.visible = _this3.dragging;
843
+ }
844
+ if (_this3.axis === 'E') {
845
+ handle.visible = false;
846
+ }
847
+ } else if (handle.name === 'START') {
848
+ handle.position.copy(_this3.worldPositionStart);
849
+ handle.visible = _this3.dragging;
850
+ } else if (handle.name === 'END') {
851
+ handle.position.copy(_this3.worldPosition);
852
+ handle.visible = _this3.dragging;
853
+ } else if (handle.name === 'DELTA') {
854
+ handle.position.copy(_this3.worldPositionStart);
855
+ handle.quaternion.copy(_this3.worldQuaternionStart);
856
+ _tempVector.set(1e-10, 1e-10, 1e-10).add(_this3.worldPositionStart).sub(_this3.worldPosition).multiplyScalar(-1);
857
+ _tempVector.applyQuaternion(_this3.worldQuaternionStart.clone().invert());
858
+ handle.scale.copy(_tempVector);
859
+ handle.visible = _this3.dragging;
860
+ } else {
861
+ handle.quaternion.copy(quaternion);
862
+ if (_this3.dragging) {
863
+ handle.position.copy(_this3.worldPositionStart);
864
+ } else {
865
+ handle.position.copy(_this3.worldPosition);
866
+ }
867
+ if (_this3.axis) {
868
+ handle.visible = _this3.axis.search(handle.name) !== -1;
869
+ }
870
+ }
871
+
872
+ // If updating helper, skip rest of the loop
873
+ return 1; // continue
874
+ }
875
+
876
+ // Align handles to current local or world rotation
877
+
878
+ handle.quaternion.copy(quaternion);
879
+ if (_this3.mode === 'translate' || _this3.mode === 'scale') {
880
+ // Hide translate and scale axis facing the camera
881
+
882
+ var AXIS_HIDE_THRESHOLD = 0.99;
883
+ var PLANE_HIDE_THRESHOLD = 0.2;
884
+ if (handle.name === 'X') {
885
+ if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_THRESHOLD) {
886
+ handle.scale.set(1e-10, 1e-10, 1e-10);
887
+ handle.visible = false;
888
+ }
889
+ }
890
+ if (handle.name === 'Y') {
891
+ if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_THRESHOLD) {
892
+ handle.scale.set(1e-10, 1e-10, 1e-10);
893
+ handle.visible = false;
894
+ }
895
+ }
896
+ if (handle.name === 'Z') {
897
+ if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) > AXIS_HIDE_THRESHOLD) {
898
+ handle.scale.set(1e-10, 1e-10, 1e-10);
899
+ handle.visible = false;
900
+ }
901
+ }
902
+ if (handle.name === 'XY') {
903
+ if (Math.abs(_alignVector.copy(_unitZ).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_THRESHOLD) {
904
+ handle.scale.set(1e-10, 1e-10, 1e-10);
905
+ handle.visible = false;
906
+ }
907
+ }
908
+ if (handle.name === 'YZ') {
909
+ if (Math.abs(_alignVector.copy(_unitX).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_THRESHOLD) {
910
+ handle.scale.set(1e-10, 1e-10, 1e-10);
911
+ handle.visible = false;
912
+ }
913
+ }
914
+ if (handle.name === 'XZ') {
915
+ if (Math.abs(_alignVector.copy(_unitY).applyQuaternion(quaternion).dot(_this3.eye)) < PLANE_HIDE_THRESHOLD) {
916
+ handle.scale.set(1e-10, 1e-10, 1e-10);
917
+ handle.visible = false;
918
+ }
919
+ }
920
+ } else if (_this3.mode === 'rotate') {
921
+ // Align handles to current local or world rotation
922
+
923
+ _tempQuaternion2.copy(quaternion);
924
+ _alignVector.copy(_this3.eye).applyQuaternion(_tempQuaternion.copy(quaternion).invert());
925
+ if (handle.name.search('E') !== -1) {
926
+ handle.quaternion.setFromRotationMatrix(_lookAtMatrix.lookAt(_this3.eye, _zeroVector, _unitY));
927
+ }
928
+ if (handle.name === 'X') {
929
+ _tempQuaternion.setFromAxisAngle(_unitX, Math.atan2(-_alignVector.y, _alignVector.z));
930
+ _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
931
+ handle.quaternion.copy(_tempQuaternion);
932
+ }
933
+ if (handle.name === 'Y') {
934
+ _tempQuaternion.setFromAxisAngle(_unitY, Math.atan2(_alignVector.x, _alignVector.z));
935
+ _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
936
+ handle.quaternion.copy(_tempQuaternion);
937
+ }
938
+ if (handle.name === 'Z') {
939
+ _tempQuaternion.setFromAxisAngle(_unitZ, Math.atan2(_alignVector.y, _alignVector.x));
940
+ _tempQuaternion.multiplyQuaternions(_tempQuaternion2, _tempQuaternion);
941
+ handle.quaternion.copy(_tempQuaternion);
942
+ }
943
+ }
944
+
945
+ // Hide disabled axes
946
+ handle.visible = handle.visible && (handle.name.indexOf('X') === -1 || _this3.showX);
947
+ handle.visible = handle.visible && (handle.name.indexOf('Y') === -1 || _this3.showY);
948
+ handle.visible = handle.visible && (handle.name.indexOf('Z') === -1 || _this3.showZ);
949
+ handle.visible = handle.visible && (handle.name.indexOf('E') === -1 || _this3.showX && _this3.showY && _this3.showZ);
950
+
951
+ // Hide disabled plane helpers
952
+ handle.visible = handle.visible && (handle.name !== 'XY' || _this3.showXY);
953
+ handle.visible = handle.visible && (handle.name !== 'YZ' || _this3.showYZ);
954
+ handle.visible = handle.visible && (handle.name !== 'XZ' || _this3.showXZ);
955
+
956
+ // highlight selected axis
957
+
958
+ handle.material._color = handle.material._color || handle.material.color.clone();
959
+ handle.material._opacity = handle.material._opacity || handle.material.opacity;
960
+ handle.material.color.copy(handle.material._color);
961
+ handle.material.opacity = handle.material._opacity;
962
+ if (_this3.enabled && _this3.axis) {
963
+ if (handle.name === _this3.axis) {
964
+ handle.material.color.setHex(0xffff00);
965
+ handle.material.opacity = 1.0;
966
+ } else if (_this3.axis.split('').some(function (a) {
967
+ return handle.name === a;
968
+ })) {
969
+ handle.material.color.setHex(0xffff00);
970
+ handle.material.opacity = 1.0;
971
+ }
972
+ }
973
+ };
974
+ for (var i = 0; i < handles.length; i++) {
975
+ if (_loop()) continue;
976
+ }
977
+ _rollupPluginBabelHelpers.superPropGet(TransformControlsGizmo, "updateMatrixWorld", this, 3)([force]);
978
+ }
979
+ }]);
980
+ }(THREE.Object3D); //
981
+ var TransformControlsPlane = /*#__PURE__*/function (_Mesh) {
982
+ function TransformControlsPlane() {
983
+ var _this4;
984
+ _rollupPluginBabelHelpers.classCallCheck(this, TransformControlsPlane);
985
+ _this4 = _rollupPluginBabelHelpers.callSuper(this, TransformControlsPlane, [new THREE.PlaneGeometry(100000, 100000, 2, 2), new THREE.MeshBasicMaterial({
986
+ visible: false,
987
+ wireframe: true,
988
+ side: THREE.DoubleSide,
989
+ transparent: true,
990
+ opacity: 0.1,
991
+ toneMapped: false
992
+ })]);
993
+ _this4.isTransformControlsPlane = true;
994
+ _this4.type = 'TransformControlsPlane';
995
+ return _this4;
996
+ }
997
+ _rollupPluginBabelHelpers.inherits(TransformControlsPlane, _Mesh);
998
+ return _rollupPluginBabelHelpers.createClass(TransformControlsPlane, [{
999
+ key: "updateMatrixWorld",
1000
+ value: function updateMatrixWorld(force) {
1001
+ var space = this.space;
1002
+ this.position.copy(this.worldPosition);
1003
+ if (this.mode === 'scale') space = 'local'; // scale always oriented to local rotation
1004
+
1005
+ _v1.copy(_unitX).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
1006
+ _v2.copy(_unitY).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
1007
+ _v3.copy(_unitZ).applyQuaternion(space === 'local' ? this.worldQuaternion : _identityQuaternion);
1008
+
1009
+ // Align the plane for current transform mode, axis and space.
1010
+
1011
+ _alignVector.copy(_v2);
1012
+ switch (this.mode) {
1013
+ case 'translate':
1014
+ case 'scale':
1015
+ switch (this.axis) {
1016
+ case 'X':
1017
+ _alignVector.copy(this.eye).cross(_v1);
1018
+ _dirVector.copy(_v1).cross(_alignVector);
1019
+ break;
1020
+ case 'Y':
1021
+ _alignVector.copy(this.eye).cross(_v2);
1022
+ _dirVector.copy(_v2).cross(_alignVector);
1023
+ break;
1024
+ case 'Z':
1025
+ _alignVector.copy(this.eye).cross(_v3);
1026
+ _dirVector.copy(_v3).cross(_alignVector);
1027
+ break;
1028
+ case 'XY':
1029
+ _dirVector.copy(_v3);
1030
+ break;
1031
+ case 'YZ':
1032
+ _dirVector.copy(_v1);
1033
+ break;
1034
+ case 'XZ':
1035
+ _alignVector.copy(_v3);
1036
+ _dirVector.copy(_v2);
1037
+ break;
1038
+ case 'XYZ':
1039
+ case 'E':
1040
+ _dirVector.set(0, 0, 0);
1041
+ break;
1042
+ }
1043
+ break;
1044
+ case 'rotate':
1045
+ default:
1046
+ // special case for rotate
1047
+ _dirVector.set(0, 0, 0);
1048
+ }
1049
+ if (_dirVector.length() === 0) {
1050
+ // If in rotate mode, make the plane parallel to camera
1051
+ this.quaternion.copy(this.cameraQuaternion);
1052
+ } else {
1053
+ _tempMatrix.lookAt(_tempVector.set(0, 0, 0), _dirVector, _alignVector);
1054
+ this.quaternion.setFromRotationMatrix(_tempMatrix);
1055
+ }
1056
+ _rollupPluginBabelHelpers.superPropGet(TransformControlsPlane, "updateMatrixWorld", this, 3)([force]);
1057
+ }
1058
+ }]);
1059
+ }(THREE.Mesh);
1060
+
1061
+ exports.TransformControls = TransformControls;
1062
+ exports.TransformControlsGizmo = TransformControlsGizmo;
1063
+ exports.TransformControlsPlane = TransformControlsPlane;