RapierBall.re.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import RAPIER from '@dimforge/rapier3d-compat';
  2. import * as RE from 'rogue-engine';
  3. import * as THREE from 'three';
  4. import RogueRapier from '../../Lib/RogueRapier';
  5. import RapierCollider from './RapierCollider';
  6. export default class RapierBall extends RapierCollider {
  7. private _radiusOffset = 0;
  8. @RE.props.num()
  9. get radiusOffset() {
  10. return this._radiusOffset;
  11. }
  12. set radiusOffset(value: number) {
  13. const oldValue = this._radiusOffset;
  14. this._radiusOffset = value;
  15. if (oldValue !== value && this.collider && RogueRapier.world) {
  16. RogueRapier.world.removeCollider(this.collider, false);
  17. this.init();
  18. }
  19. }
  20. worldScale = new THREE.Vector3();
  21. protected createShape(): void {
  22. this.object3d.getWorldScale(this.worldScale);
  23. const maxSide = Math.max(this.worldScale.x, this.worldScale.y, this.worldScale.z);
  24. let colliderDesc = RAPIER.ColliderDesc.ball(this.radiusOffset + maxSide);
  25. this.collider = RogueRapier.world.createCollider(colliderDesc, this.body);
  26. }
  27. }
  28. RE.registerComponent(RapierBall);