@babylonjs/core 7.11.3 → 7.11.4
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/Compute/computeEffect.js +21 -3
- package/Compute/computeEffect.js.map +1 -1
- package/Culling/Helper/IBoundingInfoHelperPlatform.d.ts +8 -0
- package/Culling/Helper/IBoundingInfoHelperPlatform.js +2 -0
- package/Culling/Helper/IBoundingInfoHelperPlatform.js.map +1 -0
- package/Culling/Helper/boundingInfoHelper.d.ts +14 -10
- package/Culling/Helper/boundingInfoHelper.js +22 -152
- package/Culling/Helper/boundingInfoHelper.js.map +1 -1
- package/Culling/Helper/computeShaderBoundingHelper.d.ts +34 -0
- package/Culling/Helper/computeShaderBoundingHelper.js +209 -0
- package/Culling/Helper/computeShaderBoundingHelper.js.map +1 -0
- package/Culling/Helper/transformFeedbackBoundingHelper.d.ts +21 -0
- package/Culling/Helper/transformFeedbackBoundingHelper.js +197 -0
- package/Culling/Helper/transformFeedbackBoundingHelper.js.map +1 -0
- package/Culling/index.d.ts +2 -0
- package/Culling/index.js +2 -0
- package/Culling/index.js.map +1 -1
- package/Engines/Processors/shaderProcessingOptions.d.ts +1 -1
- package/Engines/Processors/shaderProcessingOptions.js.map +1 -1
- package/Engines/Processors/shaderProcessor.js +2 -2
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +7 -0
- package/Meshes/abstractMesh.js +17 -0
- package/Meshes/abstractMesh.js.map +1 -1
- package/Morph/morphTargetManager.d.ts +8 -4
- package/Morph/morphTargetManager.js +6 -3
- package/Morph/morphTargetManager.js.map +1 -1
- package/ShadersWGSL/boundingInfo.compute.d.ts +5 -0
- package/ShadersWGSL/boundingInfo.compute.js +80 -0
- package/ShadersWGSL/boundingInfo.compute.js.map +1 -0
- package/package.json +1 -1
- package/Culling/Helper/webgl2BoundingHelper.d.ts +0 -22
- package/Culling/Helper/webgl2BoundingHelper.js +0 -61
- package/Culling/Helper/webgl2BoundingHelper.js.map +0 -1
package/Compute/computeEffect.js
CHANGED
|
@@ -100,15 +100,33 @@ export class ComputeEffect {
|
|
|
100
100
|
processingContext: null,
|
|
101
101
|
isNDCHalfZRange: this._engine.isNDCHalfZRange,
|
|
102
102
|
useReverseDepthBuffer: this._engine.useReverseDepthBuffer,
|
|
103
|
+
processCodeAfterIncludes: (shaderType, code, defines) => {
|
|
104
|
+
if (!defines) {
|
|
105
|
+
return code;
|
|
106
|
+
}
|
|
107
|
+
// We need to convert #define key value to a const
|
|
108
|
+
for (const define of defines) {
|
|
109
|
+
const keyValue = define.replace("#define", "").replace(";", "").trim();
|
|
110
|
+
const split = keyValue.split(" ");
|
|
111
|
+
if (split.length === 2) {
|
|
112
|
+
const key = split[0];
|
|
113
|
+
const value = split[1];
|
|
114
|
+
if (!isNaN(parseInt(value)) || !isNaN(parseFloat(value))) {
|
|
115
|
+
code = `const ${key} = ${value};\n` + code;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return code;
|
|
120
|
+
},
|
|
103
121
|
};
|
|
104
122
|
this._loadShader(computeSource, "Compute", "", (computeCode) => {
|
|
105
123
|
Initialize(processorOptions);
|
|
106
|
-
PreProcess(computeCode, processorOptions, (
|
|
124
|
+
PreProcess(computeCode, processorOptions, (migratedComputeCode) => {
|
|
107
125
|
this._rawComputeSourceCode = computeCode;
|
|
108
126
|
if (options.processFinalCode) {
|
|
109
|
-
|
|
127
|
+
migratedComputeCode = options.processFinalCode(migratedComputeCode);
|
|
110
128
|
}
|
|
111
|
-
const finalShaders = Finalize(
|
|
129
|
+
const finalShaders = Finalize(migratedComputeCode, "", processorOptions);
|
|
112
130
|
this._useFinalCode(finalShaders.vertexCode, baseName);
|
|
113
131
|
}, this._engine);
|
|
114
132
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeEffect.js","sourceRoot":"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,AAAP,CAAQ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IComputePipelineContext } from \"./IComputePipelineContext\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { Finalize, Initialize, PreProcess } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport type { ComputeCompilationMessages } from \"../Engines/Extensions/engine.computeShader\";\r\n\r\n/**\r\n * Defines the route to the shader code. The priority is as follows:\r\n * * object: `{ computeSource: \"compute shader code string\"}` for directly passing the shader code\r\n * * object: `{ computeElement: \"vertexShaderCode\" }`, used with shader code in script tags\r\n * * object: `{ compute: \"custom\" }`, used with `Effect.ShadersStore[\"customVertexShader\"]` and `Effect.ShadersStore[\"customFragmentShader\"]`\r\n * * string: `\"./COMMON_NAME\"`, used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.\r\n */\r\nexport type IComputeShaderPath = {\r\n /**\r\n * Directly pass the shader code\r\n */\r\n computeSource?: string;\r\n /**\r\n * Used with Effect.ShadersStore. If the `vertex` is set to `\"custom`, then\r\n * Babylon.js will read from Effect.ShadersStore[\"customVertexShader\"]\r\n */\r\n compute?: string;\r\n /**\r\n * Used with shader code in script tags\r\n */\r\n computeElement?: string;\r\n};\r\n\r\n/**\r\n * Options to be used when creating a compute effect.\r\n */\r\nexport interface IComputeEffectCreationOptions {\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: ComputeEffect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: ComputeEffect, errors: string) => void>;\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\n/**\r\n * Effect wrapping a compute shader and let execute (dispatch) the shader\r\n */\r\nexport class ComputeEffect {\r\n private static _UniqueIdSeed = 0;\r\n\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: IComputeShaderPath | string;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public onBindObservable = new Observable<ComputeEffect>();\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n private _engine: AbstractEngine;\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n /** @internal */\r\n public _key: string = \"\";\r\n private _computeSourceCodeOverride: string = \"\";\r\n /** @internal */\r\n public _pipelineContext: Nullable<IComputePipelineContext> = null;\r\n /** @internal */\r\n public _computeSourceCode: string = \"\";\r\n private _rawComputeSourceCode: string = \"\";\r\n private _entryPoint: string;\r\n private _shaderLanguage = ShaderLanguage.WGSL;\r\n private _shaderStore: { [key: string]: string };\r\n private _shaderRepository: string;\r\n private _includeShaderStore: { [key: string]: string };\r\n\r\n /**\r\n * Creates a compute effect that can be used to execute a compute shader\r\n * @param baseName Name of the effect\r\n * @param options Set of all options to create the effect\r\n * @param engine The engine the effect is created for\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n */\r\n constructor(baseName: IComputeShaderPath | string, options: IComputeEffectCreationOptions, engine: AbstractEngine, key = \"\") {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n this._engine = engine;\r\n this.uniqueId = ComputeEffect._UniqueIdSeed++;\r\n\r\n this.defines = options.defines ?? \"\";\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._entryPoint = options.entryPoint ?? \"main\";\r\n\r\n this._shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\r\n this._shaderRepository = ShaderStore.GetShadersRepository(this._shaderLanguage);\r\n this._includeShaderStore = ShaderStore.GetIncludesShadersStore(this._shaderLanguage);\r\n\r\n let computeSource: IComputeShaderPath | HTMLElement | string;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (typeof baseName === \"string\") {\r\n computeSource = baseName;\r\n } else if (baseName.computeSource) {\r\n computeSource = \"source:\" + baseName.computeSource;\r\n } else if (baseName.computeElement) {\r\n computeSource = hostDocument?.getElementById(baseName.computeElement) || baseName.computeElement;\r\n } else {\r\n computeSource = baseName.compute || baseName;\r\n }\r\n\r\n const processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: undefined,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: false,\r\n processor: null,\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: this._shaderRepository,\r\n includesShadersStore: this._includeShaderStore,\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: null,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n };\r\n\r\n this._loadShader(computeSource, \"Compute\", \"\", (computeCode) => {\r\n Initialize(processorOptions);\r\n PreProcess(\r\n computeCode,\r\n processorOptions,\r\n (migratedCommputeCode) => {\r\n this._rawComputeSourceCode = computeCode;\r\n if (options.processFinalCode) {\r\n migratedCommputeCode = options.processFinalCode(migratedCommputeCode);\r\n }\r\n const finalShaders = Finalize(migratedCommputeCode, \"\", processorOptions);\r\n this._useFinalCode(finalShaders.vertexCode, baseName);\r\n },\r\n this._engine\r\n );\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedCommputeCode: string, baseName: any) {\r\n if (baseName) {\r\n const compute = baseName.computeElement || baseName.compute || baseName.spectorName || baseName;\r\n\r\n this._computeSourceCode = \"//#define SHADER_NAME compute:\" + compute + \"\\n\" + migratedCommputeCode;\r\n } else {\r\n this._computeSourceCode = migratedCommputeCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): AbstractEngine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable<IComputePipelineContext> {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: ComputeEffect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable<IComputePipelineContext>) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n // Is in local store ?\r\n if (this._shaderStore[shader + key + \"Shader\"]) {\r\n callback(this._shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && this._shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(this._shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = this._shaderRepository + shader;\r\n }\r\n\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code of this effect\r\n */\r\n public get computeSourceCode(): string {\r\n return this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._pipelineContext?._getComputeShaderCode() ?? this._computeSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code before it has been processed by the preprocessor\r\n */\r\n public get rawComputeSourceCode(): string {\r\n return this._rawComputeSourceCode;\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createComputePipelineContext();\r\n this._pipelineContext._name = this._key;\r\n\r\n engine._prepareComputePipelineContext(\r\n this._pipelineContext,\r\n this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._computeSourceCode,\r\n this._rawComputeSourceCode,\r\n this._computeSourceCodeOverride ? null : defines,\r\n this._entryPoint\r\n );\r\n\r\n engine._executeWhenComputeStateIsCompiled(this._pipelineContext, (messages: Nullable<ComputeCompilationMessages>) => {\r\n if (messages && messages.numErrors > 0) {\r\n this._processCompilationErrors(messages, previousPipelineContext);\r\n return;\r\n }\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deleteComputePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _processCompilationErrors(e: ComputeCompilationMessages | string, previousPipelineContext: Nullable<IComputePipelineContext> = null) {\r\n this._compilationError = \"\";\r\n\r\n Logger.Error(\"Unable to compile compute effect:\");\r\n if (this.defines) {\r\n Logger.Error(\"Defines:\\n\" + this.defines);\r\n }\r\n\r\n if (ComputeEffect.LogShaderCodeOnCompilationError) {\r\n const code = this._pipelineContext?._getComputeShaderCode();\r\n if (code) {\r\n Logger.Error(\"Compute code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n\r\n if (typeof e === \"string\") {\r\n this._compilationError = e;\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n } else {\r\n for (const message of e.messages) {\r\n let msg = \"\";\r\n if (message.line !== undefined) {\r\n msg += \"Line \" + message.line + \", \";\r\n }\r\n if (message.offset !== undefined) {\r\n msg += \"Offset \" + message.offset + \", \";\r\n }\r\n if (message.length !== undefined) {\r\n msg += \"Length \" + message.length + \", \";\r\n }\r\n msg += message.type + \": \" + message.text;\r\n\r\n if (this._compilationError) {\r\n this._compilationError += \"\\n\";\r\n }\r\n this._compilationError += msg;\r\n Logger.Error(msg);\r\n }\r\n }\r\n\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n }\r\n\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseComputeEffect(this);\r\n }\r\n\r\n /**\r\n * This function will add a new compute shader to the shader store\r\n * @param name the name of the shader\r\n * @param computeShader compute shader content\r\n */\r\n public static RegisterShader(name: string, computeShader: string) {\r\n ShaderStore.GetShadersStore(ShaderLanguage.WGSL)[`${name}ComputeShader`] = computeShader;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"computeEffect.js","sourceRoot":"","sources":["../../../../dev/core/src/Compute/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AAC,CAAC;aACrB;SACJ;QAED,IAAI,uBAAuB,EAAE;YACzB,IAAI,CAAC,gBAAgB,GAAG,uBAAuB,CAAC;YAChD,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;SACxB;QAED,IAAI,IAAI,CAAC,OAAO,EAAE;YACd,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;SAC9C;QACD,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACjD,CAAC;IAED;;QAEI;IACG,OAAO;QACV,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACvB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;SACnC;QACD,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,IAAY,EAAE,aAAqB;QAC5D,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,eAAe,CAAC,GAAG,aAAa,CAAC;IAC7F,CAAC;;AA/ac,2BAAa,GAAG,CAAC,AAAJ,CAAK;AAEjC;;GAEG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IComputePipelineContext } from \"./IComputePipelineContext\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { Finalize, Initialize, PreProcess } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport type { ComputeCompilationMessages } from \"../Engines/Extensions/engine.computeShader\";\r\n\r\n/**\r\n * Defines the route to the shader code. The priority is as follows:\r\n * * object: `{ computeSource: \"compute shader code string\"}` for directly passing the shader code\r\n * * object: `{ computeElement: \"vertexShaderCode\" }`, used with shader code in script tags\r\n * * object: `{ compute: \"custom\" }`, used with `Effect.ShadersStore[\"customVertexShader\"]` and `Effect.ShadersStore[\"customFragmentShader\"]`\r\n * * string: `\"./COMMON_NAME\"`, used with external files COMMON_NAME.vertex.fx and COMMON_NAME.fragment.fx in index.html folder.\r\n */\r\nexport type IComputeShaderPath = {\r\n /**\r\n * Directly pass the shader code\r\n */\r\n computeSource?: string;\r\n /**\r\n * Used with Effect.ShadersStore. If the `vertex` is set to `\"custom`, then\r\n * Babylon.js will read from Effect.ShadersStore[\"customVertexShader\"]\r\n */\r\n compute?: string;\r\n /**\r\n * Used with shader code in script tags\r\n */\r\n computeElement?: string;\r\n};\r\n\r\n/**\r\n * Options to be used when creating a compute effect.\r\n */\r\nexport interface IComputeEffectCreationOptions {\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: ComputeEffect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: ComputeEffect, errors: string) => void>;\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\n/**\r\n * Effect wrapping a compute shader and let execute (dispatch) the shader\r\n */\r\nexport class ComputeEffect {\r\n private static _UniqueIdSeed = 0;\r\n\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: IComputeShaderPath | string;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public onBindObservable = new Observable<ComputeEffect>();\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n private _engine: AbstractEngine;\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n /** @internal */\r\n public _key: string = \"\";\r\n private _computeSourceCodeOverride: string = \"\";\r\n /** @internal */\r\n public _pipelineContext: Nullable<IComputePipelineContext> = null;\r\n /** @internal */\r\n public _computeSourceCode: string = \"\";\r\n private _rawComputeSourceCode: string = \"\";\r\n private _entryPoint: string;\r\n private _shaderLanguage = ShaderLanguage.WGSL;\r\n private _shaderStore: { [key: string]: string };\r\n private _shaderRepository: string;\r\n private _includeShaderStore: { [key: string]: string };\r\n\r\n /**\r\n * Creates a compute effect that can be used to execute a compute shader\r\n * @param baseName Name of the effect\r\n * @param options Set of all options to create the effect\r\n * @param engine The engine the effect is created for\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n */\r\n constructor(baseName: IComputeShaderPath | string, options: IComputeEffectCreationOptions, engine: AbstractEngine, key = \"\") {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n this._engine = engine;\r\n this.uniqueId = ComputeEffect._UniqueIdSeed++;\r\n\r\n this.defines = options.defines ?? \"\";\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._entryPoint = options.entryPoint ?? \"main\";\r\n\r\n this._shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\r\n this._shaderRepository = ShaderStore.GetShadersRepository(this._shaderLanguage);\r\n this._includeShaderStore = ShaderStore.GetIncludesShadersStore(this._shaderLanguage);\r\n\r\n let computeSource: IComputeShaderPath | HTMLElement | string;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (typeof baseName === \"string\") {\r\n computeSource = baseName;\r\n } else if (baseName.computeSource) {\r\n computeSource = \"source:\" + baseName.computeSource;\r\n } else if (baseName.computeElement) {\r\n computeSource = hostDocument?.getElementById(baseName.computeElement) || baseName.computeElement;\r\n } else {\r\n computeSource = baseName.compute || baseName;\r\n }\r\n\r\n const processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: undefined,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: false,\r\n processor: null,\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: this._shaderRepository,\r\n includesShadersStore: this._includeShaderStore,\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: null,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n processCodeAfterIncludes: (shaderType: string, code: string, defines?: string[]) => {\r\n if (!defines) {\r\n return code;\r\n }\r\n // We need to convert #define key value to a const\r\n for (const define of defines) {\r\n const keyValue = define.replace(\"#define\", \"\").replace(\";\", \"\").trim();\r\n const split = keyValue.split(\" \");\r\n if (split.length === 2) {\r\n const key = split[0];\r\n const value = split[1];\r\n if (!isNaN(parseInt(value)) || !isNaN(parseFloat(value))) {\r\n code = `const ${key} = ${value};\\n` + code;\r\n }\r\n }\r\n }\r\n return code;\r\n },\r\n };\r\n\r\n this._loadShader(computeSource, \"Compute\", \"\", (computeCode) => {\r\n Initialize(processorOptions);\r\n PreProcess(\r\n computeCode,\r\n processorOptions,\r\n (migratedComputeCode) => {\r\n this._rawComputeSourceCode = computeCode;\r\n if (options.processFinalCode) {\r\n migratedComputeCode = options.processFinalCode(migratedComputeCode);\r\n }\r\n const finalShaders = Finalize(migratedComputeCode, \"\", processorOptions);\r\n this._useFinalCode(finalShaders.vertexCode, baseName);\r\n },\r\n this._engine\r\n );\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedCommputeCode: string, baseName: any) {\r\n if (baseName) {\r\n const compute = baseName.computeElement || baseName.compute || baseName.spectorName || baseName;\r\n\r\n this._computeSourceCode = \"//#define SHADER_NAME compute:\" + compute + \"\\n\" + migratedCommputeCode;\r\n } else {\r\n this._computeSourceCode = migratedCommputeCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): AbstractEngine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable<IComputePipelineContext> {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: ComputeEffect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable<IComputePipelineContext>) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n // Is in local store ?\r\n if (this._shaderStore[shader + key + \"Shader\"]) {\r\n callback(this._shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && this._shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(this._shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = this._shaderRepository + shader;\r\n }\r\n\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code of this effect\r\n */\r\n public get computeSourceCode(): string {\r\n return this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._pipelineContext?._getComputeShaderCode() ?? this._computeSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code before it has been processed by the preprocessor\r\n */\r\n public get rawComputeSourceCode(): string {\r\n return this._rawComputeSourceCode;\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createComputePipelineContext();\r\n this._pipelineContext._name = this._key;\r\n\r\n engine._prepareComputePipelineContext(\r\n this._pipelineContext,\r\n this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._computeSourceCode,\r\n this._rawComputeSourceCode,\r\n this._computeSourceCodeOverride ? null : defines,\r\n this._entryPoint\r\n );\r\n\r\n engine._executeWhenComputeStateIsCompiled(this._pipelineContext, (messages: Nullable<ComputeCompilationMessages>) => {\r\n if (messages && messages.numErrors > 0) {\r\n this._processCompilationErrors(messages, previousPipelineContext);\r\n return;\r\n }\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deleteComputePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _processCompilationErrors(e: ComputeCompilationMessages | string, previousPipelineContext: Nullable<IComputePipelineContext> = null) {\r\n this._compilationError = \"\";\r\n\r\n Logger.Error(\"Unable to compile compute effect:\");\r\n if (this.defines) {\r\n Logger.Error(\"Defines:\\n\" + this.defines);\r\n }\r\n\r\n if (ComputeEffect.LogShaderCodeOnCompilationError) {\r\n const code = this._pipelineContext?._getComputeShaderCode();\r\n if (code) {\r\n Logger.Error(\"Compute code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n\r\n if (typeof e === \"string\") {\r\n this._compilationError = e;\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n } else {\r\n for (const message of e.messages) {\r\n let msg = \"\";\r\n if (message.line !== undefined) {\r\n msg += \"Line \" + message.line + \", \";\r\n }\r\n if (message.offset !== undefined) {\r\n msg += \"Offset \" + message.offset + \", \";\r\n }\r\n if (message.length !== undefined) {\r\n msg += \"Length \" + message.length + \", \";\r\n }\r\n msg += message.type + \": \" + message.text;\r\n\r\n if (this._compilationError) {\r\n this._compilationError += \"\\n\";\r\n }\r\n this._compilationError += msg;\r\n Logger.Error(msg);\r\n }\r\n }\r\n\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n }\r\n\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseComputeEffect(this);\r\n }\r\n\r\n /**\r\n * This function will add a new compute shader to the shader store\r\n * @param name the name of the shader\r\n * @param computeShader compute shader content\r\n */\r\n public static RegisterShader(name: string, computeShader: string) {\r\n ShaderStore.GetShadersStore(ShaderLanguage.WGSL)[`${name}ComputeShader`] = computeShader;\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
|
|
2
|
+
/**
|
|
3
|
+
* Interface used to define a platform support for BoundingInfoHelper class
|
|
4
|
+
*/
|
|
5
|
+
export interface IBoundingInfoHelperPlatform {
|
|
6
|
+
processAsync(mesh: AbstractMesh | AbstractMesh[]): Promise<void>;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBoundingInfoHelperPlatform.js","sourceRoot":"","sources":["../../../../../dev/core/src/Culling/Helper/IBoundingInfoHelperPlatform.ts"],"names":[],"mappings":"","sourcesContent":["import type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\n\r\n/**\r\n * Interface used to define a platform support for BoundingInfoHelper class\r\n */\r\nexport interface IBoundingInfoHelperPlatform {\r\n processAsync(mesh: AbstractMesh | AbstractMesh[]): Promise<void>;\r\n dispose(): void;\r\n}\r\n"]}
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
|
|
2
2
|
import type { AbstractEngine } from "../../Engines/abstractEngine.js";
|
|
3
3
|
/**
|
|
4
4
|
* Utility class to help with bounding info management
|
|
5
|
-
* #BCNJD4#
|
|
6
|
-
* #BCNJD4#
|
|
5
|
+
* #BCNJD4#41 =\> does not use the BoundingInfoHelper class, performs calculations on the CPU
|
|
6
|
+
* #BCNJD4#37 =\> same as #41 but use the BoundingInfoHelper class
|
|
7
|
+
* #BCNJD4#40 =\> example with bones and morphs (webGL2)
|
|
8
|
+
* #BCNJD4#42 =\> example with bones and morphs (webGPU)
|
|
9
|
+
* #HPV2TZ#475 =\> only morph (webGL2)
|
|
10
|
+
* #HPV2TZ#476 =\> only morph (webGPU)
|
|
11
|
+
* #B8B8Z2#8 =\> Large scale test (webGL2)
|
|
12
|
+
* #B8B8Z2#9 =\> Large scale test (webGPU)
|
|
7
13
|
*/
|
|
8
14
|
export declare class BoundingInfoHelper {
|
|
9
15
|
private _platform;
|
|
10
|
-
private
|
|
11
|
-
private _effects;
|
|
16
|
+
private _engine;
|
|
12
17
|
/**
|
|
13
18
|
* Creates a new BoundingInfoHelper
|
|
14
19
|
* @param engine defines the engine to use
|
|
15
20
|
*/
|
|
16
21
|
constructor(engine: AbstractEngine);
|
|
17
22
|
/**
|
|
18
|
-
* Compute the bounding info of a mesh using shaders
|
|
19
|
-
* @param
|
|
20
|
-
* @returns a promise that resolves when the bounding info is computed
|
|
23
|
+
* Compute the bounding info of a mesh / array of meshes using shaders
|
|
24
|
+
* @param target defines the mesh(es) to update
|
|
25
|
+
* @returns a promise that resolves when the bounding info is/are computed
|
|
21
26
|
*/
|
|
22
|
-
computeAsync(
|
|
23
|
-
private _updateBuffer;
|
|
27
|
+
computeAsync(target: AbstractMesh | AbstractMesh[]): Promise<void>;
|
|
24
28
|
/**
|
|
25
29
|
* Dispose and release associated resources
|
|
26
30
|
*/
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { WebGL2BoundingHelper } from "./webgl2BoundingHelper.js";
|
|
2
|
-
import { VertexBuffer, Buffer } from "../../Buffers/buffer.js";
|
|
3
|
-
import { BindBonesParameters, BindMorphTargetParameters, PrepareAttributesForBakedVertexAnimation } from "../../Materials/materialHelper.functions.js";
|
|
4
1
|
/**
|
|
5
2
|
* Utility class to help with bounding info management
|
|
6
|
-
* #BCNJD4#
|
|
7
|
-
* #BCNJD4#
|
|
3
|
+
* #BCNJD4#41 =\> does not use the BoundingInfoHelper class, performs calculations on the CPU
|
|
4
|
+
* #BCNJD4#37 =\> same as #41 but use the BoundingInfoHelper class
|
|
5
|
+
* #BCNJD4#40 =\> example with bones and morphs (webGL2)
|
|
6
|
+
* #BCNJD4#42 =\> example with bones and morphs (webGPU)
|
|
7
|
+
* #HPV2TZ#475 =\> only morph (webGL2)
|
|
8
|
+
* #HPV2TZ#476 =\> only morph (webGPU)
|
|
9
|
+
* #B8B8Z2#8 =\> Large scale test (webGL2)
|
|
10
|
+
* #B8B8Z2#9 =\> Large scale test (webGPU)
|
|
8
11
|
*/
|
|
9
12
|
export class BoundingInfoHelper {
|
|
10
13
|
/**
|
|
@@ -12,166 +15,33 @@ export class BoundingInfoHelper {
|
|
|
12
15
|
* @param engine defines the engine to use
|
|
13
16
|
*/
|
|
14
17
|
constructor(engine) {
|
|
15
|
-
this.
|
|
16
|
-
this._effects = {};
|
|
17
|
-
if (engine.createTransformFeedback) {
|
|
18
|
-
// Go down the WebGL2 path
|
|
19
|
-
this._platform = new WebGL2BoundingHelper(engine);
|
|
20
|
-
}
|
|
18
|
+
this._engine = engine;
|
|
21
19
|
}
|
|
22
20
|
/**
|
|
23
|
-
* Compute the bounding info of a mesh using shaders
|
|
24
|
-
* @param
|
|
25
|
-
* @returns a promise that resolves when the bounding info is computed
|
|
21
|
+
* Compute the bounding info of a mesh / array of meshes using shaders
|
|
22
|
+
* @param target defines the mesh(es) to update
|
|
23
|
+
* @returns a promise that resolves when the bounding info is/are computed
|
|
26
24
|
*/
|
|
27
|
-
computeAsync(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
const vertexCount = mesh.getTotalVertices();
|
|
35
|
-
let targetBuffer;
|
|
36
|
-
if (!this._buffers[mesh.uniqueId]) {
|
|
37
|
-
const targetData = new Float32Array(vertexCount * 3);
|
|
38
|
-
targetBuffer = new Buffer(mesh.getEngine(), targetData, true, 3);
|
|
39
|
-
this._buffers[mesh.uniqueId] = targetBuffer;
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
targetBuffer = this._buffers[mesh.uniqueId];
|
|
43
|
-
}
|
|
44
|
-
// Get correct effect
|
|
45
|
-
let computeEffect;
|
|
46
|
-
let numInfluencers = 0;
|
|
47
|
-
const defines = [];
|
|
48
|
-
let uniforms = [];
|
|
49
|
-
const attribs = [VertexBuffer.PositionKind];
|
|
50
|
-
const samplers = [];
|
|
51
|
-
// Bones
|
|
52
|
-
if (mesh && mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {
|
|
53
|
-
attribs.push(VertexBuffer.MatricesIndicesKind);
|
|
54
|
-
attribs.push(VertexBuffer.MatricesWeightsKind);
|
|
55
|
-
if (mesh.numBoneInfluencers > 4) {
|
|
56
|
-
attribs.push(VertexBuffer.MatricesIndicesExtraKind);
|
|
57
|
-
attribs.push(VertexBuffer.MatricesWeightsExtraKind);
|
|
58
|
-
}
|
|
59
|
-
const skeleton = mesh.skeleton;
|
|
60
|
-
defines.push("#define NUM_BONE_INFLUENCERS " + mesh.numBoneInfluencers);
|
|
61
|
-
if (skeleton.isUsingTextureForMatrices) {
|
|
62
|
-
defines.push("#define BONETEXTURE");
|
|
63
|
-
if (uniforms.indexOf("boneTextureWidth") === -1) {
|
|
64
|
-
uniforms.push("boneTextureWidth");
|
|
65
|
-
}
|
|
66
|
-
if (samplers.indexOf("boneSampler") === -1) {
|
|
67
|
-
samplers.push("boneSampler");
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
defines.push("#define BonesPerMesh " + (skeleton.bones.length + 1));
|
|
72
|
-
if (uniforms.indexOf("mBones") === -1) {
|
|
73
|
-
uniforms.push("mBones");
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
defines.push("#define NUM_BONE_INFLUENCERS 0");
|
|
25
|
+
async computeAsync(target) {
|
|
26
|
+
if (!this._platform) {
|
|
27
|
+
if (this._engine.getCaps().supportComputeShaders) {
|
|
28
|
+
const module = await import("./computeShaderBoundingHelper.js");
|
|
29
|
+
this._platform = new module.ComputeShaderBoundingHelper(this._engine);
|
|
79
30
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
numInfluencers = manager.numMaxInfluencers || manager.numInfluencers;
|
|
84
|
-
if (numInfluencers > 0) {
|
|
85
|
-
defines.push("#define MORPHTARGETS");
|
|
86
|
-
}
|
|
87
|
-
if (manager.isUsingTextureForTargets) {
|
|
88
|
-
defines.push("#define MORPHTARGETS_TEXTURE");
|
|
89
|
-
if (uniforms.indexOf("morphTargetTextureIndices") === -1) {
|
|
90
|
-
uniforms.push("morphTargetTextureIndices");
|
|
91
|
-
}
|
|
92
|
-
if (samplers.indexOf("morphTargets") === -1) {
|
|
93
|
-
samplers.push("morphTargets");
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
defines.push("#define NUM_MORPH_INFLUENCERS " + numInfluencers);
|
|
97
|
-
for (let index = 0; index < numInfluencers; index++) {
|
|
98
|
-
attribs.push(VertexBuffer.PositionKind + index);
|
|
99
|
-
}
|
|
100
|
-
if (numInfluencers > 0) {
|
|
101
|
-
uniforms = uniforms.slice();
|
|
102
|
-
uniforms.push("morphTargetInfluences");
|
|
103
|
-
uniforms.push("morphTargetCount");
|
|
104
|
-
uniforms.push("morphTargetTextureInfo");
|
|
105
|
-
uniforms.push("morphTargetTextureIndices");
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
// Baked Vertex Animation
|
|
109
|
-
const bvaManager = mesh.bakedVertexAnimationManager;
|
|
110
|
-
if (bvaManager && bvaManager.isEnabled) {
|
|
111
|
-
defines.push("#define BAKED_VERTEX_ANIMATION_TEXTURE");
|
|
112
|
-
if (uniforms.indexOf("bakedVertexAnimationSettings") === -1) {
|
|
113
|
-
uniforms.push("bakedVertexAnimationSettings");
|
|
114
|
-
}
|
|
115
|
-
if (uniforms.indexOf("bakedVertexAnimationTextureSizeInverted") === -1) {
|
|
116
|
-
uniforms.push("bakedVertexAnimationTextureSizeInverted");
|
|
117
|
-
}
|
|
118
|
-
if (uniforms.indexOf("bakedVertexAnimationTime") === -1) {
|
|
119
|
-
uniforms.push("bakedVertexAnimationTime");
|
|
120
|
-
}
|
|
121
|
-
if (samplers.indexOf("bakedVertexAnimationTexture") === -1) {
|
|
122
|
-
samplers.push("bakedVertexAnimationTexture");
|
|
123
|
-
}
|
|
124
|
-
PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);
|
|
125
|
-
}
|
|
126
|
-
const join = defines.join("\n");
|
|
127
|
-
if (!this._effects[join]) {
|
|
128
|
-
computeEffect = this._platform.createUpdateEffect(attribs, join, uniforms, samplers, numInfluencers);
|
|
129
|
-
this._effects[join] = computeEffect;
|
|
31
|
+
else if (this._engine.getCaps().supportTransformFeedbacks) {
|
|
32
|
+
const module = await import("./transformFeedbackBoundingHelper.js");
|
|
33
|
+
this._platform = new module.TransformFeedbackBoundingHelper(this._engine);
|
|
130
34
|
}
|
|
131
35
|
else {
|
|
132
|
-
|
|
36
|
+
throw new Error("Your engine does not support Compute Shaders or Transform Feedbacks");
|
|
133
37
|
}
|
|
134
|
-
if (computeEffect.isReady()) {
|
|
135
|
-
this._updateBuffer(mesh, computeEffect, targetBuffer, resolve);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
computeEffect.onCompileObservable.addOnce(() => {
|
|
139
|
-
this._updateBuffer(mesh, computeEffect, targetBuffer, resolve);
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
_updateBuffer(mesh, effect, target, resolve) {
|
|
144
|
-
effect.getEngine().enableEffect(effect);
|
|
145
|
-
const vertexCount = mesh.getTotalVertices();
|
|
146
|
-
mesh._bindDirect(effect, null, true);
|
|
147
|
-
// Bones
|
|
148
|
-
BindBonesParameters(mesh, effect);
|
|
149
|
-
// Morph targets
|
|
150
|
-
const manager = mesh.morphTargetManager;
|
|
151
|
-
if (manager && manager.numInfluencers > 0) {
|
|
152
|
-
BindMorphTargetParameters(mesh, effect);
|
|
153
38
|
}
|
|
154
|
-
|
|
155
|
-
const bvaManager = mesh.bakedVertexAnimationManager;
|
|
156
|
-
if (bvaManager && bvaManager.isEnabled) {
|
|
157
|
-
mesh.bakedVertexAnimationManager?.bind(effect, false);
|
|
158
|
-
}
|
|
159
|
-
// Execute
|
|
160
|
-
this._platform.updateBuffer(vertexCount, target);
|
|
161
|
-
// Retrieve data
|
|
162
|
-
mesh._refreshBoundingInfo(target.getData(), null);
|
|
163
|
-
resolve();
|
|
39
|
+
return this._platform.processAsync(target);
|
|
164
40
|
}
|
|
165
41
|
/**
|
|
166
42
|
* Dispose and release associated resources
|
|
167
43
|
*/
|
|
168
44
|
dispose() {
|
|
169
|
-
for (const key in this._buffers) {
|
|
170
|
-
this._buffers[key].dispose();
|
|
171
|
-
}
|
|
172
|
-
for (const key in this._effects) {
|
|
173
|
-
this._effects[key].dispose();
|
|
174
|
-
}
|
|
175
45
|
this._platform.dispose();
|
|
176
46
|
}
|
|
177
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundingInfoHelper.js","sourceRoot":"","sources":["../../../../../dev/core/src/Culling/Helper/boundingInfoHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,gCAA4B;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yBAAyB,EAAE,wCAAwC,EAAE,oDAAgD;AAKnJ;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAK3B;;;OAGG;IACH,YAAmB,MAAsB;QAPjC,aAAQ,GAA8B,EAAE,CAAC;QACzC,aAAQ,GAA8B,EAAE,CAAC;QAO7C,IAAK,MAAiB,CAAC,uBAAuB,EAAE;YAC5C,0BAA0B;YAC1B,IAAI,CAAC,SAAS,GAAG,IAAI,oBAAoB,CAAC,MAAgB,CAAC,CAAC;SAC/D;IACL,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,IAAU;QAC1B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;YAE/D,IAAI,CAAC,MAAM,EAAE;gBACT,OAAO,EAAE,CAAC,CAAC,yCAAyC;gBACpD,OAAO;aACV;YAED,MAAM,WAAW,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;YAE5C,IAAI,YAAoB,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CA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AE,MAAM,CAAC,CAAC;QAElC,gBAAgB;QAChB,MAAM,OAAO,GAAU,IAAK,CAAC,kBAAkB,CAAC;QAChD,IAAI,OAAO,IAAI,OAAO,CAAC,cAAc,GAAG,CAAC,EAAE;YACvC,yBAAyB,CAAO,IAAI,EAAE,MAAM,CAAC,CAAC;SACjD;QAED,MAAM;QACN,MAAM,UAAU,GAAU,IAAK,CAAC,2BAA2B,CAAC;QAE5D,IAAI,UAAU,IAAI,UAAU,CAAC,SAAS,EAAE;YACpC,IAAI,CAAC,2BAA2B,EAAE,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;SACzD;QAED,UAAU;QACV,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAEjD,gBAAgB;QAChB,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,OAAO,EAAmB,EAAE,IAAI,CAAC,CAAC;QAEnE,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;OAEG;IACI,OAAO;QACV,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;SAChC;QACD,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE;YAC7B,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC;SAChC;QACD,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["import { WebGL2BoundingHelper } from \"./webgl2BoundingHelper\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport { VertexBuffer, Buffer } from \"core/Buffers/buffer\";\r\nimport { BindBonesParameters, BindMorphTargetParameters, PrepareAttributesForBakedVertexAnimation } from \"core/Materials/materialHelper.functions\";\r\nimport type { Effect } from \"core/Materials/effect\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { Engine } from \"core/Engines/engine\";\r\n\r\n/**\r\n * Utility class to help with bounding info management\r\n * #BCNJD4#5\r\n * #BCNJD4#14\r\n */\r\nexport class BoundingInfoHelper {\r\n private _platform: WebGL2BoundingHelper;\r\n private _buffers: { [key: number]: Buffer } = {};\r\n private _effects: { [key: string]: Effect } = {};\r\n\r\n /**\r\n * Creates a new BoundingInfoHelper\r\n * @param engine defines the engine to use\r\n */\r\n public constructor(engine: AbstractEngine) {\r\n if ((engine as Engine).createTransformFeedback) {\r\n // Go down the WebGL2 path\r\n this._platform = new WebGL2BoundingHelper(engine as Engine);\r\n }\r\n }\r\n\r\n /**\r\n * Compute the bounding info of a mesh using shaders\r\n * @param mesh defines the mesh to update\r\n * @returns a promise that resolves when the bounding info is computed\r\n */\r\n public computeAsync(mesh: Mesh): Promise<void> {\r\n return new Promise((resolve) => {\r\n const source = mesh.getVertexBuffer(VertexBuffer.PositionKind);\r\n\r\n if (!source) {\r\n resolve(); // Take no action if mesh has no position\r\n return;\r\n }\r\n\r\n const vertexCount = mesh.getTotalVertices();\r\n\r\n let targetBuffer: Buffer;\r\n if (!this._buffers[mesh.uniqueId]) {\r\n const targetData = new Float32Array(vertexCount * 3);\r\n targetBuffer = new Buffer(mesh.getEngine(), targetData, true, 3);\r\n this._buffers[mesh.uniqueId] = targetBuffer;\r\n } else {\r\n targetBuffer = this._buffers[mesh.uniqueId];\r\n }\r\n\r\n // Get correct effect\r\n let computeEffect: Effect;\r\n let numInfluencers = 0;\r\n const defines: string[] = [];\r\n let uniforms: string[] = [];\r\n const attribs = [VertexBuffer.PositionKind];\r\n const samplers: string[] = [];\r\n\r\n // Bones\r\n if (mesh && mesh.useBones && mesh.computeBonesUsingShaders && mesh.skeleton) {\r\n attribs.push(VertexBuffer.MatricesIndicesKind);\r\n attribs.push(VertexBuffer.MatricesWeightsKind);\r\n if (mesh.numBoneInfluencers > 4) {\r\n attribs.push(VertexBuffer.MatricesIndicesExtraKind);\r\n attribs.push(VertexBuffer.MatricesWeightsExtraKind);\r\n }\r\n\r\n const skeleton = mesh.skeleton;\r\n\r\n defines.push(\"#define NUM_BONE_INFLUENCERS \" + mesh.numBoneInfluencers);\r\n\r\n if (skeleton.isUsingTextureForMatrices) {\r\n defines.push(\"#define BONETEXTURE\");\r\n\r\n if (uniforms.indexOf(\"boneTextureWidth\") === -1) {\r\n uniforms.push(\"boneTextureWidth\");\r\n }\r\n\r\n if (samplers.indexOf(\"boneSampler\") === -1) {\r\n samplers.push(\"boneSampler\");\r\n }\r\n } else {\r\n defines.push(\"#define BonesPerMesh \" + (skeleton.bones.length + 1));\r\n\r\n if (uniforms.indexOf(\"mBones\") === -1) {\r\n uniforms.push(\"mBones\");\r\n }\r\n }\r\n } else {\r\n defines.push(\"#define NUM_BONE_INFLUENCERS 0\");\r\n }\r\n\r\n // Morph\r\n const manager = mesh ? (<Mesh>mesh).morphTargetManager : null;\r\n if (manager) {\r\n numInfluencers = manager.numMaxInfluencers || manager.numInfluencers;\r\n if (numInfluencers > 0) {\r\n defines.push(\"#define MORPHTARGETS\");\r\n }\r\n if (manager.isUsingTextureForTargets) {\r\n defines.push(\"#define MORPHTARGETS_TEXTURE\");\r\n\r\n if (uniforms.indexOf(\"morphTargetTextureIndices\") === -1) {\r\n uniforms.push(\"morphTargetTextureIndices\");\r\n }\r\n\r\n if (samplers.indexOf(\"morphTargets\") === -1) {\r\n samplers.push(\"morphTargets\");\r\n }\r\n }\r\n defines.push(\"#define NUM_MORPH_INFLUENCERS \" + numInfluencers);\r\n for (let index = 0; index < numInfluencers; index++) {\r\n attribs.push(VertexBuffer.PositionKind + index);\r\n }\r\n if (numInfluencers > 0) {\r\n uniforms = uniforms.slice();\r\n uniforms.push(\"morphTargetInfluences\");\r\n uniforms.push(\"morphTargetCount\");\r\n uniforms.push(\"morphTargetTextureInfo\");\r\n uniforms.push(\"morphTargetTextureIndices\");\r\n }\r\n }\r\n\r\n // Baked Vertex Animation\r\n const bvaManager = (<Mesh>mesh).bakedVertexAnimationManager;\r\n\r\n if (bvaManager && bvaManager.isEnabled) {\r\n defines.push(\"#define BAKED_VERTEX_ANIMATION_TEXTURE\");\r\n if (uniforms.indexOf(\"bakedVertexAnimationSettings\") === -1) {\r\n uniforms.push(\"bakedVertexAnimationSettings\");\r\n }\r\n if (uniforms.indexOf(\"bakedVertexAnimationTextureSizeInverted\") === -1) {\r\n uniforms.push(\"bakedVertexAnimationTextureSizeInverted\");\r\n }\r\n if (uniforms.indexOf(\"bakedVertexAnimationTime\") === -1) {\r\n uniforms.push(\"bakedVertexAnimationTime\");\r\n }\r\n\r\n if (samplers.indexOf(\"bakedVertexAnimationTexture\") === -1) {\r\n samplers.push(\"bakedVertexAnimationTexture\");\r\n }\r\n PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n if (!this._effects[join]) {\r\n computeEffect = this._platform.createUpdateEffect(attribs, join, uniforms, samplers, numInfluencers);\r\n this._effects[join] = computeEffect;\r\n } else {\r\n computeEffect = this._effects[join];\r\n }\r\n\r\n if (computeEffect.isReady()) {\r\n this._updateBuffer(mesh, computeEffect, targetBuffer, resolve);\r\n return;\r\n }\r\n\r\n computeEffect.onCompileObservable.addOnce(() => {\r\n this._updateBuffer(mesh, computeEffect, targetBuffer, resolve);\r\n });\r\n });\r\n }\r\n\r\n private _updateBuffer(mesh: Mesh, effect: Effect, target: Buffer, resolve: () => void): void {\r\n effect.getEngine().enableEffect(effect);\r\n const vertexCount = mesh.getTotalVertices();\r\n mesh._bindDirect(effect, null, true);\r\n\r\n // Bones\r\n BindBonesParameters(mesh, effect);\r\n\r\n // Morph targets\r\n const manager = (<Mesh>mesh).morphTargetManager;\r\n if (manager && manager.numInfluencers > 0) {\r\n BindMorphTargetParameters(<Mesh>mesh, effect);\r\n }\r\n\r\n // BVA\r\n const bvaManager = (<Mesh>mesh).bakedVertexAnimationManager;\r\n\r\n if (bvaManager && bvaManager.isEnabled) {\r\n mesh.bakedVertexAnimationManager?.bind(effect, false);\r\n }\r\n\r\n // Execute\r\n this._platform.updateBuffer(vertexCount, target);\r\n\r\n // Retrieve data\r\n mesh._refreshBoundingInfo(target.getData()! as Float32Array, null);\r\n\r\n resolve();\r\n }\r\n\r\n /**\r\n * Dispose and release associated resources\r\n */\r\n public dispose(): void {\r\n for (const key in this._buffers) {\r\n this._buffers[key].dispose();\r\n }\r\n for (const key in this._effects) {\r\n this._effects[key].dispose();\r\n }\r\n this._platform.dispose();\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"boundingInfoHelper.js","sourceRoot":"","sources":["../../../../../dev/core/src/Culling/Helper/boundingInfoHelper.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IAI3B;;;OAGG;IACH,YAAmB,MAAsB;QACrC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IAC1B,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,YAAY,CAAC,MAAqC;QAC3D,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACjB,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,qBAAqB,EAAE;gBAC9C,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,+BAA+B,CAAC,CAAC;gBAC7D,IAAI,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;aACzE;iBAAM,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,yBAAyB,EAAE;gBACzD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,mCAAmC,CAAC,CAAC;gBACjE,IAAI,CAAC,SAAS,GAAG,IAAI,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC,OAAqB,CAAC,CAAC;aAC3F;iBAAM;gBACH,MAAM,IAAI,KAAK,CAAC,qEAAqE,CAAC,CAAC;aAC1F;SACJ;QAED,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ","sourcesContent":["import type { AbstractMesh } from \"core/Meshes/abstractMesh\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { IBoundingInfoHelperPlatform } from \"./IBoundingInfoHelperPlatform\";\r\nimport type { ThinEngine } from \"core/Engines\";\r\n\r\n/**\r\n * Utility class to help with bounding info management\r\n * #BCNJD4#41 =\\> does not use the BoundingInfoHelper class, performs calculations on the CPU\r\n * #BCNJD4#37 =\\> same as #41 but use the BoundingInfoHelper class\r\n * #BCNJD4#40 =\\> example with bones and morphs (webGL2)\r\n * #BCNJD4#42 =\\> example with bones and morphs (webGPU)\r\n * #HPV2TZ#475 =\\> only morph (webGL2)\r\n * #HPV2TZ#476 =\\> only morph (webGPU)\r\n * #B8B8Z2#8 =\\> Large scale test (webGL2)\r\n * #B8B8Z2#9 =\\> Large scale test (webGPU)\r\n */\r\nexport class BoundingInfoHelper {\r\n private _platform: IBoundingInfoHelperPlatform;\r\n private _engine: AbstractEngine;\r\n\r\n /**\r\n * Creates a new BoundingInfoHelper\r\n * @param engine defines the engine to use\r\n */\r\n public constructor(engine: AbstractEngine) {\r\n this._engine = engine;\r\n }\r\n\r\n /**\r\n * Compute the bounding info of a mesh / array of meshes using shaders\r\n * @param target defines the mesh(es) to update\r\n * @returns a promise that resolves when the bounding info is/are computed\r\n */\r\n public async computeAsync(target: AbstractMesh | AbstractMesh[]): Promise<void> {\r\n if (!this._platform) {\r\n if (this._engine.getCaps().supportComputeShaders) {\r\n const module = await import(\"./computeShaderBoundingHelper\");\r\n this._platform = new module.ComputeShaderBoundingHelper(this._engine);\r\n } else if (this._engine.getCaps().supportTransformFeedbacks) {\r\n const module = await import(\"./transformFeedbackBoundingHelper\");\r\n this._platform = new module.TransformFeedbackBoundingHelper(this._engine as ThinEngine);\r\n } else {\r\n throw new Error(\"Your engine does not support Compute Shaders or Transform Feedbacks\");\r\n }\r\n }\r\n\r\n return this._platform.processAsync(target);\r\n }\r\n\r\n /**\r\n * Dispose and release associated resources\r\n */\r\n public dispose(): void {\r\n this._platform.dispose();\r\n }\r\n}\r\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { IBoundingInfoHelperPlatform } from "./IBoundingInfoHelperPlatform";
|
|
2
|
+
import type { AbstractMesh } from "../../Meshes/abstractMesh.js";
|
|
3
|
+
import type { AbstractEngine } from "../../Engines/abstractEngine.js";
|
|
4
|
+
import "../../ShadersWGSL/boundingInfo.compute";
|
|
5
|
+
/** @internal */
|
|
6
|
+
export declare class ComputeShaderBoundingHelper implements IBoundingInfoHelperPlatform {
|
|
7
|
+
private _engine;
|
|
8
|
+
private _computeShaders;
|
|
9
|
+
private _positionBuffers;
|
|
10
|
+
private _indexBuffers;
|
|
11
|
+
private _weightBuffers;
|
|
12
|
+
private _indexExtraBuffers;
|
|
13
|
+
private _weightExtraBuffers;
|
|
14
|
+
private _morphTargetInfluenceBuffers;
|
|
15
|
+
private _morphTargetTextureIndexBuffers;
|
|
16
|
+
private _resultData;
|
|
17
|
+
private _resultBuffer;
|
|
18
|
+
private _ubos;
|
|
19
|
+
private _uboIndex;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new ComputeShaderBoundingHelper
|
|
22
|
+
* @param engine defines the engine to use
|
|
23
|
+
*/
|
|
24
|
+
constructor(engine: AbstractEngine);
|
|
25
|
+
private _getComputeShader;
|
|
26
|
+
private _getUBO;
|
|
27
|
+
private _extractDataAndLink;
|
|
28
|
+
private _prepareStorage;
|
|
29
|
+
/** @internal */
|
|
30
|
+
processAsync(meshes: AbstractMesh | AbstractMesh[]): Promise<void>;
|
|
31
|
+
private _disposeCache;
|
|
32
|
+
/** @internal */
|
|
33
|
+
dispose(): void;
|
|
34
|
+
}
|