CannonSphere.re.ts 887 B

123456789101112131415161718192021222324252627282930313233343536
  1. import * as RE from 'rogue-engine';
  2. import * as THREE from 'three';
  3. import * as CANNON from 'cannon-es';
  4. import CannonShape from './CannonShape';
  5. export default class CannonSphere extends CannonShape {
  6. @RE.props.num() radiusOffset: number = 1;
  7. private _collisionResponse = true;
  8. @RE.props.checkbox()
  9. get collisionResponse() {
  10. return this._collisionResponse;
  11. };
  12. set collisionResponse(value: boolean) {
  13. this._collisionResponse = value;
  14. if (!this.shape) return;
  15. this.shape.collisionResponse = value;
  16. };
  17. shape: CANNON.Sphere;
  18. bbox: THREE.Box3;
  19. protected createShape() {
  20. const scale = this.object3d.scale;
  21. const maxSide = Math.max(scale.x, scale.y, scale.z);
  22. this.shape = new CANNON.Sphere(
  23. this.radiusOffset * (maxSide)
  24. );
  25. this.shape.collisionResponse = this._collisionResponse;
  26. }
  27. }
  28. RE.registerComponent(CannonSphere);