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

Commit

Permalink
fix(cannon): adjust uuid to use makeId() in Constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 15, 2022
1 parent b6b14a5 commit 385d9b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
47 changes: 21 additions & 26 deletions libs/cannon/constraints/src/lib/constraint.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { NgtPhysicsStore } from '@angular-three/cannon';
import {
makeId,
NgtComponentStore,
NgtStore,
Ref,
Expand Down Expand Up @@ -105,32 +106,26 @@ export class NgtPhysicConstraint extends NgtComponentStore {
): NgtConstraintReturn<TConstraintType> {
return this.zone.runOutsideAngular(() => {
const physicsStore = this.physicsStore;
const uuid = THREE.MathUtils.generateUUID();

this.onCanvasReady(
this.store.ready$,
() => {
this.effect<
[CannonWorkerAPI, THREE.Object3D, THREE.Object3D]
>(
tapEffect(([worker, a, b]) => {
worker.addConstraint({
props: [a.uuid, b.uuid, opts],
type,
uuid,
});
return () => worker.removeConstraint({ uuid });
})
)(
combineLatest([
physicsStore.select((s) => s.worker),
bodyA.ref$.pipe(filter((ref) => ref != undefined)),
bodyB.ref$.pipe(filter((ref) => ref != undefined)),
])
);
},
true
);
const uuid = makeId();

this.onCanvasReady(this.store.ready$, () => {
this.effect<[CannonWorkerAPI, THREE.Object3D, THREE.Object3D]>(
tapEffect(([worker, a, b]) => {
worker.addConstraint({
props: [a.uuid, b.uuid, opts],
type,
uuid,
});
return () => worker.removeConstraint({ uuid });
})
)(
combineLatest([
physicsStore.select((s) => s.worker),
bodyA.ref$.pipe(filter((ref) => ref != undefined)),
bodyB.ref$.pipe(filter((ref) => ref != undefined)),
])
);
});

return {
bodyA,
Expand Down
2 changes: 2 additions & 0 deletions libs/cannon/debug/src/lib/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class NgtCannonDebug extends NgtInstance<

get api() {
const { bodies, bodyMap } = this.get();

return {
add(uuid: string, props: BodyProps, type: BodyShapeType) {
const body = propsToBody({ uuid, props, type });
Expand Down Expand Up @@ -152,6 +153,7 @@ export class NgtCannonDebug extends NgtInstance<
q as unknown as Quaternion
);
}

cannonDebugger.update();
},
});
Expand Down

0 comments on commit 385d9b9

Please sign in to comment.