@babylonjs/core 8.17.0 → 8.17.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Audio/audioEngine.d.ts +11 -16
- package/Audio/audioEngine.js +79 -189
- package/Audio/audioEngine.js.map +1 -1
- package/AudioV2/webAudio/webAudioEngine.d.ts +15 -1
- package/AudioV2/webAudio/webAudioEngine.js +25 -1
- package/AudioV2/webAudio/webAudioEngine.js.map +1 -1
- package/AudioV2/webAudio/webAudioMainOut.d.ts +4 -2
- package/AudioV2/webAudio/webAudioMainOut.js +19 -5
- package/AudioV2/webAudio/webAudioMainOut.js.map +1 -1
- package/AudioV2/webAudio/webAudioUnmuteUI.d.ts +6 -0
- package/AudioV2/webAudio/webAudioUnmuteUI.js +30 -2
- package/AudioV2/webAudio/webAudioUnmuteUI.js.map +1 -1
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Layers/effectLayer.d.ts +4 -0
- package/Layers/effectLayer.js +7 -5
- package/Layers/effectLayer.js.map +1 -1
- package/Layers/effectLayerSceneComponent.d.ts +1 -17
- package/Layers/effectLayerSceneComponent.js +0 -11
- package/Layers/effectLayerSceneComponent.js.map +1 -1
- package/Materials/Textures/ktx2decoderTypes.d.ts +1 -0
- package/Materials/Textures/ktx2decoderTypes.js +2 -0
- package/Materials/Textures/ktx2decoderTypes.js.map +1 -1
- package/Materials/materialHelper.functions.js +1 -2
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/uniformBuffer.d.ts +1 -1
- package/Materials/uniformBuffer.js +2 -2
- package/Materials/uniformBuffer.js.map +1 -1
- package/Meshes/trailMesh.js +2 -2
- package/Meshes/trailMesh.js.map +1 -1
- package/Morph/morphTargetManager.js +2 -0
- package/Morph/morphTargetManager.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/IShapeBlock.d.ts +14 -0
- package/Particles/Node/Blocks/Emitters/IShapeBlock.js +2 -0
- package/Particles/Node/Blocks/Emitters/IShapeBlock.js.map +1 -0
- package/Particles/Node/Blocks/Emitters/boxShapeBlock.d.ts +2 -1
- package/Particles/Node/Blocks/Emitters/boxShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/customShapeBlock.d.ts +2 -1
- package/Particles/Node/Blocks/Emitters/customShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.d.ts +2 -1
- package/Particles/Node/Blocks/Emitters/cylinderShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/meshShapeBlock.d.ts +2 -1
- package/Particles/Node/Blocks/Emitters/meshShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/pointShapeBlock.d.ts +2 -1
- package/Particles/Node/Blocks/Emitters/pointShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/Emitters/sphereShapeBlock.d.ts +4 -3
- package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js +4 -4
- package/Particles/Node/Blocks/Emitters/sphereShapeBlock.js.map +1 -1
- package/Particles/Node/Blocks/systemBlock.js +0 -1
- package/Particles/Node/Blocks/systemBlock.js.map +1 -1
- package/Particles/Node/index.d.ts +1 -0
- package/Particles/Node/index.js +1 -0
- package/Particles/Node/index.js.map +1 -1
- package/Particles/Node/nodeParticleSystemSet.d.ts +34 -1
- package/Particles/Node/nodeParticleSystemSet.helper.d.ts +10 -0
- package/Particles/Node/nodeParticleSystemSet.helper.js +90 -0
- package/Particles/Node/nodeParticleSystemSet.helper.js.map +1 -0
- package/Particles/Node/nodeParticleSystemSet.js +64 -1
- package/Particles/Node/nodeParticleSystemSet.js.map +1 -1
- package/Particles/particleSystem.d.ts +4 -6
- package/Particles/particleSystem.js +6 -8
- package/Particles/particleSystem.js.map +1 -1
- package/Physics/v2/characterController.d.ts +1 -1
- package/Physics/v2/characterController.js +1 -1
- package/Physics/v2/characterController.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +1 -1
- package/Physics/v2/physicsBody.js +2 -2
- package/Physics/v2/physicsBody.js.map +1 -1
- package/PostProcesses/RenderPipeline/postProcessRenderEffect.js +2 -2
- package/PostProcesses/RenderPipeline/postProcessRenderEffect.js.map +1 -1
- package/XR/features/WebXRControllerMovement.js +1 -1
- package/XR/features/WebXRControllerMovement.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +23 -4
- package/scene.js +38 -4
- package/scene.js.map +1 -1
|
@@ -147,7 +147,7 @@ export declare class PhysicsBody {
|
|
|
147
147
|
/**
|
|
148
148
|
* Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
149
149
|
* @param motionType - The motion type to set.
|
|
150
|
-
* @param instanceIndex - If this body is instanced, the index of the instance to set the motion type for.
|
|
150
|
+
* @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.
|
|
151
151
|
*/
|
|
152
152
|
setMotionType(motionType: PhysicsMotionType, instanceIndex?: number): void;
|
|
153
153
|
/**
|
|
@@ -197,10 +197,10 @@ export class PhysicsBody {
|
|
|
197
197
|
/**
|
|
198
198
|
* Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
199
199
|
* @param motionType - The motion type to set.
|
|
200
|
-
* @param instanceIndex - If this body is instanced, the index of the instance to set the motion type for.
|
|
200
|
+
* @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.
|
|
201
201
|
*/
|
|
202
202
|
setMotionType(motionType, instanceIndex) {
|
|
203
|
-
this.disableSync = motionType == 0 /* PhysicsMotionType.STATIC */;
|
|
203
|
+
this.disableSync = instanceIndex === undefined && motionType == 0 /* PhysicsMotionType.STATIC */;
|
|
204
204
|
this._physicsPlugin.setMotionType(this, motionType, instanceIndex);
|
|
205
205
|
}
|
|
206
206
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/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AAM,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACtB,CAAC;CACJ","sourcesContent":["import type { IBasePhysicsCollisionEvent, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport { PhysicsMotionType, PhysicsPrestepType } 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 \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport { Space } from \"core/Maths/math.axis\";\r\nimport type { Observable, Observer } from \"../../Misc/observable\";\r\nimport type { Node } from \"../../node\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"core/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.\r\n */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\r\n this.disableSync = 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 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 * @returns Observable\r\n */\r\n public getCollisionObservable(): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this);\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 * @returns\r\n */\r\n public getCollisionEndedObservable(): Observable<IBasePhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionEndedObservable(this);\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":"AACA,OAAO,EAAqB,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE/E,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,kBAAkB,CAAC,QAAQ,CAAC;IAC5D,CAAC;IAED,IAAW,cAAc,CAAC,KAAc;QACpC,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,kBAAk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I,CAAC,WAAW,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO;QACX,CAAC;QACD,qEAAqE;QACrE,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC3B,IAAI,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;QAC5C,CAAC;QACD,IAAI,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAChC,IAAI,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC5B,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACzE,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;QACrC,CAAC;QACD,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,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 type { IBasePhysicsCollisionEvent, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties } from \"./IPhysicsEnginePlugin\";\r\nimport { PhysicsMotionType, PhysicsPrestepType } 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 \"core/types\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { Bone } from \"core/Bones/bone\";\r\nimport { Space } from \"core/Maths/math.axis\";\r\nimport type { Observable, Observer } from \"../../Misc/observable\";\r\nimport type { Node } from \"../../node\";\r\nimport type { Mesh } from \"core/Meshes/mesh\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { BoundingBox } from \"core/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 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 * @returns Observable\r\n */\r\n public getCollisionObservable(): Observable<IPhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionObservable(this);\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 * @returns\r\n */\r\n public getCollisionEndedObservable(): Observable<IBasePhysicsCollisionEvent> {\r\n return this._physicsPlugin.getCollisionEndedObservable(this);\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"]}
|
|
@@ -13,9 +13,9 @@ export class PostProcessRenderEffect {
|
|
|
13
13
|
* @param getPostProcesses A function that returns a set of post processes which the effect will run in order to be run.
|
|
14
14
|
* @param singleInstance False if this post process can be run on multiple cameras. (default: true)
|
|
15
15
|
*/
|
|
16
|
-
constructor(engine, name, getPostProcesses, singleInstance) {
|
|
16
|
+
constructor(engine, name, getPostProcesses, singleInstance = true) {
|
|
17
17
|
this._name = name;
|
|
18
|
-
this._singleInstance = singleInstance
|
|
18
|
+
this._singleInstance = singleInstance;
|
|
19
19
|
this._getPostProcesses = getPostProcesses;
|
|
20
20
|
this._cameras = {};
|
|
21
21
|
this._indicesForCamera = {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postProcessRenderEffect.js","sourceRoot":"","sources":["../../../../../dev/core/src/PostProcesses/RenderPipeline/postProcessRenderEffect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIzC;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAehC;;;;;;;OAOG;IACH,YAAY,MAAsB,EAAE,IAAY,EAAE,gBAAkE,EAAE,cAAwB;QAC1I,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CAAC,eAAe,GAAG,cA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,gBAAgB,CAAC,MAAe;QACnC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\n/**\r\n * This represents a set of one or more post processes in Babylon.\r\n * A post process can be used to apply a shader to a texture after it is rendered.\r\n * @example https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n */\r\nexport class PostProcessRenderEffect {\r\n private _postProcesses: { [Key: string]: Array<PostProcess> };\r\n private _getPostProcesses: () => Nullable<PostProcess | Array<PostProcess>>;\r\n\r\n private _singleInstance: boolean;\r\n\r\n private _cameras: { [key: string]: Nullable<Camera> };\r\n private _indicesForCamera: { [key: string]: number[] };\r\n\r\n /**\r\n * Name of the effect\r\n * @internal\r\n */\r\n public _name: string;\r\n\r\n /**\r\n * Instantiates a post process render effect.\r\n * A post process can be used to apply a shader to a texture after it is rendered.\r\n * @param engine The engine the effect is tied to\r\n * @param name The name of the effect\r\n * @param getPostProcesses A function that returns a set of post processes which the effect will run in order to be run.\r\n * @param singleInstance False if this post process can be run on multiple cameras. (default: true)\r\n */\r\n constructor(engine: AbstractEngine, name: string, getPostProcesses: () => Nullable<PostProcess | Array<PostProcess>>, singleInstance?: boolean) {\r\n this._name = name;\r\n this._singleInstance = singleInstance || true;\r\n\r\n this._getPostProcesses = getPostProcesses;\r\n\r\n this._cameras = {};\r\n this._indicesForCamera = {};\r\n\r\n this._postProcesses = {};\r\n }\r\n\r\n /**\r\n * Checks if all the post processes in the effect are supported.\r\n */\r\n public get isSupported(): boolean {\r\n for (const index in this._postProcesses) {\r\n if (Object.prototype.hasOwnProperty.call(this._postProcesses, index)) {\r\n const pps = this._postProcesses[index];\r\n for (let ppIndex = 0; ppIndex < pps.length; ppIndex++) {\r\n if (!pps[ppIndex].isSupported) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Updates the current state of the effect\r\n * @internal\r\n */\r\n public _update(): void {}\r\n\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: Camera): void;\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: Camera[]): void;\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: any): void {\r\n let cameraKey;\r\n\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n if (!camera) {\r\n continue;\r\n }\r\n\r\n const cameraName = camera.name;\r\n\r\n if (this._singleInstance) {\r\n cameraKey = 0;\r\n } else {\r\n cameraKey = cameraName;\r\n }\r\n\r\n if (!this._postProcesses[cameraKey]) {\r\n const postProcess = this._getPostProcesses();\r\n if (postProcess) {\r\n this._postProcesses[cameraKey] = Array.isArray(postProcess) ? postProcess : [postProcess];\r\n }\r\n }\r\n\r\n if (!this._indicesForCamera[cameraName]) {\r\n this._indicesForCamera[cameraName] = [];\r\n }\r\n\r\n const pps = this._postProcesses[cameraKey];\r\n for (const postProcess of pps) {\r\n const index = camera.attachPostProcess(postProcess);\r\n\r\n this._indicesForCamera[cameraName].push(index);\r\n }\r\n\r\n if (!this._cameras[cameraName]) {\r\n this._cameras[cameraName] = camera;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: Camera): void;\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: Camera[]): void;\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: any): void {\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera: Camera = cams[i];\r\n const cameraName: string = camera.name;\r\n const postProcesses = this._postProcesses[this._singleInstance ? 0 : cameraName];\r\n\r\n if (postProcesses) {\r\n for (const postProcess of postProcesses) {\r\n camera.detachPostProcess(postProcess);\r\n }\r\n }\r\n\r\n if (this._cameras[cameraName]) {\r\n this._cameras[cameraName] = null;\r\n }\r\n\r\n delete this._indicesForCamera[cameraName];\r\n }\r\n }\r\n\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: Camera): void;\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: Nullable<Camera[]>): void;\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: any): void {\r\n const cams: Nullable<Array<Camera>> = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n const cameraName = camera.name;\r\n const cameraKey = this._singleInstance ? 0 : cameraName;\r\n\r\n for (let j = 0; j < this._indicesForCamera[cameraName].length; j++) {\r\n const index = this._indicesForCamera[cameraName][j];\r\n const postProcess = camera._postProcesses[index];\r\n if (postProcess === undefined || postProcess === null) {\r\n cams[i].attachPostProcess(this._postProcesses[cameraKey][j], index);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: Camera): void;\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: Nullable<Camera[]>): void;\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: any): void {\r\n const cams: Nullable<Array<Camera>> = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n const cameraName = camera.name;\r\n const pps = this._postProcesses[this._singleInstance ? 0 : cameraName];\r\n for (const postProcess of pps) {\r\n camera.detachPostProcess(postProcess);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a list of the post processes contained in the effect.\r\n * @param camera The camera to get the post processes on.\r\n * @returns The list of the post processes in the effect.\r\n */\r\n public getPostProcesses(camera?: Camera): Nullable<Array<PostProcess>> {\r\n if (this._singleInstance) {\r\n return this._postProcesses[0];\r\n } else {\r\n if (!camera) {\r\n return null;\r\n }\r\n return this._postProcesses[camera.name];\r\n }\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"postProcessRenderEffect.js","sourceRoot":"","sources":["../../../../../dev/core/src/PostProcesses/RenderPipeline/postProcessRenderEffect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIzC;;;;GAIG;AACH,MAAM,OAAO,uBAAuB;IAehC;;;;;;;OAOG;IACH,YAAY,MAAsB,EAAE,IAAY,EAAE,gBAAkE,EAAE,cAAc,GAAG,IAAI;QACvI,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;QAClB,IAAI,CA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G;IACI,gBAAgB,CAAC,MAAe;QACnC,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;QAClC,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,MAAM,EAAE,CAAC;gBACV,OAAO,IAAI,CAAC;YAChB,CAAC;YACD,OAAO,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC5C,CAAC;IACL,CAAC;CACJ","sourcesContent":["import type { Nullable } from \"../../types\";\r\nimport { Tools } from \"../../Misc/tools\";\r\nimport type { Camera } from \"../../Cameras/camera\";\r\nimport type { PostProcess } from \"../../PostProcesses/postProcess\";\r\nimport type { AbstractEngine } from \"../../Engines/abstractEngine\";\r\n/**\r\n * This represents a set of one or more post processes in Babylon.\r\n * A post process can be used to apply a shader to a texture after it is rendered.\r\n * @example https://doc.babylonjs.com/features/featuresDeepDive/postProcesses/postProcessRenderPipeline\r\n */\r\nexport class PostProcessRenderEffect {\r\n private _postProcesses: { [Key: string]: Array<PostProcess> };\r\n private _getPostProcesses: () => Nullable<PostProcess | Array<PostProcess>>;\r\n\r\n private _singleInstance: boolean;\r\n\r\n private _cameras: { [key: string]: Nullable<Camera> };\r\n private _indicesForCamera: { [key: string]: number[] };\r\n\r\n /**\r\n * Name of the effect\r\n * @internal\r\n */\r\n public _name: string;\r\n\r\n /**\r\n * Instantiates a post process render effect.\r\n * A post process can be used to apply a shader to a texture after it is rendered.\r\n * @param engine The engine the effect is tied to\r\n * @param name The name of the effect\r\n * @param getPostProcesses A function that returns a set of post processes which the effect will run in order to be run.\r\n * @param singleInstance False if this post process can be run on multiple cameras. (default: true)\r\n */\r\n constructor(engine: AbstractEngine, name: string, getPostProcesses: () => Nullable<PostProcess | Array<PostProcess>>, singleInstance = true) {\r\n this._name = name;\r\n this._singleInstance = singleInstance;\r\n\r\n this._getPostProcesses = getPostProcesses;\r\n\r\n this._cameras = {};\r\n this._indicesForCamera = {};\r\n\r\n this._postProcesses = {};\r\n }\r\n\r\n /**\r\n * Checks if all the post processes in the effect are supported.\r\n */\r\n public get isSupported(): boolean {\r\n for (const index in this._postProcesses) {\r\n if (Object.prototype.hasOwnProperty.call(this._postProcesses, index)) {\r\n const pps = this._postProcesses[index];\r\n for (let ppIndex = 0; ppIndex < pps.length; ppIndex++) {\r\n if (!pps[ppIndex].isSupported) {\r\n return false;\r\n }\r\n }\r\n }\r\n }\r\n return true;\r\n }\r\n\r\n /**\r\n * Updates the current state of the effect\r\n * @internal\r\n */\r\n public _update(): void {}\r\n\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: Camera): void;\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: Camera[]): void;\r\n /**\r\n * Attaches the effect on cameras\r\n * @param cameras The camera to attach to.\r\n * @internal\r\n */\r\n public _attachCameras(cameras: any): void {\r\n let cameraKey;\r\n\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n if (!camera) {\r\n continue;\r\n }\r\n\r\n const cameraName = camera.name;\r\n\r\n if (this._singleInstance) {\r\n cameraKey = 0;\r\n } else {\r\n cameraKey = cameraName;\r\n }\r\n\r\n if (!this._postProcesses[cameraKey]) {\r\n const postProcess = this._getPostProcesses();\r\n if (postProcess) {\r\n this._postProcesses[cameraKey] = Array.isArray(postProcess) ? postProcess : [postProcess];\r\n }\r\n }\r\n\r\n if (!this._indicesForCamera[cameraName]) {\r\n this._indicesForCamera[cameraName] = [];\r\n }\r\n\r\n const pps = this._postProcesses[cameraKey];\r\n for (const postProcess of pps) {\r\n const index = camera.attachPostProcess(postProcess);\r\n\r\n this._indicesForCamera[cameraName].push(index);\r\n }\r\n\r\n if (!this._cameras[cameraName]) {\r\n this._cameras[cameraName] = camera;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: Camera): void;\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: Camera[]): void;\r\n /**\r\n * Detaches the effect on cameras\r\n * @param cameras The camera to detach from.\r\n * @internal\r\n */\r\n public _detachCameras(cameras: any): void {\r\n const cams = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera: Camera = cams[i];\r\n const cameraName: string = camera.name;\r\n const postProcesses = this._postProcesses[this._singleInstance ? 0 : cameraName];\r\n\r\n if (postProcesses) {\r\n for (const postProcess of postProcesses) {\r\n camera.detachPostProcess(postProcess);\r\n }\r\n }\r\n\r\n if (this._cameras[cameraName]) {\r\n this._cameras[cameraName] = null;\r\n }\r\n\r\n delete this._indicesForCamera[cameraName];\r\n }\r\n }\r\n\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: Camera): void;\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: Nullable<Camera[]>): void;\r\n /**\r\n * Enables the effect on given cameras\r\n * @param cameras The camera to enable.\r\n * @internal\r\n */\r\n public _enable(cameras: any): void {\r\n const cams: Nullable<Array<Camera>> = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n const cameraName = camera.name;\r\n const cameraKey = this._singleInstance ? 0 : cameraName;\r\n\r\n for (let j = 0; j < this._indicesForCamera[cameraName].length; j++) {\r\n const index = this._indicesForCamera[cameraName][j];\r\n const postProcess = camera._postProcesses[index];\r\n if (postProcess === undefined || postProcess === null) {\r\n cams[i].attachPostProcess(this._postProcesses[cameraKey][j], index);\r\n }\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: Camera): void;\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: Nullable<Camera[]>): void;\r\n /**\r\n * Disables the effect on the given cameras\r\n * @param cameras The camera to disable.\r\n * @internal\r\n */\r\n public _disable(cameras: any): void {\r\n const cams: Nullable<Array<Camera>> = Tools.MakeArray(cameras || this._cameras);\r\n\r\n if (!cams) {\r\n return;\r\n }\r\n\r\n for (let i = 0; i < cams.length; i++) {\r\n const camera = cams[i];\r\n const cameraName = camera.name;\r\n const pps = this._postProcesses[this._singleInstance ? 0 : cameraName];\r\n for (const postProcess of pps) {\r\n camera.detachPostProcess(postProcess);\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Gets a list of the post processes contained in the effect.\r\n * @param camera The camera to get the post processes on.\r\n * @returns The list of the post processes in the effect.\r\n */\r\n public getPostProcesses(camera?: Camera): Nullable<Array<PostProcess>> {\r\n if (this._singleInstance) {\r\n return this._postProcesses[0];\r\n } else {\r\n if (!camera) {\r\n return null;\r\n }\r\n return this._postProcesses[camera.name];\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -209,7 +209,7 @@ export class WebXRControllerMovement extends WebXRAbstractFeature {
|
|
|
209
209
|
}
|
|
210
210
|
// synchronized from feature setter properties
|
|
211
211
|
this._featureContext = {
|
|
212
|
-
movementEnabled: options.movementEnabled
|
|
212
|
+
movementEnabled: options.movementEnabled ?? true,
|
|
213
213
|
movementOrientationFollowsViewerPose: options.movementOrientationFollowsViewerPose ?? true,
|
|
214
214
|
movementOrientationFollowsController: options.movementOrientationFollowsController ?? false,
|
|
215
215
|
orientationPreferredHandedness: options.orientationPreferredHandedness,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebXRControllerMovement.js","sourceRoot":"","sources":["../../../../../dev/core/src/XR/features/WebXRControllerMovement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAOjF,OAAO,EAAE,wBAAwB,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAsIzC;;;;GAIG;AACH,MAAM,OAAO,uBAAwB,SAAQ,oBAAoB;IA0D7D;;OAEG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,kBAAkB,CAAC;IACnC,CAAC;IAED;;OAEG;IACH,IAAW,eAAe;QACtB,OAAO,IAAI,CAAC,eAAe,CAAC,eAAe,CAAC;IAChD,CAAC;IAED;;;OAGG;IACH,IAAW,eAAe,CAAC,OAAgB;QACvC,IAAI,CAAC,eAAe,CAAC,eAAe,GAAG,OAAO,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,IAAW,oCAAoC;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,oCAAoC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACH,IAAW,oCAAoC,CAAC,WAAoB;QAChE,IAAI,CAAC,eAAe,CAAC,oCAAoC,GAAG,WAAW,CAAC;IAC5E,CAAC;IAED;;OAEG;IACH,IAAW,aAAa;QACpB,OAAO,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC;IAC9C,CAAC;IAED;;;OAGG;IACH,IAAW,aAAa,CAAC,aAAqB;QAC1C,IAAI,CAAC,eAAe,CAAC,aAAa,GAAG,aAAa,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,IAAW,iBAAiB;QACxB,OAAO,IAAI,CAAC,eA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,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7F,CAAC;SACJ;QACD;YACI,qBAAqB,EAAE,CAAC,wBAAwB,CAAC,eAAe,EAAE,wBAAwB,CAAC,aAAa,CAAC;YACzG,eAAe,EAAE,OAAO;YACxB,kBAAkB,EAAE,CAAC,IAAqC,EAAE,aAA2C,EAAE,cAAqD,EAAE,EAAE;gBAC9J,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvF,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3F,CAAC;SACJ;KACJ;CACJ,AAnBmC,CAmBlC;AAEF;;;;GAIG;AACoB,+BAAO,GAAG,CAAC,AAAJ,CAAK;AA6VvC,oBAAoB,CAAC,eAAe,CAChC,uBAAuB,CAAC,IAAI,EAC5B,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,uBAAuB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC,EACD,uBAAuB,CAAC,OAAO,EAC/B,IAAI,CACP,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { IWebXRMotionControllerAxesValue, IWebXRMotionControllerComponentChangesValues } from \"../motionController/webXRControllerComponent\";\r\nimport { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport { Matrix, Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { MotionControllerComponentType } from \"../motionController/webXRAbstractMotionController\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * The options container for the controller movement module\r\n */\r\nexport interface IWebXRControllerMovementOptions {\r\n /**\r\n * Override default behaviour and provide your own movement controls\r\n */\r\n customRegistrationConfigurations?: WebXRControllerMovementRegistrationConfiguration[];\r\n /**\r\n * Is movement enabled\r\n */\r\n movementEnabled?: boolean;\r\n /**\r\n * Camera direction follows view pose and movement by default will move independently of the viewer's pose.\r\n */\r\n movementOrientationFollowsViewerPose: boolean;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n movementSpeed?: number;\r\n /**\r\n * Minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n movementThreshold?: number;\r\n /**\r\n * Is rotation enabled\r\n */\r\n rotationEnabled?: boolean;\r\n /**\r\n * Minimum threshold the controller's thumstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n rotationThreshold?: number;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n rotationSpeed?: number;\r\n /**\r\n * Babylon XR Input class for controller\r\n */\r\n xrInput: WebXRInput;\r\n\r\n /**\r\n * If movement orientation should follow controller orientation instead of viewer pose.\r\n * Make sure to set movementOrientationFollowsViewerPose to false, otherwise it will be ignored.\r\n */\r\n movementOrientationFollowsController: boolean;\r\n\r\n /**\r\n * If orientation follows the controller, this is the preferred handedness to use for forward movement.\r\n * If not set (or handedness not found), the handedness will be selected by the controller triggering the movement.\r\n * Note that this only works if movementOrientationFollowsController is true.\r\n */\r\n orientationPreferredHandedness?: XRHandedness;\r\n}\r\n\r\n/**\r\n * Feature context is used in handlers and on each XR frame to control the camera movement/direction.\r\n */\r\nexport type WebXRControllerMovementFeatureContext = {\r\n movementEnabled: boolean;\r\n movementOrientationFollowsViewerPose: boolean;\r\n movementOrientationFollowsController: boolean;\r\n orientationPreferredHandedness?: XRHandedness;\r\n movementSpeed: number;\r\n movementThreshold: number;\r\n rotationEnabled: boolean;\r\n rotationSpeed: number;\r\n rotationThreshold: number;\r\n};\r\n\r\n/**\r\n * Current state of Movements shared across components and handlers.\r\n */\r\nexport type WebXRControllerMovementState = {\r\n moveX: number;\r\n moveY: number;\r\n rotateX: number;\r\n rotateY: number;\r\n};\r\n\r\n/**\r\n * Button of Axis Handler must be specified.\r\n */\r\nexport type WebXRControllerMovementRegistrationConfiguration = {\r\n /**\r\n * handlers are filtered to these types only\r\n */\r\n allowedComponentTypes?: MotionControllerComponentType[];\r\n /**\r\n * For registering movement to specific hand only. Useful if your app has a \"main hand\" and \"off hand\" for determining the functionality of a controller.\r\n */\r\n forceHandedness?: XRHandedness;\r\n /**\r\n * For main component only (useful for buttons and may not trigger axis changes).\r\n */\r\n mainComponentOnly?: boolean;\r\n /**\r\n * Additional predicate to apply to controllers to restrict a handler being added.\r\n */\r\n componentSelectionPredicate?: (xrController: WebXRInputSource) => Nullable<WebXRControllerComponent>;\r\n} & (\r\n | {\r\n /**\r\n * Called when axis changes occur.\r\n */\r\n axisChangedHandler: (\r\n axes: IWebXRMotionControllerAxesValue,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n | {\r\n /**\r\n * Called when the button state changes.\r\n */\r\n buttonChangedHandler: (\r\n pressed: IWebXRMotionControllerComponentChangesValues<boolean>,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n);\r\n\r\ntype RegisteredComponent = {\r\n registrationConfiguration: WebXRControllerMovementRegistrationConfiguration;\r\n component: WebXRControllerComponent;\r\n onAxisChangedObserver?: Nullable<Observer<IWebXRMotionControllerAxesValue>>;\r\n onButtonChangedObserver?: Nullable<Observer<WebXRControllerComponent>>;\r\n};\r\n\r\n/**\r\n * This is a movement feature to be used with WebXR-enabled motion controllers.\r\n * When enabled and attached, the feature will allow a user to move around and rotate in the scene using\r\n * the input of the attached controllers.\r\n */\r\nexport class WebXRControllerMovement extends WebXRAbstractFeature {\r\n private _controllers: {\r\n [controllerUniqueId: string]: {\r\n xrController: WebXRInputSource;\r\n registeredComponents: RegisteredComponent[];\r\n };\r\n } = {};\r\n\r\n private _currentRegistrationConfigurations: WebXRControllerMovementRegistrationConfiguration[] = [];\r\n // Feature configuration is synchronized - this is passed to all handlers (reduce GC pressure).\r\n private _featureContext: WebXRControllerMovementFeatureContext;\r\n // forward direction for movement, which may differ from viewer pose.\r\n private _movementDirection: Quaternion = new Quaternion();\r\n private _movementState: WebXRControllerMovementState;\r\n private _xrInput: WebXRInput;\r\n\r\n // unused\r\n private _tmpRotationMatrix: Matrix = Matrix.Identity();\r\n private _tmpTranslationDirection: Vector3 = new Vector3();\r\n private _tmpMovementTranslation: Vector3 = new Vector3();\r\n private _tempCacheQuaternion: Quaternion = new Quaternion();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.MOVEMENT;\r\n\r\n /**\r\n * Standard controller configurations.\r\n */\r\n public static readonly REGISTRATIONS: { [key: string]: WebXRControllerMovementRegistrationConfiguration[] } = {\r\n default: [\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"left\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.rotateX = Math.abs(axes.x) > featureContext.rotationThreshold ? axes.x : 0;\r\n movementState.rotateY = Math.abs(axes.y) > featureContext.rotationThreshold ? axes.y : 0;\r\n },\r\n },\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"right\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.moveX = Math.abs(axes.x) > featureContext.movementThreshold ? axes.x : 0;\r\n movementState.moveY = Math.abs(axes.y) > featureContext.movementThreshold ? axes.y : 0;\r\n },\r\n },\r\n ],\r\n };\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Current movement direction. Will be null before XR Frames have been processed.\r\n */\r\n public get movementDirection(): Quaternion {\r\n return this._movementDirection;\r\n }\r\n\r\n /**\r\n * Is movement enabled\r\n */\r\n public get movementEnabled(): boolean {\r\n return this._featureContext.movementEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether movement is enabled or not\r\n * @param enabled is movement enabled\r\n */\r\n public set movementEnabled(enabled: boolean) {\r\n this._featureContext.movementEnabled = enabled;\r\n }\r\n\r\n /**\r\n * If movement follows viewer pose\r\n */\r\n public get movementOrientationFollowsViewerPose(): boolean {\r\n return this._featureContext.movementOrientationFollowsViewerPose;\r\n }\r\n\r\n /**\r\n * Sets whether movement follows viewer pose\r\n * @param followsPose is movement should follow viewer pose\r\n */\r\n public set movementOrientationFollowsViewerPose(followsPose: boolean) {\r\n this._featureContext.movementOrientationFollowsViewerPose = followsPose;\r\n }\r\n\r\n /**\r\n * Gets movement speed\r\n */\r\n public get movementSpeed(): number {\r\n return this._featureContext.movementSpeed;\r\n }\r\n\r\n /**\r\n * Sets movement speed\r\n * @param movementSpeed movement speed\r\n */\r\n public set movementSpeed(movementSpeed: number) {\r\n this._featureContext.movementSpeed = movementSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n public get movementThreshold(): number {\r\n return this._featureContext.movementThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n * @param movementThreshold new threshold\r\n */\r\n public set movementThreshold(movementThreshold: number) {\r\n this._featureContext.movementThreshold = movementThreshold;\r\n }\r\n\r\n /**\r\n * Is rotation enabled\r\n */\r\n public get rotationEnabled(): boolean {\r\n return this._featureContext.rotationEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether rotation is enabled or not\r\n * @param enabled is rotation enabled\r\n */\r\n public set rotationEnabled(enabled: boolean) {\r\n this._featureContext.rotationEnabled = enabled;\r\n }\r\n\r\n /**\r\n * Gets rotation speed factor\r\n */\r\n public get rotationSpeed(): number {\r\n return this._featureContext.rotationSpeed;\r\n }\r\n\r\n /**\r\n * Sets rotation speed factor (1.0 is default)\r\n * @param rotationSpeed new rotation speed factor\r\n */\r\n public set rotationSpeed(rotationSpeed: number) {\r\n this._featureContext.rotationSpeed = rotationSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n public get rotationThreshold(): number {\r\n return this._featureContext.rotationThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n * @param threshold new threshold\r\n */\r\n public set rotationThreshold(threshold: number) {\r\n this._featureContext.rotationThreshold = threshold;\r\n }\r\n /**\r\n * constructs a new movement controller system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, options: IWebXRControllerMovementOptions) {\r\n super(_xrSessionManager);\r\n\r\n if (!options || options.xrInput === undefined) {\r\n Tools.Error('WebXRControllerMovement feature requires \"xrInput\" option.');\r\n return;\r\n }\r\n\r\n if (Array.isArray(options.customRegistrationConfigurations)) {\r\n this._currentRegistrationConfigurations = options.customRegistrationConfigurations;\r\n } else {\r\n this._currentRegistrationConfigurations = WebXRControllerMovement.REGISTRATIONS.default;\r\n }\r\n\r\n // synchronized from feature setter properties\r\n this._featureContext = {\r\n movementEnabled: options.movementEnabled || true,\r\n movementOrientationFollowsViewerPose: options.movementOrientationFollowsViewerPose ?? true,\r\n movementOrientationFollowsController: options.movementOrientationFollowsController ?? false,\r\n orientationPreferredHandedness: options.orientationPreferredHandedness,\r\n movementSpeed: options.movementSpeed ?? 1,\r\n movementThreshold: options.movementThreshold ?? 0.25,\r\n rotationEnabled: options.rotationEnabled ?? true,\r\n rotationSpeed: options.rotationSpeed ?? 1.0,\r\n rotationThreshold: options.rotationThreshold ?? 0.25,\r\n };\r\n\r\n this._movementState = {\r\n moveX: 0,\r\n moveY: 0,\r\n rotateX: 0,\r\n rotateY: 0,\r\n };\r\n\r\n this._xrInput = options.xrInput;\r\n }\r\n\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n for (const controller of this._xrInput.controllers) {\r\n this._attachController(controller);\r\n }\r\n this._addNewAttachObserver(this._xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._xrInput.onControllerRemovedObservable, (controller: WebXRInputSource) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n const keys = Object.keys(this._controllers);\r\n\r\n for (const controllerId of keys) {\r\n this._detachController(controllerId);\r\n }\r\n\r\n this._controllers = {};\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Occurs on every XR frame.\r\n * @param _xrFrame\r\n */\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n if (!this.attached) {\r\n return;\r\n }\r\n\r\n if (this._movementState.rotateX !== 0 && this._featureContext.rotationEnabled) {\r\n // smooth rotation\r\n const deltaMillis = this._xrSessionManager.scene.getEngine().getDeltaTime();\r\n const rotationY = deltaMillis * 0.001 * this._featureContext.rotationSpeed * this._movementState.rotateX * (this._xrSessionManager.scene.useRightHandedSystem ? -1 : 1);\r\n\r\n if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n this._xrInput.xrCamera.rotationQuaternion.multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else if (this._featureContext.movementOrientationFollowsController) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n // get the correct controller\r\n const handedness = this._featureContext.orientationPreferredHandedness || \"right\";\r\n const key =\r\n Object.keys(this._controllers).find((key) => this._controllers[key]?.xrController?.inputSource.handedness === handedness) || Object.keys(this._controllers)[0];\r\n const controller = this._controllers[key];\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n (controller?.xrController.pointer.rotationQuaternion || Quaternion.Identity()).multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else {\r\n // movement orientation direction does not affect camera. We use rotation speed multiplier\r\n // otherwise need to implement inertia and constraints for same feel as TargetCamera.\r\n\r\n Quaternion.RotationYawPitchRollToRef(rotationY * 3.0, 0, 0, this._tempCacheQuaternion);\r\n this._movementDirection.multiplyInPlace(this._tempCacheQuaternion);\r\n }\r\n } else if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._movementDirection.copyFrom(this._xrInput.xrCamera.rotationQuaternion);\r\n } else if (this._featureContext.movementOrientationFollowsController) {\r\n // get the correct controller\r\n const handedness = this._featureContext.orientationPreferredHandedness || \"right\";\r\n const key =\r\n Object.keys(this._controllers).find((key) => this._controllers[key]?.xrController.inputSource.handedness === handedness) || Object.keys(this._controllers)[0];\r\n const controller = this._controllers[key];\r\n this._movementDirection.copyFrom(controller?.xrController.pointer.rotationQuaternion || Quaternion.Identity());\r\n }\r\n\r\n if ((this._movementState.moveX || this._movementState.moveY) && this._featureContext.movementEnabled) {\r\n Matrix.FromQuaternionToRef(this._movementDirection, this._tmpRotationMatrix);\r\n this._tmpTranslationDirection.set(this._movementState.moveX, 0, this._movementState.moveY * (this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0));\r\n // move according to forward direction based on camera speed\r\n Vector3.TransformCoordinatesToRef(this._tmpTranslationDirection, this._tmpRotationMatrix, this._tmpMovementTranslation);\r\n this._tmpMovementTranslation.scaleInPlace(this._xrInput.xrCamera._computeLocalCameraSpeed() * this._featureContext.movementSpeed);\r\n\r\n this._xrInput.xrCamera.cameraDirection.addInPlace(this._tmpMovementTranslation);\r\n }\r\n }\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n registeredComponents: [],\r\n };\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n\r\n // movement controller only available to gamepad-enabled input sources.\r\n if (controllerData.xrController.inputSource.targetRayMode === \"tracked-pointer\" && controllerData.xrController.inputSource.gamepad) {\r\n // motion controller support\r\n const initController = () => {\r\n if (xrController.motionController) {\r\n for (const registration of this._currentRegistrationConfigurations) {\r\n let component: Nullable<WebXRControllerComponent> = null;\r\n\r\n if (registration.allowedComponentTypes) {\r\n for (const componentType of registration.allowedComponentTypes) {\r\n const componentOfType = xrController.motionController.getComponentOfType(componentType);\r\n if (componentOfType !== null) {\r\n component = componentOfType;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (registration.mainComponentOnly) {\r\n const mainComponent = xrController.motionController.getMainComponent();\r\n if (mainComponent === null) {\r\n continue;\r\n }\r\n component = mainComponent;\r\n }\r\n\r\n if (typeof registration.componentSelectionPredicate === \"function\") {\r\n // if does not match we do want to ignore a previously found component\r\n component = registration.componentSelectionPredicate(xrController);\r\n }\r\n\r\n if (component && registration.forceHandedness) {\r\n if (xrController.inputSource.handedness !== registration.forceHandedness) {\r\n continue; // do not register\r\n }\r\n }\r\n\r\n if (component === null) {\r\n continue; // do not register\r\n }\r\n\r\n const registeredComponent: RegisteredComponent = {\r\n registrationConfiguration: registration,\r\n component,\r\n };\r\n controllerData.registeredComponents.push(registeredComponent);\r\n\r\n if (\"axisChangedHandler\" in registration) {\r\n registeredComponent.onAxisChangedObserver = component.onAxisValueChangedObservable.add((axesData) => {\r\n registration.axisChangedHandler(axesData, this._movementState, this._featureContext, this._xrInput);\r\n });\r\n }\r\n\r\n if (\"buttonChangedHandler\" in registration) {\r\n registeredComponent.onButtonChangedObserver = component.onButtonStateChangedObservable.add((component) => {\r\n if (component.changes.pressed) {\r\n registration.buttonChangedHandler(component.changes.pressed, this._movementState, this._featureContext, this._xrInput);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n };\r\n\r\n if (xrController.motionController) {\r\n initController();\r\n } else {\r\n xrController.onMotionControllerInitObservable.addOnce(() => {\r\n initController();\r\n });\r\n }\r\n }\r\n };\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n\r\n for (const registeredComponent of controllerData.registeredComponents) {\r\n if (registeredComponent.onAxisChangedObserver) {\r\n registeredComponent.component.onAxisValueChangedObservable.remove(registeredComponent.onAxisChangedObserver);\r\n }\r\n if (registeredComponent.onButtonChangedObserver) {\r\n registeredComponent.component.onButtonStateChangedObservable.remove(registeredComponent.onButtonChangedObserver);\r\n }\r\n }\r\n\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerMovement.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerMovement(xrSessionManager, options);\r\n },\r\n WebXRControllerMovement.Version,\r\n true\r\n);\r\n"]}
|
|
1
|
+
{"version":3,"file":"WebXRControllerMovement.js","sourceRoot":"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BAAqB,EAAE,CAAC,wBAAwB,CAAC,eAAe,EAAE,wBAAwB,CAAC,aAAa,CAAC;YACzG,eAAe,EAAE,OAAO;YACxB,kBAAkB,EAAE,CAAC,IAAqC,EAAE,aAA2C,EAAE,cAAqD,EAAE,EAAE;gBAC9J,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvF,aAAa,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC3F,CAAC;SACJ;KACJ;CACJ,AAnBmC,CAmBlC;AAEF;;;;GAIG;AACoB,+BAAO,GAAG,CAAC,AAAJ,CAAK;AA6VvC,oBAAoB,CAAC,eAAe,CAChC,uBAAuB,CAAC,IAAI,EAC5B,CAAC,gBAAgB,EAAE,OAAO,EAAE,EAAE;IAC1B,OAAO,GAAG,EAAE,CAAC,IAAI,uBAAuB,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;AACxE,CAAC,EACD,uBAAuB,CAAC,OAAO,EAC/B,IAAI,CACP,CAAC","sourcesContent":["import { WebXRFeaturesManager, WebXRFeatureName } from \"../webXRFeaturesManager\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { WebXRSessionManager } from \"../webXRSessionManager\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { WebXRInput } from \"../webXRInput\";\r\nimport type { WebXRInputSource } from \"../webXRInputSource\";\r\nimport type { IWebXRMotionControllerAxesValue, IWebXRMotionControllerComponentChangesValues } from \"../motionController/webXRControllerComponent\";\r\nimport { WebXRControllerComponent } from \"../motionController/webXRControllerComponent\";\r\nimport { Matrix, Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { WebXRAbstractFeature } from \"./WebXRAbstractFeature\";\r\nimport type { MotionControllerComponentType } from \"../motionController/webXRAbstractMotionController\";\r\nimport { Tools } from \"../../Misc/tools\";\r\n\r\n/**\r\n * The options container for the controller movement module\r\n */\r\nexport interface IWebXRControllerMovementOptions {\r\n /**\r\n * Override default behaviour and provide your own movement controls\r\n */\r\n customRegistrationConfigurations?: WebXRControllerMovementRegistrationConfiguration[];\r\n /**\r\n * Is movement enabled\r\n */\r\n movementEnabled?: boolean;\r\n /**\r\n * Camera direction follows view pose and movement by default will move independently of the viewer's pose.\r\n */\r\n movementOrientationFollowsViewerPose: boolean;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n movementSpeed?: number;\r\n /**\r\n * Minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n movementThreshold?: number;\r\n /**\r\n * Is rotation enabled\r\n */\r\n rotationEnabled?: boolean;\r\n /**\r\n * Minimum threshold the controller's thumstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n rotationThreshold?: number;\r\n /**\r\n * Movement speed factor (default is 1.0)\r\n */\r\n rotationSpeed?: number;\r\n /**\r\n * Babylon XR Input class for controller\r\n */\r\n xrInput: WebXRInput;\r\n\r\n /**\r\n * If movement orientation should follow controller orientation instead of viewer pose.\r\n * Make sure to set movementOrientationFollowsViewerPose to false, otherwise it will be ignored.\r\n */\r\n movementOrientationFollowsController: boolean;\r\n\r\n /**\r\n * If orientation follows the controller, this is the preferred handedness to use for forward movement.\r\n * If not set (or handedness not found), the handedness will be selected by the controller triggering the movement.\r\n * Note that this only works if movementOrientationFollowsController is true.\r\n */\r\n orientationPreferredHandedness?: XRHandedness;\r\n}\r\n\r\n/**\r\n * Feature context is used in handlers and on each XR frame to control the camera movement/direction.\r\n */\r\nexport type WebXRControllerMovementFeatureContext = {\r\n movementEnabled: boolean;\r\n movementOrientationFollowsViewerPose: boolean;\r\n movementOrientationFollowsController: boolean;\r\n orientationPreferredHandedness?: XRHandedness;\r\n movementSpeed: number;\r\n movementThreshold: number;\r\n rotationEnabled: boolean;\r\n rotationSpeed: number;\r\n rotationThreshold: number;\r\n};\r\n\r\n/**\r\n * Current state of Movements shared across components and handlers.\r\n */\r\nexport type WebXRControllerMovementState = {\r\n moveX: number;\r\n moveY: number;\r\n rotateX: number;\r\n rotateY: number;\r\n};\r\n\r\n/**\r\n * Button of Axis Handler must be specified.\r\n */\r\nexport type WebXRControllerMovementRegistrationConfiguration = {\r\n /**\r\n * handlers are filtered to these types only\r\n */\r\n allowedComponentTypes?: MotionControllerComponentType[];\r\n /**\r\n * For registering movement to specific hand only. Useful if your app has a \"main hand\" and \"off hand\" for determining the functionality of a controller.\r\n */\r\n forceHandedness?: XRHandedness;\r\n /**\r\n * For main component only (useful for buttons and may not trigger axis changes).\r\n */\r\n mainComponentOnly?: boolean;\r\n /**\r\n * Additional predicate to apply to controllers to restrict a handler being added.\r\n */\r\n componentSelectionPredicate?: (xrController: WebXRInputSource) => Nullable<WebXRControllerComponent>;\r\n} & (\r\n | {\r\n /**\r\n * Called when axis changes occur.\r\n */\r\n axisChangedHandler: (\r\n axes: IWebXRMotionControllerAxesValue,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n | {\r\n /**\r\n * Called when the button state changes.\r\n */\r\n buttonChangedHandler: (\r\n pressed: IWebXRMotionControllerComponentChangesValues<boolean>,\r\n movementState: WebXRControllerMovementState,\r\n featureContext: WebXRControllerMovementFeatureContext,\r\n xrInput: WebXRInput\r\n ) => void;\r\n }\r\n);\r\n\r\ntype RegisteredComponent = {\r\n registrationConfiguration: WebXRControllerMovementRegistrationConfiguration;\r\n component: WebXRControllerComponent;\r\n onAxisChangedObserver?: Nullable<Observer<IWebXRMotionControllerAxesValue>>;\r\n onButtonChangedObserver?: Nullable<Observer<WebXRControllerComponent>>;\r\n};\r\n\r\n/**\r\n * This is a movement feature to be used with WebXR-enabled motion controllers.\r\n * When enabled and attached, the feature will allow a user to move around and rotate in the scene using\r\n * the input of the attached controllers.\r\n */\r\nexport class WebXRControllerMovement extends WebXRAbstractFeature {\r\n private _controllers: {\r\n [controllerUniqueId: string]: {\r\n xrController: WebXRInputSource;\r\n registeredComponents: RegisteredComponent[];\r\n };\r\n } = {};\r\n\r\n private _currentRegistrationConfigurations: WebXRControllerMovementRegistrationConfiguration[] = [];\r\n // Feature configuration is synchronized - this is passed to all handlers (reduce GC pressure).\r\n private _featureContext: WebXRControllerMovementFeatureContext;\r\n // forward direction for movement, which may differ from viewer pose.\r\n private _movementDirection: Quaternion = new Quaternion();\r\n private _movementState: WebXRControllerMovementState;\r\n private _xrInput: WebXRInput;\r\n\r\n // unused\r\n private _tmpRotationMatrix: Matrix = Matrix.Identity();\r\n private _tmpTranslationDirection: Vector3 = new Vector3();\r\n private _tmpMovementTranslation: Vector3 = new Vector3();\r\n private _tempCacheQuaternion: Quaternion = new Quaternion();\r\n\r\n /**\r\n * The module's name\r\n */\r\n public static readonly Name = WebXRFeatureName.MOVEMENT;\r\n\r\n /**\r\n * Standard controller configurations.\r\n */\r\n public static readonly REGISTRATIONS: { [key: string]: WebXRControllerMovementRegistrationConfiguration[] } = {\r\n default: [\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"left\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.rotateX = Math.abs(axes.x) > featureContext.rotationThreshold ? axes.x : 0;\r\n movementState.rotateY = Math.abs(axes.y) > featureContext.rotationThreshold ? axes.y : 0;\r\n },\r\n },\r\n {\r\n allowedComponentTypes: [WebXRControllerComponent.THUMBSTICK_TYPE, WebXRControllerComponent.TOUCHPAD_TYPE],\r\n forceHandedness: \"right\",\r\n axisChangedHandler: (axes: IWebXRMotionControllerAxesValue, movementState: WebXRControllerMovementState, featureContext: WebXRControllerMovementFeatureContext) => {\r\n movementState.moveX = Math.abs(axes.x) > featureContext.movementThreshold ? axes.x : 0;\r\n movementState.moveY = Math.abs(axes.y) > featureContext.movementThreshold ? axes.y : 0;\r\n },\r\n },\r\n ],\r\n };\r\n\r\n /**\r\n * The (Babylon) version of this module.\r\n * This is an integer representing the implementation version.\r\n * This number does not correspond to the webxr specs version\r\n */\r\n public static readonly Version = 1;\r\n\r\n /**\r\n * Current movement direction. Will be null before XR Frames have been processed.\r\n */\r\n public get movementDirection(): Quaternion {\r\n return this._movementDirection;\r\n }\r\n\r\n /**\r\n * Is movement enabled\r\n */\r\n public get movementEnabled(): boolean {\r\n return this._featureContext.movementEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether movement is enabled or not\r\n * @param enabled is movement enabled\r\n */\r\n public set movementEnabled(enabled: boolean) {\r\n this._featureContext.movementEnabled = enabled;\r\n }\r\n\r\n /**\r\n * If movement follows viewer pose\r\n */\r\n public get movementOrientationFollowsViewerPose(): boolean {\r\n return this._featureContext.movementOrientationFollowsViewerPose;\r\n }\r\n\r\n /**\r\n * Sets whether movement follows viewer pose\r\n * @param followsPose is movement should follow viewer pose\r\n */\r\n public set movementOrientationFollowsViewerPose(followsPose: boolean) {\r\n this._featureContext.movementOrientationFollowsViewerPose = followsPose;\r\n }\r\n\r\n /**\r\n * Gets movement speed\r\n */\r\n public get movementSpeed(): number {\r\n return this._featureContext.movementSpeed;\r\n }\r\n\r\n /**\r\n * Sets movement speed\r\n * @param movementSpeed movement speed\r\n */\r\n public set movementSpeed(movementSpeed: number) {\r\n this._featureContext.movementSpeed = movementSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n */\r\n public get movementThreshold(): number {\r\n return this._featureContext.movementThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for movement (avoids jitter/unintentional movement)\r\n * @param movementThreshold new threshold\r\n */\r\n public set movementThreshold(movementThreshold: number) {\r\n this._featureContext.movementThreshold = movementThreshold;\r\n }\r\n\r\n /**\r\n * Is rotation enabled\r\n */\r\n public get rotationEnabled(): boolean {\r\n return this._featureContext.rotationEnabled;\r\n }\r\n\r\n /**\r\n * Sets whether rotation is enabled or not\r\n * @param enabled is rotation enabled\r\n */\r\n public set rotationEnabled(enabled: boolean) {\r\n this._featureContext.rotationEnabled = enabled;\r\n }\r\n\r\n /**\r\n * Gets rotation speed factor\r\n */\r\n public get rotationSpeed(): number {\r\n return this._featureContext.rotationSpeed;\r\n }\r\n\r\n /**\r\n * Sets rotation speed factor (1.0 is default)\r\n * @param rotationSpeed new rotation speed factor\r\n */\r\n public set rotationSpeed(rotationSpeed: number) {\r\n this._featureContext.rotationSpeed = rotationSpeed;\r\n }\r\n\r\n /**\r\n * Gets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n */\r\n public get rotationThreshold(): number {\r\n return this._featureContext.rotationThreshold;\r\n }\r\n\r\n /**\r\n * Sets minimum threshold the controller's thumbstick/touchpad must pass before being recognized for rotation (avoids jitter/unintentional rotation)\r\n * @param threshold new threshold\r\n */\r\n public set rotationThreshold(threshold: number) {\r\n this._featureContext.rotationThreshold = threshold;\r\n }\r\n /**\r\n * constructs a new movement controller system\r\n * @param _xrSessionManager an instance of WebXRSessionManager\r\n * @param options configuration object for this feature\r\n */\r\n constructor(_xrSessionManager: WebXRSessionManager, options: IWebXRControllerMovementOptions) {\r\n super(_xrSessionManager);\r\n\r\n if (!options || options.xrInput === undefined) {\r\n Tools.Error('WebXRControllerMovement feature requires \"xrInput\" option.');\r\n return;\r\n }\r\n\r\n if (Array.isArray(options.customRegistrationConfigurations)) {\r\n this._currentRegistrationConfigurations = options.customRegistrationConfigurations;\r\n } else {\r\n this._currentRegistrationConfigurations = WebXRControllerMovement.REGISTRATIONS.default;\r\n }\r\n\r\n // synchronized from feature setter properties\r\n this._featureContext = {\r\n movementEnabled: options.movementEnabled ?? true,\r\n movementOrientationFollowsViewerPose: options.movementOrientationFollowsViewerPose ?? true,\r\n movementOrientationFollowsController: options.movementOrientationFollowsController ?? false,\r\n orientationPreferredHandedness: options.orientationPreferredHandedness,\r\n movementSpeed: options.movementSpeed ?? 1,\r\n movementThreshold: options.movementThreshold ?? 0.25,\r\n rotationEnabled: options.rotationEnabled ?? true,\r\n rotationSpeed: options.rotationSpeed ?? 1.0,\r\n rotationThreshold: options.rotationThreshold ?? 0.25,\r\n };\r\n\r\n this._movementState = {\r\n moveX: 0,\r\n moveY: 0,\r\n rotateX: 0,\r\n rotateY: 0,\r\n };\r\n\r\n this._xrInput = options.xrInput;\r\n }\r\n\r\n public override attach(): boolean {\r\n if (!super.attach()) {\r\n return false;\r\n }\r\n\r\n for (const controller of this._xrInput.controllers) {\r\n this._attachController(controller);\r\n }\r\n this._addNewAttachObserver(this._xrInput.onControllerAddedObservable, this._attachController);\r\n this._addNewAttachObserver(this._xrInput.onControllerRemovedObservable, (controller: WebXRInputSource) => {\r\n // REMOVE the controller\r\n this._detachController(controller.uniqueId);\r\n });\r\n\r\n return true;\r\n }\r\n\r\n public override detach(): boolean {\r\n if (!super.detach()) {\r\n return false;\r\n }\r\n const keys = Object.keys(this._controllers);\r\n\r\n for (const controllerId of keys) {\r\n this._detachController(controllerId);\r\n }\r\n\r\n this._controllers = {};\r\n\r\n return true;\r\n }\r\n\r\n /**\r\n * Occurs on every XR frame.\r\n * @param _xrFrame\r\n */\r\n protected _onXRFrame(_xrFrame: XRFrame) {\r\n if (!this.attached) {\r\n return;\r\n }\r\n\r\n if (this._movementState.rotateX !== 0 && this._featureContext.rotationEnabled) {\r\n // smooth rotation\r\n const deltaMillis = this._xrSessionManager.scene.getEngine().getDeltaTime();\r\n const rotationY = deltaMillis * 0.001 * this._featureContext.rotationSpeed * this._movementState.rotateX * (this._xrSessionManager.scene.useRightHandedSystem ? -1 : 1);\r\n\r\n if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n this._xrInput.xrCamera.rotationQuaternion.multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else if (this._featureContext.movementOrientationFollowsController) {\r\n this._xrInput.xrCamera.cameraRotation.y += rotationY;\r\n // get the correct controller\r\n const handedness = this._featureContext.orientationPreferredHandedness || \"right\";\r\n const key =\r\n Object.keys(this._controllers).find((key) => this._controllers[key]?.xrController?.inputSource.handedness === handedness) || Object.keys(this._controllers)[0];\r\n const controller = this._controllers[key];\r\n Quaternion.RotationYawPitchRollToRef(rotationY, 0, 0, this._tempCacheQuaternion);\r\n (controller?.xrController.pointer.rotationQuaternion || Quaternion.Identity()).multiplyToRef(this._tempCacheQuaternion, this._movementDirection);\r\n } else {\r\n // movement orientation direction does not affect camera. We use rotation speed multiplier\r\n // otherwise need to implement inertia and constraints for same feel as TargetCamera.\r\n\r\n Quaternion.RotationYawPitchRollToRef(rotationY * 3.0, 0, 0, this._tempCacheQuaternion);\r\n this._movementDirection.multiplyInPlace(this._tempCacheQuaternion);\r\n }\r\n } else if (this._featureContext.movementOrientationFollowsViewerPose) {\r\n this._movementDirection.copyFrom(this._xrInput.xrCamera.rotationQuaternion);\r\n } else if (this._featureContext.movementOrientationFollowsController) {\r\n // get the correct controller\r\n const handedness = this._featureContext.orientationPreferredHandedness || \"right\";\r\n const key =\r\n Object.keys(this._controllers).find((key) => this._controllers[key]?.xrController.inputSource.handedness === handedness) || Object.keys(this._controllers)[0];\r\n const controller = this._controllers[key];\r\n this._movementDirection.copyFrom(controller?.xrController.pointer.rotationQuaternion || Quaternion.Identity());\r\n }\r\n\r\n if ((this._movementState.moveX || this._movementState.moveY) && this._featureContext.movementEnabled) {\r\n Matrix.FromQuaternionToRef(this._movementDirection, this._tmpRotationMatrix);\r\n this._tmpTranslationDirection.set(this._movementState.moveX, 0, this._movementState.moveY * (this._xrSessionManager.scene.useRightHandedSystem ? 1.0 : -1.0));\r\n // move according to forward direction based on camera speed\r\n Vector3.TransformCoordinatesToRef(this._tmpTranslationDirection, this._tmpRotationMatrix, this._tmpMovementTranslation);\r\n this._tmpMovementTranslation.scaleInPlace(this._xrInput.xrCamera._computeLocalCameraSpeed() * this._featureContext.movementSpeed);\r\n\r\n this._xrInput.xrCamera.cameraDirection.addInPlace(this._tmpMovementTranslation);\r\n }\r\n }\r\n\r\n private _attachController = (xrController: WebXRInputSource) => {\r\n if (this._controllers[xrController.uniqueId]) {\r\n // already attached\r\n return;\r\n }\r\n\r\n this._controllers[xrController.uniqueId] = {\r\n xrController,\r\n registeredComponents: [],\r\n };\r\n const controllerData = this._controllers[xrController.uniqueId];\r\n\r\n // movement controller only available to gamepad-enabled input sources.\r\n if (controllerData.xrController.inputSource.targetRayMode === \"tracked-pointer\" && controllerData.xrController.inputSource.gamepad) {\r\n // motion controller support\r\n const initController = () => {\r\n if (xrController.motionController) {\r\n for (const registration of this._currentRegistrationConfigurations) {\r\n let component: Nullable<WebXRControllerComponent> = null;\r\n\r\n if (registration.allowedComponentTypes) {\r\n for (const componentType of registration.allowedComponentTypes) {\r\n const componentOfType = xrController.motionController.getComponentOfType(componentType);\r\n if (componentOfType !== null) {\r\n component = componentOfType;\r\n break;\r\n }\r\n }\r\n }\r\n\r\n if (registration.mainComponentOnly) {\r\n const mainComponent = xrController.motionController.getMainComponent();\r\n if (mainComponent === null) {\r\n continue;\r\n }\r\n component = mainComponent;\r\n }\r\n\r\n if (typeof registration.componentSelectionPredicate === \"function\") {\r\n // if does not match we do want to ignore a previously found component\r\n component = registration.componentSelectionPredicate(xrController);\r\n }\r\n\r\n if (component && registration.forceHandedness) {\r\n if (xrController.inputSource.handedness !== registration.forceHandedness) {\r\n continue; // do not register\r\n }\r\n }\r\n\r\n if (component === null) {\r\n continue; // do not register\r\n }\r\n\r\n const registeredComponent: RegisteredComponent = {\r\n registrationConfiguration: registration,\r\n component,\r\n };\r\n controllerData.registeredComponents.push(registeredComponent);\r\n\r\n if (\"axisChangedHandler\" in registration) {\r\n registeredComponent.onAxisChangedObserver = component.onAxisValueChangedObservable.add((axesData) => {\r\n registration.axisChangedHandler(axesData, this._movementState, this._featureContext, this._xrInput);\r\n });\r\n }\r\n\r\n if (\"buttonChangedHandler\" in registration) {\r\n registeredComponent.onButtonChangedObserver = component.onButtonStateChangedObservable.add((component) => {\r\n if (component.changes.pressed) {\r\n registration.buttonChangedHandler(component.changes.pressed, this._movementState, this._featureContext, this._xrInput);\r\n }\r\n });\r\n }\r\n }\r\n }\r\n };\r\n\r\n if (xrController.motionController) {\r\n initController();\r\n } else {\r\n xrController.onMotionControllerInitObservable.addOnce(() => {\r\n initController();\r\n });\r\n }\r\n }\r\n };\r\n\r\n private _detachController(xrControllerUniqueId: string) {\r\n const controllerData = this._controllers[xrControllerUniqueId];\r\n if (!controllerData) {\r\n return;\r\n }\r\n\r\n for (const registeredComponent of controllerData.registeredComponents) {\r\n if (registeredComponent.onAxisChangedObserver) {\r\n registeredComponent.component.onAxisValueChangedObservable.remove(registeredComponent.onAxisChangedObserver);\r\n }\r\n if (registeredComponent.onButtonChangedObserver) {\r\n registeredComponent.component.onButtonStateChangedObservable.remove(registeredComponent.onButtonChangedObserver);\r\n }\r\n }\r\n\r\n // remove from the map\r\n delete this._controllers[xrControllerUniqueId];\r\n }\r\n}\r\n\r\nWebXRFeaturesManager.AddWebXRFeature(\r\n WebXRControllerMovement.Name,\r\n (xrSessionManager, options) => {\r\n return () => new WebXRControllerMovement(xrSessionManager, options);\r\n },\r\n WebXRControllerMovement.Version,\r\n true\r\n);\r\n"]}
|
package/package.json
CHANGED
package/scene.d.ts
CHANGED
|
@@ -594,10 +594,6 @@ export declare class Scene implements IAnimatable, IClipPlanesHolder, IAssetCont
|
|
|
594
594
|
* An event triggered when a multi material is created
|
|
595
595
|
*/
|
|
596
596
|
onNewMultiMaterialAddedObservable: Observable<MultiMaterial>;
|
|
597
|
-
/**
|
|
598
|
-
* An event triggered when a post process is created
|
|
599
|
-
*/
|
|
600
|
-
onNewPostProcessAddedObservable: Observable<PostProcess>;
|
|
601
597
|
/**
|
|
602
598
|
* An event triggered when a material is removed
|
|
603
599
|
*/
|
|
@@ -622,10 +618,22 @@ export declare class Scene implements IAnimatable, IClipPlanesHolder, IAssetCont
|
|
|
622
618
|
* An event triggered when a frame graph is removed
|
|
623
619
|
*/
|
|
624
620
|
onFrameGraphRemovedObservable: Observable<FrameGraph>;
|
|
621
|
+
/**
|
|
622
|
+
* An event triggered when a post process is created
|
|
623
|
+
*/
|
|
624
|
+
onNewPostProcessAddedObservable: Observable<PostProcess>;
|
|
625
625
|
/**
|
|
626
626
|
* An event triggered when a post process is removed
|
|
627
627
|
*/
|
|
628
628
|
onPostProcessRemovedObservable: Observable<PostProcess>;
|
|
629
|
+
/**
|
|
630
|
+
* An event triggered when an effect layer is created
|
|
631
|
+
*/
|
|
632
|
+
onNewEffectLayerAddedObservable: Observable<EffectLayer>;
|
|
633
|
+
/**
|
|
634
|
+
* An event triggered when an effect layer is removed
|
|
635
|
+
*/
|
|
636
|
+
onEffectLayerRemovedObservable: Observable<EffectLayer>;
|
|
629
637
|
/**
|
|
630
638
|
* An event triggered when render targets are about to be rendered
|
|
631
639
|
* Can happen multiple times per frame.
|
|
@@ -1673,6 +1681,12 @@ export declare class Scene implements IAnimatable, IClipPlanesHolder, IAssetCont
|
|
|
1673
1681
|
* @returns The index of the removed post-process
|
|
1674
1682
|
*/
|
|
1675
1683
|
removePostProcess(toRemove: PostProcess): number;
|
|
1684
|
+
/**
|
|
1685
|
+
* Removes the given layer from this scene.
|
|
1686
|
+
* @param toRemove The layer to remove
|
|
1687
|
+
* @returns The index of the removed layer
|
|
1688
|
+
*/
|
|
1689
|
+
removeEffectLayer(toRemove: EffectLayer): number;
|
|
1676
1690
|
/**
|
|
1677
1691
|
* Adds the given light to this scene
|
|
1678
1692
|
* @param newLight The light to add
|
|
@@ -1748,6 +1762,11 @@ export declare class Scene implements IAnimatable, IClipPlanesHolder, IAssetCont
|
|
|
1748
1762
|
* @param newPostProcess The post process to add
|
|
1749
1763
|
*/
|
|
1750
1764
|
addPostProcess(newPostProcess: PostProcess): void;
|
|
1765
|
+
/**
|
|
1766
|
+
* Adds the given effect layer to this scene.
|
|
1767
|
+
* @param newEffectLayer The effect layer to add
|
|
1768
|
+
*/
|
|
1769
|
+
addEffectLayer(newEffectLayer: EffectLayer): void;
|
|
1751
1770
|
/**
|
|
1752
1771
|
* Switch active camera
|
|
1753
1772
|
* @param newCamera defines the new active camera
|