@babylonjs/core 6.34.0 → 6.34.2
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/Animations/animation.js +1 -1
- package/Animations/animation.js.map +1 -1
- package/Buffers/storageBuffer.d.ts +2 -1
- package/Buffers/storageBuffer.js +3 -2
- package/Buffers/storageBuffer.js.map +1 -1
- package/Cameras/Inputs/followCameraMouseWheelInput.js +12 -9
- package/Cameras/Inputs/followCameraMouseWheelInput.js.map +1 -1
- package/Cameras/Inputs/followCameraPointersInput.js +28 -9
- package/Cameras/Inputs/followCameraPointersInput.js.map +1 -1
- package/Cameras/arcRotateCamera.js +1 -1
- package/Cameras/arcRotateCamera.js.map +1 -1
- package/Cameras/followCameraInputsManager.js +2 -1
- package/Cameras/followCameraInputsManager.js.map +1 -1
- package/Debug/skeletonViewer.js +2 -1
- package/Debug/skeletonViewer.js.map +1 -1
- package/Engines/Extensions/engine.storageBuffer.d.ts +2 -1
- package/Engines/Extensions/engine.storageBuffer.js.map +1 -1
- package/Engines/Processors/shaderCodeInliner.js +15 -14
- package/Engines/Processors/shaderCodeInliner.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.computeShader.js +3 -2
- package/Engines/WebGPU/Extensions/engine.computeShader.js.map +1 -1
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js +14 -5
- package/Engines/WebGPU/Extensions/engine.storageBuffer.js.map +1 -1
- package/Engines/WebGPU/webgpuShaderProcessor.js +2 -1
- package/Engines/WebGPU/webgpuShaderProcessor.js.map +1 -1
- package/Engines/WebGPU/webgpuTintWASM.js +3 -2
- package/Engines/WebGPU/webgpuTintWASM.js.map +1 -1
- package/Engines/engine.d.ts +2 -4
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.js +4 -2
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.js +4 -4
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +75 -46
- package/Engines/webgpuEngine.js.map +1 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js +2 -1
- package/FlowGraph/Blocks/Execution/flowGraphConsoleLogBlock.js.map +1 -1
- package/FlowGraph/flowGraphBlock.js +1 -21
- package/FlowGraph/flowGraphBlock.js.map +1 -1
- package/FlowGraph/flowGraphExecutionBlock.d.ts +1 -0
- package/FlowGraph/flowGraphExecutionBlock.js +20 -0
- package/FlowGraph/flowGraphExecutionBlock.js.map +1 -1
- package/Gizmos/axisScaleGizmo.d.ts +1 -0
- package/Gizmos/axisScaleGizmo.js +12 -0
- package/Gizmos/axisScaleGizmo.js.map +1 -1
- package/Gizmos/lightGizmo.js +2 -1
- package/Gizmos/lightGizmo.js.map +1 -1
- package/Gizmos/rotationGizmo.js +1 -1
- package/Gizmos/rotationGizmo.js.map +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.js +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js +2 -1
- package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
- package/Materials/Node/Blocks/Dual/reflectionTextureBlock.js +3 -2
- package/Materials/Node/Blocks/Dual/reflectionTextureBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/fragDepthBlock.js +2 -1
- package/Materials/Node/Blocks/Fragment/fragDepthBlock.js.map +1 -1
- package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js +2 -1
- package/Materials/Node/Blocks/Fragment/heightToNormalBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js +2 -1
- package/Materials/Node/Blocks/PBR/anisotropyBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +3 -2
- package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js +2 -1
- package/Materials/Node/Blocks/PBR/reflectionBlock.js.map +1 -1
- package/Materials/Node/nodeMaterial.js +9 -8
- package/Materials/Node/nodeMaterial.js.map +1 -1
- package/Materials/Node/nodeMaterialBlock.js +2 -1
- package/Materials/Node/nodeMaterialBlock.js.map +1 -1
- package/Materials/Textures/renderTargetTexture.js +1 -2
- package/Materials/Textures/renderTargetTexture.js.map +1 -1
- package/Meshes/Builders/groundBuilder.d.ts +7 -1
- package/Meshes/Builders/groundBuilder.js +17 -8
- package/Meshes/Builders/groundBuilder.js.map +1 -1
- package/Meshes/Compression/dracoCompression.js.map +1 -1
- package/Meshes/Node/nodeGeometryBlock.js +2 -1
- package/Meshes/Node/nodeGeometryBlock.js.map +1 -1
- package/Meshes/mesh.d.ts +2 -1
- package/Meshes/mesh.js +3 -2
- package/Meshes/mesh.js.map +1 -1
- package/Misc/assetsManager.js +2 -2
- package/Misc/assetsManager.js.map +1 -1
- package/Misc/dds.js +1 -1
- package/Misc/dds.js.map +1 -1
- package/Misc/fileTools.js +4 -0
- package/Misc/fileTools.js.map +1 -1
- package/Misc/logger.d.ts +3 -3
- package/Misc/logger.js +8 -4
- package/Misc/logger.js.map +1 -1
- package/Misc/sceneSerializer.js +2 -1
- package/Misc/sceneSerializer.js.map +1 -1
- package/Misc/tools.d.ts +2 -7
- package/Misc/tools.js.map +1 -1
- package/Navigation/Plugins/recastJSPlugin.js +3 -3
- package/Navigation/Plugins/recastJSPlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.js +1 -1
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -1
- package/Physics/v2/index.d.ts +1 -0
- package/Physics/v2/index.js +1 -0
- package/Physics/v2/index.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +5 -0
- package/Physics/v2/physicsBody.js +7 -0
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/ragdoll.d.ts +102 -0
- package/Physics/v2/ragdoll.js +221 -0
- package/Physics/v2/ragdoll.js.map +1 -0
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +2 -2
- package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js +3 -2
- package/PostProcesses/RenderPipeline/Pipelines/ssrRenderingPipeline.js.map +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.js +1 -1
- package/PostProcesses/screenSpaceCurvaturePostProcess.js.map +1 -1
- package/PostProcesses/screenSpaceReflectionPostProcess.js +3 -2
- package/PostProcesses/screenSpaceReflectionPostProcess.js.map +1 -1
- package/Rendering/GaussianSplatting/gaussianSplatting.js.map +1 -1
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js +3 -2
- package/Shaders/ShadersInclude/pbrBlockSubSurface.js.map +1 -1
- package/XR/features/WebXRControllerPhysics.js +2 -2
- package/XR/features/WebXRControllerPhysics.js.map +1 -1
- package/XR/features/WebXRMeshDetector.js +2 -1
- package/XR/features/WebXRMeshDetector.js.map +1 -1
- package/XR/features/WebXRWalkingLocomotion.js +1 -1
- package/XR/features/WebXRWalkingLocomotion.js.map +1 -1
- package/XR/motionController/webXRMotionControllerManager.js +1 -1
- package/XR/motionController/webXRMotionControllerManager.js.map +1 -1
- package/XR/webXRExperienceHelper.js +2 -2
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/assetContainer.js +2 -2
- package/assetContainer.js.map +1 -1
- package/package.json +1 -1
- package/scene.d.ts +2 -4
- package/scene.js +2 -1
- package/scene.js.map +1 -1
package/Physics/v2/index.d.ts
CHANGED
package/Physics/v2/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from "./physicsShape.js";
|
|
|
5
5
|
export * from "./physicsConstraint.js";
|
|
6
6
|
export * from "./physicsMaterial.js";
|
|
7
7
|
export * from "./physicsAggregate.js";
|
|
8
|
+
export * from "./ragdoll.js";
|
|
8
9
|
export * from "./IPhysicsEnginePlugin.js";
|
|
9
10
|
/* eslint-disable import/no-internal-modules */
|
|
10
11
|
export * from "./Plugins/index.js";
|
package/Physics/v2/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnE,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC;AACvC,+CAA+C;AAC/C,cAAc,iBAAiB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nexport { PhysicsEngine as PhysicsEngineV2 } from \"./physicsEngine\";\r\nexport * from \"./physicsBody\";\r\nexport * from \"./physicsShape\";\r\nexport * from \"./physicsConstraint\";\r\nexport * from \"./physicsMaterial\";\r\nexport * from \"./physicsAggregate\";\r\nexport * from \"./IPhysicsEnginePlugin\";\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./Plugins/index\";\r\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/index.ts"],"names":[],"mappings":"AAAA,+CAA+C;AAC/C,OAAO,EAAE,aAAa,IAAI,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACnE,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,wBAAwB,CAAC;AACvC,+CAA+C;AAC/C,cAAc,iBAAiB,CAAC","sourcesContent":["/* eslint-disable import/no-internal-modules */\r\nexport { PhysicsEngine as PhysicsEngineV2 } from \"./physicsEngine\";\r\nexport * from \"./physicsBody\";\r\nexport * from \"./physicsShape\";\r\nexport * from \"./physicsConstraint\";\r\nexport * from \"./physicsMaterial\";\r\nexport * from \"./physicsAggregate\";\r\nexport * from \"./ragdoll\";\r\nexport * from \"./IPhysicsEnginePlugin\";\r\n/* eslint-disable import/no-internal-modules */\r\nexport * from \"./Plugins/index\";\r\n"]}
|
|
@@ -343,6 +343,11 @@ export declare class PhysicsBody {
|
|
|
343
343
|
* @param instanceIndex The index of the instance in an instanced body
|
|
344
344
|
*/
|
|
345
345
|
setTargetTransform(position: Vector3, rotation: Quaternion, instanceIndex?: number): void;
|
|
346
|
+
/**
|
|
347
|
+
* Returns if the body has been disposed.
|
|
348
|
+
* @returns true if disposed, false otherwise.
|
|
349
|
+
*/
|
|
350
|
+
get isDisposed(): boolean;
|
|
346
351
|
/**
|
|
347
352
|
* Disposes the body from the physics engine.
|
|
348
353
|
*
|
|
@@ -508,6 +508,13 @@ export class PhysicsBody {
|
|
|
508
508
|
setTargetTransform(position, rotation, instanceIndex) {
|
|
509
509
|
this._physicsPlugin.setTargetTransform(this, position, rotation, instanceIndex);
|
|
510
510
|
}
|
|
511
|
+
/**
|
|
512
|
+
* Returns if the body has been disposed.
|
|
513
|
+
* @returns true if disposed, false otherwise.
|
|
514
|
+
*/
|
|
515
|
+
get isDisposed() {
|
|
516
|
+
return this._isDisposed;
|
|
517
|
+
}
|
|
511
518
|
/**
|
|
512
519
|
* Disposes the body from the physics engine.
|
|
513
520
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,EAAE,KAAK,EAAE,iCAA6B;AAO7C;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA4CpB;;;;;;;;;;;;;OAaG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,YAAqB,EAAE,KAAY;QAzD5G;;WAEG;QACI,gBAAW,GAAQ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;;;OAIG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,WAAW,EAAE;YAClB,OAAO;SACV;QACD,qEAAqE;QACrE,IAAI,IAAI,CAAC,mBAAmB,EAAE;YAC1B,IAAI,CAAC,2BAA2B,CAAC,KAAK,CAAC,CAAC;SAC3C;QACD,IAAI,IAAI,CAAC,wBAAwB,EAAE;YAC/B,IAAI,CAAC,gCAAgC,CAAC,KAAK,CAAC,CAAC;SAChD;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACzE,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;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;IAC5B,CAAC;CACJ","sourcesContent":["import type { IBasePhysicsCollisionEvent, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties, PhysicsMotionType } 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\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 * 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 disablePreStep: boolean = true;\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 /**\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 as IPhysicsEnginePluginV2;\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 // 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 * 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._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public get shape(): Nullable<PhysicsShape> {\r\n return this._physicsPlugin.getShape(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 *\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 *\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 */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\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 */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\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 * intial values, which you can then customize.\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 *\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 *\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 * @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 *\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 *\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 *\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 *\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 return 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 * @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 *\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 *\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 return 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 * @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 * 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(): {} {\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 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 * 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 }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsBody.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/physicsBody.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,EAAE,KAAK,EAAE,iCAA6B;AAO7C;;;;GAIG;AACH,MAAM,OAAO,WAAW;IA4CpB;;;;;;;;;;;;;OAaG;IACH,YAAY,aAA4B,EAAE,UAA6B,EAAE,YAAqB,EAAE,KAAY;QAzD5G;;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;QAKlD;;;WAGG;QACH,mBAAc,GAAY,IAAI,CAAC;QASvB,gBAAW,GAAG,KAAK,CAAC;QAiBxB,IAAI,CAAC,KAAK,EAAE;YACR,OAAO;SACV;QACD,MAAM,aAAa,GAAG,KAAK,CAAC,gBAAgB,EAAmB,CAA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AC,KAAK,CAAC,CAAC;SAChD;QACD,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YACzE,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;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;IAC5B,CAAC;CACJ","sourcesContent":["import type { IBasePhysicsCollisionEvent, IPhysicsCollisionEvent, IPhysicsEnginePluginV2, PhysicsMassProperties, PhysicsMotionType } 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\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 * 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 disablePreStep: boolean = true;\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 /**\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 as IPhysicsEnginePluginV2;\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 // 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 * 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._physicsPlugin.setShape(this, shape);\r\n }\r\n\r\n /**\r\n * Retrieves the physics shape associated with this object.\r\n *\r\n * @returns The physics shape associated with this object, or `undefined` if no\r\n * shape is associated.\r\n *\r\n * This method is useful for retrieving the physics shape associated with this object,\r\n * which can be used to apply physical forces to the object or to detect collisions.\r\n */\r\n public get shape(): Nullable<PhysicsShape> {\r\n return this._physicsPlugin.getShape(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 *\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 *\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 */\r\n public setMotionType(motionType: PhysicsMotionType, instanceIndex?: number) {\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 */\r\n public getMotionType(instanceIndex?: number): PhysicsMotionType {\r\n return this._physicsPlugin.getMotionType(this, instanceIndex);\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 * intial values, which you can then customize.\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 *\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 *\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 * @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 *\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 *\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 *\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 *\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 return 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 * @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 *\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 *\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 return 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 * @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 * 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(): {} {\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 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 }\r\n}\r\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Skeleton } from "../../Bones/skeleton";
|
|
2
|
+
import { Vector3 } from "../../Maths/math.vector";
|
|
3
|
+
import type { Mesh } from "../../Meshes/mesh";
|
|
4
|
+
/**
|
|
5
|
+
* Ragdoll bone properties
|
|
6
|
+
* @experimental
|
|
7
|
+
*/
|
|
8
|
+
export declare class RagdollBoneProperties {
|
|
9
|
+
/**
|
|
10
|
+
* Width of the box shape
|
|
11
|
+
*/
|
|
12
|
+
width?: number;
|
|
13
|
+
/**
|
|
14
|
+
* depth of the box shape
|
|
15
|
+
*/
|
|
16
|
+
depth?: number;
|
|
17
|
+
/**
|
|
18
|
+
* height of the box shape
|
|
19
|
+
*/
|
|
20
|
+
height?: number;
|
|
21
|
+
/**
|
|
22
|
+
* size that will be used of width, depth and height of the shape box
|
|
23
|
+
*/
|
|
24
|
+
size?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Type of Physics Constraint used between bones
|
|
27
|
+
*/
|
|
28
|
+
joint?: number | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Main rotation axis used by the constraint, in local space
|
|
31
|
+
*/
|
|
32
|
+
rotationAxis?: Vector3;
|
|
33
|
+
/**
|
|
34
|
+
* Minimum rotation angle value
|
|
35
|
+
*/
|
|
36
|
+
min?: number;
|
|
37
|
+
/**
|
|
38
|
+
* Maximum rotation angle value
|
|
39
|
+
*/
|
|
40
|
+
max?: number;
|
|
41
|
+
/**
|
|
42
|
+
* Offset along local axis
|
|
43
|
+
*/
|
|
44
|
+
boxOffset?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Axis that need an offset
|
|
47
|
+
*/
|
|
48
|
+
boneOffsetAxis?: Vector3;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Ragdoll for Physics V2
|
|
52
|
+
* Current known limitation is scene must be using Right hand coordinates
|
|
53
|
+
* @experimental
|
|
54
|
+
*/
|
|
55
|
+
export declare class Ragdoll {
|
|
56
|
+
private _skeleton;
|
|
57
|
+
private _scene;
|
|
58
|
+
private _mesh;
|
|
59
|
+
private _config;
|
|
60
|
+
private _boxConfigs;
|
|
61
|
+
private _bones;
|
|
62
|
+
private _initialRotation;
|
|
63
|
+
private _boneNames;
|
|
64
|
+
private _transforms;
|
|
65
|
+
private _aggregates;
|
|
66
|
+
private _ragdollMode;
|
|
67
|
+
private _rootBoneName;
|
|
68
|
+
private _rootBoneIndex;
|
|
69
|
+
private _mass;
|
|
70
|
+
private _restitution;
|
|
71
|
+
/**
|
|
72
|
+
* Pause synchronization between physics and bone position/orientation
|
|
73
|
+
*/
|
|
74
|
+
pauseSync: boolean;
|
|
75
|
+
private _putBoxesInBoneCenter;
|
|
76
|
+
private _defaultJoint;
|
|
77
|
+
private _defaultJointMin;
|
|
78
|
+
private _defaultJointMax;
|
|
79
|
+
private _boneOffsetAxis;
|
|
80
|
+
/**
|
|
81
|
+
* Construct a new Ragdoll object. Once ready, it can be made dynamic by calling `Ragdoll` method
|
|
82
|
+
* @param skeleton The skeleton containing bones to be physicalized
|
|
83
|
+
* @param mesh The mesh used by the skeleton
|
|
84
|
+
* @param config an array of `RagdollBoneProperties` corresponding to bones and their properties used to instanciate physics bodies
|
|
85
|
+
*/
|
|
86
|
+
constructor(skeleton: Skeleton, mesh: Mesh, config: RagdollBoneProperties[]);
|
|
87
|
+
private _createColliders;
|
|
88
|
+
private _initJoints;
|
|
89
|
+
private _syncBonesAndBoxes;
|
|
90
|
+
private _addImpostorRotationToBone;
|
|
91
|
+
private _defineRootBone;
|
|
92
|
+
private _findNearestParent;
|
|
93
|
+
private _init;
|
|
94
|
+
/**
|
|
95
|
+
* Enable ragdoll mode. Create physics objects and make them dynamic.
|
|
96
|
+
*/
|
|
97
|
+
ragdoll(): void;
|
|
98
|
+
/**
|
|
99
|
+
* Dispose resources and remove physics objects
|
|
100
|
+
*/
|
|
101
|
+
dispose(): void;
|
|
102
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { Vector3, Matrix, TmpVectors } from "../../Maths/math.vector.js";
|
|
2
|
+
import { PhysicsAggregate } from "./physicsAggregate.js";
|
|
3
|
+
import { BallAndSocketConstraint } from "./physicsConstraint.js";
|
|
4
|
+
import { Axis, Space } from "../../Maths/math.axis.js";
|
|
5
|
+
import { PhysicsShapeType, PhysicsConstraintType } from "./IPhysicsEnginePlugin.js";
|
|
6
|
+
import { Logger } from "../../Misc/logger.js";
|
|
7
|
+
import { TransformNode } from "../../Meshes/transformNode.js";
|
|
8
|
+
/**
|
|
9
|
+
* Ragdoll bone properties
|
|
10
|
+
* @experimental
|
|
11
|
+
*/
|
|
12
|
+
export class RagdollBoneProperties {
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Ragdoll for Physics V2
|
|
16
|
+
* Current known limitation is scene must be using Right hand coordinates
|
|
17
|
+
* @experimental
|
|
18
|
+
*/
|
|
19
|
+
export class Ragdoll {
|
|
20
|
+
/**
|
|
21
|
+
* Construct a new Ragdoll object. Once ready, it can be made dynamic by calling `Ragdoll` method
|
|
22
|
+
* @param skeleton The skeleton containing bones to be physicalized
|
|
23
|
+
* @param mesh The mesh used by the skeleton
|
|
24
|
+
* @param config an array of `RagdollBoneProperties` corresponding to bones and their properties used to instanciate physics bodies
|
|
25
|
+
*/
|
|
26
|
+
constructor(skeleton, mesh, config) {
|
|
27
|
+
this._boxConfigs = new Array();
|
|
28
|
+
this._bones = new Array();
|
|
29
|
+
this._initialRotation = new Array();
|
|
30
|
+
this._boneNames = [];
|
|
31
|
+
this._transforms = new Array();
|
|
32
|
+
this._aggregates = new Array();
|
|
33
|
+
this._ragdollMode = false;
|
|
34
|
+
this._rootBoneName = "";
|
|
35
|
+
this._rootBoneIndex = -1;
|
|
36
|
+
this._mass = 10;
|
|
37
|
+
this._restitution = 0;
|
|
38
|
+
/**
|
|
39
|
+
* Pause synchronization between physics and bone position/orientation
|
|
40
|
+
*/
|
|
41
|
+
this.pauseSync = false;
|
|
42
|
+
this._defaultJoint = PhysicsConstraintType.HINGE;
|
|
43
|
+
this._defaultJointMin = -90;
|
|
44
|
+
this._defaultJointMax = 90;
|
|
45
|
+
this._skeleton = skeleton;
|
|
46
|
+
this._scene = skeleton.getScene();
|
|
47
|
+
this._mesh = mesh;
|
|
48
|
+
this._config = config; // initial, user defined box configs. May have several box configs jammed into 1 index.
|
|
49
|
+
this._boxConfigs = []; // final box configs. Every element is a separate box config (this.config may have several configs jammed into 1 index).
|
|
50
|
+
this._putBoxesInBoneCenter = false;
|
|
51
|
+
this._defaultJoint = PhysicsConstraintType.HINGE;
|
|
52
|
+
this._boneOffsetAxis = Axis.Y;
|
|
53
|
+
}
|
|
54
|
+
_createColliders() {
|
|
55
|
+
var _a, _b, _c;
|
|
56
|
+
this._mesh.computeWorldMatrix();
|
|
57
|
+
const config = this._config;
|
|
58
|
+
for (let i = 0; i < config.length; i++) {
|
|
59
|
+
const boneNames = config[i].bone !== undefined ? [config[i].bone] : config[i].bones;
|
|
60
|
+
for (let ii = 0; ii < boneNames.length; ii++) {
|
|
61
|
+
const currentBone = this._skeleton.bones[this._skeleton.getBoneIndexByName(boneNames[ii])];
|
|
62
|
+
if (currentBone == undefined) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
// First define the box dimensions, so we can then use them when calling CreateBox().
|
|
66
|
+
const currentRagdollBoneProperties = {
|
|
67
|
+
width: this._config[i].width,
|
|
68
|
+
depth: this._config[i].depth,
|
|
69
|
+
height: this._config[i].height,
|
|
70
|
+
size: this._config[i].size,
|
|
71
|
+
};
|
|
72
|
+
currentRagdollBoneProperties.width = (_a = currentRagdollBoneProperties.width) !== null && _a !== void 0 ? _a : currentRagdollBoneProperties.size;
|
|
73
|
+
currentRagdollBoneProperties.depth = (_b = currentRagdollBoneProperties.depth) !== null && _b !== void 0 ? _b : currentRagdollBoneProperties.size;
|
|
74
|
+
currentRagdollBoneProperties.height = (_c = currentRagdollBoneProperties.height) !== null && _c !== void 0 ? _c : currentRagdollBoneProperties.size;
|
|
75
|
+
const transform = new TransformNode(boneNames[ii] + "_transform", this._scene);
|
|
76
|
+
// Define the rest of the box properties.
|
|
77
|
+
currentRagdollBoneProperties.joint = config[i].joint !== undefined ? config[i].joint : this._defaultJoint;
|
|
78
|
+
currentRagdollBoneProperties.rotationAxis = config[i].rotationAxis !== undefined ? config[i].rotationAxis : Axis.X;
|
|
79
|
+
currentRagdollBoneProperties.min = config[i].min !== undefined ? config[i].min : this._defaultJointMin;
|
|
80
|
+
currentRagdollBoneProperties.max = config[i].max !== undefined ? config[i].max : this._defaultJointMax;
|
|
81
|
+
// Offset value.
|
|
82
|
+
let boxOffset = 0;
|
|
83
|
+
if ((config[i].putBoxInBoneCenter !== undefined && config[i].putBoxInBoneCenter) || this._putBoxesInBoneCenter) {
|
|
84
|
+
if (currentBone.length === undefined) {
|
|
85
|
+
Logger.Log("The length property is not defined for bone " + currentBone.name);
|
|
86
|
+
}
|
|
87
|
+
boxOffset = currentBone.length / 2;
|
|
88
|
+
}
|
|
89
|
+
else if (config[i].boxOffset !== undefined) {
|
|
90
|
+
boxOffset = config[i].boxOffset;
|
|
91
|
+
}
|
|
92
|
+
currentRagdollBoneProperties.boxOffset = boxOffset;
|
|
93
|
+
// Offset axis.
|
|
94
|
+
const boneOffsetAxis = config[i].boneOffsetAxis !== undefined ? config[i].boneOffsetAxis : this._boneOffsetAxis;
|
|
95
|
+
const boneDir = currentBone.getDirection(boneOffsetAxis, this._mesh);
|
|
96
|
+
currentRagdollBoneProperties.boneOffsetAxis = boneOffsetAxis;
|
|
97
|
+
transform.position = currentBone.getAbsolutePosition(this._mesh).add(boneDir.scale(boxOffset));
|
|
98
|
+
const mass = config[i].mass !== undefined ? config[i].mass : this._mass;
|
|
99
|
+
const restitution = config[i].restitution !== undefined ? config[i].restitution : this._restitution;
|
|
100
|
+
const aggregate = new PhysicsAggregate(transform, PhysicsShapeType.BOX, {
|
|
101
|
+
mass: mass,
|
|
102
|
+
restitution: restitution,
|
|
103
|
+
friction: 0.6,
|
|
104
|
+
extents: new Vector3(currentRagdollBoneProperties.width, currentRagdollBoneProperties.height, currentRagdollBoneProperties.depth),
|
|
105
|
+
}, this._scene);
|
|
106
|
+
aggregate.body.setCollisionCallbackEnabled(true);
|
|
107
|
+
aggregate.body.disablePreStep = false;
|
|
108
|
+
this._aggregates.push(aggregate);
|
|
109
|
+
this._bones.push(currentBone);
|
|
110
|
+
this._boneNames.push(currentBone.name);
|
|
111
|
+
this._transforms.push(transform);
|
|
112
|
+
this._boxConfigs.push(currentRagdollBoneProperties);
|
|
113
|
+
this._initialRotation.push(currentBone.getRotationQuaternion(Space.WORLD, this._mesh));
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
_initJoints() {
|
|
118
|
+
this._mesh.computeWorldMatrix();
|
|
119
|
+
for (let i = 0; i < this._bones.length; i++) {
|
|
120
|
+
// The root bone has no joints.
|
|
121
|
+
if (i == this._rootBoneIndex)
|
|
122
|
+
continue;
|
|
123
|
+
const nearestParent = this._findNearestParent(i);
|
|
124
|
+
if (nearestParent == null) {
|
|
125
|
+
Logger.Warn("Couldn't find a nearest parent bone in the configs for bone called " + this._boneNames[i]);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const boneParentIndex = this._boneNames.indexOf(nearestParent.name);
|
|
129
|
+
let distanceFromParentBoxToBone = this._bones[i].getAbsolutePosition(this._mesh).subtract(this._transforms[boneParentIndex].position);
|
|
130
|
+
const wmat = this._transforms[boneParentIndex].computeWorldMatrix();
|
|
131
|
+
const invertedWorldMat = Matrix.Invert(wmat);
|
|
132
|
+
distanceFromParentBoxToBone = Vector3.TransformCoordinates(this._bones[i].getAbsolutePosition(this._mesh), invertedWorldMat);
|
|
133
|
+
const boneAbsPos = this._bones[i].getAbsolutePosition(this._mesh);
|
|
134
|
+
const boxAbsPos = this._transforms[i].position.clone();
|
|
135
|
+
const myConnectedPivot = boneAbsPos.subtract(boxAbsPos);
|
|
136
|
+
const joint = new BallAndSocketConstraint(distanceFromParentBoxToBone, myConnectedPivot, this._boxConfigs[i].rotationAxis, this._boxConfigs[i].rotationAxis, this._scene);
|
|
137
|
+
this._aggregates[boneParentIndex].body.addConstraint(this._aggregates[i].body, joint);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
_syncBonesAndBoxes() {
|
|
141
|
+
if (this.pauseSync) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (this._ragdollMode) {
|
|
145
|
+
this._bones[this._rootBoneIndex].getDirectionToRef(this._boxConfigs[this._rootBoneIndex].boneOffsetAxis, this._mesh, TmpVectors.Vector3[0]);
|
|
146
|
+
TmpVectors.Vector3[0].scaleInPlace(this._boxConfigs[this._rootBoneIndex].boxOffset);
|
|
147
|
+
this._bones[this._rootBoneIndex].getAbsolutePositionToRef(this._mesh, TmpVectors.Vector3[1]);
|
|
148
|
+
TmpVectors.Vector3[1].addInPlace(TmpVectors.Vector3[0]);
|
|
149
|
+
this._bones[this._rootBoneIndex].setAbsolutePosition(this._transforms[this._rootBoneIndex].position, this._mesh);
|
|
150
|
+
this._addImpostorRotationToBone(this._rootBoneIndex);
|
|
151
|
+
const rootPos = this._aggregates[this._rootBoneIndex].body.transformNode.position;
|
|
152
|
+
// Move the mesh, to guarantee alignment between root bone and impostor box position
|
|
153
|
+
TmpVectors.Vector3[1].subtractToRef(rootPos, TmpVectors.Vector3[0]);
|
|
154
|
+
this._mesh.position.subtractToRef(TmpVectors.Vector3[0], this._mesh.position);
|
|
155
|
+
for (let i = 0; i < this._bones.length; i++) {
|
|
156
|
+
if (i == this._rootBoneIndex)
|
|
157
|
+
continue;
|
|
158
|
+
this._addImpostorRotationToBone(i);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
_addImpostorRotationToBone(boneIndex) {
|
|
163
|
+
var _a, _b, _c;
|
|
164
|
+
(_c = (_b = (_a = this._aggregates[boneIndex].body) === null || _a === void 0 ? void 0 : _a.transformNode) === null || _b === void 0 ? void 0 : _b.rotationQuaternion) === null || _c === void 0 ? void 0 : _c.multiplyToRef(this._initialRotation[boneIndex], TmpVectors.Quaternion[0]);
|
|
165
|
+
this._bones[boneIndex].setRotationQuaternion(TmpVectors.Quaternion[0], Space.WORLD, this._mesh);
|
|
166
|
+
}
|
|
167
|
+
// Return true if root bone is valid/exists in this.bonesNames. false otherwise.
|
|
168
|
+
_defineRootBone() {
|
|
169
|
+
const skeletonRoots = this._skeleton.getChildren();
|
|
170
|
+
if (skeletonRoots.length != 1) {
|
|
171
|
+
Logger.Log("Ragdoll creation failed: there can only be one root in the skeleton.");
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
this._rootBoneName = skeletonRoots[0].name;
|
|
175
|
+
this._rootBoneIndex = this._boneNames.indexOf(this._rootBoneName);
|
|
176
|
+
if (this._rootBoneIndex == -1) {
|
|
177
|
+
Logger.Log("Ragdoll creation failed: the array boneNames doesn't have the root bone. The root bone is " + this._skeleton.getChildren());
|
|
178
|
+
return false;
|
|
179
|
+
}
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
_findNearestParent(boneIndex) {
|
|
183
|
+
let nearestParent = this._bones[boneIndex].getParent();
|
|
184
|
+
do {
|
|
185
|
+
if (nearestParent != null && this._boneNames.includes(nearestParent.name)) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
nearestParent = nearestParent === null || nearestParent === void 0 ? void 0 : nearestParent.getParent();
|
|
189
|
+
} while (nearestParent != null);
|
|
190
|
+
return nearestParent;
|
|
191
|
+
}
|
|
192
|
+
_init() {
|
|
193
|
+
this._createColliders();
|
|
194
|
+
// If this.defineRootBone() returns false... there is not root bone.
|
|
195
|
+
if (!this._defineRootBone()) {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
this._initJoints();
|
|
199
|
+
this._scene.registerBeforeRender(() => {
|
|
200
|
+
this._syncBonesAndBoxes();
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Enable ragdoll mode. Create physics objects and make them dynamic.
|
|
205
|
+
*/
|
|
206
|
+
ragdoll() {
|
|
207
|
+
if (!this._ragdollMode) {
|
|
208
|
+
this._ragdollMode = true;
|
|
209
|
+
this._init();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Dispose resources and remove physics objects
|
|
214
|
+
*/
|
|
215
|
+
dispose() {
|
|
216
|
+
this._aggregates.forEach((aggregate) => {
|
|
217
|
+
aggregate.dispose();
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=ragdoll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ragdoll.js","sourceRoot":"","sources":["../../../../../dev/core/src/Physics/v2/ragdoll.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAE9D,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,iCAA6B;AACnD,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAGjF,O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ton\";\r\nimport { Vector3, Matrix, TmpVectors } from \"../../Maths/math.vector\";\r\nimport type { Quaternion } from \"../../Maths/math.vector\";\r\nimport type { Scene } from \"../../scene\";\r\nimport { PhysicsAggregate } from \"./physicsAggregate\";\r\nimport { BallAndSocketConstraint } from \"./physicsConstraint\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport { Axis, Space } from \"core/Maths/math.axis\";\r\nimport { PhysicsShapeType, PhysicsConstraintType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Bone } from \"../../Bones/bone\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport { TransformNode } from \"../../Meshes/transformNode\";\r\n\r\n/**\r\n * Ragdoll bone properties\r\n * @experimental\r\n */\r\nexport class RagdollBoneProperties {\r\n /**\r\n * Width of the box shape\r\n */\r\n width?: number;\r\n /**\r\n * depth of the box shape\r\n */\r\n depth?: number;\r\n /**\r\n * height of the box shape\r\n */\r\n height?: number;\r\n /**\r\n * size that will be used of width, depth and height of the shape box\r\n */\r\n size?: number;\r\n /**\r\n * Type of Physics Constraint used between bones\r\n */\r\n joint?: number | undefined;\r\n /**\r\n * Main rotation axis used by the constraint, in local space\r\n */\r\n rotationAxis?: Vector3;\r\n /**\r\n * Minimum rotation angle value\r\n */\r\n min?: number;\r\n /**\r\n * Maximum rotation angle value\r\n */\r\n max?: number;\r\n /**\r\n * Offset along local axis\r\n */\r\n boxOffset?: number;\r\n /**\r\n * Axis that need an offset\r\n */\r\n boneOffsetAxis?: Vector3;\r\n}\r\n\r\n/**\r\n * Ragdoll for Physics V2\r\n * Current known limitation is scene must be using Right hand coordinates\r\n * @experimental\r\n */\r\nexport class Ragdoll {\r\n private _skeleton: Skeleton;\r\n private _scene: Scene;\r\n private _mesh: Mesh;\r\n private _config: any;\r\n private _boxConfigs: Array<RagdollBoneProperties> = new Array<RagdollBoneProperties>();\r\n\r\n private _bones: Array<Bone> = new Array<Bone>();\r\n private _initialRotation: Array<Quaternion> = new Array<Quaternion>();\r\n private _boneNames: string[] = [];\r\n private _transforms: Array<TransformNode> = new Array<TransformNode>();\r\n private _aggregates: Array<PhysicsAggregate> = new Array<PhysicsAggregate>();\r\n private _ragdollMode: boolean = false;\r\n private _rootBoneName: string = \"\";\r\n private _rootBoneIndex: number = -1;\r\n private _mass: number = 10;\r\n private _restitution: number = 0;\r\n\r\n /**\r\n * Pause synchronization between physics and bone position/orientation\r\n */\r\n public pauseSync: boolean = false;\r\n\r\n private _putBoxesInBoneCenter: boolean;\r\n private _defaultJoint: number = PhysicsConstraintType.HINGE;\r\n private _defaultJointMin: number = -90;\r\n private _defaultJointMax: number = 90;\r\n\r\n private _boneOffsetAxis: Vector3;\r\n\r\n /**\r\n * Construct a new Ragdoll object. Once ready, it can be made dynamic by calling `Ragdoll` method\r\n * @param skeleton The skeleton containing bones to be physicalized\r\n * @param mesh The mesh used by the skeleton\r\n * @param config an array of `RagdollBoneProperties` corresponding to bones and their properties used to instanciate physics bodies\r\n */\r\n constructor(skeleton: Skeleton, mesh: Mesh, config: RagdollBoneProperties[]) {\r\n this._skeleton = skeleton;\r\n this._scene = skeleton.getScene();\r\n this._mesh = mesh;\r\n this._config = config; // initial, user defined box configs. May have several box configs jammed into 1 index.\r\n this._boxConfigs = []; // final box configs. Every element is a separate box config (this.config may have several configs jammed into 1 index).\r\n this._putBoxesInBoneCenter = false;\r\n this._defaultJoint = PhysicsConstraintType.HINGE;\r\n this._boneOffsetAxis = Axis.Y;\r\n }\r\n\r\n private _createColliders(): void {\r\n this._mesh.computeWorldMatrix();\r\n\r\n const config = this._config;\r\n for (let i = 0; i < config.length; i++) {\r\n const boneNames = config[i].bone !== undefined ? [config[i].bone] : config[i].bones;\r\n\r\n for (let ii = 0; ii < boneNames.length; ii++) {\r\n const currentBone = this._skeleton.bones[this._skeleton.getBoneIndexByName(boneNames[ii])];\r\n if (currentBone == undefined) {\r\n return;\r\n }\r\n\r\n // First define the box dimensions, so we can then use them when calling CreateBox().\r\n const currentRagdollBoneProperties: RagdollBoneProperties = {\r\n width: this._config[i].width,\r\n depth: this._config[i].depth,\r\n height: this._config[i].height,\r\n size: this._config[i].size,\r\n };\r\n\r\n currentRagdollBoneProperties.width = currentRagdollBoneProperties.width ?? currentRagdollBoneProperties.size;\r\n currentRagdollBoneProperties.depth = currentRagdollBoneProperties.depth ?? currentRagdollBoneProperties.size;\r\n currentRagdollBoneProperties.height = currentRagdollBoneProperties.height ?? currentRagdollBoneProperties.size;\r\n const transform = new TransformNode(boneNames[ii] + \"_transform\", this._scene);\r\n\r\n // Define the rest of the box properties.\r\n currentRagdollBoneProperties.joint = config[i].joint !== undefined ? config[i].joint : this._defaultJoint;\r\n currentRagdollBoneProperties.rotationAxis = config[i].rotationAxis !== undefined ? config[i].rotationAxis : Axis.X;\r\n currentRagdollBoneProperties.min = config[i].min !== undefined ? config[i].min : this._defaultJointMin;\r\n currentRagdollBoneProperties.max = config[i].max !== undefined ? config[i].max : this._defaultJointMax;\r\n\r\n // Offset value.\r\n let boxOffset = 0;\r\n if ((config[i].putBoxInBoneCenter !== undefined && config[i].putBoxInBoneCenter) || this._putBoxesInBoneCenter) {\r\n if (currentBone.length === undefined) {\r\n Logger.Log(\"The length property is not defined for bone \" + currentBone.name);\r\n }\r\n boxOffset = currentBone.length / 2;\r\n } else if (config[i].boxOffset !== undefined) {\r\n boxOffset = config[i].boxOffset;\r\n }\r\n currentRagdollBoneProperties.boxOffset = boxOffset;\r\n\r\n // Offset axis.\r\n const boneOffsetAxis = config[i].boneOffsetAxis !== undefined ? config[i].boneOffsetAxis : this._boneOffsetAxis;\r\n const boneDir = currentBone.getDirection(boneOffsetAxis, this._mesh);\r\n currentRagdollBoneProperties.boneOffsetAxis = boneOffsetAxis;\r\n\r\n transform.position = currentBone.getAbsolutePosition(this._mesh).add(boneDir.scale(boxOffset));\r\n\r\n const mass = config[i].mass !== undefined ? config[i].mass : this._mass;\r\n const restitution = config[i].restitution !== undefined ? config[i].restitution : this._restitution;\r\n const aggregate = new PhysicsAggregate(\r\n transform,\r\n PhysicsShapeType.BOX,\r\n {\r\n mass: mass,\r\n restitution: restitution,\r\n friction: 0.6,\r\n extents: new Vector3(currentRagdollBoneProperties.width, currentRagdollBoneProperties.height, currentRagdollBoneProperties.depth),\r\n },\r\n this._scene\r\n );\r\n aggregate.body.setCollisionCallbackEnabled(true);\r\n aggregate.body.disablePreStep = false;\r\n this._aggregates.push(aggregate);\r\n this._bones.push(currentBone);\r\n this._boneNames.push(currentBone.name);\r\n this._transforms.push(transform);\r\n this._boxConfigs.push(currentRagdollBoneProperties);\r\n this._initialRotation.push(currentBone.getRotationQuaternion(Space.WORLD, this._mesh));\r\n }\r\n }\r\n }\r\n\r\n private _initJoints(): void {\r\n this._mesh.computeWorldMatrix();\r\n for (let i = 0; i < this._bones.length; i++) {\r\n // The root bone has no joints.\r\n if (i == this._rootBoneIndex) continue;\r\n\r\n const nearestParent = this._findNearestParent(i);\r\n\r\n if (nearestParent == null) {\r\n Logger.Warn(\"Couldn't find a nearest parent bone in the configs for bone called \" + this._boneNames[i]);\r\n return;\r\n }\r\n\r\n const boneParentIndex = this._boneNames.indexOf(nearestParent.name);\r\n\r\n let distanceFromParentBoxToBone = this._bones[i].getAbsolutePosition(this._mesh).subtract(this._transforms[boneParentIndex].position);\r\n\r\n const wmat = this._transforms[boneParentIndex].computeWorldMatrix();\r\n const invertedWorldMat = Matrix.Invert(wmat);\r\n distanceFromParentBoxToBone = Vector3.TransformCoordinates(this._bones[i].getAbsolutePosition(this._mesh), invertedWorldMat);\r\n\r\n const boneAbsPos = this._bones[i].getAbsolutePosition(this._mesh);\r\n const boxAbsPos = this._transforms[i].position.clone();\r\n const myConnectedPivot = boneAbsPos.subtract(boxAbsPos);\r\n\r\n const joint = new BallAndSocketConstraint(\r\n distanceFromParentBoxToBone,\r\n myConnectedPivot,\r\n this._boxConfigs[i].rotationAxis!,\r\n this._boxConfigs[i].rotationAxis!,\r\n this._scene\r\n );\r\n this._aggregates[boneParentIndex].body.addConstraint(this._aggregates[i].body, joint);\r\n }\r\n }\r\n\r\n private _syncBonesAndBoxes(): void {\r\n if (this.pauseSync) {\r\n return;\r\n }\r\n\r\n if (this._ragdollMode) {\r\n this._bones[this._rootBoneIndex].getDirectionToRef(this._boxConfigs[this._rootBoneIndex].boneOffsetAxis!, this._mesh, TmpVectors.Vector3[0]);\r\n TmpVectors.Vector3[0].scaleInPlace(this._boxConfigs[this._rootBoneIndex].boxOffset!);\r\n this._bones[this._rootBoneIndex].getAbsolutePositionToRef(this._mesh, TmpVectors.Vector3[1]);\r\n TmpVectors.Vector3[1].addInPlace(TmpVectors.Vector3[0]);\r\n\r\n this._bones[this._rootBoneIndex].setAbsolutePosition(this._transforms[this._rootBoneIndex].position, this._mesh);\r\n this._addImpostorRotationToBone(this._rootBoneIndex);\r\n\r\n const rootPos = this._aggregates[this._rootBoneIndex].body.transformNode.position;\r\n\r\n // Move the mesh, to guarantee alignment between root bone and impostor box position\r\n TmpVectors.Vector3[1].subtractToRef(rootPos, TmpVectors.Vector3[0]);\r\n this._mesh.position.subtractToRef(TmpVectors.Vector3[0], this._mesh.position);\r\n\r\n for (let i = 0; i < this._bones.length; i++) {\r\n if (i == this._rootBoneIndex) continue;\r\n this._addImpostorRotationToBone(i);\r\n }\r\n }\r\n }\r\n\r\n private _addImpostorRotationToBone(boneIndex: number): void {\r\n this._aggregates[boneIndex].body?.transformNode?.rotationQuaternion?.multiplyToRef(this._initialRotation[boneIndex], TmpVectors.Quaternion[0]);\r\n this._bones[boneIndex].setRotationQuaternion(TmpVectors.Quaternion[0], Space.WORLD, this._mesh);\r\n }\r\n\r\n // Return true if root bone is valid/exists in this.bonesNames. false otherwise.\r\n private _defineRootBone(): boolean {\r\n const skeletonRoots = this._skeleton.getChildren();\r\n if (skeletonRoots.length != 1) {\r\n Logger.Log(\"Ragdoll creation failed: there can only be one root in the skeleton.\");\r\n return false;\r\n }\r\n\r\n this._rootBoneName = skeletonRoots[0].name;\r\n this._rootBoneIndex = this._boneNames.indexOf(this._rootBoneName);\r\n if (this._rootBoneIndex == -1) {\r\n Logger.Log(\"Ragdoll creation failed: the array boneNames doesn't have the root bone. The root bone is \" + this._skeleton.getChildren());\r\n return false;\r\n }\r\n\r\n return true;\r\n }\r\n\r\n private _findNearestParent(boneIndex: number): any {\r\n let nearestParent: Nullable<Bone> | undefined = this._bones[boneIndex].getParent();\r\n do {\r\n if (nearestParent != null && this._boneNames.includes(nearestParent.name)) {\r\n break;\r\n }\r\n\r\n nearestParent = nearestParent?.getParent();\r\n } while (nearestParent != null);\r\n\r\n return nearestParent;\r\n }\r\n\r\n private _init() {\r\n this._createColliders();\r\n\r\n // If this.defineRootBone() returns false... there is not root bone.\r\n if (!this._defineRootBone()) {\r\n return;\r\n }\r\n\r\n this._initJoints();\r\n this._scene.registerBeforeRender(() => {\r\n this._syncBonesAndBoxes();\r\n });\r\n }\r\n\r\n /**\r\n * Enable ragdoll mode. Create physics objects and make them dynamic.\r\n */\r\n public ragdoll(): void {\r\n if (!this._ragdollMode) {\r\n this._ragdollMode = true;\r\n this._init();\r\n }\r\n }\r\n\r\n /**\r\n * Dispose resources and remove physics objects\r\n */\r\n dispose(): void {\r\n this._aggregates.forEach((aggregate: PhysicsAggregate) => {\r\n aggregate.dispose();\r\n });\r\n }\r\n}\r\n"]}
|
|
@@ -228,13 +228,13 @@ export class SSAO2RenderingPipeline extends PostProcessRenderPipeline {
|
|
|
228
228
|
if (this._forceGeometryBuffer) {
|
|
229
229
|
scene.enableGeometryBufferRenderer();
|
|
230
230
|
if ((_a = scene.geometryBufferRenderer) === null || _a === void 0 ? void 0 : _a.generateNormalsInWorldSpace) {
|
|
231
|
-
|
|
231
|
+
Logger.Error("SSAO2RenderingPipeline does not support generateNormalsInWorldSpace=true for the geometry buffer renderer!");
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
234
|
else {
|
|
235
235
|
scene.enablePrePassRenderer();
|
|
236
236
|
if ((_b = scene.prePassRenderer) === null || _b === void 0 ? void 0 : _b.generateNormalsInWorldSpace) {
|
|
237
|
-
|
|
237
|
+
Logger.Error("SSAO2RenderingPipeline does not support generateNormalsInWorldSpace=true for the prepass renderer!");
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
this._createRandomTexture();
|