@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.
Files changed (169) hide show
  1. package/editor/Editor.js +793 -0
  2. package/editor/SelectionVisualizer.js +148 -0
  3. package/editor/actions/concrete/ActionUpdateTexture.js +21 -0
  4. package/editor/actions/concrete/ArrayCopyAction.js +39 -0
  5. package/editor/actions/concrete/ComponentAddAction.js +47 -0
  6. package/editor/actions/concrete/ComponentRemoveAction.js +38 -0
  7. package/editor/actions/concrete/EntityCreateAction.js +47 -0
  8. package/editor/actions/concrete/EntityRemoveAction.js +51 -0
  9. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +118 -0
  10. package/editor/actions/concrete/ModifyPatchSampler2DAction.spec.js +30 -0
  11. package/editor/actions/concrete/ModifyPatchTextureArray2DAction.js +182 -0
  12. package/editor/actions/concrete/PaintTerrainOverlayAction.js +45 -0
  13. package/editor/actions/concrete/PatchTerrainHeightAction.js +67 -0
  14. package/editor/actions/concrete/PatchTerrainTextureAction.js +152 -0
  15. package/editor/actions/concrete/SelectionAddAction.js +36 -0
  16. package/editor/actions/concrete/SelectionClearAction.js +22 -0
  17. package/editor/actions/concrete/SelectionRemoveAction.js +30 -0
  18. package/editor/actions/concrete/TransformModifyAction.js +46 -0
  19. package/editor/actions/concrete/WriteGridValueAction.js +46 -0
  20. package/editor/ecs/EditorEntity.js +12 -0
  21. package/editor/ecs/EditorEntitySystem.js +14 -0
  22. package/editor/ecs/component/FieldDescriptor.js +34 -0
  23. package/editor/ecs/component/FieldValueAdapter.js +20 -0
  24. package/editor/ecs/component/TypeEditor.js +33 -0
  25. package/editor/ecs/component/TypeSchema.d.ts +38 -0
  26. package/editor/ecs/component/createFieldEditor.js +92 -0
  27. package/editor/ecs/component/createObjectEditor.js +361 -0
  28. package/editor/ecs/component/editors/ColorEditor.js +39 -0
  29. package/editor/ecs/component/editors/HTMLElementEditor.js +17 -0
  30. package/editor/ecs/component/editors/ImagePathEditor.js +82 -0
  31. package/editor/ecs/component/editors/LargeStrongEditor.js +107 -0
  32. package/editor/ecs/component/editors/NumericIntervalEditor.js +86 -0
  33. package/editor/ecs/component/editors/ObservedBooleanEditor.js +13 -0
  34. package/editor/ecs/component/editors/ObservedEnumEditor.js +32 -0
  35. package/editor/ecs/component/editors/ObservedIntegerEditor.js +43 -0
  36. package/editor/ecs/component/editors/ObservedStringEditor.js +51 -0
  37. package/editor/ecs/component/editors/Sampler2DEditor.js +221 -0
  38. package/editor/ecs/component/editors/collection/ListEditor.js +83 -0
  39. package/editor/ecs/component/editors/common/BitFlagsEditor.js +80 -0
  40. package/editor/ecs/component/editors/common/EnumEditor.js +41 -0
  41. package/editor/ecs/component/editors/common/makeV3_editor.js +85 -0
  42. package/editor/ecs/component/editors/common/noEditor.js +9 -0
  43. package/editor/ecs/component/editors/ecs/GridObstacleEditor.js +17 -0
  44. package/editor/ecs/component/editors/ecs/MinimapMarkerEditor.js +16 -0
  45. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +225 -0
  46. package/editor/ecs/component/editors/ecs/ParameterTrackEditor.js +17 -0
  47. package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +18 -0
  48. package/editor/ecs/component/editors/ecs/ParticleEmitterEditor.js +58 -0
  49. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +58 -0
  50. package/editor/ecs/component/editors/ecs/SimulationStepDefinitionEditor.js +21 -0
  51. package/editor/ecs/component/editors/ecs/Trail2DEditor.js +33 -0
  52. package/editor/ecs/component/editors/ecs/TransformEditor.js +23 -0
  53. package/editor/ecs/component/editors/ecs/terrain/SplatMappingEditor.js +21 -0
  54. package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +95 -0
  55. package/editor/ecs/component/editors/ecs/terrain/TerrainLayerEditor.js +18 -0
  56. package/editor/ecs/component/editors/ecs/terrain/TerrainLayersEditor.js +22 -0
  57. package/editor/ecs/component/editors/ecs/terrain/TerrainOverlayEditor.js +20 -0
  58. package/editor/ecs/component/editors/geom/QuaternionEditor.js +63 -0
  59. package/editor/ecs/component/editors/geom/Vector1Editor.js +57 -0
  60. package/editor/ecs/component/editors/geom/Vector2Editor.js +11 -0
  61. package/editor/ecs/component/editors/geom/Vector3Editor.js +13 -0
  62. package/editor/ecs/component/editors/geom/Vector4Editor.js +12 -0
  63. package/editor/ecs/component/editors/primitive/ArrayEditor.js +46 -0
  64. package/editor/ecs/component/editors/primitive/BooleanEditor.js +27 -0
  65. package/editor/ecs/component/editors/primitive/FunctionEditor.js +29 -0
  66. package/editor/ecs/component/editors/primitive/NumberEditor.js +60 -0
  67. package/editor/ecs/component/editors/primitive/ObjectEditor.js +12 -0
  68. package/editor/ecs/component/editors/primitive/StringEditor.js +31 -0
  69. package/editor/ecs/component/editors/three/BufferGeometryEditor.js +28 -0
  70. package/editor/ecs/component/editors/three/MaterialEditor.js +27 -0
  71. package/editor/ecs/component/editors/three/MeshEditor.js +35 -0
  72. package/editor/ecs/component/editors/three/TextureEditor.js +112 -0
  73. package/editor/ecs/component/findNearestRegisteredType.js +59 -0
  74. package/editor/ecs/component/prototypeObjectEditor.js +379 -0
  75. package/editor/enableEditor.js +85 -0
  76. package/editor/library/MeshLibrary.js +33 -0
  77. package/editor/process/DisableGameUIProcess.js +43 -0
  78. package/editor/process/EditorProcess.js +35 -0
  79. package/editor/process/ObstacleGridDisplayProcess.js +120 -0
  80. package/editor/process/ProcessEngine.js +123 -0
  81. package/editor/process/SymbolicDisplayProcess.js +132 -0
  82. package/editor/process/symbolic/ComponentSymbolicDisplay.js +34 -0
  83. package/editor/process/symbolic/SymbolicDisplayInternalAPI.js +159 -0
  84. package/editor/process/symbolic/buildThreeJSHelperEntity.js +36 -0
  85. package/editor/process/symbolic/make3DSymbolicDisplay.js +91 -0
  86. package/editor/process/symbolic/makeCameraSymbolicDisplay.js +32 -0
  87. package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +176 -0
  88. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  89. package/editor/process/symbolic/makeHelperSphereGeometry.js +73 -0
  90. package/editor/process/symbolic/makeLightSymbolicDisplay.js +77 -0
  91. package/editor/process/symbolic/makeParticleEmitterSymbolicDisplay.js +146 -0
  92. package/editor/process/symbolic/makePathSymbolicDisplay.js +105 -0
  93. package/editor/process/symbolic/makePositionedIconDisplaySymbol.js +74 -0
  94. package/editor/process/symbolic/makeSocketsSymbolicDisplay.js +153 -0
  95. package/editor/process/symbolic/makeSolidArrowGeometry.js +391 -0
  96. package/editor/process/symbolic/makeSoundEmitterSymbolicDisplay.js +89 -0
  97. package/editor/process/symbolic/makeStoryTriggerSetAreaDisplay.js +114 -0
  98. package/editor/process/symbolic/synchronizeTransform.js +50 -0
  99. package/editor/tools/FoliagePaintTool.js +168 -0
  100. package/editor/tools/GridPaintTool.js +247 -0
  101. package/editor/tools/SelectionTool.js +407 -0
  102. package/editor/tools/TopDownCameraControlTool.js +59 -0
  103. package/editor/tools/TransformTool.js +370 -0
  104. package/editor/tools/engine/Tool.js +121 -0
  105. package/editor/tools/engine/ToolEngine.js +193 -0
  106. package/editor/tools/engine/ToolState.js +9 -0
  107. package/editor/tools/engine/ToolStateMachine.js +53 -0
  108. package/editor/tools/paint/TerrainHeightPaintTool.js +297 -0
  109. package/editor/tools/paint/TerrainPaintTool.js +211 -0
  110. package/editor/tools/paint/TerrainTexturePaintTool.js +193 -0
  111. package/editor/tools/paint/prototypeTerrainEditor.js +135 -0
  112. package/editor/tools/v2/BlenderCameraOrientationGizmo.d.ts +50 -0
  113. package/editor/tools/v2/BlenderCameraOrientationGizmo.js +500 -0
  114. package/editor/tools/v2/TransformControls.d.ts +20 -0
  115. package/editor/tools/v2/TransformControls.js +1782 -0
  116. package/editor/tools/v2/prototypeTransformControls.js +92 -0
  117. package/editor/view/EditorView.js +462 -0
  118. package/editor/view/GridPickCoordinateView.js +88 -0
  119. package/editor/view/ecs/ComponentControlFactory.js +48 -0
  120. package/editor/view/ecs/ComponentControlView.js +214 -0
  121. package/editor/view/ecs/EntityEditor.js +258 -0
  122. package/editor/view/ecs/EntityList.js +258 -0
  123. package/editor/view/ecs/components/BlackboardController.js +50 -0
  124. package/editor/view/ecs/components/DatGuiController.js +216 -0
  125. package/editor/view/ecs/components/FogOfWarController.js +78 -0
  126. package/editor/view/ecs/components/FogOfWarRevealerController.js +44 -0
  127. package/editor/view/ecs/components/GeneratedArmyController.js +42 -0
  128. package/editor/view/ecs/components/GridObstacleController.js +72 -0
  129. package/editor/view/ecs/components/GridPositionController.js +40 -0
  130. package/editor/view/ecs/components/HeadsUpDisplayController.js +30 -0
  131. package/editor/view/ecs/components/HighlightController.js +47 -0
  132. package/editor/view/ecs/components/MeshController.js +125 -0
  133. package/editor/view/ecs/components/PathFollowerController.js +87 -0
  134. package/editor/view/ecs/components/TagController.js +80 -0
  135. package/editor/view/ecs/components/TerrainController.js +225 -0
  136. package/editor/view/ecs/components/TransformController.js +103 -0
  137. package/editor/view/ecs/components/UnitShopController.js +112 -0
  138. package/editor/view/ecs/components/army/ArmyController.js +130 -0
  139. package/editor/view/ecs/components/color/GaugeView.js +107 -0
  140. package/editor/view/ecs/components/common/AutoCanvasView.js +53 -0
  141. package/editor/view/ecs/components/common/LineView.js +17 -0
  142. package/editor/view/ecs/components/common/NumberController.js +112 -0
  143. package/editor/view/ecs/components/common/NumericIntervalController.js +64 -0
  144. package/editor/view/ecs/components/gui/GUIElementController.js +117 -0
  145. package/editor/view/ecs/components/items/ItemContainerController.js +132 -0
  146. package/editor/view/ecs/components/items/ItemContainerController.stories.js +50 -0
  147. package/editor/view/ecs/components/items/ItemController.js +52 -0
  148. package/editor/view/ecs/components/particles/ColorParameterLUTController.js +444 -0
  149. package/editor/view/ecs/components/particles/ParameterTrackController.js +51 -0
  150. package/editor/view/ecs/components/particles/ParticleEmitterController.js +213 -0
  151. package/editor/view/ecs/components/particles/ParticleLayerController.js +213 -0
  152. package/editor/view/ecs/components/particles/ScalarParameterLUTController.js +401 -0
  153. package/editor/view/ecs/components/sockets/AttachmentSocketsController.js +51 -0
  154. package/editor/view/ecs/components/sound/SoundEmitterController.js +137 -0
  155. package/editor/view/ecs/components/story/StoryTriggerSetController.js +214 -0
  156. package/editor/view/ecs/components/unit/AuraController.js +45 -0
  157. package/editor/view/library/MeshLibraryView.js +164 -0
  158. package/editor/view/node-graph/NodeGraphEditorView.js +170 -0
  159. package/editor/view/node-graph/NodeGraphView.js +453 -0
  160. package/editor/view/node-graph/NodeView.js +135 -0
  161. package/editor/view/node-graph/PortView.js +69 -0
  162. package/editor/view/process/ProcessView.js +63 -0
  163. package/editor/view/tools/ToolSettingsView.js +143 -0
  164. package/editor/view/tools/ToolView.js +58 -0
  165. package/package.json +2 -1
  166. package/src/engine/intelligence/behavior/composite/CompositeBehavior.js +18 -2
  167. package/src/engine/intelligence/behavior/composite/ParallelBehavior.js +21 -9
  168. package/src/engine/intelligence/behavior/composite/SequenceBehavior.js +5 -1
  169. 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
+ }