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

Commit

Permalink
fix(cannon): a ref doesn't have to be a instance
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Apr 14, 2022
1 parent 0b32a40 commit fa74fc2
Showing 1 changed file with 12 additions and 39 deletions.
51 changes: 12 additions & 39 deletions libs/cannon/constraints/src/lib/constraint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { NgtPhysicsStore } from '@angular-three/cannon';
import {
NgtComponentStore,
NgtStore,
NgtUnknownInstance,
Ref,
tapEffect,
} from '@angular-three/core';
Expand Down Expand Up @@ -125,22 +124,8 @@ export class NgtPhysicConstraint extends NgtComponentStore {
)(
combineLatest([
physicsStore.select((s) => s.worker),
bodyA.ref$.pipe(
filter(
(ref) =>
(
ref as unknown as NgtUnknownInstance
)?.['__ngt__'] != undefined
)
),
bodyB.ref$.pipe(
filter(
(ref) =>
(
ref as unknown as NgtUnknownInstance
)?.['__ngt__'] != undefined
)
),
bodyA.ref$.pipe(filter((ref) => ref != undefined)),
bodyB.ref$.pipe(filter((ref) => ref != undefined)),
])
);
},
Expand All @@ -155,44 +140,32 @@ export class NgtPhysicConstraint extends NgtComponentStore {

const enableDisable = {
disable: () => {
requestAnimationFrame(() => {
worker.disableConstraint({ uuid });
});
worker.disableConstraint({ uuid });
},
enable: () => {
requestAnimationFrame(() => {
worker.enableConstraint({ uuid });
});
worker.enableConstraint({ uuid });
},
} as NgtConstraintORHingeApi<TConstraintType>;

if (type === 'Hinge') {
return {
...enableDisable,
disableMotor: () => {
requestAnimationFrame(() => {
worker.disableConstraintMotor({ uuid });
});
worker.disableConstraintMotor({ uuid });
},
enableMotor: () => {
requestAnimationFrame(() => {
worker.enableConstraintMotor({ uuid });
});
worker.enableConstraintMotor({ uuid });
},
setMotorMaxForce: (value: number) => {
requestAnimationFrame(() => {
worker.setConstraintMotorMaxForce({
props: value,
uuid,
});
worker.setConstraintMotorMaxForce({
props: value,
uuid,
});
},
setMotorSpeed: (value: number) => {
requestAnimationFrame(() => {
worker.setConstraintMotorSpeed({
props: value,
uuid,
});
worker.setConstraintMotorSpeed({
props: value,
uuid,
});
},
};
Expand Down

0 comments on commit fa74fc2

Please sign in to comment.