@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,92 @@
|
|
|
1
|
+
import { EngineHarness } from "../../../src/engine/EngineHarness.js";
|
|
2
|
+
import EntityBuilder from "../../../src/engine/ecs/EntityBuilder.js";
|
|
3
|
+
import { ShadedGeometry } from "../../../src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
|
|
4
|
+
import { BoxBufferGeometry, MeshStandardMaterial } from "three";
|
|
5
|
+
import { Transform } from "../../../src/engine/ecs/transform/Transform.js";
|
|
6
|
+
import { ShadedGeometrySystem } from "../../../src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js";
|
|
7
|
+
import { TransformControls } from "./TransformControls.js";
|
|
8
|
+
import { Camera } from "../../../src/engine/graphics/ecs/camera/Camera.js";
|
|
9
|
+
import { TransformAttachmentSystem } from "../../../src/engine/ecs/transform-attachment/TransformAttachmentSystem.js";
|
|
10
|
+
import InputController from "../../../src/engine/input/ecs/components/InputController.js";
|
|
11
|
+
import InputControllerSystem from "../../../src/engine/input/ecs/systems/InputControllerSystem.js";
|
|
12
|
+
import { GLTFAssetLoader } from "../../../src/engine/asset/loaders/GLTFAssetLoader.js";
|
|
13
|
+
import {
|
|
14
|
+
three_object_to_entity_composition
|
|
15
|
+
} from "../../../src/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js";
|
|
16
|
+
|
|
17
|
+
const harness = new EngineHarness();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {Engine} engine
|
|
22
|
+
*/
|
|
23
|
+
async function main(engine) {
|
|
24
|
+
await EngineHarness.buildBasics({
|
|
25
|
+
engine,
|
|
26
|
+
cameraController: false
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const gltf_asset = await engine.assetManager.promise('data/models/sponza-pbr/gltf/sponza.glb', 'gltf');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
const ecd = engine.entityManager.dataset;
|
|
33
|
+
|
|
34
|
+
// create something to drag
|
|
35
|
+
const cube_entity = new EntityBuilder()
|
|
36
|
+
.add(ShadedGeometry.from(
|
|
37
|
+
new BoxBufferGeometry(1, 1, 1),
|
|
38
|
+
new MeshStandardMaterial({
|
|
39
|
+
color: 0xFFAAAA
|
|
40
|
+
})
|
|
41
|
+
))
|
|
42
|
+
.add(Transform.fromJSON({
|
|
43
|
+
position: {
|
|
44
|
+
x: 10,
|
|
45
|
+
y: 0,
|
|
46
|
+
z: 10
|
|
47
|
+
}
|
|
48
|
+
}))
|
|
49
|
+
.build(ecd);
|
|
50
|
+
|
|
51
|
+
const camera = ecd.getAnyComponent(Camera);
|
|
52
|
+
|
|
53
|
+
const controls = new TransformControls(camera.component.object, engine.gameView.el);
|
|
54
|
+
|
|
55
|
+
const entityNode = three_object_to_entity_composition(gltf_asset.create());
|
|
56
|
+
entityNode.build(ecd);
|
|
57
|
+
entityNode.transform.scale.multiplyScalar(0.1);
|
|
58
|
+
|
|
59
|
+
controls.build(ecd); // add controls to the scene
|
|
60
|
+
// controls.attach(cube_entity); // make controls target the cube
|
|
61
|
+
controls.attach(entityNode.entity.entity); // make controls target the cube
|
|
62
|
+
|
|
63
|
+
new EntityBuilder()
|
|
64
|
+
.add(new InputController([{
|
|
65
|
+
path: 'keyboard/keys/w/down',
|
|
66
|
+
listener() {
|
|
67
|
+
controls.mode = "translate"
|
|
68
|
+
}
|
|
69
|
+
}, {
|
|
70
|
+
path: 'keyboard/keys/e/down',
|
|
71
|
+
listener() {
|
|
72
|
+
controls.mode = "scale"
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
path: 'keyboard/keys/r/down',
|
|
76
|
+
listener() {
|
|
77
|
+
controls.mode = "rotate"
|
|
78
|
+
}
|
|
79
|
+
}]))
|
|
80
|
+
.build(ecd);
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
harness.initialize({
|
|
85
|
+
configuration(config, engine) {
|
|
86
|
+
config.addSystem(new ShadedGeometrySystem(engine));
|
|
87
|
+
config.addSystem(new TransformAttachmentSystem(engine));
|
|
88
|
+
config.addSystem(new InputControllerSystem(engine.devices));
|
|
89
|
+
|
|
90
|
+
config.addLoader('gltf', new GLTFAssetLoader());
|
|
91
|
+
}
|
|
92
|
+
}).then(main);
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 14/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import View from "../../src/view/View.js";
|
|
7
|
+
import dom from "../../src/view/DOM.js";
|
|
8
|
+
|
|
9
|
+
import EntityListView from './ecs/EntityList.js';
|
|
10
|
+
import EntityEditorView from './ecs/EntityEditor.js';
|
|
11
|
+
import ComponentControlFactory from './ecs/ComponentControlFactory.js';
|
|
12
|
+
import VirtualListView from '../../src/view/common/VirtualListView.js';
|
|
13
|
+
import LabelView from '../../src/view/common/LabelView.js';
|
|
14
|
+
import ToolView from './tools/ToolView.js';
|
|
15
|
+
|
|
16
|
+
import SimpleWindow from '../../src/view/elements/SimpleWindow.js';
|
|
17
|
+
import ToolSettingsView from "./tools/ToolSettingsView.js";
|
|
18
|
+
import GridPickCoordinateView from "./GridPickCoordinateView.js";
|
|
19
|
+
import ListView from "../../src/view/common/ListView.js";
|
|
20
|
+
import ProcessView from "./process/ProcessView.js";
|
|
21
|
+
import MeshLibraryView from "./library/MeshLibraryView.js";
|
|
22
|
+
import BottomLeftResizeHandleView from "../../src/view/elements/BottomLeftResizeHandleView.js";
|
|
23
|
+
import Vector2 from "../../src/core/geom/Vector2.js";
|
|
24
|
+
import Vector3 from "../../src/core/geom/Vector3.js";
|
|
25
|
+
import Mesh from "../../src/engine/graphics/ecs/mesh/Mesh.js";
|
|
26
|
+
import { Transform } from "../../src/engine/ecs/transform/Transform.js";
|
|
27
|
+
import SelectionClearAction from "../actions/concrete/SelectionClearAction.js";
|
|
28
|
+
import EntityCreateAction from "../actions/concrete/EntityCreateAction.js";
|
|
29
|
+
import ComponentAddAction from "../actions/concrete/ComponentAddAction.js";
|
|
30
|
+
import SelectionAddAction from "../actions/concrete/SelectionAddAction.js";
|
|
31
|
+
import { passThrough } from "../../src/core/function/Functions.js";
|
|
32
|
+
import { ProcessState } from "../../src/core/process/ProcessState.js";
|
|
33
|
+
import { MeshEvents } from "../../src/engine/graphics/ecs/mesh/MeshEvents.js";
|
|
34
|
+
import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
35
|
+
import { SurfacePoint3 } from "../../src/core/geom/3d/SurfacePoint3.js";
|
|
36
|
+
|
|
37
|
+
class ViewManager extends View {
|
|
38
|
+
constructor() {
|
|
39
|
+
super();
|
|
40
|
+
const dRoot = dom('div');
|
|
41
|
+
dRoot.addClass('view-manager');
|
|
42
|
+
|
|
43
|
+
this.el = dRoot.el;
|
|
44
|
+
|
|
45
|
+
this.storage = [];
|
|
46
|
+
|
|
47
|
+
//store parameters of previously opened windows
|
|
48
|
+
this.memory = {};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
add(view, title) {
|
|
52
|
+
const simpleWindow = new SimpleWindow(
|
|
53
|
+
view,
|
|
54
|
+
{
|
|
55
|
+
draggable: true,
|
|
56
|
+
closeable: false,
|
|
57
|
+
resizable: true,
|
|
58
|
+
title: title
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
this.storage.push({
|
|
63
|
+
original: view,
|
|
64
|
+
window: simpleWindow
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
this.addChild(simpleWindow);
|
|
68
|
+
|
|
69
|
+
if (this.memory.hasOwnProperty(title)) {
|
|
70
|
+
const windowParams = this.memory[title];
|
|
71
|
+
view.size.copy(windowParams.size);
|
|
72
|
+
simpleWindow.position.copy(windowParams.position);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return simpleWindow;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
exists(view) {
|
|
79
|
+
return this.getInternalIndex(view) !== -1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getInternalIndex(view) {
|
|
83
|
+
for (let i = 0; i < this.storage.length; i++) {
|
|
84
|
+
const el = this.storage[i];
|
|
85
|
+
if (el.original === view) {
|
|
86
|
+
return i;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return -1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
remove(view) {
|
|
93
|
+
//find the window
|
|
94
|
+
const internalIndex = this.getInternalIndex(view);
|
|
95
|
+
|
|
96
|
+
if (internalIndex === -1) {
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const el = this.storage[internalIndex];
|
|
101
|
+
//cut from internal index
|
|
102
|
+
this.storage.splice(internalIndex, 1);
|
|
103
|
+
|
|
104
|
+
const vWindow = el.window;
|
|
105
|
+
this.removeChild(vWindow);
|
|
106
|
+
|
|
107
|
+
//remember window parameters
|
|
108
|
+
this.memory[vWindow.title.get()] = {
|
|
109
|
+
position: vWindow.position.clone(),
|
|
110
|
+
size: view.size.clone()
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
*
|
|
120
|
+
* @param {Editor} editor
|
|
121
|
+
*/
|
|
122
|
+
function prepareMeshLibrary(editor) {
|
|
123
|
+
let resolveEngine;
|
|
124
|
+
|
|
125
|
+
const pEngine = new Promise(function (resolve, reject) {
|
|
126
|
+
resolveEngine = resolve;
|
|
127
|
+
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
*
|
|
132
|
+
* @type {Promise<GraphicsEngine>}
|
|
133
|
+
*/
|
|
134
|
+
const pGraphicsEngine = pEngine.then(function (e) {
|
|
135
|
+
return e.graphics;
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const pRenderer = pGraphicsEngine.then(function (graphicsEngine) {
|
|
139
|
+
return graphicsEngine.renderer;
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const pAssetManager = pEngine.then(e => e.assetManager);
|
|
143
|
+
|
|
144
|
+
const meshLibraryView = new MeshLibraryView(
|
|
145
|
+
editor.meshLibrary,
|
|
146
|
+
pAssetManager,
|
|
147
|
+
pRenderer
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
function handleDropEvent(event) {
|
|
151
|
+
event.stopPropagation();
|
|
152
|
+
event.preventDefault();
|
|
153
|
+
|
|
154
|
+
const dataText = event.dataTransfer.getData('text/json');
|
|
155
|
+
if (dataText === "") {
|
|
156
|
+
//no data
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const data = JSON.parse(dataText);
|
|
161
|
+
|
|
162
|
+
const type = data.type;
|
|
163
|
+
|
|
164
|
+
if (type !== "Mesh") {
|
|
165
|
+
//wrong type
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const url = data.url;
|
|
170
|
+
|
|
171
|
+
const engine = editor.engine;
|
|
172
|
+
const graphics = engine.graphics;
|
|
173
|
+
|
|
174
|
+
const position = new Vector2(event.clientX, event.clientY);
|
|
175
|
+
|
|
176
|
+
graphics.viewport.positionGlobalToLocal(position, position);
|
|
177
|
+
|
|
178
|
+
const normalizedPosition = new Vector2();
|
|
179
|
+
|
|
180
|
+
//compute world position for drop
|
|
181
|
+
|
|
182
|
+
graphics.normalizeViewportPoint(position, normalizedPosition);
|
|
183
|
+
|
|
184
|
+
const source = new Vector3();
|
|
185
|
+
const direction = new Vector3();
|
|
186
|
+
|
|
187
|
+
graphics.viewportProjectionRay(normalizedPosition.x, normalizedPosition.y, source, direction);
|
|
188
|
+
|
|
189
|
+
const entityManager = engine.entityManager;
|
|
190
|
+
const ecd = entityManager.dataset;
|
|
191
|
+
|
|
192
|
+
const terrain = obtainTerrain(ecd);
|
|
193
|
+
|
|
194
|
+
const worldPosition = new Vector3();
|
|
195
|
+
|
|
196
|
+
const mesh = new Mesh();
|
|
197
|
+
|
|
198
|
+
mesh.castShadow = true;
|
|
199
|
+
mesh.receiveShadow = true;
|
|
200
|
+
|
|
201
|
+
const transform = new Transform();
|
|
202
|
+
|
|
203
|
+
const actions = editor.actions;
|
|
204
|
+
actions.mark('New Mesh Placed from Library');
|
|
205
|
+
const entityCreateAction = new EntityCreateAction();
|
|
206
|
+
actions.do(entityCreateAction);
|
|
207
|
+
|
|
208
|
+
const sp3 = new SurfacePoint3();
|
|
209
|
+
|
|
210
|
+
const hit_found = terrain.raycastFirstSync(sp3, source.x, source.y, source.z, direction.x, direction.y, direction.z);
|
|
211
|
+
|
|
212
|
+
function handleMeshSetEvent() {
|
|
213
|
+
const bb = mesh.boundingBox;
|
|
214
|
+
|
|
215
|
+
const c0 = new Vector3(bb.x0, bb.y0, bb.z0);
|
|
216
|
+
const c1 = new Vector3(bb.x1, bb.y1, bb.z1);
|
|
217
|
+
|
|
218
|
+
const diagonal = c0.distanceTo(c1);
|
|
219
|
+
|
|
220
|
+
const offset = direction.clone().multiplyScalar(diagonal);
|
|
221
|
+
|
|
222
|
+
transform.position.add(offset);
|
|
223
|
+
|
|
224
|
+
//remove listener
|
|
225
|
+
ecd.removeEntityEventListener(entityCreateAction.entity, MeshEvents.DataSet, handleMeshSetEvent);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (hit_found) {
|
|
229
|
+
//got a terrain ray hit, set world placement position to that point
|
|
230
|
+
worldPosition.copy(sp3.position);
|
|
231
|
+
} else {
|
|
232
|
+
//set position to the source of the ray pick if there's nothing else available
|
|
233
|
+
worldPosition.copy(source);
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
//wait for mesh to load
|
|
237
|
+
ecd.addEntityEventListener(entityCreateAction.entity, MeshEvents.DataSet, handleMeshSetEvent);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
transform.position.copy(worldPosition);
|
|
241
|
+
|
|
242
|
+
mesh.url = url;
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
actions.doMany([
|
|
246
|
+
new ComponentAddAction(entityCreateAction.entity, transform),
|
|
247
|
+
new ComponentAddAction(entityCreateAction.entity, mesh),
|
|
248
|
+
//automatically select newly placed object
|
|
249
|
+
new SelectionClearAction(),
|
|
250
|
+
new SelectionAddAction([entityCreateAction.entity])
|
|
251
|
+
]);
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function handleDragOverEvent(event) {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
meshLibraryView.on.linked.add(function () {
|
|
261
|
+
resolveEngine(editor.engine);
|
|
262
|
+
|
|
263
|
+
const viewport = editor.engine.graphics.viewport;
|
|
264
|
+
|
|
265
|
+
viewport.el.addEventListener('drop', handleDropEvent);
|
|
266
|
+
viewport.el.addEventListener('dragover', handleDragOverEvent);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
meshLibraryView.on.unlinked.add(function () {
|
|
270
|
+
const viewport = editor.engine.graphics.viewport;
|
|
271
|
+
|
|
272
|
+
viewport.el.removeEventListener('drop', handleDropEvent);
|
|
273
|
+
viewport.el.removeEventListener('dragover', handleDragOverEvent);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
meshLibraryView.size.set(400, 400);
|
|
277
|
+
|
|
278
|
+
const resizeHandleView = new BottomLeftResizeHandleView(meshLibraryView);
|
|
279
|
+
meshLibraryView.addChild(resizeHandleView);
|
|
280
|
+
|
|
281
|
+
return meshLibraryView;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
class EditorView extends View {
|
|
285
|
+
/**
|
|
286
|
+
*
|
|
287
|
+
* @param {Editor} editor
|
|
288
|
+
* @constructor
|
|
289
|
+
*/
|
|
290
|
+
constructor(editor) {
|
|
291
|
+
super(editor);
|
|
292
|
+
|
|
293
|
+
const dRoot = dom('div');
|
|
294
|
+
dRoot.addClass('editor-view');
|
|
295
|
+
|
|
296
|
+
this.el = dRoot.el;
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
*
|
|
300
|
+
* @type {Editor}
|
|
301
|
+
*/
|
|
302
|
+
this.editor = editor;
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
*
|
|
306
|
+
* @type {View|null}
|
|
307
|
+
*/
|
|
308
|
+
this.gameView = null;
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
const entityListView = new EntityListView(editor);
|
|
312
|
+
this.entityListView = entityListView;
|
|
313
|
+
|
|
314
|
+
//entity editor
|
|
315
|
+
const controllerFactory = new ComponentControlFactory();
|
|
316
|
+
const entityEditor = new EntityEditorView(controllerFactory, editor);
|
|
317
|
+
|
|
318
|
+
this.entityEditor = entityEditor;
|
|
319
|
+
|
|
320
|
+
function inspectEntity(entity) {
|
|
321
|
+
const em = editor.engine.entityManager;
|
|
322
|
+
entityEditor.entityManager.set(em);
|
|
323
|
+
entityEditor.model.set(entity);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
this.bindSignal(editor.selection.on.added, function (entity) {
|
|
327
|
+
if (editor.selection.length === 1) {
|
|
328
|
+
//when first thing is selected - inspect it automatically
|
|
329
|
+
inspectEntity(entity);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
entityListView.on.interaction.add(inspectEntity);
|
|
334
|
+
this.entityListView = entityListView;
|
|
335
|
+
|
|
336
|
+
const toolSettings = new ToolSettingsView({});
|
|
337
|
+
this.toolSettings = toolSettings;
|
|
338
|
+
|
|
339
|
+
//tool bar
|
|
340
|
+
const toolBar = new ListView(editor.toolEngine.tools, {
|
|
341
|
+
elementFactory: function (tool) {
|
|
342
|
+
const toolView = new ToolView({ tool, editor });
|
|
343
|
+
|
|
344
|
+
toolView.el.addEventListener('click', function () {
|
|
345
|
+
editor.toolEngine.activate(tool.name);
|
|
346
|
+
toolSettings.setTool(tool);
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
const activeTool = editor.toolEngine.active;
|
|
350
|
+
|
|
351
|
+
function handleActivation() {
|
|
352
|
+
toolView.el.classList.toggle('active', activeTool.getValue() === tool);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
toolView.on.linked.add(handleActivation);
|
|
356
|
+
toolView.bindSignal(activeTool.onChanged, handleActivation);
|
|
357
|
+
|
|
358
|
+
return toolView;
|
|
359
|
+
},
|
|
360
|
+
classList: ['editor-tool-bar']
|
|
361
|
+
});
|
|
362
|
+
this.toolBar = toolBar;
|
|
363
|
+
|
|
364
|
+
//tool bar
|
|
365
|
+
const processBar = new ListView(editor.processEngine.processes, {
|
|
366
|
+
elementFactory: function (process) {
|
|
367
|
+
const toolView = new ProcessView(process);
|
|
368
|
+
toolView.el.addEventListener('click', function () {
|
|
369
|
+
if (process.__state.getValue() !== ProcessState.Running) {
|
|
370
|
+
editor.processEngine.startByName(process.name);
|
|
371
|
+
} else {
|
|
372
|
+
editor.processEngine.stopByName(process.name);
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
return toolView;
|
|
377
|
+
},
|
|
378
|
+
classList: ['editor-process-bar']
|
|
379
|
+
});
|
|
380
|
+
this.processBar = processBar;
|
|
381
|
+
|
|
382
|
+
//selection list
|
|
383
|
+
const selectionView = new VirtualListView(editor.selection, {
|
|
384
|
+
elementFactory: function (entity) {
|
|
385
|
+
const labelView = new LabelView(entity, { format: passThrough });
|
|
386
|
+
labelView.el.addEventListener('click', function () {
|
|
387
|
+
inspectEntity(entity);
|
|
388
|
+
});
|
|
389
|
+
return labelView;
|
|
390
|
+
},
|
|
391
|
+
classList: ['selected-entities']
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
selectionView.size.set(70, 120);
|
|
395
|
+
this.selectionView = selectionView;
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
const coordinateView = new GridPickCoordinateView(editor);
|
|
399
|
+
this.coordinateView = coordinateView;
|
|
400
|
+
|
|
401
|
+
this.meshLibraryView = prepareMeshLibrary(editor);
|
|
402
|
+
this.meshLibraryView.size.set(340, 200);
|
|
403
|
+
|
|
404
|
+
//
|
|
405
|
+
this.bindSignal(this.size.onChanged, this.layout.bind(this));
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
this.addChild(this.coordinateView);
|
|
409
|
+
this.addChild(this.selectionView);
|
|
410
|
+
this.addChild(this.entityEditor);
|
|
411
|
+
this.addChild(this.entityListView);
|
|
412
|
+
this.addChild(this.toolBar);
|
|
413
|
+
this.addChild(this.processBar);
|
|
414
|
+
this.addChild(this.meshLibraryView);
|
|
415
|
+
this.addChild(this.toolSettings);
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
layout() {
|
|
419
|
+
const size = this.size;
|
|
420
|
+
|
|
421
|
+
this.entityEditor.size.set(360, size.y);
|
|
422
|
+
this.entityEditor.position.set(size.x - this.entityEditor.size.x, 0);
|
|
423
|
+
|
|
424
|
+
this.entityListView.size.set(200, size.y);
|
|
425
|
+
this.entityListView.position.set(0, 0);
|
|
426
|
+
|
|
427
|
+
if (this.gameView !== null) {
|
|
428
|
+
this.gameView.position.set(this.entityListView.position.x + this.entityListView.size.x, 0);
|
|
429
|
+
this.gameView.size.set(size.x - (this.entityEditor.size.x + this.entityListView.size.x), size.y);
|
|
430
|
+
|
|
431
|
+
this.toolBar.size.set(this.gameView.size.x, 36);
|
|
432
|
+
this.toolBar.position.set(this.gameView.position.x + 5, this.gameView.position.y + this.gameView.size.y - (this.toolBar.size.y + 5));
|
|
433
|
+
|
|
434
|
+
// this.processBar.size.set(this.gameView.size.x, 36);
|
|
435
|
+
// this.processBar.position.set(this.toolBar.position.x, 5);
|
|
436
|
+
|
|
437
|
+
this.meshLibraryView.position.set(this.gameView.position.x + this.gameView.size.x - (this.meshLibraryView.size.x + 5), 5);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
link() {
|
|
442
|
+
super.link();
|
|
443
|
+
|
|
444
|
+
//hijack game view from the engine
|
|
445
|
+
this.gameView = this.editor.engine.gameView;
|
|
446
|
+
this.addChild(this.gameView);
|
|
447
|
+
|
|
448
|
+
this.layout();
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
unlink() {
|
|
452
|
+
super.unlink();
|
|
453
|
+
if (this.gameView !== null) {
|
|
454
|
+
//release game view
|
|
455
|
+
this.removeChild(this.gameView);
|
|
456
|
+
this.gameView = null;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
export default EditorView;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import View from "../../src/view/View.js";
|
|
2
|
+
import domify from "../../src/view/DOM.js";
|
|
3
|
+
import { PointerDevice } from "../../src/engine/input/devices/PointerDevice.js";
|
|
4
|
+
import { obtainTerrain } from "../../src/engine/ecs/terrain/util/obtainTerrain.js";
|
|
5
|
+
import { pick } from "../../src/ecs/grid/pick.js";
|
|
6
|
+
|
|
7
|
+
class GridPickCoordinateView extends View {
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {Editor} editor
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
constructor(editor) {
|
|
14
|
+
super();
|
|
15
|
+
|
|
16
|
+
this.$el = domify('div');
|
|
17
|
+
|
|
18
|
+
this.el = this.$el.el;
|
|
19
|
+
|
|
20
|
+
this.addClass('ui-grid-pick-coordinate-view');
|
|
21
|
+
|
|
22
|
+
this.pointer = new PointerDevice(null);
|
|
23
|
+
|
|
24
|
+
this.editor = editor;
|
|
25
|
+
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
pick(x, y) {
|
|
29
|
+
const $el = this.$el;
|
|
30
|
+
const engine = this.editor.engine;
|
|
31
|
+
|
|
32
|
+
const vp = engine.gameView.position;
|
|
33
|
+
|
|
34
|
+
const em = engine.entityManager;
|
|
35
|
+
|
|
36
|
+
const ecd = em.dataset;
|
|
37
|
+
|
|
38
|
+
if (ecd === null) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const terrain = obtainTerrain(ecd);
|
|
43
|
+
|
|
44
|
+
if (terrain === null) {
|
|
45
|
+
//no terrain
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
pick(x - vp.x, y - vp.y, engine.graphics, terrain, function (v2, v3, normal) {
|
|
50
|
+
v2.floor();
|
|
51
|
+
$el.text(`x: ${v2.x}, y: ${v2.y}`);
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @return {PointerDevice}
|
|
58
|
+
*/
|
|
59
|
+
getPointer() {
|
|
60
|
+
return this.editor.engine.devices.pointer;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
link() {
|
|
64
|
+
super.link();
|
|
65
|
+
|
|
66
|
+
const viewport = this.editor.engine.graphics.viewport;
|
|
67
|
+
|
|
68
|
+
this.pointer.domElement = viewport.el;
|
|
69
|
+
|
|
70
|
+
this.pointer.start();
|
|
71
|
+
|
|
72
|
+
const position = this.getPointer().position;
|
|
73
|
+
this.pick(position.x, position.y);
|
|
74
|
+
|
|
75
|
+
position.onChanged.add(this.pick, this);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
unlink() {
|
|
79
|
+
super.unlink();
|
|
80
|
+
|
|
81
|
+
this.pointer.stop();
|
|
82
|
+
|
|
83
|
+
this.getPointer().position.onChanged.remove(this.pick, this);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
export default GridPickCoordinateView;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Created by Alex on 14/01/2017.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
//TODO consider making more abstract and using as a ViewFactory elsewhere
|
|
7
|
+
|
|
8
|
+
import { assert } from "../../../src/core/assert.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @constructor
|
|
13
|
+
*/
|
|
14
|
+
function ComponentControlFactory() {
|
|
15
|
+
this.controllerTypes = {};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {string} componentTypeName
|
|
21
|
+
* @param {function} factory
|
|
22
|
+
* @returns {ComponentControlFactory}
|
|
23
|
+
*/
|
|
24
|
+
ComponentControlFactory.prototype.register = function (componentTypeName, factory) {
|
|
25
|
+
assert.equal(typeof factory, 'function');
|
|
26
|
+
assert.equal(typeof componentTypeName, 'string');
|
|
27
|
+
|
|
28
|
+
this.controllerTypes[componentTypeName] = factory;
|
|
29
|
+
|
|
30
|
+
return this;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {string} componentTypeName
|
|
36
|
+
* @returns {object} instance of a controller for given component type
|
|
37
|
+
*/
|
|
38
|
+
ComponentControlFactory.prototype.create = function (componentTypeName) {
|
|
39
|
+
const factory = this.controllerTypes[componentTypeName];
|
|
40
|
+
return factory();
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
ComponentControlFactory.prototype.exists = function (typeName) {
|
|
44
|
+
return this.controllerTypes.hasOwnProperty(typeName);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default ComponentControlFactory;
|
|
48
|
+
|