@babylonjs/core 8.46.2 → 8.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/constants.d.ts +1 -1
- package/Engines/constants.js +1 -1
- package/Engines/constants.js.map +1 -1
- package/Lights/areaLight.d.ts +1 -1
- package/Lights/areaLight.js +1 -1
- package/Lights/areaLight.js.map +1 -1
- package/Lights/rectAreaLight.d.ts +20 -0
- package/Lights/rectAreaLight.js +45 -0
- package/Lights/rectAreaLight.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js +6 -3
- package/Materials/Node/Blocks/Fragment/imageProcessingBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/material.d.ts +1 -1
- package/Materials/material.js +1 -1
- package/Materials/material.js.map +1 -1
- package/Materials/materialHelper.functions.d.ts +2 -1
- package/Materials/materialHelper.functions.js +6 -2
- package/Materials/materialHelper.functions.js.map +1 -1
- package/Materials/materialPluginManager.js +2 -2
- package/Materials/materialPluginManager.js.map +1 -1
- package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js +1 -5
- package/Misc/HighDynamicRange/cubemapToSphericalPolynomial.js.map +1 -1
- package/Misc/areaLightsTextureTools.d.ts +52 -0
- package/Misc/areaLightsTextureTools.js +227 -0
- package/Misc/areaLightsTextureTools.js.map +1 -0
- package/Misc/decorators.serialization.js +6 -1
- package/Misc/decorators.serialization.js.map +1 -1
- package/Misc/index.d.ts +3 -0
- package/Misc/index.js +4 -0
- package/Misc/index.js.map +1 -1
- package/Particles/Node/Blocks/particleSourceTextureBlock.d.ts +4 -0
- package/Particles/Node/Blocks/particleSourceTextureBlock.js +9 -3
- package/Particles/Node/Blocks/particleSourceTextureBlock.js.map +1 -1
- package/Particles/Node/nodeParticleSystemSet.d.ts +2 -0
- package/Particles/Node/nodeParticleSystemSet.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +1 -0
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +10 -0
- package/Physics/v2/Plugins/havokPlugin.js +13 -0
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +10 -0
- package/Physics/v2/physicsBody.js +12 -0
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsEngineComponent.d.ts +5 -0
- package/Physics/v2/physicsEngineComponent.js +13 -0
- package/Physics/v2/physicsEngineComponent.js.map +1 -1
- package/Rendering/utilityLayerRenderer.d.ts +6 -0
- package/Rendering/utilityLayerRenderer.js +14 -5
- package/Rendering/utilityLayerRenderer.js.map +1 -1
- package/Shaders/ShadersInclude/lightFragment.js +13 -0
- package/Shaders/ShadersInclude/lightFragment.js.map +1 -1
- package/Shaders/ShadersInclude/lightFragmentDeclaration.js +3 -0
- package/Shaders/ShadersInclude/lightFragmentDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/lightUboDeclaration.js +3 -0
- package/Shaders/ShadersInclude/lightUboDeclaration.js.map +1 -1
- package/Shaders/ShadersInclude/lightsFragmentFunctions.js +6 -0
- package/Shaders/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/ltcHelperFunctions.js +17 -1
- package/Shaders/ShadersInclude/ltcHelperFunctions.js.map +1 -1
- package/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.js +6 -0
- package/Shaders/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
- package/Shaders/areaLightTextureProcessing.fragment.d.ts +5 -0
- package/Shaders/areaLightTextureProcessing.fragment.js +13 -0
- package/Shaders/areaLightTextureProcessing.fragment.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/lightFragment.js +14 -0
- package/ShadersWGSL/ShadersInclude/lightFragment.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js +3 -0
- package/ShadersWGSL/ShadersInclude/lightUboDeclaration.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js +6 -0
- package/ShadersWGSL/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/ltcHelperFunctions.js +19 -1
- package/ShadersWGSL/ShadersInclude/ltcHelperFunctions.js.map +1 -1
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js +5 -0
- package/ShadersWGSL/ShadersInclude/pbrDirectLightingSetupFunctions.js.map +1 -1
- package/ShadersWGSL/areaLightTextureProcessing.fragment.d.ts +5 -0
- package/ShadersWGSL/areaLightTextureProcessing.fragment.js +12 -0
- package/ShadersWGSL/areaLightTextureProcessing.fragment.js.map +1 -0
- package/ShadersWGSL/iblVoxelGrid.vertex.js +2 -2
- package/ShadersWGSL/iblVoxelGrid.vertex.js.map +1 -1
- package/States/alphaCullingState.js +0 -1
- package/States/alphaCullingState.js.map +1 -1
- package/package.json +1 -1
|
@@ -313,6 +313,16 @@ export declare class PhysicsBody {
|
|
|
313
313
|
* @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.
|
|
314
314
|
*/
|
|
315
315
|
applyAngularImpulse(angularImpulse: Vector3, instanceIndex?: number): void;
|
|
316
|
+
/**
|
|
317
|
+
* Applies a torque to the physics body.
|
|
318
|
+
*
|
|
319
|
+
* @param torque The torque vector.
|
|
320
|
+
* @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.
|
|
321
|
+
*
|
|
322
|
+
* This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,
|
|
323
|
+
* angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.
|
|
324
|
+
*/
|
|
325
|
+
applyTorque(torque: Vector3, instanceIndex?: number): void;
|
|
316
326
|
/**
|
|
317
327
|
* Applies a force to the physics object.
|
|
318
328
|
*
|
|
@@ -406,6 +406,18 @@ export class PhysicsBody {
|
|
|
406
406
|
applyAngularImpulse(angularImpulse, instanceIndex) {
|
|
407
407
|
this._physicsPlugin.applyAngularImpulse(this, angularImpulse, instanceIndex);
|
|
408
408
|
}
|
|
409
|
+
/**
|
|
410
|
+
* Applies a torque to the physics body.
|
|
411
|
+
*
|
|
412
|
+
* @param torque The torque vector.
|
|
413
|
+
* @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.
|
|
414
|
+
*
|
|
415
|
+
* This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,
|
|
416
|
+
* angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.
|
|
417
|
+
*/
|
|
418
|
+
applyTorque(torque, instanceIndex) {
|
|
419
|
+
this._physicsPlugin.applyTorque(this, torque, instanceIndex);
|
|
420
|
+
}
|
|
409
421
|
/**
|
|
410
422
|
* Applies a force to the physics object.
|
|
411
423
|
*
|
|
@@ -1 +1 @@
|
|
|
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,kBAAkB,CAAC,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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"]}
|
|
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,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,QAAQ,CAAC;IAC1F,CAAC;IAmBD;;;;;;;;;;;;;OAaG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,YAAqB,EAAE,KAAY;QAxE5G;;WAEG;QACI,gBAAW,GAAQ,SAAS,CAAC;QACpC;;WAEG;QACI,yBAAoB,GAAe,EAAE,CAAC;QAS7C;;WAEG;QACK,wBAAmB,GAAY,KAAK,CAAC;QAC7C;;WAEG;QACK,6BAAwB,GAAY,KAAK,CAAC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AAI,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 torque to the physics body.\r\n *\r\n * @param torque The torque vector.\r\n * @param instanceIndex For a instanced body, the instance to where the torque should be applied. If not specified, the torque is applied to all instances.\r\n *\r\n * This method is useful for applying a torque to a physics body, which can be used to simulate rotational forces such as motors,\r\n * angular momentum, and rotational dynamics. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyTorque(torque: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyTorque(this, torque, instanceIndex);\r\n }\r\n\r\n /**\r\n * Applies a force to the physics object.\r\n *\r\n * @param force The force vector.\r\n * @param location The location of the force.\r\n * @param instanceIndex For a instanced body, the instance to where the force should be applied. If not specified, the force is applied to all instances.\r\n *\r\n * This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,\r\n * collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.\r\n */\r\n public applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void {\r\n this._physicsPlugin.applyForce(this, force, location, instanceIndex);\r\n }\r\n\r\n /**\r\n * Retrieves the geometry of the body from the physics plugin.\r\n *\r\n * @returns The geometry of the body.\r\n *\r\n * This method is useful for retrieving the geometry of the body from the physics plugin, which can be used for various physics calculations.\r\n */\r\n public getGeometry(): object {\r\n return this._physicsPlugin.getBodyGeometry(this);\r\n }\r\n\r\n /**\r\n * Returns an observable that will be notified for when a collision starts or continues for this PhysicsBody\r\n * @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"]}
|
|
@@ -27,6 +27,11 @@ declare module "../../Meshes/transformNode.js" {
|
|
|
27
27
|
* @returns the current mesh
|
|
28
28
|
*/
|
|
29
29
|
applyAngularImpulse(angularImpulse: Vector3): TransformNode;
|
|
30
|
+
/** Apply a physic torque to the mesh
|
|
31
|
+
* @param torque defines the torque to apply
|
|
32
|
+
* @returns the current mesh
|
|
33
|
+
*/
|
|
34
|
+
applyTorque(torque: Vector3): TransformNode;
|
|
30
35
|
/** @internal */
|
|
31
36
|
_disposePhysicsObserver: Nullable<Observer<Node>>;
|
|
32
37
|
}
|
|
@@ -59,4 +59,17 @@ TransformNode.prototype.applyAngularImpulse = function (angularImpulse) {
|
|
|
59
59
|
this.physicsBody.applyAngularImpulse(angularImpulse);
|
|
60
60
|
return this;
|
|
61
61
|
};
|
|
62
|
+
/**
|
|
63
|
+
* Apply a physic torque to the mesh
|
|
64
|
+
* @param torque defines the torque to apply
|
|
65
|
+
* @returns the current mesh
|
|
66
|
+
* @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
|
|
67
|
+
*/
|
|
68
|
+
TransformNode.prototype.applyTorque = function (torque) {
|
|
69
|
+
if (!this.physicsBody) {
|
|
70
|
+
throw new Error("No Physics Body for TransformNode");
|
|
71
|
+
}
|
|
72
|
+
this.physicsBody.applyTorque(torque);
|
|
73
|
+
return this;
|
|
74
|
+
};
|
|
62
75
|
//# sourceMappingURL=physicsEngineComponent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsEngineComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D,OAAO,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"physicsEngineComponent.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsEngineComponent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAI3D,OAAO,iCAAiC,CAAC;AA0CzC,MAAM,CAAC,cAAc,CAAC,aAAa,CAAC,SAAS,EAAE,aAAa,EAAE;IAC1D,GAAG,EAAE;QACD,OAAO,IAAI,CAAC,YAAY,CAAC;IAC7B,CAAC;IACD,GAAG,EAAE,UAA+B,KAA4B;QAC5D,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;YAC9B,OAAO;QACX,CAAC;QACD,IAAI,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC/B,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAClE,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAE1B,IAAI,KAAK,EAAE,CAAC;YACR,IAAI,CAAC,uBAAuB,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,GAAG,EAAE;gBAC7D,UAAU;gBACV,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;oBACnB,IAAI,CAAC,WAAW,CAAC,OAA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\"../../Misc/observable\";\r\nimport type { Vector3 } from \"../../Maths/math.vector\";\r\nimport { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { Node } from \"../../node\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\n\r\nimport \"../joinedPhysicsEngineComponent\";\r\n\r\ndeclare module \"../../Meshes/transformNode\" {\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n export interface TransformNode {\r\n /** @internal */\r\n _physicsBody: Nullable<PhysicsBody>;\r\n\r\n /**\r\n * @see\r\n */\r\n physicsBody: Nullable<PhysicsBody>;\r\n\r\n /**\r\n *\r\n */\r\n getPhysicsBody(): Nullable<PhysicsBody>;\r\n\r\n /** Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n */\r\n applyImpulse(force: Vector3, contactPoint: Vector3): TransformNode;\r\n\r\n /** Apply a physic angular impulse to the mesh\r\n * @param angularImpulse defines the torque to apply\r\n * @returns the current mesh\r\n */\r\n applyAngularImpulse(angularImpulse: Vector3): TransformNode;\r\n\r\n /** Apply a physic torque to the mesh\r\n * @param torque defines the torque to apply\r\n * @returns the current mesh\r\n */\r\n applyTorque(torque: Vector3): TransformNode;\r\n\r\n /** @internal */\r\n _disposePhysicsObserver: Nullable<Observer<Node>>;\r\n }\r\n}\r\n\r\nObject.defineProperty(TransformNode.prototype, \"physicsBody\", {\r\n get: function (this: TransformNode) {\r\n return this._physicsBody;\r\n },\r\n set: function (this: TransformNode, value: Nullable<PhysicsBody>) {\r\n if (this._physicsBody === value) {\r\n return;\r\n }\r\n if (this._disposePhysicsObserver) {\r\n this.onDisposeObservable.remove(this._disposePhysicsObserver);\r\n }\r\n\r\n this._physicsBody = value;\r\n\r\n if (value) {\r\n this._disposePhysicsObserver = this.onDisposeObservable.add(() => {\r\n // Physics\r\n if (this.physicsBody) {\r\n this.physicsBody.dispose(/*!doNotRecurse*/);\r\n this.physicsBody = null;\r\n }\r\n });\r\n }\r\n },\r\n enumerable: true,\r\n configurable: true,\r\n});\r\n\r\n/**\r\n * Gets the current physics body\r\n * @returns a physics body or null\r\n */\r\nTransformNode.prototype.getPhysicsBody = function (): Nullable<PhysicsBody> {\r\n return this.physicsBody;\r\n};\r\n\r\n/**\r\n * Apply a physic impulse to the mesh\r\n * @param force defines the force to apply\r\n * @param contactPoint defines where to apply the force\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyImpulse = function (force: Vector3, contactPoint: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyImpulse(force, contactPoint);\r\n return this;\r\n};\r\n\r\n/**\r\n * Apply a physic angular impulse to the mesh\r\n * @param angularImpulse defines the torque to apply\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyAngularImpulse = function (angularImpulse: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyAngularImpulse(angularImpulse);\r\n return this;\r\n};\r\n\r\n/**\r\n * Apply a physic torque to the mesh\r\n * @param torque defines the torque to apply\r\n * @returns the current mesh\r\n * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine\r\n */\r\nTransformNode.prototype.applyTorque = function (torque: Vector3): TransformNode {\r\n if (!this.physicsBody) {\r\n throw new Error(\"No Physics Body for TransformNode\");\r\n }\r\n this.physicsBody.applyTorque(torque);\r\n return this;\r\n};\r\n"]}
|
|
@@ -54,6 +54,12 @@ export declare class UtilityLayerRenderer implements IDisposable {
|
|
|
54
54
|
* A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)
|
|
55
55
|
*/
|
|
56
56
|
static get DefaultKeepDepthUtilityLayer(): UtilityLayerRenderer;
|
|
57
|
+
/**
|
|
58
|
+
* Creates an utility layer, and set it as a default utility layer (Depth map of the previous scene is not cleared before drawing on top of it)
|
|
59
|
+
* @param scene associated scene
|
|
60
|
+
* @internal
|
|
61
|
+
*/
|
|
62
|
+
static _CreateDefaultKeepUtilityLayerFromScene(scene: Scene): UtilityLayerRenderer;
|
|
57
63
|
/**
|
|
58
64
|
* The scene that is rendered on top of the original scene
|
|
59
65
|
*/
|
|
@@ -78,14 +78,23 @@ export class UtilityLayerRenderer {
|
|
|
78
78
|
*/
|
|
79
79
|
static get DefaultKeepDepthUtilityLayer() {
|
|
80
80
|
if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {
|
|
81
|
-
UtilityLayerRenderer.
|
|
82
|
-
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
|
|
83
|
-
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {
|
|
84
|
-
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;
|
|
85
|
-
});
|
|
81
|
+
return UtilityLayerRenderer._CreateDefaultKeepUtilityLayerFromScene(EngineStore.LastCreatedScene);
|
|
86
82
|
}
|
|
87
83
|
return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;
|
|
88
84
|
}
|
|
85
|
+
/**
|
|
86
|
+
* Creates an utility layer, and set it as a default utility layer (Depth map of the previous scene is not cleared before drawing on top of it)
|
|
87
|
+
* @param scene associated scene
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
static _CreateDefaultKeepUtilityLayerFromScene(scene) {
|
|
91
|
+
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(scene);
|
|
92
|
+
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;
|
|
93
|
+
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {
|
|
94
|
+
UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;
|
|
95
|
+
});
|
|
96
|
+
return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;
|
|
97
|
+
}
|
|
89
98
|
/**
|
|
90
99
|
* Instantiates a UtilityLayerRenderer
|
|
91
100
|
* @param originalScene the original scene that will be rendered on top of
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilityLayerRenderer.js","sourceRoot":"","sources":["../../../../dev/core/src/Rendering/utilityLayerRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAW7B;;;;OAIG;IACI,eAAe,CAAC,sBAAgC;QACnD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,aAAa,CAAC;QAC9B,CAAC;aAAM,CAAC;YACJ,IAAI,SAAiB,CAAC;YACtB,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClF,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC9F,CAA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AiB,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;AArYD,gBAAgB;AACF,yCAAoB,GAAmC,IAAI,AAAvC,CAAwC;AAC1E,gBAAgB;AACF,kDAA6B,GAAmC,IAAI,AAAvC,CAAwC","sourcesContent":["import type { IDisposable } from \"../scene\";\r\nimport { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { PointerInfoPre } from \"../Events/pointerEvents\";\r\nimport { PointerInfo, PointerEventTypes } from \"../Events/pointerEvents\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { HemisphericLight } from \"../Lights/hemisphericLight\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { IPointerEvent } from \"../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Renders a layer on top of an existing scene\r\n */\r\nexport class UtilityLayerRenderer implements IDisposable {\r\n private _pointerCaptures: { [pointerId: number]: boolean } = {};\r\n private _lastPointerEvents: { [pointerId: number]: boolean } = {};\r\n /** @internal */\r\n public static _DefaultUtilityLayer: Nullable<UtilityLayerRenderer> = null;\r\n /** @internal */\r\n public static _DefaultKeepDepthUtilityLayer: Nullable<UtilityLayerRenderer> = null;\r\n private _sharedGizmoLight: Nullable<HemisphericLight> = null;\r\n\r\n private _renderCamera: Nullable<Camera> = null;\r\n\r\n /**\r\n * Gets the camera that is used to render the utility layer (when not set, this will be the last active camera)\r\n * @param getRigParentIfPossible if the current active camera is a rig camera, should its parent camera be returned\r\n * @returns the camera that is used when rendering the utility layer\r\n */\r\n public getRenderCamera(getRigParentIfPossible?: boolean) {\r\n if (this._renderCamera) {\r\n return this._renderCamera;\r\n } else {\r\n let activeCam: Camera;\r\n if (this.originalScene.activeCameras && this.originalScene.activeCameras.length > 1) {\r\n activeCam = this.originalScene.activeCameras[this.originalScene.activeCameras.length - 1];\r\n } else {\r\n activeCam = this.originalScene.activeCamera!;\r\n }\r\n\r\n if (getRigParentIfPossible && activeCam && activeCam.isRigCamera) {\r\n return activeCam.rigParent!;\r\n }\r\n return activeCam;\r\n }\r\n }\r\n /**\r\n * Sets the camera that should be used when rendering the utility layer (If set to null the last active camera will be used)\r\n * @param cam the camera that should be used when rendering the utility layer\r\n */\r\n public setRenderCamera(cam: Nullable<Camera>) {\r\n this._renderCamera = cam;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Light which used by gizmos to get light shading\r\n */\r\n public _getSharedGizmoLight(): HemisphericLight {\r\n if (!this._sharedGizmoLight) {\r\n this._sharedGizmoLight = new HemisphericLight(\"shared gizmo light\", new Vector3(0, 1, 0), this.utilityLayerScene);\r\n this._sharedGizmoLight.intensity = 2;\r\n this._sharedGizmoLight.groundColor = Color3.Gray();\r\n }\r\n return this._sharedGizmoLight;\r\n }\r\n\r\n /**\r\n * If the picking should be done on the utility layer prior to the actual scene (Default: true)\r\n */\r\n public pickUtilitySceneFirst = true;\r\n /**\r\n * A shared utility layer that can be used to overlay objects into a scene (Depth map of the previous scene is cleared before drawing on top of it)\r\n */\r\n public static get DefaultUtilityLayer(): UtilityLayerRenderer {\r\n if (UtilityLayerRenderer._DefaultUtilityLayer == null) {\r\n return UtilityLayerRenderer._CreateDefaultUtilityLayerFromScene(EngineStore.LastCreatedScene!);\r\n }\r\n\r\n return UtilityLayerRenderer._DefaultUtilityLayer;\r\n }\r\n\r\n /**\r\n * Creates an utility layer, and set it as a default utility layer\r\n * @param scene associated scene\r\n * @internal\r\n */\r\n public static _CreateDefaultUtilityLayerFromScene(scene: Scene): UtilityLayerRenderer {\r\n UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(scene);\r\n UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\r\n UtilityLayerRenderer._DefaultUtilityLayer = null;\r\n });\r\n\r\n return UtilityLayerRenderer._DefaultUtilityLayer;\r\n }\r\n /**\r\n * A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)\r\n */\r\n public static get DefaultKeepDepthUtilityLayer(): UtilityLayerRenderer {\r\n if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(EngineStore.LastCreatedScene!);\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;\r\n });\r\n }\r\n return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;\r\n }\r\n\r\n /**\r\n * The scene that is rendered on top of the original scene\r\n */\r\n public utilityLayerScene: Scene;\r\n\r\n /**\r\n * If the utility layer should automatically be rendered on top of existing scene\r\n */\r\n public shouldRender: boolean = true;\r\n /**\r\n * If set to true, only pointer down onPointerObservable events will be blocked when picking is occluded by original scene\r\n */\r\n public onlyCheckPointerDownEvents = true;\r\n\r\n /**\r\n * If set to false, only pointerUp, pointerDown and pointerMove will be sent to the utilityLayerScene (false by default)\r\n */\r\n public processAllEvents = false;\r\n\r\n /**\r\n * Set to false to disable picking\r\n */\r\n public pickingEnabled = true;\r\n\r\n /**\r\n * Observable raised when the pointer moves from the utility layer scene to the main scene\r\n */\r\n public onPointerOutObservable = new Observable<number>();\r\n\r\n /** Gets or sets a predicate that will be used to indicate utility meshes present in the main scene */\r\n public mainSceneTrackerPredicate: (mesh: Nullable<AbstractMesh>) => boolean;\r\n\r\n private _afterRenderObserver: Nullable<Observer<Camera>>;\r\n private _sceneDisposeObserver: Nullable<Observer<Scene>>;\r\n private _originalPointerObserver: Nullable<Observer<PointerInfoPre>>;\r\n /**\r\n * Instantiates a UtilityLayerRenderer\r\n * @param originalScene the original scene that will be rendered on top of\r\n * @param handleEvents boolean indicating if the utility layer should handle events\r\n * @param manualRender boolean indicating if the utility layer should render manually.\r\n */\r\n constructor(\r\n /** the original scene that will be rendered on top of */\r\n public originalScene: Scene,\r\n public readonly handleEvents: boolean = true,\r\n manualRender = false\r\n ) {\r\n // Create scene which will be rendered in the foreground and remove it from being referenced by engine to avoid interfering with existing app\r\n this.utilityLayerScene = new Scene(originalScene.getEngine(), { virtual: true, useFloatingOrigin: originalScene.floatingOriginMode });\r\n this.utilityLayerScene.useRightHandedSystem = originalScene.useRightHandedSystem;\r\n this.utilityLayerScene._allowPostProcessClearColor = false;\r\n\r\n // Deactivate post processes\r\n this.utilityLayerScene.postProcessesEnabled = false;\r\n\r\n // Detach controls on utility scene, events will be fired by logic below to handle picking priority\r\n this.utilityLayerScene.detachControl();\r\n\r\n if (handleEvents) {\r\n this._originalPointerObserver = originalScene.onPrePointerObservable.add((prePointerInfo) => {\r\n if (!this.utilityLayerScene.activeCamera) {\r\n return;\r\n }\r\n if (!this.pickingEnabled) {\r\n return;\r\n }\r\n\r\n if (!this.processAllEvents) {\r\n if (\r\n prePointerInfo.type !== PointerEventTypes.POINTERMOVE &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERUP &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERDOWN &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERDOUBLETAP\r\n ) {\r\n return;\r\n }\r\n }\r\n this.utilityLayerScene.pointerX = originalScene.pointerX;\r\n this.utilityLayerScene.pointerY = originalScene.pointerY;\r\n const pointerEvent = <IPointerEvent>prePointerInfo.event;\r\n if (originalScene.isPointerCaptured(pointerEvent.pointerId)) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n return;\r\n }\r\n\r\n const getNearPickDataForScene = (scene: Scene) => {\r\n let scenePick = null;\r\n\r\n if (prePointerInfo.nearInteractionPickingInfo) {\r\n if (prePointerInfo.nearInteractionPickingInfo.pickedMesh!.getScene() == scene) {\r\n scenePick = prePointerInfo.nearInteractionPickingInfo;\r\n } else {\r\n scenePick = new PickingInfo();\r\n }\r\n } else if (scene !== this.utilityLayerScene && prePointerInfo.originalPickingInfo) {\r\n scenePick = prePointerInfo.originalPickingInfo;\r\n } else {\r\n let previousActiveCamera: Nullable<Camera> = null;\r\n // If a camera is set for rendering with this layer\r\n // it will also be used for the ray computation\r\n // To preserve back compat and because scene.pick always use activeCamera\r\n // it's substituted temporarily and a new scenePick is forced.\r\n // otherwise, the ray with previously active camera is always used.\r\n // It's set back to previous activeCamera after operation.\r\n if (this._renderCamera) {\r\n previousActiveCamera = scene._activeCamera;\r\n scene._activeCamera = this._renderCamera;\r\n prePointerInfo.ray = null;\r\n }\r\n scenePick = prePointerInfo.ray ? scene.pickWithRay(prePointerInfo.ray) : scene.pick(originalScene.pointerX, originalScene.pointerY);\r\n if (previousActiveCamera) {\r\n scene._activeCamera = previousActiveCamera;\r\n }\r\n }\r\n\r\n return scenePick;\r\n };\r\n\r\n const utilityScenePick = getNearPickDataForScene(this.utilityLayerScene);\r\n\r\n if (!prePointerInfo.ray && utilityScenePick) {\r\n prePointerInfo.ray = utilityScenePick.ray;\r\n }\r\n\r\n if (prePointerInfo.originalPickingInfo?.aimTransform && utilityScenePick) {\r\n utilityScenePick.aimTransform = prePointerInfo.originalPickingInfo.aimTransform;\r\n utilityScenePick.gripTransform = prePointerInfo.originalPickingInfo.gripTransform;\r\n }\r\n\r\n // always fire the prepointer observable\r\n this.utilityLayerScene.onPrePointerObservable.notifyObservers(prePointerInfo);\r\n\r\n // allow every non pointer down event to flow to the utility layer\r\n if (this.onlyCheckPointerDownEvents && prePointerInfo.type != PointerEventTypes.POINTERDOWN) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(\r\n new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick),\r\n prePointerInfo.type\r\n );\r\n }\r\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n }\r\n return;\r\n }\r\n\r\n if (this.utilityLayerScene.autoClearDepthAndStencil || this.pickUtilitySceneFirst) {\r\n // If this layer is an overlay, check if this layer was hit and if so, skip pointer events for the main scene\r\n if (utilityScenePick && utilityScenePick.hit) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(\r\n new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick),\r\n prePointerInfo.type\r\n );\r\n }\r\n prePointerInfo.skipOnPointerObservable = true;\r\n }\r\n } else {\r\n const originalScenePick = getNearPickDataForScene(originalScene);\r\n const pointerEvent = <IPointerEvent>prePointerInfo.event;\r\n\r\n // If the layer can be occluded by the original scene, only fire pointer events to the first layer that hit they ray\r\n if (originalScenePick && utilityScenePick) {\r\n // No pick in utility scene\r\n if (utilityScenePick.distance === 0 && originalScenePick.pickedMesh) {\r\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\r\n // We touched an utility mesh present in the main scene\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n prePointerInfo.skipOnPointerObservable = true;\r\n } else if (prePointerInfo.type === PointerEventTypes.POINTERDOWN) {\r\n this._pointerCaptures[pointerEvent.pointerId] = true;\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n } else if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\r\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\r\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\r\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\r\n delete this._lastPointerEvents[pointerEvent.pointerId];\r\n }\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n }\r\n } else if (!this._pointerCaptures[pointerEvent.pointerId] && (utilityScenePick.distance < originalScenePick.distance || originalScenePick.distance === 0)) {\r\n // We pick something in utility scene or the pick in utility is closer than the one in main scene\r\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\r\n // If a previous utility layer set this, do not unset this\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n prePointerInfo.skipOnPointerObservable = utilityScenePick.distance > 0;\r\n }\r\n } else if (!this._pointerCaptures[pointerEvent.pointerId] && utilityScenePick.distance >= originalScenePick.distance) {\r\n // We have a pick in both scenes but main is closer than utility\r\n\r\n // We touched an utility mesh present in the main scene\r\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n prePointerInfo.skipOnPointerObservable = true;\r\n } else {\r\n if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\r\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\r\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\r\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\r\n delete this._lastPointerEvents[pointerEvent.pointerId];\r\n }\r\n }\r\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\r\n }\r\n }\r\n\r\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n }\r\n }\r\n }\r\n });\r\n\r\n // As a newly added utility layer will be rendered over the screen last, it's pointer events should be processed first\r\n if (this._originalPointerObserver) {\r\n originalScene.onPrePointerObservable.makeObserverTopPriority(this._originalPointerObserver);\r\n }\r\n }\r\n\r\n // Render directly on top of existing scene without clearing\r\n this.utilityLayerScene.autoClear = false;\r\n\r\n if (!manualRender) {\r\n this._afterRenderObserver = this.originalScene.onAfterRenderCameraObservable.add((camera) => {\r\n // Only render when the render camera finishes rendering\r\n if (this.shouldRender && camera == this.getRenderCamera()) {\r\n this.render();\r\n }\r\n });\r\n }\r\n\r\n this._sceneDisposeObserver = this.originalScene.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n\r\n this._updateCamera();\r\n }\r\n\r\n private _notifyObservers(prePointerInfo: PointerInfoPre, pickInfo: PickingInfo, pointerEvent: IPointerEvent) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(new PointerInfo(prePointerInfo.type, prePointerInfo.event, pickInfo), prePointerInfo.type);\r\n this._lastPointerEvents[pointerEvent.pointerId] = true;\r\n }\r\n }\r\n\r\n /**\r\n * Renders the utility layers scene on top of the original scene\r\n */\r\n public render() {\r\n this._updateCamera();\r\n if (this.utilityLayerScene.activeCamera) {\r\n // Set the camera's scene to utility layers scene\r\n const oldScene = this.utilityLayerScene.activeCamera.getScene();\r\n const camera = this.utilityLayerScene.activeCamera;\r\n camera._scene = this.utilityLayerScene;\r\n if (camera.leftCamera) {\r\n camera.leftCamera._scene = this.utilityLayerScene;\r\n }\r\n if (camera.rightCamera) {\r\n camera.rightCamera._scene = this.utilityLayerScene;\r\n }\r\n\r\n this.utilityLayerScene.render(false);\r\n\r\n // Reset camera's scene back to original\r\n camera._scene = oldScene;\r\n if (camera.leftCamera) {\r\n camera.leftCamera._scene = oldScene;\r\n }\r\n if (camera.rightCamera) {\r\n camera.rightCamera._scene = oldScene;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the renderer\r\n */\r\n public dispose() {\r\n this.onPointerOutObservable.clear();\r\n\r\n if (this._afterRenderObserver) {\r\n this.originalScene.onAfterCameraRenderObservable.remove(this._afterRenderObserver);\r\n }\r\n if (this._sceneDisposeObserver) {\r\n this.originalScene.onDisposeObservable.remove(this._sceneDisposeObserver);\r\n }\r\n if (this._originalPointerObserver) {\r\n this.originalScene.onPrePointerObservable.remove(this._originalPointerObserver);\r\n }\r\n this.utilityLayerScene.dispose();\r\n }\r\n\r\n private _updateCamera() {\r\n this.utilityLayerScene.cameraToUseForPointers = this.getRenderCamera();\r\n this.utilityLayerScene.activeCamera = this.getRenderCamera();\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"utilityLayerRenderer.js","sourceRoot":"","sources":["../../../../dev/core/src/Rendering/utilityLayerRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C;;GAEG;AACH,MAAM,OAAO,oBAAoB;IAW7B;;;;OAIG;IACI,eAAe,CAAC,sBAAgC;QACnD,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,aAAa,CAAC;QAC9B,CAAC;aAAM,CAAC;YACJ,IAAI,SAAiB,CAAC;YACtB,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,IAAI,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClF,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC9F,CAAC;iBAAM,CAAC;gBACJ,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,YAAa,CAAC;YACjD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I,CAAC,iBAAiB,CAAC,sBAAsB,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;QACvE,IAAI,CAAC,iBAAiB,CAAC,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC;IACjE,CAAC;;AAhZD,gBAAgB;AACF,yCAAoB,GAAmC,IAAI,AAAvC,CAAwC;AAC1E,gBAAgB;AACF,kDAA6B,GAAmC,IAAI,AAAvC,CAAwC","sourcesContent":["import type { IDisposable } from \"../scene\";\r\nimport { Scene } from \"../scene\";\r\nimport type { Nullable } from \"../types\";\r\nimport type { Observer } from \"../Misc/observable\";\r\nimport { Observable } from \"../Misc/observable\";\r\nimport type { PointerInfoPre } from \"../Events/pointerEvents\";\r\nimport { PointerInfo, PointerEventTypes } from \"../Events/pointerEvents\";\r\nimport { PickingInfo } from \"../Collisions/pickingInfo\";\r\nimport type { AbstractMesh } from \"../Meshes/abstractMesh\";\r\nimport { EngineStore } from \"../Engines/engineStore\";\r\nimport { HemisphericLight } from \"../Lights/hemisphericLight\";\r\nimport { Vector3 } from \"../Maths/math.vector\";\r\nimport type { Camera } from \"../Cameras/camera\";\r\nimport { Color3 } from \"../Maths/math.color\";\r\nimport type { IPointerEvent } from \"../Events/deviceInputEvents\";\r\n\r\n/**\r\n * Renders a layer on top of an existing scene\r\n */\r\nexport class UtilityLayerRenderer implements IDisposable {\r\n private _pointerCaptures: { [pointerId: number]: boolean } = {};\r\n private _lastPointerEvents: { [pointerId: number]: boolean } = {};\r\n /** @internal */\r\n public static _DefaultUtilityLayer: Nullable<UtilityLayerRenderer> = null;\r\n /** @internal */\r\n public static _DefaultKeepDepthUtilityLayer: Nullable<UtilityLayerRenderer> = null;\r\n private _sharedGizmoLight: Nullable<HemisphericLight> = null;\r\n\r\n private _renderCamera: Nullable<Camera> = null;\r\n\r\n /**\r\n * Gets the camera that is used to render the utility layer (when not set, this will be the last active camera)\r\n * @param getRigParentIfPossible if the current active camera is a rig camera, should its parent camera be returned\r\n * @returns the camera that is used when rendering the utility layer\r\n */\r\n public getRenderCamera(getRigParentIfPossible?: boolean) {\r\n if (this._renderCamera) {\r\n return this._renderCamera;\r\n } else {\r\n let activeCam: Camera;\r\n if (this.originalScene.activeCameras && this.originalScene.activeCameras.length > 1) {\r\n activeCam = this.originalScene.activeCameras[this.originalScene.activeCameras.length - 1];\r\n } else {\r\n activeCam = this.originalScene.activeCamera!;\r\n }\r\n\r\n if (getRigParentIfPossible && activeCam && activeCam.isRigCamera) {\r\n return activeCam.rigParent!;\r\n }\r\n return activeCam;\r\n }\r\n }\r\n /**\r\n * Sets the camera that should be used when rendering the utility layer (If set to null the last active camera will be used)\r\n * @param cam the camera that should be used when rendering the utility layer\r\n */\r\n public setRenderCamera(cam: Nullable<Camera>) {\r\n this._renderCamera = cam;\r\n }\r\n\r\n /**\r\n * @internal\r\n * Light which used by gizmos to get light shading\r\n */\r\n public _getSharedGizmoLight(): HemisphericLight {\r\n if (!this._sharedGizmoLight) {\r\n this._sharedGizmoLight = new HemisphericLight(\"shared gizmo light\", new Vector3(0, 1, 0), this.utilityLayerScene);\r\n this._sharedGizmoLight.intensity = 2;\r\n this._sharedGizmoLight.groundColor = Color3.Gray();\r\n }\r\n return this._sharedGizmoLight;\r\n }\r\n\r\n /**\r\n * If the picking should be done on the utility layer prior to the actual scene (Default: true)\r\n */\r\n public pickUtilitySceneFirst = true;\r\n /**\r\n * A shared utility layer that can be used to overlay objects into a scene (Depth map of the previous scene is cleared before drawing on top of it)\r\n */\r\n public static get DefaultUtilityLayer(): UtilityLayerRenderer {\r\n if (UtilityLayerRenderer._DefaultUtilityLayer == null) {\r\n return UtilityLayerRenderer._CreateDefaultUtilityLayerFromScene(EngineStore.LastCreatedScene!);\r\n }\r\n\r\n return UtilityLayerRenderer._DefaultUtilityLayer;\r\n }\r\n\r\n /**\r\n * Creates an utility layer, and set it as a default utility layer\r\n * @param scene associated scene\r\n * @internal\r\n */\r\n public static _CreateDefaultUtilityLayerFromScene(scene: Scene): UtilityLayerRenderer {\r\n UtilityLayerRenderer._DefaultUtilityLayer = new UtilityLayerRenderer(scene);\r\n UtilityLayerRenderer._DefaultUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\r\n UtilityLayerRenderer._DefaultUtilityLayer = null;\r\n });\r\n\r\n return UtilityLayerRenderer._DefaultUtilityLayer;\r\n }\r\n /**\r\n * A shared utility layer that can be used to embed objects into a scene (Depth map of the previous scene is not cleared before drawing on top of it)\r\n */\r\n public static get DefaultKeepDepthUtilityLayer(): UtilityLayerRenderer {\r\n if (UtilityLayerRenderer._DefaultKeepDepthUtilityLayer == null) {\r\n return UtilityLayerRenderer._CreateDefaultKeepUtilityLayerFromScene(EngineStore.LastCreatedScene!);\r\n }\r\n return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;\r\n }\r\n\r\n /**\r\n * Creates an utility layer, and set it as a default utility layer (Depth map of the previous scene is not cleared before drawing on top of it)\r\n * @param scene associated scene\r\n * @internal\r\n */\r\n public static _CreateDefaultKeepUtilityLayerFromScene(scene: Scene): UtilityLayerRenderer {\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = new UtilityLayerRenderer(scene);\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.utilityLayerScene.autoClearDepthAndStencil = false;\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer.originalScene.onDisposeObservable.addOnce(() => {\r\n UtilityLayerRenderer._DefaultKeepDepthUtilityLayer = null;\r\n });\r\n\r\n return UtilityLayerRenderer._DefaultKeepDepthUtilityLayer;\r\n }\r\n\r\n /**\r\n * The scene that is rendered on top of the original scene\r\n */\r\n public utilityLayerScene: Scene;\r\n\r\n /**\r\n * If the utility layer should automatically be rendered on top of existing scene\r\n */\r\n public shouldRender: boolean = true;\r\n /**\r\n * If set to true, only pointer down onPointerObservable events will be blocked when picking is occluded by original scene\r\n */\r\n public onlyCheckPointerDownEvents = true;\r\n\r\n /**\r\n * If set to false, only pointerUp, pointerDown and pointerMove will be sent to the utilityLayerScene (false by default)\r\n */\r\n public processAllEvents = false;\r\n\r\n /**\r\n * Set to false to disable picking\r\n */\r\n public pickingEnabled = true;\r\n\r\n /**\r\n * Observable raised when the pointer moves from the utility layer scene to the main scene\r\n */\r\n public onPointerOutObservable = new Observable<number>();\r\n\r\n /** Gets or sets a predicate that will be used to indicate utility meshes present in the main scene */\r\n public mainSceneTrackerPredicate: (mesh: Nullable<AbstractMesh>) => boolean;\r\n\r\n private _afterRenderObserver: Nullable<Observer<Camera>>;\r\n private _sceneDisposeObserver: Nullable<Observer<Scene>>;\r\n private _originalPointerObserver: Nullable<Observer<PointerInfoPre>>;\r\n /**\r\n * Instantiates a UtilityLayerRenderer\r\n * @param originalScene the original scene that will be rendered on top of\r\n * @param handleEvents boolean indicating if the utility layer should handle events\r\n * @param manualRender boolean indicating if the utility layer should render manually.\r\n */\r\n constructor(\r\n /** the original scene that will be rendered on top of */\r\n public originalScene: Scene,\r\n public readonly handleEvents: boolean = true,\r\n manualRender = false\r\n ) {\r\n // Create scene which will be rendered in the foreground and remove it from being referenced by engine to avoid interfering with existing app\r\n this.utilityLayerScene = new Scene(originalScene.getEngine(), { virtual: true, useFloatingOrigin: originalScene.floatingOriginMode });\r\n this.utilityLayerScene.useRightHandedSystem = originalScene.useRightHandedSystem;\r\n this.utilityLayerScene._allowPostProcessClearColor = false;\r\n\r\n // Deactivate post processes\r\n this.utilityLayerScene.postProcessesEnabled = false;\r\n\r\n // Detach controls on utility scene, events will be fired by logic below to handle picking priority\r\n this.utilityLayerScene.detachControl();\r\n\r\n if (handleEvents) {\r\n this._originalPointerObserver = originalScene.onPrePointerObservable.add((prePointerInfo) => {\r\n if (!this.utilityLayerScene.activeCamera) {\r\n return;\r\n }\r\n if (!this.pickingEnabled) {\r\n return;\r\n }\r\n\r\n if (!this.processAllEvents) {\r\n if (\r\n prePointerInfo.type !== PointerEventTypes.POINTERMOVE &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERUP &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERDOWN &&\r\n prePointerInfo.type !== PointerEventTypes.POINTERDOUBLETAP\r\n ) {\r\n return;\r\n }\r\n }\r\n this.utilityLayerScene.pointerX = originalScene.pointerX;\r\n this.utilityLayerScene.pointerY = originalScene.pointerY;\r\n const pointerEvent = <IPointerEvent>prePointerInfo.event;\r\n if (originalScene.isPointerCaptured(pointerEvent.pointerId)) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n return;\r\n }\r\n\r\n const getNearPickDataForScene = (scene: Scene) => {\r\n let scenePick = null;\r\n\r\n if (prePointerInfo.nearInteractionPickingInfo) {\r\n if (prePointerInfo.nearInteractionPickingInfo.pickedMesh!.getScene() == scene) {\r\n scenePick = prePointerInfo.nearInteractionPickingInfo;\r\n } else {\r\n scenePick = new PickingInfo();\r\n }\r\n } else if (scene !== this.utilityLayerScene && prePointerInfo.originalPickingInfo) {\r\n scenePick = prePointerInfo.originalPickingInfo;\r\n } else {\r\n let previousActiveCamera: Nullable<Camera> = null;\r\n // If a camera is set for rendering with this layer\r\n // it will also be used for the ray computation\r\n // To preserve back compat and because scene.pick always use activeCamera\r\n // it's substituted temporarily and a new scenePick is forced.\r\n // otherwise, the ray with previously active camera is always used.\r\n // It's set back to previous activeCamera after operation.\r\n if (this._renderCamera) {\r\n previousActiveCamera = scene._activeCamera;\r\n scene._activeCamera = this._renderCamera;\r\n prePointerInfo.ray = null;\r\n }\r\n scenePick = prePointerInfo.ray ? scene.pickWithRay(prePointerInfo.ray) : scene.pick(originalScene.pointerX, originalScene.pointerY);\r\n if (previousActiveCamera) {\r\n scene._activeCamera = previousActiveCamera;\r\n }\r\n }\r\n\r\n return scenePick;\r\n };\r\n\r\n const utilityScenePick = getNearPickDataForScene(this.utilityLayerScene);\r\n\r\n if (!prePointerInfo.ray && utilityScenePick) {\r\n prePointerInfo.ray = utilityScenePick.ray;\r\n }\r\n\r\n if (prePointerInfo.originalPickingInfo?.aimTransform && utilityScenePick) {\r\n utilityScenePick.aimTransform = prePointerInfo.originalPickingInfo.aimTransform;\r\n utilityScenePick.gripTransform = prePointerInfo.originalPickingInfo.gripTransform;\r\n }\r\n\r\n // always fire the prepointer observable\r\n this.utilityLayerScene.onPrePointerObservable.notifyObservers(prePointerInfo);\r\n\r\n // allow every non pointer down event to flow to the utility layer\r\n if (this.onlyCheckPointerDownEvents && prePointerInfo.type != PointerEventTypes.POINTERDOWN) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(\r\n new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick),\r\n prePointerInfo.type\r\n );\r\n }\r\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n }\r\n return;\r\n }\r\n\r\n if (this.utilityLayerScene.autoClearDepthAndStencil || this.pickUtilitySceneFirst) {\r\n // If this layer is an overlay, check if this layer was hit and if so, skip pointer events for the main scene\r\n if (utilityScenePick && utilityScenePick.hit) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(\r\n new PointerInfo(prePointerInfo.type, prePointerInfo.event, utilityScenePick),\r\n prePointerInfo.type\r\n );\r\n }\r\n prePointerInfo.skipOnPointerObservable = true;\r\n }\r\n } else {\r\n const originalScenePick = getNearPickDataForScene(originalScene);\r\n const pointerEvent = <IPointerEvent>prePointerInfo.event;\r\n\r\n // If the layer can be occluded by the original scene, only fire pointer events to the first layer that hit they ray\r\n if (originalScenePick && utilityScenePick) {\r\n // No pick in utility scene\r\n if (utilityScenePick.distance === 0 && originalScenePick.pickedMesh) {\r\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\r\n // We touched an utility mesh present in the main scene\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n prePointerInfo.skipOnPointerObservable = true;\r\n } else if (prePointerInfo.type === PointerEventTypes.POINTERDOWN) {\r\n this._pointerCaptures[pointerEvent.pointerId] = true;\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n } else if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\r\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\r\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\r\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\r\n delete this._lastPointerEvents[pointerEvent.pointerId];\r\n }\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n }\r\n } else if (!this._pointerCaptures[pointerEvent.pointerId] && (utilityScenePick.distance < originalScenePick.distance || originalScenePick.distance === 0)) {\r\n // We pick something in utility scene or the pick in utility is closer than the one in main scene\r\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\r\n // If a previous utility layer set this, do not unset this\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n prePointerInfo.skipOnPointerObservable = utilityScenePick.distance > 0;\r\n }\r\n } else if (!this._pointerCaptures[pointerEvent.pointerId] && utilityScenePick.distance >= originalScenePick.distance) {\r\n // We have a pick in both scenes but main is closer than utility\r\n\r\n // We touched an utility mesh present in the main scene\r\n if (this.mainSceneTrackerPredicate && this.mainSceneTrackerPredicate(originalScenePick.pickedMesh)) {\r\n this._notifyObservers(prePointerInfo, originalScenePick, pointerEvent);\r\n prePointerInfo.skipOnPointerObservable = true;\r\n } else {\r\n if (prePointerInfo.type === PointerEventTypes.POINTERMOVE || prePointerInfo.type === PointerEventTypes.POINTERUP) {\r\n if (this._lastPointerEvents[pointerEvent.pointerId]) {\r\n // We need to send a last pointerup to the utilityLayerScene to make sure animations can complete\r\n this.onPointerOutObservable.notifyObservers(pointerEvent.pointerId);\r\n delete this._lastPointerEvents[pointerEvent.pointerId];\r\n }\r\n }\r\n this._notifyObservers(prePointerInfo, utilityScenePick, pointerEvent);\r\n }\r\n }\r\n\r\n if (prePointerInfo.type === PointerEventTypes.POINTERUP && this._pointerCaptures[pointerEvent.pointerId]) {\r\n this._pointerCaptures[pointerEvent.pointerId] = false;\r\n }\r\n }\r\n }\r\n });\r\n\r\n // As a newly added utility layer will be rendered over the screen last, it's pointer events should be processed first\r\n if (this._originalPointerObserver) {\r\n originalScene.onPrePointerObservable.makeObserverTopPriority(this._originalPointerObserver);\r\n }\r\n }\r\n\r\n // Render directly on top of existing scene without clearing\r\n this.utilityLayerScene.autoClear = false;\r\n\r\n if (!manualRender) {\r\n this._afterRenderObserver = this.originalScene.onAfterRenderCameraObservable.add((camera) => {\r\n // Only render when the render camera finishes rendering\r\n if (this.shouldRender && camera == this.getRenderCamera()) {\r\n this.render();\r\n }\r\n });\r\n }\r\n\r\n this._sceneDisposeObserver = this.originalScene.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n\r\n this._updateCamera();\r\n }\r\n\r\n private _notifyObservers(prePointerInfo: PointerInfoPre, pickInfo: PickingInfo, pointerEvent: IPointerEvent) {\r\n if (!prePointerInfo.skipOnPointerObservable) {\r\n this.utilityLayerScene.onPointerObservable.notifyObservers(new PointerInfo(prePointerInfo.type, prePointerInfo.event, pickInfo), prePointerInfo.type);\r\n this._lastPointerEvents[pointerEvent.pointerId] = true;\r\n }\r\n }\r\n\r\n /**\r\n * Renders the utility layers scene on top of the original scene\r\n */\r\n public render() {\r\n this._updateCamera();\r\n if (this.utilityLayerScene.activeCamera) {\r\n // Set the camera's scene to utility layers scene\r\n const oldScene = this.utilityLayerScene.activeCamera.getScene();\r\n const camera = this.utilityLayerScene.activeCamera;\r\n camera._scene = this.utilityLayerScene;\r\n if (camera.leftCamera) {\r\n camera.leftCamera._scene = this.utilityLayerScene;\r\n }\r\n if (camera.rightCamera) {\r\n camera.rightCamera._scene = this.utilityLayerScene;\r\n }\r\n\r\n this.utilityLayerScene.render(false);\r\n\r\n // Reset camera's scene back to original\r\n camera._scene = oldScene;\r\n if (camera.leftCamera) {\r\n camera.leftCamera._scene = oldScene;\r\n }\r\n if (camera.rightCamera) {\r\n camera.rightCamera._scene = oldScene;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Disposes of the renderer\r\n */\r\n public dispose() {\r\n this.onPointerOutObservable.clear();\r\n\r\n if (this._afterRenderObserver) {\r\n this.originalScene.onAfterCameraRenderObservable.remove(this._afterRenderObserver);\r\n }\r\n if (this._sceneDisposeObserver) {\r\n this.originalScene.onDisposeObservable.remove(this._sceneDisposeObserver);\r\n }\r\n if (this._originalPointerObserver) {\r\n this.originalScene.onPrePointerObservable.remove(this._originalPointerObserver);\r\n }\r\n this.utilityLayerScene.dispose();\r\n }\r\n\r\n private _updateCamera() {\r\n this.utilityLayerScene.cameraToUseForPointers = this.getRenderCamera();\r\n this.utilityLayerScene.activeCamera = this.getRenderCamera();\r\n }\r\n}\r\n"]}
|
|
@@ -46,8 +46,12 @@ preInfo=computeHemisphericPreLightingInfo(light{X}.vLightData,viewDirectionW,nor
|
|
|
46
46
|
#elif defined(DIRLIGHT{X})
|
|
47
47
|
preInfo=computeDirectionalPreLightingInfo(light{X}.vLightData,viewDirectionW,normalW);
|
|
48
48
|
#elif defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
|
|
49
|
+
#if defined(RECTAREALIGHTEMISSIONTEXTURE{X})
|
|
50
|
+
preInfo=computeAreaPreLightingInfoWithTexture(areaLightsLTC1Sampler,areaLightsLTC2Sampler,rectAreaLightEmissionTexture{X},viewDirectionW,normalW,vPositionW,light{X}.vLightData,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,roughness);
|
|
51
|
+
#else
|
|
49
52
|
preInfo=computeAreaPreLightingInfo(areaLightsLTC1Sampler,areaLightsLTC2Sampler,viewDirectionW,normalW,vPositionW,light{X}.vLightData,light{X}.vLightWidth.xyz,light{X}.vLightHeight.xyz,roughness);
|
|
50
53
|
#endif
|
|
54
|
+
#endif
|
|
51
55
|
preInfo.NdotV=NdotV;
|
|
52
56
|
#ifdef SPOTLIGHT{X}
|
|
53
57
|
#ifdef LIGHT_FALLOFF_GLTF{X}
|
|
@@ -191,12 +195,21 @@ info=computeHemisphericLighting(viewDirectionW,normalW,light{X}.vLightData,diffu
|
|
|
191
195
|
#elif defined(POINTLIGHT{X}) || defined(DIRLIGHT{X})
|
|
192
196
|
info=computeLighting(viewDirectionW,normalW,light{X}.vLightData,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,diffuse{X}.a,glossiness);
|
|
193
197
|
#elif defined(AREALIGHT{X}) && defined(AREALIGHTUSED) && defined(AREALIGHTSUPPORTED)
|
|
198
|
+
#if defined(RECTAREALIGHTEMISSIONTEXTURE{X})
|
|
199
|
+
info=computeAreaLightingWithTexture(areaLightsLTC1Sampler,areaLightsLTC2Sampler,rectAreaLightEmissionTexture{X},viewDirectionW,normalW,vPositionW,light{X}.vLightData.xyz,light{X}.vLightWidth.rgb,light{X}.vLightHeight.rgb,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,
|
|
200
|
+
#ifdef AREALIGHTNOROUGHTNESS
|
|
201
|
+
0.5
|
|
202
|
+
#else
|
|
203
|
+
vReflectionInfos.y
|
|
204
|
+
#endif
|
|
205
|
+
#else
|
|
194
206
|
info=computeAreaLighting(areaLightsLTC1Sampler,areaLightsLTC2Sampler,viewDirectionW,normalW,vPositionW,light{X}.vLightData.xyz,light{X}.vLightWidth.rgb,light{X}.vLightHeight.rgb,diffuse{X}.rgb,light{X}.vLightSpecular.rgb,
|
|
195
207
|
#ifdef AREALIGHTNOROUGHTNESS
|
|
196
208
|
0.5
|
|
197
209
|
#else
|
|
198
210
|
vReflectionInfos.y
|
|
199
211
|
#endif
|
|
212
|
+
#endif
|
|
200
213
|
);
|
|
201
214
|
#elif defined(CLUSTLIGHT{X}) && CLUSTLIGHT_BATCH>0
|
|
202
215
|
{int sliceIndex=min(getClusteredSliceIndex(light{X}.vSliceData,vViewDepth),CLUSTLIGHT_SLICES-1);info=computeClusteredLighting(lightDataTexture{X},tileMaskTexture{X},viewDirectionW,normalW,light{X}.vLightData,ivec2(light{X}.vSliceRanges[sliceIndex]),glossiness);}
|