CannonBox.re.ts 704 B

12345678910111213141516171819202122232425
  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 CannonBox extends CannonShape {
  6. shape: CANNON.Box;
  7. @RE.Prop("Vector3") sizeOffset: THREE.Vector3 = new THREE.Vector3(1, 1, 1);
  8. worldScale = new THREE.Vector3();
  9. protected createShape() {
  10. this.object3d.getWorldScale(this.worldScale);
  11. this.shape = new CANNON.Box(
  12. new CANNON.Vec3(
  13. this.sizeOffset.x * (this.worldScale.x/2),
  14. this.sizeOffset.y * (this.worldScale.y/2),
  15. this.sizeOffset.z * (this.worldScale.z/2)
  16. )
  17. );
  18. }
  19. }
  20. RE.registerComponent(CannonBox);