@babylonjs/core 5.57.0 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Engines/WebGPU/Extensions/engine.multiRender.js +51 -8
- package/Engines/WebGPU/Extensions/engine.multiRender.js.map +1 -1
- package/Engines/WebGPU/webgpuHardwareTexture.d.ts +4 -3
- package/Engines/WebGPU/webgpuHardwareTexture.js +23 -10
- package/Engines/WebGPU/webgpuHardwareTexture.js.map +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.d.ts +1 -1
- package/Engines/WebGPU/webgpuTextureHelper.js +6 -14
- package/Engines/WebGPU/webgpuTextureHelper.js.map +1 -1
- package/Engines/engine.d.ts +5 -6
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +16 -8
- package/Engines/webgpuEngine.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.d.ts +2 -0
- package/Lights/Shadows/shadowGenerator.js +11 -22
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Maths/math.vector.js +4 -2
- package/Maths/math.vector.js.map +1 -1
- package/Meshes/abstractMesh.d.ts +13 -0
- package/Meshes/abstractMesh.js +20 -0
- package/Meshes/abstractMesh.js.map +1 -1
- package/Meshes/thinInstanceMesh.js +4 -1
- package/Meshes/thinInstanceMesh.js.map +1 -1
- package/Particles/solidParticleSystem.d.ts +1 -1
- package/Particles/solidParticleSystem.js +1 -1
- package/Particles/solidParticleSystem.js.map +1 -1
- package/Physics/physicsEngineComponent.d.ts +1 -0
- package/Physics/physicsEngineComponent.js +1 -0
- package/Physics/physicsEngineComponent.js.map +1 -1
- package/Physics/physicsHelper.d.ts +12 -5
- package/Physics/physicsHelper.js +160 -90
- package/Physics/physicsHelper.js.map +1 -1
- package/Physics/physicsRaycastResult.d.ts +9 -0
- package/Physics/physicsRaycastResult.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +120 -77
- package/Physics/v2/IPhysicsEnginePlugin.js +119 -48
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/Plugins/havokPlugin.d.ts +687 -0
- package/Physics/v2/Plugins/havokPlugin.js +1592 -0
- package/Physics/v2/Plugins/havokPlugin.js.map +1 -0
- package/Physics/v2/Plugins/index.d.ts +1 -0
- package/Physics/v2/Plugins/index.js +1 -1
- package/Physics/v2/Plugins/index.js.map +1 -1
- package/Physics/v2/index.d.ts +1 -0
- package/Physics/v2/index.js +2 -0
- package/Physics/v2/index.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +9 -2
- package/Physics/v2/physicsAggregate.js +66 -31
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +51 -62
- package/Physics/v2/physicsBody.js +101 -128
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsConstraint.d.ts +57 -25
- package/Physics/v2/physicsConstraint.js +32 -15
- package/Physics/v2/physicsConstraint.js.map +1 -1
- package/Physics/v2/physicsEngine.d.ts +0 -1
- package/Physics/v2/physicsEngine.js +0 -1
- package/Physics/v2/physicsEngine.js.map +1 -1
- package/Physics/v2/physicsEngineComponent.d.ts +0 -10
- package/Physics/v2/physicsEngineComponent.js +0 -29
- package/Physics/v2/physicsEngineComponent.js.map +1 -1
- package/Physics/v2/physicsShape.d.ts +52 -11
- package/Physics/v2/physicsShape.js +80 -23
- package/Physics/v2/physicsShape.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,OAA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C,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,eAAe,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;gBAC7I,MAAM;SACb;IACL,CAAC;IAED;;OAEG;IACI,OAAO;QACV,IAAI,IAAI,CAAC,oBAAoB,EAAE;YAC3B,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;YAC9E,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;SACpC;QACD,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { PhysicsMotionType, ShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n /**\r\n * The native options of the physics aggregate\r\n */\r\n nativeOptions?: any;\r\n /**\r\n * Specifies if the parent should be ignored\r\n */\r\n ignoreParent?: boolean;\r\n /**\r\n * Specifies if bi-directional transformations should be disabled\r\n */\r\n disableBidirectionalTransformation?: boolean;\r\n /**\r\n * The pressure inside the physics aggregate, soft object only\r\n */\r\n pressure?: number;\r\n /**\r\n * The stiffness the physics aggregate, soft object only\r\n */\r\n stiffness?: number;\r\n /**\r\n * The number of iterations used in maintaining consistent vertex velocities, soft object only\r\n */\r\n velocityIterations?: number;\r\n /**\r\n * The number of iterations used in maintaining consistent vertex positions, soft object only\r\n */\r\n positionIterations?: number;\r\n /**\r\n * The number used to fix points on a cloth (0, 1, 2, 4, 8) or rope (0, 1, 2) only\r\n * 0 None, 1, back left or top, 2, back right or bottom, 4, front left, 8, front right\r\n * Add to fix multiple points\r\n */\r\n fixedPoints?: number;\r\n /**\r\n * The collision margin around a soft object\r\n */\r\n margin?: number;\r\n /**\r\n * The collision margin around a soft object\r\n */\r\n damping?: number;\r\n /**\r\n * The path for a rope based on an extrusion\r\n */\r\n path?: any;\r\n /**\r\n * The shape of an extrusion used for a rope based on an extrusion\r\n */\r\n shape?: any;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: number,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n if (this.transformNode.parent && this._options.mass !== 0) {\r\n Logger.Warn(\"A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.\");\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n this.body = new PhysicsBody(transformNode, motionType, this._scene);\r\n this._addSizeOptions();\r\n this._options.center = _options.center ?? this.body.getObjectCenterDelta();\r\n this.shape = new PhysicsShape({ type, parameters: this._options as any }, this._scene);\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.massProperties = { mass: this._options.mass };\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n // The body is already disposed on its own observable, so it's not necessary to dispose it here.\r\n this.shape.dispose();\r\n });\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n const impostorExtents = this.body.getObjectExtents();\r\n\r\n switch (this.type) {\r\n case ShapeType.SPHERE:\r\n if (Scalar.WithinEpsilon(impostorExtents.x, impostorExtents.y, 0.0001) && Scalar.WithinEpsilon(impostorExtents.x, impostorExtents.z, 0.0001)) {\r\n this._options.radius = this._options.radius ? this._options.radius : impostorExtents.x / 2;\r\n } else {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes.\");\r\n }\r\n break;\r\n case ShapeType.CAPSULE:\r\n {\r\n const capRadius = impostorExtents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, -impostorExtents.y * 0.5 + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, impostorExtents.y * 0.5 - capRadius, 0);\r\n }\r\n break;\r\n case ShapeType.CYLINDER:\r\n {\r\n const capRadius = impostorExtents.x / 2;\r\n this._options.radius = this._options.radius ? this._options.radius : capRadius;\r\n this._options.pointA = this._options.pointA ? this._options.pointA : new Vector3(0, -impostorExtents.y * 0.5, 0);\r\n this._options.pointB = this._options.pointB ? this._options.pointB : new Vector3(0, impostorExtents.y * 0.5, 0);\r\n }\r\n break;\r\n case ShapeType.MESH:\r\n case ShapeType.CONVEX_HULL:\r\n if (!this._options.mesh && (this.transformNode.getClassName() === \"Mesh\" || this.transformNode.getClassName() === \"InstancedMesh\")) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else {\r\n Logger.Warn(\"No mesh was provided for the mesh shape\");\r\n }\r\n break;\r\n case ShapeType.BOX:\r\n this._options.extents = this._options.extents ? this._options.extents : new Vector3(impostorExtents.x, impostorExtents.y, impostorExtents.z);\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n this.shape.dispose();\r\n }\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM7E,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAwGxD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAoBzB;IACI;;OAEG;IACI,aAA4B;IACnC;;OAEG;IACI,IAAqC,EACpC,WAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,EAClD,MAAc;;QANf,kBAAa,GAAb,aAAa,CAAe;QAI5B,SAAI,GAAJ,IAAI,CAAiC;QACpC,aAAQ,GAAR,QAAQ,CAA0C;QAClD,WAAM,GAAN,MAAM,CAAQ;QAdlB,8BAAyB,GAAG,IAAI,CAAC;QAgBrC,eAAe;QACf,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACrB,MAAM,CAAC,KAAK,CAAC,wDAAwD,CAAC,CAAC;YACvE,OAAO;SACV;QACD,IAAI,IAAI,CAAC,aAAa,CAAC,MAAM,IAAI,IAAI,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC,EAAE;YACvD,MAAM,CAAC,IAAI,CAAC,sJAAsJ,CAAC,CAAC;SACvK;QAED,iCAAiC;QACjC,IAAI,CAAC,IAAI,CAAC,MAAM,IAAI,aAAa,CAAC,QAAQ,EAAE;YACx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,CAAC,yBAAyB,EAAE;YAChC,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;SACxB;IACL,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport { PhysicsShape } from \"./physicsShape\";\r\nimport { Logger } from \"../../Misc/logger\";\r\nimport type { Scene } from \"../../scene\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport { TmpVectors, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { PhysicsMotionType, PhysicsShapeType } from \"./IPhysicsEnginePlugin\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Observer } from \"../../Misc/observable\";\r\nimport type { Nullable } from \"../../types\";\r\nimport type { Node } from \"../../node\";\r\nimport type { AbstractMesh } from \"../../Meshes/abstractMesh\";\r\nimport { BoundingBox } from \"../../Culling/boundingBox\";\r\n\r\n/**\r\n * The interface for the physics aggregate parameters\r\n */\r\nexport interface PhysicsAggregateParameters {\r\n /**\r\n * The mass of the physics aggregate\r\n */\r\n mass: number;\r\n /**\r\n * The friction of the physics aggregate\r\n */\r\n friction?: number;\r\n /**\r\n * The coefficient of restitution of the physics aggregate\r\n */\r\n restitution?: number;\r\n /**\r\n * The native options of the physics aggregate\r\n */\r\n nativeOptions?: any;\r\n /**\r\n * Specifies if the parent should be ignored\r\n */\r\n ignoreParent?: boolean;\r\n /**\r\n * Specifies if bi-directional transformations should be disabled\r\n */\r\n disableBidirectionalTransformation?: boolean;\r\n /**\r\n * The pressure inside the physics aggregate, soft object only\r\n */\r\n pressure?: number;\r\n /**\r\n * The stiffness the physics aggregate, soft object only\r\n */\r\n stiffness?: number;\r\n /**\r\n * The number of iterations used in maintaining consistent vertex velocities, soft object only\r\n */\r\n velocityIterations?: number;\r\n /**\r\n * The number of iterations used in maintaining consistent vertex positions, soft object only\r\n */\r\n positionIterations?: number;\r\n /**\r\n * The number used to fix points on a cloth (0, 1, 2, 4, 8) or rope (0, 1, 2) only\r\n * 0 None, 1, back left or top, 2, back right or bottom, 4, front left, 8, front right\r\n * Add to fix multiple points\r\n */\r\n fixedPoints?: number;\r\n /**\r\n * The collision margin around a soft object\r\n */\r\n margin?: number;\r\n /**\r\n * The collision margin around a soft object\r\n */\r\n damping?: number;\r\n /**\r\n * The path for a rope based on an extrusion\r\n */\r\n path?: any;\r\n /**\r\n * The shape of an extrusion used for a rope based on an extrusion\r\n */\r\n shape?: any;\r\n\r\n /**\r\n * Radius for sphere, cylinder and capsule\r\n */\r\n radius?: number;\r\n\r\n /**\r\n * Starting point for cylinder/capsule\r\n */\r\n pointA?: Vector3;\r\n\r\n /**\r\n * Ending point for cylinder/capsule\r\n */\r\n pointB?: Vector3;\r\n\r\n /**\r\n * Extents for box\r\n */\r\n extents?: Vector3;\r\n\r\n /**\r\n * mesh local center\r\n */\r\n center?: Vector3;\r\n\r\n /**\r\n * mesh object. Used for mesh and convex hull aggregates.\r\n */\r\n mesh?: Mesh;\r\n\r\n /**\r\n * Physics engine will try to make this body sleeping and not active\r\n */\r\n startAsleep?: boolean;\r\n}\r\n/**\r\n * Helper class to create and interact with a PhysicsAggregate.\r\n * This is a transition object that works like Physics Plugin V1 Impostors.\r\n * This helper instanciate all mandatory physics objects to get a body/shape and material.\r\n * It's less efficient that handling body and shapes independently but for prototyping or\r\n * a small numbers of physics objects, it's good enough.\r\n */\r\nexport class PhysicsAggregate {\r\n /**\r\n * The body that is associated with this aggregate\r\n */\r\n public body: PhysicsBody;\r\n\r\n /**\r\n * The shape that is associated with this aggregate\r\n */\r\n public shape: PhysicsShape;\r\n\r\n /**\r\n * The material that is associated with this aggregate\r\n */\r\n public material: PhysicsMaterial;\r\n\r\n private _disposeShapeWhenDisposed = true;\r\n\r\n private _nodeDisposeObserver: Nullable<Observer<Node>>;\r\n\r\n constructor(\r\n /**\r\n * The physics-enabled object used as the physics aggregate\r\n */\r\n public transformNode: TransformNode,\r\n /**\r\n * The type of the physics aggregate\r\n */\r\n public type: PhysicsShapeType | PhysicsShape,\r\n private _options: PhysicsAggregateParameters = { mass: 0 },\r\n private _scene?: Scene\r\n ) {\r\n //sanity check!\r\n if (!this.transformNode) {\r\n Logger.Error(\"No object was provided. A physics object is obligatory\");\r\n return;\r\n }\r\n if (this.transformNode.parent && this._options.mass !== 0) {\r\n Logger.Warn(\"A physics impostor has been created for an object which has a parent. Babylon physics currently works in local space so unexpected issues may occur.\");\r\n }\r\n\r\n // Legacy support for old syntax.\r\n if (!this._scene && transformNode.getScene) {\r\n this._scene = transformNode.getScene();\r\n }\r\n\r\n if (!this._scene) {\r\n return;\r\n }\r\n\r\n //default options params\r\n this._options.mass = _options.mass === void 0 ? 0 : _options.mass;\r\n this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;\r\n this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;\r\n\r\n const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;\r\n const startAsleep = this._options.startAsleep ?? false;\r\n this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);\r\n this._addSizeOptions();\r\n if ((type as any).getClassName && (type as any).getClassName() === \"PhysicsShape\") {\r\n this.shape = type as PhysicsShape;\r\n this._disposeShapeWhenDisposed = false;\r\n } else {\r\n this.shape = new PhysicsShape({ type: type as PhysicsShapeType, parameters: this._options as any }, this._scene);\r\n }\r\n\r\n this.material = { friction: this._options.friction, restitution: this._options.restitution };\r\n this.body.shape = this.shape;\r\n this.shape.material = this.material;\r\n\r\n this.body.setMassProperties({ mass: this._options.mass });\r\n\r\n this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {\r\n this.dispose();\r\n });\r\n }\r\n\r\n private _getObjectBoundingBox() {\r\n if ((this.transformNode as AbstractMesh).getRawBoundingInfo) {\r\n return (this.transformNode as AbstractMesh).getRawBoundingInfo().boundingBox;\r\n } else {\r\n return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));\r\n }\r\n }\r\n\r\n private _addSizeOptions(): void {\r\n this.transformNode.computeWorldMatrix(true);\r\n const bb = this._getObjectBoundingBox();\r\n const extents = TmpVectors.Vector3[0];\r\n extents.copyFrom(bb.extendSizeWorld);\r\n extents.scaleInPlace(2);\r\n extents.multiplyInPlace(this.transformNode.scaling);\r\n\r\n const min = TmpVectors.Vector3[1];\r\n min.copyFrom(bb.minimum);\r\n min.scaleInPlace(2);\r\n min.multiplyInPlace(this.transformNode.scaling);\r\n\r\n if (!this._options.center) {\r\n const center = new Vector3();\r\n center.copyFrom(bb.center);\r\n center.multiplyInPlace(this.transformNode.scaling);\r\n this._options.center = center;\r\n }\r\n\r\n switch (this.type) {\r\n case PhysicsShapeType.SPHERE:\r\n if (!this._options.radius && Scalar.WithinEpsilon(extents.x, extents.y, 0.0001) && Scalar.WithinEpsilon(extents.x, extents.z, 0.0001)) {\r\n this._options.radius = extents.x / 2;\r\n } else if (!this._options.radius) {\r\n Logger.Warn(\"Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.\");\r\n this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;\r\n }\r\n break;\r\n case PhysicsShapeType.CAPSULE:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y + capRadius, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y - capRadius, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.CYLINDER:\r\n {\r\n const capRadius = extents.x / 2;\r\n this._options.radius = this._options.radius ?? capRadius;\r\n this._options.pointA = this._options.pointA ?? new Vector3(0, min.y, 0);\r\n this._options.pointB = this._options.pointB ?? new Vector3(0, min.y + extents.y, 0);\r\n }\r\n break;\r\n case PhysicsShapeType.MESH:\r\n case PhysicsShapeType.CONVEX_HULL:\r\n if (!this._options.mesh && (this.transformNode.getClassName() === \"Mesh\" || this.transformNode.getClassName() === \"InstancedMesh\")) {\r\n this._options.mesh = this.transformNode as Mesh;\r\n } else if (\r\n !(\r\n this._options.mesh &&\r\n this._options.mesh.getClassName &&\r\n (this._options.mesh.getClassName() === \"Mesh\" || this._options.mesh.getClassName() === \"InstancedMesh\")\r\n )\r\n ) {\r\n throw new Error(\"No valid mesh was provided for mesh or convex hull shape parameter.\");\r\n }\r\n break;\r\n case PhysicsShapeType.BOX:\r\n this._options.extents = this._options.extents ?? new Vector3(extents.x, extents.y, extents.z);\r\n break;\r\n }\r\n }\r\n\r\n /**\r\n * Releases the body, shape and material\r\n */\r\n public dispose(): void {\r\n if (this._nodeDisposeObserver) {\r\n this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);\r\n this._nodeDisposeObserver = null;\r\n }\r\n this.body.dispose();\r\n if (this._disposeShapeWhenDisposed) {\r\n this.shape.dispose();\r\n }\r\n }\r\n}\r\n"]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { IPhysicsCollisionEvent,
|
|
1
|
+
import type { IPhysicsCollisionEvent, PhysicsMassProperties, PhysicsMotionType } from "./IPhysicsEnginePlugin";
|
|
2
2
|
import type { PhysicsShape } from "./physicsShape";
|
|
3
3
|
import { Vector3, Quaternion } from "../../Maths/math.vector";
|
|
4
4
|
import type { Scene } from "../../scene";
|
|
5
|
-
import type { AbstractMesh } from "../../Meshes
|
|
6
|
-
import type {
|
|
5
|
+
import type { TransformNode, AbstractMesh } from "../../Meshes";
|
|
6
|
+
import type { Nullable } from "../../types.js";
|
|
7
7
|
import type { PhysicsConstraint } from "./physicsConstraint";
|
|
8
8
|
import type { Bone } from "../../Bones/bone.js";
|
|
9
9
|
import type { Observable } from "../../Misc/observable";
|
|
@@ -29,6 +29,10 @@ export declare class PhysicsBody {
|
|
|
29
29
|
* The engine used to create and manage this Physics Body
|
|
30
30
|
*/
|
|
31
31
|
private _physicsEngine;
|
|
32
|
+
/**
|
|
33
|
+
* If the collision callback is enabled
|
|
34
|
+
*/
|
|
35
|
+
private _collisionCBEnabled;
|
|
32
36
|
/**
|
|
33
37
|
* The transform node associated with this Physics Body
|
|
34
38
|
*/
|
|
@@ -38,8 +42,10 @@ export declare class PhysicsBody {
|
|
|
38
42
|
* True by default for maximum performance.
|
|
39
43
|
*/
|
|
40
44
|
disablePreStep: boolean;
|
|
41
|
-
|
|
42
|
-
|
|
45
|
+
/**
|
|
46
|
+
* Physics engine will try to make this body sleeping and not active
|
|
47
|
+
*/
|
|
48
|
+
startAsleep: boolean;
|
|
43
49
|
private _nodeDisposeObserver;
|
|
44
50
|
/**
|
|
45
51
|
* Constructs a new physics body for the given node.
|
|
@@ -51,7 +57,12 @@ export declare class PhysicsBody {
|
|
|
51
57
|
* It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.
|
|
52
58
|
* It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.
|
|
53
59
|
*/
|
|
54
|
-
constructor(transformNode: TransformNode, motionType: PhysicsMotionType, scene: Scene);
|
|
60
|
+
constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene);
|
|
61
|
+
/**
|
|
62
|
+
* Returns the string "PhysicsBody".
|
|
63
|
+
* @returns "PhysicsBody"
|
|
64
|
+
*/
|
|
65
|
+
getClassName(): string;
|
|
55
66
|
/**
|
|
56
67
|
* Clone the PhysicsBody to a new body and assign it to the transformNode parameter
|
|
57
68
|
* @param transformNode transformNode that will be used for the cloned PhysicsBody
|
|
@@ -63,10 +74,9 @@ export declare class PhysicsBody {
|
|
|
63
74
|
*/
|
|
64
75
|
updateBodyInstances(): void;
|
|
65
76
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param shapeNode - A node with a physics shape. Should be a child of the body node
|
|
77
|
+
* This returns the number of internal instances of the physics body
|
|
68
78
|
*/
|
|
69
|
-
|
|
79
|
+
get numInstances(): number;
|
|
70
80
|
/**
|
|
71
81
|
* Sets the shape of the physics body.
|
|
72
82
|
* @param shape - The shape of the physics body.
|
|
@@ -74,7 +84,7 @@ export declare class PhysicsBody {
|
|
|
74
84
|
* 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.
|
|
75
85
|
* The shape is used to calculate the body's mass, inertia, and other properties.
|
|
76
86
|
*/
|
|
77
|
-
set shape(shape: PhysicsShape);
|
|
87
|
+
set shape(shape: Nullable<PhysicsShape>);
|
|
78
88
|
/**
|
|
79
89
|
* Retrieves the physics shape associated with this object.
|
|
80
90
|
*
|
|
@@ -84,26 +94,7 @@ export declare class PhysicsBody {
|
|
|
84
94
|
* This method is useful for retrieving the physics shape associated with this object,
|
|
85
95
|
* which can be used to apply physical forces to the object or to detect collisions.
|
|
86
96
|
*/
|
|
87
|
-
get shape(): PhysicsShape
|
|
88
|
-
/**
|
|
89
|
-
* Sets the filter group of the physics body.
|
|
90
|
-
* @param group - The filter group of the physics body.
|
|
91
|
-
*
|
|
92
|
-
* This method is useful for setting the filter group of the physics body.
|
|
93
|
-
* The filter group is used to determine which bodies should collide with each other.
|
|
94
|
-
* This allows for more control over the physics engine and can be used to create more realistic simulations.
|
|
95
|
-
*/
|
|
96
|
-
set filterGroup(group: number);
|
|
97
|
-
/**
|
|
98
|
-
* Gets the filter group of the physics engine.
|
|
99
|
-
*
|
|
100
|
-
* @returns The filter group of the physics engine.
|
|
101
|
-
*
|
|
102
|
-
* This method is useful for getting the filter group of the physics engine,
|
|
103
|
-
* which is used to determine which objects will interact with each other.
|
|
104
|
-
* This is important for creating realistic physics simulations.
|
|
105
|
-
*/
|
|
106
|
-
get filterGroup(): number;
|
|
97
|
+
get shape(): Nullable<PhysicsShape>;
|
|
107
98
|
/**
|
|
108
99
|
* Sets the event mask for the physics engine.
|
|
109
100
|
*
|
|
@@ -112,7 +103,7 @@ export declare class PhysicsBody {
|
|
|
112
103
|
* This method is useful for setting the event mask for the physics engine, which determines which events
|
|
113
104
|
* will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.
|
|
114
105
|
*/
|
|
115
|
-
|
|
106
|
+
setEventMask(eventMask: number, instanceIndex?: number): void;
|
|
116
107
|
/**
|
|
117
108
|
* Gets the event mask of the physics engine.
|
|
118
109
|
*
|
|
@@ -123,15 +114,15 @@ export declare class PhysicsBody {
|
|
|
123
114
|
* This is important for ensuring that the engine is responding to the correct events and not
|
|
124
115
|
* wasting resources on unnecessary events.
|
|
125
116
|
*/
|
|
126
|
-
|
|
117
|
+
getEventMask(instanceIndex?: number): number;
|
|
127
118
|
/**
|
|
128
119
|
* Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
129
120
|
*/
|
|
130
|
-
|
|
121
|
+
setMotionType(motionType: PhysicsMotionType, instanceIndex?: number): void;
|
|
131
122
|
/**
|
|
132
123
|
* Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
133
124
|
*/
|
|
134
|
-
|
|
125
|
+
getMotionType(instanceIndex?: number): PhysicsMotionType;
|
|
135
126
|
/**
|
|
136
127
|
* Computes the mass properties of the physics object, based on the set of physics shapes this body uses.
|
|
137
128
|
* This method is useful for computing the initial mass properties of a physics object, such as its mass,
|
|
@@ -139,16 +130,17 @@ export declare class PhysicsBody {
|
|
|
139
130
|
* object in the physics engine, and computing values based on the shape will provide you with reasonable
|
|
140
131
|
* intial values, which you can then customize.
|
|
141
132
|
*/
|
|
142
|
-
computeMassProperties():
|
|
133
|
+
computeMassProperties(instanceIndex?: number): PhysicsMassProperties;
|
|
143
134
|
/**
|
|
144
135
|
* Sets the mass properties of the physics object.
|
|
145
136
|
*
|
|
146
137
|
* @param massProps - The mass properties to set.
|
|
138
|
+
* @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.
|
|
147
139
|
*
|
|
148
140
|
* This method is useful for setting the mass properties of a physics object, such as its mass,
|
|
149
141
|
* inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.
|
|
150
142
|
*/
|
|
151
|
-
|
|
143
|
+
setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void;
|
|
152
144
|
/**
|
|
153
145
|
* Retrieves the mass properties of the object.
|
|
154
146
|
*
|
|
@@ -159,7 +151,7 @@ export declare class PhysicsBody {
|
|
|
159
151
|
* and moment of inertia. This information is necessary for accurate physics
|
|
160
152
|
* simulations.
|
|
161
153
|
*/
|
|
162
|
-
|
|
154
|
+
getMassProperties(instanceIndex?: number): PhysicsMassProperties;
|
|
163
155
|
/**
|
|
164
156
|
* Sets the linear damping of the physics body.
|
|
165
157
|
*
|
|
@@ -169,7 +161,7 @@ export declare class PhysicsBody {
|
|
|
169
161
|
* which is the rate at which the body's velocity decreases over time. This is useful for simulating
|
|
170
162
|
* the effects of air resistance or other forms of friction.
|
|
171
163
|
*/
|
|
172
|
-
|
|
164
|
+
setLinearDamping(damping: number, instanceIndex?: number): void;
|
|
173
165
|
/**
|
|
174
166
|
* Gets the linear damping of the physics body.
|
|
175
167
|
* @returns The linear damping of the physics body.
|
|
@@ -178,7 +170,7 @@ export declare class PhysicsBody {
|
|
|
178
170
|
* resistance the body has to linear motion. This is useful for simulating realistic physics behavior
|
|
179
171
|
* in a game.
|
|
180
172
|
*/
|
|
181
|
-
|
|
173
|
+
getLinearDamping(instanceIndex?: number): number;
|
|
182
174
|
/**
|
|
183
175
|
* Sets the angular damping of the physics body.
|
|
184
176
|
* @param damping The angular damping of the body.
|
|
@@ -187,7 +179,7 @@ export declare class PhysicsBody {
|
|
|
187
179
|
* By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.
|
|
188
180
|
* This can be used to create realistic physical behavior in a physics engine.
|
|
189
181
|
*/
|
|
190
|
-
|
|
182
|
+
setAngularDamping(damping: number, instanceIndex?: number): void;
|
|
191
183
|
/**
|
|
192
184
|
* Gets the angular damping of the physics body.
|
|
193
185
|
*
|
|
@@ -197,7 +189,7 @@ export declare class PhysicsBody {
|
|
|
197
189
|
* which is the rate of reduction of the angular velocity over time.
|
|
198
190
|
* This is important for simulating realistic physics behavior in a game.
|
|
199
191
|
*/
|
|
200
|
-
|
|
192
|
+
getAngularDamping(instanceIndex?: number): number;
|
|
201
193
|
/**
|
|
202
194
|
* Sets the linear velocity of the physics object.
|
|
203
195
|
* @param linVel - The linear velocity to set.
|
|
@@ -207,14 +199,14 @@ export declare class PhysicsBody {
|
|
|
207
199
|
* By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.
|
|
208
200
|
* This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.
|
|
209
201
|
*/
|
|
210
|
-
setLinearVelocity(linVel: Vector3): void;
|
|
202
|
+
setLinearVelocity(linVel: Vector3, instanceIndex?: number): void;
|
|
211
203
|
/**
|
|
212
204
|
* Gets the linear velocity of the physics body and stores it in the given vector3.
|
|
213
205
|
* @param linVel - The vector3 to store the linear velocity in.
|
|
214
206
|
*
|
|
215
207
|
* This method is useful for getting the linear velocity of a physics body in a physics engine.
|
|
216
208
|
* This can be used to determine the speed and direction of the body, which can be used to calculate the motion of the body.*/
|
|
217
|
-
getLinearVelocityToRef(linVel: Vector3): void;
|
|
209
|
+
getLinearVelocityToRef(linVel: Vector3, instanceIndex?: number): void;
|
|
218
210
|
/**
|
|
219
211
|
* Sets the angular velocity of the physics object.
|
|
220
212
|
* @param angVel - The angular velocity to set.
|
|
@@ -223,7 +215,7 @@ export declare class PhysicsBody {
|
|
|
223
215
|
* simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,
|
|
224
216
|
* which is important for simulating realistic motion.
|
|
225
217
|
*/
|
|
226
|
-
setAngularVelocity(angVel: Vector3): void;
|
|
218
|
+
setAngularVelocity(angVel: Vector3, instanceIndex?: number): void;
|
|
227
219
|
/**
|
|
228
220
|
* Gets the angular velocity of the physics body and stores it in the given vector3.
|
|
229
221
|
* @param angVel - The vector3 to store the angular velocity in.
|
|
@@ -231,27 +223,29 @@ export declare class PhysicsBody {
|
|
|
231
223
|
* This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's
|
|
232
224
|
* rotational speed. This information can be used to create realistic physics simulations.
|
|
233
225
|
*/
|
|
234
|
-
getAngularVelocityToRef(angVel: Vector3): void;
|
|
226
|
+
getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void;
|
|
235
227
|
/**
|
|
236
228
|
* Applies an impulse to the physics object.
|
|
237
229
|
*
|
|
238
230
|
* @param impulse The impulse vector.
|
|
239
231
|
* @param location The location of the impulse.
|
|
232
|
+
* @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.
|
|
240
233
|
*
|
|
241
234
|
* This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,
|
|
242
235
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
243
236
|
*/
|
|
244
|
-
applyImpulse(impulse: Vector3, location: Vector3): void;
|
|
237
|
+
applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void;
|
|
245
238
|
/**
|
|
246
239
|
* Applies a force to the physics object.
|
|
247
240
|
*
|
|
248
241
|
* @param force The force vector.
|
|
249
242
|
* @param location The location of the force.
|
|
243
|
+
* @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.
|
|
250
244
|
*
|
|
251
245
|
* This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
|
|
252
246
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
253
247
|
*/
|
|
254
|
-
applyForce(force: Vector3, location: Vector3): void;
|
|
248
|
+
applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void;
|
|
255
249
|
/**
|
|
256
250
|
* Retrieves the geometry of the body from the physics plugin.
|
|
257
251
|
*
|
|
@@ -270,28 +264,18 @@ export declare class PhysicsBody {
|
|
|
270
264
|
* @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable
|
|
271
265
|
*/
|
|
272
266
|
setCollisionCallbackEnabled(enabled: boolean): void;
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
* @returns the object extents
|
|
276
|
-
*/
|
|
277
|
-
getObjectExtents(): Vector3;
|
|
278
|
-
/**
|
|
279
|
-
* returns the delta between the object bounding box center and the mesh origin
|
|
280
|
-
* @returns delta between object bounding box center and origin
|
|
281
|
-
*/
|
|
282
|
-
getObjectCenterDelta(): Vector3;
|
|
283
|
-
/**
|
|
284
|
-
* @returns geometric center of the associated mesh
|
|
285
|
-
*/
|
|
286
|
-
getObjectCenter(): Vector3;
|
|
267
|
+
getObjectCenterWorld(instanceIndex?: number): Vector3;
|
|
268
|
+
getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3;
|
|
287
269
|
/**
|
|
288
270
|
* Adds a constraint to the physics engine.
|
|
289
271
|
*
|
|
290
272
|
* @param childBody - The body to which the constraint will be applied.
|
|
291
273
|
* @param constraint - The constraint to be applied.
|
|
274
|
+
* @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.
|
|
275
|
+
* @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.
|
|
292
276
|
*
|
|
293
277
|
*/
|
|
294
|
-
addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void;
|
|
278
|
+
addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void;
|
|
295
279
|
/**
|
|
296
280
|
* Sync with a bone
|
|
297
281
|
* @param bone The bone that the impostor will be synced to.
|
|
@@ -302,6 +286,11 @@ export declare class PhysicsBody {
|
|
|
302
286
|
* @param boneAxis Optional vector3 axis the bone is aligned with
|
|
303
287
|
*/
|
|
304
288
|
syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3): void;
|
|
289
|
+
/**
|
|
290
|
+
* Executes a callback on the body or all of the instances of a body
|
|
291
|
+
* @param callback the callback to execute
|
|
292
|
+
*/
|
|
293
|
+
iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void): void;
|
|
305
294
|
/**
|
|
306
295
|
* Disposes the body from the physics engine.
|
|
307
296
|
*
|