@babylonjs/core 7.40.0 → 7.40.2

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.
@@ -201,7 +201,7 @@ export const _retryWithInterval = (condition, onSuccess, onError, step = 16, max
201
201
  maxTimeout -= step;
202
202
  if (maxTimeout < 0) {
203
203
  clearInterval(int);
204
- onError?.();
204
+ onError?.(new Error("Timeout"));
205
205
  }
206
206
  }, step);
207
207
  };
@@ -1 +1 @@
1
- {"version":3,"file":"effect.functions.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/effect.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iCAAgC;AAIjF,OAAO,EAAE,cAAc,EAAE,2CAA0C;AACnE,OAAO,EAAE,WAAW,EAAE,kCAAiC;AAIvD,OAAO,EAAE,MAAM,EAAE,0BAAyB;AAC1C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,iDAAgD;AACxF,OAAO,EAAE,SAAS,EAAE,+CAA8C;AAyElE;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,OAAqB;IACjE,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,CAAC,CAAC;IAC5C,OAAO,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;AAC7C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CAAC,QAA0B;IAC1D,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC5B,MAAM,OAAO,GAAI,QAAiC,CAAC,OAAO,CAAC;IAC3D,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC;QAClB,MAAM,WAAW,GAAG,cAAc,CAAC,OAAQ,CAAC,CAAC;QAC7C,MAAM,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QACzD,cAAc,EAAE,OAAO,EAAE,CAAC;QAC1B,OAAO,WAAW,CA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L,CAAC,EAAE,IAAI,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import type { ProcessingOptions, ShaderCustomProcessingFunction, ShaderProcessingContext } from \"core/Engines/Processors/shaderProcessingOptions\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"core/Misc/domManagement\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport type { WebGLContext } from \"core/Engines/thinEngine.functions\";\r\nimport { getStateObject } from \"core/Engines/thinEngine.functions\";\r\nimport { ShaderStore } from \"core/Engines/shaderStore\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { Effect, IShaderPath } from \"./effect\";\r\nimport type { IPipelineContext } from \"core/Engines/IPipelineContext\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { Finalize, Initialize, Process } from \"core/Engines/Processors/shaderProcessor\";\r\nimport { _loadFile } from \"core/Engines/abstractEngine.functions\";\r\nimport type { WebGLPipelineContext } from \"core/Engines/WebGL/webGLPipelineContext\";\r\n\r\n/**\r\n * Options to be used when creating a pipeline\r\n */\r\nexport interface IPipelineGenerationOptions {\r\n /**\r\n * The definition of the shader content.\r\n * Can be either a unified name, name per vertex and frament or the shader code content itself\r\n */\r\n shaderNameOrContent: string | IShaderPath;\r\n /**\r\n * Unique key to identify the pipeline.\r\n * Note that though not mandatory, it's recommended to provide a key to be able to use the automated pipeline loading system.\r\n */\r\n key?: string;\r\n /**\r\n * The list of defines to be used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * If true, the global defines will be added to the defines array\r\n */\r\n addGlobalDefines?: boolean;\r\n /**\r\n * The shader language.\r\n * Defaults to the language suiting the platform name (GLSL for WEBGL2, WGSL for WEBGPU)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n\r\n /**\r\n * The name of the platform to be used when processing the shader\r\n * defaults to WEBGL2\r\n */\r\n platformName?: string /* \"WEBGL2\" | \"WEBGL1\" | \"WEBGPU\" */;\r\n\r\n /**\r\n * extend the processing options when running code processing\r\n */\r\n extendedProcessingOptions?: Partial<ProcessingOptions>;\r\n\r\n /**\r\n * extend the pipeline generation options\r\n */\r\n extendedCreatePipelineOptions?: Partial<ICreateAndPreparePipelineContextOptions>;\r\n\r\n /**\r\n * If true, generating a new pipeline will return when the pipeline is ready to be used\r\n */\r\n waitForIsReady?: boolean;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface ICreateAndPreparePipelineContextOptions {\r\n parallelShaderCompile?: { COMPLETION_STATUS_KHR: number };\r\n shaderProcessingContext: Nullable<ShaderProcessingContext>;\r\n existingPipelineContext?: Nullable<IPipelineContext>;\r\n name?: string;\r\n rebuildRebind?: (vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void) => void;\r\n onRenderingStateCompiled?: (pipelineContext?: IPipelineContext) => void;\r\n context?: WebGL2RenderingContext | WebGLRenderingContext;\r\n // preparePipeline options\r\n createAsRaw?: boolean;\r\n vertex: string;\r\n fragment: string;\r\n defines: Nullable<string>;\r\n transformFeedbackVaryings: Nullable<string[]>;\r\n}\r\n\r\n/**\r\n * Get a cached pipeline context\r\n * @param name the pipeline name\r\n * @param context the context to be used when creating the pipeline\r\n * @returns the cached pipeline context if it exists\r\n * @internal\r\n */\r\nexport function getCachedPipeline(name: string, context: WebGLContext): IPipelineContext | undefined {\r\n const stateObject = getStateObject(context);\r\n return stateObject.cachedPipelines[name];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function resetCachedPipeline(pipeline: IPipelineContext): void {\r\n const name = pipeline._name;\r\n const context = (pipeline as WebGLPipelineContext).context;\r\n if (name && context) {\r\n const stateObject = getStateObject(context!);\r\n const cachedPipeline = stateObject.cachedPipelines[name];\r\n cachedPipeline?.dispose();\r\n delete stateObject.cachedPipelines[name];\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function _processShaderCode(\r\n processorOptions: ProcessingOptions,\r\n baseName: any,\r\n processFinalCode?: Nullable<ShaderCustomProcessingFunction>,\r\n onFinalCodeReady?: (vertexCode: string, fragmentCode: string) => void,\r\n shaderLanguage?: ShaderLanguage,\r\n engine?: AbstractEngine,\r\n effectContext?: Effect\r\n) {\r\n let vertexSource: string | HTMLElement | IShaderPath;\r\n let fragmentSource: string | HTMLElement | IShaderPath;\r\n\r\n // const baseName = this.name;\r\n const hostDocument = IsWindowObjectExist() ? engine?.getHostDocument() : null;\r\n\r\n if (typeof baseName === \"string\") {\r\n vertexSource = baseName;\r\n } else if (baseName.vertexSource) {\r\n vertexSource = \"source:\" + baseName.vertexSource;\r\n } else if (baseName.vertexElement) {\r\n vertexSource = hostDocument?.getElementById(baseName.vertexElement) || baseName.vertexElement;\r\n } else {\r\n vertexSource = baseName.vertex || baseName;\r\n }\r\n if (typeof baseName === \"string\") {\r\n fragmentSource = baseName;\r\n } else if (baseName.fragmentSource) {\r\n fragmentSource = \"source:\" + baseName.fragmentSource;\r\n } else if (baseName.fragmentElement) {\r\n fragmentSource = hostDocument?.getElementById(baseName.fragmentElement) || baseName.fragmentElement;\r\n } else {\r\n fragmentSource = baseName.fragment || baseName;\r\n }\r\n\r\n const shaderCodes: [string | undefined, string | undefined] = [undefined, undefined];\r\n const shadersLoaded = () => {\r\n if (shaderCodes[0] && shaderCodes[1]) {\r\n processorOptions.isFragment = true;\r\n const [migratedVertexCode, fragmentCode] = shaderCodes;\r\n Process(\r\n fragmentCode,\r\n processorOptions,\r\n (migratedFragmentCode, codeBeforeMigration) => {\r\n if (effectContext) {\r\n effectContext._fragmentSourceCodeBeforeMigration = codeBeforeMigration;\r\n }\r\n if (processFinalCode) {\r\n migratedFragmentCode = processFinalCode(\"fragment\", migratedFragmentCode);\r\n }\r\n const finalShaders = Finalize(migratedVertexCode, migratedFragmentCode, processorOptions);\r\n processorOptions = null as any;\r\n const finalCode = _useFinalCode(finalShaders.vertexCode, finalShaders.fragmentCode, baseName, shaderLanguage);\r\n onFinalCodeReady?.(finalCode.vertexSourceCode, finalCode.fragmentSourceCode);\r\n },\r\n engine\r\n );\r\n }\r\n };\r\n _loadShader(\r\n vertexSource,\r\n \"Vertex\",\r\n \"\",\r\n (vertexCode) => {\r\n Initialize(processorOptions);\r\n Process(\r\n vertexCode,\r\n processorOptions,\r\n (migratedVertexCode, codeBeforeMigration) => {\r\n if (effectContext) {\r\n effectContext._rawVertexSourceCode = vertexCode;\r\n effectContext._vertexSourceCodeBeforeMigration = codeBeforeMigration;\r\n }\r\n if (processFinalCode) {\r\n migratedVertexCode = processFinalCode(\"vertex\", migratedVertexCode);\r\n }\r\n shaderCodes[0] = migratedVertexCode;\r\n shadersLoaded();\r\n },\r\n engine\r\n );\r\n },\r\n shaderLanguage\r\n );\r\n _loadShader(\r\n fragmentSource,\r\n \"Fragment\",\r\n \"Pixel\",\r\n (fragmentCode) => {\r\n if (effectContext) {\r\n effectContext._rawFragmentSourceCode = fragmentCode;\r\n }\r\n shaderCodes[1] = fragmentCode;\r\n shadersLoaded();\r\n },\r\n shaderLanguage\r\n );\r\n}\r\n\r\nfunction _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void, shaderLanguage?: ShaderLanguage, _loadFileInjection?: typeof _loadFile) {\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.substring(0, 7) === \"source:\") {\r\n callback(shader.substring(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substring(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substring(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n const shaderStore = ShaderStore.GetShadersStore(shaderLanguage);\r\n\r\n // Is in local store ?\r\n if (shaderStore[shader + key + \"Shader\"]) {\r\n callback(shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(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 = ShaderStore.GetShadersRepository(shaderLanguage) + shader;\r\n }\r\n _loadFileInjection = _loadFileInjection || _loadFile;\r\n if (!_loadFileInjection) {\r\n // we got to this point and loadFile was not injected - throw an error\r\n throw new Error(\"loadFileInjection is not defined\");\r\n }\r\n // Vertex shader\r\n _loadFileInjection(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n}\r\n\r\nfunction _useFinalCode(migratedVertexCode: string, migratedFragmentCode: string, baseName: any, shaderLanguage?: ShaderLanguage) {\r\n if (baseName) {\r\n const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;\r\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;\r\n\r\n return {\r\n vertexSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME vertex:\" + vertex + \"\\n\" + migratedVertexCode,\r\n fragmentSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME fragment:\" + fragment + \"\\n\" + migratedFragmentCode,\r\n };\r\n } else {\r\n return {\r\n vertexSourceCode: migratedVertexCode,\r\n fragmentSourceCode: migratedFragmentCode,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Creates and prepares a pipeline context\r\n * @internal\r\n */\r\nexport const createAndPreparePipelineContext = (\r\n options: ICreateAndPreparePipelineContextOptions,\r\n createPipelineContext: typeof AbstractEngine.prototype.createPipelineContext,\r\n _preparePipelineContext: typeof AbstractEngine.prototype._preparePipelineContext,\r\n _executeWhenRenderingStateIsCompiled: typeof AbstractEngine.prototype._executeWhenRenderingStateIsCompiled\r\n): IPipelineContext => {\r\n try {\r\n const pipelineContext: IPipelineContext = options.existingPipelineContext || createPipelineContext(options.shaderProcessingContext);\r\n pipelineContext._name = options.name;\r\n if (options.name && options.context) {\r\n const stateObject = getStateObject(options.context);\r\n stateObject.cachedPipelines[options.name] = pipelineContext;\r\n }\r\n\r\n // Flagged as async as we may need to delay load some processing tools\r\n // This does not break anything as the execution is waiting for _executeWhenRenderingStateIsCompiled\r\n _preparePipelineContext(\r\n pipelineContext,\r\n options.vertex,\r\n options.fragment,\r\n !!options.createAsRaw,\r\n \"\",\r\n \"\",\r\n options.rebuildRebind,\r\n options.defines,\r\n options.transformFeedbackVaryings,\r\n \"\",\r\n () => {\r\n _executeWhenRenderingStateIsCompiled(pipelineContext, () => {\r\n options.onRenderingStateCompiled?.(pipelineContext);\r\n });\r\n }\r\n );\r\n\r\n return pipelineContext;\r\n } catch (e) {\r\n Logger.Error(\"Error compiling effect\");\r\n throw e;\r\n }\r\n};\r\n\r\nexport const _retryWithInterval = (condition: () => boolean, onSuccess: () => void, onError?: (e?: any) => void, step = 16, maxTimeout = 1000) => {\r\n const int = setInterval(() => {\r\n try {\r\n if (condition()) {\r\n clearInterval(int);\r\n onSuccess();\r\n }\r\n } catch (e) {\r\n clearInterval(int);\r\n onError?.(e);\r\n }\r\n maxTimeout -= step;\r\n if (maxTimeout < 0) {\r\n clearInterval(int);\r\n onError?.();\r\n }\r\n }, step);\r\n};\r\n"]}
1
+ {"version":3,"file":"effect.functions.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/effect.functions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,iCAAgC;AAIjF,OAAO,EAAE,cAAc,EAAE,2CAA0C;AACnE,OAAO,EAAE,WAAW,EAAE,kCAAiC;AAIvD,OAAO,EAAE,MAAM,EAAE,0BAAyB;AAC1C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,OAAO,EAAE,iDAAgD;AACxF,OAAO,EAAE,SAAS,EAAE,+CAA8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BAAkB,GAAG,CAAC,SAAwB,EAAE,SAAqB,EAAE,OAA2B,EAAE,IAAI,GAAG,EAAE,EAAE,UAAU,GAAG,IAAI,EAAE,EAAE;IAC7I,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,EAAE;QACzB,IAAI,CAAC;YACD,IAAI,SAAS,EAAE,EAAE,CAAC;gBACd,aAAa,CAAC,GAAG,CAAC,CAAC;gBACnB,SAAS,EAAE,CAAC;YAChB,CAAC;QACL,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,aAAa,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC;QACjB,CAAC;QACD,UAAU,IAAI,IAAI,CAAC;QACnB,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACjB,aAAa,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,EAAE,CAAC,IAAI,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC;QACpC,CAAC;IACL,CAAC,EAAE,IAAI,CAAC,CAAC;AACb,CAAC,CAAC","sourcesContent":["import type { ProcessingOptions, ShaderCustomProcessingFunction, ShaderProcessingContext } from \"core/Engines/Processors/shaderProcessingOptions\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"core/Misc/domManagement\";\r\nimport type { Nullable } from \"core/types\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport type { WebGLContext } from \"core/Engines/thinEngine.functions\";\r\nimport { getStateObject } from \"core/Engines/thinEngine.functions\";\r\nimport { ShaderStore } from \"core/Engines/shaderStore\";\r\nimport type { AbstractEngine } from \"core/Engines/abstractEngine\";\r\nimport type { Effect, IShaderPath } from \"./effect\";\r\nimport type { IPipelineContext } from \"core/Engines/IPipelineContext\";\r\nimport { Logger } from \"core/Misc/logger\";\r\nimport { Finalize, Initialize, Process } from \"core/Engines/Processors/shaderProcessor\";\r\nimport { _loadFile } from \"core/Engines/abstractEngine.functions\";\r\nimport type { WebGLPipelineContext } from \"core/Engines/WebGL/webGLPipelineContext\";\r\n\r\n/**\r\n * Options to be used when creating a pipeline\r\n */\r\nexport interface IPipelineGenerationOptions {\r\n /**\r\n * The definition of the shader content.\r\n * Can be either a unified name, name per vertex and frament or the shader code content itself\r\n */\r\n shaderNameOrContent: string | IShaderPath;\r\n /**\r\n * Unique key to identify the pipeline.\r\n * Note that though not mandatory, it's recommended to provide a key to be able to use the automated pipeline loading system.\r\n */\r\n key?: string;\r\n /**\r\n * The list of defines to be used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * If true, the global defines will be added to the defines array\r\n */\r\n addGlobalDefines?: boolean;\r\n /**\r\n * The shader language.\r\n * Defaults to the language suiting the platform name (GLSL for WEBGL2, WGSL for WEBGPU)\r\n */\r\n shaderLanguage?: ShaderLanguage;\r\n\r\n /**\r\n * The name of the platform to be used when processing the shader\r\n * defaults to WEBGL2\r\n */\r\n platformName?: string /* \"WEBGL2\" | \"WEBGL1\" | \"WEBGPU\" */;\r\n\r\n /**\r\n * extend the processing options when running code processing\r\n */\r\n extendedProcessingOptions?: Partial<ProcessingOptions>;\r\n\r\n /**\r\n * extend the pipeline generation options\r\n */\r\n extendedCreatePipelineOptions?: Partial<ICreateAndPreparePipelineContextOptions>;\r\n\r\n /**\r\n * If true, generating a new pipeline will return when the pipeline is ready to be used\r\n */\r\n waitForIsReady?: boolean;\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport interface ICreateAndPreparePipelineContextOptions {\r\n parallelShaderCompile?: { COMPLETION_STATUS_KHR: number };\r\n shaderProcessingContext: Nullable<ShaderProcessingContext>;\r\n existingPipelineContext?: Nullable<IPipelineContext>;\r\n name?: string;\r\n rebuildRebind?: (vertexSourceCode: string, fragmentSourceCode: string, onCompiled: (pipelineContext: IPipelineContext) => void, onError: (message: string) => void) => void;\r\n onRenderingStateCompiled?: (pipelineContext?: IPipelineContext) => void;\r\n context?: WebGL2RenderingContext | WebGLRenderingContext;\r\n // preparePipeline options\r\n createAsRaw?: boolean;\r\n vertex: string;\r\n fragment: string;\r\n defines: Nullable<string>;\r\n transformFeedbackVaryings: Nullable<string[]>;\r\n}\r\n\r\n/**\r\n * Get a cached pipeline context\r\n * @param name the pipeline name\r\n * @param context the context to be used when creating the pipeline\r\n * @returns the cached pipeline context if it exists\r\n * @internal\r\n */\r\nexport function getCachedPipeline(name: string, context: WebGLContext): IPipelineContext | undefined {\r\n const stateObject = getStateObject(context);\r\n return stateObject.cachedPipelines[name];\r\n}\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function resetCachedPipeline(pipeline: IPipelineContext): void {\r\n const name = pipeline._name;\r\n const context = (pipeline as WebGLPipelineContext).context;\r\n if (name && context) {\r\n const stateObject = getStateObject(context!);\r\n const cachedPipeline = stateObject.cachedPipelines[name];\r\n cachedPipeline?.dispose();\r\n delete stateObject.cachedPipelines[name];\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function _processShaderCode(\r\n processorOptions: ProcessingOptions,\r\n baseName: any,\r\n processFinalCode?: Nullable<ShaderCustomProcessingFunction>,\r\n onFinalCodeReady?: (vertexCode: string, fragmentCode: string) => void,\r\n shaderLanguage?: ShaderLanguage,\r\n engine?: AbstractEngine,\r\n effectContext?: Effect\r\n) {\r\n let vertexSource: string | HTMLElement | IShaderPath;\r\n let fragmentSource: string | HTMLElement | IShaderPath;\r\n\r\n // const baseName = this.name;\r\n const hostDocument = IsWindowObjectExist() ? engine?.getHostDocument() : null;\r\n\r\n if (typeof baseName === \"string\") {\r\n vertexSource = baseName;\r\n } else if (baseName.vertexSource) {\r\n vertexSource = \"source:\" + baseName.vertexSource;\r\n } else if (baseName.vertexElement) {\r\n vertexSource = hostDocument?.getElementById(baseName.vertexElement) || baseName.vertexElement;\r\n } else {\r\n vertexSource = baseName.vertex || baseName;\r\n }\r\n if (typeof baseName === \"string\") {\r\n fragmentSource = baseName;\r\n } else if (baseName.fragmentSource) {\r\n fragmentSource = \"source:\" + baseName.fragmentSource;\r\n } else if (baseName.fragmentElement) {\r\n fragmentSource = hostDocument?.getElementById(baseName.fragmentElement) || baseName.fragmentElement;\r\n } else {\r\n fragmentSource = baseName.fragment || baseName;\r\n }\r\n\r\n const shaderCodes: [string | undefined, string | undefined] = [undefined, undefined];\r\n const shadersLoaded = () => {\r\n if (shaderCodes[0] && shaderCodes[1]) {\r\n processorOptions.isFragment = true;\r\n const [migratedVertexCode, fragmentCode] = shaderCodes;\r\n Process(\r\n fragmentCode,\r\n processorOptions,\r\n (migratedFragmentCode, codeBeforeMigration) => {\r\n if (effectContext) {\r\n effectContext._fragmentSourceCodeBeforeMigration = codeBeforeMigration;\r\n }\r\n if (processFinalCode) {\r\n migratedFragmentCode = processFinalCode(\"fragment\", migratedFragmentCode);\r\n }\r\n const finalShaders = Finalize(migratedVertexCode, migratedFragmentCode, processorOptions);\r\n processorOptions = null as any;\r\n const finalCode = _useFinalCode(finalShaders.vertexCode, finalShaders.fragmentCode, baseName, shaderLanguage);\r\n onFinalCodeReady?.(finalCode.vertexSourceCode, finalCode.fragmentSourceCode);\r\n },\r\n engine\r\n );\r\n }\r\n };\r\n _loadShader(\r\n vertexSource,\r\n \"Vertex\",\r\n \"\",\r\n (vertexCode) => {\r\n Initialize(processorOptions);\r\n Process(\r\n vertexCode,\r\n processorOptions,\r\n (migratedVertexCode, codeBeforeMigration) => {\r\n if (effectContext) {\r\n effectContext._rawVertexSourceCode = vertexCode;\r\n effectContext._vertexSourceCodeBeforeMigration = codeBeforeMigration;\r\n }\r\n if (processFinalCode) {\r\n migratedVertexCode = processFinalCode(\"vertex\", migratedVertexCode);\r\n }\r\n shaderCodes[0] = migratedVertexCode;\r\n shadersLoaded();\r\n },\r\n engine\r\n );\r\n },\r\n shaderLanguage\r\n );\r\n _loadShader(\r\n fragmentSource,\r\n \"Fragment\",\r\n \"Pixel\",\r\n (fragmentCode) => {\r\n if (effectContext) {\r\n effectContext._rawFragmentSourceCode = fragmentCode;\r\n }\r\n shaderCodes[1] = fragmentCode;\r\n shadersLoaded();\r\n },\r\n shaderLanguage\r\n );\r\n}\r\n\r\nfunction _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void, shaderLanguage?: ShaderLanguage, _loadFileInjection?: typeof _loadFile) {\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.substring(0, 7) === \"source:\") {\r\n callback(shader.substring(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substring(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substring(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n const shaderStore = ShaderStore.GetShadersStore(shaderLanguage);\r\n\r\n // Is in local store ?\r\n if (shaderStore[shader + key + \"Shader\"]) {\r\n callback(shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(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 = ShaderStore.GetShadersRepository(shaderLanguage) + shader;\r\n }\r\n _loadFileInjection = _loadFileInjection || _loadFile;\r\n if (!_loadFileInjection) {\r\n // we got to this point and loadFile was not injected - throw an error\r\n throw new Error(\"loadFileInjection is not defined\");\r\n }\r\n // Vertex shader\r\n _loadFileInjection(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n}\r\n\r\nfunction _useFinalCode(migratedVertexCode: string, migratedFragmentCode: string, baseName: any, shaderLanguage?: ShaderLanguage) {\r\n if (baseName) {\r\n const vertex = baseName.vertexElement || baseName.vertex || baseName.spectorName || baseName;\r\n const fragment = baseName.fragmentElement || baseName.fragment || baseName.spectorName || baseName;\r\n\r\n return {\r\n vertexSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME vertex:\" + vertex + \"\\n\" + migratedVertexCode,\r\n fragmentSourceCode: (shaderLanguage === ShaderLanguage.WGSL ? \"//\" : \"\") + \"#define SHADER_NAME fragment:\" + fragment + \"\\n\" + migratedFragmentCode,\r\n };\r\n } else {\r\n return {\r\n vertexSourceCode: migratedVertexCode,\r\n fragmentSourceCode: migratedFragmentCode,\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Creates and prepares a pipeline context\r\n * @internal\r\n */\r\nexport const createAndPreparePipelineContext = (\r\n options: ICreateAndPreparePipelineContextOptions,\r\n createPipelineContext: typeof AbstractEngine.prototype.createPipelineContext,\r\n _preparePipelineContext: typeof AbstractEngine.prototype._preparePipelineContext,\r\n _executeWhenRenderingStateIsCompiled: typeof AbstractEngine.prototype._executeWhenRenderingStateIsCompiled\r\n): IPipelineContext => {\r\n try {\r\n const pipelineContext: IPipelineContext = options.existingPipelineContext || createPipelineContext(options.shaderProcessingContext);\r\n pipelineContext._name = options.name;\r\n if (options.name && options.context) {\r\n const stateObject = getStateObject(options.context);\r\n stateObject.cachedPipelines[options.name] = pipelineContext;\r\n }\r\n\r\n // Flagged as async as we may need to delay load some processing tools\r\n // This does not break anything as the execution is waiting for _executeWhenRenderingStateIsCompiled\r\n _preparePipelineContext(\r\n pipelineContext,\r\n options.vertex,\r\n options.fragment,\r\n !!options.createAsRaw,\r\n \"\",\r\n \"\",\r\n options.rebuildRebind,\r\n options.defines,\r\n options.transformFeedbackVaryings,\r\n \"\",\r\n () => {\r\n _executeWhenRenderingStateIsCompiled(pipelineContext, () => {\r\n options.onRenderingStateCompiled?.(pipelineContext);\r\n });\r\n }\r\n );\r\n\r\n return pipelineContext;\r\n } catch (e) {\r\n Logger.Error(\"Error compiling effect\");\r\n throw e;\r\n }\r\n};\r\n\r\nexport const _retryWithInterval = (condition: () => boolean, onSuccess: () => void, onError?: (e?: any) => void, step = 16, maxTimeout = 1000) => {\r\n const int = setInterval(() => {\r\n try {\r\n if (condition()) {\r\n clearInterval(int);\r\n onSuccess();\r\n }\r\n } catch (e) {\r\n clearInterval(int);\r\n onError?.(e);\r\n }\r\n maxTimeout -= step;\r\n if (maxTimeout < 0) {\r\n clearInterval(int);\r\n onError?.(new Error(\"Timeout\"));\r\n }\r\n }, step);\r\n};\r\n"]}
@@ -40,10 +40,10 @@ export class RGBDTextureTools {
40
40
  const shaderLanguage = isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */;
41
41
  internalTexture.isReady = false;
42
42
  if (isWebGPU) {
43
- await Promise.all([import("../ShadersWGSL/rgbdDecode.fragment.js"), import("../ShadersWGSL/rgbdEncode.fragment.js")]);
43
+ await import("../ShadersWGSL/rgbdDecode.fragment.js");
44
44
  }
45
45
  else {
46
- await Promise.all([import("../Shaders/rgbdDecode.fragment.js"), import("../Shaders/rgbdEncode.fragment.js")]);
46
+ await import("../Shaders/rgbdDecode.fragment.js");
47
47
  }
48
48
  // Expand the texture if possible
49
49
  // Simply run through the decode PP.
@@ -95,7 +95,13 @@ export class RGBDTextureTools {
95
95
  * @param outputTextureType type of the texture in which the encoding is performed
96
96
  * @returns a promise with the internalTexture having its texture replaced by the result of the processing
97
97
  */
98
- static EncodeTextureToRGBD(internalTexture, scene, outputTextureType = 0) {
98
+ static async EncodeTextureToRGBD(internalTexture, scene, outputTextureType = 0) {
99
+ if (!scene.getEngine().isWebGPU) {
100
+ await import("../Shaders/rgbdEncode.fragment.js");
101
+ }
102
+ else {
103
+ await import("../ShadersWGSL/rgbdEncode.fragment.js");
104
+ }
99
105
  return ApplyPostProcess("rgbdEncode", internalTexture, scene, outputTextureType, 1, 5);
100
106
  }
101
107
  }
@@ -1 +1 @@
1
- {"version":3,"file":"rgbdTextureTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/rgbdTextureTools.ts"],"names":[],"mappings":"AAAA,OA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MAAM,EAAE,EAAE;wBACjC,MAAM,CAAC,YAAY,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;wBACvD,MAAM,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;oBACpC,CAAC,CAAC;oBACF,OAAO,CAAC,QAAQ,EAAG,CAAC,kBAAkB,CAAC,YAAY,CAAC,CAAC,eAAgB,CAAC,EAAE,eAAe,EAAE,IAAI,CAAC,CAAC;oBAE/F,UAAU;oBACV,MAAM,CAAC,yBAAyB,EAAE,CAAC;oBACnC,MAAM,CAAC,eAAe,CAAC,eAAe,CAAC,CAAC;oBACxC,IAAI,eAAe,EAAE,CAAC;wBAClB,eAAe,CAAC,OAAO,EAAE,CAAC;oBAC9B,CAAC;oBAED,gBAAgB;oBAChB,eAAe,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;oBAE7C,8BAA8B;oBAC9B,eAAe,CAAC,OAAO,GAAG,IAAI,CAAC;gBACnC,CAAC,CAAC,CAAC;YACP,CAAC,CAAC,CAAC;QACP,CAAC,CAAC;QAEF,IAAI,aAAa,EAAE,CAAC;YAChB,IAAI,OAAO,EAAE,CAAC;gBACV,iBAAiB,EAAE,CAAC;YACxB,CAAC;iBAAM,CAAC;gBACJ,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YACxD,CAAC;QACL,CAAC;IACL,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,mBAAmB,CAAC,eAAgC,EAAE,KAAY,EAAE,iBAAiB,GAAG,SAAS,CAAC,yBAAyB;QACrI,OAAO,gBAAgB,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,CAAC,4BAA4B,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC3J,CAAC;CACJ","sourcesContent":["import { Constants } from \"../Engines/constants\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\n\r\nimport { ApplyPostProcess } from \"./textureTools\";\r\n\r\nimport type { Texture } from \"../Materials/Textures/texture\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { Scene } from \"../scene\";\r\nimport { ShaderLanguage } from \"core/Materials\";\r\n\r\n/**\r\n * Class used to host RGBD texture specific utilities\r\n */\r\nexport class RGBDTextureTools {\r\n /**\r\n * Expand the RGBD Texture from RGBD to Half Float if possible.\r\n * @param texture the texture to expand.\r\n */\r\n public static ExpandRGBDTexture(texture: Texture) {\r\n const internalTexture = texture._texture;\r\n if (!internalTexture || !texture.isRGBD) {\r\n return;\r\n }\r\n\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine();\r\n const caps = engine.getCaps();\r\n const isReady = internalTexture.isReady;\r\n let expandTexture = false;\r\n\r\n // If half float available we can uncompress the texture\r\n if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\r\n expandTexture = true;\r\n internalTexture.type = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n // If full float available we can uncompress the texture\r\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\r\n expandTexture = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n if (expandTexture) {\r\n // Do not use during decode.\r\n internalTexture.isReady = false;\r\n internalTexture._isRGBD = false;\r\n internalTexture.invertY = false;\r\n }\r\n\r\n const expandRGBDTexture = async () => {\r\n const isWebGPU = engine.isWebGPU;\r\n const shaderLanguage = isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL;\r\n internalTexture.isReady = false;\r\n\r\n if (isWebGPU) {\r\n await Promise.all([import(\"../ShadersWGSL/rgbdDecode.fragment\"), import(\"../ShadersWGSL/rgbdEncode.fragment\")]);\r\n } else {\r\n await Promise.all([import(\"../Shaders/rgbdDecode.fragment\"), import(\"../Shaders/rgbdEncode.fragment\")]);\r\n }\r\n\r\n // Expand the texture if possible\r\n // Simply run through the decode PP.\r\n const rgbdPostProcess = new PostProcess(\r\n \"rgbdDecode\",\r\n \"rgbdDecode\",\r\n null,\r\n null,\r\n 1,\r\n null,\r\n Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n undefined,\r\n internalTexture.type,\r\n undefined,\r\n null,\r\n false,\r\n undefined,\r\n shaderLanguage\r\n );\r\n rgbdPostProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const expandedTexture = engine.createRenderTargetTexture(internalTexture.width, {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode: internalTexture.samplingMode,\r\n type: internalTexture.type,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n });\r\n\r\n rgbdPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n // PP Render Pass\r\n rgbdPostProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n texture.getScene()!.postProcessManager.directRender([rgbdPostProcess!], expandedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (rgbdPostProcess) {\r\n rgbdPostProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n expandedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.isReady = true;\r\n });\r\n });\r\n };\r\n\r\n if (expandTexture) {\r\n if (isReady) {\r\n expandRGBDTexture();\r\n } else {\r\n texture.onLoadObservable.addOnce(expandRGBDTexture);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Encode the texture to RGBD if possible.\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param outputTextureType type of the texture in which the encoding is performed\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n public static EncodeTextureToRGBD(internalTexture: InternalTexture, scene: Scene, outputTextureType = Constants.TEXTURETYPE_UNSIGNED_BYTE): Promise<InternalTexture> {\r\n return ApplyPostProcess(\"rgbdEncode\", internalTexture, scene, outputTextureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"rgbdTextureTools.js","sourceRoot":"","sources":["../../../../dev/core/src/Misc/rgbdTextureTools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAE3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAOlD;;GAEG;AACH,MAAM,OAAO,gBAAgB;IACzB;;;OAGG;IACI,MAAM,CAAC,iBAAiB,CAAC,OAAgB;QAC5C,MAAM,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;QACzC,IAAI,CAAC,eAAe,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACtC,OAAO;QACX,CAAC;QAED,yBAAyB;QACzB,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,EAAE,CAAC;QAC3C,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,eAAe,CAAC,OAAO,CAAC;QACxC,IAAI,aAAa,GAAG,KAAK,CAAC;QAE1B,wDAAwD;QACxD,IAAI,IAAI,CAAC,sBAAsB,IAAI,IAAI,CAAC,+BAA+B,EAAE,CAAC;YACtE,aAAa,GAAG,IAAI,CAAC;YACrB,eAAe,CAAC,IAAI,GAAG,SAAS,CAAC,sBAAsB,CAAC;QAC5D,CAAC;QACD,wDAAwD;aACnD,IAAI,IAAI,CAAC,kBAAkB,IAAI,IAAI,CAAC,2BAA2B,EAAE,CAAC;YACnE,aAAa,GAAG,IAAI,CAAC;YACrB,eAAe,CAAC,IAAI,GAAG,SAAS,CAAC,iBAAiB,CAAC;QACvD,CAAC;QAED,I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C;QACnD,CAAC;aAAM,CAAC;YACJ,MAAM,MAAM,CAAC,oCAAoC,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,gBAAgB,CAAC,YAAY,EAAE,eAAe,EAAE,KAAK,EAAE,iBAAiB,EAAE,SAAS,CAAC,4BAA4B,EAAE,SAAS,CAAC,kBAAkB,CAAC,CAAC;IAC3J,CAAC;CACJ","sourcesContent":["import { Constants } from \"../Engines/constants\";\r\nimport { PostProcess } from \"../PostProcesses/postProcess\";\r\n\r\nimport { ApplyPostProcess } from \"./textureTools\";\r\n\r\nimport type { Texture } from \"../Materials/Textures/texture\";\r\nimport type { InternalTexture } from \"../Materials/Textures/internalTexture\";\r\nimport type { Scene } from \"../scene\";\r\nimport { ShaderLanguage } from \"core/Materials\";\r\n\r\n/**\r\n * Class used to host RGBD texture specific utilities\r\n */\r\nexport class RGBDTextureTools {\r\n /**\r\n * Expand the RGBD Texture from RGBD to Half Float if possible.\r\n * @param texture the texture to expand.\r\n */\r\n public static ExpandRGBDTexture(texture: Texture) {\r\n const internalTexture = texture._texture;\r\n if (!internalTexture || !texture.isRGBD) {\r\n return;\r\n }\r\n\r\n // Gets everything ready.\r\n const engine = internalTexture.getEngine();\r\n const caps = engine.getCaps();\r\n const isReady = internalTexture.isReady;\r\n let expandTexture = false;\r\n\r\n // If half float available we can uncompress the texture\r\n if (caps.textureHalfFloatRender && caps.textureHalfFloatLinearFiltering) {\r\n expandTexture = true;\r\n internalTexture.type = Constants.TEXTURETYPE_HALF_FLOAT;\r\n }\r\n // If full float available we can uncompress the texture\r\n else if (caps.textureFloatRender && caps.textureFloatLinearFiltering) {\r\n expandTexture = true;\r\n internalTexture.type = Constants.TEXTURETYPE_FLOAT;\r\n }\r\n\r\n if (expandTexture) {\r\n // Do not use during decode.\r\n internalTexture.isReady = false;\r\n internalTexture._isRGBD = false;\r\n internalTexture.invertY = false;\r\n }\r\n\r\n const expandRGBDTexture = async () => {\r\n const isWebGPU = engine.isWebGPU;\r\n const shaderLanguage = isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL;\r\n internalTexture.isReady = false;\r\n\r\n if (isWebGPU) {\r\n await import(\"../ShadersWGSL/rgbdDecode.fragment\");\r\n } else {\r\n await import(\"../Shaders/rgbdDecode.fragment\");\r\n }\r\n\r\n // Expand the texture if possible\r\n // Simply run through the decode PP.\r\n const rgbdPostProcess = new PostProcess(\r\n \"rgbdDecode\",\r\n \"rgbdDecode\",\r\n null,\r\n null,\r\n 1,\r\n null,\r\n Constants.TEXTURE_TRILINEAR_SAMPLINGMODE,\r\n engine,\r\n false,\r\n undefined,\r\n internalTexture.type,\r\n undefined,\r\n null,\r\n false,\r\n undefined,\r\n shaderLanguage\r\n );\r\n rgbdPostProcess.externalTextureSamplerBinding = true;\r\n\r\n // Hold the output of the decoding.\r\n const expandedTexture = engine.createRenderTargetTexture(internalTexture.width, {\r\n generateDepthBuffer: false,\r\n generateMipMaps: false,\r\n generateStencilBuffer: false,\r\n samplingMode: internalTexture.samplingMode,\r\n type: internalTexture.type,\r\n format: Constants.TEXTUREFORMAT_RGBA,\r\n });\r\n\r\n rgbdPostProcess.onEffectCreatedObservable.addOnce((e) => {\r\n e.executeWhenCompiled(() => {\r\n // PP Render Pass\r\n rgbdPostProcess.onApply = (effect) => {\r\n effect._bindTexture(\"textureSampler\", internalTexture);\r\n effect.setFloat2(\"scale\", 1, 1);\r\n };\r\n texture.getScene()!.postProcessManager.directRender([rgbdPostProcess!], expandedTexture, true);\r\n\r\n // Cleanup\r\n engine.restoreDefaultFramebuffer();\r\n engine._releaseTexture(internalTexture);\r\n if (rgbdPostProcess) {\r\n rgbdPostProcess.dispose();\r\n }\r\n\r\n // Internal Swap\r\n expandedTexture._swapAndDie(internalTexture);\r\n\r\n // Ready to get rolling again.\r\n internalTexture.isReady = true;\r\n });\r\n });\r\n };\r\n\r\n if (expandTexture) {\r\n if (isReady) {\r\n expandRGBDTexture();\r\n } else {\r\n texture.onLoadObservable.addOnce(expandRGBDTexture);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Encode the texture to RGBD if possible.\r\n * @param internalTexture the texture to encode\r\n * @param scene the scene hosting the texture\r\n * @param outputTextureType type of the texture in which the encoding is performed\r\n * @returns a promise with the internalTexture having its texture replaced by the result of the processing\r\n */\r\n public static async EncodeTextureToRGBD(internalTexture: InternalTexture, scene: Scene, outputTextureType = Constants.TEXTURETYPE_UNSIGNED_BYTE): Promise<InternalTexture> {\r\n if (!scene.getEngine().isWebGPU) {\r\n await import(\"../Shaders/rgbdEncode.fragment\");\r\n } else {\r\n await import(\"../ShadersWGSL/rgbdEncode.fragment\");\r\n }\r\n return ApplyPostProcess(\"rgbdEncode\", internalTexture, scene, outputTextureType, Constants.TEXTURE_NEAREST_SAMPLINGMODE, Constants.TEXTUREFORMAT_RGBA);\r\n }\r\n}\r\n"]}
@@ -107,6 +107,10 @@ export declare class WebXRNearInteraction extends WebXRAbstractFeature {
107
107
  * This color will be applied to the selection ring when selection is triggered
108
108
  */
109
109
  selectionMeshPickedColor: Color3;
110
+ /**
111
+ * If set to true, the selection mesh will always be hidden. Otherwise it will be shown only when needed
112
+ */
113
+ alwaysHideSelectionMesh: boolean;
110
114
  /**
111
115
  * constructs a new background remover module
112
116
  * @param _xrSessionManager the session manager for this module
@@ -48,6 +48,7 @@ export var WebXRNearControllerMode;
48
48
  */
49
49
  WebXRNearControllerMode[WebXRNearControllerMode["CENTERED_IN_FRONT"] = 2] = "CENTERED_IN_FRONT";
50
50
  })(WebXRNearControllerMode || (WebXRNearControllerMode = {}));
51
+ const _tmpVectors = [new Vector3(), new Vector3(), new Vector3(), new Vector3()];
51
52
  /**
52
53
  * A module that will enable near interaction near interaction for hands and motion controllers of XR Input Sources
53
54
  */
@@ -131,6 +132,10 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
131
132
  * This color will be applied to the selection ring when selection is triggered
132
133
  */
133
134
  this.selectionMeshPickedColor = new Color3(0.3, 0.3, 1.0);
135
+ /**
136
+ * If set to true, the selection mesh will always be hidden. Otherwise it will be shown only when needed
137
+ */
138
+ this.alwaysHideSelectionMesh = false;
134
139
  this._hoverRadius = 0.1;
135
140
  this._pickRadius = 0.02;
136
141
  this._controllerPickRadius = 0.03; // The radius is slightly larger here to make it easier to manipulate since it's not tied to the hand position
@@ -417,7 +422,7 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
417
422
  if (controllerData.pick && controllerData.pick.pickedPoint && controllerData.pick.hit) {
418
423
  controllerData.meshUnderPointer = controllerData.pick.pickedMesh;
419
424
  controllerData.pickedPointVisualCue.position.copyFrom(controllerData.pick.pickedPoint);
420
- controllerData.pickedPointVisualCue.isVisible = true;
425
+ controllerData.pickedPointVisualCue.isVisible = !this.alwaysHideSelectionMesh;
421
426
  if (this._farInteractionFeature && this._farInteractionFeature.attached) {
422
427
  this._farInteractionFeature._setPointerSelectionDisabledByPointerId(controllerData.id, true);
423
428
  }
@@ -514,7 +519,7 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
514
519
  this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);
515
520
  controllerData.downTriggered = false;
516
521
  controllerData.grabInteraction = false;
517
- controllerData.pickedPointVisualCue.isVisible = true;
522
+ controllerData.pickedPointVisualCue.isVisible = !this.alwaysHideSelectionMesh;
518
523
  }
519
524
  }
520
525
  else {
@@ -573,7 +578,7 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
573
578
  this._isControllerReadyForNearInteraction(controllerData.id)) {
574
579
  this._scene.simulatePointerUp(controllerData.pick, pointerEventInit);
575
580
  controllerData.grabInteraction = false;
576
- controllerData.pickedPointVisualCue.isVisible = true;
581
+ controllerData.pickedPointVisualCue.isVisible = !this.alwaysHideSelectionMesh;
577
582
  controllerData.downTriggered = false;
578
583
  }
579
584
  };
@@ -779,9 +784,11 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
779
784
  if (!skipBoundingInfo && !BoundingSphere.Intersects(boundingInfo.boundingSphere, sphere)) {
780
785
  return pi;
781
786
  }
782
- const result = TmpVectors.Vector3[0];
783
- const tmpVec = TmpVectors.Vector3[1];
784
- const tmpRay = new Ray(Vector3.Zero(), Vector3.Zero(), 1);
787
+ const result = _tmpVectors[0];
788
+ const tmpVec = _tmpVectors[1];
789
+ _tmpVectors[2].setAll(0);
790
+ _tmpVectors[3].setAll(0);
791
+ const tmpRay = new Ray(_tmpVectors[2], _tmpVectors[3], 1);
785
792
  let distance = +Infinity;
786
793
  let tmp, tmpDistanceSphereToCenter, tmpDistanceSurfaceToCenter, intersectionInfo;
787
794
  const center = TmpVectors.Vector3[2];
@@ -795,8 +802,8 @@ export class WebXRNearInteraction extends WebXRAbstractFeature {
795
802
  Vector3.TransformCoordinatesToRef(tmpVec, mesh.getWorldMatrix(), tmpVec);
796
803
  tmp = Vector3.Distance(tmpVec, sphere.center);
797
804
  // Check for finger inside of mesh
798
- tmpDistanceSurfaceToCenter = Vector3.Distance(tmpVec, mesh.getAbsolutePosition());
799
- tmpDistanceSphereToCenter = Vector3.Distance(sphere.center, mesh.getAbsolutePosition());
805
+ tmpDistanceSurfaceToCenter = Vector3.DistanceSquared(tmpVec, mesh.getAbsolutePosition());
806
+ tmpDistanceSphereToCenter = Vector3.DistanceSquared(sphere.center, mesh.getAbsolutePosition());
800
807
  if (tmpDistanceSphereToCenter !== -1 && tmpDistanceSurfaceToCenter !== -1 && tmpDistanceSurfaceToCenter > tmpDistanceSphereToCenter) {
801
808
  tmp = 0;
802
809
  tmpVec.copyFrom(sphere.center);