@babylonjs/smart-filters 1.0.13 → 8.18.0
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/dist/blockFoundation/aggregateBlock.d.ts +3 -3
- package/dist/blockFoundation/aggregateBlock.d.ts.map +1 -1
- package/dist/blockFoundation/aggregateBlock.js +1 -2
- package/dist/blockFoundation/aggregateBlock.js.map +1 -1
- package/dist/blockFoundation/baseBlock.d.ts +2 -2
- package/dist/blockFoundation/baseBlock.d.ts.map +1 -1
- package/dist/blockFoundation/baseBlock.js +5 -6
- package/dist/blockFoundation/baseBlock.js.map +1 -1
- package/dist/blockFoundation/customAggregateBlock.d.ts.map +1 -1
- package/dist/blockFoundation/customAggregateBlock.js +2 -2
- package/dist/blockFoundation/customAggregateBlock.js.map +1 -1
- package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/customShaderBlock.js +4 -6
- package/dist/blockFoundation/customShaderBlock.js.map +1 -1
- package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/disableableShaderBlock.js +4 -4
- package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
- package/dist/blockFoundation/index.js +0 -2
- package/dist/blockFoundation/index.js.map +1 -1
- package/dist/blockFoundation/inputBlock.d.ts +8 -8
- package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
- package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
- package/dist/blockFoundation/inputBlock.js +7 -7
- package/dist/blockFoundation/inputBlock.js.map +1 -1
- package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
- package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
- package/dist/blockFoundation/inputBlock.serializer.js +26 -28
- package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
- package/dist/blockFoundation/outputBlock.d.ts +4 -9
- package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
- package/dist/blockFoundation/outputBlock.js +13 -14
- package/dist/blockFoundation/outputBlock.js.map +1 -1
- package/dist/blockFoundation/shaderBlock.d.ts +4 -4
- package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
- package/dist/blockFoundation/shaderBlock.js +13 -19
- package/dist/blockFoundation/shaderBlock.js.map +1 -1
- package/dist/blockFoundation/textureOptions.d.ts +1 -1
- package/dist/blockFoundation/textureOptions.js +1 -1
- package/dist/command/command.d.ts +1 -1
- package/dist/command/command.js +1 -1
- package/dist/command/commandBuffer.d.ts +1 -1
- package/dist/command/commandBuffer.d.ts.map +1 -1
- package/dist/command/commandBuffer.js +2 -2
- package/dist/command/commandBufferDebugger.d.ts +2 -2
- package/dist/command/commandBufferDebugger.d.ts.map +1 -1
- package/dist/command/commandBufferDebugger.js +1 -1
- package/dist/command/commandBufferDebugger.js.map +1 -1
- package/dist/command/index.d.ts +3 -1
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +5 -1
- package/dist/command/index.js.map +1 -1
- package/dist/connection/connectionPoint.d.ts +3 -3
- package/dist/connection/connectionPoint.d.ts.map +1 -1
- package/dist/connection/connectionPoint.js +2 -2
- package/dist/connection/connectionPoint.js.map +1 -1
- package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
- package/dist/connection/connectionPointCompatibilityState.js +1 -1
- package/dist/connection/connectionPointType.d.ts +3 -3
- package/dist/connection/connectionPointType.d.ts.map +1 -1
- package/dist/connection/connectionPointWithDefault.d.ts +3 -3
- package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
- package/dist/connection/connectionPointWithDefault.js.map +1 -1
- package/dist/connection/index.d.ts +2 -1
- package/dist/connection/index.d.ts.map +1 -1
- package/dist/connection/index.js +3 -3
- package/dist/connection/index.js.map +1 -1
- package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
- package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
- package/dist/editorUtils/editableInPropertyPage.js +2 -2
- package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
- package/dist/editorUtils/index.d.ts +1 -0
- package/dist/editorUtils/index.d.ts.map +1 -1
- package/dist/editorUtils/index.js +2 -0
- package/dist/editorUtils/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/optimization/dependencyGraph.js.map +1 -1
- package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
- package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
- package/dist/optimization/optimizedShaderBlock.js.map +1 -1
- package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
- package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
- package/dist/optimization/smartFilterOptimizer.js +34 -57
- package/dist/optimization/smartFilterOptimizer.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -3
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/renderTargetGenerator.d.ts +1 -1
- package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
- package/dist/runtime/renderTargetGenerator.js +5 -7
- package/dist/runtime/renderTargetGenerator.js.map +1 -1
- package/dist/runtime/shaderRuntime.d.ts +7 -7
- package/dist/runtime/shaderRuntime.d.ts.map +1 -1
- package/dist/runtime/shaderRuntime.js +7 -8
- package/dist/runtime/shaderRuntime.js.map +1 -1
- package/dist/runtime/smartFilterRuntime.d.ts +3 -3
- package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
- package/dist/runtime/smartFilterRuntime.js.map +1 -1
- package/dist/runtime/strongRef.d.ts +1 -1
- package/dist/runtime/strongRef.js +1 -1
- package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
- package/dist/serialization/importCustomBlockDefinition.js +8 -9
- package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
- package/dist/serialization/index.d.ts +1 -0
- package/dist/serialization/index.d.ts.map +1 -1
- package/dist/serialization/index.js +3 -0
- package/dist/serialization/index.js.map +1 -1
- package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
- package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
- package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
- package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
- package/dist/serialization/serializedSmartFilter.d.ts +1 -1
- package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
- package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
- package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
- package/dist/serialization/smartFilterDeserializer.js +9 -12
- package/dist/serialization/smartFilterDeserializer.js.map +1 -1
- package/dist/serialization/smartFilterSerializer.d.ts +2 -2
- package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
- package/dist/serialization/smartFilterSerializer.js +10 -13
- package/dist/serialization/smartFilterSerializer.js.map +1 -1
- package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
- package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
- package/dist/serialization/v1/defaultBlockSerializer.js +1 -1
- package/dist/serialization/v1/index.d.ts +1 -0
- package/dist/serialization/v1/index.d.ts.map +1 -1
- package/dist/serialization/v1/index.js +2 -0
- package/dist/serialization/v1/index.js.map +1 -1
- package/dist/serialization/v1/shaderBlockSerialization.types.d.ts +3 -3
- package/dist/serialization/v1/shaderBlockSerialization.types.d.ts.map +1 -1
- package/dist/serialization/v1/smartFilterSerialization.types.d.ts +2 -2
- package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -1
- package/dist/smartFilter.d.ts +8 -8
- package/dist/smartFilter.d.ts.map +1 -1
- package/dist/smartFilter.js +6 -7
- package/dist/smartFilter.js.map +1 -1
- package/dist/utils/buildTools/buildShaders.d.ts +3 -2
- package/dist/utils/buildTools/buildShaders.d.ts.map +1 -1
- package/dist/utils/buildTools/buildShaders.js +7 -6
- package/dist/utils/buildTools/buildShaders.js.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +4 -2
- package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoBlock.js +136 -141
- package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +4 -4
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -1
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.js +55 -48
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -1
- package/dist/utils/buildTools/convertShaders.d.ts +8 -5
- package/dist/utils/buildTools/convertShaders.d.ts.map +1 -1
- package/dist/utils/buildTools/convertShaders.js +38 -14
- package/dist/utils/buildTools/convertShaders.js.map +1 -1
- package/dist/utils/buildTools/shaderConverter.d.ts +4 -4
- package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
- package/dist/utils/buildTools/shaderConverter.js +17 -21
- package/dist/utils/buildTools/shaderConverter.js.map +1 -1
- package/dist/utils/buildTools/watchShaders.d.ts +3 -2
- package/dist/utils/buildTools/watchShaders.d.ts.map +1 -1
- package/dist/utils/buildTools/watchShaders.js +10 -8
- package/dist/utils/buildTools/watchShaders.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/renderTargetUtils.d.ts +3 -3
- package/dist/utils/renderTargetUtils.d.ts.map +1 -1
- package/dist/utils/renderTargetUtils.js +4 -4
- package/dist/utils/renderTargetUtils.js.map +1 -1
- package/dist/utils/shaderCodeUtils.d.ts +8 -8
- package/dist/utils/shaderCodeUtils.d.ts.map +1 -1
- package/dist/utils/shaderCodeUtils.js +16 -28
- package/dist/utils/shaderCodeUtils.js.map +1 -1
- package/dist/utils/textureLoaders.d.ts +2 -2
- package/dist/utils/textureLoaders.d.ts.map +1 -1
- package/dist/utils/textureLoaders.js +2 -3
- package/dist/utils/textureLoaders.js.map +1 -1
- package/dist/utils/textureUtils.d.ts +5 -5
- package/dist/utils/textureUtils.d.ts.map +1 -1
- package/dist/utils/textureUtils.js +1 -1
- package/dist/utils/textureUtils.js.map +1 -1
- package/dist/version.d.ts +2 -2
- package/dist/version.js +2 -2
- package/license.md +21 -21
- package/package.json +13 -8
- package/src/blockFoundation/aggregateBlock.ts +148 -151
- package/src/blockFoundation/baseBlock.ts +339 -364
- package/src/blockFoundation/customAggregateBlock.ts +88 -104
- package/src/blockFoundation/customShaderBlock.ts +312 -326
- package/src/blockFoundation/disableableShaderBlock.ts +91 -100
- package/src/blockFoundation/index.ts +9 -9
- package/src/blockFoundation/inputBlock.deserializer.ts +72 -97
- package/src/blockFoundation/inputBlock.serialization.types.ts +126 -132
- package/src/blockFoundation/inputBlock.serializer.ts +150 -150
- package/src/blockFoundation/inputBlock.ts +181 -192
- package/src/blockFoundation/outputBlock.ts +144 -151
- package/src/blockFoundation/shaderBlock.ts +156 -163
- package/src/blockFoundation/textureOptions.ts +57 -57
- package/src/command/command.ts +59 -59
- package/src/command/commandBuffer.ts +71 -71
- package/src/command/commandBufferDebugger.ts +14 -14
- package/src/command/index.ts +7 -3
- package/src/connection/connectionPoint.ts +205 -214
- package/src/connection/connectionPointCompatibilityState.ts +31 -31
- package/src/connection/connectionPointType.ts +45 -45
- package/src/connection/connectionPointWithDefault.ts +27 -35
- package/src/connection/index.ts +8 -9
- package/src/editorUtils/editableInPropertyPage.ts +106 -106
- package/src/editorUtils/index.ts +3 -1
- package/src/index.ts +16 -15
- package/src/optimization/dependencyGraph.ts +96 -96
- package/src/optimization/index.ts +1 -1
- package/src/optimization/optimizedShaderBlock.ts +131 -134
- package/src/optimization/smartFilterOptimizer.ts +757 -825
- package/src/runtime/index.ts +8 -6
- package/src/runtime/renderTargetGenerator.ts +222 -248
- package/src/runtime/shaderRuntime.ts +174 -173
- package/src/runtime/smartFilterRuntime.ts +112 -112
- package/src/runtime/strongRef.ts +18 -18
- package/src/serialization/importCustomBlockDefinition.ts +86 -86
- package/src/serialization/index.ts +10 -7
- package/src/serialization/serializedBlockDefinition.ts +12 -12
- package/src/serialization/serializedShaderBlockDefinition.ts +7 -7
- package/src/serialization/serializedSmartFilter.ts +6 -6
- package/src/serialization/smartFilterDeserializer.ts +190 -220
- package/src/serialization/smartFilterSerializer.ts +110 -121
- package/src/serialization/v1/defaultBlockSerializer.ts +21 -21
- package/src/serialization/v1/index.ts +4 -2
- package/src/serialization/v1/shaderBlockSerialization.types.ts +85 -85
- package/src/serialization/v1/smartFilterSerialization.types.ts +129 -133
- package/src/smartFilter.ts +255 -260
- package/src/utils/buildTools/buildShaders.ts +14 -13
- package/src/utils/buildTools/convertGlslIntoBlock.ts +370 -385
- package/src/utils/buildTools/convertGlslIntoShaderProgram.ts +173 -172
- package/src/utils/buildTools/convertShaders.ts +65 -43
- package/src/utils/buildTools/recordVersionNumber.js +17 -0
- package/src/utils/buildTools/shaderConverter.ts +466 -478
- package/src/utils/buildTools/watchShaders.ts +44 -42
- package/src/utils/index.ts +4 -2
- package/src/utils/renderTargetUtils.ts +30 -35
- package/src/utils/shaderCodeUtils.ts +192 -207
- package/src/utils/textureLoaders.ts +31 -43
- package/src/utils/textureUtils.ts +28 -32
- package/src/version.ts +2 -2
- package/dist/utils/buildTools/determineVersion.d.ts +0 -36
- package/dist/utils/buildTools/determineVersion.d.ts.map +0 -1
- package/dist/utils/buildTools/determineVersion.js +0 -109
- package/dist/utils/buildTools/determineVersion.js.map +0 -1
- package/dist/utils/buildTools/versionUp.d.ts +0 -2
- package/dist/utils/buildTools/versionUp.d.ts.map +0 -1
- package/dist/utils/buildTools/versionUp.js +0 -53
- package/dist/utils/buildTools/versionUp.js.map +0 -1
- package/src/utils/buildTools/determineVersion.ts +0 -128
- package/src/utils/buildTools/versionUp.ts +0 -61
package/src/smartFilter.ts
CHANGED
|
@@ -1,260 +1,255 @@
|
|
|
1
|
-
import type { ThinEngine } from "
|
|
2
|
-
import type { Nullable } from "
|
|
3
|
-
import type { SmartFilterRuntime } from "./runtime/smartFilterRuntime";
|
|
4
|
-
import type { BaseBlock } from "./blockFoundation/baseBlock";
|
|
5
|
-
import type { ConnectionPointType } from "./connection/connectionPointType";
|
|
6
|
-
import type { ConnectionPoint } from "./connection/connectionPoint";
|
|
7
|
-
import { OutputBlock } from "./blockFoundation/outputBlock.js";
|
|
8
|
-
import { InternalSmartFilterRuntime } from "./runtime/smartFilterRuntime.js";
|
|
9
|
-
import { RenderTargetGenerator } from "./runtime/renderTargetGenerator.js";
|
|
10
|
-
import { AggregateBlock } from "./blockFoundation/aggregateBlock.js";
|
|
11
|
-
import type { IEditorData } from "
|
|
12
|
-
import type { IDisposable } from "./IDisposable";
|
|
13
|
-
import { ShaderBlock } from "./blockFoundation/shaderBlock.js";
|
|
14
|
-
import type { ThinRenderTargetTexture } from "
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* How long to wait for shader compilation and texture loading to complete before erroring out.
|
|
19
|
-
*/
|
|
20
|
-
const InitializationTimeout = 10000;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Data passed to the initialize function of the blocks.
|
|
24
|
-
*/
|
|
25
|
-
export type InitializationData = {
|
|
26
|
-
/**
|
|
27
|
-
* The current smart filter runtime the block is being initialized for.
|
|
28
|
-
*/
|
|
29
|
-
readonly runtime: InternalSmartFilterRuntime;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The output block of the smart filter.
|
|
33
|
-
* This is used to determine if a block is linked to the output block so that we can prevent an
|
|
34
|
-
* extra render pass.
|
|
35
|
-
*/
|
|
36
|
-
readonly outputBlock: OutputBlock;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* The list of promises to wait for during the initialization step.
|
|
40
|
-
*/
|
|
41
|
-
readonly initializationPromises: Promise<void>[];
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Resources that need to be disposed when the runtime is disposed.
|
|
45
|
-
*/
|
|
46
|
-
readonly disposableResources: IDisposable[];
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The smart filter class is the main class of the smart filter module.
|
|
51
|
-
*
|
|
52
|
-
* It is responsible for managing a graph of smart filter blocks.
|
|
53
|
-
*
|
|
54
|
-
* It is also responsible for creating the runtime associated to the current state of the filter.
|
|
55
|
-
*/
|
|
56
|
-
export class SmartFilter {
|
|
57
|
-
/**
|
|
58
|
-
* The friendly name of the smart filter.
|
|
59
|
-
*/
|
|
60
|
-
public readonly name: string;
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* The namespace of the smart filter.
|
|
64
|
-
*/
|
|
65
|
-
public readonly namespace: Nullable<string>;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The smart filter output (input connection point of the output block...).
|
|
69
|
-
*
|
|
70
|
-
* This is where the smart filter final block should be connected to in order to be visible on screen.
|
|
71
|
-
*/
|
|
72
|
-
public readonly output: ConnectionPoint<ConnectionPointType.Texture>;
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* The output block of the smart filter.
|
|
76
|
-
*/
|
|
77
|
-
public readonly outputBlock: OutputBlock;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* User defined comments to describe the current smart filter.
|
|
81
|
-
*/
|
|
82
|
-
public comments: Nullable<string> = null;
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Data used by the smart filter editor.
|
|
86
|
-
*/
|
|
87
|
-
public editorData: Nullable<IEditorData> = null;
|
|
88
|
-
|
|
89
|
-
private readonly _attachedBlocks: Array<BaseBlock>;
|
|
90
|
-
/**
|
|
91
|
-
* Creates a new instance of a @see SmartFilter.
|
|
92
|
-
* @param name - The friendly name of the smart filter
|
|
93
|
-
* @param namespace - The namespace of the smart filter
|
|
94
|
-
*/
|
|
95
|
-
constructor(name: string, namespace: Nullable<string> = null) {
|
|
96
|
-
this.name = name;
|
|
97
|
-
this.namespace = namespace;
|
|
98
|
-
|
|
99
|
-
this._attachedBlocks = new Array<BaseBlock>();
|
|
100
|
-
this.outputBlock = new OutputBlock(this);
|
|
101
|
-
this.output = this.outputBlock.input;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* @returns the list of blocks attached to the smart filter.
|
|
106
|
-
*/
|
|
107
|
-
public get attachedBlocks(): ReadonlyArray<BaseBlock> {
|
|
108
|
-
return this._attachedBlocks;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* @returns The current class name of the smart filter.
|
|
113
|
-
*/
|
|
114
|
-
public getClassName(): string {
|
|
115
|
-
return "SmartFilter";
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Registers a block to be part of this smart filter.
|
|
120
|
-
* @param block - The block to register on the smart filter
|
|
121
|
-
* @throws if the block is already registered on another smart filter
|
|
122
|
-
* @remarks This function will not register the block if it is already registered on the smart filter.
|
|
123
|
-
*/
|
|
124
|
-
public registerBlock(block: BaseBlock): void {
|
|
125
|
-
// It is impossible to attach a block from another filter
|
|
126
|
-
if (block.smartFilter !== this) {
|
|
127
|
-
throw new Error("Block is not part of this smart filter");
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// No need to attach a block several times
|
|
131
|
-
if (this._attachedBlocks.indexOf(block) !== -1) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// Add the block to the list of attached blocks
|
|
136
|
-
this._attachedBlocks.push(block);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Removes the block from the smart filter.
|
|
141
|
-
* @param block - The block to remove from the smart filter
|
|
142
|
-
* @remarks This function will disconnect the block on removal.
|
|
143
|
-
* This Output block cannot be removed.
|
|
144
|
-
*/
|
|
145
|
-
public removeBlock(block: BaseBlock): void {
|
|
146
|
-
const attachedBlockIndex = this._attachedBlocks.indexOf(block);
|
|
147
|
-
|
|
148
|
-
// The block can only be removed if it is not the output block
|
|
149
|
-
// and if it is attached to the smart filter
|
|
150
|
-
if (attachedBlockIndex > -1 && !block.isOutput) {
|
|
151
|
-
// Disconnects all the connections of the block
|
|
152
|
-
block.disconnect();
|
|
153
|
-
|
|
154
|
-
// Removes the block from the list of attached blocks
|
|
155
|
-
this._attachedBlocks.splice(attachedBlockIndex, 1);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
private _generateCommandsAndGatherInitPromises(initializationData: InitializationData): void {
|
|
160
|
-
const outputBlock = this.outputBlock;
|
|
161
|
-
|
|
162
|
-
outputBlock.visit(initializationData, (block: BaseBlock, initializationData: InitializationData) => {
|
|
163
|
-
block.generateCommandsAndGatherInitPromises(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
block._unmergeFromSmartFilter();
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
}
|
|
1
|
+
import type { ThinEngine } from "core/Engines/thinEngine.js";
|
|
2
|
+
import type { Nullable } from "core/types.js";
|
|
3
|
+
import type { SmartFilterRuntime } from "./runtime/smartFilterRuntime.js";
|
|
4
|
+
import type { BaseBlock } from "./blockFoundation/baseBlock.js";
|
|
5
|
+
import type { ConnectionPointType } from "./connection/connectionPointType.js";
|
|
6
|
+
import type { ConnectionPoint } from "./connection/connectionPoint.js";
|
|
7
|
+
import { OutputBlock } from "./blockFoundation/outputBlock.js";
|
|
8
|
+
import { InternalSmartFilterRuntime } from "./runtime/smartFilterRuntime.js";
|
|
9
|
+
import { RenderTargetGenerator } from "./runtime/renderTargetGenerator.js";
|
|
10
|
+
import { AggregateBlock } from "./blockFoundation/aggregateBlock.js";
|
|
11
|
+
import type { IEditorData } from "shared-ui-components/nodeGraphSystem/interfaces/nodeLocationInfo.js";
|
|
12
|
+
import type { IDisposable } from "./IDisposable.js";
|
|
13
|
+
import { ShaderBlock } from "./blockFoundation/shaderBlock.js";
|
|
14
|
+
import type { ThinRenderTargetTexture } from "core/Materials/Textures/thinRenderTargetTexture.js";
|
|
15
|
+
import { GetBlockOutputTextureSize } from "./utils/textureUtils.js";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* How long to wait for shader compilation and texture loading to complete before erroring out.
|
|
19
|
+
*/
|
|
20
|
+
const InitializationTimeout = 10000;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Data passed to the initialize function of the blocks.
|
|
24
|
+
*/
|
|
25
|
+
export type InitializationData = {
|
|
26
|
+
/**
|
|
27
|
+
* The current smart filter runtime the block is being initialized for.
|
|
28
|
+
*/
|
|
29
|
+
readonly runtime: InternalSmartFilterRuntime;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The output block of the smart filter.
|
|
33
|
+
* This is used to determine if a block is linked to the output block so that we can prevent an
|
|
34
|
+
* extra render pass.
|
|
35
|
+
*/
|
|
36
|
+
readonly outputBlock: OutputBlock;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The list of promises to wait for during the initialization step.
|
|
40
|
+
*/
|
|
41
|
+
readonly initializationPromises: Promise<void>[];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Resources that need to be disposed when the runtime is disposed.
|
|
45
|
+
*/
|
|
46
|
+
readonly disposableResources: IDisposable[];
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The smart filter class is the main class of the smart filter module.
|
|
51
|
+
*
|
|
52
|
+
* It is responsible for managing a graph of smart filter blocks.
|
|
53
|
+
*
|
|
54
|
+
* It is also responsible for creating the runtime associated to the current state of the filter.
|
|
55
|
+
*/
|
|
56
|
+
export class SmartFilter {
|
|
57
|
+
/**
|
|
58
|
+
* The friendly name of the smart filter.
|
|
59
|
+
*/
|
|
60
|
+
public readonly name: string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The namespace of the smart filter.
|
|
64
|
+
*/
|
|
65
|
+
public readonly namespace: Nullable<string>;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The smart filter output (input connection point of the output block...).
|
|
69
|
+
*
|
|
70
|
+
* This is where the smart filter final block should be connected to in order to be visible on screen.
|
|
71
|
+
*/
|
|
72
|
+
public readonly output: ConnectionPoint<ConnectionPointType.Texture>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The output block of the smart filter.
|
|
76
|
+
*/
|
|
77
|
+
public readonly outputBlock: OutputBlock;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* User defined comments to describe the current smart filter.
|
|
81
|
+
*/
|
|
82
|
+
public comments: Nullable<string> = null;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Data used by the smart filter editor.
|
|
86
|
+
*/
|
|
87
|
+
public editorData: Nullable<IEditorData> = null;
|
|
88
|
+
|
|
89
|
+
private readonly _attachedBlocks: Array<BaseBlock>;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a new instance of a @see SmartFilter.
|
|
92
|
+
* @param name - The friendly name of the smart filter
|
|
93
|
+
* @param namespace - The namespace of the smart filter
|
|
94
|
+
*/
|
|
95
|
+
constructor(name: string, namespace: Nullable<string> = null) {
|
|
96
|
+
this.name = name;
|
|
97
|
+
this.namespace = namespace;
|
|
98
|
+
|
|
99
|
+
this._attachedBlocks = new Array<BaseBlock>();
|
|
100
|
+
this.outputBlock = new OutputBlock(this);
|
|
101
|
+
this.output = this.outputBlock.input;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @returns the list of blocks attached to the smart filter.
|
|
106
|
+
*/
|
|
107
|
+
public get attachedBlocks(): ReadonlyArray<BaseBlock> {
|
|
108
|
+
return this._attachedBlocks;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @returns The current class name of the smart filter.
|
|
113
|
+
*/
|
|
114
|
+
public getClassName(): string {
|
|
115
|
+
return "SmartFilter";
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Registers a block to be part of this smart filter.
|
|
120
|
+
* @param block - The block to register on the smart filter
|
|
121
|
+
* @throws if the block is already registered on another smart filter
|
|
122
|
+
* @remarks This function will not register the block if it is already registered on the smart filter.
|
|
123
|
+
*/
|
|
124
|
+
public registerBlock(block: BaseBlock): void {
|
|
125
|
+
// It is impossible to attach a block from another filter
|
|
126
|
+
if (block.smartFilter !== this) {
|
|
127
|
+
throw new Error("Block is not part of this smart filter");
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// No need to attach a block several times
|
|
131
|
+
if (this._attachedBlocks.indexOf(block) !== -1) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Add the block to the list of attached blocks
|
|
136
|
+
this._attachedBlocks.push(block);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Removes the block from the smart filter.
|
|
141
|
+
* @param block - The block to remove from the smart filter
|
|
142
|
+
* @remarks This function will disconnect the block on removal.
|
|
143
|
+
* This Output block cannot be removed.
|
|
144
|
+
*/
|
|
145
|
+
public removeBlock(block: BaseBlock): void {
|
|
146
|
+
const attachedBlockIndex = this._attachedBlocks.indexOf(block);
|
|
147
|
+
|
|
148
|
+
// The block can only be removed if it is not the output block
|
|
149
|
+
// and if it is attached to the smart filter
|
|
150
|
+
if (attachedBlockIndex > -1 && !block.isOutput) {
|
|
151
|
+
// Disconnects all the connections of the block
|
|
152
|
+
block.disconnect();
|
|
153
|
+
|
|
154
|
+
// Removes the block from the list of attached blocks
|
|
155
|
+
this._attachedBlocks.splice(attachedBlockIndex, 1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private _generateCommandsAndGatherInitPromises(initializationData: InitializationData): void {
|
|
160
|
+
const outputBlock = this.outputBlock;
|
|
161
|
+
|
|
162
|
+
outputBlock.visit(initializationData, (block: BaseBlock, initializationData: InitializationData) => {
|
|
163
|
+
block.generateCommandsAndGatherInitPromises(initializationData, outputBlock.input.connectedTo?.ownerBlock === block);
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Create a new runtime for the current state of the smart filter.
|
|
169
|
+
* @param engine - The Babylon.js engine to use for the runtime
|
|
170
|
+
* @param renderTargetGenerator - The render target generator to use to generate the RTTs for the shader blocks. If not provided, a default one will be created.
|
|
171
|
+
* @returns the runtime that can be used to render the smart filter
|
|
172
|
+
*/
|
|
173
|
+
public async createRuntimeAsync(engine: ThinEngine, renderTargetGenerator?: RenderTargetGenerator): Promise<SmartFilterRuntime> {
|
|
174
|
+
const runtime = new InternalSmartFilterRuntime(engine);
|
|
175
|
+
|
|
176
|
+
const initializationData: InitializationData = {
|
|
177
|
+
runtime,
|
|
178
|
+
outputBlock: this.outputBlock,
|
|
179
|
+
initializationPromises: [],
|
|
180
|
+
disposableResources: [],
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
this._workWithAggregateFreeGraph(() => {
|
|
184
|
+
this.outputBlock.prepareForRuntime();
|
|
185
|
+
|
|
186
|
+
renderTargetGenerator = renderTargetGenerator ?? new RenderTargetGenerator(false);
|
|
187
|
+
renderTargetGenerator.setOutputTextures(this, initializationData);
|
|
188
|
+
|
|
189
|
+
this.outputBlock.propagateRuntimeData();
|
|
190
|
+
|
|
191
|
+
this._generateCommandsAndGatherInitPromises(initializationData);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
// Wait for all the blocks to be initialized
|
|
195
|
+
if (initializationData.initializationPromises.length > 0) {
|
|
196
|
+
const timeoutPromise = new Promise((resolve) => setTimeout(resolve, InitializationTimeout, true));
|
|
197
|
+
// eslint-disable-next-line github/no-then
|
|
198
|
+
const initializationPromises = Promise.all(initializationData.initializationPromises).then(() => false);
|
|
199
|
+
const timedOut = await Promise.race([initializationPromises, timeoutPromise]);
|
|
200
|
+
if (timedOut) {
|
|
201
|
+
throw new Error("Initialization promises timed out");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Register the resources to dispose when the runtime is disposed
|
|
206
|
+
initializationData.disposableResources.forEach((resource) => runtime.registerResource(resource));
|
|
207
|
+
|
|
208
|
+
return runtime;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Resizes any intermediate textures according to the new size of the render target
|
|
213
|
+
* @param engine - The engine used to render the smart filter
|
|
214
|
+
*/
|
|
215
|
+
public resize(engine: ThinEngine): void {
|
|
216
|
+
this._workWithAggregateFreeGraph(() => {
|
|
217
|
+
this.outputBlock.visit({}, (block: BaseBlock) => {
|
|
218
|
+
if (!(block instanceof ShaderBlock)) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (block.output.runtimeData?.value) {
|
|
223
|
+
const size = GetBlockOutputTextureSize(this, engine, block.outputTextureOptions);
|
|
224
|
+
(block.output.runtimeData.value as ThinRenderTargetTexture).resize(size);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @internal
|
|
232
|
+
* Merges all aggregate blocks into the smart filter graph, executes the passed-in work, then restores the aggregate blocks.
|
|
233
|
+
* @param work - The work to execute with the aggregate blocks merged
|
|
234
|
+
*/
|
|
235
|
+
public _workWithAggregateFreeGraph(work: () => void): void {
|
|
236
|
+
const mergedAggregateBlocks: AggregateBlock[] = [];
|
|
237
|
+
|
|
238
|
+
// Merge all aggregate blocks
|
|
239
|
+
this.outputBlock.visit({}, (block: BaseBlock, _extraData: object) => {
|
|
240
|
+
if (block instanceof AggregateBlock) {
|
|
241
|
+
block._mergeIntoSmartFilter(mergedAggregateBlocks);
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
// Do the passed in work
|
|
247
|
+
work();
|
|
248
|
+
} finally {
|
|
249
|
+
// Restore all aggregate blocks, even if work throws
|
|
250
|
+
for (const block of mergedAggregateBlocks) {
|
|
251
|
+
block._unmergeFromSmartFilter();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Builds all .glsl files under <shaderPath>.
|
|
3
|
-
* @param shaderPath - The path to the shaders to watch
|
|
4
|
-
* @param
|
|
5
|
-
* @
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Builds all .glsl files under <shaderPath>.
|
|
3
|
+
* @param shaderPath - The path to the shaders to watch
|
|
4
|
+
* @param smartFiltersCorePath - The path to import the Smart Filters core from
|
|
5
|
+
* @param babylonCorePath - The path to import the Babylon core from (optional)
|
|
6
|
+
* @example node buildShaders.js <shaderPath> @babylonjs/smart-filters
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { ConvertShaders } from "./convertShaders.js";
|
|
10
|
+
|
|
11
|
+
const ExternalArguments = process.argv.slice(2);
|
|
12
|
+
if (ExternalArguments.length >= 2 && ExternalArguments[0] && ExternalArguments[1]) {
|
|
13
|
+
ConvertShaders(ExternalArguments[0], ExternalArguments[1], ExternalArguments[2]);
|
|
14
|
+
}
|