@woosh/meep-engine 2.46.29 → 2.46.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/editor/Editor.js +793 -0
- package/editor/SelectionVisualizer.js +148 -0
- package/editor/actions/concrete/ActionUpdateTexture.js +21 -0
- package/editor/actions/concrete/ArrayCopyAction.js +39 -0
- package/editor/actions/concrete/ComponentAddAction.js +47 -0
- package/editor/actions/concrete/ComponentRemoveAction.js +38 -0
- package/editor/actions/concrete/EntityCreateAction.js +47 -0
- package/editor/actions/concrete/EntityRemoveAction.js +51 -0
- package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
- package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
- package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +182 -0
- package/editor/actions/concrete/PaintTerrainOverlayAction.js +45 -0
- package/editor/actions/concrete/PatchTerrainHeightAction.js +67 -0
- package/editor/actions/concrete/PatchTerrainTextureAction.js +152 -0
- package/editor/actions/concrete/SelectionAddAction.js +36 -0
- package/editor/actions/concrete/SelectionClearAction.js +22 -0
- package/editor/actions/concrete/SelectionRemoveAction.js +30 -0
- package/editor/actions/concrete/TransformModifyAction.js +46 -0
- package/editor/actions/concrete/WriteGridValueAction.js +46 -0
- package/editor/ecs/EditorEntity.js +12 -0
- package/editor/ecs/EditorEntitySystem.js +14 -0
- package/editor/ecs/component/FieldDescriptor.js +34 -0
- package/editor/ecs/component/FieldValueAdapter.js +20 -0
- package/editor/ecs/component/TypeEditor.js +33 -0
- package/editor/ecs/component/TypeSchema.d.ts +38 -0
- package/editor/ecs/component/createFieldEditor.js +92 -0
- package/editor/ecs/component/createObjectEditor.js +361 -0
- package/editor/ecs/component/editors/ColorEditor.js +39 -0
- package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
- package/editor/ecs/component/editors/ImagePathEditor.js +82 -0
- package/editor/ecs/component/editors/LargeStrongEditor.js +107 -0
- package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
- package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
- package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
- package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
- package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
- package/editor/ecs/component/editors/Sampler2DEditor.js +221 -0
- package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
- package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
- package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
- package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
- package/editor/ecs/component/editors/common/noEditor.js +9 -0
- package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
- package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +225 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
- package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +18 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +58 -0
- package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
- package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
- package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
- package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +95 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
- package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
- package/editor/ecs/component/editors/geom/QuaternionEditor.js +63 -0
- package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
- package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
- package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
- package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
- package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
- package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
- package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
- package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
- package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
- package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
- package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
- package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
- package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
- package/editor/ecs/component/editors/three/TextureEditor.js +112 -0
- package/editor/ecs/component/findNearestRegisteredType.js +59 -0
- package/editor/ecs/component/prototypeObjectEditor.js +379 -0
- package/editor/enableEditor.js +85 -0
- package/editor/library/MeshLibrary.js +33 -0
- package/editor/process/DisableGameUIProcess.js +43 -0
- package/editor/process/EditorProcess.js +35 -0
- package/editor/process/ObstacleGridDisplayProcess.js +120 -0
- package/editor/process/ProcessEngine.js +123 -0
- package/editor/process/SymbolicDisplayProcess.js +132 -0
- package/editor/process/symbolic/ComponentSymbolicDisplay.js +34 -0
- package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +159 -0
- package/editor/process/symbolic/buildThreeJSHelperEntity.js +36 -0
- package/editor/process/symbolic/make3DSymbolicDisplay.js +91 -0
- package/editor/process/symbolic/makeCameraSymbolicDisplay.js +32 -0
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +176 -0
- package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
- package/editor/process/symbolic/makeHelperSphereGeometry.js +73 -0
- package/editor/process/symbolic/makeLightSymbolicDisplay.js +77 -0
- package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +146 -0
- package/editor/process/symbolic/makePathSymbolicDisplay.js +105 -0
- package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +74 -0
- package/editor/process/symbolic/makeSocketsSymbolicDisplay.js +153 -0
- package/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
- package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.js +89 -0
- package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +114 -0
- package/editor/process/symbolic/synchronizeTransform.js +50 -0
- package/editor/tools/FoliagePaintTool.js +168 -0
- package/editor/tools/GridPaintTool.js +247 -0
- package/editor/tools/SelectionTool.js +407 -0
- package/editor/tools/TopDownCameraControlTool.js +59 -0
- package/editor/tools/TransformTool.js +370 -0
- package/editor/tools/engine/Tool.js +121 -0
- package/editor/tools/engine/ToolEngine.js +193 -0
- package/editor/tools/engine/ToolState.js +9 -0
- package/editor/tools/engine/ToolStateMachine.js +53 -0
- package/editor/tools/paint/TerrainHeightPaintTool.js +297 -0
- package/editor/tools/paint/TerrainPaintTool.js +211 -0
- package/editor/tools/paint/TerrainTexturePaintTool.js +193 -0
- package/editor/tools/paint/prototypeTerrainEditor.js +135 -0
- package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +50 -0
- package/editor/tools/v2/BlenderCameraOrientationGizmo.js +500 -0
- package/editor/tools/v2/TransformControls.d.ts +20 -0
- package/editor/tools/v2/TransformControls.js +1782 -0
- package/editor/tools/v2/prototypeTransformControls.js +92 -0
- package/editor/view/EditorView.js +462 -0
- package/editor/view/GridPickCoordinateView.js +88 -0
- package/editor/view/ecs/ComponentControlFactory.js +48 -0
- package/editor/view/ecs/ComponentControlView.js +214 -0
- package/editor/view/ecs/EntityEditor.js +258 -0
- package/editor/view/ecs/EntityList.js +258 -0
- package/editor/view/ecs/components/BlackboardController.js +50 -0
- package/editor/view/ecs/components/DatGuiController.js +216 -0
- package/editor/view/ecs/components/FogOfWarController.js +78 -0
- package/editor/view/ecs/components/FogOfWarRevealerController.js +44 -0
- package/editor/view/ecs/components/GeneratedArmyController.js +42 -0
- package/editor/view/ecs/components/GridObstacleController.js +72 -0
- package/editor/view/ecs/components/GridPositionController.js +40 -0
- package/editor/view/ecs/components/HeadsUpDisplayController.js +30 -0
- package/editor/view/ecs/components/HighlightController.js +47 -0
- package/editor/view/ecs/components/MeshController.js +125 -0
- package/editor/view/ecs/components/PathFollowerController.js +87 -0
- package/editor/view/ecs/components/TagController.js +80 -0
- package/editor/view/ecs/components/TerrainController.js +225 -0
- package/editor/view/ecs/components/TransformController.js +103 -0
- package/editor/view/ecs/components/UnitShopController.js +112 -0
- package/editor/view/ecs/components/army/ArmyController.js +130 -0
- package/editor/view/ecs/components/color/GaugeView.js +107 -0
- package/editor/view/ecs/components/common/AutoCanvasView.js +53 -0
- package/editor/view/ecs/components/common/LineView.js +17 -0
- package/editor/view/ecs/components/common/NumberController.js +112 -0
- package/editor/view/ecs/components/common/NumericIntervalController.js +64 -0
- package/editor/view/ecs/components/gui/GUIElementController.js +117 -0
- package/editor/view/ecs/components/items/ItemContainerController.js +132 -0
- package/editor/view/ecs/components/items/ItemContainerController.stories.js +50 -0
- package/editor/view/ecs/components/items/ItemController.js +52 -0
- package/editor/view/ecs/components/particles/ColorParameterLUTController.js +444 -0
- package/editor/view/ecs/components/particles/ParameterTrackController.js +51 -0
- package/editor/view/ecs/components/particles/ParticleEmitterController.js +213 -0
- package/editor/view/ecs/components/particles/ParticleLayerController.js +213 -0
- package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +401 -0
- package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +51 -0
- package/editor/view/ecs/components/sound/SoundEmitterController.js +137 -0
- package/editor/view/ecs/components/story/StoryTriggerSetController.js +214 -0
- package/editor/view/ecs/components/unit/AuraController.js +45 -0
- package/editor/view/library/MeshLibraryView.js +164 -0
- package/editor/view/node-graph/NodeGraphEditorView.js +170 -0
- package/editor/view/node-graph/NodeGraphView.js +453 -0
- package/editor/view/node-graph/NodeView.js +135 -0
- package/editor/view/node-graph/PortView.js +69 -0
- package/editor/view/process/ProcessView.js +63 -0
- package/editor/view/tools/ToolSettingsView.js +143 -0
- package/editor/view/tools/ToolView.js +58 -0
- package/package.json +2 -1
- package/src/engine/intelligence/behavior/composite/CompositeBehavior.js +18 -2
- package/src/engine/intelligence/behavior/composite/ParallelBehavior.js +21 -9
- package/src/engine/intelligence/behavior/composite/SequenceBehavior.js +5 -1
- package/src/engine/intelligence/behavior/util/DelayBehavior.js +8 -3
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { min2 } from "../../../src/core/math/min2.js";
|
|
2
|
+
import View from "../../../src/view/View.js";
|
|
3
|
+
import { NodeGraphCamera, NodeGraphView } from "./NodeGraphView.js";
|
|
4
|
+
import {
|
|
5
|
+
NodeDescriptionVisualRegistry
|
|
6
|
+
} from "../../../src/core/model/node-graph/visual/NodeDescriptionVisualRegistry.js";
|
|
7
|
+
import AABB2 from "../../../src/core/geom/AABB2.js";
|
|
8
|
+
import ButtonView from "../../../src/view/elements/button/ButtonView.js";
|
|
9
|
+
import EmptyView from "../../../src/view/elements/EmptyView.js";
|
|
10
|
+
|
|
11
|
+
export class NodeGraphEditorView extends View {
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {NodeGraph} graph
|
|
15
|
+
* @param {NodeRegistry} nodeRegistry
|
|
16
|
+
* @param {NodeGraphVisualData} visual
|
|
17
|
+
* @param {NodeGraphCamera} camera
|
|
18
|
+
* @param {InterfaceCommand[]} [actions]
|
|
19
|
+
*/
|
|
20
|
+
constructor({ graph, nodeRegistry, visual, camera, actions = [] }) {
|
|
21
|
+
super();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @type {NodeGraphCamera}
|
|
26
|
+
*/
|
|
27
|
+
this.camera = camera;
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* @type {NodeGraphVisualData}
|
|
31
|
+
*/
|
|
32
|
+
this.visual = visual;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @type {NodeGraph}
|
|
37
|
+
*/
|
|
38
|
+
this.graph = graph;
|
|
39
|
+
|
|
40
|
+
this.el = document.createElement('div');
|
|
41
|
+
this.addClass('ui-node-graph-editor-view');
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
const visualRegistry = new NodeDescriptionVisualRegistry();
|
|
45
|
+
//generate visual descriptions for registry nodes
|
|
46
|
+
nodeRegistry.nodes.forEach(node => {
|
|
47
|
+
visualRegistry.generate(node);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
const graphView = new NodeGraphView({
|
|
52
|
+
graph: graph,
|
|
53
|
+
visual: visual,
|
|
54
|
+
camera,
|
|
55
|
+
nodeVisualRegistry: visualRegistry
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
this.size.onChanged.add((x, y) => graphView.size.set(x, y));
|
|
59
|
+
this.addChild(graphView);
|
|
60
|
+
|
|
61
|
+
const self = this;
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
//
|
|
65
|
+
const vUserInterface = new EmptyView({
|
|
66
|
+
classList: ['user-interface']
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const vActionBar = new EmptyView({
|
|
70
|
+
classList: ['actions']
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
vUserInterface.addChild(vActionBar);
|
|
74
|
+
|
|
75
|
+
this.addChild(vUserInterface);
|
|
76
|
+
|
|
77
|
+
vActionBar.addChild(new ButtonView({
|
|
78
|
+
action() {
|
|
79
|
+
self.cameraContainAll()
|
|
80
|
+
},
|
|
81
|
+
classList: ["contain-all"]
|
|
82
|
+
}));
|
|
83
|
+
|
|
84
|
+
actions.forEach(ic => {
|
|
85
|
+
const b = new ButtonView({
|
|
86
|
+
action() {
|
|
87
|
+
ic.command.action();
|
|
88
|
+
},
|
|
89
|
+
classList: [ic.command.id]
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
vActionBar.addChild(b);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// ensure point events are enabled
|
|
96
|
+
this.css({
|
|
97
|
+
pointerEvents: 'auto'
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
layout() {
|
|
102
|
+
this.visual.layout(this.graph);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
cameraContainAll() {
|
|
106
|
+
/**
|
|
107
|
+
*
|
|
108
|
+
* @type {NodeGraphCamera}
|
|
109
|
+
*/
|
|
110
|
+
const camera = this.camera;
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
* @type {NodeGraphVisualData}
|
|
114
|
+
*/
|
|
115
|
+
const visual = this.visual;
|
|
116
|
+
|
|
117
|
+
//compute bounds of the graph
|
|
118
|
+
const bounds = new AABB2();
|
|
119
|
+
|
|
120
|
+
bounds.setNegativelyInfiniteBounds();
|
|
121
|
+
|
|
122
|
+
visual.computeBoundingBox(bounds);
|
|
123
|
+
|
|
124
|
+
if (bounds.x0 > bounds.x1) {
|
|
125
|
+
bounds.x0 = 0;
|
|
126
|
+
bounds.x1 = 0;
|
|
127
|
+
}
|
|
128
|
+
if (bounds.y0 > bounds.y1) {
|
|
129
|
+
bounds.y0 = 0;
|
|
130
|
+
bounds.y1 = 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
//expand bounds a bit
|
|
134
|
+
const PADDING = 32;
|
|
135
|
+
bounds.grow(PADDING);
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
//compute largest side scale
|
|
139
|
+
const boundsWidth = bounds.getWidth();
|
|
140
|
+
const boundsHeight = bounds.getHeight();
|
|
141
|
+
|
|
142
|
+
const canvas_width = this.size.x;
|
|
143
|
+
const canvas_height = this.size.y;
|
|
144
|
+
|
|
145
|
+
const xScale = canvas_width / boundsWidth;
|
|
146
|
+
const yScale = canvas_height / boundsHeight;
|
|
147
|
+
|
|
148
|
+
const scale = min2(
|
|
149
|
+
xScale,
|
|
150
|
+
yScale
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
if (scale === 0) {
|
|
154
|
+
camera.position.set(bounds.x0, bounds.y0);
|
|
155
|
+
|
|
156
|
+
camera.scale.set(1);
|
|
157
|
+
|
|
158
|
+
} else {
|
|
159
|
+
|
|
160
|
+
const xOffset = (boundsWidth - (canvas_width / scale)) / 2;
|
|
161
|
+
const yOffset = (boundsHeight - (canvas_height / scale)) / 2;
|
|
162
|
+
|
|
163
|
+
camera.position.set(bounds.x0 + xOffset, bounds.y0 + yOffset);
|
|
164
|
+
|
|
165
|
+
camera.scale.set(scale);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import { clamp } from "../../../src/core/math/clamp.js";
|
|
2
|
+
import { lerp } from "../../../src/core/math/lerp.js";
|
|
3
|
+
import { max2 } from "../../../src/core/math/max2.js";
|
|
4
|
+
import { min2 } from "../../../src/core/math/min2.js";
|
|
5
|
+
import View from "../../../src/view/View.js";
|
|
6
|
+
import { AutoCanvasView } from "../ecs/components/common/AutoCanvasView.js";
|
|
7
|
+
import Vector2 from "../../../src/core/geom/Vector2.js";
|
|
8
|
+
import Vector1 from "../../../src/core/geom/Vector1.js";
|
|
9
|
+
import ListView from "../../../src/view/common/ListView.js";
|
|
10
|
+
import { NodeView } from "./NodeView.js";
|
|
11
|
+
import List from "../../../src/core/collection/list/List.js";
|
|
12
|
+
import { DraggableAspect } from "../../../src/engine/ui/DraggableAspect.js";
|
|
13
|
+
import { PortDirection } from "../../../src/core/model/node-graph/node/PortDirection.js";
|
|
14
|
+
import { NodeInstancePortReference } from "../../../src/core/model/node-graph/node/NodeInstancePortReference.js";
|
|
15
|
+
|
|
16
|
+
export class NodeGraphCamera {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.position = new Vector2();
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @type {Vector1}
|
|
22
|
+
*/
|
|
23
|
+
this.scale = new Vector1(1);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const v2 = new Vector2();
|
|
28
|
+
|
|
29
|
+
const CONNECTION_WIDTH = 3;
|
|
30
|
+
const PORT_BEND_OFFSET_X = 100;
|
|
31
|
+
|
|
32
|
+
export class NodeGraphView extends View {
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param {NodeGraph} graph
|
|
36
|
+
* @param {NodeGraphVisualData} visual
|
|
37
|
+
* @param {NodeGraphCamera} camera
|
|
38
|
+
* @param {NodeDescriptionVisualRegistry} nodeVisualRegistry
|
|
39
|
+
*/
|
|
40
|
+
constructor({ graph, visual, camera, nodeVisualRegistry }) {
|
|
41
|
+
super();
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
*
|
|
45
|
+
* @type {NodeGraphCamera}
|
|
46
|
+
*/
|
|
47
|
+
this.camera = camera;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @type {NodeGraph}
|
|
52
|
+
*/
|
|
53
|
+
this.graph = graph;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @type {NodeGraphVisualData}
|
|
58
|
+
*/
|
|
59
|
+
this.visual = visual;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @type {List<number>}
|
|
64
|
+
*/
|
|
65
|
+
this.selection = new List();
|
|
66
|
+
|
|
67
|
+
this.el = document.createElement('div');
|
|
68
|
+
|
|
69
|
+
this.addClass('ui-node-graph-view');
|
|
70
|
+
|
|
71
|
+
const tempConnection = {
|
|
72
|
+
enabled: false,
|
|
73
|
+
anchor: new Vector2(),
|
|
74
|
+
endpoint: null
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const vBlockCanvas = new ListView(graph.nodes, {
|
|
78
|
+
classList: ['block-canvas'],
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @param {NodeInstance} node
|
|
82
|
+
* @returns {View}
|
|
83
|
+
*/
|
|
84
|
+
elementFactory(node) {
|
|
85
|
+
let nodeVisualData = visual.getNode(node.id);
|
|
86
|
+
|
|
87
|
+
if (nodeVisualData === undefined) {
|
|
88
|
+
const vd0 = nodeVisualRegistry.get(node.description.id);
|
|
89
|
+
|
|
90
|
+
if (vd0 === undefined) {
|
|
91
|
+
throw new Error(`Node (name='${node.description.name}', id=${node.description.id}) not found in registry`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const vd1 = vd0.clone();
|
|
95
|
+
|
|
96
|
+
vd1.id = node.id;
|
|
97
|
+
|
|
98
|
+
visual.addNode(node.id, vd1);
|
|
99
|
+
|
|
100
|
+
nodeVisualData = vd1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
const nodeView = new NodeView({
|
|
104
|
+
node,
|
|
105
|
+
visual: nodeVisualData,
|
|
106
|
+
visualData: visual,
|
|
107
|
+
portCreationCallback(portView, port) {
|
|
108
|
+
|
|
109
|
+
const draggableAspect = new DraggableAspect({
|
|
110
|
+
el: portView.el,
|
|
111
|
+
dragStart(p) {
|
|
112
|
+
|
|
113
|
+
const endpoint = new NodeInstancePortReference();
|
|
114
|
+
|
|
115
|
+
endpoint.set(node, port);
|
|
116
|
+
|
|
117
|
+
tempConnection.enabled = true;
|
|
118
|
+
tempConnection.endpoint = endpoint;
|
|
119
|
+
|
|
120
|
+
},
|
|
121
|
+
dragEnd() {
|
|
122
|
+
tempConnection.enabled = false;
|
|
123
|
+
|
|
124
|
+
vConnectionCanvas.render();
|
|
125
|
+
},
|
|
126
|
+
drag(p, o) {
|
|
127
|
+
const scale = camera.scale.getValue();
|
|
128
|
+
tempConnection.anchor.set(
|
|
129
|
+
(p.x / scale + camera.position.x),
|
|
130
|
+
(p.y / scale + camera.position.y)
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
vConnectionCanvas.render();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
draggableAspect.getPointer().on.up.add(() => {
|
|
138
|
+
//pointer released above the port
|
|
139
|
+
|
|
140
|
+
if (tempConnection.enabled) {
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* @type {NodeInstancePortReference}
|
|
144
|
+
*/
|
|
145
|
+
const endpoint = tempConnection.endpoint;
|
|
146
|
+
|
|
147
|
+
const endpointPort = endpoint.port;
|
|
148
|
+
|
|
149
|
+
if (endpointPort === port) {
|
|
150
|
+
//can't connect port to itself
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (endpointPort.direction === port.direction) {
|
|
155
|
+
//can't connect ports of teh same directionality
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const dataType = endpointPort.dataType;
|
|
160
|
+
|
|
161
|
+
//check that the port types match
|
|
162
|
+
if (port.dataType === dataType) {
|
|
163
|
+
|
|
164
|
+
if (endpointPort.direction === PortDirection.Out) {
|
|
165
|
+
graph.createConnection(endpoint.instance.id, endpointPort.id, node.id, port.id);
|
|
166
|
+
} else {
|
|
167
|
+
graph.createConnection(node.id, port.id, endpoint.instance.id, endpointPort.id);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
portView.on.linked.add(draggableAspect.start, draggableAspect);
|
|
175
|
+
portView.on.unlinked.add(draggableAspect.stop, draggableAspect);
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
nodeView.bindSignal(nodeView.position.onChanged, vConnectionCanvas.render, vConnectionCanvas);
|
|
181
|
+
|
|
182
|
+
return nodeView;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
this.addChild(vBlockCanvas);
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
//create canvas to draw connections on
|
|
190
|
+
const vConnectionCanvas = new AutoCanvasView({
|
|
191
|
+
classList: ['connection-canvas']
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
const v2_source = new Vector2();
|
|
195
|
+
const v2_target = new Vector2();
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
*
|
|
199
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
200
|
+
* @param width
|
|
201
|
+
* @param height
|
|
202
|
+
*/
|
|
203
|
+
vConnectionCanvas.draw = (ctx, width, height) => {
|
|
204
|
+
ctx.clearRect(0, 0, width, height);
|
|
205
|
+
|
|
206
|
+
ctx.lineWidth = max2(1, CONNECTION_WIDTH * camera.scale.getValue());
|
|
207
|
+
ctx.lineCap = 'round';
|
|
208
|
+
|
|
209
|
+
//draw connections
|
|
210
|
+
graph.connections.forEach(connection => {
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
const source = connection.source;
|
|
214
|
+
const target = connection.target;
|
|
215
|
+
|
|
216
|
+
this.getEndpointGraphPosition(source, v2_source);
|
|
217
|
+
|
|
218
|
+
this.getEndpointGraphPosition(target, v2_target);
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
this.drawConnection(ctx, v2_source, v2_target, source.port.dataType);
|
|
222
|
+
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
//draw temp connection
|
|
226
|
+
|
|
227
|
+
if (tempConnection.enabled) {
|
|
228
|
+
/**
|
|
229
|
+
*
|
|
230
|
+
* @type {NodeInstancePortReference}
|
|
231
|
+
*/
|
|
232
|
+
const endpoint = tempConnection.endpoint;
|
|
233
|
+
|
|
234
|
+
this.getEndpointGraphPosition(endpoint, v2_source);
|
|
235
|
+
const dataType = endpoint.port.dataType;
|
|
236
|
+
if (endpoint.port.direction === PortDirection.Out) {
|
|
237
|
+
this.drawConnection(ctx, v2_source, tempConnection.anchor, dataType);
|
|
238
|
+
} else {
|
|
239
|
+
this.drawConnection(ctx, tempConnection.anchor, v2_source, dataType);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
this.addChild(vConnectionCanvas);
|
|
245
|
+
|
|
246
|
+
this.size.onChanged.add((x, y) => {
|
|
247
|
+
vConnectionCanvas.size.set(x, y);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
function onCameraChange() {
|
|
251
|
+
const scale = camera.scale.getValue();
|
|
252
|
+
const p = camera.position;
|
|
253
|
+
|
|
254
|
+
vBlockCanvas.scale.setScalar(scale);
|
|
255
|
+
vBlockCanvas.position.set(-p.x * scale, -p.y * scale);
|
|
256
|
+
|
|
257
|
+
vConnectionCanvas.render();
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
this.initializeNavigationControls();
|
|
261
|
+
|
|
262
|
+
this.on.linked.add(onCameraChange);
|
|
263
|
+
this.bindSignal(camera.position.onChanged, onCameraChange);
|
|
264
|
+
this.bindSignal(camera.scale.onChanged, onCameraChange);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
initializeNavigationControls() {
|
|
268
|
+
const cameraPosition = new Vector2();
|
|
269
|
+
const camera = this.camera;
|
|
270
|
+
|
|
271
|
+
const canvasSize = this.size;
|
|
272
|
+
|
|
273
|
+
const draggableAspect = new DraggableAspect({
|
|
274
|
+
el: this.el,
|
|
275
|
+
dragStart() {
|
|
276
|
+
cameraPosition.copy(camera.position)
|
|
277
|
+
},
|
|
278
|
+
drag(p, o) {
|
|
279
|
+
const d = o.clone();
|
|
280
|
+
|
|
281
|
+
d.sub(p);
|
|
282
|
+
d.multiplyScalar(1 / camera.scale.getValue());
|
|
283
|
+
|
|
284
|
+
d.add(cameraPosition);
|
|
285
|
+
|
|
286
|
+
camera.position.copy(d);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
draggableAspect.getPointer().on.wheel.add((delta, position) => {
|
|
291
|
+
const scaleDelta = -delta.y / 20;
|
|
292
|
+
const oldScale = camera.scale.getValue();
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
const v = (1 + scaleDelta) * oldScale;
|
|
296
|
+
const newScale = clamp(v, .03, 4);
|
|
297
|
+
|
|
298
|
+
const actualScaleDelta = newScale / oldScale - 1;
|
|
299
|
+
|
|
300
|
+
camera.scale.set(newScale);
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
const canvasSizeInGraphSpace = new Vector2();
|
|
304
|
+
canvasSizeInGraphSpace.copy(canvasSize);
|
|
305
|
+
canvasSizeInGraphSpace.divideScalar(newScale);
|
|
306
|
+
|
|
307
|
+
const selectionSizeDelta = new Vector2();
|
|
308
|
+
selectionSizeDelta.copy(canvasSizeInGraphSpace);
|
|
309
|
+
selectionSizeDelta.multiplyScalar(actualScaleDelta);
|
|
310
|
+
|
|
311
|
+
const graphCameraPosition = new Vector2();
|
|
312
|
+
this.transformPointGraph2Canvas(camera.position, graphCameraPosition);
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
const localOffset = position.clone().sub(graphCameraPosition);
|
|
316
|
+
|
|
317
|
+
const normalizedOffset = localOffset.clone();
|
|
318
|
+
normalizedOffset.divide(canvasSize);
|
|
319
|
+
|
|
320
|
+
const positionDelta = selectionSizeDelta.clone();
|
|
321
|
+
positionDelta._multiply(normalizedOffset.x, normalizedOffset.y);
|
|
322
|
+
|
|
323
|
+
camera.position.add(positionDelta);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
this.on.linked.add(draggableAspect.start, draggableAspect);
|
|
327
|
+
this.on.unlinked.add(draggableAspect.stop, draggableAspect);
|
|
328
|
+
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
*
|
|
334
|
+
* @param x0
|
|
335
|
+
* @param y0
|
|
336
|
+
* @param x1
|
|
337
|
+
* @param y1
|
|
338
|
+
* @returns {boolean}
|
|
339
|
+
*/
|
|
340
|
+
isGraphAABBVisible(x0, y0, x1, y1) {
|
|
341
|
+
|
|
342
|
+
const scale = this.camera.scale.getValue();
|
|
343
|
+
const cp = this.camera.position;
|
|
344
|
+
|
|
345
|
+
//transform graph-space to canvas-space
|
|
346
|
+
const _x0 = (x0 - cp.x) * scale;
|
|
347
|
+
const _y0 = (y0 - cp.y) * scale;
|
|
348
|
+
const _x1 = (x1 - cp.x) * scale;
|
|
349
|
+
const _y1 = (y1 - cp.y) * scale;
|
|
350
|
+
|
|
351
|
+
return _x0 < this.size.x && _x1 > 0 && _y0 < this.size.y && _y1 > 0;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
*
|
|
356
|
+
* @param {CanvasRenderingContext2D} ctx
|
|
357
|
+
* @param {Vector2} source
|
|
358
|
+
* @param {Vector2} target
|
|
359
|
+
* @param {DataType} dataType
|
|
360
|
+
*/
|
|
361
|
+
drawConnection(ctx, source, target, dataType) {
|
|
362
|
+
//check that the connection is visible
|
|
363
|
+
const cw_2 = (CONNECTION_WIDTH / 2);
|
|
364
|
+
|
|
365
|
+
const x0 = min2(source.x, target.x) - (cw_2 + PORT_BEND_OFFSET_X);
|
|
366
|
+
const y0 = min2(source.y, target.y) - cw_2;
|
|
367
|
+
const x1 = max2(source.x, target.x) + cw_2 + PORT_BEND_OFFSET_X;
|
|
368
|
+
const y1 = max2(source.y, target.y) + cw_2;
|
|
369
|
+
|
|
370
|
+
if (!this.isGraphAABBVisible(x0, y0, x1, y1)) {
|
|
371
|
+
//connection is not visible, don't draw
|
|
372
|
+
return;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
const cameraScale = this.camera.scale.getValue();
|
|
376
|
+
|
|
377
|
+
const alpha = clamp(lerp(0, 1, cameraScale * CONNECTION_WIDTH), 0, 1);
|
|
378
|
+
|
|
379
|
+
const dataColor = this.visual.getDataColor(dataType.id);
|
|
380
|
+
ctx.strokeStyle = `rgba(${dataColor.r * 255}, ${dataColor.g * 255}, ${dataColor.b * 255}, ${alpha})`;
|
|
381
|
+
|
|
382
|
+
ctx.beginPath();
|
|
383
|
+
|
|
384
|
+
this.transformPointGraph2Canvas(source, v2);
|
|
385
|
+
|
|
386
|
+
ctx.moveTo(v2.x, v2.y);
|
|
387
|
+
|
|
388
|
+
const cp1x = v2.x + PORT_BEND_OFFSET_X * cameraScale;
|
|
389
|
+
const cp1y = v2.y;
|
|
390
|
+
|
|
391
|
+
this.transformPointGraph2Canvas(target, v2);
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
const cp2x = v2.x - PORT_BEND_OFFSET_X * cameraScale;
|
|
395
|
+
const cp2y = v2.y;
|
|
396
|
+
|
|
397
|
+
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, v2.x, v2.y);
|
|
398
|
+
|
|
399
|
+
ctx.stroke();
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
*
|
|
404
|
+
* @param {NodeInstancePortReference} endpoint
|
|
405
|
+
* @param {Vector2} output
|
|
406
|
+
*/
|
|
407
|
+
getEndpointGraphPosition(endpoint, output) {
|
|
408
|
+
const instance = endpoint.instance;
|
|
409
|
+
|
|
410
|
+
const nodeVisualData = this.visual.getNode(instance.id);
|
|
411
|
+
|
|
412
|
+
const nodePosition = nodeVisualData.dimensions.position;
|
|
413
|
+
|
|
414
|
+
const portVisualData = nodeVisualData.getPort(endpoint.port.id);
|
|
415
|
+
|
|
416
|
+
const portPosition = portVisualData.position;
|
|
417
|
+
|
|
418
|
+
const x = nodePosition.x + portPosition.x;
|
|
419
|
+
const y = nodePosition.y + portPosition.y;
|
|
420
|
+
|
|
421
|
+
output.set(x, y);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Convert point from Graph coordinate space to Canvas coordinate space
|
|
426
|
+
* @param {Vector2} input
|
|
427
|
+
* @param {Vector2} output
|
|
428
|
+
*/
|
|
429
|
+
transformPointGraph2Canvas(input, output) {
|
|
430
|
+
const scale = this.camera.scale.getValue();
|
|
431
|
+
const p = this.camera.position;
|
|
432
|
+
|
|
433
|
+
const x = (input.x - p.x) * scale;
|
|
434
|
+
const y = (input.y - p.y) * scale;
|
|
435
|
+
|
|
436
|
+
output.set(x, y);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Convert point from Canvas coordinate space to Graph coordinate space
|
|
441
|
+
* @param {Vector2} input
|
|
442
|
+
* @param {Vector2} output
|
|
443
|
+
*/
|
|
444
|
+
transformPointCanvas2Graph(input, output) {
|
|
445
|
+
const scale = this.camera.scale.getValue();
|
|
446
|
+
const p = this.camera.position;
|
|
447
|
+
|
|
448
|
+
const x = (input.x / scale) + p.x;
|
|
449
|
+
const y = (input.y / scale) + p.y;
|
|
450
|
+
|
|
451
|
+
output.set(x, y);
|
|
452
|
+
}
|
|
453
|
+
}
|