@onerjs/core 8.47.2 → 8.47.4
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/Cameras/geospatialCameraMovement.js +4 -5
- package/Cameras/geospatialCameraMovement.js.map +1 -1
- package/Layers/thinSelectionOutlineLayer.d.ts +1 -0
- package/Layers/thinSelectionOutlineLayer.js +15 -3
- package/Layers/thinSelectionOutlineLayer.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +8 -1
- package/Meshes/abstractMesh.js +9 -2
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/mesh.js +2 -2
- package/Meshes/mesh.js.map +1 -1
- package/Physics/v2/characterController.d.ts +5 -0
- package/Physics/v2/characterController.js +6 -0
- package/Physics/v2/characterController.js.map +1 -1
- package/Physics/v2/physicsBody.js +3 -1
- package/Physics/v2/physicsBody.js.map +1 -1
- package/XR/webXRSessionManager.js +7 -5
- package/XR/webXRSessionManager.js.map +1 -1
- package/package.json +1 -1
|
@@ -146,7 +146,9 @@ export class PhysicsBody {
|
|
|
146
146
|
*/
|
|
147
147
|
set shape(shape) {
|
|
148
148
|
this._shape = shape;
|
|
149
|
-
|
|
149
|
+
if (shape) {
|
|
150
|
+
this._physicsPlugin.setShape(this, shape);
|
|
151
|
+
}
|
|
150
152
|
}
|
|
151
153
|
/**
|
|
152
154
|
* Retrieves the physics shape associated with this object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAAA,OAAO,EAMH,kBAAkB,GACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAc1E;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA8BpB;;;OAGG;IACH,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,YAAY,IAAI,kBAA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G,IAAI,CAAC;IACtB,CAAC;CACJ","sourcesContent":["import {\r\n type IBasePhysicsCollisionEvent,\r\n type IPhysicsCollisionEvent,\r\n type IPhysicsEnginePluginV2,\r\n type PhysicsMassProperties,\r\n PhysicsMotionType,\r\n PhysicsPrestepType,\r\n} from \"./IPhysicsEnginePlugin\";\r\nimport { type PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { type Scene } from \"../../scene\";\r\nimport { type PhysicsEngine } from \"./physicsEngine\";\r\nimport { type Nullable } from \"../../types\";\r\nimport { type PhysicsConstraint } from \"./physicsConstraint\";\r\nimport { type Bone } from \"../../Bones/bone\";\r\nimport { Space } from \"../../Maths/math.axis\";\r\nimport { type Observable, type Observer } from \"../../Misc/observable\";\r\nimport { type Node } from \"../../node\";\r\nimport { type Mesh } from \"../../Meshes/mesh\";\r\nimport { type AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { type TransformNode } from \"../../Meshes/transformNode\";\r\nimport { type BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * If the collision callback is enabled\r\n */\r\n private _collisionCBEnabled: boolean = false;\r\n /**\r\n * If the collision ended callback is enabled\r\n */\r\n private _collisionEndedCBEnabled: boolean = false;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n public get disablePreStep(): boolean {\r\n return this._prestepType == PhysicsPrestepType.DISABLED;\r\n }\r\n\r\n public set disablePreStep(value: boolean) {\r\n this._prestepType = value ? PhysicsPrestepType.DISABLED : PhysicsPrestepType.TELEPORT;\r\n }\r\n\r\n /**\r\n * Disable sync from physics to transformNode. This value is set to true at body creation or at motionType setting when the body is not dynamic.\r\n */\r\n disableSync: boolean = false;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n public startAsleep: boolean;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n private _isDisposed = false;\r\n\r\n private _shape: Nullable<PhysicsShape> = null;\r\n\r\n private _prestepType: PhysicsPrestepType = PhysicsPrestepType.DISABLED;\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for. For better performance, it is advised that this node does not have a parent.\r\n * @param motionType - The motion type of the physics body. The options are:\r\n * - PhysicsMotionType.STATIC - Static bodies are not moving and unaffected by forces or collisions. They are good for level boundaries or terrain.\r\n * - PhysicsMotionType.DYNAMIC - Dynamic bodies are fully simulated. They can move and collide with other objects.\r\n * - PhysicsMotionType.ANIMATED - They behave like dynamic bodies, but they won't be affected by other bodies, but still push other bodies out of the way.\r\n * @param startsAsleep - Whether the physics body should start in a sleeping state (not a guarantee). Defaults to false.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n\r\n this.startAsleep = startsAsleep;\r\n\r\n // only dynamic and animated body needs sync from physics to transformNode\r\n this.disableSync = motionType == PhysicsMotionType.STATIC;\r\n\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, motionType, m);\r\n } else {\r\n // single instance\r\n if (transformNode.parent) {\r\n // Force computation of world matrix so that the parent transforms are correctly reflected in absolutePosition/absoluteRotationQuaternion.\r\n transformNode.computeWorldMatrix(true);\r\n }\r\n this._physicsPlugin.initBody(this, motionType, transformNode.absolutePosition, transformNode.absoluteRotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n\r\n this._nodeDisposeObserver = transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Returns the string \"PhysicsBody\".\r\n * @returns \"PhysicsBody\"\r\n */\r\n public getClassName() {\r\n return \"PhysicsBody\";\r\n }\r\n\r\n /**\r\n * Clone the PhysicsBody to a new body and assign it to the transformNode parameter\r\n * @param transformNode transformNode that will be used for the cloned PhysicsBody\r\n * @returns the newly cloned PhysicsBody\r\n */\r\n public clone(transformNode: TransformNode): PhysicsBody {\r\n const clonedBody = new PhysicsBody(transformNode, this.getMotionType(), this.startAsleep, this.transformNode.getScene());\r\n clonedBody.shape = this.shape;\r\n clonedBody.setMassProperties(this.getMassProperties());\r\n clonedBody.setLinearDamping(this.getLinearDamping());\r\n clonedBody.setAngularDamping(this.getAngularDamping());\r\n return clonedBody;\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * This returns the number of internal instances of the physics body\r\n */\r\n public get numInstances(): number {\r\n return this._pluginDataInstances.length;\r\n }\r\n\r\n /**\r\n * Get the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public get motionType(): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public set shape(shape: Nullable<PhysicsShape>) {\r\n this._shape = shape;\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public get shape(): Nullable<PhysicsShape> {\r\n return this._shape;\r\n }\r\n\r\n /**\r\n * Returns the bounding box of the physics body.\r\n * @returns The bounding box of the physics body.\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBodyBoundingBox(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the event mask for.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number, instanceIndex?: number) {\r\n this._physicsPlugin.setEventMask(this, eventMask, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the event mask for.\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(instanceIndex?: number): number {\r\n return this._physicsPlugin.getEventMask(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param motionType - The motion type to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the motion type for. If body is instanced but instanceIndex is undefined, the motion type will be set for all instances.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = instanceIndex === undefined && motionType == PhysicsMotionType.STATIC;\r\n this._physicsPlugin.setMotionType(this, motionType, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the motion type for.\r\n * @returns The motion type of the physics body.\r\n */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the prestep type of the body\r\n * @param prestepType prestep type provided by PhysicsPrestepType\r\n */\r\n public setPrestepType(prestepType: PhysicsPrestepType): void {\r\n this._prestepType = prestepType;\r\n }\r\n\r\n /**\r\n * Get the current prestep type of the body\r\n * @returns the type of prestep associated with the body and its instance index\r\n */\r\n public getPrestepType(): PhysicsPrestepType {\r\n return this._prestepType;\r\n }\r\n\r\n /**\r\n * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.\r\n * This method is useful for computing the initial mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass; these values are important for accurately simulating the physics of the\r\n * object in the physics engine, and computing values based on the shape will provide you with reasonable\r\n * initial values, which you can then customize.\r\n * @param instanceIndex - The index of the instance to compute the mass properties for.\r\n * @returns The mass properties of the object.\r\n */\r\n public computeMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.computeMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n * @param instanceIndex - The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void {\r\n this._physicsPlugin.setMassProperties(this, massProps, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the mass properties for.\r\n * @returns The mass properties of the object.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.getMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear damping for.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setLinearDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear damping for.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getLinearDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular damping for.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setAngularDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular damping for.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getAngularDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear velocity for.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocityToRef(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getLinearVelocityToRef(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n * @returns The linear velocity of the physics body.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getLinearVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular velocity for.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getAngularVelocityToRef(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n * @returns The angular velocity of the physics body.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getAngularVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Add torque to a physics body\r\n * @param angularImpulse The angular impulse vector.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n */\r\n public applyAngularImpulse(angularImpulse: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyAngularImpulse(this, angularImpulse, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a torque to the physics body.\r\n *\r\n * @param torque The torque vector.\r\n * @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.\r\n *\r\n * This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,\r\n * angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyTorque(torque: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyTorque(this, torque, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n * @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyForce(this, force, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): object {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for when a collision starts or continues for this PhysicsBody\r\n * @param instanceIndex - optionally, the index of the instance in the body\r\n * @returns Observable\r\n */\r\n public getCollisionObservable(instanceIndex?: number): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified when the body has finished colliding with another body\r\n * @param instanceIndex - optionally, the index of the instance in the body\r\n * @returns Observable\r\n */\r\n public getCollisionEndedObservable(instanceIndex?: number): Observable<IBasePhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionEndedObservable(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Enable or disable collision callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n this._collisionCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Enable or disable collision ended callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision ended will rise a collision event and notifies the observable\r\n */\r\n public setCollisionEndedCallbackEnabled(enabled: boolean): void {\r\n this._collisionEndedCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionEndedCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorld(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n return this.getObjectCenterWorldToRef(ref, instanceIndex);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param ref - The vector3 to store the result in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3 {\r\n if (this._pluginDataInstances?.length > 0) {\r\n const index = instanceIndex || 0;\r\n const matrixData = (this.transformNode as Mesh)._thinInstanceDataStorage.matrixData;\r\n if (matrixData) {\r\n ref.set(matrixData[index * 16 + 12], matrixData[index * 16 + 13], matrixData[index * 16 + 14]);\r\n }\r\n } else {\r\n ref.copyFrom(this.transformNode.position);\r\n }\r\n return ref;\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n * @param childInstanceIndex - If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint, instanceIndex, childInstanceIndex);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * Executes a callback on the body or all of the instances of a body\r\n * @param callback the callback to execute\r\n */\r\n public iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void) {\r\n if (this._pluginDataInstances?.length > 0) {\r\n for (let i = 0; i < this._pluginDataInstances.length; i++) {\r\n callback(this, i);\r\n }\r\n } else {\r\n callback(this, undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the gravity factor of the physics body\r\n * @param factor the gravity factor to set\r\n * @param instanceIndex the instance of the body to set, if undefined all instances will be set\r\n */\r\n public setGravityFactor(factor: number, instanceIndex?: number) {\r\n this._physicsPlugin.setGravityFactor(this, factor, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the gravity factor of the physics body\r\n * @param instanceIndex the instance of the body to get, if undefined the value of first instance will be returned\r\n * @returns the gravity factor\r\n */\r\n public getGravityFactor(instanceIndex?: number): number {\r\n return this._physicsPlugin.getGravityFactor(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target\r\n * @param position The target position\r\n * @param rotation The target rotation\r\n * @param instanceIndex The index of the instance in an instanced body\r\n */\r\n public setTargetTransform(position: Vector3, rotation: Quaternion, instanceIndex?: number) {\r\n this._physicsPlugin.setTargetTransform(this, position, rotation, instanceIndex);\r\n }\r\n\r\n /**\r\n * Returns if the body has been disposed.\r\n * @returns true if disposed, false otherwise.\r\n */\r\n public get isDisposed() {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n // Disable collisions CB so it doesn't fire when the body is disposed\r\n if (this._collisionCBEnabled) {\r\n this.setCollisionCallbackEnabled(false);\r\n }\r\n if (this._collisionEndedCBEnabled) {\r\n this.setCollisionEndedCallbackEnabled(false);\r\n }\r\n if (this._nodeDisposeObserver) {\r\n this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this.transformNode.physicsBody = null;\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n this._isDisposed = true;\r\n this.shape = null;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAAA,O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AAI,CAAC,cAAc,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,aAAa,CAAC,WAAW,GAAG,IAAI,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;CACJ","sourcesContent":["import {\r\n type IBasePhysicsCollisionEvent,\r\n type IPhysicsCollisionEvent,\r\n type IPhysicsEnginePluginV2,\r\n type PhysicsMassProperties,\r\n PhysicsMotionType,\r\n PhysicsPrestepType,\r\n} from \"./IPhysicsEnginePlugin\";\r\nimport { type PhysicsShape } from \"./physicsShape\";\r\nimport { Vector3, Quaternion, TmpVectors } from \"../../Maths/math.vector\";\r\nimport { type Scene } from \"../../scene\";\r\nimport { type PhysicsEngine } from \"./physicsEngine\";\r\nimport { type Nullable } from \"../../types\";\r\nimport { type PhysicsConstraint } from \"./physicsConstraint\";\r\nimport { type Bone } from \"../../Bones/bone\";\r\nimport { Space } from \"../../Maths/math.axis\";\r\nimport { type Observable, type Observer } from \"../../Misc/observable\";\r\nimport { type Node } from \"../../node\";\r\nimport { type Mesh } from \"../../Meshes/mesh\";\r\nimport { type AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { type TransformNode } from \"../../Meshes/transformNode\";\r\nimport { type BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * PhysicsBody is useful for creating a physics body that can be used in a physics engine. It allows\r\n * the user to set the mass and velocity of the body, which can then be used to calculate the\r\n * motion of the body in the physics engine.\r\n */\r\nexport class PhysicsBody {\r\n /**\r\n * V2 Physics plugin private data for single Transform\r\n */\r\n public _pluginData: any = undefined;\r\n /**\r\n * V2 Physics plugin private data for instances\r\n */\r\n public _pluginDataInstances: Array<any> = [];\r\n /**\r\n * The V2 plugin used to create and manage this Physics Body\r\n */\r\n private _physicsPlugin: IPhysicsEnginePluginV2;\r\n /**\r\n * The engine used to create and manage this Physics Body\r\n */\r\n private _physicsEngine: PhysicsEngine;\r\n /**\r\n * If the collision callback is enabled\r\n */\r\n private _collisionCBEnabled: boolean = false;\r\n /**\r\n * If the collision ended callback is enabled\r\n */\r\n private _collisionEndedCBEnabled: boolean = false;\r\n /**\r\n * The transform node associated with this Physics Body\r\n */\r\n transformNode: TransformNode;\r\n\r\n /**\r\n * Disable pre-step that consists in updating Physics Body from Transform Node Translation/Orientation.\r\n * True by default for maximum performance.\r\n */\r\n public get disablePreStep(): boolean {\r\n return this._prestepType == PhysicsPrestepType.DISABLED;\r\n }\r\n\r\n public set disablePreStep(value: boolean) {\r\n this._prestepType = value ? PhysicsPrestepType.DISABLED : PhysicsPrestepType.TELEPORT;\r\n }\r\n\r\n /**\r\n * Disable sync from physics to transformNode. This value is set to true at body creation or at motionType setting when the body is not dynamic.\r\n */\r\n disableSync: boolean = false;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n public startAsleep: boolean;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n private _isDisposed = false;\r\n\r\n private _shape: Nullable<PhysicsShape> = null;\r\n\r\n private _prestepType: PhysicsPrestepType = PhysicsPrestepType.DISABLED;\r\n /**\r\n * Constructs a new physics body for the given node.\r\n * @param transformNode - The Transform Node to construct the physics body for. For better performance, it is advised that this node does not have a parent.\r\n * @param motionType - The motion type of the physics body. The options are:\r\n * - PhysicsMotionType.STATIC - Static bodies are not moving and unaffected by forces or collisions. They are good for level boundaries or terrain.\r\n * - PhysicsMotionType.DYNAMIC - Dynamic bodies are fully simulated. They can move and collide with other objects.\r\n * - PhysicsMotionType.ANIMATED - They behave like dynamic bodies, but they won't be affected by other bodies, but still push other bodies out of the way.\r\n * @param startsAsleep - Whether the physics body should start in a sleeping state (not a guarantee). Defaults to false.\r\n * @param scene - The scene containing the physics engine.\r\n *\r\n * This code is useful for creating a physics body for a given Transform Node in a scene.\r\n * It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.\r\n * It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.\r\n */\r\n constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene) {\r\n if (!scene) {\r\n return;\r\n }\r\n const physicsEngine = scene.getPhysicsEngine() as PhysicsEngine;\r\n if (!physicsEngine) {\r\n throw new Error(\"No Physics Engine available.\");\r\n }\r\n this._physicsEngine = physicsEngine;\r\n if (physicsEngine.getPluginVersion() != 2) {\r\n throw new Error(\"Plugin version is incorrect. Expected version 2.\");\r\n }\r\n const physicsPlugin = physicsEngine.getPhysicsPlugin();\r\n if (!physicsPlugin) {\r\n throw new Error(\"No Physics Plugin available.\");\r\n }\r\n\r\n this._physicsPlugin = physicsPlugin;\r\n if (!transformNode.rotationQuaternion) {\r\n transformNode.rotationQuaternion = Quaternion.FromEulerAngles(transformNode.rotation.x, transformNode.rotation.y, transformNode.rotation.z);\r\n }\r\n\r\n this.startAsleep = startsAsleep;\r\n\r\n // only dynamic and animated body needs sync from physics to transformNode\r\n this.disableSync = motionType == PhysicsMotionType.STATIC;\r\n\r\n // instances?\r\n const m = transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.initBodyInstances(this, motionType, m);\r\n } else {\r\n // single instance\r\n if (transformNode.parent) {\r\n // Force computation of world matrix so that the parent transforms are correctly reflected in absolutePosition/absoluteRotationQuaternion.\r\n transformNode.computeWorldMatrix(true);\r\n }\r\n this._physicsPlugin.initBody(this, motionType, transformNode.absolutePosition, transformNode.absoluteRotationQuaternion);\r\n }\r\n this.transformNode = transformNode;\r\n transformNode.physicsBody = this;\r\n physicsEngine.addBody(this);\r\n\r\n this._nodeDisposeObserver = transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n /**\r\n * Returns the string \"PhysicsBody\".\r\n * @returns \"PhysicsBody\"\r\n */\r\n public getClassName() {\r\n return \"PhysicsBody\";\r\n }\r\n\r\n /**\r\n * Clone the PhysicsBody to a new body and assign it to the transformNode parameter\r\n * @param transformNode transformNode that will be used for the cloned PhysicsBody\r\n * @returns the newly cloned PhysicsBody\r\n */\r\n public clone(transformNode: TransformNode): PhysicsBody {\r\n const clonedBody = new PhysicsBody(transformNode, this.getMotionType(), this.startAsleep, this.transformNode.getScene());\r\n clonedBody.shape = this.shape;\r\n clonedBody.setMassProperties(this.getMassProperties());\r\n clonedBody.setLinearDamping(this.getLinearDamping());\r\n clonedBody.setAngularDamping(this.getAngularDamping());\r\n return clonedBody;\r\n }\r\n\r\n /**\r\n * If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.\r\n */\r\n public updateBodyInstances() {\r\n const m = this.transformNode as Mesh;\r\n if (m.hasThinInstances) {\r\n this._physicsPlugin.updateBodyInstances(this, m);\r\n }\r\n }\r\n\r\n /**\r\n * This returns the number of internal instances of the physics body\r\n */\r\n public get numInstances(): number {\r\n return this._pluginDataInstances.length;\r\n }\r\n\r\n /**\r\n * Get the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n */\r\n public get motionType(): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this);\r\n }\r\n\r\n /**\r\n * Sets the shape of the physics body.\r\n * @param shape - The shape of the physics body.\r\n *\r\n * This method is useful for setting the shape of the physics body, which is necessary for the physics engine to accurately simulate the body's behavior.\r\n * The shape is used to calculate the body's mass, inertia, and other properties.\r\n */\r\n public set shape(shape: Nullable<PhysicsShape>) {\r\n this._shape = shape;\r\n if (shape) {\r\n this._physicsPlugin.setShape(this, shape);\r\n }\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public get shape(): Nullable<PhysicsShape> {\r\n return this._shape;\r\n }\r\n\r\n /**\r\n * Returns the bounding box of the physics body.\r\n * @returns The bounding box of the physics body.\r\n */\r\n public getBoundingBox(): BoundingBox {\r\n return this._physicsPlugin.getBodyBoundingBox(this);\r\n }\r\n\r\n /**\r\n * Sets the event mask for the physics engine.\r\n *\r\n * @param eventMask - A bitmask that determines which events will be sent to the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the event mask for.\r\n *\r\n * This method is useful for setting the event mask for the physics engine, which determines which events\r\n * will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.\r\n */\r\n public setEventMask(eventMask: number, instanceIndex?: number) {\r\n this._physicsPlugin.setEventMask(this, eventMask, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the event mask of the physics engine.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the event mask for.\r\n * @returns The event mask of the physics engine.\r\n *\r\n * This method is useful for getting the event mask of the physics engine,\r\n * which is used to determine which events the engine will respond to.\r\n * This is important for ensuring that the engine is responding to the correct events and not\r\n * wasting resources on unnecessary events.\r\n */\r\n public getEventMask(instanceIndex?: number): number {\r\n return this._physicsPlugin.getEventMask(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param motionType - The motion type to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the motion type for. If body is instanced but instanceIndex is undefined, the motion type will be set for all instances.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = instanceIndex === undefined && motionType == PhysicsMotionType.STATIC;\r\n this._physicsPlugin.setMotionType(this, motionType, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the motion type for.\r\n * @returns The motion type of the physics body.\r\n */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the prestep type of the body\r\n * @param prestepType prestep type provided by PhysicsPrestepType\r\n */\r\n public setPrestepType(prestepType: PhysicsPrestepType): void {\r\n this._prestepType = prestepType;\r\n }\r\n\r\n /**\r\n * Get the current prestep type of the body\r\n * @returns the type of prestep associated with the body and its instance index\r\n */\r\n public getPrestepType(): PhysicsPrestepType {\r\n return this._prestepType;\r\n }\r\n\r\n /**\r\n * Computes the mass properties of the physics object, based on the set of physics shapes this body uses.\r\n * This method is useful for computing the initial mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass; these values are important for accurately simulating the physics of the\r\n * object in the physics engine, and computing values based on the shape will provide you with reasonable\r\n * initial values, which you can then customize.\r\n * @param instanceIndex - The index of the instance to compute the mass properties for.\r\n * @returns The mass properties of the object.\r\n */\r\n public computeMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.computeMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the mass properties of the physics object.\r\n *\r\n * @param massProps - The mass properties to set.\r\n * @param instanceIndex - The index of the instance to set the mass properties for. If not defined, the mass properties will be set for all instances.\r\n *\r\n * This method is useful for setting the mass properties of a physics object, such as its mass,\r\n * inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.\r\n */\r\n public setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void {\r\n this._physicsPlugin.setMassProperties(this, massProps, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the mass properties of the object.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the mass properties for.\r\n * @returns The mass properties of the object.\r\n *\r\n * This method is useful for physics simulations, as it allows the user to\r\n * retrieve the mass properties of the object, such as its mass, center of mass,\r\n * and moment of inertia. This information is necessary for accurate physics\r\n * simulations.\r\n */\r\n public getMassProperties(instanceIndex?: number): PhysicsMassProperties {\r\n return this._physicsPlugin.getMassProperties(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear damping of the physics body.\r\n *\r\n * @param damping - The linear damping value.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear damping for.\r\n *\r\n * This method is useful for controlling the linear damping of the physics body,\r\n * which is the rate at which the body's velocity decreases over time. This is useful for simulating\r\n * the effects of air resistance or other forms of friction.\r\n */\r\n public setLinearDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setLinearDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear damping for.\r\n * @returns The linear damping of the physics body.\r\n *\r\n * This method is useful for retrieving the linear damping of the physics body, which is the amount of\r\n * resistance the body has to linear motion. This is useful for simulating realistic physics behavior\r\n * in a game.\r\n */\r\n public getLinearDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getLinearDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the angular damping of the physics body.\r\n * @param damping The angular damping of the body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular damping for.\r\n *\r\n * This method is useful for controlling the angular velocity of a physics body.\r\n * By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.\r\n * This can be used to create realistic physical behavior in a physics engine.\r\n */\r\n public setAngularDamping(damping: number, instanceIndex?: number) {\r\n this._physicsPlugin.setAngularDamping(this, damping, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular damping of the physics body.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular damping for.\r\n *\r\n * @returns The angular damping of the physics body.\r\n *\r\n * This method is useful for getting the angular damping of the physics body,\r\n * which is the rate of reduction of the angular velocity over time.\r\n * This is important for simulating realistic physics behavior in a game.\r\n */\r\n public getAngularDamping(instanceIndex?: number): number {\r\n return this._physicsPlugin.getAngularDamping(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Sets the linear velocity of the physics object.\r\n * @param linVel - The linear velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the linear velocity for.\r\n *\r\n * This method is useful for setting the linear velocity of a physics object,\r\n * which is necessary for simulating realistic physics in a game engine.\r\n * By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.\r\n * This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.\r\n */\r\n public setLinearVelocity(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setLinearVelocity(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body and stores it in the given vector3.\r\n * @param linVel - The vector3 to store the linear velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocityToRef(linVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getLinearVelocityToRef(this, linVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the linear velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the linear velocity for.\r\n * @returns The linear velocity of the physics body.\r\n *\r\n * This method is useful for getting the linear velocity of a physics body in a physics engine.\r\n * This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.\r\n */\r\n public getLinearVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getLinearVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Sets the angular velocity of the physics object.\r\n * @param angVel - The angular velocity to set.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to set the angular velocity for.\r\n *\r\n * This method is useful for setting the angular velocity of a physics object, which is necessary for\r\n * simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,\r\n * which is important for simulating realistic motion.\r\n */\r\n public setAngularVelocity(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.setAngularVelocity(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body and stores it in the given vector3.\r\n * @param angVel - The vector3 to store the angular velocity in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.getAngularVelocityToRef(this, angVel, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the angular velocity of the physics body as a new vector3.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the angular velocity for.\r\n * @returns The angular velocity of the physics body.\r\n *\r\n * This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's\r\n * rotational speed. This information can be used to create realistic physics simulations.\r\n */\r\n public getAngularVelocity(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n this.getAngularVelocityToRef(ref, instanceIndex);\r\n return ref;\r\n }\r\n\r\n /**\r\n * Applies an impulse to the physics object.\r\n *\r\n * @param impulse The impulse vector.\r\n * @param location The location of the impulse.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n *\r\n * This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyImpulse(this, impulse, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Add torque to a physics body\r\n * @param angularImpulse The angular impulse vector.\r\n * @param instanceIndex For a instanced body, the instance to where the impulse should be applied. If not specified, the impulse is applied to all instances.\r\n */\r\n public applyAngularImpulse(angularImpulse: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyAngularImpulse(this, angularImpulse, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a torque to the physics body.\r\n *\r\n * @param torque The torque vector.\r\n * @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.\r\n *\r\n * This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,\r\n * angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyTorque(torque: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyTorque(this, torque, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n * @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyForce(this, force, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): object {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for when a collision starts or continues for this PhysicsBody\r\n * @param instanceIndex - optionally, the index of the instance in the body\r\n * @returns Observable\r\n */\r\n public getCollisionObservable(instanceIndex?: number): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified when the body has finished colliding with another body\r\n * @param instanceIndex - optionally, the index of the instance in the body\r\n * @returns Observable\r\n */\r\n public getCollisionEndedObservable(instanceIndex?: number): Observable<IBasePhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionEndedObservable(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Enable or disable collision callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable\r\n */\r\n public setCollisionCallbackEnabled(enabled: boolean): void {\r\n this._collisionCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Enable or disable collision ended callback for this PhysicsBody.\r\n * @param enabled true if PhysicsBody's collision ended will rise a collision event and notifies the observable\r\n */\r\n public setCollisionEndedCallbackEnabled(enabled: boolean): void {\r\n this._collisionEndedCBEnabled = enabled;\r\n this._physicsPlugin.setCollisionEndedCallbackEnabled(this, enabled);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorld(instanceIndex?: number): Vector3 {\r\n const ref = new Vector3();\r\n return this.getObjectCenterWorldToRef(ref, instanceIndex);\r\n }\r\n\r\n /**\r\n * Get the center of the object in world space.\r\n * @param ref - The vector3 to store the result in.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to get the center for.\r\n * @returns geometric center of the associated mesh\r\n */\r\n public getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3 {\r\n if (this._pluginDataInstances?.length > 0) {\r\n const index = instanceIndex || 0;\r\n const matrixData = (this.transformNode as Mesh)._thinInstanceDataStorage.matrixData;\r\n if (matrixData) {\r\n ref.set(matrixData[index * 16 + 12], matrixData[index * 16 + 13], matrixData[index * 16 + 14]);\r\n }\r\n } else {\r\n ref.copyFrom(this.transformNode.position);\r\n }\r\n return ref;\r\n }\r\n\r\n /**\r\n * Adds a constraint to the physics engine.\r\n *\r\n * @param childBody - The body to which the constraint will be applied.\r\n * @param constraint - The constraint to be applied.\r\n * @param instanceIndex - If this body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n * @param childInstanceIndex - If the child body is instanced, the index of the instance to which the constraint will be applied. If not specified, no constraint will be applied.\r\n *\r\n */\r\n public addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void {\r\n this._physicsPlugin.addConstraint(this, childBody, constraint, instanceIndex, childInstanceIndex);\r\n }\r\n\r\n /**\r\n * Sync with a bone\r\n * @param bone The bone that the impostor will be synced to.\r\n * @param boneMesh The mesh that the bone is influencing.\r\n * @param jointPivot The pivot of the joint / bone in local space.\r\n * @param distToJoint Optional distance from the impostor to the joint.\r\n * @param adjustRotation Optional quaternion for adjusting the local rotation of the bone.\r\n * @param boneAxis Optional vector3 axis the bone is aligned with\r\n */\r\n public syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3) {\r\n const mesh = this.transformNode;\r\n\r\n if (mesh.rotationQuaternion) {\r\n if (adjustRotation) {\r\n const tempQuat = TmpVectors.Quaternion[0];\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, tempQuat);\r\n tempQuat.multiplyToRef(adjustRotation, mesh.rotationQuaternion);\r\n } else {\r\n bone.getRotationQuaternionToRef(Space.WORLD, boneMesh, mesh.rotationQuaternion);\r\n }\r\n }\r\n\r\n const pos = TmpVectors.Vector3[0];\r\n const boneDir = TmpVectors.Vector3[1];\r\n\r\n if (!boneAxis) {\r\n boneAxis = TmpVectors.Vector3[2];\r\n boneAxis.x = 0;\r\n boneAxis.y = 1;\r\n boneAxis.z = 0;\r\n }\r\n\r\n bone.getDirectionToRef(boneAxis, boneMesh, boneDir);\r\n bone.getAbsolutePositionToRef(boneMesh, pos);\r\n\r\n if ((distToJoint === undefined || distToJoint === null) && jointPivot) {\r\n distToJoint = jointPivot.length();\r\n }\r\n\r\n if (distToJoint !== undefined && distToJoint !== null) {\r\n pos.x += boneDir.x * distToJoint;\r\n pos.y += boneDir.y * distToJoint;\r\n pos.z += boneDir.z * distToJoint;\r\n }\r\n\r\n mesh.setAbsolutePosition(pos);\r\n }\r\n\r\n /**\r\n * Executes a callback on the body or all of the instances of a body\r\n * @param callback the callback to execute\r\n */\r\n public iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void) {\r\n if (this._pluginDataInstances?.length > 0) {\r\n for (let i = 0; i < this._pluginDataInstances.length; i++) {\r\n callback(this, i);\r\n }\r\n } else {\r\n callback(this, undefined);\r\n }\r\n }\r\n\r\n /**\r\n * Sets the gravity factor of the physics body\r\n * @param factor the gravity factor to set\r\n * @param instanceIndex the instance of the body to set, if undefined all instances will be set\r\n */\r\n public setGravityFactor(factor: number, instanceIndex?: number) {\r\n this._physicsPlugin.setGravityFactor(this, factor, instanceIndex);\r\n }\r\n\r\n /**\r\n * Gets the gravity factor of the physics body\r\n * @param instanceIndex the instance of the body to get, if undefined the value of first instance will be returned\r\n * @returns the gravity factor\r\n */\r\n public getGravityFactor(instanceIndex?: number): number {\r\n return this._physicsPlugin.getGravityFactor(this, instanceIndex);\r\n }\r\n\r\n /**\r\n * Set the target transformation (position and rotation) of the body, such that the body will set its velocity to reach that target\r\n * @param position The target position\r\n * @param rotation The target rotation\r\n * @param instanceIndex The index of the instance in an instanced body\r\n */\r\n public setTargetTransform(position: Vector3, rotation: Quaternion, instanceIndex?: number) {\r\n this._physicsPlugin.setTargetTransform(this, position, rotation, instanceIndex);\r\n }\r\n\r\n /**\r\n * Returns if the body has been disposed.\r\n * @returns true if disposed, false otherwise.\r\n */\r\n public get isDisposed() {\r\n return this._isDisposed;\r\n }\r\n\r\n /**\r\n * Disposes the body from the physics engine.\r\n *\r\n * This method is useful for cleaning up the physics engine when a body is no longer needed. Disposing the body will free up resources and prevent memory leaks.\r\n */\r\n public dispose() {\r\n if (this._isDisposed) {\r\n return;\r\n }\r\n // Disable collisions CB so it doesn't fire when the body is disposed\r\n if (this._collisionCBEnabled) {\r\n this.setCollisionCallbackEnabled(false);\r\n }\r\n if (this._collisionEndedCBEnabled) {\r\n this.setCollisionEndedCallbackEnabled(false);\r\n }\r\n if (this._nodeDisposeObserver) {\r\n this.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this._physicsEngine.removeBody(this);\r\n this._physicsPlugin.removeBody(this);\r\n this._physicsPlugin.disposeBody(this);\r\n this.transformNode.physicsBody = null;\r\n this._pluginData = null;\r\n this._pluginDataInstances.length = 0;\r\n this._isDisposed = true;\r\n this.shape = null;\r\n }\r\n}\r\n"]}
|
|
@@ -210,16 +210,18 @@ export class WebXRSessionManager {
|
|
|
210
210
|
// handle when the session is ended (By calling session.end or device ends its own session eg. pressing home button on phone)
|
|
211
211
|
this.session.addEventListener("end", () => {
|
|
212
212
|
this.inXRSession = false;
|
|
213
|
+
// Cache the value of engine in case it is disposed during onXRSessionEnded callbacks
|
|
214
|
+
const engine = this._engine;
|
|
213
215
|
// Notify frame observers
|
|
214
216
|
this.onXRSessionEnded.notifyObservers(null);
|
|
215
|
-
if (
|
|
217
|
+
if (engine && !engine.isDisposed) {
|
|
216
218
|
// make sure dimensions object is restored
|
|
217
|
-
|
|
219
|
+
engine.framebufferDimensionsObject = null;
|
|
218
220
|
// Restore frame buffer to avoid clear on xr framebuffer after session end
|
|
219
|
-
|
|
221
|
+
engine.restoreDefaultFramebuffer();
|
|
220
222
|
// Need to restart render loop as after the session is ended the last request for new frame will never call callback
|
|
221
|
-
|
|
222
|
-
|
|
223
|
+
engine.customAnimationFrameRequester = null;
|
|
224
|
+
engine._renderLoop();
|
|
223
225
|
}
|
|
224
226
|
// Dispose render target textures.
|
|
225
227
|
// Only dispose on native because we can't destroy opaque textures on browser.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webXRSessionManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRSessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAiB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAK/D,OAAO,EAAE,wBAAwB,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAKvG,OAAO,EAAE,oBAAoB,EAAE,oBAAoB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IAC1D,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc,CAAC,KAAuB;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,IAAI,CAAC,iBAAiB,CAAC,cAAc,GAAG,GAAG,CAAC;QAChD,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;IACjD,CAAC;CACJ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport { type Observer, Observable } from \"../Misc/observable\";\r\nimport { type Nullable } from \"../types\";\r\nimport { type IDisposable, type Scene } from \"../scene\";\r\nimport { type RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { type WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRManagedOutputCanvas, WebXRManagedOutputCanvasOptions } from \"./webXRManagedOutputCanvas\";\r\nimport { type Engine } from \"../Engines/engine\";\r\nimport { type IWebXRRenderTargetTextureProvider, type WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\nimport { type Viewport } from \"../Maths/math.viewport\";\r\nimport { type WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { NativeXRLayerWrapper, NativeXRRenderTarget } from \"./native/nativeXRRenderTarget\";\r\nimport { WebXRWebGLLayerWrapper } from \"./webXRWebGLLayer\";\r\nimport { type AbstractEngine } from \"../Engines/abstractEngine\";\r\n\r\n/**\r\n * Manages an XRSession to work with Babylon's engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRSessionManagers\r\n */\r\nexport class WebXRSessionManager implements IDisposable, IWebXRRenderTargetTextureProvider {\r\n private _engine: Nullable<Engine>;\r\n private _referenceSpace: XRReferenceSpace;\r\n private _baseLayerWrapper: Nullable<WebXRLayerWrapper>;\r\n private _baseLayerRTTProvider: Nullable<WebXRLayerRenderTargetTextureProvider>;\r\n private _xrNavigator: any;\r\n private _sessionMode: XRSessionMode;\r\n private _onEngineDisposedObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n /**\r\n * The base reference space from which the session started. good if you want to reset your\r\n * reference space\r\n */\r\n public baseReferenceSpace: XRReferenceSpace;\r\n /**\r\n * Current XR frame\r\n */\r\n public currentFrame: Nullable<XRFrame>;\r\n /** WebXR timestamp updated every frame */\r\n public currentTimestamp: number = -1;\r\n /**\r\n * Used just in case of a failure to initialize an immersive session.\r\n * The viewer reference space is compensated using this height, creating a kind of \"viewer-floor\" reference space\r\n */\r\n public defaultHeightCompensation = 1.7;\r\n /**\r\n * Fires every time a new xrFrame arrives which can be used to update the camera\r\n */\r\n public onXRFrameObservable: Observable<XRFrame> = new Observable<XRFrame>();\r\n /**\r\n * Fires when the reference space changed\r\n */\r\n public onXRReferenceSpaceChanged: Observable<XRReferenceSpace> = new Observable();\r\n /**\r\n * Fires when the xr session is ended either by the device or manually done\r\n */\r\n public onXRSessionEnded: Observable<any> = new Observable<any>();\r\n /**\r\n * Fires when the xr session is initialized: right after requestSession was called and returned with a successful result\r\n */\r\n public onXRSessionInit: Observable<XRSession> = new Observable<XRSession>();\r\n\r\n /**\r\n * Fires when the xr reference space has been initialized\r\n */\r\n public onXRReferenceSpaceInitialized: Observable<XRReferenceSpace> = new Observable<XRReferenceSpace>();\r\n\r\n /**\r\n * Fires when the session manager is rendering the first frame\r\n */\r\n public onXRReady: Observable<WebXRSessionManager> = new Observable<WebXRSessionManager>();\r\n /**\r\n * Underlying xr session\r\n */\r\n public session: XRSession;\r\n /**\r\n * The viewer (head position) reference space. This can be used to get the XR world coordinates\r\n * or get the offset the player is currently at.\r\n */\r\n public viewerReferenceSpace: XRReferenceSpace;\r\n /**\r\n * Are we currently in the XR loop?\r\n */\r\n public inXRFrameLoop: boolean = false;\r\n /**\r\n * Are we in an XR session?\r\n */\r\n public inXRSession: boolean = false;\r\n\r\n private _worldScalingFactor: number = 1;\r\n\r\n /**\r\n * Observable raised when the world scale has changed\r\n */\r\n public onWorldScaleFactorChangedObservable: Observable<{\r\n previousScaleFactor: number;\r\n newScaleFactor: number;\r\n }> = new Observable(undefined, true);\r\n\r\n /**\r\n * Scale factor to apply to all XR-related elements (camera, controllers)\r\n */\r\n public get worldScalingFactor(): number {\r\n return this._worldScalingFactor;\r\n }\r\n\r\n public set worldScalingFactor(value: number) {\r\n const oldValue = this._worldScalingFactor;\r\n this._worldScalingFactor = value;\r\n this.onWorldScaleFactorChangedObservable.notifyObservers({\r\n previousScaleFactor: oldValue,\r\n newScaleFactor: value,\r\n });\r\n }\r\n\r\n /**\r\n * Constructs a WebXRSessionManager, this must be initialized within a user action before usage\r\n * @param scene The scene which the session should be created for\r\n */\r\n constructor(\r\n /** The scene which the session should be created for */\r\n public scene: Scene\r\n ) {\r\n this._engine = scene.getEngine() as Engine;\r\n this._onEngineDisposedObserver = this._engine.onDisposeObservable.addOnce(() => {\r\n this._engine = null;\r\n });\r\n scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n\r\n this.onXRSessionEnded.add(() => {\r\n // Set the scene's pointer camera to null to stop the XR camera being used for picking.\r\n scene.cameraToUseForPointers = null;\r\n });\r\n }\r\n\r\n /**\r\n * The current reference space used in this session. This reference space can constantly change!\r\n * It is mainly used to offset the camera's position.\r\n */\r\n public get referenceSpace(): XRReferenceSpace {\r\n return this._referenceSpace;\r\n }\r\n\r\n /**\r\n * Set a new reference space and triggers the observable\r\n */\r\n public set referenceSpace(newReferenceSpace: XRReferenceSpace) {\r\n this._referenceSpace = newReferenceSpace;\r\n this.onXRReferenceSpaceChanged.notifyObservers(this._referenceSpace);\r\n }\r\n\r\n /**\r\n * The mode for the managed XR session\r\n */\r\n public get sessionMode(): XRSessionMode {\r\n return this._sessionMode;\r\n }\r\n\r\n /**\r\n * Disposes of the session manager\r\n * This should be called explicitly by the dev, if required.\r\n */\r\n public dispose() {\r\n // disposing without leaving XR? Exit XR first\r\n if (this.inXRSession) {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this.exitXRAsync();\r\n }\r\n this.onXRReady.clear();\r\n this.onXRFrameObservable.clear();\r\n this.onXRSessionEnded.clear();\r\n this.onXRReferenceSpaceChanged.clear();\r\n this.onXRReferenceSpaceInitialized.clear();\r\n this.onXRSessionInit.clear();\r\n this.onWorldScaleFactorChangedObservable.clear();\r\n this._engine?.onDisposeObservable.remove(this._onEngineDisposedObserver);\r\n this._engine = null;\r\n }\r\n\r\n /**\r\n * Stops the xrSession and restores the render loop\r\n * @returns Promise which resolves after it exits XR\r\n */\r\n public async exitXRAsync() {\r\n if (this.session && this.inXRSession) {\r\n this.inXRSession = false;\r\n try {\r\n return await this.session.end();\r\n } catch {\r\n Logger.Warn(\"Could not end XR session.\");\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n return this._baseLayerRTTProvider?.trySetViewportForView(viewport, view) || false;\r\n }\r\n\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture> {\r\n return this._baseLayerRTTProvider?.getRenderTargetTextureForEye(eye) || null;\r\n }\r\n\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n return this._baseLayerRTTProvider?.getRenderTargetTextureForView(view) || null;\r\n }\r\n\r\n /**\r\n * Creates a WebXRRenderTarget object for the XR session\r\n * @param options optional options to provide when creating a new render target\r\n * @returns a WebXR render target to which the session can render\r\n */\r\n public getWebXRRenderTarget(options?: WebXRManagedOutputCanvasOptions): WebXRRenderTarget {\r\n const engine = this.scene.getEngine();\r\n if (this._xrNavigator.xr.native) {\r\n return new NativeXRRenderTarget(this);\r\n } else {\r\n options = options || WebXRManagedOutputCanvasOptions.GetDefaults(engine);\r\n options.canvasElement = options.canvasElement || engine.getRenderingCanvas() || undefined;\r\n return new WebXRManagedOutputCanvas(this, options);\r\n }\r\n }\r\n\r\n /**\r\n * Initializes the manager\r\n * After initialization enterXR can be called to start an XR session\r\n * @returns Promise which resolves after it is initialized\r\n */\r\n public async initializeAsync(): Promise<void> {\r\n // Check if the browser supports webXR\r\n this._xrNavigator = navigator;\r\n if (!this._xrNavigator.xr) {\r\n throw new Error(\"WebXR not supported on this browser.\");\r\n }\r\n }\r\n\r\n /**\r\n * Initializes an xr session\r\n * @param xrSessionMode mode to initialize\r\n * @param xrSessionInit defines optional and required values to pass to the session builder\r\n * @returns a promise which will resolve once the session has been initialized\r\n */\r\n public async initializeSessionAsync(xrSessionMode: XRSessionMode = \"immersive-vr\", xrSessionInit: XRSessionInit = {}): Promise<XRSession> {\r\n const session = await this._xrNavigator.xr.requestSession(xrSessionMode, xrSessionInit);\r\n\r\n this.session = session;\r\n this._sessionMode = xrSessionMode;\r\n this.inXRSession = true;\r\n this.onXRSessionInit.notifyObservers(session);\r\n\r\n // handle when the session is ended (By calling session.end or device ends its own session eg. pressing home button on phone)\r\n this.session.addEventListener(\r\n \"end\",\r\n () => {\r\n this.inXRSession = false;\r\n\r\n // Notify frame observers\r\n this.onXRSessionEnded.notifyObservers(null);\r\n\r\n if (this._engine) {\r\n // make sure dimensions object is restored\r\n this._engine.framebufferDimensionsObject = null;\r\n\r\n // Restore frame buffer to avoid clear on xr framebuffer after session end\r\n this._engine.restoreDefaultFramebuffer();\r\n\r\n // Need to restart render loop as after the session is ended the last request for new frame will never call callback\r\n this._engine.customAnimationFrameRequester = null;\r\n this._engine._renderLoop();\r\n }\r\n\r\n // Dispose render target textures.\r\n // Only dispose on native because we can't destroy opaque textures on browser.\r\n if (this.isNative) {\r\n this._baseLayerRTTProvider?.dispose();\r\n }\r\n this._baseLayerRTTProvider = null;\r\n this._baseLayerWrapper = null;\r\n },\r\n { once: true }\r\n );\r\n\r\n return this.session;\r\n }\r\n\r\n /**\r\n * Checks if a session would be supported for the creation options specified\r\n * @param sessionMode session mode to check if supported eg. immersive-vr\r\n * @returns A Promise that resolves to true if supported and false if not\r\n */\r\n public async isSessionSupportedAsync(sessionMode: XRSessionMode): Promise<boolean> {\r\n return await WebXRSessionManager.IsSessionSupportedAsync(sessionMode);\r\n }\r\n\r\n /**\r\n * Resets the reference space to the one started the session\r\n */\r\n public resetReferenceSpace() {\r\n this.referenceSpace = this.baseReferenceSpace;\r\n }\r\n\r\n /**\r\n * Starts rendering to the xr layer\r\n */\r\n public runXRRenderLoop() {\r\n if (!this.inXRSession || !this._engine) {\r\n return;\r\n }\r\n\r\n // Tell the engine's render loop to be driven by the xr session's refresh rate and provide xr pose information\r\n this._engine.customAnimationFrameRequester = {\r\n requestAnimationFrame: (callback: FrameRequestCallback) => this.session.requestAnimationFrame(callback),\r\n renderFunction: (timestamp: number, xrFrame: Nullable<XRFrame>) => {\r\n if (!this.inXRSession || !this._engine) {\r\n return;\r\n }\r\n // Store the XR frame and timestamp in the session manager\r\n this.currentFrame = xrFrame;\r\n this.currentTimestamp = timestamp;\r\n if (xrFrame) {\r\n this.inXRFrameLoop = true;\r\n const framebufferDimensionsObject = this._baseLayerRTTProvider?.getFramebufferDimensions() || null;\r\n // equality can be tested as it should be the same object\r\n if (this._engine.framebufferDimensionsObject !== framebufferDimensionsObject) {\r\n this._engine.framebufferDimensionsObject = framebufferDimensionsObject;\r\n }\r\n this.onXRFrameObservable.notifyObservers(xrFrame);\r\n this._engine._renderLoop();\r\n this._engine.framebufferDimensionsObject = null;\r\n this.inXRFrameLoop = false;\r\n }\r\n },\r\n };\r\n\r\n this._engine.framebufferDimensionsObject = this._baseLayerRTTProvider?.getFramebufferDimensions() || null;\r\n this.onXRFrameObservable.addOnce(() => {\r\n this.onXRReady.notifyObservers(this);\r\n });\r\n\r\n // Stop window's animation frame and trigger sessions animation frame\r\n if (typeof window !== \"undefined\" && window.cancelAnimationFrame) {\r\n window.cancelAnimationFrame(this._engine._frameHandler);\r\n }\r\n this._engine._renderLoop();\r\n }\r\n\r\n /**\r\n * Sets the reference space on the xr session\r\n * @param referenceSpaceType space to set\r\n * @returns a promise that will resolve once the reference space has been set\r\n */\r\n public async setReferenceSpaceTypeAsync(referenceSpaceType: XRReferenceSpaceType = \"local-floor\"): Promise<XRReferenceSpace> {\r\n let referenceSpace: XRReferenceSpace;\r\n let viewerReferenceSpace: Nullable<XRReferenceSpace> = null;\r\n try {\r\n referenceSpace = await this.session.requestReferenceSpace(referenceSpaceType);\r\n } catch (rejectionReason) {\r\n Logger.Error(\"XR.requestReferenceSpace failed for the following reason: \");\r\n Logger.Error(rejectionReason);\r\n Logger.Log('Defaulting to universally-supported \"viewer\" reference space type.');\r\n\r\n try {\r\n viewerReferenceSpace = (await this.session.requestReferenceSpace(\"viewer\")) as XRReferenceSpace;\r\n const heightCompensation = new XRRigidTransform({ x: 0, y: -this.defaultHeightCompensation, z: 0 });\r\n referenceSpace = viewerReferenceSpace.getOffsetReferenceSpace(heightCompensation);\r\n } catch (rejectionReason) {\r\n Logger.Error(rejectionReason);\r\n // eslint-disable-next-line no-throw-literal\r\n throw 'XR initialization failed: required \"viewer\" reference space type not supported.';\r\n }\r\n }\r\n // create viewer reference space before setting the first reference space\r\n this.viewerReferenceSpace = viewerReferenceSpace ?? ((await this.session.requestReferenceSpace(\"viewer\")) as XRReferenceSpace);\r\n // initialize the base and offset (currently the same)\r\n this.referenceSpace = this.baseReferenceSpace = referenceSpace;\r\n this.onXRReferenceSpaceInitialized.notifyObservers(referenceSpace);\r\n return this.referenceSpace;\r\n }\r\n\r\n /**\r\n * Updates the render state of the session.\r\n * Note that this is deprecated in favor of WebXRSessionManager.updateRenderState().\r\n * @param state state to set\r\n * @returns a promise that resolves once the render state has been updated\r\n * @deprecated Use updateRenderState() instead.\r\n */\r\n public async updateRenderStateAsync(state: XRRenderState): Promise<void> {\r\n return await this.session.updateRenderState(state);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setBaseLayerWrapper(baseLayerWrapper: Nullable<WebXRLayerWrapper>): void {\r\n if (this.isNative) {\r\n this._baseLayerRTTProvider?.dispose();\r\n }\r\n this._baseLayerWrapper = baseLayerWrapper;\r\n this._baseLayerRTTProvider = this._baseLayerWrapper?.createRenderTargetTextureProvider(this) || null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getBaseLayerWrapper(): Nullable<WebXRLayerWrapper> {\r\n return this._baseLayerWrapper;\r\n }\r\n\r\n /**\r\n * Updates the render state of the session\r\n * @param state state to set\r\n */\r\n public updateRenderState(state: XRRenderStateInit): void {\r\n if (state.baseLayer) {\r\n this._setBaseLayerWrapper(this.isNative ? new NativeXRLayerWrapper(state.baseLayer) : new WebXRWebGLLayerWrapper(state.baseLayer));\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this.session.updateRenderState(state);\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves with a boolean indicating if the provided session mode is supported by this browser\r\n * @param sessionMode defines the session to test\r\n * @returns a promise with boolean as final value\r\n */\r\n public static async IsSessionSupportedAsync(sessionMode: XRSessionMode): Promise<boolean> {\r\n if (!(navigator as any).xr) {\r\n return false;\r\n }\r\n // When the specs are final, remove supportsSession!\r\n const functionToUse = (navigator as any).xr.isSessionSupported || (navigator as any).xr.supportsSession;\r\n if (!functionToUse) {\r\n return false;\r\n } else {\r\n try {\r\n const result = functionToUse.call((navigator as any).xr, sessionMode);\r\n const returnValue = typeof result === \"undefined\" ? true : result;\r\n return returnValue;\r\n } catch (e: any) {\r\n Logger.Warn(e);\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Returns true if Babylon.js is using the BabylonNative backend, otherwise false\r\n */\r\n public get isNative(): boolean {\r\n return this._xrNavigator.xr.native ?? false;\r\n }\r\n\r\n /**\r\n * The current frame rate as reported by the device\r\n */\r\n public get currentFrameRate(): number | undefined {\r\n return this.session?.frameRate;\r\n }\r\n\r\n /**\r\n * A list of supported frame rates (only available in-session!\r\n */\r\n public get supportedFrameRates(): Float32Array | undefined {\r\n return this.session?.supportedFrameRates;\r\n }\r\n\r\n /**\r\n * Set the framerate of the session.\r\n * @param rate the new framerate. This value needs to be in the supportedFrameRates array\r\n * @returns a promise that resolves once the framerate has been set\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public async updateTargetFrameRate(rate: number): Promise<void> {\r\n return await this.session.updateTargetFrameRate(rate);\r\n }\r\n\r\n /**\r\n * Run a callback in the xr render loop\r\n * @param callback the callback to call when in XR Frame\r\n * @param ignoreIfNotInSession if no session is currently running, run it first thing on the next session\r\n */\r\n public runInXRFrame(callback: () => void, ignoreIfNotInSession = true): void {\r\n if (this.inXRFrameLoop) {\r\n callback();\r\n } else if (this.inXRSession || !ignoreIfNotInSession) {\r\n this.onXRFrameObservable.addOnce(callback);\r\n }\r\n }\r\n\r\n /**\r\n * Check if fixed foveation is supported on this device\r\n */\r\n public get isFixedFoveationSupported(): boolean {\r\n return this._baseLayerWrapper?.isFixedFoveationSupported || false;\r\n }\r\n\r\n /**\r\n * Get the fixed foveation currently set, as specified by the webxr specs\r\n * If this returns null, then fixed foveation is not supported\r\n */\r\n public get fixedFoveation(): Nullable<number> {\r\n return this._baseLayerWrapper?.fixedFoveation || null;\r\n }\r\n\r\n /**\r\n * Set the fixed foveation to the specified value, as specified by the webxr specs\r\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\r\n */\r\n public set fixedFoveation(value: Nullable<number>) {\r\n const val = Math.max(0, Math.min(1, value || 0));\r\n if (this._baseLayerWrapper) {\r\n this._baseLayerWrapper.fixedFoveation = val;\r\n }\r\n }\r\n\r\n /**\r\n * Get the features enabled on the current session\r\n * This is only available in-session!\r\n * @see https://www.w3.org/TR/webxr/#dom-xrsession-enabledfeatures\r\n */\r\n public get enabledFeatures(): Nullable<string[]> {\r\n return this.session?.enabledFeatures ?? null;\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"webXRSessionManager.js","sourceRoot":"","sources":["../../../../dev/core/src/XR/webXRSessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAiB,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAK/D,OAAO,EAAE,wBAAwB,EAAE,+BAA+B,EAAE,MAAM,4BAA4B,CAAC;AAKvG,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAG3D;;;GAGG;AACH,MAAM,OAAO,mBAAmB;IA+E5B;;OAEG;IACH,IAAW,kBAAkB;QACzB,OAAO,IAAI,CAAC,mBAAmB,CAAC;IACpC,CAAC;IAED,IAAW,kBAAkB,CAAC,KAAa;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,mBAAmB,CAAC;QAC1C,IAAI,CAAC,mBAAmB,GAAG,KAAK,CAAC;QACjC,IAAI,CAAC,mCAAmC,CAAC,eAAe,CAAC;YACrD,mBAAmB,EAAE,QAAQ;YAC7B,cAAc,EAAE,KAAK;SACxB,CAAC,CAAC;IACP,CAAC;IAED;;;OAGG;IACH;IACI,wDAAwD;IACjD,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;QAnFvB,0CAA0C;QACnC,qBAAgB,GAAW,CAAC,CAAC,CAAC;QACrC;;;WAGG;QACI,8BAAyB,GAAG,GAAG,CAAC;QACv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gE;IACzD,KAAK,CAAC,qBAAqB,CAAC,IAAY;QAC3C,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,qBAAqB,CAAC,IAAI,CAAC,CAAC;IAC1D,CAAC;IAED;;;;OAIG;IACI,YAAY,CAAC,QAAoB,EAAE,oBAAoB,GAAG,IAAI;QACjE,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,QAAQ,EAAE,CAAC;QACf,CAAC;aAAM,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,oBAAoB,EAAE,CAAC;YACnD,IAAI,CAAC,mBAAmB,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC/C,CAAC;IACL,CAAC;IAED;;OAEG;IACH,IAAW,yBAAyB;QAChC,OAAO,IAAI,CAAC,iBAAiB,EAAE,yBAAyB,IAAI,KAAK,CAAC;IACtE,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc;QACrB,OAAO,IAAI,CAAC,iBAAiB,EAAE,cAAc,IAAI,IAAI,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,IAAW,cAAc,CAAC,KAAuB;QAC7C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzB,IAAI,CAAC,iBAAiB,CAAC,cAAc,GAAG,GAAG,CAAC;QAChD,CAAC;IACL,CAAC;IAED;;;;OAIG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,OAAO,EAAE,eAAe,IAAI,IAAI,CAAC;IACjD,CAAC;CACJ","sourcesContent":["import { Logger } from \"../Misc/logger\";\r\nimport { type Observer, Observable } from \"../Misc/observable\";\r\nimport { type Nullable } from \"../types\";\r\nimport { type IDisposable, type Scene } from \"../scene\";\r\nimport { type RenderTargetTexture } from \"../Materials/Textures/renderTargetTexture\";\r\nimport { type WebXRRenderTarget } from \"./webXRTypes\";\r\nimport { WebXRManagedOutputCanvas, WebXRManagedOutputCanvasOptions } from \"./webXRManagedOutputCanvas\";\r\nimport { type Engine } from \"../Engines/engine\";\r\nimport { type IWebXRRenderTargetTextureProvider, type WebXRLayerRenderTargetTextureProvider } from \"./webXRRenderTargetTextureProvider\";\r\nimport { type Viewport } from \"../Maths/math.viewport\";\r\nimport { type WebXRLayerWrapper } from \"./webXRLayerWrapper\";\r\nimport { NativeXRLayerWrapper, NativeXRRenderTarget } from \"./native/nativeXRRenderTarget\";\r\nimport { WebXRWebGLLayerWrapper } from \"./webXRWebGLLayer\";\r\nimport { type AbstractEngine } from \"../Engines/abstractEngine\";\r\n\r\n/**\r\n * Manages an XRSession to work with Babylon's engine\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/webXR/webXRSessionManagers\r\n */\r\nexport class WebXRSessionManager implements IDisposable, IWebXRRenderTargetTextureProvider {\r\n private _engine: Nullable<Engine>;\r\n private _referenceSpace: XRReferenceSpace;\r\n private _baseLayerWrapper: Nullable<WebXRLayerWrapper>;\r\n private _baseLayerRTTProvider: Nullable<WebXRLayerRenderTargetTextureProvider>;\r\n private _xrNavigator: any;\r\n private _sessionMode: XRSessionMode;\r\n private _onEngineDisposedObserver: Nullable<Observer<AbstractEngine>>;\r\n\r\n /**\r\n * The base reference space from which the session started. good if you want to reset your\r\n * reference space\r\n */\r\n public baseReferenceSpace: XRReferenceSpace;\r\n /**\r\n * Current XR frame\r\n */\r\n public currentFrame: Nullable<XRFrame>;\r\n /** WebXR timestamp updated every frame */\r\n public currentTimestamp: number = -1;\r\n /**\r\n * Used just in case of a failure to initialize an immersive session.\r\n * The viewer reference space is compensated using this height, creating a kind of \"viewer-floor\" reference space\r\n */\r\n public defaultHeightCompensation = 1.7;\r\n /**\r\n * Fires every time a new xrFrame arrives which can be used to update the camera\r\n */\r\n public onXRFrameObservable: Observable<XRFrame> = new Observable<XRFrame>();\r\n /**\r\n * Fires when the reference space changed\r\n */\r\n public onXRReferenceSpaceChanged: Observable<XRReferenceSpace> = new Observable();\r\n /**\r\n * Fires when the xr session is ended either by the device or manually done\r\n */\r\n public onXRSessionEnded: Observable<any> = new Observable<any>();\r\n /**\r\n * Fires when the xr session is initialized: right after requestSession was called and returned with a successful result\r\n */\r\n public onXRSessionInit: Observable<XRSession> = new Observable<XRSession>();\r\n\r\n /**\r\n * Fires when the xr reference space has been initialized\r\n */\r\n public onXRReferenceSpaceInitialized: Observable<XRReferenceSpace> = new Observable<XRReferenceSpace>();\r\n\r\n /**\r\n * Fires when the session manager is rendering the first frame\r\n */\r\n public onXRReady: Observable<WebXRSessionManager> = new Observable<WebXRSessionManager>();\r\n /**\r\n * Underlying xr session\r\n */\r\n public session: XRSession;\r\n /**\r\n * The viewer (head position) reference space. This can be used to get the XR world coordinates\r\n * or get the offset the player is currently at.\r\n */\r\n public viewerReferenceSpace: XRReferenceSpace;\r\n /**\r\n * Are we currently in the XR loop?\r\n */\r\n public inXRFrameLoop: boolean = false;\r\n /**\r\n * Are we in an XR session?\r\n */\r\n public inXRSession: boolean = false;\r\n\r\n private _worldScalingFactor: number = 1;\r\n\r\n /**\r\n * Observable raised when the world scale has changed\r\n */\r\n public onWorldScaleFactorChangedObservable: Observable<{\r\n previousScaleFactor: number;\r\n newScaleFactor: number;\r\n }> = new Observable(undefined, true);\r\n\r\n /**\r\n * Scale factor to apply to all XR-related elements (camera, controllers)\r\n */\r\n public get worldScalingFactor(): number {\r\n return this._worldScalingFactor;\r\n }\r\n\r\n public set worldScalingFactor(value: number) {\r\n const oldValue = this._worldScalingFactor;\r\n this._worldScalingFactor = value;\r\n this.onWorldScaleFactorChangedObservable.notifyObservers({\r\n previousScaleFactor: oldValue,\r\n newScaleFactor: value,\r\n });\r\n }\r\n\r\n /**\r\n * Constructs a WebXRSessionManager, this must be initialized within a user action before usage\r\n * @param scene The scene which the session should be created for\r\n */\r\n constructor(\r\n /** The scene which the session should be created for */\r\n public scene: Scene\r\n ) {\r\n this._engine = scene.getEngine() as Engine;\r\n this._onEngineDisposedObserver = this._engine.onDisposeObservable.addOnce(() => {\r\n this._engine = null;\r\n });\r\n scene.onDisposeObservable.addOnce(() => {\r\n this.dispose();\r\n });\r\n\r\n this.onXRSessionEnded.add(() => {\r\n // Set the scene's pointer camera to null to stop the XR camera being used for picking.\r\n scene.cameraToUseForPointers = null;\r\n });\r\n }\r\n\r\n /**\r\n * The current reference space used in this session. This reference space can constantly change!\r\n * It is mainly used to offset the camera's position.\r\n */\r\n public get referenceSpace(): XRReferenceSpace {\r\n return this._referenceSpace;\r\n }\r\n\r\n /**\r\n * Set a new reference space and triggers the observable\r\n */\r\n public set referenceSpace(newReferenceSpace: XRReferenceSpace) {\r\n this._referenceSpace = newReferenceSpace;\r\n this.onXRReferenceSpaceChanged.notifyObservers(this._referenceSpace);\r\n }\r\n\r\n /**\r\n * The mode for the managed XR session\r\n */\r\n public get sessionMode(): XRSessionMode {\r\n return this._sessionMode;\r\n }\r\n\r\n /**\r\n * Disposes of the session manager\r\n * This should be called explicitly by the dev, if required.\r\n */\r\n public dispose() {\r\n // disposing without leaving XR? Exit XR first\r\n if (this.inXRSession) {\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this.exitXRAsync();\r\n }\r\n this.onXRReady.clear();\r\n this.onXRFrameObservable.clear();\r\n this.onXRSessionEnded.clear();\r\n this.onXRReferenceSpaceChanged.clear();\r\n this.onXRReferenceSpaceInitialized.clear();\r\n this.onXRSessionInit.clear();\r\n this.onWorldScaleFactorChangedObservable.clear();\r\n this._engine?.onDisposeObservable.remove(this._onEngineDisposedObserver);\r\n this._engine = null;\r\n }\r\n\r\n /**\r\n * Stops the xrSession and restores the render loop\r\n * @returns Promise which resolves after it exits XR\r\n */\r\n public async exitXRAsync() {\r\n if (this.session && this.inXRSession) {\r\n this.inXRSession = false;\r\n try {\r\n return await this.session.end();\r\n } catch {\r\n Logger.Warn(\"Could not end XR session.\");\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Attempts to set the framebuffer-size-normalized viewport to be rendered this frame for this view.\r\n * In the event of a failure, the supplied viewport is not updated.\r\n * @param viewport the viewport to which the view will be rendered\r\n * @param view the view for which to set the viewport\r\n * @returns whether the operation was successful\r\n */\r\n public trySetViewportForView(viewport: Viewport, view: XRView): boolean {\r\n return this._baseLayerRTTProvider?.trySetViewportForView(viewport, view) || false;\r\n }\r\n\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this eye\r\n * @param eye the eye for which to get the render target\r\n * @returns the render target for the specified eye or null if not available\r\n */\r\n public getRenderTargetTextureForEye(eye: XREye): Nullable<RenderTargetTexture> {\r\n return this._baseLayerRTTProvider?.getRenderTargetTextureForEye(eye) || null;\r\n }\r\n\r\n /**\r\n * Gets the correct render target texture to be rendered this frame for this view\r\n * @param view the view for which to get the render target\r\n * @returns the render target for the specified view or null if not available\r\n */\r\n public getRenderTargetTextureForView(view: XRView): Nullable<RenderTargetTexture> {\r\n return this._baseLayerRTTProvider?.getRenderTargetTextureForView(view) || null;\r\n }\r\n\r\n /**\r\n * Creates a WebXRRenderTarget object for the XR session\r\n * @param options optional options to provide when creating a new render target\r\n * @returns a WebXR render target to which the session can render\r\n */\r\n public getWebXRRenderTarget(options?: WebXRManagedOutputCanvasOptions): WebXRRenderTarget {\r\n const engine = this.scene.getEngine();\r\n if (this._xrNavigator.xr.native) {\r\n return new NativeXRRenderTarget(this);\r\n } else {\r\n options = options || WebXRManagedOutputCanvasOptions.GetDefaults(engine);\r\n options.canvasElement = options.canvasElement || engine.getRenderingCanvas() || undefined;\r\n return new WebXRManagedOutputCanvas(this, options);\r\n }\r\n }\r\n\r\n /**\r\n * Initializes the manager\r\n * After initialization enterXR can be called to start an XR session\r\n * @returns Promise which resolves after it is initialized\r\n */\r\n public async initializeAsync(): Promise<void> {\r\n // Check if the browser supports webXR\r\n this._xrNavigator = navigator;\r\n if (!this._xrNavigator.xr) {\r\n throw new Error(\"WebXR not supported on this browser.\");\r\n }\r\n }\r\n\r\n /**\r\n * Initializes an xr session\r\n * @param xrSessionMode mode to initialize\r\n * @param xrSessionInit defines optional and required values to pass to the session builder\r\n * @returns a promise which will resolve once the session has been initialized\r\n */\r\n public async initializeSessionAsync(xrSessionMode: XRSessionMode = \"immersive-vr\", xrSessionInit: XRSessionInit = {}): Promise<XRSession> {\r\n const session = await this._xrNavigator.xr.requestSession(xrSessionMode, xrSessionInit);\r\n\r\n this.session = session;\r\n this._sessionMode = xrSessionMode;\r\n this.inXRSession = true;\r\n this.onXRSessionInit.notifyObservers(session);\r\n\r\n // handle when the session is ended (By calling session.end or device ends its own session eg. pressing home button on phone)\r\n this.session.addEventListener(\r\n \"end\",\r\n () => {\r\n this.inXRSession = false;\r\n\r\n // Cache the value of engine in case it is disposed during onXRSessionEnded callbacks\r\n const engine = this._engine;\r\n\r\n // Notify frame observers\r\n this.onXRSessionEnded.notifyObservers(null);\r\n\r\n if (engine && !engine.isDisposed) {\r\n // make sure dimensions object is restored\r\n engine.framebufferDimensionsObject = null;\r\n\r\n // Restore frame buffer to avoid clear on xr framebuffer after session end\r\n engine.restoreDefaultFramebuffer();\r\n\r\n // Need to restart render loop as after the session is ended the last request for new frame will never call callback\r\n engine.customAnimationFrameRequester = null;\r\n engine._renderLoop();\r\n }\r\n\r\n // Dispose render target textures.\r\n // Only dispose on native because we can't destroy opaque textures on browser.\r\n if (this.isNative) {\r\n this._baseLayerRTTProvider?.dispose();\r\n }\r\n this._baseLayerRTTProvider = null;\r\n this._baseLayerWrapper = null;\r\n },\r\n { once: true }\r\n );\r\n\r\n return this.session;\r\n }\r\n\r\n /**\r\n * Checks if a session would be supported for the creation options specified\r\n * @param sessionMode session mode to check if supported eg. immersive-vr\r\n * @returns A Promise that resolves to true if supported and false if not\r\n */\r\n public async isSessionSupportedAsync(sessionMode: XRSessionMode): Promise<boolean> {\r\n return await WebXRSessionManager.IsSessionSupportedAsync(sessionMode);\r\n }\r\n\r\n /**\r\n * Resets the reference space to the one started the session\r\n */\r\n public resetReferenceSpace() {\r\n this.referenceSpace = this.baseReferenceSpace;\r\n }\r\n\r\n /**\r\n * Starts rendering to the xr layer\r\n */\r\n public runXRRenderLoop() {\r\n if (!this.inXRSession || !this._engine) {\r\n return;\r\n }\r\n\r\n // Tell the engine's render loop to be driven by the xr session's refresh rate and provide xr pose information\r\n this._engine.customAnimationFrameRequester = {\r\n requestAnimationFrame: (callback: FrameRequestCallback) => this.session.requestAnimationFrame(callback),\r\n renderFunction: (timestamp: number, xrFrame: Nullable<XRFrame>) => {\r\n if (!this.inXRSession || !this._engine) {\r\n return;\r\n }\r\n // Store the XR frame and timestamp in the session manager\r\n this.currentFrame = xrFrame;\r\n this.currentTimestamp = timestamp;\r\n if (xrFrame) {\r\n this.inXRFrameLoop = true;\r\n const framebufferDimensionsObject = this._baseLayerRTTProvider?.getFramebufferDimensions() || null;\r\n // equality can be tested as it should be the same object\r\n if (this._engine.framebufferDimensionsObject !== framebufferDimensionsObject) {\r\n this._engine.framebufferDimensionsObject = framebufferDimensionsObject;\r\n }\r\n this.onXRFrameObservable.notifyObservers(xrFrame);\r\n this._engine._renderLoop();\r\n this._engine.framebufferDimensionsObject = null;\r\n this.inXRFrameLoop = false;\r\n }\r\n },\r\n };\r\n\r\n this._engine.framebufferDimensionsObject = this._baseLayerRTTProvider?.getFramebufferDimensions() || null;\r\n this.onXRFrameObservable.addOnce(() => {\r\n this.onXRReady.notifyObservers(this);\r\n });\r\n\r\n // Stop window's animation frame and trigger sessions animation frame\r\n if (typeof window !== \"undefined\" && window.cancelAnimationFrame) {\r\n window.cancelAnimationFrame(this._engine._frameHandler);\r\n }\r\n this._engine._renderLoop();\r\n }\r\n\r\n /**\r\n * Sets the reference space on the xr session\r\n * @param referenceSpaceType space to set\r\n * @returns a promise that will resolve once the reference space has been set\r\n */\r\n public async setReferenceSpaceTypeAsync(referenceSpaceType: XRReferenceSpaceType = \"local-floor\"): Promise<XRReferenceSpace> {\r\n let referenceSpace: XRReferenceSpace;\r\n let viewerReferenceSpace: Nullable<XRReferenceSpace> = null;\r\n try {\r\n referenceSpace = await this.session.requestReferenceSpace(referenceSpaceType);\r\n } catch (rejectionReason) {\r\n Logger.Error(\"XR.requestReferenceSpace failed for the following reason: \");\r\n Logger.Error(rejectionReason);\r\n Logger.Log('Defaulting to universally-supported \"viewer\" reference space type.');\r\n\r\n try {\r\n viewerReferenceSpace = (await this.session.requestReferenceSpace(\"viewer\")) as XRReferenceSpace;\r\n const heightCompensation = new XRRigidTransform({ x: 0, y: -this.defaultHeightCompensation, z: 0 });\r\n referenceSpace = viewerReferenceSpace.getOffsetReferenceSpace(heightCompensation);\r\n } catch (rejectionReason) {\r\n Logger.Error(rejectionReason);\r\n // eslint-disable-next-line no-throw-literal\r\n throw 'XR initialization failed: required \"viewer\" reference space type not supported.';\r\n }\r\n }\r\n // create viewer reference space before setting the first reference space\r\n this.viewerReferenceSpace = viewerReferenceSpace ?? ((await this.session.requestReferenceSpace(\"viewer\")) as XRReferenceSpace);\r\n // initialize the base and offset (currently the same)\r\n this.referenceSpace = this.baseReferenceSpace = referenceSpace;\r\n this.onXRReferenceSpaceInitialized.notifyObservers(referenceSpace);\r\n return this.referenceSpace;\r\n }\r\n\r\n /**\r\n * Updates the render state of the session.\r\n * Note that this is deprecated in favor of WebXRSessionManager.updateRenderState().\r\n * @param state state to set\r\n * @returns a promise that resolves once the render state has been updated\r\n * @deprecated Use updateRenderState() instead.\r\n */\r\n public async updateRenderStateAsync(state: XRRenderState): Promise<void> {\r\n return await this.session.updateRenderState(state);\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _setBaseLayerWrapper(baseLayerWrapper: Nullable<WebXRLayerWrapper>): void {\r\n if (this.isNative) {\r\n this._baseLayerRTTProvider?.dispose();\r\n }\r\n this._baseLayerWrapper = baseLayerWrapper;\r\n this._baseLayerRTTProvider = this._baseLayerWrapper?.createRenderTargetTextureProvider(this) || null;\r\n }\r\n\r\n /**\r\n * @internal\r\n */\r\n public _getBaseLayerWrapper(): Nullable<WebXRLayerWrapper> {\r\n return this._baseLayerWrapper;\r\n }\r\n\r\n /**\r\n * Updates the render state of the session\r\n * @param state state to set\r\n */\r\n public updateRenderState(state: XRRenderStateInit): void {\r\n if (state.baseLayer) {\r\n this._setBaseLayerWrapper(this.isNative ? new NativeXRLayerWrapper(state.baseLayer) : new WebXRWebGLLayerWrapper(state.baseLayer));\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\r\n this.session.updateRenderState(state);\r\n }\r\n\r\n /**\r\n * Returns a promise that resolves with a boolean indicating if the provided session mode is supported by this browser\r\n * @param sessionMode defines the session to test\r\n * @returns a promise with boolean as final value\r\n */\r\n public static async IsSessionSupportedAsync(sessionMode: XRSessionMode): Promise<boolean> {\r\n if (!(navigator as any).xr) {\r\n return false;\r\n }\r\n // When the specs are final, remove supportsSession!\r\n const functionToUse = (navigator as any).xr.isSessionSupported || (navigator as any).xr.supportsSession;\r\n if (!functionToUse) {\r\n return false;\r\n } else {\r\n try {\r\n const result = functionToUse.call((navigator as any).xr, sessionMode);\r\n const returnValue = typeof result === \"undefined\" ? true : result;\r\n return returnValue;\r\n } catch (e: any) {\r\n Logger.Warn(e);\r\n return false;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Returns true if Babylon.js is using the BabylonNative backend, otherwise false\r\n */\r\n public get isNative(): boolean {\r\n return this._xrNavigator.xr.native ?? false;\r\n }\r\n\r\n /**\r\n * The current frame rate as reported by the device\r\n */\r\n public get currentFrameRate(): number | undefined {\r\n return this.session?.frameRate;\r\n }\r\n\r\n /**\r\n * A list of supported frame rates (only available in-session!\r\n */\r\n public get supportedFrameRates(): Float32Array | undefined {\r\n return this.session?.supportedFrameRates;\r\n }\r\n\r\n /**\r\n * Set the framerate of the session.\r\n * @param rate the new framerate. This value needs to be in the supportedFrameRates array\r\n * @returns a promise that resolves once the framerate has been set\r\n */\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public async updateTargetFrameRate(rate: number): Promise<void> {\r\n return await this.session.updateTargetFrameRate(rate);\r\n }\r\n\r\n /**\r\n * Run a callback in the xr render loop\r\n * @param callback the callback to call when in XR Frame\r\n * @param ignoreIfNotInSession if no session is currently running, run it first thing on the next session\r\n */\r\n public runInXRFrame(callback: () => void, ignoreIfNotInSession = true): void {\r\n if (this.inXRFrameLoop) {\r\n callback();\r\n } else if (this.inXRSession || !ignoreIfNotInSession) {\r\n this.onXRFrameObservable.addOnce(callback);\r\n }\r\n }\r\n\r\n /**\r\n * Check if fixed foveation is supported on this device\r\n */\r\n public get isFixedFoveationSupported(): boolean {\r\n return this._baseLayerWrapper?.isFixedFoveationSupported || false;\r\n }\r\n\r\n /**\r\n * Get the fixed foveation currently set, as specified by the webxr specs\r\n * If this returns null, then fixed foveation is not supported\r\n */\r\n public get fixedFoveation(): Nullable<number> {\r\n return this._baseLayerWrapper?.fixedFoveation || null;\r\n }\r\n\r\n /**\r\n * Set the fixed foveation to the specified value, as specified by the webxr specs\r\n * This value will be normalized to be between 0 and 1, 1 being max foveation, 0 being no foveation\r\n */\r\n public set fixedFoveation(value: Nullable<number>) {\r\n const val = Math.max(0, Math.min(1, value || 0));\r\n if (this._baseLayerWrapper) {\r\n this._baseLayerWrapper.fixedFoveation = val;\r\n }\r\n }\r\n\r\n /**\r\n * Get the features enabled on the current session\r\n * This is only available in-session!\r\n * @see https://www.w3.org/TR/webxr/#dom-xrsession-enabledfeatures\r\n */\r\n public get enabledFeatures(): Nullable<string[]> {\r\n return this.session?.enabledFeatures ?? null;\r\n }\r\n}\r\n"]}
|