@babylonjs/core 8.53.1 → 8.54.1

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 (74) hide show
  1. package/Engines/AbstractEngine/abstractEngine.renderPass.js +1 -0
  2. package/Engines/AbstractEngine/abstractEngine.renderPass.js.map +1 -1
  3. package/Engines/WebGPU/webgpuTextureManager.js +5 -4
  4. package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
  5. package/Engines/abstractEngine.js +2 -2
  6. package/Engines/abstractEngine.js.map +1 -1
  7. package/FrameGraph/Tasks/PostProcesses/ssao2RenderingPipelineTask.js +3 -0
  8. package/FrameGraph/Tasks/PostProcesses/ssao2RenderingPipelineTask.js.map +1 -1
  9. package/FrameGraph/Tasks/PostProcesses/ssrRenderingPipelineTask.js +3 -0
  10. package/FrameGraph/Tasks/PostProcesses/ssrRenderingPipelineTask.js.map +1 -1
  11. package/FrameGraph/Tasks/PostProcesses/volumetricLightingTask.d.ts +3 -1
  12. package/FrameGraph/Tasks/PostProcesses/volumetricLightingTask.js +14 -0
  13. package/FrameGraph/Tasks/PostProcesses/volumetricLightingTask.js.map +1 -1
  14. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.d.ts +2 -2
  15. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js +20 -14
  16. package/FrameGraph/Tasks/Rendering/csmShadowGeneratorTask.js.map +1 -1
  17. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.d.ts +3 -2
  18. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js +38 -14
  19. package/FrameGraph/Tasks/Rendering/shadowGeneratorTask.js.map +1 -1
  20. package/Lights/Shadows/cascadedShadowGenerator.js +0 -1
  21. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  22. package/Lights/Shadows/shadowGenerator.d.ts +28 -1
  23. package/Lights/Shadows/shadowGenerator.js +77 -11
  24. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  25. package/Lights/lightingVolume.d.ts +1 -0
  26. package/Lights/lightingVolume.js +9 -1
  27. package/Lights/lightingVolume.js.map +1 -1
  28. package/Loading/Plugins/babylonFileLoader.js +44 -14
  29. package/Loading/Plugins/babylonFileLoader.js.map +1 -1
  30. package/Loading/sceneLoader.js +1 -1
  31. package/Loading/sceneLoader.js.map +1 -1
  32. package/Materials/Textures/Procedurals/proceduralTexture.js +0 -1
  33. package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
  34. package/Maths/index.d.ts +2 -0
  35. package/Maths/index.js +2 -0
  36. package/Maths/index.js.map +1 -1
  37. package/Maths/math.geospatial.d.ts +12 -0
  38. package/Maths/math.geospatial.functions.d.ts +19 -0
  39. package/Maths/math.geospatial.functions.js +27 -0
  40. package/Maths/math.geospatial.functions.js.map +1 -0
  41. package/Maths/math.geospatial.js +2 -0
  42. package/Maths/math.geospatial.js.map +1 -0
  43. package/Meshes/abstractMesh.d.ts +4 -0
  44. package/Meshes/abstractMesh.js +4 -0
  45. package/Meshes/abstractMesh.js.map +1 -1
  46. package/Meshes/mesh.d.ts +2 -0
  47. package/Meshes/mesh.js +19 -2
  48. package/Meshes/mesh.js.map +1 -1
  49. package/Particles/particleSystem.js +4 -1
  50. package/Particles/particleSystem.js.map +1 -1
  51. package/Particles/pointsCloudSystem.js +1 -1
  52. package/Particles/pointsCloudSystem.js.map +1 -1
  53. package/Particles/solidParticleSystem.js +4 -4
  54. package/Particles/solidParticleSystem.js.map +1 -1
  55. package/Physics/v2/characterController.js +1 -1
  56. package/Physics/v2/characterController.js.map +1 -1
  57. package/Physics/v2/ragdoll.js +1 -2
  58. package/Physics/v2/ragdoll.js.map +1 -1
  59. package/PostProcesses/postProcess.js +1 -1
  60. package/PostProcesses/postProcess.js.map +1 -1
  61. package/Probes/reflectionProbe.js +0 -1
  62. package/Probes/reflectionProbe.js.map +1 -1
  63. package/Rendering/depthRenderer.js +0 -1
  64. package/Rendering/depthRenderer.js.map +1 -1
  65. package/Rendering/thinDepthPeelingRenderer.js +1 -1
  66. package/Rendering/thinDepthPeelingRenderer.js.map +1 -1
  67. package/Shaders/ShadersInclude/screenSpaceRayTrace.js +18 -8
  68. package/Shaders/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
  69. package/ShadersWGSL/ShadersInclude/screenSpaceRayTrace.js +18 -7
  70. package/ShadersWGSL/ShadersInclude/screenSpaceRayTrace.js.map +1 -1
  71. package/Sprites/spriteManager.js +2 -2
  72. package/Sprites/spriteManager.js.map +1 -1
  73. package/assetContainer.js.map +1 -1
  74. package/package.json +1 -1
@@ -26,6 +26,7 @@ export declare class LightingVolume {
26
26
  private _positions;
27
27
  private _indices;
28
28
  private _needFullUpdateUBO;
29
+ private _currentShadowDepthTexture;
29
30
  private _shadowGenerator?;
30
31
  /**
31
32
  * The shadow generator used to create the lighting volume.
@@ -169,9 +169,16 @@ export class LightingVolume {
169
169
  if (this._engine.isWebGPU) {
170
170
  this._uBuffer.updateMatrix("invViewProjMatrix", this._shadowGenerator.getTransformMatrix().invertToRef(TmpVectors.Matrix[0]));
171
171
  if (this._engine._enableGPUDebugMarkers) {
172
- this._engine.restoreDefaultFramebuffer(true);
173
172
  this._engine._debugPushGroup?.(`Update lighting volume (${this._name})`);
174
173
  }
174
+ const depthTexture = this._shadowGenerator.getShadowMap()?.depthStencilTexture;
175
+ if (depthTexture && depthTexture !== this._currentShadowDepthTexture) {
176
+ this._currentShadowDepthTexture = depthTexture;
177
+ this._cs.triggerContextRebuild = this._cs.fastMode;
178
+ this._cs2.triggerContextRebuild = this._cs2.fastMode;
179
+ this._cs.setInternalTexture("shadowMap", depthTexture);
180
+ this._cs2.setInternalTexture("shadowMap", depthTexture);
181
+ }
175
182
  if (this._needUpdateGeometry()) {
176
183
  this._fullUpdateUBO(true);
177
184
  const dispatchSize = Math.ceil((this._tesselation + 1) / 32);
@@ -249,6 +256,7 @@ export class LightingVolume {
249
256
  }
250
257
  if (this._shadowGenerator) {
251
258
  const depthTexture = this._shadowGenerator.getShadowMap()?.depthStencilTexture;
259
+ this._currentShadowDepthTexture = depthTexture || null;
252
260
  if (depthTexture) {
253
261
  this._cs?.setInternalTexture("shadowMap", depthTexture);
254
262
  this._cs2?.setInternalTexture("shadowMap", depthTexture);
@@ -1 +1 @@
1
- {"version":3,"file":"lightingVolume.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/lightingVolume.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,yBAAwB;AAC7C,OAAO,EAAE,SAAS,EAAE,gCAA+B;AACnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,gCAA+B;AACrE,OAAO,EAAE,gBAAgB,EAAE,8BAAqC;AAChE,OAAO,EAAE,IAAI,EAAE,0BAAyB;AACxC,OAAO,EAAE,aAAa,EAAE,oCAAmC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,wCAAuC;AACtE,OAAO,EAAE,aAAa,EAAE,sCAAqC;AAC7D,OAAO,EAAE,aAAa,EAAE,oCAAmC;AAC3D,OAAO,EAAE,WAAW,EAAE,6CAA4C;AAClE,OAAO,EAAE,YAAY,EAAE,6BAA4B;AAEnD,kDAAiD;AAEjD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;AAE9B;;GAEG;AACH,MAAM,OAAO,cAAc;IAwBvB;;OAEG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,gBAAiB,CAAC;IAClC,CAAC;IAED,IAAW,eAAe,CAAC,EAAmB;QAC1C,MAAM,KAAK,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QAE5B,IAAI,CAAC,CAAC,KAAK,YAAY,gBAAgB,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,CAAC,KAAK,qCAAqC,CAAC,CAAC;QAC3F,CAAC;QAED,IAAI,CAAC,gBAAgB,GAAG,EAAE,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC;QAEpB,I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index\";\r\nimport { AbortError } from \"core/Misc/error\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { Matrix, Vector3, TmpVectors } from \"core/Maths/math.vector\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport { ComputeShader } from \"core/Compute/computeShader\";\r\nimport { CopyTextureToTexture } from \"core/Misc/copyTextureToTexture\";\r\nimport { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { StorageBuffer } from \"core/Buffers/storageBuffer\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\n\r\nimport \"core/ShadersWGSL/lightingVolume.compute\";\r\n\r\nconst TmpVec3 = new Vector3();\r\n\r\n/**\r\n * Class used to create a lighting volume from a directional light's shadow generator.\r\n */\r\nexport class LightingVolume {\r\n private readonly _engine: AbstractEngine;\r\n private readonly _scene: Scene;\r\n private readonly _mesh: Mesh;\r\n private readonly _copyTexture?: CopyTextureToTexture;\r\n private readonly _uBuffer?: UniformBuffer;\r\n private readonly _buildFullVolume = true;\r\n private _name: string;\r\n private _cs?: ComputeShader;\r\n private _cs2?: ComputeShader;\r\n private _light?: DirectionalLight;\r\n private _fallbackTexture?: BaseTexture;\r\n private _storageBuffer?: StorageBuffer;\r\n private _depthCopy?: RenderTargetWrapper;\r\n private _readPixelPromise: Nullable<Promise<ArrayBufferView>> = null;\r\n private _readPixelAbortController: Nullable<AbortController> = null;\r\n private _numFrames = 0;\r\n private _firstUpdate = true;\r\n private _currentLightDirection = new Vector3();\r\n private _positions: Float32Array;\r\n private _indices: number[];\r\n private _needFullUpdateUBO = true;\r\n\r\n private _shadowGenerator?: ShadowGenerator;\r\n /**\r\n * The shadow generator used to create the lighting volume.\r\n */\r\n public get shadowGenerator() {\r\n return this._shadowGenerator!;\r\n }\r\n\r\n public set shadowGenerator(sg: ShadowGenerator) {\r\n const light = sg.getLight();\r\n\r\n if (!(light instanceof DirectionalLight)) {\r\n throw new Error(`LightingVolumeMesh ${this._name}: light must be a directional light`);\r\n }\r\n\r\n this._shadowGenerator = sg;\r\n this._light = light;\r\n\r\n this._updateGeometry();\r\n\r\n if (!this._engine.isWebGPU) {\r\n this._createFallbackTextures();\r\n }\r\n\r\n this._setComputeShaderInputs();\r\n }\r\n\r\n private _tesselation = 0;\r\n /**\r\n * The tesselation level of the lighting volume.\r\n */\r\n public get tesselation() {\r\n return this._tesselation;\r\n }\r\n\r\n public set tesselation(n: number) {\r\n this._tesselation = n;\r\n this._createGeometry();\r\n }\r\n\r\n /**\r\n * The mesh used as a support for the lighting volume.\r\n * Note that this mesh is not automatically added to the scene's mesh array.\r\n * If you want to render it, you need to add it manually.\r\n */\r\n public get mesh() {\r\n return this._mesh;\r\n }\r\n\r\n private _frequency = 1;\r\n\r\n /**\r\n * The frequency (in number of times you call updateMesh) at which the lighting volume is updated.\r\n */\r\n public get frequency() {\r\n return this._frequency;\r\n }\r\n\r\n public set frequency(value: number) {\r\n this._frequency = value;\r\n this._firstUpdate = true;\r\n }\r\n\r\n /**\r\n * The name of the lighting volume.\r\n */\r\n public get name() {\r\n return this._name;\r\n }\r\n\r\n public set name(name: string) {\r\n this._name = name;\r\n if (this._mesh) {\r\n this._mesh.name = name;\r\n }\r\n }\r\n\r\n /**\r\n * Indicates whether this is the first update of the lighting volume.\r\n * If true, the volume has not yet been updated for the first time.\r\n */\r\n public get firstUpdate() {\r\n return this._firstUpdate;\r\n }\r\n\r\n /** @internal */\r\n public _setComputeShaderFastMode(enabled: boolean) {\r\n if (this._cs) {\r\n this._cs.fastMode = enabled;\r\n this._cs.triggerContextRebuild = enabled;\r\n }\r\n if (this._cs2) {\r\n this._cs2.fastMode = enabled;\r\n this._cs2.triggerContextRebuild = enabled;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new LightingVolume.\r\n * @param name The name of the lighting volume.\r\n * @param scene The scene the lighting volume belongs to.\r\n * @param shadowGenerator The shadow generator used to create the lighting volume. This is optional in the constructor, but must be set before calling updateMesh.\r\n * @param tesselation The tesselation level of the lighting volume (default: 64).\r\n */\r\n constructor(name: string, scene: Scene, shadowGenerator?: ShadowGenerator, tesselation = 64) {\r\n const light = shadowGenerator ? shadowGenerator.getLight() : undefined;\r\n\r\n if (light && !(light instanceof DirectionalLight)) {\r\n throw new Error(`LightingVolumeMesh ${name}: light must be a directional light`);\r\n }\r\n\r\n this._name = name;\r\n this._shadowGenerator = shadowGenerator;\r\n this._light = light as DirectionalLight;\r\n this._indices = [];\r\n\r\n this._engine = scene.getEngine();\r\n this._scene = scene;\r\n\r\n this._mesh = new Mesh(name, this._scene);\r\n scene.meshes.splice(scene.meshes.indexOf(this._mesh), 1);\r\n\r\n if (this._engine.isWebGPU) {\r\n this._uBuffer = new UniformBuffer(this._engine);\r\n\r\n this._uBuffer.addUniform(\"invViewProjMatrix\", 16);\r\n this._uBuffer.addUniform(\"invViewMatrix\", 16);\r\n this._uBuffer.addUniform(\"startVertexIndex\", 1);\r\n this._uBuffer.addUniform(\"step\", 1);\r\n this._uBuffer.addUniform(\"tesselation\", 1);\r\n this._uBuffer.addUniform(\"orthoMin\", 3);\r\n this._uBuffer.addUniform(\"orthoMax\", 3);\r\n this._uBuffer.update();\r\n\r\n this._createComputeShader();\r\n } else {\r\n this._copyTexture = new CopyTextureToTexture(this._engine, false, true);\r\n this._createFallbackTextures();\r\n }\r\n\r\n this._tesselation = tesselation;\r\n this._createGeometry();\r\n }\r\n\r\n /**\r\n * Checks if the lighting volume is ready to be updated.\r\n * @returns True if the volume is ready to be updated.\r\n */\r\n public isReady() {\r\n let isReady = this._mesh.isReady(true);\r\n if (this._cs) {\r\n isReady = this._cs.isReady() && isReady;\r\n }\r\n if (this._cs2) {\r\n isReady = this._cs2.isReady() && isReady;\r\n }\r\n return isReady;\r\n }\r\n\r\n /**\r\n * Updates the lighting volume mesh.\r\n * @param forceUpdate If true, forces the update even if the frequency condition is not met.\r\n */\r\n public update(forceUpdate = false) {\r\n if (this._tesselation === 0 || !this._shadowGenerator) {\r\n return;\r\n }\r\n\r\n if (!forceUpdate && !this._firstUpdate && (this.frequency === 0 || ++this._numFrames < this.frequency)) {\r\n return;\r\n }\r\n\r\n this._numFrames = 0;\r\n\r\n if (this._engine.isWebGPU) {\r\n this._uBuffer!.updateMatrix(\"invViewProjMatrix\", this._shadowGenerator.getTransformMatrix().invertToRef(TmpVectors.Matrix[0]));\r\n\r\n if (this._engine._enableGPUDebugMarkers) {\r\n this._engine.restoreDefaultFramebuffer(true);\r\n this._engine._debugPushGroup?.(`Update lighting volume (${this._name})`);\r\n }\r\n\r\n if (this._needUpdateGeometry()) {\r\n this._fullUpdateUBO(true);\r\n\r\n const dispatchSize = Math.ceil((this._tesselation + 1) / 32);\r\n\r\n this._engine._debugPushGroup?.(`Update vertices of other planes`);\r\n this._cs2!.dispatch(dispatchSize, 1, 1);\r\n this._engine._debugPopGroup?.();\r\n } else {\r\n this._fullUpdateUBO();\r\n }\r\n\r\n const dispatchSize = Math.ceil((this._tesselation + 1) / 8);\r\n\r\n this._engine._debugPushGroup?.(`Update vertices of far plane`);\r\n this._cs!.dispatch(dispatchSize, dispatchSize, 1);\r\n this._engine._debugPopGroup?.();\r\n\r\n if (this._engine._enableGPUDebugMarkers) {\r\n this._engine._debugPopGroup?.();\r\n }\r\n\r\n this._firstUpdate = false;\r\n } else {\r\n try {\r\n void this._fallbackReadPixelAsync();\r\n } catch {\r\n this._readPixelPromise = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the lighting volume and associated resources.\r\n */\r\n public dispose() {\r\n this._readPixelAbortController?.abort(new AbortError(\"LightingVolume is disposed\"));\r\n this._readPixelAbortController = null;\r\n this._mesh.dispose();\r\n if (this._fallbackTexture) {\r\n this._fallbackTexture._texture = null;\r\n }\r\n this._fallbackTexture?.dispose();\r\n this._copyTexture?.dispose();\r\n this._storageBuffer?.dispose();\r\n this._uBuffer?.dispose();\r\n this._depthCopy?.dispose();\r\n }\r\n\r\n private _needUpdateGeometry() {\r\n if (this._cs?.triggerContextRebuild || (this._light && !this._currentLightDirection.equals(this._light.direction))) {\r\n this._currentLightDirection.copyFrom(this._light!.direction);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _createComputeShader() {\r\n this._cs = new ComputeShader(\"updateFarPlaneVertices\", this._engine, \"lightingVolume\", {\r\n bindingsMapping: {\r\n shadowMap: { group: 0, binding: 0 },\r\n params: { group: 0, binding: 1 },\r\n positions: { group: 0, binding: 2 },\r\n },\r\n defines: !this._buildFullVolume ? [\"#define KEEP_EDGES\", \"#define MOVE_FAR_DEPTH_TO_NEAR\"] : undefined,\r\n entryPoint: \"updateFarPlaneVertices\",\r\n });\r\n\r\n this._cs2 = new ComputeShader(\"updatePlaneVertices\", this._engine, \"lightingVolume\", {\r\n bindingsMapping: {\r\n shadowMap: { group: 0, binding: 0 },\r\n params: { group: 0, binding: 1 },\r\n positions: { group: 0, binding: 2 },\r\n },\r\n entryPoint: \"updatePlaneVertices\",\r\n });\r\n\r\n this._setComputeShaderInputs();\r\n }\r\n\r\n private _setComputeShaderInputs() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n if (this._shadowGenerator) {\r\n const depthTexture = this._shadowGenerator.getShadowMap()?.depthStencilTexture;\r\n if (depthTexture) {\r\n this._cs?.setInternalTexture(\"shadowMap\", depthTexture);\r\n this._cs2?.setInternalTexture(\"shadowMap\", depthTexture);\r\n }\r\n }\r\n\r\n if (this._uBuffer) {\r\n this._cs?.setUniformBuffer(\"params\", this._uBuffer);\r\n this._cs2?.setUniformBuffer(\"params\", this._uBuffer);\r\n }\r\n if (this._storageBuffer) {\r\n this._cs?.setStorageBuffer(\"positions\", this._storageBuffer);\r\n this._cs2?.setStorageBuffer(\"positions\", this._storageBuffer);\r\n }\r\n }\r\n\r\n private _createFallbackTextures() {\r\n if (!this._shadowGenerator) {\r\n return;\r\n }\r\n\r\n this._readPixelAbortController?.abort(new AbortError(\"Fallback textures are being (re)created\"));\r\n this._readPixelAbortController = new AbortController();\r\n\r\n const mapSize = this._shadowGenerator.mapSize;\r\n\r\n this._depthCopy?.dispose();\r\n this._depthCopy = this._engine.createRenderTargetTexture(\r\n { width: mapSize, height: mapSize },\r\n {\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RED,\r\n samples: 1,\r\n label: `${this._name} - fallback internal texture`,\r\n generateDepthBuffer: false,\r\n }\r\n );\r\n\r\n this._fallbackTexture?.dispose();\r\n this._fallbackTexture = new BaseTexture(this._scene, this._depthCopy.texture);\r\n this._fallbackTexture.name = `${this._name} - fallback texture`;\r\n }\r\n\r\n private async _fallbackReadPixelAsync() {\r\n if (this._readPixelPromise || !this._fallbackTexture || !this._copyTexture) {\r\n return;\r\n }\r\n\r\n const abortController = this._readPixelAbortController;\r\n\r\n abortController?.signal.throwIfAborted();\r\n\r\n const engine = this._engine as Engine;\r\n\r\n const shadowGenerator = this._shadowGenerator;\r\n const shadowMapDepthTexture = shadowGenerator?.getShadowMap()?.depthStencilTexture;\r\n\r\n if (!shadowMapDepthTexture) {\r\n return;\r\n }\r\n\r\n // Copies the shadow map of the shadow generator into _depthCopy\r\n // That's because we can't read from a depth attachment texture in WebGL. We must first copy it to a regular texture.\r\n engine.updateTextureSamplingMode(Constants.TEXTURE_NEAREST_SAMPLINGMODE, shadowMapDepthTexture);\r\n engine.updateTextureComparisonFunction(shadowMapDepthTexture, 0);\r\n\r\n this._copyTexture.copy(shadowMapDepthTexture, this._depthCopy);\r\n\r\n engine.updateTextureComparisonFunction(shadowMapDepthTexture, Constants.LESS);\r\n\r\n // Gets the texture from GPU to CPU\r\n this._readPixelPromise = this._fallbackTexture.readPixels(0, 0, undefined, true, false);\r\n if (!this._readPixelPromise) {\r\n return;\r\n }\r\n\r\n const buffer = await this._readPixelPromise;\r\n\r\n abortController?.signal.throwIfAborted();\r\n\r\n const depthValues = buffer as Float32Array;\r\n const positions = this._mesh.getVerticesData(\"position\");\r\n const numTesselation = this._tesselation;\r\n const startPos = this._buildFullVolume ? (numTesselation + 1) * 4 * 3 : 4 * 3;\r\n const mapSize = shadowGenerator.mapSize;\r\n const step = (mapSize - 1) / numTesselation;\r\n\r\n if (!positions) {\r\n this._readPixelPromise = null;\r\n return;\r\n }\r\n\r\n const halfTesselation = numTesselation / 2;\r\n\r\n const invViewProjMatrix = shadowGenerator.getTransformMatrix().clone();\r\n invViewProjMatrix.invertToRef(invViewProjMatrix);\r\n\r\n const factor = 4;\r\n\r\n if (this._needUpdateGeometry()) {\r\n this._updateGeometry();\r\n }\r\n\r\n let posIndex = startPos;\r\n let stepY = 0;\r\n for (let y = 0; y < numTesselation + 1; ++y) {\r\n for (let x = 0; x < numTesselation + 1; ++x) {\r\n let depth = depthValues[Math.floor(mapSize * Math.floor(stepY) + x * step) * factor];\r\n if (!this._buildFullVolume) {\r\n if (y === 0 || x === 0 || y === numTesselation || x === numTesselation) {\r\n posIndex += 3;\r\n continue;\r\n }\r\n if (depth === 1) {\r\n depth = 0;\r\n }\r\n }\r\n\r\n TmpVec3.set((x - halfTesselation) / halfTesselation, (y - halfTesselation) / halfTesselation, -1 + 2 * depth);\r\n\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewProjMatrix, TmpVec3);\r\n\r\n positions[posIndex] = TmpVec3.x;\r\n positions[posIndex + 1] = TmpVec3.y;\r\n positions[posIndex + 2] = TmpVec3.z;\r\n posIndex += 3;\r\n }\r\n stepY += step;\r\n }\r\n\r\n this._mesh.setVerticesData(\"position\", positions);\r\n\r\n this._readPixelPromise = null;\r\n this._firstUpdate = false;\r\n }\r\n\r\n private _fullUpdateUBO(force = false) {\r\n const light = this._light;\r\n\r\n if ((!force && !this._needFullUpdateUBO) || !light || !this._shadowGenerator) {\r\n this._uBuffer!.update();\r\n return;\r\n }\r\n\r\n this._needFullUpdateUBO = false;\r\n\r\n const numTesselation = this._tesselation;\r\n const min = TmpVectors.Vector3[0].set(light.orthoLeft, light.orthoBottom, light.shadowMinZ ?? Constants.ShadowMinZ);\r\n const max = TmpVectors.Vector3[1].set(light.orthoRight, light.orthoTop, light.shadowMaxZ ?? Constants.ShadowMaxZ);\r\n\r\n const invViewMatrix = this._shadowGenerator.viewMatrix.invertToRef(TmpVectors.Matrix[1]);\r\n\r\n this._uBuffer!.updateUInt(\"startVertexIndex\", this._buildFullVolume ? (numTesselation + 1) * 4 * 3 : 4 * 3);\r\n this._uBuffer!.updateFloat(\"step\", ((this._shadowGenerator?.mapSize ?? 128) - 1) / numTesselation);\r\n this._uBuffer!.updateUInt(\"tesselation\", numTesselation);\r\n this._uBuffer!.updateVector3(\"orthoMin\", min);\r\n this._uBuffer!.updateVector3(\"orthoMax\", max);\r\n this._uBuffer!.updateMatrix(\"invViewMatrix\", invViewMatrix);\r\n this._uBuffer!.update();\r\n }\r\n\r\n private _createGeometry() {\r\n const light = this._light;\r\n\r\n if (!light) {\r\n return;\r\n }\r\n\r\n this._tesselation = Math.max(Math.ceil(this._tesselation) & ~1, 2);\r\n\r\n const numTesselation = this._tesselation;\r\n const vertexNumber = (numTesselation + 1) * (numTesselation + 1) + (this._buildFullVolume ? (numTesselation + 1) * 4 : 4);\r\n\r\n this._positions = new Float32Array(vertexNumber * 3);\r\n this._indices.length = 0;\r\n\r\n this._createIndices(light);\r\n\r\n this._mesh.setIndices(this._indices, vertexNumber);\r\n\r\n if (this._engine.isWebGPU) {\r\n const webGPUEngine = this._engine as WebGPUEngine;\r\n\r\n this._storageBuffer?.dispose();\r\n this._storageBuffer = new StorageBuffer(webGPUEngine, vertexNumber * 3 * 4, Constants.BUFFER_CREATIONFLAG_VERTEX | Constants.BUFFER_CREATIONFLAG_READWRITE);\r\n\r\n this._mesh.setVerticesBuffer(new VertexBuffer(webGPUEngine, this._storageBuffer.getBuffer(), \"position\", { takeBufferOwnership: false }), true, vertexNumber);\r\n\r\n this._setComputeShaderInputs();\r\n\r\n this._cs!.triggerContextRebuild = true;\r\n this._cs2!.triggerContextRebuild = true;\r\n\r\n this._needFullUpdateUBO = true;\r\n }\r\n\r\n this._updateGeometry();\r\n }\r\n\r\n private _updateGeometry() {\r\n const light = this._light;\r\n\r\n if (!light || !this._shadowGenerator) {\r\n return;\r\n }\r\n\r\n if (this._indices.length === 0) {\r\n this._createGeometry();\r\n return;\r\n }\r\n\r\n if (this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n const numTesselation = this._tesselation;\r\n\r\n const min = TmpVectors.Vector3[0].set(light.orthoLeft, light.orthoBottom, light.shadowMinZ ?? Constants.ShadowMinZ);\r\n const max = TmpVectors.Vector3[1].set(light.orthoRight, light.orthoTop, light.shadowMaxZ ?? Constants.ShadowMaxZ);\r\n\r\n const invViewMatrix = this._shadowGenerator.viewMatrix.invertToRef(TmpVectors.Matrix[1]);\r\n\r\n const stepX = (max.x - min.x) / numTesselation;\r\n const stepY = (max.y - min.y) / numTesselation;\r\n\r\n let vIndex = 0;\r\n\r\n if (this._buildFullVolume) {\r\n // Right faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(max.x, min.y + i * stepY, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n // Left faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(min.x, min.y + i * stepY, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n // Bottom faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(min.x + i * stepX, min.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n // Top faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(min.x + i * stepX, max.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n } else {\r\n // Closes the volume with two near triangles\r\n TmpVec3.set(max.x, min.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n\r\n TmpVec3.set(max.x, max.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n\r\n TmpVec3.set(min.x, min.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n\r\n TmpVec3.set(min.x, max.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n this._mesh.setVerticesData(\"position\", this._positions);\r\n }\r\n\r\n private _createIndices(light: DirectionalLight) {\r\n const invViewMatrix = Matrix.LookAtLH(light.position, light.position.add(light.direction), Vector3.UpReadOnly);\r\n invViewMatrix.invertToRef(invViewMatrix);\r\n\r\n const numTesselation = this._tesselation;\r\n\r\n const startFarIndices = this._buildFullVolume ? (numTesselation + 1) * 4 : 4;\r\n\r\n if (this._buildFullVolume) {\r\n const rightFaceStartIndex = 0;\r\n\r\n // Right faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(\r\n rightFaceStartIndex + i,\r\n startFarIndices + numTesselation + (i + 1) * (numTesselation + 1),\r\n startFarIndices + numTesselation + i * (numTesselation + 1)\r\n );\r\n this._indices.push(rightFaceStartIndex + i, rightFaceStartIndex + i + 1, startFarIndices + numTesselation + (i + 1) * (numTesselation + 1));\r\n }\r\n }\r\n\r\n const leftFaceStartIndex = rightFaceStartIndex + numTesselation + 1;\r\n\r\n // Left faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(leftFaceStartIndex + i, startFarIndices + 0 + i * (numTesselation + 1), startFarIndices + 0 + (i + 1) * (numTesselation + 1));\r\n this._indices.push(leftFaceStartIndex + i, startFarIndices + 0 + (i + 1) * (numTesselation + 1), leftFaceStartIndex + i + 1);\r\n }\r\n }\r\n\r\n const bottomFaceStartIndex = leftFaceStartIndex + numTesselation + 1;\r\n\r\n // Bottom faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(bottomFaceStartIndex + i, bottomFaceStartIndex + i + 1, startFarIndices + i + 0 * (numTesselation + 1));\r\n this._indices.push(bottomFaceStartIndex + i + 1, startFarIndices + i + 1 + 0 * (numTesselation + 1), startFarIndices + i + 0 * (numTesselation + 1));\r\n }\r\n }\r\n\r\n const topFaceStartIndex = bottomFaceStartIndex + numTesselation + 1;\r\n\r\n // Top faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(topFaceStartIndex + i, startFarIndices + i + numTesselation * (numTesselation + 1), topFaceStartIndex + i + 1);\r\n this._indices.push(\r\n topFaceStartIndex + i + 1,\r\n startFarIndices + i + numTesselation * (numTesselation + 1),\r\n startFarIndices + i + 1 + numTesselation * (numTesselation + 1)\r\n );\r\n }\r\n }\r\n\r\n // Near faces of the frustum\r\n for (let i = 0; i < numTesselation; ++i) {\r\n this._indices.push(leftFaceStartIndex + i, leftFaceStartIndex + i + 1, topFaceStartIndex + numTesselation - i);\r\n if (i < numTesselation - 1) {\r\n this._indices.push(leftFaceStartIndex + i + 1, topFaceStartIndex + numTesselation - i - 1, topFaceStartIndex + numTesselation - i);\r\n }\r\n }\r\n\r\n for (let i = 0; i < numTesselation; ++i) {\r\n this._indices.push(bottomFaceStartIndex + i, rightFaceStartIndex + numTesselation - i, rightFaceStartIndex + numTesselation - i - 1);\r\n if (i < numTesselation - 1) {\r\n this._indices.push(bottomFaceStartIndex + i, rightFaceStartIndex + numTesselation - i - 1, bottomFaceStartIndex + i + 1);\r\n }\r\n }\r\n } else {\r\n this._indices.push(0, 2, 1);\r\n this._indices.push(2, 3, 1);\r\n }\r\n\r\n // Tesselate the far plane\r\n for (let iy = 0; iy <= numTesselation; ++iy) {\r\n for (let ix = 0; ix <= numTesselation; ++ix) {\r\n if (ix < numTesselation && iy < numTesselation) {\r\n this._indices.push(\r\n startFarIndices + ix + iy * (numTesselation + 1),\r\n startFarIndices + ix + 1 + iy * (numTesselation + 1),\r\n startFarIndices + ix + 1 + (iy + 1) * (numTesselation + 1)\r\n );\r\n this._indices.push(\r\n startFarIndices + ix + iy * (numTesselation + 1),\r\n startFarIndices + ix + 1 + (iy + 1) * (numTesselation + 1),\r\n startFarIndices + ix + (iy + 1) * (numTesselation + 1)\r\n );\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"lightingVolume.js","sourceRoot":"","sources":["../../../../dev/core/src/Lights/lightingVolume.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,yBAAwB;AAC7C,OAAO,EAAE,SAAS,EAAE,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GAAG,CAAC,CAAC,GAAG,CAAC,cAAc,GAAG,CAAC,CAAC,CACzD,CAAC;gBACN,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { AbstractEngine, Engine, InternalTexture, Nullable, RenderTargetWrapper, Scene, ShadowGenerator, WebGPUEngine } from \"core/index\";\r\nimport { AbortError } from \"core/Misc/error\";\r\nimport { Constants } from \"core/Engines/constants\";\r\nimport { Matrix, Vector3, TmpVectors } from \"core/Maths/math.vector\";\r\nimport { DirectionalLight } from \"core/Lights/directionalLight\";\r\nimport { Mesh } from \"core/Meshes/mesh\";\r\nimport { ComputeShader } from \"core/Compute/computeShader\";\r\nimport { CopyTextureToTexture } from \"core/Misc/copyTextureToTexture\";\r\nimport { UniformBuffer } from \"core/Materials/uniformBuffer\";\r\nimport { StorageBuffer } from \"core/Buffers/storageBuffer\";\r\nimport { BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { VertexBuffer } from \"core/Buffers/buffer\";\r\n\r\nimport \"core/ShadersWGSL/lightingVolume.compute\";\r\n\r\nconst TmpVec3 = new Vector3();\r\n\r\n/**\r\n * Class used to create a lighting volume from a directional light's shadow generator.\r\n */\r\nexport class LightingVolume {\r\n private readonly _engine: AbstractEngine;\r\n private readonly _scene: Scene;\r\n private readonly _mesh: Mesh;\r\n private readonly _copyTexture?: CopyTextureToTexture;\r\n private readonly _uBuffer?: UniformBuffer;\r\n private readonly _buildFullVolume = true;\r\n private _name: string;\r\n private _cs?: ComputeShader;\r\n private _cs2?: ComputeShader;\r\n private _light?: DirectionalLight;\r\n private _fallbackTexture?: BaseTexture;\r\n private _storageBuffer?: StorageBuffer;\r\n private _depthCopy?: RenderTargetWrapper;\r\n private _readPixelPromise: Nullable<Promise<ArrayBufferView>> = null;\r\n private _readPixelAbortController: Nullable<AbortController> = null;\r\n private _numFrames = 0;\r\n private _firstUpdate = true;\r\n private _currentLightDirection = new Vector3();\r\n private _positions: Float32Array;\r\n private _indices: number[];\r\n private _needFullUpdateUBO = true;\r\n private _currentShadowDepthTexture: Nullable<InternalTexture>;\r\n\r\n private _shadowGenerator?: ShadowGenerator;\r\n /**\r\n * The shadow generator used to create the lighting volume.\r\n */\r\n public get shadowGenerator() {\r\n return this._shadowGenerator!;\r\n }\r\n\r\n public set shadowGenerator(sg: ShadowGenerator) {\r\n const light = sg.getLight();\r\n\r\n if (!(light instanceof DirectionalLight)) {\r\n throw new Error(`LightingVolumeMesh ${this._name}: light must be a directional light`);\r\n }\r\n\r\n this._shadowGenerator = sg;\r\n this._light = light;\r\n\r\n this._updateGeometry();\r\n\r\n if (!this._engine.isWebGPU) {\r\n this._createFallbackTextures();\r\n }\r\n\r\n this._setComputeShaderInputs();\r\n }\r\n\r\n private _tesselation = 0;\r\n /**\r\n * The tesselation level of the lighting volume.\r\n */\r\n public get tesselation() {\r\n return this._tesselation;\r\n }\r\n\r\n public set tesselation(n: number) {\r\n this._tesselation = n;\r\n this._createGeometry();\r\n }\r\n\r\n /**\r\n * The mesh used as a support for the lighting volume.\r\n * Note that this mesh is not automatically added to the scene's mesh array.\r\n * If you want to render it, you need to add it manually.\r\n */\r\n public get mesh() {\r\n return this._mesh;\r\n }\r\n\r\n private _frequency = 1;\r\n\r\n /**\r\n * The frequency (in number of times you call updateMesh) at which the lighting volume is updated.\r\n */\r\n public get frequency() {\r\n return this._frequency;\r\n }\r\n\r\n public set frequency(value: number) {\r\n this._frequency = value;\r\n this._firstUpdate = true;\r\n }\r\n\r\n /**\r\n * The name of the lighting volume.\r\n */\r\n public get name() {\r\n return this._name;\r\n }\r\n\r\n public set name(name: string) {\r\n this._name = name;\r\n if (this._mesh) {\r\n this._mesh.name = name;\r\n }\r\n }\r\n\r\n /**\r\n * Indicates whether this is the first update of the lighting volume.\r\n * If true, the volume has not yet been updated for the first time.\r\n */\r\n public get firstUpdate() {\r\n return this._firstUpdate;\r\n }\r\n\r\n /** @internal */\r\n public _setComputeShaderFastMode(enabled: boolean) {\r\n if (this._cs) {\r\n this._cs.fastMode = enabled;\r\n this._cs.triggerContextRebuild = enabled;\r\n }\r\n if (this._cs2) {\r\n this._cs2.fastMode = enabled;\r\n this._cs2.triggerContextRebuild = enabled;\r\n }\r\n }\r\n\r\n /**\r\n * Creates a new LightingVolume.\r\n * @param name The name of the lighting volume.\r\n * @param scene The scene the lighting volume belongs to.\r\n * @param shadowGenerator The shadow generator used to create the lighting volume. This is optional in the constructor, but must be set before calling updateMesh.\r\n * @param tesselation The tesselation level of the lighting volume (default: 64).\r\n */\r\n constructor(name: string, scene: Scene, shadowGenerator?: ShadowGenerator, tesselation = 64) {\r\n const light = shadowGenerator ? shadowGenerator.getLight() : undefined;\r\n\r\n if (light && !(light instanceof DirectionalLight)) {\r\n throw new Error(`LightingVolumeMesh ${name}: light must be a directional light`);\r\n }\r\n\r\n this._name = name;\r\n this._shadowGenerator = shadowGenerator;\r\n this._light = light as DirectionalLight;\r\n this._indices = [];\r\n\r\n this._engine = scene.getEngine();\r\n this._scene = scene;\r\n\r\n this._mesh = new Mesh(name, this._scene);\r\n scene.meshes.splice(scene.meshes.indexOf(this._mesh), 1);\r\n\r\n if (this._engine.isWebGPU) {\r\n this._uBuffer = new UniformBuffer(this._engine);\r\n\r\n this._uBuffer.addUniform(\"invViewProjMatrix\", 16);\r\n this._uBuffer.addUniform(\"invViewMatrix\", 16);\r\n this._uBuffer.addUniform(\"startVertexIndex\", 1);\r\n this._uBuffer.addUniform(\"step\", 1);\r\n this._uBuffer.addUniform(\"tesselation\", 1);\r\n this._uBuffer.addUniform(\"orthoMin\", 3);\r\n this._uBuffer.addUniform(\"orthoMax\", 3);\r\n this._uBuffer.update();\r\n\r\n this._createComputeShader();\r\n } else {\r\n this._copyTexture = new CopyTextureToTexture(this._engine, false, true);\r\n this._createFallbackTextures();\r\n }\r\n\r\n this._tesselation = tesselation;\r\n this._createGeometry();\r\n }\r\n\r\n /**\r\n * Checks if the lighting volume is ready to be updated.\r\n * @returns True if the volume is ready to be updated.\r\n */\r\n public isReady() {\r\n let isReady = this._mesh.isReady(true);\r\n if (this._cs) {\r\n isReady = this._cs.isReady() && isReady;\r\n }\r\n if (this._cs2) {\r\n isReady = this._cs2.isReady() && isReady;\r\n }\r\n return isReady;\r\n }\r\n\r\n /**\r\n * Updates the lighting volume mesh.\r\n * @param forceUpdate If true, forces the update even if the frequency condition is not met.\r\n */\r\n public update(forceUpdate = false) {\r\n if (this._tesselation === 0 || !this._shadowGenerator) {\r\n return;\r\n }\r\n\r\n if (!forceUpdate && !this._firstUpdate && (this.frequency === 0 || ++this._numFrames < this.frequency)) {\r\n return;\r\n }\r\n\r\n this._numFrames = 0;\r\n\r\n if (this._engine.isWebGPU) {\r\n this._uBuffer!.updateMatrix(\"invViewProjMatrix\", this._shadowGenerator.getTransformMatrix().invertToRef(TmpVectors.Matrix[0]));\r\n\r\n if (this._engine._enableGPUDebugMarkers) {\r\n this._engine._debugPushGroup?.(`Update lighting volume (${this._name})`);\r\n }\r\n\r\n const depthTexture = this._shadowGenerator.getShadowMap()?.depthStencilTexture;\r\n if (depthTexture && depthTexture !== this._currentShadowDepthTexture) {\r\n this._currentShadowDepthTexture = depthTexture!;\r\n this._cs!.triggerContextRebuild = this._cs!.fastMode;\r\n this._cs2!.triggerContextRebuild = this._cs2!.fastMode;\r\n this._cs!.setInternalTexture(\"shadowMap\", depthTexture);\r\n this._cs2!.setInternalTexture(\"shadowMap\", depthTexture);\r\n }\r\n\r\n if (this._needUpdateGeometry()) {\r\n this._fullUpdateUBO(true);\r\n\r\n const dispatchSize = Math.ceil((this._tesselation + 1) / 32);\r\n\r\n this._engine._debugPushGroup?.(`Update vertices of other planes`);\r\n this._cs2!.dispatch(dispatchSize, 1, 1);\r\n this._engine._debugPopGroup?.();\r\n } else {\r\n this._fullUpdateUBO();\r\n }\r\n\r\n const dispatchSize = Math.ceil((this._tesselation + 1) / 8);\r\n\r\n this._engine._debugPushGroup?.(`Update vertices of far plane`);\r\n this._cs!.dispatch(dispatchSize, dispatchSize, 1);\r\n this._engine._debugPopGroup?.();\r\n\r\n if (this._engine._enableGPUDebugMarkers) {\r\n this._engine._debugPopGroup?.();\r\n }\r\n\r\n this._firstUpdate = false;\r\n } else {\r\n try {\r\n void this._fallbackReadPixelAsync();\r\n } catch {\r\n this._readPixelPromise = null;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes the lighting volume and associated resources.\r\n */\r\n public dispose() {\r\n this._readPixelAbortController?.abort(new AbortError(\"LightingVolume is disposed\"));\r\n this._readPixelAbortController = null;\r\n this._mesh.dispose();\r\n if (this._fallbackTexture) {\r\n this._fallbackTexture._texture = null;\r\n }\r\n this._fallbackTexture?.dispose();\r\n this._copyTexture?.dispose();\r\n this._storageBuffer?.dispose();\r\n this._uBuffer?.dispose();\r\n this._depthCopy?.dispose();\r\n }\r\n\r\n private _needUpdateGeometry() {\r\n if (this._cs?.triggerContextRebuild || (this._light && !this._currentLightDirection.equals(this._light.direction))) {\r\n this._currentLightDirection.copyFrom(this._light!.direction);\r\n return true;\r\n }\r\n\r\n return false;\r\n }\r\n\r\n private _createComputeShader() {\r\n this._cs = new ComputeShader(\"updateFarPlaneVertices\", this._engine, \"lightingVolume\", {\r\n bindingsMapping: {\r\n shadowMap: { group: 0, binding: 0 },\r\n params: { group: 0, binding: 1 },\r\n positions: { group: 0, binding: 2 },\r\n },\r\n defines: !this._buildFullVolume ? [\"#define KEEP_EDGES\", \"#define MOVE_FAR_DEPTH_TO_NEAR\"] : undefined,\r\n entryPoint: \"updateFarPlaneVertices\",\r\n });\r\n\r\n this._cs2 = new ComputeShader(\"updatePlaneVertices\", this._engine, \"lightingVolume\", {\r\n bindingsMapping: {\r\n shadowMap: { group: 0, binding: 0 },\r\n params: { group: 0, binding: 1 },\r\n positions: { group: 0, binding: 2 },\r\n },\r\n entryPoint: \"updatePlaneVertices\",\r\n });\r\n\r\n this._setComputeShaderInputs();\r\n }\r\n\r\n private _setComputeShaderInputs() {\r\n if (!this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n if (this._shadowGenerator) {\r\n const depthTexture = this._shadowGenerator.getShadowMap()?.depthStencilTexture;\r\n this._currentShadowDepthTexture = depthTexture || null;\r\n if (depthTexture) {\r\n this._cs?.setInternalTexture(\"shadowMap\", depthTexture);\r\n this._cs2?.setInternalTexture(\"shadowMap\", depthTexture);\r\n }\r\n }\r\n\r\n if (this._uBuffer) {\r\n this._cs?.setUniformBuffer(\"params\", this._uBuffer);\r\n this._cs2?.setUniformBuffer(\"params\", this._uBuffer);\r\n }\r\n if (this._storageBuffer) {\r\n this._cs?.setStorageBuffer(\"positions\", this._storageBuffer);\r\n this._cs2?.setStorageBuffer(\"positions\", this._storageBuffer);\r\n }\r\n }\r\n\r\n private _createFallbackTextures() {\r\n if (!this._shadowGenerator) {\r\n return;\r\n }\r\n\r\n this._readPixelAbortController?.abort(new AbortError(\"Fallback textures are being (re)created\"));\r\n this._readPixelAbortController = new AbortController();\r\n\r\n const mapSize = this._shadowGenerator.mapSize;\r\n\r\n this._depthCopy?.dispose();\r\n this._depthCopy = this._engine.createRenderTargetTexture(\r\n { width: mapSize, height: mapSize },\r\n {\r\n type: Constants.TEXTURETYPE_FLOAT,\r\n format: Constants.TEXTUREFORMAT_RED,\r\n samples: 1,\r\n label: `${this._name} - fallback internal texture`,\r\n generateDepthBuffer: false,\r\n }\r\n );\r\n\r\n this._fallbackTexture?.dispose();\r\n this._fallbackTexture = new BaseTexture(this._scene, this._depthCopy.texture);\r\n this._fallbackTexture.name = `${this._name} - fallback texture`;\r\n }\r\n\r\n private async _fallbackReadPixelAsync() {\r\n if (this._readPixelPromise || !this._fallbackTexture || !this._copyTexture) {\r\n return;\r\n }\r\n\r\n const abortController = this._readPixelAbortController;\r\n\r\n abortController?.signal.throwIfAborted();\r\n\r\n const engine = this._engine as Engine;\r\n\r\n const shadowGenerator = this._shadowGenerator;\r\n const shadowMapDepthTexture = shadowGenerator?.getShadowMap()?.depthStencilTexture;\r\n\r\n if (!shadowMapDepthTexture) {\r\n return;\r\n }\r\n\r\n // Copies the shadow map of the shadow generator into _depthCopy\r\n // That's because we can't read from a depth attachment texture in WebGL. We must first copy it to a regular texture.\r\n engine.updateTextureSamplingMode(Constants.TEXTURE_NEAREST_SAMPLINGMODE, shadowMapDepthTexture);\r\n engine.updateTextureComparisonFunction(shadowMapDepthTexture, 0);\r\n\r\n this._copyTexture.copy(shadowMapDepthTexture, this._depthCopy);\r\n\r\n engine.updateTextureComparisonFunction(shadowMapDepthTexture, Constants.LESS);\r\n\r\n // Gets the texture from GPU to CPU\r\n this._readPixelPromise = this._fallbackTexture.readPixels(0, 0, undefined, true, false);\r\n if (!this._readPixelPromise) {\r\n return;\r\n }\r\n\r\n const buffer = await this._readPixelPromise;\r\n\r\n abortController?.signal.throwIfAborted();\r\n\r\n const depthValues = buffer as Float32Array;\r\n const positions = this._mesh.getVerticesData(\"position\");\r\n const numTesselation = this._tesselation;\r\n const startPos = this._buildFullVolume ? (numTesselation + 1) * 4 * 3 : 4 * 3;\r\n const mapSize = shadowGenerator.mapSize;\r\n const step = (mapSize - 1) / numTesselation;\r\n\r\n if (!positions) {\r\n this._readPixelPromise = null;\r\n return;\r\n }\r\n\r\n const halfTesselation = numTesselation / 2;\r\n\r\n const invViewProjMatrix = shadowGenerator.getTransformMatrix().clone();\r\n invViewProjMatrix.invertToRef(invViewProjMatrix);\r\n\r\n const factor = 4;\r\n\r\n if (this._needUpdateGeometry()) {\r\n this._updateGeometry();\r\n }\r\n\r\n let posIndex = startPos;\r\n let stepY = 0;\r\n for (let y = 0; y < numTesselation + 1; ++y) {\r\n for (let x = 0; x < numTesselation + 1; ++x) {\r\n let depth = depthValues[Math.floor(mapSize * Math.floor(stepY) + x * step) * factor];\r\n if (!this._buildFullVolume) {\r\n if (y === 0 || x === 0 || y === numTesselation || x === numTesselation) {\r\n posIndex += 3;\r\n continue;\r\n }\r\n if (depth === 1) {\r\n depth = 0;\r\n }\r\n }\r\n\r\n TmpVec3.set((x - halfTesselation) / halfTesselation, (y - halfTesselation) / halfTesselation, -1 + 2 * depth);\r\n\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewProjMatrix, TmpVec3);\r\n\r\n positions[posIndex] = TmpVec3.x;\r\n positions[posIndex + 1] = TmpVec3.y;\r\n positions[posIndex + 2] = TmpVec3.z;\r\n posIndex += 3;\r\n }\r\n stepY += step;\r\n }\r\n\r\n this._mesh.setVerticesData(\"position\", positions);\r\n\r\n this._readPixelPromise = null;\r\n this._firstUpdate = false;\r\n }\r\n\r\n private _fullUpdateUBO(force = false) {\r\n const light = this._light;\r\n\r\n if ((!force && !this._needFullUpdateUBO) || !light || !this._shadowGenerator) {\r\n this._uBuffer!.update();\r\n return;\r\n }\r\n\r\n this._needFullUpdateUBO = false;\r\n\r\n const numTesselation = this._tesselation;\r\n const min = TmpVectors.Vector3[0].set(light.orthoLeft, light.orthoBottom, light.shadowMinZ ?? Constants.ShadowMinZ);\r\n const max = TmpVectors.Vector3[1].set(light.orthoRight, light.orthoTop, light.shadowMaxZ ?? Constants.ShadowMaxZ);\r\n\r\n const invViewMatrix = this._shadowGenerator.viewMatrix.invertToRef(TmpVectors.Matrix[1]);\r\n\r\n this._uBuffer!.updateUInt(\"startVertexIndex\", this._buildFullVolume ? (numTesselation + 1) * 4 * 3 : 4 * 3);\r\n this._uBuffer!.updateFloat(\"step\", ((this._shadowGenerator?.mapSize ?? 128) - 1) / numTesselation);\r\n this._uBuffer!.updateUInt(\"tesselation\", numTesselation);\r\n this._uBuffer!.updateVector3(\"orthoMin\", min);\r\n this._uBuffer!.updateVector3(\"orthoMax\", max);\r\n this._uBuffer!.updateMatrix(\"invViewMatrix\", invViewMatrix);\r\n this._uBuffer!.update();\r\n }\r\n\r\n private _createGeometry() {\r\n const light = this._light;\r\n\r\n if (!light) {\r\n return;\r\n }\r\n\r\n this._tesselation = Math.max(Math.ceil(this._tesselation) & ~1, 2);\r\n\r\n const numTesselation = this._tesselation;\r\n const vertexNumber = (numTesselation + 1) * (numTesselation + 1) + (this._buildFullVolume ? (numTesselation + 1) * 4 : 4);\r\n\r\n this._positions = new Float32Array(vertexNumber * 3);\r\n this._indices.length = 0;\r\n\r\n this._createIndices(light);\r\n\r\n this._mesh.setIndices(this._indices, vertexNumber);\r\n\r\n if (this._engine.isWebGPU) {\r\n const webGPUEngine = this._engine as WebGPUEngine;\r\n\r\n this._storageBuffer?.dispose();\r\n this._storageBuffer = new StorageBuffer(webGPUEngine, vertexNumber * 3 * 4, Constants.BUFFER_CREATIONFLAG_VERTEX | Constants.BUFFER_CREATIONFLAG_READWRITE);\r\n\r\n this._mesh.setVerticesBuffer(new VertexBuffer(webGPUEngine, this._storageBuffer.getBuffer(), \"position\", { takeBufferOwnership: false }), true, vertexNumber);\r\n\r\n this._setComputeShaderInputs();\r\n\r\n this._cs!.triggerContextRebuild = true;\r\n this._cs2!.triggerContextRebuild = true;\r\n\r\n this._needFullUpdateUBO = true;\r\n }\r\n\r\n this._updateGeometry();\r\n }\r\n\r\n private _updateGeometry() {\r\n const light = this._light;\r\n\r\n if (!light || !this._shadowGenerator) {\r\n return;\r\n }\r\n\r\n if (this._indices.length === 0) {\r\n this._createGeometry();\r\n return;\r\n }\r\n\r\n if (this._engine.isWebGPU) {\r\n return;\r\n }\r\n\r\n const numTesselation = this._tesselation;\r\n\r\n const min = TmpVectors.Vector3[0].set(light.orthoLeft, light.orthoBottom, light.shadowMinZ ?? Constants.ShadowMinZ);\r\n const max = TmpVectors.Vector3[1].set(light.orthoRight, light.orthoTop, light.shadowMaxZ ?? Constants.ShadowMaxZ);\r\n\r\n const invViewMatrix = this._shadowGenerator.viewMatrix.invertToRef(TmpVectors.Matrix[1]);\r\n\r\n const stepX = (max.x - min.x) / numTesselation;\r\n const stepY = (max.y - min.y) / numTesselation;\r\n\r\n let vIndex = 0;\r\n\r\n if (this._buildFullVolume) {\r\n // Right faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(max.x, min.y + i * stepY, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n // Left faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(min.x, min.y + i * stepY, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n // Bottom faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(min.x + i * stepX, min.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n // Top faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n TmpVec3.set(min.x + i * stepX, max.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n } else {\r\n // Closes the volume with two near triangles\r\n TmpVec3.set(max.x, min.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n\r\n TmpVec3.set(max.x, max.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n\r\n TmpVec3.set(min.x, min.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n\r\n TmpVec3.set(min.x, max.y, min.z);\r\n Vector3.TransformCoordinatesToRef(TmpVec3, invViewMatrix, TmpVec3);\r\n this._positions[vIndex++] = TmpVec3.x;\r\n this._positions[vIndex++] = TmpVec3.y;\r\n this._positions[vIndex++] = TmpVec3.z;\r\n }\r\n\r\n this._mesh.setVerticesData(\"position\", this._positions);\r\n }\r\n\r\n private _createIndices(light: DirectionalLight) {\r\n const invViewMatrix = Matrix.LookAtLH(light.position, light.position.add(light.direction), Vector3.UpReadOnly);\r\n invViewMatrix.invertToRef(invViewMatrix);\r\n\r\n const numTesselation = this._tesselation;\r\n\r\n const startFarIndices = this._buildFullVolume ? (numTesselation + 1) * 4 : 4;\r\n\r\n if (this._buildFullVolume) {\r\n const rightFaceStartIndex = 0;\r\n\r\n // Right faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(\r\n rightFaceStartIndex + i,\r\n startFarIndices + numTesselation + (i + 1) * (numTesselation + 1),\r\n startFarIndices + numTesselation + i * (numTesselation + 1)\r\n );\r\n this._indices.push(rightFaceStartIndex + i, rightFaceStartIndex + i + 1, startFarIndices + numTesselation + (i + 1) * (numTesselation + 1));\r\n }\r\n }\r\n\r\n const leftFaceStartIndex = rightFaceStartIndex + numTesselation + 1;\r\n\r\n // Left faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(leftFaceStartIndex + i, startFarIndices + 0 + i * (numTesselation + 1), startFarIndices + 0 + (i + 1) * (numTesselation + 1));\r\n this._indices.push(leftFaceStartIndex + i, startFarIndices + 0 + (i + 1) * (numTesselation + 1), leftFaceStartIndex + i + 1);\r\n }\r\n }\r\n\r\n const bottomFaceStartIndex = leftFaceStartIndex + numTesselation + 1;\r\n\r\n // Bottom faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(bottomFaceStartIndex + i, bottomFaceStartIndex + i + 1, startFarIndices + i + 0 * (numTesselation + 1));\r\n this._indices.push(bottomFaceStartIndex + i + 1, startFarIndices + i + 1 + 0 * (numTesselation + 1), startFarIndices + i + 0 * (numTesselation + 1));\r\n }\r\n }\r\n\r\n const topFaceStartIndex = bottomFaceStartIndex + numTesselation + 1;\r\n\r\n // Top faces of the frustum\r\n for (let i = 0; i <= numTesselation; ++i) {\r\n if (i < numTesselation) {\r\n this._indices.push(topFaceStartIndex + i, startFarIndices + i + numTesselation * (numTesselation + 1), topFaceStartIndex + i + 1);\r\n this._indices.push(\r\n topFaceStartIndex + i + 1,\r\n startFarIndices + i + numTesselation * (numTesselation + 1),\r\n startFarIndices + i + 1 + numTesselation * (numTesselation + 1)\r\n );\r\n }\r\n }\r\n\r\n // Near faces of the frustum\r\n for (let i = 0; i < numTesselation; ++i) {\r\n this._indices.push(leftFaceStartIndex + i, leftFaceStartIndex + i + 1, topFaceStartIndex + numTesselation - i);\r\n if (i < numTesselation - 1) {\r\n this._indices.push(leftFaceStartIndex + i + 1, topFaceStartIndex + numTesselation - i - 1, topFaceStartIndex + numTesselation - i);\r\n }\r\n }\r\n\r\n for (let i = 0; i < numTesselation; ++i) {\r\n this._indices.push(bottomFaceStartIndex + i, rightFaceStartIndex + numTesselation - i, rightFaceStartIndex + numTesselation - i - 1);\r\n if (i < numTesselation - 1) {\r\n this._indices.push(bottomFaceStartIndex + i, rightFaceStartIndex + numTesselation - i - 1, bottomFaceStartIndex + i + 1);\r\n }\r\n }\r\n } else {\r\n this._indices.push(0, 2, 1);\r\n this._indices.push(2, 3, 1);\r\n }\r\n\r\n // Tesselate the far plane\r\n for (let iy = 0; iy <= numTesselation; ++iy) {\r\n for (let ix = 0; ix <= numTesselation; ++ix) {\r\n if (ix < numTesselation && iy < numTesselation) {\r\n this._indices.push(\r\n startFarIndices + ix + iy * (numTesselation + 1),\r\n startFarIndices + ix + 1 + iy * (numTesselation + 1),\r\n startFarIndices + ix + 1 + (iy + 1) * (numTesselation + 1)\r\n );\r\n this._indices.push(\r\n startFarIndices + ix + iy * (numTesselation + 1),\r\n startFarIndices + ix + 1 + (iy + 1) * (numTesselation + 1),\r\n startFarIndices + ix + (iy + 1) * (numTesselation + 1)\r\n );\r\n }\r\n }\r\n }\r\n }\r\n}\r\n"]}
@@ -151,8 +151,36 @@ export function LoadAssetContainerFromSerializedScene(scene, serializedScene, ro
151
151
  }
152
152
  const LoadAssetContainer = (scene, data, rootUrl, onError, addToScene = false) => {
153
153
  const container = new AssetContainer(scene);
154
+ // When loading into a container (not directly into the scene), suppress entity-added
155
+ // observables to prevent scene events during loading. Entities still get added to scene
156
+ // arrays (so the linking code can find them), but no events fire.
157
+ // They are removed from the scene at the end via container.removeAllFromScene().
158
+ let savedObservables;
154
159
  if (!addToScene) {
155
- scene._blockEntityCollection = true;
160
+ savedObservables = {
161
+ mesh: scene.onNewMeshAddedObservable,
162
+ transformNode: scene.onNewTransformNodeAddedObservable,
163
+ light: scene.onNewLightAddedObservable,
164
+ camera: scene.onNewCameraAddedObservable,
165
+ material: scene.onNewMaterialAddedObservable,
166
+ multiMaterial: scene.onNewMultiMaterialAddedObservable,
167
+ texture: scene.onNewTextureAddedObservable,
168
+ skeleton: scene.onNewSkeletonAddedObservable,
169
+ geometry: scene.onNewGeometryAddedObservable,
170
+ animationGroup: scene.onNewAnimationGroupAddedObservable,
171
+ particleSystem: scene.onNewParticleSystemAddedObservable,
172
+ };
173
+ scene.onNewMeshAddedObservable = new Observable();
174
+ scene.onNewTransformNodeAddedObservable = new Observable();
175
+ scene.onNewLightAddedObservable = new Observable();
176
+ scene.onNewCameraAddedObservable = new Observable();
177
+ scene.onNewMaterialAddedObservable = new Observable();
178
+ scene.onNewMultiMaterialAddedObservable = new Observable();
179
+ scene.onNewTextureAddedObservable = new Observable();
180
+ scene.onNewSkeletonAddedObservable = new Observable();
181
+ scene.onNewGeometryAddedObservable = new Observable();
182
+ scene.onNewAnimationGroupAddedObservable = new Observable();
183
+ scene.onNewParticleSystemAddedObservable = new Observable();
156
184
  }
157
185
  // Entire method running in try block, so ALWAYS logs as far as it got, only actually writes details
158
186
  // when SceneLoader.debugLogging = true (default), or exception encountered.
@@ -341,17 +369,7 @@ const LoadAssetContainer = (scene, data, rootUrl, onError, addToScene = false) =
341
369
  if (vertexData !== undefined && vertexData !== null) {
342
370
  for (index = 0, cache = vertexData.length; index < cache; index++) {
343
371
  const parsedVertexData = vertexData[index];
344
- // Geometies are found by loadedUniqueId when imported
345
- // So we need to temporarily unblock the entity collection to add them to the scene
346
- scene._blockEntityCollection = false;
347
- // Temporarily replace the onNewGeometryAddedObservable to avoid multiple notifications
348
- const onNewGeometryAddedObservable = scene.onNewGeometryAddedObservable;
349
- scene.onNewGeometryAddedObservable = new Observable();
350
372
  addedGeometry.push(Geometry.Parse(parsedVertexData, scene, rootUrl));
351
- // Restore the onNewGeometryAddedObservable
352
- scene.onNewGeometryAddedObservable = onNewGeometryAddedObservable;
353
- // Restore the previous state of entity collection blocking
354
- scene._blockEntityCollection = !addToScene;
355
373
  }
356
374
  }
357
375
  for (const g of addedGeometry) {
@@ -655,10 +673,22 @@ const LoadAssetContainer = (scene, data, rootUrl, onError, addToScene = false) =
655
673
  TempMorphTargetManagerIndexContainer = {};
656
674
  TempSkeletonIndexContainer = {};
657
675
  if (!addToScene) {
658
- // Removes any breadcrumb left during the loading like geometries
676
+ // Restore observables before removing from scene
677
+ if (savedObservables) {
678
+ scene.onNewMeshAddedObservable = savedObservables.mesh;
679
+ scene.onNewTransformNodeAddedObservable = savedObservables.transformNode;
680
+ scene.onNewLightAddedObservable = savedObservables.light;
681
+ scene.onNewCameraAddedObservable = savedObservables.camera;
682
+ scene.onNewMaterialAddedObservable = savedObservables.material;
683
+ scene.onNewMultiMaterialAddedObservable = savedObservables.multiMaterial;
684
+ scene.onNewTextureAddedObservable = savedObservables.texture;
685
+ scene.onNewSkeletonAddedObservable = savedObservables.skeleton;
686
+ scene.onNewGeometryAddedObservable = savedObservables.geometry;
687
+ scene.onNewAnimationGroupAddedObservable = savedObservables.animationGroup;
688
+ scene.onNewParticleSystemAddedObservable = savedObservables.particleSystem;
689
+ }
690
+ // Removes entities from scene arrays and moves them to the container
659
691
  container.removeAllFromScene();
660
- // Unblock entity collection
661
- scene._blockEntityCollection = false;
662
692
  }
663
693
  if (log !== null && SceneLoaderFlags.loggingLevel !== 0) {
664
694
  Logger.Log(logOperation("loadAssets", parsedData ? parsedData.producer : "Unknown") + (SceneLoaderFlags.loggingLevel !== 1 ? log : ""));