@woosh/meep-engine 2.46.29 → 2.46.30

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 (165) hide show
  1. package/editor/Editor.js +793 -0
  2. package/editor/SelectionVisualizer.js +148 -0
  3. package/editor/actions/concrete/ActionUpdateTexture.js +21 -0
  4. package/editor/actions/concrete/ArrayCopyAction.js +39 -0
  5. package/editor/actions/concrete/ComponentAddAction.js +47 -0
  6. package/editor/actions/concrete/ComponentRemoveAction.js +38 -0
  7. package/editor/actions/concrete/EntityCreateAction.js +47 -0
  8. package/editor/actions/concrete/EntityRemoveAction.js +51 -0
  9. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
  10. package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
  11. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +182 -0
  12. package/editor/actions/concrete/PaintTerrainOverlayAction.js +45 -0
  13. package/editor/actions/concrete/PatchTerrainHeightAction.js +67 -0
  14. package/editor/actions/concrete/PatchTerrainTextureAction.js +152 -0
  15. package/editor/actions/concrete/SelectionAddAction.js +36 -0
  16. package/editor/actions/concrete/SelectionClearAction.js +22 -0
  17. package/editor/actions/concrete/SelectionRemoveAction.js +30 -0
  18. package/editor/actions/concrete/TransformModifyAction.js +46 -0
  19. package/editor/actions/concrete/WriteGridValueAction.js +46 -0
  20. package/editor/ecs/EditorEntity.js +12 -0
  21. package/editor/ecs/EditorEntitySystem.js +14 -0
  22. package/editor/ecs/component/FieldDescriptor.js +34 -0
  23. package/editor/ecs/component/FieldValueAdapter.js +20 -0
  24. package/editor/ecs/component/TypeEditor.js +33 -0
  25. package/editor/ecs/component/TypeSchema.d.ts +38 -0
  26. package/editor/ecs/component/createFieldEditor.js +92 -0
  27. package/editor/ecs/component/createObjectEditor.js +361 -0
  28. package/editor/ecs/component/editors/ColorEditor.js +39 -0
  29. package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
  30. package/editor/ecs/component/editors/ImagePathEditor.js +82 -0
  31. package/editor/ecs/component/editors/LargeStrongEditor.js +107 -0
  32. package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
  33. package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
  34. package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
  35. package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
  36. package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
  37. package/editor/ecs/component/editors/Sampler2DEditor.js +221 -0
  38. package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
  39. package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
  40. package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
  41. package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
  42. package/editor/ecs/component/editors/common/noEditor.js +9 -0
  43. package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
  44. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
  45. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +225 -0
  46. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
  47. package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +18 -0
  48. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
  49. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +58 -0
  50. package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
  51. package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
  52. package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
  53. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
  54. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +95 -0
  55. package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
  56. package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
  57. package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
  58. package/editor/ecs/component/editors/geom/QuaternionEditor.js +63 -0
  59. package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
  60. package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
  61. package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
  62. package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
  63. package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
  64. package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
  65. package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
  66. package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
  67. package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
  68. package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
  69. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
  70. package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
  71. package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
  72. package/editor/ecs/component/editors/three/TextureEditor.js +112 -0
  73. package/editor/ecs/component/findNearestRegisteredType.js +59 -0
  74. package/editor/ecs/component/prototypeObjectEditor.js +379 -0
  75. package/editor/enableEditor.js +85 -0
  76. package/editor/library/MeshLibrary.js +33 -0
  77. package/editor/process/DisableGameUIProcess.js +43 -0
  78. package/editor/process/EditorProcess.js +35 -0
  79. package/editor/process/ObstacleGridDisplayProcess.js +120 -0
  80. package/editor/process/ProcessEngine.js +123 -0
  81. package/editor/process/SymbolicDisplayProcess.js +132 -0
  82. package/editor/process/symbolic/ComponentSymbolicDisplay.js +34 -0
  83. package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +159 -0
  84. package/editor/process/symbolic/buildThreeJSHelperEntity.js +36 -0
  85. package/editor/process/symbolic/make3DSymbolicDisplay.js +91 -0
  86. package/editor/process/symbolic/makeCameraSymbolicDisplay.js +32 -0
  87. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +176 -0
  88. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  89. package/editor/process/symbolic/makeHelperSphereGeometry.js +73 -0
  90. package/editor/process/symbolic/makeLightSymbolicDisplay.js +77 -0
  91. package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +146 -0
  92. package/editor/process/symbolic/makePathSymbolicDisplay.js +105 -0
  93. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +74 -0
  94. package/editor/process/symbolic/makeSocketsSymbolicDisplay.js +153 -0
  95. package/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
  96. package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.js +89 -0
  97. package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +114 -0
  98. package/editor/process/symbolic/synchronizeTransform.js +50 -0
  99. package/editor/tools/FoliagePaintTool.js +168 -0
  100. package/editor/tools/GridPaintTool.js +247 -0
  101. package/editor/tools/SelectionTool.js +407 -0
  102. package/editor/tools/TopDownCameraControlTool.js +59 -0
  103. package/editor/tools/TransformTool.js +370 -0
  104. package/editor/tools/engine/Tool.js +121 -0
  105. package/editor/tools/engine/ToolEngine.js +193 -0
  106. package/editor/tools/engine/ToolState.js +9 -0
  107. package/editor/tools/engine/ToolStateMachine.js +53 -0
  108. package/editor/tools/paint/TerrainHeightPaintTool.js +297 -0
  109. package/editor/tools/paint/TerrainPaintTool.js +211 -0
  110. package/editor/tools/paint/TerrainTexturePaintTool.js +193 -0
  111. package/editor/tools/paint/prototypeTerrainEditor.js +135 -0
  112. package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +50 -0
  113. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +500 -0
  114. package/editor/tools/v2/TransformControls.d.ts +20 -0
  115. package/editor/tools/v2/TransformControls.js +1782 -0
  116. package/editor/tools/v2/prototypeTransformControls.js +92 -0
  117. package/editor/view/EditorView.js +462 -0
  118. package/editor/view/GridPickCoordinateView.js +88 -0
  119. package/editor/view/ecs/ComponentControlFactory.js +48 -0
  120. package/editor/view/ecs/ComponentControlView.js +214 -0
  121. package/editor/view/ecs/EntityEditor.js +258 -0
  122. package/editor/view/ecs/EntityList.js +258 -0
  123. package/editor/view/ecs/components/BlackboardController.js +50 -0
  124. package/editor/view/ecs/components/DatGuiController.js +216 -0
  125. package/editor/view/ecs/components/FogOfWarController.js +78 -0
  126. package/editor/view/ecs/components/FogOfWarRevealerController.js +44 -0
  127. package/editor/view/ecs/components/GeneratedArmyController.js +42 -0
  128. package/editor/view/ecs/components/GridObstacleController.js +72 -0
  129. package/editor/view/ecs/components/GridPositionController.js +40 -0
  130. package/editor/view/ecs/components/HeadsUpDisplayController.js +30 -0
  131. package/editor/view/ecs/components/HighlightController.js +47 -0
  132. package/editor/view/ecs/components/MeshController.js +125 -0
  133. package/editor/view/ecs/components/PathFollowerController.js +87 -0
  134. package/editor/view/ecs/components/TagController.js +80 -0
  135. package/editor/view/ecs/components/TerrainController.js +225 -0
  136. package/editor/view/ecs/components/TransformController.js +103 -0
  137. package/editor/view/ecs/components/UnitShopController.js +112 -0
  138. package/editor/view/ecs/components/army/ArmyController.js +130 -0
  139. package/editor/view/ecs/components/color/GaugeView.js +107 -0
  140. package/editor/view/ecs/components/common/AutoCanvasView.js +53 -0
  141. package/editor/view/ecs/components/common/LineView.js +17 -0
  142. package/editor/view/ecs/components/common/NumberController.js +112 -0
  143. package/editor/view/ecs/components/common/NumericIntervalController.js +64 -0
  144. package/editor/view/ecs/components/gui/GUIElementController.js +117 -0
  145. package/editor/view/ecs/components/items/ItemContainerController.js +132 -0
  146. package/editor/view/ecs/components/items/ItemContainerController.stories.js +50 -0
  147. package/editor/view/ecs/components/items/ItemController.js +52 -0
  148. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +444 -0
  149. package/editor/view/ecs/components/particles/ParameterTrackController.js +51 -0
  150. package/editor/view/ecs/components/particles/ParticleEmitterController.js +213 -0
  151. package/editor/view/ecs/components/particles/ParticleLayerController.js +213 -0
  152. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +401 -0
  153. package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +51 -0
  154. package/editor/view/ecs/components/sound/SoundEmitterController.js +137 -0
  155. package/editor/view/ecs/components/story/StoryTriggerSetController.js +214 -0
  156. package/editor/view/ecs/components/unit/AuraController.js +45 -0
  157. package/editor/view/library/MeshLibraryView.js +164 -0
  158. package/editor/view/node-graph/NodeGraphEditorView.js +170 -0
  159. package/editor/view/node-graph/NodeGraphView.js +453 -0
  160. package/editor/view/node-graph/NodeView.js +135 -0
  161. package/editor/view/node-graph/PortView.js +69 -0
  162. package/editor/view/process/ProcessView.js +63 -0
  163. package/editor/view/tools/ToolSettingsView.js +143 -0
  164. package/editor/view/tools/ToolView.js +58 -0
  165. package/package.json +2 -1
@@ -0,0 +1,500 @@
1
+ import { CanvasView } from "../../../src/view/elements/CanvasView.js";
2
+ import Vector3 from "../../../src/core/geom/Vector3.js";
3
+ import { compose_matrix4_array } from "../../../src/core/geom/3d/compose_matrix4_array.js";
4
+ import { mat4 } from "gl-matrix";
5
+ import { readPositionFromMouseEvent } from "../../../src/engine/input/devices/PointerDevice.js";
6
+ import Vector2, { v2_distance } from "../../../src/core/geom/Vector2.js";
7
+ import { Color } from "../../../src/core/color/Color.js";
8
+ import { inverseLerp } from "../../../src/core/math/inverseLerp.js";
9
+ import { clamp01 } from "../../../src/core/math/clamp01.js";
10
+ import { lerp } from "../../../src/core/math/lerp.js";
11
+ import Signal from "../../../src/core/events/signal/Signal.js";
12
+ import Quaternion from "../../../src/core/geom/Quaternion.js";
13
+ import { invertQuaternionOrientation } from "../../../src/engine/graphics/ecs/camera/InvertQuaternionOrientation.js";
14
+
15
+ const scratch_color = new Color();
16
+ const scratch_quat = new Quaternion();
17
+ const scratch_m4 = new Float32Array(16);
18
+
19
+ class DirectionStyle {
20
+ constructor() {
21
+ this.near = {
22
+ fill: new Color(1, 0, 0),
23
+ stroke_width: 0,
24
+ stroke_color: new Color(0, 0, 0)
25
+ };
26
+ this.far = {
27
+ fill: new Color(1, 0, 0),
28
+ stroke_width: 0,
29
+ stroke_color: new Color(0, 0, 0)
30
+ };
31
+ }
32
+
33
+ fromJSON({
34
+ near_fill = '#FF0000',
35
+ near_stroke_width = 0,
36
+ near_stroke_color = '#000000',
37
+ far_fill = '#FF0000',
38
+ far_stroke_width = 0,
39
+ far_stroke_color = '#000000'
40
+ }) {
41
+
42
+ this.near.fill.parse(near_fill);
43
+ this.near.stroke_width = near_stroke_width;
44
+ this.near.stroke_color.parse(near_stroke_color);
45
+
46
+ this.far.fill.parse(far_fill);
47
+ this.far.stroke_width = far_stroke_width;
48
+ this.far.stroke_color.parse(far_stroke_color);
49
+ }
50
+
51
+ static fromJSON(j) {
52
+ const r = new DirectionStyle();
53
+
54
+ r.fromJSON(j);
55
+
56
+ return r;
57
+ }
58
+ }
59
+
60
+ function apply_hierarchical_options_from_json(source, target) {
61
+ for (const prop_name in source) {
62
+ if (!target.hasOwnProperty(prop_name)) {
63
+ console.warn(`Property '${prop_name}' doesn't exist, valid properties are : ${Object.keys(target)}`);
64
+ continue;
65
+ }
66
+
67
+ const existing_target_value = target[prop_name];
68
+ const source_value = source[prop_name];
69
+
70
+ if (typeof existing_target_value === "object") {
71
+ if (typeof existing_target_value.fromJSON === "function") {
72
+ existing_target_value.fromJSON(source_value);
73
+ } else {
74
+ apply_hierarchical_options_from_json(source_value, existing_target_value);
75
+ }
76
+ } else {
77
+ target[prop_name] = source_value;
78
+ }
79
+
80
+
81
+ }
82
+ }
83
+
84
+
85
+ /**
86
+ * Modelled on https://github.com/jrj2211/three-orientation-gizmo/blob/master/src/OrientationGizmo.js
87
+ */
88
+ export class BlenderCameraOrientationGizmo extends CanvasView {
89
+ /**
90
+ *
91
+ */
92
+ constructor(options = {}) {
93
+ super();
94
+
95
+ /**
96
+ *
97
+ * @type {Quaternion}
98
+ */
99
+ this.orientation = null;
100
+
101
+ this.options = {
102
+ size: 100,
103
+ padding: 8,
104
+ bubbleSizePrimary: 10,
105
+ bubbleSizeSecondary: 8,
106
+ showSecondary: true,
107
+ lineWidth: 2,
108
+ fontSize: "11px",
109
+ fontFamily: "arial",
110
+ fontWeight: "bold",
111
+ fontColor: "rgba(0,0,0,0.8)",
112
+ fontYAdjust: 1,
113
+ selectionFontColor: "#FFFFFF",
114
+ invertOrientation: true,
115
+ axisStyles: {
116
+ px: DirectionStyle.fromJSON({
117
+ near_fill: "#FF3653",
118
+ far_fill: "#9D3B4A"
119
+ }),
120
+ py: DirectionStyle.fromJSON({
121
+ near_fill: "#8ADB00",
122
+ far_fill: "#648C23"
123
+ }),
124
+ pz: DirectionStyle.fromJSON({
125
+ near_fill: "#2C8FFF",
126
+ far_fill: "#36679D"
127
+ }),
128
+ nx: DirectionStyle.fromJSON({
129
+ near_stroke_color: "#FF3653",
130
+ near_stroke_width: 1,
131
+ near_fill: "#6E3D44",
132
+ far_stroke_color: "#9D3B4A",
133
+ far_stroke_width: 1,
134
+ far_fill: 'rgba(0,0,0,0)'
135
+ }),
136
+ ny: DirectionStyle.fromJSON({
137
+ near_stroke_color: "#8ADB00",
138
+ near_stroke_width: 1,
139
+ near_fill: "#526532",
140
+ far_stroke_color: "#648C23",
141
+ far_stroke_width: 1,
142
+ far_fill: 'rgba(0,0,0,0)'
143
+ }),
144
+ nz: DirectionStyle.fromJSON({
145
+ near_stroke_color: "#2C8FFF",
146
+ near_stroke_width: 1,
147
+ near_fill: "#3B536E",
148
+ far_stroke_color: "#36679D",
149
+ far_stroke_width: 1,
150
+ far_fill: 'rgba(0,0,0,0)'
151
+ })
152
+ }
153
+ };
154
+
155
+ // read options
156
+ apply_hierarchical_options_from_json(options, this.options);
157
+
158
+ // Generate list of axes
159
+ this.bubbles = [
160
+ {
161
+ axis: "x",
162
+ direction: new Vector3(1, 0, 0),
163
+ size: this.options.bubbleSizePrimary,
164
+ style: this.options.axisStyles.px,
165
+ line: this.options.lineWidth,
166
+ label: "X",
167
+ primary: true
168
+ },
169
+ {
170
+ axis: "y",
171
+ direction: new Vector3(0, 1, 0),
172
+ size: this.options.bubbleSizePrimary,
173
+ style: this.options.axisStyles.py,
174
+ line: this.options.lineWidth,
175
+ label: "Y",
176
+ primary: true
177
+ },
178
+ {
179
+ axis: "z",
180
+ direction: new Vector3(0, 0, 1),
181
+ size: this.options.bubbleSizePrimary,
182
+ style: this.options.axisStyles.pz,
183
+ line: this.options.lineWidth,
184
+ label: "Z",
185
+ primary: true
186
+ },
187
+ {
188
+ axis: "-x",
189
+ direction: new Vector3(-1, 0, 0),
190
+ size: this.options.bubbleSizeSecondary,
191
+ style: this.options.axisStyles.nx,
192
+ label: "-X",
193
+ labelHideUnselected: true,
194
+ primary: false
195
+ },
196
+ {
197
+ axis: "-y",
198
+ direction: new Vector3(0, -1, 0),
199
+ size: this.options.bubbleSizeSecondary,
200
+ style: this.options.axisStyles.ny,
201
+ label: "-Y",
202
+ labelHideUnselected: true,
203
+ primary: false
204
+ },
205
+ {
206
+ axis: "-z",
207
+ direction: new Vector3(0, 0, -1),
208
+ size: this.options.bubbleSizeSecondary,
209
+ style: this.options.axisStyles.nz,
210
+ label: "-Y",
211
+ labelHideUnselected: true,
212
+ primary: false
213
+ },
214
+ ];
215
+
216
+ /**
217
+ *
218
+ * @type {Vector3|null}
219
+ */
220
+ this.input_pointer_position = null;
221
+
222
+ this.center = new Vector3(this.options.size / 2, this.options.size / 2, 0);
223
+ this.selectedAxis = null;
224
+
225
+ this.size.setScalar(this.options.size);
226
+
227
+ this.onMouseMove = this.onMouseMove.bind(this);
228
+ this.onMouseOut = this.onMouseOut.bind(this);
229
+ this.onMouseClick = this.onMouseClick.bind(this);
230
+
231
+ /**
232
+ *
233
+ * Invoked when axis is clicked
234
+ * @type {Signal<string,Vector3>}
235
+ */
236
+ this.on.axisSelected = new Signal();
237
+
238
+ /**
239
+ *
240
+ * @type {boolean}
241
+ * @private
242
+ */
243
+ this.__needs_update = true;
244
+ }
245
+
246
+ link() {
247
+ super.link();
248
+
249
+ const el = this.el;
250
+
251
+ el.addEventListener('mousemove', this.onMouseMove);
252
+ el.addEventListener('mouseout', this.onMouseOut);
253
+ el.addEventListener('click', this.onMouseClick);
254
+ }
255
+
256
+ unlink() {
257
+ const el = this.el;
258
+
259
+ el.removeEventListener('mousemove', this.onMouseMove);
260
+ el.removeEventListener('mouseout', this.onMouseOut);
261
+ el.removeEventListener('click', this.onMouseClick);
262
+
263
+ super.unlink();
264
+ }
265
+
266
+ /**
267
+ *
268
+ * @param {MouseEvent} evt
269
+ */
270
+ onMouseMove(evt) {
271
+ this._setPointerPositionFromEvent(evt);
272
+ this.__try_update();
273
+ }
274
+
275
+ /**
276
+ *
277
+ * @param {MouseEvent} evt
278
+ * @private
279
+ */
280
+ _setPointerPositionFromEvent(evt) {
281
+ const v2 = new Vector2();
282
+
283
+ readPositionFromMouseEvent(v2, evt);
284
+
285
+ const position_changed = (this.input_pointer_position === null || this.input_pointer_position.x !== v2.x || this.input_pointer_position.y !== v2.y);
286
+
287
+ this.input_pointer_position = new Vector3(v2.x, v2.y, 0);
288
+
289
+
290
+ if (position_changed) {
291
+ this.__needs_update = true;
292
+ }
293
+
294
+ return position_changed;
295
+ }
296
+
297
+ /**
298
+ *
299
+ * @param {MouseEvent} evt
300
+ */
301
+ onMouseOut(evt) {
302
+ this.input_pointer_position = null;
303
+ this.__needs_update = true;
304
+ this.__try_update();
305
+ }
306
+
307
+ /**
308
+ *
309
+ * @param {MouseEvent} evt
310
+ */
311
+ onMouseClick(evt) {
312
+
313
+ this._setPointerPositionFromEvent(evt);
314
+
315
+ this.__try_update();
316
+
317
+ if (this.selectedAxis !== null) {
318
+
319
+ if (this.on.axisSelected.hasHandlers()) {
320
+ // axis selection will be handled, stop propagation
321
+ evt.stopPropagation();
322
+ }
323
+
324
+ this.on.axisSelected.send2(
325
+ this.selectedAxis.axis,
326
+ this.selectedAxis.direction.clone()
327
+ );
328
+ }
329
+ }
330
+
331
+ drawCircle(p, radius = 10, fill_color = "#FF0000", stroke_width = 0, stroke_color = "#FFFFFF") {
332
+ const ctx = this.context2d;
333
+
334
+ ctx.beginPath();
335
+ ctx.arc(p.x, p.y, radius, 0, 2 * Math.PI, false);
336
+ ctx.fillStyle = fill_color;
337
+ ctx.fill();
338
+
339
+ if (stroke_width > 0) {
340
+ ctx.lineWidth = stroke_width;
341
+ ctx.strokeStyle = stroke_color;
342
+ ctx.stroke();
343
+ }
344
+
345
+ ctx.closePath();
346
+ }
347
+
348
+ drawLine(p1, p2, width = 1, color = "#FF0000") {
349
+ const ctx = this.context2d;
350
+
351
+ ctx.beginPath();
352
+ ctx.moveTo(p1.x, p1.y);
353
+ ctx.lineTo(p2.x, p2.y);
354
+ ctx.lineWidth = width;
355
+ ctx.strokeStyle = color;
356
+ ctx.stroke();
357
+ ctx.closePath();
358
+ }
359
+
360
+ __try_update() {
361
+ if (!this.__needs_update) {
362
+ return;
363
+ }
364
+ this.update();
365
+ }
366
+
367
+ update() {
368
+ // reset flag
369
+ this.__needs_update = false;
370
+
371
+ this.clear();
372
+
373
+ // Calculate the rotation matrix from the camera
374
+ const rotation_matrix = scratch_m4;
375
+ let rotation = this.orientation;
376
+
377
+ if (rotation === null) {
378
+ // not connected
379
+ return;
380
+ }
381
+
382
+ if (this.options.invertOrientation) {
383
+ const q = scratch_quat;
384
+
385
+ invertQuaternionOrientation(q, rotation);
386
+
387
+ rotation = q;
388
+ }
389
+
390
+ compose_matrix4_array(rotation_matrix, Vector3.zero, rotation, Vector3.one);
391
+ mat4.invert(rotation_matrix, rotation_matrix);
392
+
393
+ for (const bubble of this.bubbles) {
394
+ const direction = bubble.direction.clone();
395
+ direction.applyMatrix4(rotation_matrix);
396
+
397
+ bubble.position = this.getBubblePosition(direction);
398
+ }
399
+
400
+ // Generate a list of layers to draw
401
+ const layers = [];
402
+
403
+ for (const bubble of this.bubbles) {
404
+ // Check if the name starts with a negative and dont add it to the layer list if secondary axis is turned off
405
+ const is_secondary = bubble.axis[0] !== "-";
406
+ if (this.options.showSecondary === true || is_secondary) {
407
+ layers.push(bubble);
408
+ }
409
+ }
410
+
411
+ // Sort the layers where the +Z position is last so its drawn on top of anything below it
412
+ layers.sort((a, b) => (a.position.z > b.position.z) ? 1 : -1);
413
+
414
+ // If the mouse is over the gizmo, find the closest axis and highlight it
415
+ this.selectedAxis = null;
416
+
417
+ if (this.input_pointer_position) {
418
+ let closestDist = Infinity;
419
+ let closestZ = -Infinity;
420
+
421
+ // Loop through each layer
422
+ for (let bubble of layers) {
423
+ const distance = v2_distance(this.input_pointer_position.x, this.input_pointer_position.y, bubble.position.x, bubble.position.y);
424
+
425
+ // Only select the axis if its closer to the mouse than the previous or if its within its bubble circle
426
+ if (
427
+ distance < closestDist
428
+ && closestZ < bubble.position.z
429
+ && distance <= bubble.size
430
+ ) {
431
+
432
+ closestDist = distance;
433
+ closestZ = bubble.position.z;
434
+ this.selectedAxis = bubble;
435
+
436
+ }
437
+ }
438
+ }
439
+
440
+ // Draw the layers
441
+ this.drawLayers(layers);
442
+ }
443
+
444
+ /**
445
+ *
446
+ * @param {{style:DirectionStyle, position:Vector3, size:number,line:boolean, label?:string,labelHideUnselected?:boolean}[]} layers
447
+ */
448
+ drawLayers(layers) {
449
+ // For each layer, draw the bubble
450
+ for (let bubble of layers) {
451
+
452
+ // Find the color
453
+ const is_selected = this.selectedAxis === bubble;
454
+
455
+ const closeness = clamp01(inverseLerp(-1, 0.8, bubble.position.z));
456
+
457
+ const style = bubble.style;
458
+
459
+ scratch_color.lerpColors(style.far.fill, style.near.fill, closeness);
460
+ const fill_color = scratch_color.toCssRGBAString();
461
+
462
+ scratch_color.lerpColors(style.far.stroke_color, style.near.stroke_color, closeness);
463
+ const stroke_color = scratch_color.toCssRGBAString();
464
+
465
+ const stroke_width = lerp(style.far.stroke_width, style.near.stroke_width, closeness);
466
+
467
+ // Draw the circle for the bubbble
468
+ this.drawCircle(bubble.position, bubble.size, fill_color, stroke_width, stroke_color);
469
+
470
+ // Draw the line that connects it to the center if enabled
471
+ if (bubble.line) {
472
+ this.drawLine(this.center, bubble.position, bubble.line, fill_color);
473
+ }
474
+
475
+ // Write the axis label (X,Y,Z) if provided
476
+ if (bubble.label && (is_selected || (bubble.labelHideUnselected !== true))) {
477
+ const ctx = this.context2d;
478
+
479
+ ctx.font = [this.options.fontWeight, this.options.fontSize, this.options.fontFamily].join(" ");
480
+ ctx.fillStyle = is_selected ? this.options.selectionFontColor : this.options.fontColor;
481
+ ctx.textBaseline = 'middle';
482
+ ctx.textAlign = 'center';
483
+ ctx.fillText(bubble.label, bubble.position.x, bubble.position.y + this.options.fontYAdjust);
484
+ }
485
+ }
486
+ }
487
+
488
+ /**
489
+ *
490
+ * @param {Vector3} position
491
+ * @returns {Vector3}
492
+ */
493
+ getBubblePosition(position) {
494
+ return new Vector3(
495
+ (position.x * (this.center.x - (this.options.bubbleSizePrimary / 2) - this.options.padding)) + this.center.x,
496
+ this.center.y - (position.y * (this.center.y - (this.options.bubbleSizePrimary / 2) - this.options.padding)),
497
+ position.z
498
+ );
499
+ }
500
+ }
@@ -0,0 +1,20 @@
1
+ import {OrthographicCamera, PerspectiveCamera} from "three";
2
+ import {EntityComponentDataset} from "../../../src/engine/ecs/EntityComponentDataset";
3
+ import {EntityNode} from "../../../src/engine/ecs/parent/EntityNode";
4
+
5
+ export class TransformControls extends EntityNode {
6
+ constructor(camera: PerspectiveCamera | OrthographicCamera, domElement: HTMLElement, autoUpdate?: boolean)
7
+
8
+ build(ecd: EntityComponentDataset): void
9
+
10
+ destroy(): void
11
+
12
+ attach(entity: number): void
13
+
14
+ detach(): void
15
+
16
+ /**
17
+ * Can be triggered manually if `autoUpdate` was not set in the constructor
18
+ */
19
+ update(): void
20
+ }