CannonSphere.re.ts 563 B

123456789101112131415161718192021
  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.Prop("Number") radiusOffset: number = 1;
  7. shape: CANNON.Sphere;
  8. bbox: THREE.Box3;
  9. protected createShape() {
  10. const scale = this.object3d.scale;
  11. const maxSide = Math.max(scale.x, scale.y, scale.z);
  12. this.shape = new CANNON.Sphere(
  13. this.radiusOffset * (maxSide)
  14. );
  15. }
  16. }
  17. RE.registerComponent(CannonSphere);