@babylonjs/smart-filters 1.0.12 → 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.
Files changed (259) hide show
  1. package/dist/blockFoundation/aggregateBlock.d.ts +3 -3
  2. package/dist/blockFoundation/aggregateBlock.d.ts.map +1 -1
  3. package/dist/blockFoundation/aggregateBlock.js +1 -2
  4. package/dist/blockFoundation/aggregateBlock.js.map +1 -1
  5. package/dist/blockFoundation/baseBlock.d.ts +2 -2
  6. package/dist/blockFoundation/baseBlock.d.ts.map +1 -1
  7. package/dist/blockFoundation/baseBlock.js +5 -6
  8. package/dist/blockFoundation/baseBlock.js.map +1 -1
  9. package/dist/blockFoundation/customAggregateBlock.d.ts.map +1 -1
  10. package/dist/blockFoundation/customAggregateBlock.js +2 -2
  11. package/dist/blockFoundation/customAggregateBlock.js.map +1 -1
  12. package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
  13. package/dist/blockFoundation/customShaderBlock.js +4 -6
  14. package/dist/blockFoundation/customShaderBlock.js.map +1 -1
  15. package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
  16. package/dist/blockFoundation/disableableShaderBlock.js +4 -4
  17. package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
  18. package/dist/blockFoundation/index.js +0 -2
  19. package/dist/blockFoundation/index.js.map +1 -1
  20. package/dist/blockFoundation/inputBlock.d.ts +8 -8
  21. package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
  22. package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
  23. package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
  24. package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
  25. package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
  26. package/dist/blockFoundation/inputBlock.js +7 -7
  27. package/dist/blockFoundation/inputBlock.js.map +1 -1
  28. package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
  29. package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
  30. package/dist/blockFoundation/inputBlock.serializer.js +26 -28
  31. package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
  32. package/dist/blockFoundation/outputBlock.d.ts +4 -9
  33. package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
  34. package/dist/blockFoundation/outputBlock.js +13 -14
  35. package/dist/blockFoundation/outputBlock.js.map +1 -1
  36. package/dist/blockFoundation/shaderBlock.d.ts +4 -4
  37. package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
  38. package/dist/blockFoundation/shaderBlock.js +13 -19
  39. package/dist/blockFoundation/shaderBlock.js.map +1 -1
  40. package/dist/blockFoundation/textureOptions.d.ts +1 -1
  41. package/dist/blockFoundation/textureOptions.js +1 -1
  42. package/dist/command/command.d.ts +1 -1
  43. package/dist/command/command.js +1 -1
  44. package/dist/command/commandBuffer.d.ts +1 -1
  45. package/dist/command/commandBuffer.d.ts.map +1 -1
  46. package/dist/command/commandBuffer.js +2 -2
  47. package/dist/command/commandBufferDebugger.d.ts +2 -2
  48. package/dist/command/commandBufferDebugger.d.ts.map +1 -1
  49. package/dist/command/commandBufferDebugger.js +1 -1
  50. package/dist/command/commandBufferDebugger.js.map +1 -1
  51. package/dist/command/index.d.ts +3 -1
  52. package/dist/command/index.d.ts.map +1 -1
  53. package/dist/command/index.js +5 -1
  54. package/dist/command/index.js.map +1 -1
  55. package/dist/connection/connectionPoint.d.ts +3 -3
  56. package/dist/connection/connectionPoint.d.ts.map +1 -1
  57. package/dist/connection/connectionPoint.js +2 -2
  58. package/dist/connection/connectionPoint.js.map +1 -1
  59. package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
  60. package/dist/connection/connectionPointCompatibilityState.js +1 -1
  61. package/dist/connection/connectionPointType.d.ts +3 -3
  62. package/dist/connection/connectionPointType.d.ts.map +1 -1
  63. package/dist/connection/connectionPointWithDefault.d.ts +3 -3
  64. package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
  65. package/dist/connection/connectionPointWithDefault.js.map +1 -1
  66. package/dist/connection/index.d.ts +2 -1
  67. package/dist/connection/index.d.ts.map +1 -1
  68. package/dist/connection/index.js +3 -3
  69. package/dist/connection/index.js.map +1 -1
  70. package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
  71. package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
  72. package/dist/editorUtils/editableInPropertyPage.js +2 -2
  73. package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
  74. package/dist/editorUtils/index.d.ts +1 -0
  75. package/dist/editorUtils/index.d.ts.map +1 -1
  76. package/dist/editorUtils/index.js +2 -0
  77. package/dist/editorUtils/index.js.map +1 -1
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +1 -1
  80. package/dist/index.js.map +1 -1
  81. package/dist/optimization/dependencyGraph.js.map +1 -1
  82. package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
  83. package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
  84. package/dist/optimization/optimizedShaderBlock.js.map +1 -1
  85. package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
  86. package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
  87. package/dist/optimization/smartFilterOptimizer.js +34 -57
  88. package/dist/optimization/smartFilterOptimizer.js.map +1 -1
  89. package/dist/runtime/index.d.ts +2 -1
  90. package/dist/runtime/index.d.ts.map +1 -1
  91. package/dist/runtime/index.js +3 -3
  92. package/dist/runtime/index.js.map +1 -1
  93. package/dist/runtime/renderTargetGenerator.d.ts +1 -1
  94. package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
  95. package/dist/runtime/renderTargetGenerator.js +5 -7
  96. package/dist/runtime/renderTargetGenerator.js.map +1 -1
  97. package/dist/runtime/shaderRuntime.d.ts +7 -7
  98. package/dist/runtime/shaderRuntime.d.ts.map +1 -1
  99. package/dist/runtime/shaderRuntime.js +7 -8
  100. package/dist/runtime/shaderRuntime.js.map +1 -1
  101. package/dist/runtime/smartFilterRuntime.d.ts +3 -3
  102. package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
  103. package/dist/runtime/smartFilterRuntime.js.map +1 -1
  104. package/dist/runtime/strongRef.d.ts +1 -1
  105. package/dist/runtime/strongRef.js +1 -1
  106. package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
  107. package/dist/serialization/importCustomBlockDefinition.js +8 -9
  108. package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
  109. package/dist/serialization/index.d.ts +1 -0
  110. package/dist/serialization/index.d.ts.map +1 -1
  111. package/dist/serialization/index.js +3 -0
  112. package/dist/serialization/index.js.map +1 -1
  113. package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
  114. package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
  115. package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
  116. package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
  117. package/dist/serialization/serializedSmartFilter.d.ts +1 -1
  118. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
  119. package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
  120. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
  121. package/dist/serialization/smartFilterDeserializer.js +14 -12
  122. package/dist/serialization/smartFilterDeserializer.js.map +1 -1
  123. package/dist/serialization/smartFilterSerializer.d.ts +2 -2
  124. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
  125. package/dist/serialization/smartFilterSerializer.js +10 -13
  126. package/dist/serialization/smartFilterSerializer.js.map +1 -1
  127. package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
  128. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
  129. package/dist/serialization/v1/defaultBlockSerializer.js +3 -1
  130. package/dist/serialization/v1/defaultBlockSerializer.js.map +1 -1
  131. package/dist/serialization/v1/index.d.ts +1 -0
  132. package/dist/serialization/v1/index.d.ts.map +1 -1
  133. package/dist/serialization/v1/index.js +2 -0
  134. package/dist/serialization/v1/index.js.map +1 -1
  135. package/dist/serialization/v1/shaderBlockSerialization.types.d.ts +3 -3
  136. package/dist/serialization/v1/shaderBlockSerialization.types.d.ts.map +1 -1
  137. package/dist/serialization/v1/smartFilterSerialization.types.d.ts +5 -2
  138. package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -1
  139. package/dist/smartFilter.d.ts +8 -8
  140. package/dist/smartFilter.d.ts.map +1 -1
  141. package/dist/smartFilter.js +6 -7
  142. package/dist/smartFilter.js.map +1 -1
  143. package/dist/utils/buildTools/buildShaders.d.ts +3 -2
  144. package/dist/utils/buildTools/buildShaders.d.ts.map +1 -1
  145. package/dist/utils/buildTools/buildShaders.js +7 -6
  146. package/dist/utils/buildTools/buildShaders.js.map +1 -1
  147. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +4 -2
  148. package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -1
  149. package/dist/utils/buildTools/convertGlslIntoBlock.js +136 -141
  150. package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -1
  151. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +4 -4
  152. package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -1
  153. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js +55 -48
  154. package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -1
  155. package/dist/utils/buildTools/convertShaders.d.ts +8 -5
  156. package/dist/utils/buildTools/convertShaders.d.ts.map +1 -1
  157. package/dist/utils/buildTools/convertShaders.js +38 -14
  158. package/dist/utils/buildTools/convertShaders.js.map +1 -1
  159. package/dist/utils/buildTools/shaderConverter.d.ts +4 -4
  160. package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -1
  161. package/dist/utils/buildTools/shaderConverter.js +17 -21
  162. package/dist/utils/buildTools/shaderConverter.js.map +1 -1
  163. package/dist/utils/buildTools/watchShaders.d.ts +3 -2
  164. package/dist/utils/buildTools/watchShaders.d.ts.map +1 -1
  165. package/dist/utils/buildTools/watchShaders.js +10 -8
  166. package/dist/utils/buildTools/watchShaders.js.map +1 -1
  167. package/dist/utils/index.d.ts +1 -0
  168. package/dist/utils/index.d.ts.map +1 -1
  169. package/dist/utils/index.js +2 -1
  170. package/dist/utils/index.js.map +1 -1
  171. package/dist/utils/renderTargetUtils.d.ts +3 -3
  172. package/dist/utils/renderTargetUtils.d.ts.map +1 -1
  173. package/dist/utils/renderTargetUtils.js +4 -4
  174. package/dist/utils/renderTargetUtils.js.map +1 -1
  175. package/dist/utils/shaderCodeUtils.d.ts +8 -8
  176. package/dist/utils/shaderCodeUtils.d.ts.map +1 -1
  177. package/dist/utils/shaderCodeUtils.js +16 -28
  178. package/dist/utils/shaderCodeUtils.js.map +1 -1
  179. package/dist/utils/textureLoaders.d.ts +2 -2
  180. package/dist/utils/textureLoaders.d.ts.map +1 -1
  181. package/dist/utils/textureLoaders.js +2 -3
  182. package/dist/utils/textureLoaders.js.map +1 -1
  183. package/dist/utils/textureUtils.d.ts +5 -5
  184. package/dist/utils/textureUtils.d.ts.map +1 -1
  185. package/dist/utils/textureUtils.js +1 -1
  186. package/dist/utils/textureUtils.js.map +1 -1
  187. package/dist/version.d.ts +2 -2
  188. package/dist/version.js +2 -2
  189. package/license.md +21 -21
  190. package/package.json +14 -9
  191. package/src/blockFoundation/aggregateBlock.ts +148 -151
  192. package/src/blockFoundation/baseBlock.ts +339 -364
  193. package/src/blockFoundation/customAggregateBlock.ts +88 -104
  194. package/src/blockFoundation/customShaderBlock.ts +312 -326
  195. package/src/blockFoundation/disableableShaderBlock.ts +91 -100
  196. package/src/blockFoundation/index.ts +9 -9
  197. package/src/blockFoundation/inputBlock.deserializer.ts +72 -97
  198. package/src/blockFoundation/inputBlock.serialization.types.ts +126 -132
  199. package/src/blockFoundation/inputBlock.serializer.ts +150 -150
  200. package/src/blockFoundation/inputBlock.ts +181 -192
  201. package/src/blockFoundation/outputBlock.ts +144 -151
  202. package/src/blockFoundation/shaderBlock.ts +156 -163
  203. package/src/blockFoundation/textureOptions.ts +57 -57
  204. package/src/command/command.ts +59 -59
  205. package/src/command/commandBuffer.ts +71 -71
  206. package/src/command/commandBufferDebugger.ts +14 -14
  207. package/src/command/index.ts +7 -3
  208. package/src/connection/connectionPoint.ts +205 -214
  209. package/src/connection/connectionPointCompatibilityState.ts +31 -31
  210. package/src/connection/connectionPointType.ts +45 -45
  211. package/src/connection/connectionPointWithDefault.ts +27 -35
  212. package/src/connection/index.ts +8 -9
  213. package/src/editorUtils/editableInPropertyPage.ts +106 -106
  214. package/src/editorUtils/index.ts +3 -1
  215. package/src/index.ts +16 -15
  216. package/src/optimization/dependencyGraph.ts +96 -96
  217. package/src/optimization/index.ts +1 -1
  218. package/src/optimization/optimizedShaderBlock.ts +131 -134
  219. package/src/optimization/smartFilterOptimizer.ts +757 -825
  220. package/src/runtime/index.ts +8 -6
  221. package/src/runtime/renderTargetGenerator.ts +222 -248
  222. package/src/runtime/shaderRuntime.ts +174 -173
  223. package/src/runtime/smartFilterRuntime.ts +112 -112
  224. package/src/runtime/strongRef.ts +18 -18
  225. package/src/serialization/importCustomBlockDefinition.ts +86 -86
  226. package/src/serialization/index.ts +10 -7
  227. package/src/serialization/serializedBlockDefinition.ts +12 -12
  228. package/src/serialization/serializedShaderBlockDefinition.ts +7 -7
  229. package/src/serialization/serializedSmartFilter.ts +6 -6
  230. package/src/serialization/smartFilterDeserializer.ts +190 -214
  231. package/src/serialization/smartFilterSerializer.ts +110 -121
  232. package/src/serialization/v1/defaultBlockSerializer.ts +21 -19
  233. package/src/serialization/v1/index.ts +4 -2
  234. package/src/serialization/v1/shaderBlockSerialization.types.ts +85 -85
  235. package/src/serialization/v1/smartFilterSerialization.types.ts +129 -129
  236. package/src/smartFilter.ts +255 -260
  237. package/src/utils/buildTools/buildShaders.ts +14 -13
  238. package/src/utils/buildTools/convertGlslIntoBlock.ts +370 -385
  239. package/src/utils/buildTools/convertGlslIntoShaderProgram.ts +173 -172
  240. package/src/utils/buildTools/convertShaders.ts +65 -43
  241. package/src/utils/buildTools/recordVersionNumber.js +17 -0
  242. package/src/utils/buildTools/shaderConverter.ts +466 -478
  243. package/src/utils/buildTools/watchShaders.ts +44 -42
  244. package/src/utils/index.ts +4 -2
  245. package/src/utils/renderTargetUtils.ts +30 -35
  246. package/src/utils/shaderCodeUtils.ts +192 -207
  247. package/src/utils/textureLoaders.ts +31 -43
  248. package/src/utils/textureUtils.ts +28 -32
  249. package/src/version.ts +2 -2
  250. package/dist/utils/buildTools/determineVersion.d.ts +0 -36
  251. package/dist/utils/buildTools/determineVersion.d.ts.map +0 -1
  252. package/dist/utils/buildTools/determineVersion.js +0 -109
  253. package/dist/utils/buildTools/determineVersion.js.map +0 -1
  254. package/dist/utils/buildTools/versionUp.d.ts +0 -2
  255. package/dist/utils/buildTools/versionUp.d.ts.map +0 -1
  256. package/dist/utils/buildTools/versionUp.js +0 -53
  257. package/dist/utils/buildTools/versionUp.js.map +0 -1
  258. package/src/utils/buildTools/determineVersion.ts +0 -128
  259. package/src/utils/buildTools/versionUp.ts +0 -61
@@ -1,151 +1,148 @@
1
- import type { Nullable } from "@babylonjs/core/types";
2
- import type { ConnectionPoint, RuntimeData } from "../connection/connectionPoint";
3
- import type { ConnectionPointType } from "../connection/connectionPointType";
4
-
5
- import { BaseBlock } from "./baseBlock.js";
6
-
7
- /**
8
- * The aggregate block class is the base class for all blocks that be created from other blocks.
9
- *
10
- * It is responsible for managing a hidden chain of smart filter blocks in order and expose them through
11
- * its own connection points.
12
- *
13
- * The internal state is basically a filter itself.
14
- */
15
- export abstract class AggregateBlock extends BaseBlock {
16
- /**
17
- * The class name of the block.
18
- */
19
- public static override ClassName = "AggregateBlock";
20
-
21
- /**
22
- * The list of relationships between the internal graph output and the outside ones.
23
- */
24
- private readonly _aggregatedOutputs: [ConnectionPoint, ConnectionPoint][] = [];
25
-
26
- /**
27
- * The list of relationships between the internal graph inputs and the outside ones.
28
- */
29
- private readonly _aggregatedInputs: [ConnectionPoint[], ConnectionPoint][] = [];
30
-
31
- /**
32
- * Do not override prepareForRuntime for aggregate blocks. It is not supported.
33
- */
34
- public override prepareForRuntime(): never {
35
- throw new Error("Aggregate blocks should not be prepared for runtime.");
36
- }
37
-
38
- /**
39
- * @internal
40
- * Merges the internal graph into the SmartFilter
41
- */
42
- public _mergeIntoSmartFilter(mergedAggregateBlocks: AggregateBlock[]): void {
43
- // Rewire output connections
44
- for (const [internalConnectionPoint, externalConnectionPoint] of this._aggregatedOutputs) {
45
- const endpointsToConnectTo = externalConnectionPoint.endpoints.slice();
46
- externalConnectionPoint.disconnectAllEndpoints();
47
- for (const endpoint of endpointsToConnectTo) {
48
- internalConnectionPoint.connectTo(endpoint);
49
- }
50
- }
51
-
52
- // Rewire input connections
53
- for (const [internalConnectionPoints, externalConnectionPoint] of this._aggregatedInputs) {
54
- const connectedToExternalConnectionPoint = externalConnectionPoint.connectedTo;
55
- if (connectedToExternalConnectionPoint) {
56
- connectedToExternalConnectionPoint.disconnectFrom(externalConnectionPoint);
57
- for (const internalConnectionPoint of internalConnectionPoints) {
58
- connectedToExternalConnectionPoint.connectTo(internalConnectionPoint);
59
- }
60
- } else {
61
- // If the external connection point is not connected to anything but has a default value,
62
- // pass that default value along to the internal connection points it is associated with
63
- const defaultValue = externalConnectionPoint.runtimeData;
64
- if (defaultValue !== null) {
65
- for (const internalConnectionPoint of internalConnectionPoints) {
66
- internalConnectionPoint.runtimeData = defaultValue;
67
- }
68
- }
69
- }
70
- }
71
-
72
- // Tell any internal aggregate blocks to merge
73
- // Must be done after the inputs and outputs were merged at our level, or the internal aggregate block may not be wired up to anything
74
- for (const aggregateOutput of this._aggregatedOutputs) {
75
- const internalConnectionPoint = aggregateOutput[0];
76
- internalConnectionPoint.ownerBlock.visit({}, (block: BaseBlock, _extraData: Object) => {
77
- if (block instanceof AggregateBlock) {
78
- block._mergeIntoSmartFilter(mergedAggregateBlocks);
79
- }
80
- });
81
- }
82
-
83
- // Add ourselves to the list of merged aggregate blocks
84
- mergedAggregateBlocks.push(this);
85
- }
86
-
87
- /**
88
- * @internal
89
- * Undoes a previous mergeIntoSmartFilter call.
90
- */
91
- public _unmergeFromSmartFilter(): void {
92
- for (const [internalConnectionPoint, externalConnectionPoint] of this._aggregatedOutputs) {
93
- const endpointsToConnectTo = internalConnectionPoint.endpoints.slice();
94
- internalConnectionPoint.disconnectAllEndpoints();
95
- for (const endpoint of endpointsToConnectTo) {
96
- externalConnectionPoint.connectTo(endpoint);
97
- }
98
- }
99
-
100
- for (const [internalConnectionPoints, externalConnectionPoint] of this._aggregatedInputs) {
101
- if (internalConnectionPoints[0]) {
102
- const connectedToInternalConnectionPoint = internalConnectionPoints[0].connectedTo;
103
- if (connectedToInternalConnectionPoint) {
104
- for (const internalConnectionPoint of internalConnectionPoints) {
105
- connectedToInternalConnectionPoint.disconnectFrom(internalConnectionPoint);
106
- }
107
- connectedToInternalConnectionPoint.connectTo(externalConnectionPoint);
108
- }
109
- }
110
- }
111
- }
112
-
113
- /**
114
- * Registers an input connection from the internal graph as an input of the aggregated graph.
115
- * @param name - The name of the exposed input connection point
116
- * @param internalConnectionPoints - The input connection points in the inner graph to wire up to the new subfilter input
117
- * @param defaultValue - The default value to use for the input connection point
118
- * @returns the connection point referencing the input block
119
- */
120
- protected _registerSubfilterInput<U extends ConnectionPointType>(
121
- name: string,
122
- internalConnectionPoints: ConnectionPoint<U>[],
123
- defaultValue: Nullable<RuntimeData<U>> = null
124
- ): ConnectionPoint<U> {
125
- const type = internalConnectionPoints[0]?.type;
126
- if (type === undefined) {
127
- throw new Error("Cannot register an input connection point with no internal connection points");
128
- }
129
- const externalInputConnectionPoint = this._registerInput(name, type, defaultValue);
130
-
131
- this._aggregatedInputs.push([internalConnectionPoints, externalInputConnectionPoint]);
132
-
133
- return externalInputConnectionPoint;
134
- }
135
-
136
- /**
137
- * Registers an output connection point from the internal graph as an output of the aggregated graph.
138
- * @param name - The name of the exposed output connection point
139
- * @param internalConnectionPoint - The output connection point in the inner graph to expose as an output on the aggregate block
140
- * @returns the connection point referencing the output connection point
141
- */
142
- protected _registerSubfilterOutput<U extends ConnectionPointType>(
143
- name: string,
144
- internalConnectionPoint: ConnectionPoint<U>
145
- ): ConnectionPoint<U> {
146
- const externalOutputConnectionPoint = this._registerOutput(name, internalConnectionPoint.type);
147
-
148
- this._aggregatedOutputs.push([internalConnectionPoint, externalOutputConnectionPoint]);
149
- return externalOutputConnectionPoint;
150
- }
151
- }
1
+ import type { Nullable } from "core/types.js";
2
+ import type { ConnectionPoint, RuntimeData } from "../connection/connectionPoint.js";
3
+ import type { ConnectionPointType } from "../connection/connectionPointType.js";
4
+
5
+ import { BaseBlock } from "./baseBlock.js";
6
+
7
+ /**
8
+ * The aggregate block class is the base class for all blocks that be created from other blocks.
9
+ *
10
+ * It is responsible for managing a hidden chain of smart filter blocks in order and expose them through
11
+ * its own connection points.
12
+ *
13
+ * The internal state is basically a filter itself.
14
+ */
15
+ export abstract class AggregateBlock extends BaseBlock {
16
+ /**
17
+ * The class name of the block.
18
+ */
19
+ public static override ClassName = "AggregateBlock";
20
+
21
+ /**
22
+ * The list of relationships between the internal graph output and the outside ones.
23
+ */
24
+ private readonly _aggregatedOutputs: [ConnectionPoint, ConnectionPoint][] = [];
25
+
26
+ /**
27
+ * The list of relationships between the internal graph inputs and the outside ones.
28
+ */
29
+ private readonly _aggregatedInputs: [ConnectionPoint[], ConnectionPoint][] = [];
30
+
31
+ /**
32
+ * Do not override prepareForRuntime for aggregate blocks. It is not supported.
33
+ */
34
+ public override prepareForRuntime(): never {
35
+ throw new Error("Aggregate blocks should not be prepared for runtime.");
36
+ }
37
+
38
+ /**
39
+ * @internal
40
+ * Merges the internal graph into the SmartFilter
41
+ */
42
+ public _mergeIntoSmartFilter(mergedAggregateBlocks: AggregateBlock[]): void {
43
+ // Rewire output connections
44
+ for (const [internalConnectionPoint, externalConnectionPoint] of this._aggregatedOutputs) {
45
+ const endpointsToConnectTo = externalConnectionPoint.endpoints.slice();
46
+ externalConnectionPoint.disconnectAllEndpoints();
47
+ for (const endpoint of endpointsToConnectTo) {
48
+ internalConnectionPoint.connectTo(endpoint);
49
+ }
50
+ }
51
+
52
+ // Rewire input connections
53
+ for (const [internalConnectionPoints, externalConnectionPoint] of this._aggregatedInputs) {
54
+ const connectedToExternalConnectionPoint = externalConnectionPoint.connectedTo;
55
+ if (connectedToExternalConnectionPoint) {
56
+ connectedToExternalConnectionPoint.disconnectFrom(externalConnectionPoint);
57
+ for (const internalConnectionPoint of internalConnectionPoints) {
58
+ connectedToExternalConnectionPoint.connectTo(internalConnectionPoint);
59
+ }
60
+ } else {
61
+ // If the external connection point is not connected to anything but has a default value,
62
+ // pass that default value along to the internal connection points it is associated with
63
+ const defaultValue = externalConnectionPoint.runtimeData;
64
+ if (defaultValue !== null) {
65
+ for (const internalConnectionPoint of internalConnectionPoints) {
66
+ internalConnectionPoint.runtimeData = defaultValue;
67
+ }
68
+ }
69
+ }
70
+ }
71
+
72
+ // Tell any internal aggregate blocks to merge
73
+ // Must be done after the inputs and outputs were merged at our level, or the internal aggregate block may not be wired up to anything
74
+ for (const aggregateOutput of this._aggregatedOutputs) {
75
+ const internalConnectionPoint = aggregateOutput[0];
76
+ internalConnectionPoint.ownerBlock.visit({}, (block: BaseBlock, _extraData: object) => {
77
+ if (block instanceof AggregateBlock) {
78
+ block._mergeIntoSmartFilter(mergedAggregateBlocks);
79
+ }
80
+ });
81
+ }
82
+
83
+ // Add ourselves to the list of merged aggregate blocks
84
+ mergedAggregateBlocks.push(this);
85
+ }
86
+
87
+ /**
88
+ * @internal
89
+ * Undoes a previous mergeIntoSmartFilter call.
90
+ */
91
+ public _unmergeFromSmartFilter(): void {
92
+ for (const [internalConnectionPoint, externalConnectionPoint] of this._aggregatedOutputs) {
93
+ const endpointsToConnectTo = internalConnectionPoint.endpoints.slice();
94
+ internalConnectionPoint.disconnectAllEndpoints();
95
+ for (const endpoint of endpointsToConnectTo) {
96
+ externalConnectionPoint.connectTo(endpoint);
97
+ }
98
+ }
99
+
100
+ for (const [internalConnectionPoints, externalConnectionPoint] of this._aggregatedInputs) {
101
+ if (internalConnectionPoints[0]) {
102
+ const connectedToInternalConnectionPoint = internalConnectionPoints[0].connectedTo;
103
+ if (connectedToInternalConnectionPoint) {
104
+ for (const internalConnectionPoint of internalConnectionPoints) {
105
+ connectedToInternalConnectionPoint.disconnectFrom(internalConnectionPoint);
106
+ }
107
+ connectedToInternalConnectionPoint.connectTo(externalConnectionPoint);
108
+ }
109
+ }
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Registers an input connection from the internal graph as an input of the aggregated graph.
115
+ * @param name - The name of the exposed input connection point
116
+ * @param internalConnectionPoints - The input connection points in the inner graph to wire up to the new subfilter input
117
+ * @param defaultValue - The default value to use for the input connection point
118
+ * @returns the connection point referencing the input block
119
+ */
120
+ protected _registerSubfilterInput<U extends ConnectionPointType>(
121
+ name: string,
122
+ internalConnectionPoints: ConnectionPoint<U>[],
123
+ defaultValue: Nullable<RuntimeData<U>> = null
124
+ ): ConnectionPoint<U> {
125
+ const type = internalConnectionPoints[0]?.type;
126
+ if (type === undefined) {
127
+ throw new Error("Cannot register an input connection point with no internal connection points");
128
+ }
129
+ const externalInputConnectionPoint = this._registerInput(name, type, defaultValue);
130
+
131
+ this._aggregatedInputs.push([internalConnectionPoints, externalInputConnectionPoint]);
132
+
133
+ return externalInputConnectionPoint;
134
+ }
135
+
136
+ /**
137
+ * Registers an output connection point from the internal graph as an output of the aggregated graph.
138
+ * @param name - The name of the exposed output connection point
139
+ * @param internalConnectionPoint - The output connection point in the inner graph to expose as an output on the aggregate block
140
+ * @returns the connection point referencing the output connection point
141
+ */
142
+ protected _registerSubfilterOutput<U extends ConnectionPointType>(name: string, internalConnectionPoint: ConnectionPoint<U>): ConnectionPoint<U> {
143
+ const externalOutputConnectionPoint = this._registerOutput(name, internalConnectionPoint.type);
144
+
145
+ this._aggregatedOutputs.push([internalConnectionPoint, externalOutputConnectionPoint]);
146
+ return externalOutputConnectionPoint;
147
+ }
148
+ }