Skip to content
This repository was archived by the owner on Feb 10, 2023. It is now read-only.

Commit 7b09397

Browse files
committed
feat(cannon): add remove to physic body
1 parent 881b92b commit 7b09397

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

libs/cannon/src/lib/body.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export type WorkerApi = {
7575
scaleOverride: (scale: NgtTriple) => void;
7676
sleep: () => void;
7777
wakeUp: () => void;
78+
remove: () => void;
7879
};
7980

8081
export interface NgtPhysicsBodyPublicApi extends WorkerApi {
@@ -423,12 +424,22 @@ export class NgtPhysicBody extends NgtComponentStore {
423424
};
424425
};
425426

427+
const makeRemove = (index?: number) => {
428+
const uuid = NgtCannonUtils.getUUID(ref, index);
429+
return () => {
430+
if (uuid) {
431+
worker.removeBodies({ uuid: [uuid] });
432+
}
433+
};
434+
};
435+
426436
function makeApi(index?: number): WorkerApi {
427437
return {
428438
allowSleep: makeAtomic('allowSleep', index),
429439
angularDamping: makeAtomic('angularDamping', index),
430440
angularFactor: makeVec('angularFactor', index),
431441
angularVelocity: makeVec('angularVelocity', index),
442+
remove: makeRemove(index),
432443
applyForce(force: NgtTriple, worldPoint: NgtTriple) {
433444
const uuid = NgtCannonUtils.getUUID(ref, index);
434445
uuid &&

0 commit comments

Comments
 (0)