@onerjs/core 8.44.7 → 8.44.9
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/Bones/skeleton.d.ts +5 -0
- package/Bones/skeleton.js +35 -8
- package/Bones/skeleton.js.map +1 -1
- package/Collisions/collider.js +2 -2
- package/Collisions/collider.js.map +1 -1
- package/Culling/Helper/computeShaderBoundingHelper.js +8 -1
- package/Culling/Helper/computeShaderBoundingHelper.js.map +1 -1
- package/Culling/Helper/transformFeedbackBoundingHelper.js +1 -1
- package/Culling/Helper/transformFeedbackBoundingHelper.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessingContext.d.ts +1 -0
- package/Engines/WebGPU/webgpuShaderProcessingContext.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessor.d.ts +1 -1
- package/Engines/WebGPU/webgpuShaderProcessor.js +2 -2
- package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js +20 -2
- package/Engines/WebGPU/webgpuShaderProcessorsWGSL.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.d.ts +2 -1
- package/Engines/engineCapabilities.d.ts +2 -0
- package/Engines/engineCapabilities.js.map +1 -1
- package/Engines/nullEngine.js +1 -0
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.js +1 -0
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/thinNativeEngine.js +1 -0
- package/Engines/thinNativeEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +1 -0
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphDebugBlock.d.ts +45 -0
- package/FlowGraph/Blocks/Data/flowGraphDebugBlock.js +98 -0
- package/FlowGraph/Blocks/Data/flowGraphDebugBlock.js.map +1 -0
- package/FlowGraph/Blocks/Data/flowGraphGetPropertyBlock.d.ts +16 -0
- package/FlowGraph/Blocks/Data/flowGraphGetPropertyBlock.js +15 -2
- package/FlowGraph/Blocks/Data/flowGraphGetPropertyBlock.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphPointerDownEventBlock.d.ts +64 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerDownEventBlock.js +54 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerDownEventBlock.js.map +1 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerMoveEventBlock.d.ts +64 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerMoveEventBlock.js +54 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerMoveEventBlock.js.map +1 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerUpEventBlock.d.ts +64 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerUpEventBlock.js +54 -0
- package/FlowGraph/Blocks/Event/flowGraphPointerUpEventBlock.js.map +1 -0
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.d.ts +1 -0
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js +17 -1
- package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.d.ts +1 -0
- package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.js +23 -3
- package/FlowGraph/Blocks/Event/flowGraphSendCustomEventBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphInterpolationBlock.js +2 -2
- package/FlowGraph/Blocks/Execution/Animation/flowGraphInterpolationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js +7 -1
- package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.d.ts +4 -0
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js +6 -2
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.js +2 -2
- package/FlowGraph/Blocks/Execution/flowGraphSetPropertyBlock.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.js +0 -4
- package/FlowGraph/Blocks/Execution/flowGraphSetVariableBlock.js.map +1 -1
- package/FlowGraph/Blocks/flowGraphBlockFactory.js +16 -0
- package/FlowGraph/Blocks/flowGraphBlockFactory.js.map +1 -1
- package/FlowGraph/Blocks/flowGraphBlockNames.d.ts +2 -1
- package/FlowGraph/Blocks/flowGraphBlockNames.js +1 -0
- package/FlowGraph/Blocks/flowGraphBlockNames.js.map +1 -1
- package/FlowGraph/flowGraph.d.ts +63 -2
- package/FlowGraph/flowGraph.js +210 -19
- package/FlowGraph/flowGraph.js.map +1 -1
- package/FlowGraph/flowGraphContext.d.ts +73 -0
- package/FlowGraph/flowGraphContext.js +115 -0
- package/FlowGraph/flowGraphContext.js.map +1 -1
- package/FlowGraph/flowGraphExecutionBlock.d.ts +7 -0
- package/FlowGraph/flowGraphExecutionBlock.js +7 -0
- package/FlowGraph/flowGraphExecutionBlock.js.map +1 -1
- package/FlowGraph/flowGraphParser.js +1 -0
- package/FlowGraph/flowGraphParser.js.map +1 -1
- package/FlowGraph/flowGraphSceneEventCoordinator.d.ts +3 -0
- package/FlowGraph/flowGraphSceneEventCoordinator.js +13 -1
- package/FlowGraph/flowGraphSceneEventCoordinator.js.map +1 -1
- package/FlowGraph/flowGraphSignalConnection.d.ts +5 -0
- package/FlowGraph/flowGraphSignalConnection.js +12 -0
- package/FlowGraph/flowGraphSignalConnection.js.map +1 -1
- package/FlowGraph/flowGraphValidator.d.ts +66 -0
- package/FlowGraph/flowGraphValidator.js +324 -0
- package/FlowGraph/flowGraphValidator.js.map +1 -0
- package/FlowGraph/index.d.ts +1 -0
- package/FlowGraph/index.js +1 -0
- package/FlowGraph/index.js.map +1 -1
- package/FlowGraph/serialization.js +10 -3
- package/FlowGraph/serialization.js.map +1 -1
- package/Layers/thinEffectLayer.js +1 -1
- package/Layers/thinEffectLayer.js.map +1 -1
- package/Layers/thinSelectionOutlineLayer.js +1 -1
- package/Layers/thinSelectionOutlineLayer.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.js +1 -1
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Materials/Node/Blocks/Vertex/bonesBlock.js +2 -2
- package/Materials/Node/Blocks/Vertex/bonesBlock.js.map +1 -1
- package/Materials/PBR/openpbrMaterial.js +1 -1
- package/Materials/PBR/openpbrMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +1 -1
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/materialHelper.functions.js +2 -2
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/materialHelper.geometryrendering.js +1 -1
- package/Materials/materialHelper.geometryrendering.js.map +1 -1
- package/Materials/standardMaterial.js +1 -1
- package/Materials/standardMaterial.js.map +1 -1
- package/Meshes/mesh.js +2 -2
- package/Meshes/mesh.js.map +1 -1
- package/Misc/bitArray.js +1 -1
- package/Misc/bitArray.js.map +1 -1
- package/Misc/tools.js +3 -3
- package/Misc/tools.js.map +1 -1
- package/Particles/thinParticleSystem.js +2 -2
- package/Particles/thinParticleSystem.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Rendering/depthRenderer.js +1 -1
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +3 -3
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/outlineRenderer.js +1 -1
- package/Rendering/outlineRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/bonesDeclaration.js +5 -7
- package/Shaders/ShadersInclude/bonesDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/bonesDeclaration.js +3 -3
- package/ShadersWGSL/ShadersInclude/bonesDeclaration.js.map +1 -1
- package/ShadersWGSL/boundingInfo.compute.js +4 -3
- package/ShadersWGSL/boundingInfo.compute.js.map +1 -1
- package/package.json +1 -1
package/FlowGraph/flowGraph.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { Observable } from "../Misc/observable.js";
|
|
2
2
|
import { FlowGraphContext } from "./flowGraphContext.js";
|
|
3
3
|
import { FlowGraphExecutionBlock } from "./flowGraphExecutionBlock.js";
|
|
4
|
+
import { FlowGraphAsyncExecutionBlock } from "./flowGraphAsyncExecutionBlock.js";
|
|
4
5
|
import { FlowGraphSceneEventCoordinator } from "./flowGraphSceneEventCoordinator.js";
|
|
5
6
|
import { _IsDescendantOf } from "./utils.js";
|
|
7
|
+
import { ValidateFlowGraphWithBlockList } from "./flowGraphValidator.js";
|
|
6
8
|
export var FlowGraphState;
|
|
7
9
|
(function (FlowGraphState) {
|
|
8
10
|
/**
|
|
@@ -13,6 +15,10 @@ export var FlowGraphState;
|
|
|
13
15
|
* The graph is running
|
|
14
16
|
*/
|
|
15
17
|
FlowGraphState[FlowGraphState["Started"] = 1] = "Started";
|
|
18
|
+
/**
|
|
19
|
+
* The graph is paused (contexts kept, pending tasks cancelled)
|
|
20
|
+
*/
|
|
21
|
+
FlowGraphState[FlowGraphState["Paused"] = 2] = "Paused";
|
|
16
22
|
})(FlowGraphState || (FlowGraphState = {}));
|
|
17
23
|
/**
|
|
18
24
|
* Class used to represent a flow graph.
|
|
@@ -23,6 +29,12 @@ export var FlowGraphState;
|
|
|
23
29
|
* @experimental FlowGraph is still in development and is subject to change.
|
|
24
30
|
*/
|
|
25
31
|
export class FlowGraph {
|
|
32
|
+
/**
|
|
33
|
+
* The scene associated with this flow graph.
|
|
34
|
+
*/
|
|
35
|
+
get scene() {
|
|
36
|
+
return this._scene;
|
|
37
|
+
}
|
|
26
38
|
/**
|
|
27
39
|
* The state of the graph
|
|
28
40
|
*/
|
|
@@ -59,6 +71,11 @@ export class FlowGraph {
|
|
|
59
71
|
["SceneAfterRender" /* FlowGraphEventType.SceneAfterRender */]: [],
|
|
60
72
|
["NoTrigger" /* FlowGraphEventType.NoTrigger */]: [],
|
|
61
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* All blocks that belong to this graph, including unreachable ones.
|
|
76
|
+
* @internal
|
|
77
|
+
*/
|
|
78
|
+
this._allBlocks = [];
|
|
62
79
|
this._executionContexts = [];
|
|
63
80
|
/**
|
|
64
81
|
* The state of the graph
|
|
@@ -67,7 +84,19 @@ export class FlowGraph {
|
|
|
67
84
|
this._scene = params.scene;
|
|
68
85
|
this._sceneEventCoordinator = new FlowGraphSceneEventCoordinator(this._scene);
|
|
69
86
|
this._coordinator = params.coordinator;
|
|
87
|
+
}
|
|
88
|
+
_attachEventObserver() {
|
|
89
|
+
if (this._eventObserver) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
70
92
|
this._eventObserver = this._sceneEventCoordinator.onEventTriggeredObservable.add((event) => {
|
|
93
|
+
if (event.type === "SceneDispose" /* FlowGraphEventType.SceneDispose */) {
|
|
94
|
+
this.dispose();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (this.state !== 1 /* FlowGraphState.Started */) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
71
100
|
for (const context of this._executionContexts) {
|
|
72
101
|
const order = this._getContextualOrder(event.type, context);
|
|
73
102
|
for (const block of order) {
|
|
@@ -87,12 +116,42 @@ export class FlowGraph {
|
|
|
87
116
|
context._notifyOnTick(event.payload);
|
|
88
117
|
}
|
|
89
118
|
break;
|
|
90
|
-
case "SceneDispose" /* FlowGraphEventType.SceneDispose */:
|
|
91
|
-
this.dispose();
|
|
92
|
-
break;
|
|
93
119
|
}
|
|
94
120
|
});
|
|
95
121
|
}
|
|
122
|
+
_detachEventObserver() {
|
|
123
|
+
this._eventObserver?.remove();
|
|
124
|
+
this._eventObserver = null;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Sets a new scene for this flow graph, re-wiring all event listeners.
|
|
128
|
+
* This is useful when the scene the flow graph should listen to changes
|
|
129
|
+
* (e.g. when a new scene is loaded in an editor preview).
|
|
130
|
+
* If the graph is currently running, it will be stopped first and must be
|
|
131
|
+
* restarted manually after calling this method.
|
|
132
|
+
* @param scene the new scene to attach to
|
|
133
|
+
*/
|
|
134
|
+
setScene(scene) {
|
|
135
|
+
if (scene === this._scene) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (this.state === 1 /* FlowGraphState.Started */) {
|
|
139
|
+
this.stop();
|
|
140
|
+
}
|
|
141
|
+
// Tear down old event coordinator
|
|
142
|
+
this._detachEventObserver();
|
|
143
|
+
this._sceneEventCoordinator.dispose();
|
|
144
|
+
// Rebuild with the new scene
|
|
145
|
+
this._scene = scene;
|
|
146
|
+
this._scene.constantlyUpdateMeshUnderPointer = true; // ensure pointer info is always up to date for event blocks that need it
|
|
147
|
+
this._sceneEventCoordinator = new FlowGraphSceneEventCoordinator(this._scene);
|
|
148
|
+
// Pre-attach the event observer so that events from the new
|
|
149
|
+
// coordinator are routed to the graph immediately. The handler
|
|
150
|
+
// guards against processing events while the graph is stopped,
|
|
151
|
+
// but having the observer in place ensures no events are lost
|
|
152
|
+
// when start() is called shortly after.
|
|
153
|
+
this._attachEventObserver();
|
|
154
|
+
}
|
|
96
155
|
/**
|
|
97
156
|
* Create a context. A context represents one self contained execution for the graph, with its own variables.
|
|
98
157
|
* @returns the context, where you can get and set variables
|
|
@@ -110,19 +169,82 @@ export class FlowGraph {
|
|
|
110
169
|
getContext(index) {
|
|
111
170
|
return this._executionContexts[index];
|
|
112
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Returns all blocks registered in this graph, including disconnected ones.
|
|
174
|
+
* @returns a read-only array of all blocks
|
|
175
|
+
*/
|
|
176
|
+
getAllBlocks() {
|
|
177
|
+
return this._allBlocks;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Register a block with the graph. This does not wire any connections;
|
|
181
|
+
* it simply ensures the block is tracked so that serialization, editor
|
|
182
|
+
* display, and validation see it even when it is not reachable from an
|
|
183
|
+
* event block.
|
|
184
|
+
* @param block the block to register
|
|
185
|
+
*/
|
|
186
|
+
addBlock(block) {
|
|
187
|
+
if (this._allBlocks.indexOf(block) === -1) {
|
|
188
|
+
this._allBlocks.push(block);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Remove a block from the graph. Disconnects all of its ports and, if it
|
|
193
|
+
* is an event block, unregisters it from the event-block lists.
|
|
194
|
+
* @param block the block to remove
|
|
195
|
+
*/
|
|
196
|
+
removeBlock(block) {
|
|
197
|
+
const idx = this._allBlocks.indexOf(block);
|
|
198
|
+
if (idx !== -1) {
|
|
199
|
+
this._allBlocks.splice(idx, 1);
|
|
200
|
+
}
|
|
201
|
+
// If it is an event block, remove from the event-block registry
|
|
202
|
+
if (block instanceof FlowGraphExecutionBlock && "type" in block) {
|
|
203
|
+
const eventBlock = block;
|
|
204
|
+
const list = this._eventBlocks[eventBlock.type];
|
|
205
|
+
if (list) {
|
|
206
|
+
const eIdx = list.indexOf(eventBlock);
|
|
207
|
+
if (eIdx !== -1) {
|
|
208
|
+
list.splice(eIdx, 1);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// If the block has pending async tasks (e.g. event subscriptions),
|
|
213
|
+
// cancel them in all active execution contexts so deletion takes
|
|
214
|
+
// effect immediately even while the graph is running.
|
|
215
|
+
if (block instanceof FlowGraphAsyncExecutionBlock) {
|
|
216
|
+
for (const context of this._executionContexts) {
|
|
217
|
+
block._cancelPendingTasks(context);
|
|
218
|
+
block._resetAfterCanceled(context);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Disconnect all ports
|
|
222
|
+
for (const input of block.dataInputs) {
|
|
223
|
+
input.disconnectFromAll();
|
|
224
|
+
}
|
|
225
|
+
for (const output of block.dataOutputs) {
|
|
226
|
+
output.disconnectFromAll();
|
|
227
|
+
}
|
|
228
|
+
if (block instanceof FlowGraphExecutionBlock) {
|
|
229
|
+
for (const signalIn of block.signalInputs) {
|
|
230
|
+
signalIn.disconnectFromAll();
|
|
231
|
+
}
|
|
232
|
+
for (const signalOut of block.signalOutputs) {
|
|
233
|
+
signalOut.disconnectFromAll();
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
113
237
|
/**
|
|
114
238
|
* Add an event block. When the graph is started, it will start listening to events
|
|
115
239
|
* from the block and execute the graph when they are triggered.
|
|
116
240
|
* @param block the event block to be added
|
|
117
241
|
*/
|
|
118
242
|
addEventBlock(block) {
|
|
243
|
+
this.addBlock(block);
|
|
119
244
|
if (block.type === "PointerOver" /* FlowGraphEventType.PointerOver */ || block.type === "PointerOut" /* FlowGraphEventType.PointerOut */) {
|
|
120
245
|
this._scene.constantlyUpdateMeshUnderPointer = true;
|
|
121
246
|
}
|
|
122
|
-
|
|
123
|
-
if (block.type !== "NoTrigger" /* FlowGraphEventType.NoTrigger */) {
|
|
124
|
-
this._eventBlocks[block.type].push(block);
|
|
125
|
-
}
|
|
247
|
+
this._eventBlocks[block.type].push(block);
|
|
126
248
|
// if already started, sort and add to the pending
|
|
127
249
|
if (this.state === 1 /* FlowGraphState.Started */) {
|
|
128
250
|
for (const context of this._executionContexts) {
|
|
@@ -139,26 +261,74 @@ export class FlowGraph {
|
|
|
139
261
|
});
|
|
140
262
|
}
|
|
141
263
|
}
|
|
264
|
+
/**
|
|
265
|
+
* Stops the flow graph. Cancels all pending tasks and clears execution contexts,
|
|
266
|
+
* but keeps event blocks so the graph can be restarted.
|
|
267
|
+
*/
|
|
268
|
+
stop() {
|
|
269
|
+
if (this.state === 0 /* FlowGraphState.Stopped */) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
this._detachEventObserver();
|
|
273
|
+
this.state = 0 /* FlowGraphState.Stopped */;
|
|
274
|
+
for (const context of this._executionContexts) {
|
|
275
|
+
context._clearPendingBlocks();
|
|
276
|
+
context._clearPendingActivation();
|
|
277
|
+
}
|
|
278
|
+
this._executionContexts.length = 0;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Pauses the flow graph. Cancels pending tasks but keeps execution contexts and event blocks.
|
|
282
|
+
* Call start() to resume.
|
|
283
|
+
*/
|
|
284
|
+
pause() {
|
|
285
|
+
if (this.state !== 1 /* FlowGraphState.Started */) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
this._detachEventObserver();
|
|
289
|
+
this.state = 2 /* FlowGraphState.Paused */;
|
|
290
|
+
for (const context of this._executionContexts) {
|
|
291
|
+
context._clearPendingBlocks();
|
|
292
|
+
}
|
|
293
|
+
}
|
|
142
294
|
/**
|
|
143
295
|
* Starts the flow graph. Initializes the event blocks and starts listening to events.
|
|
296
|
+
* Can also be called to resume from a paused state.
|
|
144
297
|
*/
|
|
145
298
|
start() {
|
|
146
299
|
if (this.state === 1 /* FlowGraphState.Started */) {
|
|
147
300
|
return;
|
|
148
301
|
}
|
|
302
|
+
const resumingFromPause = this.state === 2 /* FlowGraphState.Paused */;
|
|
149
303
|
if (this._executionContexts.length === 0) {
|
|
150
304
|
this.createContext();
|
|
151
305
|
}
|
|
152
|
-
this.
|
|
153
|
-
if (state === 1 /* FlowGraphState.Started */) {
|
|
154
|
-
this._startPendingEvents();
|
|
155
|
-
// the only event we need to check is the scene ready event. If the scene is already ready when the graph starts, we should start the pending tasks.
|
|
156
|
-
if (this._scene.isReady(true)) {
|
|
157
|
-
this._sceneEventCoordinator.onEventTriggeredObservable.notifyObservers({ type: "SceneReady" /* FlowGraphEventType.SceneReady */ });
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
});
|
|
306
|
+
this._attachEventObserver();
|
|
161
307
|
this.state = 1 /* FlowGraphState.Started */;
|
|
308
|
+
this._startPendingEvents();
|
|
309
|
+
// On a fresh start (not resume), fire the SceneReady event.
|
|
310
|
+
// The coordinator's own scene-ready observer may have already
|
|
311
|
+
// fired (and been lost) while the graph was stopped, so reset
|
|
312
|
+
// the flag and handle the ready state ourselves.
|
|
313
|
+
if (!resumingFromPause) {
|
|
314
|
+
this._sceneEventCoordinator.sceneReadyTriggered = false;
|
|
315
|
+
if (this._scene.isReady(true)) {
|
|
316
|
+
this._sceneEventCoordinator.sceneReadyTriggered = true;
|
|
317
|
+
this._sceneEventCoordinator.onEventTriggeredObservable.notifyObservers({ type: "SceneReady" /* FlowGraphEventType.SceneReady */ });
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
// Scene isn't ready yet (e.g. pending shader compilations after
|
|
321
|
+
// a scene swap). Use executeWhenReady(true) which restarts the
|
|
322
|
+
// readiness check loop — a plain addOnce on onReadyObservable
|
|
323
|
+
// may never fire if the check loop already completed.
|
|
324
|
+
this._scene.executeWhenReady(() => {
|
|
325
|
+
if (this.state === 1 /* FlowGraphState.Started */ && !this._sceneEventCoordinator.sceneReadyTriggered) {
|
|
326
|
+
this._sceneEventCoordinator.sceneReadyTriggered = true;
|
|
327
|
+
this._sceneEventCoordinator.onEventTriggeredObservable.notifyObservers({ type: "SceneReady" /* FlowGraphEventType.SceneReady */ });
|
|
328
|
+
}
|
|
329
|
+
}, true);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
162
332
|
}
|
|
163
333
|
_startPendingEvents() {
|
|
164
334
|
for (const context of this._executionContexts) {
|
|
@@ -201,12 +371,14 @@ export class FlowGraph {
|
|
|
201
371
|
this.state = 0 /* FlowGraphState.Stopped */;
|
|
202
372
|
for (const context of this._executionContexts) {
|
|
203
373
|
context._clearPendingBlocks();
|
|
374
|
+
context._clearPendingActivation();
|
|
204
375
|
}
|
|
205
376
|
this._executionContexts.length = 0;
|
|
206
377
|
for (const type in this._eventBlocks) {
|
|
207
378
|
this._eventBlocks[type].length = 0;
|
|
208
379
|
}
|
|
209
|
-
this.
|
|
380
|
+
this._allBlocks.length = 0;
|
|
381
|
+
this._detachEventObserver();
|
|
210
382
|
this._sceneEventCoordinator.dispose();
|
|
211
383
|
}
|
|
212
384
|
/**
|
|
@@ -245,6 +417,14 @@ export class FlowGraph {
|
|
|
245
417
|
}
|
|
246
418
|
}
|
|
247
419
|
}
|
|
420
|
+
/**
|
|
421
|
+
* Validates the flow graph and returns all issues found.
|
|
422
|
+
* Uses the tracked block list for complete validation including unreachable block detection.
|
|
423
|
+
* @returns The validation result containing errors and warnings.
|
|
424
|
+
*/
|
|
425
|
+
validate() {
|
|
426
|
+
return ValidateFlowGraphWithBlockList(this, this._allBlocks);
|
|
427
|
+
}
|
|
248
428
|
/**
|
|
249
429
|
* Serializes a graph
|
|
250
430
|
* @param serializationObject the object to write the values in
|
|
@@ -252,11 +432,22 @@ export class FlowGraph {
|
|
|
252
432
|
*/
|
|
253
433
|
serialize(serializationObject = {}, valueSerializeFunction) {
|
|
254
434
|
serializationObject.allBlocks = [];
|
|
255
|
-
|
|
435
|
+
// Collect all blocks: traversal-reachable ones plus any registered
|
|
436
|
+
// orphans in _allBlocks (e.g. disconnected blocks in the editor).
|
|
437
|
+
const seen = new Set();
|
|
438
|
+
const serializeBlock = (block) => {
|
|
439
|
+
if (seen.has(block.uniqueId)) {
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
seen.add(block.uniqueId);
|
|
256
443
|
const serializedBlock = {};
|
|
257
444
|
block.serialize(serializedBlock);
|
|
258
445
|
serializationObject.allBlocks.push(serializedBlock);
|
|
259
|
-
}
|
|
446
|
+
};
|
|
447
|
+
this.visitAllBlocks(serializeBlock);
|
|
448
|
+
for (const block of this._allBlocks) {
|
|
449
|
+
serializeBlock(block);
|
|
450
|
+
}
|
|
260
451
|
serializationObject.executionContexts = [];
|
|
261
452
|
for (const context of this._executionContexts) {
|
|
262
453
|
const serializedContext = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flowGraph.js","sourceRoot":"","sources":["../../../../dev/core/src/FlowGraph/flowGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EA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,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;;OAIG;IACI,SAAS,CAAC,sBAA2B,EAAE,EAAE,sBAAoF;QAChI,mBAAmB,CAAC,SAAS,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,cAAc,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1B,MAAM,eAAe,GAAQ,EAAE,CAAC;YAChC,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;YACjC,mBAAmB,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC,CAAC;QACH,mBAAmB,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAC3C,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5C,MAAM,iBAAiB,GAAQ,EAAE,CAAC;YAClC,OAAO,CAAC,SAAS,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,CAAC;YAC7D,mBAAmB,CAAC,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { FlowGraphEventBlock } from \"./flowGraphEventBlock\";\r\nimport { FlowGraphContext } from \"./flowGraphContext\";\r\nimport type { FlowGraphBlock } from \"./flowGraphBlock\";\r\nimport { FlowGraphExecutionBlock } from \"./flowGraphExecutionBlock\";\r\nimport type { FlowGraphCoordinator } from \"./flowGraphCoordinator\";\r\nimport type { IObjectAccessor } from \"./typeDefinitions\";\r\nimport type { IPathToObjectConverter } from \"../ObjectModel/objectModelInterfaces\";\r\nimport type { IAssetContainer } from \"core/IAssetContainer\";\r\nimport { FlowGraphEventType } from \"./flowGraphEventType\";\r\nimport type { IFlowGraphEventTrigger } from \"./flowGraphSceneEventCoordinator\";\r\nimport { FlowGraphSceneEventCoordinator } from \"./flowGraphSceneEventCoordinator\";\r\nimport type { FlowGraphMeshPickEventBlock } from \"./Blocks/Event/flowGraphMeshPickEventBlock\";\r\nimport { _IsDescendantOf } from \"./utils\";\r\n\r\nexport const enum FlowGraphState {\r\n /**\r\n * The graph is stopped\r\n */\r\n Stopped,\r\n /**\r\n * The graph is running\r\n */\r\n Started,\r\n}\r\n\r\n/**\r\n * Parameters used to create a flow graph.\r\n */\r\nexport interface IFlowGraphParams {\r\n /**\r\n * The scene that the flow graph belongs to.\r\n */\r\n scene: Scene;\r\n /**\r\n * The event coordinator used by the flow graph.\r\n */\r\n coordinator: FlowGraphCoordinator;\r\n}\r\n\r\n/**\r\n * Options for parsing a flow graph.\r\n */\r\nexport interface IFlowGraphParseOptions {\r\n /**\r\n * A function that parses complex values in a scene.\r\n * @param key the key of the value\r\n * @param serializationObject the object to read the value from\r\n * @param assetsContainer the assets container\r\n * @param scene the scene to read the value from\r\n */\r\n valueParseFunction?: (key: string, serializationObject: any, assetsContainer: IAssetContainer, scene: Scene) => any;\r\n /**\r\n * The flow graph coordinator.\r\n */\r\n coordinator: FlowGraphCoordinator;\r\n /**\r\n * A function that converts a path to an object accessor.\r\n */\r\n pathConverter?: IPathToObjectConverter<IObjectAccessor>;\r\n}\r\n/**\r\n * Class used to represent a flow graph.\r\n * A flow graph is a graph of blocks that can be used to create complex logic.\r\n * Blocks can be added to the graph and connected to each other.\r\n * The graph can then be started, which will init and start all of its event blocks.\r\n *\r\n * @experimental FlowGraph is still in development and is subject to change.\r\n */\r\nexport class FlowGraph {\r\n /**\r\n * An observable that is triggered when the state of the graph changes.\r\n */\r\n public onStateChangedObservable: Observable<FlowGraphState> = new Observable();\r\n /** @internal */\r\n public _eventBlocks: { [keyof in FlowGraphEventType]: FlowGraphEventBlock[] } = {\r\n [FlowGraphEventType.SceneReady]: [],\r\n [FlowGraphEventType.SceneDispose]: [],\r\n [FlowGraphEventType.SceneBeforeRender]: [],\r\n [FlowGraphEventType.MeshPick]: [],\r\n [FlowGraphEventType.PointerDown]: [],\r\n [FlowGraphEventType.PointerUp]: [],\r\n [FlowGraphEventType.PointerMove]: [],\r\n [FlowGraphEventType.PointerOver]: [],\r\n [FlowGraphEventType.PointerOut]: [],\r\n [FlowGraphEventType.SceneAfterRender]: [],\r\n [FlowGraphEventType.NoTrigger]: [],\r\n };\r\n /**\r\n * @internal\r\n */\r\n public readonly _scene: Scene;\r\n private _coordinator: FlowGraphCoordinator;\r\n private _executionContexts: FlowGraphContext[] = [];\r\n private _sceneEventCoordinator: FlowGraphSceneEventCoordinator;\r\n private _eventObserver: Nullable<Observer<IFlowGraphEventTrigger>>;\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n private _state: FlowGraphState = FlowGraphState.Stopped;\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n public get state() {\r\n return this._state;\r\n }\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n public set state(value: FlowGraphState) {\r\n this._state = value;\r\n this.onStateChangedObservable.notifyObservers(value);\r\n }\r\n\r\n /**\r\n * Construct a Flow Graph\r\n * @param params construction parameters. currently only the scene\r\n */\r\n public constructor(params: IFlowGraphParams) {\r\n this._scene = params.scene;\r\n this._sceneEventCoordinator = new FlowGraphSceneEventCoordinator(this._scene);\r\n this._coordinator = params.coordinator;\r\n\r\n this._eventObserver = this._sceneEventCoordinator.onEventTriggeredObservable.add((event) => {\r\n for (const context of this._executionContexts) {\r\n const order = this._getContextualOrder(event.type, context);\r\n for (const block of order) {\r\n // iterate contexts\r\n if (!block._executeEvent(context, event.payload)) {\r\n break;\r\n }\r\n }\r\n }\r\n // custom behavior(s) of specific events\r\n switch (event.type) {\r\n case FlowGraphEventType.SceneReady:\r\n this._sceneEventCoordinator.sceneReadyTriggered = true;\r\n break;\r\n case FlowGraphEventType.SceneBeforeRender:\r\n for (const context of this._executionContexts) {\r\n context._notifyOnTick(event.payload);\r\n }\r\n break;\r\n case FlowGraphEventType.SceneDispose:\r\n this.dispose();\r\n break;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Create a context. A context represents one self contained execution for the graph, with its own variables.\r\n * @returns the context, where you can get and set variables\r\n */\r\n public createContext() {\r\n const context = new FlowGraphContext({ scene: this._scene, coordinator: this._coordinator });\r\n this._executionContexts.push(context);\r\n return context;\r\n }\r\n\r\n /**\r\n * Returns the execution context at a given index\r\n * @param index the index of the context\r\n * @returns the execution context at that index\r\n */\r\n public getContext(index: number) {\r\n return this._executionContexts[index];\r\n }\r\n\r\n /**\r\n * Add an event block. When the graph is started, it will start listening to events\r\n * from the block and execute the graph when they are triggered.\r\n * @param block the event block to be added\r\n */\r\n public addEventBlock(block: FlowGraphEventBlock): void {\r\n if (block.type === FlowGraphEventType.PointerOver || block.type === FlowGraphEventType.PointerOut) {\r\n this._scene.constantlyUpdateMeshUnderPointer = true;\r\n }\r\n\r\n // don't add if NoTrigger, but still start the pending tasks\r\n if (block.type !== FlowGraphEventType.NoTrigger) {\r\n this._eventBlocks[block.type].push(block);\r\n }\r\n // if already started, sort and add to the pending\r\n if (this.state === FlowGraphState.Started) {\r\n for (const context of this._executionContexts) {\r\n block._startPendingTasks(context);\r\n }\r\n } else {\r\n this.onStateChangedObservable.addOnce((state) => {\r\n if (state === FlowGraphState.Started) {\r\n for (const context of this._executionContexts) {\r\n block._startPendingTasks(context);\r\n }\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Starts the flow graph. Initializes the event blocks and starts listening to events.\r\n */\r\n public start() {\r\n if (this.state === FlowGraphState.Started) {\r\n return;\r\n }\r\n if (this._executionContexts.length === 0) {\r\n this.createContext();\r\n }\r\n this.onStateChangedObservable.add((state) => {\r\n if (state === FlowGraphState.Started) {\r\n this._startPendingEvents();\r\n // the only event we need to check is the scene ready event. If the scene is already ready when the graph starts, we should start the pending tasks.\r\n if (this._scene.isReady(true)) {\r\n this._sceneEventCoordinator.onEventTriggeredObservable.notifyObservers({ type: FlowGraphEventType.SceneReady });\r\n }\r\n }\r\n });\r\n this.state = FlowGraphState.Started;\r\n }\r\n\r\n private _startPendingEvents() {\r\n for (const context of this._executionContexts) {\r\n for (const type in this._eventBlocks) {\r\n const order = this._getContextualOrder(type as FlowGraphEventType, context);\r\n for (const block of order) {\r\n block._startPendingTasks(context);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _getContextualOrder(type: FlowGraphEventType, context: FlowGraphContext): FlowGraphEventBlock[] {\r\n const order = this._eventBlocks[type].sort((a, b) => b.initPriority - a.initPriority);\r\n\r\n if (type === FlowGraphEventType.MeshPick) {\r\n const meshPickOrder = [] as FlowGraphEventBlock[];\r\n for (const block1 of order) {\r\n // If the block is a mesh pick, guarantee that picks of children meshes come before picks of parent meshes\r\n const mesh1 = (block1 as FlowGraphMeshPickEventBlock).asset.getValue(context);\r\n let i = 0;\r\n for (; i < order.length; i++) {\r\n const block2 = order[i];\r\n const mesh2 = (block2 as FlowGraphMeshPickEventBlock).asset.getValue(context);\r\n if (mesh1 && mesh2 && _IsDescendantOf(mesh1, mesh2)) {\r\n break;\r\n }\r\n }\r\n meshPickOrder.splice(i, 0, block1);\r\n }\r\n return meshPickOrder;\r\n }\r\n return order;\r\n }\r\n\r\n /**\r\n * Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.\r\n */\r\n public dispose() {\r\n if (this.state === FlowGraphState.Stopped) {\r\n return;\r\n }\r\n this.state = FlowGraphState.Stopped;\r\n for (const context of this._executionContexts) {\r\n context._clearPendingBlocks();\r\n }\r\n this._executionContexts.length = 0;\r\n for (const type in this._eventBlocks) {\r\n this._eventBlocks[type as FlowGraphEventType].length = 0;\r\n }\r\n this._eventObserver?.remove();\r\n this._sceneEventCoordinator.dispose();\r\n }\r\n\r\n /**\r\n * Executes a function in all blocks of a flow graph, starting with the event blocks.\r\n * @param visitor the function to execute.\r\n */\r\n public visitAllBlocks(visitor: (block: FlowGraphBlock) => void) {\r\n const visitList: FlowGraphBlock[] = [];\r\n const idsAddedToVisitList = new Set<string>();\r\n for (const type in this._eventBlocks) {\r\n for (const block of this._eventBlocks[type as FlowGraphEventType]) {\r\n visitList.push(block);\r\n idsAddedToVisitList.add(block.uniqueId);\r\n }\r\n }\r\n\r\n while (visitList.length > 0) {\r\n const block = visitList.pop()!;\r\n visitor(block);\r\n\r\n for (const dataIn of block.dataInputs) {\r\n for (const connection of dataIn._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalOut of block.signalOutputs) {\r\n for (const connection of signalOut._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Serializes a graph\r\n * @param serializationObject the object to write the values in\r\n * @param valueSerializeFunction a function to serialize complex values\r\n */\r\n public serialize(serializationObject: any = {}, valueSerializeFunction?: (key: string, value: any, serializationObject: any) => void) {\r\n serializationObject.allBlocks = [];\r\n this.visitAllBlocks((block) => {\r\n const serializedBlock: any = {};\r\n block.serialize(serializedBlock);\r\n serializationObject.allBlocks.push(serializedBlock);\r\n });\r\n serializationObject.executionContexts = [];\r\n for (const context of this._executionContexts) {\r\n const serializedContext: any = {};\r\n context.serialize(serializedContext, valueSerializeFunction);\r\n serializationObject.executionContexts.push(serializedContext);\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"flowGraph.js","sourceRoot":"","sources":["../../../../dev/core/src/FlowGraph/flowGraph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIhD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,C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,CAAC,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,CAAC;QACF,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC;QACpC,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAClC,cAAc,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC;QACD,mBAAmB,CAAC,iBAAiB,GAAG,EAAE,CAAC;QAC3C,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC5C,MAAM,iBAAiB,GAAQ,EAAE,CAAC;YAClC,OAAO,CAAC,SAAS,CAAC,iBAAiB,EAAE,sBAAsB,CAAC,CAAC;YAC7D,mBAAmB,CAAC,iBAAiB,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAClE,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { FlowGraphEventBlock } from \"./flowGraphEventBlock\";\r\nimport { FlowGraphContext } from \"./flowGraphContext\";\r\nimport type { FlowGraphBlock } from \"./flowGraphBlock\";\r\nimport { FlowGraphExecutionBlock } from \"./flowGraphExecutionBlock\";\r\nimport { FlowGraphAsyncExecutionBlock } from \"./flowGraphAsyncExecutionBlock\";\r\nimport type { FlowGraphCoordinator } from \"./flowGraphCoordinator\";\r\nimport type { IObjectAccessor } from \"./typeDefinitions\";\r\nimport type { IPathToObjectConverter } from \"../ObjectModel/objectModelInterfaces\";\r\nimport type { IAssetContainer } from \"core/IAssetContainer\";\r\nimport { FlowGraphEventType } from \"./flowGraphEventType\";\r\nimport type { IFlowGraphEventTrigger } from \"./flowGraphSceneEventCoordinator\";\r\nimport { FlowGraphSceneEventCoordinator } from \"./flowGraphSceneEventCoordinator\";\r\nimport type { FlowGraphMeshPickEventBlock } from \"./Blocks/Event/flowGraphMeshPickEventBlock\";\r\nimport { _IsDescendantOf } from \"./utils\";\r\nimport type { IFlowGraphValidationResult } from \"./flowGraphValidator\";\r\nimport { ValidateFlowGraphWithBlockList } from \"./flowGraphValidator\";\r\n\r\nexport const enum FlowGraphState {\r\n /**\r\n * The graph is stopped\r\n */\r\n Stopped,\r\n /**\r\n * The graph is running\r\n */\r\n Started,\r\n /**\r\n * The graph is paused (contexts kept, pending tasks cancelled)\r\n */\r\n Paused,\r\n}\r\n\r\n/**\r\n * Parameters used to create a flow graph.\r\n */\r\nexport interface IFlowGraphParams {\r\n /**\r\n * The scene that the flow graph belongs to.\r\n */\r\n scene: Scene;\r\n /**\r\n * The event coordinator used by the flow graph.\r\n */\r\n coordinator: FlowGraphCoordinator;\r\n}\r\n\r\n/**\r\n * Options for parsing a flow graph.\r\n */\r\nexport interface IFlowGraphParseOptions {\r\n /**\r\n * A function that parses complex values in a scene.\r\n * @param key the key of the value\r\n * @param serializationObject the object to read the value from\r\n * @param assetsContainer the assets container to read assets from\r\n * @param scene the scene to read the value from\r\n */\r\n valueParseFunction?: (key: string, serializationObject: any, assetsContainer: IAssetContainer, scene: Scene) => any;\r\n /**\r\n * The flow graph coordinator.\r\n */\r\n coordinator: FlowGraphCoordinator;\r\n /**\r\n * A function that converts a path to an object accessor.\r\n */\r\n pathConverter?: IPathToObjectConverter<IObjectAccessor>;\r\n}\r\n/**\r\n * Class used to represent a flow graph.\r\n * A flow graph is a graph of blocks that can be used to create complex logic.\r\n * Blocks can be added to the graph and connected to each other.\r\n * The graph can then be started, which will init and start all of its event blocks.\r\n *\r\n * @experimental FlowGraph is still in development and is subject to change.\r\n */\r\nexport class FlowGraph {\r\n /**\r\n * An observable that is triggered when the state of the graph changes.\r\n */\r\n public onStateChangedObservable: Observable<FlowGraphState> = new Observable();\r\n /** @internal */\r\n public _eventBlocks: { [keyof in FlowGraphEventType]: FlowGraphEventBlock[] } = {\r\n [FlowGraphEventType.SceneReady]: [],\r\n [FlowGraphEventType.SceneDispose]: [],\r\n [FlowGraphEventType.SceneBeforeRender]: [],\r\n [FlowGraphEventType.MeshPick]: [],\r\n [FlowGraphEventType.PointerDown]: [],\r\n [FlowGraphEventType.PointerUp]: [],\r\n [FlowGraphEventType.PointerMove]: [],\r\n [FlowGraphEventType.PointerOver]: [],\r\n [FlowGraphEventType.PointerOut]: [],\r\n [FlowGraphEventType.SceneAfterRender]: [],\r\n [FlowGraphEventType.NoTrigger]: [],\r\n };\r\n\r\n /**\r\n * All blocks that belong to this graph, including unreachable ones.\r\n * @internal\r\n */\r\n public _allBlocks: FlowGraphBlock[] = [];\r\n /**\r\n * @internal\r\n */\r\n public readonly _scene: Scene;\r\n\r\n /**\r\n * The scene associated with this flow graph.\r\n */\r\n public get scene(): Scene {\r\n return this._scene;\r\n }\r\n private _coordinator: FlowGraphCoordinator;\r\n private _executionContexts: FlowGraphContext[] = [];\r\n private _sceneEventCoordinator: FlowGraphSceneEventCoordinator;\r\n private _eventObserver: Nullable<Observer<IFlowGraphEventTrigger>>;\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n private _state: FlowGraphState = FlowGraphState.Stopped;\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n public get state() {\r\n return this._state;\r\n }\r\n\r\n /**\r\n * The state of the graph\r\n */\r\n public set state(value: FlowGraphState) {\r\n this._state = value;\r\n this.onStateChangedObservable.notifyObservers(value);\r\n }\r\n\r\n /**\r\n * Construct a Flow Graph\r\n * @param params construction parameters. currently only the scene\r\n */\r\n public constructor(params: IFlowGraphParams) {\r\n this._scene = params.scene;\r\n this._sceneEventCoordinator = new FlowGraphSceneEventCoordinator(this._scene);\r\n this._coordinator = params.coordinator;\r\n }\r\n\r\n private _attachEventObserver() {\r\n if (this._eventObserver) {\r\n return;\r\n }\r\n this._eventObserver = this._sceneEventCoordinator.onEventTriggeredObservable.add((event) => {\r\n if (event.type === FlowGraphEventType.SceneDispose) {\r\n this.dispose();\r\n return;\r\n }\r\n\r\n if (this.state !== FlowGraphState.Started) {\r\n return;\r\n }\r\n\r\n for (const context of this._executionContexts) {\r\n const order = this._getContextualOrder(event.type, context);\r\n for (const block of order) {\r\n // iterate contexts\r\n if (!block._executeEvent(context, event.payload)) {\r\n break;\r\n }\r\n }\r\n }\r\n // custom behavior(s) of specific events\r\n switch (event.type) {\r\n case FlowGraphEventType.SceneReady:\r\n this._sceneEventCoordinator.sceneReadyTriggered = true;\r\n break;\r\n case FlowGraphEventType.SceneBeforeRender:\r\n for (const context of this._executionContexts) {\r\n context._notifyOnTick(event.payload);\r\n }\r\n break;\r\n }\r\n });\r\n }\r\n\r\n private _detachEventObserver() {\r\n this._eventObserver?.remove();\r\n this._eventObserver = null;\r\n }\r\n\r\n /**\r\n * Sets a new scene for this flow graph, re-wiring all event listeners.\r\n * This is useful when the scene the flow graph should listen to changes\r\n * (e.g. when a new scene is loaded in an editor preview).\r\n * If the graph is currently running, it will be stopped first and must be\r\n * restarted manually after calling this method.\r\n * @param scene the new scene to attach to\r\n */\r\n public setScene(scene: Scene): void {\r\n if (scene === this._scene) {\r\n return;\r\n }\r\n if (this.state === FlowGraphState.Started) {\r\n this.stop();\r\n }\r\n // Tear down old event coordinator\r\n this._detachEventObserver();\r\n this._sceneEventCoordinator.dispose();\r\n // Rebuild with the new scene\r\n (this as { _scene: Scene })._scene = scene;\r\n this._scene.constantlyUpdateMeshUnderPointer = true; // ensure pointer info is always up to date for event blocks that need it\r\n this._sceneEventCoordinator = new FlowGraphSceneEventCoordinator(this._scene);\r\n // Pre-attach the event observer so that events from the new\r\n // coordinator are routed to the graph immediately. The handler\r\n // guards against processing events while the graph is stopped,\r\n // but having the observer in place ensures no events are lost\r\n // when start() is called shortly after.\r\n this._attachEventObserver();\r\n }\r\n\r\n /**\r\n * Create a context. A context represents one self contained execution for the graph, with its own variables.\r\n * @returns the context, where you can get and set variables\r\n */\r\n public createContext() {\r\n const context = new FlowGraphContext({ scene: this._scene, coordinator: this._coordinator });\r\n this._executionContexts.push(context);\r\n return context;\r\n }\r\n\r\n /**\r\n * Returns the execution context at a given index\r\n * @param index the index of the context\r\n * @returns the execution context at that index\r\n */\r\n public getContext(index: number) {\r\n return this._executionContexts[index];\r\n }\r\n\r\n /**\r\n * Returns all blocks registered in this graph, including disconnected ones.\r\n * @returns a read-only array of all blocks\r\n */\r\n public getAllBlocks(): readonly FlowGraphBlock[] {\r\n return this._allBlocks;\r\n }\r\n\r\n /**\r\n * Register a block with the graph. This does not wire any connections;\r\n * it simply ensures the block is tracked so that serialization, editor\r\n * display, and validation see it even when it is not reachable from an\r\n * event block.\r\n * @param block the block to register\r\n */\r\n public addBlock(block: FlowGraphBlock): void {\r\n if (this._allBlocks.indexOf(block) === -1) {\r\n this._allBlocks.push(block);\r\n }\r\n }\r\n\r\n /**\r\n * Remove a block from the graph. Disconnects all of its ports and, if it\r\n * is an event block, unregisters it from the event-block lists.\r\n * @param block the block to remove\r\n */\r\n public removeBlock(block: FlowGraphBlock): void {\r\n const idx = this._allBlocks.indexOf(block);\r\n if (idx !== -1) {\r\n this._allBlocks.splice(idx, 1);\r\n }\r\n // If it is an event block, remove from the event-block registry\r\n if (block instanceof FlowGraphExecutionBlock && \"type\" in block) {\r\n const eventBlock = block as unknown as FlowGraphEventBlock;\r\n const list = this._eventBlocks[eventBlock.type];\r\n if (list) {\r\n const eIdx = list.indexOf(eventBlock);\r\n if (eIdx !== -1) {\r\n list.splice(eIdx, 1);\r\n }\r\n }\r\n }\r\n // If the block has pending async tasks (e.g. event subscriptions),\r\n // cancel them in all active execution contexts so deletion takes\r\n // effect immediately even while the graph is running.\r\n if (block instanceof FlowGraphAsyncExecutionBlock) {\r\n for (const context of this._executionContexts) {\r\n block._cancelPendingTasks(context);\r\n block._resetAfterCanceled(context);\r\n }\r\n }\r\n // Disconnect all ports\r\n for (const input of block.dataInputs) {\r\n input.disconnectFromAll();\r\n }\r\n for (const output of block.dataOutputs) {\r\n output.disconnectFromAll();\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalIn of block.signalInputs) {\r\n signalIn.disconnectFromAll();\r\n }\r\n for (const signalOut of block.signalOutputs) {\r\n signalOut.disconnectFromAll();\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add an event block. When the graph is started, it will start listening to events\r\n * from the block and execute the graph when they are triggered.\r\n * @param block the event block to be added\r\n */\r\n public addEventBlock(block: FlowGraphEventBlock): void {\r\n this.addBlock(block);\r\n if (block.type === FlowGraphEventType.PointerOver || block.type === FlowGraphEventType.PointerOut) {\r\n this._scene.constantlyUpdateMeshUnderPointer = true;\r\n }\r\n\r\n this._eventBlocks[block.type].push(block);\r\n\r\n // if already started, sort and add to the pending\r\n if (this.state === FlowGraphState.Started) {\r\n for (const context of this._executionContexts) {\r\n block._startPendingTasks(context);\r\n }\r\n } else {\r\n this.onStateChangedObservable.addOnce((state) => {\r\n if (state === FlowGraphState.Started) {\r\n for (const context of this._executionContexts) {\r\n block._startPendingTasks(context);\r\n }\r\n }\r\n });\r\n }\r\n }\r\n\r\n /**\r\n * Stops the flow graph. Cancels all pending tasks and clears execution contexts,\r\n * but keeps event blocks so the graph can be restarted.\r\n */\r\n public stop() {\r\n if (this.state === FlowGraphState.Stopped) {\r\n return;\r\n }\r\n this._detachEventObserver();\r\n this.state = FlowGraphState.Stopped;\r\n for (const context of this._executionContexts) {\r\n context._clearPendingBlocks();\r\n context._clearPendingActivation();\r\n }\r\n this._executionContexts.length = 0;\r\n }\r\n\r\n /**\r\n * Pauses the flow graph. Cancels pending tasks but keeps execution contexts and event blocks.\r\n * Call start() to resume.\r\n */\r\n public pause() {\r\n if (this.state !== FlowGraphState.Started) {\r\n return;\r\n }\r\n this._detachEventObserver();\r\n this.state = FlowGraphState.Paused;\r\n for (const context of this._executionContexts) {\r\n context._clearPendingBlocks();\r\n }\r\n }\r\n\r\n /**\r\n * Starts the flow graph. Initializes the event blocks and starts listening to events.\r\n * Can also be called to resume from a paused state.\r\n */\r\n public start() {\r\n if (this.state === FlowGraphState.Started) {\r\n return;\r\n }\r\n const resumingFromPause = this.state === FlowGraphState.Paused;\r\n if (this._executionContexts.length === 0) {\r\n this.createContext();\r\n }\r\n this._attachEventObserver();\r\n this.state = FlowGraphState.Started;\r\n this._startPendingEvents();\r\n // On a fresh start (not resume), fire the SceneReady event.\r\n // The coordinator's own scene-ready observer may have already\r\n // fired (and been lost) while the graph was stopped, so reset\r\n // the flag and handle the ready state ourselves.\r\n if (!resumingFromPause) {\r\n this._sceneEventCoordinator.sceneReadyTriggered = false;\r\n if (this._scene.isReady(true)) {\r\n this._sceneEventCoordinator.sceneReadyTriggered = true;\r\n this._sceneEventCoordinator.onEventTriggeredObservable.notifyObservers({ type: FlowGraphEventType.SceneReady });\r\n } else {\r\n // Scene isn't ready yet (e.g. pending shader compilations after\r\n // a scene swap). Use executeWhenReady(true) which restarts the\r\n // readiness check loop — a plain addOnce on onReadyObservable\r\n // may never fire if the check loop already completed.\r\n this._scene.executeWhenReady(() => {\r\n if (this.state === FlowGraphState.Started && !this._sceneEventCoordinator.sceneReadyTriggered) {\r\n this._sceneEventCoordinator.sceneReadyTriggered = true;\r\n this._sceneEventCoordinator.onEventTriggeredObservable.notifyObservers({ type: FlowGraphEventType.SceneReady });\r\n }\r\n }, true);\r\n }\r\n }\r\n }\r\n\r\n private _startPendingEvents() {\r\n for (const context of this._executionContexts) {\r\n for (const type in this._eventBlocks) {\r\n const order = this._getContextualOrder(type as FlowGraphEventType, context);\r\n for (const block of order) {\r\n block._startPendingTasks(context);\r\n }\r\n }\r\n }\r\n }\r\n\r\n private _getContextualOrder(type: FlowGraphEventType, context: FlowGraphContext): FlowGraphEventBlock[] {\r\n const order = this._eventBlocks[type].sort((a, b) => b.initPriority - a.initPriority);\r\n\r\n if (type === FlowGraphEventType.MeshPick) {\r\n const meshPickOrder = [] as FlowGraphEventBlock[];\r\n for (const block1 of order) {\r\n // If the block is a mesh pick, guarantee that picks of children meshes come before picks of parent meshes\r\n const mesh1 = (block1 as FlowGraphMeshPickEventBlock).asset.getValue(context);\r\n let i = 0;\r\n for (; i < order.length; i++) {\r\n const block2 = order[i];\r\n const mesh2 = (block2 as FlowGraphMeshPickEventBlock).asset.getValue(context);\r\n if (mesh1 && mesh2 && _IsDescendantOf(mesh1, mesh2)) {\r\n break;\r\n }\r\n }\r\n meshPickOrder.splice(i, 0, block1);\r\n }\r\n return meshPickOrder;\r\n }\r\n return order;\r\n }\r\n\r\n /**\r\n * Disposes of the flow graph. Cancels any pending tasks and removes all event listeners.\r\n */\r\n public dispose() {\r\n if (this.state === FlowGraphState.Stopped) {\r\n return;\r\n }\r\n this.state = FlowGraphState.Stopped;\r\n for (const context of this._executionContexts) {\r\n context._clearPendingBlocks();\r\n context._clearPendingActivation();\r\n }\r\n this._executionContexts.length = 0;\r\n for (const type in this._eventBlocks) {\r\n this._eventBlocks[type as FlowGraphEventType].length = 0;\r\n }\r\n this._allBlocks.length = 0;\r\n this._detachEventObserver();\r\n this._sceneEventCoordinator.dispose();\r\n }\r\n\r\n /**\r\n * Executes a function in all blocks of a flow graph, starting with the event blocks.\r\n * @param visitor the function to execute.\r\n */\r\n public visitAllBlocks(visitor: (block: FlowGraphBlock) => void) {\r\n const visitList: FlowGraphBlock[] = [];\r\n const idsAddedToVisitList = new Set<string>();\r\n for (const type in this._eventBlocks) {\r\n for (const block of this._eventBlocks[type as FlowGraphEventType]) {\r\n visitList.push(block);\r\n idsAddedToVisitList.add(block.uniqueId);\r\n }\r\n }\r\n\r\n while (visitList.length > 0) {\r\n const block = visitList.pop()!;\r\n visitor(block);\r\n\r\n for (const dataIn of block.dataInputs) {\r\n for (const connection of dataIn._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n if (block instanceof FlowGraphExecutionBlock) {\r\n for (const signalOut of block.signalOutputs) {\r\n for (const connection of signalOut._connectedPoint) {\r\n if (!idsAddedToVisitList.has(connection._ownerBlock.uniqueId)) {\r\n visitList.push(connection._ownerBlock);\r\n idsAddedToVisitList.add(connection._ownerBlock.uniqueId);\r\n }\r\n }\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Validates the flow graph and returns all issues found.\r\n * Uses the tracked block list for complete validation including unreachable block detection.\r\n * @returns The validation result containing errors and warnings.\r\n */\r\n public validate(): IFlowGraphValidationResult {\r\n return ValidateFlowGraphWithBlockList(this, this._allBlocks);\r\n }\r\n\r\n /**\r\n * Serializes a graph\r\n * @param serializationObject the object to write the values in\r\n * @param valueSerializeFunction a function to serialize complex values\r\n */\r\n public serialize(serializationObject: any = {}, valueSerializeFunction?: (key: string, value: any, serializationObject: any) => void) {\r\n serializationObject.allBlocks = [];\r\n // Collect all blocks: traversal-reachable ones plus any registered\r\n // orphans in _allBlocks (e.g. disconnected blocks in the editor).\r\n const seen = new Set<string>();\r\n const serializeBlock = (block: FlowGraphBlock) => {\r\n if (seen.has(block.uniqueId)) {\r\n return;\r\n }\r\n seen.add(block.uniqueId);\r\n const serializedBlock: any = {};\r\n block.serialize(serializedBlock);\r\n serializationObject.allBlocks.push(serializedBlock);\r\n };\r\n this.visitAllBlocks(serializeBlock);\r\n for (const block of this._allBlocks) {\r\n serializeBlock(block);\r\n }\r\n serializationObject.executionContexts = [];\r\n for (const context of this._executionContexts) {\r\n const serializedContext: any = {};\r\n context.serialize(serializedContext, valueSerializeFunction);\r\n serializationObject.executionContexts.push(serializedContext);\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -10,6 +10,19 @@ import type { IAssetContainer } from "../IAssetContainer.js";
|
|
|
10
10
|
import type { Nullable } from "../types.js";
|
|
11
11
|
import { FlowGraphLogger } from "./flowGraphLogger.js";
|
|
12
12
|
import type { IFlowGraphOnTickEventPayload } from "./Blocks/Event/flowGraphSceneTickEventBlock.js";
|
|
13
|
+
import type { FlowGraphExecutionBlock } from "./flowGraphExecutionBlock.js";
|
|
14
|
+
import type { FlowGraphSignalConnection } from "./flowGraphSignalConnection.js";
|
|
15
|
+
/**
|
|
16
|
+
* Represents a pending signal activation that was paused by a breakpoint.
|
|
17
|
+
*/
|
|
18
|
+
export interface IFlowGraphPendingActivation {
|
|
19
|
+
/** The block that was about to execute */
|
|
20
|
+
readonly block: FlowGraphExecutionBlock;
|
|
21
|
+
/** The context in which execution was paused */
|
|
22
|
+
readonly context: FlowGraphContext;
|
|
23
|
+
/** The signal connection that triggered the execution */
|
|
24
|
+
readonly signal: FlowGraphSignalConnection;
|
|
25
|
+
}
|
|
13
26
|
/**
|
|
14
27
|
* Construction parameters for the context.
|
|
15
28
|
*/
|
|
@@ -90,6 +103,36 @@ export declare class FlowGraphContext {
|
|
|
90
103
|
* Observable that is triggered when a node is executed.
|
|
91
104
|
*/
|
|
92
105
|
onNodeExecutedObservable: Observable<FlowGraphBlock>;
|
|
106
|
+
/**
|
|
107
|
+
* Observable triggered when a breakpoint is hit.
|
|
108
|
+
* Observers receive the pending activation (block, context, signal) that was paused.
|
|
109
|
+
*/
|
|
110
|
+
onBreakpointHitObservable: Observable<IFlowGraphPendingActivation>;
|
|
111
|
+
/**
|
|
112
|
+
* A predicate called before each execution block runs.
|
|
113
|
+
* If it returns true, execution is paused before the block and a
|
|
114
|
+
* pending activation is stored, which can be resumed via
|
|
115
|
+
* {@link continueExecution} or {@link stepExecution}.
|
|
116
|
+
*
|
|
117
|
+
* Set to `null` to disable breakpoint checking.
|
|
118
|
+
*/
|
|
119
|
+
breakpointPredicate: Nullable<(block: FlowGraphExecutionBlock) => boolean>;
|
|
120
|
+
/**
|
|
121
|
+
* The activation that is currently paused due to a breakpoint hit.
|
|
122
|
+
* `null` when execution is not paused on a breakpoint.
|
|
123
|
+
*/
|
|
124
|
+
private _pendingActivation;
|
|
125
|
+
/**
|
|
126
|
+
* When true, the next activation will pause regardless of the breakpoint predicate.
|
|
127
|
+
* Set by {@link stepExecution}.
|
|
128
|
+
*/
|
|
129
|
+
private _stepMode;
|
|
130
|
+
/**
|
|
131
|
+
* When set, the breakpoint check is skipped for this specific block uniqueId
|
|
132
|
+
* on the very next call to {@link _shouldBreak}. Used by continue/step to avoid
|
|
133
|
+
* immediately re-hitting the breakpoint on the block being resumed.
|
|
134
|
+
*/
|
|
135
|
+
private _skipBreakpointForBlockId;
|
|
93
136
|
/**
|
|
94
137
|
* The assets context used by the flow graph context.
|
|
95
138
|
* Note that it can be shared between flow graph contexts.
|
|
@@ -278,6 +321,36 @@ export declare class FlowGraphContext {
|
|
|
278
321
|
* Incremented for every block executed.
|
|
279
322
|
*/
|
|
280
323
|
get executionId(): number;
|
|
324
|
+
/**
|
|
325
|
+
* Check whether the given block should break before executing.
|
|
326
|
+
* Called by the signal connection infrastructure.
|
|
327
|
+
* @internal
|
|
328
|
+
* @param block the block about to execute
|
|
329
|
+
* @param signal the signal that is triggering the execution
|
|
330
|
+
* @returns true if execution should be paused (breakpoint hit)
|
|
331
|
+
*/
|
|
332
|
+
_shouldBreak(block: FlowGraphExecutionBlock, signal: FlowGraphSignalConnection): boolean;
|
|
333
|
+
/**
|
|
334
|
+
* Returns the currently paused activation, or null if not paused.
|
|
335
|
+
*/
|
|
336
|
+
get pendingActivation(): Nullable<IFlowGraphPendingActivation>;
|
|
337
|
+
/**
|
|
338
|
+
* Resume execution from a breakpoint hit.
|
|
339
|
+
* The paused block and all downstream blocks will execute normally until
|
|
340
|
+
* the next breakpoint (if any) is hit.
|
|
341
|
+
*/
|
|
342
|
+
continueExecution(): void;
|
|
343
|
+
/**
|
|
344
|
+
* Execute exactly the paused block and then pause again before the next
|
|
345
|
+
* execution block fires. If no activation is pending, this is a no-op.
|
|
346
|
+
*/
|
|
347
|
+
stepExecution(): void;
|
|
348
|
+
/**
|
|
349
|
+
* Discard any pending breakpoint activation without resuming.
|
|
350
|
+
* Used when stopping or resetting the graph.
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
_clearPendingActivation(): void;
|
|
281
354
|
/**
|
|
282
355
|
* Serializes a context
|
|
283
356
|
* @param serializationObject the object to write the values in
|