@woosh/meep-engine 2.46.29 → 2.46.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/editor/Editor.js +793 -0
- package/editor/SelectionVisualizer.js +148 -0
- package/editor/actions/concrete/ActionUpdateTexture.js +21 -0
- package/editor/actions/concrete/ArrayCopyAction.js +39 -0
- package/editor/actions/concrete/ComponentAddAction.js +47 -0
- package/editor/actions/concrete/ComponentRemoveAction.js +38 -0
- package/editor/actions/concrete/EntityCreateAction.js +47 -0
- package/editor/actions/concrete/EntityRemoveAction.js +51 -0
- package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
- package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
- package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +182 -0
- package/editor/actions/concrete/PaintTerrainOverlayAction.js +45 -0
- package/editor/actions/concrete/PatchTerrainHeightAction.js +67 -0
- package/editor/actions/concrete/PatchTerrainTextureAction.js +152 -0
- package/editor/actions/concrete/SelectionAddAction.js +36 -0
- package/editor/actions/concrete/SelectionClearAction.js +22 -0
- package/editor/actions/concrete/SelectionRemoveAction.js +30 -0
- package/editor/actions/concrete/TransformModifyAction.js +46 -0
- package/editor/actions/concrete/WriteGridValueAction.js +46 -0
- package/editor/ecs/EditorEntity.js +12 -0
- package/editor/ecs/EditorEntitySystem.js +14 -0
- package/editor/ecs/component/FieldDescriptor.js +34 -0
- package/editor/ecs/component/FieldValueAdapter.js +20 -0
- package/editor/ecs/component/TypeEditor.js +33 -0
- package/editor/ecs/component/TypeSchema.d.ts +38 -0
- package/editor/ecs/component/createFieldEditor.js +92 -0
- package/editor/ecs/component/createObjectEditor.js +361 -0
- package/editor/ecs/component/editors/ColorEditor.js +39 -0
- package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
- package/editor/ecs/component/editors/ImagePathEditor.js +82 -0
- package/editor/ecs/component/editors/LargeStrongEditor.js +107 -0
- package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
- package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
- package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
- package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
- package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
- package/editor/ecs/component/editors/Sampler2DEditor.js +221 -0
- package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
- package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
- package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
- package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
- package/editor/ecs/component/editors/common/noEditor.js +9 -0
- package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
- package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +225 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +18 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
- package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
- package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
- package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +95 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
- package/editor/ecs/component/editors/geom/QuaternionEditor.js +63 -0
- package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
- package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
- package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
- package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
- package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
- package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
- package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
- package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
- package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
- package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
- package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
- package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
- package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
- package/editor/ecs/component/editors/three/TextureEditor.js +112 -0
- package/editor/ecs/component/findNearestRegisteredType.js +59 -0
- package/editor/ecs/component/prototypeObjectEditor.js +379 -0
- package/editor/enableEditor.js +85 -0
- package/editor/library/MeshLibrary.js +33 -0
- package/editor/process/DisableGameUIProcess.js +43 -0
- package/editor/process/EditorProcess.js +35 -0
- package/editor/process/ObstacleGridDisplayProcess.js +120 -0
- package/editor/process/ProcessEngine.js +123 -0
- package/editor/process/SymbolicDisplayProcess.js +132 -0
- package/editor/process/symbolic/ComponentSymbolicDisplay.js +34 -0
- package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +159 -0
- package/editor/process/symbolic/buildThreeJSHelperEntity.js +36 -0
- package/editor/process/symbolic/make3DSymbolicDisplay.js +91 -0
- package/editor/process/symbolic/makeCameraSymbolicDisplay.js +32 -0
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +176 -0
- package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
- package/editor/process/symbolic/makeHelperSphereGeometry.js +73 -0
- package/editor/process/symbolic/makeLightSymbolicDisplay.js +77 -0
- package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +146 -0
- package/editor/process/symbolic/makePathSymbolicDisplay.js +105 -0
- package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +74 -0
- package/editor/process/symbolic/makeSocketsSymbolicDisplay.js +153 -0
- package/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
- package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.js +89 -0
- package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +114 -0
- package/editor/process/symbolic/synchronizeTransform.js +50 -0
- package/editor/tools/FoliagePaintTool.js +168 -0
- package/editor/tools/GridPaintTool.js +247 -0
- package/editor/tools/SelectionTool.js +407 -0
- package/editor/tools/TopDownCameraControlTool.js +59 -0
- package/editor/tools/TransformTool.js +370 -0
- package/editor/tools/engine/Tool.js +121 -0
- package/editor/tools/engine/ToolEngine.js +193 -0
- package/editor/tools/engine/ToolState.js +9 -0
- package/editor/tools/engine/ToolStateMachine.js +53 -0
- package/editor/tools/paint/TerrainHeightPaintTool.js +297 -0
- package/editor/tools/paint/TerrainPaintTool.js +211 -0
- package/editor/tools/paint/TerrainTexturePaintTool.js +193 -0
- package/editor/tools/paint/prototypeTerrainEditor.js +135 -0
- package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +50 -0
- package/editor/tools/v2/BlenderCameraOrientationGizmo.js +500 -0
- package/editor/tools/v2/TransformControls.d.ts +20 -0
- package/editor/tools/v2/TransformControls.js +1782 -0
- package/editor/tools/v2/prototypeTransformControls.js +92 -0
- package/editor/view/EditorView.js +462 -0
- package/editor/view/GridPickCoordinateView.js +88 -0
- package/editor/view/ecs/ComponentControlFactory.js +48 -0
- package/editor/view/ecs/ComponentControlView.js +214 -0
- package/editor/view/ecs/EntityEditor.js +258 -0
- package/editor/view/ecs/EntityList.js +258 -0
- package/editor/view/ecs/components/BlackboardController.js +50 -0
- package/editor/view/ecs/components/DatGuiController.js +216 -0
- package/editor/view/ecs/components/FogOfWarController.js +78 -0
- package/editor/view/ecs/components/FogOfWarRevealerController.js +44 -0
- package/editor/view/ecs/components/GeneratedArmyController.js +42 -0
- package/editor/view/ecs/components/GridObstacleController.js +72 -0
- package/editor/view/ecs/components/GridPositionController.js +40 -0
- package/editor/view/ecs/components/HeadsUpDisplayController.js +30 -0
- package/editor/view/ecs/components/HighlightController.js +47 -0
- package/editor/view/ecs/components/MeshController.js +125 -0
- package/editor/view/ecs/components/PathFollowerController.js +87 -0
- package/editor/view/ecs/components/TagController.js +80 -0
- package/editor/view/ecs/components/TerrainController.js +225 -0
- package/editor/view/ecs/components/TransformController.js +103 -0
- package/editor/view/ecs/components/UnitShopController.js +112 -0
- package/editor/view/ecs/components/army/ArmyController.js +130 -0
- package/editor/view/ecs/components/color/GaugeView.js +107 -0
- package/editor/view/ecs/components/common/AutoCanvasView.js +53 -0
- package/editor/view/ecs/components/common/LineView.js +17 -0
- package/editor/view/ecs/components/common/NumberController.js +112 -0
- package/editor/view/ecs/components/common/NumericIntervalController.js +64 -0
- package/editor/view/ecs/components/gui/GUIElementController.js +117 -0
- package/editor/view/ecs/components/items/ItemContainerController.js +132 -0
- package/editor/view/ecs/components/items/ItemContainerController.stories.js +50 -0
- package/editor/view/ecs/components/items/ItemController.js +52 -0
- package/editor/view/ecs/components/particles/ColorParameterLUTController.js +444 -0
- package/editor/view/ecs/components/particles/ParameterTrackController.js +51 -0
- package/editor/view/ecs/components/particles/ParticleEmitterController.js +213 -0
- package/editor/view/ecs/components/particles/ParticleLayerController.js +213 -0
- package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +401 -0
- package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +51 -0
- package/editor/view/ecs/components/sound/SoundEmitterController.js +137 -0
- package/editor/view/ecs/components/story/StoryTriggerSetController.js +214 -0
- package/editor/view/ecs/components/unit/AuraController.js +45 -0
- package/editor/view/library/MeshLibraryView.js +164 -0
- package/editor/view/node-graph/NodeGraphEditorView.js +170 -0
- package/editor/view/node-graph/NodeGraphView.js +453 -0
- package/editor/view/node-graph/NodeView.js +135 -0
- package/editor/view/node-graph/PortView.js +69 -0
- package/editor/view/process/ProcessView.js +63 -0
- package/editor/view/tools/ToolSettingsView.js +143 -0
- package/editor/view/tools/ToolView.js +58 -0
- package/package.json +2 -1
- package/src/engine/intelligence/behavior/composite/CompositeBehavior.js +18 -2
- package/src/engine/intelligence/behavior/composite/ParallelBehavior.js +21 -9
- package/src/engine/intelligence/behavior/composite/SequenceBehavior.js +5 -1
- package/src/engine/intelligence/behavior/util/DelayBehavior.js +8 -3
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
import GuiControl from "../../../../../src/view/controller/controls/GuiControl.js";
|
|
2
|
+
import View from "../../../../../src/view/View.js";
|
|
3
|
+
import { PointerDevice } from "../../../../../src/engine/input/devices/PointerDevice.js";
|
|
4
|
+
import Vector2 from "../../../../../src/core/geom/Vector2.js";
|
|
5
|
+
import ObservedValue from "../../../../../src/core/model/ObservedValue.js";
|
|
6
|
+
import { ColorPickerView } from "../../../../../src/view/elements/ColorPickerView.js";
|
|
7
|
+
import Vector1 from "../../../../../src/core/geom/Vector1.js";
|
|
8
|
+
import Vector4 from "../../../../../src/core/geom/Vector4.js";
|
|
9
|
+
import {
|
|
10
|
+
ParameterLookupTableFlags
|
|
11
|
+
} from "../../../../../src/engine/graphics/particles/particular/engine/parameter/ParameterLookupTableFlags.js";
|
|
12
|
+
import { DomSizeObserver } from "../../../../../src/view/util/DomSizeObserver.js";
|
|
13
|
+
import { AutoCanvasView } from "../common/AutoCanvasView.js";
|
|
14
|
+
import EmptyView from "../../../../../src/view/elements/EmptyView.js";
|
|
15
|
+
import { clamp01 } from "../../../../../src/core/math/clamp01.js";
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MarkerView extends View {
|
|
19
|
+
constructor() {
|
|
20
|
+
super();
|
|
21
|
+
|
|
22
|
+
const el = document.createElement('div');
|
|
23
|
+
this.el = el;
|
|
24
|
+
|
|
25
|
+
this.el.classList.add('marker-view');
|
|
26
|
+
|
|
27
|
+
this.color = new ObservedValue();
|
|
28
|
+
|
|
29
|
+
this.color.onChanged.add(function (value) {
|
|
30
|
+
el.style.backgroundColor = value;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @param {Array.<MarkerView>} markers
|
|
39
|
+
* @param {function():ParameterLookupTable} model
|
|
40
|
+
* @param {function} update
|
|
41
|
+
* @param {HTMLCanvasElement} canvas
|
|
42
|
+
* @param {Vector1} selection
|
|
43
|
+
* @returns {MarkerView}
|
|
44
|
+
*/
|
|
45
|
+
function buildMarker(markers, model, update, canvas, selection) {
|
|
46
|
+
const marker = new MarkerView();
|
|
47
|
+
|
|
48
|
+
const pMarker = new PointerDevice(marker.el);
|
|
49
|
+
const pGlobal = new PointerDevice(window);
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const dragAnchor = new Vector2();
|
|
53
|
+
let dragScale;
|
|
54
|
+
let oldPosition;
|
|
55
|
+
|
|
56
|
+
let dragging = false;
|
|
57
|
+
|
|
58
|
+
function handleMove(position, event) {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
|
|
62
|
+
const delta = position.clone().sub(dragAnchor);
|
|
63
|
+
|
|
64
|
+
const markerIndex = markers.indexOf(marker);
|
|
65
|
+
|
|
66
|
+
if (markerIndex === -1) {
|
|
67
|
+
//dead marker
|
|
68
|
+
pMarker.stop();
|
|
69
|
+
pGlobal.stop();
|
|
70
|
+
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const lut = model();
|
|
75
|
+
|
|
76
|
+
const positionDelta = delta.x / canvas.width;
|
|
77
|
+
|
|
78
|
+
const newPosition = clamp01(oldPosition + positionDelta);
|
|
79
|
+
|
|
80
|
+
lut.positions[markerIndex] = newPosition;
|
|
81
|
+
|
|
82
|
+
update();
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function handleDragEnd() {
|
|
86
|
+
pGlobal.on.move.remove(handleMove);
|
|
87
|
+
pGlobal.on.up.remove(handleDragEnd);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
pGlobal.on.down.add(function (position) {
|
|
91
|
+
dragAnchor.copy(position);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
pMarker.on.down.add(function (position, event) {
|
|
95
|
+
const markerIndex = markers.indexOf(marker);
|
|
96
|
+
|
|
97
|
+
if (markerIndex === -1) {
|
|
98
|
+
//dead marker
|
|
99
|
+
pMarker.stop();
|
|
100
|
+
pGlobal.stop();
|
|
101
|
+
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (event.which === 2) {
|
|
106
|
+
//middle mouse button
|
|
107
|
+
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
event.stopPropagation();
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
const lut = model();
|
|
113
|
+
|
|
114
|
+
lut.positions.splice(markerIndex, 1);
|
|
115
|
+
lut.data.splice(markerIndex * lut.itemSize, lut.itemSize);
|
|
116
|
+
|
|
117
|
+
if (selection.getValue() === markerIndex) {
|
|
118
|
+
selection.set(-1);
|
|
119
|
+
} else if (selection.getValue() > markerIndex) {
|
|
120
|
+
selection._sub(1);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
update();
|
|
124
|
+
} else {
|
|
125
|
+
selection.set(markerIndex);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
pMarker.on.dragStart.add(function () {
|
|
130
|
+
dragging = true;
|
|
131
|
+
|
|
132
|
+
const lut = model();
|
|
133
|
+
|
|
134
|
+
dragScale = lut.valueMax - lut.valueMin;
|
|
135
|
+
if (dragScale === 0) {
|
|
136
|
+
dragScale = 0.1;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const markerIndex = markers.indexOf(marker);
|
|
140
|
+
|
|
141
|
+
oldPosition = lut.positions[markerIndex];
|
|
142
|
+
|
|
143
|
+
pGlobal.on.move.add(handleMove);
|
|
144
|
+
pGlobal.on.up.add(handleDragEnd);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
pMarker.start();
|
|
148
|
+
pGlobal.start();
|
|
149
|
+
|
|
150
|
+
return marker;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
*
|
|
155
|
+
* @param {CanvasRenderingContext2D} context
|
|
156
|
+
* @param {number} width
|
|
157
|
+
* @param {number} height
|
|
158
|
+
* @param {number}cellSize
|
|
159
|
+
* @param {string} color1
|
|
160
|
+
* @param {string} color2
|
|
161
|
+
*/
|
|
162
|
+
export function drawCheckers(context, width, height, cellSize, color1, color2) {
|
|
163
|
+
const lX = Math.ceil(width / cellSize);
|
|
164
|
+
const lY = Math.ceil(height / cellSize);
|
|
165
|
+
|
|
166
|
+
let i, j;
|
|
167
|
+
|
|
168
|
+
for (i = 0; i < lX; i++) {
|
|
169
|
+
|
|
170
|
+
const x = i * cellSize;
|
|
171
|
+
|
|
172
|
+
for (j = 0; j < lY; j++) {
|
|
173
|
+
|
|
174
|
+
const y = j * cellSize;
|
|
175
|
+
|
|
176
|
+
const color = (i + j) % 2 === 0 ? color1 : color2;
|
|
177
|
+
|
|
178
|
+
context.fillStyle = color;
|
|
179
|
+
|
|
180
|
+
context.fillRect(x, y, cellSize, cellSize);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
*
|
|
187
|
+
* @param {ParameterLookupTable} lut
|
|
188
|
+
* @param {CanvasRenderingContext2D} context
|
|
189
|
+
* @param {number} width
|
|
190
|
+
* @param {number} height
|
|
191
|
+
*/
|
|
192
|
+
function drawGradient(lut, context, width, height) {
|
|
193
|
+
|
|
194
|
+
//create gradient
|
|
195
|
+
const gradient = context.createLinearGradient(0, 0, width, 0);
|
|
196
|
+
|
|
197
|
+
const positions = lut.positions;
|
|
198
|
+
|
|
199
|
+
const numValues = positions.length;
|
|
200
|
+
|
|
201
|
+
const colorSample = [1, 1, 1, 1];
|
|
202
|
+
for (let i = 0; i < numValues; i++) {
|
|
203
|
+
const position = positions[i];
|
|
204
|
+
|
|
205
|
+
lut.sample(position, colorSample);
|
|
206
|
+
|
|
207
|
+
const r = colorSample[0] * 255;
|
|
208
|
+
const g = colorSample[1] * 255;
|
|
209
|
+
const b = colorSample[2] * 255;
|
|
210
|
+
const a = colorSample[3];
|
|
211
|
+
|
|
212
|
+
const color = `rgba(${r},${g},${b},${a})`;
|
|
213
|
+
|
|
214
|
+
gradient.addColorStop(position, color);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//draw gradient
|
|
218
|
+
context.fillStyle = gradient;
|
|
219
|
+
|
|
220
|
+
context.fillRect(0, 0, width, height);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export class ColorParameterLUTController extends GuiControl {
|
|
224
|
+
constructor() {
|
|
225
|
+
super();
|
|
226
|
+
|
|
227
|
+
const vColorPicker = new ColorPickerView();
|
|
228
|
+
const color = new Vector4(1, 1, 1, 1);
|
|
229
|
+
vColorPicker.model.set(color);
|
|
230
|
+
|
|
231
|
+
const selection = new Vector1(-1);
|
|
232
|
+
|
|
233
|
+
this.el.classList.add('color-parameter-lut-controller');
|
|
234
|
+
|
|
235
|
+
const self = this;
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
const vGradient = new EmptyView({ classList: ['gradient'] });
|
|
239
|
+
this.addChild(vGradient);
|
|
240
|
+
this.addChild(vColorPicker);
|
|
241
|
+
|
|
242
|
+
const vCanvas = new AutoCanvasView({ classList: ['gradient-canvas'] });
|
|
243
|
+
const canvas = vCanvas.el;
|
|
244
|
+
|
|
245
|
+
vGradient.addChild(vCanvas);
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
*
|
|
249
|
+
* @type {Array.<MarkerView>}
|
|
250
|
+
*/
|
|
251
|
+
const markers = [];
|
|
252
|
+
|
|
253
|
+
selection.onChanged.add(function (value) {
|
|
254
|
+
markers.forEach(function (markerView, index) {
|
|
255
|
+
markerView.el.classList.toggle('selected', index === value);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const lut = model();
|
|
259
|
+
|
|
260
|
+
if (value !== -1 && lut !== null) {
|
|
261
|
+
|
|
262
|
+
const position = lut.positions[value];
|
|
263
|
+
|
|
264
|
+
const colorArray = [];
|
|
265
|
+
|
|
266
|
+
lut.sample(position, colorArray);
|
|
267
|
+
|
|
268
|
+
color.set(colorArray[0], colorArray[1], colorArray[2], colorArray[3]);
|
|
269
|
+
|
|
270
|
+
} else {
|
|
271
|
+
color.set(1, 1, 1, 1);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
color.onChanged.add(function (r, g, b, a) {
|
|
276
|
+
|
|
277
|
+
const lut = model();
|
|
278
|
+
|
|
279
|
+
if (lut === null) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
const markIndex = selection.getValue();
|
|
284
|
+
|
|
285
|
+
if (markIndex === -1) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const address = markIndex * lut.itemSize;
|
|
290
|
+
|
|
291
|
+
lut.data[address + 0] = r;
|
|
292
|
+
lut.data[address + 1] = g;
|
|
293
|
+
lut.data[address + 2] = b;
|
|
294
|
+
lut.data[address + 3] = a;
|
|
295
|
+
|
|
296
|
+
lut.computeStatistics();
|
|
297
|
+
|
|
298
|
+
update();
|
|
299
|
+
});
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
*
|
|
303
|
+
* @returns {ParameterLookupTable}
|
|
304
|
+
*/
|
|
305
|
+
function model() {
|
|
306
|
+
return self.model.getValue();
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
vCanvas.draw = function (context, width, height) {
|
|
310
|
+
|
|
311
|
+
//clear
|
|
312
|
+
context.clearRect(0, 0, width, height);
|
|
313
|
+
|
|
314
|
+
//draw transparency checkers
|
|
315
|
+
drawCheckers(context, width, height, 5, '#FFFFFF', '#999999');
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
*
|
|
319
|
+
* @type {ParameterLookupTable}
|
|
320
|
+
*/
|
|
321
|
+
const lut = model();
|
|
322
|
+
|
|
323
|
+
if (lut === null) {
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
drawGradient(lut, context, width, height);
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
function updateGradient() {
|
|
331
|
+
vCanvas.render();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
function createMarker() {
|
|
335
|
+
const marker = buildMarker(markers, model, update, canvas, selection);
|
|
336
|
+
|
|
337
|
+
markers.push(marker);
|
|
338
|
+
vGradient.addChild(marker);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function resizeMarkerPool(size) {
|
|
342
|
+
while (size < markers.length) {
|
|
343
|
+
const marker = markers.pop();
|
|
344
|
+
vGradient.removeChild(marker);
|
|
345
|
+
}
|
|
346
|
+
while (size > markers.length) {
|
|
347
|
+
createMarker();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function updateMarkers() {
|
|
352
|
+
const lut = model();
|
|
353
|
+
|
|
354
|
+
if (lut === null) {
|
|
355
|
+
resizeMarkerPool(0);
|
|
356
|
+
} else {
|
|
357
|
+
|
|
358
|
+
const numValue = lut.positions.length;
|
|
359
|
+
|
|
360
|
+
resizeMarkerPool(numValue);
|
|
361
|
+
|
|
362
|
+
for (let i = 0; i < numValue; i++) {
|
|
363
|
+
const marker = markers[i];
|
|
364
|
+
|
|
365
|
+
const position = lut.positions[i];
|
|
366
|
+
|
|
367
|
+
marker.el.style.left = `${position * 100}%`;
|
|
368
|
+
|
|
369
|
+
const sample = [];
|
|
370
|
+
|
|
371
|
+
lut.sample(position, sample);
|
|
372
|
+
|
|
373
|
+
const r = sample[0] * 255;
|
|
374
|
+
const g = sample[1] * 255;
|
|
375
|
+
const b = sample[2] * 255;
|
|
376
|
+
|
|
377
|
+
const color = `rgb(${r},${g},${b})`;
|
|
378
|
+
|
|
379
|
+
marker.color.set(color);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function update() {
|
|
385
|
+
updateGradient();
|
|
386
|
+
updateMarkers();
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
const pCanvas = new PointerDevice(canvas);
|
|
390
|
+
|
|
391
|
+
pCanvas.on.down.add(function (position, event) {
|
|
392
|
+
const p = event.offsetX / canvas.width;
|
|
393
|
+
|
|
394
|
+
const lut = model();
|
|
395
|
+
|
|
396
|
+
//ensure that statistics are present
|
|
397
|
+
lut.computeStatistics();
|
|
398
|
+
|
|
399
|
+
const value = [];
|
|
400
|
+
|
|
401
|
+
lut.sample(p, value);
|
|
402
|
+
|
|
403
|
+
//erase NaN values if there are any
|
|
404
|
+
for (let i = 0; i < value.length; i++) {
|
|
405
|
+
if (Number.isNaN(value[i])) {
|
|
406
|
+
value[i] = 0;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
lut.setFlag(ParameterLookupTableFlags.WriteMode);
|
|
412
|
+
|
|
413
|
+
lut.addValue(p, value);
|
|
414
|
+
|
|
415
|
+
lut.clearFlag(ParameterLookupTableFlags.WriteMode);
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
lut.computeStatistics();
|
|
419
|
+
update();
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
pCanvas.start();
|
|
423
|
+
|
|
424
|
+
this.addChild(vGradient);
|
|
425
|
+
|
|
426
|
+
const sizeObserver = new DomSizeObserver({ depth: 5 });
|
|
427
|
+
sizeObserver.dimensions.size.onChanged.add(update);
|
|
428
|
+
|
|
429
|
+
this.on.linked.add(() => {
|
|
430
|
+
update();
|
|
431
|
+
|
|
432
|
+
sizeObserver.attach(this.el);
|
|
433
|
+
sizeObserver.start();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
this.on.unlinked.add(() => {
|
|
437
|
+
sizeObserver.stop();
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
this.model.onChanged.add(function (lut, oldLut) {
|
|
441
|
+
update();
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import GuiControl from "../../../../../src/view/controller/controls/GuiControl.js";
|
|
2
|
+
import LabelView from "../../../../../src/view/common/LabelView.js";
|
|
3
|
+
import { ColorParameterLUTController } from "./ColorParameterLUTController.js";
|
|
4
|
+
import { ScalarParameterLUTController } from "./ScalarParameterLUTController.js";
|
|
5
|
+
import {
|
|
6
|
+
ParticleParameters
|
|
7
|
+
} from "../../../../../src/engine/graphics/particles/particular/engine/emitter/ParticleParameters.js";
|
|
8
|
+
import ObservedString from "../../../../../src/core/model/ObservedString.js";
|
|
9
|
+
|
|
10
|
+
export class ParameterTrackController extends GuiControl {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
|
|
14
|
+
const self = this;
|
|
15
|
+
|
|
16
|
+
const trackName = new ObservedString("");
|
|
17
|
+
|
|
18
|
+
const lName = new LabelView(trackName);
|
|
19
|
+
|
|
20
|
+
let cLUT = null;
|
|
21
|
+
|
|
22
|
+
this.addChild(lName);
|
|
23
|
+
|
|
24
|
+
this.model.onChanged.add(function (track) {
|
|
25
|
+
if (cLUT !== null) {
|
|
26
|
+
self.removeChild(cLUT);
|
|
27
|
+
cLUT = null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (track === null) {
|
|
31
|
+
trackName.set("");
|
|
32
|
+
} else {
|
|
33
|
+
const name = track.name;
|
|
34
|
+
|
|
35
|
+
trackName.set(name);
|
|
36
|
+
|
|
37
|
+
if (name === ParticleParameters.Color) {
|
|
38
|
+
cLUT = new ColorParameterLUTController();
|
|
39
|
+
} else if (name === ParticleParameters.Scale) {
|
|
40
|
+
cLUT = new ScalarParameterLUTController();
|
|
41
|
+
} else {
|
|
42
|
+
throw new Error(`Unsupported type '${type}'`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
cLUT.model.set(track.track);
|
|
46
|
+
|
|
47
|
+
self.addChild(cLUT);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
import DatGuiController from "../DatGuiController.js";
|
|
2
|
+
import { BlendingType } from "../../../../../src/engine/graphics/texture/sampler/BlendingType.js";
|
|
3
|
+
import { ParticleLayer } from "../../../../../src/engine/graphics/particles/particular/engine/emitter/ParticleLayer.js";
|
|
4
|
+
import ParticleLayerController from "./ParticleLayerController.js";
|
|
5
|
+
import {
|
|
6
|
+
ParticleEmitterFlag
|
|
7
|
+
} from "../../../../../src/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js";
|
|
8
|
+
import { NativeListController } from "../../../../../src/view/controller/controls/NativeListController.js";
|
|
9
|
+
import EmptyView from "../../../../../src/view/elements/EmptyView.js";
|
|
10
|
+
import ObservedValue from "../../../../../src/core/model/ObservedValue.js";
|
|
11
|
+
import { noop } from "../../../../../src/core/function/Functions.js";
|
|
12
|
+
import {
|
|
13
|
+
SimulationStepType
|
|
14
|
+
} from "../../../../../src/engine/graphics/particles/particular/engine/simulator/SimulationStepType.js";
|
|
15
|
+
import {
|
|
16
|
+
SimulationStepDefinition
|
|
17
|
+
} from "../../../../../src/engine/graphics/particles/particular/engine/simulator/SimulationStepDefinition.js";
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {*} value
|
|
23
|
+
* @param {Object} enumerable
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/
|
|
26
|
+
export function enumNameByValue(value, enumerable) {
|
|
27
|
+
return Object.keys(enumerable)[Object.values(enumerable).indexOf(value)];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {ParticleEmitter} emitter
|
|
33
|
+
* @param {ParticleEmitterSystem} system
|
|
34
|
+
* @param {function} op
|
|
35
|
+
* @param {*} [arg0]
|
|
36
|
+
*/
|
|
37
|
+
function applyEmitterChanges(emitter, system, op, arg0) {
|
|
38
|
+
const particleEngine = system.particleEngine;
|
|
39
|
+
|
|
40
|
+
const isSleeping = emitter.getFlag(ParticleEmitterFlag.Sleeping);
|
|
41
|
+
|
|
42
|
+
//re-add the emitter
|
|
43
|
+
particleEngine.remove(emitter);
|
|
44
|
+
|
|
45
|
+
if (system.renderLayer.visibleSet.contains(emitter.mesh)) {
|
|
46
|
+
//remove from visible layer if present
|
|
47
|
+
system.renderLayer.visibleSet.forceRemove(emitter.mesh);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
//execute operation
|
|
51
|
+
op(emitter, arg0);
|
|
52
|
+
|
|
53
|
+
//clear flags
|
|
54
|
+
emitter.clearFlag(ParticleEmitterFlag.Built | ParticleEmitterFlag.Initialized);
|
|
55
|
+
|
|
56
|
+
//update internal state
|
|
57
|
+
emitter.registerLayerParameters();
|
|
58
|
+
emitter.build();
|
|
59
|
+
emitter.initialize();
|
|
60
|
+
emitter.computeBoundingBox();
|
|
61
|
+
|
|
62
|
+
particleEngine.add(emitter);
|
|
63
|
+
|
|
64
|
+
emitter.writeFlag(ParticleEmitterFlag.Sleeping, isSleeping);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export class ParticleEmitterController extends EmptyView {
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* @param {ParticleEmitterSystem} particleEmitterSystem
|
|
71
|
+
* @constructor
|
|
72
|
+
*/
|
|
73
|
+
constructor(particleEmitterSystem) {
|
|
74
|
+
super();
|
|
75
|
+
|
|
76
|
+
this.model = new ObservedValue(null);
|
|
77
|
+
|
|
78
|
+
const self = this;
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
function applyChanges() {
|
|
82
|
+
const emitter = self.model.getValue();
|
|
83
|
+
|
|
84
|
+
if (emitter !== null) {
|
|
85
|
+
applyEmitterChanges(emitter, particleEmitterSystem, noop);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {function(ParticleEmitter)} op
|
|
92
|
+
* @param {v} [v]
|
|
93
|
+
*/
|
|
94
|
+
function makeChange(op, v) {
|
|
95
|
+
const emitter = self.model.getValue();
|
|
96
|
+
|
|
97
|
+
if (emitter !== null) {
|
|
98
|
+
applyEmitterChanges(emitter, particleEmitterSystem, op, v);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
*
|
|
104
|
+
* @param {function(ParticleEmitter)} op
|
|
105
|
+
* @returns {function(...[*]=)}
|
|
106
|
+
*/
|
|
107
|
+
function mutator(op) {
|
|
108
|
+
return function (arg0) {
|
|
109
|
+
makeChange(op, arg0);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
*
|
|
116
|
+
* @param {ParticleEmitter} emitter
|
|
117
|
+
* @param oldEmitter
|
|
118
|
+
*/
|
|
119
|
+
function modelSet(emitter, oldEmitter) {
|
|
120
|
+
|
|
121
|
+
self.removeAllChildren();
|
|
122
|
+
|
|
123
|
+
if (emitter !== null) {
|
|
124
|
+
|
|
125
|
+
const emitterSurrogate = {
|
|
126
|
+
preWarm: emitter.getFlag(ParticleEmitterFlag.PreWarm),
|
|
127
|
+
depthRead: !emitter.getFlag(ParticleEmitterFlag.DepthReadDisabled),
|
|
128
|
+
depthSoft: !emitter.getFlag(ParticleEmitterFlag.DepthSoftDisabled),
|
|
129
|
+
velocityAlign: emitter.getFlag(ParticleEmitterFlag.AlignOnVelocity),
|
|
130
|
+
blendingMode: enumNameByValue(emitter.blendingMode, BlendingType),
|
|
131
|
+
update: function () {
|
|
132
|
+
applyChanges();
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
const dat = new DatGuiController();
|
|
138
|
+
|
|
139
|
+
self.addChild(dat);
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
dat.addControl(emitterSurrogate, 'preWarm').onChange(mutator((emitter, value) => {
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @type {ParticleEmitter}
|
|
146
|
+
*/
|
|
147
|
+
emitter.writeFlag(ParticleEmitterFlag.PreWarm, value);
|
|
148
|
+
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
dat.addControl(emitterSurrogate, 'depthRead').onChange(mutator((emitter, value) => {
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @type {ParticleEmitter}
|
|
155
|
+
*/
|
|
156
|
+
emitter.writeFlag(ParticleEmitterFlag.DepthReadDisabled, !value);
|
|
157
|
+
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
dat.addControl(emitterSurrogate, 'depthSoft').onChange(mutator((emitter, value) => {
|
|
161
|
+
/**
|
|
162
|
+
* @type {ParticleEmitter}
|
|
163
|
+
*/
|
|
164
|
+
emitter.writeFlag(ParticleEmitterFlag.DepthSoftDisabled, !value);
|
|
165
|
+
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
dat.addControl(emitterSurrogate, 'velocityAlign').onChange(mutator((emitter, value) => {
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @type {ParticleEmitter}
|
|
172
|
+
*/
|
|
173
|
+
emitter.writeFlag(ParticleEmitterFlag.AlignOnVelocity, value);
|
|
174
|
+
|
|
175
|
+
}));
|
|
176
|
+
|
|
177
|
+
dat.addControl(emitterSurrogate, 'blendingMode', Object.keys(BlendingType)).onChange(mutator((emitter, blendModeName) => {
|
|
178
|
+
|
|
179
|
+
emitter.blendingMode = BlendingType[blendModeName];
|
|
180
|
+
|
|
181
|
+
}));
|
|
182
|
+
|
|
183
|
+
dat.addControl(emitterSurrogate, 'update').name('Apply Changes');
|
|
184
|
+
|
|
185
|
+
self.addChild(new NativeListController({
|
|
186
|
+
model: emitter.layers,
|
|
187
|
+
elementViewFactory(layer) {
|
|
188
|
+
const c = new ParticleLayerController(makeChange);
|
|
189
|
+
|
|
190
|
+
c.model.set(layer);
|
|
191
|
+
|
|
192
|
+
return c;
|
|
193
|
+
},
|
|
194
|
+
elementFactory() {
|
|
195
|
+
const r = new ParticleLayer();
|
|
196
|
+
|
|
197
|
+
r.steps.add(SimulationStepDefinition.from(SimulationStepType.FixedPhysics, []))
|
|
198
|
+
|
|
199
|
+
return r;
|
|
200
|
+
},
|
|
201
|
+
operationAdd(list, layer) {
|
|
202
|
+
makeChange(emitter => {
|
|
203
|
+
emitter.addLayer(layer);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
}))
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
this.model.onChanged.add(modelSet);
|
|
212
|
+
}
|
|
213
|
+
}
|