@babylonjs/smart-filters 1.0.13 → 8.19.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 +9 -0
  13. package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -1
  14. package/dist/blockFoundation/customShaderBlock.js +47 -7
  15. package/dist/blockFoundation/customShaderBlock.js.map +1 -1
  16. package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -1
  17. package/dist/blockFoundation/disableableShaderBlock.js +4 -4
  18. package/dist/blockFoundation/disableableShaderBlock.js.map +1 -1
  19. package/dist/blockFoundation/index.js +0 -2
  20. package/dist/blockFoundation/index.js.map +1 -1
  21. package/dist/blockFoundation/inputBlock.d.ts +8 -8
  22. package/dist/blockFoundation/inputBlock.d.ts.map +1 -1
  23. package/dist/blockFoundation/inputBlock.deserializer.d.ts +1 -1
  24. package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -1
  25. package/dist/blockFoundation/inputBlock.deserializer.js +1 -1
  26. package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -1
  27. package/dist/blockFoundation/inputBlock.js +7 -7
  28. package/dist/blockFoundation/inputBlock.js.map +1 -1
  29. package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -1
  30. package/dist/blockFoundation/inputBlock.serializer.d.ts +1 -1
  31. package/dist/blockFoundation/inputBlock.serializer.js +26 -28
  32. package/dist/blockFoundation/inputBlock.serializer.js.map +1 -1
  33. package/dist/blockFoundation/outputBlock.d.ts +4 -9
  34. package/dist/blockFoundation/outputBlock.d.ts.map +1 -1
  35. package/dist/blockFoundation/outputBlock.js +13 -14
  36. package/dist/blockFoundation/outputBlock.js.map +1 -1
  37. package/dist/blockFoundation/shaderBlock.d.ts +4 -4
  38. package/dist/blockFoundation/shaderBlock.d.ts.map +1 -1
  39. package/dist/blockFoundation/shaderBlock.js +13 -19
  40. package/dist/blockFoundation/shaderBlock.js.map +1 -1
  41. package/dist/blockFoundation/textureOptions.d.ts +1 -1
  42. package/dist/blockFoundation/textureOptions.js +1 -1
  43. package/dist/command/command.d.ts +1 -1
  44. package/dist/command/command.js +1 -1
  45. package/dist/command/commandBuffer.d.ts +1 -1
  46. package/dist/command/commandBuffer.d.ts.map +1 -1
  47. package/dist/command/commandBuffer.js +2 -2
  48. package/dist/command/commandBufferDebugger.d.ts +2 -2
  49. package/dist/command/commandBufferDebugger.d.ts.map +1 -1
  50. package/dist/command/commandBufferDebugger.js +1 -1
  51. package/dist/command/commandBufferDebugger.js.map +1 -1
  52. package/dist/command/index.d.ts +3 -1
  53. package/dist/command/index.d.ts.map +1 -1
  54. package/dist/command/index.js +5 -1
  55. package/dist/command/index.js.map +1 -1
  56. package/dist/connection/connectionPoint.d.ts +3 -3
  57. package/dist/connection/connectionPoint.d.ts.map +1 -1
  58. package/dist/connection/connectionPoint.js +2 -2
  59. package/dist/connection/connectionPoint.js.map +1 -1
  60. package/dist/connection/connectionPointCompatibilityState.d.ts +1 -1
  61. package/dist/connection/connectionPointCompatibilityState.js +1 -1
  62. package/dist/connection/connectionPointType.d.ts +3 -3
  63. package/dist/connection/connectionPointType.d.ts.map +1 -1
  64. package/dist/connection/connectionPointWithDefault.d.ts +3 -3
  65. package/dist/connection/connectionPointWithDefault.d.ts.map +1 -1
  66. package/dist/connection/connectionPointWithDefault.js.map +1 -1
  67. package/dist/connection/index.d.ts +2 -1
  68. package/dist/connection/index.d.ts.map +1 -1
  69. package/dist/connection/index.js +3 -3
  70. package/dist/connection/index.js.map +1 -1
  71. package/dist/editorUtils/editableInPropertyPage.d.ts +2 -2
  72. package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -1
  73. package/dist/editorUtils/editableInPropertyPage.js +2 -2
  74. package/dist/editorUtils/editableInPropertyPage.js.map +1 -1
  75. package/dist/editorUtils/index.d.ts +1 -0
  76. package/dist/editorUtils/index.d.ts.map +1 -1
  77. package/dist/editorUtils/index.js +2 -0
  78. package/dist/editorUtils/index.js.map +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +1 -1
  81. package/dist/index.js.map +1 -1
  82. package/dist/optimization/dependencyGraph.js.map +1 -1
  83. package/dist/optimization/optimizedShaderBlock.d.ts +4 -4
  84. package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -1
  85. package/dist/optimization/optimizedShaderBlock.js.map +1 -1
  86. package/dist/optimization/smartFilterOptimizer.d.ts +2 -2
  87. package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -1
  88. package/dist/optimization/smartFilterOptimizer.js +34 -57
  89. package/dist/optimization/smartFilterOptimizer.js.map +1 -1
  90. package/dist/runtime/index.d.ts +2 -1
  91. package/dist/runtime/index.d.ts.map +1 -1
  92. package/dist/runtime/index.js +3 -3
  93. package/dist/runtime/index.js.map +1 -1
  94. package/dist/runtime/renderTargetGenerator.d.ts +1 -1
  95. package/dist/runtime/renderTargetGenerator.d.ts.map +1 -1
  96. package/dist/runtime/renderTargetGenerator.js +5 -7
  97. package/dist/runtime/renderTargetGenerator.js.map +1 -1
  98. package/dist/runtime/shaderRuntime.d.ts +7 -7
  99. package/dist/runtime/shaderRuntime.d.ts.map +1 -1
  100. package/dist/runtime/shaderRuntime.js +7 -8
  101. package/dist/runtime/shaderRuntime.js.map +1 -1
  102. package/dist/runtime/smartFilterRuntime.d.ts +3 -3
  103. package/dist/runtime/smartFilterRuntime.d.ts.map +1 -1
  104. package/dist/runtime/smartFilterRuntime.js.map +1 -1
  105. package/dist/runtime/strongRef.d.ts +1 -1
  106. package/dist/runtime/strongRef.js +1 -1
  107. package/dist/serialization/importCustomBlockDefinition.d.ts +1 -1
  108. package/dist/serialization/importCustomBlockDefinition.js +8 -9
  109. package/dist/serialization/importCustomBlockDefinition.js.map +1 -1
  110. package/dist/serialization/index.d.ts +1 -0
  111. package/dist/serialization/index.d.ts.map +1 -1
  112. package/dist/serialization/index.js +3 -0
  113. package/dist/serialization/index.js.map +1 -1
  114. package/dist/serialization/serializedBlockDefinition.d.ts +2 -2
  115. package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -1
  116. package/dist/serialization/serializedShaderBlockDefinition.d.ts +1 -1
  117. package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -1
  118. package/dist/serialization/serializedSmartFilter.d.ts +1 -1
  119. package/dist/serialization/serializedSmartFilter.d.ts.map +1 -1
  120. package/dist/serialization/smartFilterDeserializer.d.ts +6 -6
  121. package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -1
  122. package/dist/serialization/smartFilterDeserializer.js +9 -12
  123. package/dist/serialization/smartFilterDeserializer.js.map +1 -1
  124. package/dist/serialization/smartFilterSerializer.d.ts +2 -2
  125. package/dist/serialization/smartFilterSerializer.d.ts.map +1 -1
  126. package/dist/serialization/smartFilterSerializer.js +10 -13
  127. package/dist/serialization/smartFilterSerializer.js.map +1 -1
  128. package/dist/serialization/v1/defaultBlockSerializer.d.ts +2 -2
  129. package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -1
  130. package/dist/serialization/v1/defaultBlockSerializer.js +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 +2 -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 +13 -8
  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 +362 -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 -220
  231. package/src/serialization/smartFilterSerializer.ts +110 -121
  232. package/src/serialization/v1/defaultBlockSerializer.ts +21 -21
  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 -133
  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 +24 -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,214 +1,205 @@
1
- import type { Nullable } from "@babylonjs/core/types";
2
- import {
3
- ConnectionPointCompatibilityState,
4
- getCompatibilityIssueMessage,
5
- } from "./connectionPointCompatibilityState.js";
6
- import { ConnectionPointDirection } from "./connectionPointDirection.js";
7
- import type { BaseBlock } from "../blockFoundation/baseBlock.js";
8
- import type { ConnectionPointType, ConnectionPointValue } from "./connectionPointType";
9
- import type { StrongRef } from "../runtime/strongRef";
10
-
11
- /**
12
- * This represents a strong reference to the data being passed through a connection point.
13
- */
14
- export type RuntimeData<U extends ConnectionPointType> = StrongRef<ConnectionPointValue<U>>;
15
-
16
- /**
17
- * This defines a connection point.
18
- *
19
- * A connection point is any input/output of a block.
20
- * It can be linked to another connection point following some rules:
21
- * - The type of the connection point must be compatible with the other one.
22
- * - The direction of the connection point must be different from the other one.
23
- * - The connection cannot create a cycle in the list of blocks.
24
- * The relationship is always 1:N for input:output
25
- */
26
- export class ConnectionPoint<U extends ConnectionPointType = ConnectionPointType> {
27
- /**
28
- * The name of the connection point.
29
- * This is used to identify the connection point inside a block.
30
- */
31
- public readonly name: string;
32
-
33
- /**
34
- * The type of the connection point (float, texture, etc.)
35
- */
36
- public readonly type: U;
37
-
38
- /**
39
- * The direction of the connection point (input or output)
40
- */
41
- public readonly direction: ConnectionPointDirection;
42
-
43
- /**
44
- * The smart filter block the connection point belongs to.
45
- */
46
- public readonly ownerBlock: BaseBlock;
47
-
48
- /**
49
- * User provided name for the connection point.
50
- */
51
- public displayName: Nullable<string> = null;
52
-
53
- /**
54
- * The @see RunTimeData used during the init phase to reference the result of the previous block.
55
- * Those are only used for input connection points.
56
- * The previous block are "pushing" this in during the init stage.
57
- */
58
- public runtimeData: Nullable<RuntimeData<U>> = null;
59
-
60
- /**
61
- * The default runtimeData used when no connection is made to the connection point.
62
- */
63
- public readonly defaultRuntimeData: Nullable<RuntimeData<U>> = null;
64
-
65
- private _connectedTo: Nullable<ConnectionPoint<U>> = null;
66
- private _endpoints: Array<ConnectionPoint<U>> = [];
67
-
68
- /**
69
- * Create a new connection point.
70
- * @param name - The name the connection point has in the block
71
- * @param ownerBlock - The block the connection point belongs to
72
- * @param type - The type of the connection point
73
- * @param direction - The direction of the connection point
74
- * @param defaultRuntimeData - The default runtime data to use when no connection is made to the connection point
75
- */
76
- constructor(
77
- name: string,
78
- ownerBlock: BaseBlock,
79
- type: U,
80
- direction: ConnectionPointDirection,
81
- defaultRuntimeData: Nullable<RuntimeData<U>> = null
82
- ) {
83
- this.name = name;
84
- this.ownerBlock = ownerBlock;
85
- this.type = type;
86
- this.direction = direction;
87
- this.defaultRuntimeData = defaultRuntimeData;
88
- this.runtimeData = defaultRuntimeData;
89
- }
90
-
91
- /**
92
- * @returns The connection point this connection point is connected to.
93
- * (the one on the other side of the connection)
94
- * Only input connection points have a connected point which they received their value from.
95
- * (Relation is always 1:N for input:output)
96
- */
97
- public get connectedTo(): Nullable<ConnectionPoint<U>> {
98
- return this._connectedTo;
99
- }
100
-
101
- /**
102
- * @returns The connection points this output connection point is connected to.
103
- * (the ones on the other side of the connection)
104
- * Only output connection points have a list of endpoints which they provide their value to.
105
- * (Relation is always 1:N for input:output)
106
- */
107
- public get endpoints(): ReadonlyArray<ConnectionPoint<U>> {
108
- return this._endpoints;
109
- }
110
-
111
- /**
112
- * Gets a state indicating if the current point can be connected to another point
113
- * @param other - defines the other connection point
114
- * @returns the compatibility state
115
- */
116
- public checkCompatibilityState(other: ConnectionPoint<U>): ConnectionPointCompatibilityState {
117
- // Only connects output to input
118
- if (this.direction === ConnectionPointDirection.Input) {
119
- return other.checkCompatibilityState(this);
120
- }
121
-
122
- // Check types
123
- if (this.type !== other.type) {
124
- return ConnectionPointCompatibilityState.TypeIncompatible;
125
- }
126
-
127
- // Check directions
128
- if (this.direction === other.direction) {
129
- return ConnectionPointCompatibilityState.DirectionIncompatible;
130
- }
131
-
132
- // Check hierarchy
133
- if (other.ownerBlock.isAnAncestorOf(this.ownerBlock)) {
134
- return ConnectionPointCompatibilityState.HierarchyIssue;
135
- }
136
-
137
- return ConnectionPointCompatibilityState.Compatible;
138
- }
139
-
140
- /**
141
- * Checks if the connection point can be connected to another one.
142
- * @param connectionPoint - The other connection point to check compatibility with
143
- * @returns true if the connection point can be connected to the other one
144
- */
145
- public canConnectTo(connectionPoint: ConnectionPoint<U>) {
146
- return this.checkCompatibilityState(connectionPoint) === ConnectionPointCompatibilityState.Compatible;
147
- }
148
-
149
- /**
150
- * Connect this connection point to another one.
151
- * @param other - The other connection point to connect to
152
- * @throws if the connection point cannot be connected to the other one
153
- */
154
- public connectTo(other: ConnectionPoint<U>): void {
155
- // Only connects output to input
156
- if (this.direction === ConnectionPointDirection.Input) {
157
- other.connectTo(this);
158
- return;
159
- }
160
-
161
- // Check compatibility
162
- const compatibility = this.checkCompatibilityState(other);
163
- if (compatibility !== ConnectionPointCompatibilityState.Compatible) {
164
- throw getCompatibilityIssueMessage(compatibility);
165
- }
166
-
167
- // Adds the connection point to the list of endpoints
168
- this._endpoints.push(other);
169
- // Fill at the same time the connectedTo property of the other connection point
170
- other._connectedTo = this;
171
- }
172
-
173
- /**
174
- * Disconnects this point from one of his endpoint
175
- * @param endpoint - defines the other connection point
176
- */
177
- public disconnectFrom(endpoint: ConnectionPoint<U>): void {
178
- const index = this._endpoints.indexOf(endpoint);
179
- if (index === -1) {
180
- return;
181
- }
182
-
183
- // Remove the connection point from the list of endpoints
184
- this._endpoints.splice(index, 1);
185
-
186
- // Connections are double-linked - remove the reference back to this connection point from the one we just disconnected from
187
- endpoint._connectedTo = null;
188
- endpoint.runtimeData = endpoint.defaultRuntimeData;
189
- }
190
-
191
- /**
192
- * Disconnects this point from all its endpoints.
193
- */
194
- public disconnectAllEndpoints(): void {
195
- // Detach outputs
196
- let endpoint: ConnectionPoint<U> | undefined;
197
- while ((endpoint = this._endpoints[0])) {
198
- this.disconnectFrom(endpoint);
199
- }
200
- }
201
-
202
- /**
203
- * Propagates the current runtime data to all endpoints.
204
- */
205
- public propagateRuntimeData(): void {
206
- if (!this.runtimeData) {
207
- this.runtimeData = {} as RuntimeData<U>;
208
- }
209
-
210
- for (const endpoint of this.endpoints) {
211
- endpoint.runtimeData = this.runtimeData;
212
- }
213
- }
214
- }
1
+ import type { Nullable } from "core/types.js";
2
+ import { ConnectionPointCompatibilityState, GetCompatibilityIssueMessage } from "./connectionPointCompatibilityState.js";
3
+ import { ConnectionPointDirection } from "./connectionPointDirection.js";
4
+ import type { BaseBlock } from "../blockFoundation/baseBlock.js";
5
+ import type { ConnectionPointType, ConnectionPointValue } from "./connectionPointType.js";
6
+ import type { StrongRef } from "../runtime/strongRef.js";
7
+
8
+ /**
9
+ * This represents a strong reference to the data being passed through a connection point.
10
+ */
11
+ export type RuntimeData<U extends ConnectionPointType> = StrongRef<ConnectionPointValue<U>>;
12
+
13
+ /**
14
+ * This defines a connection point.
15
+ *
16
+ * A connection point is any input/output of a block.
17
+ * It can be linked to another connection point following some rules:
18
+ * - The type of the connection point must be compatible with the other one.
19
+ * - The direction of the connection point must be different from the other one.
20
+ * - The connection cannot create a cycle in the list of blocks.
21
+ * The relationship is always 1:N for input:output
22
+ */
23
+ export class ConnectionPoint<U extends ConnectionPointType = ConnectionPointType> {
24
+ /**
25
+ * The name of the connection point.
26
+ * This is used to identify the connection point inside a block.
27
+ */
28
+ public readonly name: string;
29
+
30
+ /**
31
+ * The type of the connection point (float, texture, etc.)
32
+ */
33
+ public readonly type: U;
34
+
35
+ /**
36
+ * The direction of the connection point (input or output)
37
+ */
38
+ public readonly direction: ConnectionPointDirection;
39
+
40
+ /**
41
+ * The smart filter block the connection point belongs to.
42
+ */
43
+ public readonly ownerBlock: BaseBlock;
44
+
45
+ /**
46
+ * User provided name for the connection point.
47
+ */
48
+ public displayName: Nullable<string> = null;
49
+
50
+ /**
51
+ * The @see RunTimeData used during the init phase to reference the result of the previous block.
52
+ * Those are only used for input connection points.
53
+ * The previous block are "pushing" this in during the init stage.
54
+ */
55
+ public runtimeData: Nullable<RuntimeData<U>> = null;
56
+
57
+ /**
58
+ * The default runtimeData used when no connection is made to the connection point.
59
+ */
60
+ public readonly defaultRuntimeData: Nullable<RuntimeData<U>> = null;
61
+
62
+ private _connectedTo: Nullable<ConnectionPoint<U>> = null;
63
+ private _endpoints: Array<ConnectionPoint<U>> = [];
64
+
65
+ /**
66
+ * Create a new connection point.
67
+ * @param name - The name the connection point has in the block
68
+ * @param ownerBlock - The block the connection point belongs to
69
+ * @param type - The type of the connection point
70
+ * @param direction - The direction of the connection point
71
+ * @param defaultRuntimeData - The default runtime data to use when no connection is made to the connection point
72
+ */
73
+ constructor(name: string, ownerBlock: BaseBlock, type: U, direction: ConnectionPointDirection, defaultRuntimeData: Nullable<RuntimeData<U>> = null) {
74
+ this.name = name;
75
+ this.ownerBlock = ownerBlock;
76
+ this.type = type;
77
+ this.direction = direction;
78
+ this.defaultRuntimeData = defaultRuntimeData;
79
+ this.runtimeData = defaultRuntimeData;
80
+ }
81
+
82
+ /**
83
+ * @returns The connection point this connection point is connected to.
84
+ * (the one on the other side of the connection)
85
+ * Only input connection points have a connected point which they received their value from.
86
+ * (Relation is always 1:N for input:output)
87
+ */
88
+ public get connectedTo(): Nullable<ConnectionPoint<U>> {
89
+ return this._connectedTo;
90
+ }
91
+
92
+ /**
93
+ * @returns The connection points this output connection point is connected to.
94
+ * (the ones on the other side of the connection)
95
+ * Only output connection points have a list of endpoints which they provide their value to.
96
+ * (Relation is always 1:N for input:output)
97
+ */
98
+ public get endpoints(): ReadonlyArray<ConnectionPoint<U>> {
99
+ return this._endpoints;
100
+ }
101
+
102
+ /**
103
+ * Gets a state indicating if the current point can be connected to another point
104
+ * @param other - defines the other connection point
105
+ * @returns the compatibility state
106
+ */
107
+ public checkCompatibilityState(other: ConnectionPoint<U>): ConnectionPointCompatibilityState {
108
+ // Only connects output to input
109
+ if (this.direction === ConnectionPointDirection.Input) {
110
+ return other.checkCompatibilityState(this);
111
+ }
112
+
113
+ // Check types
114
+ if (this.type !== other.type) {
115
+ return ConnectionPointCompatibilityState.TypeIncompatible;
116
+ }
117
+
118
+ // Check directions
119
+ if (this.direction === other.direction) {
120
+ return ConnectionPointCompatibilityState.DirectionIncompatible;
121
+ }
122
+
123
+ // Check hierarchy
124
+ if (other.ownerBlock.isAnAncestorOf(this.ownerBlock)) {
125
+ return ConnectionPointCompatibilityState.HierarchyIssue;
126
+ }
127
+
128
+ return ConnectionPointCompatibilityState.Compatible;
129
+ }
130
+
131
+ /**
132
+ * Checks if the connection point can be connected to another one.
133
+ * @param connectionPoint - The other connection point to check compatibility with
134
+ * @returns true if the connection point can be connected to the other one
135
+ */
136
+ public canConnectTo(connectionPoint: ConnectionPoint<U>) {
137
+ return this.checkCompatibilityState(connectionPoint) === ConnectionPointCompatibilityState.Compatible;
138
+ }
139
+
140
+ /**
141
+ * Connect this connection point to another one.
142
+ * @param other - The other connection point to connect to
143
+ * @throws if the connection point cannot be connected to the other one
144
+ */
145
+ public connectTo(other: ConnectionPoint<U>): void {
146
+ // Only connects output to input
147
+ if (this.direction === ConnectionPointDirection.Input) {
148
+ other.connectTo(this);
149
+ return;
150
+ }
151
+
152
+ // Check compatibility
153
+ const compatibility = this.checkCompatibilityState(other);
154
+ if (compatibility !== ConnectionPointCompatibilityState.Compatible) {
155
+ throw GetCompatibilityIssueMessage(compatibility);
156
+ }
157
+
158
+ // Adds the connection point to the list of endpoints
159
+ this._endpoints.push(other);
160
+ // Fill at the same time the connectedTo property of the other connection point
161
+ other._connectedTo = this;
162
+ }
163
+
164
+ /**
165
+ * Disconnects this point from one of his endpoint
166
+ * @param endpoint - defines the other connection point
167
+ */
168
+ public disconnectFrom(endpoint: ConnectionPoint<U>): void {
169
+ const index = this._endpoints.indexOf(endpoint);
170
+ if (index === -1) {
171
+ return;
172
+ }
173
+
174
+ // Remove the connection point from the list of endpoints
175
+ this._endpoints.splice(index, 1);
176
+
177
+ // Connections are double-linked - remove the reference back to this connection point from the one we just disconnected from
178
+ endpoint._connectedTo = null;
179
+ endpoint.runtimeData = endpoint.defaultRuntimeData;
180
+ }
181
+
182
+ /**
183
+ * Disconnects this point from all its endpoints.
184
+ */
185
+ public disconnectAllEndpoints(): void {
186
+ // Detach outputs
187
+ let endpoint: ConnectionPoint<U> | undefined;
188
+ while ((endpoint = this._endpoints[0])) {
189
+ this.disconnectFrom(endpoint);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Propagates the current runtime data to all endpoints.
195
+ */
196
+ public propagateRuntimeData(): void {
197
+ if (!this.runtimeData) {
198
+ this.runtimeData = {} as RuntimeData<U>;
199
+ }
200
+
201
+ for (const endpoint of this.endpoints) {
202
+ endpoint.runtimeData = this.runtimeData;
203
+ }
204
+ }
205
+ }
@@ -1,31 +1,31 @@
1
- /**
2
- * Defines how compatible connection points are.
3
- */
4
- export enum ConnectionPointCompatibilityState {
5
- /** Points are compatibles */
6
- Compatible,
7
- /** Points are incompatible because of their types */
8
- TypeIncompatible,
9
- /** Points are incompatible because of their directions */
10
- DirectionIncompatible,
11
- /** Points are incompatible because they are in the same hierarchy **/
12
- HierarchyIssue,
13
- }
14
-
15
- /**
16
- * Gets a user friendly message for the given compatibility state.
17
- * @param state - Defines the compatibility state
18
- * @returns the message associated with a compatibility state.
19
- */
20
- export function getCompatibilityIssueMessage(state: ConnectionPointCompatibilityState): string {
21
- switch (state) {
22
- case ConnectionPointCompatibilityState.TypeIncompatible:
23
- return "Cannot connect two different connection types";
24
- case ConnectionPointCompatibilityState.DirectionIncompatible:
25
- return "Cannot connect with the same direction";
26
- case ConnectionPointCompatibilityState.HierarchyIssue:
27
- return "Source block cannot be connected with one of its ancestors";
28
- default:
29
- return "";
30
- }
31
- }
1
+ /**
2
+ * Defines how compatible connection points are.
3
+ */
4
+ export enum ConnectionPointCompatibilityState {
5
+ /** Points are compatibles */
6
+ Compatible,
7
+ /** Points are incompatible because of their types */
8
+ TypeIncompatible,
9
+ /** Points are incompatible because of their directions */
10
+ DirectionIncompatible,
11
+ /** Points are incompatible because they are in the same hierarchy **/
12
+ HierarchyIssue,
13
+ }
14
+
15
+ /**
16
+ * Gets a user friendly message for the given compatibility state.
17
+ * @param state - Defines the compatibility state
18
+ * @returns the message associated with a compatibility state.
19
+ */
20
+ export function GetCompatibilityIssueMessage(state: ConnectionPointCompatibilityState): string {
21
+ switch (state) {
22
+ case ConnectionPointCompatibilityState.TypeIncompatible:
23
+ return "Cannot connect two different connection types";
24
+ case ConnectionPointCompatibilityState.DirectionIncompatible:
25
+ return "Cannot connect with the same direction";
26
+ case ConnectionPointCompatibilityState.HierarchyIssue:
27
+ return "Source block cannot be connected with one of its ancestors";
28
+ default:
29
+ return "";
30
+ }
31
+ }
@@ -1,45 +1,45 @@
1
- import type { ThinTexture } from "@babylonjs/core/Materials/Textures/thinTexture";
2
- import type { IColor3Like, IColor4Like, IVector2Like } from "@babylonjs/core/Maths/math.like";
3
- import type { Nullable } from "@babylonjs/core/types";
4
-
5
- /**
6
- * Defines the type of a connection point.
7
- */
8
- export enum ConnectionPointType {
9
- /** Float */
10
- Float = 1,
11
- /** Texture */
12
- Texture = 2,
13
- /** Color3 */
14
- Color3 = 3,
15
- /** Color4 */
16
- Color4 = 4,
17
- /** Boolean */
18
- Boolean = 5,
19
- /** Vector2 */
20
- Vector2 = 6,
21
- }
22
-
23
- /**
24
- * A union of all supported connection point types
25
- */
26
- export type AllConnectionPointTypes =
27
- | ConnectionPointType.Float
28
- | ConnectionPointType.Texture
29
- | ConnectionPointType.Color3
30
- | ConnectionPointType.Color4
31
- | ConnectionPointType.Boolean
32
- | ConnectionPointType.Vector2;
33
-
34
- /**
35
- * Retrieves the type of the value from the Connection point type.
36
- */
37
- // prettier-ignore
38
- export type ConnectionPointValue<T extends ConnectionPointType = ConnectionPointType> =
39
- T extends ConnectionPointType.Float ? number :
40
- T extends ConnectionPointType.Texture ? Nullable<ThinTexture> :
41
- T extends ConnectionPointType.Color3 ? IColor3Like :
42
- T extends ConnectionPointType.Color4 ? IColor4Like :
43
- T extends ConnectionPointType.Boolean ? boolean :
44
- T extends ConnectionPointType.Vector2 ? IVector2Like :
45
- never;
1
+ import type { ThinTexture } from "core/Materials/Textures/thinTexture.js";
2
+ import type { IColor3Like, IColor4Like, IVector2Like } from "core/Maths/math.like.js";
3
+ import type { Nullable } from "core/types.js";
4
+
5
+ /**
6
+ * Defines the type of a connection point.
7
+ */
8
+ export enum ConnectionPointType {
9
+ /** Float */
10
+ Float = 1,
11
+ /** Texture */
12
+ Texture = 2,
13
+ /** Color3 */
14
+ Color3 = 3,
15
+ /** Color4 */
16
+ Color4 = 4,
17
+ /** Boolean */
18
+ Boolean = 5,
19
+ /** Vector2 */
20
+ Vector2 = 6,
21
+ }
22
+
23
+ /**
24
+ * A union of all supported connection point types
25
+ */
26
+ export type AllConnectionPointTypes =
27
+ | ConnectionPointType.Float
28
+ | ConnectionPointType.Texture
29
+ | ConnectionPointType.Color3
30
+ | ConnectionPointType.Color4
31
+ | ConnectionPointType.Boolean
32
+ | ConnectionPointType.Vector2;
33
+
34
+ /**
35
+ * Retrieves the type of the value from the Connection point type.
36
+ */
37
+ // prettier-ignore
38
+ export type ConnectionPointValue<T extends ConnectionPointType = ConnectionPointType> =
39
+ T extends ConnectionPointType.Float ? number :
40
+ T extends ConnectionPointType.Texture ? Nullable<ThinTexture> :
41
+ T extends ConnectionPointType.Color3 ? IColor3Like :
42
+ T extends ConnectionPointType.Color4 ? IColor4Like :
43
+ T extends ConnectionPointType.Boolean ? boolean :
44
+ T extends ConnectionPointType.Vector2 ? IVector2Like :
45
+ never;
@@ -1,35 +1,27 @@
1
- import type { BaseBlock } from "../blockFoundation/baseBlock";
2
- import { ConnectionPoint, type RuntimeData } from "./connectionPoint.js";
3
- import type { ConnectionPointDirection } from "./connectionPointDirection";
4
- import type { ConnectionPointType } from "./connectionPointType";
5
-
6
- /**
7
- * A ConnectionPoint whose runtimeData is never null - if not hooked up to a connection, it will use a default value.
8
- */
9
- export class ConnectionPointWithDefault<
10
- U extends ConnectionPointType = ConnectionPointType,
11
- > extends ConnectionPoint<U> {
12
- /**
13
- * The runtime data for this ConnectionPoint - it will never be null - if not hooked up to a connection, it will use the default value.
14
- */
15
- public override runtimeData: RuntimeData<U>;
16
-
17
- /**
18
- * Create a new ConnectionPointWithDefault
19
- * @param name - The name the connection point has in the block
20
- * @param ownerBlock - The block the connection point belongs to
21
- * @param type - The type of the connection point
22
- * @param direction - The direction of the connection point
23
- * @param runtimeData - The runtimeData to use for this connection point if no connection is made
24
- */
25
- constructor(
26
- name: string,
27
- ownerBlock: BaseBlock,
28
- type: U,
29
- direction: ConnectionPointDirection,
30
- runtimeData: RuntimeData<U>
31
- ) {
32
- super(name, ownerBlock, type, direction, runtimeData);
33
- this.runtimeData = runtimeData;
34
- }
35
- }
1
+ import type { BaseBlock } from "../blockFoundation/baseBlock.js";
2
+ import { ConnectionPoint, type RuntimeData } from "./connectionPoint.js";
3
+ import type { ConnectionPointDirection } from "./connectionPointDirection.js";
4
+ import type { ConnectionPointType } from "./connectionPointType.js";
5
+
6
+ /**
7
+ * A ConnectionPoint whose runtimeData is never null - if not hooked up to a connection, it will use a default value.
8
+ */
9
+ export class ConnectionPointWithDefault<U extends ConnectionPointType = ConnectionPointType> extends ConnectionPoint<U> {
10
+ /**
11
+ * The runtime data for this ConnectionPoint - it will never be null - if not hooked up to a connection, it will use the default value.
12
+ */
13
+ public override runtimeData: RuntimeData<U>;
14
+
15
+ /**
16
+ * Create a new ConnectionPointWithDefault
17
+ * @param name - The name the connection point has in the block
18
+ * @param ownerBlock - The block the connection point belongs to
19
+ * @param type - The type of the connection point
20
+ * @param direction - The direction of the connection point
21
+ * @param runtimeData - The runtimeData to use for this connection point if no connection is made
22
+ */
23
+ constructor(name: string, ownerBlock: BaseBlock, type: U, direction: ConnectionPointDirection, runtimeData: RuntimeData<U>) {
24
+ super(name, ownerBlock, type, direction, runtimeData);
25
+ this.runtimeData = runtimeData;
26
+ }
27
+ }