@onerjs/smart-filters 8.25.1 → 8.25.3
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/IDisposable.d.ts +10 -0
- package/dist/IDisposable.d.ts.map +1 -0
- package/dist/IDisposable.js +2 -0
- package/dist/IDisposable.js.map +1 -0
- package/dist/blockFoundation/aggregateBlock.d.ts +56 -0
- package/dist/blockFoundation/aggregateBlock.d.ts.map +1 -0
- package/dist/blockFoundation/aggregateBlock.js +130 -0
- package/dist/blockFoundation/aggregateBlock.js.map +1 -0
- package/dist/blockFoundation/baseBlock.d.ts +176 -0
- package/dist/blockFoundation/baseBlock.d.ts.map +1 -0
- package/dist/blockFoundation/baseBlock.js +276 -0
- package/dist/blockFoundation/baseBlock.js.map +1 -0
- package/dist/blockFoundation/customAggregateBlock.d.ts +38 -0
- package/dist/blockFoundation/customAggregateBlock.d.ts.map +1 -0
- package/dist/blockFoundation/customAggregateBlock.js +63 -0
- package/dist/blockFoundation/customAggregateBlock.js.map +1 -0
- package/dist/blockFoundation/customShaderBlock.d.ts +73 -0
- package/dist/blockFoundation/customShaderBlock.d.ts.map +1 -0
- package/dist/blockFoundation/customShaderBlock.js +232 -0
- package/dist/blockFoundation/customShaderBlock.js.map +1 -0
- package/dist/blockFoundation/disableableShaderBlock.d.ts +56 -0
- package/dist/blockFoundation/disableableShaderBlock.d.ts.map +1 -0
- package/dist/blockFoundation/disableableShaderBlock.js +68 -0
- package/dist/blockFoundation/disableableShaderBlock.js.map +1 -0
- package/dist/blockFoundation/index.d.ts +10 -0
- package/dist/blockFoundation/index.d.ts.map +1 -0
- package/dist/blockFoundation/index.js +8 -0
- package/dist/blockFoundation/index.js.map +1 -0
- package/dist/blockFoundation/inputBlock.d.ts +127 -0
- package/dist/blockFoundation/inputBlock.d.ts.map +1 -0
- package/dist/blockFoundation/inputBlock.deserializer.d.ts +12 -0
- package/dist/blockFoundation/inputBlock.deserializer.d.ts.map +1 -0
- package/dist/blockFoundation/inputBlock.deserializer.js +65 -0
- package/dist/blockFoundation/inputBlock.deserializer.js.map +1 -0
- package/dist/blockFoundation/inputBlock.js +89 -0
- package/dist/blockFoundation/inputBlock.js.map +1 -0
- package/dist/blockFoundation/inputBlock.serialization.types.d.ts +105 -0
- package/dist/blockFoundation/inputBlock.serialization.types.d.ts.map +1 -0
- package/dist/blockFoundation/inputBlock.serialization.types.js +2 -0
- package/dist/blockFoundation/inputBlock.serialization.types.js.map +1 -0
- package/dist/blockFoundation/inputBlock.serializer.d.ts +6 -0
- package/dist/blockFoundation/inputBlock.serializer.d.ts.map +1 -0
- package/dist/blockFoundation/inputBlock.serializer.js +130 -0
- package/dist/blockFoundation/inputBlock.serializer.js.map +1 -0
- package/dist/blockFoundation/outputBlock.d.ts +47 -0
- package/dist/blockFoundation/outputBlock.d.ts.map +1 -0
- package/dist/blockFoundation/outputBlock.js +123 -0
- package/dist/blockFoundation/outputBlock.js.map +1 -0
- package/dist/blockFoundation/shaderBlock.d.ts +64 -0
- package/dist/blockFoundation/shaderBlock.d.ts.map +1 -0
- package/dist/blockFoundation/shaderBlock.js +125 -0
- package/dist/blockFoundation/shaderBlock.js.map +1 -0
- package/dist/blockFoundation/textureOptions.d.ts +47 -0
- package/dist/blockFoundation/textureOptions.d.ts.map +1 -0
- package/dist/blockFoundation/textureOptions.js +37 -0
- package/dist/blockFoundation/textureOptions.js.map +1 -0
- package/dist/command/command.d.ts +48 -0
- package/dist/command/command.d.ts.map +1 -0
- package/dist/command/command.js +15 -0
- package/dist/command/command.js.map +1 -0
- package/dist/command/commandBuffer.d.ts +40 -0
- package/dist/command/commandBuffer.d.ts.map +1 -0
- package/dist/command/commandBuffer.js +58 -0
- package/dist/command/commandBuffer.js.map +1 -0
- package/dist/command/commandBufferDebugger.d.ts +7 -0
- package/dist/command/commandBufferDebugger.d.ts.map +1 -0
- package/dist/command/commandBufferDebugger.js +13 -0
- package/dist/command/commandBufferDebugger.js.map +1 -0
- package/dist/command/index.d.ts +6 -0
- package/dist/command/index.d.ts.map +1 -0
- package/dist/command/index.js +8 -0
- package/dist/command/index.js.map +1 -0
- package/dist/connection/connectionPoint.d.ts +110 -0
- package/dist/connection/connectionPoint.d.ts.map +1 -0
- package/dist/connection/connectionPoint.js +154 -0
- package/dist/connection/connectionPoint.js.map +1 -0
- package/dist/connection/connectionPointCompatibilityState.d.ts +20 -0
- package/dist/connection/connectionPointCompatibilityState.d.ts.map +1 -0
- package/dist/connection/connectionPointCompatibilityState.js +32 -0
- package/dist/connection/connectionPointCompatibilityState.js.map +1 -0
- package/dist/connection/connectionPointDirection.d.ts +10 -0
- package/dist/connection/connectionPointDirection.d.ts.map +1 -0
- package/dist/connection/connectionPointDirection.js +11 -0
- package/dist/connection/connectionPointDirection.js.map +1 -0
- package/dist/connection/connectionPointType.d.ts +29 -0
- package/dist/connection/connectionPointType.d.ts.map +1 -0
- package/dist/connection/connectionPointType.js +19 -0
- package/dist/connection/connectionPointType.js.map +1 -0
- package/dist/connection/connectionPointWithDefault.d.ts +23 -0
- package/dist/connection/connectionPointWithDefault.d.ts.map +1 -0
- package/dist/connection/connectionPointWithDefault.js +19 -0
- package/dist/connection/connectionPointWithDefault.js.map +1 -0
- package/dist/connection/index.d.ts +8 -0
- package/dist/connection/index.d.ts.map +1 -0
- package/dist/connection/index.js +7 -0
- package/dist/connection/index.js.map +1 -0
- package/dist/editorUtils/editableInPropertyPage.d.ts +80 -0
- package/dist/editorUtils/editableInPropertyPage.d.ts.map +1 -0
- package/dist/editorUtils/editableInPropertyPage.js +42 -0
- package/dist/editorUtils/editableInPropertyPage.js.map +1 -0
- package/dist/editorUtils/index.d.ts +3 -0
- package/dist/editorUtils/index.d.ts.map +1 -0
- package/dist/editorUtils/index.js +4 -0
- package/dist/editorUtils/index.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/optimization/dependencyGraph.d.ts +31 -0
- package/dist/optimization/dependencyGraph.d.ts.map +1 -0
- package/dist/optimization/dependencyGraph.js +78 -0
- package/dist/optimization/dependencyGraph.js.map +1 -0
- package/dist/optimization/index.d.ts +2 -0
- package/dist/optimization/index.d.ts.map +1 -0
- package/dist/optimization/index.js +2 -0
- package/dist/optimization/index.js.map +1 -0
- package/dist/optimization/optimizedShaderBlock.d.ts +75 -0
- package/dist/optimization/optimizedShaderBlock.d.ts.map +1 -0
- package/dist/optimization/optimizedShaderBlock.js +105 -0
- package/dist/optimization/optimizedShaderBlock.js.map +1 -0
- package/dist/optimization/smartFilterOptimizer.d.ts +126 -0
- package/dist/optimization/smartFilterOptimizer.d.ts.map +1 -0
- package/dist/optimization/smartFilterOptimizer.js +666 -0
- package/dist/optimization/smartFilterOptimizer.js.map +1 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +7 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/renderTargetGenerator.d.ts +43 -0
- package/dist/runtime/renderTargetGenerator.d.ts.map +1 -0
- package/dist/runtime/renderTargetGenerator.js +169 -0
- package/dist/runtime/renderTargetGenerator.js.map +1 -0
- package/dist/runtime/shaderRuntime.d.ts +103 -0
- package/dist/runtime/shaderRuntime.d.ts.map +1 -0
- package/dist/runtime/shaderRuntime.js +132 -0
- package/dist/runtime/shaderRuntime.js.map +1 -0
- package/dist/runtime/smartFilterRuntime.d.ts +69 -0
- package/dist/runtime/smartFilterRuntime.d.ts.map +1 -0
- package/dist/runtime/smartFilterRuntime.js +63 -0
- package/dist/runtime/smartFilterRuntime.js.map +1 -0
- package/dist/runtime/strongRef.d.ts +16 -0
- package/dist/runtime/strongRef.d.ts.map +1 -0
- package/dist/runtime/strongRef.js +9 -0
- package/dist/runtime/strongRef.js.map +1 -0
- package/dist/serialization/importCustomBlockDefinition.d.ts +15 -0
- package/dist/serialization/importCustomBlockDefinition.d.ts.map +1 -0
- package/dist/serialization/importCustomBlockDefinition.js +76 -0
- package/dist/serialization/importCustomBlockDefinition.js.map +1 -0
- package/dist/serialization/index.d.ts +9 -0
- package/dist/serialization/index.d.ts.map +1 -0
- package/dist/serialization/index.js +11 -0
- package/dist/serialization/index.js.map +1 -0
- package/dist/serialization/serializedBlockDefinition.d.ts +12 -0
- package/dist/serialization/serializedBlockDefinition.d.ts.map +1 -0
- package/dist/serialization/serializedBlockDefinition.js +2 -0
- package/dist/serialization/serializedBlockDefinition.js.map +1 -0
- package/dist/serialization/serializedShaderBlockDefinition.d.ts +7 -0
- package/dist/serialization/serializedShaderBlockDefinition.d.ts.map +1 -0
- package/dist/serialization/serializedShaderBlockDefinition.js +2 -0
- package/dist/serialization/serializedShaderBlockDefinition.js.map +1 -0
- package/dist/serialization/serializedSmartFilter.d.ts +6 -0
- package/dist/serialization/serializedSmartFilter.d.ts.map +1 -0
- package/dist/serialization/serializedSmartFilter.js +2 -0
- package/dist/serialization/serializedSmartFilter.js.map +1 -0
- package/dist/serialization/smartFilterDeserializer.d.ts +34 -0
- package/dist/serialization/smartFilterDeserializer.d.ts.map +1 -0
- package/dist/serialization/smartFilterDeserializer.js +141 -0
- package/dist/serialization/smartFilterDeserializer.js.map +1 -0
- package/dist/serialization/smartFilterSerializer.d.ts +23 -0
- package/dist/serialization/smartFilterSerializer.d.ts.map +1 -0
- package/dist/serialization/smartFilterSerializer.js +95 -0
- package/dist/serialization/smartFilterSerializer.js.map +1 -0
- package/dist/serialization/v1/defaultBlockSerializer.d.ts +9 -0
- package/dist/serialization/v1/defaultBlockSerializer.d.ts.map +1 -0
- package/dist/serialization/v1/defaultBlockSerializer.js +19 -0
- package/dist/serialization/v1/defaultBlockSerializer.js.map +1 -0
- package/dist/serialization/v1/index.d.ts +4 -0
- package/dist/serialization/v1/index.d.ts.map +1 -0
- package/dist/serialization/v1/index.js +5 -0
- package/dist/serialization/v1/index.js.map +1 -0
- package/dist/serialization/v1/shaderBlockSerialization.types.d.ts +73 -0
- package/dist/serialization/v1/shaderBlockSerialization.types.d.ts.map +1 -0
- package/dist/serialization/v1/shaderBlockSerialization.types.js +7 -0
- package/dist/serialization/v1/shaderBlockSerialization.types.js.map +1 -0
- package/dist/serialization/v1/smartFilterSerialization.types.d.ts +98 -0
- package/dist/serialization/v1/smartFilterSerialization.types.d.ts.map +1 -0
- package/dist/serialization/v1/smartFilterSerialization.types.js +2 -0
- package/dist/serialization/v1/smartFilterSerialization.types.js.map +1 -0
- package/dist/smartFilter.d.ts +118 -0
- package/dist/smartFilter.d.ts.map +1 -0
- package/dist/smartFilter.js +169 -0
- package/dist/smartFilter.js.map +1 -0
- package/dist/utils/buildTools/buildShaders.d.ts +9 -0
- package/dist/utils/buildTools/buildShaders.d.ts.map +1 -0
- package/dist/utils/buildTools/buildShaders.js +13 -0
- package/dist/utils/buildTools/buildShaders.js.map +1 -0
- package/dist/utils/buildTools/convertGlslIntoBlock.d.ts +9 -0
- package/dist/utils/buildTools/convertGlslIntoBlock.d.ts.map +1 -0
- package/dist/utils/buildTools/convertGlslIntoBlock.js +346 -0
- package/dist/utils/buildTools/convertGlslIntoBlock.js.map +1 -0
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts +26 -0
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.d.ts.map +1 -0
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.js +141 -0
- package/dist/utils/buildTools/convertGlslIntoShaderProgram.js.map +1 -0
- package/dist/utils/buildTools/convertShaders.d.ts +16 -0
- package/dist/utils/buildTools/convertShaders.d.ts.map +1 -0
- package/dist/utils/buildTools/convertShaders.js +62 -0
- package/dist/utils/buildTools/convertShaders.js.map +1 -0
- package/dist/utils/buildTools/shaderCode.types.d.ts +51 -0
- package/dist/utils/buildTools/shaderCode.types.d.ts.map +1 -0
- package/dist/utils/buildTools/shaderCode.types.js +2 -0
- package/dist/utils/buildTools/shaderCode.types.js.map +1 -0
- package/dist/utils/buildTools/shaderConverter.d.ts +77 -0
- package/dist/utils/buildTools/shaderConverter.d.ts.map +1 -0
- package/dist/utils/buildTools/shaderConverter.js +297 -0
- package/dist/utils/buildTools/shaderConverter.js.map +1 -0
- package/dist/utils/buildTools/watchShaders.d.ts +9 -0
- package/dist/utils/buildTools/watchShaders.d.ts.map +1 -0
- package/dist/utils/buildTools/watchShaders.js +39 -0
- package/dist/utils/buildTools/watchShaders.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/renderTargetUtils.d.ts +14 -0
- package/dist/utils/renderTargetUtils.d.ts.map +1 -0
- package/dist/utils/renderTargetUtils.js +23 -0
- package/dist/utils/renderTargetUtils.js.map +1 -0
- package/dist/utils/shaderCodeUtils.d.ts +91 -0
- package/dist/utils/shaderCodeUtils.d.ts.map +1 -0
- package/dist/utils/shaderCodeUtils.js +111 -0
- package/dist/utils/shaderCodeUtils.js.map +1 -0
- package/dist/utils/textureLoaders.d.ts +16 -0
- package/dist/utils/textureLoaders.d.ts.map +1 -0
- package/dist/utils/textureLoaders.js +22 -0
- package/dist/utils/textureLoaders.js.map +1 -0
- package/dist/utils/textureUtils.d.ts +13 -0
- package/dist/utils/textureUtils.d.ts.map +1 -0
- package/dist/utils/textureUtils.js +25 -0
- package/dist/utils/textureUtils.js.map +1 -0
- package/dist/utils/uniqueIdGenerator.d.ts +19 -0
- package/dist/utils/uniqueIdGenerator.d.ts.map +1 -0
- package/dist/utils/uniqueIdGenerator.js +27 -0
- package/dist/utils/uniqueIdGenerator.js.map +1 -0
- package/dist/version.d.ts +5 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +5 -0
- package/dist/version.js.map +1 -0
- package/package.json +1 -1
- package/src/optimization/smartFilterOptimizer.ts +305 -158
- package/src/version.ts +1 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { EffectRenderer } from "@onerjs/core/Materials/effectRenderer.js";
|
|
2
|
+
import { CommandBuffer } from "../command/commandBuffer.js";
|
|
3
|
+
/**
|
|
4
|
+
* The internal runtime implementation exposing more information than @see SmartFilterRuntime.
|
|
5
|
+
* This is used internally to render the smart filter.
|
|
6
|
+
*
|
|
7
|
+
* It is not fully exposed publicly to prevent any misuse of the runtime.
|
|
8
|
+
*/
|
|
9
|
+
export class InternalSmartFilterRuntime {
|
|
10
|
+
/**
|
|
11
|
+
* Instantiates a new smart filter runtime for one given engine.
|
|
12
|
+
* @param engine - the engine to use to render the smart filter
|
|
13
|
+
*/
|
|
14
|
+
constructor(engine) {
|
|
15
|
+
this.engine = engine;
|
|
16
|
+
this._resources = [];
|
|
17
|
+
this.commandBuffer = new CommandBuffer();
|
|
18
|
+
this.effectRenderer = new EffectRenderer(engine);
|
|
19
|
+
this.registerResource(this.effectRenderer);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Register a resource to be disposed when the runtime is disposed.
|
|
23
|
+
* @param resource - defines the resource to dispose once the runtime is disposed
|
|
24
|
+
*/
|
|
25
|
+
registerResource(resource) {
|
|
26
|
+
this._resources.push(resource);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Registers a command to be executed during the render loop.
|
|
30
|
+
* @param command - defines the command to execute
|
|
31
|
+
*/
|
|
32
|
+
registerCommand(command) {
|
|
33
|
+
this.commandBuffer.push(command);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Renders the smart filter.
|
|
37
|
+
* This function will execute all the commands contained int the command buffer.
|
|
38
|
+
*/
|
|
39
|
+
render() {
|
|
40
|
+
try {
|
|
41
|
+
const depthTest = this.engine.depthCullingState.depthTest;
|
|
42
|
+
const stencilTest = this.engine.stencilState.stencilTest;
|
|
43
|
+
this.commandBuffer.execute();
|
|
44
|
+
// EffectRenderer.applyEffectWrapper(), which is called by ShaderRuntime._draw(),
|
|
45
|
+
// sets the depth/stencil state, so we need to restore it.
|
|
46
|
+
this.engine.depthCullingState.depthTest = depthTest;
|
|
47
|
+
this.engine.stencilState.stencilTest = stencilTest;
|
|
48
|
+
}
|
|
49
|
+
catch (e) {
|
|
50
|
+
// eslint-disable-next-line no-debugger
|
|
51
|
+
debugger;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Dispose the runtime and all its associated resources
|
|
56
|
+
*/
|
|
57
|
+
dispose() {
|
|
58
|
+
for (const resource of this._resources) {
|
|
59
|
+
resource.dispose();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=smartFilterRuntime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterRuntime.js","sourceRoot":"","sources":["../../src/runtime/smartFilterRuntime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,iDAAyC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAyB5D;;;;;GAKG;AACH,MAAM,OAAO,0BAA0B;IAkBnC;;;OAGG;IACH,YAAY,MAAkB;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QAErB,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;QAEzC,IAAI,CAAC,cAAc,GAAG,IAAI,cAAc,CAAC,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;IAED;;;OAGG;IACI,gBAAgB,CAAC,QAAqB;QACzC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACnC,CAAC;IAED;;;OAGG;IACI,eAAe,CAAC,OAAgB;QACnC,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,MAAM;QACT,IAAI,CAAC;YACD,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,CAAC;YAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,CAAC;YAEzD,IAAI,CAAC,aAAa,CAAC,OAAO,EAAE,CAAC;YAE7B,iFAAiF;YACjF,0DAA0D;YAC1D,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,SAAS,GAAG,SAAS,CAAC;YACpD,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,WAAW,GAAG,WAAW,CAAC;QACvD,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,uCAAuC;YACvC,QAAQ,CAAC;QACb,CAAC;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACvB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This describes a strong reference to any data type.
|
|
3
|
+
*/
|
|
4
|
+
export type StrongRef<T> = {
|
|
5
|
+
/**
|
|
6
|
+
* The value of the strong reference.
|
|
7
|
+
*/
|
|
8
|
+
value: T;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Create a strong reference to the given value.
|
|
12
|
+
* @param value - the value to wrap in a strong reference
|
|
13
|
+
* @returns the strong reference containing the value
|
|
14
|
+
*/
|
|
15
|
+
export declare function CreateStrongRef<T>(value: T): StrongRef<T>;
|
|
16
|
+
//# sourceMappingURL=strongRef.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongRef.d.ts","sourceRoot":"","sources":["../../src/runtime/strongRef.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI;IACvB;;OAEG;IACH,KAAK,EAAE,CAAC,CAAC;CACZ,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAEzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a strong reference to the given value.
|
|
3
|
+
* @param value - the value to wrap in a strong reference
|
|
4
|
+
* @returns the strong reference containing the value
|
|
5
|
+
*/
|
|
6
|
+
export function CreateStrongRef(value) {
|
|
7
|
+
return { value };
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=strongRef.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongRef.js","sourceRoot":"","sources":["../../src/runtime/strongRef.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAI,KAAQ;IACvC,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SerializedBlockDefinition } from "./serializedBlockDefinition.js";
|
|
2
|
+
/**
|
|
3
|
+
* Imports a serialized custom block definition. Supports either serialized CustomShaderBlock definitions or
|
|
4
|
+
* CustomAggregateBlock definitions. Can throw an exception if the serialized data is invalid.
|
|
5
|
+
*
|
|
6
|
+
* CustomShaderBlock definitions can be supplied either as serialized SerializedBlockDefinition object
|
|
7
|
+
* or a glsl shader with the required annotations (see readme.md for details).
|
|
8
|
+
*
|
|
9
|
+
* CustomAggregateBlock definitions must be supplied as serialized SerializedBlockDefinition object.
|
|
10
|
+
*
|
|
11
|
+
* @param serializedData - The serialized data
|
|
12
|
+
* @returns The serialized block definition
|
|
13
|
+
*/
|
|
14
|
+
export declare function ImportCustomBlockDefinition(serializedData: string): SerializedBlockDefinition;
|
|
15
|
+
//# sourceMappingURL=importCustomBlockDefinition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importCustomBlockDefinition.d.ts","sourceRoot":"","sources":["../../src/serialization/importCustomBlockDefinition.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,gCAAgC,CAAC;AAIhF;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CAAC,cAAc,EAAE,MAAM,GAAG,yBAAyB,CAyB7F"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ConnectionPointType } from "../connection/connectionPointType.js";
|
|
2
|
+
import { HasGlslHeader, ParseFragmentShader } from "../utils/buildTools/shaderConverter.js";
|
|
3
|
+
/**
|
|
4
|
+
* Imports a serialized custom block definition. Supports either serialized CustomShaderBlock definitions or
|
|
5
|
+
* CustomAggregateBlock definitions. Can throw an exception if the serialized data is invalid.
|
|
6
|
+
*
|
|
7
|
+
* CustomShaderBlock definitions can be supplied either as serialized SerializedBlockDefinition object
|
|
8
|
+
* or a glsl shader with the required annotations (see readme.md for details).
|
|
9
|
+
*
|
|
10
|
+
* CustomAggregateBlock definitions must be supplied as serialized SerializedBlockDefinition object.
|
|
11
|
+
*
|
|
12
|
+
* @param serializedData - The serialized data
|
|
13
|
+
* @returns The serialized block definition
|
|
14
|
+
*/
|
|
15
|
+
export function ImportCustomBlockDefinition(serializedData) {
|
|
16
|
+
if (HasGlslHeader(serializedData)) {
|
|
17
|
+
return ImportAnnotatedGlsl(serializedData);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
// Assume this is a serialized JSON object
|
|
21
|
+
const blockDefinition = JSON.parse(serializedData);
|
|
22
|
+
// Some old SmartFilters didn't have a format property - default to smartFilter if missing
|
|
23
|
+
if (blockDefinition.format === undefined) {
|
|
24
|
+
blockDefinition.format = "smartFilter";
|
|
25
|
+
}
|
|
26
|
+
// SmartFilters can be serialized without a blockType
|
|
27
|
+
// By convention, we use the SmartFilter name as the blockType when importing them as SerializedBlockDefinitions
|
|
28
|
+
if (blockDefinition.format === "smartFilter" && blockDefinition.name && !blockDefinition.blockType) {
|
|
29
|
+
blockDefinition.blockType = blockDefinition.name;
|
|
30
|
+
}
|
|
31
|
+
// Validation
|
|
32
|
+
if (!blockDefinition.blockType) {
|
|
33
|
+
throw new Error("Could not find a blockType");
|
|
34
|
+
}
|
|
35
|
+
return blockDefinition;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Converts a fragment shader .glsl file to an SerializedBlockDefinition instance for use
|
|
40
|
+
* as a CustomShaderBlock. The .glsl file must contain certain annotations to be imported.
|
|
41
|
+
* See readme.md for more information.
|
|
42
|
+
* @param fragmentShader - The contents of the .glsl fragment shader file
|
|
43
|
+
* @returns The serialized block definition
|
|
44
|
+
*/
|
|
45
|
+
function ImportAnnotatedGlsl(fragmentShader) {
|
|
46
|
+
const fragmentShaderInfo = ParseFragmentShader(fragmentShader);
|
|
47
|
+
if (!fragmentShaderInfo.blockType) {
|
|
48
|
+
throw new Error("blockType must be defined");
|
|
49
|
+
}
|
|
50
|
+
// Calculate the input connection points
|
|
51
|
+
const inputConnectionPoints = [];
|
|
52
|
+
for (const uniform of fragmentShaderInfo.uniforms) {
|
|
53
|
+
// Add to input connection point list
|
|
54
|
+
const inputConnectionPoint = {
|
|
55
|
+
name: uniform.name,
|
|
56
|
+
type: uniform.type,
|
|
57
|
+
autoBind: uniform.properties?.autoBind,
|
|
58
|
+
};
|
|
59
|
+
if (inputConnectionPoint.type !== ConnectionPointType.Texture && uniform.properties?.default !== undefined) {
|
|
60
|
+
inputConnectionPoint.defaultValue = uniform.properties.default;
|
|
61
|
+
}
|
|
62
|
+
inputConnectionPoints.push(inputConnectionPoint);
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
format: "shaderBlockDefinition",
|
|
66
|
+
formatVersion: 1,
|
|
67
|
+
blockType: fragmentShaderInfo.blockType,
|
|
68
|
+
namespace: fragmentShaderInfo.namespace,
|
|
69
|
+
shaderProgram: {
|
|
70
|
+
fragment: fragmentShaderInfo.shaderCode,
|
|
71
|
+
},
|
|
72
|
+
inputConnectionPoints,
|
|
73
|
+
disableOptimization: !!fragmentShaderInfo.disableOptimization,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=importCustomBlockDefinition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importCustomBlockDefinition.js","sourceRoot":"","sources":["../../src/serialization/importCustomBlockDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAK5F;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,2BAA2B,CAAC,cAAsB;IAC9D,IAAI,aAAa,CAAC,cAAc,CAAC,EAAE,CAAC;QAChC,OAAO,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAC/C,CAAC;SAAM,CAAC;QACJ,0CAA0C;QAC1C,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;QAEnD,0FAA0F;QAC1F,IAAI,eAAe,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YACvC,eAAe,CAAC,MAAM,GAAG,aAAa,CAAC;QAC3C,CAAC;QAED,qDAAqD;QACrD,gHAAgH;QAChH,IAAI,eAAe,CAAC,MAAM,KAAK,aAAa,IAAI,eAAe,CAAC,IAAI,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;YACjG,eAAe,CAAC,SAAS,GAAG,eAAe,CAAC,IAAI,CAAC;QACrD,CAAC;QAED,aAAa;QACb,IAAI,CAAC,eAAe,CAAC,SAAS,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAClD,CAAC;QAED,OAAO,eAAe,CAAC;IAC3B,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,SAAS,mBAAmB,CAAC,cAAsB;IAC/C,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAE/D,IAAI,CAAC,kBAAkB,CAAC,SAAS,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;IACjD,CAAC;IAED,wCAAwC;IACxC,MAAM,qBAAqB,GAAuC,EAAE,CAAC;IACrE,KAAK,MAAM,OAAO,IAAI,kBAAkB,CAAC,QAAQ,EAAE,CAAC;QAChD,qCAAqC;QACrC,MAAM,oBAAoB,GAAqC;YAC3D,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,QAAQ,EAAE,OAAO,CAAC,UAAU,EAAE,QAA2B;SAC5D,CAAC;QACF,IAAI,oBAAoB,CAAC,IAAI,KAAK,mBAAmB,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;YACzG,oBAAoB,CAAC,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;QACnE,CAAC;QACD,qBAAqB,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;IACrD,CAAC;IAED,OAAO;QACH,MAAM,EAAE,uBAAuB;QAC/B,aAAa,EAAE,CAAC;QAChB,SAAS,EAAE,kBAAkB,CAAC,SAAS;QACvC,SAAS,EAAE,kBAAkB,CAAC,SAAS;QACvC,aAAa,EAAE;YACX,QAAQ,EAAE,kBAAkB,CAAC,UAAU;SAC1C;QACD,qBAAqB;QACrB,mBAAmB,EAAE,CAAC,CAAC,kBAAkB,CAAC,mBAAmB;KAChE,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from "./v1/index.js";
|
|
2
|
+
export * from "./serializedSmartFilter.js";
|
|
3
|
+
export * from "./smartFilterDeserializer.js";
|
|
4
|
+
export * from "./smartFilterSerializer.js";
|
|
5
|
+
export * from "./serializedShaderBlockDefinition.js";
|
|
6
|
+
export * from "./serializedBlockDefinition.js";
|
|
7
|
+
export * from "./importCustomBlockDefinition.js";
|
|
8
|
+
export { ImportCustomBlockDefinition as importCustomBlockDefinition } from "./importCustomBlockDefinition.js";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AACA,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AAEjD,OAAO,EAAE,2BAA2B,IAAI,2BAA2B,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* eslint-disable import/no-internal-modules */
|
|
2
|
+
export * from "./v1/index.js";
|
|
3
|
+
export * from "./serializedSmartFilter.js";
|
|
4
|
+
export * from "./smartFilterDeserializer.js";
|
|
5
|
+
export * from "./smartFilterSerializer.js";
|
|
6
|
+
export * from "./serializedShaderBlockDefinition.js";
|
|
7
|
+
export * from "./serializedBlockDefinition.js";
|
|
8
|
+
export * from "./importCustomBlockDefinition.js";
|
|
9
|
+
// Back compat for when camelCase was used
|
|
10
|
+
export { ImportCustomBlockDefinition as importCustomBlockDefinition } from "./importCustomBlockDefinition.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/serialization/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,cAAc,eAAe,CAAC;AAC9B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,kCAAkC,CAAC;AACjD,0CAA0C;AAC1C,OAAO,EAAE,2BAA2B,IAAI,2BAA2B,EAAE,MAAM,kCAAkC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SerializedShaderBlockDefinition } from "./serializedShaderBlockDefinition.js";
|
|
2
|
+
import type { SerializedSmartFilter } from "./serializedSmartFilter.js";
|
|
3
|
+
/**
|
|
4
|
+
* Type that represents any type of serialized block definition - shader or aggregate.
|
|
5
|
+
*/
|
|
6
|
+
export type SerializedBlockDefinition = (SerializedShaderBlockDefinition | SerializedSmartFilter) & {
|
|
7
|
+
/**
|
|
8
|
+
* The type of block this is.
|
|
9
|
+
*/
|
|
10
|
+
blockType: string;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=serializedBlockDefinition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializedBlockDefinition.d.ts","sourceRoot":"","sources":["../../src/serialization/serializedBlockDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,sCAAsC,CAAC;AAC5F,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,+BAA+B,GAAG,qBAAqB,CAAC,GAAG;IAChG;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;CACrB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializedBlockDefinition.js","sourceRoot":"","sources":["../../src/serialization/serializedBlockDefinition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SerializedShaderBlockDefinitionV1 } from "./v1/shaderBlockSerialization.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Type union of all versions of serialized SmartFilter block definitions
|
|
4
|
+
* A block definition is an object which is used to create a CustomShaderBlock instance.
|
|
5
|
+
*/
|
|
6
|
+
export type SerializedShaderBlockDefinition = SerializedShaderBlockDefinitionV1;
|
|
7
|
+
//# sourceMappingURL=serializedShaderBlockDefinition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializedShaderBlockDefinition.d.ts","sourceRoot":"","sources":["../../src/serialization/serializedShaderBlockDefinition.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iCAAiC,EAAE,MAAM,wCAAwC,CAAC;AAEhG;;;GAGG;AACH,MAAM,MAAM,+BAA+B,GAAG,iCAAiC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializedShaderBlockDefinition.js","sourceRoot":"","sources":["../../src/serialization/serializedShaderBlockDefinition.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SerializedSmartFilterV1 } from "./v1/smartFilterSerialization.types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Type union of all versions of serialized SmartFilters
|
|
4
|
+
*/
|
|
5
|
+
export type SerializedSmartFilter = SerializedSmartFilterV1;
|
|
6
|
+
//# sourceMappingURL=serializedSmartFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializedSmartFilter.d.ts","sourceRoot":"","sources":["../../src/serialization/serializedSmartFilter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAEtF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serializedSmartFilter.js","sourceRoot":"","sources":["../../src/serialization/serializedSmartFilter.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BaseBlock } from "../blockFoundation/baseBlock.js";
|
|
2
|
+
import { SmartFilter } from "../smartFilter.js";
|
|
3
|
+
import type { ThinEngine } from "@onerjs/core/Engines/thinEngine.js";
|
|
4
|
+
import type { ISerializedBlockV1, OptionalBlockDeserializerV1 } from "./v1/smartFilterSerialization.types.js";
|
|
5
|
+
import type { Nullable } from "@onerjs/core/types.js";
|
|
6
|
+
/**
|
|
7
|
+
* A function that creates a block instance of the given class block type, or return null if it cannot.
|
|
8
|
+
*/
|
|
9
|
+
export type BlockFactory = (smartFilter: SmartFilter, engine: ThinEngine, serializedBlock: ISerializedBlockV1, smartFilterDeserializer: SmartFilterDeserializer) => Promise<Nullable<BaseBlock>>;
|
|
10
|
+
/**
|
|
11
|
+
* Deserializes serialized SmartFilters. The caller passes in a map of block deserializers it wants to use,
|
|
12
|
+
* which allows the caller to provide custom deserializers for blocks beyond the core blocks.
|
|
13
|
+
* The deserializer supports versioned serialized SmartFilters.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SmartFilterDeserializer {
|
|
16
|
+
private readonly _blockFactory;
|
|
17
|
+
private readonly _customInputBlockDeserializer?;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new SmartFilterDeserializer
|
|
20
|
+
* @param blockFactory - A function that creates a block of the given class name, or returns null if it cannot
|
|
21
|
+
* @param customInputBlockDeserializer - An optional custom deserializer for InputBlocks - if supplied and it returns null, the default deserializer will be used
|
|
22
|
+
*/
|
|
23
|
+
constructor(blockFactory: BlockFactory, customInputBlockDeserializer?: OptionalBlockDeserializerV1);
|
|
24
|
+
/**
|
|
25
|
+
* Deserializes a SmartFilter from a JSON object - can be safely called multiple times and has no side effects within the class.
|
|
26
|
+
* @param engine - The ThinEngine to pass to the new SmartFilter
|
|
27
|
+
* @param smartFilterJson - The JSON object to deserialize
|
|
28
|
+
* @returns A promise that resolves to the deserialized SmartFilter
|
|
29
|
+
*/
|
|
30
|
+
deserialize(engine: ThinEngine, smartFilterJson: any): Promise<SmartFilter>;
|
|
31
|
+
private _deserializeV1Async;
|
|
32
|
+
private _deserializeBlockV1Async;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=smartFilterDeserializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterDeserializer.d.ts","sourceRoot":"","sources":["../../src/serialization/smartFilterDeserializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAIhD,OAAO,KAAK,EAAE,UAAU,EAAE,2CAAmC;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAA2B,2BAA2B,EAA2B,MAAM,wCAAwC,CAAC;AAEhK,OAAO,KAAK,EAAE,QAAQ,EAAE,8BAAsB;AAE9C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CACvB,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,UAAU,EAClB,eAAe,EAAE,kBAAkB,EACnC,uBAAuB,EAAE,uBAAuB,KAC/C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC;AAElC;;;;GAIG;AACH,qBAAa,uBAAuB;IAChC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,6BAA6B,CAAC,CAA8B;IAE7E;;;;OAIG;gBACgB,YAAY,EAAE,YAAY,EAAE,4BAA4B,CAAC,EAAE,2BAA2B;IAKzG;;;;;OAKG;IAEU,WAAW,CAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC;YAc1E,mBAAmB;YA0DnB,wBAAwB;CAqEzC"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { SmartFilter } from "../smartFilter.js";
|
|
2
|
+
import { ShaderBlock } from "../blockFoundation/shaderBlock.js";
|
|
3
|
+
import { InputBlockDeserializer } from "../blockFoundation/inputBlock.deserializer.js";
|
|
4
|
+
import { OutputBlock } from "../blockFoundation/outputBlock.js";
|
|
5
|
+
import { InputBlock } from "../blockFoundation/inputBlock.js";
|
|
6
|
+
import { UniqueIdGenerator } from "../utils/uniqueIdGenerator.js";
|
|
7
|
+
/**
|
|
8
|
+
* Deserializes serialized SmartFilters. The caller passes in a map of block deserializers it wants to use,
|
|
9
|
+
* which allows the caller to provide custom deserializers for blocks beyond the core blocks.
|
|
10
|
+
* The deserializer supports versioned serialized SmartFilters.
|
|
11
|
+
*/
|
|
12
|
+
export class SmartFilterDeserializer {
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new SmartFilterDeserializer
|
|
15
|
+
* @param blockFactory - A function that creates a block of the given class name, or returns null if it cannot
|
|
16
|
+
* @param customInputBlockDeserializer - An optional custom deserializer for InputBlocks - if supplied and it returns null, the default deserializer will be used
|
|
17
|
+
*/
|
|
18
|
+
constructor(blockFactory, customInputBlockDeserializer) {
|
|
19
|
+
this._blockFactory = blockFactory;
|
|
20
|
+
this._customInputBlockDeserializer = customInputBlockDeserializer;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Deserializes a SmartFilter from a JSON object - can be safely called multiple times and has no side effects within the class.
|
|
24
|
+
* @param engine - The ThinEngine to pass to the new SmartFilter
|
|
25
|
+
* @param smartFilterJson - The JSON object to deserialize
|
|
26
|
+
* @returns A promise that resolves to the deserialized SmartFilter
|
|
27
|
+
*/
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
29
|
+
async deserialize(engine, smartFilterJson) {
|
|
30
|
+
const serializedSmartFilter = smartFilterJson;
|
|
31
|
+
// Back-compat for the rename of version to formatVersion, didn't warrant a new version
|
|
32
|
+
if (serializedSmartFilter.version && serializedSmartFilter.formatVersion === undefined) {
|
|
33
|
+
serializedSmartFilter.formatVersion = serializedSmartFilter.version;
|
|
34
|
+
}
|
|
35
|
+
switch (serializedSmartFilter.formatVersion) {
|
|
36
|
+
case 1:
|
|
37
|
+
return await this._deserializeV1Async(engine, serializedSmartFilter);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async _deserializeV1Async(engine, serializedSmartFilter) {
|
|
41
|
+
const smartFilter = new SmartFilter(serializedSmartFilter.name, serializedSmartFilter.namespace);
|
|
42
|
+
const blockIdMap = new Map();
|
|
43
|
+
// Only needed for smart filters saved before we started using uniqueIds for the maps, didn't warrant new version
|
|
44
|
+
const blockNameMap = new Map();
|
|
45
|
+
// Deserialize the SmartFilter level data
|
|
46
|
+
smartFilter.comments = serializedSmartFilter.comments;
|
|
47
|
+
smartFilter.editorData = serializedSmartFilter.editorData;
|
|
48
|
+
// Deserialize the blocks
|
|
49
|
+
const blockDeserializationWork = [];
|
|
50
|
+
const blockDefinitionsWhichCouldNotBeDeserialized = [];
|
|
51
|
+
serializedSmartFilter.blocks.forEach((serializedBlock) => {
|
|
52
|
+
blockDeserializationWork.push(this._deserializeBlockV1Async(smartFilter, serializedBlock, engine, blockDefinitionsWhichCouldNotBeDeserialized, blockIdMap, blockNameMap));
|
|
53
|
+
});
|
|
54
|
+
await Promise.all(blockDeserializationWork);
|
|
55
|
+
// If any block definitions could not be deserialized, throw an error
|
|
56
|
+
if (blockDefinitionsWhichCouldNotBeDeserialized.length > 0) {
|
|
57
|
+
throw new Error(`Could not deserialize the following block definitions: ${blockDefinitionsWhichCouldNotBeDeserialized.join(", ")}`);
|
|
58
|
+
}
|
|
59
|
+
// Deserialize the connections
|
|
60
|
+
serializedSmartFilter.connections.forEach((connection) => {
|
|
61
|
+
// Find the source block and its connection point's connectTo function
|
|
62
|
+
const sourceBlock = typeof connection.outputBlock === "string" ? blockNameMap.get(connection.outputBlock) : blockIdMap.get(connection.outputBlock);
|
|
63
|
+
if (!sourceBlock) {
|
|
64
|
+
throw new Error(`Source block ${connection.outputBlock} not found`);
|
|
65
|
+
}
|
|
66
|
+
const sourceConnectionPoint = sourceBlock.outputs.find((output) => output.name === connection.outputConnectionPoint);
|
|
67
|
+
if (!sourceConnectionPoint || typeof sourceConnectionPoint.connectTo !== "function") {
|
|
68
|
+
throw new Error(`Block ${connection.outputBlock} does not have an connection point named ${connection.outputConnectionPoint}`);
|
|
69
|
+
}
|
|
70
|
+
const sourceConnectToFunction = sourceConnectionPoint.connectTo.bind(sourceConnectionPoint);
|
|
71
|
+
// Find the target block and its connection point
|
|
72
|
+
const targetBlock = typeof connection.inputBlock === "string" ? blockNameMap.get(connection.inputBlock) : blockIdMap.get(connection.inputBlock);
|
|
73
|
+
if (!targetBlock) {
|
|
74
|
+
throw new Error(`Target block ${connection.inputBlock} not found`);
|
|
75
|
+
}
|
|
76
|
+
const targetConnectionPoint = targetBlock.inputs.find((input) => input.name === connection.inputConnectionPoint);
|
|
77
|
+
if (!targetConnectionPoint || typeof targetConnectionPoint !== "object") {
|
|
78
|
+
throw new Error(`Block ${connection.inputBlock} does not have a connection point named ${connection.inputConnectionPoint}`);
|
|
79
|
+
}
|
|
80
|
+
// Create the connection
|
|
81
|
+
sourceConnectToFunction.call(sourceBlock, targetConnectionPoint);
|
|
82
|
+
});
|
|
83
|
+
return smartFilter;
|
|
84
|
+
}
|
|
85
|
+
async _deserializeBlockV1Async(smartFilter, serializedBlock, engine, blockTypesWhichCouldNotBeDeserialized, blockIdMap, blockNameMap) {
|
|
86
|
+
let newBlock = null;
|
|
87
|
+
// Back compat for early Smart Filter V1 serialization where the blockType was stored in className
|
|
88
|
+
// Not worth creating a new version for this, as it's only used in the deserializer
|
|
89
|
+
if (serializedBlock.className && !serializedBlock.blockType) {
|
|
90
|
+
serializedBlock.blockType = serializedBlock.className;
|
|
91
|
+
}
|
|
92
|
+
// Back compat for early Smart Filter V1 serialization where the namespace was not stored
|
|
93
|
+
if (serializedBlock.namespace === undefined) {
|
|
94
|
+
serializedBlock.namespace = null;
|
|
95
|
+
}
|
|
96
|
+
// Get the instance of the block
|
|
97
|
+
switch (serializedBlock.blockType) {
|
|
98
|
+
case InputBlock.ClassName:
|
|
99
|
+
{
|
|
100
|
+
if (this._customInputBlockDeserializer) {
|
|
101
|
+
newBlock = await this._customInputBlockDeserializer(smartFilter, serializedBlock, engine);
|
|
102
|
+
}
|
|
103
|
+
if (newBlock === null) {
|
|
104
|
+
newBlock = InputBlockDeserializer(smartFilter, serializedBlock);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case OutputBlock.ClassName:
|
|
109
|
+
{
|
|
110
|
+
newBlock = smartFilter.output.ownerBlock;
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
default: {
|
|
114
|
+
// If it's not an input or output block, use the provided block factory
|
|
115
|
+
newBlock = await this._blockFactory(smartFilter, engine, serializedBlock, this);
|
|
116
|
+
if (!newBlock) {
|
|
117
|
+
if (blockTypesWhichCouldNotBeDeserialized.indexOf(serializedBlock.blockType) === -1) {
|
|
118
|
+
blockTypesWhichCouldNotBeDeserialized.push(serializedBlock.blockType);
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Deserializers are not responsible for setting the uniqueId or comments.
|
|
125
|
+
// This is so they don't have to be passed into the constructors when programmatically creating
|
|
126
|
+
// blocks, and so each deserializer doesn't have to remember to do it.
|
|
127
|
+
newBlock.uniqueId = serializedBlock.uniqueId;
|
|
128
|
+
newBlock.comments = serializedBlock.comments;
|
|
129
|
+
// Deserializers are also not responsible for deserializing the outputTextureOptions of ShaderBlocks.
|
|
130
|
+
if (serializedBlock.outputTextureOptions && newBlock instanceof ShaderBlock) {
|
|
131
|
+
newBlock.outputTextureOptions = serializedBlock.outputTextureOptions;
|
|
132
|
+
}
|
|
133
|
+
// We need to ensure any uniqueIds generated in the future (e.g. a new block is added to the SmartFilter)
|
|
134
|
+
// are higher than this one.
|
|
135
|
+
UniqueIdGenerator.EnsureIdsGreaterThan(newBlock.uniqueId);
|
|
136
|
+
// Save in the map
|
|
137
|
+
blockIdMap.set(newBlock.uniqueId, newBlock);
|
|
138
|
+
blockNameMap.set(newBlock.name, newBlock);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=smartFilterDeserializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterDeserializer.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,eAAe,CAAC,SAAS,CAAC,CAAC;oBAC1E,CAAC;oBACD,OAAO;gBACX,CAAC;YACL,CAAC;QACL,CAAC;QAED,0EAA0E;QAC1E,+FAA+F;QAC/F,sEAAsE;QACtE,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;QAC7C,QAAQ,CAAC,QAAQ,GAAG,eAAe,CAAC,QAAQ,CAAC;QAE7C,qGAAqG;QACrG,IAAI,eAAe,CAAC,oBAAoB,IAAI,QAAQ,YAAY,WAAW,EAAE,CAAC;YAC1E,QAAQ,CAAC,oBAAoB,GAAG,eAAe,CAAC,oBAAoB,CAAC;QACzE,CAAC;QAED,yGAAyG;QACzG,4BAA4B;QAC5B,iBAAiB,CAAC,oBAAoB,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAE1D,kBAAkB;QAClB,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5C,YAAY,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC9C,CAAC;CACJ"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SmartFilter } from "../smartFilter.js";
|
|
2
|
+
import type { IBlockSerializerV1, SerializedSmartFilterV1 } from "./v1/smartFilterSerialization.types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Serializes SmartFilters using the latest SmartFilter serialization version.
|
|
5
|
+
* The caller passes in information necessary to serialize the blocks in the SmartFilter.
|
|
6
|
+
* This allows the caller to provide custom serializers for blocks beyond the core blocks.
|
|
7
|
+
*/
|
|
8
|
+
export declare class SmartFilterSerializer {
|
|
9
|
+
private readonly _blockSerializers;
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new SmartFilterSerializer
|
|
12
|
+
* @param blocksUsingDefaultSerialization - A list of the blockType of blocks which can use default serialization (they only have ConnectionPoint properties and no constructor parameters)
|
|
13
|
+
* @param additionalBlockSerializers - An array of block serializers to use, beyond those for the core blocks
|
|
14
|
+
*/
|
|
15
|
+
constructor(blocksUsingDefaultSerialization: string[], additionalBlockSerializers: IBlockSerializerV1[]);
|
|
16
|
+
/**
|
|
17
|
+
* Serializes a SmartFilter to a JSON object of the latest version
|
|
18
|
+
* @param smartFilter - The SmartFilter to serialize
|
|
19
|
+
* @returns The serialized SmartFilter
|
|
20
|
+
*/
|
|
21
|
+
serialize(smartFilter: SmartFilter): SerializedSmartFilterV1;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=smartFilterSerializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterSerializer.d.ts","sourceRoot":"","sources":["../../src/serialization/smartFilterSerializer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAMrD,OAAO,KAAK,EAAE,kBAAkB,EAAiE,uBAAuB,EAAE,MAAM,wCAAwC,CAAC;AAgBzK;;;;GAIG;AACH,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA4C;IAE9E;;;;OAIG;gBACgB,+BAA+B,EAAE,MAAM,EAAE,EAAE,0BAA0B,EAAE,kBAAkB,EAAE;IAS9G;;;;OAIG;IACI,SAAS,CAAC,WAAW,EAAE,WAAW,GAAG,uBAAuB;CA4DtE"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { InputBlockSerializer } from "../blockFoundation/inputBlock.serializer.js";
|
|
2
|
+
import { DefaultBlockSerializer } from "./v1/defaultBlockSerializer.js";
|
|
3
|
+
import { OutputBlock } from "../blockFoundation/outputBlock.js";
|
|
4
|
+
import { CustomShaderBlock } from "../blockFoundation/customShaderBlock.js";
|
|
5
|
+
import { CustomAggregateBlock } from "../blockFoundation/customAggregateBlock.js";
|
|
6
|
+
/**
|
|
7
|
+
* Determines if two serialized connection points are equivalent to each other
|
|
8
|
+
* @param a - The first connection point to compare
|
|
9
|
+
* @param b - The second connection point to compare
|
|
10
|
+
* @returns True if the connection points are equivalent, false otherwise
|
|
11
|
+
*/
|
|
12
|
+
function SerializedConnectionPointsEqual(a, b) {
|
|
13
|
+
return (a.inputBlock === b.inputBlock && a.inputConnectionPoint === b.inputConnectionPoint && a.outputBlock === b.outputBlock && a.outputConnectionPoint === b.outputConnectionPoint);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Serializes SmartFilters using the latest SmartFilter serialization version.
|
|
17
|
+
* The caller passes in information necessary to serialize the blocks in the SmartFilter.
|
|
18
|
+
* This allows the caller to provide custom serializers for blocks beyond the core blocks.
|
|
19
|
+
*/
|
|
20
|
+
export class SmartFilterSerializer {
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new SmartFilterSerializer
|
|
23
|
+
* @param blocksUsingDefaultSerialization - A list of the blockType of blocks which can use default serialization (they only have ConnectionPoint properties and no constructor parameters)
|
|
24
|
+
* @param additionalBlockSerializers - An array of block serializers to use, beyond those for the core blocks
|
|
25
|
+
*/
|
|
26
|
+
constructor(blocksUsingDefaultSerialization, additionalBlockSerializers) {
|
|
27
|
+
this._blockSerializers = new Map();
|
|
28
|
+
this._blockSerializers.set(InputBlockSerializer.blockType, InputBlockSerializer.serialize);
|
|
29
|
+
this._blockSerializers.set(OutputBlock.ClassName, DefaultBlockSerializer);
|
|
30
|
+
blocksUsingDefaultSerialization.forEach((block) => {
|
|
31
|
+
this._blockSerializers.set(block, DefaultBlockSerializer);
|
|
32
|
+
});
|
|
33
|
+
additionalBlockSerializers.forEach((serializer) => this._blockSerializers.set(serializer.blockType, serializer.serialize));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Serializes a SmartFilter to a JSON object of the latest version
|
|
37
|
+
* @param smartFilter - The SmartFilter to serialize
|
|
38
|
+
* @returns The serialized SmartFilter
|
|
39
|
+
*/
|
|
40
|
+
serialize(smartFilter) {
|
|
41
|
+
const connections = [];
|
|
42
|
+
const blocks = smartFilter.attachedBlocks.map((block) => {
|
|
43
|
+
// Serialize the block itself
|
|
44
|
+
const blockClassName = block.getClassName();
|
|
45
|
+
const serializeFn = blockClassName === CustomShaderBlock.ClassName || blockClassName === CustomAggregateBlock.ClassName
|
|
46
|
+
? DefaultBlockSerializer
|
|
47
|
+
: this._blockSerializers.get(block.blockType);
|
|
48
|
+
if (!serializeFn) {
|
|
49
|
+
throw new Error(`No serializer was provided for a block of type ${block.blockType}`);
|
|
50
|
+
}
|
|
51
|
+
const serializedBlock = serializeFn(block);
|
|
52
|
+
// Serialize the connections to the inputs
|
|
53
|
+
block.inputs.forEach((input) => {
|
|
54
|
+
const connectedTo = input.connectedTo;
|
|
55
|
+
if (connectedTo) {
|
|
56
|
+
const newConnection = {
|
|
57
|
+
inputBlock: block.uniqueId,
|
|
58
|
+
inputConnectionPoint: input.name,
|
|
59
|
+
outputBlock: connectedTo.ownerBlock.uniqueId,
|
|
60
|
+
outputConnectionPoint: connectedTo.name,
|
|
61
|
+
};
|
|
62
|
+
if (!connections.find((other) => SerializedConnectionPointsEqual(newConnection, other))) {
|
|
63
|
+
connections.push(newConnection);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
// Serialize the connections to the outputs
|
|
68
|
+
block.outputs.forEach((output) => {
|
|
69
|
+
output.endpoints.forEach((input) => {
|
|
70
|
+
const newConnection = {
|
|
71
|
+
inputBlock: input.ownerBlock.uniqueId,
|
|
72
|
+
inputConnectionPoint: input.name,
|
|
73
|
+
outputBlock: block.uniqueId,
|
|
74
|
+
outputConnectionPoint: output.name,
|
|
75
|
+
};
|
|
76
|
+
if (!connections.find((other) => SerializedConnectionPointsEqual(newConnection, other))) {
|
|
77
|
+
connections.push(newConnection);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
return serializedBlock;
|
|
82
|
+
});
|
|
83
|
+
return {
|
|
84
|
+
format: "smartFilter",
|
|
85
|
+
formatVersion: 1,
|
|
86
|
+
name: smartFilter.name,
|
|
87
|
+
namespace: smartFilter.namespace,
|
|
88
|
+
comments: smartFilter.comments,
|
|
89
|
+
editorData: smartFilter.editorData,
|
|
90
|
+
blocks,
|
|
91
|
+
connections,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=smartFilterSerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"smartFilterSerializer.js","sourceRoot":"","sources":["../../src/serialization/smartFilterSerializer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,6CAA6C,CAAC;AAEnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAEhE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAElF;;;;;GAKG;AACH,SAAS,+BAA+B,CAAC,CAA0B,EAAE,CAA0B;IAC3F,OAAO,CACH,CAAC,CAAC,UAAU,KAAK,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,oBAAoB,KAAK,CAAC,CAAC,oBAAoB,IAAI,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,qBAAqB,KAAK,CAAC,CAAC,qBAAqB,CAC/K,CAAC;AACN,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAG9B;;;;OAIG;IACH,YAAmB,+BAAyC,EAAE,0BAAgD;QAP7F,sBAAiB,GAAkC,IAAI,GAAG,EAAE,CAAC;QAQ1E,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,oBAAoB,CAAC,SAAS,EAAE,oBAAoB,CAAC,SAAS,CAAC,CAAC;QAC3F,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,WAAW,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC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