Skip to content

Commit d236991

Browse files
authored
Add function "updateBodyInstances" to synchronize mesh instances with physics body instances. (#13576)
1 parent 44c29b9 commit d236991

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/dev/core/src/Physics/v2/IPhysicsEnginePlugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export interface IPhysicsEnginePluginV2 {
123123
// body
124124
initBody(body: PhysicsBody, position: Vector3, orientation: Quaternion): void;
125125
initBodyInstances(body: PhysicsBody, mesh: Mesh): void;
126+
updateBodyInstances(body: PhysicsBody, mesh: Mesh): void;
126127
removeBody(body: PhysicsBody): void;
127128
sync(body: PhysicsBody): void;
128129
syncTransform(body: PhysicsBody, transformNode: TransformNode): void;

packages/dev/core/src/Physics/v2/physicsBody.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ export class PhysicsBody {
8484
physicsEngine.addBody(this);
8585
}
8686

87+
/**
88+
* If a physics body is connected to an instanced node, update the number physic instances to match the number of node instances.
89+
*/
90+
public updateBodyInstances() {
91+
const m = this.transformNode as Mesh;
92+
if (m.hasThinInstances) {
93+
this._physicsPlugin.updateBodyInstances(this, m);
94+
}
95+
}
96+
8797
/**
8898
* Sets the shape of the physics body.
8999
* @param shape - The shape of the physics body.

0 commit comments

Comments
 (0)