@babylonjs/core 6.7.0 → 6.8.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.
- package/Actions/abstractActionManager.js.map +1 -1
- package/Actions/action.js.map +1 -1
- package/Animations/animation.js.map +1 -1
- package/Animations/animationGroup.d.ts +5 -0
- package/Animations/animationGroup.js +12 -0
- package/Animations/animationGroup.js.map +1 -1
- package/Animations/easing.js.map +1 -1
- package/Audio/audioSceneComponent.js.map +1 -1
- package/Audio/sound.js.map +1 -1
- package/BakedVertexAnimation/bakedVertexAnimationManager.js.map +1 -1
- package/Behaviors/Cameras/bouncingBehavior.js.map +1 -1
- package/Behaviors/Cameras/framingBehavior.js.map +1 -1
- package/Behaviors/Meshes/fadeInOutBehavior.js.map +1 -1
- package/Behaviors/Meshes/pointerDragBehavior.js.map +1 -1
- package/Bones/bone.js.map +1 -1
- package/Bones/boneIKController.js.map +1 -1
- package/Bones/boneLookController.js.map +1 -1
- package/Buffers/dataBuffer.js.map +1 -1
- package/Cameras/Inputs/BaseCameraMouseWheelInput.js.map +1 -1
- package/Cameras/Inputs/BaseCameraPointersInput.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraGamepadInput.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraKeyboardMoveInput.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraMouseWheelInput.js.map +1 -1
- package/Cameras/Inputs/arcRotateCameraPointersInput.js.map +1 -1
- package/Cameras/Inputs/flyCameraKeyboardInput.js.map +1 -1
- package/Cameras/Inputs/flyCameraMouseInput.js.map +1 -1
- package/Cameras/Inputs/followCameraKeyboardMoveInput.js.map +1 -1
- package/Cameras/Inputs/followCameraMouseWheelInput.js.map +1 -1
- package/Cameras/Inputs/followCameraPointersInput.js.map +1 -1
- package/Cameras/Inputs/freeCameraGamepadInput.js.map +1 -1
- package/Cameras/Inputs/freeCameraKeyboardMoveInput.js.map +1 -1
- package/Cameras/Inputs/freeCameraMouseInput.js.map +1 -1
- package/Cameras/Inputs/freeCameraTouchInput.js.map +1 -1
- package/Cameras/VR/vrExperienceHelper.js.map +1 -1
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Cameras/camera.js.map +1 -1
- package/Cameras/flyCamera.js.map +1 -1
- package/Cameras/followCamera.js.map +1 -1
- package/Cameras/freeCamera.js.map +1 -1
- package/Cameras/targetCamera.js.map +1 -1
- package/Collisions/collider.js.map +1 -1
- package/Compute/computeEffect.js.map +1 -1
- package/Compute/computeShader.js +1 -5
- package/Compute/computeShader.js.map +1 -1
- package/Culling/Octrees/octree.js.map +1 -1
- package/Culling/boundingBox.js.map +1 -1
- package/Culling/boundingInfo.js.map +1 -1
- package/Culling/boundingSphere.js.map +1 -1
- package/Culling/ray.d.ts +7 -2
- package/Culling/ray.js +8 -3
- package/Culling/ray.js.map +1 -1
- package/Debug/debugLayer.js +1 -9
- package/Debug/debugLayer.js.map +1 -1
- package/Debug/skeletonViewer.js.map +1 -1
- package/Engines/Extensions/engine.cubeTexture.js +1 -6
- package/Engines/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/Extensions/engine.multiview.d.ts +6 -1
- package/Engines/Extensions/engine.multiview.js +27 -7
- package/Engines/Extensions/engine.multiview.js.map +1 -1
- package/Engines/Extensions/engine.renderTarget.js +1 -6
- package/Engines/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/Extensions/engine.renderTargetCube.js +1 -9
- package/Engines/Extensions/engine.renderTargetCube.js.map +1 -1
- package/Engines/Extensions/engine.webVR.js +1 -5
- package/Engines/Extensions/engine.webVR.js.map +1 -1
- package/Engines/Native/nativeInterfaces.d.ts +1 -0
- package/Engines/Native/nativeInterfaces.js.map +1 -1
- package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js +3 -0
- package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js.map +1 -1
- package/Engines/Processors/Expressions/shaderDefineExpression.d.ts +37 -0
- package/Engines/Processors/Expressions/shaderDefineExpression.js +57 -0
- package/Engines/Processors/Expressions/shaderDefineExpression.js.map +1 -1
- package/Engines/Processors/shaderCodeInliner.js.map +1 -1
- package/Engines/Processors/shaderProcessor.js +34 -14
- package/Engines/Processors/shaderProcessor.js.map +1 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.d.ts +19 -0
- package/Engines/WebGL/webGLRenderTargetWrapper.js +20 -1
- package/Engines/WebGL/webGLRenderTargetWrapper.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.cubeTexture.js +1 -7
- package/Engines/WebGPU/Extensions/engine.cubeTexture.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTarget.js +1 -8
- package/Engines/WebGPU/Extensions/engine.renderTarget.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.renderTargetCube.js +1 -10
- package/Engines/WebGPU/Extensions/engine.renderTargetCube.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheBindGroups.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheRenderPipeline.js.map +1 -1
- package/Engines/WebGPU/webgpuCacheSampler.js +1 -6
- package/Engines/WebGPU/webgpuCacheSampler.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
- package/Engines/WebGPU/webgpuTintWASM.js +1 -4
- package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
- package/Engines/engine.d.ts +8 -1
- package/Engines/engine.js.map +1 -1
- package/Engines/engineCapabilities.d.ts +2 -0
- package/Engines/engineCapabilities.js.map +1 -1
- package/Engines/nativeEngine.d.ts +2 -0
- package/Engines/nativeEngine.js +16 -0
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/nullEngine.js +1 -9
- package/Engines/nullEngine.js.map +1 -1
- package/Engines/thinEngine.js +7 -9
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +3 -14
- package/Engines/webgpuEngine.js.map +1 -1
- package/Gamepads/Controllers/gearVRController.js.map +1 -1
- package/Gamepads/Controllers/oculusTouchController.js.map +1 -1
- package/Gamepads/Controllers/poseEnabledController.js.map +1 -1
- package/Gamepads/Controllers/windowsMotionController.js.map +1 -1
- package/Gamepads/gamepad.js.map +1 -1
- package/Gizmos/cameraGizmo.js.map +1 -1
- package/Gizmos/gizmo.js.map +1 -1
- package/Gizmos/lightGizmo.js.map +1 -1
- package/Gizmos/planeRotationGizmo.js.map +1 -1
- package/Helpers/environmentHelper.js +2 -8
- package/Helpers/environmentHelper.js.map +1 -1
- package/Helpers/textureDome.js.map +1 -1
- package/Inputs/scene.inputManager.js +4 -1
- package/Inputs/scene.inputManager.js.map +1 -1
- package/Layers/effectLayer.js +1 -8
- package/Layers/effectLayer.js.map +1 -1
- package/Layers/glowLayer.js +1 -12
- package/Layers/glowLayer.js.map +1 -1
- package/Layers/highlightLayer.js +1 -11
- package/Layers/highlightLayer.js.map +1 -1
- package/Legacy/legacy.js +1 -1
- package/Legacy/legacy.js.map +1 -1
- package/LensFlares/lensFlareSystem.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.js +1 -4
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Lights/directionalLight.js.map +1 -1
- package/Lights/hemisphericLight.js.map +1 -1
- package/Lights/light.js.map +1 -1
- package/Lights/spotLight.js.map +1 -1
- package/Loading/loadingScreen.js.map +1 -1
- package/Loading/sceneLoader.d.ts +8 -8
- package/Loading/sceneLoader.js +35 -19
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +1 -1
- package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragmentOutputBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/perturbNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/clearCoatBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/refractionBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/sheenBlock.js.map +1 -1
- package/Materials/Node/Blocks/addBlock.js +2 -0
- package/Materials/Node/Blocks/addBlock.js.map +1 -1
- package/Materials/Node/Blocks/clampBlock.js.map +1 -1
- package/Materials/Node/Blocks/cloudBlock.js.map +1 -1
- package/Materials/Node/Blocks/customBlock.d.ts +1 -0
- package/Materials/Node/Blocks/customBlock.js +18 -2
- package/Materials/Node/Blocks/customBlock.js.map +1 -1
- package/Materials/Node/Blocks/divideBlock.js +2 -0
- package/Materials/Node/Blocks/divideBlock.js.map +1 -1
- package/Materials/Node/Blocks/meshAttributeExistsBlock.js.map +1 -1
- package/Materials/Node/Blocks/multiplyBlock.js +2 -0
- package/Materials/Node/Blocks/multiplyBlock.js.map +1 -1
- package/Materials/Node/Blocks/remapBlock.js.map +1 -1
- package/Materials/Node/Blocks/subtractBlock.js +2 -0
- package/Materials/Node/Blocks/subtractBlock.js.map +1 -1
- package/Materials/Node/Blocks/triPlanarBlock.js.map +1 -1
- package/Materials/Node/Blocks/worleyNoise3DBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.d.ts +6 -1
- package/Materials/Node/nodeMaterial.js +6 -10
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/PBR/pbrAnisotropicConfiguration.js.map +1 -1
- package/Materials/PBR/pbrBRDFConfiguration.js.map +1 -1
- package/Materials/PBR/pbrBaseMaterial.js +1 -5
- package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
- package/Materials/PBR/pbrBaseSimpleMaterial.js.map +1 -1
- package/Materials/PBR/pbrClearCoatConfiguration.js.map +1 -1
- package/Materials/PBR/pbrIridescenceConfiguration.js.map +1 -1
- package/Materials/PBR/pbrMaterial.d.ts +2 -1
- package/Materials/PBR/pbrMaterial.js +6 -13
- package/Materials/PBR/pbrMaterial.js.map +1 -1
- package/Materials/PBR/pbrMetallicRoughnessMaterial.js.map +1 -1
- package/Materials/PBR/pbrSheenConfiguration.js.map +1 -1
- package/Materials/PBR/pbrSpecularGlossinessMaterial.js.map +1 -1
- package/Materials/PBR/pbrSubSurfaceConfiguration.js.map +1 -1
- package/Materials/Textures/Procedurals/proceduralTexture.js.map +1 -1
- package/Materials/Textures/baseTexture.js.map +1 -1
- package/Materials/Textures/cubeTexture.js.map +1 -1
- package/Materials/Textures/equiRectangularCubeTexture.js.map +1 -1
- package/Materials/Textures/hdrCubeTexture.js.map +1 -1
- package/Materials/Textures/htmlElementTexture.js +1 -4
- package/Materials/Textures/htmlElementTexture.js.map +1 -1
- package/Materials/Textures/internalTexture.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/Textures/videoTexture.js +9 -22
- package/Materials/Textures/videoTexture.js.map +1 -1
- package/Materials/colorCurves.js.map +1 -1
- package/Materials/effect.js.map +1 -1
- package/Materials/greasedLinePluginMaterial.d.ts +307 -0
- package/Materials/greasedLinePluginMaterial.js +553 -0
- package/Materials/greasedLinePluginMaterial.js.map +1 -0
- package/Materials/imageProcessingConfiguration.js.map +1 -1
- package/Materials/index.d.ts +1 -0
- package/Materials/index.js +1 -0
- package/Materials/index.js.map +1 -1
- package/Materials/material.d.ts +3 -0
- package/Materials/material.decalMapConfiguration.js.map +1 -1
- package/Materials/material.detailMapConfiguration.js.map +1 -1
- package/Materials/material.js +40 -5
- package/Materials/material.js.map +1 -1
- package/Materials/materialPluginBase.d.ts +2 -2
- package/Materials/materialPluginBase.js +2 -2
- package/Materials/materialPluginBase.js.map +1 -1
- package/Materials/materialPluginManager.d.ts +3 -2
- package/Materials/materialPluginManager.js +3 -1
- package/Materials/materialPluginManager.js.map +1 -1
- package/Materials/multiMaterial.js +1 -1
- package/Materials/multiMaterial.js.map +1 -1
- package/Materials/shaderMaterial.d.ts +23 -4
- package/Materials/shaderMaterial.js +41 -21
- package/Materials/shaderMaterial.js.map +1 -1
- package/Materials/standardMaterial.d.ts +2 -1
- package/Materials/standardMaterial.js +4 -1
- package/Materials/standardMaterial.js.map +1 -1
- package/Materials/uniformBuffer.js.map +1 -1
- package/Maths/math.vector.d.ts +2 -1
- package/Maths/math.vector.js +3 -2
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/Builders/decalBuilder.js +4 -4
- package/Meshes/Builders/decalBuilder.js.map +1 -1
- package/Meshes/Builders/greasedLineBuilder.d.ts +105 -0
- package/Meshes/Builders/greasedLineBuilder.js +330 -0
- package/Meshes/Builders/greasedLineBuilder.js.map +1 -0
- package/Meshes/Builders/index.d.ts +1 -0
- package/Meshes/Builders/index.js +1 -0
- package/Meshes/Builders/index.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +3 -2
- package/Meshes/abstractMesh.js +5 -3
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/greasedLineMesh.d.ts +189 -0
- package/Meshes/greasedLineMesh.js +437 -0
- package/Meshes/greasedLineMesh.js.map +1 -0
- package/Meshes/index.d.ts +1 -0
- package/Meshes/index.js +1 -0
- package/Meshes/index.js.map +1 -1
- package/Meshes/mesh.d.ts +4 -0
- package/Meshes/mesh.js +20 -10
- package/Meshes/mesh.js.map +1 -1
- package/Meshes/mesh.vertexData.js.map +1 -1
- package/Meshes/meshUVSpaceRenderer.js +1 -8
- package/Meshes/meshUVSpaceRenderer.js.map +1 -1
- package/Meshes/transformNode.js.map +1 -1
- package/Misc/basis.js.map +1 -1
- package/Misc/deepCopier.js +8 -2
- package/Misc/deepCopier.js.map +1 -1
- package/Misc/dumpTools.d.ts +4 -3
- package/Misc/dumpTools.js +5 -4
- package/Misc/dumpTools.js.map +1 -1
- package/Misc/environmentTextureTools.js +1 -1
- package/Misc/environmentTextureTools.js.map +1 -1
- package/Misc/fileTools.js +10 -10
- package/Misc/fileTools.js.map +1 -1
- package/Misc/greasedLineTools.d.ts +141 -0
- package/Misc/greasedLineTools.js +263 -0
- package/Misc/greasedLineTools.js.map +1 -0
- package/Misc/index.d.ts +1 -0
- package/Misc/index.js +1 -0
- package/Misc/index.js.map +1 -1
- package/Misc/khronosTextureContainer.js.map +1 -1
- package/Misc/observable.d.ts +11 -0
- package/Misc/observable.js +26 -1
- package/Misc/observable.js.map +1 -1
- package/Misc/sceneOptimizer.js.map +1 -1
- package/Misc/screenshotTools.d.ts +15 -5
- package/Misc/screenshotTools.js +23 -13
- package/Misc/screenshotTools.js.map +1 -1
- package/Misc/smartArray.js.map +1 -1
- package/Misc/tools.d.ts +21 -9
- package/Misc/tools.js +21 -9
- package/Misc/tools.js.map +1 -1
- package/Misc/videoRecorder.js +1 -4
- package/Misc/videoRecorder.js.map +1 -1
- package/Misc/virtualJoystick.js +1 -4
- package/Misc/virtualJoystick.js.map +1 -1
- package/Misc/webRequest.js.map +1 -1
- package/Morph/morphTarget.js.map +1 -1
- package/Morph/morphTargetManager.js.map +1 -1
- package/Offline/database.js.map +1 -1
- package/Particles/baseParticleSystem.js.map +1 -1
- package/Particles/gpuParticleSystem.d.ts +1 -0
- package/Particles/gpuParticleSystem.js +5 -8
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particle.js.map +1 -1
- package/Particles/particleSystem.js +1 -1
- package/Particles/particleSystem.js.map +1 -1
- package/Particles/particleSystemSet.js.map +1 -1
- package/Physics/physicsHelper.js +4 -4
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/physicsRaycastResult.d.ts +3 -1
- package/Physics/physicsRaycastResult.js +10 -1
- package/Physics/physicsRaycastResult.js.map +1 -1
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
- package/Physics/v1/physicsImpostor.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +10 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +3 -2
- package/Physics/v2/Plugins/havokPlugin.js +9 -6
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/defaultRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssaoRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/standardRenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
- package/PostProcesses/blackAndWhitePostProcess.js.map +1 -1
- package/PostProcesses/bloomMergePostProcess.js.map +1 -1
- package/PostProcesses/blurPostProcess.js.map +1 -1
- package/PostProcesses/circleOfConfusionPostProcess.js.map +1 -1
- package/PostProcesses/colorCorrectionPostProcess.js.map +1 -1
- package/PostProcesses/convolutionPostProcess.js.map +1 -1
- package/PostProcesses/depthOfFieldBlurPostProcess.js.map +1 -1
- package/PostProcesses/extractHighlightsPostProcess.js.map +1 -1
- package/PostProcesses/filterPostProcess.js.map +1 -1
- package/PostProcesses/grainPostProcess.js.map +1 -1
- package/PostProcesses/imageProcessingPostProcess.js.map +1 -1
- package/PostProcesses/motionBlurPostProcess.js.map +1 -1
- package/PostProcesses/postProcess.js.map +1 -1
- package/PostProcesses/refractionPostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
- package/PostProcesses/sharpenPostProcess.js.map +1 -1
- package/PostProcesses/volumetricLightScatteringPostProcess.js.map +1 -1
- package/Probes/reflectionProbe.js.map +1 -1
- package/Rendering/boundingBoxRenderer.js +2 -4
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Rendering/depthPeelingRenderer.js.map +1 -1
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/outlineRenderer.js.map +1 -1
- package/Rendering/prePassRenderer.js.map +1 -1
- package/Rendering/renderingGroup.js.map +1 -1
- package/Rendering/renderingManager.js.map +1 -1
- package/Rendering/subSurfaceConfiguration.js.map +1 -1
- package/Rendering/utilityLayerRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.js +4 -2
- package/Shaders/ShadersInclude/pbrBlockAlbedoOpacity.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDebug.js +11 -2
- package/Shaders/ShadersInclude/pbrDebug.js.map +1 -1
- package/Shaders/velocity.fragment.d.ts +5 -0
- package/Shaders/velocity.fragment.js +13 -0
- package/Shaders/velocity.fragment.js.map +1 -0
- package/Shaders/velocity.vertex.d.ts +7 -0
- package/Shaders/velocity.vertex.js +23 -0
- package/Shaders/velocity.vertex.js.map +1 -0
- package/Sprites/spriteManager.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.js.map +1 -1
- package/XR/features/WebXRBackgroundRemover.js.map +1 -1
- package/XR/features/WebXRControllerMovement.js.map +1 -1
- package/XR/features/WebXRControllerPhysics.js +4 -13
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
- package/XR/features/WebXRControllerTeleportation.js.map +1 -1
- package/XR/features/WebXRDOMOverlay.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/features/WebXREyeTracking.js.map +1 -1
- package/XR/features/WebXRFeaturePointSystem.js.map +1 -1
- package/XR/features/WebXRHandTracking.js +2 -8
- package/XR/features/WebXRHandTracking.js.map +1 -1
- package/XR/features/WebXRHitTest.js.map +1 -1
- package/XR/features/WebXRHitTestLegacy.js.map +1 -1
- package/XR/features/WebXRImageTracking.js.map +1 -1
- package/XR/features/WebXRLayers.js +18 -8
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRLightEstimation.js.map +1 -1
- package/XR/features/WebXRMeshDetector.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/features/WebXRPlaneDetector.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.d.ts +138 -0
- package/XR/features/WebXRSpaceWarp.js +290 -0
- package/XR/features/WebXRSpaceWarp.js.map +1 -0
- package/XR/features/index.d.ts +1 -0
- package/XR/features/index.js +1 -0
- package/XR/features/index.js.map +1 -1
- package/XR/motionController/webXRAbstractMotionController.js +1 -4
- package/XR/motionController/webXRAbstractMotionController.js.map +1 -1
- package/XR/motionController/webXRControllerComponent.js.map +1 -1
- package/XR/motionController/webXRGenericMotionController.js.map +1 -1
- package/XR/motionController/webXRHTCViveMotionController.js.map +1 -1
- package/XR/motionController/webXRMicrosoftMixedRealityController.js.map +1 -1
- package/XR/motionController/webXROculusTouchMotionController.js.map +1 -1
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXRDefaultExperience.js +6 -28
- package/XR/webXRDefaultExperience.js.map +1 -1
- package/XR/webXRFeaturesManager.d.ts +4 -0
- package/XR/webXRFeaturesManager.js +5 -4
- package/XR/webXRFeaturesManager.js.map +1 -1
- package/XR/webXRInput.js +1 -6
- package/XR/webXRInput.js.map +1 -1
- package/XR/webXRSessionManager.d.ts +4 -0
- package/XR/webXRSessionManager.js +6 -0
- package/XR/webXRSessionManager.js.map +1 -1
- package/abstractScene.js.map +1 -1
- package/assetContainer.js +1 -4
- package/assetContainer.js.map +1 -1
- package/node.js.map +1 -1
- package/package.json +2 -4
- package/scene.d.ts +5 -2
- package/scene.js +9 -12
- package/scene.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeEffect.js","sourceRoot":"","sources":["../../../../lts/core/generated/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IAAI,CAAC","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IComputePipelineContext } from \"./IComputePipelineContext\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\ndeclare type Engine = import(\"../Engines/engine\").Engine;\r\n\r\n/**\r\n * Options to be used when creating a compute effect.\r\n */\r\nexport interface IComputeEffectCreationOptions {\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: ComputeEffect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: ComputeEffect, errors: string) => void>;\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\n/**\r\n * Effect wrapping a compute shader and let execute (dispatch) the shader\r\n */\r\nexport class ComputeEffect {\r\n private static _UniqueIdSeed = 0;\r\n\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: any = null;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public onBindObservable = new Observable<ComputeEffect>();\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n private _engine: Engine;\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n /** @internal */\r\n public _key: string = \"\";\r\n private _computeSourceCodeOverride: string = \"\";\r\n /** @internal */\r\n public _pipelineContext: Nullable<IComputePipelineContext> = null;\r\n /** @internal */\r\n public _computeSourceCode: string = \"\";\r\n private _rawComputeSourceCode: string = \"\";\r\n private _entryPoint: string;\r\n private _shaderLanguage = ShaderLanguage.WGSL;\r\n private _shaderStore: { [key: string]: string };\r\n private _shaderRepository: string;\r\n private _includeShaderStore: { [key: string]: string };\r\n\r\n /**\r\n * Creates a compute effect that can be used to execute a compute shader\r\n * @param baseName Name of the effect\r\n * @param options Set of all options to create the effect\r\n * @param engine The engine the effect is created for\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n */\r\n constructor(baseName: any, options: IComputeEffectCreationOptions, engine: Engine, key = \"\") {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n this._engine = engine;\r\n this.uniqueId = ComputeEffect._UniqueIdSeed++;\r\n\r\n this.defines = options.defines ?? \"\";\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._entryPoint = options.entryPoint ?? \"main\";\r\n\r\n this._shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\r\n this._shaderRepository = ShaderStore.GetShadersRepository(this._shaderLanguage);\r\n this._includeShaderStore = ShaderStore.GetIncludesShadersStore(this._shaderLanguage);\r\n\r\n let computeSource: any;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (baseName.computeSource) {\r\n computeSource = \"source:\" + baseName.computeSource;\r\n } else if (baseName.computeElement) {\r\n computeSource = hostDocument ? hostDocument.getElementById(baseName.computeElement) : null;\r\n\r\n if (!computeSource) {\r\n computeSource = baseName.computeElement;\r\n }\r\n } else {\r\n computeSource = baseName.compute || baseName;\r\n }\r\n\r\n const processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: undefined,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: false,\r\n processor: null,\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: this._shaderRepository,\r\n includesShadersStore: this._includeShaderStore,\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: null,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n };\r\n\r\n this._loadShader(computeSource, \"Compute\", \"\", (computeCode) => {\r\n ShaderProcessor.Initialize(processorOptions);\r\n ShaderProcessor.PreProcess(\r\n computeCode,\r\n processorOptions,\r\n (migratedCommputeCode) => {\r\n this._rawComputeSourceCode = computeCode;\r\n if (options.processFinalCode) {\r\n migratedCommputeCode = options.processFinalCode(migratedCommputeCode);\r\n }\r\n const finalShaders = ShaderProcessor.Finalize(migratedCommputeCode, \"\", processorOptions);\r\n this._useFinalCode(finalShaders.vertexCode, baseName);\r\n },\r\n this._engine\r\n );\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedCommputeCode: string, baseName: any) {\r\n if (baseName) {\r\n const compute = baseName.computeElement || baseName.compute || baseName.spectorName || baseName;\r\n\r\n this._computeSourceCode = \"//#define SHADER_NAME compute:\" + compute + \"\\n\" + migratedCommputeCode;\r\n } else {\r\n this._computeSourceCode = migratedCommputeCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable<IComputePipelineContext> {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: ComputeEffect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable<IComputePipelineContext>) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n // Is in local store ?\r\n if (this._shaderStore[shader + key + \"Shader\"]) {\r\n callback(this._shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && this._shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(this._shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = this._shaderRepository + shader;\r\n }\r\n\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code of this effect\r\n */\r\n public get computeSourceCode(): string {\r\n return this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._pipelineContext?._getComputeShaderCode() ?? this._computeSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code before it has been processed by the preprocessor\r\n */\r\n public get rawComputeSourceCode(): string {\r\n return this._rawComputeSourceCode;\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createComputePipelineContext();\r\n this._pipelineContext._name = this._key;\r\n\r\n engine._prepareComputePipelineContext(\r\n this._pipelineContext,\r\n this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._computeSourceCode,\r\n this._rawComputeSourceCode,\r\n this._computeSourceCodeOverride ? null : defines,\r\n this._entryPoint\r\n );\r\n\r\n engine._executeWhenComputeStateIsCompiled(this._pipelineContext, () => {\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deleteComputePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _getShaderCodeAndErrorLine(code: Nullable<string>, error: Nullable<string>): [Nullable<string>, Nullable<string>] {\r\n const regexp = /COMPUTE SHADER ERROR: 0:(\\d+?):/;\r\n\r\n let errorLine = null;\r\n\r\n if (error && code) {\r\n const res = error.match(regexp);\r\n if (res && res.length === 2) {\r\n const lineNumber = parseInt(res[1]);\r\n const lines = code.split(\"\\n\", -1);\r\n if (lines.length >= lineNumber) {\r\n errorLine = `Offending line [${lineNumber}] in compute code: ${lines[lineNumber - 1]}`;\r\n }\r\n }\r\n }\r\n\r\n return [code, errorLine];\r\n }\r\n\r\n private _processCompilationErrors(e: any, previousPipelineContext: Nullable<IComputePipelineContext> = null) {\r\n this._compilationError = e.message;\r\n\r\n // Let's go through fallbacks then\r\n Logger.Error(\"Unable to compile compute effect:\");\r\n Logger.Error(\"Defines:\\r\\n\" + this.defines);\r\n if (ComputeEffect.LogShaderCodeOnCompilationError) {\r\n let lineErrorVertex = null,\r\n code = null;\r\n if (this._pipelineContext?._getComputeShaderCode()) {\r\n [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(this._pipelineContext._getComputeShaderCode(), this._compilationError);\r\n if (code) {\r\n Logger.Error(\"Compute code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n if (lineErrorVertex) {\r\n Logger.Error(lineErrorVertex);\r\n }\r\n }\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseComputeEffect(this);\r\n }\r\n\r\n /**\r\n * This function will add a new compute shader to the shader store\r\n * @param name the name of the shader\r\n * @param computeShader compute shader content\r\n */\r\n public static RegisterShader(name: string, computeShader: string) {\r\n ShaderStore.GetShadersStore(ShaderLanguage.WGSL)[`${name}ComputeShader`] = computeShader;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"computeEffect.js","sourceRoot":"","sources":["../../../../lts/core/generated/Compute/computeEffect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AA8B7D;;GAEG;AACH,MAAM,OAAO,aAAa;IAgEtB;;;;;;OAMG;IACH,YAAY,QAAa,EAAE,OAAsC,EAAE,MAAc,EAAE,GAAG,GAAG,EAAE;;QAhE3F;;WAEG;QACI,SAAI,GAAQ,IAAI,CAAC;QACxB;;WAEG;QACI,YAAO,GAAW,EAAE,CAAC;QAC5B;;WAEG;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GAAG,IAAI,CAAC;YACrB,IAAI,IAAI,CAAC,OAAO,EAAE;gBACd,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;aAC9C;YACD,IAAI,CAAC,iBAAiB,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;SAChD;IACL,CAAC;IAED;;QAEI;IACG,OAAO;QACV,IAAI,IAAI,CAAC,gBAAgB,EAAE;YACvB,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC;SACnC;QACD,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,cAAc,CAAC,IAAY,EAAE,aAAqB;QAC5D,WAAW,CAAC,eAAe,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI,eAAe,CAAC,GAAG,aAAa,CAAC;IAC7F,CAAC;;AAzZc,2BAAa,GAAG,CAAC,AAAJ,CAAK;AAEjC;;GAEG;AACW,6CAA+B,GAAG,IAAI,AAAP,CAAQ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport type { Nullable } from \"../types\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { IComputePipelineContext } from \"./IComputePipelineContext\";\r\nimport { GetDOMTextContent, IsWindowObjectExist } from \"../Misc/domManagement\";\r\nimport { ShaderProcessor } from \"../Engines/Processors/shaderProcessor\";\r\nimport type { ProcessingOptions } from \"../Engines/Processors/shaderProcessingOptions\";\r\nimport { ShaderStore } from \"../Engines/shaderStore\";\r\nimport { ShaderLanguage } from \"../Materials/shaderLanguage\";\r\n\r\ndeclare type Engine = import(\"../Engines/engine\").Engine;\r\n\r\n/**\r\n * Options to be used when creating a compute effect.\r\n */\r\nexport interface IComputeEffectCreationOptions {\r\n /**\r\n * Define statements that will be set in the shader.\r\n */\r\n defines: any;\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n onCompiled: Nullable<(effect: ComputeEffect) => void>;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n onError: Nullable<(effect: ComputeEffect, errors: string) => void>;\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\n/**\r\n * Effect wrapping a compute shader and let execute (dispatch) the shader\r\n */\r\nexport class ComputeEffect {\r\n private static _UniqueIdSeed = 0;\r\n\r\n /**\r\n * Enable logging of the shader code when a compilation error occurs\r\n */\r\n public static LogShaderCodeOnCompilationError = true;\r\n /**\r\n * Name of the effect.\r\n */\r\n public name: any = null;\r\n /**\r\n * String container all the define statements that should be set on the shader.\r\n */\r\n public defines: string = \"\";\r\n /**\r\n * Callback that will be called when the shader is compiled.\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n /**\r\n * Callback that will be called if an error occurs during shader compilation.\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n /**\r\n * Unique ID of the effect.\r\n */\r\n public uniqueId = 0;\r\n /**\r\n * Observable that will be called when the shader is compiled.\r\n * It is recommended to use executeWhenCompile() or to make sure that scene.isReady() is called to get this observable raised.\r\n */\r\n public onCompileObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called if an error occurs during shader compilation.\r\n */\r\n public onErrorObservable = new Observable<ComputeEffect>();\r\n /**\r\n * Observable that will be called when effect is bound.\r\n */\r\n public onBindObservable = new Observable<ComputeEffect>();\r\n\r\n /**\r\n * @internal\r\n * Specifies if the effect was previously ready\r\n */\r\n public _wasPreviouslyReady = false;\r\n\r\n private _engine: Engine;\r\n private _isReady = false;\r\n private _compilationError = \"\";\r\n /** @internal */\r\n public _key: string = \"\";\r\n private _computeSourceCodeOverride: string = \"\";\r\n /** @internal */\r\n public _pipelineContext: Nullable<IComputePipelineContext> = null;\r\n /** @internal */\r\n public _computeSourceCode: string = \"\";\r\n private _rawComputeSourceCode: string = \"\";\r\n private _entryPoint: string;\r\n private _shaderLanguage = ShaderLanguage.WGSL;\r\n private _shaderStore: { [key: string]: string };\r\n private _shaderRepository: string;\r\n private _includeShaderStore: { [key: string]: string };\r\n\r\n /**\r\n * Creates a compute effect that can be used to execute a compute shader\r\n * @param baseName Name of the effect\r\n * @param options Set of all options to create the effect\r\n * @param engine The engine the effect is created for\r\n * @param key Effect Key identifying uniquely compiled shader variants\r\n */\r\n constructor(baseName: any, options: IComputeEffectCreationOptions, engine: Engine, key = \"\") {\r\n this.name = baseName;\r\n this._key = key;\r\n\r\n this._engine = engine;\r\n this.uniqueId = ComputeEffect._UniqueIdSeed++;\r\n\r\n this.defines = options.defines ?? \"\";\r\n this.onError = options.onError;\r\n this.onCompiled = options.onCompiled;\r\n this._entryPoint = options.entryPoint ?? \"main\";\r\n\r\n this._shaderStore = ShaderStore.GetShadersStore(this._shaderLanguage);\r\n this._shaderRepository = ShaderStore.GetShadersRepository(this._shaderLanguage);\r\n this._includeShaderStore = ShaderStore.GetIncludesShadersStore(this._shaderLanguage);\r\n\r\n let computeSource: any;\r\n\r\n const hostDocument = IsWindowObjectExist() ? this._engine.getHostDocument() : null;\r\n\r\n if (baseName.computeSource) {\r\n computeSource = \"source:\" + baseName.computeSource;\r\n } else if (baseName.computeElement) {\r\n computeSource = hostDocument ? hostDocument.getElementById(baseName.computeElement) : null;\r\n\r\n if (!computeSource) {\r\n computeSource = baseName.computeElement;\r\n }\r\n } else {\r\n computeSource = baseName.compute || baseName;\r\n }\r\n\r\n const processorOptions: ProcessingOptions = {\r\n defines: this.defines.split(\"\\n\"),\r\n indexParameters: undefined,\r\n isFragment: false,\r\n shouldUseHighPrecisionShader: false,\r\n processor: null,\r\n supportsUniformBuffers: this._engine.supportsUniformBuffers,\r\n shadersRepository: this._shaderRepository,\r\n includesShadersStore: this._includeShaderStore,\r\n version: (this._engine.version * 100).toString(),\r\n platformName: this._engine.shaderPlatformName,\r\n processingContext: null,\r\n isNDCHalfZRange: this._engine.isNDCHalfZRange,\r\n useReverseDepthBuffer: this._engine.useReverseDepthBuffer,\r\n };\r\n\r\n this._loadShader(computeSource, \"Compute\", \"\", (computeCode) => {\r\n ShaderProcessor.Initialize(processorOptions);\r\n ShaderProcessor.PreProcess(\r\n computeCode,\r\n processorOptions,\r\n (migratedCommputeCode) => {\r\n this._rawComputeSourceCode = computeCode;\r\n if (options.processFinalCode) {\r\n migratedCommputeCode = options.processFinalCode(migratedCommputeCode);\r\n }\r\n const finalShaders = ShaderProcessor.Finalize(migratedCommputeCode, \"\", processorOptions);\r\n this._useFinalCode(finalShaders.vertexCode, baseName);\r\n },\r\n this._engine\r\n );\r\n });\r\n }\r\n\r\n private _useFinalCode(migratedCommputeCode: string, baseName: any) {\r\n if (baseName) {\r\n const compute = baseName.computeElement || baseName.compute || baseName.spectorName || baseName;\r\n\r\n this._computeSourceCode = \"//#define SHADER_NAME compute:\" + compute + \"\\n\" + migratedCommputeCode;\r\n } else {\r\n this._computeSourceCode = migratedCommputeCode;\r\n }\r\n this._prepareEffect();\r\n }\r\n\r\n /**\r\n * Unique key for this effect\r\n */\r\n public get key(): string {\r\n return this._key;\r\n }\r\n\r\n /**\r\n * If the effect has been compiled and prepared.\r\n * @returns if the effect is compiled and prepared.\r\n */\r\n public isReady(): boolean {\r\n try {\r\n return this._isReadyInternal();\r\n } catch {\r\n return false;\r\n }\r\n }\r\n\r\n private _isReadyInternal(): boolean {\r\n if (this._isReady) {\r\n return true;\r\n }\r\n if (this._pipelineContext) {\r\n return this._pipelineContext.isReady;\r\n }\r\n return false;\r\n }\r\n\r\n /**\r\n * The engine the effect was initialized with.\r\n * @returns the engine.\r\n */\r\n public getEngine(): Engine {\r\n return this._engine;\r\n }\r\n\r\n /**\r\n * The pipeline context for this effect\r\n * @returns the associated pipeline context\r\n */\r\n public getPipelineContext(): Nullable<IComputePipelineContext> {\r\n return this._pipelineContext;\r\n }\r\n\r\n /**\r\n * The error from the last compilation.\r\n * @returns the error string.\r\n */\r\n public getCompilationError(): string {\r\n return this._compilationError;\r\n }\r\n\r\n /**\r\n * Adds a callback to the onCompiled observable and call the callback immediately if already ready.\r\n * @param func The callback to be used.\r\n */\r\n public executeWhenCompiled(func: (effect: ComputeEffect) => void): void {\r\n if (this.isReady()) {\r\n func(this);\r\n return;\r\n }\r\n\r\n this.onCompileObservable.add((effect) => {\r\n func(effect);\r\n });\r\n\r\n if (!this._pipelineContext || this._pipelineContext.isAsync) {\r\n setTimeout(() => {\r\n this._checkIsReady(null);\r\n }, 16);\r\n }\r\n }\r\n\r\n private _checkIsReady(previousPipelineContext: Nullable<IComputePipelineContext>) {\r\n try {\r\n if (this._isReadyInternal()) {\r\n return;\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n return;\r\n }\r\n\r\n setTimeout(() => {\r\n this._checkIsReady(previousPipelineContext);\r\n }, 16);\r\n }\r\n\r\n private _loadShader(shader: any, key: string, optionalKey: string, callback: (data: any) => void): void {\r\n if (typeof HTMLElement !== \"undefined\") {\r\n // DOM element ?\r\n if (shader instanceof HTMLElement) {\r\n const shaderCode = GetDOMTextContent(shader);\r\n callback(shaderCode);\r\n return;\r\n }\r\n }\r\n\r\n // Direct source ?\r\n if (shader.substr(0, 7) === \"source:\") {\r\n callback(shader.substr(7));\r\n return;\r\n }\r\n\r\n // Base64 encoded ?\r\n if (shader.substr(0, 7) === \"base64:\") {\r\n const shaderBinary = window.atob(shader.substr(7));\r\n callback(shaderBinary);\r\n return;\r\n }\r\n\r\n // Is in local store ?\r\n if (this._shaderStore[shader + key + \"Shader\"]) {\r\n callback(this._shaderStore[shader + key + \"Shader\"]);\r\n return;\r\n }\r\n\r\n if (optionalKey && this._shaderStore[shader + optionalKey + \"Shader\"]) {\r\n callback(this._shaderStore[shader + optionalKey + \"Shader\"]);\r\n return;\r\n }\r\n\r\n let shaderUrl;\r\n\r\n if (shader[0] === \".\" || shader[0] === \"/\" || shader.indexOf(\"http\") > -1) {\r\n shaderUrl = shader;\r\n } else {\r\n shaderUrl = this._shaderRepository + shader;\r\n }\r\n\r\n this._engine._loadFile(shaderUrl + \".\" + key.toLowerCase() + \".fx\", callback);\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code of this effect\r\n */\r\n public get computeSourceCode(): string {\r\n return this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._pipelineContext?._getComputeShaderCode() ?? this._computeSourceCode;\r\n }\r\n\r\n /**\r\n * Gets the compute shader source code before it has been processed by the preprocessor\r\n */\r\n public get rawComputeSourceCode(): string {\r\n return this._rawComputeSourceCode;\r\n }\r\n\r\n /**\r\n * Prepares the effect\r\n * @internal\r\n */\r\n public _prepareEffect() {\r\n const defines = this.defines;\r\n\r\n const previousPipelineContext = this._pipelineContext;\r\n\r\n this._isReady = false;\r\n\r\n try {\r\n const engine = this._engine;\r\n\r\n this._pipelineContext = engine.createComputePipelineContext();\r\n this._pipelineContext._name = this._key;\r\n\r\n engine._prepareComputePipelineContext(\r\n this._pipelineContext,\r\n this._computeSourceCodeOverride ? this._computeSourceCodeOverride : this._computeSourceCode,\r\n this._rawComputeSourceCode,\r\n this._computeSourceCodeOverride ? null : defines,\r\n this._entryPoint\r\n );\r\n\r\n engine._executeWhenComputeStateIsCompiled(this._pipelineContext, () => {\r\n this._compilationError = \"\";\r\n this._isReady = true;\r\n if (this.onCompiled) {\r\n this.onCompiled(this);\r\n }\r\n this.onCompileObservable.notifyObservers(this);\r\n this.onCompileObservable.clear();\r\n\r\n if (previousPipelineContext) {\r\n this.getEngine()._deleteComputePipelineContext(previousPipelineContext);\r\n }\r\n });\r\n\r\n if (this._pipelineContext.isAsync) {\r\n this._checkIsReady(previousPipelineContext);\r\n }\r\n } catch (e) {\r\n this._processCompilationErrors(e, previousPipelineContext);\r\n }\r\n }\r\n\r\n private _getShaderCodeAndErrorLine(code: Nullable<string>, error: Nullable<string>): [Nullable<string>, Nullable<string>] {\r\n const regexp = /COMPUTE SHADER ERROR: 0:(\\d+?):/;\r\n\r\n let errorLine = null;\r\n\r\n if (error && code) {\r\n const res = error.match(regexp);\r\n if (res && res.length === 2) {\r\n const lineNumber = parseInt(res[1]);\r\n const lines = code.split(\"\\n\", -1);\r\n if (lines.length >= lineNumber) {\r\n errorLine = `Offending line [${lineNumber}] in compute code: ${lines[lineNumber - 1]}`;\r\n }\r\n }\r\n }\r\n\r\n return [code, errorLine];\r\n }\r\n\r\n private _processCompilationErrors(e: any, previousPipelineContext: Nullable<IComputePipelineContext> = null) {\r\n this._compilationError = e.message;\r\n\r\n // Let's go through fallbacks then\r\n Logger.Error(\"Unable to compile compute effect:\");\r\n Logger.Error(\"Defines:\\r\\n\" + this.defines);\r\n if (ComputeEffect.LogShaderCodeOnCompilationError) {\r\n let lineErrorVertex = null,\r\n code = null;\r\n if (this._pipelineContext?._getComputeShaderCode()) {\r\n [code, lineErrorVertex] = this._getShaderCodeAndErrorLine(this._pipelineContext._getComputeShaderCode(), this._compilationError);\r\n if (code) {\r\n Logger.Error(\"Compute code:\");\r\n Logger.Error(code);\r\n }\r\n }\r\n if (lineErrorVertex) {\r\n Logger.Error(lineErrorVertex);\r\n }\r\n }\r\n Logger.Error(\"Error: \" + this._compilationError);\r\n if (previousPipelineContext) {\r\n this._pipelineContext = previousPipelineContext;\r\n this._isReady = true;\r\n if (this.onError) {\r\n this.onError(this, this._compilationError);\r\n }\r\n this.onErrorObservable.notifyObservers(this);\r\n }\r\n }\r\n\r\n /**\r\n * Release all associated resources.\r\n **/\r\n public dispose() {\r\n if (this._pipelineContext) {\r\n this._pipelineContext.dispose();\r\n }\r\n this._engine._releaseComputeEffect(this);\r\n }\r\n\r\n /**\r\n * This function will add a new compute shader to the shader store\r\n * @param name the name of the shader\r\n * @param computeShader compute shader content\r\n */\r\n public static RegisterShader(name: string, computeShader: string) {\r\n ShaderStore.GetShadersStore(ShaderLanguage.WGSL)[`${name}ComputeShader`] = computeShader;\r\n }\r\n}\r\n"]}
|
package/Compute/computeShader.js
CHANGED
|
@@ -58,11 +58,7 @@ export class ComputeShader {
|
|
|
58
58
|
}
|
|
59
59
|
this._context = engine.createComputeContext();
|
|
60
60
|
this._shaderPath = shaderPath;
|
|
61
|
-
this._options = {
|
|
62
|
-
bindingsMapping: {},
|
|
63
|
-
defines: [],
|
|
64
|
-
...options,
|
|
65
|
-
};
|
|
61
|
+
this._options = Object.assign({ bindingsMapping: {}, defines: [] }, options);
|
|
66
62
|
}
|
|
67
63
|
/**
|
|
68
64
|
* Gets the current class name of the material e.g. "ComputeShader"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../lts/core/generated/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AAgCtE;;GAEG;AACH,MAAM,OAAO,aAAa;IAsBtB;;OAEG;IACH,IAAW,OAAO;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,WAAW,CAAC;IAC5B,CAAC;IAYD;;;;;;;;;;OAUG;IACH,YAAY,IAAY,EAAE,MAAkB,EAAE,UAAe,EAAE,UAA0C,EAAE;QAnDnG,cAAS,GAA+B,EAAE,CAAC;QAC3C,cAAS,GAAsC,EAAE,CAAC;QAElD,oBAAe,GAAG,K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AAI,KAAK,kBAAkB,CAAC,qBAAqB,EAAE;gBAClE,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;aAC3C;iBAAM;gBACH,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aAC3C;SACJ;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAtWG;IADC,SAAS,EAAE;2CACQ;AAwWxB,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: ThinEngine;\r\n private _shaderPath: any;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: ThinEngine, shaderPath: any, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n public dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return new Promise((resolve) => {\r\n const check = () => {\r\n if (!this.dispatch(x, y, z)) {\r\n setTimeout(check, delay);\r\n } else {\r\n resolve();\r\n }\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(() => new ComputeShader(source.name, scene.getEngine(), source.shaderPath, source.options), source, scene, rootUrl);\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
|
|
1
|
+
{"version":3,"file":"computeShader.js","sourceRoot":"","sources":["../../../../lts/core/generated/Compute/computeShader.ts"],"names":[],"mappings":";AAIA,OAAO,EAAE,mBAAmB,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EA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MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,EAAE;YAC/B,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;YACrC,MAAM,OAAO,GAAY,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;YAE7E,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,OAAO,EAAE;gBAC7C,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aACpC;iBAAM,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,qBAAqB,EAAE;gBAClE,OAAO,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;aAC3C;iBAAM;gBACH,OAAO,CAAC,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;aAC3C;SACJ;QAED,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ;AAtWU;IADN,SAAS,EAAE;2CACQ;AAwWxB,aAAa,CAAC,uBAAuB,EAAE,aAAa,CAAC,CAAC","sourcesContent":["import type { UniformBuffer } from \"../Materials/uniformBuffer\";\r\nimport type { ThinEngine } from \"../Engines/thinEngine\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport { SerializationHelper, serialize } from \"../Misc/decorators\";\r\nimport { RegisterClass } from \"../Misc/typeStore\";\r\nimport type { ComputeEffect, IComputeEffectCreationOptions } from \"./computeEffect\";\r\nimport type { ComputeBindingMapping } from \"../Engines/Extensions/engine.computeShader\";\r\nimport { ComputeBindingType } from \"../Engines/Extensions/engine.computeShader\";\r\nimport type { BaseTexture } from \"../Materials/Textures/baseTexture\";\r\nimport { Texture } from \"../Materials/Textures/texture\";\r\nimport { UniqueIdGenerator } from \"../Misc/uniqueIdGenerator\";\r\nimport type { IComputeContext } from \"./IComputeContext\";\r\nimport type { StorageBuffer } from \"../Buffers/storageBuffer\";\r\nimport { Logger } from \"../Misc/logger\";\r\nimport { TextureSampler } from \"../Materials/Textures/textureSampler\";\r\nimport type { DataBuffer } from \"core/Buffers/dataBuffer\";\r\n\r\n/**\r\n * Defines the options associated with the creation of a compute shader.\r\n */\r\nexport interface IComputeShaderOptions {\r\n /**\r\n * list of bindings mapping (key is property name, value is binding location)\r\n * Must be provided because browsers don't support reflection for wgsl shaders yet (so there's no way to query the binding/group from a variable name)\r\n * TODO: remove this when browsers support reflection for wgsl shaders\r\n */\r\n bindingsMapping: ComputeBindingMapping;\r\n\r\n /**\r\n * The list of defines used in the shader\r\n */\r\n defines?: string[];\r\n\r\n /**\r\n * The name of the entry point in the shader source (default: \"main\")\r\n */\r\n entryPoint?: string;\r\n\r\n /**\r\n * If provided, will be called with the shader code so that this code can be updated before it is compiled by the GPU\r\n */\r\n processFinalCode?: Nullable<(code: string) => string>;\r\n}\r\n\r\ntype ComputeBindingListInternal = { [key: string]: { type: ComputeBindingType; object: any; indexInGroupEntries?: number; buffer?: Nullable<DataBuffer> } };\r\n\r\n/**\r\n * The ComputeShader object lets you execute a compute shader on your GPU (if supported by the engine)\r\n */\r\nexport class ComputeShader {\r\n private _engine: ThinEngine;\r\n private _shaderPath: any;\r\n private _options: IComputeShaderOptions;\r\n private _effect: ComputeEffect;\r\n private _cachedDefines: string;\r\n private _bindings: ComputeBindingListInternal = {};\r\n private _samplers: { [key: string]: TextureSampler } = {};\r\n private _context: IComputeContext;\r\n private _contextIsDirty = false;\r\n\r\n /**\r\n * Gets the unique id of the compute shader\r\n */\r\n public readonly uniqueId: number;\r\n\r\n /**\r\n * The name of the shader\r\n */\r\n @serialize()\r\n public name: string;\r\n\r\n /**\r\n * The options used to create the shader\r\n */\r\n public get options() {\r\n return this._options;\r\n }\r\n\r\n /**\r\n * The shaderPath used to create the shader\r\n */\r\n public get shaderPath() {\r\n return this._shaderPath;\r\n }\r\n\r\n /**\r\n * Callback triggered when the shader is compiled\r\n */\r\n public onCompiled: Nullable<(effect: ComputeEffect) => void> = null;\r\n\r\n /**\r\n * Callback triggered when an error occurs\r\n */\r\n public onError: Nullable<(effect: ComputeEffect, errors: string) => void> = null;\r\n\r\n /**\r\n * Instantiates a new compute shader.\r\n * @param name Defines the name of the compute shader in the scene\r\n * @param engine Defines the engine the compute shader belongs to\r\n * @param shaderPath Defines the route to the shader code in one of three ways:\r\n * * object: \\{ compute: \"custom\" \\}, used with ShaderStore.ShadersStoreWGSL[\"customComputeShader\"]\r\n * * object: \\{ computeElement: \"HTMLElementId\" \\}, used with shader code in script tags\r\n * * object: \\{ computeSource: \"compute shader code string\" \\}, where the string contains the shader code\r\n * * string: try first to find the code in ShaderStore.ShadersStoreWGSL[shaderPath + \"ComputeShader\"]. If not, assumes it is a file with name shaderPath.compute.fx in index.html folder.\r\n * @param options Define the options used to create the shader\r\n */\r\n constructor(name: string, engine: ThinEngine, shaderPath: any, options: Partial<IComputeShaderOptions> = {}) {\r\n this.name = name;\r\n this._engine = engine;\r\n this.uniqueId = UniqueIdGenerator.UniqueId;\r\n\r\n if (!this._engine.getCaps().supportComputeShaders) {\r\n Logger.Error(\"This engine does not support compute shaders!\");\r\n return;\r\n }\r\n if (!options.bindingsMapping) {\r\n Logger.Error(\"You must provide the binding mappings as browsers don't support reflection for wgsl shaders yet!\");\r\n return;\r\n }\r\n\r\n this._context = engine.createComputeContext()!;\r\n this._shaderPath = shaderPath;\r\n this._options = {\r\n bindingsMapping: {},\r\n defines: [],\r\n ...options,\r\n };\r\n }\r\n\r\n /**\r\n * Gets the current class name of the material e.g. \"ComputeShader\"\r\n * Mainly use in serialization.\r\n * @returns the class name\r\n */\r\n public getClassName(): string {\r\n return \"ComputeShader\";\r\n }\r\n\r\n /**\r\n * Binds a texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n * @param bindSampler Bind the sampler corresponding to the texture (default: true). The sampler will be bound just before the binding index of the texture\r\n */\r\n public setTexture(name: string, texture: BaseTexture, bindSampler = true): void {\r\n const current = this._bindings[name];\r\n\r\n this._bindings[name] = {\r\n type: bindSampler ? ComputeBindingType.Texture : ComputeBindingType.TextureWithoutSampler,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture || current.type !== this._bindings[name].type;\r\n }\r\n\r\n /**\r\n * Binds a storage texture to the shader\r\n * @param name Binding name of the texture\r\n * @param texture Texture to bind\r\n */\r\n public setStorageTexture(name: string, texture: BaseTexture): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== texture;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageTexture,\r\n object: texture,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a uniform buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setUniformBuffer(name: string, buffer: UniformBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.UniformBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a storage buffer to the shader\r\n * @param name Binding name of the buffer\r\n * @param buffer Buffer to bind\r\n */\r\n public setStorageBuffer(name: string, buffer: StorageBuffer): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || current.object !== buffer;\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.StorageBuffer,\r\n object: buffer,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Binds a texture sampler to the shader\r\n * @param name Binding name of the sampler\r\n * @param sampler Sampler to bind\r\n */\r\n public setTextureSampler(name: string, sampler: TextureSampler): void {\r\n const current = this._bindings[name];\r\n\r\n this._contextIsDirty ||= !current || !sampler.compareSampler(current.object);\r\n\r\n this._bindings[name] = {\r\n type: ComputeBindingType.Sampler,\r\n object: sampler,\r\n indexInGroupEntries: current?.indexInGroupEntries,\r\n };\r\n }\r\n\r\n /**\r\n * Specifies that the compute shader is ready to be executed (the compute effect and all the resources are ready)\r\n * @returns true if the compute shader is ready to be executed\r\n */\r\n public isReady(): boolean {\r\n let effect = this._effect;\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key],\r\n type = binding.type,\r\n object = binding.object;\r\n\r\n switch (type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const texture = object as BaseTexture;\r\n if (!texture.isReady()) {\r\n return false;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n const defines = [];\r\n\r\n const shaderName = this._shaderPath;\r\n\r\n if (this._options.defines) {\r\n for (let index = 0; index < this._options.defines.length; index++) {\r\n defines.push(this._options.defines[index]);\r\n }\r\n }\r\n\r\n const join = defines.join(\"\\n\");\r\n\r\n if (this._cachedDefines !== join) {\r\n this._cachedDefines = join;\r\n\r\n effect = this._engine.createComputeEffect(shaderName, <IComputeEffectCreationOptions>{\r\n defines: join,\r\n entryPoint: this._options.entryPoint,\r\n onCompiled: this.onCompiled,\r\n onError: this.onError,\r\n });\r\n\r\n this._effect = effect;\r\n }\r\n\r\n if (!effect.isReady()) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispatches (executes) the compute shader\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @returns True if the dispatch could be done, else false (meaning either the compute effect or at least one of the bound resources was not ready)\r\n */\r\n public dispatch(x: number, y?: number, z?: number): boolean {\r\n if (!this.isReady()) {\r\n return false;\r\n }\r\n\r\n // If the sampling parameters of a texture bound to the shader have changed, we must clear the compute context so that it is recreated with the updated values\r\n // Also, if the actual (gpu) buffer used by a uniform buffer has changed, we must clear the compute context so that it is recreated with the updated value\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n\r\n if (!this._options.bindingsMapping[key]) {\r\n throw new Error(\"ComputeShader ('\" + this.name + \"'): No binding mapping has been provided for the property '\" + key + \"'\");\r\n }\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture: {\r\n const sampler = this._samplers[key];\r\n const texture = binding.object as BaseTexture;\r\n\r\n if (!sampler || !texture._texture || !sampler.compareSampler(texture._texture)) {\r\n this._samplers[key] = new TextureSampler().setParameters(\r\n texture.wrapU,\r\n texture.wrapV,\r\n texture.wrapR,\r\n texture.anisotropicFilteringLevel,\r\n texture._texture!.samplingMode,\r\n texture._texture?._comparisonFunction\r\n );\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n case ComputeBindingType.UniformBuffer: {\r\n const ubo = binding.object as UniformBuffer;\r\n if (ubo.getBuffer() !== binding.buffer) {\r\n binding.buffer = ubo.getBuffer();\r\n this._contextIsDirty = true;\r\n }\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (this._contextIsDirty) {\r\n this._contextIsDirty = false;\r\n this._context.clear();\r\n }\r\n\r\n this._engine.computeDispatch(this._effect, this._context, this._bindings, x, y, z, this._options.bindingsMapping);\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Waits for the compute shader to be ready and executes it\r\n * @param x Number of workgroups to execute on the X dimension\r\n * @param y Number of workgroups to execute on the Y dimension (default: 1)\r\n * @param z Number of workgroups to execute on the Z dimension (default: 1)\r\n * @param delay Delay between the retries while the shader is not ready (in milliseconds - 10 by default)\r\n * @returns A promise that is resolved once the shader has been sent to the GPU. Note that it does not mean that the shader execution itself is finished!\r\n */\r\n public dispatchWhenReady(x: number, y?: number, z?: number, delay = 10): Promise<void> {\r\n return new Promise((resolve) => {\r\n const check = () => {\r\n if (!this.dispatch(x, y, z)) {\r\n setTimeout(check, delay);\r\n } else {\r\n resolve();\r\n }\r\n };\r\n\r\n check();\r\n });\r\n }\r\n\r\n /**\r\n * Serializes this compute shader in a JSON representation\r\n * @returns the serialized compute shader object\r\n */\r\n public serialize(): any {\r\n const serializationObject = SerializationHelper.Serialize(this);\r\n\r\n serializationObject.options = this._options;\r\n serializationObject.shaderPath = this._shaderPath;\r\n serializationObject.bindings = {};\r\n serializationObject.textures = {};\r\n\r\n for (const key in this._bindings) {\r\n const binding = this._bindings[key];\r\n const object = binding.object;\r\n\r\n switch (binding.type) {\r\n case ComputeBindingType.Texture:\r\n case ComputeBindingType.TextureWithoutSampler:\r\n case ComputeBindingType.StorageTexture: {\r\n const serializedData = (object as BaseTexture).serialize();\r\n if (serializedData) {\r\n serializationObject.textures[key] = serializedData;\r\n serializationObject.bindings[key] = {\r\n type: binding.type,\r\n };\r\n }\r\n break;\r\n }\r\n\r\n case ComputeBindingType.UniformBuffer: {\r\n break;\r\n }\r\n }\r\n }\r\n\r\n return serializationObject;\r\n }\r\n\r\n /**\r\n * Creates a compute shader from parsed compute shader data\r\n * @param source defines the JSON representation of the compute shader\r\n * @param scene defines the hosting scene\r\n * @param rootUrl defines the root URL to use to load textures and relative dependencies\r\n * @returns a new compute shader\r\n */\r\n public static Parse(source: any, scene: Scene, rootUrl: string): ComputeShader {\r\n const compute = SerializationHelper.Parse(() => new ComputeShader(source.name, scene.getEngine(), source.shaderPath, source.options), source, scene, rootUrl);\r\n\r\n for (const key in source.textures) {\r\n const binding = source.bindings[key];\r\n const texture = <Texture>Texture.Parse(source.textures[key], scene, rootUrl);\r\n\r\n if (binding.type === ComputeBindingType.Texture) {\r\n compute.setTexture(key, texture);\r\n } else if (binding.type === ComputeBindingType.TextureWithoutSampler) {\r\n compute.setTexture(key, texture, false);\r\n } else {\r\n compute.setStorageTexture(key, texture);\r\n }\r\n }\r\n\r\n return compute;\r\n }\r\n}\r\n\r\nRegisterClass(\"BABYLON.ComputeShader\", ComputeShader);\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3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,CAAC,EAAE;QAC3E,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC7B;AACL,CAAC,CAAC","sourcesContent":["import type { SmartArray } from \"../../Misc/smartArray\";\r\nimport { SmartArrayNoDuplicate } from \"../../Misc/smartArray\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Ray } from \"../../Culling/ray\";\r\nimport { OctreeBlock } from \"./octreeBlock\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\n\r\n/**\r\n * Octrees are a really powerful data structure that can quickly select entities based on space coordinates.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n */\r\nexport class Octree<T> {\r\n /**\r\n * Blocks within the octree containing objects\r\n */\r\n public blocks: Array<OctreeBlock<T>>;\r\n /**\r\n * Content stored in the octree\r\n */\r\n public dynamicContent = new Array<T>();\r\n\r\n private _maxBlockCapacity: number;\r\n private _selectionContent: SmartArrayNoDuplicate<T>;\r\n private _creationFunc: (entry: T, block: OctreeBlock<T>) => void;\r\n\r\n /**\r\n * Creates a octree\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n * @param creationFunc function to be used to instantiate the octree\r\n * @param maxBlockCapacity defines the maximum number of meshes you want on your octree's leaves (default: 64)\r\n * @param maxDepth defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.)\r\n */\r\n constructor(\r\n creationFunc: (entry: T, block: OctreeBlock<T>) => void,\r\n maxBlockCapacity?: number,\r\n /** Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.) */\r\n public maxDepth = 2\r\n ) {\r\n this._maxBlockCapacity = maxBlockCapacity || 64;\r\n this._selectionContent = new SmartArrayNoDuplicate<T>(1024);\r\n this._creationFunc = creationFunc;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Updates the octree by adding blocks for the passed in meshes within the min and max world parameters\r\n * @param worldMin worldMin for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n * @param worldMax worldMax for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n * @param entries meshes to be added to the octree blocks\r\n */\r\n public update(worldMin: Vector3, worldMax: Vector3, entries: T[]): void {\r\n OctreeBlock._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);\r\n }\r\n\r\n /**\r\n * Adds a mesh to the octree\r\n * @param entry Mesh to add to the octree\r\n */\r\n public addMesh(entry: T): void {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.addEntry(entry);\r\n }\r\n }\r\n\r\n /**\r\n * Remove an element from the octree\r\n * @param entry defines the element to remove\r\n */\r\n public removeMesh(entry: T): void {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.removeEntry(entry);\r\n }\r\n }\r\n\r\n /**\r\n * Selects an array of meshes within the frustum\r\n * @param frustumPlanes The frustum planes to use which will select all meshes within it\r\n * @param allowDuplicate If duplicate objects are allowed in the resulting object array\r\n * @returns array of meshes within the frustum\r\n */\r\n public select(frustumPlanes: Plane[], allowDuplicate?: boolean): SmartArray<T> {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.select(frustumPlanes, this._selectionContent, allowDuplicate);\r\n }\r\n\r\n if (allowDuplicate) {\r\n this._selectionContent.concat(this.dynamicContent);\r\n } else {\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n }\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Test if the octree intersect with the given bounding sphere and if yes, then add its content to the selection array\r\n * @param sphereCenter defines the bounding sphere center\r\n * @param sphereRadius defines the bounding sphere radius\r\n * @param allowDuplicate defines if the selection array can contains duplicated entries\r\n * @returns an array of objects that intersect the sphere\r\n */\r\n public intersects(sphereCenter: Vector3, sphereRadius: number, allowDuplicate?: boolean): SmartArray<T> {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersects(sphereCenter, sphereRadius, this._selectionContent, allowDuplicate);\r\n }\r\n\r\n if (allowDuplicate) {\r\n this._selectionContent.concat(this.dynamicContent);\r\n } else {\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n }\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Test if the octree intersect with the given ray and if yes, then add its content to resulting array\r\n * @param ray defines the ray to test with\r\n * @returns array of intersected objects\r\n */\r\n public intersectsRay(ray: Ray): SmartArray<T> {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersectsRay(ray, this._selectionContent);\r\n }\r\n\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Adds a mesh into the octree block if it intersects the block\r\n * @param entry\r\n * @param block\r\n */\r\n public static CreationFuncForMeshes = (entry: AbstractMesh, block: OctreeBlock<AbstractMesh>): void => {\r\n const boundingInfo = entry.getBoundingInfo();\r\n if (!entry.isBlocked && boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\r\n block.entries.push(entry);\r\n }\r\n };\r\n\r\n /**\r\n * Adds a submesh into the octree block if it intersects the block\r\n * @param entry\r\n * @param block\r\n */\r\n public static CreationFuncForSubMeshes = (entry: SubMesh, block: OctreeBlock<SubMesh>): void => {\r\n const boundingInfo = entry.getBoundingInfo();\r\n if (boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\r\n block.entries.push(entry);\r\n }\r\n };\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"octree.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Culling/Octrees/octree.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAK9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C;;;GAGG;AACH,MAAM,OAAO,MAAM;IAcf;;;;;;OAMG;IACH,YACI,YAAuD,EACvD,gBAAyB;IACzB,qKAAqK;IAC9J,WAAW,CAAC;QAAZ,aAAQ,GAAR,QAAQ,CAAI;QApBvB;;WAEG;QACI,mBAAc,GAAG,IAAI,KAAK,EAAK,CAAC;QAmBnC,IAAI,CAAC,iBAAiB,GAAG,gBAAgB,IAAI,EAAE,CAAC;QAChD,IAAI,CAAC,iBAAiB,GAAG,IAAI,qBAAqB,CAAI,IAAI,CAAC,CAAC;QAC5D,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;IACtC,CAAC;IAED,UAAU;IACV;;;;;OAKG;IACI,MAAM,CAAC,QAAiB,EAAE,QAAiB,EAAE,OAAY;QAC5D,WAAW,CAAC,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;IAC/H,CAAC;IAED;;;OAGG;IACI,OAAO,CAAC,KAAQ;QACnB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YACrD,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACjC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;SACzB;IACL,CAAC;IAED;;;OAGG;IACI,UA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CAAC;IAC7C,IAAI,YAAY,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE;QAC3E,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC7B;AACL,CAAC,AALqC,CAKpC","sourcesContent":["import type { SmartArray } from \"../../Misc/smartArray\";\r\nimport { SmartArrayNoDuplicate } from \"../../Misc/smartArray\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport type { SubMesh } from \"../../Meshes/subMesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { Ray } from \"../../Culling/ray\";\r\nimport { OctreeBlock } from \"./octreeBlock\";\r\nimport type { Plane } from \"../../Maths/math.plane\";\r\n\r\n/**\r\n * Octrees are a really powerful data structure that can quickly select entities based on space coordinates.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n */\r\nexport class Octree<T> {\r\n /**\r\n * Blocks within the octree containing objects\r\n */\r\n public blocks: Array<OctreeBlock<T>>;\r\n /**\r\n * Content stored in the octree\r\n */\r\n public dynamicContent = new Array<T>();\r\n\r\n private _maxBlockCapacity: number;\r\n private _selectionContent: SmartArrayNoDuplicate<T>;\r\n private _creationFunc: (entry: T, block: OctreeBlock<T>) => void;\r\n\r\n /**\r\n * Creates a octree\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/scene/optimizeOctrees\r\n * @param creationFunc function to be used to instantiate the octree\r\n * @param maxBlockCapacity defines the maximum number of meshes you want on your octree's leaves (default: 64)\r\n * @param maxDepth defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.)\r\n */\r\n constructor(\r\n creationFunc: (entry: T, block: OctreeBlock<T>) => void,\r\n maxBlockCapacity?: number,\r\n /** Defines the maximum depth (sub-levels) for your octree. Default value is 2, which means 8 8 8 = 512 blocks :) (This parameter takes precedence over capacity.) */\r\n public maxDepth = 2\r\n ) {\r\n this._maxBlockCapacity = maxBlockCapacity || 64;\r\n this._selectionContent = new SmartArrayNoDuplicate<T>(1024);\r\n this._creationFunc = creationFunc;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Updates the octree by adding blocks for the passed in meshes within the min and max world parameters\r\n * @param worldMin worldMin for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n * @param worldMax worldMax for the octree blocks var blockSize = new Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);\r\n * @param entries meshes to be added to the octree blocks\r\n */\r\n public update(worldMin: Vector3, worldMax: Vector3, entries: T[]): void {\r\n OctreeBlock._CreateBlocks(worldMin, worldMax, entries, this._maxBlockCapacity, 0, this.maxDepth, this, this._creationFunc);\r\n }\r\n\r\n /**\r\n * Adds a mesh to the octree\r\n * @param entry Mesh to add to the octree\r\n */\r\n public addMesh(entry: T): void {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.addEntry(entry);\r\n }\r\n }\r\n\r\n /**\r\n * Remove an element from the octree\r\n * @param entry defines the element to remove\r\n */\r\n public removeMesh(entry: T): void {\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.removeEntry(entry);\r\n }\r\n }\r\n\r\n /**\r\n * Selects an array of meshes within the frustum\r\n * @param frustumPlanes The frustum planes to use which will select all meshes within it\r\n * @param allowDuplicate If duplicate objects are allowed in the resulting object array\r\n * @returns array of meshes within the frustum\r\n */\r\n public select(frustumPlanes: Plane[], allowDuplicate?: boolean): SmartArray<T> {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.select(frustumPlanes, this._selectionContent, allowDuplicate);\r\n }\r\n\r\n if (allowDuplicate) {\r\n this._selectionContent.concat(this.dynamicContent);\r\n } else {\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n }\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Test if the octree intersect with the given bounding sphere and if yes, then add its content to the selection array\r\n * @param sphereCenter defines the bounding sphere center\r\n * @param sphereRadius defines the bounding sphere radius\r\n * @param allowDuplicate defines if the selection array can contains duplicated entries\r\n * @returns an array of objects that intersect the sphere\r\n */\r\n public intersects(sphereCenter: Vector3, sphereRadius: number, allowDuplicate?: boolean): SmartArray<T> {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersects(sphereCenter, sphereRadius, this._selectionContent, allowDuplicate);\r\n }\r\n\r\n if (allowDuplicate) {\r\n this._selectionContent.concat(this.dynamicContent);\r\n } else {\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n }\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Test if the octree intersect with the given ray and if yes, then add its content to resulting array\r\n * @param ray defines the ray to test with\r\n * @returns array of intersected objects\r\n */\r\n public intersectsRay(ray: Ray): SmartArray<T> {\r\n this._selectionContent.reset();\r\n\r\n for (let index = 0; index < this.blocks.length; index++) {\r\n const block = this.blocks[index];\r\n block.intersectsRay(ray, this._selectionContent);\r\n }\r\n\r\n this._selectionContent.concatWithNoDuplicate(this.dynamicContent);\r\n\r\n return this._selectionContent;\r\n }\r\n\r\n /**\r\n * Adds a mesh into the octree block if it intersects the block\r\n * @param entry\r\n * @param block\r\n */\r\n public static CreationFuncForMeshes = (entry: AbstractMesh, block: OctreeBlock<AbstractMesh>): void => {\r\n const boundingInfo = entry.getBoundingInfo();\r\n if (!entry.isBlocked && boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\r\n block.entries.push(entry);\r\n }\r\n };\r\n\r\n /**\r\n * Adds a submesh into the octree block if it intersects the block\r\n * @param entry\r\n * @param block\r\n */\r\n public static CreationFuncForSubMeshes = (entry: SubMesh, block: OctreeBlock<SubMesh>): void => {\r\n const boundingInfo = entry.getBoundingInfo();\r\n if (boundingInfo.boundingBox.intersectsMinMax(block.minPoint, block.maxPoint)) {\r\n block.entries.push(entry);\r\n }\r\n };\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundingBox.js","sourceRoot":"","sources":["../../../../lts/core/generated/Culling/boundingBox.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAIvD,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAKlD;;GAEG;AACH,MAAM,OAAO,WAAW;IA2DpB;;;;;OAKG;IACH,YAAY,GAA2B,EAAE,GAA2B,EAAE,WAAmC;QAhEzG;;WAEG;QACa,YAAO,GAAc,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAC5E;;WAEG;QACa,WAAM,GAAY,OAAO,CAAC,IAAI,EAAE,CAAC;QACjD;;WAEG;QACa,gBAAW,GAAY,OAAO,CAAC,IAAI,EAAE,CAAC;QACtD;;WAEG;QACa,eAAU,GAAY,OAAO,CAAC,IAAI,EAAE,CAAC;QACrD;;WAEG;QACa,oBAAe,GAAY,OAAO,CAAC,IAAI,EAAE,CAAC;QAC1D;;WAEG;QACa,eAAU,GAAc,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QAC/E;;WAEG;QACa,iBAAY,GAAc,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;QACjF;;WAEG;QACa,iBAAY,GAAY,OAAO,CAAC,IAAI,EAAE,CAAC;QACvD;;WAEG;QACa,iBAAY,GAAY,OAAO,CAAC,IAAI,EAAE,CAAC;QACvD;;W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IAAI,CAAC;IAChB,CAAC;;AA9SuB,uBAAW,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import type { DeepImmutable, Nullable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { BoundingSphere } from \"../Culling/boundingSphere\";\r\n\r\nimport type { ICullable } from \"./boundingInfo\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\ndeclare type DrawWrapper = import(\"../Materials/drawWrapper\").DrawWrapper;\r\n\r\n/**\r\n * Class used to store bounding box information\r\n */\r\nexport class BoundingBox implements ICullable {\r\n /**\r\n * Gets the 8 vectors representing the bounding box in local space\r\n */\r\n public readonly vectors: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);\r\n /**\r\n * Gets the center of the bounding box in local space\r\n */\r\n public readonly center: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the center of the bounding box in world space\r\n */\r\n public readonly centerWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the extend size in local space\r\n */\r\n public readonly extendSize: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the extend size in world space\r\n */\r\n public readonly extendSizeWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the OBB (object bounding box) directions\r\n */\r\n public readonly directions: Vector3[] = ArrayTools.BuildArray(3, Vector3.Zero);\r\n /**\r\n * Gets the 8 vectors representing the bounding box in world space\r\n */\r\n public readonly vectorsWorld: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);\r\n /**\r\n * Gets the minimum vector in world space\r\n */\r\n public readonly minimumWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in world space\r\n */\r\n public readonly maximumWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the minimum vector in local space\r\n */\r\n public readonly minimum: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in local space\r\n */\r\n public readonly maximum: Vector3 = Vector3.Zero();\r\n\r\n private _worldMatrix: DeepImmutable<Matrix>;\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);\r\n\r\n /**\r\n * @internal\r\n */\r\n public _tag: number;\r\n\r\n /** @internal */\r\n public _drawWrapperFront: Nullable<DrawWrapper> = null;\r\n /** @internal */\r\n public _drawWrapperBack: Nullable<DrawWrapper> = null;\r\n\r\n /**\r\n * Creates a new bounding box\r\n * @param min defines the minimum vector (in local space)\r\n * @param max defines the maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n this.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Recreates the entire bounding box from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n const vectors = this.vectors;\r\n\r\n this.minimum.copyFromFloats(minX, minY, minZ);\r\n this.maximum.copyFromFloats(maxX, maxY, maxZ);\r\n vectors[0].copyFromFloats(minX, minY, minZ);\r\n vectors[1].copyFromFloats(maxX, maxY, maxZ);\r\n vectors[2].copyFromFloats(maxX, minY, minZ);\r\n vectors[3].copyFromFloats(minX, maxY, minZ);\r\n vectors[4].copyFromFloats(minX, minY, maxZ);\r\n vectors[5].copyFromFloats(maxX, maxY, minZ);\r\n vectors[6].copyFromFloats(minX, maxY, maxZ);\r\n vectors[7].copyFromFloats(maxX, minY, maxZ);\r\n\r\n // OBB\r\n max.addToRef(min, this.center).scaleInPlace(0.5);\r\n max.subtractToRef(min, this.extendSize).scaleInPlace(0.5);\r\n\r\n this._worldMatrix = worldMatrix || Matrix.IdentityReadOnly;\r\n\r\n this._update(this._worldMatrix);\r\n }\r\n\r\n /**\r\n * Scale the current bounding box by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding box\r\n */\r\n public scale(factor: number): BoundingBox {\r\n const tmpVectors = BoundingBox._TmpVector3;\r\n const diff = this.maximum.subtractToRef(this.minimum, tmpVectors[0]);\r\n const len = diff.length();\r\n diff.normalizeFromLength(len);\r\n const distance = len * factor;\r\n const newRadius = diff.scaleInPlace(distance * 0.5);\r\n\r\n const min = this.center.subtractToRef(newRadius, tmpVectors[1]);\r\n const max = this.center.addToRef(newRadius, tmpVectors[2]);\r\n\r\n this.reConstruct(min, max, this._worldMatrix);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the world matrix of the bounding box\r\n * @returns a matrix\r\n */\r\n public getWorldMatrix(): DeepImmutable<Matrix> {\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _update(world: DeepImmutable<Matrix>): void {\r\n const minWorld = this.minimumWorld;\r\n const maxWorld = this.maximumWorld;\r\n const directions = this.directions;\r\n const vectorsWorld = this.vectorsWorld;\r\n const vectors = this.vectors;\r\n\r\n if (!world.isIdentity()) {\r\n minWorld.setAll(Number.MAX_VALUE);\r\n maxWorld.setAll(-Number.MAX_VALUE);\r\n\r\n for (let index = 0; index < 8; ++index) {\r\n const v = vectorsWorld[index];\r\n Vector3.TransformCoordinatesToRef(vectors[index], world, v);\r\n minWorld.minimizeInPlace(v);\r\n maxWorld.maximizeInPlace(v);\r\n }\r\n\r\n // Extend\r\n maxWorld.subtractToRef(minWorld, this.extendSizeWorld).scaleInPlace(0.5);\r\n maxWorld.addToRef(minWorld, this.centerWorld).scaleInPlace(0.5);\r\n } else {\r\n minWorld.copyFrom(this.minimum);\r\n maxWorld.copyFrom(this.maximum);\r\n for (let index = 0; index < 8; ++index) {\r\n vectorsWorld[index].copyFrom(vectors[index]);\r\n }\r\n\r\n // Extend\r\n this.extendSizeWorld.copyFrom(this.extendSize);\r\n this.centerWorld.copyFrom(this.center);\r\n }\r\n\r\n Vector3.FromArrayToRef(world.m, 0, directions[0]);\r\n Vector3.FromArrayToRef(world.m, 4, directions[1]);\r\n Vector3.FromArrayToRef(world.m, 8, directions[2]);\r\n\r\n this._worldMatrix = world;\r\n }\r\n\r\n /**\r\n * Tests if the bounding box is intersecting the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n return BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);\r\n }\r\n\r\n /**\r\n * Tests if the bounding box is entirely inside the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an inclusion\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);\r\n }\r\n\r\n /**\r\n * Tests if a point is inside the bounding box\r\n * @param point defines the point to test\r\n * @returns true if the point is inside the bounding box\r\n */\r\n public intersectsPoint(point: DeepImmutable<Vector3>): boolean {\r\n const min = this.minimumWorld;\r\n const max = this.maximumWorld;\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n const pointX = point.x,\r\n pointY = point.y,\r\n pointZ = point.z;\r\n const delta = -Epsilon;\r\n\r\n if (maxX - pointX < delta || delta > pointX - minX) {\r\n return false;\r\n }\r\n\r\n if (maxY - pointY < delta || delta > pointY - minY) {\r\n return false;\r\n }\r\n\r\n if (maxZ - pointZ < delta || delta > pointZ - minZ) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if the bounding box intersects with a bounding sphere\r\n * @param sphere defines the sphere to test\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsSphere(sphere: DeepImmutable<BoundingSphere>): boolean {\r\n return BoundingBox.IntersectsSphere(this.minimumWorld, this.maximumWorld, sphere.centerWorld, sphere.radiusWorld);\r\n }\r\n\r\n /**\r\n * Tests if the bounding box intersects with a box defined by a min and max vectors\r\n * @param min defines the min vector to use\r\n * @param max defines the max vector to use\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsMinMax(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>): boolean {\r\n const myMin = this.minimumWorld;\r\n const myMax = this.maximumWorld;\r\n const myMinX = myMin.x,\r\n myMinY = myMin.y,\r\n myMinZ = myMin.z,\r\n myMaxX = myMax.x,\r\n myMaxY = myMax.y,\r\n myMaxZ = myMax.z;\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n if (myMaxX < minX || myMinX > maxX) {\r\n return false;\r\n }\r\n\r\n if (myMaxY < minY || myMinY > maxY) {\r\n return false;\r\n }\r\n\r\n if (myMaxZ < minZ || myMinZ > maxZ) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Disposes the resources of the class\r\n */\r\n public dispose(): void {\r\n this._drawWrapperFront?.dispose();\r\n this._drawWrapperBack?.dispose();\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Tests if two bounding boxes are intersections\r\n * @param box0 defines the first box to test\r\n * @param box1 defines the second box to test\r\n * @returns true if there is an intersection\r\n */\r\n public static Intersects(box0: DeepImmutable<BoundingBox>, box1: DeepImmutable<BoundingBox>): boolean {\r\n return box0.intersectsMinMax(box1.minimumWorld, box1.maximumWorld);\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defines by a min/max vectors intersects a sphere\r\n * @param minPoint defines the minimum vector of the bounding box\r\n * @param maxPoint defines the maximum vector of the bounding box\r\n * @param sphereCenter defines the sphere center\r\n * @param sphereRadius defines the sphere radius\r\n * @returns true if there is an intersection\r\n */\r\n public static IntersectsSphere(minPoint: DeepImmutable<Vector3>, maxPoint: DeepImmutable<Vector3>, sphereCenter: DeepImmutable<Vector3>, sphereRadius: number): boolean {\r\n const vector = BoundingBox._TmpVector3[0];\r\n Vector3.ClampToRef(sphereCenter, minPoint, maxPoint, vector);\r\n const num = Vector3.DistanceSquared(sphereCenter, vector);\r\n return num <= sphereRadius * sphereRadius;\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defined with 8 vectors is entirely inside frustum planes\r\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an inclusion\r\n */\r\n public static IsCompletelyInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n for (let p = 0; p < 6; ++p) {\r\n const frustumPlane = frustumPlanes[p];\r\n for (let i = 0; i < 8; ++i) {\r\n if (frustumPlane.dotCoordinate(boundingVectors[i]) < 0) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defined with 8 vectors intersects frustum planes\r\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public static IsInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n for (let p = 0; p < 6; ++p) {\r\n let canReturnFalse = true;\r\n const frustumPlane = frustumPlanes[p];\r\n for (let i = 0; i < 8; ++i) {\r\n if (frustumPlane.dotCoordinate(boundingVectors[i]) >= 0) {\r\n canReturnFalse = false;\r\n break;\r\n }\r\n }\r\n if (canReturnFalse) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"boundingBox.js","sourceRoot":"","sources":["../../../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I,MAAM,CAAC,qBAAqB,CAAC,eAA8C,EAAE,aAA0C;QAC1H,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;YACxB,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;gBACxB,IAAI,YAAY,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE;oBACpD,OAAO,KAAK,CAAC;iBAChB;aACJ;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;;;OAKG;IACI,MAAM,CAAC,WAAW,CAAC,eAA8C,EAAE,aAA0C;QAChH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;YACxB,IAAI,cAAc,GAAG,IAAI,CAAC;YAC1B,MAAM,YAAY,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;YACtC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;gBACxB,IAAI,YAAY,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;oBACrD,cAAc,GAAG,KAAK,CAAC;oBACvB,MAAM;iBACT;aACJ;YACD,IAAI,cAAc,EAAE;gBAChB,OAAO,KAAK,CAAC;aAChB;SACJ;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;;AA9SuB,uBAAW,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,AAAzC,CAA0C","sourcesContent":["import type { DeepImmutable, Nullable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport { Matrix, Vector3 } from \"../Maths/math.vector\";\r\nimport type { BoundingSphere } from \"../Culling/boundingSphere\";\r\n\r\nimport type { ICullable } from \"./boundingInfo\";\r\nimport { Epsilon } from \"../Maths/math.constants\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\ndeclare type DrawWrapper = import(\"../Materials/drawWrapper\").DrawWrapper;\r\n\r\n/**\r\n * Class used to store bounding box information\r\n */\r\nexport class BoundingBox implements ICullable {\r\n /**\r\n * Gets the 8 vectors representing the bounding box in local space\r\n */\r\n public readonly vectors: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);\r\n /**\r\n * Gets the center of the bounding box in local space\r\n */\r\n public readonly center: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the center of the bounding box in world space\r\n */\r\n public readonly centerWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the extend size in local space\r\n */\r\n public readonly extendSize: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the extend size in world space\r\n */\r\n public readonly extendSizeWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the OBB (object bounding box) directions\r\n */\r\n public readonly directions: Vector3[] = ArrayTools.BuildArray(3, Vector3.Zero);\r\n /**\r\n * Gets the 8 vectors representing the bounding box in world space\r\n */\r\n public readonly vectorsWorld: Vector3[] = ArrayTools.BuildArray(8, Vector3.Zero);\r\n /**\r\n * Gets the minimum vector in world space\r\n */\r\n public readonly minimumWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in world space\r\n */\r\n public readonly maximumWorld: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the minimum vector in local space\r\n */\r\n public readonly minimum: Vector3 = Vector3.Zero();\r\n /**\r\n * Gets the maximum vector in local space\r\n */\r\n public readonly maximum: Vector3 = Vector3.Zero();\r\n\r\n private _worldMatrix: DeepImmutable<Matrix>;\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(3, Vector3.Zero);\r\n\r\n /**\r\n * @internal\r\n */\r\n public _tag: number;\r\n\r\n /** @internal */\r\n public _drawWrapperFront: Nullable<DrawWrapper> = null;\r\n /** @internal */\r\n public _drawWrapperBack: Nullable<DrawWrapper> = null;\r\n\r\n /**\r\n * Creates a new bounding box\r\n * @param min defines the minimum vector (in local space)\r\n * @param max defines the maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n this.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n // Methods\r\n\r\n /**\r\n * Recreates the entire bounding box from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n const vectors = this.vectors;\r\n\r\n this.minimum.copyFromFloats(minX, minY, minZ);\r\n this.maximum.copyFromFloats(maxX, maxY, maxZ);\r\n vectors[0].copyFromFloats(minX, minY, minZ);\r\n vectors[1].copyFromFloats(maxX, maxY, maxZ);\r\n vectors[2].copyFromFloats(maxX, minY, minZ);\r\n vectors[3].copyFromFloats(minX, maxY, minZ);\r\n vectors[4].copyFromFloats(minX, minY, maxZ);\r\n vectors[5].copyFromFloats(maxX, maxY, minZ);\r\n vectors[6].copyFromFloats(minX, maxY, maxZ);\r\n vectors[7].copyFromFloats(maxX, minY, maxZ);\r\n\r\n // OBB\r\n max.addToRef(min, this.center).scaleInPlace(0.5);\r\n max.subtractToRef(min, this.extendSize).scaleInPlace(0.5);\r\n\r\n this._worldMatrix = worldMatrix || Matrix.IdentityReadOnly;\r\n\r\n this._update(this._worldMatrix);\r\n }\r\n\r\n /**\r\n * Scale the current bounding box by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding box\r\n */\r\n public scale(factor: number): BoundingBox {\r\n const tmpVectors = BoundingBox._TmpVector3;\r\n const diff = this.maximum.subtractToRef(this.minimum, tmpVectors[0]);\r\n const len = diff.length();\r\n diff.normalizeFromLength(len);\r\n const distance = len * factor;\r\n const newRadius = diff.scaleInPlace(distance * 0.5);\r\n\r\n const min = this.center.subtractToRef(newRadius, tmpVectors[1]);\r\n const max = this.center.addToRef(newRadius, tmpVectors[2]);\r\n\r\n this.reConstruct(min, max, this._worldMatrix);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Gets the world matrix of the bounding box\r\n * @returns a matrix\r\n */\r\n public getWorldMatrix(): DeepImmutable<Matrix> {\r\n return this._worldMatrix;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _update(world: DeepImmutable<Matrix>): void {\r\n const minWorld = this.minimumWorld;\r\n const maxWorld = this.maximumWorld;\r\n const directions = this.directions;\r\n const vectorsWorld = this.vectorsWorld;\r\n const vectors = this.vectors;\r\n\r\n if (!world.isIdentity()) {\r\n minWorld.setAll(Number.MAX_VALUE);\r\n maxWorld.setAll(-Number.MAX_VALUE);\r\n\r\n for (let index = 0; index < 8; ++index) {\r\n const v = vectorsWorld[index];\r\n Vector3.TransformCoordinatesToRef(vectors[index], world, v);\r\n minWorld.minimizeInPlace(v);\r\n maxWorld.maximizeInPlace(v);\r\n }\r\n\r\n // Extend\r\n maxWorld.subtractToRef(minWorld, this.extendSizeWorld).scaleInPlace(0.5);\r\n maxWorld.addToRef(minWorld, this.centerWorld).scaleInPlace(0.5);\r\n } else {\r\n minWorld.copyFrom(this.minimum);\r\n maxWorld.copyFrom(this.maximum);\r\n for (let index = 0; index < 8; ++index) {\r\n vectorsWorld[index].copyFrom(vectors[index]);\r\n }\r\n\r\n // Extend\r\n this.extendSizeWorld.copyFrom(this.extendSize);\r\n this.centerWorld.copyFrom(this.center);\r\n }\r\n\r\n Vector3.FromArrayToRef(world.m, 0, directions[0]);\r\n Vector3.FromArrayToRef(world.m, 4, directions[1]);\r\n Vector3.FromArrayToRef(world.m, 8, directions[2]);\r\n\r\n this._worldMatrix = world;\r\n }\r\n\r\n /**\r\n * Tests if the bounding box is intersecting the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n return BoundingBox.IsInFrustum(this.vectorsWorld, frustumPlanes);\r\n }\r\n\r\n /**\r\n * Tests if the bounding box is entirely inside the frustum planes\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an inclusion\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n return BoundingBox.IsCompletelyInFrustum(this.vectorsWorld, frustumPlanes);\r\n }\r\n\r\n /**\r\n * Tests if a point is inside the bounding box\r\n * @param point defines the point to test\r\n * @returns true if the point is inside the bounding box\r\n */\r\n public intersectsPoint(point: DeepImmutable<Vector3>): boolean {\r\n const min = this.minimumWorld;\r\n const max = this.maximumWorld;\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n const pointX = point.x,\r\n pointY = point.y,\r\n pointZ = point.z;\r\n const delta = -Epsilon;\r\n\r\n if (maxX - pointX < delta || delta > pointX - minX) {\r\n return false;\r\n }\r\n\r\n if (maxY - pointY < delta || delta > pointY - minY) {\r\n return false;\r\n }\r\n\r\n if (maxZ - pointZ < delta || delta > pointZ - minZ) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if the bounding box intersects with a bounding sphere\r\n * @param sphere defines the sphere to test\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsSphere(sphere: DeepImmutable<BoundingSphere>): boolean {\r\n return BoundingBox.IntersectsSphere(this.minimumWorld, this.maximumWorld, sphere.centerWorld, sphere.radiusWorld);\r\n }\r\n\r\n /**\r\n * Tests if the bounding box intersects with a box defined by a min and max vectors\r\n * @param min defines the min vector to use\r\n * @param max defines the max vector to use\r\n * @returns true if there is an intersection\r\n */\r\n public intersectsMinMax(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>): boolean {\r\n const myMin = this.minimumWorld;\r\n const myMax = this.maximumWorld;\r\n const myMinX = myMin.x,\r\n myMinY = myMin.y,\r\n myMinZ = myMin.z,\r\n myMaxX = myMax.x,\r\n myMaxY = myMax.y,\r\n myMaxZ = myMax.z;\r\n const minX = min.x,\r\n minY = min.y,\r\n minZ = min.z,\r\n maxX = max.x,\r\n maxY = max.y,\r\n maxZ = max.z;\r\n if (myMaxX < minX || myMinX > maxX) {\r\n return false;\r\n }\r\n\r\n if (myMaxY < minY || myMinY > maxY) {\r\n return false;\r\n }\r\n\r\n if (myMaxZ < minZ || myMinZ > maxZ) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Disposes the resources of the class\r\n */\r\n public dispose(): void {\r\n this._drawWrapperFront?.dispose();\r\n this._drawWrapperBack?.dispose();\r\n }\r\n\r\n // Statics\r\n\r\n /**\r\n * Tests if two bounding boxes are intersections\r\n * @param box0 defines the first box to test\r\n * @param box1 defines the second box to test\r\n * @returns true if there is an intersection\r\n */\r\n public static Intersects(box0: DeepImmutable<BoundingBox>, box1: DeepImmutable<BoundingBox>): boolean {\r\n return box0.intersectsMinMax(box1.minimumWorld, box1.maximumWorld);\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defines by a min/max vectors intersects a sphere\r\n * @param minPoint defines the minimum vector of the bounding box\r\n * @param maxPoint defines the maximum vector of the bounding box\r\n * @param sphereCenter defines the sphere center\r\n * @param sphereRadius defines the sphere radius\r\n * @returns true if there is an intersection\r\n */\r\n public static IntersectsSphere(minPoint: DeepImmutable<Vector3>, maxPoint: DeepImmutable<Vector3>, sphereCenter: DeepImmutable<Vector3>, sphereRadius: number): boolean {\r\n const vector = BoundingBox._TmpVector3[0];\r\n Vector3.ClampToRef(sphereCenter, minPoint, maxPoint, vector);\r\n const num = Vector3.DistanceSquared(sphereCenter, vector);\r\n return num <= sphereRadius * sphereRadius;\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defined with 8 vectors is entirely inside frustum planes\r\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an inclusion\r\n */\r\n public static IsCompletelyInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n for (let p = 0; p < 6; ++p) {\r\n const frustumPlane = frustumPlanes[p];\r\n for (let i = 0; i < 8; ++i) {\r\n if (frustumPlane.dotCoordinate(boundingVectors[i]) < 0) {\r\n return false;\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Tests if a bounding box defined with 8 vectors intersects frustum planes\r\n * @param boundingVectors defines an array of 8 vectors representing a bounding box\r\n * @param frustumPlanes defines the frustum planes to test\r\n * @returns true if there is an intersection\r\n */\r\n public static IsInFrustum(boundingVectors: Array<DeepImmutable<Vector3>>, frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n for (let p = 0; p < 6; ++p) {\r\n let canReturnFalse = true;\r\n const frustumPlane = frustumPlanes[p];\r\n for (let i = 0; i < 8; ++i) {\r\n if (frustumPlane.dotCoordinate(boundingVectors[i]) >= 0) {\r\n canReturnFalse = false;\r\n break;\r\n }\r\n }\r\n if (canReturnFalse) {\r\n return false;\r\n }\r\n }\r\n return true;\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"boundingInfo.js","sourceRoot":"","sources":["../../../../lts/core/generated/Culling/boundingInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,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AAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YACjF,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YACjF,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YACjF,OAAO,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AAjRuB,wBAAW,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC","sourcesContent":["import type { DeepImmutable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { TmpVectors } from \"../Maths/math.vector\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { BoundingBox } from \"./boundingBox\";\r\nimport { BoundingSphere } from \"./boundingSphere\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\ndeclare type Collider = import(\"../Collisions/collider\").Collider;\r\n\r\nconst _result0 = { min: 0, max: 0 };\r\nconst _result1 = { min: 0, max: 0 };\r\nconst computeBoxExtents = (axis: DeepImmutable<Vector3>, box: DeepImmutable<BoundingBox>, result: { min: number; max: number }) => {\r\n const p = Vector3.Dot(box.centerWorld, axis);\r\n\r\n const r0 = Math.abs(Vector3.Dot(box.directions[0], axis)) * box.extendSize.x;\r\n const r1 = Math.abs(Vector3.Dot(box.directions[1], axis)) * box.extendSize.y;\r\n const r2 = Math.abs(Vector3.Dot(box.directions[2], axis)) * box.extendSize.z;\r\n\r\n const r = r0 + r1 + r2;\r\n result.min = p - r;\r\n result.max = p + r;\r\n};\r\n\r\nconst axisOverlap = (axis: DeepImmutable<Vector3>, box0: DeepImmutable<BoundingBox>, box1: DeepImmutable<BoundingBox>): boolean => {\r\n computeBoxExtents(axis, box0, _result0);\r\n computeBoxExtents(axis, box1, _result1);\r\n return !(_result0.min > _result1.max || _result1.min > _result0.max);\r\n};\r\n\r\n/**\r\n * Interface for cullable objects\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#back-face-culling\r\n */\r\nexport interface ICullable {\r\n /**\r\n * Checks if the object or part of the object is in the frustum\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n isInFrustum(frustumPlanes: Plane[]): boolean;\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n isCompletelyInFrustum(frustumPlanes: Plane[]): boolean;\r\n}\r\n\r\n/**\r\n * Info for a bounding data of a mesh\r\n */\r\nexport class BoundingInfo implements ICullable {\r\n /**\r\n * Bounding box for the mesh\r\n */\r\n public readonly boundingBox: BoundingBox;\r\n /**\r\n * Bounding sphere for the mesh\r\n */\r\n public readonly boundingSphere: BoundingSphere;\r\n\r\n private _isLocked = false;\r\n\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(2, Vector3.Zero);\r\n\r\n /**\r\n * Constructs bounding info\r\n * @param minimum min vector of the bounding box/sphere\r\n * @param maximum max vector of the bounding box/sphere\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(minimum: DeepImmutable<Vector3>, maximum: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n this.boundingBox = new BoundingBox(minimum, maximum, worldMatrix);\r\n this.boundingSphere = new BoundingSphere(minimum, maximum, worldMatrix);\r\n }\r\n\r\n /**\r\n * Recreates the entire bounding info from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n this.boundingBox.reConstruct(min, max, worldMatrix);\r\n this.boundingSphere.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n /**\r\n * min vector of the bounding box/sphere\r\n */\r\n public get minimum(): Vector3 {\r\n return this.boundingBox.minimum;\r\n }\r\n\r\n /**\r\n * max vector of the bounding box/sphere\r\n */\r\n public get maximum(): Vector3 {\r\n return this.boundingBox.maximum;\r\n }\r\n\r\n /**\r\n * If the info is locked and won't be updated to avoid perf overhead\r\n */\r\n public get isLocked(): boolean {\r\n return this._isLocked;\r\n }\r\n\r\n public set isLocked(value: boolean) {\r\n this._isLocked = value;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Updates the bounding sphere and box\r\n * @param world world matrix to be used to update\r\n */\r\n public update(world: DeepImmutable<Matrix>) {\r\n if (this._isLocked) {\r\n return;\r\n }\r\n this.boundingBox._update(world);\r\n this.boundingSphere._update(world);\r\n }\r\n\r\n /**\r\n * Recreate the bounding info to be centered around a specific point given a specific extend.\r\n * @param center New center of the bounding info\r\n * @param extend New extend of the bounding info\r\n * @returns the current bounding info\r\n */\r\n public centerOn(center: DeepImmutable<Vector3>, extend: DeepImmutable<Vector3>): BoundingInfo {\r\n const minimum = BoundingInfo._TmpVector3[0].copyFrom(center).subtractInPlace(extend);\r\n const maximum = BoundingInfo._TmpVector3[1].copyFrom(center).addInPlace(extend);\r\n\r\n this.boundingBox.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n this.boundingSphere.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Grows the bounding info to include the given point.\r\n * @param point The point that will be included in the current bounding info (in local space)\r\n * @returns the current bounding info\r\n */\r\n public encapsulate(point: Vector3): BoundingInfo {\r\n const minimum = Vector3.Minimize(this.minimum, point);\r\n const maximum = Vector3.Maximize(this.maximum, point);\r\n this.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Grows the bounding info to encapsulate the given bounding info.\r\n * @param toEncapsulate The bounding info that will be encapsulated in the current bounding info\r\n * @returns the current bounding info\r\n */\r\n public encapsulateBoundingInfo(toEncapsulate: BoundingInfo): BoundingInfo {\r\n const invw = TmpVectors.Matrix[0];\r\n this.boundingBox.getWorldMatrix().invertToRef(invw);\r\n\r\n const v = TmpVectors.Vector3[0];\r\n\r\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.minimumWorld, invw, v);\r\n this.encapsulate(v);\r\n\r\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.maximumWorld, invw, v);\r\n this.encapsulate(v);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Scale the current bounding info by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding info\r\n */\r\n public scale(factor: number): BoundingInfo {\r\n this.boundingBox.scale(factor);\r\n this.boundingSphere.scale(factor);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns `true` if the bounding info is within the frustum defined by the passed array of planes.\r\n * @param frustumPlanes defines the frustum to test\r\n * @param strategy defines the strategy to use for the culling (default is BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD)\r\n * The different strategies available are:\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD most accurate but slower @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_STANDARD\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY faster but less accurate @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\r\n * @returns true if the bounding info is in the frustum planes\r\n */\r\n public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>, strategy: number = Constants.MESHES_CULLINGSTRATEGY_STANDARD): boolean {\r\n const inclusionTest =\r\n strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n if (inclusionTest) {\r\n if (this.boundingSphere.isCenterInFrustum(frustumPlanes)) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!this.boundingSphere.isInFrustum(frustumPlanes)) {\r\n return false;\r\n }\r\n\r\n const bSphereOnlyTest =\r\n strategy === Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n if (bSphereOnlyTest) {\r\n return true;\r\n }\r\n\r\n return this.boundingBox.isInFrustum(frustumPlanes);\r\n }\r\n\r\n /**\r\n * Gets the world distance between the min and max points of the bounding box\r\n */\r\n public get diagonalLength(): number {\r\n const boundingBox = this.boundingBox;\r\n const diag = boundingBox.maximumWorld.subtractToRef(boundingBox.minimumWorld, BoundingInfo._TmpVector3[0]);\r\n return diag.length();\r\n }\r\n\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n return this.boundingBox.isCompletelyInFrustum(frustumPlanes);\r\n }\r\n /**\r\n * @internal\r\n */\r\n public _checkCollision(collider: Collider): boolean {\r\n return collider._canDoCollision(this.boundingSphere.centerWorld, this.boundingSphere.radiusWorld, this.boundingBox.minimumWorld, this.boundingBox.maximumWorld);\r\n }\r\n\r\n /**\r\n * Checks if a point is inside the bounding box and bounding sphere or the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n * @param point the point to check intersection with\r\n * @returns if the point intersects\r\n */\r\n public intersectsPoint(point: DeepImmutable<Vector3>): boolean {\r\n if (!this.boundingSphere.centerWorld) {\r\n return false;\r\n }\r\n\r\n if (!this.boundingSphere.intersectsPoint(point)) {\r\n return false;\r\n }\r\n\r\n if (!this.boundingBox.intersectsPoint(point)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Checks if another bounding info intersects the bounding box and bounding sphere or the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n * @param boundingInfo the bounding info to check intersection with\r\n * @param precise if the intersection should be done using OBB\r\n * @returns if the bounding info intersects\r\n */\r\n public intersects(boundingInfo: DeepImmutable<BoundingInfo>, precise: boolean): boolean {\r\n if (!BoundingSphere.Intersects(this.boundingSphere, boundingInfo.boundingSphere)) {\r\n return false;\r\n }\r\n\r\n if (!BoundingBox.Intersects(this.boundingBox, boundingInfo.boundingBox)) {\r\n return false;\r\n }\r\n\r\n if (!precise) {\r\n return true;\r\n }\r\n\r\n const box0 = this.boundingBox;\r\n const box1 = boundingInfo.boundingBox;\r\n\r\n if (!axisOverlap(box0.directions[0], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box0.directions[1], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box0.directions[2], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[0], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[1], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[2], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"boundingInfo.js","sourceRoot":"","sources":["../../../../lts/core/generated/Culling/boundingInfo.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,WAAW,EAA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AAE;YACjF,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YACjF,OAAO,KAAK,CAAC;SAChB;QACD,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE;YACjF,OAAO,KAAK,CAAC;SAChB;QAED,OAAO,IAAI,CAAC;IAChB,CAAC;;AAjRuB,wBAAW,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,AAAzC,CAA0C","sourcesContent":["import type { DeepImmutable } from \"../types\";\r\nimport { ArrayTools } from \"../Misc/arrayTools\";\r\nimport type { Matrix } from \"../Maths/math.vector\";\r\nimport { TmpVectors } from \"../Maths/math.vector\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport { Constants } from \"../Engines/constants\";\r\nimport { BoundingBox } from \"./boundingBox\";\r\nimport { BoundingSphere } from \"./boundingSphere\";\r\nimport type { Plane } from \"../Maths/math.plane\";\r\n\r\ndeclare type Collider = import(\"../Collisions/collider\").Collider;\r\n\r\nconst _result0 = { min: 0, max: 0 };\r\nconst _result1 = { min: 0, max: 0 };\r\nconst computeBoxExtents = (axis: DeepImmutable<Vector3>, box: DeepImmutable<BoundingBox>, result: { min: number; max: number }) => {\r\n const p = Vector3.Dot(box.centerWorld, axis);\r\n\r\n const r0 = Math.abs(Vector3.Dot(box.directions[0], axis)) * box.extendSize.x;\r\n const r1 = Math.abs(Vector3.Dot(box.directions[1], axis)) * box.extendSize.y;\r\n const r2 = Math.abs(Vector3.Dot(box.directions[2], axis)) * box.extendSize.z;\r\n\r\n const r = r0 + r1 + r2;\r\n result.min = p - r;\r\n result.max = p + r;\r\n};\r\n\r\nconst axisOverlap = (axis: DeepImmutable<Vector3>, box0: DeepImmutable<BoundingBox>, box1: DeepImmutable<BoundingBox>): boolean => {\r\n computeBoxExtents(axis, box0, _result0);\r\n computeBoxExtents(axis, box1, _result1);\r\n return !(_result0.min > _result1.max || _result1.min > _result0.max);\r\n};\r\n\r\n/**\r\n * Interface for cullable objects\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/materials/using/materials_introduction#back-face-culling\r\n */\r\nexport interface ICullable {\r\n /**\r\n * Checks if the object or part of the object is in the frustum\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n isInFrustum(frustumPlanes: Plane[]): boolean;\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n isCompletelyInFrustum(frustumPlanes: Plane[]): boolean;\r\n}\r\n\r\n/**\r\n * Info for a bounding data of a mesh\r\n */\r\nexport class BoundingInfo implements ICullable {\r\n /**\r\n * Bounding box for the mesh\r\n */\r\n public readonly boundingBox: BoundingBox;\r\n /**\r\n * Bounding sphere for the mesh\r\n */\r\n public readonly boundingSphere: BoundingSphere;\r\n\r\n private _isLocked = false;\r\n\r\n private static readonly _TmpVector3 = ArrayTools.BuildArray(2, Vector3.Zero);\r\n\r\n /**\r\n * Constructs bounding info\r\n * @param minimum min vector of the bounding box/sphere\r\n * @param maximum max vector of the bounding box/sphere\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n constructor(minimum: DeepImmutable<Vector3>, maximum: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n this.boundingBox = new BoundingBox(minimum, maximum, worldMatrix);\r\n this.boundingSphere = new BoundingSphere(minimum, maximum, worldMatrix);\r\n }\r\n\r\n /**\r\n * Recreates the entire bounding info from scratch as if we call the constructor in place\r\n * @param min defines the new minimum vector (in local space)\r\n * @param max defines the new maximum vector (in local space)\r\n * @param worldMatrix defines the new world matrix\r\n */\r\n public reConstruct(min: DeepImmutable<Vector3>, max: DeepImmutable<Vector3>, worldMatrix?: DeepImmutable<Matrix>) {\r\n this.boundingBox.reConstruct(min, max, worldMatrix);\r\n this.boundingSphere.reConstruct(min, max, worldMatrix);\r\n }\r\n\r\n /**\r\n * min vector of the bounding box/sphere\r\n */\r\n public get minimum(): Vector3 {\r\n return this.boundingBox.minimum;\r\n }\r\n\r\n /**\r\n * max vector of the bounding box/sphere\r\n */\r\n public get maximum(): Vector3 {\r\n return this.boundingBox.maximum;\r\n }\r\n\r\n /**\r\n * If the info is locked and won't be updated to avoid perf overhead\r\n */\r\n public get isLocked(): boolean {\r\n return this._isLocked;\r\n }\r\n\r\n public set isLocked(value: boolean) {\r\n this._isLocked = value;\r\n }\r\n\r\n // Methods\r\n /**\r\n * Updates the bounding sphere and box\r\n * @param world world matrix to be used to update\r\n */\r\n public update(world: DeepImmutable<Matrix>) {\r\n if (this._isLocked) {\r\n return;\r\n }\r\n this.boundingBox._update(world);\r\n this.boundingSphere._update(world);\r\n }\r\n\r\n /**\r\n * Recreate the bounding info to be centered around a specific point given a specific extend.\r\n * @param center New center of the bounding info\r\n * @param extend New extend of the bounding info\r\n * @returns the current bounding info\r\n */\r\n public centerOn(center: DeepImmutable<Vector3>, extend: DeepImmutable<Vector3>): BoundingInfo {\r\n const minimum = BoundingInfo._TmpVector3[0].copyFrom(center).subtractInPlace(extend);\r\n const maximum = BoundingInfo._TmpVector3[1].copyFrom(center).addInPlace(extend);\r\n\r\n this.boundingBox.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n this.boundingSphere.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Grows the bounding info to include the given point.\r\n * @param point The point that will be included in the current bounding info (in local space)\r\n * @returns the current bounding info\r\n */\r\n public encapsulate(point: Vector3): BoundingInfo {\r\n const minimum = Vector3.Minimize(this.minimum, point);\r\n const maximum = Vector3.Maximize(this.maximum, point);\r\n this.reConstruct(minimum, maximum, this.boundingBox.getWorldMatrix());\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Grows the bounding info to encapsulate the given bounding info.\r\n * @param toEncapsulate The bounding info that will be encapsulated in the current bounding info\r\n * @returns the current bounding info\r\n */\r\n public encapsulateBoundingInfo(toEncapsulate: BoundingInfo): BoundingInfo {\r\n const invw = TmpVectors.Matrix[0];\r\n this.boundingBox.getWorldMatrix().invertToRef(invw);\r\n\r\n const v = TmpVectors.Vector3[0];\r\n\r\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.minimumWorld, invw, v);\r\n this.encapsulate(v);\r\n\r\n Vector3.TransformCoordinatesToRef(toEncapsulate.boundingBox.maximumWorld, invw, v);\r\n this.encapsulate(v);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Scale the current bounding info by applying a scale factor\r\n * @param factor defines the scale factor to apply\r\n * @returns the current bounding info\r\n */\r\n public scale(factor: number): BoundingInfo {\r\n this.boundingBox.scale(factor);\r\n this.boundingSphere.scale(factor);\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Returns `true` if the bounding info is within the frustum defined by the passed array of planes.\r\n * @param frustumPlanes defines the frustum to test\r\n * @param strategy defines the strategy to use for the culling (default is BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD)\r\n * The different strategies available are:\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_STANDARD most accurate but slower @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_STANDARD\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY faster but less accurate @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION\r\n * * BABYLON.AbstractMesh.CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY can be faster if always visible @see https://doc.babylonjs.com/typedoc/classes/BABYLON.AbstractMesh#CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY\r\n * @returns true if the bounding info is in the frustum planes\r\n */\r\n public isInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>, strategy: number = Constants.MESHES_CULLINGSTRATEGY_STANDARD): boolean {\r\n const inclusionTest =\r\n strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n if (inclusionTest) {\r\n if (this.boundingSphere.isCenterInFrustum(frustumPlanes)) {\r\n return true;\r\n }\r\n }\r\n\r\n if (!this.boundingSphere.isInFrustum(frustumPlanes)) {\r\n return false;\r\n }\r\n\r\n const bSphereOnlyTest =\r\n strategy === Constants.MESHES_CULLINGSTRATEGY_BOUNDINGSPHERE_ONLY || strategy === Constants.MESHES_CULLINGSTRATEGY_OPTIMISTIC_INCLUSION_THEN_BSPHERE_ONLY;\r\n if (bSphereOnlyTest) {\r\n return true;\r\n }\r\n\r\n return this.boundingBox.isInFrustum(frustumPlanes);\r\n }\r\n\r\n /**\r\n * Gets the world distance between the min and max points of the bounding box\r\n */\r\n public get diagonalLength(): number {\r\n const boundingBox = this.boundingBox;\r\n const diag = boundingBox.maximumWorld.subtractToRef(boundingBox.minimumWorld, BoundingInfo._TmpVector3[0]);\r\n return diag.length();\r\n }\r\n\r\n /**\r\n * Checks if a cullable object (mesh...) is in the camera frustum\r\n * Unlike isInFrustum this checks the full bounding box\r\n * @param frustumPlanes Camera near/planes\r\n * @returns true if the object is in frustum otherwise false\r\n */\r\n public isCompletelyInFrustum(frustumPlanes: Array<DeepImmutable<Plane>>): boolean {\r\n return this.boundingBox.isCompletelyInFrustum(frustumPlanes);\r\n }\r\n /**\r\n * @internal\r\n */\r\n public _checkCollision(collider: Collider): boolean {\r\n return collider._canDoCollision(this.boundingSphere.centerWorld, this.boundingSphere.radiusWorld, this.boundingBox.minimumWorld, this.boundingBox.maximumWorld);\r\n }\r\n\r\n /**\r\n * Checks if a point is inside the bounding box and bounding sphere or the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n * @param point the point to check intersection with\r\n * @returns if the point intersects\r\n */\r\n public intersectsPoint(point: DeepImmutable<Vector3>): boolean {\r\n if (!this.boundingSphere.centerWorld) {\r\n return false;\r\n }\r\n\r\n if (!this.boundingSphere.intersectsPoint(point)) {\r\n return false;\r\n }\r\n\r\n if (!this.boundingBox.intersectsPoint(point)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Checks if another bounding info intersects the bounding box and bounding sphere or the mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/interactions/mesh_intersect\r\n * @param boundingInfo the bounding info to check intersection with\r\n * @param precise if the intersection should be done using OBB\r\n * @returns if the bounding info intersects\r\n */\r\n public intersects(boundingInfo: DeepImmutable<BoundingInfo>, precise: boolean): boolean {\r\n if (!BoundingSphere.Intersects(this.boundingSphere, boundingInfo.boundingSphere)) {\r\n return false;\r\n }\r\n\r\n if (!BoundingBox.Intersects(this.boundingBox, boundingInfo.boundingBox)) {\r\n return false;\r\n }\r\n\r\n if (!precise) {\r\n return true;\r\n }\r\n\r\n const box0 = this.boundingBox;\r\n const box1 = boundingInfo.boundingBox;\r\n\r\n if (!axisOverlap(box0.directions[0], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box0.directions[1], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box0.directions[2], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[0], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[1], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(box1.directions[2], box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[0], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[1], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[0]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[1]), box0, box1)) {\r\n return false;\r\n }\r\n if (!axisOverlap(Vector3.Cross(box0.directions[2], box1.directions[2]), box0, box1)) {\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n}\r\n"]}
|