castle-web-cli 0.4.236 → 0.4.238

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 (218) hide show
  1. package/dist/api.d.ts +2 -0
  2. package/dist/bundle.d.ts +24 -0
  3. package/dist/bundle.js +447 -4
  4. package/dist/bundleLatin1.d.ts +6 -0
  5. package/dist/bundleLatin1.js +333 -0
  6. package/dist/castle-host/host.d.ts +10 -1
  7. package/dist/castle-host/host.js +78 -9
  8. package/dist/castleJson.d.ts +20 -0
  9. package/dist/castleJson.js +40 -0
  10. package/dist/deckExports.d.ts +35 -0
  11. package/dist/deckExports.js +365 -0
  12. package/dist/importCheckHook.d.ts +1 -0
  13. package/dist/importCheckHook.js +1 -1
  14. package/dist/index.js +5 -0
  15. package/dist/init.js +2 -1
  16. package/dist/save-deck.js +18 -13
  17. package/kits/base/castle.json +1 -1
  18. package/kits/base/sdk/README.md +47 -0
  19. package/kits/base/sdk/castle.d.ts +3 -1
  20. package/kits/base/sdk/castle.js +1 -0
  21. package/kits/base/sdk/commands.d.ts +25 -1
  22. package/kits/base/sdk/commands.js +29 -1
  23. package/kits/base/sdk/hub.d.ts +17 -0
  24. package/kits/base/sdk/hub.js +33 -9
  25. package/kits/base/sdk/localCache.d.ts +27 -0
  26. package/kits/base/sdk/localCache.js +115 -0
  27. package/kits/base/sdk/localCacheStore.d.ts +15 -0
  28. package/kits/base/sdk/localCacheStore.js +358 -0
  29. package/kits/base/sdk/transport.d.ts +1 -0
  30. package/kits/base/sdk/transport.js +4 -5
  31. package/kits/hub-game/CLAUDE.md +22 -2
  32. package/kits/hub-game/castle.json +4 -1
  33. package/kits/hub-game/code/client/act.js +66 -91
  34. package/kits/hub-game/code/client/actCore.js +134 -0
  35. package/kits/hub-game/code/client/car.js +35 -0
  36. package/kits/hub-game/code/client/chrome.js +207 -381
  37. package/kits/hub-game/code/client/crowdNames.js +2 -2
  38. package/kits/hub-game/code/client/emoteWheel.js +109 -0
  39. package/kits/hub-game/code/client/hats.js +2 -0
  40. package/kits/hub-game/code/client/hookLayer.js +99 -48
  41. package/kits/hub-game/code/client/hostGo.js +77 -0
  42. package/kits/hub-game/code/client/hubControls.js +125 -0
  43. package/kits/hub-game/code/client/hubEntry.js +187 -0
  44. package/kits/hub-game/code/client/hudSurface.js +148 -0
  45. package/kits/hub-game/code/client/hudTree.js +96 -0
  46. package/kits/hub-game/code/client/idle.js +59 -13
  47. package/kits/hub-game/code/client/invites.js +13 -4
  48. package/kits/hub-game/code/client/menuIcons.js +8 -0
  49. package/kits/hub-game/code/client/noTrips.js +38 -0
  50. package/kits/hub-game/code/client/qualityEntry.js +6 -1
  51. package/kits/hub-game/code/client/rehello.js +3 -1
  52. package/kits/hub-game/code/client/riders.js +26 -0
  53. package/kits/hub-game/code/client/role.js +79 -0
  54. package/kits/hub-game/code/client/safeLayout.js +32 -3
  55. package/kits/hub-game/code/client/sound.js +10 -3
  56. package/kits/hub-game/code/client/soundscape.js +2 -2
  57. package/kits/hub-game/code/client/soundscapeAmbience.js +38 -8
  58. package/kits/hub-game/code/client/soundscapeBaked.js +24 -5
  59. package/kits/hub-game/code/client/soundscapeCues.js +2 -1
  60. package/kits/hub-game/code/client/state.js +19 -0
  61. package/kits/hub-game/code/client/stuck.js +2 -1
  62. package/kits/hub-game/code/client/talkSurface.js +178 -0
  63. package/kits/hub-game/code/client/talkTree.js +238 -0
  64. package/kits/hub-game/code/client/tiers.js +8 -5
  65. package/kits/hub-game/code/client/uiDom.js +600 -0
  66. package/kits/hub-game/code/client/uiTree.js +359 -0
  67. package/kits/hub-game/code/client/vehicle.js +154 -0
  68. package/kits/hub-game/code/client/wear.js +27 -5
  69. package/kits/hub-game/code/client/worldLabels.js +3 -2
  70. package/kits/hub-game/code/client/yours.js +10 -3
  71. package/kits/hub-game/code/server/actors.js +4 -3
  72. package/kits/hub-game/code/server/analytics.js +56 -6
  73. package/kits/hub-game/code/server/decor.js +56 -16
  74. package/kits/hub-game/code/server/hub.js +258 -46
  75. package/kits/hub-game/code/server/idle.js +118 -5
  76. package/kits/hub-game/code/server/manifest.js +46 -4
  77. package/kits/hub-game/code/server/npcs.js +4 -2
  78. package/kits/hub-game/code/server/players.js +3 -0
  79. package/kits/hub-game/code/server/role.js +142 -0
  80. package/kits/hub-game/code/server/standing.js +6 -4
  81. package/kits/hub-game/code/server/vehicle.js +126 -0
  82. package/kits/hub-game/code/shared/car.js +52 -0
  83. package/kits/hub-game/code/shared/deckFlags.js +34 -0
  84. package/kits/hub-game/code/shared/deviceClass.js +39 -0
  85. package/kits/hub-game/code/shared/expression.js +9 -0
  86. package/kits/hub-game/code/systems/hub.js +300 -85
  87. package/kits/hub-game/docs/analytics.md +11 -2
  88. package/kits/hub-game/docs/contract.md +353 -14
  89. package/kits/hub-game/docs/vehicle-preset.md +132 -0
  90. package/kits/hub-game/models/hats/baker-cap.pxmodel +89 -0
  91. package/kits/hub-game/models/hats/chef-toque.pxmodel +60 -0
  92. package/kits/hub-game/models/hats/delivery-cap.pxmodel +105 -0
  93. package/kits/hub-game/models/hats/fire-helmet.pxmodel +87 -0
  94. package/kits/hub-game/models/hats/hard-hat.pxmodel +71 -0
  95. package/kits/hub-game/models/hats/nurse-cap.pxmodel +61 -0
  96. package/kits/hub-game/models/hats/police-cap.pxmodel +105 -0
  97. package/kits/hub-game/models/hats/teacher-beret.pxmodel +52 -0
  98. package/kits/hub-game/models/role/square/top-apron.pxmodel +109 -0
  99. package/kits/hub-game/models/role/square/top-cardigan.pxmodel +141 -0
  100. package/kits/hub-game/models/role/square/top-coat.pxmodel +157 -0
  101. package/kits/hub-game/models/role/square/top-scrubs.pxmodel +93 -0
  102. package/kits/hub-game/models/role/square/top-tabard.pxmodel +109 -0
  103. package/kits/hub-game/models/role/square/top-vest.pxmodel +109 -0
  104. package/kits/hub-game/models/role/tool-bag.pxmodel +75 -0
  105. package/kits/hub-game/models/role/tool-bell.pxmodel +71 -0
  106. package/kits/hub-game/models/role/tool-hose.pxmodel +60 -0
  107. package/kits/hub-game/models/role/tool-parcel.pxmodel +61 -0
  108. package/kits/hub-game/models/role/tool-torch.pxmodel +55 -0
  109. package/kits/hub-game/models/role/tool-tray.pxmodel +75 -0
  110. package/kits/hub-game/models/role/top-apron.pxmodel +70 -0
  111. package/kits/hub-game/models/role/top-cardigan.pxmodel +102 -0
  112. package/kits/hub-game/models/role/top-coat.pxmodel +79 -0
  113. package/kits/hub-game/models/role/top-scrubs.pxmodel +54 -0
  114. package/kits/hub-game/models/role/top-tabard.pxmodel +70 -0
  115. package/kits/hub-game/models/role/top-vest.pxmodel +70 -0
  116. package/kits/hub-game/package-lock.json +1 -1
  117. package/kits/hub-game/package.json +1 -1
  118. package/kits/hub-game/scripts/check.mjs +7 -4
  119. package/kits/hub-game/scripts/fixtures/car-vectors.json +279 -0
  120. package/kits/hub-game/scripts/fixtures/decor-keyless-draw.json +2 -1
  121. package/kits/hub-game/scripts/fixtures/hud-surface.json +670 -0
  122. package/kits/hub-game/scripts/fixtures/talk-surface.json +3930 -0
  123. package/kits/hub-game/scripts/gen-hats.mjs +46 -2
  124. package/kits/hub-game/scripts/gen-role.mjs +80 -0
  125. package/kits/hub-game/scripts/test-act-core.mjs +167 -0
  126. package/kits/hub-game/scripts/test-actions-client.mjs +34 -0
  127. package/kits/hub-game/scripts/test-actors.mjs +48 -0
  128. package/kits/hub-game/scripts/test-analytics.mjs +99 -5
  129. package/kits/hub-game/scripts/test-apply-deck.mjs +122 -0
  130. package/kits/hub-game/scripts/test-back-visibility.mjs +3 -1
  131. package/kits/hub-game/scripts/test-ballot.mjs +2 -0
  132. package/kits/hub-game/scripts/test-car.mjs +43 -0
  133. package/kits/hub-game/scripts/test-decor-client.mjs +2 -1
  134. package/kits/hub-game/scripts/test-decor.mjs +77 -0
  135. package/kits/hub-game/scripts/test-device-class.mjs +83 -0
  136. package/kits/hub-game/scripts/test-emote-wheel.mjs +374 -0
  137. package/kits/hub-game/scripts/test-hats.mjs +5 -4
  138. package/kits/hub-game/scripts/test-host-go.mjs +265 -0
  139. package/kits/hub-game/scripts/test-hub-controls.mjs +108 -0
  140. package/kits/hub-game/scripts/test-hub-entry.mjs +531 -0
  141. package/kits/hub-game/scripts/test-hub-ops.mjs +75 -0
  142. package/kits/hub-game/scripts/test-hub-trip.mjs +85 -0
  143. package/kits/hub-game/scripts/test-hud-clear.mjs +12 -2
  144. package/kits/hub-game/scripts/test-hud-rate.mjs +6 -2
  145. package/kits/hub-game/scripts/test-hud-surface.mjs +272 -0
  146. package/kits/hub-game/scripts/test-idle.mjs +347 -1
  147. package/kits/hub-game/scripts/test-interest-cells.mjs +8 -1
  148. package/kits/hub-game/scripts/test-invites-client.mjs +42 -1
  149. package/kits/hub-game/scripts/test-manifest.mjs +30 -0
  150. package/kits/hub-game/scripts/test-no-trips.mjs +42 -0
  151. package/kits/hub-game/scripts/test-placement-cache.mjs +1 -1
  152. package/kits/hub-game/scripts/test-quality.mjs +13 -0
  153. package/kits/hub-game/scripts/test-rehello.mjs +258 -3
  154. package/kits/hub-game/scripts/test-resume-pose-server.mjs +203 -0
  155. package/kits/hub-game/scripts/test-resync.mjs +183 -0
  156. package/kits/hub-game/scripts/test-role-client.mjs +421 -0
  157. package/kits/hub-game/scripts/test-role.mjs +350 -0
  158. package/kits/hub-game/scripts/test-safe-layout.mjs +50 -1
  159. package/kits/hub-game/scripts/test-soundscape.mjs +124 -7
  160. package/kits/hub-game/scripts/test-standing.mjs +15 -1
  161. package/kits/hub-game/scripts/test-talk-surface.mjs +296 -0
  162. package/kits/hub-game/scripts/test-tiers.mjs +13 -0
  163. package/kits/hub-game/scripts/test-ui-dom-dom.mjs +96 -0
  164. package/kits/hub-game/scripts/test-ui-tree.mjs +711 -0
  165. package/kits/hub-game/scripts/test-vehicle-client.mjs +159 -0
  166. package/kits/hub-game/scripts/test-vehicle.mjs +135 -0
  167. package/kits/hub-game/scripts/test-yours.mjs +33 -0
  168. package/kits/hub-game/tools/hubScene/export.mjs +613 -0
  169. package/kits/hub-game/tools/hubScene/hubdata.mjs +921 -0
  170. package/kits/hub-game/tools/hubScene/merge-root.mjs +39 -0
  171. package/kits/hub-game/tools/hubScene/nodeworld.mjs +227 -0
  172. package/kits/hub-game/tools/hubScene/test/export-fixture.mjs +798 -0
  173. package/kits/hub-game/tools/hubScene/test/fixture.json +637 -0
  174. package/kits/hub-game/tools/hubScene/test/paint-export.mjs +40 -0
  175. package/kits/hub-game/tools/hubScene/test/upload.test.mjs +655 -0
  176. package/kits/hub-game/tools/hubScene/upload.mjs +636 -0
  177. package/kits/hub-game/tools/hubScene/validate-manifest.mjs +291 -0
  178. package/kits/multiplayer-3d/castle.json +4 -4
  179. package/kits/multiplayer-3d/code/client/resumeGate.js +30 -2
  180. package/kits/multiplayer-3d/code/client/steer.js +3 -1
  181. package/kits/multiplayer-3d/code/systems/multiplayer.js +30 -2
  182. package/kits/multiplayer-3d/package-lock.json +1 -1
  183. package/kits/multiplayer-3d/scripts/test-resume-gate.mjs +74 -2
  184. package/kits/physics-3d/CLAUDE.md +1 -1
  185. package/kits/physics-3d/behaviors/Player.jsx +37 -27
  186. package/kits/physics-3d/castle.json +2 -2
  187. package/kits/physics-3d/docs/engine-geometry-memory.md +23 -0
  188. package/kits/physics-3d/engine3d/memoryprofile.js +17 -0
  189. package/kits/physics-3d/engine3d/playerRun.js +6 -1
  190. package/kits/physics-3d/engine3d/pxmodel.js +6 -1
  191. package/kits/physics-3d/engine3d/world3d.js +6 -3
  192. package/kits/physics-3d/package.json +1 -1
  193. package/kits/physics-3d/play/behaviors/Player.js +40 -28
  194. package/kits/physics-3d/scripts/test-memory-profile.mjs +237 -0
  195. package/kits/physics-3d/systems/physics3d.js +5 -2
  196. package/kits/real-time/castle.json +2 -2
  197. package/kits/real-time/code/client/messages.js +5 -0
  198. package/kits/real-time/code/server/session.js +28 -1
  199. package/kits/real-time/package-lock.json +1 -1
  200. package/package.json +5 -4
  201. package/vendor/three/LICENSE +21 -0
  202. package/vendor/three/build/three.core.js +58773 -0
  203. package/vendor/three/build/three.module.js +18251 -0
  204. package/vendor/three/examples/jsm/controls/OrbitControls.js +1860 -0
  205. package/vendor/three/examples/jsm/controls/TransformControls.js +1918 -0
  206. package/vendor/three/examples/jsm/exporters/GLTFExporter.js +3595 -0
  207. package/vendor/three/examples/jsm/geometries/RoundedBoxGeometry.js +216 -0
  208. package/vendor/three/examples/jsm/math/MeshSurfaceSampler.js +315 -0
  209. package/vendor/three/examples/jsm/postprocessing/EffectComposer.js +363 -0
  210. package/vendor/three/examples/jsm/postprocessing/MaskPass.js +195 -0
  211. package/vendor/three/examples/jsm/postprocessing/OutputPass.js +139 -0
  212. package/vendor/three/examples/jsm/postprocessing/Pass.js +191 -0
  213. package/vendor/three/examples/jsm/postprocessing/RenderPass.js +183 -0
  214. package/vendor/three/examples/jsm/postprocessing/ShaderPass.js +135 -0
  215. package/vendor/three/examples/jsm/shaders/CopyShader.js +52 -0
  216. package/vendor/three/examples/jsm/shaders/OutputShader.js +103 -0
  217. package/vendor/three/examples/jsm/utils/BufferGeometryUtils.js +1435 -0
  218. package/vendor/three/package.json +134 -0
@@ -0,0 +1,1918 @@
1
+ import {
2
+ BoxGeometry,
3
+ BufferGeometry,
4
+ Controls,
5
+ CylinderGeometry,
6
+ DoubleSide,
7
+ Euler,
8
+ Float32BufferAttribute,
9
+ Line,
10
+ LineBasicMaterial,
11
+ Matrix4,
12
+ Mesh,
13
+ MeshBasicMaterial,
14
+ Object3D,
15
+ OctahedronGeometry,
16
+ PlaneGeometry,
17
+ Quaternion,
18
+ Raycaster,
19
+ SphereGeometry,
20
+ TorusGeometry,
21
+ Vector3
22
+ } from 'three';
23
+
24
+ const _raycaster = new Raycaster();
25
+
26
+ const _tempVector = new Vector3();
27
+ const _tempVector2 = new Vector3();
28
+ const _tempQuaternion = new Quaternion();
29
+ const _unit = {
30
+ X: new Vector3( 1, 0, 0 ),
31
+ Y: new Vector3( 0, 1, 0 ),
32
+ Z: new Vector3( 0, 0, 1 )
33
+ };
34
+
35
+ /**
36
+ * Fires if any type of change (object or property change) is performed. Property changes
37
+ * are separate events you can add event listeners to. The event type is "propertyname-changed".
38
+ *
39
+ * @event TransformControls#change
40
+ * @type {Object}
41
+ */
42
+ const _changeEvent = { type: 'change' };
43
+
44
+ /**
45
+ * Fires if a pointer (mouse/touch) becomes active.
46
+ *
47
+ * @event TransformControls#mouseDown
48
+ * @type {Object}
49
+ */
50
+ const _mouseDownEvent = { type: 'mouseDown', mode: null };
51
+
52
+ /**
53
+ * Fires if a pointer (mouse/touch) is no longer active.
54
+ *
55
+ * @event TransformControls#mouseUp
56
+ * @type {Object}
57
+ */
58
+ const _mouseUpEvent = { type: 'mouseUp', mode: null };
59
+
60
+ /**
61
+ * Fires if the controlled 3D object is changed.
62
+ *
63
+ * @event TransformControls#objectChange
64
+ * @type {Object}
65
+ */
66
+ const _objectChangeEvent = { type: 'objectChange' };
67
+
68
+ /**
69
+ * This class can be used to transform objects in 3D space by adapting a similar interaction model
70
+ * of DCC tools like Blender. Unlike other controls, it is not intended to transform the scene's camera.
71
+ *
72
+ * `TransformControls` expects that its attached 3D object is part of the scene graph.
73
+ *
74
+ * @augments Controls
75
+ * @three_import import { TransformControls } from 'three/addons/controls/TransformControls.js';
76
+ */
77
+ class TransformControls extends Controls {
78
+
79
+ /**
80
+ * Constructs a new controls instance.
81
+ *
82
+ * @param {Camera} camera - The camera of the rendered scene.
83
+ * @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
84
+ */
85
+ constructor( camera, domElement = null ) {
86
+
87
+ super( undefined, domElement );
88
+
89
+ const root = new TransformControlsRoot( this );
90
+ this._root = root;
91
+
92
+ const gizmo = new TransformControlsGizmo();
93
+ this._gizmo = gizmo;
94
+ root.add( gizmo );
95
+
96
+ const plane = new TransformControlsPlane();
97
+ this._plane = plane;
98
+ root.add( plane );
99
+
100
+ const scope = this;
101
+
102
+ // Defined getter, setter and store for a property
103
+ function defineProperty( propName, defaultValue ) {
104
+
105
+ let propValue = defaultValue;
106
+
107
+ Object.defineProperty( scope, propName, {
108
+
109
+ get: function () {
110
+
111
+ return propValue !== undefined ? propValue : defaultValue;
112
+
113
+ },
114
+
115
+ set: function ( value ) {
116
+
117
+ if ( propValue !== value ) {
118
+
119
+ propValue = value;
120
+ plane[ propName ] = value;
121
+ gizmo[ propName ] = value;
122
+
123
+ scope.dispatchEvent( { type: propName + '-changed', value: value } );
124
+ scope.dispatchEvent( _changeEvent );
125
+
126
+ }
127
+
128
+ }
129
+
130
+ } );
131
+
132
+ scope[ propName ] = defaultValue;
133
+ plane[ propName ] = defaultValue;
134
+ gizmo[ propName ] = defaultValue;
135
+
136
+ }
137
+
138
+ // Define properties with getters/setter
139
+ // Setting the defined property will automatically trigger change event
140
+ // Defined properties are passed down to gizmo and plane
141
+
142
+ /**
143
+ * The camera of the rendered scene.
144
+ *
145
+ * @name TransformControls#camera
146
+ * @type {Camera}
147
+ */
148
+ defineProperty( 'camera', camera );
149
+ defineProperty( 'object', undefined );
150
+ defineProperty( 'enabled', true );
151
+
152
+ /**
153
+ * The current transformation axis.
154
+ *
155
+ * @name TransformControls#axis
156
+ * @type {string}
157
+ */
158
+ defineProperty( 'axis', null );
159
+
160
+ /**
161
+ * The current transformation axis.
162
+ *
163
+ * @name TransformControls#mode
164
+ * @type {('translate'|'rotate'|'scale')}
165
+ * @default 'translate'
166
+ */
167
+ defineProperty( 'mode', 'translate' );
168
+
169
+ /**
170
+ * By default, 3D objects are continuously translated. If you set this property to a numeric
171
+ * value (world units), you can define in which steps the 3D object should be translated.
172
+ *
173
+ * @name TransformControls#translationSnap
174
+ * @type {?number}
175
+ * @default null
176
+ */
177
+ defineProperty( 'translationSnap', null );
178
+
179
+ /**
180
+ * By default, 3D objects are continuously rotated. If you set this property to a numeric
181
+ * value (radians), you can define in which steps the 3D object should be rotated.
182
+ *
183
+ * @name TransformControls#rotationSnap
184
+ * @type {?number}
185
+ * @default null
186
+ */
187
+ defineProperty( 'rotationSnap', null );
188
+
189
+ /**
190
+ * By default, 3D objects are continuously scaled. If you set this property to a numeric
191
+ * value, you can define in which steps the 3D object should be scaled.
192
+ *
193
+ * @name TransformControls#scaleSnap
194
+ * @type {?number}
195
+ * @default null
196
+ */
197
+ defineProperty( 'scaleSnap', null );
198
+
199
+ /**
200
+ * Defines in which coordinate space transformations should be performed.
201
+ *
202
+ * @name TransformControls#space
203
+ * @type {('world'|'local')}
204
+ * @default 'world'
205
+ */
206
+ defineProperty( 'space', 'world' );
207
+
208
+ /**
209
+ * The size of the helper UI (axes/planes).
210
+ *
211
+ * @name TransformControls#size
212
+ * @type {number}
213
+ * @default 1
214
+ */
215
+ defineProperty( 'size', 1 );
216
+
217
+ /**
218
+ * Whether dragging is currently performed or not.
219
+ *
220
+ * @name TransformControls#dragging
221
+ * @type {boolean}
222
+ * @readonly
223
+ * @default false
224
+ */
225
+ defineProperty( 'dragging', false );
226
+
227
+ /**
228
+ * Whether the x-axis helper should be visible or not.
229
+ *
230
+ * @name TransformControls#showX
231
+ * @type {boolean}
232
+ * @default true
233
+ */
234
+ defineProperty( 'showX', true );
235
+
236
+ /**
237
+ * Whether the y-axis helper should be visible or not.
238
+ *
239
+ * @name TransformControls#showY
240
+ * @type {boolean}
241
+ * @default true
242
+ */
243
+ defineProperty( 'showY', true );
244
+
245
+ /**
246
+ * Whether the z-axis helper should be visible or not.
247
+ *
248
+ * @name TransformControls#showZ
249
+ * @type {boolean}
250
+ * @default true
251
+ */
252
+ defineProperty( 'showZ', true );
253
+
254
+ /**
255
+ * The minimum allowed X position during translation.
256
+ *
257
+ * @name TransformControls#minX
258
+ * @type {number}
259
+ * @default -Infinity
260
+ */
261
+ defineProperty( 'minX', - Infinity );
262
+
263
+ /**
264
+ * The maximum allowed X position during translation.
265
+ *
266
+ * @name TransformControls#maxX
267
+ * @type {number}
268
+ * @default Infinity
269
+ */
270
+ defineProperty( 'maxX', Infinity );
271
+
272
+ /**
273
+ * The minimum allowed y position during translation.
274
+ *
275
+ * @name TransformControls#minY
276
+ * @type {number}
277
+ * @default -Infinity
278
+ */
279
+ defineProperty( 'minY', - Infinity );
280
+
281
+ /**
282
+ * The maximum allowed Y position during translation.
283
+ *
284
+ * @name TransformControls#maxY
285
+ * @type {number}
286
+ * @default Infinity
287
+ */
288
+ defineProperty( 'maxY', Infinity );
289
+
290
+ /**
291
+ * The minimum allowed z position during translation.
292
+ *
293
+ * @name TransformControls#minZ
294
+ * @type {number}
295
+ * @default -Infinity
296
+ */
297
+ defineProperty( 'minZ', - Infinity );
298
+
299
+ /**
300
+ * The maximum allowed Z position during translation.
301
+ *
302
+ * @name TransformControls#maxZ
303
+ * @type {number}
304
+ * @default Infinity
305
+ */
306
+ defineProperty( 'maxZ', Infinity );
307
+
308
+ // Reusable utility variables
309
+
310
+ const worldPosition = new Vector3();
311
+ const worldPositionStart = new Vector3();
312
+ const worldQuaternion = new Quaternion();
313
+ const worldQuaternionStart = new Quaternion();
314
+ const cameraPosition = new Vector3();
315
+ const cameraQuaternion = new Quaternion();
316
+ const pointStart = new Vector3();
317
+ const pointEnd = new Vector3();
318
+ const rotationAxis = new Vector3();
319
+ const rotationAngle = 0;
320
+ const eye = new Vector3();
321
+
322
+ // TODO: remove properties unused in plane and gizmo
323
+
324
+ defineProperty( 'worldPosition', worldPosition );
325
+ defineProperty( 'worldPositionStart', worldPositionStart );
326
+ defineProperty( 'worldQuaternion', worldQuaternion );
327
+ defineProperty( 'worldQuaternionStart', worldQuaternionStart );
328
+ defineProperty( 'cameraPosition', cameraPosition );
329
+ defineProperty( 'cameraQuaternion', cameraQuaternion );
330
+ defineProperty( 'pointStart', pointStart );
331
+ defineProperty( 'pointEnd', pointEnd );
332
+ defineProperty( 'rotationAxis', rotationAxis );
333
+ defineProperty( 'rotationAngle', rotationAngle );
334
+ defineProperty( 'eye', eye );
335
+
336
+ this._offset = new Vector3();
337
+ this._startNorm = new Vector3();
338
+ this._endNorm = new Vector3();
339
+ this._cameraScale = new Vector3();
340
+
341
+ this._parentPosition = new Vector3();
342
+ this._parentQuaternion = new Quaternion();
343
+ this._parentQuaternionInv = new Quaternion();
344
+ this._parentScale = new Vector3();
345
+
346
+ this._worldScaleStart = new Vector3();
347
+ this._worldQuaternionInv = new Quaternion();
348
+ this._worldScale = new Vector3();
349
+
350
+ this._positionStart = new Vector3();
351
+ this._quaternionStart = new Quaternion();
352
+ this._scaleStart = new Vector3();
353
+
354
+ this._getPointer = getPointer.bind( this );
355
+ this._onPointerDown = onPointerDown.bind( this );
356
+ this._onPointerHover = onPointerHover.bind( this );
357
+ this._onPointerMove = onPointerMove.bind( this );
358
+ this._onPointerUp = onPointerUp.bind( this );
359
+
360
+ if ( domElement !== null ) {
361
+
362
+ this.connect( domElement );
363
+
364
+ }
365
+
366
+ }
367
+
368
+ connect( element ) {
369
+
370
+ super.connect( element );
371
+
372
+ this.domElement.addEventListener( 'pointerdown', this._onPointerDown );
373
+ this.domElement.addEventListener( 'pointermove', this._onPointerHover );
374
+ this.domElement.addEventListener( 'pointerup', this._onPointerUp );
375
+
376
+ this.domElement.style.touchAction = 'none'; // disable touch scroll
377
+
378
+ }
379
+
380
+ disconnect() {
381
+
382
+ this.domElement.removeEventListener( 'pointerdown', this._onPointerDown );
383
+ this.domElement.removeEventListener( 'pointermove', this._onPointerHover );
384
+ this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
385
+ this.domElement.removeEventListener( 'pointerup', this._onPointerUp );
386
+
387
+ this.domElement.style.touchAction = 'auto';
388
+
389
+ }
390
+
391
+ /**
392
+ * Returns the visual representation of the controls. Add the helper to your scene to
393
+ * visually transform the attached 3D object.
394
+ *
395
+ * @return {TransformControlsRoot} The helper.
396
+ */
397
+ getHelper() {
398
+
399
+ return this._root;
400
+
401
+ }
402
+
403
+ pointerHover( pointer ) {
404
+
405
+ if ( this.object === undefined || this.dragging === true ) return;
406
+
407
+ if ( pointer !== null ) _raycaster.setFromCamera( pointer, this.camera );
408
+
409
+ const intersect = intersectObjectWithRay( this._gizmo.picker[ this.mode ], _raycaster );
410
+
411
+ if ( intersect ) {
412
+
413
+ this.axis = intersect.object.name;
414
+
415
+ } else {
416
+
417
+ this.axis = null;
418
+
419
+ }
420
+
421
+ }
422
+
423
+ pointerDown( pointer ) {
424
+
425
+ if ( this.object === undefined || this.dragging === true || ( pointer != null && pointer.button !== 0 ) ) return;
426
+
427
+ if ( this.axis !== null ) {
428
+
429
+ if ( pointer !== null ) _raycaster.setFromCamera( pointer, this.camera );
430
+
431
+ const planeIntersect = intersectObjectWithRay( this._plane, _raycaster, true );
432
+
433
+ if ( planeIntersect ) {
434
+
435
+ this.object.updateMatrixWorld();
436
+ this.object.parent.updateMatrixWorld();
437
+
438
+ this._positionStart.copy( this.object.position );
439
+ this._quaternionStart.copy( this.object.quaternion );
440
+ this._scaleStart.copy( this.object.scale );
441
+
442
+ this.object.matrixWorld.decompose( this.worldPositionStart, this.worldQuaternionStart, this._worldScaleStart );
443
+
444
+ this.pointStart.copy( planeIntersect.point ).sub( this.worldPositionStart );
445
+
446
+ }
447
+
448
+ this.dragging = true;
449
+ _mouseDownEvent.mode = this.mode;
450
+ this.dispatchEvent( _mouseDownEvent );
451
+
452
+ }
453
+
454
+ }
455
+
456
+ pointerMove( pointer ) {
457
+
458
+ const axis = this.axis;
459
+ const mode = this.mode;
460
+ const object = this.object;
461
+ let space = this.space;
462
+
463
+ if ( mode === 'scale' ) {
464
+
465
+ space = 'local';
466
+
467
+ } else if ( axis === 'E' || axis === 'XYZE' || axis === 'XYZ' ) {
468
+
469
+ space = 'world';
470
+
471
+ }
472
+
473
+ if ( object === undefined || axis === null || this.dragging === false || ( pointer !== null && pointer.button !== - 1 ) ) return;
474
+
475
+ if ( pointer !== null ) _raycaster.setFromCamera( pointer, this.camera );
476
+
477
+ const planeIntersect = intersectObjectWithRay( this._plane, _raycaster, true );
478
+
479
+ if ( ! planeIntersect ) return;
480
+
481
+ this.pointEnd.copy( planeIntersect.point ).sub( this.worldPositionStart );
482
+
483
+ if ( mode === 'translate' ) {
484
+
485
+ // Apply translate
486
+
487
+ this._offset.copy( this.pointEnd ).sub( this.pointStart );
488
+
489
+ if ( space === 'local' && axis !== 'XYZ' ) {
490
+
491
+ this._offset.applyQuaternion( this._worldQuaternionInv );
492
+
493
+ }
494
+
495
+ if ( axis.indexOf( 'X' ) === - 1 ) this._offset.x = 0;
496
+ if ( axis.indexOf( 'Y' ) === - 1 ) this._offset.y = 0;
497
+ if ( axis.indexOf( 'Z' ) === - 1 ) this._offset.z = 0;
498
+
499
+ if ( space === 'local' && axis !== 'XYZ' ) {
500
+
501
+ this._offset.applyQuaternion( this._quaternionStart ).divide( this._parentScale );
502
+
503
+ } else {
504
+
505
+ this._offset.applyQuaternion( this._parentQuaternionInv ).divide( this._parentScale );
506
+
507
+ }
508
+
509
+ object.position.copy( this._offset ).add( this._positionStart );
510
+
511
+ // Apply translation snap
512
+
513
+ if ( this.translationSnap ) {
514
+
515
+ if ( space === 'local' ) {
516
+
517
+ object.position.applyQuaternion( _tempQuaternion.copy( this._quaternionStart ).invert() );
518
+
519
+ if ( axis.search( 'X' ) !== - 1 ) {
520
+
521
+ object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
522
+
523
+ }
524
+
525
+ if ( axis.search( 'Y' ) !== - 1 ) {
526
+
527
+ object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
528
+
529
+ }
530
+
531
+ if ( axis.search( 'Z' ) !== - 1 ) {
532
+
533
+ object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
534
+
535
+ }
536
+
537
+ object.position.applyQuaternion( this._quaternionStart );
538
+
539
+ }
540
+
541
+ if ( space === 'world' ) {
542
+
543
+ if ( object.parent ) {
544
+
545
+ object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
546
+
547
+ }
548
+
549
+ if ( axis.search( 'X' ) !== - 1 ) {
550
+
551
+ object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
552
+
553
+ }
554
+
555
+ if ( axis.search( 'Y' ) !== - 1 ) {
556
+
557
+ object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
558
+
559
+ }
560
+
561
+ if ( axis.search( 'Z' ) !== - 1 ) {
562
+
563
+ object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
564
+
565
+ }
566
+
567
+ if ( object.parent ) {
568
+
569
+ object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
570
+
571
+ }
572
+
573
+ }
574
+
575
+ }
576
+
577
+ object.position.x = Math.max( this.minX, Math.min( this.maxX, object.position.x ) );
578
+ object.position.y = Math.max( this.minY, Math.min( this.maxY, object.position.y ) );
579
+ object.position.z = Math.max( this.minZ, Math.min( this.maxZ, object.position.z ) );
580
+
581
+ } else if ( mode === 'scale' ) {
582
+
583
+ if ( axis.search( 'XYZ' ) !== - 1 ) {
584
+
585
+ let d = this.pointEnd.length() / this.pointStart.length();
586
+
587
+ if ( this.pointEnd.dot( this.pointStart ) < 0 ) d *= - 1;
588
+
589
+ _tempVector2.set( d, d, d );
590
+
591
+ } else {
592
+
593
+ _tempVector.copy( this.pointStart );
594
+ _tempVector2.copy( this.pointEnd );
595
+
596
+ _tempVector.applyQuaternion( this._worldQuaternionInv );
597
+ _tempVector2.applyQuaternion( this._worldQuaternionInv );
598
+
599
+ _tempVector2.divide( _tempVector );
600
+
601
+ if ( axis.search( 'X' ) === - 1 ) {
602
+
603
+ _tempVector2.x = 1;
604
+
605
+ }
606
+
607
+ if ( axis.search( 'Y' ) === - 1 ) {
608
+
609
+ _tempVector2.y = 1;
610
+
611
+ }
612
+
613
+ if ( axis.search( 'Z' ) === - 1 ) {
614
+
615
+ _tempVector2.z = 1;
616
+
617
+ }
618
+
619
+ }
620
+
621
+ // Apply scale
622
+
623
+ object.scale.copy( this._scaleStart ).multiply( _tempVector2 );
624
+
625
+ if ( this.scaleSnap ) {
626
+
627
+ if ( axis.search( 'X' ) !== - 1 ) {
628
+
629
+ object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
630
+
631
+ }
632
+
633
+ if ( axis.search( 'Y' ) !== - 1 ) {
634
+
635
+ object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
636
+
637
+ }
638
+
639
+ if ( axis.search( 'Z' ) !== - 1 ) {
640
+
641
+ object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
642
+
643
+ }
644
+
645
+ }
646
+
647
+ } else if ( mode === 'rotate' ) {
648
+
649
+ this._offset.copy( this.pointEnd ).sub( this.pointStart );
650
+
651
+ const ROTATION_SPEED = 20 / this.worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
652
+
653
+ let _inPlaneRotation = false;
654
+
655
+ if ( axis === 'XYZE' ) {
656
+
657
+ this.rotationAxis.copy( this._offset ).cross( this.eye ).normalize();
658
+ this.rotationAngle = this._offset.dot( _tempVector.copy( this.rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
659
+
660
+ } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
661
+
662
+ this.rotationAxis.copy( _unit[ axis ] );
663
+
664
+ _tempVector.copy( _unit[ axis ] );
665
+
666
+ if ( space === 'local' ) {
667
+
668
+ _tempVector.applyQuaternion( this.worldQuaternion );
669
+
670
+ }
671
+
672
+ _tempVector.cross( this.eye );
673
+
674
+ // When _tempVector is 0 after cross with this.eye the vectors are parallel and should use in-plane rotation logic.
675
+ if ( _tempVector.length() === 0 ) {
676
+
677
+ _inPlaneRotation = true;
678
+
679
+ } else {
680
+
681
+ this.rotationAngle = this._offset.dot( _tempVector.normalize() ) * ROTATION_SPEED;
682
+
683
+ }
684
+
685
+
686
+ }
687
+
688
+ if ( axis === 'E' || _inPlaneRotation ) {
689
+
690
+ this.rotationAxis.copy( this.eye );
691
+ this.rotationAngle = this.pointEnd.angleTo( this.pointStart );
692
+
693
+ this._startNorm.copy( this.pointStart ).normalize();
694
+ this._endNorm.copy( this.pointEnd ).normalize();
695
+
696
+ this.rotationAngle *= ( this._endNorm.cross( this._startNorm ).dot( this.eye ) < 0 ? 1 : - 1 );
697
+
698
+ }
699
+
700
+ // Apply rotation snap
701
+
702
+ if ( this.rotationSnap ) this.rotationAngle = Math.round( this.rotationAngle / this.rotationSnap ) * this.rotationSnap;
703
+
704
+ // Apply rotate
705
+ if ( space === 'local' && axis !== 'E' && axis !== 'XYZE' ) {
706
+
707
+ object.quaternion.copy( this._quaternionStart );
708
+ object.quaternion.multiply( _tempQuaternion.setFromAxisAngle( this.rotationAxis, this.rotationAngle ) ).normalize();
709
+
710
+ } else {
711
+
712
+ this.rotationAxis.applyQuaternion( this._parentQuaternionInv );
713
+ object.quaternion.copy( _tempQuaternion.setFromAxisAngle( this.rotationAxis, this.rotationAngle ) );
714
+ object.quaternion.multiply( this._quaternionStart ).normalize();
715
+
716
+ }
717
+
718
+ }
719
+
720
+ this.dispatchEvent( _changeEvent );
721
+ this.dispatchEvent( _objectChangeEvent );
722
+
723
+ }
724
+
725
+ pointerUp( pointer ) {
726
+
727
+ if ( pointer !== null && pointer.button !== 0 ) return;
728
+
729
+ if ( this.dragging && ( this.axis !== null ) ) {
730
+
731
+ _mouseUpEvent.mode = this.mode;
732
+ this.dispatchEvent( _mouseUpEvent );
733
+
734
+ }
735
+
736
+ this.dragging = false;
737
+ this.axis = null;
738
+
739
+ }
740
+
741
+ dispose() {
742
+
743
+ this.disconnect();
744
+
745
+ this._root.dispose();
746
+
747
+ }
748
+
749
+ /**
750
+ * Sets the 3D object that should be transformed and ensures the controls UI is visible.
751
+ *
752
+ * @param {Object3D} object - The 3D object that should be transformed.
753
+ * @return {TransformControls} A reference to this controls.
754
+ */
755
+ attach( object ) {
756
+
757
+ this.object = object;
758
+ this._root.visible = true;
759
+
760
+ return this;
761
+
762
+ }
763
+
764
+ /**
765
+ * Removes the current 3D object from the controls and makes the helper UI invisible.
766
+ *
767
+ * @return {TransformControls} A reference to this controls.
768
+ */
769
+ detach() {
770
+
771
+ this.object = undefined;
772
+ this.axis = null;
773
+
774
+ this._root.visible = false;
775
+
776
+ return this;
777
+
778
+ }
779
+
780
+ /**
781
+ * Resets the object's position, rotation and scale to when the current transform began.
782
+ */
783
+ reset() {
784
+
785
+ if ( ! this.enabled ) return;
786
+
787
+ if ( this.dragging ) {
788
+
789
+ this.object.position.copy( this._positionStart );
790
+ this.object.quaternion.copy( this._quaternionStart );
791
+ this.object.scale.copy( this._scaleStart );
792
+
793
+ this.dispatchEvent( _changeEvent );
794
+ this.dispatchEvent( _objectChangeEvent );
795
+
796
+ this.pointStart.copy( this.pointEnd );
797
+
798
+ }
799
+
800
+ }
801
+
802
+ /**
803
+ * Returns the raycaster that is used for user interaction. This object is shared between all
804
+ * instances of `TransformControls`.
805
+ *
806
+ * @returns {Raycaster} The internal raycaster.
807
+ */
808
+ getRaycaster() {
809
+
810
+ return _raycaster;
811
+
812
+ }
813
+
814
+ /**
815
+ * Returns the transformation mode.
816
+ *
817
+ * @returns {'translate'|'rotate'|'scale'} The transformation mode.
818
+ */
819
+ getMode() {
820
+
821
+ return this.mode;
822
+
823
+ }
824
+
825
+ /**
826
+ * Sets the given transformation mode.
827
+ *
828
+ * @param {'translate'|'rotate'|'scale'} mode - The transformation mode to set.
829
+ */
830
+ setMode( mode ) {
831
+
832
+ this.mode = mode;
833
+
834
+ }
835
+
836
+ /**
837
+ * Sets the translation snap.
838
+ *
839
+ * @param {?number} translationSnap - The translation snap to set.
840
+ */
841
+ setTranslationSnap( translationSnap ) {
842
+
843
+ this.translationSnap = translationSnap;
844
+
845
+ }
846
+
847
+ /**
848
+ * Sets the rotation snap.
849
+ *
850
+ * @param {?number} rotationSnap - The rotation snap to set.
851
+ */
852
+ setRotationSnap( rotationSnap ) {
853
+
854
+ this.rotationSnap = rotationSnap;
855
+
856
+ }
857
+
858
+ /**
859
+ * Sets the scale snap.
860
+ *
861
+ * @param {?number} scaleSnap - The scale snap to set.
862
+ */
863
+ setScaleSnap( scaleSnap ) {
864
+
865
+ this.scaleSnap = scaleSnap;
866
+
867
+ }
868
+
869
+ /**
870
+ * Sets the size of the helper UI.
871
+ *
872
+ * @param {number} size - The size to set.
873
+ */
874
+ setSize( size ) {
875
+
876
+ this.size = size;
877
+
878
+ }
879
+
880
+ /**
881
+ * Sets the coordinate space in which transformations are applied.
882
+ *
883
+ * @param {'world'|'local'} space - The space to set.
884
+ */
885
+ setSpace( space ) {
886
+
887
+ this.space = space;
888
+
889
+ }
890
+
891
+ /**
892
+ * Sets the colors of the control's gizmo.
893
+ *
894
+ * @param {number|Color|string} xAxis - The x-axis color.
895
+ * @param {number|Color|string} yAxis - The y-axis color.
896
+ * @param {number|Color|string} zAxis - The z-axis color.
897
+ * @param {number|Color|string} active - The color for active elements.
898
+ */
899
+ setColors( xAxis, yAxis, zAxis, active ) {
900
+
901
+ const materialLib = this._gizmo.materialLib;
902
+
903
+ materialLib.xAxis.color.set( xAxis );
904
+ materialLib.yAxis.color.set( yAxis );
905
+ materialLib.zAxis.color.set( zAxis );
906
+ materialLib.active.color.set( active );
907
+ materialLib.xAxisTransparent.color.set( xAxis );
908
+ materialLib.yAxisTransparent.color.set( yAxis );
909
+ materialLib.zAxisTransparent.color.set( zAxis );
910
+ materialLib.activeTransparent.color.set( active );
911
+
912
+ // update color caches
913
+
914
+ if ( materialLib.xAxis._color ) materialLib.xAxis._color.set( xAxis );
915
+ if ( materialLib.yAxis._color ) materialLib.yAxis._color.set( yAxis );
916
+ if ( materialLib.zAxis._color ) materialLib.zAxis._color.set( zAxis );
917
+ if ( materialLib.active._color ) materialLib.active._color.set( active );
918
+ if ( materialLib.xAxisTransparent._color ) materialLib.xAxisTransparent._color.set( xAxis );
919
+ if ( materialLib.yAxisTransparent._color ) materialLib.yAxisTransparent._color.set( yAxis );
920
+ if ( materialLib.zAxisTransparent._color ) materialLib.zAxisTransparent._color.set( zAxis );
921
+ if ( materialLib.activeTransparent._color ) materialLib.activeTransparent._color.set( active );
922
+
923
+ }
924
+
925
+ }
926
+
927
+ // mouse / touch event handlers
928
+
929
+ function getPointer( event ) {
930
+
931
+ if ( this.domElement.ownerDocument.pointerLockElement ) {
932
+
933
+ return {
934
+ x: 0,
935
+ y: 0,
936
+ button: event.button
937
+ };
938
+
939
+ } else {
940
+
941
+ const rect = this.domElement.getBoundingClientRect();
942
+
943
+ return {
944
+ x: ( event.clientX - rect.left ) / rect.width * 2 - 1,
945
+ y: - ( event.clientY - rect.top ) / rect.height * 2 + 1,
946
+ button: event.button
947
+ };
948
+
949
+ }
950
+
951
+ }
952
+
953
+ function onPointerHover( event ) {
954
+
955
+ if ( ! this.enabled ) return;
956
+
957
+ switch ( event.pointerType ) {
958
+
959
+ case 'mouse':
960
+ case 'pen':
961
+ this.pointerHover( this._getPointer( event ) );
962
+ break;
963
+
964
+ }
965
+
966
+ }
967
+
968
+ function onPointerDown( event ) {
969
+
970
+ if ( ! this.enabled ) return;
971
+
972
+ if ( ! document.pointerLockElement ) {
973
+
974
+ this.domElement.setPointerCapture( event.pointerId );
975
+
976
+ }
977
+
978
+ this.domElement.addEventListener( 'pointermove', this._onPointerMove );
979
+
980
+ this.pointerHover( this._getPointer( event ) );
981
+ this.pointerDown( this._getPointer( event ) );
982
+
983
+ }
984
+
985
+ function onPointerMove( event ) {
986
+
987
+ if ( ! this.enabled ) return;
988
+
989
+ this.pointerMove( this._getPointer( event ) );
990
+
991
+ }
992
+
993
+ function onPointerUp( event ) {
994
+
995
+ if ( ! this.enabled ) return;
996
+
997
+ this.domElement.releasePointerCapture( event.pointerId );
998
+
999
+ this.domElement.removeEventListener( 'pointermove', this._onPointerMove );
1000
+
1001
+ this.pointerUp( this._getPointer( event ) );
1002
+
1003
+ }
1004
+
1005
+ function intersectObjectWithRay( object, raycaster, includeInvisible ) {
1006
+
1007
+ const allIntersections = raycaster.intersectObject( object, true );
1008
+
1009
+ for ( let i = 0; i < allIntersections.length; i ++ ) {
1010
+
1011
+ if ( allIntersections[ i ].object.visible || includeInvisible ) {
1012
+
1013
+ return allIntersections[ i ];
1014
+
1015
+ }
1016
+
1017
+ }
1018
+
1019
+ return false;
1020
+
1021
+ }
1022
+
1023
+ //
1024
+
1025
+ // Reusable utility variables
1026
+
1027
+ const _tempEuler = new Euler();
1028
+ const _alignVector = new Vector3( 0, 1, 0 );
1029
+ const _zeroVector = new Vector3( 0, 0, 0 );
1030
+ const _lookAtMatrix = new Matrix4();
1031
+ const _tempQuaternion2 = new Quaternion();
1032
+ const _identityQuaternion = new Quaternion();
1033
+ const _dirVector = new Vector3();
1034
+ const _tempMatrix = new Matrix4();
1035
+
1036
+ const _unitX = new Vector3( 1, 0, 0 );
1037
+ const _unitY = new Vector3( 0, 1, 0 );
1038
+ const _unitZ = new Vector3( 0, 0, 1 );
1039
+
1040
+ const _v1 = new Vector3();
1041
+ const _v2 = new Vector3();
1042
+ const _v3 = new Vector3();
1043
+
1044
+ class TransformControlsRoot extends Object3D {
1045
+
1046
+ constructor( controls ) {
1047
+
1048
+ super();
1049
+
1050
+ this.isTransformControlsRoot = true;
1051
+
1052
+ this.controls = controls;
1053
+ this.visible = false;
1054
+
1055
+ }
1056
+
1057
+ // updateMatrixWorld updates key transformation variables
1058
+ updateMatrixWorld( force ) {
1059
+
1060
+ const controls = this.controls;
1061
+
1062
+ if ( controls.object !== undefined ) {
1063
+
1064
+ controls.object.updateMatrixWorld();
1065
+
1066
+ if ( controls.object.parent === null ) {
1067
+
1068
+ console.error( 'TransformControls: The attached 3D object must be a part of the scene graph.' );
1069
+
1070
+ } else {
1071
+
1072
+ controls.object.parent.matrixWorld.decompose( controls._parentPosition, controls._parentQuaternion, controls._parentScale );
1073
+
1074
+ }
1075
+
1076
+ controls.object.matrixWorld.decompose( controls.worldPosition, controls.worldQuaternion, controls._worldScale );
1077
+
1078
+ controls._parentQuaternionInv.copy( controls._parentQuaternion ).invert();
1079
+ controls._worldQuaternionInv.copy( controls.worldQuaternion ).invert();
1080
+
1081
+ }
1082
+
1083
+ controls.camera.updateMatrixWorld();
1084
+ controls.camera.matrixWorld.decompose( controls.cameraPosition, controls.cameraQuaternion, controls._cameraScale );
1085
+
1086
+ if ( controls.camera.isOrthographicCamera ) {
1087
+
1088
+ controls.camera.getWorldDirection( controls.eye ).negate();
1089
+
1090
+ } else {
1091
+
1092
+ controls.eye.copy( controls.cameraPosition ).sub( controls.worldPosition ).normalize();
1093
+
1094
+ }
1095
+
1096
+ super.updateMatrixWorld( force );
1097
+
1098
+ }
1099
+
1100
+ dispose() {
1101
+
1102
+ this.traverse( function ( child ) {
1103
+
1104
+ if ( child.geometry ) child.geometry.dispose();
1105
+ if ( child.material ) child.material.dispose();
1106
+
1107
+ } );
1108
+
1109
+ }
1110
+
1111
+ }
1112
+
1113
+ class TransformControlsGizmo extends Object3D {
1114
+
1115
+ constructor() {
1116
+
1117
+ super();
1118
+
1119
+ this.isTransformControlsGizmo = true;
1120
+
1121
+ this.type = 'TransformControlsGizmo';
1122
+
1123
+ // shared materials
1124
+
1125
+ const gizmoMaterial = new MeshBasicMaterial( {
1126
+ depthTest: false,
1127
+ depthWrite: false,
1128
+ fog: false,
1129
+ toneMapped: false,
1130
+ transparent: true
1131
+ } );
1132
+
1133
+ const gizmoLineMaterial = new LineBasicMaterial( {
1134
+ depthTest: false,
1135
+ depthWrite: false,
1136
+ fog: false,
1137
+ toneMapped: false,
1138
+ transparent: true
1139
+ } );
1140
+
1141
+ // Make unique material for each axis/color
1142
+
1143
+ const matInvisible = gizmoMaterial.clone();
1144
+ matInvisible.opacity = 0.15;
1145
+
1146
+ const matHelper = gizmoLineMaterial.clone();
1147
+ matHelper.opacity = 0.5;
1148
+
1149
+ const matRed = gizmoMaterial.clone();
1150
+ matRed.color.setHex( 0xff0000 );
1151
+
1152
+ const matGreen = gizmoMaterial.clone();
1153
+ matGreen.color.setHex( 0x00ff00 );
1154
+
1155
+ const matBlue = gizmoMaterial.clone();
1156
+ matBlue.color.setHex( 0x0000ff );
1157
+
1158
+ const matRedTransparent = gizmoMaterial.clone();
1159
+ matRedTransparent.color.setHex( 0xff0000 );
1160
+ matRedTransparent.opacity = 0.5;
1161
+
1162
+ const matGreenTransparent = gizmoMaterial.clone();
1163
+ matGreenTransparent.color.setHex( 0x00ff00 );
1164
+ matGreenTransparent.opacity = 0.5;
1165
+
1166
+ const matBlueTransparent = gizmoMaterial.clone();
1167
+ matBlueTransparent.color.setHex( 0x0000ff );
1168
+ matBlueTransparent.opacity = 0.5;
1169
+
1170
+ const matWhiteTransparent = gizmoMaterial.clone();
1171
+ matWhiteTransparent.opacity = 0.25;
1172
+
1173
+ const matYellowTransparent = gizmoMaterial.clone();
1174
+ matYellowTransparent.color.setHex( 0xffff00 );
1175
+ matYellowTransparent.opacity = 0.25;
1176
+
1177
+ const matYellow = gizmoMaterial.clone();
1178
+ matYellow.color.setHex( 0xffff00 );
1179
+
1180
+ const matGray = gizmoMaterial.clone();
1181
+ matGray.color.setHex( 0x787878 );
1182
+
1183
+ // materials in the below property are configurable via setColors()
1184
+
1185
+ this.materialLib = {
1186
+ xAxis: matRed,
1187
+ yAxis: matGreen,
1188
+ zAxis: matBlue,
1189
+ active: matYellow,
1190
+ xAxisTransparent: matRedTransparent,
1191
+ yAxisTransparent: matGreenTransparent,
1192
+ zAxisTransparent: matBlueTransparent,
1193
+ activeTransparent: matYellowTransparent
1194
+ };
1195
+
1196
+ // reusable geometry
1197
+
1198
+ const arrowGeometry = new CylinderGeometry( 0, 0.04, 0.1, 12 );
1199
+ arrowGeometry.translate( 0, 0.05, 0 );
1200
+
1201
+ const scaleHandleGeometry = new BoxGeometry( 0.08, 0.08, 0.08 );
1202
+ scaleHandleGeometry.translate( 0, 0.04, 0 );
1203
+
1204
+ const lineGeometry = new BufferGeometry();
1205
+ lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
1206
+
1207
+ const lineGeometry2 = new CylinderGeometry( 0.0075, 0.0075, 0.5, 3 );
1208
+ lineGeometry2.translate( 0, 0.25, 0 );
1209
+
1210
+ function CircleGeometry( radius, arc ) {
1211
+
1212
+ const geometry = new TorusGeometry( radius, 0.0075, 3, 64, arc * Math.PI * 2 );
1213
+ geometry.rotateY( Math.PI / 2 );
1214
+ geometry.rotateX( Math.PI / 2 );
1215
+ return geometry;
1216
+
1217
+ }
1218
+
1219
+ // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
1220
+
1221
+ function TranslateHelperGeometry() {
1222
+
1223
+ const geometry = new BufferGeometry();
1224
+
1225
+ geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
1226
+
1227
+ return geometry;
1228
+
1229
+ }
1230
+
1231
+ // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
1232
+
1233
+ const gizmoTranslate = {
1234
+ X: [
1235
+ [ new Mesh( arrowGeometry, matRed ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
1236
+ [ new Mesh( arrowGeometry, matRed ), [ - 0.5, 0, 0 ], [ 0, 0, Math.PI / 2 ]],
1237
+ [ new Mesh( lineGeometry2, matRed ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
1238
+ ],
1239
+ Y: [
1240
+ [ new Mesh( arrowGeometry, matGreen ), [ 0, 0.5, 0 ]],
1241
+ [ new Mesh( arrowGeometry, matGreen ), [ 0, - 0.5, 0 ], [ Math.PI, 0, 0 ]],
1242
+ [ new Mesh( lineGeometry2, matGreen ) ]
1243
+ ],
1244
+ Z: [
1245
+ [ new Mesh( arrowGeometry, matBlue ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]],
1246
+ [ new Mesh( arrowGeometry, matBlue ), [ 0, 0, - 0.5 ], [ - Math.PI / 2, 0, 0 ]],
1247
+ [ new Mesh( lineGeometry2, matBlue ), null, [ Math.PI / 2, 0, 0 ]]
1248
+ ],
1249
+ XYZ: [
1250
+ [ new Mesh( new OctahedronGeometry( 0.1, 0 ), matWhiteTransparent ), [ 0, 0, 0 ]]
1251
+ ],
1252
+ XY: [
1253
+ [ new Mesh( new BoxGeometry( 0.15, 0.15, 0.01 ), matBlueTransparent ), [ 0.15, 0.15, 0 ]]
1254
+ ],
1255
+ YZ: [
1256
+ [ new Mesh( new BoxGeometry( 0.15, 0.15, 0.01 ), matRedTransparent ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]]
1257
+ ],
1258
+ XZ: [
1259
+ [ new Mesh( new BoxGeometry( 0.15, 0.15, 0.01 ), matGreenTransparent ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]]
1260
+ ]
1261
+ };
1262
+
1263
+ const pickerTranslate = {
1264
+ X: [
1265
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0.3, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
1266
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ - 0.3, 0, 0 ], [ 0, 0, Math.PI / 2 ]]
1267
+ ],
1268
+ Y: [
1269
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, 0.3, 0 ]],
1270
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, - 0.3, 0 ], [ 0, 0, Math.PI ]]
1271
+ ],
1272
+ Z: [
1273
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, 0, 0.3 ], [ Math.PI / 2, 0, 0 ]],
1274
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, 0, - 0.3 ], [ - Math.PI / 2, 0, 0 ]]
1275
+ ],
1276
+ XYZ: [
1277
+ [ new Mesh( new OctahedronGeometry( 0.2, 0 ), matInvisible ) ]
1278
+ ],
1279
+ XY: [
1280
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.01 ), matInvisible ), [ 0.15, 0.15, 0 ]]
1281
+ ],
1282
+ YZ: [
1283
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.01 ), matInvisible ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]]
1284
+ ],
1285
+ XZ: [
1286
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.01 ), matInvisible ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]]
1287
+ ]
1288
+ };
1289
+
1290
+ const helperTranslate = {
1291
+ START: [
1292
+ [ new Mesh( new OctahedronGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
1293
+ ],
1294
+ END: [
1295
+ [ new Mesh( new OctahedronGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
1296
+ ],
1297
+ DELTA: [
1298
+ [ new Line( TranslateHelperGeometry(), matHelper ), null, null, null, 'helper' ]
1299
+ ],
1300
+ X: [
1301
+ [ new Line( lineGeometry, matHelper ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
1302
+ ],
1303
+ Y: [
1304
+ [ new Line( lineGeometry, matHelper ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
1305
+ ],
1306
+ Z: [
1307
+ [ new Line( lineGeometry, matHelper ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
1308
+ ]
1309
+ };
1310
+
1311
+ const gizmoRotate = {
1312
+ XYZE: [
1313
+ [ new Mesh( CircleGeometry( 0.5, 1 ), matGray ), null, [ 0, Math.PI / 2, 0 ]]
1314
+ ],
1315
+ X: [
1316
+ [ new Mesh( CircleGeometry( 0.5, 0.5 ), matRed ) ]
1317
+ ],
1318
+ Y: [
1319
+ [ new Mesh( CircleGeometry( 0.5, 0.5 ), matGreen ), null, [ 0, 0, - Math.PI / 2 ]]
1320
+ ],
1321
+ Z: [
1322
+ [ new Mesh( CircleGeometry( 0.5, 0.5 ), matBlue ), null, [ 0, Math.PI / 2, 0 ]]
1323
+ ],
1324
+ E: [
1325
+ [ new Mesh( CircleGeometry( 0.75, 1 ), matYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]]
1326
+ ]
1327
+ };
1328
+
1329
+ const helperRotate = {
1330
+ AXIS: [
1331
+ [ new Line( lineGeometry, matHelper ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
1332
+ ]
1333
+ };
1334
+
1335
+ const pickerRotate = {
1336
+ XYZE: [
1337
+ [ new Mesh( new SphereGeometry( 0.25, 10, 8 ), matInvisible ) ]
1338
+ ],
1339
+ X: [
1340
+ [ new Mesh( new TorusGeometry( 0.5, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]],
1341
+ ],
1342
+ Y: [
1343
+ [ new Mesh( new TorusGeometry( 0.5, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
1344
+ ],
1345
+ Z: [
1346
+ [ new Mesh( new TorusGeometry( 0.5, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
1347
+ ],
1348
+ E: [
1349
+ [ new Mesh( new TorusGeometry( 0.75, 0.1, 2, 24 ), matInvisible ) ]
1350
+ ]
1351
+ };
1352
+
1353
+ const gizmoScale = {
1354
+ X: [
1355
+ [ new Mesh( scaleHandleGeometry, matRed ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
1356
+ [ new Mesh( lineGeometry2, matRed ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
1357
+ [ new Mesh( scaleHandleGeometry, matRed ), [ - 0.5, 0, 0 ], [ 0, 0, Math.PI / 2 ]],
1358
+ ],
1359
+ Y: [
1360
+ [ new Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.5, 0 ]],
1361
+ [ new Mesh( lineGeometry2, matGreen ) ],
1362
+ [ new Mesh( scaleHandleGeometry, matGreen ), [ 0, - 0.5, 0 ], [ 0, 0, Math.PI ]],
1363
+ ],
1364
+ Z: [
1365
+ [ new Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]],
1366
+ [ new Mesh( lineGeometry2, matBlue ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
1367
+ [ new Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, - 0.5 ], [ - Math.PI / 2, 0, 0 ]]
1368
+ ],
1369
+ XY: [
1370
+ [ new Mesh( new BoxGeometry( 0.15, 0.15, 0.01 ), matBlueTransparent ), [ 0.15, 0.15, 0 ]]
1371
+ ],
1372
+ YZ: [
1373
+ [ new Mesh( new BoxGeometry( 0.15, 0.15, 0.01 ), matRedTransparent ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]]
1374
+ ],
1375
+ XZ: [
1376
+ [ new Mesh( new BoxGeometry( 0.15, 0.15, 0.01 ), matGreenTransparent ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]]
1377
+ ],
1378
+ XYZ: [
1379
+ [ new Mesh( new BoxGeometry( 0.1, 0.1, 0.1 ), matWhiteTransparent ) ],
1380
+ ]
1381
+ };
1382
+
1383
+ const pickerScale = {
1384
+ X: [
1385
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0.3, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
1386
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ - 0.3, 0, 0 ], [ 0, 0, Math.PI / 2 ]]
1387
+ ],
1388
+ Y: [
1389
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, 0.3, 0 ]],
1390
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, - 0.3, 0 ], [ 0, 0, Math.PI ]]
1391
+ ],
1392
+ Z: [
1393
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, 0, 0.3 ], [ Math.PI / 2, 0, 0 ]],
1394
+ [ new Mesh( new CylinderGeometry( 0.2, 0, 0.6, 4 ), matInvisible ), [ 0, 0, - 0.3 ], [ - Math.PI / 2, 0, 0 ]]
1395
+ ],
1396
+ XY: [
1397
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.01 ), matInvisible ), [ 0.15, 0.15, 0 ]],
1398
+ ],
1399
+ YZ: [
1400
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.01 ), matInvisible ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]],
1401
+ ],
1402
+ XZ: [
1403
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.01 ), matInvisible ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]],
1404
+ ],
1405
+ XYZ: [
1406
+ [ new Mesh( new BoxGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 0 ]],
1407
+ ]
1408
+ };
1409
+
1410
+ const helperScale = {
1411
+ X: [
1412
+ [ new Line( lineGeometry, matHelper ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
1413
+ ],
1414
+ Y: [
1415
+ [ new Line( lineGeometry, matHelper ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
1416
+ ],
1417
+ Z: [
1418
+ [ new Line( lineGeometry, matHelper ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
1419
+ ]
1420
+ };
1421
+
1422
+ // Creates an Object3D with gizmos described in custom hierarchy definition.
1423
+
1424
+ function setupGizmo( gizmoMap ) {
1425
+
1426
+ const gizmo = new Object3D();
1427
+
1428
+ for ( const name in gizmoMap ) {
1429
+
1430
+ for ( let i = gizmoMap[ name ].length; i --; ) {
1431
+
1432
+ const object = gizmoMap[ name ][ i ][ 0 ].clone();
1433
+ const position = gizmoMap[ name ][ i ][ 1 ];
1434
+ const rotation = gizmoMap[ name ][ i ][ 2 ];
1435
+ const scale = gizmoMap[ name ][ i ][ 3 ];
1436
+ const tag = gizmoMap[ name ][ i ][ 4 ];
1437
+
1438
+ // name and tag properties are essential for picking and updating logic.
1439
+ object.name = name;
1440
+ object.tag = tag;
1441
+
1442
+ if ( position ) {
1443
+
1444
+ object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
1445
+
1446
+ }
1447
+
1448
+ if ( rotation ) {
1449
+
1450
+ object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
1451
+
1452
+ }
1453
+
1454
+ if ( scale ) {
1455
+
1456
+ object.scale.set( scale[ 0 ], scale[ 1 ], scale[ 2 ] );
1457
+
1458
+ }
1459
+
1460
+ object.updateMatrix();
1461
+
1462
+ const tempGeometry = object.geometry.clone();
1463
+ tempGeometry.applyMatrix4( object.matrix );
1464
+ object.geometry = tempGeometry;
1465
+ object.renderOrder = Infinity;
1466
+
1467
+ object.position.set( 0, 0, 0 );
1468
+ object.rotation.set( 0, 0, 0 );
1469
+ object.scale.set( 1, 1, 1 );
1470
+
1471
+ gizmo.add( object );
1472
+
1473
+ }
1474
+
1475
+ }
1476
+
1477
+ return gizmo;
1478
+
1479
+ }
1480
+
1481
+ // Gizmo creation
1482
+
1483
+ this.gizmo = {};
1484
+ this.picker = {};
1485
+ this.helper = {};
1486
+
1487
+ this.add( this.gizmo[ 'translate' ] = setupGizmo( gizmoTranslate ) );
1488
+ this.add( this.gizmo[ 'rotate' ] = setupGizmo( gizmoRotate ) );
1489
+ this.add( this.gizmo[ 'scale' ] = setupGizmo( gizmoScale ) );
1490
+ this.add( this.picker[ 'translate' ] = setupGizmo( pickerTranslate ) );
1491
+ this.add( this.picker[ 'rotate' ] = setupGizmo( pickerRotate ) );
1492
+ this.add( this.picker[ 'scale' ] = setupGizmo( pickerScale ) );
1493
+ this.add( this.helper[ 'translate' ] = setupGizmo( helperTranslate ) );
1494
+ this.add( this.helper[ 'rotate' ] = setupGizmo( helperRotate ) );
1495
+ this.add( this.helper[ 'scale' ] = setupGizmo( helperScale ) );
1496
+
1497
+ // Pickers should be hidden always
1498
+
1499
+ this.picker[ 'translate' ].visible = false;
1500
+ this.picker[ 'rotate' ].visible = false;
1501
+ this.picker[ 'scale' ].visible = false;
1502
+
1503
+ }
1504
+
1505
+ // updateMatrixWorld will update transformations and appearance of individual handles
1506
+
1507
+ updateMatrixWorld( force ) {
1508
+
1509
+ const space = ( this.mode === 'scale' ) ? 'local' : this.space; // scale always oriented to local rotation
1510
+
1511
+ const quaternion = ( space === 'local' ) ? this.worldQuaternion : _identityQuaternion;
1512
+
1513
+ // Show only gizmos for current transform mode
1514
+
1515
+ this.gizmo[ 'translate' ].visible = this.mode === 'translate';
1516
+ this.gizmo[ 'rotate' ].visible = this.mode === 'rotate';
1517
+ this.gizmo[ 'scale' ].visible = this.mode === 'scale';
1518
+
1519
+ this.helper[ 'translate' ].visible = this.mode === 'translate';
1520
+ this.helper[ 'rotate' ].visible = this.mode === 'rotate';
1521
+ this.helper[ 'scale' ].visible = this.mode === 'scale';
1522
+
1523
+
1524
+ let handles = [];
1525
+ handles = handles.concat( this.picker[ this.mode ].children );
1526
+ handles = handles.concat( this.gizmo[ this.mode ].children );
1527
+ handles = handles.concat( this.helper[ this.mode ].children );
1528
+
1529
+ for ( let i = 0; i < handles.length; i ++ ) {
1530
+
1531
+ const handle = handles[ i ];
1532
+
1533
+ // hide aligned to camera
1534
+
1535
+ handle.visible = true;
1536
+ handle.rotation.set( 0, 0, 0 );
1537
+ handle.position.copy( this.worldPosition );
1538
+
1539
+ let factor;
1540
+
1541
+ if ( this.camera.isOrthographicCamera ) {
1542
+
1543
+ factor = ( this.camera.top - this.camera.bottom ) / this.camera.zoom;
1544
+
1545
+ } else {
1546
+
1547
+ factor = this.worldPosition.distanceTo( this.cameraPosition ) * Math.min( 1.9 * Math.tan( Math.PI * this.camera.fov / 360 ) / this.camera.zoom, 7 );
1548
+
1549
+ }
1550
+
1551
+ handle.scale.set( 1, 1, 1 ).multiplyScalar( factor * this.size / 4 );
1552
+
1553
+ // TODO: simplify helpers and consider decoupling from gizmo
1554
+
1555
+ if ( handle.tag === 'helper' ) {
1556
+
1557
+ handle.visible = false;
1558
+
1559
+ if ( handle.name === 'AXIS' ) {
1560
+
1561
+ handle.visible = !! this.axis;
1562
+
1563
+ if ( this.axis === 'X' ) {
1564
+
1565
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, 0, 0 ) );
1566
+ handle.quaternion.copy( quaternion ).multiply( _tempQuaternion );
1567
+
1568
+ if ( Math.abs( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
1569
+
1570
+ handle.visible = false;
1571
+
1572
+ }
1573
+
1574
+ }
1575
+
1576
+ if ( this.axis === 'Y' ) {
1577
+
1578
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, 0, Math.PI / 2 ) );
1579
+ handle.quaternion.copy( quaternion ).multiply( _tempQuaternion );
1580
+
1581
+ if ( Math.abs( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
1582
+
1583
+ handle.visible = false;
1584
+
1585
+ }
1586
+
1587
+ }
1588
+
1589
+ if ( this.axis === 'Z' ) {
1590
+
1591
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, Math.PI / 2, 0 ) );
1592
+ handle.quaternion.copy( quaternion ).multiply( _tempQuaternion );
1593
+
1594
+ if ( Math.abs( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
1595
+
1596
+ handle.visible = false;
1597
+
1598
+ }
1599
+
1600
+ }
1601
+
1602
+ if ( this.axis === 'XYZE' ) {
1603
+
1604
+ _tempQuaternion.setFromEuler( _tempEuler.set( 0, Math.PI / 2, 0 ) );
1605
+ _alignVector.copy( this.rotationAxis );
1606
+ handle.quaternion.setFromRotationMatrix( _lookAtMatrix.lookAt( _zeroVector, _alignVector, _unitY ) );
1607
+ handle.quaternion.multiply( _tempQuaternion );
1608
+ handle.visible = this.dragging;
1609
+
1610
+ }
1611
+
1612
+ if ( this.axis === 'E' ) {
1613
+
1614
+ handle.visible = false;
1615
+
1616
+ }
1617
+
1618
+
1619
+ } else if ( handle.name === 'START' ) {
1620
+
1621
+ handle.position.copy( this.worldPositionStart );
1622
+ handle.visible = this.dragging;
1623
+
1624
+ } else if ( handle.name === 'END' ) {
1625
+
1626
+ handle.position.copy( this.worldPosition );
1627
+ handle.visible = this.dragging;
1628
+
1629
+ } else if ( handle.name === 'DELTA' ) {
1630
+
1631
+ handle.position.copy( this.worldPositionStart );
1632
+ handle.quaternion.copy( this.worldQuaternionStart );
1633
+ _tempVector.set( 1e-10, 1e-10, 1e-10 ).add( this.worldPositionStart ).sub( this.worldPosition ).multiplyScalar( - 1 );
1634
+ _tempVector.applyQuaternion( this.worldQuaternionStart.clone().invert() );
1635
+ handle.scale.copy( _tempVector );
1636
+ handle.visible = this.dragging;
1637
+
1638
+ } else {
1639
+
1640
+ handle.quaternion.copy( quaternion );
1641
+
1642
+ if ( this.dragging ) {
1643
+
1644
+ handle.position.copy( this.worldPositionStart );
1645
+
1646
+ } else {
1647
+
1648
+ handle.position.copy( this.worldPosition );
1649
+
1650
+ }
1651
+
1652
+ if ( this.axis ) {
1653
+
1654
+ handle.visible = this.axis.search( handle.name ) !== - 1;
1655
+
1656
+ }
1657
+
1658
+ }
1659
+
1660
+ // If updating helper, skip rest of the loop
1661
+ continue;
1662
+
1663
+ }
1664
+
1665
+ // Align handles to current local or world rotation
1666
+
1667
+ handle.quaternion.copy( quaternion );
1668
+
1669
+ if ( this.mode === 'translate' || this.mode === 'scale' ) {
1670
+
1671
+ // Hide translate and scale axis facing the camera
1672
+
1673
+ const AXIS_HIDE_THRESHOLD = 0.99;
1674
+ const PLANE_HIDE_THRESHOLD = 0.2;
1675
+
1676
+ if ( handle.name === 'X' ) {
1677
+
1678
+ if ( Math.abs( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_THRESHOLD ) {
1679
+
1680
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
1681
+ handle.visible = false;
1682
+
1683
+ }
1684
+
1685
+ }
1686
+
1687
+ if ( handle.name === 'Y' ) {
1688
+
1689
+ if ( Math.abs( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_THRESHOLD ) {
1690
+
1691
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
1692
+ handle.visible = false;
1693
+
1694
+ }
1695
+
1696
+ }
1697
+
1698
+ if ( handle.name === 'Z' ) {
1699
+
1700
+ if ( Math.abs( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_THRESHOLD ) {
1701
+
1702
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
1703
+ handle.visible = false;
1704
+
1705
+ }
1706
+
1707
+ }
1708
+
1709
+ if ( handle.name === 'XY' ) {
1710
+
1711
+ if ( Math.abs( _alignVector.copy( _unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_THRESHOLD ) {
1712
+
1713
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
1714
+ handle.visible = false;
1715
+
1716
+ }
1717
+
1718
+ }
1719
+
1720
+ if ( handle.name === 'YZ' ) {
1721
+
1722
+ if ( Math.abs( _alignVector.copy( _unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_THRESHOLD ) {
1723
+
1724
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
1725
+ handle.visible = false;
1726
+
1727
+ }
1728
+
1729
+ }
1730
+
1731
+ if ( handle.name === 'XZ' ) {
1732
+
1733
+ if ( Math.abs( _alignVector.copy( _unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_THRESHOLD ) {
1734
+
1735
+ handle.scale.set( 1e-10, 1e-10, 1e-10 );
1736
+ handle.visible = false;
1737
+
1738
+ }
1739
+
1740
+ }
1741
+
1742
+ } else if ( this.mode === 'rotate' ) {
1743
+
1744
+ // Align handles to current local or world rotation
1745
+
1746
+ _tempQuaternion2.copy( quaternion );
1747
+ _alignVector.copy( this.eye ).applyQuaternion( _tempQuaternion.copy( quaternion ).invert() );
1748
+
1749
+ if ( handle.name.search( 'E' ) !== - 1 ) {
1750
+
1751
+ handle.quaternion.setFromRotationMatrix( _lookAtMatrix.lookAt( this.eye, _zeroVector, _unitY ) );
1752
+
1753
+ }
1754
+
1755
+ if ( handle.name === 'X' ) {
1756
+
1757
+ _tempQuaternion.setFromAxisAngle( _unitX, Math.atan2( - _alignVector.y, _alignVector.z ) );
1758
+ _tempQuaternion.multiplyQuaternions( _tempQuaternion2, _tempQuaternion );
1759
+ handle.quaternion.copy( _tempQuaternion );
1760
+
1761
+ }
1762
+
1763
+ if ( handle.name === 'Y' ) {
1764
+
1765
+ _tempQuaternion.setFromAxisAngle( _unitY, Math.atan2( _alignVector.x, _alignVector.z ) );
1766
+ _tempQuaternion.multiplyQuaternions( _tempQuaternion2, _tempQuaternion );
1767
+ handle.quaternion.copy( _tempQuaternion );
1768
+
1769
+ }
1770
+
1771
+ if ( handle.name === 'Z' ) {
1772
+
1773
+ _tempQuaternion.setFromAxisAngle( _unitZ, Math.atan2( _alignVector.y, _alignVector.x ) );
1774
+ _tempQuaternion.multiplyQuaternions( _tempQuaternion2, _tempQuaternion );
1775
+ handle.quaternion.copy( _tempQuaternion );
1776
+
1777
+ }
1778
+
1779
+ }
1780
+
1781
+ // Hide disabled axes
1782
+ handle.visible = handle.visible && ( handle.name.indexOf( 'X' ) === - 1 || this.showX );
1783
+ handle.visible = handle.visible && ( handle.name.indexOf( 'Y' ) === - 1 || this.showY );
1784
+ handle.visible = handle.visible && ( handle.name.indexOf( 'Z' ) === - 1 || this.showZ );
1785
+ handle.visible = handle.visible && ( handle.name.indexOf( 'E' ) === - 1 || ( this.showX && this.showY && this.showZ ) );
1786
+
1787
+ // highlight selected axis
1788
+
1789
+ handle.material._color = handle.material._color || handle.material.color.clone();
1790
+ handle.material._opacity = handle.material._opacity || handle.material.opacity;
1791
+
1792
+ handle.material.color.copy( handle.material._color );
1793
+ handle.material.opacity = handle.material._opacity;
1794
+
1795
+ if ( this.enabled && this.axis ) {
1796
+
1797
+ if ( handle.name === this.axis ) {
1798
+
1799
+ handle.material.color.copy( this.materialLib.active.color );
1800
+ handle.material.opacity = 1.0;
1801
+
1802
+ } else if ( this.axis.split( '' ).some( function ( a ) {
1803
+
1804
+ return handle.name === a;
1805
+
1806
+ } ) ) {
1807
+
1808
+ handle.material.color.copy( this.materialLib.active.color );
1809
+ handle.material.opacity = 1.0;
1810
+
1811
+ }
1812
+
1813
+ }
1814
+
1815
+ }
1816
+
1817
+ super.updateMatrixWorld( force );
1818
+
1819
+ }
1820
+
1821
+ }
1822
+
1823
+ //
1824
+
1825
+ class TransformControlsPlane extends Mesh {
1826
+
1827
+ constructor() {
1828
+
1829
+ super(
1830
+ new PlaneGeometry( 100000, 100000, 2, 2 ),
1831
+ new MeshBasicMaterial( { visible: false, wireframe: true, side: DoubleSide, transparent: true, opacity: 0.1, toneMapped: false } )
1832
+ );
1833
+
1834
+ this.isTransformControlsPlane = true;
1835
+
1836
+ this.type = 'TransformControlsPlane';
1837
+
1838
+ }
1839
+
1840
+ updateMatrixWorld( force ) {
1841
+
1842
+ let space = this.space;
1843
+
1844
+ this.position.copy( this.worldPosition );
1845
+
1846
+ if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
1847
+
1848
+ _v1.copy( _unitX ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
1849
+ _v2.copy( _unitY ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
1850
+ _v3.copy( _unitZ ).applyQuaternion( space === 'local' ? this.worldQuaternion : _identityQuaternion );
1851
+
1852
+ // Align the plane for current transform mode, axis and space.
1853
+
1854
+ _alignVector.copy( _v2 );
1855
+
1856
+ switch ( this.mode ) {
1857
+
1858
+ case 'translate':
1859
+ case 'scale':
1860
+ switch ( this.axis ) {
1861
+
1862
+ case 'X':
1863
+ _alignVector.copy( this.eye ).cross( _v1 );
1864
+ _dirVector.copy( _v1 ).cross( _alignVector );
1865
+ break;
1866
+ case 'Y':
1867
+ _alignVector.copy( this.eye ).cross( _v2 );
1868
+ _dirVector.copy( _v2 ).cross( _alignVector );
1869
+ break;
1870
+ case 'Z':
1871
+ _alignVector.copy( this.eye ).cross( _v3 );
1872
+ _dirVector.copy( _v3 ).cross( _alignVector );
1873
+ break;
1874
+ case 'XY':
1875
+ _dirVector.copy( _v3 );
1876
+ break;
1877
+ case 'YZ':
1878
+ _dirVector.copy( _v1 );
1879
+ break;
1880
+ case 'XZ':
1881
+ _alignVector.copy( _v3 );
1882
+ _dirVector.copy( _v2 );
1883
+ break;
1884
+ case 'XYZ':
1885
+ case 'E':
1886
+ _dirVector.set( 0, 0, 0 );
1887
+ break;
1888
+
1889
+ }
1890
+
1891
+ break;
1892
+ case 'rotate':
1893
+ default:
1894
+ // special case for rotate
1895
+ _dirVector.set( 0, 0, 0 );
1896
+
1897
+ }
1898
+
1899
+ if ( _dirVector.length() === 0 ) {
1900
+
1901
+ // If in rotate mode, make the plane parallel to camera
1902
+ this.quaternion.copy( this.cameraQuaternion );
1903
+
1904
+ } else {
1905
+
1906
+ _tempMatrix.lookAt( _tempVector.set( 0, 0, 0 ), _dirVector, _alignVector );
1907
+
1908
+ this.quaternion.setFromRotationMatrix( _tempMatrix );
1909
+
1910
+ }
1911
+
1912
+ super.updateMatrixWorld( force );
1913
+
1914
+ }
1915
+
1916
+ }
1917
+
1918
+ export { TransformControls, TransformControlsGizmo, TransformControlsPlane };