@babylonjs/core 7.3.2 → 7.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/Compute/computeEffect.js +4 -4
  2. package/Compute/computeEffect.js.map +1 -1
  3. package/Engines/IPipelineContext.d.ts +3 -0
  4. package/Engines/IPipelineContext.js.map +1 -1
  5. package/Engines/Native/nativePipelineContext.d.ts +2 -0
  6. package/Engines/Native/nativePipelineContext.js +3 -0
  7. package/Engines/Native/nativePipelineContext.js.map +1 -1
  8. package/Engines/Processors/iShaderProcessor.d.ts +3 -2
  9. package/Engines/Processors/iShaderProcessor.js.map +1 -1
  10. package/Engines/Processors/shaderProcessor.d.ts +15 -23
  11. package/Engines/Processors/shaderProcessor.js +332 -320
  12. package/Engines/Processors/shaderProcessor.js.map +1 -1
  13. package/Engines/WebGL/webGLPipelineContext.d.ts +2 -0
  14. package/Engines/WebGL/webGLPipelineContext.js +3 -0
  15. package/Engines/WebGL/webGLPipelineContext.js.map +1 -1
  16. package/Engines/WebGL/webGLShaderProcessors.d.ts +3 -2
  17. package/Engines/WebGL/webGLShaderProcessors.js +2 -2
  18. package/Engines/WebGL/webGLShaderProcessors.js.map +1 -1
  19. package/Engines/WebGPU/Extensions/engine.computeShader.js +1 -1
  20. package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
  21. package/Engines/WebGPU/webgpuPipelineContext.d.ts +2 -0
  22. package/Engines/WebGPU/webgpuPipelineContext.js +3 -0
  23. package/Engines/WebGPU/webgpuPipelineContext.js.map +1 -1
  24. package/Engines/WebGPU/webgpuShaderProcessorsGLSL.d.ts +3 -2
  25. package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js +2 -4
  26. package/Engines/WebGPU/webgpuShaderProcessorsGLSL.js.map +1 -1
  27. package/Engines/abstractEngine.d.ts +10 -5
  28. package/Engines/abstractEngine.functions.d.ts +38 -0
  29. package/Engines/abstractEngine.functions.js +75 -0
  30. package/Engines/abstractEngine.functions.js.map +1 -0
  31. package/Engines/abstractEngine.js +22 -14
  32. package/Engines/abstractEngine.js.map +1 -1
  33. package/Engines/constants.d.ts +2 -0
  34. package/Engines/constants.js +2 -0
  35. package/Engines/constants.js.map +1 -1
  36. package/Engines/thinEngine.d.ts +11 -6
  37. package/Engines/thinEngine.functions.d.ts +96 -0
  38. package/Engines/thinEngine.functions.js +249 -0
  39. package/Engines/thinEngine.functions.js.map +1 -0
  40. package/Engines/thinEngine.js +50 -129
  41. package/Engines/thinEngine.js.map +1 -1
  42. package/Engines/webgpuEngine.js +5 -1
  43. package/Engines/webgpuEngine.js.map +1 -1
  44. package/Materials/Node/Blocks/Dual/textureBlock.js +3 -3
  45. package/Materials/Node/Blocks/Dual/textureBlock.js.map +1 -1
  46. package/Materials/Textures/Procedurals/proceduralTexture.d.ts +9 -1
  47. package/Materials/Textures/Procedurals/proceduralTexture.js +16 -0
  48. package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
  49. package/Materials/effect.d.ts +11 -6
  50. package/Materials/effect.functions.d.ts +86 -0
  51. package/Materials/effect.functions.js +185 -0
  52. package/Materials/effect.functions.js.map +1 -0
  53. package/Materials/effect.js +94 -153
  54. package/Materials/effect.js.map +1 -1
  55. package/Materials/effect.webgl.functions.d.ts +13 -0
  56. package/Materials/effect.webgl.functions.js +83 -0
  57. package/Materials/effect.webgl.functions.js.map +1 -0
  58. package/Materials/materialPluginManager.js +2 -2
  59. package/Materials/materialPluginManager.js.map +1 -1
  60. package/Meshes/Compression/dracoCompression.js.map +1 -1
  61. package/Meshes/Compression/dracoCompressionWorker.d.ts +1 -1
  62. package/Meshes/Compression/dracoCompressionWorker.js +21 -10
  63. package/Meshes/Compression/dracoCompressionWorker.js.map +1 -1
  64. package/Meshes/Node/nodeGeometryBlock.js +1 -0
  65. package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
  66. package/Misc/fileTools.js +4 -3
  67. package/Misc/fileTools.js.map +1 -1
  68. package/package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,MAAM,UAAU,wBAAwB,CAAC,UAAkB;IACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACrC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACrB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACtB,4BAA4B,EAAE,CAAC;aAClC;YACD,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,UAAU,4BAA4B;IACxC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACnB,MAAM,GAAG,KAAK,CAAC;IACf,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC","sourcesContent":["import type { ProcessingOptions, ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"./material\";\r\nimport type {\r\n MaterialPluginPrepareEffect,\r\n MaterialPluginBindForSubMesh,\r\n MaterialPluginDisposed,\r\n MaterialPluginGetActiveTextures,\r\n MaterialPluginGetAnimatables,\r\n MaterialPluginGetDefineNames,\r\n MaterialPluginHasTexture,\r\n MaterialPluginIsReadyForSubMesh,\r\n MaterialPluginPrepareDefines,\r\n MaterialPluginPrepareUniformBuffer,\r\n MaterialPluginHardBindForSubMesh,\r\n MaterialPluginHasRenderTargetTextures,\r\n MaterialPluginFillRenderTargetTextures,\r\n} from \"./materialPluginEvent\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport type { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\n\r\ndeclare module \"./material\" {\r\n export interface Material {\r\n /**\r\n * Plugin manager for this material\r\n */\r\n pluginManager?: MaterialPluginManager;\r\n }\r\n}\r\n\r\nconst rxOption = new RegExp(\"^([gimus]+)!\");\r\n\r\n/**\r\n * Class that manages the plugins of a material\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginManager {\r\n /** Map a plugin class name to a #define name (used in the vertex/fragment shaders as a marker of the plugin usage) */\r\n private static _MaterialPluginClassToMainDefine: { [name: string]: string } = {};\r\n private static _MaterialPluginCounter: number = 0;\r\n\r\n protected _material: Material;\r\n protected _scene: Scene;\r\n protected _engine: AbstractEngine;\r\n /** @internal */\r\n public _plugins: MaterialPluginBase[] = [];\r\n protected _activePlugins: MaterialPluginBase[] = [];\r\n protected _activePluginsForExtraEvents: MaterialPluginBase[] = [];\r\n protected _codeInjectionPoints: { [shaderType: string]: { [codeName: string]: boolean } };\r\n protected _defineNamesFromPlugins?: { [name: string]: { type: string; default: any } };\r\n protected _uboDeclaration: string;\r\n protected _vertexDeclaration: string;\r\n protected _fragmentDeclaration: string;\r\n protected _uniformList: string[];\r\n protected _samplerList: string[];\r\n protected _uboList: string[];\r\n\r\n static {\r\n EngineStore.OnEnginesDisposedObservable.add(() => {\r\n UnregisterAllMaterialPlugins();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a new instance of the plugin manager\r\n * @param material material that this manager will manage the plugins for\r\n */\r\n constructor(material: Material) {\r\n this._material = material;\r\n this._scene = material.getScene();\r\n this._engine = this._scene.getEngine();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _addPlugin(plugin: MaterialPluginBase): boolean {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === plugin.name) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._material._uniformBufferLayoutBuilt) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw `The plugin \"${plugin.name}\" can't be added to the material \"${this._material.name}\" because this material has already been used for rendering! Please add plugins to materials before any rendering with this material occurs.`;\r\n }\r\n\r\n const pluginClassName = plugin.getClassName();\r\n if (!MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]) {\r\n MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName] = \"MATERIALPLUGIN_\" + ++MaterialPluginManager._MaterialPluginCounter;\r\n }\r\n\r\n this._material._callbackPluginEventGeneric = (id, info) => this._handlePluginEvent(id, info);\r\n\r\n this._plugins.push(plugin);\r\n this._plugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._codeInjectionPoints = {};\r\n\r\n const defineNamesFromPlugins: { [name: string]: { type: string; default: any } } = {};\r\n defineNamesFromPlugins[MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]] = {\r\n type: \"boolean\",\r\n default: true,\r\n };\r\n\r\n for (const plugin of this._plugins) {\r\n plugin.collectDefines(defineNamesFromPlugins);\r\n this._collectPointNames(\"vertex\", plugin.getCustomCode(\"vertex\"));\r\n this._collectPointNames(\"fragment\", plugin.getCustomCode(\"fragment\"));\r\n }\r\n\r\n this._defineNamesFromPlugins = defineNamesFromPlugins;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _activatePlugin(plugin: MaterialPluginBase): void {\r\n if (this._activePlugins.indexOf(plugin) === -1) {\r\n this._activePlugins.push(plugin);\r\n this._activePlugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._material._callbackPluginEventIsReadyForSubMesh = this._handlePluginEventIsReadyForSubMesh.bind(this);\r\n this._material._callbackPluginEventPrepareDefinesBeforeAttributes = this._handlePluginEventPrepareDefinesBeforeAttributes.bind(this);\r\n this._material._callbackPluginEventPrepareDefines = this._handlePluginEventPrepareDefines.bind(this);\r\n this._material._callbackPluginEventBindForSubMesh = this._handlePluginEventBindForSubMesh.bind(this);\r\n\r\n if (plugin.registerForExtraEvents) {\r\n this._activePluginsForExtraEvents.push(plugin);\r\n this._activePluginsForExtraEvents.sort((a, b) => a.priority - b.priority);\r\n this._material._callbackPluginEventHasRenderTargetTextures = this._handlePluginEventHasRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventFillRenderTargetTextures = this._handlePluginEventFillRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventHardBindForSubMesh = this._handlePluginEventHardBindForSubMesh.bind(this);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a plugin from the list of plugins managed by this manager\r\n * @param name name of the plugin\r\n * @returns the plugin if found, else null\r\n */\r\n public getPlugin<T = MaterialPluginBase>(name: string): Nullable<T> {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === name) {\r\n return this._plugins[i] as T;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n protected _handlePluginEventIsReadyForSubMesh(eventData: MaterialPluginIsReadyForSubMesh): void {\r\n let isReady = true;\r\n for (const plugin of this._activePlugins) {\r\n isReady = isReady && plugin.isReadyForSubMesh(eventData.defines, this._scene, this._engine, eventData.subMesh);\r\n }\r\n eventData.isReadyForSubMesh = isReady;\r\n }\r\n\r\n protected _handlePluginEventPrepareDefinesBeforeAttributes(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefinesBeforeAttributes(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventPrepareDefines(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefines(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHardBindForSubMesh(eventData: MaterialPluginHardBindForSubMesh): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.hardBindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventBindForSubMesh(eventData: MaterialPluginBindForSubMesh): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.bindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHasRenderTargetTextures(eventData: MaterialPluginHasRenderTargetTextures): void {\r\n let hasRenderTargetTextures = false;\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n hasRenderTargetTextures = plugin.hasRenderTargetTextures();\r\n if (hasRenderTargetTextures) {\r\n break;\r\n }\r\n }\r\n eventData.hasRenderTargetTextures = hasRenderTargetTextures;\r\n }\r\n\r\n protected _handlePluginEventFillRenderTargetTextures(eventData: MaterialPluginFillRenderTargetTextures): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.fillRenderTargetTextures(eventData.renderTargets);\r\n }\r\n }\r\n\r\n protected _handlePluginEvent(\r\n id: number,\r\n info:\r\n | MaterialPluginGetActiveTextures\r\n | MaterialPluginGetAnimatables\r\n | MaterialPluginHasTexture\r\n | MaterialPluginDisposed\r\n | MaterialPluginGetDefineNames\r\n | MaterialPluginPrepareEffect\r\n | MaterialPluginPrepareUniformBuffer\r\n ): void {\r\n switch (id) {\r\n case MaterialPluginEvent.GetActiveTextures: {\r\n const eventData = info as MaterialPluginGetActiveTextures;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getActiveTextures(eventData.activeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetAnimatables: {\r\n const eventData = info as MaterialPluginGetAnimatables;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getAnimatables(eventData.animatables);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.HasTexture: {\r\n const eventData = info as MaterialPluginHasTexture;\r\n let hasTexture = false;\r\n for (const plugin of this._activePlugins) {\r\n hasTexture = plugin.hasTexture(eventData.texture);\r\n if (hasTexture) {\r\n break;\r\n }\r\n }\r\n eventData.hasTexture = hasTexture;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.Disposed: {\r\n const eventData = info as MaterialPluginDisposed;\r\n for (const plugin of this._plugins) {\r\n plugin.dispose(eventData.forceDisposeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetDefineNames: {\r\n const eventData = info as MaterialPluginGetDefineNames;\r\n eventData.defineNames = this._defineNamesFromPlugins;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareEffect: {\r\n const eventData = info as MaterialPluginPrepareEffect;\r\n for (const plugin of this._activePlugins) {\r\n eventData.fallbackRank = plugin.addFallbacks(eventData.defines, eventData.fallbacks, eventData.fallbackRank);\r\n plugin.getAttributes(eventData.attributes, this._scene, eventData.mesh);\r\n }\r\n if (this._uniformList.length > 0) {\r\n eventData.uniforms.push(...this._uniformList);\r\n }\r\n if (this._samplerList.length > 0) {\r\n eventData.samplers.push(...this._samplerList);\r\n }\r\n if (this._uboList.length > 0) {\r\n eventData.uniformBuffersNames.push(...this._uboList);\r\n }\r\n eventData.customCode = this._injectCustomCode(eventData, eventData.customCode);\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareUniformBuffer: {\r\n const eventData = info as MaterialPluginPrepareUniformBuffer;\r\n this._uboDeclaration = \"\";\r\n this._vertexDeclaration = \"\";\r\n this._fragmentDeclaration = \"\";\r\n this._uniformList = [];\r\n this._samplerList = [];\r\n this._uboList = [];\r\n for (const plugin of this._plugins) {\r\n const uniforms = plugin.getUniforms();\r\n if (uniforms) {\r\n if (uniforms.ubo) {\r\n for (const uniform of uniforms.ubo) {\r\n if (uniform.size && uniform.type) {\r\n const arraySize = uniform.arraySize ?? 0;\r\n eventData.ubo.addUniform(uniform.name, uniform.size, arraySize);\r\n this._uboDeclaration += `${uniform.type} ${uniform.name}${arraySize > 0 ? `[${arraySize}]` : \"\"};\\n`;\r\n }\r\n this._uniformList.push(uniform.name);\r\n }\r\n }\r\n if (uniforms.vertex) {\r\n this._vertexDeclaration += uniforms.vertex + \"\\n\";\r\n }\r\n if (uniforms.fragment) {\r\n this._fragmentDeclaration += uniforms.fragment + \"\\n\";\r\n }\r\n }\r\n plugin.getSamplers(this._samplerList);\r\n plugin.getUniformBuffersNames(this._uboList);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n protected _collectPointNames(shaderType: string, customCode: Nullable<{ [pointName: string]: string }> | undefined): void {\r\n if (!customCode) {\r\n return;\r\n }\r\n for (const pointName in customCode) {\r\n if (!this._codeInjectionPoints[shaderType]) {\r\n this._codeInjectionPoints[shaderType] = {};\r\n }\r\n this._codeInjectionPoints[shaderType][pointName] = true;\r\n }\r\n }\r\n\r\n protected _injectCustomCode(eventData: MaterialPluginPrepareEffect, existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction {\r\n return (shaderType: string, code: string) => {\r\n if (existingCallback) {\r\n code = existingCallback(shaderType, code);\r\n }\r\n if (this._uboDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_UBO_DECLARATION\", this._uboDeclaration);\r\n }\r\n if (this._vertexDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_VERTEX_DECLARATION\", this._vertexDeclaration);\r\n }\r\n if (this._fragmentDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_FRAGMENT_DECLARATION\", this._fragmentDeclaration);\r\n }\r\n const points = this._codeInjectionPoints?.[shaderType];\r\n if (!points) {\r\n return code;\r\n }\r\n let processorOptions: Nullable<ProcessingOptions> = null;\r\n for (let pointName in points) {\r\n let injectedCode = \"\";\r\n for (const plugin of this._activePlugins) {\r\n let customCode = plugin.getCustomCode(shaderType)?.[pointName];\r\n if (!customCode) {\r\n continue;\r\n }\r\n if (plugin.resolveIncludes) {\r\n if (processorOptions === null) {\r\n const shaderLanguage = ShaderLanguage.GLSL;\r\n processorOptions = {\r\n defines: [], // not used by _ProcessIncludes\r\n indexParameters: eventData.indexParameters,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\r\n processor: undefined as any, // not used by _ProcessIncludes\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: ShaderStore.GetShadersRepository(shaderLanguage),\r\n includesShadersStore: ShaderStore.GetIncludesShadersStore(shaderLanguage),\r\n version: undefined as any, // not used by _ProcessIncludes\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: undefined as any, // not used by _ProcessIncludes\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n processCodeAfterIncludes: undefined as any, // not used by _ProcessIncludes\r\n };\r\n }\r\n processorOptions.isFragment = shaderType === \"fragment\";\r\n ShaderProcessor._ProcessIncludes(customCode, processorOptions, (code) => (customCode = code));\r\n }\r\n injectedCode += customCode + \"\\n\";\r\n }\r\n if (injectedCode.length > 0) {\r\n if (pointName.charAt(0) === \"!\") {\r\n // pointName is a regular expression\r\n pointName = pointName.substring(1);\r\n\r\n let regexFlags = \"g\";\r\n if (pointName.charAt(0) === \"!\") {\r\n // no flags\r\n regexFlags = \"\";\r\n pointName = pointName.substring(1);\r\n } else {\r\n // get the flag(s)\r\n const matchOption = rxOption.exec(pointName);\r\n if (matchOption && matchOption.length >= 2) {\r\n regexFlags = matchOption[1];\r\n pointName = pointName.substring(regexFlags.length + 1);\r\n }\r\n }\r\n\r\n if (regexFlags.indexOf(\"g\") < 0) {\r\n // we force the \"g\" flag so that the regexp object is stateful!\r\n regexFlags += \"g\";\r\n }\r\n\r\n const sourceCode = code;\r\n const rx = new RegExp(pointName, regexFlags);\r\n let match = rx.exec(sourceCode);\r\n while (match !== null) {\r\n let newCode = injectedCode;\r\n for (let i = 0; i < match.length; ++i) {\r\n newCode = newCode.replace(\"$\" + i, match[i]);\r\n }\r\n code = code.replace(match[0], newCode);\r\n match = rx.exec(sourceCode);\r\n }\r\n } else {\r\n const fullPointName = \"#define \" + pointName;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n }\r\n return code;\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Type for plugin material factories.\r\n */\r\nexport type PluginMaterialFactory = (material: Material) => Nullable<MaterialPluginBase>;\r\n\r\nconst plugins: Array<[string, PluginMaterialFactory]> = [];\r\nlet inited = false;\r\nlet observer: Nullable<Observer<Material>> = null;\r\n\r\n/**\r\n * Registers a new material plugin through a factory, or updates it. This makes the plugin available to all materials instantiated after its registration.\r\n * @param pluginName The plugin name\r\n * @param factory The factory function which allows to create the plugin\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterMaterialPlugin(pluginName: string, factory: PluginMaterialFactory): void {\r\n if (!inited) {\r\n observer = Material.OnEventObservable.add((material: Material) => {\r\n for (const [, factory] of plugins) {\r\n factory(material);\r\n }\r\n }, MaterialPluginEvent.Created);\r\n inited = true;\r\n }\r\n const existing = plugins.filter(([name, _factory]) => name === pluginName);\r\n if (existing.length > 0) {\r\n existing[0][1] = factory;\r\n } else {\r\n plugins.push([pluginName, factory]);\r\n }\r\n}\r\n\r\n/**\r\n * Removes a material plugin from the list of global plugins.\r\n * @param pluginName The plugin name\r\n * @returns true if the plugin has been removed, else false\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterMaterialPlugin(pluginName: string): boolean {\r\n for (let i = 0; i < plugins.length; ++i) {\r\n if (plugins[i][0] === pluginName) {\r\n plugins.splice(i, 1);\r\n if (plugins.length === 0) {\r\n UnregisterAllMaterialPlugins();\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Clear the list of global material plugins\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterAllMaterialPlugins(): void {\r\n plugins.length = 0;\r\n inited = false;\r\n Material.OnEventObservable.remove(observer);\r\n observer = null;\r\n}\r\n"]}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kB;IACvD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACrC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,UAAU,EAAE;YAC9B,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YACrB,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE;gBACtB,4BAA4B,EAAE,CAAC;aAClC;YACD,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,KAAK,CAAC;AACjB,CAAC;AAED;;GAEG;AACH,gEAAgE;AAChE,MAAM,UAAU,4BAA4B;IACxC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;IACnB,MAAM,GAAG,KAAK,CAAC;IACf,QAAQ,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAC5C,QAAQ,GAAG,IAAI,CAAC;AACpB,CAAC","sourcesContent":["import type { ProcessingOptions, ShaderCustomProcessingFunction } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Material } from \"./material\";\r\nimport type {\r\n MaterialPluginPrepareEffect,\r\n MaterialPluginBindForSubMesh,\r\n MaterialPluginDisposed,\r\n MaterialPluginGetActiveTextures,\r\n MaterialPluginGetAnimatables,\r\n MaterialPluginGetDefineNames,\r\n MaterialPluginHasTexture,\r\n MaterialPluginIsReadyForSubMesh,\r\n MaterialPluginPrepareDefines,\r\n MaterialPluginPrepareUniformBuffer,\r\n MaterialPluginHardBindForSubMesh,\r\n MaterialPluginHasRenderTargetTextures,\r\n MaterialPluginFillRenderTargetTextures,\r\n} from \"./materialPluginEvent\";\r\nimport { MaterialPluginEvent } from \"./materialPluginEvent\";\r\nimport type { Observer } from \"core/Misc/observable\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\n\r\nimport type { Scene } from \"../scene\";\r\nimport type { AbstractEngine } from \"../Engines/abstractEngine\";\r\nimport type { MaterialPluginBase } from \"./materialPluginBase\";\r\nimport { _ProcessIncludes } from \"../Engines/Processors/shaderProcessor\";\r\nimport { ShaderLanguage } from \"./shaderLanguage\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\n\r\ndeclare module \"./material\" {\r\n export interface Material {\r\n /**\r\n * Plugin manager for this material\r\n */\r\n pluginManager?: MaterialPluginManager;\r\n }\r\n}\r\n\r\nconst rxOption = new RegExp(\"^([gimus]+)!\");\r\n\r\n/**\r\n * Class that manages the plugins of a material\r\n * @since 5.0\r\n */\r\nexport class MaterialPluginManager {\r\n /** Map a plugin class name to a #define name (used in the vertex/fragment shaders as a marker of the plugin usage) */\r\n private static _MaterialPluginClassToMainDefine: { [name: string]: string } = {};\r\n private static _MaterialPluginCounter: number = 0;\r\n\r\n protected _material: Material;\r\n protected _scene: Scene;\r\n protected _engine: AbstractEngine;\r\n /** @internal */\r\n public _plugins: MaterialPluginBase[] = [];\r\n protected _activePlugins: MaterialPluginBase[] = [];\r\n protected _activePluginsForExtraEvents: MaterialPluginBase[] = [];\r\n protected _codeInjectionPoints: { [shaderType: string]: { [codeName: string]: boolean } };\r\n protected _defineNamesFromPlugins?: { [name: string]: { type: string; default: any } };\r\n protected _uboDeclaration: string;\r\n protected _vertexDeclaration: string;\r\n protected _fragmentDeclaration: string;\r\n protected _uniformList: string[];\r\n protected _samplerList: string[];\r\n protected _uboList: string[];\r\n\r\n static {\r\n EngineStore.OnEnginesDisposedObservable.add(() => {\r\n UnregisterAllMaterialPlugins();\r\n });\r\n }\r\n\r\n /**\r\n * Creates a new instance of the plugin manager\r\n * @param material material that this manager will manage the plugins for\r\n */\r\n constructor(material: Material) {\r\n this._material = material;\r\n this._scene = material.getScene();\r\n this._engine = this._scene.getEngine();\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _addPlugin(plugin: MaterialPluginBase): boolean {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === plugin.name) {\r\n return false;\r\n }\r\n }\r\n\r\n if (this._material._uniformBufferLayoutBuilt) {\r\n // eslint-disable-next-line no-throw-literal\r\n throw `The plugin \"${plugin.name}\" can't be added to the material \"${this._material.name}\" because this material has already been used for rendering! Please add plugins to materials before any rendering with this material occurs.`;\r\n }\r\n\r\n const pluginClassName = plugin.getClassName();\r\n if (!MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]) {\r\n MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName] = \"MATERIALPLUGIN_\" + ++MaterialPluginManager._MaterialPluginCounter;\r\n }\r\n\r\n this._material._callbackPluginEventGeneric = (id, info) => this._handlePluginEvent(id, info);\r\n\r\n this._plugins.push(plugin);\r\n this._plugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._codeInjectionPoints = {};\r\n\r\n const defineNamesFromPlugins: { [name: string]: { type: string; default: any } } = {};\r\n defineNamesFromPlugins[MaterialPluginManager._MaterialPluginClassToMainDefine[pluginClassName]] = {\r\n type: \"boolean\",\r\n default: true,\r\n };\r\n\r\n for (const plugin of this._plugins) {\r\n plugin.collectDefines(defineNamesFromPlugins);\r\n this._collectPointNames(\"vertex\", plugin.getCustomCode(\"vertex\"));\r\n this._collectPointNames(\"fragment\", plugin.getCustomCode(\"fragment\"));\r\n }\r\n\r\n this._defineNamesFromPlugins = defineNamesFromPlugins;\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _activatePlugin(plugin: MaterialPluginBase): void {\r\n if (this._activePlugins.indexOf(plugin) === -1) {\r\n this._activePlugins.push(plugin);\r\n this._activePlugins.sort((a, b) => a.priority - b.priority);\r\n\r\n this._material._callbackPluginEventIsReadyForSubMesh = this._handlePluginEventIsReadyForSubMesh.bind(this);\r\n this._material._callbackPluginEventPrepareDefinesBeforeAttributes = this._handlePluginEventPrepareDefinesBeforeAttributes.bind(this);\r\n this._material._callbackPluginEventPrepareDefines = this._handlePluginEventPrepareDefines.bind(this);\r\n this._material._callbackPluginEventBindForSubMesh = this._handlePluginEventBindForSubMesh.bind(this);\r\n\r\n if (plugin.registerForExtraEvents) {\r\n this._activePluginsForExtraEvents.push(plugin);\r\n this._activePluginsForExtraEvents.sort((a, b) => a.priority - b.priority);\r\n this._material._callbackPluginEventHasRenderTargetTextures = this._handlePluginEventHasRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventFillRenderTargetTextures = this._handlePluginEventFillRenderTargetTextures.bind(this);\r\n this._material._callbackPluginEventHardBindForSubMesh = this._handlePluginEventHardBindForSubMesh.bind(this);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a plugin from the list of plugins managed by this manager\r\n * @param name name of the plugin\r\n * @returns the plugin if found, else null\r\n */\r\n public getPlugin<T = MaterialPluginBase>(name: string): Nullable<T> {\r\n for (let i = 0; i < this._plugins.length; ++i) {\r\n if (this._plugins[i].name === name) {\r\n return this._plugins[i] as T;\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n protected _handlePluginEventIsReadyForSubMesh(eventData: MaterialPluginIsReadyForSubMesh): void {\r\n let isReady = true;\r\n for (const plugin of this._activePlugins) {\r\n isReady = isReady && plugin.isReadyForSubMesh(eventData.defines, this._scene, this._engine, eventData.subMesh);\r\n }\r\n eventData.isReadyForSubMesh = isReady;\r\n }\r\n\r\n protected _handlePluginEventPrepareDefinesBeforeAttributes(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefinesBeforeAttributes(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventPrepareDefines(eventData: MaterialPluginPrepareDefines): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.prepareDefines(eventData.defines, this._scene, eventData.mesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHardBindForSubMesh(eventData: MaterialPluginHardBindForSubMesh): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.hardBindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventBindForSubMesh(eventData: MaterialPluginBindForSubMesh): void {\r\n for (const plugin of this._activePlugins) {\r\n plugin.bindForSubMesh(this._material._uniformBuffer, this._scene, this._engine, eventData.subMesh);\r\n }\r\n }\r\n\r\n protected _handlePluginEventHasRenderTargetTextures(eventData: MaterialPluginHasRenderTargetTextures): void {\r\n let hasRenderTargetTextures = false;\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n hasRenderTargetTextures = plugin.hasRenderTargetTextures();\r\n if (hasRenderTargetTextures) {\r\n break;\r\n }\r\n }\r\n eventData.hasRenderTargetTextures = hasRenderTargetTextures;\r\n }\r\n\r\n protected _handlePluginEventFillRenderTargetTextures(eventData: MaterialPluginFillRenderTargetTextures): void {\r\n for (const plugin of this._activePluginsForExtraEvents) {\r\n plugin.fillRenderTargetTextures(eventData.renderTargets);\r\n }\r\n }\r\n\r\n protected _handlePluginEvent(\r\n id: number,\r\n info:\r\n | MaterialPluginGetActiveTextures\r\n | MaterialPluginGetAnimatables\r\n | MaterialPluginHasTexture\r\n | MaterialPluginDisposed\r\n | MaterialPluginGetDefineNames\r\n | MaterialPluginPrepareEffect\r\n | MaterialPluginPrepareUniformBuffer\r\n ): void {\r\n switch (id) {\r\n case MaterialPluginEvent.GetActiveTextures: {\r\n const eventData = info as MaterialPluginGetActiveTextures;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getActiveTextures(eventData.activeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetAnimatables: {\r\n const eventData = info as MaterialPluginGetAnimatables;\r\n for (const plugin of this._activePlugins) {\r\n plugin.getAnimatables(eventData.animatables);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.HasTexture: {\r\n const eventData = info as MaterialPluginHasTexture;\r\n let hasTexture = false;\r\n for (const plugin of this._activePlugins) {\r\n hasTexture = plugin.hasTexture(eventData.texture);\r\n if (hasTexture) {\r\n break;\r\n }\r\n }\r\n eventData.hasTexture = hasTexture;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.Disposed: {\r\n const eventData = info as MaterialPluginDisposed;\r\n for (const plugin of this._plugins) {\r\n plugin.dispose(eventData.forceDisposeTextures);\r\n }\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.GetDefineNames: {\r\n const eventData = info as MaterialPluginGetDefineNames;\r\n eventData.defineNames = this._defineNamesFromPlugins;\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareEffect: {\r\n const eventData = info as MaterialPluginPrepareEffect;\r\n for (const plugin of this._activePlugins) {\r\n eventData.fallbackRank = plugin.addFallbacks(eventData.defines, eventData.fallbacks, eventData.fallbackRank);\r\n plugin.getAttributes(eventData.attributes, this._scene, eventData.mesh);\r\n }\r\n if (this._uniformList.length > 0) {\r\n eventData.uniforms.push(...this._uniformList);\r\n }\r\n if (this._samplerList.length > 0) {\r\n eventData.samplers.push(...this._samplerList);\r\n }\r\n if (this._uboList.length > 0) {\r\n eventData.uniformBuffersNames.push(...this._uboList);\r\n }\r\n eventData.customCode = this._injectCustomCode(eventData, eventData.customCode);\r\n break;\r\n }\r\n\r\n case MaterialPluginEvent.PrepareUniformBuffer: {\r\n const eventData = info as MaterialPluginPrepareUniformBuffer;\r\n this._uboDeclaration = \"\";\r\n this._vertexDeclaration = \"\";\r\n this._fragmentDeclaration = \"\";\r\n this._uniformList = [];\r\n this._samplerList = [];\r\n this._uboList = [];\r\n for (const plugin of this._plugins) {\r\n const uniforms = plugin.getUniforms();\r\n if (uniforms) {\r\n if (uniforms.ubo) {\r\n for (const uniform of uniforms.ubo) {\r\n if (uniform.size && uniform.type) {\r\n const arraySize = uniform.arraySize ?? 0;\r\n eventData.ubo.addUniform(uniform.name, uniform.size, arraySize);\r\n this._uboDeclaration += `${uniform.type} ${uniform.name}${arraySize > 0 ? `[${arraySize}]` : \"\"};\\n`;\r\n }\r\n this._uniformList.push(uniform.name);\r\n }\r\n }\r\n if (uniforms.vertex) {\r\n this._vertexDeclaration += uniforms.vertex + \"\\n\";\r\n }\r\n if (uniforms.fragment) {\r\n this._fragmentDeclaration += uniforms.fragment + \"\\n\";\r\n }\r\n }\r\n plugin.getSamplers(this._samplerList);\r\n plugin.getUniformBuffersNames(this._uboList);\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n protected _collectPointNames(shaderType: string, customCode: Nullable<{ [pointName: string]: string }> | undefined): void {\r\n if (!customCode) {\r\n return;\r\n }\r\n for (const pointName in customCode) {\r\n if (!this._codeInjectionPoints[shaderType]) {\r\n this._codeInjectionPoints[shaderType] = {};\r\n }\r\n this._codeInjectionPoints[shaderType][pointName] = true;\r\n }\r\n }\r\n\r\n protected _injectCustomCode(eventData: MaterialPluginPrepareEffect, existingCallback?: (shaderType: string, code: string) => string): ShaderCustomProcessingFunction {\r\n return (shaderType: string, code: string) => {\r\n if (existingCallback) {\r\n code = existingCallback(shaderType, code);\r\n }\r\n if (this._uboDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_UBO_DECLARATION\", this._uboDeclaration);\r\n }\r\n if (this._vertexDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_VERTEX_DECLARATION\", this._vertexDeclaration);\r\n }\r\n if (this._fragmentDeclaration) {\r\n code = code.replace(\"#define ADDITIONAL_FRAGMENT_DECLARATION\", this._fragmentDeclaration);\r\n }\r\n const points = this._codeInjectionPoints?.[shaderType];\r\n if (!points) {\r\n return code;\r\n }\r\n let processorOptions: Nullable<ProcessingOptions> = null;\r\n for (let pointName in points) {\r\n let injectedCode = \"\";\r\n for (const plugin of this._activePlugins) {\r\n let customCode = plugin.getCustomCode(shaderType)?.[pointName];\r\n if (!customCode) {\r\n continue;\r\n }\r\n if (plugin.resolveIncludes) {\r\n if (processorOptions === null) {\r\n const shaderLanguage = ShaderLanguage.GLSL;\r\n processorOptions = {\r\n defines: [], // not used by _ProcessIncludes\r\n indexParameters: eventData.indexParameters,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: this._engine._shouldUseHighPrecisionShader,\r\n processor: undefined as any, // not used by _ProcessIncludes\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: ShaderStore.GetShadersRepository(shaderLanguage),\r\n includesShadersStore: ShaderStore.GetIncludesShadersStore(shaderLanguage),\r\n version: undefined as any, // not used by _ProcessIncludes\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: undefined as any, // not used by _ProcessIncludes\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n processCodeAfterIncludes: undefined as any, // not used by _ProcessIncludes\r\n };\r\n }\r\n processorOptions.isFragment = shaderType === \"fragment\";\r\n _ProcessIncludes(customCode, processorOptions, (code) => (customCode = code));\r\n }\r\n injectedCode += customCode + \"\\n\";\r\n }\r\n if (injectedCode.length > 0) {\r\n if (pointName.charAt(0) === \"!\") {\r\n // pointName is a regular expression\r\n pointName = pointName.substring(1);\r\n\r\n let regexFlags = \"g\";\r\n if (pointName.charAt(0) === \"!\") {\r\n // no flags\r\n regexFlags = \"\";\r\n pointName = pointName.substring(1);\r\n } else {\r\n // get the flag(s)\r\n const matchOption = rxOption.exec(pointName);\r\n if (matchOption && matchOption.length >= 2) {\r\n regexFlags = matchOption[1];\r\n pointName = pointName.substring(regexFlags.length + 1);\r\n }\r\n }\r\n\r\n if (regexFlags.indexOf(\"g\") < 0) {\r\n // we force the \"g\" flag so that the regexp object is stateful!\r\n regexFlags += \"g\";\r\n }\r\n\r\n const sourceCode = code;\r\n const rx = new RegExp(pointName, regexFlags);\r\n let match = rx.exec(sourceCode);\r\n while (match !== null) {\r\n let newCode = injectedCode;\r\n for (let i = 0; i < match.length; ++i) {\r\n newCode = newCode.replace(\"$\" + i, match[i]);\r\n }\r\n code = code.replace(match[0], newCode);\r\n match = rx.exec(sourceCode);\r\n }\r\n } else {\r\n const fullPointName = \"#define \" + pointName;\r\n code = code.replace(fullPointName, \"\\n\" + injectedCode + \"\\n\" + fullPointName);\r\n }\r\n }\r\n }\r\n return code;\r\n };\r\n }\r\n}\r\n\r\n/**\r\n * Type for plugin material factories.\r\n */\r\nexport type PluginMaterialFactory = (material: Material) => Nullable<MaterialPluginBase>;\r\n\r\nconst plugins: Array<[string, PluginMaterialFactory]> = [];\r\nlet inited = false;\r\nlet observer: Nullable<Observer<Material>> = null;\r\n\r\n/**\r\n * Registers a new material plugin through a factory, or updates it. This makes the plugin available to all materials instantiated after its registration.\r\n * @param pluginName The plugin name\r\n * @param factory The factory function which allows to create the plugin\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function RegisterMaterialPlugin(pluginName: string, factory: PluginMaterialFactory): void {\r\n if (!inited) {\r\n observer = Material.OnEventObservable.add((material: Material) => {\r\n for (const [, factory] of plugins) {\r\n factory(material);\r\n }\r\n }, MaterialPluginEvent.Created);\r\n inited = true;\r\n }\r\n const existing = plugins.filter(([name, _factory]) => name === pluginName);\r\n if (existing.length > 0) {\r\n existing[0][1] = factory;\r\n } else {\r\n plugins.push([pluginName, factory]);\r\n }\r\n}\r\n\r\n/**\r\n * Removes a material plugin from the list of global plugins.\r\n * @param pluginName The plugin name\r\n * @returns true if the plugin has been removed, else false\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterMaterialPlugin(pluginName: string): boolean {\r\n for (let i = 0; i < plugins.length; ++i) {\r\n if (plugins[i][0] === pluginName) {\r\n plugins.splice(i, 1);\r\n if (plugins.length === 0) {\r\n UnregisterAllMaterialPlugins();\r\n }\r\n return true;\r\n }\r\n }\r\n return false;\r\n}\r\n\r\n/**\r\n * Clear the list of global material plugins\r\n */\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\nexport function UnregisterAllMaterialPlugins(): void {\r\n plugins.length = 0;\r\n inited = false;\r\n Material.OnEventObservable.remove(observer);\r\n observer = null;\r\n}\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompression.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M,IAAI,CAAC,yBAAyB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;QACxE,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC;QACpC,IAAI,QAAQ,CAAC,OAAO,EAAE;YAClB,UAAU,CAAC,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;SACzC;QACD,KAAK,MAAM,SAAS,IAAI,QAAQ,CAAC,UAAU,EAAE;YACzC,MAAM,SAAS,GAAG,YAAY,CAAC,YAAY,CACvC,SAAS,CAAC,IAAI,EACd,SAAS,CAAC,IAAI,EACd,YAAY,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,EACxC,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,aAAa,CACzB,CAAC;YAEF,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AAvVD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer, jsModule?: DracoDecoderModule): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n (jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n /**\r\n * Optional worker pool to use for async decoding instead of creating a new worker pool.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The decoder module if already available.\r\n */\r\n jsModule?: any /* DecoderModule */;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (decoder.workerPool || (typeof numWorkers === \"object\" && numWorkers.workerPool)) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(decoder.workerPool || (numWorkers as IDracoCompressionOptions).workerPool!);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === \"object\" && numWorkers.wasmBinary);\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);\r\n // code maintained here for back-compat with no changes\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n if (useWorkers) {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary!, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (typeof DracoDecoderModule === \"undefined\") {\r\n if (!decoder.jsModule) {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n }\r\n }\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer, decoder.jsModule);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompression.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompression.ts"],"names":[],"mappings":"AAAA,yDAAyD;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAoC,cAAc,EAAE,mBAAmB,EAAE,MAAM,0B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SAAS,CAAC,UAAU,EACpB,QAAQ,CAAC,aAAa,CACzB,CAAC;YAEF,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC;SAC7C;QACD,OAAO,UAAU,CAAC;IACtB,CAAC;;AAvVD;;;;;GAKG;AACW,8BAAa,GAAmC;IAC1D,OAAO,EAAE;QACL,OAAO,EAAE,GAAG,KAAK,CAAC,cAAc,6BAA6B;QAC7D,aAAa,EAAE,GAAG,KAAK,CAAC,cAAc,0BAA0B;QAChE,WAAW,EAAE,GAAG,KAAK,CAAC,cAAc,wBAAwB;KAC/D;CACJ,CAAC;AAUF;;GAEG;AACW,kCAAiB,GAAG,gBAAgB,CAAC,oBAAoB,EAAE,CAAC;AAW3D,yBAAQ,GAA+B,IAAI,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport { AutoReleaseWorkerPool } from \"../../Misc/workerPool\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { IDisposable, Scene } from \"../../scene\";\r\nimport { Geometry } from \"../geometry\";\r\nimport { VertexBuffer } from \"../buffer\";\r\nimport { VertexData } from \"../mesh.vertexData\";\r\nimport type { DecoderModule } from \"draco3dgltf\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { decodeMesh, type AttributeData, type Message, workerFunction, initializeWebWorker } from \"./dracoCompressionWorker\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\ninterface MeshData {\r\n indices?: Uint16Array | Uint32Array;\r\n attributes: Array<AttributeData>;\r\n totalVertices: number;\r\n}\r\n\r\nfunction createDecoderAsync(wasmBinary?: ArrayBuffer, jsModule?: DracoDecoderModule): Promise<{ module: DecoderModule }> {\r\n return new Promise((resolve) => {\r\n (jsModule || DracoDecoderModule)({ wasmBinary }).then((module) => {\r\n resolve({ module });\r\n });\r\n });\r\n}\r\n\r\n/**\r\n * Configuration for Draco compression\r\n */\r\nexport interface IDracoCompressionConfiguration {\r\n /**\r\n * Configuration for the decoder.\r\n */\r\n decoder: {\r\n /**\r\n * The url to the WebAssembly module.\r\n */\r\n wasmUrl?: string;\r\n\r\n /**\r\n * The url to the WebAssembly binary.\r\n */\r\n wasmBinaryUrl?: string;\r\n\r\n /**\r\n * The url to the fallback JavaScript module.\r\n */\r\n fallbackUrl?: string;\r\n /**\r\n * Optional worker pool to use for async decoding instead of creating a new worker pool.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n\r\n /**\r\n * The decoder module if already available.\r\n */\r\n jsModule?: any /* DecoderModule */;\r\n };\r\n}\r\n\r\n/**\r\n * Options for Draco compression\r\n */\r\nexport interface IDracoCompressionOptions {\r\n /**\r\n * The number of workers for async operations. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n numWorkers?: number;\r\n /**\r\n * Optional ArrayBuffer of the WebAssembly binary.\r\n * If provided it will be used instead of loading the binary from wasmBinaryUrl.\r\n */\r\n wasmBinary?: ArrayBuffer;\r\n /**\r\n * Optional worker pool to use for async decoding.\r\n * If provided, numWorkers will be ignored and the worker pool will be used instead.\r\n * If provided the draco script will not be loaded from the DracoConfiguration.\r\n */\r\n workerPool?: AutoReleaseWorkerPool;\r\n}\r\n\r\n/**\r\n * Draco compression (https://google.github.io/draco/)\r\n *\r\n * This class wraps the Draco module.\r\n *\r\n * **Encoder**\r\n *\r\n * The encoder is not currently implemented.\r\n *\r\n * **Decoder**\r\n *\r\n * By default, the configuration points to a copy of the Draco decoder files for glTF from the babylon.js preview cdn https://preview.babylonjs.com/draco_wasm_wrapper_gltf.js.\r\n *\r\n * To update the configuration, use the following code:\r\n * ```javascript\r\n * DracoCompression.Configuration = {\r\n * decoder: {\r\n * wasmUrl: \"<url to the WebAssembly library>\",\r\n * wasmBinaryUrl: \"<url to the WebAssembly binary>\",\r\n * fallbackUrl: \"<url to the fallback JavaScript library>\",\r\n * }\r\n * };\r\n * ```\r\n *\r\n * Draco has two versions, one for WebAssembly and one for JavaScript. The decoder configuration can be set to only support WebAssembly or only support the JavaScript version.\r\n * Decoding will automatically fallback to the JavaScript version if WebAssembly version is not configured or if WebAssembly is not supported by the browser.\r\n * Use `DracoCompression.DecoderAvailable` to determine if the decoder configuration is available for the current context.\r\n *\r\n * To decode Draco compressed data, get the default DracoCompression object and call decodeMeshToGeometryAsync:\r\n * ```javascript\r\n * var geometry = await DracoCompression.Default.decodeMeshToGeometryAsync(data);\r\n * ```\r\n *\r\n * @see https://playground.babylonjs.com/#DMZIBD#0\r\n */\r\nexport class DracoCompression implements IDisposable {\r\n private _workerPoolPromise?: Promise<AutoReleaseWorkerPool>;\r\n private _decoderModulePromise?: Promise<{ module: DecoderModule }>;\r\n\r\n /**\r\n * The configuration. Defaults to the following urls:\r\n * - wasmUrl: \"https://cdn.babylonjs.com/draco_wasm_wrapper_gltf.js\"\r\n * - wasmBinaryUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.wasm\"\r\n * - fallbackUrl: \"https://cdn.babylonjs.com/draco_decoder_gltf.js\"\r\n */\r\n public static Configuration: IDracoCompressionConfiguration = {\r\n decoder: {\r\n wasmUrl: `${Tools._DefaultCdnUrl}/draco_wasm_wrapper_gltf.js`,\r\n wasmBinaryUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.wasm`,\r\n fallbackUrl: `${Tools._DefaultCdnUrl}/draco_decoder_gltf.js`,\r\n },\r\n };\r\n\r\n /**\r\n * Returns true if the decoder configuration is available.\r\n */\r\n public static get DecoderAvailable(): boolean {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n return !!((decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\") || decoder.fallbackUrl);\r\n }\r\n\r\n /**\r\n * Default number of workers to create when creating the draco compression object.\r\n */\r\n public static DefaultNumWorkers = DracoCompression.GetDefaultNumWorkers();\r\n\r\n private static GetDefaultNumWorkers(): number {\r\n if (typeof navigator !== \"object\" || !navigator.hardwareConcurrency) {\r\n return 1;\r\n }\r\n\r\n // Use 50% of the available logical processors but capped at 4.\r\n return Math.min(Math.floor(navigator.hardwareConcurrency * 0.5), 4);\r\n }\r\n\r\n private static _Default: Nullable<DracoCompression> = null;\r\n\r\n /**\r\n * Default instance for the draco compression object.\r\n */\r\n public static get Default(): DracoCompression {\r\n if (!DracoCompression._Default) {\r\n DracoCompression._Default = new DracoCompression();\r\n }\r\n\r\n return DracoCompression._Default;\r\n }\r\n\r\n /**\r\n * Constructor\r\n * @param numWorkers The number of workers for async operations Or an options object. Specify `0` to disable web workers and run synchronously in the current context.\r\n */\r\n constructor(numWorkers: number | IDracoCompressionOptions = DracoCompression.DefaultNumWorkers) {\r\n const decoder = DracoCompression.Configuration.decoder;\r\n // check if the decoder binary and worker pool was injected\r\n // Note - it is expected that the developer checked if WebWorker, WebAssembly and the URL object are available\r\n if (decoder.workerPool || (typeof numWorkers === \"object\" && numWorkers.workerPool)) {\r\n // set the promise accordingly\r\n this._workerPoolPromise = Promise.resolve(decoder.workerPool || (numWorkers as IDracoCompressionOptions).workerPool!);\r\n } else {\r\n // to avoid making big changes to the decider, if wasmBinary is provided use it in the wasmBinaryPromise\r\n const wasmBinaryProvided = decoder.wasmBinary || (typeof numWorkers === \"object\" && numWorkers.wasmBinary);\r\n const numberOfWorkers = typeof numWorkers === \"number\" ? numWorkers : numWorkers.numWorkers;\r\n const useWorkers = numberOfWorkers && typeof Worker === \"function\" && typeof URL === \"function\";\r\n const urlNeeded = useWorkers || (!useWorkers && !decoder.jsModule);\r\n // code maintained here for back-compat with no changes\r\n\r\n const decoderInfo: { url: string | undefined; wasmBinaryPromise: Promise<ArrayBuffer | undefined> } =\r\n decoder.wasmUrl && decoder.wasmBinaryUrl && typeof WebAssembly === \"object\"\r\n ? {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.wasmUrl, true) : \"\",\r\n wasmBinaryPromise: wasmBinaryProvided ? Promise.resolve(wasmBinaryProvided) : Tools.LoadFileAsync(Tools.GetBabylonScriptURL(decoder.wasmBinaryUrl, true)),\r\n }\r\n : {\r\n url: urlNeeded ? Tools.GetBabylonScriptURL(decoder.fallbackUrl!) : \"\",\r\n wasmBinaryPromise: Promise.resolve(undefined),\r\n };\r\n if (useWorkers) {\r\n this._workerPoolPromise = decoderInfo.wasmBinaryPromise.then((decoderWasmBinary) => {\r\n const workerContent = `${decodeMesh}(${workerFunction})()`;\r\n const workerBlobUrl = URL.createObjectURL(new Blob([workerContent], { type: \"application/javascript\" }));\r\n\r\n return new AutoReleaseWorkerPool(numberOfWorkers as number, () => {\r\n const worker = new Worker(workerBlobUrl);\r\n return initializeWebWorker(worker, decoderWasmBinary, decoderInfo.url);\r\n });\r\n });\r\n } else {\r\n this._decoderModulePromise = decoderInfo.wasmBinaryPromise.then(async (decoderWasmBinary) => {\r\n if (typeof DracoDecoderModule === \"undefined\") {\r\n if (!decoder.jsModule) {\r\n if (!decoderInfo.url) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n await Tools.LoadBabylonScriptAsync(decoderInfo.url);\r\n }\r\n }\r\n return await createDecoderAsync(decoderWasmBinary as ArrayBuffer, decoder.jsModule);\r\n });\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Stop all async operations and release resources.\r\n */\r\n public dispose(): void {\r\n if (this._workerPoolPromise) {\r\n this._workerPoolPromise.then((workerPool) => {\r\n workerPool.dispose();\r\n });\r\n }\r\n\r\n delete this._workerPoolPromise;\r\n delete this._decoderModulePromise;\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves when ready. Call this manually to ensure draco compression is ready before use.\r\n * @returns a promise that resolves when ready\r\n */\r\n public async whenReadyAsync(): Promise<void> {\r\n if (this._workerPoolPromise) {\r\n await this._workerPoolPromise;\r\n return;\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n await this._decoderModulePromise;\r\n return;\r\n }\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to mesh data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @param gltfNormalizedOverride A map of attributes from vertex buffer kinds to normalized flags to override the Draco normalization\r\n * @returns A promise that resolves with the decoded mesh data\r\n */\r\n public decodeMeshToMeshDataAsync(\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes?: { [kind: string]: number },\r\n gltfNormalizedOverride?: { [kind: string]: boolean }\r\n ): Promise<MeshData> {\r\n const dataView = data instanceof ArrayBuffer ? new Int8Array(data) : new Int8Array(data.buffer, data.byteOffset, data.byteLength);\r\n\r\n const applyGltfNormalizedOverride = (kind: string, normalized: boolean): boolean => {\r\n if (gltfNormalizedOverride && gltfNormalizedOverride[kind] !== undefined) {\r\n if (normalized !== gltfNormalizedOverride[kind]) {\r\n Logger.Warn(\r\n `Normalized flag from Draco data (${normalized}) does not match normalized flag from glTF accessor (${gltfNormalizedOverride[kind]}). Using flag from glTF accessor.`\r\n );\r\n }\r\n\r\n return gltfNormalizedOverride[kind];\r\n } else {\r\n return normalized;\r\n }\r\n };\r\n\r\n if (this._workerPoolPromise) {\r\n return this._workerPoolPromise.then((workerPool) => {\r\n return new Promise<MeshData>((resolve, reject) => {\r\n workerPool.push((worker, onComplete) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n onComplete();\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"decodeMeshDone\": {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve({ indices: resultIndices!, attributes: resultAttributes, totalVertices: message.totalVertices });\r\n onComplete();\r\n break;\r\n }\r\n case \"indices\": {\r\n resultIndices = message.data;\r\n break;\r\n }\r\n case \"attribute\": {\r\n resultAttributes.push({\r\n kind: message.kind,\r\n data: message.data,\r\n size: message.size,\r\n byteOffset: message.byteOffset,\r\n byteStride: message.byteStride,\r\n normalized: applyGltfNormalizedOverride(message.kind, message.normalized),\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n const dataViewCopy = dataView.slice();\r\n worker.postMessage({ id: \"decodeMesh\", dataView: dataViewCopy, attributes: attributes }, [dataViewCopy.buffer]);\r\n });\r\n });\r\n });\r\n }\r\n\r\n if (this._decoderModulePromise) {\r\n return this._decoderModulePromise.then((decoder) => {\r\n let resultIndices: Nullable<Uint16Array | Uint32Array> = null;\r\n const resultAttributes: Array<AttributeData> = [];\r\n\r\n const numPoints = decodeMesh(\r\n decoder.module,\r\n dataView,\r\n attributes,\r\n (indices) => {\r\n resultIndices = indices;\r\n },\r\n (kind, data, size, byteOffset, byteStride, normalized) => {\r\n resultAttributes.push({\r\n kind,\r\n data,\r\n size,\r\n byteOffset,\r\n byteStride,\r\n normalized,\r\n });\r\n }\r\n );\r\n\r\n return { indices: resultIndices!, attributes: resultAttributes, totalVertices: numPoints };\r\n });\r\n }\r\n\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon geometry.\r\n * @param name The name to use when creating the geometry\r\n * @param scene The scene to use when creating the geometry\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded geometry\r\n */\r\n public async decodeMeshToGeometryAsync(name: string, scene: Scene, data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /** @internal */\r\n public async _decodeMeshToGeometryForGltfAsync(\r\n name: string,\r\n scene: Scene,\r\n data: ArrayBuffer | ArrayBufferView,\r\n attributes: { [kind: string]: number },\r\n gltfNormalizedOverride: { [kind: string]: boolean }\r\n ): Promise<Geometry> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes, gltfNormalizedOverride);\r\n const geometry = new Geometry(name, scene);\r\n if (meshData.indices) {\r\n geometry.setIndices(meshData.indices);\r\n }\r\n for (const attribute of meshData.attributes) {\r\n geometry.setVerticesBuffer(\r\n new VertexBuffer(\r\n scene.getEngine(),\r\n attribute.data,\r\n attribute.kind,\r\n false,\r\n undefined,\r\n attribute.byteStride,\r\n undefined,\r\n attribute.byteOffset,\r\n attribute.size,\r\n undefined,\r\n attribute.normalized,\r\n true\r\n ),\r\n meshData.totalVertices\r\n );\r\n }\r\n return geometry;\r\n }\r\n\r\n /**\r\n * Decode Draco compressed mesh data to Babylon vertex data.\r\n * @param data The ArrayBuffer or ArrayBufferView for the Draco compression data\r\n * @param attributes A map of attributes from vertex buffer kinds to Draco unique ids\r\n * @returns A promise that resolves with the decoded vertex data\r\n * @deprecated Use {@link decodeMeshToGeometryAsync} for better performance in some cases\r\n */\r\n public async decodeMeshAsync(data: ArrayBuffer | ArrayBufferView, attributes?: { [kind: string]: number }): Promise<VertexData> {\r\n const meshData = await this.decodeMeshToMeshDataAsync(data, attributes);\r\n const vertexData = new VertexData();\r\n if (meshData.indices) {\r\n vertexData.indices = meshData.indices;\r\n }\r\n for (const attribute of meshData.attributes) {\r\n const floatData = VertexBuffer.GetFloatData(\r\n attribute.data,\r\n attribute.size,\r\n VertexBuffer.GetDataType(attribute.data),\r\n attribute.byteOffset,\r\n attribute.byteStride,\r\n attribute.normalized,\r\n meshData.totalVertices\r\n );\r\n\r\n vertexData.set(floatData, attribute.kind);\r\n }\r\n return vertexData;\r\n }\r\n}\r\n"]}
@@ -39,5 +39,5 @@ export declare function workerFunction(): void;
39
39
  * @param moduleUrl The url to the draco decoder module (optional)
40
40
  * @returns A promise that resolves when the worker is initialized
41
41
  */
42
- export declare function initializeWebWorker(worker: Worker, decoderWasmBinary: ArrayBuffer, moduleUrl?: string): Promise<Worker>;
42
+ export declare function initializeWebWorker(worker: Worker, decoderWasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker>;
43
43
  export {};
@@ -130,7 +130,8 @@ export function workerFunction() {
130
130
  if (decoder.url) {
131
131
  importScripts(decoder.url);
132
132
  }
133
- decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });
133
+ const initDecoderObject = decoder.wasmBinary ? { wasmBinary: decoder.wasmBinary } : {};
134
+ decoderPromise = DracoDecoderModule(initDecoderObject);
134
135
  postMessage({ id: "initDone" });
135
136
  break;
136
137
  }
@@ -174,15 +175,25 @@ export function initializeWebWorker(worker, decoderWasmBinary, moduleUrl) {
174
175
  };
175
176
  worker.addEventListener("error", onError);
176
177
  worker.addEventListener("message", onMessage);
177
- // clone the array buffer to make it transferable
178
- const clone = decoderWasmBinary.slice(0);
179
- worker.postMessage({
180
- id: "init",
181
- decoder: {
182
- url: moduleUrl,
183
- wasmBinary: clone,
184
- },
185
- }, [clone]);
178
+ if (!decoderWasmBinary) {
179
+ worker.postMessage({
180
+ id: "init",
181
+ decoder: {
182
+ url: moduleUrl,
183
+ },
184
+ });
185
+ }
186
+ else {
187
+ // clone the array buffer to make it transferable
188
+ const clone = decoderWasmBinary.slice(0);
189
+ worker.postMessage({
190
+ id: "init",
191
+ decoder: {
192
+ url: moduleUrl,
193
+ wasmBinary: clone,
194
+ },
195
+ }, [clone]);
196
+ }
186
197
  // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers
187
198
  });
188
199
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,aAAkB,CAAC,iBAAiB,EACpC,IAAe,EACf,UAAkD,EAClD,aAA2D,EAC3D,eAAiI;IAEjI,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,MAAM,GAA4B,IAAI,CAAC;IAC3C,IAAI,QAAQ,GAAgC,IAAI,CAAC;IAEjD,IAAI;QACA,OAAO,GAAG,IAAI,aAAa,CAAC,OAAO,EAAa,CAAC;QAEjD,MAAM,GAAG,IAAI,aAAa,CAAC,aAAa,EAAmB,CAAC;QAC5D,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QAEnC,IAAI,MAAc,CAAC;QACnB,MAAM,IAAI,GAAG,OAAO,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC;QACpD,QAAQ,IAAI,EAAE;YACV,KAAK,aAAa,CAAC,eAAe,CAAC,CAAC;gBAChC,MAAM,IAAI,GAAG,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC;gBACtC,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;gBAClD,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,EAAE;oBAChC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;iBACvC;gBAED,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,CAA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K,CAAC,IAAI,CAAC,EAAE,KAAK,UAAU,EAAE;gBAC9B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC7C,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,CAAC,MAAM,CAAC,CAAC;aACnB;QACL,CAAC,CAAC;QAEF,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAE9C,iDAAiD;QACjD,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACzC,MAAM,CAAC,WAAW,CACd;YACI,EAAE,EAAE,MAAM;YACV,OAAO,EAAE;gBACL,GAAG,EAAE,SAAS;gBACd,UAAU,EAAE,KAAK;aACpB;SACJ,EACD,CAAC,KAAK,CAAC,CACV,CAAC;QACF,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\nexport interface AttributeData {\r\n kind: string;\r\n data: ArrayBufferView;\r\n size: number;\r\n byteOffset: number;\r\n byteStride: number;\r\n normalized: boolean;\r\n}\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\ninterface DecodeMeshDoneMessage {\r\n id: \"decodeMeshDone\";\r\n totalVertices: number;\r\n}\r\n\r\ninterface IndicesMessage {\r\n id: \"indices\";\r\n data: Uint16Array | Uint32Array;\r\n}\r\n\r\ninterface AttributeMessage extends AttributeData {\r\n id: \"attribute\";\r\n}\r\nexport type Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: Message, transfer?: any[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function decodeMesh(\r\n decoderModule: any /*DecoderModule*/,\r\n data: Int8Array,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder() as Decoder;\r\n\r\n buffer = new decoderModule.DecoderBuffer() as DecoderBuffer;\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh as Mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud as PointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributes) {\r\n for (const kind in attributes) {\r\n const id = attributes[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: { [kind: string]: number } = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function workerFunction(): void {\r\n let decoderPromise: PromiseLike<any> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n const decoder = message.decoder;\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n }\r\n decoderPromise = DracoDecoderModule({ wasmBinary: decoder.wasmBinary });\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = decodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param decoderWasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, decoderWasmBinary: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n // clone the array buffer to make it transferable\r\n const clone = decoderWasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n decoder: {\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n },\r\n [clone]\r\n );\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
1
+ {"version":3,"file":"dracoCompressionWorker.js","sourceRoot":"","sources":["../../../../../dev/core/src/Meshes/Compression/dracoCompressionWorker.ts"],"names":[],"mappings":"AAsCA;;GAEG;AACH,MAAM,UAAU,UAAU,CACtB,aAAkB,CAAC,iBAAiB,EACpC,IAAe,EACf,UAAkD,EAClD,aAA2D,EAC3D,eAAiI;IAEjI,IAAI,OAAO,GAAsB,IAAI,CAAC;IACtC,IAAI,MAAM,GAA4B,IAAI,CAAC;IAC3C,IAAI,QAAQ,GAAgC,IAAI,CAAC;IAEjD,IAAI;QACA,OAAO,GAAG,IAAI,aAAa,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;oBACL,GAAG,EAAE,SAAS;iBACjB;aACJ,CAAC,CAAC;SACN;aAAM;YACH,iDAAiD;YACjD,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;YACzC,MAAM,CAAC,WAAW,CACd;gBACI,EAAE,EAAE,MAAM;gBACV,OAAO,EAAE;oBACL,GAAG,EAAE,SAAS;oBACd,UAAU,EAAE,KAAK;iBACpB;aACJ,EACD,CAAC,KAAK,CAAC,CACV,CAAC;SACL;QACD,0FAA0F;IAC9F,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["import type { Nullable } from \"core/types\";\r\nimport type { DecoderBuffer, Decoder, Mesh, PointCloud, Status } from \"draco3dgltf\";\r\nimport { DracoDecoderModule } from \"draco3dgltf\";\r\n\r\n// eslint-disable-next-line @typescript-eslint/naming-convention\r\ndeclare let DracoDecoderModule: DracoDecoderModule;\r\n\r\nexport interface AttributeData {\r\n kind: string;\r\n data: ArrayBufferView;\r\n size: number;\r\n byteOffset: number;\r\n byteStride: number;\r\n normalized: boolean;\r\n}\r\n\r\ninterface InitDoneMessage {\r\n id: \"initDone\";\r\n}\r\n\r\ninterface DecodeMeshDoneMessage {\r\n id: \"decodeMeshDone\";\r\n totalVertices: number;\r\n}\r\n\r\ninterface IndicesMessage {\r\n id: \"indices\";\r\n data: Uint16Array | Uint32Array;\r\n}\r\n\r\ninterface AttributeMessage extends AttributeData {\r\n id: \"attribute\";\r\n}\r\nexport type Message = InitDoneMessage | DecodeMeshDoneMessage | IndicesMessage | AttributeMessage;\r\n// WorkerGlobalScope\r\ndeclare function importScripts(...urls: string[]): void;\r\ndeclare function postMessage(message: Message, transfer?: any[]): void;\r\n\r\n/**\r\n * @internal\r\n */\r\nexport function decodeMesh(\r\n decoderModule: any /*DecoderModule*/,\r\n data: Int8Array,\r\n attributes: { [kind: string]: number } | undefined,\r\n onIndicesData: (indices: Uint16Array | Uint32Array) => void,\r\n onAttributeData: (kind: string, data: ArrayBufferView, size: number, offset: number, stride: number, normalized: boolean) => void\r\n): number {\r\n let decoder: Nullable<Decoder> = null;\r\n let buffer: Nullable<DecoderBuffer> = null;\r\n let geometry: Nullable<Mesh | PointCloud> = null;\r\n\r\n try {\r\n decoder = new decoderModule.Decoder() as Decoder;\r\n\r\n buffer = new decoderModule.DecoderBuffer() as DecoderBuffer;\r\n buffer.Init(data, data.byteLength);\r\n\r\n let status: Status;\r\n const type = decoder.GetEncodedGeometryType(buffer);\r\n switch (type) {\r\n case decoderModule.TRIANGULAR_MESH: {\r\n const mesh = new decoderModule.Mesh();\r\n status = decoder.DecodeBufferToMesh(buffer, mesh);\r\n if (!status.ok() || mesh.ptr === 0) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n const numFaces = mesh.num_faces();\r\n const numIndices = numFaces * 3;\r\n const byteLength = numIndices * 4;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetTrianglesUInt32Array(mesh, byteLength, ptr);\r\n const indices = new Uint32Array(numIndices);\r\n indices.set(new Uint32Array(decoderModule.HEAPF32.buffer, ptr, numIndices));\r\n onIndicesData(indices);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n\r\n geometry = mesh as Mesh;\r\n break;\r\n }\r\n case decoderModule.POINT_CLOUD: {\r\n const pointCloud = new decoderModule.PointCloud();\r\n status = decoder.DecodeBufferToPointCloud(buffer, pointCloud);\r\n if (!status.ok() || !pointCloud.ptr) {\r\n throw new Error(status.error_msg());\r\n }\r\n\r\n geometry = pointCloud as PointCloud;\r\n break;\r\n }\r\n default: {\r\n throw new Error(`Invalid geometry type ${type}`);\r\n }\r\n }\r\n\r\n const numPoints = geometry.num_points();\r\n\r\n const processAttribute = (decoder: Decoder, geometry: Mesh | PointCloud, kind: string, attribute: any) => {\r\n const dataType = attribute.data_type();\r\n const numComponents = attribute.num_components();\r\n const normalized = attribute.normalized();\r\n const byteStride = attribute.byte_stride();\r\n const byteOffset = attribute.byte_offset();\r\n\r\n const dataTypeInfo = {\r\n [decoderModule.DT_FLOAT32]: { typedArrayConstructor: Float32Array, heap: decoderModule.HEAPF32 },\r\n [decoderModule.DT_INT8]: { typedArrayConstructor: Int8Array, heap: decoderModule.HEAP8 },\r\n [decoderModule.DT_INT16]: { typedArrayConstructor: Int16Array, heap: decoderModule.HEAP16 },\r\n [decoderModule.DT_INT32]: { typedArrayConstructor: Int32Array, heap: decoderModule.HEAP32 },\r\n [decoderModule.DT_UINT8]: { typedArrayConstructor: Uint8Array, heap: decoderModule.HEAPU8 },\r\n [decoderModule.DT_UINT16]: { typedArrayConstructor: Uint16Array, heap: decoderModule.HEAPU16 },\r\n [decoderModule.DT_UINT32]: { typedArrayConstructor: Uint32Array, heap: decoderModule.HEAPU32 },\r\n };\r\n\r\n const info = dataTypeInfo[dataType];\r\n if (!info) {\r\n throw new Error(`Invalid data type ${dataType}`);\r\n }\r\n\r\n const numValues = numPoints * numComponents;\r\n const byteLength = numValues * info.typedArrayConstructor.BYTES_PER_ELEMENT;\r\n\r\n const ptr = decoderModule._malloc(byteLength);\r\n try {\r\n decoder.GetAttributeDataArrayForAllPoints(geometry, attribute, dataType, byteLength, ptr);\r\n const data = new info.typedArrayConstructor(info.heap.buffer, ptr, numValues);\r\n onAttributeData(kind, data.slice(), numComponents, byteOffset, byteStride, normalized);\r\n } finally {\r\n decoderModule._free(ptr);\r\n }\r\n };\r\n\r\n if (attributes) {\r\n for (const kind in attributes) {\r\n const id = attributes[kind];\r\n const attribute = decoder.GetAttributeByUniqueId(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n } else {\r\n const dracoAttributeTypes: { [kind: string]: number } = {\r\n position: decoderModule.POSITION,\r\n normal: decoderModule.NORMAL,\r\n color: decoderModule.COLOR,\r\n uv: decoderModule.TEX_COORD,\r\n };\r\n\r\n for (const kind in dracoAttributeTypes) {\r\n const id = decoder.GetAttributeId(geometry, dracoAttributeTypes[kind]);\r\n if (id !== -1) {\r\n const attribute = decoder.GetAttribute(geometry, id);\r\n processAttribute(decoder, geometry, kind, attribute);\r\n }\r\n }\r\n }\r\n\r\n return numPoints;\r\n } finally {\r\n if (geometry) {\r\n decoderModule.destroy(geometry);\r\n }\r\n\r\n if (buffer) {\r\n decoderModule.destroy(buffer);\r\n }\r\n\r\n if (decoder) {\r\n decoderModule.destroy(decoder);\r\n }\r\n }\r\n}\r\n\r\n/**\r\n * The worker function that gets converted to a blob url to pass into a worker.\r\n * To be used if a developer wants to create their own worker instance and inject it instead of using the default worker.\r\n */\r\nexport function workerFunction(): void {\r\n let decoderPromise: PromiseLike<any> | undefined;\r\n\r\n onmessage = (event) => {\r\n const message = event.data;\r\n switch (message.id) {\r\n case \"init\": {\r\n const decoder = message.decoder;\r\n // if URL is provided then load the script. Otherwise expect the script to be loaded already\r\n if (decoder.url) {\r\n importScripts(decoder.url);\r\n }\r\n const initDecoderObject = decoder.wasmBinary ? { wasmBinary: decoder.wasmBinary } : {};\r\n decoderPromise = DracoDecoderModule(initDecoderObject);\r\n postMessage({ id: \"initDone\" });\r\n break;\r\n }\r\n case \"decodeMesh\": {\r\n if (!decoderPromise) {\r\n throw new Error(\"Draco decoder module is not available\");\r\n }\r\n decoderPromise.then((decoder) => {\r\n const numPoints = decodeMesh(\r\n decoder,\r\n message.dataView,\r\n message.attributes,\r\n (indices) => {\r\n postMessage({ id: \"indices\", data: indices }, [indices.buffer]);\r\n },\r\n (kind, data, size, offset, stride, normalized) => {\r\n postMessage({ id: \"attribute\", kind, data, size, byteOffset: offset, byteStride: stride, normalized }, [data.buffer]);\r\n }\r\n );\r\n postMessage({ id: \"decodeMeshDone\", totalVertices: numPoints });\r\n });\r\n break;\r\n }\r\n }\r\n };\r\n}\r\n\r\n/**\r\n * Initializes a worker that was created for the draco agent pool\r\n * @param worker The worker to initialize\r\n * @param decoderWasmBinary The wasm binary to load into the worker\r\n * @param moduleUrl The url to the draco decoder module (optional)\r\n * @returns A promise that resolves when the worker is initialized\r\n */\r\nexport function initializeWebWorker(worker: Worker, decoderWasmBinary?: ArrayBuffer, moduleUrl?: string): Promise<Worker> {\r\n return new Promise<Worker>((resolve, reject) => {\r\n const onError = (error: ErrorEvent) => {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n reject(error);\r\n };\r\n\r\n const onMessage = (event: MessageEvent<Message>) => {\r\n if (event.data.id === \"initDone\") {\r\n worker.removeEventListener(\"error\", onError);\r\n worker.removeEventListener(\"message\", onMessage);\r\n resolve(worker);\r\n }\r\n };\r\n\r\n worker.addEventListener(\"error\", onError);\r\n worker.addEventListener(\"message\", onMessage);\r\n\r\n if (!decoderWasmBinary) {\r\n worker.postMessage({\r\n id: \"init\",\r\n decoder: {\r\n url: moduleUrl,\r\n },\r\n });\r\n } else {\r\n // clone the array buffer to make it transferable\r\n const clone = decoderWasmBinary.slice(0);\r\n worker.postMessage(\r\n {\r\n id: \"init\",\r\n decoder: {\r\n url: moduleUrl,\r\n wasmBinary: clone,\r\n },\r\n },\r\n [clone]\r\n );\r\n }\r\n // note: no transfer list as the ArrayBuffer is shared across main thread and pool workers\r\n });\r\n}\r\n"]}
@@ -315,6 +315,7 @@ export class NodeGeometryBlock {
315
315
  serializationObject.customType = "BABYLON." + this.getClassName();
316
316
  serializationObject.id = this.uniqueId;
317
317
  serializationObject.name = this.name;
318
+ serializationObject.visibleOnFrame = this.visibleOnFrame;
318
319
  serializationObject.inputs = [];
319
320
  serializationObject.outputs = [];
320
321
  for (const input of this.inputs) {