CannonConstraint.ts 780 B

123456789101112131415161718192021222324252627282930
  1. import * as RE from 'rogue-engine';
  2. import { Object3D } from 'three';
  3. import * as CANNON from 'cannon-es';
  4. import CannonBody from '../CannonBody.re';
  5. import * as RogueCannon from '../../Lib/RogueCannon';
  6. export default class CannonConstraint extends RE.Component {
  7. constraint: CANNON.Constraint;
  8. targetBody: CANNON.Body;
  9. start() {
  10. this.createConstraint();
  11. }
  12. protected getCannonBodyComponent(object3d: Object3D): CannonBody {
  13. const cannonBody = RE.getComponent(CannonBody, object3d);
  14. if (!cannonBody) {
  15. throw "CannonHinge targets must have a Cannon Body Component"
  16. }
  17. return cannonBody;
  18. }
  19. protected createConstraint() {}
  20. onRemoved() {
  21. RogueCannon.getWorld().removeConstraint(this.constraint);
  22. }
  23. }