@onerjs/core 8.54.3 → 8.54.5

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 (211) hide show
  1. package/DeviceInput/webDeviceInputSystem.js +4 -0
  2. package/DeviceInput/webDeviceInputSystem.js.map +1 -1
  3. package/Engines/WebGPU/Extensions/engine.cubeTexture.pure.js +1 -1
  4. package/Engines/WebGPU/Extensions/engine.cubeTexture.pure.js.map +1 -1
  5. package/Engines/WebGPU/Extensions/engine.rawTexture.pure.js +2 -2
  6. package/Engines/WebGPU/Extensions/engine.rawTexture.pure.js.map +1 -1
  7. package/Engines/WebGPU/webgpuCacheRenderPipeline.d.ts +1 -0
  8. package/Engines/WebGPU/webgpuCacheRenderPipeline.js +18 -4
  9. package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
  10. package/Engines/WebGPU/webgpuCacheTextureView.d.ts +13 -0
  11. package/Engines/WebGPU/webgpuCacheTextureView.js +32 -0
  12. package/Engines/WebGPU/webgpuCacheTextureView.js.map +1 -0
  13. package/Engines/WebGPU/webgpuRenderTargetWrapper.d.ts +10 -0
  14. package/Engines/WebGPU/webgpuRenderTargetWrapper.js +10 -0
  15. package/Engines/WebGPU/webgpuRenderTargetWrapper.js.map +1 -1
  16. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.pure.js +57 -4
  17. package/Engines/WebGPU/webgpuShaderProcessorsWGSL.pure.js.map +1 -1
  18. package/Engines/WebGPU/webgpuTextureManager.d.ts +1 -1
  19. package/Engines/WebGPU/webgpuTextureManager.js +4 -2
  20. package/Engines/WebGPU/webgpuTextureManager.js.map +1 -1
  21. package/Engines/abstractEngine.pure.js +2 -2
  22. package/Engines/abstractEngine.pure.js.map +1 -1
  23. package/Engines/thinNativeEngine.pure.d.ts +5 -0
  24. package/Engines/thinNativeEngine.pure.js +29 -6
  25. package/Engines/thinNativeEngine.pure.js.map +1 -1
  26. package/Engines/webgpuEngine.pure.d.ts +1 -0
  27. package/Engines/webgpuEngine.pure.js +21 -8
  28. package/Engines/webgpuEngine.pure.js.map +1 -1
  29. package/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.d.ts +95 -1
  30. package/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.js +169 -4
  31. package/FlowGraph/Blocks/Data/Math/flowGraphMathBlocks.pure.js.map +1 -1
  32. package/FlowGraph/Blocks/Data/Math/flowGraphMathCombineExtractBlocks.pure.d.ts +21 -6
  33. package/FlowGraph/Blocks/Data/Math/flowGraphMathCombineExtractBlocks.pure.js +28 -26
  34. package/FlowGraph/Blocks/Data/Math/flowGraphMathCombineExtractBlocks.pure.js.map +1 -1
  35. package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.pure.d.ts +30 -2
  36. package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.pure.js +111 -29
  37. package/FlowGraph/Blocks/Data/Math/flowGraphMatrixMathBlocks.pure.js.map +1 -1
  38. package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.d.ts +56 -2
  39. package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.js +99 -14
  40. package/FlowGraph/Blocks/Data/Math/flowGraphVectorMathBlocks.pure.js.map +1 -1
  41. package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.pure.js +10 -2
  42. package/FlowGraph/Blocks/Data/Transformers/flowGraphJsonPointerParserBlock.pure.js.map +1 -1
  43. package/FlowGraph/Blocks/Data/Utils/flowGraphArrayIndexBlock.pure.js +21 -1
  44. package/FlowGraph/Blocks/Data/Utils/flowGraphArrayIndexBlock.pure.js.map +1 -1
  45. package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.d.ts +18 -0
  46. package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js +29 -2
  47. package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js.map +1 -1
  48. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.pure.d.ts +15 -0
  49. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.pure.js +44 -7
  50. package/FlowGraph/Blocks/Event/flowGraphReceiveCustomEventBlock.pure.js.map +1 -1
  51. package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.pure.d.ts +9 -0
  52. package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.pure.js +9 -1
  53. package/FlowGraph/Blocks/Event/flowGraphSceneReadyEventBlock.pure.js.map +1 -1
  54. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.pure.d.ts +7 -0
  55. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.pure.js +8 -1
  56. package/FlowGraph/Blocks/Event/flowGraphSceneTickEventBlock.pure.js.map +1 -1
  57. package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.d.ts +5 -0
  58. package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.js +8 -0
  59. package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.js.map +1 -0
  60. package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.pure.d.ts +37 -0
  61. package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.pure.js +44 -0
  62. package/FlowGraph/Blocks/Event/flowGraphStopEventPropagationBlock.pure.js.map +1 -0
  63. package/FlowGraph/Blocks/Event/index.d.ts +1 -0
  64. package/FlowGraph/Blocks/Event/index.js +1 -0
  65. package/FlowGraph/Blocks/Event/index.js.map +1 -1
  66. package/FlowGraph/Blocks/Event/pure.d.ts +1 -0
  67. package/FlowGraph/Blocks/Event/pure.js +1 -0
  68. package/FlowGraph/Blocks/Event/pure.js.map +1 -1
  69. package/FlowGraph/Blocks/Execution/Animation/flowGraphBezierCurveEasingBlock.pure.d.ts +4 -1
  70. package/FlowGraph/Blocks/Execution/Animation/flowGraphBezierCurveEasingBlock.pure.js +67 -2
  71. package/FlowGraph/Blocks/Execution/Animation/flowGraphBezierCurveEasingBlock.pure.js.map +1 -1
  72. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.pure.d.ts +13 -0
  73. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.pure.js +102 -7
  74. package/FlowGraph/Blocks/Execution/Animation/flowGraphPlayAnimationBlock.pure.js.map +1 -1
  75. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.pure.js +5 -1
  76. package/FlowGraph/Blocks/Execution/Animation/flowGraphStopAnimationBlock.pure.js.map +1 -1
  77. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCancelDelayBlock.pure.js +5 -1
  78. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphCancelDelayBlock.pure.js.map +1 -1
  79. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.pure.d.ts +11 -2
  80. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.pure.js +21 -3
  81. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphForLoopBlock.pure.js.map +1 -1
  82. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSetDelayBlock.pure.js +25 -4
  83. package/FlowGraph/Blocks/Execution/ControlFlow/flowGraphSetDelayBlock.pure.js.map +1 -1
  84. package/FlowGraph/Blocks/flowGraphBlockFactory.js +18 -0
  85. package/FlowGraph/Blocks/flowGraphBlockFactory.js.map +1 -1
  86. package/FlowGraph/Blocks/flowGraphBlockNames.d.ts +9 -0
  87. package/FlowGraph/Blocks/flowGraphBlockNames.js +9 -0
  88. package/FlowGraph/Blocks/flowGraphBlockNames.js.map +1 -1
  89. package/FlowGraph/CustomTypes/flowGraphMatrix.d.ts +17 -3
  90. package/FlowGraph/CustomTypes/flowGraphMatrix.js +27 -21
  91. package/FlowGraph/CustomTypes/flowGraphMatrix.js.map +1 -1
  92. package/FlowGraph/flowGraphContext.d.ts +23 -0
  93. package/FlowGraph/flowGraphContext.js +29 -0
  94. package/FlowGraph/flowGraphContext.js.map +1 -1
  95. package/FlowGraph/flowGraphCoordinator.d.ts +58 -1
  96. package/FlowGraph/flowGraphCoordinator.js +72 -0
  97. package/FlowGraph/flowGraphCoordinator.js.map +1 -1
  98. package/FlowGraph/flowGraphDelayRegistry.d.ts +31 -0
  99. package/FlowGraph/flowGraphDelayRegistry.js +50 -0
  100. package/FlowGraph/flowGraphDelayRegistry.js.map +1 -0
  101. package/FlowGraph/flowGraphHostResolver.d.ts +69 -0
  102. package/FlowGraph/flowGraphHostResolver.js +25 -0
  103. package/FlowGraph/flowGraphHostResolver.js.map +1 -0
  104. package/FlowGraph/flowGraphMath.d.ts +48 -1
  105. package/FlowGraph/flowGraphMath.js +169 -4
  106. package/FlowGraph/flowGraphMath.js.map +1 -1
  107. package/FlowGraph/flowGraphPathConverterComponent.d.ts +14 -3
  108. package/FlowGraph/flowGraphPathConverterComponent.js +110 -18
  109. package/FlowGraph/flowGraphPathConverterComponent.js.map +1 -1
  110. package/FlowGraph/flowGraphSignalConnection.pure.js +7 -1
  111. package/FlowGraph/flowGraphSignalConnection.pure.js.map +1 -1
  112. package/FlowGraph/index.d.ts +2 -0
  113. package/FlowGraph/index.js +2 -0
  114. package/FlowGraph/index.js.map +1 -1
  115. package/FlowGraph/pure.d.ts +2 -0
  116. package/FlowGraph/pure.js +2 -0
  117. package/FlowGraph/pure.js.map +1 -1
  118. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js +3 -1
  119. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.pure.js.map +1 -1
  120. package/Maths/math.vector.pure.d.ts +10 -0
  121. package/Maths/math.vector.pure.js +13 -0
  122. package/Maths/math.vector.pure.js.map +1 -1
  123. package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.d.ts +216 -1
  124. package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js +714 -67
  125. package/Meshes/GaussianSplatting/gaussianSplattingMesh.pure.js.map +1 -1
  126. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.d.ts +81 -4
  127. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js +487 -54
  128. package/Meshes/GaussianSplatting/gaussianSplattingMeshBase.pure.js.map +1 -1
  129. package/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.pure.d.ts +19 -0
  130. package/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.pure.js +24 -0
  131. package/Meshes/GaussianSplatting/gaussianSplattingPartProxyMesh.pure.js.map +1 -1
  132. package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js +48 -10
  133. package/Meshes/GaussianSplatting/gaussianSplattingSortWorker.js.map +1 -1
  134. package/Meshes/GreasedLine/greasedLineRibbonMesh.pure.js +5 -1
  135. package/Meshes/GreasedLine/greasedLineRibbonMesh.pure.js.map +1 -1
  136. package/Meshes/abstractMesh.pure.js +5 -3
  137. package/Meshes/abstractMesh.pure.js.map +1 -1
  138. package/Misc/greasedLineTools.js +1 -1
  139. package/Misc/greasedLineTools.js.map +1 -1
  140. package/Misc/tools.pure.js +14 -2
  141. package/Misc/tools.pure.js.map +1 -1
  142. package/Particles/gpuParticleSystem.pure.d.ts +66 -1
  143. package/Particles/gpuParticleSystem.pure.js +189 -49
  144. package/Particles/gpuParticleSystem.pure.js.map +1 -1
  145. package/Physics/v2/Plugins/havokPlugin.d.ts +15 -0
  146. package/Physics/v2/Plugins/havokPlugin.js +16 -6
  147. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  148. package/Physics/v2/characterController.js +71 -19
  149. package/Physics/v2/characterController.js.map +1 -1
  150. package/ShadersWGSL/ShadersInclude/clusteredLightingCompute.d.ts +5 -0
  151. package/ShadersWGSL/ShadersInclude/clusteredLightingCompute.js +29 -0
  152. package/ShadersWGSL/ShadersInclude/clusteredLightingCompute.js.map +1 -0
  153. package/ShadersWGSL/ShadersInclude/lightFragment.js +2 -3
  154. package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
  155. package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.d.ts +1 -0
  156. package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js +2 -17
  157. package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
  158. package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.d.ts +6 -0
  159. package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js +123 -0
  160. package/ShadersWGSL/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -0
  161. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.d.ts +1 -1
  162. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +2 -111
  163. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  164. package/ShadersWGSL/background.fragment.js +2 -1
  165. package/ShadersWGSL/background.fragment.js.map +1 -1
  166. package/ShadersWGSL/default.fragment.js +2 -1
  167. package/ShadersWGSL/default.fragment.js.map +1 -1
  168. package/ShadersWGSL/openpbr.fragment.js +2 -1
  169. package/ShadersWGSL/openpbr.fragment.js.map +1 -1
  170. package/ShadersWGSL/pbr.fragment.js +2 -1
  171. package/ShadersWGSL/pbr.fragment.js.map +1 -1
  172. package/XR/features/Layers/WebXRWebGPUCompositionLayer.d.ts +3 -9
  173. package/XR/features/Layers/WebXRWebGPUCompositionLayer.js +4 -11
  174. package/XR/features/Layers/WebXRWebGPUCompositionLayer.js.map +1 -1
  175. package/XR/features/WebXRAbstractFeature.d.ts +9 -0
  176. package/XR/features/WebXRAbstractFeature.js +16 -0
  177. package/XR/features/WebXRAbstractFeature.js.map +1 -1
  178. package/XR/features/WebXRDepthSensing.pure.d.ts +7 -0
  179. package/XR/features/WebXRDepthSensing.pure.js +350 -39
  180. package/XR/features/WebXRDepthSensing.pure.js.map +1 -1
  181. package/XR/features/WebXRImageTracking.pure.js.map +1 -1
  182. package/XR/features/WebXRLayers.pure.d.ts +6 -5
  183. package/XR/features/WebXRLayers.pure.js +65 -8
  184. package/XR/features/WebXRLayers.pure.js.map +1 -1
  185. package/XR/features/WebXRRawCameraAccess.pure.js +9 -2
  186. package/XR/features/WebXRRawCameraAccess.pure.js.map +1 -1
  187. package/XR/features/WebXRSpaceWarp.pure.d.ts +0 -1
  188. package/XR/features/WebXRSpaceWarp.pure.js +13 -4
  189. package/XR/features/WebXRSpaceWarp.pure.js.map +1 -1
  190. package/XR/features/WebXRWalkingLocomotion.pure.js.map +1 -1
  191. package/XR/webXRCamera.js +27 -0
  192. package/XR/webXRCamera.js.map +1 -1
  193. package/XR/webXRFeatureWarningRegistry.d.ts +14 -0
  194. package/XR/webXRFeatureWarningRegistry.js +19 -0
  195. package/XR/webXRFeatureWarningRegistry.js.map +1 -0
  196. package/XR/webXRFeaturesManager.d.ts +5 -0
  197. package/XR/webXRFeaturesManager.js +23 -4
  198. package/XR/webXRFeaturesManager.js.map +1 -1
  199. package/XR/webXRGraphicsBinding.d.ts +17 -10
  200. package/XR/webXRGraphicsBinding.js +8 -5
  201. package/XR/webXRGraphicsBinding.js.map +1 -1
  202. package/XR/webXRSessionManager.d.ts +3 -5
  203. package/XR/webXRSessionManager.js +1 -3
  204. package/XR/webXRSessionManager.js.map +1 -1
  205. package/XR/webXRWebGPURenderTargetTextureProvider.d.ts +21 -5
  206. package/XR/webXRWebGPURenderTargetTextureProvider.js +38 -10
  207. package/XR/webXRWebGPURenderTargetTextureProvider.js.map +1 -1
  208. package/package.json +1 -1
  209. package/scene.pure.d.ts +7 -0
  210. package/scene.pure.js +8 -0
  211. package/scene.pure.js.map +1 -1
@@ -1,4 +1,5 @@
1
1
 
2
+ import { Color4 } from "../Maths/math.color.pure.js";
2
3
  import { WebXRLayerRenderTargetTexture } from "./webXRLayerRenderTargetTexture.js";
3
4
  import { WebXRLayerRenderTargetTextureProvider } from "./webXRRenderTargetTextureProvider.js";
4
5
  /**
@@ -37,6 +38,11 @@ function GetBabylonDepthFormat(format) {
37
38
  * @internal
38
39
  */
39
40
  export class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {
41
+ constructor(_xrSessionManager, layerWrapper) {
42
+ super(_xrSessionManager.scene, layerWrapper);
43
+ this._xrSessionManager = _xrSessionManager;
44
+ this._transparentClearColor = new Color4(0, 0, 0, 0);
45
+ }
40
46
  get _webgpuEngine() {
41
47
  return this._engine;
42
48
  }
@@ -66,6 +72,10 @@ export class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTarg
66
72
  }
67
73
  const renderTargetTexture = new WebXRLayerRenderTargetTexture("XR renderTargetTexture", { width, height }, this._scene);
68
74
  renderTargetTexture.renderTarget._samples = renderTargetTexture.samples;
75
+ // The projection-layer texture is presented directly by the XR compositor (top-left origin, never
76
+ // re-sampled by Babylon), so opt this target out of the engine's render-target Y-flip / winding
77
+ // compensation and render it upright, matching the WebXR/WebGPU spec's plain render pass.
78
+ renderTargetTexture.renderTarget._disableEngineYFlip = true;
69
79
  return renderTargetTexture;
70
80
  }
71
81
  /**
@@ -99,28 +109,46 @@ export class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTarg
99
109
  * `camera.isRightCamera`, so this observer clears both eyes' targets. WebGL providers never attach it,
100
110
  * so the WebGL path is unchanged.
101
111
  *
102
- * The observer mirrors the clear semantics of `Scene._clearFrameBuffer` (minus the right-eye skip): it
103
- * only clears when the scene has `autoClear` enabled, clears color at most once per frame (guarded by
104
- * `RenderTargetTexture._cleared`, which the scene resets per frame in `_checkCameraRenderTarget`), always
105
- * clears depth+stencil, and honors `skipInitialClear`. This keeps the "clear once per RTT per frame"
106
- * contract instead of clearing color on every notification.
112
+ * Color is cleared at most once per ENGINE FRAME, not once per `Scene.render`. The distinction matters:
113
+ * more than one scene can render the same XR camera within a single XR frame. `UtilityLayerRenderer`
114
+ * (used by controller pointer selection and near interaction) renders a second scene through the same
115
+ * rig cameras, and every `Scene.render` resets `RenderTargetTexture._cleared` for those cameras' targets
116
+ * (`Scene._checkCameraRenderTarget`), so a `_cleared`-based guard is defeated and each eye is re-cleared
117
+ * after it was drawn — presenting a clear-colored frame with the geometry gone. `AbstractEngine.frameId`
118
+ * only advances in `endFrame`, once per XR frame, so unlike `_cleared` it cannot be reset by another
119
+ * scene rendering the same camera.
120
+ *
121
+ * In immersive AR, color is cleared to transparent when `WebXRExperienceHelper` disables
122
+ * `Scene.autoClear`. WebGL XR framebuffers are cleared to transparent by the user agent, but WebGPU render
123
+ * passes require the application to request that clear explicitly. Skipping it leaves pixels from prior
124
+ * frames in passthrough regions, producing trails behind moving objects.
125
+ *
126
+ * Depth and stencil are still cleared on every notification, matching the previous behavior and the
127
+ * expectations of overlay scenes that draw on top of the main scene.
107
128
  * @param renderTargetTexture the per-eye render target to clear each frame
108
129
  */
109
130
  _attachPerEyeClearObserver(renderTargetTexture) {
131
+ let lastColorClearedFrameId = -1;
110
132
  renderTargetTexture.onClearObservable.add((engine) => {
111
133
  // Honor skipInitialClear so this observer preserves the default clear semantics it replaces.
112
134
  if (renderTargetTexture.skipInitialClear) {
113
135
  return;
114
136
  }
115
137
  const scene = renderTargetTexture.getScene();
138
+ const isImmersiveAR = this._xrSessionManager.sessionMode === "immersive-ar";
116
139
  // When autoClear is disabled the scene does not clear render targets; match that so this observer
117
- // does not force a clear the user opted out of.
118
- if (scene && !scene.autoClear) {
140
+ // does not force a clear the user opted out of. Immersive AR is the exception: the experience
141
+ // helper disables autoClear because WebGL XR is cleared by the user agent, while WebGPU is not.
142
+ if (scene && !scene.autoClear && !isImmersiveAR) {
119
143
  return;
120
144
  }
121
- // Clear color only once per frame (!_cleared), always clear depth+stencil, then mark the target
122
- // cleared for this frame so a second notification in the same frame does not re-clear color.
123
- engine.clear(renderTargetTexture.clearColor ?? scene?.clearColor ?? null, !renderTargetTexture._cleared, true, true);
145
+ const clearColor = engine.frameId !== lastColorClearedFrameId;
146
+ const color = isImmersiveAR && scene && !scene.autoClear ? this._transparentClearColor : (renderTargetTexture.clearColor ?? scene?.clearColor ?? null);
147
+ engine.clear(color, clearColor, true, true);
148
+ if (clearColor) {
149
+ lastColorClearedFrameId = engine.frameId;
150
+ }
151
+ // Kept in sync so anything else reading the flag still sees this target as cleared this frame.
124
152
  renderTargetTexture._cleared = true;
125
153
  });
126
154
  }
@@ -1 +1 @@
1
- {"version":3,"file":"webXRWebGPURenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRWebGPURenderTargetTextureProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,qCAAqC,EAAE,MAAM,oCAAoC,CAAC;AAE3F;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,MAAwB;IACnD,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,cAAc;YACf,OAAO,SAAS,CAAC,qBAAqB,CAAC;QAC3C,KAAK,aAAa;YACd,OAAO,SAAS,CAAC,qBAAqB,CAAC;QAC3C,KAAK,sBAAsB;YACvB,OAAO,SAAS,CAAC,8BAA8B,CAAC;QACpD,KAAK,cAAc;YACf,OAAO,SAAS,CAAC,2BAA2B,CAAC;QACjD,KAAK,uBAAuB;YACxB,OAAO,SAAS,CAAC,mCAAmC,CAAC;QACzD,KAAK,UAAU;YACX,OAAO,SAAS,CAAC,sBAAsB,CAAC;QAC5C;YACI,uFAAuF;YACvF,OAAO,SAAS,CAAC,8BAA8B,CAAC;IACxD,CAAC;AACL,CAAC;AAED;;;;;;GAMG;AACH,MAAM,OAAgB,sCAAuC,SAAQ,qCAAqC;IACtG,IAAY,aAAa;QACrB,OAAO,IAAI,CAAC,OAAuB,CAAC;IACxC,CAAC;IAEO,iBAAiB,CAAC,OAAmB;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACzD,CAAC;IAEO,iBAAiB,CAAC,OAAmB,EAAE,kBAAoC;QAC/E,MAAM,eAAe,GAAG,IAAI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BAA0B,CAAC,mBAAwC;QACvE,mBAAmB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE;YACjD,6FAA6F;YAC7F,IAAI,mBAAmB,CAAC,gBAAgB,EAAE,CAAC;gBACvC,OAAO;YACX,CAAC;YACD,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,EAAE,CAAC;YAC7C,kGAAkG;YAClG,gDAAgD;YAChD,IAAI,KAAK,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;gBAC5B,OAAO;YACX,CAAC;YACD,gGAAgG;YAChG,6FAA6F;YAC7F,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,UAAU,IAAI,KAAK,EAAE,UAAU,IAAI,IAAI,EAAE,CAAC,mBAAmB,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;YACrH,mBAAmB,CAAC,QAAQ,GAAG,IAAI,CAAC;QACxC,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;;;;;;;;OASG;IACO,yCAAyC,CAAC,mBAAwC,EAAE,YAAwB,EAAE,mBAAyC;QAC7J,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,aAAa,CAAC,0BAA0B,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;QACvE,CAAC;QACD,MAAM,KAAK,GAAG,mBAAmB,CAAC,YAAY,EAAE,oBAAoB,CAAC;QACrE,IAAI,KAAK,IAAI,mBAAmB,EAAE,CAAC;YAC/B,IAAI,CAAC,aAAa,CAAC,0BAA0B,CAAC,KAAK,EAAE,mBAAmB,CAAC,CAAC;QAC9E,CAAC;IACL,CAAC;CACJ","sourcesContent":["import { Constants } from \"../Engines/constants\";\nimport { type WebGPUEngine } from \"../Engines/webgpuEngine\";\nimport { type InternalTexture } from \"../Materials/Textures/internalTexture\";\nimport { type RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture.pure\";\nimport { type Nullable } from \"../types\";\nimport { WebXRLayerRenderTargetTexture } from \"./webXRLayerRenderTargetTexture\";\nimport { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\n\n/**\n * Maps a WebGPU depth/stencil {@link GPUTextureFormat} to the matching Babylon `TEXTUREFORMAT_*` constant.\n *\n * The engine reads `InternalTexture.format` (a Babylon constant) when it builds the render pass depth\n * attachment for a render target, so a depth texture wrapped from an external `GPUTexture` must carry the\n * correct Babylon format or the depth attachment pipeline format will not match the sub-image's texture.\n * @param format the WebGPU depth/stencil format requested when the layer was created\n * @returns the matching Babylon texture format constant\n */\nfunction GetBabylonDepthFormat(format: GPUTextureFormat): number {\n switch (format) {\n case \"depth16unorm\":\n return Constants.TEXTUREFORMAT_DEPTH16;\n case \"depth24plus\":\n return Constants.TEXTUREFORMAT_DEPTH24;\n case \"depth24plus-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n case \"depth32float\":\n return Constants.TEXTUREFORMAT_DEPTH32_FLOAT;\n case \"depth32float-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8;\n case \"stencil8\":\n return Constants.TEXTUREFORMAT_STENCIL8;\n default:\n // Fall back to a combined depth/stencil format, which is the projection layer default.\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n }\n}\n\n/**\n * Provides render target textures for WebGPU-backed XR layers. Owns all WebGPU-specific texture wrapping\n * (via {@link WebGPUEngine.wrapWebGPUTexture} / {@link WebGPUEngine.updateWrappedWebGPUTexture}) so the base\n * provider can stay graphics-API-agnostic. Mirrors {@link WebXRWebGLRenderTargetTextureProvider} for the\n * WebGPU (XRGPUBinding) backend.\n * @internal\n */\nexport abstract class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\n private get _webgpuEngine(): WebGPUEngine {\n return this._engine as WebGPUEngine;\n }\n\n private _wrapColorTexture(texture: GPUTexture): InternalTexture {\n return this._webgpuEngine.wrapWebGPUTexture(texture);\n }\n\n private _wrapDepthTexture(texture: GPUTexture, depthStencilFormat: GPUTextureFormat): InternalTexture {\n const internalTexture = this._webgpuEngine.wrapWebGPUTexture(texture);\n // The engine derives the color attachment format automatically from the wrapped hardware texture,\n // but the depth attachment format is read from the Babylon InternalTexture.format, which\n // wrapWebGPUTexture does not set. Assign it here from the format the layer was created with.\n internalTexture.format = GetBabylonDepthFormat(depthStencilFormat);\n return internalTexture;\n }\n\n /**\n * Builds the render target shell as a {@link WebXRLayerRenderTargetTexture} for the single-view path so\n * each eye can bind its own array layer of a layered projection-layer texture. Multiview is not yet\n * supported on this WebGPU path and is delegated to the base implementation.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param multiview whether the render target should be a multiview render target\n * @returns the created (but not yet registered) render target texture\n */\n protected override _createRenderTargetTextureShell(width: number, height: number, multiview: boolean): RenderTargetTexture {\n if (multiview) {\n return super._createRenderTargetTextureShell(width, height, multiview);\n }\n const renderTargetTexture = new WebXRLayerRenderTargetTexture(\"XR renderTargetTexture\", { width, height }, this._scene);\n renderTargetTexture.renderTarget!._samples = renderTargetTexture.samples;\n return renderTargetTexture;\n }\n\n /**\n * Wraps the sub-image's color (and optional depth/stencil) GPUTextures and builds a new render target\n * texture around them. Use this on first creation and whenever the sub-image texture size changes.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param colorTexture the sub-image color GPUTexture\n * @param depthStencilTexture the sub-image depth/stencil GPUTexture, if any\n * @param depthStencilFormat the WebGPU depth/stencil format the layer was created with, if depth is provided\n * @param multiview whether the render target should be a multiview render target\n * @returns the created render target texture\n */\n protected _createRenderTargetTextureFromGPUTextures(\n width: number,\n height: number,\n colorTexture: GPUTexture,\n depthStencilTexture: Nullable<GPUTexture>,\n depthStencilFormat: GPUTextureFormat | undefined,\n multiview: boolean\n ): WebXRLayerRenderTargetTexture {\n const color = this._wrapColorTexture(colorTexture);\n const depth = depthStencilTexture && depthStencilFormat ? this._wrapDepthTexture(depthStencilTexture, depthStencilFormat) : null;\n // Single-view (the only path here) always builds a WebXRLayerRenderTargetTexture via the shell override above.\n const renderTargetTexture = this._createRenderTargetTextureInternal(width, height, color, depth, multiview) as WebXRLayerRenderTargetTexture;\n this._attachPerEyeClearObserver(renderTargetTexture);\n return renderTargetTexture;\n }\n\n /**\n * Ensures this render target is cleared every frame, including for the right eye.\n *\n * `Scene._clearFrameBuffer` skips clearing the right rig camera's framebuffer (`!camera.isRightCamera`).\n * That is a valid optimization for WebGL2 stereo, where both eyes render into a single side-by-side\n * texture and the left eye's full clear already covers the whole texture. WebGPU projection layers give\n * each eye its OWN render target (a distinct array layer rendered in a separate render pass), so the\n * right eye's color and — critically — depth would never be cleared, leaving its depth test to reject\n * every fragment (a black right eye). The scene notifies `onClearObservable` regardless of\n * `camera.isRightCamera`, so this observer clears both eyes' targets. WebGL providers never attach it,\n * so the WebGL path is unchanged.\n *\n * The observer mirrors the clear semantics of `Scene._clearFrameBuffer` (minus the right-eye skip): it\n * only clears when the scene has `autoClear` enabled, clears color at most once per frame (guarded by\n * `RenderTargetTexture._cleared`, which the scene resets per frame in `_checkCameraRenderTarget`), always\n * clears depth+stencil, and honors `skipInitialClear`. This keeps the \"clear once per RTT per frame\"\n * contract instead of clearing color on every notification.\n * @param renderTargetTexture the per-eye render target to clear each frame\n */\n private _attachPerEyeClearObserver(renderTargetTexture: RenderTargetTexture): void {\n renderTargetTexture.onClearObservable.add((engine) => {\n // Honor skipInitialClear so this observer preserves the default clear semantics it replaces.\n if (renderTargetTexture.skipInitialClear) {\n return;\n }\n const scene = renderTargetTexture.getScene();\n // When autoClear is disabled the scene does not clear render targets; match that so this observer\n // does not force a clear the user opted out of.\n if (scene && !scene.autoClear) {\n return;\n }\n // Clear color only once per frame (!_cleared), always clear depth+stencil, then mark the target\n // cleared for this frame so a second notification in the same frame does not re-clear color.\n engine.clear(renderTargetTexture.clearColor ?? scene?.clearColor ?? null, !renderTargetTexture._cleared, true, true);\n renderTargetTexture._cleared = true;\n });\n }\n\n /**\n * Repoints the wrapped color/depth textures of an existing render target at the current frame's\n * GPUTextures, preserving the RenderTargetTexture / InternalTexture identity held by the XR camera's\n * `outputRenderTarget`. The sub-image textures are only valid for the current frame and may rotate from\n * a compositor pool, so this must run every frame. The new GPUTextures must have the same dimensions as\n * the wrapped ones (guaranteed by the caller's size-change branch, which rebuilds instead).\n * @param renderTargetTexture the render target whose wrapped textures should be repointed\n * @param colorTexture the current frame's color GPUTexture\n * @param depthStencilTexture the current frame's depth/stencil GPUTexture, if any\n */\n protected _updateRenderTargetTextureFromGPUTextures(renderTargetTexture: RenderTargetTexture, colorTexture: GPUTexture, depthStencilTexture: Nullable<GPUTexture>): void {\n const color = renderTargetTexture._texture;\n if (color) {\n this._webgpuEngine.updateWrappedWebGPUTexture(color, colorTexture);\n }\n const depth = renderTargetTexture.renderTarget?._depthStencilTexture;\n if (depth && depthStencilTexture) {\n this._webgpuEngine.updateWrappedWebGPUTexture(depth, depthStencilTexture);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"webXRWebGPURenderTargetTextureProvider.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRWebGPURenderTargetTextureProvider.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAKjD,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAElD,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAEhF,OAAO,EAAE,qCAAqC,EAAE,MAAM,oCAAoC,CAAC;AAG3F;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,MAAwB;IACnD,QAAQ,MAAM,EAAE,CAAC;QACb,KAAK,cAAc;YACf,OAAO,SAAS,CAAC,qBAAqB,CAAC;QAC3C,KAAK,aAAa;YACd,OAAO,SAAS,CAAC,qBAAqB,CAAC;QAC3C,KAAK,sBAAsB;YACvB,OAAO,SAAS,CAAC,8BAA8B,CAAC;QACpD,KAAK,cAAc;Y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uEngine\";\nimport { type WebGPURenderTargetWrapper } from \"../Engines/WebGPU/webgpuRenderTargetWrapper\";\nimport { type InternalTexture } from \"../Materials/Textures/internalTexture\";\nimport { type RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture.pure\";\nimport { Color4 } from \"../Maths/math.color.pure\";\nimport { type Nullable } from \"../types\";\nimport { WebXRLayerRenderTargetTexture } from \"./webXRLayerRenderTargetTexture\";\nimport { type WebXRLayerWrapper } from \"./webXRLayerWrapper\";\nimport { WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\nimport { type WebXRSessionManager } from \"./webXRSessionManager\";\n\n/**\n * Maps a WebGPU depth/stencil {@link GPUTextureFormat} to the matching Babylon `TEXTUREFORMAT_*` constant.\n *\n * The engine reads `InternalTexture.format` (a Babylon constant) when it builds the render pass depth\n * attachment for a render target, so a depth texture wrapped from an external `GPUTexture` must carry the\n * correct Babylon format or the depth attachment pipeline format will not match the sub-image's texture.\n * @param format the WebGPU depth/stencil format requested when the layer was created\n * @returns the matching Babylon texture format constant\n */\nfunction GetBabylonDepthFormat(format: GPUTextureFormat): number {\n switch (format) {\n case \"depth16unorm\":\n return Constants.TEXTUREFORMAT_DEPTH16;\n case \"depth24plus\":\n return Constants.TEXTUREFORMAT_DEPTH24;\n case \"depth24plus-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n case \"depth32float\":\n return Constants.TEXTUREFORMAT_DEPTH32_FLOAT;\n case \"depth32float-stencil8\":\n return Constants.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8;\n case \"stencil8\":\n return Constants.TEXTUREFORMAT_STENCIL8;\n default:\n // Fall back to a combined depth/stencil format, which is the projection layer default.\n return Constants.TEXTUREFORMAT_DEPTH24_STENCIL8;\n }\n}\n\n/**\n * Provides render target textures for WebGPU-backed XR layers. Owns all WebGPU-specific texture wrapping\n * (via {@link WebGPUEngine.wrapWebGPUTexture} / {@link WebGPUEngine.updateWrappedWebGPUTexture}) so the base\n * provider can stay graphics-API-agnostic. Mirrors {@link WebXRWebGLRenderTargetTextureProvider} for the\n * WebGPU (XRGPUBinding) backend.\n * @internal\n */\nexport abstract class WebXRWebGPURenderTargetTextureProvider extends WebXRLayerRenderTargetTextureProvider {\n private readonly _transparentClearColor = new Color4(0, 0, 0, 0);\n\n constructor(\n protected readonly _xrSessionManager: WebXRSessionManager,\n layerWrapper: WebXRLayerWrapper\n ) {\n super(_xrSessionManager.scene, layerWrapper);\n }\n\n private get _webgpuEngine(): WebGPUEngine {\n return this._engine as WebGPUEngine;\n }\n\n private _wrapColorTexture(texture: GPUTexture): InternalTexture {\n return this._webgpuEngine.wrapWebGPUTexture(texture);\n }\n\n private _wrapDepthTexture(texture: GPUTexture, depthStencilFormat: GPUTextureFormat): InternalTexture {\n const internalTexture = this._webgpuEngine.wrapWebGPUTexture(texture);\n // The engine derives the color attachment format automatically from the wrapped hardware texture,\n // but the depth attachment format is read from the Babylon InternalTexture.format, which\n // wrapWebGPUTexture does not set. Assign it here from the format the layer was created with.\n internalTexture.format = GetBabylonDepthFormat(depthStencilFormat);\n return internalTexture;\n }\n\n /**\n * Builds the render target shell as a {@link WebXRLayerRenderTargetTexture} for the single-view path so\n * each eye can bind its own array layer of a layered projection-layer texture. Multiview is not yet\n * supported on this WebGPU path and is delegated to the base implementation.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param multiview whether the render target should be a multiview render target\n * @returns the created (but not yet registered) render target texture\n */\n protected override _createRenderTargetTextureShell(width: number, height: number, multiview: boolean): RenderTargetTexture {\n if (multiview) {\n return super._createRenderTargetTextureShell(width, height, multiview);\n }\n const renderTargetTexture = new WebXRLayerRenderTargetTexture(\"XR renderTargetTexture\", { width, height }, this._scene);\n renderTargetTexture.renderTarget!._samples = renderTargetTexture.samples;\n // The projection-layer texture is presented directly by the XR compositor (top-left origin, never\n // re-sampled by Babylon), so opt this target out of the engine's render-target Y-flip / winding\n // compensation and render it upright, matching the WebXR/WebGPU spec's plain render pass.\n (renderTargetTexture.renderTarget as WebGPURenderTargetWrapper)._disableEngineYFlip = true;\n return renderTargetTexture;\n }\n\n /**\n * Wraps the sub-image's color (and optional depth/stencil) GPUTextures and builds a new render target\n * texture around them. Use this on first creation and whenever the sub-image texture size changes.\n * @param width the width of the render target\n * @param height the height of the render target\n * @param colorTexture the sub-image color GPUTexture\n * @param depthStencilTexture the sub-image depth/stencil GPUTexture, if any\n * @param depthStencilFormat the WebGPU depth/stencil format the layer was created with, if depth is provided\n * @param multiview whether the render target should be a multiview render target\n * @returns the created render target texture\n */\n protected _createRenderTargetTextureFromGPUTextures(\n width: number,\n height: number,\n colorTexture: GPUTexture,\n depthStencilTexture: Nullable<GPUTexture>,\n depthStencilFormat: GPUTextureFormat | undefined,\n multiview: boolean\n ): WebXRLayerRenderTargetTexture {\n const color = this._wrapColorTexture(colorTexture);\n const depth = depthStencilTexture && depthStencilFormat ? this._wrapDepthTexture(depthStencilTexture, depthStencilFormat) : null;\n // Single-view (the only path here) always builds a WebXRLayerRenderTargetTexture via the shell override above.\n const renderTargetTexture = this._createRenderTargetTextureInternal(width, height, color, depth, multiview) as WebXRLayerRenderTargetTexture;\n this._attachPerEyeClearObserver(renderTargetTexture);\n return renderTargetTexture;\n }\n\n /**\n * Ensures this render target is cleared every frame, including for the right eye.\n *\n * `Scene._clearFrameBuffer` skips clearing the right rig camera's framebuffer (`!camera.isRightCamera`).\n * That is a valid optimization for WebGL2 stereo, where both eyes render into a single side-by-side\n * texture and the left eye's full clear already covers the whole texture. WebGPU projection layers give\n * each eye its OWN render target (a distinct array layer rendered in a separate render pass), so the\n * right eye's color and — critically — depth would never be cleared, leaving its depth test to reject\n * every fragment (a black right eye). The scene notifies `onClearObservable` regardless of\n * `camera.isRightCamera`, so this observer clears both eyes' targets. WebGL providers never attach it,\n * so the WebGL path is unchanged.\n *\n * Color is cleared at most once per ENGINE FRAME, not once per `Scene.render`. The distinction matters:\n * more than one scene can render the same XR camera within a single XR frame. `UtilityLayerRenderer`\n * (used by controller pointer selection and near interaction) renders a second scene through the same\n * rig cameras, and every `Scene.render` resets `RenderTargetTexture._cleared` for those cameras' targets\n * (`Scene._checkCameraRenderTarget`), so a `_cleared`-based guard is defeated and each eye is re-cleared\n * after it was drawn — presenting a clear-colored frame with the geometry gone. `AbstractEngine.frameId`\n * only advances in `endFrame`, once per XR frame, so unlike `_cleared` it cannot be reset by another\n * scene rendering the same camera.\n *\n * In immersive AR, color is cleared to transparent when `WebXRExperienceHelper` disables\n * `Scene.autoClear`. WebGL XR framebuffers are cleared to transparent by the user agent, but WebGPU render\n * passes require the application to request that clear explicitly. Skipping it leaves pixels from prior\n * frames in passthrough regions, producing trails behind moving objects.\n *\n * Depth and stencil are still cleared on every notification, matching the previous behavior and the\n * expectations of overlay scenes that draw on top of the main scene.\n * @param renderTargetTexture the per-eye render target to clear each frame\n */\n private _attachPerEyeClearObserver(renderTargetTexture: RenderTargetTexture): void {\n let lastColorClearedFrameId = -1;\n renderTargetTexture.onClearObservable.add((engine) => {\n // Honor skipInitialClear so this observer preserves the default clear semantics it replaces.\n if (renderTargetTexture.skipInitialClear) {\n return;\n }\n const scene = renderTargetTexture.getScene();\n const isImmersiveAR = this._xrSessionManager.sessionMode === \"immersive-ar\";\n // When autoClear is disabled the scene does not clear render targets; match that so this observer\n // does not force a clear the user opted out of. Immersive AR is the exception: the experience\n // helper disables autoClear because WebGL XR is cleared by the user agent, while WebGPU is not.\n if (scene && !scene.autoClear && !isImmersiveAR) {\n return;\n }\n const clearColor = engine.frameId !== lastColorClearedFrameId;\n const color = isImmersiveAR && scene && !scene.autoClear ? this._transparentClearColor : (renderTargetTexture.clearColor ?? scene?.clearColor ?? null);\n engine.clear(color, clearColor, true, true);\n if (clearColor) {\n lastColorClearedFrameId = engine.frameId;\n }\n // Kept in sync so anything else reading the flag still sees this target as cleared this frame.\n renderTargetTexture._cleared = true;\n });\n }\n\n /**\n * Repoints the wrapped color/depth textures of an existing render target at the current frame's\n * GPUTextures, preserving the RenderTargetTexture / InternalTexture identity held by the XR camera's\n * `outputRenderTarget`. The sub-image textures are only valid for the current frame and may rotate from\n * a compositor pool, so this must run every frame. The new GPUTextures must have the same dimensions as\n * the wrapped ones (guaranteed by the caller's size-change branch, which rebuilds instead).\n * @param renderTargetTexture the render target whose wrapped textures should be repointed\n * @param colorTexture the current frame's color GPUTexture\n * @param depthStencilTexture the current frame's depth/stencil GPUTexture, if any\n */\n protected _updateRenderTargetTextureFromGPUTextures(renderTargetTexture: RenderTargetTexture, colorTexture: GPUTexture, depthStencilTexture: Nullable<GPUTexture>): void {\n const color = renderTargetTexture._texture;\n if (color) {\n this._webgpuEngine.updateWrappedWebGPUTexture(color, colorTexture);\n }\n const depth = renderTargetTexture.renderTarget?._depthStencilTexture;\n if (depth && depthStencilTexture) {\n this._webgpuEngine.updateWrappedWebGPUTexture(depth, depthStencilTexture);\n }\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onerjs/core",
3
- "version": "8.54.3",
3
+ "version": "8.54.5",
4
4
  "main": "index.js",
5
5
  "module": "index.js",
6
6
  "types": "index.d.ts",
package/scene.pure.d.ts CHANGED
@@ -1118,6 +1118,13 @@ export declare class Scene implements IAnimatable, IClipPlanesHolder, IAssetCont
1118
1118
  /** @internal */
1119
1119
  _pendingData: any[];
1120
1120
  private _isDisposed;
1121
+ /**
1122
+ * @internal
1123
+ * Set to true once scene disposal has begun (it stays true afterwards). Used so that resources released during
1124
+ * teardown (e.g. mesh effects) are freed immediately instead of being deferred to the next frame, which may never
1125
+ * happen once rendering stops.
1126
+ */
1127
+ _isDisposing: boolean;
1121
1128
  private _isReadyChecks;
1122
1129
  /**
1123
1130
  * Gets or sets a boolean indicating that all submeshes of active meshes must be rendered
package/scene.pure.js CHANGED
@@ -1321,6 +1321,13 @@ export class Scene {
1321
1321
  /** @internal */
1322
1322
  this._pendingData = [];
1323
1323
  this._isDisposed = false;
1324
+ /**
1325
+ * @internal
1326
+ * Set to true once scene disposal has begun (it stays true afterwards). Used so that resources released during
1327
+ * teardown (e.g. mesh effects) are freed immediately instead of being deferred to the next frame, which may never
1328
+ * happen once rendering stops.
1329
+ */
1330
+ this._isDisposing = false;
1324
1331
  this._isReadyChecks = [];
1325
1332
  /**
1326
1333
  * Gets or sets a boolean indicating that all submeshes of active meshes must be rendered
@@ -4635,6 +4642,7 @@ export class Scene {
4635
4642
  if (this.isDisposed) {
4636
4643
  return;
4637
4644
  }
4645
+ this._isDisposing = true;
4638
4646
  this.beforeRender = null;
4639
4647
  this.afterRender = null;
4640
4648
  this.metadata = null;