@babylonjs/core 5.56.0 → 5.57.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Compute/computeShader.d.ts +3 -3
- package/Compute/computeShader.js +22 -12
- package/Compute/computeShader.js.map +1 -1
- package/Culling/boundingInfo.d.ts +1 -1
- package/Culling/boundingInfo.js +9 -3
- package/Culling/boundingInfo.js.map +1 -1
- package/Engines/thinEngine.js +2 -2
- package/Engines/thinEngine.js.map +1 -1
- package/Layers/effectLayer.js +2 -2
- package/Layers/effectLayer.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.d.ts +2 -0
- package/Lights/Shadows/shadowGenerator.js +13 -24
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Materials/clipPlaneMaterialHelper.d.ts +3 -1
- package/Materials/clipPlaneMaterialHelper.js +53 -32
- package/Materials/clipPlaneMaterialHelper.js.map +1 -1
- package/Materials/shaderMaterial.js +2 -2
- package/Materials/shaderMaterial.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/instancedMesh.d.ts +9 -0
- package/Meshes/instancedMesh.js +30 -0
- package/Meshes/instancedMesh.js.map +1 -1
- package/Meshes/thinInstanceMesh.js +4 -1
- package/Meshes/thinInstanceMesh.js.map +1 -1
- package/Particles/gpuParticleSystem.js +2 -2
- package/Particles/gpuParticleSystem.js.map +1 -1
- package/Particles/particleSystem.js +2 -2
- package/Particles/particleSystem.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 +3 -0
- package/Physics/physicsRaycastResult.js.map +1 -1
- package/Physics/v2/IPhysicsEnginePlugin.d.ts +119 -76
- package/Physics/v2/IPhysicsEnginePlugin.js +119 -48
- package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
- package/Physics/v2/physicsAggregate.d.ts +6 -2
- package/Physics/v2/physicsAggregate.js +65 -30
- package/Physics/v2/physicsAggregate.js.map +1 -1
- package/Physics/v2/physicsBody.d.ts +48 -62
- package/Physics/v2/physicsBody.js +100 -128
- package/Physics/v2/physicsBody.js.map +1 -1
- package/Physics/v2/physicsConstraint.d.ts +34 -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 +37 -8
- package/Physics/v2/physicsShape.js +52 -18
- package/Physics/v2/physicsShape.js.map +1 -1
- package/Rendering/depthRenderer.js +2 -2
- package/Rendering/depthRenderer.js.map +1 -1
- package/Rendering/geometryBufferRenderer.js +2 -2
- package/Rendering/geometryBufferRenderer.js.map +1 -1
- package/Rendering/outlineRenderer.js +2 -2
- package/Rendering/outlineRenderer.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { PhysicsBody } from "./physicsBody.js";
|
|
2
2
|
import { PhysicsShape } from "./physicsShape.js";
|
|
3
3
|
import { Logger } from "../../Misc/logger.js";
|
|
4
|
-
import { Vector3 } from "../../Maths/math.vector.js";
|
|
4
|
+
import { TmpVectors, Vector3 } from "../../Maths/math.vector.js";
|
|
5
5
|
import { Scalar } from "../../Maths/math.scalar.js";
|
|
6
|
-
import { PhysicsMotionType,
|
|
6
|
+
import { PhysicsMotionType, PhysicsShapeType } from "./IPhysicsEnginePlugin.js";
|
|
7
|
+
import { BoundingBox } from "../../Culling/boundingBox.js";
|
|
7
8
|
/**
|
|
8
9
|
* Helper class to create and interact with a PhysicsAggregate.
|
|
9
10
|
* This is a transition object that works like Physics Plugin V1 Impostors.
|
|
@@ -26,6 +27,7 @@ export class PhysicsAggregate {
|
|
|
26
27
|
this.type = type;
|
|
27
28
|
this._options = _options;
|
|
28
29
|
this._scene = _scene;
|
|
30
|
+
this._disposeShapeWhenDisposed = true;
|
|
29
31
|
//sanity check!
|
|
30
32
|
if (!this.transformNode) {
|
|
31
33
|
Logger.Error("No object was provided. A physics object is obligatory");
|
|
@@ -46,58 +48,89 @@ export class PhysicsAggregate {
|
|
|
46
48
|
this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;
|
|
47
49
|
this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;
|
|
48
50
|
const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;
|
|
49
|
-
|
|
51
|
+
const startAsleep = (_a = this._options.startAsleep) !== null && _a !== void 0 ? _a : false;
|
|
52
|
+
this.body = new PhysicsBody(transformNode, motionType, startAsleep, this._scene);
|
|
50
53
|
this._addSizeOptions();
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
if (type.getClassName && type.getClassName() === "PhysicsShape") {
|
|
55
|
+
this.shape = type;
|
|
56
|
+
this._disposeShapeWhenDisposed = false;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this.shape = new PhysicsShape({ type: type, parameters: this._options }, this._scene);
|
|
60
|
+
}
|
|
53
61
|
this.material = { friction: this._options.friction, restitution: this._options.restitution };
|
|
54
62
|
this.body.shape = this.shape;
|
|
55
63
|
this.shape.material = this.material;
|
|
56
|
-
this.body.
|
|
64
|
+
this.body.setMassProperties({ mass: this._options.mass });
|
|
57
65
|
this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {
|
|
58
|
-
|
|
59
|
-
this.shape.dispose();
|
|
66
|
+
this.dispose();
|
|
60
67
|
});
|
|
61
68
|
}
|
|
69
|
+
_getObjectBoundingBox() {
|
|
70
|
+
if (this.transformNode.getRawBoundingInfo) {
|
|
71
|
+
return this.transformNode.getRawBoundingInfo().boundingBox;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
return new BoundingBox(new Vector3(-0.5, -0.5, -0.5), new Vector3(0.5, 0.5, 0.5));
|
|
75
|
+
}
|
|
76
|
+
}
|
|
62
77
|
_addSizeOptions() {
|
|
63
|
-
var _a, _b, _c;
|
|
64
|
-
|
|
78
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
79
|
+
this.transformNode.computeWorldMatrix(true);
|
|
80
|
+
const bb = this._getObjectBoundingBox();
|
|
81
|
+
const extents = TmpVectors.Vector3[0];
|
|
82
|
+
extents.copyFrom(bb.extendSizeWorld);
|
|
83
|
+
extents.scaleInPlace(2);
|
|
84
|
+
extents.multiplyInPlace(this.transformNode.scaling);
|
|
85
|
+
const min = TmpVectors.Vector3[1];
|
|
86
|
+
min.copyFrom(bb.minimum);
|
|
87
|
+
min.scaleInPlace(2);
|
|
88
|
+
min.multiplyInPlace(this.transformNode.scaling);
|
|
89
|
+
if (!this._options.center) {
|
|
90
|
+
const center = new Vector3();
|
|
91
|
+
center.copyFrom(bb.center);
|
|
92
|
+
center.multiplyInPlace(this.transformNode.scaling);
|
|
93
|
+
this._options.center = center;
|
|
94
|
+
}
|
|
65
95
|
switch (this.type) {
|
|
66
|
-
case
|
|
67
|
-
if (Scalar.WithinEpsilon(
|
|
68
|
-
this._options.radius =
|
|
96
|
+
case PhysicsShapeType.SPHERE:
|
|
97
|
+
if (!this._options.radius && Scalar.WithinEpsilon(extents.x, extents.y, 0.0001) && Scalar.WithinEpsilon(extents.x, extents.z, 0.0001)) {
|
|
98
|
+
this._options.radius = extents.x / 2;
|
|
69
99
|
}
|
|
70
100
|
else {
|
|
71
|
-
Logger.Warn("Non uniform scaling is unsupported for sphere shapes.");
|
|
101
|
+
Logger.Warn("Non uniform scaling is unsupported for sphere shapes. Setting the radius to the biggest bounding box extent.");
|
|
102
|
+
this._options.radius = Math.max(extents.x, extents.y, extents.z) / 2;
|
|
72
103
|
}
|
|
73
104
|
break;
|
|
74
|
-
case
|
|
105
|
+
case PhysicsShapeType.CAPSULE:
|
|
75
106
|
{
|
|
76
|
-
const capRadius =
|
|
107
|
+
const capRadius = extents.x / 2;
|
|
77
108
|
this._options.radius = (_a = this._options.radius) !== null && _a !== void 0 ? _a : capRadius;
|
|
78
|
-
this._options.pointA = (_b = this._options.pointA) !== null && _b !== void 0 ? _b : new Vector3(0,
|
|
79
|
-
this._options.pointB = (_c = this._options.pointB) !== null && _c !== void 0 ? _c : new Vector3(0,
|
|
109
|
+
this._options.pointA = (_b = this._options.pointA) !== null && _b !== void 0 ? _b : new Vector3(0, min.y + capRadius, 0);
|
|
110
|
+
this._options.pointB = (_c = this._options.pointB) !== null && _c !== void 0 ? _c : new Vector3(0, min.y + extents.y - capRadius, 0);
|
|
80
111
|
}
|
|
81
112
|
break;
|
|
82
|
-
case
|
|
113
|
+
case PhysicsShapeType.CYLINDER:
|
|
83
114
|
{
|
|
84
|
-
const capRadius =
|
|
85
|
-
this._options.radius = this._options.radius ?
|
|
86
|
-
this._options.pointA = this._options.pointA ?
|
|
87
|
-
this._options.pointB = this._options.pointB ?
|
|
115
|
+
const capRadius = extents.x / 2;
|
|
116
|
+
this._options.radius = (_d = this._options.radius) !== null && _d !== void 0 ? _d : capRadius;
|
|
117
|
+
this._options.pointA = (_e = this._options.pointA) !== null && _e !== void 0 ? _e : new Vector3(0, min.y, 0);
|
|
118
|
+
this._options.pointB = (_f = this._options.pointB) !== null && _f !== void 0 ? _f : new Vector3(0, min.y + extents.y, 0);
|
|
88
119
|
}
|
|
89
120
|
break;
|
|
90
|
-
case
|
|
91
|
-
case
|
|
121
|
+
case PhysicsShapeType.MESH:
|
|
122
|
+
case PhysicsShapeType.CONVEX_HULL:
|
|
92
123
|
if (!this._options.mesh && (this.transformNode.getClassName() === "Mesh" || this.transformNode.getClassName() === "InstancedMesh")) {
|
|
93
124
|
this._options.mesh = this.transformNode;
|
|
94
125
|
}
|
|
95
|
-
else
|
|
96
|
-
|
|
126
|
+
else if (!(this._options.mesh &&
|
|
127
|
+
this._options.mesh.getClassName &&
|
|
128
|
+
(this._options.mesh.getClassName() === "Mesh" || this._options.mesh.getClassName() === "InstancedMesh"))) {
|
|
129
|
+
throw new Error("No valid mesh was provided for mesh or convex hull shape parameter.");
|
|
97
130
|
}
|
|
98
131
|
break;
|
|
99
|
-
case
|
|
100
|
-
this._options.extents = this._options.extents ?
|
|
132
|
+
case PhysicsShapeType.BOX:
|
|
133
|
+
this._options.extents = (_g = this._options.extents) !== null && _g !== void 0 ? _g : new Vector3(extents.x, extents.y, extents.z);
|
|
101
134
|
break;
|
|
102
135
|
}
|
|
103
136
|
}
|
|
@@ -110,7 +143,9 @@ export class PhysicsAggregate {
|
|
|
110
143
|
this._nodeDisposeObserver = null;
|
|
111
144
|
}
|
|
112
145
|
this.body.dispose();
|
|
113
|
-
this.
|
|
146
|
+
if (this._disposeShapeWhenDisposed) {
|
|
147
|
+
this.shape.dispose();
|
|
148
|
+
}
|
|
114
149
|
}
|
|
115
150
|
}
|
|
116
151
|
//# sourceMappingURL=physicsAggregate.js.map
|
|
@@ -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,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CAAC,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;AAqGxD;;;;;;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;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AC,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 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\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 {\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,7 @@ export declare class PhysicsBody {
|
|
|
38
42
|
* True by default for maximum performance.
|
|
39
43
|
*/
|
|
40
44
|
disablePreStep: boolean;
|
|
41
|
-
|
|
42
|
-
private static _IDENTITY_QUATERNION;
|
|
45
|
+
startAsleep: boolean;
|
|
43
46
|
private _nodeDisposeObserver;
|
|
44
47
|
/**
|
|
45
48
|
* Constructs a new physics body for the given node.
|
|
@@ -51,7 +54,12 @@ export declare class PhysicsBody {
|
|
|
51
54
|
* It checks the version of the physics engine and the physics plugin, and initializes the body accordingly.
|
|
52
55
|
* It also sets the node's rotation quaternion if it is not already set. Finally, it adds the body to the physics engine.
|
|
53
56
|
*/
|
|
54
|
-
constructor(transformNode: TransformNode, motionType: PhysicsMotionType, scene: Scene);
|
|
57
|
+
constructor(transformNode: TransformNode, motionType: PhysicsMotionType, startsAsleep: boolean, scene: Scene);
|
|
58
|
+
/**
|
|
59
|
+
* Returns the string "PhysicsBody".
|
|
60
|
+
* @returns "PhysicsBody"
|
|
61
|
+
*/
|
|
62
|
+
getClassName(): string;
|
|
55
63
|
/**
|
|
56
64
|
* Clone the PhysicsBody to a new body and assign it to the transformNode parameter
|
|
57
65
|
* @param transformNode transformNode that will be used for the cloned PhysicsBody
|
|
@@ -63,10 +71,9 @@ export declare class PhysicsBody {
|
|
|
63
71
|
*/
|
|
64
72
|
updateBodyInstances(): void;
|
|
65
73
|
/**
|
|
66
|
-
*
|
|
67
|
-
* @param shapeNode - A node with a physics shape. Should be a child of the body node
|
|
74
|
+
* This returns the number of internal instances of the physics body
|
|
68
75
|
*/
|
|
69
|
-
|
|
76
|
+
get numInstances(): number;
|
|
70
77
|
/**
|
|
71
78
|
* Sets the shape of the physics body.
|
|
72
79
|
* @param shape - The shape of the physics body.
|
|
@@ -74,7 +81,7 @@ export declare class PhysicsBody {
|
|
|
74
81
|
* 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
82
|
* The shape is used to calculate the body's mass, inertia, and other properties.
|
|
76
83
|
*/
|
|
77
|
-
set shape(shape: PhysicsShape);
|
|
84
|
+
set shape(shape: Nullable<PhysicsShape>);
|
|
78
85
|
/**
|
|
79
86
|
* Retrieves the physics shape associated with this object.
|
|
80
87
|
*
|
|
@@ -84,26 +91,7 @@ export declare class PhysicsBody {
|
|
|
84
91
|
* This method is useful for retrieving the physics shape associated with this object,
|
|
85
92
|
* which can be used to apply physical forces to the object or to detect collisions.
|
|
86
93
|
*/
|
|
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;
|
|
94
|
+
get shape(): Nullable<PhysicsShape>;
|
|
107
95
|
/**
|
|
108
96
|
* Sets the event mask for the physics engine.
|
|
109
97
|
*
|
|
@@ -112,7 +100,7 @@ export declare class PhysicsBody {
|
|
|
112
100
|
* This method is useful for setting the event mask for the physics engine, which determines which events
|
|
113
101
|
* will be sent to the physics engine. This allows the user to control which events the physics engine will respond to.
|
|
114
102
|
*/
|
|
115
|
-
|
|
103
|
+
setEventMask(eventMask: number, instanceIndex?: number): void;
|
|
116
104
|
/**
|
|
117
105
|
* Gets the event mask of the physics engine.
|
|
118
106
|
*
|
|
@@ -123,15 +111,15 @@ export declare class PhysicsBody {
|
|
|
123
111
|
* This is important for ensuring that the engine is responding to the correct events and not
|
|
124
112
|
* wasting resources on unnecessary events.
|
|
125
113
|
*/
|
|
126
|
-
|
|
114
|
+
getEventMask(instanceIndex?: number): number;
|
|
127
115
|
/**
|
|
128
116
|
* Sets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
129
117
|
*/
|
|
130
|
-
|
|
118
|
+
setMotionType(motionType: PhysicsMotionType, instanceIndex?: number): void;
|
|
131
119
|
/**
|
|
132
120
|
* Gets the motion type of the physics body. Can be STATIC, DYNAMIC, or ANIMATED.
|
|
133
121
|
*/
|
|
134
|
-
|
|
122
|
+
getMotionType(instanceIndex?: number): PhysicsMotionType;
|
|
135
123
|
/**
|
|
136
124
|
* Computes the mass properties of the physics object, based on the set of physics shapes this body uses.
|
|
137
125
|
* This method is useful for computing the initial mass properties of a physics object, such as its mass,
|
|
@@ -139,16 +127,17 @@ export declare class PhysicsBody {
|
|
|
139
127
|
* object in the physics engine, and computing values based on the shape will provide you with reasonable
|
|
140
128
|
* intial values, which you can then customize.
|
|
141
129
|
*/
|
|
142
|
-
computeMassProperties():
|
|
130
|
+
computeMassProperties(instanceIndex?: number): PhysicsMassProperties;
|
|
143
131
|
/**
|
|
144
132
|
* Sets the mass properties of the physics object.
|
|
145
133
|
*
|
|
146
134
|
* @param massProps - The mass properties to set.
|
|
135
|
+
* @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
136
|
*
|
|
148
137
|
* This method is useful for setting the mass properties of a physics object, such as its mass,
|
|
149
138
|
* inertia, and center of mass. This is important for accurately simulating the physics of the object in the physics engine.
|
|
150
139
|
*/
|
|
151
|
-
|
|
140
|
+
setMassProperties(massProps: PhysicsMassProperties, instanceIndex?: number): void;
|
|
152
141
|
/**
|
|
153
142
|
* Retrieves the mass properties of the object.
|
|
154
143
|
*
|
|
@@ -159,7 +148,7 @@ export declare class PhysicsBody {
|
|
|
159
148
|
* and moment of inertia. This information is necessary for accurate physics
|
|
160
149
|
* simulations.
|
|
161
150
|
*/
|
|
162
|
-
|
|
151
|
+
getMassProperties(instanceIndex?: number): PhysicsMassProperties;
|
|
163
152
|
/**
|
|
164
153
|
* Sets the linear damping of the physics body.
|
|
165
154
|
*
|
|
@@ -169,7 +158,7 @@ export declare class PhysicsBody {
|
|
|
169
158
|
* which is the rate at which the body's velocity decreases over time. This is useful for simulating
|
|
170
159
|
* the effects of air resistance or other forms of friction.
|
|
171
160
|
*/
|
|
172
|
-
|
|
161
|
+
setLinearDamping(damping: number, instanceIndex?: number): void;
|
|
173
162
|
/**
|
|
174
163
|
* Gets the linear damping of the physics body.
|
|
175
164
|
* @returns The linear damping of the physics body.
|
|
@@ -178,7 +167,7 @@ export declare class PhysicsBody {
|
|
|
178
167
|
* resistance the body has to linear motion. This is useful for simulating realistic physics behavior
|
|
179
168
|
* in a game.
|
|
180
169
|
*/
|
|
181
|
-
|
|
170
|
+
getLinearDamping(instanceIndex?: number): number;
|
|
182
171
|
/**
|
|
183
172
|
* Sets the angular damping of the physics body.
|
|
184
173
|
* @param damping The angular damping of the body.
|
|
@@ -187,7 +176,7 @@ export declare class PhysicsBody {
|
|
|
187
176
|
* By setting the damping, the body's angular velocity will be reduced over time, simulating the effect of friction.
|
|
188
177
|
* This can be used to create realistic physical behavior in a physics engine.
|
|
189
178
|
*/
|
|
190
|
-
|
|
179
|
+
setAngularDamping(damping: number, instanceIndex?: number): void;
|
|
191
180
|
/**
|
|
192
181
|
* Gets the angular damping of the physics body.
|
|
193
182
|
*
|
|
@@ -197,7 +186,7 @@ export declare class PhysicsBody {
|
|
|
197
186
|
* which is the rate of reduction of the angular velocity over time.
|
|
198
187
|
* This is important for simulating realistic physics behavior in a game.
|
|
199
188
|
*/
|
|
200
|
-
|
|
189
|
+
getAngularDamping(instanceIndex?: number): number;
|
|
201
190
|
/**
|
|
202
191
|
* Sets the linear velocity of the physics object.
|
|
203
192
|
* @param linVel - The linear velocity to set.
|
|
@@ -207,14 +196,14 @@ export declare class PhysicsBody {
|
|
|
207
196
|
* By setting the linear velocity, the physics object will move in the direction and speed specified by the vector.
|
|
208
197
|
* This allows for realistic physics simulations, such as simulating the motion of a ball rolling down a hill.
|
|
209
198
|
*/
|
|
210
|
-
setLinearVelocity(linVel: Vector3): void;
|
|
199
|
+
setLinearVelocity(linVel: Vector3, instanceIndex?: number): void;
|
|
211
200
|
/**
|
|
212
201
|
* Gets the linear velocity of the physics body and stores it in the given vector3.
|
|
213
202
|
* @param linVel - The vector3 to store the linear velocity in.
|
|
214
203
|
*
|
|
215
204
|
* This method is useful for getting the linear velocity of a physics body in a physics engine.
|
|
216
205
|
* 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;
|
|
206
|
+
getLinearVelocityToRef(linVel: Vector3, instanceIndex?: number): void;
|
|
218
207
|
/**
|
|
219
208
|
* Sets the angular velocity of the physics object.
|
|
220
209
|
* @param angVel - The angular velocity to set.
|
|
@@ -223,7 +212,7 @@ export declare class PhysicsBody {
|
|
|
223
212
|
* simulating realistic physics behavior. The angular velocity is used to determine the rate of rotation of the object,
|
|
224
213
|
* which is important for simulating realistic motion.
|
|
225
214
|
*/
|
|
226
|
-
setAngularVelocity(angVel: Vector3): void;
|
|
215
|
+
setAngularVelocity(angVel: Vector3, instanceIndex?: number): void;
|
|
227
216
|
/**
|
|
228
217
|
* Gets the angular velocity of the physics body and stores it in the given vector3.
|
|
229
218
|
* @param angVel - The vector3 to store the angular velocity in.
|
|
@@ -231,27 +220,29 @@ export declare class PhysicsBody {
|
|
|
231
220
|
* This method is useful for getting the angular velocity of a physics body, which can be used to determine the body's
|
|
232
221
|
* rotational speed. This information can be used to create realistic physics simulations.
|
|
233
222
|
*/
|
|
234
|
-
getAngularVelocityToRef(angVel: Vector3): void;
|
|
223
|
+
getAngularVelocityToRef(angVel: Vector3, instanceIndex?: number): void;
|
|
235
224
|
/**
|
|
236
225
|
* Applies an impulse to the physics object.
|
|
237
226
|
*
|
|
238
227
|
* @param impulse The impulse vector.
|
|
239
228
|
* @param location The location of the impulse.
|
|
229
|
+
* @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
230
|
*
|
|
241
231
|
* This method is useful for applying an impulse to a physics object, which can be used to simulate physical forces such as gravity,
|
|
242
232
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
243
233
|
*/
|
|
244
|
-
applyImpulse(impulse: Vector3, location: Vector3): void;
|
|
234
|
+
applyImpulse(impulse: Vector3, location: Vector3, instanceIndex?: number): void;
|
|
245
235
|
/**
|
|
246
236
|
* Applies a force to the physics object.
|
|
247
237
|
*
|
|
248
238
|
* @param force The force vector.
|
|
249
239
|
* @param location The location of the force.
|
|
240
|
+
* @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
241
|
*
|
|
251
242
|
* This method is useful for applying a force to a physics object, which can be used to simulate physical forces such as gravity,
|
|
252
243
|
* collisions, and explosions. This can be used to create realistic physics simulations in a game or other application.
|
|
253
244
|
*/
|
|
254
|
-
applyForce(force: Vector3, location: Vector3): void;
|
|
245
|
+
applyForce(force: Vector3, location: Vector3, instanceIndex?: number): void;
|
|
255
246
|
/**
|
|
256
247
|
* Retrieves the geometry of the body from the physics plugin.
|
|
257
248
|
*
|
|
@@ -270,28 +261,18 @@ export declare class PhysicsBody {
|
|
|
270
261
|
* @param enabled true if PhysicsBody's collision will rise a collision event and notifies the observable
|
|
271
262
|
*/
|
|
272
263
|
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;
|
|
264
|
+
getObjectCenterWorld(instanceIndex?: number): Vector3;
|
|
265
|
+
getObjectCenterWorldToRef(ref: Vector3, instanceIndex?: number): Vector3;
|
|
287
266
|
/**
|
|
288
267
|
* Adds a constraint to the physics engine.
|
|
289
268
|
*
|
|
290
269
|
* @param childBody - The body to which the constraint will be applied.
|
|
291
270
|
* @param constraint - The constraint to be applied.
|
|
271
|
+
* @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.
|
|
272
|
+
* @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
273
|
*
|
|
293
274
|
*/
|
|
294
|
-
addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint): void;
|
|
275
|
+
addConstraint(childBody: PhysicsBody, constraint: PhysicsConstraint, instanceIndex?: number, childInstanceIndex?: number): void;
|
|
295
276
|
/**
|
|
296
277
|
* Sync with a bone
|
|
297
278
|
* @param bone The bone that the impostor will be synced to.
|
|
@@ -302,6 +283,11 @@ export declare class PhysicsBody {
|
|
|
302
283
|
* @param boneAxis Optional vector3 axis the bone is aligned with
|
|
303
284
|
*/
|
|
304
285
|
syncWithBone(bone: Bone, boneMesh: AbstractMesh, jointPivot: Vector3, distToJoint?: number, adjustRotation?: Quaternion, boneAxis?: Vector3): void;
|
|
286
|
+
/**
|
|
287
|
+
* Executes a callback on the body or all of the instances of a body
|
|
288
|
+
* @param callback the callback to execute
|
|
289
|
+
*/
|
|
290
|
+
iterateOverAllInstances(callback: (body: PhysicsBody, instanceIndex?: number) => void): void;
|
|
305
291
|
/**
|
|
306
292
|
* Disposes the body from the physics engine.
|
|
307
293
|
*
|