@woosh/meep-engine 2.46.28 → 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
- package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +6 -1
- package/src/core/geom/3d/aabb/aabb3_matrix4_project.js +1 -1
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.d.ts +9 -0
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +148 -9
- package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +21 -1
- package/src/engine/graphics/render/forward_plus/LightManager.js +0 -60
- package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +1 -3
- package/src/engine/graphics/render/forward_plus/model/Decal.js +1 -1
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.d.ts +0 -3
- package/src/engine/graphics/render/forward_plus/plugin/ForwardPlusRenderingPlugin.js +0 -11
|
@@ -0,0 +1,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 14/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import Tool from './engine/Tool.js';
|
|
7
|
+
import Vector2 from '../../src/core/geom/Vector2.js';
|
|
8
|
+
import AABB2 from '../../src/core/geom/AABB2.js';
|
|
9
|
+
import { Camera } from '../../src/engine/graphics/ecs/camera/Camera.js';
|
|
10
|
+
import View from '../../src/view/View.js';
|
|
11
|
+
|
|
12
|
+
import SelectionAddAction from '../actions/concrete/SelectionAddAction.js';
|
|
13
|
+
import SelectionClearAction from '../actions/concrete/SelectionClearAction.js';
|
|
14
|
+
|
|
15
|
+
import { Frustum as ThreeFrustum, Raycaster } from 'three';
|
|
16
|
+
import Vector3 from "../../src/core/geom/Vector3.js";
|
|
17
|
+
import EditorEntity from "../ecs/EditorEntity.js";
|
|
18
|
+
import Terrain from "../../src/engine/ecs/terrain/ecs/Terrain.js";
|
|
19
|
+
import { SurfacePoint3 } from "../../src/core/geom/3d/SurfacePoint3.js";
|
|
20
|
+
import { makeScreenScissorFrustum } from "../../src/engine/graphics/camera/makeScreenScissorFrustum.js";
|
|
21
|
+
import { ShadedGeometrySystem } from "../../src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
|
|
22
|
+
|
|
23
|
+
class SelectionView extends View {
|
|
24
|
+
constructor() {
|
|
25
|
+
super();
|
|
26
|
+
this.el = document.createElement('div');
|
|
27
|
+
const style = this.el.style;
|
|
28
|
+
|
|
29
|
+
style.left = "0";
|
|
30
|
+
style.top = "0";
|
|
31
|
+
style.borderWidth = "1px";
|
|
32
|
+
style.borderStyle = "solid";
|
|
33
|
+
style.borderColor = "#02ff00";
|
|
34
|
+
style.background = "rgba(2,256,0,0.1)";
|
|
35
|
+
style.pointerEvents = "none";
|
|
36
|
+
style.zIndex = 1000;
|
|
37
|
+
style.position = "absolute";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
class SelectionTool extends Tool {
|
|
43
|
+
constructor() {
|
|
44
|
+
super();
|
|
45
|
+
this.name = "marquee_selection";
|
|
46
|
+
this.settings = {};
|
|
47
|
+
this.anchorPoint = new Vector2();
|
|
48
|
+
this.targetPoint = new Vector2();
|
|
49
|
+
this.box = new AABB2();
|
|
50
|
+
|
|
51
|
+
this.selectionMarker = new SelectionView();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
readPosition(target) {
|
|
55
|
+
const pointerPosition = this.engine.devices.pointer.position;
|
|
56
|
+
|
|
57
|
+
target.copy(pointerPosition).sub(this.engine.gameView.position);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
start() {
|
|
61
|
+
//read mouse position
|
|
62
|
+
//set anchor point
|
|
63
|
+
this.readPosition(this.anchorPoint);
|
|
64
|
+
//run update loop once
|
|
65
|
+
this.update();
|
|
66
|
+
//add view of selection
|
|
67
|
+
document.body.appendChild(this.selectionMarker.el);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
update() {
|
|
71
|
+
this.readPosition(this.targetPoint);
|
|
72
|
+
//update selection marker
|
|
73
|
+
|
|
74
|
+
const x0 = Math.min(this.targetPoint.x, this.anchorPoint.x);
|
|
75
|
+
const x1 = Math.max(this.targetPoint.x, this.anchorPoint.x);
|
|
76
|
+
const y0 = Math.min(this.targetPoint.y, this.anchorPoint.y);
|
|
77
|
+
const y1 = Math.max(this.targetPoint.y, this.anchorPoint.y);
|
|
78
|
+
|
|
79
|
+
this.box.set(x0, y0, x1, y1);
|
|
80
|
+
|
|
81
|
+
this.selectionMarker.position.set(x0, y0).add(this.engine.gameView.position);
|
|
82
|
+
this.selectionMarker.size.set(x1 - x0, y1 - y0);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
stop() {
|
|
86
|
+
const self = this;
|
|
87
|
+
//finish selection
|
|
88
|
+
|
|
89
|
+
//remove selection view
|
|
90
|
+
if (this.selectionMarker.el.parentNode === document.body) {
|
|
91
|
+
document.body.removeChild(this.selectionMarker.el);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
*
|
|
96
|
+
* @type {Engine|null}
|
|
97
|
+
*/
|
|
98
|
+
const engine = this.engine;
|
|
99
|
+
|
|
100
|
+
//convert selection box to a frustum based on camera view
|
|
101
|
+
|
|
102
|
+
let camera = null;
|
|
103
|
+
const em = engine.entityManager;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
*
|
|
107
|
+
* @param {Camera} c
|
|
108
|
+
* @returns {boolean}
|
|
109
|
+
*/
|
|
110
|
+
function visitCamera(c) {
|
|
111
|
+
if (!c.active) {
|
|
112
|
+
//skip inactive camera
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
camera = c.object;
|
|
117
|
+
//TODO check assumption that first camera is the right one
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
em.dataset.traverseComponents(Camera, visitCamera);
|
|
122
|
+
|
|
123
|
+
if (camera === null) {
|
|
124
|
+
console.error("Couldn't find a camera to project selection box from");
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
let selection;
|
|
128
|
+
|
|
129
|
+
const editor = this.editor;
|
|
130
|
+
|
|
131
|
+
const box = this.box;
|
|
132
|
+
//if box size is 0, it leads to all planes being converged on one point, to correct this we need to ensure that box dimensions are greater than zero
|
|
133
|
+
const dX = Math.abs(box.x0 - box.x1);
|
|
134
|
+
const dY = Math.abs(box.y0 - box.y1);
|
|
135
|
+
|
|
136
|
+
if (dX < SELECTION_MIN_SIZE && dY < SELECTION_MIN_SIZE) {
|
|
137
|
+
|
|
138
|
+
selection = pickingEntitySelection(new Vector2(box.x0, box.y0), editor.engine, camera);
|
|
139
|
+
|
|
140
|
+
} else {
|
|
141
|
+
|
|
142
|
+
if (dX < SELECTION_MIN_SIZE) {
|
|
143
|
+
box.x0 -= (SELECTION_MIN_SIZE - dX) / 2;
|
|
144
|
+
box.x1 += (SELECTION_MIN_SIZE - dX) / 2;
|
|
145
|
+
}
|
|
146
|
+
if (dY < SELECTION_MIN_SIZE) {
|
|
147
|
+
box.y0 -= (SELECTION_MIN_SIZE - dY) / 2;
|
|
148
|
+
box.y1 += (SELECTION_MIN_SIZE - dY) / 2;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
selection = marqueeSelection(box, editor, camera);
|
|
153
|
+
}
|
|
154
|
+
console.log("Selected entities", selection);
|
|
155
|
+
|
|
156
|
+
const actions = editor.actions;
|
|
157
|
+
|
|
158
|
+
actions.mark();
|
|
159
|
+
if (!self.modifiers.shift) {
|
|
160
|
+
actions.do(new SelectionClearAction());
|
|
161
|
+
}
|
|
162
|
+
actions.do(new SelectionAddAction(selection));
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
const SELECTION_MIN_SIZE = 0.01;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
*
|
|
172
|
+
* @param {int} entity
|
|
173
|
+
* @param {EntityComponentDataset} dataset
|
|
174
|
+
* @returns {int}
|
|
175
|
+
*/
|
|
176
|
+
function dereferenceEntity(entity, dataset) {
|
|
177
|
+
if (dataset.componentTypeMap.indexOf(EditorEntity) === -1) {
|
|
178
|
+
//EditorEntity is not registered
|
|
179
|
+
return entity;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const editorEntity = dataset.getComponent(entity, EditorEntity);
|
|
183
|
+
|
|
184
|
+
if (editorEntity === undefined) {
|
|
185
|
+
return entity;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (editorEntity.referenceEntity !== -1) {
|
|
189
|
+
//reference found, deference
|
|
190
|
+
return editorEntity.referenceEntity;
|
|
191
|
+
} else {
|
|
192
|
+
//no reference, just ignore this one
|
|
193
|
+
return -1;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
*
|
|
199
|
+
* @param {LeafNode|BinaryNode} node
|
|
200
|
+
* @returns {number|undefined}
|
|
201
|
+
*/
|
|
202
|
+
function findEntityOfNode(node) {
|
|
203
|
+
const entity = node.entity;
|
|
204
|
+
if (typeof entity === "number") {
|
|
205
|
+
return entity;
|
|
206
|
+
} else {
|
|
207
|
+
const parentNode = node.parentNode;
|
|
208
|
+
if (parentNode !== null) {
|
|
209
|
+
return findEntityOfNode(parentNode);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
*
|
|
217
|
+
* @param {Vector2} point
|
|
218
|
+
* @param {Engine} engine
|
|
219
|
+
* @param {THREE.Camera} camera
|
|
220
|
+
* @returns {number[]} entities
|
|
221
|
+
*/
|
|
222
|
+
export function pickingEntitySelection(point, engine, camera) {
|
|
223
|
+
|
|
224
|
+
const em = engine.entityManager;
|
|
225
|
+
const dataset = em.dataset;
|
|
226
|
+
|
|
227
|
+
const graphicsEngine = engine.graphics;
|
|
228
|
+
|
|
229
|
+
const source = new Vector3(0, 0, 0);
|
|
230
|
+
const rayDirection = new Vector3(0, 0, 0);
|
|
231
|
+
|
|
232
|
+
const normalizedPoint = new Vector2(0, 0);
|
|
233
|
+
|
|
234
|
+
graphicsEngine.normalizeViewportPoint(point, normalizedPoint);
|
|
235
|
+
|
|
236
|
+
graphicsEngine.viewportProjectionRay(normalizedPoint.x, normalizedPoint.y, source, rayDirection);
|
|
237
|
+
|
|
238
|
+
// push source by a small amount along the way to prevent selection of elements directly on the NEAR plane
|
|
239
|
+
source.add(rayDirection.clone().multiplyScalar(0.0001));
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
let bestCandidate = null;
|
|
243
|
+
let bestDistance = Infinity;
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
*
|
|
248
|
+
* @param {number} entity
|
|
249
|
+
* @param {Vector3} contact
|
|
250
|
+
*/
|
|
251
|
+
function tryAddEntity(entity, contact) {
|
|
252
|
+
const distance = source.distanceSqrTo(contact);
|
|
253
|
+
|
|
254
|
+
if (distance < bestDistance) {
|
|
255
|
+
bestDistance = distance;
|
|
256
|
+
|
|
257
|
+
entity = dereferenceEntity(entity, dataset);
|
|
258
|
+
|
|
259
|
+
if (entity === -1) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
bestCandidate = entity;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
*
|
|
269
|
+
* @type {ShadedGeometrySystem|undefined}
|
|
270
|
+
*/
|
|
271
|
+
const sgm = em.getSystem(ShadedGeometrySystem);
|
|
272
|
+
|
|
273
|
+
if (sgm !== undefined && sgm !== null) {
|
|
274
|
+
const hits = sgm.raycast(
|
|
275
|
+
source.x, source.y, source.y,
|
|
276
|
+
rayDirection.x, rayDirection.y, rayDirection.z
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
for (let i = 0; i < hits.length; i++) {
|
|
280
|
+
const hit = hits[i];
|
|
281
|
+
|
|
282
|
+
tryAddEntity(hit.entity, hit.contact.position);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
//query render layers
|
|
287
|
+
engine.graphics.layers.traverse(function (layer) {
|
|
288
|
+
/**
|
|
289
|
+
*
|
|
290
|
+
* @type {BinaryNode}
|
|
291
|
+
*/
|
|
292
|
+
const bvh = layer.bvh;
|
|
293
|
+
|
|
294
|
+
bvh.traverseRayLeafIntersections(source.x, source.y, source.z, rayDirection.x, rayDirection.y, rayDirection.z, function (leaf) {
|
|
295
|
+
const entity = findEntityOfNode(leaf);
|
|
296
|
+
|
|
297
|
+
if (typeof entity !== "number") {
|
|
298
|
+
//no entity
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const object = leaf.object;
|
|
303
|
+
if (
|
|
304
|
+
leaf.hasOwnProperty("object")
|
|
305
|
+
&& typeof object === "object"
|
|
306
|
+
&& object !== null
|
|
307
|
+
&& object.isObject3D
|
|
308
|
+
&& typeof object.raycast === "function"
|
|
309
|
+
) {
|
|
310
|
+
//found a "raycast" function on the value object held by the leaf, assuming this is THREE.js raycast function
|
|
311
|
+
const raycaster = new Raycaster(source, rayDirection, 0, Infinity);
|
|
312
|
+
|
|
313
|
+
// WORKAROUND FOR https://github.com/mrdoob/three.js/issues/17078
|
|
314
|
+
raycaster.camera = camera;
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
object.traverse(node => {
|
|
318
|
+
const intersection = [];
|
|
319
|
+
node.raycast(raycaster, intersection);
|
|
320
|
+
|
|
321
|
+
intersection.forEach(function (contact) {
|
|
322
|
+
tryAddEntity(entity, contact.point);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
} else {
|
|
327
|
+
/**
|
|
328
|
+
*
|
|
329
|
+
* @type {Terrain}
|
|
330
|
+
*/
|
|
331
|
+
const terrain = dataset.getComponent(entity, Terrain);
|
|
332
|
+
|
|
333
|
+
if (terrain !== undefined) {
|
|
334
|
+
const sp = new SurfacePoint3();
|
|
335
|
+
|
|
336
|
+
terrain.raycastFirstSync(sp, source.x, source.y, source.z, rayDirection.x, rayDirection.y, rayDirection.z);
|
|
337
|
+
|
|
338
|
+
tryAddEntity(entity, sp.position);
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const center = new Vector3(0, 0, 0);
|
|
343
|
+
|
|
344
|
+
leaf.getCenter(center);
|
|
345
|
+
|
|
346
|
+
tryAddEntity(entity, center);
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
return bestCandidate !== null ? [bestCandidate] : [];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
*
|
|
357
|
+
* @param {AABB2} box in screen-space, in pixels
|
|
358
|
+
* @param {Editor} editor
|
|
359
|
+
* @param {THREE.Camera} camera
|
|
360
|
+
*/
|
|
361
|
+
function marqueeSelection(box, editor, camera) {
|
|
362
|
+
const engine = editor.engine;
|
|
363
|
+
|
|
364
|
+
const dataset = engine.entityManager.dataset;
|
|
365
|
+
|
|
366
|
+
const normalizedBox = box.clone();
|
|
367
|
+
/**
|
|
368
|
+
* @type {Vector2}
|
|
369
|
+
*/
|
|
370
|
+
const viewportSize = engine.graphics.viewport.size;
|
|
371
|
+
/*
|
|
372
|
+
need to convert pixel size into normalized viewport coordinates, they range from -1 to 1 and have inverse Y axis compared to html
|
|
373
|
+
*/
|
|
374
|
+
normalizedBox.x0 = (box.x0 / viewportSize.x) * 2 - 1;
|
|
375
|
+
normalizedBox.x1 = (box.x1 / viewportSize.x) * 2 - 1;
|
|
376
|
+
normalizedBox.y0 = -(box.y0 / viewportSize.y) * 2 + 1;
|
|
377
|
+
normalizedBox.y1 = -(box.y1 / viewportSize.y) * 2 + 1;
|
|
378
|
+
|
|
379
|
+
const frustum = new ThreeFrustum();
|
|
380
|
+
|
|
381
|
+
makeScreenScissorFrustum(frustum, normalizedBox, camera);
|
|
382
|
+
|
|
383
|
+
const selection = [];
|
|
384
|
+
//query render layers
|
|
385
|
+
engine.graphics.layers.traverse(function (layer) {
|
|
386
|
+
layer.bvh.threeTraverseFrustumsIntersections([frustum], function (leaf, fullyInside) {
|
|
387
|
+
|
|
388
|
+
if (leaf.hasOwnProperty("entity") && selection.indexOf(leaf.entity) === -1) {
|
|
389
|
+
let entity = findEntityOfNode(leaf);
|
|
390
|
+
|
|
391
|
+
entity = dereferenceEntity(entity, dataset);
|
|
392
|
+
|
|
393
|
+
if (entity === -1) {
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (selection.indexOf(entity) === -1) {
|
|
398
|
+
selection.push(entity);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
|
|
404
|
+
return selection;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
export default SelectionTool;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 16/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
import Tool from './engine/Tool.js';
|
|
5
|
+
import TopDownCameraControllerSystem
|
|
6
|
+
from "../../src/engine/graphics/ecs/camera/topdown/TopDownCameraControllerSystem.js";
|
|
7
|
+
import { makeOrbitalCameraController } from "../../src/engine/graphics/camera/makeOrbitalCameraController.js";
|
|
8
|
+
import EditorEntity from "../ecs/EditorEntity.js";
|
|
9
|
+
|
|
10
|
+
class TopDownCameraControlTool extends Tool {
|
|
11
|
+
constructor() {
|
|
12
|
+
super();
|
|
13
|
+
this.name = "camera_control";
|
|
14
|
+
this.system = null;
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @type {EntityBuilder}
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
this.__controller = null;
|
|
23
|
+
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
initialize() {
|
|
27
|
+
super.initialize();
|
|
28
|
+
|
|
29
|
+
const engine = this.engine;
|
|
30
|
+
const editor = this.editor;
|
|
31
|
+
|
|
32
|
+
const em = engine.entityManager;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
this.system = em.getSystem(TopDownCameraControllerSystem);
|
|
36
|
+
this.system.enabled.set(true);
|
|
37
|
+
|
|
38
|
+
const ecd = em.dataset;
|
|
39
|
+
|
|
40
|
+
this.__controller = makeOrbitalCameraController({
|
|
41
|
+
ecd: ecd,
|
|
42
|
+
camera_entity: editor.cameraEntity.entity,
|
|
43
|
+
dom_element: engine.graphics.domElement
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.__controller.add(new EditorEntity());
|
|
47
|
+
|
|
48
|
+
this.__controller.build(ecd);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
shutdown() {
|
|
52
|
+
this.system.enabled.set(false);
|
|
53
|
+
|
|
54
|
+
this.__controller.destroy();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
export default TopDownCameraControlTool;
|