@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.
- 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
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { TransformControls } from "../../src/engine/graphics/three/TransfromControls.js";
|
|
2
|
+
import { Camera } from "../../src/engine/graphics/ecs/camera/Camera.js";
|
|
3
|
+
|
|
4
|
+
import { Group, Object3D } from 'three';
|
|
5
|
+
import { SignalBinding } from "../../src/core/events/signal/SignalBinding.js";
|
|
6
|
+
import { Transform } from "../../src/engine/ecs/transform/Transform.js";
|
|
7
|
+
import Tool from "./engine/Tool.js";
|
|
8
|
+
import { KeyCodes } from "../../src/engine/input/devices/KeyCodes.js";
|
|
9
|
+
import TransformModifyAction from "../actions/concrete/TransformModifyAction.js";
|
|
10
|
+
import { assert } from "../../src/core/assert.js";
|
|
11
|
+
import { threeUpdateTransform } from "../../src/engine/graphics/util/threeUpdateTransform.js";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
function TransformContainer(entity) {
|
|
15
|
+
this.entity = entity;
|
|
16
|
+
|
|
17
|
+
//create a surrogate object
|
|
18
|
+
this.surrogate = new Object3D();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {Editor} editor
|
|
24
|
+
* @param {Transform} transform
|
|
25
|
+
*/
|
|
26
|
+
TransformContainer.prototype.link = function (editor, transform) {
|
|
27
|
+
const engine = editor.engine;
|
|
28
|
+
|
|
29
|
+
let allowWriteToModel = true;
|
|
30
|
+
let allowWriteToSurrogate = true;
|
|
31
|
+
|
|
32
|
+
const activeCamera = editor.cameraEntity.getComponent(Camera);
|
|
33
|
+
|
|
34
|
+
this.controls = new TransformControls(activeCamera.object, engine.gameView.el);
|
|
35
|
+
|
|
36
|
+
//make controls smaller, this was requested by Joao originally, to match other editors where gizmos are not as large
|
|
37
|
+
this.controls.size = 0.7;
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const surrogate = this.surrogate;
|
|
41
|
+
|
|
42
|
+
function patchThreeVector3(vector, target) {
|
|
43
|
+
let x = vector.x;
|
|
44
|
+
let y = vector.y;
|
|
45
|
+
let z = vector.z;
|
|
46
|
+
Object.defineProperties(vector, {
|
|
47
|
+
x: {
|
|
48
|
+
get() {
|
|
49
|
+
return x;
|
|
50
|
+
},
|
|
51
|
+
set(v) {
|
|
52
|
+
x = v;
|
|
53
|
+
|
|
54
|
+
if (allowWriteToModel) {
|
|
55
|
+
allowWriteToSurrogate = false;
|
|
56
|
+
target.setX(v);
|
|
57
|
+
allowWriteToSurrogate = true;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
y: {
|
|
62
|
+
get() {
|
|
63
|
+
return y;
|
|
64
|
+
},
|
|
65
|
+
set(v) {
|
|
66
|
+
y = v;
|
|
67
|
+
|
|
68
|
+
if (allowWriteToModel) {
|
|
69
|
+
allowWriteToSurrogate = false;
|
|
70
|
+
target.setY(v);
|
|
71
|
+
allowWriteToSurrogate = true;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
z: {
|
|
76
|
+
get() {
|
|
77
|
+
return z;
|
|
78
|
+
},
|
|
79
|
+
set(v) {
|
|
80
|
+
z = v;
|
|
81
|
+
|
|
82
|
+
if (allowWriteToModel) {
|
|
83
|
+
allowWriteToSurrogate = false;
|
|
84
|
+
target.setZ(v);
|
|
85
|
+
allowWriteToSurrogate = true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
patchThreeVector3(surrogate.position, transform.position);
|
|
93
|
+
|
|
94
|
+
patchThreeVector3(surrogate.scale, transform.scale);
|
|
95
|
+
|
|
96
|
+
assert.typeOf(surrogate.rotation._onChange, 'function', 'rotation._onChange');
|
|
97
|
+
|
|
98
|
+
surrogate.rotation._onChange(function () {
|
|
99
|
+
if (!allowWriteToModel) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
allowWriteToSurrogate = false;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
transform.rotation.__setFromEuler(surrogate.rotation.x, surrogate.rotation.y, surrogate.rotation.z, 'XYZ');
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error(e);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
allowWriteToSurrogate = true;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
assert.typeOf(surrogate.quaternion._onChange, 'function', 'quaternion._onChange');
|
|
115
|
+
|
|
116
|
+
surrogate.quaternion._onChange(function () {
|
|
117
|
+
if (!allowWriteToModel) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
allowWriteToSurrogate = false;
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
transform.rotation.copy(surrogate.quaternion);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
console.error(e);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
allowWriteToSurrogate = true;
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
//set surrogate transform to match component
|
|
133
|
+
surrogate.position.copy(transform.position);
|
|
134
|
+
transform.rotation.__setThreeEuler(surrogate.rotation);
|
|
135
|
+
surrogate.quaternion.copy(transform.rotation);
|
|
136
|
+
surrogate.scale.copy(transform.scale);
|
|
137
|
+
|
|
138
|
+
this.bindings = [
|
|
139
|
+
new SignalBinding(transform.position.onChanged, function (x, y, z) {
|
|
140
|
+
allowWriteToModel = false;
|
|
141
|
+
|
|
142
|
+
if (allowWriteToSurrogate) {
|
|
143
|
+
surrogate.position.set(x, y, z);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
allowWriteToModel = true;
|
|
147
|
+
}),
|
|
148
|
+
new SignalBinding(transform.scale.onChanged, function (x, y, z) {
|
|
149
|
+
allowWriteToModel = false;
|
|
150
|
+
|
|
151
|
+
if (allowWriteToSurrogate) {
|
|
152
|
+
surrogate.scale.set(x, y, z);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
allowWriteToModel = true;
|
|
156
|
+
}),
|
|
157
|
+
new SignalBinding(transform.rotation.onChanged, function () {
|
|
158
|
+
allowWriteToModel = false;
|
|
159
|
+
|
|
160
|
+
if (allowWriteToSurrogate) {
|
|
161
|
+
const rotation = transform.rotation;
|
|
162
|
+
rotation.__setThreeEuler(surrogate.rotation);
|
|
163
|
+
surrogate.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
allowWriteToModel = true;
|
|
167
|
+
}),
|
|
168
|
+
];
|
|
169
|
+
|
|
170
|
+
this.bindings.forEach(function (b) {
|
|
171
|
+
b.link();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
this.controls.attach(surrogate);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
TransformContainer.prototype.unlink = function () {
|
|
178
|
+
this.bindings.forEach(function (b) {
|
|
179
|
+
b.unlink();
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
this.controls.detach();
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
*
|
|
187
|
+
* @enum {string}
|
|
188
|
+
*/
|
|
189
|
+
export const TransformerMode = {
|
|
190
|
+
Scale: 'scale',
|
|
191
|
+
Translation: 'translate',
|
|
192
|
+
Rotation: 'rotate'
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export class TransformTool extends Tool {
|
|
196
|
+
/**
|
|
197
|
+
*
|
|
198
|
+
* @constructor
|
|
199
|
+
*/
|
|
200
|
+
constructor() {
|
|
201
|
+
super();
|
|
202
|
+
this.name = "spatial_transform";
|
|
203
|
+
|
|
204
|
+
this.mode.set(TransformerMode.Translation);
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
*
|
|
208
|
+
* @type {TransformContainer[]}
|
|
209
|
+
*/
|
|
210
|
+
this.surrogates = [];
|
|
211
|
+
this.actions = [];
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
*
|
|
215
|
+
* @type {Group}
|
|
216
|
+
*/
|
|
217
|
+
this.editObject = new Group();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
initialize() {
|
|
221
|
+
super.initialize();
|
|
222
|
+
|
|
223
|
+
const editor = this.editor;
|
|
224
|
+
|
|
225
|
+
const self = this;
|
|
226
|
+
|
|
227
|
+
this.mode.onChanged.add(function (mode) {
|
|
228
|
+
self.surrogates.forEach(function (s) {
|
|
229
|
+
s.controls.setMode(mode);
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
*
|
|
235
|
+
* @returns {EntityManager}
|
|
236
|
+
*/
|
|
237
|
+
function getEM() {
|
|
238
|
+
return self.editor.engine.entityManager;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function handleSelectionAdded(entity) {
|
|
242
|
+
const em = getEM();
|
|
243
|
+
|
|
244
|
+
const t = em.getComponent(entity, Transform);
|
|
245
|
+
|
|
246
|
+
if (t === null) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
//create a surrogate object
|
|
251
|
+
const surrogate = new TransformContainer(entity);
|
|
252
|
+
|
|
253
|
+
surrogate.link(self.editor, t);
|
|
254
|
+
surrogate.controls.setMode(self.mode.getValue());
|
|
255
|
+
|
|
256
|
+
self.editObject.add(surrogate.controls);
|
|
257
|
+
self.editObject.add(surrogate.surrogate);
|
|
258
|
+
|
|
259
|
+
self.surrogates[entity] = surrogate;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function handleSelectionRemoved(entity) {
|
|
263
|
+
const surrogate = self.surrogates[entity];
|
|
264
|
+
|
|
265
|
+
if (surrogate === undefined) {
|
|
266
|
+
//no surrogate
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
self.editObject.remove(surrogate.controls);
|
|
271
|
+
self.editObject.remove(surrogate.surrogate);
|
|
272
|
+
|
|
273
|
+
surrogate.unlink();
|
|
274
|
+
//cleanup
|
|
275
|
+
surrogate.controls.dispose();
|
|
276
|
+
|
|
277
|
+
delete self.surrogates[entity];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
this.bindings = [
|
|
281
|
+
new SignalBinding(editor.selection.on.added, handleSelectionAdded),
|
|
282
|
+
new SignalBinding(editor.selection.on.removed, handleSelectionRemoved)
|
|
283
|
+
];
|
|
284
|
+
|
|
285
|
+
this.handlers = {
|
|
286
|
+
handleSelectionAdded,
|
|
287
|
+
handleSelectionRemoved
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
this.surrogates = [];
|
|
292
|
+
|
|
293
|
+
this.editor.selection.forEach(this.handlers.handleSelectionAdded);
|
|
294
|
+
|
|
295
|
+
this.bindings.forEach(function (b) {
|
|
296
|
+
b.link();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
this.editor.engine.graphics.scene.add(this.editObject);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
shutdown() {
|
|
303
|
+
this.editor.selection.forEach(this.handlers.handleSelectionRemoved);
|
|
304
|
+
this.bindings.forEach(function (b) {
|
|
305
|
+
b.unlink();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
this.editor.engine.graphics.scene.remove(this.editObject);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
update() {
|
|
312
|
+
this.surrogates.forEach(s => {
|
|
313
|
+
threeUpdateTransform(s.controls);
|
|
314
|
+
threeUpdateTransform(s.surrogate);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
start() {
|
|
319
|
+
|
|
320
|
+
const self = this;
|
|
321
|
+
this.actions = this.surrogates.map(function (s) {
|
|
322
|
+
const entity = s.entity;
|
|
323
|
+
|
|
324
|
+
const t = self.engine.entityManager.getComponent(entity, Transform);
|
|
325
|
+
|
|
326
|
+
const action = new TransformModifyAction(entity, null);
|
|
327
|
+
|
|
328
|
+
action.oldState = t.clone();
|
|
329
|
+
|
|
330
|
+
return action;
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
stop() {
|
|
336
|
+
const self = this;
|
|
337
|
+
this.actions.forEach(function (action) {
|
|
338
|
+
const entity = action.entity;
|
|
339
|
+
|
|
340
|
+
const t = self.engine.entityManager.getComponent(entity, Transform);
|
|
341
|
+
|
|
342
|
+
if (!t.equals(action.oldState)) {
|
|
343
|
+
action.modified = t.clone();
|
|
344
|
+
|
|
345
|
+
//restore state before transform. This is a hack, but a functional one
|
|
346
|
+
t.copy(action.oldState);
|
|
347
|
+
|
|
348
|
+
const actionProcessor = self.editor.actions;
|
|
349
|
+
actionProcessor.mark('transform modification');
|
|
350
|
+
actionProcessor.do(action);
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @param {KeyboardEvent} event
|
|
358
|
+
*/
|
|
359
|
+
handleKeyboardEvent(event) {
|
|
360
|
+
const keyCode = event.keyCode;
|
|
361
|
+
|
|
362
|
+
if (keyCode === KeyCodes.w) {
|
|
363
|
+
this.mode.set(TransformerMode.Translation);
|
|
364
|
+
} else if (keyCode === KeyCodes.e) {
|
|
365
|
+
this.mode.set(TransformerMode.Rotation);
|
|
366
|
+
} else if (keyCode === KeyCodes.r) {
|
|
367
|
+
this.mode.set(TransformerMode.Scale);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 14/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import ObservedValue from '../../../src/core/model/ObservedValue.js';
|
|
7
|
+
import { buildToolStateMachine } from "./ToolStateMachine.js";
|
|
8
|
+
import { ToolState } from "./ToolState.js";
|
|
9
|
+
import ObservedString from "../../../src/core/model/ObservedString.js";
|
|
10
|
+
|
|
11
|
+
class Tool {
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @constructor
|
|
15
|
+
* @property {ObservedValue.<String>} mode
|
|
16
|
+
*/
|
|
17
|
+
constructor() {
|
|
18
|
+
this.name = null;
|
|
19
|
+
this.mode = new ObservedValue();
|
|
20
|
+
this.settings = {};
|
|
21
|
+
this.modifiers = {
|
|
22
|
+
shift: false,
|
|
23
|
+
alternative: false
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @type {Engine|null}
|
|
28
|
+
*/
|
|
29
|
+
this.engine = null;
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @type {Editor|null}
|
|
33
|
+
*/
|
|
34
|
+
this.editor = null;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* @type {ObservedString}
|
|
39
|
+
*/
|
|
40
|
+
this.icon = new ObservedString("");
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @type {StateMachine}
|
|
45
|
+
*/
|
|
46
|
+
this.stateMachine = buildToolStateMachine(this);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param {Editor} editor
|
|
52
|
+
*/
|
|
53
|
+
updateIcon(editor) {
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
*
|
|
59
|
+
* @returns {ToolState|number}
|
|
60
|
+
*/
|
|
61
|
+
getState() {
|
|
62
|
+
return this.stateMachine.getState();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
isRunning() {
|
|
66
|
+
return this.getState() === ToolState.Running;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
*
|
|
71
|
+
* @param {ToolState} s
|
|
72
|
+
* @returns {Promise}
|
|
73
|
+
*/
|
|
74
|
+
moveToState(s) {
|
|
75
|
+
const sm = this.stateMachine;
|
|
76
|
+
|
|
77
|
+
return sm.navigateTo(s);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Activate the tool and prepare it for usage
|
|
82
|
+
*/
|
|
83
|
+
initialize() {
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Deactivate the tool and remove and influence it may have
|
|
88
|
+
*/
|
|
89
|
+
shutdown() {
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Update loop
|
|
95
|
+
*/
|
|
96
|
+
update() {
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Start usage of the tool.
|
|
102
|
+
* @example Start painting with a brush
|
|
103
|
+
*/
|
|
104
|
+
start() {
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Finish usage of the tool
|
|
109
|
+
* @example Finish brush stroke
|
|
110
|
+
*/
|
|
111
|
+
stop() {
|
|
112
|
+
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
handleKeyboardEvent(e) {
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
export default Tool;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 14/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import List from '../../../src/core/collection/list/List.js';
|
|
7
|
+
import ObservedValue from '../../../src/core/model/ObservedValue.js';
|
|
8
|
+
import { decodeMouseEventButtons, PointerDevice } from '../../../src/engine/input/devices/PointerDevice.js';
|
|
9
|
+
|
|
10
|
+
import SelectionTool from '../SelectionTool.js';
|
|
11
|
+
import TopDownCameraControlTool from '../TopDownCameraControlTool.js';
|
|
12
|
+
import GridPaintTool from "../GridPaintTool.js";
|
|
13
|
+
import FoliagePaintTool from "../FoliagePaintTool.js";
|
|
14
|
+
import { TransformTool } from "../TransformTool.js";
|
|
15
|
+
import { ToolState } from "./ToolState.js";
|
|
16
|
+
import Clock from "../../../src/engine/Clock.js";
|
|
17
|
+
import { TerrainHeightPaintTool } from "../paint/TerrainHeightPaintTool.js";
|
|
18
|
+
import { TerrainTexturePaintTool } from "../paint/TerrainTexturePaintTool.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @constructor
|
|
23
|
+
* @property {List.<Tool>} tools
|
|
24
|
+
* @property {ObservedValue.<Tool>} active
|
|
25
|
+
*/
|
|
26
|
+
function ToolEngine() {
|
|
27
|
+
this.tools = new List();
|
|
28
|
+
this.active = new ObservedValue(null);
|
|
29
|
+
this.engine = null;
|
|
30
|
+
this.isRunning = false;
|
|
31
|
+
this.shutdownCallbacks = [];
|
|
32
|
+
this.pointer = null;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
ToolEngine.prototype.activate = function (toolName) {
|
|
36
|
+
const self = this;
|
|
37
|
+
this.tools.visitFirstMatch(function (tool) {
|
|
38
|
+
return tool.name === toolName;
|
|
39
|
+
}, function (tool) {
|
|
40
|
+
self.active.set(tool);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
ToolEngine.prototype.initialize = function () {
|
|
45
|
+
|
|
46
|
+
this.active.onChanged.add((newTool, oldTool) => {
|
|
47
|
+
console.log("active tool changed. Old: ", oldTool, ", New :", newTool);
|
|
48
|
+
|
|
49
|
+
if (oldTool !== null && typeof oldTool === "object") {
|
|
50
|
+
oldTool.moveToState(ToolState.Initial);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (newTool !== null && typeof newTool === "object") {
|
|
54
|
+
newTool.editor = this.editor;
|
|
55
|
+
newTool.engine = this.engine;
|
|
56
|
+
|
|
57
|
+
newTool.moveToState(ToolState.Ready);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const terrainPaintToolRaise = new TerrainHeightPaintTool();
|
|
62
|
+
terrainPaintToolRaise.name = "terrain-height";
|
|
63
|
+
|
|
64
|
+
const terrainTexturePaintTool0 = new TerrainTexturePaintTool();
|
|
65
|
+
terrainTexturePaintTool0.name = `terrain-texture-0`;
|
|
66
|
+
terrainTexturePaintTool0.settings.splatIndex = 0;
|
|
67
|
+
|
|
68
|
+
const terrainTexturePaintTool1 = new TerrainTexturePaintTool();
|
|
69
|
+
terrainTexturePaintTool1.name = `terrain-texture-1`;
|
|
70
|
+
terrainTexturePaintTool1.settings.splatIndex = 1;
|
|
71
|
+
|
|
72
|
+
const terrainTexturePaintTool2 = new TerrainTexturePaintTool();
|
|
73
|
+
terrainTexturePaintTool2.name = `terrain-texture-2`;
|
|
74
|
+
terrainTexturePaintTool2.settings.splatIndex = 2;
|
|
75
|
+
|
|
76
|
+
const terrainTexturePaintTool3 = new TerrainTexturePaintTool();
|
|
77
|
+
terrainTexturePaintTool3.name = `terrain-texture-3`;
|
|
78
|
+
terrainTexturePaintTool3.settings.splatIndex = 3;
|
|
79
|
+
|
|
80
|
+
const tools = this.tools;
|
|
81
|
+
tools
|
|
82
|
+
.add(new SelectionTool())
|
|
83
|
+
.add(new TopDownCameraControlTool())
|
|
84
|
+
.add(new GridPaintTool())
|
|
85
|
+
.add(new TransformTool())
|
|
86
|
+
.add(terrainPaintToolRaise)
|
|
87
|
+
.add(terrainTexturePaintTool0)
|
|
88
|
+
.add(terrainTexturePaintTool1)
|
|
89
|
+
.add(terrainTexturePaintTool2)
|
|
90
|
+
.add(terrainTexturePaintTool3)
|
|
91
|
+
.add(new FoliagePaintTool());
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @param {Engine} engine
|
|
97
|
+
* @param {Editor} editor
|
|
98
|
+
*/
|
|
99
|
+
ToolEngine.prototype.startup = function (engine, editor) {
|
|
100
|
+
this.engine = engine;
|
|
101
|
+
this.editor = editor;
|
|
102
|
+
this.isRunning = true;
|
|
103
|
+
const pointer = this.pointer = new PointerDevice(engine.graphics.domElement);
|
|
104
|
+
|
|
105
|
+
const self = this;
|
|
106
|
+
|
|
107
|
+
const clock = new Clock();
|
|
108
|
+
|
|
109
|
+
clock.start();
|
|
110
|
+
|
|
111
|
+
function update() {
|
|
112
|
+
if (!self.isRunning) {
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
requestAnimationFrame(update);
|
|
116
|
+
|
|
117
|
+
const tool = self.active.get();
|
|
118
|
+
|
|
119
|
+
const delta = clock.getDelta();
|
|
120
|
+
|
|
121
|
+
if (tool !== null) {
|
|
122
|
+
tool.update(delta);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
//start update loop
|
|
127
|
+
update();
|
|
128
|
+
|
|
129
|
+
//hook up interaction controls
|
|
130
|
+
function pointerDown(position, event) {
|
|
131
|
+
const tool = self.active.get();
|
|
132
|
+
if (tool !== null) {
|
|
133
|
+
tool.modifiers.shift = event.shiftKey;
|
|
134
|
+
|
|
135
|
+
if (typeof event.buttons === "number") {
|
|
136
|
+
const decodedButtons = decodeMouseEventButtons(event.buttons);
|
|
137
|
+
|
|
138
|
+
const isPrimaryPressed = decodedButtons[0];
|
|
139
|
+
|
|
140
|
+
if (!isPrimaryPressed) {
|
|
141
|
+
//when working with mouse, only activate on primary mouse button
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
tool.moveToState(ToolState.Running);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function pointerUp(position, event) {
|
|
152
|
+
const tool = self.active.get();
|
|
153
|
+
if (tool !== null) {
|
|
154
|
+
|
|
155
|
+
tool.moveToState(ToolState.Ready);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
pointer.on.down.add(pointerDown);
|
|
161
|
+
pointer.on.up.add(pointerUp);
|
|
162
|
+
pointer.start();
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
function cleanup() {
|
|
166
|
+
pointer.on.down.remove(pointerDown);
|
|
167
|
+
pointer.on.up.remove(pointerUp);
|
|
168
|
+
pointer.stop();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
this.shutdownCallbacks.push(cleanup);
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
ToolEngine.prototype.shutdown = function () {
|
|
175
|
+
this.isRunning = false;
|
|
176
|
+
const toolProxy = this.active;
|
|
177
|
+
|
|
178
|
+
const tool = toolProxy.getValue();
|
|
179
|
+
|
|
180
|
+
if (tool !== null) {
|
|
181
|
+
toolProxy.set(null);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
//execute cleanup
|
|
185
|
+
this.shutdownCallbacks.forEach(function (cb) {
|
|
186
|
+
cb();
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
this.shutdownCallbacks = [];
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
export default ToolEngine;
|