@babylonjs/core 5.51.0 → 5.53.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.
Files changed (107) hide show
  1. package/Animations/animatable.d.ts +5 -3
  2. package/Animations/animatable.js +11 -8
  3. package/Animations/animatable.js.map +1 -1
  4. package/Animations/animationGroup.js +3 -1
  5. package/Animations/animationGroup.js.map +1 -1
  6. package/Animations/runtimeAnimation.d.ts +1 -0
  7. package/Animations/runtimeAnimation.js +1 -0
  8. package/Animations/runtimeAnimation.js.map +1 -1
  9. package/Collisions/pickingInfo.d.ts +2 -1
  10. package/Collisions/pickingInfo.js +4 -3
  11. package/Collisions/pickingInfo.js.map +1 -1
  12. package/DeviceInput/eventFactory.js +4 -0
  13. package/DeviceInput/eventFactory.js.map +1 -1
  14. package/DeviceInput/webDeviceInputSystem.js +17 -9
  15. package/DeviceInput/webDeviceInputSystem.js.map +1 -1
  16. package/Engines/engine.d.ts +2 -0
  17. package/Engines/engine.js +5 -0
  18. package/Engines/engine.js.map +1 -1
  19. package/Engines/thinEngine.js +3 -3
  20. package/Engines/thinEngine.js.map +1 -1
  21. package/Inputs/scene.inputManager.js +5 -12
  22. package/Inputs/scene.inputManager.js.map +1 -1
  23. package/Materials/Node/Blocks/Dual/sceneDepthBlock.d.ts +4 -0
  24. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js +37 -2
  25. package/Materials/Node/Blocks/Dual/sceneDepthBlock.js.map +1 -1
  26. package/Materials/Node/nodeMaterialDecorator.d.ts +1 -1
  27. package/Materials/Node/nodeMaterialDecorator.js.map +1 -1
  28. package/Materials/PBR/pbrMaterial.js +1 -0
  29. package/Materials/PBR/pbrMaterial.js.map +1 -1
  30. package/Materials/Textures/Filtering/hdrFiltering.js +4 -0
  31. package/Materials/Textures/Filtering/hdrFiltering.js.map +1 -1
  32. package/Materials/Textures/cubeTexture.js +7 -1
  33. package/Materials/Textures/cubeTexture.js.map +1 -1
  34. package/Materials/materialPluginBase.d.ts +3 -2
  35. package/Materials/materialPluginBase.js.map +1 -1
  36. package/Materials/materialPluginManager.js +13 -3
  37. package/Materials/materialPluginManager.js.map +1 -1
  38. package/Materials/uniformBuffer.d.ts +2 -0
  39. package/Materials/uniformBuffer.js +4 -0
  40. package/Materials/uniformBuffer.js.map +1 -1
  41. package/Maths/math.frustum.d.ts +8 -1
  42. package/Maths/math.frustum.js +14 -0
  43. package/Maths/math.frustum.js.map +1 -1
  44. package/Meshes/instancedMesh.d.ts +2 -1
  45. package/Meshes/instancedMesh.js +3 -2
  46. package/Meshes/instancedMesh.js.map +1 -1
  47. package/Meshes/mesh.d.ts +10 -5
  48. package/Meshes/mesh.js +40 -16
  49. package/Meshes/mesh.js.map +1 -1
  50. package/Misc/environmentTextureTools.js +7 -0
  51. package/Misc/environmentTextureTools.js.map +1 -1
  52. package/Misc/filesInput.d.ts +5 -2
  53. package/Misc/filesInput.js +39 -20
  54. package/Misc/filesInput.js.map +1 -1
  55. package/Misc/observable.js +3 -0
  56. package/Misc/observable.js.map +1 -1
  57. package/Misc/sceneOptimizer.js +3 -0
  58. package/Misc/sceneOptimizer.js.map +1 -1
  59. package/Misc/virtualJoystick.js +2 -2
  60. package/Misc/virtualJoystick.js.map +1 -1
  61. package/Particles/gpuParticleSystem.js +18 -14
  62. package/Particles/gpuParticleSystem.js.map +1 -1
  63. package/Physics/v2/IPhysicsEnginePlugin.d.ts +126 -19
  64. package/Physics/v2/IPhysicsEnginePlugin.js +6 -0
  65. package/Physics/v2/IPhysicsEnginePlugin.js.map +1 -1
  66. package/Physics/v2/physicsAggregate.d.ts +7 -1
  67. package/Physics/v2/physicsAggregate.js +23 -9
  68. package/Physics/v2/physicsAggregate.js.map +1 -1
  69. package/Physics/v2/physicsBody.d.ts +50 -31
  70. package/Physics/v2/physicsBody.js +75 -34
  71. package/Physics/v2/physicsBody.js.map +1 -1
  72. package/Physics/v2/physicsConstraint.d.ts +6 -6
  73. package/Physics/v2/physicsConstraint.js +6 -6
  74. package/Physics/v2/physicsConstraint.js.map +1 -1
  75. package/Physics/v2/physicsEngineComponent.d.ts +10 -0
  76. package/Physics/v2/physicsEngineComponent.js +27 -0
  77. package/Physics/v2/physicsEngineComponent.js.map +1 -1
  78. package/Physics/v2/physicsMaterial.d.ts +52 -46
  79. package/Physics/v2/physicsMaterial.js +23 -80
  80. package/Physics/v2/physicsMaterial.js.map +1 -1
  81. package/Physics/v2/physicsShape.d.ts +34 -9
  82. package/Physics/v2/physicsShape.js +59 -8
  83. package/Physics/v2/physicsShape.js.map +1 -1
  84. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.d.ts +59 -13
  85. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js +131 -54
  86. package/PostProcesses/RenderPipeline/Pipelines/ssao2RenderingPipeline.js.map +1 -1
  87. package/Rendering/depthRenderer.js +1 -1
  88. package/Rendering/depthRenderer.js.map +1 -1
  89. package/Rendering/depthRendererSceneComponent.d.ts +2 -1
  90. package/Rendering/depthRendererSceneComponent.js +2 -2
  91. package/Rendering/depthRendererSceneComponent.js.map +1 -1
  92. package/Shaders/sprites.fragment.js +6 -1
  93. package/Shaders/sprites.fragment.js.map +1 -1
  94. package/Shaders/ssao2.fragment.js +0 -2
  95. package/Shaders/ssao2.fragment.js.map +1 -1
  96. package/Sprites/spriteManager.d.ts +7 -0
  97. package/Sprites/spriteManager.js +27 -0
  98. package/Sprites/spriteManager.js.map +1 -1
  99. package/Sprites/spriteRenderer.d.ts +8 -0
  100. package/Sprites/spriteRenderer.js +42 -19
  101. package/Sprites/spriteRenderer.js.map +1 -1
  102. package/XR/features/WebXRControllerTeleportation.d.ts +9 -0
  103. package/XR/features/WebXRControllerTeleportation.js +28 -4
  104. package/XR/features/WebXRControllerTeleportation.js.map +1 -1
  105. package/assetContainer.js +1 -1
  106. package/assetContainer.js.map +1 -1
  107. package/package.json +1 -1
@@ -8,6 +8,7 @@ import type { TransformNode } from "../../Meshes/transformNode";
8
8
  import type { PhysicsMaterial } from "./physicsMaterial";
9
9
  import type { Mesh } from "../../Meshes/mesh";
10
10
  import type { Nullable } from "../../types.js";
11
+ import type { Observable } from "../../Misc/observable.js";
11
12
  /** @internal */
12
13
  export declare enum ConstraintAxisLimitMode {
13
14
  FREE = 0,
@@ -51,24 +52,95 @@ export declare enum ConstraintMotorType {
51
52
  VELOCITY = 1,
52
53
  POSITION = 2
53
54
  }
55
+ /**
56
+ * Collision object that is the parameter when notification for collision fires.
57
+ */
58
+ export interface IPhysicsCollisionEvent {
59
+ /**
60
+ * 1st physics body that collided
61
+ */
62
+ collider: PhysicsBody;
63
+ /**
64
+ * 2nd physics body that collided
65
+ */
66
+ collidedAgainst: PhysicsBody;
67
+ /**
68
+ * World position where the collision occured
69
+ */
70
+ point: Nullable<Vector3>;
71
+ /**
72
+ * Penetration distance
73
+ */
74
+ distance: number;
75
+ /**
76
+ * Impulse value computed by the solver response
77
+ */
78
+ impulse: number;
79
+ /**
80
+ * Collision world normal direction
81
+ */
82
+ normal: Nullable<Vector3>;
83
+ }
54
84
  /** @internal */
55
85
  export interface PhysicsShapeParameters {
86
+ /**
87
+ * Shape center position
88
+ */
56
89
  center?: Vector3;
90
+ /**
91
+ * Radius for cylinder, shape and capsule
92
+ */
57
93
  radius?: number;
94
+ /**
95
+ * First point position that defines the cylinder or capsule
96
+ */
58
97
  pointA?: Vector3;
98
+ /**
99
+ * Second point position that defines the cylinder or capsule
100
+ */
59
101
  pointB?: Vector3;
102
+ /**
103
+ *
104
+ */
60
105
  rotation?: Quaternion;
106
+ /**
107
+ * Dimesion extention for the box
108
+ */
61
109
  extents?: Vector3;
110
+ /**
111
+ * Mesh used for Mesh shape or convex hull. It can be different than the mesh the body is attached to.
112
+ */
62
113
  mesh?: Mesh;
114
+ /**
115
+ * Use children hierarchy
116
+ */
63
117
  includeChildMeshes?: boolean;
64
118
  }
65
119
  /** @internal */
66
120
  export interface PhysicsConstraintParameters {
121
+ /**
122
+ * Pivot vector for 1st body
123
+ */
67
124
  pivotA?: Vector3;
125
+ /**
126
+ * Pivot vector for 2nd body
127
+ */
68
128
  pivotB?: Vector3;
129
+ /**
130
+ * Axis vector for 1st body
131
+ */
69
132
  axisA?: Vector3;
133
+ /**
134
+ * Axis vector for 2nd body
135
+ */
70
136
  axisB?: Vector3;
137
+ /**
138
+ * Maximum distance between both bodies
139
+ */
71
140
  maxDistance?: number;
141
+ /**
142
+ * Can connected bodies collide?
143
+ */
72
144
  collision?: boolean;
73
145
  }
74
146
  /**
@@ -77,45 +149,85 @@ export interface PhysicsConstraintParameters {
77
149
  /** @internal */
78
150
  export interface MassProperties {
79
151
  /**
152
+ * The center of mass, in local space. This is The
153
+ * point the body will rotate around when applying
154
+ * an angular velocity.
80
155
  *
156
+ * If not provided, the physics engine will compute
157
+ * an appropriate value.
81
158
  */
82
- centerOfMass: Vector3;
159
+ centerOfMass?: Vector3;
83
160
  /**
161
+ * The total mass of this object, in kilograms. This
162
+ * affects how easy it is to move the body. A value
163
+ * of zero will be used as an infinite mass.
84
164
  *
165
+ * If not provided, the physics engine will compute
166
+ * an appropriate value.
85
167
  */
86
- mass: number;
168
+ mass?: number;
87
169
  /**
170
+ * The principal moments of inertia of this object
171
+ * for a unit mass. This determines how easy it is
172
+ * for the body to rotate. A value of zero on any
173
+ * axis will be used as infinite interia about that
174
+ * axis.
88
175
  *
176
+ * If not provided, the physics engine will compute
177
+ * an appropriate value.
89
178
  */
90
- inertia: Vector3;
179
+ inertia?: Vector3;
91
180
  /**
181
+ * The rotation rotating from inertia major axis space
182
+ * to parent space (i.e., the rotation which, when
183
+ * applied to the 3x3 inertia tensor causes the inertia
184
+ * tensor to become a diagonal matrix). This determines
185
+ * how the values of inertia are aligned with the parent
186
+ * object.
92
187
  *
188
+ * If not provided, the physics engine will compute
189
+ * an appropriate value.
93
190
  */
94
- inertiaOrientation: Quaternion;
191
+ inertiaOrientation?: Quaternion;
192
+ }
193
+ export declare enum PhysicsMotionType {
194
+ STATIC = 0,
195
+ ANIMATED = 1,
196
+ DYNAMIC = 2
95
197
  }
96
198
  /** @internal */
97
199
  export interface IPhysicsEnginePluginV2 {
98
200
  /**
99
- *
201
+ * Physics plugin world instance
100
202
  */
101
203
  world: any;
102
204
  /**
103
- *
205
+ * Physics plugin name
104
206
  */
105
207
  name: string;
208
+ /**
209
+ * Collision observable
210
+ */
211
+ onCollisionObservable: Observable<{
212
+ collider: PhysicsBody;
213
+ collidedAgainst: PhysicsBody;
214
+ point: Nullable<Vector3>;
215
+ distance: number;
216
+ impulse: number;
217
+ normal: Nullable<Vector3>;
218
+ }>;
106
219
  setGravity(gravity: Vector3): void;
107
220
  setTimeStep(timeStep: number): void;
108
221
  getTimeStep(): number;
109
222
  executeStep(delta: number, bodies: Array<PhysicsBody>): void;
110
223
  getPluginVersion(): number;
111
- registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
112
- unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
113
- initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;
114
- initBodyInstances(body: PhysicsBody, mesh: Mesh): void;
224
+ initBody(body: PhysicsBody, motionType: PhysicsMotionType, position: Vector3, orientation: Quaternion): void;
225
+ initBodyInstances(body: PhysicsBody, motionType: PhysicsMotionType, mesh: Mesh): void;
115
226
  updateBodyInstances(body: PhysicsBody, mesh: Mesh): void;
116
227
  removeBody(body: PhysicsBody): void;
117
228
  sync(body: PhysicsBody): void;
118
229
  syncTransform(body: PhysicsBody, transformNode: TransformNode): void;
230
+ addNodeShape(body: PhysicsBody, shapeNode: TransformNode): void;
119
231
  setShape(body: PhysicsBody, shape: PhysicsShape): void;
120
232
  getShape(body: PhysicsBody): PhysicsShape;
121
233
  getShapeType(shape: PhysicsShape): ShapeType;
@@ -123,6 +235,9 @@ export interface IPhysicsEnginePluginV2 {
123
235
  getFilterGroup(body: PhysicsBody): number;
124
236
  setEventMask(body: PhysicsBody, eventMask: number): void;
125
237
  getEventMask(body: PhysicsBody): number;
238
+ setMotionType(body: PhysicsBody, motionType: PhysicsMotionType): void;
239
+ getMotionType(body: PhysicsBody): PhysicsMotionType;
240
+ computeMassProperties(body: PhysicsBody): MassProperties;
126
241
  setMassProperties(body: PhysicsBody, massProps: MassProperties): void;
127
242
  getMassProperties(body: PhysicsBody): MassProperties;
128
243
  setLinearDamping(body: PhysicsBody, damping: number): void;
@@ -137,15 +252,13 @@ export interface IPhysicsEnginePluginV2 {
137
252
  getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;
138
253
  getBodyGeometry(body: PhysicsBody): {};
139
254
  disposeBody(body: PhysicsBody): void;
140
- registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
141
- unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;
142
255
  setCollisionCallbackEnabled(body: PhysicsBody, enabled: boolean): void;
143
256
  addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;
257
+ getCollisionObservable(body: PhysicsBody): Observable<IPhysicsCollisionEvent>;
144
258
  initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;
145
259
  setFilterLayer(shape: PhysicsShape, layer: number): void;
146
260
  getFilterLayer(shape: PhysicsShape): number;
147
261
  setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void;
148
- getMaterial(shape: PhysicsShape): PhysicsMaterial;
149
262
  setDensity(shape: PhysicsShape, density: number): void;
150
263
  getDensity(shape: PhysicsShape): number;
151
264
  addChild(shape: PhysicsShape, newChild: PhysicsShape, childTransform: TransformNode): void;
@@ -153,12 +266,6 @@ export interface IPhysicsEnginePluginV2 {
153
266
  getNumChildren(shape: PhysicsShape): number;
154
267
  getBoundingBox(shape: PhysicsShape): BoundingBox;
155
268
  disposeShape(shape: PhysicsShape): void;
156
- initMaterial(material: PhysicsMaterial): void;
157
- setFriction(material: PhysicsMaterial, friction: number): void;
158
- getFriction(material: PhysicsMaterial): number;
159
- setRestitution(material: PhysicsMaterial, restitution: number): void;
160
- getRestitution(material: PhysicsMaterial): number;
161
- disposeMaterial(material: PhysicsMaterial): void;
162
269
  initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;
163
270
  setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;
164
271
  getEnabled(constraint: PhysicsConstraint): boolean;
@@ -46,4 +46,10 @@ export var ConstraintMotorType;
46
46
  ConstraintMotorType[ConstraintMotorType["VELOCITY"] = 1] = "VELOCITY";
47
47
  ConstraintMotorType[ConstraintMotorType["POSITION"] = 2] = "POSITION";
48
48
  })(ConstraintMotorType || (ConstraintMotorType = {}));
49
+ export var PhysicsMotionType;
50
+ (function (PhysicsMotionType) {
51
+ PhysicsMotionType[PhysicsMotionType["STATIC"] = 0] = "STATIC";
52
+ PhysicsMotionType[PhysicsMotionType["ANIMATED"] = 1] = "ANIMATED";
53
+ PhysicsMotionType[PhysicsMotionType["DYNAMIC"] = 2] = "DYNAMIC";
54
+ })(PhysicsMotionType || (PhysicsMotionType = {}));
49
55
  //# sourceMappingURL=IPhysicsEnginePlugin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"IPhysicsEnginePlugin.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/IPhysicsEnginePlugin.ts"],"names":[],"mappings":"AAWA,gBAAgB;AAChB,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,qEAAI,CAAA;IACJ,2EAAO,CAAA;IACP,yEAAM,CAAA;IACN,qEAAI,CAAA;AACR,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAQX;AARD,WAAY,cAAc;IACtB,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yEAAe,CAAA;AACnB,CAAC,EARW,cAAc,KAAd,cAAc,QAQzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACtB,yEAAmB,CAAA;IACnB,2DAAY,CAAA;IACZ,qDAAS,CAAA;IACT,uDAAU,CAAA;IACV,mDAAQ,CAAA;IACR,6DAAa,CAAA;AACjB,CAAC,EAPW,cAAc,KAAd,cAAc,QAOzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACjB,6CAAM,CAAA;IACN,+CAAO,CAAA;IACP,iDAAQ,CAAA;IACR,uCAAG,CAAA;IACH,uDAAW,CAAA;IACX,mDAAS,CAAA;IACT,yCAAI,CAAA;IACJ,uDAAW,CAAA;AACf,CAAC,EATW,SAAS,KAAT,SAAS,QASpB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,6DAAI,CAAA;IACJ,qEAAQ,CAAA;IACR,qEAAQ,CAAA;AACZ,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B","sourcesContent":["import type { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Nullable } from \"core/types\";\r\n\r\n/** @internal */\r\nexport enum ConstraintAxisLimitMode {\r\n FREE,\r\n LIMITED,\r\n LOCKED,\r\n NONE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintAxis {\r\n LINEAR_X,\r\n LINEAR_Y,\r\n LINEAR_Z,\r\n ANGULAR_X,\r\n ANGULAR_Y,\r\n ANGULAR_Z,\r\n LINEAR_DISTANCE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintType {\r\n BALL_AND_SOCKET = 1,\r\n DISTANCE = 2,\r\n HINGE = 3,\r\n SLIDER = 4,\r\n LOCK = 5,\r\n PRISMATIC = 6,\r\n}\r\n\r\n/** @internal */\r\nexport enum ShapeType {\r\n SPHERE,\r\n CAPSULE,\r\n CYLINDER,\r\n BOX,\r\n CONVEX_HULL,\r\n CONTAINER,\r\n MESH,\r\n HEIGHTFIELD,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintMotorType {\r\n NONE,\r\n VELOCITY,\r\n POSITION,\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsShapeParameters {\r\n center?: Vector3;\r\n radius?: number;\r\n pointA?: Vector3;\r\n pointB?: Vector3;\r\n rotation?: Quaternion;\r\n extents?: Vector3;\r\n mesh?: Mesh;\r\n includeChildMeshes?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsConstraintParameters {\r\n pivotA?: Vector3;\r\n pivotB?: Vector3;\r\n axisA?: Vector3;\r\n axisB?: Vector3;\r\n maxDistance?: number;\r\n collision?: boolean;\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport interface MassProperties {\r\n /**\r\n *\r\n */\r\n centerOfMass: Vector3;\r\n /**\r\n *\r\n */\r\n mass: number;\r\n /**\r\n *\r\n */\r\n inertia: Vector3;\r\n /**\r\n *\r\n */\r\n inertiaOrientation: Quaternion;\r\n}\r\n\r\n/** @internal */\r\nexport interface IPhysicsEnginePluginV2 {\r\n /**\r\n *\r\n */\r\n world: any;\r\n /**\r\n *\r\n */\r\n name: string;\r\n setGravity(gravity: Vector3): void;\r\n setTimeStep(timeStep: number): void;\r\n getTimeStep(): number;\r\n executeStep(delta: number, bodies: Array<PhysicsBody>): void; //not forgetting pre and post events\r\n getPluginVersion(): number;\r\n registerOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n unregisterOnCollide(func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n\r\n // body\r\n initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;\r\n initBodyInstances(body: PhysicsBody, mesh: Mesh): void;\r\n updateBodyInstances(body: PhysicsBody, mesh: Mesh): void;\r\n removeBody(body: PhysicsBody): void;\r\n sync(body: PhysicsBody): void;\r\n syncTransform(body: PhysicsBody, transformNode: TransformNode): void;\r\n setShape(body: PhysicsBody, shape: PhysicsShape): void;\r\n getShape(body: PhysicsBody): PhysicsShape;\r\n getShapeType(shape: PhysicsShape): ShapeType;\r\n setFilterGroup(body: PhysicsBody, group: number): void;\r\n getFilterGroup(body: PhysicsBody): number;\r\n setEventMask(body: PhysicsBody, eventMask: number): void;\r\n getEventMask(body: PhysicsBody): number;\r\n setMassProperties(body: PhysicsBody, massProps: MassProperties): void;\r\n getMassProperties(body: PhysicsBody): MassProperties;\r\n setLinearDamping(body: PhysicsBody, damping: number): void;\r\n getLinearDamping(body: PhysicsBody): number;\r\n setAngularDamping(body: PhysicsBody, damping: number): void;\r\n getAngularDamping(body: PhysicsBody): number;\r\n setLinearVelocity(body: PhysicsBody, linVel: Vector3): void;\r\n getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3): void;\r\n applyImpulse(body: PhysicsBody, impulse: Vector3, location: Vector3): void;\r\n applyForce(body: PhysicsBody, force: Vector3, location: Vector3): void;\r\n setAngularVelocity(body: PhysicsBody, angVel: Vector3): void;\r\n getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;\r\n getBodyGeometry(body: PhysicsBody): {};\r\n disposeBody(body: PhysicsBody): void;\r\n registerOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n unregisterOnBodyCollide(body: PhysicsBody, func: (collider: PhysicsBody, collidedAgainst: PhysicsBody, point: Nullable<Vector3>) => void): void;\r\n setCollisionCallbackEnabled(body: PhysicsBody, enabled: boolean): void;\r\n addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;\r\n\r\n // shape\r\n initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;\r\n setFilterLayer(shape: PhysicsShape, layer: number): void;\r\n getFilterLayer(shape: PhysicsShape): number;\r\n setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void;\r\n getMaterial(shape: PhysicsShape): PhysicsMaterial;\r\n setDensity(shape: PhysicsShape, density: number): void;\r\n getDensity(shape: PhysicsShape): number;\r\n addChild(shape: PhysicsShape, newChild: PhysicsShape, childTransform: TransformNode): void;\r\n removeChild(shape: PhysicsShape, childIndex: number): void;\r\n getNumChildren(shape: PhysicsShape): number;\r\n getBoundingBox(shape: PhysicsShape): BoundingBox;\r\n disposeShape(shape: PhysicsShape): void;\r\n\r\n // material\r\n initMaterial(material: PhysicsMaterial): void;\r\n setFriction(material: PhysicsMaterial, friction: number): void;\r\n getFriction(material: PhysicsMaterial): number;\r\n setRestitution(material: PhysicsMaterial, restitution: number): void;\r\n getRestitution(material: PhysicsMaterial): number;\r\n disposeMaterial(material: PhysicsMaterial): void;\r\n\r\n // constraint\r\n initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;\r\n setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getEnabled(constraint: PhysicsConstraint): boolean;\r\n setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getCollisionsEnabled(constraint: PhysicsConstraint): boolean;\r\n setAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis, friction: number): void;\r\n getAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis, limitMode: ConstraintAxisLimitMode): void;\r\n getAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintAxisLimitMode;\r\n setAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, minLimit: number): void;\r\n getAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, limit: number): void;\r\n getAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis, motorType: ConstraintMotorType): void;\r\n getAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintMotorType;\r\n setAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis, target: number): void;\r\n getAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis, maxForce: number): void;\r\n getAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n disposeConstraint(constraint: PhysicsConstraint): void;\r\n\r\n // raycast\r\n raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult): void;\r\n\r\n dispose(): void;\r\n}\r\n"]}
1
+ {"version":3,"file":"IPhysicsEnginePlugin.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/IPhysicsEnginePlugin.ts"],"names":[],"mappings":"AAYA,gBAAgB;AAChB,MAAM,CAAN,IAAY,uBAKX;AALD,WAAY,uBAAuB;IAC/B,qEAAI,CAAA;IACJ,2EAAO,CAAA;IACP,yEAAM,CAAA;IACN,qEAAI,CAAA;AACR,CAAC,EALW,uBAAuB,KAAvB,uBAAuB,QAKlC;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAQX;AARD,WAAY,cAAc;IACtB,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,2DAAQ,CAAA;IACR,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,6DAAS,CAAA;IACT,yEAAe,CAAA;AACnB,CAAC,EARW,cAAc,KAAd,cAAc,QAQzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,cAOX;AAPD,WAAY,cAAc;IACtB,yEAAmB,CAAA;IACnB,2DAAY,CAAA;IACZ,qDAAS,CAAA;IACT,uDAAU,CAAA;IACV,mDAAQ,CAAA;IACR,6DAAa,CAAA;AACjB,CAAC,EAPW,cAAc,KAAd,cAAc,QAOzB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,SASX;AATD,WAAY,SAAS;IACjB,6CAAM,CAAA;IACN,+CAAO,CAAA;IACP,iDAAQ,CAAA;IACR,uCAAG,CAAA;IACH,uDAAW,CAAA;IACX,mDAAS,CAAA;IACT,yCAAI,CAAA;IACJ,uDAAW,CAAA;AACf,CAAC,EATW,SAAS,KAAT,SAAS,QASpB;AAED,gBAAgB;AAChB,MAAM,CAAN,IAAY,mBAIX;AAJD,WAAY,mBAAmB;IAC3B,6DAAI,CAAA;IACJ,qEAAQ,CAAA;IACR,qEAAQ,CAAA;AACZ,CAAC,EAJW,mBAAmB,KAAnB,mBAAmB,QAI9B;AAgJD,MAAM,CAAN,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,6DAAM,CAAA;IACN,iEAAQ,CAAA;IACR,+DAAO,CAAA;AACX,CAAC,EAJW,iBAAiB,KAAjB,iBAAiB,QAI5B","sourcesContent":["import type { Vector3, Quaternion } from \"../../Maths/math.vector\";\r\nimport type { PhysicsRaycastResult } from \"../physicsRaycastResult\";\r\nimport type { PhysicsBody } from \"./physicsBody\";\r\nimport type { PhysicsShape } from \"./physicsShape\";\r\nimport type { PhysicsConstraint } from \"./physicsConstraint\";\r\nimport type { BoundingBox } from \"../../Culling/boundingBox\";\r\nimport type { TransformNode } from \"../../Meshes/transformNode\";\r\nimport type { PhysicsMaterial } from \"./physicsMaterial\";\r\nimport type { Mesh } from \"../../Meshes/mesh\";\r\nimport type { Nullable } from \"core/types\";\r\nimport type { Observable } from \"core/Misc/observable\";\r\n\r\n/** @internal */\r\nexport enum ConstraintAxisLimitMode {\r\n FREE,\r\n LIMITED,\r\n LOCKED,\r\n NONE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintAxis {\r\n LINEAR_X,\r\n LINEAR_Y,\r\n LINEAR_Z,\r\n ANGULAR_X,\r\n ANGULAR_Y,\r\n ANGULAR_Z,\r\n LINEAR_DISTANCE,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintType {\r\n BALL_AND_SOCKET = 1,\r\n DISTANCE = 2,\r\n HINGE = 3,\r\n SLIDER = 4,\r\n LOCK = 5,\r\n PRISMATIC = 6,\r\n}\r\n\r\n/** @internal */\r\nexport enum ShapeType {\r\n SPHERE,\r\n CAPSULE,\r\n CYLINDER,\r\n BOX,\r\n CONVEX_HULL,\r\n CONTAINER,\r\n MESH,\r\n HEIGHTFIELD,\r\n}\r\n\r\n/** @internal */\r\nexport enum ConstraintMotorType {\r\n NONE,\r\n VELOCITY,\r\n POSITION,\r\n}\r\n\r\n/**\r\n * Collision object that is the parameter when notification for collision fires.\r\n */\r\nexport interface IPhysicsCollisionEvent {\r\n /**\r\n * 1st physics body that collided\r\n */\r\n collider: PhysicsBody;\r\n /**\r\n * 2nd physics body that collided\r\n */\r\n collidedAgainst: PhysicsBody;\r\n /**\r\n * World position where the collision occured\r\n */\r\n point: Nullable<Vector3>;\r\n /**\r\n * Penetration distance\r\n */\r\n distance: number;\r\n /**\r\n * Impulse value computed by the solver response\r\n */\r\n impulse: number;\r\n /**\r\n * Collision world normal direction\r\n */\r\n normal: Nullable<Vector3>;\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsShapeParameters {\r\n /**\r\n * Shape center position\r\n */\r\n center?: Vector3;\r\n /**\r\n * Radius for cylinder, shape and capsule\r\n */\r\n radius?: number;\r\n /**\r\n * First point position that defines the cylinder or capsule\r\n */\r\n pointA?: Vector3;\r\n /**\r\n * Second point position that defines the cylinder or capsule\r\n */\r\n pointB?: Vector3;\r\n /**\r\n *\r\n */\r\n rotation?: Quaternion;\r\n /**\r\n * Dimesion extention for the box\r\n */\r\n extents?: Vector3;\r\n /**\r\n * Mesh used for Mesh shape or convex hull. It can be different than the mesh the body is attached to.\r\n */\r\n mesh?: Mesh;\r\n /**\r\n * Use children hierarchy\r\n */\r\n includeChildMeshes?: boolean;\r\n}\r\n\r\n/** @internal */\r\nexport interface PhysicsConstraintParameters {\r\n /**\r\n * Pivot vector for 1st body\r\n */\r\n pivotA?: Vector3;\r\n /**\r\n * Pivot vector for 2nd body\r\n */\r\n pivotB?: Vector3;\r\n /**\r\n * Axis vector for 1st body\r\n */\r\n axisA?: Vector3;\r\n /**\r\n * Axis vector for 2nd body\r\n */\r\n axisB?: Vector3;\r\n /**\r\n * Maximum distance between both bodies\r\n */\r\n maxDistance?: number;\r\n /**\r\n * Can connected bodies collide?\r\n */\r\n collision?: boolean;\r\n}\r\n\r\n/**\r\n *\r\n */\r\n/** @internal */\r\nexport interface MassProperties {\r\n /**\r\n * The center of mass, in local space. This is The\r\n * point the body will rotate around when applying\r\n * an angular velocity.\r\n *\r\n * If not provided, the physics engine will compute\r\n * an appropriate value.\r\n */\r\n centerOfMass?: Vector3;\r\n /**\r\n * The total mass of this object, in kilograms. This\r\n * affects how easy it is to move the body. A value\r\n * of zero will be used as an infinite mass.\r\n *\r\n * If not provided, the physics engine will compute\r\n * an appropriate value.\r\n */\r\n mass?: number;\r\n /**\r\n * The principal moments of inertia of this object\r\n * for a unit mass. This determines how easy it is\r\n * for the body to rotate. A value of zero on any\r\n * axis will be used as infinite interia about that\r\n * axis.\r\n *\r\n * If not provided, the physics engine will compute\r\n * an appropriate value.\r\n */\r\n inertia?: Vector3;\r\n /**\r\n * The rotation rotating from inertia major axis space\r\n * to parent space (i.e., the rotation which, when\r\n * applied to the 3x3 inertia tensor causes the inertia\r\n * tensor to become a diagonal matrix). This determines\r\n * how the values of inertia are aligned with the parent\r\n * object.\r\n *\r\n * If not provided, the physics engine will compute\r\n * an appropriate value.\r\n */\r\n inertiaOrientation?: Quaternion;\r\n}\r\n\r\nexport enum PhysicsMotionType {\r\n STATIC,\r\n ANIMATED,\r\n DYNAMIC,\r\n}\r\n\r\n/** @internal */\r\nexport interface IPhysicsEnginePluginV2 {\r\n /**\r\n * Physics plugin world instance\r\n */\r\n world: any;\r\n /**\r\n * Physics plugin name\r\n */\r\n name: string;\r\n\r\n /**\r\n * Collision observable\r\n */\r\n onCollisionObservable: Observable<{\r\n collider: PhysicsBody;\r\n collidedAgainst: PhysicsBody;\r\n point: Nullable<Vector3>;\r\n distance: number;\r\n impulse: number;\r\n normal: Nullable<Vector3>;\r\n }>;\r\n\r\n setGravity(gravity: Vector3): void;\r\n setTimeStep(timeStep: number): void;\r\n getTimeStep(): number;\r\n executeStep(delta: number, bodies: Array<PhysicsBody>): void; //not forgetting pre and post events\r\n getPluginVersion(): number;\r\n\r\n // body\r\n initBody(body: PhysicsBody, motionType: PhysicsMotionType, position: Vector3, orientation: Quaternion): void;\r\n initBodyInstances(body: PhysicsBody, motionType: PhysicsMotionType, mesh: Mesh): void;\r\n updateBodyInstances(body: PhysicsBody, mesh: Mesh): void;\r\n removeBody(body: PhysicsBody): void;\r\n sync(body: PhysicsBody): void;\r\n syncTransform(body: PhysicsBody, transformNode: TransformNode): void;\r\n addNodeShape(body: PhysicsBody, shapeNode: TransformNode): void;\r\n setShape(body: PhysicsBody, shape: PhysicsShape): void;\r\n getShape(body: PhysicsBody): PhysicsShape;\r\n getShapeType(shape: PhysicsShape): ShapeType;\r\n setFilterGroup(body: PhysicsBody, group: number): void;\r\n getFilterGroup(body: PhysicsBody): number;\r\n setEventMask(body: PhysicsBody, eventMask: number): void;\r\n getEventMask(body: PhysicsBody): number;\r\n setMotionType(body: PhysicsBody, motionType: PhysicsMotionType): void;\r\n getMotionType(body: PhysicsBody): PhysicsMotionType;\r\n computeMassProperties(body: PhysicsBody): MassProperties;\r\n setMassProperties(body: PhysicsBody, massProps: MassProperties): void;\r\n getMassProperties(body: PhysicsBody): MassProperties;\r\n setLinearDamping(body: PhysicsBody, damping: number): void;\r\n getLinearDamping(body: PhysicsBody): number;\r\n setAngularDamping(body: PhysicsBody, damping: number): void;\r\n getAngularDamping(body: PhysicsBody): number;\r\n setLinearVelocity(body: PhysicsBody, linVel: Vector3): void;\r\n getLinearVelocityToRef(body: PhysicsBody, linVel: Vector3): void;\r\n applyImpulse(body: PhysicsBody, impulse: Vector3, location: Vector3): void;\r\n applyForce(body: PhysicsBody, force: Vector3, location: Vector3): void;\r\n setAngularVelocity(body: PhysicsBody, angVel: Vector3): void;\r\n getAngularVelocityToRef(body: PhysicsBody, angVel: Vector3): void;\r\n getBodyGeometry(body: PhysicsBody): {};\r\n disposeBody(body: PhysicsBody): void;\r\n setCollisionCallbackEnabled(body: PhysicsBody, enabled: boolean): void;\r\n addConstraint(body: PhysicsBody, childBody: PhysicsBody, constraint: PhysicsConstraint): void;\r\n getCollisionObservable(body: PhysicsBody): Observable<IPhysicsCollisionEvent>;\r\n\r\n // shape\r\n initShape(shape: PhysicsShape, type: ShapeType, options: PhysicsShapeParameters): void;\r\n setFilterLayer(shape: PhysicsShape, layer: number): void;\r\n getFilterLayer(shape: PhysicsShape): number;\r\n setMaterial(shape: PhysicsShape, material: PhysicsMaterial): void;\r\n setDensity(shape: PhysicsShape, density: number): void;\r\n getDensity(shape: PhysicsShape): number;\r\n addChild(shape: PhysicsShape, newChild: PhysicsShape, childTransform: TransformNode): void;\r\n removeChild(shape: PhysicsShape, childIndex: number): void;\r\n getNumChildren(shape: PhysicsShape): number;\r\n getBoundingBox(shape: PhysicsShape): BoundingBox;\r\n disposeShape(shape: PhysicsShape): void;\r\n\r\n // constraint\r\n initConstraint(constraint: PhysicsConstraint, body: PhysicsBody, childBody: PhysicsBody): void;\r\n setEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getEnabled(constraint: PhysicsConstraint): boolean;\r\n setCollisionsEnabled(constraint: PhysicsConstraint, isEnabled: boolean): void;\r\n getCollisionsEnabled(constraint: PhysicsConstraint): boolean;\r\n setAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis, friction: number): void;\r\n getAxisFriction(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis, limitMode: ConstraintAxisLimitMode): void;\r\n getAxisMode(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintAxisLimitMode;\r\n setAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, minLimit: number): void;\r\n getAxisMinLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis, limit: number): void;\r\n getAxisMaxLimit(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis, motorType: ConstraintMotorType): void;\r\n getAxisMotorType(constraint: PhysicsConstraint, axis: ConstraintAxis): ConstraintMotorType;\r\n setAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis, target: number): void;\r\n getAxisMotorTarget(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n setAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis, maxForce: number): void;\r\n getAxisMotorMaxForce(constraint: PhysicsConstraint, axis: ConstraintAxis): number;\r\n disposeConstraint(constraint: PhysicsConstraint): void;\r\n\r\n // raycast\r\n raycast(from: Vector3, to: Vector3, result: PhysicsRaycastResult): void;\r\n\r\n dispose(): void;\r\n}\r\n"]}
@@ -1,9 +1,10 @@
1
1
  import { PhysicsBody } from "./physicsBody";
2
- import { PhysicsMaterial } from "./physicsMaterial";
2
+ import type { PhysicsMaterial } from "./physicsMaterial";
3
3
  import { PhysicsShape } from "./physicsShape";
4
4
  import type { Scene } from "../../scene";
5
5
  import type { TransformNode } from "../../Meshes/transformNode";
6
6
  import { Vector3 } from "../../Maths/math.vector";
7
+ import type { Mesh } from "../../Meshes/mesh";
7
8
  /**
8
9
  * The interface for the physics aggregate parameters
9
10
  */
@@ -90,6 +91,10 @@ export interface PhysicsAggregateParameters {
90
91
  * mesh local center
91
92
  */
92
93
  center?: Vector3;
94
+ /**
95
+ * mesh object. Used for mesh and convex hull aggregates.
96
+ */
97
+ mesh?: Mesh;
93
98
  }
94
99
  /**
95
100
  * Helper class to create and interact with a PhysicsAggregate.
@@ -121,6 +126,7 @@ export declare class PhysicsAggregate {
121
126
  * The material that is associated with this aggregate
122
127
  */
123
128
  material: PhysicsMaterial;
129
+ private _nodeDisposeObserver;
124
130
  constructor(
125
131
  /**
126
132
  * The physics-enabled object used as the physics aggregate
@@ -1,10 +1,9 @@
1
1
  import { PhysicsBody } from "./physicsBody.js";
2
- import { PhysicsMaterial } from "./physicsMaterial.js";
3
2
  import { PhysicsShape } from "./physicsShape.js";
4
3
  import { Logger } from "../../Misc/logger.js";
5
- import { Quaternion, Vector3 } from "../../Maths/math.vector.js";
4
+ import { Vector3 } from "../../Maths/math.vector.js";
6
5
  import { Scalar } from "../../Maths/math.scalar.js";
7
- import { ShapeType } from "./IPhysicsEnginePlugin.js";
6
+ import { PhysicsMotionType, ShapeType } from "./IPhysicsEnginePlugin.js";
8
7
  /**
9
8
  * Helper class to create and interact with a PhysicsAggregate.
10
9
  * This is a transition object that works like Physics Plugin V1 Impostors.
@@ -46,14 +45,19 @@ export class PhysicsAggregate {
46
45
  this._options.mass = _options.mass === void 0 ? 0 : _options.mass;
47
46
  this._options.friction = _options.friction === void 0 ? 0.2 : _options.friction;
48
47
  this._options.restitution = _options.restitution === void 0 ? 0.2 : _options.restitution;
49
- this.body = new PhysicsBody(transformNode, this._scene);
48
+ const motionType = this._options.mass === 0 ? PhysicsMotionType.STATIC : PhysicsMotionType.DYNAMIC;
49
+ this.body = new PhysicsBody(transformNode, motionType, this._scene);
50
50
  this._addSizeOptions();
51
51
  this._options.center = (_a = _options.center) !== null && _a !== void 0 ? _a : this.body.getObjectCenterDelta();
52
52
  this.shape = new PhysicsShape({ type, parameters: this._options }, this._scene);
53
- this.material = new PhysicsMaterial(this._options.friction, this._options.restitution, this._scene);
54
- this.body.setShape(this.shape);
55
- this.shape.setMaterial(this.material);
56
- this.body.setMassProperties({ centerOfMass: new Vector3(0, 0, 0), mass: this._options.mass, inertia: new Vector3(1, 1, 1), inertiaOrientation: Quaternion.Identity() });
53
+ this.material = { friction: this._options.friction, restitution: this._options.restitution };
54
+ this.body.shape = this.shape;
55
+ this.shape.material = this.material;
56
+ this.body.massProperties = { mass: this._options.mass };
57
+ this._nodeDisposeObserver = this.transformNode.onDisposeObservable.add(() => {
58
+ // The body is already disposed on its own observable, so it's not necessary to dispose it here.
59
+ this.shape.dispose();
60
+ });
57
61
  }
58
62
  _addSizeOptions() {
59
63
  var _a, _b, _c;
@@ -85,6 +89,13 @@ export class PhysicsAggregate {
85
89
  break;
86
90
  case ShapeType.MESH:
87
91
  case ShapeType.CONVEX_HULL:
92
+ if (!this._options.mesh && (this.transformNode.getClassName() === "Mesh" || this.transformNode.getClassName() === "InstancedMesh")) {
93
+ this._options.mesh = this.transformNode;
94
+ }
95
+ else {
96
+ Logger.Warn("No mesh was provided for the mesh shape");
97
+ }
98
+ break;
88
99
  case ShapeType.BOX:
89
100
  this._options.extents = this._options.extents ? this._options.extents : new Vector3(impostorExtents.x, impostorExtents.y, impostorExtents.z);
90
101
  break;
@@ -94,8 +105,11 @@ export class PhysicsAggregate {
94
105
  * Releases the body, shape and material
95
106
  */
96
107
  dispose() {
108
+ if (this._nodeDisposeObserver) {
109
+ this.body.transformNode.onDisposeObservable.remove(this._nodeDisposeObserver);
110
+ this._nodeDisposeObserver = null;
111
+ }
97
112
  this.body.dispose();
98
- this.material.dispose();
99
113
  this.shape.dispose();
100
114
  }
101
115
  }
@@ -1 +1 @@
1
- {"version":3,"file":"physicsAggregate.js","sourceRoot":"","sources":["../../../../../lts/core/generated/Physics/v2/physicsAggregate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AED;;OAEG;IACI,OAAO;QACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACJ","sourcesContent":["import { PhysicsBody } from \"./physicsBody\";\r\nimport { 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 { Quaternion, Vector3 } from \"../../Maths/math.vector\";\r\nimport { Scalar } from \"../../Maths/math.scalar\";\r\nimport { ShapeType } from \"./IPhysicsEnginePlugin\";\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 * 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 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 this.body = new PhysicsBody(transformNode, 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 = new PhysicsMaterial(this._options.friction, this._options.restitution, this._scene);\r\n this.body.setShape(this.shape);\r\n this.shape.setMaterial(this.material);\r\n this.body.setMassProperties({ centerOfMass: new Vector3(0, 0, 0), mass: this._options.mass, inertia: new Vector3(1, 1, 1), inertiaOrientation: Quaternion.Identity() });\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 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 this.body.dispose();\r\n this.material.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,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAuGtE;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAkBzB;IACI;;OAEG;IACI,aAA4B;IACnC;;OAEG;IACI,IAAY,EACX,WAAuC,EAAE,IAAI,EAAE,CAAC,EAAE,EAClD,MAAc;;QANf,kBAAa,GAAb,aAAa,CAAe;QAI5B,SAAI,GAAJ,IAAI,CAAQ;QACX,aAAQ,GAAR,QAAQ,CAA0C;QAClD,WAAM,GAAN,MAAM,CAAQ;QAEtB,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,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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"]}