@babylonjs/core 6.26.0 → 6.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Behaviors/Meshes/attachToBoxBehavior.js.map +1 -1
- package/Cameras/Inputs/flyCameraMouseInput.js.map +1 -1
- package/Cameras/VR/vrExperienceHelper.js.map +1 -1
- package/Collisions/intersectionInfo.js.map +1 -1
- package/Engines/Processors/Expressions/Operators/shaderDefineArithmeticOperator.js.map +1 -1
- package/Engines/Processors/Expressions/Operators/shaderDefineIsDefinedOperator.js.map +1 -1
- package/Engines/WebGPU/webgpuBundleList.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.d.ts +3 -4
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js +5 -6
- package/FlowGraph/Blocks/Data/flowGraphBinaryOperationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.d.ts +22 -0
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js +26 -0
- package/FlowGraph/Blocks/Data/flowGraphCachedOperationBlock.js.map +1 -0
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.d.ts +3 -5
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js +5 -6
- package/FlowGraph/Blocks/Data/flowGraphConstantOperationBlock.js.map +1 -1
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.d.ts +3 -4
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js +5 -6
- package/FlowGraph/Blocks/Data/flowGraphUnaryOperationBlock.js.map +1 -1
- package/FlowGraph/flowGraphConnection.d.ts +1 -1
- package/FlowGraph/flowGraphConnection.js +2 -1
- package/FlowGraph/flowGraphConnection.js.map +1 -1
- package/FlowGraph/flowGraphContext.d.ts +10 -0
- package/FlowGraph/flowGraphContext.js +14 -0
- package/FlowGraph/flowGraphContext.js.map +1 -1
- package/FlowGraph/flowGraphDataConnection.js.map +1 -1
- package/FlowGraph/flowGraphRichTypes.js.map +1 -1
- package/FlowGraph/flowGraphSignalConnection.js +1 -0
- package/FlowGraph/flowGraphSignalConnection.js.map +1 -1
- package/Layers/highlightLayer.js.map +1 -1
- package/Loading/loadingScreen.js.map +1 -1
- package/Materials/Background/backgroundMaterial.d.ts +16 -0
- package/Materials/Background/backgroundMaterial.js +44 -0
- package/Materials/Background/backgroundMaterial.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js +0 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBaseBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +6 -2
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineBaseMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineMesh.js.map +1 -1
- package/Meshes/GreasedLine/greasedLineRibbonMesh.js.map +1 -1
- package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.d.ts +10 -1
- package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js +27 -5
- package/Meshes/Node/Blocks/Instances/instantiateOnFacesBlock.js.map +1 -1
- package/Meshes/Node/Blocks/mergeGeometryBlock.js +16 -4
- package/Meshes/Node/Blocks/mergeGeometryBlock.js.map +1 -1
- package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.d.ts +5 -0
- package/Meshes/Node/Interfaces/nodeGeometryExecutionContext.js.map +1 -1
- package/Meshes/Node/nodeGeometryBuildState.js +3 -0
- package/Meshes/Node/nodeGeometryBuildState.js.map +1 -1
- package/Meshes/csg.js.map +1 -1
- package/Meshes/geodesicMesh.js.map +1 -1
- package/Meshes/meshSimplification.js.map +1 -1
- package/Misc/PerformanceViewer/performanceViewerCollector.js.map +1 -1
- package/Misc/fileTools.js.map +1 -1
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/v1/Plugins/ammoJSPlugin.js.map +1 -1
- package/Physics/v1/Plugins/cannonJSPlugin.js.map +1 -1
- package/Physics/v1/Plugins/oimoJSPlugin.js.map +1 -1
- package/Physics/v1/physicsEngine.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderPipeline.js.map +1 -1
- package/PostProcesses/bloomEffect.js.map +1 -1
- package/Rendering/boundingBoxRenderer.js +6 -2
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/backgroundFragmentDeclaration.js +3 -0
- package/Shaders/ShadersInclude/backgroundFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/backgroundUboDeclaration.js +1 -8
- package/Shaders/ShadersInclude/backgroundUboDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js +1 -1
- package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrHelperFunctions.js +1 -3
- package/Shaders/ShadersInclude/pbrHelperFunctions.js.map +1 -1
- package/Shaders/background.fragment.js +11 -1
- package/Shaders/background.fragment.js.map +1 -1
- package/Shaders/default.fragment.js +0 -1
- package/Shaders/default.fragment.js.map +1 -1
- package/XR/features/WebXRAnchorSystem.js.map +1 -1
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRControllerPointerSelection.js.map +1 -1
- package/XR/features/WebXRControllerTeleportation.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/features/WebXRLayers.js.map +1 -1
- package/XR/features/WebXRMeshDetector.js.map +1 -1
- package/XR/features/WebXRNearInteraction.js.map +1 -1
- package/XR/features/WebXRPlaneDetector.js.map +1 -1
- package/XR/features/WebXRSpaceWarp.js.map +1 -1
- package/XR/native/nativeXRRenderTarget.js.map +1 -1
- package/XR/webXRCamera.js.map +1 -1
- package/XR/webXRManagedOutputCanvas.js.map +1 -1
- package/XR/webXRRenderTargetTextureProvider.js.map +1 -1
- package/XR/webXRWebGLLayer.js.map +1 -1
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attachToBoxBehavior.js","sourceRoot":"","sources":["../../../../../dev/core/src/Behaviors/Meshes/attachToBoxBehavior.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAQtE;;GAEG;AACH,MAAM,iBAAiB;IACnB,YAAmB,SAAkB,EAAS,mBAAmB,IAAI,OAAO,EAAE,EAAS,OAAO,CAAC,EAAS,SAAS,KAAK;QAAnG,cAAS,GAAT,SAAS,CAAS;QAAS,qBAAgB,GAAhB,gBAAgB,CAAgB;QAAS,SAAI,GAAJ,IAAI,CAAI;QAAS,WAAM,GAAN,MAAM,CAAQ;IAAG,CAAC;CAC7H;AAED;;GAEG;AACH,MAAM,OAAO,mBAAmB;IA2B5B;;;OAGG;IACH,YAAoB,GAAkB;QAAlB,QAAG,GAAH,GAAG,CAAe;QA9BtC;;WAEG;QACI,SAAI,GAAG,qBAAqB,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAG,IAAI,CAAC;QACnC;;WAEG;QACI,iCAA4B,GAAG,IAAI,CAAC;QACnC,iBAAY,GAAG;YACnB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YACnC,IAAI,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,iBAAiB,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACtC,IAAI,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;YACxC,IAAI,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,YAAY,CAAC,CAAC,C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maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Behavior } from \"../../Behaviors/behavior\";\r\n\r\n/**\r\n * @internal\r\n */\r\nclass FaceDirectionInfo {\r\n constructor(public direction: Vector3, public rotatedDirection = new Vector3(), public diff = 0, public ignore = false) {}\r\n}\r\n\r\n/**\r\n * A behavior that when attached to a mesh will will place a specified node on the meshes face pointing towards the camera\r\n */\r\nexport class AttachToBoxBehavior implements Behavior<Mesh> {\r\n /**\r\n * The name of the behavior\r\n */\r\n public name = \"AttachToBoxBehavior\";\r\n /**\r\n * The distance away from the face of the mesh that the UI should be attached to (default: 0.15)\r\n */\r\n public distanceAwayFromFace = 0.15;\r\n /**\r\n * The distance from the bottom of the face that the UI should be attached to (default: 0.15)\r\n */\r\n public distanceAwayFromBottomOfFace = 0.15;\r\n private _faceVectors = [\r\n new FaceDirectionInfo(Vector3.Up()),\r\n new FaceDirectionInfo(Vector3.Down()),\r\n new FaceDirectionInfo(Vector3.Left()),\r\n new FaceDirectionInfo(Vector3.Right()),\r\n new FaceDirectionInfo(Vector3.Forward()),\r\n new FaceDirectionInfo(Vector3.Forward().scaleInPlace(-1)),\r\n ];\r\n private _target: Mesh;\r\n private _scene: Scene;\r\n private _onRenderObserver: Nullable<Observer<Scene>>;\r\n private _tmpMatrix = new Matrix();\r\n private _tmpVector = new Vector3();\r\n\r\n /**\r\n * Creates the AttachToBoxBehavior, used to attach UI to the closest face of the box to a camera\r\n * @param _ui The transform node that should be attached to the mesh\r\n */\r\n constructor(private _ui: TransformNode) {\r\n /* Does nothing */\r\n }\r\n\r\n /**\r\n * Initializes the behavior\r\n */\r\n public init() {\r\n /* Does nothing */\r\n }\r\n\r\n private _closestFace(targetDirection: Vector3) {\r\n // Go over each face and calculate the angle between the face's normal and targetDirection\r\n this._faceVectors.forEach((v) => {\r\n if (!this._target.rotationQuaternion) {\r\n this._target.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._target.rotation.y, this._target.rotation.x, this._target.rotation.z);\r\n }\r\n this._target.rotationQuaternion.toRotationMatrix(this._tmpMatrix);\r\n Vector3.TransformCoordinatesToRef(v.direction, this._tmpMatrix, v.rotatedDirection);\r\n v.diff = Vector3.GetAngleBetweenVectors(v.rotatedDirection, targetDirection, Vector3.Cross(v.rotatedDirection, targetDirection));\r\n });\r\n // Return the face information of the one with the normal closest to target direction\r\n return this._faceVectors.reduce((min, p) => {\r\n if (min.ignore) {\r\n return p;\r\n } else if (p.ignore) {\r\n return min;\r\n } else {\r\n return min.diff < p.diff ? min : p;\r\n }\r\n }, this._faceVectors[0]);\r\n }\r\n\r\n private _zeroVector = Vector3.Zero();\r\n private _lookAtTmpMatrix = new Matrix();\r\n private _lookAtToRef(pos: Vector3, up = new Vector3(0, 1, 0), ref: Quaternion) {\r\n Matrix.LookAtLHToRef(this._zeroVector, pos, up, this._lookAtTmpMatrix);\r\n this._lookAtTmpMatrix.invert();\r\n Quaternion.FromRotationMatrixToRef(this._lookAtTmpMatrix, ref);\r\n }\r\n\r\n /**\r\n * Attaches the AttachToBoxBehavior to the passed in mesh\r\n * @param target The mesh that the specified node will be attached to\r\n */\r\n attach(target: Mesh) {\r\n this._target = target;\r\n this._scene = this._target.getScene();\r\n\r\n // Every frame, update the app bars position\r\n this._onRenderObserver = this._scene.onBeforeRenderObservable.add(() => {\r\n if (!this._scene.activeCamera) {\r\n return;\r\n }\r\n\r\n // Find the face closest to the cameras position\r\n let cameraPos = this._scene.activeCamera.position;\r\n if ((<any>this._scene.activeCamera).devicePosition) {\r\n cameraPos = (<any>this._scene.activeCamera).devicePosition;\r\n }\r\n const facing = this._closestFace(cameraPos.subtract(target.position));\r\n if (this._scene.activeCamera.leftCamera) {\r\n this._scene.activeCamera.leftCamera.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);\r\n } else {\r\n this._scene.activeCamera.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);\r\n }\r\n\r\n // Get camera up direction\r\n Vector3.TransformCoordinatesToRef(Vector3.Up(), this._tmpMatrix, this._tmpVector);\r\n // Ignore faces to not select a parallel face for the up vector of the UI\r\n this._faceVectors.forEach((v) => {\r\n if (facing.direction.x && v.direction.x) {\r\n v.ignore = true;\r\n }\r\n if (facing.direction.y && v.direction.y) {\r\n v.ignore = true;\r\n }\r\n if (facing.direction.z && v.direction.z) {\r\n v.ignore = true;\r\n }\r\n });\r\n const facingUp = this._closestFace(this._tmpVector);\r\n // Unignore faces\r\n this._faceVectors.forEach((v) => {\r\n v.ignore = false;\r\n });\r\n\r\n // Position the app bar on that face\r\n this._ui.position.copyFrom(target.position);\r\n if (facing.direction.x) {\r\n facing.rotatedDirection.scaleToRef(target.scaling.x / 2 + this.distanceAwayFromFace, this._tmpVector);\r\n this._ui.position.addInPlace(this._tmpVector);\r\n }\r\n if (facing.direction.y) {\r\n facing.rotatedDirection.scaleToRef(target.scaling.y / 2 + this.distanceAwayFromFace, this._tmpVector);\r\n this._ui.position.addInPlace(this._tmpVector);\r\n }\r\n if (facing.direction.z) {\r\n facing.rotatedDirection.scaleToRef(target.scaling.z / 2 + this.distanceAwayFromFace, this._tmpVector);\r\n this._ui.position.addInPlace(this._tmpVector);\r\n }\r\n\r\n // Rotate to be oriented properly to the camera\r\n if (!this._ui.rotationQuaternion) {\r\n this._ui.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._ui.rotation.y, this._ui.rotation.x, this._ui.rotation.z);\r\n }\r\n facing.rotatedDirection.scaleToRef(-1, this._tmpVector);\r\n this._lookAtToRef(this._tmpVector, facingUp.rotatedDirection, this._ui.rotationQuaternion);\r\n\r\n // Place ui the correct distance from the bottom of the mesh\r\n if (facingUp.direction.x) {\r\n this._ui.up.scaleToRef(this.distanceAwayFromBottomOfFace - target.scaling.x / 2, this._tmpVector);\r\n }\r\n if (facingUp.direction.y) {\r\n this._ui.up.scaleToRef(this.distanceAwayFromBottomOfFace - target.scaling.y / 2, this._tmpVector);\r\n }\r\n if (facingUp.direction.z) {\r\n this._ui.up.scaleToRef(this.distanceAwayFromBottomOfFace - target.scaling.z / 2, this._tmpVector);\r\n }\r\n this._ui.position.addInPlace(this._tmpVector);\r\n });\r\n }\r\n\r\n /**\r\n * Detaches the behavior from the mesh\r\n */\r\n detach() {\r\n this._scene.onBeforeRenderObservable.remove(this._onRenderObserver);\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"attachToBoxBehavior.js","sourceRoot":"","sources":["../../../../../dev/core/src/Behaviors/Meshes/attachToBoxBehavior.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAQtE;;GAEG;AACH,MAAM,iBAAiB;IACnB,YACW,SAAkB,EAClB,mBAAmB,IAAI,OAAO,EAAE,EAChC,OAAO,CAAC,EACR,SAAS,KAAK;QAHd,cAAS,GAAT,SAAS,CAAS;QAClB,qBAAgB,GAAhB,gBAAgB,CAAgB;QAChC,SAAI,GAAJ,IAAI,CAAI;QACR,WAAM,GAAN,MAAM,CAAQ;IACtB,CAAC;CACP;AAED;;GAEG;AACH,MAAM,OAAO,mBAAmB;IA2B5B;;;OAGG;IACH,YAAoB,GAAkB;QAAlB,QAAG,GAAH,GAAG,CAAe;QA9BtC;;WAEG;QACI,SAAI,GAAG,qBAAqB,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAG,IAAI,CAAC;QACnC;;WAEG;QACI,iCAA4B,GAAG,IAAI,CAAC;QACnC,iBAAY,GAAG;YACnB,IAAI,iBAAiB,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YACnC,IAAI,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,iBAAiB,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;YACrC,IAAI,iBAAiB,C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IAED;;OAEG;IACH,MAAM;QACF,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IACxE,CAAC;CACJ","sourcesContent":["import { Vector3, Matrix, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Behavior } from \"../../Behaviors/behavior\";\r\n\r\n/**\r\n * @internal\r\n */\r\nclass FaceDirectionInfo {\r\n constructor(\r\n public direction: Vector3,\r\n public rotatedDirection = new Vector3(),\r\n public diff = 0,\r\n public ignore = false\r\n ) {}\r\n}\r\n\r\n/**\r\n * A behavior that when attached to a mesh will will place a specified node on the meshes face pointing towards the camera\r\n */\r\nexport class AttachToBoxBehavior implements Behavior<Mesh> {\r\n /**\r\n * The name of the behavior\r\n */\r\n public name = \"AttachToBoxBehavior\";\r\n /**\r\n * The distance away from the face of the mesh that the UI should be attached to (default: 0.15)\r\n */\r\n public distanceAwayFromFace = 0.15;\r\n /**\r\n * The distance from the bottom of the face that the UI should be attached to (default: 0.15)\r\n */\r\n public distanceAwayFromBottomOfFace = 0.15;\r\n private _faceVectors = [\r\n new FaceDirectionInfo(Vector3.Up()),\r\n new FaceDirectionInfo(Vector3.Down()),\r\n new FaceDirectionInfo(Vector3.Left()),\r\n new FaceDirectionInfo(Vector3.Right()),\r\n new FaceDirectionInfo(Vector3.Forward()),\r\n new FaceDirectionInfo(Vector3.Forward().scaleInPlace(-1)),\r\n ];\r\n private _target: Mesh;\r\n private _scene: Scene;\r\n private _onRenderObserver: Nullable<Observer<Scene>>;\r\n private _tmpMatrix = new Matrix();\r\n private _tmpVector = new Vector3();\r\n\r\n /**\r\n * Creates the AttachToBoxBehavior, used to attach UI to the closest face of the box to a camera\r\n * @param _ui The transform node that should be attached to the mesh\r\n */\r\n constructor(private _ui: TransformNode) {\r\n /* Does nothing */\r\n }\r\n\r\n /**\r\n * Initializes the behavior\r\n */\r\n public init() {\r\n /* Does nothing */\r\n }\r\n\r\n private _closestFace(targetDirection: Vector3) {\r\n // Go over each face and calculate the angle between the face's normal and targetDirection\r\n this._faceVectors.forEach((v) => {\r\n if (!this._target.rotationQuaternion) {\r\n this._target.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._target.rotation.y, this._target.rotation.x, this._target.rotation.z);\r\n }\r\n this._target.rotationQuaternion.toRotationMatrix(this._tmpMatrix);\r\n Vector3.TransformCoordinatesToRef(v.direction, this._tmpMatrix, v.rotatedDirection);\r\n v.diff = Vector3.GetAngleBetweenVectors(v.rotatedDirection, targetDirection, Vector3.Cross(v.rotatedDirection, targetDirection));\r\n });\r\n // Return the face information of the one with the normal closest to target direction\r\n return this._faceVectors.reduce((min, p) => {\r\n if (min.ignore) {\r\n return p;\r\n } else if (p.ignore) {\r\n return min;\r\n } else {\r\n return min.diff < p.diff ? min : p;\r\n }\r\n }, this._faceVectors[0]);\r\n }\r\n\r\n private _zeroVector = Vector3.Zero();\r\n private _lookAtTmpMatrix = new Matrix();\r\n private _lookAtToRef(pos: Vector3, up = new Vector3(0, 1, 0), ref: Quaternion) {\r\n Matrix.LookAtLHToRef(this._zeroVector, pos, up, this._lookAtTmpMatrix);\r\n this._lookAtTmpMatrix.invert();\r\n Quaternion.FromRotationMatrixToRef(this._lookAtTmpMatrix, ref);\r\n }\r\n\r\n /**\r\n * Attaches the AttachToBoxBehavior to the passed in mesh\r\n * @param target The mesh that the specified node will be attached to\r\n */\r\n attach(target: Mesh) {\r\n this._target = target;\r\n this._scene = this._target.getScene();\r\n\r\n // Every frame, update the app bars position\r\n this._onRenderObserver = this._scene.onBeforeRenderObservable.add(() => {\r\n if (!this._scene.activeCamera) {\r\n return;\r\n }\r\n\r\n // Find the face closest to the cameras position\r\n let cameraPos = this._scene.activeCamera.position;\r\n if ((<any>this._scene.activeCamera).devicePosition) {\r\n cameraPos = (<any>this._scene.activeCamera).devicePosition;\r\n }\r\n const facing = this._closestFace(cameraPos.subtract(target.position));\r\n if (this._scene.activeCamera.leftCamera) {\r\n this._scene.activeCamera.leftCamera.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);\r\n } else {\r\n this._scene.activeCamera.computeWorldMatrix().getRotationMatrixToRef(this._tmpMatrix);\r\n }\r\n\r\n // Get camera up direction\r\n Vector3.TransformCoordinatesToRef(Vector3.Up(), this._tmpMatrix, this._tmpVector);\r\n // Ignore faces to not select a parallel face for the up vector of the UI\r\n this._faceVectors.forEach((v) => {\r\n if (facing.direction.x && v.direction.x) {\r\n v.ignore = true;\r\n }\r\n if (facing.direction.y && v.direction.y) {\r\n v.ignore = true;\r\n }\r\n if (facing.direction.z && v.direction.z) {\r\n v.ignore = true;\r\n }\r\n });\r\n const facingUp = this._closestFace(this._tmpVector);\r\n // Unignore faces\r\n this._faceVectors.forEach((v) => {\r\n v.ignore = false;\r\n });\r\n\r\n // Position the app bar on that face\r\n this._ui.position.copyFrom(target.position);\r\n if (facing.direction.x) {\r\n facing.rotatedDirection.scaleToRef(target.scaling.x / 2 + this.distanceAwayFromFace, this._tmpVector);\r\n this._ui.position.addInPlace(this._tmpVector);\r\n }\r\n if (facing.direction.y) {\r\n facing.rotatedDirection.scaleToRef(target.scaling.y / 2 + this.distanceAwayFromFace, this._tmpVector);\r\n this._ui.position.addInPlace(this._tmpVector);\r\n }\r\n if (facing.direction.z) {\r\n facing.rotatedDirection.scaleToRef(target.scaling.z / 2 + this.distanceAwayFromFace, this._tmpVector);\r\n this._ui.position.addInPlace(this._tmpVector);\r\n }\r\n\r\n // Rotate to be oriented properly to the camera\r\n if (!this._ui.rotationQuaternion) {\r\n this._ui.rotationQuaternion = Quaternion.RotationYawPitchRoll(this._ui.rotation.y, this._ui.rotation.x, this._ui.rotation.z);\r\n }\r\n facing.rotatedDirection.scaleToRef(-1, this._tmpVector);\r\n this._lookAtToRef(this._tmpVector, facingUp.rotatedDirection, this._ui.rotationQuaternion);\r\n\r\n // Place ui the correct distance from the bottom of the mesh\r\n if (facingUp.direction.x) {\r\n this._ui.up.scaleToRef(this.distanceAwayFromBottomOfFace - target.scaling.x / 2, this._tmpVector);\r\n }\r\n if (facingUp.direction.y) {\r\n this._ui.up.scaleToRef(this.distanceAwayFromBottomOfFace - target.scaling.y / 2, this._tmpVector);\r\n }\r\n if (facingUp.direction.z) {\r\n this._ui.up.scaleToRef(this.distanceAwayFromBottomOfFace - target.scaling.z / 2, this._tmpVector);\r\n }\r\n this._ui.position.addInPlace(this._tmpVector);\r\n });\r\n }\r\n\r\n /**\r\n * Detaches the behavior from the mesh\r\n */\r\n detach() {\r\n this._scene.onBeforeRenderObservable.remove(this._onRenderObserver);\r\n }\r\n}\r\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flyCameraMouseInput.js","sourceRoot":"","sources":["../../../../../dev/core/src/Cameras/Inputs/flyCameraMouseInput.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAGrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEzC;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IAsD5B;;;OAGG;IACH;QA/CA;;WAEG;QAEI,YAAO,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAE3B;;WAEG;QACI,eAAU,GAAa,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QAEzC;;WAEG;QACI,iBAAY,GAAa,CAAC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Y,CAAC;QACnC,CAAC,CAAC,EACJ;YACE,2CAA2C;YAC3C,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACrD,iBAAiB;YACjB,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;YACvB,6BAA6B;YAC7B,eAAe,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;SACnD;QAED,qDAAqD;QACrD,eAAe,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;CACJ;AAhRU;IADN,SAAS,EAAE;oDACe;AA+BpB;IADN,SAAS,EAAE;+DACuB;AAmPjC,gBAAiB,CAAC,qBAAqB,CAAC,GAAG,mBAAmB,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FlyCamera } from \"../../Cameras/flyCamera\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport { Axis } from \"../../Maths/math.axis\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n/**\r\n * Listen to mouse events to control the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FlyCameraMouseInput implements ICameraInput<FlyCamera> {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: FlyCamera;\r\n\r\n /**\r\n * Defines if touch is enabled. (Default is true.)\r\n */\r\n public touchEnabled: boolean;\r\n\r\n /**\r\n * Defines the buttons associated with the input to handle camera rotation.\r\n */\r\n @serialize()\r\n public buttons = [0, 1, 2];\r\n\r\n /**\r\n * Assign buttons for Yaw control.\r\n */\r\n public buttonsYaw: number[] = [-1, 0, 1];\r\n\r\n /**\r\n * Assign buttons for Pitch control.\r\n */\r\n public buttonsPitch: number[] = [-1, 0, 1];\r\n\r\n /**\r\n * Assign buttons for Roll control.\r\n */\r\n public buttonsRoll: number[] = [2];\r\n\r\n /**\r\n * Detect if any button is being pressed while mouse is moved.\r\n * -1 = Mouse locked.\r\n * 0 = Left button.\r\n * 1 = Middle Button.\r\n * 2 = Right Button.\r\n */\r\n public activeButton: number = -1;\r\n\r\n /**\r\n * Defines the pointer's angular sensibility, to control the camera rotation speed.\r\n * Higher values reduce its sensitivity.\r\n */\r\n @serialize()\r\n public angularSensibility = 1000.0;\r\n\r\n private _observer: Nullable<Observer<PointerInfo>>;\r\n private _rollObserver: Nullable<Observer<Scene>>;\r\n private _previousPosition: Nullable<{ x: number; y: number }> = null;\r\n private _noPreventDefault: boolean | undefined;\r\n private _element: HTMLElement;\r\n\r\n /**\r\n * Listen to mouse events to control the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Attach the mouse control to the HTML DOM element.\r\n * @param noPreventDefault Defines whether events caught by the controls should call preventdefault().\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n this._noPreventDefault = noPreventDefault;\r\n\r\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver((p: any) => {\r\n this._pointerInput(p);\r\n }, PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE);\r\n\r\n // Correct Roll by rate, if enabled.\r\n this._rollObserver = this.camera.getScene().onBeforeRenderObservable.add(() => {\r\n if (this.camera.rollCorrect) {\r\n this.camera.restoreRoll(this.camera.rollCorrect);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n\r\n this.camera.getScene().onBeforeRenderObservable.remove(this._rollObserver);\r\n\r\n this._observer = null;\r\n this._rollObserver = null;\r\n this._previousPosition = null;\r\n this._noPreventDefault = undefined;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name.\r\n */\r\n public getClassName(): string {\r\n return \"FlyCameraMouseInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input's friendly name.\r\n */\r\n public getSimpleName(): string {\r\n return \"mouse\";\r\n }\r\n\r\n // Track mouse movement, when the pointer is not locked.\r\n private _pointerInput(p: any): void {\r\n const e = <IPointerEvent>p.event;\r\n\r\n const camera = this.camera;\r\n const engine = camera.getEngine();\r\n\r\n if (!this.touchEnabled && e.pointerType === \"touch\") {\r\n return;\r\n }\r\n\r\n // Mouse is moved but an unknown mouse button is pressed.\r\n if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(e.button) === -1) {\r\n return;\r\n }\r\n\r\n const srcElement = <HTMLElement>e.target;\r\n\r\n // Mouse down.\r\n if (p.type === PointerEventTypes.POINTERDOWN) {\r\n try {\r\n srcElement?.setPointerCapture(e.pointerId);\r\n } catch (e) {\r\n // Nothing to do with the error. Execution continues.\r\n }\r\n\r\n this._previousPosition = {\r\n x: e.clientX,\r\n y: e.clientY,\r\n };\r\n\r\n this.activeButton = e.button;\r\n\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n this._element.focus();\r\n }\r\n\r\n // This is required to move while pointer button is down\r\n if (engine.isPointerLock) {\r\n this._onMouseMove(p.event);\r\n }\r\n }\r\n // Mouse up.\r\n else if (p.type === PointerEventTypes.POINTERUP) {\r\n try {\r\n srcElement?.releasePointerCapture(e.pointerId);\r\n } catch (e) {\r\n // Nothing to do with the error. Execution continues.\r\n }\r\n\r\n this.activeButton = -1;\r\n\r\n this._previousPosition = null;\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n }\r\n }\r\n // Mouse move.\r\n else if (p.type === PointerEventTypes.POINTERMOVE) {\r\n if (!this._previousPosition) {\r\n if (engine.isPointerLock) {\r\n this._onMouseMove(p.event);\r\n }\r\n\r\n return;\r\n }\r\n\r\n const offsetX = e.clientX - this._previousPosition.x;\r\n const offsetY = e.clientY - this._previousPosition.y;\r\n\r\n this._rotateCamera(offsetX, offsetY);\r\n\r\n this._previousPosition = {\r\n x: e.clientX,\r\n y: e.clientY,\r\n };\r\n\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n }\r\n }\r\n }\r\n\r\n // Track mouse movement, when pointer is locked.\r\n private _onMouseMove(e: any): void {\r\n const camera = this.camera;\r\n const engine = camera.getEngine();\r\n\r\n if (!engine.isPointerLock) {\r\n return;\r\n }\r\n\r\n const offsetX = e.movementX;\r\n const offsetY = e.movementY;\r\n\r\n this._rotateCamera(offsetX, offsetY);\r\n\r\n this._previousPosition = null;\r\n\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n }\r\n }\r\n\r\n /**\r\n * Rotate camera by mouse offset.\r\n * @param offsetX\r\n * @param offsetY\r\n */\r\n private _rotateCamera(offsetX: number, offsetY: number): void {\r\n const camera = this.camera;\r\n const handednessMultiplier = camera._calculateHandednessMultiplier();\r\n\r\n offsetX *= handednessMultiplier;\r\n\r\n const x = offsetX / this.angularSensibility;\r\n const y = offsetY / this.angularSensibility;\r\n\r\n // Initialize to current rotation.\r\n const currentRotation = Quaternion.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, camera.rotation.z);\r\n let rotationChange: Quaternion;\r\n\r\n // Pitch.\r\n if (\r\n this.buttonsPitch.some((v) => {\r\n return v === this.activeButton;\r\n })\r\n ) {\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.X, y);\r\n // Apply Pitch to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n }\r\n\r\n // Yaw.\r\n if (\r\n this.buttonsYaw.some((v) => {\r\n return v === this.activeButton;\r\n })\r\n ) {\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.Y, x);\r\n // Apply Yaw to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n\r\n // Add Roll, if banked turning is enabled, within Roll limit.\r\n const limit = camera.bankedTurnLimit + camera._trackRoll; // Defaults to 90° plus manual roll.\r\n if (camera.bankedTurn && -limit < camera.rotation.z && camera.rotation.z < limit) {\r\n const bankingDelta = camera.bankedTurnMultiplier * -x;\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.Z, bankingDelta);\r\n // Apply Yaw to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n }\r\n }\r\n\r\n // Roll.\r\n if (\r\n this.buttonsRoll.some((v) => {\r\n return v === this.activeButton;\r\n })\r\n ) {\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.Z, -x);\r\n // Track Rolling.\r\n camera._trackRoll -= x;\r\n // Apply Pitch to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n }\r\n\r\n // Apply rotationQuaternion to Euler camera.rotation.\r\n currentRotation.toEulerAnglesToRef(camera.rotation);\r\n }\r\n}\r\n\r\n(<any>CameraInputTypes)[\"FlyCameraMouseInput\"] = FlyCameraMouseInput;\r\n"]}
|
|
1
|
+
{"version":3,"file":"flyCameraMouseInput.js","sourceRoot":"","sources":["../../../../../dev/core/src/Cameras/Inputs/flyCameraMouseInput.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAGlD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAGrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAE/D,OAAO,EAAE,U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CAAC,GAAG,KAAK,EAAE;gBAC9E,MAAM,YAAY,GAAG,MAAM,CAAC,oBAAoB,GAAG,CAAC,CAAC,CAAC;gBACtD,2CAA2C;gBAC3C,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;gBAC/D,2BAA2B;gBAC3B,eAAe,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;aACnD;SACJ;QAED,QAAQ;QACR,IACI,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE;YACxB,OAAO,CAAC,KAAK,IAAI,CAAC,YAAY,CAAC;QACnC,CAAC,CAAC,EACJ;YACE,2CAA2C;YAC3C,cAAc,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;YACrD,iBAAiB;YACjB,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC;YACvB,6BAA6B;YAC7B,eAAe,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;SACnD;QAED,qDAAqD;QACrD,eAAe,CAAC,kBAAkB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxD,CAAC;CACJ;AAnRU;IADN,SAAS,EAAE;oDACe;AA+BpB;IADN,SAAS,EAAE;+DACuB;AAsPjC,gBAAiB,CAAC,qBAAqB,CAAC,GAAG,mBAAmB,CAAC","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { serialize } from \"../../Misc/decorators\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { ICameraInput } from \"../../Cameras/cameraInputsManager\";\r\nimport { CameraInputTypes } from \"../../Cameras/cameraInputsManager\";\r\nimport type { FlyCamera } from \"../../Cameras/flyCamera\";\r\nimport type { PointerInfo } from \"../../Events/pointerEvents\";\r\nimport { PointerEventTypes } from \"../../Events/pointerEvents\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { Quaternion } from \"../../Maths/math.vector\";\r\nimport { Axis } from \"../../Maths/math.axis\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { IPointerEvent } from \"../../Events/deviceInputEvents\";\r\n/**\r\n * Listen to mouse events to control the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\nexport class FlyCameraMouseInput implements ICameraInput<FlyCamera> {\r\n /**\r\n * Defines the camera the input is attached to.\r\n */\r\n public camera: FlyCamera;\r\n\r\n /**\r\n * Defines if touch is enabled. (Default is true.)\r\n */\r\n public touchEnabled: boolean;\r\n\r\n /**\r\n * Defines the buttons associated with the input to handle camera rotation.\r\n */\r\n @serialize()\r\n public buttons = [0, 1, 2];\r\n\r\n /**\r\n * Assign buttons for Yaw control.\r\n */\r\n public buttonsYaw: number[] = [-1, 0, 1];\r\n\r\n /**\r\n * Assign buttons for Pitch control.\r\n */\r\n public buttonsPitch: number[] = [-1, 0, 1];\r\n\r\n /**\r\n * Assign buttons for Roll control.\r\n */\r\n public buttonsRoll: number[] = [2];\r\n\r\n /**\r\n * Detect if any button is being pressed while mouse is moved.\r\n * -1 = Mouse locked.\r\n * 0 = Left button.\r\n * 1 = Middle Button.\r\n * 2 = Right Button.\r\n */\r\n public activeButton: number = -1;\r\n\r\n /**\r\n * Defines the pointer's angular sensibility, to control the camera rotation speed.\r\n * Higher values reduce its sensitivity.\r\n */\r\n @serialize()\r\n public angularSensibility = 1000.0;\r\n\r\n private _observer: Nullable<Observer<PointerInfo>>;\r\n private _rollObserver: Nullable<Observer<Scene>>;\r\n private _previousPosition: Nullable<{ x: number; y: number }> = null;\r\n private _noPreventDefault: boolean | undefined;\r\n private _element: HTMLElement;\r\n\r\n /**\r\n * Listen to mouse events to control the camera.\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/cameras/customizingCameraInputs\r\n */\r\n constructor() {}\r\n\r\n /**\r\n * Attach the mouse control to the HTML DOM element.\r\n * @param noPreventDefault Defines whether events caught by the controls should call preventdefault().\r\n */\r\n public attachControl(noPreventDefault?: boolean): void {\r\n // eslint-disable-next-line prefer-rest-params\r\n noPreventDefault = Tools.BackCompatCameraNoPreventDefault(arguments);\r\n this._noPreventDefault = noPreventDefault;\r\n\r\n this._observer = this.camera.getScene()._inputManager._addCameraPointerObserver(\r\n (p: any) => {\r\n this._pointerInput(p);\r\n },\r\n PointerEventTypes.POINTERDOWN | PointerEventTypes.POINTERUP | PointerEventTypes.POINTERMOVE\r\n );\r\n\r\n // Correct Roll by rate, if enabled.\r\n this._rollObserver = this.camera.getScene().onBeforeRenderObservable.add(() => {\r\n if (this.camera.rollCorrect) {\r\n this.camera.restoreRoll(this.camera.rollCorrect);\r\n }\r\n });\r\n }\r\n\r\n /**\r\n * Detach the current controls from the specified dom element.\r\n */\r\n public detachControl(): void {\r\n if (this._observer) {\r\n this.camera.getScene()._inputManager._removeCameraPointerObserver(this._observer);\r\n\r\n this.camera.getScene().onBeforeRenderObservable.remove(this._rollObserver);\r\n\r\n this._observer = null;\r\n this._rollObserver = null;\r\n this._previousPosition = null;\r\n this._noPreventDefault = undefined;\r\n }\r\n }\r\n\r\n /**\r\n * Gets the class name of the current input.\r\n * @returns the class name.\r\n */\r\n public getClassName(): string {\r\n return \"FlyCameraMouseInput\";\r\n }\r\n\r\n /**\r\n * Get the friendly name associated with the input class.\r\n * @returns the input's friendly name.\r\n */\r\n public getSimpleName(): string {\r\n return \"mouse\";\r\n }\r\n\r\n // Track mouse movement, when the pointer is not locked.\r\n private _pointerInput(p: any): void {\r\n const e = <IPointerEvent>p.event;\r\n\r\n const camera = this.camera;\r\n const engine = camera.getEngine();\r\n\r\n if (!this.touchEnabled && e.pointerType === \"touch\") {\r\n return;\r\n }\r\n\r\n // Mouse is moved but an unknown mouse button is pressed.\r\n if (p.type !== PointerEventTypes.POINTERMOVE && this.buttons.indexOf(e.button) === -1) {\r\n return;\r\n }\r\n\r\n const srcElement = <HTMLElement>e.target;\r\n\r\n // Mouse down.\r\n if (p.type === PointerEventTypes.POINTERDOWN) {\r\n try {\r\n srcElement?.setPointerCapture(e.pointerId);\r\n } catch (e) {\r\n // Nothing to do with the error. Execution continues.\r\n }\r\n\r\n this._previousPosition = {\r\n x: e.clientX,\r\n y: e.clientY,\r\n };\r\n\r\n this.activeButton = e.button;\r\n\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n this._element.focus();\r\n }\r\n\r\n // This is required to move while pointer button is down\r\n if (engine.isPointerLock) {\r\n this._onMouseMove(p.event);\r\n }\r\n }\r\n // Mouse up.\r\n else if (p.type === PointerEventTypes.POINTERUP) {\r\n try {\r\n srcElement?.releasePointerCapture(e.pointerId);\r\n } catch (e) {\r\n // Nothing to do with the error. Execution continues.\r\n }\r\n\r\n this.activeButton = -1;\r\n\r\n this._previousPosition = null;\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n }\r\n }\r\n // Mouse move.\r\n else if (p.type === PointerEventTypes.POINTERMOVE) {\r\n if (!this._previousPosition) {\r\n if (engine.isPointerLock) {\r\n this._onMouseMove(p.event);\r\n }\r\n\r\n return;\r\n }\r\n\r\n const offsetX = e.clientX - this._previousPosition.x;\r\n const offsetY = e.clientY - this._previousPosition.y;\r\n\r\n this._rotateCamera(offsetX, offsetY);\r\n\r\n this._previousPosition = {\r\n x: e.clientX,\r\n y: e.clientY,\r\n };\r\n\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n }\r\n }\r\n }\r\n\r\n // Track mouse movement, when pointer is locked.\r\n private _onMouseMove(e: any): void {\r\n const camera = this.camera;\r\n const engine = camera.getEngine();\r\n\r\n if (!engine.isPointerLock) {\r\n return;\r\n }\r\n\r\n const offsetX = e.movementX;\r\n const offsetY = e.movementY;\r\n\r\n this._rotateCamera(offsetX, offsetY);\r\n\r\n this._previousPosition = null;\r\n\r\n if (!this._noPreventDefault) {\r\n e.preventDefault();\r\n }\r\n }\r\n\r\n /**\r\n * Rotate camera by mouse offset.\r\n * @param offsetX\r\n * @param offsetY\r\n */\r\n private _rotateCamera(offsetX: number, offsetY: number): void {\r\n const camera = this.camera;\r\n const handednessMultiplier = camera._calculateHandednessMultiplier();\r\n\r\n offsetX *= handednessMultiplier;\r\n\r\n const x = offsetX / this.angularSensibility;\r\n const y = offsetY / this.angularSensibility;\r\n\r\n // Initialize to current rotation.\r\n const currentRotation = Quaternion.RotationYawPitchRoll(camera.rotation.y, camera.rotation.x, camera.rotation.z);\r\n let rotationChange: Quaternion;\r\n\r\n // Pitch.\r\n if (\r\n this.buttonsPitch.some((v) => {\r\n return v === this.activeButton;\r\n })\r\n ) {\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.X, y);\r\n // Apply Pitch to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n }\r\n\r\n // Yaw.\r\n if (\r\n this.buttonsYaw.some((v) => {\r\n return v === this.activeButton;\r\n })\r\n ) {\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.Y, x);\r\n // Apply Yaw to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n\r\n // Add Roll, if banked turning is enabled, within Roll limit.\r\n const limit = camera.bankedTurnLimit + camera._trackRoll; // Defaults to 90° plus manual roll.\r\n if (camera.bankedTurn && -limit < camera.rotation.z && camera.rotation.z < limit) {\r\n const bankingDelta = camera.bankedTurnMultiplier * -x;\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.Z, bankingDelta);\r\n // Apply Yaw to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n }\r\n }\r\n\r\n // Roll.\r\n if (\r\n this.buttonsRoll.some((v) => {\r\n return v === this.activeButton;\r\n })\r\n ) {\r\n // Apply change in Radians to vector Angle.\r\n rotationChange = Quaternion.RotationAxis(Axis.Z, -x);\r\n // Track Rolling.\r\n camera._trackRoll -= x;\r\n // Apply Pitch to quaternion.\r\n currentRotation.multiplyInPlace(rotationChange);\r\n }\r\n\r\n // Apply rotationQuaternion to Euler camera.rotation.\r\n currentRotation.toEulerAnglesToRef(camera.rotation);\r\n }\r\n}\r\n\r\n(<any>CameraInputTypes)[\"FlyCameraMouseInput\"] = FlyCameraMouseInput;\r\n"]}
|