CannonLockConstraint.re.ts 879 B

123456789101112131415161718192021222324252627
  1. import * as RE from 'rogue-engine';
  2. import * as CANNON from 'cannon-es';
  3. import * as THREE from 'three';
  4. import CannonConstraint from './CannonConstraint';
  5. import * as RogueCannon from '../../Lib/RogueCannon';
  6. export default class CannonLockConstraint extends CannonConstraint {
  7. constraint: CANNON.LockConstraint;
  8. @RE.Prop("Object3D") target: THREE.Object3D;
  9. @RE.Prop("Number") maxForce: number = 1e6;
  10. protected createConstraint() {
  11. if (!this.target) throw "CannonHinge requires a target";
  12. const bodyA = this.getCannonBodyComponent(this.object3d).body;
  13. const bodyB = this.getCannonBodyComponent(this.target).body;
  14. this.constraint = new CANNON.LockConstraint(bodyA, bodyB, {
  15. maxForce: this.maxForce
  16. });
  17. RogueCannon.getWorld().addConstraint(this.constraint);
  18. }
  19. }
  20. RE.registerComponent(CannonLockConstraint);