@babylonjs/core 6.26.0 → 6.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/Behaviors/Meshes/attachToBoxBehavior.js.map +1 -1
  2. package/Cameras/Inputs/flyCameraMouseInput.js.map +1 -1
  3. package/Cameras/VR/vrExperienceHelper.js.map +1 -1
  4. package/Collisions/intersectionInfo.js.map +1 -1
  5. package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js.map +1 -1
  6. package/Engines/Processors/Expressions/Operators/shaderDefineIsDefinedOperator.js.map +1 -1
  7. package/Engines/WebGPU/webgpuBundleList.js.map +1 -1
  8. package/Engines/thinEngine.js +2 -2
  9. package/Engines/thinEngine.js.map +1 -1
  10. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.d.ts +3 -4
  11. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js +5 -6
  12. package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js.map +1 -1
  13. package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.d.ts +22 -0
  14. package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js +26 -0
  15. package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js.map +1 -0
  16. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.d.ts +3 -5
  17. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js +5 -6
  18. package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js.map +1 -1
  19. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.d.ts +3 -4
  20. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js +5 -6
  21. package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js.map +1 -1
  22. package/FlowGraph/flowGraphConnection.d.ts +1 -1
  23. package/FlowGraph/flowGraphConnection.js +2 -1
  24. package/FlowGraph/flowGraphConnection.js.map +1 -1
  25. package/FlowGraph/flowGraphContext.d.ts +10 -0
  26. package/FlowGraph/flowGraphContext.js +14 -0
  27. package/FlowGraph/flowGraphContext.js.map +1 -1
  28. package/FlowGraph/flowGraphDataConnection.js.map +1 -1
  29. package/FlowGraph/flowGraphRichTypes.js.map +1 -1
  30. package/FlowGraph/flowGraphSignalConnection.js +1 -0
  31. package/FlowGraph/flowGraphSignalConnection.js.map +1 -1
  32. package/Layers/highlightLayer.js.map +1 -1
  33. package/Loading/loadingScreen.js.map +1 -1
  34. package/Materials/Background/backgroundMaterial.d.ts +16 -0
  35. package/Materials/Background/backgroundMaterial.js +44 -0
  36. package/Materials/Background/backgroundMaterial.js.map +1 -1
  37. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js +0 -1
  38. package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
  39. package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
  40. package/Materials/Node/nodeMaterial.js +6 -2
  41. package/Materials/Node/nodeMaterial.js.map +1 -1
  42. package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
  43. package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
  44. package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
  45. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.d.ts +10 -1
  46. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js +27 -5
  47. package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js.map +1 -1
  48. package/Meshes/Node/Blocks/mergeGeometryBlock.js +16 -4
  49. package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
  50. package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.d.ts +5 -0
  51. package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.js.map +1 -1
  52. package/Meshes/Node/nodeGeometryBuildState.js +3 -0
  53. package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
  54. package/Meshes/csg.js.map +1 -1
  55. package/Meshes/geodesicMesh.js.map +1 -1
  56. package/Meshes/meshSimplification.js.map +1 -1
  57. package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
  58. package/Misc/fileTools.js.map +1 -1
  59. package/Physics/physicsHelper.js.map +1 -1
  60. package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
  61. package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -1
  62. package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -1
  63. package/Physics/v1/physicsEngine.js.map +1 -1
  64. package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
  65. package/Physics/v2/physicsEngine.js.map +1 -1
  66. package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
  67. package/PostProcesses/bloomEffect.js.map +1 -1
  68. package/Rendering/boundingBoxRenderer.js +6 -2
  69. package/Rendering/boundingBoxRenderer.js.map +1 -1
  70. package/Shaders/ShadersInclude/backgroundFragmentDeclaration.js +3 -0
  71. package/Shaders/ShadersInclude/backgroundFragmentDeclaration.js.map +1 -1
  72. package/Shaders/ShadersInclude/backgroundUboDeclaration.js +1 -8
  73. package/Shaders/ShadersInclude/backgroundUboDeclaration.js.map +1 -1
  74. package/Shaders/ShadersInclude/helperFunctions.js +1 -1
  75. package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
  76. package/Shaders/ShadersInclude/pbrHelperFunctions.js +1 -3
  77. package/Shaders/ShadersInclude/pbrHelperFunctions.js.map +1 -1
  78. package/Shaders/background.fragment.js +11 -1
  79. package/Shaders/background.fragment.js.map +1 -1
  80. package/Shaders/default.fragment.js +0 -1
  81. package/Shaders/default.fragment.js.map +1 -1
  82. package/XR/features/WebXRAnchorSystem.js.map +1 -1
  83. package/XR/features/WebXRControllerPhysics.js.map +1 -1
  84. package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
  85. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  86. package/XR/features/WebXRDepthSensing.js.map +1 -1
  87. package/XR/features/WebXRLayers.js.map +1 -1
  88. package/XR/features/WebXRMeshDetector.js.map +1 -1
  89. package/XR/features/WebXRNearInteraction.js.map +1 -1
  90. package/XR/features/WebXRPlaneDetector.js.map +1 -1
  91. package/XR/features/WebXRSpaceWarp.js.map +1 -1
  92. package/XR/native/nativeXRRenderTarget.js.map +1 -1
  93. package/XR/webXRCamera.js.map +1 -1
  94. package/XR/webXRManagedOutputCanvas.js.map +1 -1
  95. package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
  96. package/XR/webXRWebGLLayer.js.map +1 -1
  97. package/assetContainer.js.map +1 -1
  98. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"default.fragment.js","sourceRoot":"","sources":["../../../../dev/core/src/Shaders/default.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,6CAA6C,CAAC;AACrD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,2CAA2C,CAAC;AACnD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,2CAA2C,CAAC;AACnD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,0CAA0C,CAAC;AAClD,OAAO,2CAA2C,CAAC;AACnD,OAAO,6CAA6C,CAAC;AACrD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,6CAA6C,CAAC;AACrD,OAAO,2CAA2C,CAAC;AACnD,OAAO,4CAA4C,CAAC;AACpD,OAAO,wCAAwC,CAAC;AAChD,OAAO,+CAA+C,CAAC;AACvD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,yCAAyC,CAAC;AACjD,OAAO,oCAAoC,CAAC;AAC5C,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCAAgC,CAAC;AACxC,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCAAgC,CAAC;AACxC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,8BAA8B,CAAC;AACtC,OAAO,8BAA8B,CAAC;AAEtC,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAClC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Ud,CAAC;AACF,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/defaultFragmentDeclaration\";\nimport \"./ShadersInclude/defaultUboDeclaration\";\nimport \"./ShadersInclude/prePassDeclaration\";\nimport \"./ShadersInclude/oitDeclaration\";\nimport \"./ShadersInclude/mainUVVaryingDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/lightFragmentDeclaration\";\nimport \"./ShadersInclude/lightUboDeclaration\";\nimport \"./ShadersInclude/lightsFragmentFunctions\";\nimport \"./ShadersInclude/shadowsFragmentFunctions\";\nimport \"./ShadersInclude/samplerFragmentDeclaration\";\nimport \"./ShadersInclude/fresnelFunction\";\nimport \"./ShadersInclude/reflectionFunction\";\nimport \"./ShadersInclude/imageProcessingDeclaration\";\nimport \"./ShadersInclude/imageProcessingFunctions\";\nimport \"./ShadersInclude/bumpFragmentMainFunctions\";\nimport \"./ShadersInclude/bumpFragmentFunctions\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/bumpFragment\";\nimport \"./ShadersInclude/decalFragment\";\nimport \"./ShadersInclude/depthPrePass\";\nimport \"./ShadersInclude/lightFragment\";\nimport \"./ShadersInclude/logDepthFragment\";\nimport \"./ShadersInclude/fogFragment\";\nimport \"./ShadersInclude/oitFragment\";\n\nconst name = \"defaultPixelShader\";\nconst shader = `#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include<prePassDeclaration>[SCENE_MRT_COUNT]\n#include<oitDeclaration>\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\n#define RECIPROCAL_PI2 0.15915494\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include<mainUVVaryingDeclaration>[1..7]\n#include<helperFunctions>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<samplerFragmentDeclaration>(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_SAMPLERNAME_,diffuse)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULARTERM)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_SAMPLERNAME_,specular)\n#endif\n#include<fresnelFunction>\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentMainFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#if defined(ALPHATEST) && !defined(ALPHATEST_AFTERALLALPHACOMPUTATIONS)\nif (baseColor.a<alphaCutOff)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_ALPHA\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#if defined(DECAL) && !defined(DECAL_AFTER_DETAIL)\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#include<depthPrePass>\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef DETAIL\nbaseColor.rgb=baseColor.rgb*2.0*mix(0.5,detailColor.r,vDetailInfos.y);\n#endif\n#if defined(DECAL) && defined(DECAL_AFTER_DETAIL)\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;float aggShadow=0.;float numLights=0.;\n#ifdef LIGHTMAP\nvec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);\n#ifdef RGBDLIGHTMAP\nlightmapColor.rgb=fromRGBD(lightmapColor);\n#endif\nlightmapColor.rgb*=vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\naggShadow=aggShadow/numLights;vec4 refractionColor=vec4(0.,0.,0.,1.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\n#ifdef USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,vRefractionSize,vRefractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec4 refractionLookup=textureCube(refractionCubeSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=texture2D(refraction2DSampler,refractionCoords);\n#endif\n#ifdef RGBDREFRACTION\nrefractionColor.rgb=fromRGBD(refractionColor);\n#endif\n#ifdef IS_REFRACTION_LINEAR\nrefractionColor.rgb=toGammaSpace(refractionColor.rgb);\n#endif\nrefractionColor.rgb*=vRefractionInfos.x;\n#endif\nvec4 reflectionColor=vec4(0.,0.,0.,1.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nvReflectionUVW.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias);\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW);\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;reflectionColor=texture2D(reflection2DSampler,coords);\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef IS_REFLECTION_LINEAR\nreflectionColor.rgb=toGammaSpace(reflectionColor.rgb);\n#endif\nreflectionColor.rgb*=vReflectionInfos.x;\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor.rgb*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);refractionColor.rgb*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n#ifdef ALPHATEST\n#ifdef ALPHATEST_AFTERALLALPHACOMPUTATIONS\nif (alpha<alphaCutOff)\ndiscard;\n#endif\n#ifndef ALPHABLEND\nalpha=1.0;\n#endif\n#endif\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor.rgb,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+emissiveColor+refractionColor.rgb,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);\n#endif\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor.rgb;\n#else\ncolor.rgb+=lightmapColor.rgb;\n#endif\n#endif\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FOG\ncolor.rgb=max(color.rgb,0.);\n#include<logDepthFragment>\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);\n#endif\n#endif\ncolor.a*=visibility;\n#ifdef PREMULTIPLYALPHA\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\n#ifdef PREPASS\nfloat writeGeometryInfo=color.a>0.4 ? 1.0 : 0.0;gl_FragData[0]=color; \n#ifdef PREPASS_POSITION\ngl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);\n#endif\n#ifdef PREPASS_VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);\n#endif\n#ifdef PREPASS_IRRADIANCE\ngl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_DEPTH\ngl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_NORMAL\n#ifdef PREPASS_NORMAL_WORLDSPACE\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalW,writeGeometryInfo); \n#else\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo); \n#endif\n#endif\n#ifdef PREPASS_ALBEDO_SQRT\ngl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_REFLECTIVITY\n#if defined(SPECULARTERM)\n#if defined(SPECULAR)\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularMapColor))*writeGeometryInfo; \n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularColor),1.0)*writeGeometryInfo;\n#endif\n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(0.0,0.0,0.0,1.0)*writeGeometryInfo;\n#endif\n#endif\n#endif\n#if !defined(PREPASS) || defined(WEBGL2)\ngl_FragColor=color;\n#endif\n#include<oitFragment>\n#if ORDER_INDEPENDENT_TRANSPARENCY\nif (fragDepth==nearestDepth) {frontColor.rgb+=color.rgb*color.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-color.a);} else {backColor+=color;}\n#endif\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const defaultPixelShader = { name, shader };\n"]}
1
+ {"version":3,"file":"default.fragment.js","sourceRoot":"","sources":["../../../../dev/core/src/Shaders/default.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,6CAA6C,CAAC;AACrD,OAAO,wCAAwC,CAAC;AAChD,OAAO,qCAAqC,CAAC;AAC7C,OAAO,iCAAiC,CAAC;AACzC,OAAO,2CAA2C,CAAC;AACnD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,2CAA2C,CAAC;AACnD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,0CAA0C,CAAC;AAClD,OAAO,2CAA2C,CAAC;AACnD,OAAO,6CAA6C,CAAC;AACrD,OAAO,kCAAkC,CAAC;AAC1C,OAAO,qCAAqC,CAAC;AAC7C,OAAO,6CAA6C,CAAC;AACrD,OAAO,2CAA2C,CAAC;AACnD,OAAO,4CAA4C,CAAC;AACpD,OAAO,wCAAwC,CAAC;AAChD,OAAO,+CAA+C,CAAC;AACvD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,yCAAyC,CAAC;AACjD,OAAO,oCAAoC,CAAC;AAC5C,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCAAgC,CAAC;AACxC,OAAO,+BAA+B,CAAC;AACvC,OAAO,gCAAgC,CAAC;AACxC,OAAO,mCAAmC,CAAC;AAC3C,OAAO,8BAA8B,CAAC;AACtC,OAAO,8BAA8B,CAAC;AAEtC,MAAM,IAAI,GAAG,oBAAoB,CAAC;AAClC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyUd,CAAC;AACF,aAAa;AACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxC,gBAAgB;AAChB,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\nimport \"./ShadersInclude/defaultFragmentDeclaration\";\nimport \"./ShadersInclude/defaultUboDeclaration\";\nimport \"./ShadersInclude/prePassDeclaration\";\nimport \"./ShadersInclude/oitDeclaration\";\nimport \"./ShadersInclude/mainUVVaryingDeclaration\";\nimport \"./ShadersInclude/helperFunctions\";\nimport \"./ShadersInclude/lightFragmentDeclaration\";\nimport \"./ShadersInclude/lightUboDeclaration\";\nimport \"./ShadersInclude/lightsFragmentFunctions\";\nimport \"./ShadersInclude/shadowsFragmentFunctions\";\nimport \"./ShadersInclude/samplerFragmentDeclaration\";\nimport \"./ShadersInclude/fresnelFunction\";\nimport \"./ShadersInclude/reflectionFunction\";\nimport \"./ShadersInclude/imageProcessingDeclaration\";\nimport \"./ShadersInclude/imageProcessingFunctions\";\nimport \"./ShadersInclude/bumpFragmentMainFunctions\";\nimport \"./ShadersInclude/bumpFragmentFunctions\";\nimport \"./ShadersInclude/clipPlaneFragmentDeclaration\";\nimport \"./ShadersInclude/logDepthDeclaration\";\nimport \"./ShadersInclude/fogFragmentDeclaration\";\nimport \"./ShadersInclude/clipPlaneFragment\";\nimport \"./ShadersInclude/bumpFragment\";\nimport \"./ShadersInclude/decalFragment\";\nimport \"./ShadersInclude/depthPrePass\";\nimport \"./ShadersInclude/lightFragment\";\nimport \"./ShadersInclude/logDepthFragment\";\nimport \"./ShadersInclude/fogFragment\";\nimport \"./ShadersInclude/oitFragment\";\n\nconst name = \"defaultPixelShader\";\nconst shader = `#include<__decl__defaultFragment>\n#if defined(BUMP) || !defined(NORMAL)\n#extension GL_OES_standard_derivatives : enable\n#endif\n#include<prePassDeclaration>[SCENE_MRT_COUNT]\n#include<oitDeclaration>\n#define CUSTOM_FRAGMENT_BEGIN\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nvarying vec4 vColor;\n#endif\n#include<mainUVVaryingDeclaration>[1..7]\n#include<helperFunctions>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<samplerFragmentDeclaration>(_DEFINENAME_,DIFFUSE,_VARYINGNAME_,Diffuse,_SAMPLERNAME_,diffuse)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,AMBIENT,_VARYINGNAME_,Ambient,_SAMPLERNAME_,ambient)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,OPACITY,_VARYINGNAME_,Opacity,_SAMPLERNAME_,opacity)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,EMISSIVE,_VARYINGNAME_,Emissive,_SAMPLERNAME_,emissive)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,LIGHTMAP,_VARYINGNAME_,Lightmap,_SAMPLERNAME_,lightmap)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,DECAL,_VARYINGNAME_,Decal,_SAMPLERNAME_,decal)\n#ifdef REFRACTION\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\n#endif\n#endif\n#if defined(SPECULARTERM)\n#include<samplerFragmentDeclaration>(_DEFINENAME_,SPECULAR,_VARYINGNAME_,Specular,_SAMPLERNAME_,specular)\n#endif\n#include<fresnelFunction>\n#ifdef REFLECTION\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#if defined(REFLECTIONMAP_EQUIRECTANGULAR_FIXED) || defined(REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED)\nvarying vec3 vDirectionW;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n#include<imageProcessingDeclaration>\n#include<imageProcessingFunctions>\n#include<bumpFragmentMainFunctions>\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n#include<fogFragmentDeclaration>\n#define CUSTOM_FRAGMENT_DEFINITIONS\nvoid main(void) {\n#define CUSTOM_FRAGMENT_MAIN_BEGIN\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition.xyz-vPositionW);vec4 baseColor=vec4(1.,1.,1.,1.);vec3 diffuseColor=vDiffuseColor.rgb;float alpha=vDiffuseColor.a;\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=normalize(-cross(dFdx(vPositionW),dFdy(vPositionW)));\n#endif\n#include<bumpFragment>\n#ifdef TWOSIDEDLIGHTING\nnormalW=gl_FrontFacing ? normalW : -normalW;\n#endif\n#ifdef DIFFUSE\nbaseColor=texture2D(diffuseSampler,vDiffuseUV+uvOffset);\n#if defined(ALPHATEST) && !defined(ALPHATEST_AFTERALLALPHACOMPUTATIONS)\nif (baseColor.a<alphaCutOff)\ndiscard;\n#endif\n#ifdef ALPHAFROMDIFFUSE\nalpha*=baseColor.a;\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_ALPHA\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#if defined(DECAL) && !defined(DECAL_AFTER_DETAIL)\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#include<depthPrePass>\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef DETAIL\nbaseColor.rgb=baseColor.rgb*2.0*mix(0.5,detailColor.r,vDetailInfos.y);\n#endif\n#if defined(DECAL) && defined(DECAL_AFTER_DETAIL)\nvec4 decalColor=texture2D(decalSampler,vDecalUV+uvOffset);\n#include<decalFragment>(surfaceAlbedo,baseColor,GAMMADECAL,_GAMMADECAL_NOTUSED_)\n#endif\n#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE\nvec3 baseAmbientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nbaseAmbientColor=texture2D(ambientSampler,vAmbientUV+uvOffset).rgb*vAmbientInfos.y;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_LIGHTS\n#ifdef SPECULARTERM\nfloat glossiness=vSpecularColor.a;vec3 specularColor=vSpecularColor.rgb;\n#ifdef SPECULAR\nvec4 specularMapColor=texture2D(specularSampler,vSpecularUV+uvOffset);specularColor=specularMapColor.rgb;\n#ifdef GLOSSINESS\nglossiness=glossiness*specularMapColor.a;\n#endif\n#endif\n#else\nfloat glossiness=0.;\n#endif\nvec3 diffuseBase=vec3(0.,0.,0.);lightingInfo info;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\nfloat shadow=1.;float aggShadow=0.;float numLights=0.;\n#ifdef LIGHTMAP\nvec4 lightmapColor=texture2D(lightmapSampler,vLightmapUV+uvOffset);\n#ifdef RGBDLIGHTMAP\nlightmapColor.rgb=fromRGBD(lightmapColor);\n#endif\nlightmapColor.rgb*=vLightmapInfos.y;\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\naggShadow=aggShadow/numLights;vec4 refractionColor=vec4(0.,0.,0.,1.);\n#ifdef REFRACTION\nvec3 refractionVector=normalize(refract(-viewDirectionW,normalW,vRefractionInfos.y));\n#ifdef REFRACTIONMAP_3D\n#ifdef USE_LOCAL_REFRACTIONMAP_CUBIC\nrefractionVector=parallaxCorrectNormal(vPositionW,refractionVector,vRefractionSize,vRefractionPosition);\n#endif\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;vec4 refractionLookup=textureCube(refractionCubeSampler,refractionVector);if (dot(refractionVector,viewDirectionW)<1.0) {refractionColor=refractionLookup;}\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));vec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;refractionCoords.y=1.0-refractionCoords.y;refractionColor=texture2D(refraction2DSampler,refractionCoords);\n#endif\n#ifdef RGBDREFRACTION\nrefractionColor.rgb=fromRGBD(refractionColor);\n#endif\n#ifdef IS_REFRACTION_LINEAR\nrefractionColor.rgb=toGammaSpace(refractionColor.rgb);\n#endif\nrefractionColor.rgb*=vRefractionInfos.x;\n#endif\nvec4 reflectionColor=vec4(0.,0.,0.,1.);\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef REFLECTIONMAP_OPPOSITEZ\nvReflectionUVW.z*=-1.0;\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef ROUGHNESS\nfloat bias=vReflectionInfos.y;\n#ifdef SPECULARTERM\n#ifdef SPECULAR\n#ifdef GLOSSINESS\nbias*=(1.0-specularMapColor.a);\n#endif\n#endif\n#endif\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW,bias);\n#else\nreflectionColor=textureCube(reflectionCubeSampler,vReflectionUVW);\n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;reflectionColor=texture2D(reflection2DSampler,coords);\n#endif\n#ifdef RGBDREFLECTION\nreflectionColor.rgb=fromRGBD(reflectionColor);\n#endif\n#ifdef IS_REFLECTION_LINEAR\nreflectionColor.rgb=toGammaSpace(reflectionColor.rgb);\n#endif\nreflectionColor.rgb*=vReflectionInfos.x;\n#ifdef REFLECTIONFRESNEL\nfloat reflectionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,reflectionRightColor.a,reflectionLeftColor.a);\n#ifdef REFLECTIONFRESNELFROMSPECULAR\n#ifdef SPECULARTERM\nreflectionColor.rgb*=specularColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#else\nreflectionColor.rgb*=reflectionLeftColor.rgb*(1.0-reflectionFresnelTerm)+reflectionFresnelTerm*reflectionRightColor.rgb;\n#endif\n#endif\n#endif\n#ifdef REFRACTIONFRESNEL\nfloat refractionFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,refractionRightColor.a,refractionLeftColor.a);refractionColor.rgb*=refractionLeftColor.rgb*(1.0-refractionFresnelTerm)+refractionFresnelTerm*refractionRightColor.rgb;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV+uvOffset);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);alpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);alpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n#ifdef ALPHATEST\n#ifdef ALPHATEST_AFTERALLALPHACOMPUTATIONS\nif (alpha<alphaCutOff)\ndiscard;\n#endif\n#ifndef ALPHABLEND\nalpha=1.0;\n#endif\n#endif\nvec3 emissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nemissiveColor+=texture2D(emissiveSampler,vEmissiveUV+uvOffset).rgb*vEmissiveInfos.y;\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);emissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n#ifdef DIFFUSEFRESNEL\nfloat diffuseFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,diffuseRightColor.a,diffuseLeftColor.a);diffuseBase*=diffuseLeftColor.rgb*(1.0-diffuseFresnelTerm)+diffuseFresnelTerm*diffuseRightColor.rgb;\n#endif\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\n#ifdef LINKEMISSIVEWITHDIFFUSE\nvec3 finalDiffuse=clamp((diffuseBase+emissiveColor)*diffuseColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#else\nvec3 finalDiffuse=clamp(diffuseBase*diffuseColor+emissiveColor+vAmbientColor,0.0,1.0)*baseColor.rgb;\n#endif\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=specularBase*specularColor;\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+dot(finalSpecular,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef REFLECTIONOVERALPHA\nalpha=clamp(alpha+dot(reflectionColor.rgb,vec3(0.3,0.59,0.11)),0.,1.);\n#endif\n#ifdef EMISSIVEASILLUMINATION\nvec4 color=vec4(clamp(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+emissiveColor+refractionColor.rgb,0.0,1.0),alpha);\n#else\nvec4 color=vec4(finalDiffuse*baseAmbientColor+finalSpecular+reflectionColor.rgb+refractionColor.rgb,alpha);\n#endif\n#ifdef LIGHTMAP\n#ifndef LIGHTMAPEXCLUDED\n#ifdef USELIGHTMAPASSHADOWMAP\ncolor.rgb*=lightmapColor.rgb;\n#else\ncolor.rgb+=lightmapColor.rgb;\n#endif\n#endif\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FOG\ncolor.rgb=max(color.rgb,0.);\n#include<logDepthFragment>\n#include<fogFragment>\n#ifdef IMAGEPROCESSINGPOSTPROCESS\ncolor.rgb=toLinearSpace(color.rgb);\n#else\n#ifdef IMAGEPROCESSING\ncolor.rgb=toLinearSpace(color.rgb);color=applyImageProcessing(color);\n#endif\n#endif\ncolor.a*=visibility;\n#ifdef PREMULTIPLYALPHA\ncolor.rgb*=color.a;\n#endif\n#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR\n#ifdef PREPASS\nfloat writeGeometryInfo=color.a>0.4 ? 1.0 : 0.0;gl_FragData[0]=color; \n#ifdef PREPASS_POSITION\ngl_FragData[PREPASS_POSITION_INDEX]=vec4(vPositionW,writeGeometryInfo);\n#endif\n#ifdef PREPASS_VELOCITY\nvec2 a=(vCurrentPosition.xy/vCurrentPosition.w)*0.5+0.5;vec2 b=(vPreviousPosition.xy/vPreviousPosition.w)*0.5+0.5;vec2 velocity=abs(a-b);velocity=vec2(pow(velocity.x,1.0/3.0),pow(velocity.y,1.0/3.0))*sign(a-b)*0.5+0.5;gl_FragData[PREPASS_VELOCITY_INDEX]=vec4(velocity,0.0,writeGeometryInfo);\n#endif\n#ifdef PREPASS_IRRADIANCE\ngl_FragData[PREPASS_IRRADIANCE_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_DEPTH\ngl_FragData[PREPASS_DEPTH_INDEX]=vec4(vViewPos.z,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_NORMAL\n#ifdef PREPASS_NORMAL_WORLDSPACE\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalW,writeGeometryInfo); \n#else\ngl_FragData[PREPASS_NORMAL_INDEX]=vec4(normalize((view*vec4(normalW,0.0)).rgb),writeGeometryInfo); \n#endif\n#endif\n#ifdef PREPASS_ALBEDO_SQRT\ngl_FragData[PREPASS_ALBEDO_SQRT_INDEX]=vec4(0.0,0.0,0.0,writeGeometryInfo); \n#endif\n#ifdef PREPASS_REFLECTIVITY\n#if defined(SPECULARTERM)\n#if defined(SPECULAR)\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularMapColor))*writeGeometryInfo; \n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(toLinearSpace(specularColor),1.0)*writeGeometryInfo;\n#endif\n#else\ngl_FragData[PREPASS_REFLECTIVITY_INDEX]=vec4(0.0,0.0,0.0,1.0)*writeGeometryInfo;\n#endif\n#endif\n#endif\n#if !defined(PREPASS) || defined(WEBGL2)\ngl_FragColor=color;\n#endif\n#include<oitFragment>\n#if ORDER_INDEPENDENT_TRANSPARENCY\nif (fragDepth==nearestDepth) {frontColor.rgb+=color.rgb*color.a*alphaMultiplier;frontColor.a=1.0-alphaMultiplier*(1.0-color.a);} else {backColor+=color;}\n#endif\n#define CUSTOM_FRAGMENT_MAIN_END\n}\n`;\n// Sideeffect\nShaderStore.ShadersStore[name] = shader;\n/** @internal */\nexport const defaultPixelShader = { name, shader };\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WebXRAnchorSystem.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRAnchorSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAA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,CAAC,oBAAoB,GAAG,GAAG,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE;gBAChC,mFAAmF;aACtF;iBAAM;gBACH,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,cAAc,EAAE,EAAE,GAAG,CAAC,CAAC;aAC1E;SACJ;QAED,OAAqB,MAAM,CAAC;IAChC,CAAC;IAEO,KAAK,CAAC,6BAA6B,CAAC,gBAAkC,EAAE,OAAgB;;QAC5F,IAAI,OAAO,CAAC,YAAY,EAAE;YACtB,IAAI;gBACA,OAAO,OAAO,CAAC,YAAY,CAAC,gBAAgB,EAAE,MAAA,IAAI,CAAC,8BAA8B,mCAAI,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;aAC/H;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;aAC1B;SACJ;aAAM;YACH,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC9D;IACL,CAAC;;AAtTD;;GAEG;AACoB,sBAAI,GAAG,gBAAgB,CAAC,aAAa,AAAjC,CAAkC;AAC7D;;;;GAIG;AACoB,yBAAO,GAAG,CAAC,AAAJ,CAAK;AAgTvC,sBAAsB;AACtB,oBAAoB,CAAC,eAAe,CAChC,iBAAiB,CAAC,IAAI,EACtB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,EACD,iBAAiB,CAAC,OAAO,CAC5B,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Matrix, Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRHitResult } from \"./WebXRHitTest\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Configuration options of the anchor system\r\n */\r\nexport interface IWebXRAnchorSystemOptions {\r\n /**\r\n * a node that will be used to convert local to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n\r\n /**\r\n * If set to true a reference of the created anchors will be kept until the next session starts\r\n * If not defined, anchors will be removed from the array when the feature is detached or the session ended.\r\n */\r\n doNotRemoveAnchorsOnSessionEnded?: boolean;\r\n}\r\n\r\n/**\r\n * A babylon container for an XR Anchor\r\n */\r\nexport interface IWebXRAnchor {\r\n /**\r\n * A babylon-assigned ID for this anchor\r\n */\r\n id: number;\r\n /**\r\n * Transformation matrix to apply to an object attached to this anchor\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native anchor object\r\n */\r\n xrAnchor: XRAnchor;\r\n\r\n /**\r\n * if defined, this object will be constantly updated by the anchor's position and rotation\r\n */\r\n attachedNode?: TransformNode;\r\n\r\n /**\r\n * Remove this anchor from the scene\r\n */\r\n remove(): void;\r\n}\r\n\r\n/**\r\n * An internal interface for a future (promise based) anchor\r\n */\r\ninterface IWebXRFutureAnchor {\r\n /**\r\n * The native anchor\r\n */\r\n nativeAnchor?: XRAnchor;\r\n /**\r\n * Was this request submitted to the xr frame?\r\n */\r\n submitted: boolean;\r\n /**\r\n * Was this promise resolved already?\r\n */\r\n resolved: boolean;\r\n /**\r\n * A resolve function\r\n */\r\n resolve: (xrAnchor: IWebXRAnchor) => void;\r\n /**\r\n * A reject function\r\n */\r\n reject: (msg?: string) => void;\r\n /**\r\n * The XR Transformation of the future anchor\r\n */\r\n xrTransformation: XRRigidTransform;\r\n}\r\n\r\nlet anchorIdProvider = 0;\r\n\r\n/**\r\n * An implementation of the anchor system for WebXR.\r\n * For further information see https://github.com/immersive-web/anchors/\r\n */\r\nexport class WebXRAnchorSystem extends WebXRAbstractFeature {\r\n private _lastFrameDetected: XRAnchorSet = new Set();\r\n\r\n private _trackedAnchors: Array<IWebXRAnchor> = [];\r\n\r\n private _referenceSpaceForFrameAnchors: XRReferenceSpace;\r\n\r\n private _futureAnchors: IWebXRFutureAnchor[] = [];\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.ANCHOR_SYSTEM;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Observers registered here will be executed when a new anchor was added to the session\r\n */\r\n public onAnchorAddedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an anchor was removed from the session\r\n */\r\n public onAnchorRemovedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an existing anchor updates\r\n * This can execute N times every frame\r\n */\r\n public onAnchorUpdatedObservable: Observable<IWebXRAnchor> = new Observable();\r\n\r\n /**\r\n * Set the reference space to use for anchor creation, when not using a hit test.\r\n * Will default to the session's reference space if not defined\r\n */\r\n public set referenceSpaceForFrameAnchors(referenceSpace: XRReferenceSpace) {\r\n this._referenceSpaceForFrameAnchors = referenceSpace;\r\n }\r\n\r\n /**\r\n * constructs a new anchor system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param _options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private _options: IWebXRAnchorSystemOptions = {}) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"anchors\";\r\n }\r\n\r\n private _tmpVector = new Vector3();\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n private _populateTmpTransformation(position: Vector3, rotationQuaternion: Quaternion) {\r\n this._tmpVector.copyFrom(position);\r\n this._tmpQuaternion.copyFrom(rotationQuaternion);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpVector.z *= -1;\r\n this._tmpQuaternion.z *= -1;\r\n this._tmpQuaternion.w *= -1;\r\n }\r\n return {\r\n position: this._tmpVector,\r\n rotationQuaternion: this._tmpQuaternion,\r\n };\r\n }\r\n\r\n /**\r\n * Create a new anchor point using a hit test result at a specific point in the scene\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param hitTestResult The hit test result to use for this anchor creation\r\n * @param position an optional position offset for this anchor\r\n * @param rotationQuaternion an optional rotation offset for this anchor\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorPointUsingHitTestResultAsync(\r\n hitTestResult: IWebXRHitResult,\r\n position: Vector3 = new Vector3(),\r\n rotationQuaternion: Quaternion = new Quaternion()\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const m = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n if (!hitTestResult.xrHitResult.createAnchor) {\r\n this.detach();\r\n throw new Error(\"Anchors not enabled in this environment/browser\");\r\n } else {\r\n try {\r\n const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\r\n return new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor,\r\n resolved: false,\r\n submitted: true,\r\n xrTransformation: m,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add a new anchor at a specific position and rotation\r\n * This function will add a new anchor per default in the next available frame. Unless forced, the createAnchor function\r\n * will be called in the next xrFrame loop to make sure that the anchor can be created correctly.\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param position the position in which to add an anchor\r\n * @param rotationQuaternion an optional rotation for the anchor transformation\r\n * @param forceCreateInCurrentFrame force the creation of this anchor in the current frame. Must be called inside xrFrame loop!\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorAtPositionAndRotationAsync(\r\n position: Vector3,\r\n rotationQuaternion: Quaternion = new Quaternion(),\r\n forceCreateInCurrentFrame = false\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const xrTransformation = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n const xrAnchor =\r\n forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame\r\n ? await this._createAnchorAtTransformation(xrTransformation, this._xrSessionManager.currentFrame)\r\n : undefined;\r\n // add the transformation to the future anchors list\r\n return new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor: xrAnchor,\r\n resolved: false,\r\n submitted: false,\r\n xrTransformation,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Get the list of anchors currently being tracked by the system\r\n */\r\n public get anchors(): IWebXRAnchor[] {\r\n return this._trackedAnchors;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.doNotRemoveAnchorsOnSessionEnded) {\r\n while (this._trackedAnchors.length) {\r\n const toRemove = this._trackedAnchors.pop();\r\n if (toRemove) {\r\n try {\r\n // try to natively remove it as well\r\n toRemove.remove();\r\n } catch (e) {\r\n // no-op\r\n }\r\n // as the xr frame loop is removed, we need to notify manually\r\n this.onAnchorRemovedObservable.notifyObservers(toRemove);\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n this._futureAnchors.length = 0;\r\n super.dispose();\r\n this.onAnchorAddedObservable.clear();\r\n this.onAnchorRemovedObservable.clear();\r\n this.onAnchorUpdatedObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n if (!this.attached || !frame) {\r\n return;\r\n }\r\n\r\n const trackedAnchors = frame.trackedAnchors;\r\n if (trackedAnchors) {\r\n const toRemove = this._trackedAnchors\r\n .filter((anchor) => !trackedAnchors.has(anchor.xrAnchor))\r\n .map((anchor) => {\r\n const index = this._trackedAnchors.indexOf(anchor);\r\n return index;\r\n });\r\n let idxTracker = 0;\r\n toRemove.forEach((index) => {\r\n const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];\r\n this.onAnchorRemovedObservable.notifyObservers(anchor);\r\n idxTracker++;\r\n });\r\n // now check for new ones\r\n trackedAnchors.forEach((xrAnchor) => {\r\n if (!this._lastFrameDetected.has(xrAnchor)) {\r\n const newAnchor: Partial<IWebXRAnchor> = {\r\n id: anchorIdProvider++,\r\n xrAnchor: xrAnchor,\r\n remove: () => xrAnchor.delete(),\r\n };\r\n const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);\r\n this._trackedAnchors.push(anchor);\r\n this.onAnchorAddedObservable.notifyObservers(anchor);\r\n // search for the future anchor promise that matches this\r\n const results = this._futureAnchors.filter((futureAnchor) => futureAnchor.nativeAnchor === xrAnchor);\r\n const result = results[0];\r\n if (result) {\r\n result.resolve(anchor);\r\n result.resolved = true;\r\n }\r\n } else {\r\n const index = this._findIndexInAnchorArray(xrAnchor);\r\n const anchor = this._trackedAnchors[index];\r\n try {\r\n // anchors update every frame\r\n this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);\r\n if (anchor.attachedNode) {\r\n anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();\r\n anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);\r\n }\r\n this.onAnchorUpdatedObservable.notifyObservers(anchor);\r\n } catch (e) {\r\n Tools.Warn(`Anchor could not be updated`);\r\n }\r\n }\r\n });\r\n this._lastFrameDetected = trackedAnchors;\r\n }\r\n\r\n // process future anchors\r\n this._futureAnchors.forEach((futureAnchor) => {\r\n if (!futureAnchor.resolved && !futureAnchor.submitted) {\r\n this._createAnchorAtTransformation(futureAnchor.xrTransformation, frame).then(\r\n (nativeAnchor) => {\r\n futureAnchor.nativeAnchor = nativeAnchor;\r\n },\r\n (error) => {\r\n futureAnchor.resolved = true;\r\n futureAnchor.reject(error);\r\n }\r\n );\r\n futureAnchor.submitted = true;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * avoiding using Array.find for global support.\r\n * @param xrAnchor the plane to find in the array\r\n */\r\n private _findIndexInAnchorArray(xrAnchor: XRAnchor) {\r\n for (let i = 0; i < this._trackedAnchors.length; ++i) {\r\n if (this._trackedAnchors[i].xrAnchor === xrAnchor) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n private _updateAnchorWithXRFrame(xrAnchor: XRAnchor, anchor: Partial<IWebXRAnchor>, xrFrame: XRFrame): IWebXRAnchor {\r\n // matrix\r\n const pose = xrFrame.getPose(xrAnchor.anchorSpace, this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const mat = anchor.transformationMatrix || new Matrix();\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n anchor.transformationMatrix = mat;\r\n if (!this._options.worldParentNode) {\r\n // Logger.Warn(\"Please provide a world parent node to apply world transformation\");\r\n } else {\r\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n }\r\n\r\n return <IWebXRAnchor>anchor;\r\n }\r\n\r\n private async _createAnchorAtTransformation(xrTransformation: XRRigidTransform, xrFrame: XRFrame) {\r\n if (xrFrame.createAnchor) {\r\n try {\r\n return xrFrame.createAnchor(xrTransformation, this._referenceSpaceForFrameAnchors ?? this._xrSessionManager.referenceSpace);\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n } else {\r\n this.detach();\r\n throw new Error(\"Anchors are not enabled in your browser\");\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRAnchorSystem.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRAnchorSystem(xrSessionManager, options);\r\n },\r\n WebXRAnchorSystem.Version\r\n);\r\n"]}
1
+ {"version":3,"file":"WebXRAnchorSystem.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRAnchorSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAEjF,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAEtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AA4EzC,IAAI,gBAAgB,GAAG,CAAC,CAAC;AAEzB;;;GAGG;AACH,MAAM,OAAO,iBAAkB,SAAQ,oBAAoB;IAkCvD;;;OAGG;IACH,IAAW,6BAA6B,CAAC,cAAgC;QACrE,IAAI,CAAC,8BAA8B,GAAG,cAAc,CAA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,OAAgB;;QAC5F,IAAI,OAAO,CAAC,YAAY,EAAE;YACtB,IAAI;gBACA,OAAO,OAAO,CAAC,YAAY,CAAC,gBAAgB,EAAE,MAAA,IAAI,CAAC,8BAA8B,mCAAI,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;aAC/H;YAAC,OAAO,KAAK,EAAE;gBACZ,MAAM,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC;aAC1B;SACJ;aAAM;YACH,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;SAC9D;IACL,CAAC;;AAzTD;;GAEG;AACoB,sBAAI,GAAG,gBAAgB,CAAC,aAAa,AAAjC,CAAkC;AAC7D;;;;GAIG;AACoB,yBAAO,GAAG,CAAC,AAAJ,CAAK;AAmTvC,sBAAsB;AACtB,oBAAoB,CAAC,eAAe,CAChC,iBAAiB,CAAC,IAAI,EACtB,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,iBAAiB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AAClE,CAAC,EACD,iBAAiB,CAAC,OAAO,CAC5B,CAAC","sourcesContent":["import { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport { Observable } from \"../../Misc/observable\";\r\nimport { Matrix, Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { IWebXRHitResult } from \"./WebXRHitTest\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * Configuration options of the anchor system\r\n */\r\nexport interface IWebXRAnchorSystemOptions {\r\n /**\r\n * a node that will be used to convert local to world coordinates\r\n */\r\n worldParentNode?: TransformNode;\r\n\r\n /**\r\n * If set to true a reference of the created anchors will be kept until the next session starts\r\n * If not defined, anchors will be removed from the array when the feature is detached or the session ended.\r\n */\r\n doNotRemoveAnchorsOnSessionEnded?: boolean;\r\n}\r\n\r\n/**\r\n * A babylon container for an XR Anchor\r\n */\r\nexport interface IWebXRAnchor {\r\n /**\r\n * A babylon-assigned ID for this anchor\r\n */\r\n id: number;\r\n /**\r\n * Transformation matrix to apply to an object attached to this anchor\r\n */\r\n transformationMatrix: Matrix;\r\n /**\r\n * The native anchor object\r\n */\r\n xrAnchor: XRAnchor;\r\n\r\n /**\r\n * if defined, this object will be constantly updated by the anchor's position and rotation\r\n */\r\n attachedNode?: TransformNode;\r\n\r\n /**\r\n * Remove this anchor from the scene\r\n */\r\n remove(): void;\r\n}\r\n\r\n/**\r\n * An internal interface for a future (promise based) anchor\r\n */\r\ninterface IWebXRFutureAnchor {\r\n /**\r\n * The native anchor\r\n */\r\n nativeAnchor?: XRAnchor;\r\n /**\r\n * Was this request submitted to the xr frame?\r\n */\r\n submitted: boolean;\r\n /**\r\n * Was this promise resolved already?\r\n */\r\n resolved: boolean;\r\n /**\r\n * A resolve function\r\n */\r\n resolve: (xrAnchor: IWebXRAnchor) => void;\r\n /**\r\n * A reject function\r\n */\r\n reject: (msg?: string) => void;\r\n /**\r\n * The XR Transformation of the future anchor\r\n */\r\n xrTransformation: XRRigidTransform;\r\n}\r\n\r\nlet anchorIdProvider = 0;\r\n\r\n/**\r\n * An implementation of the anchor system for WebXR.\r\n * For further information see https://github.com/immersive-web/anchors/\r\n */\r\nexport class WebXRAnchorSystem extends WebXRAbstractFeature {\r\n private _lastFrameDetected: XRAnchorSet = new Set();\r\n\r\n private _trackedAnchors: Array<IWebXRAnchor> = [];\r\n\r\n private _referenceSpaceForFrameAnchors: XRReferenceSpace;\r\n\r\n private _futureAnchors: IWebXRFutureAnchor[] = [];\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.ANCHOR_SYSTEM;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the WebXR specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Observers registered here will be executed when a new anchor was added to the session\r\n */\r\n public onAnchorAddedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an anchor was removed from the session\r\n */\r\n public onAnchorRemovedObservable: Observable<IWebXRAnchor> = new Observable();\r\n /**\r\n * Observers registered here will be executed when an existing anchor updates\r\n * This can execute N times every frame\r\n */\r\n public onAnchorUpdatedObservable: Observable<IWebXRAnchor> = new Observable();\r\n\r\n /**\r\n * Set the reference space to use for anchor creation, when not using a hit test.\r\n * Will default to the session's reference space if not defined\r\n */\r\n public set referenceSpaceForFrameAnchors(referenceSpace: XRReferenceSpace) {\r\n this._referenceSpaceForFrameAnchors = referenceSpace;\r\n }\r\n\r\n /**\r\n * constructs a new anchor system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param _options configuration object for this feature\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private _options: IWebXRAnchorSystemOptions = {}\r\n ) {\r\n super(_xrSessionManager);\r\n this.xrNativeFeatureName = \"anchors\";\r\n }\r\n\r\n private _tmpVector = new Vector3();\r\n private _tmpQuaternion = new Quaternion();\r\n\r\n private _populateTmpTransformation(position: Vector3, rotationQuaternion: Quaternion) {\r\n this._tmpVector.copyFrom(position);\r\n this._tmpQuaternion.copyFrom(rotationQuaternion);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n this._tmpVector.z *= -1;\r\n this._tmpQuaternion.z *= -1;\r\n this._tmpQuaternion.w *= -1;\r\n }\r\n return {\r\n position: this._tmpVector,\r\n rotationQuaternion: this._tmpQuaternion,\r\n };\r\n }\r\n\r\n /**\r\n * Create a new anchor point using a hit test result at a specific point in the scene\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param hitTestResult The hit test result to use for this anchor creation\r\n * @param position an optional position offset for this anchor\r\n * @param rotationQuaternion an optional rotation offset for this anchor\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorPointUsingHitTestResultAsync(\r\n hitTestResult: IWebXRHitResult,\r\n position: Vector3 = new Vector3(),\r\n rotationQuaternion: Quaternion = new Quaternion()\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const m = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n if (!hitTestResult.xrHitResult.createAnchor) {\r\n this.detach();\r\n throw new Error(\"Anchors not enabled in this environment/browser\");\r\n } else {\r\n try {\r\n const nativeAnchor = await hitTestResult.xrHitResult.createAnchor(m);\r\n return new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor,\r\n resolved: false,\r\n submitted: true,\r\n xrTransformation: m,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Add a new anchor at a specific position and rotation\r\n * This function will add a new anchor per default in the next available frame. Unless forced, the createAnchor function\r\n * will be called in the next xrFrame loop to make sure that the anchor can be created correctly.\r\n * An anchor is tracked only after it is added to the trackerAnchors in xrFrame. The promise returned here does not yet guaranty that.\r\n * Use onAnchorAddedObservable to get newly added anchors if you require tracking guaranty.\r\n *\r\n * @param position the position in which to add an anchor\r\n * @param rotationQuaternion an optional rotation for the anchor transformation\r\n * @param forceCreateInCurrentFrame force the creation of this anchor in the current frame. Must be called inside xrFrame loop!\r\n * @returns A promise that fulfills when babylon has created the corresponding WebXRAnchor object and tracking has begun\r\n */\r\n public async addAnchorAtPositionAndRotationAsync(\r\n position: Vector3,\r\n rotationQuaternion: Quaternion = new Quaternion(),\r\n forceCreateInCurrentFrame = false\r\n ): Promise<IWebXRAnchor> {\r\n // convert to XR space (right handed) if needed\r\n this._populateTmpTransformation(position, rotationQuaternion);\r\n // the matrix that we'll use\r\n const xrTransformation = new XRRigidTransform(\r\n { x: this._tmpVector.x, y: this._tmpVector.y, z: this._tmpVector.z },\r\n { x: this._tmpQuaternion.x, y: this._tmpQuaternion.y, z: this._tmpQuaternion.z, w: this._tmpQuaternion.w }\r\n );\r\n const xrAnchor =\r\n forceCreateInCurrentFrame && this.attached && this._xrSessionManager.currentFrame\r\n ? await this._createAnchorAtTransformation(xrTransformation, this._xrSessionManager.currentFrame)\r\n : undefined;\r\n // add the transformation to the future anchors list\r\n return new Promise<IWebXRAnchor>((resolve, reject) => {\r\n this._futureAnchors.push({\r\n nativeAnchor: xrAnchor,\r\n resolved: false,\r\n submitted: false,\r\n xrTransformation,\r\n resolve,\r\n reject,\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Get the list of anchors currently being tracked by the system\r\n */\r\n public get anchors(): IWebXRAnchor[] {\r\n return this._trackedAnchors;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.doNotRemoveAnchorsOnSessionEnded) {\r\n while (this._trackedAnchors.length) {\r\n const toRemove = this._trackedAnchors.pop();\r\n if (toRemove) {\r\n try {\r\n // try to natively remove it as well\r\n toRemove.remove();\r\n } catch (e) {\r\n // no-op\r\n }\r\n // as the xr frame loop is removed, we need to notify manually\r\n this.onAnchorRemovedObservable.notifyObservers(toRemove);\r\n }\r\n }\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Dispose this feature and all of the resources attached\r\n */\r\n public dispose(): void {\r\n this._futureAnchors.length = 0;\r\n super.dispose();\r\n this.onAnchorAddedObservable.clear();\r\n this.onAnchorRemovedObservable.clear();\r\n this.onAnchorUpdatedObservable.clear();\r\n }\r\n\r\n protected _onXRFrame(frame: XRFrame) {\r\n if (!this.attached || !frame) {\r\n return;\r\n }\r\n\r\n const trackedAnchors = frame.trackedAnchors;\r\n if (trackedAnchors) {\r\n const toRemove = this._trackedAnchors\r\n .filter((anchor) => !trackedAnchors.has(anchor.xrAnchor))\r\n .map((anchor) => {\r\n const index = this._trackedAnchors.indexOf(anchor);\r\n return index;\r\n });\r\n let idxTracker = 0;\r\n toRemove.forEach((index) => {\r\n const anchor = this._trackedAnchors.splice(index - idxTracker, 1)[0];\r\n this.onAnchorRemovedObservable.notifyObservers(anchor);\r\n idxTracker++;\r\n });\r\n // now check for new ones\r\n trackedAnchors.forEach((xrAnchor) => {\r\n if (!this._lastFrameDetected.has(xrAnchor)) {\r\n const newAnchor: Partial<IWebXRAnchor> = {\r\n id: anchorIdProvider++,\r\n xrAnchor: xrAnchor,\r\n remove: () => xrAnchor.delete(),\r\n };\r\n const anchor = this._updateAnchorWithXRFrame(xrAnchor, newAnchor, frame);\r\n this._trackedAnchors.push(anchor);\r\n this.onAnchorAddedObservable.notifyObservers(anchor);\r\n // search for the future anchor promise that matches this\r\n const results = this._futureAnchors.filter((futureAnchor) => futureAnchor.nativeAnchor === xrAnchor);\r\n const result = results[0];\r\n if (result) {\r\n result.resolve(anchor);\r\n result.resolved = true;\r\n }\r\n } else {\r\n const index = this._findIndexInAnchorArray(xrAnchor);\r\n const anchor = this._trackedAnchors[index];\r\n try {\r\n // anchors update every frame\r\n this._updateAnchorWithXRFrame(xrAnchor, anchor, frame);\r\n if (anchor.attachedNode) {\r\n anchor.attachedNode.rotationQuaternion = anchor.attachedNode.rotationQuaternion || new Quaternion();\r\n anchor.transformationMatrix.decompose(anchor.attachedNode.scaling, anchor.attachedNode.rotationQuaternion, anchor.attachedNode.position);\r\n }\r\n this.onAnchorUpdatedObservable.notifyObservers(anchor);\r\n } catch (e) {\r\n Tools.Warn(`Anchor could not be updated`);\r\n }\r\n }\r\n });\r\n this._lastFrameDetected = trackedAnchors;\r\n }\r\n\r\n // process future anchors\r\n this._futureAnchors.forEach((futureAnchor) => {\r\n if (!futureAnchor.resolved && !futureAnchor.submitted) {\r\n this._createAnchorAtTransformation(futureAnchor.xrTransformation, frame).then(\r\n (nativeAnchor) => {\r\n futureAnchor.nativeAnchor = nativeAnchor;\r\n },\r\n (error) => {\r\n futureAnchor.resolved = true;\r\n futureAnchor.reject(error);\r\n }\r\n );\r\n futureAnchor.submitted = true;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * avoiding using Array.find for global support.\r\n * @param xrAnchor the plane to find in the array\r\n */\r\n private _findIndexInAnchorArray(xrAnchor: XRAnchor) {\r\n for (let i = 0; i < this._trackedAnchors.length; ++i) {\r\n if (this._trackedAnchors[i].xrAnchor === xrAnchor) {\r\n return i;\r\n }\r\n }\r\n return -1;\r\n }\r\n\r\n private _updateAnchorWithXRFrame(xrAnchor: XRAnchor, anchor: Partial<IWebXRAnchor>, xrFrame: XRFrame): IWebXRAnchor {\r\n // matrix\r\n const pose = xrFrame.getPose(xrAnchor.anchorSpace, this._xrSessionManager.referenceSpace);\r\n if (pose) {\r\n const mat = anchor.transformationMatrix || new Matrix();\r\n Matrix.FromArrayToRef(pose.transform.matrix, 0, mat);\r\n if (!this._xrSessionManager.scene.useRightHandedSystem) {\r\n mat.toggleModelMatrixHandInPlace();\r\n }\r\n anchor.transformationMatrix = mat;\r\n if (!this._options.worldParentNode) {\r\n // Logger.Warn(\"Please provide a world parent node to apply world transformation\");\r\n } else {\r\n mat.multiplyToRef(this._options.worldParentNode.getWorldMatrix(), mat);\r\n }\r\n }\r\n\r\n return <IWebXRAnchor>anchor;\r\n }\r\n\r\n private async _createAnchorAtTransformation(xrTransformation: XRRigidTransform, xrFrame: XRFrame) {\r\n if (xrFrame.createAnchor) {\r\n try {\r\n return xrFrame.createAnchor(xrTransformation, this._referenceSpaceForFrameAnchors ?? this._xrSessionManager.referenceSpace);\r\n } catch (error) {\r\n throw new Error(error);\r\n }\r\n } else {\r\n this.detach();\r\n throw new Error(\"Anchors are not enabled in your browser\");\r\n }\r\n }\r\n}\r\n\r\n// register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRAnchorSystem.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRAnchorSystem(xrSessionManager, options);\r\n },\r\n WebXRAnchorSystem.Version\r\n);\r\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"WebXRControllerPhysics.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRControllerPhysics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAInE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;GAEG;AACH,MAAM,OAAO,8BAA8B;CAwD1C;AAED;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,oBAAoB;IAqCpD,sBAAsB,CAAC,YAA8B;QACzD,MAAM,YAAY,GAAW,IAAI,CAAC,QAAQ,CAAC,iBAAkB,CAAC,YAAY,IAAI,eAAe,CAAC,cAAc,CAAC;QAC7G,MAAM,YAAY,GAA8D,IAAI,CAAC,QAAQ,CAAC,iBAAkB,CAAC,YAAY,IAAI,GAAG,CAAC;QACrI,MAAM,YAAY,GAAG,YAAY,CAAC,gBAAgB,GAAG,YAAY,CAAC,QAAQ,EAAE;YACxE,SAAS,EAAE,OAAO,YAAY,KAAK,QAAQ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IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,CAAC;aAChE;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,iBAAiB,CAAC,oBAA4B;QAClD,MAAM,cAAc,GAAG,IAAI,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;QAC/D,IAAI,CAAC,cAAc,EAAE;YACjB,OAAO;SACV;QACD,IAAI,cAAc,CAAC,YAAY,EAAE;YAC7B,cAAc,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;SACzC;QACD,sBAAsB;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACnD,CAAC;;AAnOD;;GAEG;AACoB,2BAAI,GAAG,gBAAgB,CAAC,mBAAmB,AAAvC,CAAwC;AACnE;;;;GAIG;AACoB,8BAAO,GAAG,CAAC,AAAJ,CAAK;AA6NvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,sBAAsB,CAAC,IAAI,EAC3B,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,sBAAsB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC,EACD,sBAAsB,CAAC,OAAO,EAC9B,IAAI,CACP,CAAC","sourcesContent":["import { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport { PhysicsImpostor } from \"../../Physics/v1/physicsImpostor\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { CreateSphere } from \"../../Meshes/Builders/sphereBuilder\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Options for the controller physics feature\r\n */\r\nexport class IWebXRControllerPhysicsOptions {\r\n /**\r\n * Should the headset get its own impostor\r\n */\r\n enableHeadsetImpostor?: boolean;\r\n /**\r\n * Optional parameters for the headset impostor\r\n */\r\n headsetImpostorParams?: {\r\n /**\r\n * The type of impostor to create. Default is sphere\r\n */\r\n impostorType: number;\r\n /**\r\n * the size of the impostor. Defaults to 10cm\r\n */\r\n impostorSize?: number | { width: number; height: number; depth: number };\r\n /**\r\n * Friction definitions\r\n */\r\n friction?: number;\r\n /**\r\n * Restitution\r\n */\r\n restitution?: number;\r\n };\r\n /**\r\n * The physics properties of the future impostors\r\n */\r\n physicsProperties?: {\r\n /**\r\n * If set to true, a mesh impostor will be created when the controller mesh was loaded\r\n * Note that this requires a physics engine that supports mesh impostors!\r\n */\r\n useControllerMesh?: boolean;\r\n /**\r\n * The type of impostor to create. Default is sphere\r\n */\r\n impostorType?: number;\r\n /**\r\n * the size of the impostor. Defaults to 10cm\r\n */\r\n impostorSize?: number | { width: number; height: number; depth: number };\r\n /**\r\n * Friction definitions\r\n */\r\n friction?: number;\r\n /**\r\n * Restitution\r\n */\r\n restitution?: number;\r\n };\r\n /**\r\n * the xr input to use with this pointer selection\r\n */\r\n public xrInput: WebXRInput;\r\n}\r\n\r\n/**\r\n * Add physics impostor to your webxr controllers,\r\n * including naive calculation of their linear and angular velocity\r\n */\r\nexport class WebXRControllerPhysics extends WebXRAbstractFeature {\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n if (!this._xrSessionManager.scene.isPhysicsEnabled()) {\r\n Logger.Warn(\"physics engine not enabled, skipped. Please add this controller manually.\");\r\n }\r\n // if no motion controller available, create impostors!\r\n if (this._options.physicsProperties!.useControllerMesh && xrController.inputSource.gamepad) {\r\n xrController.onMotionControllerInitObservable.addOnce((motionController) => {\r\n if (!motionController._doNotLoadControllerMesh) {\r\n motionController.onModelLoadedObservable.addOnce(() => {\r\n const impostor = new PhysicsImpostor(motionController.rootMesh!, PhysicsImpostor.MeshImpostor, {\r\n mass: 0,\r\n ...this._options.physicsProperties,\r\n });\r\n\r\n const controllerMesh = xrController.grip || xrController.pointer;\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n impostor,\r\n oldPos: controllerMesh.position.clone(),\r\n oldRotation: controllerMesh.rotationQuaternion!.clone(),\r\n };\r\n });\r\n } else {\r\n // This controller isn't using a model, create impostors instead\r\n this._createPhysicsImpostor(xrController);\r\n }\r\n });\r\n } else {\r\n this._createPhysicsImpostor(xrController);\r\n }\r\n };\r\n\r\n private _createPhysicsImpostor(xrController: WebXRInputSource) {\r\n const impostorType: number = this._options.physicsProperties!.impostorType || PhysicsImpostor.SphereImpostor;\r\n const impostorSize: number | { width: number; height: number; depth: number } = this._options.physicsProperties!.impostorSize || 0.1;\r\n const impostorMesh = CreateSphere(\"impostor-mesh-\" + xrController.uniqueId, {\r\n diameterX: typeof impostorSize === \"number\" ? impostorSize : impostorSize.width,\r\n diameterY: typeof impostorSize === \"number\" ? impostorSize : impostorSize.height,\r\n diameterZ: typeof impostorSize === \"number\" ? impostorSize : impostorSize.depth,\r\n });\r\n impostorMesh.isVisible = this._debugMode;\r\n impostorMesh.isPickable = false;\r\n impostorMesh.rotationQuaternion = new Quaternion();\r\n const controllerMesh = xrController.grip || xrController.pointer;\r\n impostorMesh.position.copyFrom(controllerMesh.position);\r\n impostorMesh.rotationQuaternion!.copyFrom(controllerMesh.rotationQuaternion!);\r\n const impostor = new PhysicsImpostor(impostorMesh, impostorType, {\r\n mass: 0,\r\n ...this._options.physicsProperties,\r\n });\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n impostor,\r\n impostorMesh,\r\n };\r\n }\r\n\r\n private _controllers: {\r\n [id: string]: {\r\n xrController: WebXRInputSource;\r\n impostorMesh?: AbstractMesh;\r\n impostor: PhysicsImpostor;\r\n oldPos?: Vector3;\r\n oldSpeed?: Vector3;\r\n oldRotation?: Quaternion;\r\n };\r\n } = {};\r\n private _debugMode = false;\r\n private _delta: number = 0;\r\n private _headsetImpostor?: PhysicsImpostor;\r\n private _headsetMesh?: AbstractMesh;\r\n private _lastTimestamp: number = 0;\r\n private _tmpQuaternion: Quaternion = new Quaternion();\r\n private _tmpVector: Vector3 = new Vector3();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.PHYSICS_CONTROLLERS;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Construct a new Controller Physics Feature\r\n * @param _xrSessionManager the corresponding xr session manager\r\n * @param _options options to create this feature with\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, private readonly _options: IWebXRControllerPhysicsOptions) {\r\n super(_xrSessionManager);\r\n if (!this._options.physicsProperties) {\r\n this._options.physicsProperties = {};\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * enable debugging - will show console outputs and the impostor mesh\r\n */\r\n public _enablePhysicsDebug() {\r\n this._debugMode = true;\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n const controllerData = this._controllers[controllerId];\r\n if (controllerData.impostorMesh) {\r\n controllerData.impostorMesh.isVisible = true;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Manually add a controller (if no xrInput was provided or physics engine was not enabled)\r\n * @param xrController the controller to add\r\n */\r\n public addController(xrController: WebXRInputSource) {\r\n this._attachController(xrController);\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.xrInput) {\r\n return true;\r\n }\r\n\r\n this._options.xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n if (this._options.enableHeadsetImpostor) {\r\n const params = this._options.headsetImpostorParams || {\r\n impostorType: PhysicsImpostor.SphereImpostor,\r\n restitution: 0.8,\r\n impostorSize: 0.3,\r\n };\r\n const impostorSize = params.impostorSize || 0.3;\r\n this._headsetMesh = CreateSphere(\"headset-mesh\", {\r\n diameterX: typeof impostorSize === \"number\" ? impostorSize : impostorSize.width,\r\n diameterY: typeof impostorSize === \"number\" ? impostorSize : impostorSize.height,\r\n diameterZ: typeof impostorSize === \"number\" ? impostorSize : impostorSize.depth,\r\n });\r\n this._headsetMesh.rotationQuaternion = new Quaternion();\r\n this._headsetMesh.isVisible = false;\r\n this._headsetImpostor = new PhysicsImpostor(this._headsetMesh, params.impostorType, { mass: 0, ...params });\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n if (this._headsetMesh) {\r\n this._headsetMesh.dispose();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Get the headset impostor, if enabled\r\n * @returns the impostor\r\n */\r\n public getHeadsetImpostor() {\r\n return this._headsetImpostor;\r\n }\r\n\r\n /**\r\n * Get the physics impostor of a specific controller.\r\n * The impostor is not attached to a mesh because a mesh for each controller is not obligatory\r\n * @param controller the controller or the controller id of which to get the impostor\r\n * @returns the impostor or null\r\n */\r\n public getImpostorForController(controller: WebXRInputSource | string): Nullable<PhysicsImpostor> {\r\n const id = typeof controller === \"string\" ? controller : controller.uniqueId;\r\n if (this._controllers[id]) {\r\n return this._controllers[id].impostor;\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Update the physics properties provided in the constructor\r\n * @param newProperties the new properties object\r\n * @param newProperties.impostorType\r\n * @param newProperties.impostorSize\r\n * @param newProperties.friction\r\n * @param newProperties.restitution\r\n */\r\n public setPhysicsProperties(newProperties: {\r\n impostorType?: number;\r\n impostorSize?: number | { width: number; height: number; depth: number };\r\n friction?: number;\r\n restitution?: number;\r\n }) {\r\n this._options.physicsProperties = {\r\n ...this._options.physicsProperties,\r\n ...newProperties,\r\n };\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: any): void {\r\n this._delta = this._xrSessionManager.currentTimestamp - this._lastTimestamp;\r\n this._lastTimestamp = this._xrSessionManager.currentTimestamp;\r\n if (this._headsetMesh && this._headsetImpostor) {\r\n this._headsetMesh.position.copyFrom(this._options.xrInput.xrCamera.globalPosition);\r\n this._headsetMesh.rotationQuaternion!.copyFrom(this._options.xrInput.xrCamera.absoluteRotation);\r\n if (this._options.xrInput.xrCamera._lastXRViewerPose?.linearVelocity) {\r\n const lv = this._options.xrInput.xrCamera._lastXRViewerPose.linearVelocity;\r\n this._tmpVector.set(lv.x, lv.y, lv.z);\r\n this._headsetImpostor.setLinearVelocity(this._tmpVector);\r\n }\r\n if (this._options.xrInput.xrCamera._lastXRViewerPose?.angularVelocity) {\r\n const av = this._options.xrInput.xrCamera._lastXRViewerPose.angularVelocity;\r\n this._tmpVector.set(av.x, av.y, av.z);\r\n this._headsetImpostor.setAngularVelocity(this._tmpVector);\r\n }\r\n }\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n const controllerData = this._controllers[controllerId];\r\n const controllerMesh = controllerData.xrController.grip || controllerData.xrController.pointer;\r\n const comparedPosition = controllerData.oldPos || controllerData.impostorMesh!.position;\r\n if (controllerData.xrController._lastXRPose?.linearVelocity) {\r\n const lv = controllerData.xrController._lastXRPose.linearVelocity;\r\n this._tmpVector.set(lv.x, lv.y, lv.z);\r\n controllerData.impostor.setLinearVelocity(this._tmpVector);\r\n } else {\r\n controllerMesh.position.subtractToRef(comparedPosition, this._tmpVector);\r\n this._tmpVector.scaleInPlace(1000 / this._delta);\r\n controllerData.impostor.setLinearVelocity(this._tmpVector);\r\n }\r\n comparedPosition.copyFrom(controllerMesh.position);\r\n if (this._debugMode) {\r\n console.log(this._tmpVector, \"linear\");\r\n }\r\n\r\n const comparedQuaternion = controllerData.oldRotation || controllerData.impostorMesh!.rotationQuaternion!;\r\n if (controllerData.xrController._lastXRPose?.angularVelocity) {\r\n const av = controllerData.xrController._lastXRPose.angularVelocity;\r\n this._tmpVector.set(av.x, av.y, av.z);\r\n controllerData.impostor.setAngularVelocity(this._tmpVector);\r\n } else {\r\n if (!comparedQuaternion.equalsWithEpsilon(controllerMesh.rotationQuaternion!)) {\r\n // roughly based on this - https://www.gamedev.net/forums/topic/347752-quaternion-and-angular-velocity/\r\n comparedQuaternion.conjugateInPlace().multiplyToRef(controllerMesh.rotationQuaternion!, this._tmpQuaternion);\r\n const len = Math.sqrt(\r\n this._tmpQuaternion.x * this._tmpQuaternion.x + this._tmpQuaternion.y * this._tmpQuaternion.y + this._tmpQuaternion.z * this._tmpQuaternion.z\r\n );\r\n this._tmpVector.set(this._tmpQuaternion.x, this._tmpQuaternion.y, this._tmpQuaternion.z);\r\n // define a better epsilon\r\n if (len < 0.001) {\r\n this._tmpVector.scaleInPlace(2);\r\n } else {\r\n const angle = 2 * Math.atan2(len, this._tmpQuaternion.w);\r\n this._tmpVector.scaleInPlace(angle / (len * (this._delta / 1000)));\r\n }\r\n controllerData.impostor.setAngularVelocity(this._tmpVector);\r\n }\r\n }\r\n comparedQuaternion.copyFrom(controllerMesh.rotationQuaternion!);\r\n if (this._debugMode) {\r\n console.log(this._tmpVector, this._tmpQuaternion, \"angular\");\r\n }\r\n });\r\n }\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n if (controllerData.impostorMesh) {\r\n controllerData.impostorMesh.dispose();\r\n }\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerPhysics.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerPhysics(xrSessionManager, options);\r\n },\r\n WebXRControllerPhysics.Version,\r\n true\r\n);\r\n"]}
1
+ {"version":3,"file":"WebXRControllerPhysics.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRControllerPhysics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE9D,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAInE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACjF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C;;GAEG;AACH,MAAM,OAAO,8BAA8B;CAwD1C;AAED;;;GAGG;AACH,MAAM,OAAO,sBAAuB,SAAQ,oBAAoB;IAqCpD,sBAAsB,CAAC,YAA8B;QACzD,MAAM,YAAY,GAAW,IAAI,CAAC,QAAQ,CAAC,iBAAkB,CAAC,YAAY,IAAI,eAAe,CAAC,cAAc,CAAC;QAC7G,MAAM,YAAY,GAA8D,IAAI,CAAC,QAAQ,CAAC,iBAAkB,CAAC,YAAY,IAAI,GAAG,CAAC;QACrI,MAAM,YAAY,GAAG,YAAY,CAAC,gBAAgB,GAAG,YAAY,CAAC,QAAQ,EAAE;YACxE,SAAS,EAAE,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK;YAC/E,SAAS,EAAE,OAAO,YAAY,KAAK,QAAQ,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,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AoB,CAAC,CAAC;QAC/D,IAAI,CAAC,cAAc,EAAE;YACjB,OAAO;SACV;QACD,IAAI,cAAc,CAAC,YAAY,EAAE;YAC7B,cAAc,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;SACzC;QACD,sBAAsB;QACtB,OAAO,IAAI,CAAC,YAAY,CAAC,oBAAoB,CAAC,CAAC;IACnD,CAAC;;AAtOD;;GAEG;AACoB,2BAAI,GAAG,gBAAgB,CAAC,mBAAmB,AAAvC,CAAwC;AACnE;;;;GAIG;AACoB,8BAAO,GAAG,CAAC,AAAJ,CAAK;AAgOvC,qBAAqB;AACrB,oBAAoB,CAAC,eAAe,CAChC,sBAAsB,CAAC,IAAI,EAC3B,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,sBAAsB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACvE,CAAC,EACD,sBAAsB,CAAC,OAAO,EAC9B,IAAI,CACP,CAAC","sourcesContent":["import { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport { PhysicsImpostor } from \"../../Physics/v1/physicsImpostor\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { CreateSphere } from \"../../Meshes/Builders/sphereBuilder\";\r\nimport { WebXRFeatureName, WebXRFeaturesManager } from \"../webXRFeaturesManager\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Nullable } from \"../../types\";\r\n\r\n/**\r\n * Options for the controller physics feature\r\n */\r\nexport class IWebXRControllerPhysicsOptions {\r\n /**\r\n * Should the headset get its own impostor\r\n */\r\n enableHeadsetImpostor?: boolean;\r\n /**\r\n * Optional parameters for the headset impostor\r\n */\r\n headsetImpostorParams?: {\r\n /**\r\n * The type of impostor to create. Default is sphere\r\n */\r\n impostorType: number;\r\n /**\r\n * the size of the impostor. Defaults to 10cm\r\n */\r\n impostorSize?: number | { width: number; height: number; depth: number };\r\n /**\r\n * Friction definitions\r\n */\r\n friction?: number;\r\n /**\r\n * Restitution\r\n */\r\n restitution?: number;\r\n };\r\n /**\r\n * The physics properties of the future impostors\r\n */\r\n physicsProperties?: {\r\n /**\r\n * If set to true, a mesh impostor will be created when the controller mesh was loaded\r\n * Note that this requires a physics engine that supports mesh impostors!\r\n */\r\n useControllerMesh?: boolean;\r\n /**\r\n * The type of impostor to create. Default is sphere\r\n */\r\n impostorType?: number;\r\n /**\r\n * the size of the impostor. Defaults to 10cm\r\n */\r\n impostorSize?: number | { width: number; height: number; depth: number };\r\n /**\r\n * Friction definitions\r\n */\r\n friction?: number;\r\n /**\r\n * Restitution\r\n */\r\n restitution?: number;\r\n };\r\n /**\r\n * the xr input to use with this pointer selection\r\n */\r\n public xrInput: WebXRInput;\r\n}\r\n\r\n/**\r\n * Add physics impostor to your webxr controllers,\r\n * including naive calculation of their linear and angular velocity\r\n */\r\nexport class WebXRControllerPhysics extends WebXRAbstractFeature {\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n if (!this._xrSessionManager.scene.isPhysicsEnabled()) {\r\n Logger.Warn(\"physics engine not enabled, skipped. Please add this controller manually.\");\r\n }\r\n // if no motion controller available, create impostors!\r\n if (this._options.physicsProperties!.useControllerMesh && xrController.inputSource.gamepad) {\r\n xrController.onMotionControllerInitObservable.addOnce((motionController) => {\r\n if (!motionController._doNotLoadControllerMesh) {\r\n motionController.onModelLoadedObservable.addOnce(() => {\r\n const impostor = new PhysicsImpostor(motionController.rootMesh!, PhysicsImpostor.MeshImpostor, {\r\n mass: 0,\r\n ...this._options.physicsProperties,\r\n });\r\n\r\n const controllerMesh = xrController.grip || xrController.pointer;\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n impostor,\r\n oldPos: controllerMesh.position.clone(),\r\n oldRotation: controllerMesh.rotationQuaternion!.clone(),\r\n };\r\n });\r\n } else {\r\n // This controller isn't using a model, create impostors instead\r\n this._createPhysicsImpostor(xrController);\r\n }\r\n });\r\n } else {\r\n this._createPhysicsImpostor(xrController);\r\n }\r\n };\r\n\r\n private _createPhysicsImpostor(xrController: WebXRInputSource) {\r\n const impostorType: number = this._options.physicsProperties!.impostorType || PhysicsImpostor.SphereImpostor;\r\n const impostorSize: number | { width: number; height: number; depth: number } = this._options.physicsProperties!.impostorSize || 0.1;\r\n const impostorMesh = CreateSphere(\"impostor-mesh-\" + xrController.uniqueId, {\r\n diameterX: typeof impostorSize === \"number\" ? impostorSize : impostorSize.width,\r\n diameterY: typeof impostorSize === \"number\" ? impostorSize : impostorSize.height,\r\n diameterZ: typeof impostorSize === \"number\" ? impostorSize : impostorSize.depth,\r\n });\r\n impostorMesh.isVisible = this._debugMode;\r\n impostorMesh.isPickable = false;\r\n impostorMesh.rotationQuaternion = new Quaternion();\r\n const controllerMesh = xrController.grip || xrController.pointer;\r\n impostorMesh.position.copyFrom(controllerMesh.position);\r\n impostorMesh.rotationQuaternion!.copyFrom(controllerMesh.rotationQuaternion!);\r\n const impostor = new PhysicsImpostor(impostorMesh, impostorType, {\r\n mass: 0,\r\n ...this._options.physicsProperties,\r\n });\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n impostor,\r\n impostorMesh,\r\n };\r\n }\r\n\r\n private _controllers: {\r\n [id: string]: {\r\n xrController: WebXRInputSource;\r\n impostorMesh?: AbstractMesh;\r\n impostor: PhysicsImpostor;\r\n oldPos?: Vector3;\r\n oldSpeed?: Vector3;\r\n oldRotation?: Quaternion;\r\n };\r\n } = {};\r\n private _debugMode = false;\r\n private _delta: number = 0;\r\n private _headsetImpostor?: PhysicsImpostor;\r\n private _headsetMesh?: AbstractMesh;\r\n private _lastTimestamp: number = 0;\r\n private _tmpQuaternion: Quaternion = new Quaternion();\r\n private _tmpVector: Vector3 = new Vector3();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.PHYSICS_CONTROLLERS;\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Construct a new Controller Physics Feature\r\n * @param _xrSessionManager the corresponding xr session manager\r\n * @param _options options to create this feature with\r\n */\r\n constructor(\r\n _xrSessionManager: WebXRSessionManager,\r\n private readonly _options: IWebXRControllerPhysicsOptions\r\n ) {\r\n super(_xrSessionManager);\r\n if (!this._options.physicsProperties) {\r\n this._options.physicsProperties = {};\r\n }\r\n }\r\n\r\n /**\r\n * @internal\r\n * enable debugging - will show console outputs and the impostor mesh\r\n */\r\n public _enablePhysicsDebug() {\r\n this._debugMode = true;\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n const controllerData = this._controllers[controllerId];\r\n if (controllerData.impostorMesh) {\r\n controllerData.impostorMesh.isVisible = true;\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Manually add a controller (if no xrInput was provided or physics engine was not enabled)\r\n * @param xrController the controller to add\r\n */\r\n public addController(xrController: WebXRInputSource) {\r\n this._attachController(xrController);\r\n }\r\n\r\n /**\r\n * attach this feature\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n if (!this._options.xrInput) {\r\n return true;\r\n }\r\n\r\n this._options.xrInput.controllers.forEach(this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._options.xrInput.onControllerRemovedObservable, (controller) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n if (this._options.enableHeadsetImpostor) {\r\n const params = this._options.headsetImpostorParams || {\r\n impostorType: PhysicsImpostor.SphereImpostor,\r\n restitution: 0.8,\r\n impostorSize: 0.3,\r\n };\r\n const impostorSize = params.impostorSize || 0.3;\r\n this._headsetMesh = CreateSphere(\"headset-mesh\", {\r\n diameterX: typeof impostorSize === \"number\" ? impostorSize : impostorSize.width,\r\n diameterY: typeof impostorSize === \"number\" ? impostorSize : impostorSize.height,\r\n diameterZ: typeof impostorSize === \"number\" ? impostorSize : impostorSize.depth,\r\n });\r\n this._headsetMesh.rotationQuaternion = new Quaternion();\r\n this._headsetMesh.isVisible = false;\r\n this._headsetImpostor = new PhysicsImpostor(this._headsetMesh, params.impostorType, { mass: 0, ...params });\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * detach this feature.\r\n * Will usually be called by the features manager\r\n *\r\n * @returns true if successful.\r\n */\r\n public detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n this._detachController(controllerId);\r\n });\r\n\r\n if (this._headsetMesh) {\r\n this._headsetMesh.dispose();\r\n }\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Get the headset impostor, if enabled\r\n * @returns the impostor\r\n */\r\n public getHeadsetImpostor() {\r\n return this._headsetImpostor;\r\n }\r\n\r\n /**\r\n * Get the physics impostor of a specific controller.\r\n * The impostor is not attached to a mesh because a mesh for each controller is not obligatory\r\n * @param controller the controller or the controller id of which to get the impostor\r\n * @returns the impostor or null\r\n */\r\n public getImpostorForController(controller: WebXRInputSource | string): Nullable<PhysicsImpostor> {\r\n const id = typeof controller === \"string\" ? controller : controller.uniqueId;\r\n if (this._controllers[id]) {\r\n return this._controllers[id].impostor;\r\n } else {\r\n return null;\r\n }\r\n }\r\n\r\n /**\r\n * Update the physics properties provided in the constructor\r\n * @param newProperties the new properties object\r\n * @param newProperties.impostorType\r\n * @param newProperties.impostorSize\r\n * @param newProperties.friction\r\n * @param newProperties.restitution\r\n */\r\n public setPhysicsProperties(newProperties: {\r\n impostorType?: number;\r\n impostorSize?: number | { width: number; height: number; depth: number };\r\n friction?: number;\r\n restitution?: number;\r\n }) {\r\n this._options.physicsProperties = {\r\n ...this._options.physicsProperties,\r\n ...newProperties,\r\n };\r\n }\r\n\r\n protected _onXRFrame(_xrFrame: any): void {\r\n this._delta = this._xrSessionManager.currentTimestamp - this._lastTimestamp;\r\n this._lastTimestamp = this._xrSessionManager.currentTimestamp;\r\n if (this._headsetMesh && this._headsetImpostor) {\r\n this._headsetMesh.position.copyFrom(this._options.xrInput.xrCamera.globalPosition);\r\n this._headsetMesh.rotationQuaternion!.copyFrom(this._options.xrInput.xrCamera.absoluteRotation);\r\n if (this._options.xrInput.xrCamera._lastXRViewerPose?.linearVelocity) {\r\n const lv = this._options.xrInput.xrCamera._lastXRViewerPose.linearVelocity;\r\n this._tmpVector.set(lv.x, lv.y, lv.z);\r\n this._headsetImpostor.setLinearVelocity(this._tmpVector);\r\n }\r\n if (this._options.xrInput.xrCamera._lastXRViewerPose?.angularVelocity) {\r\n const av = this._options.xrInput.xrCamera._lastXRViewerPose.angularVelocity;\r\n this._tmpVector.set(av.x, av.y, av.z);\r\n this._headsetImpostor.setAngularVelocity(this._tmpVector);\r\n }\r\n }\r\n Object.keys(this._controllers).forEach((controllerId) => {\r\n const controllerData = this._controllers[controllerId];\r\n const controllerMesh = controllerData.xrController.grip || controllerData.xrController.pointer;\r\n const comparedPosition = controllerData.oldPos || controllerData.impostorMesh!.position;\r\n if (controllerData.xrController._lastXRPose?.linearVelocity) {\r\n const lv = controllerData.xrController._lastXRPose.linearVelocity;\r\n this._tmpVector.set(lv.x, lv.y, lv.z);\r\n controllerData.impostor.setLinearVelocity(this._tmpVector);\r\n } else {\r\n controllerMesh.position.subtractToRef(comparedPosition, this._tmpVector);\r\n this._tmpVector.scaleInPlace(1000 / this._delta);\r\n controllerData.impostor.setLinearVelocity(this._tmpVector);\r\n }\r\n comparedPosition.copyFrom(controllerMesh.position);\r\n if (this._debugMode) {\r\n console.log(this._tmpVector, \"linear\");\r\n }\r\n\r\n const comparedQuaternion = controllerData.oldRotation || controllerData.impostorMesh!.rotationQuaternion!;\r\n if (controllerData.xrController._lastXRPose?.angularVelocity) {\r\n const av = controllerData.xrController._lastXRPose.angularVelocity;\r\n this._tmpVector.set(av.x, av.y, av.z);\r\n controllerData.impostor.setAngularVelocity(this._tmpVector);\r\n } else {\r\n if (!comparedQuaternion.equalsWithEpsilon(controllerMesh.rotationQuaternion!)) {\r\n // roughly based on this - https://www.gamedev.net/forums/topic/347752-quaternion-and-angular-velocity/\r\n comparedQuaternion.conjugateInPlace().multiplyToRef(controllerMesh.rotationQuaternion!, this._tmpQuaternion);\r\n const len = Math.sqrt(\r\n this._tmpQuaternion.x * this._tmpQuaternion.x + this._tmpQuaternion.y * this._tmpQuaternion.y + this._tmpQuaternion.z * this._tmpQuaternion.z\r\n );\r\n this._tmpVector.set(this._tmpQuaternion.x, this._tmpQuaternion.y, this._tmpQuaternion.z);\r\n // define a better epsilon\r\n if (len < 0.001) {\r\n this._tmpVector.scaleInPlace(2);\r\n } else {\r\n const angle = 2 * Math.atan2(len, this._tmpQuaternion.w);\r\n this._tmpVector.scaleInPlace(angle / (len * (this._delta / 1000)));\r\n }\r\n controllerData.impostor.setAngularVelocity(this._tmpVector);\r\n }\r\n }\r\n comparedQuaternion.copyFrom(controllerMesh.rotationQuaternion!);\r\n if (this._debugMode) {\r\n console.log(this._tmpVector, this._tmpQuaternion, \"angular\");\r\n }\r\n });\r\n }\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n if (controllerData.impostorMesh) {\r\n controllerData.impostorMesh.dispose();\r\n }\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n}\r\n\r\n//register the plugin\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerPhysics.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerPhysics(xrSessionManager, options);\r\n },\r\n WebXRControllerPhysics.Version,\r\n true\r\n);\r\n"]}