CannonCylinder.re.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 CannonCylinder extends CannonShape {
  6. shape: CANNON.Cylinder;
  7. @RE.props.num() radiusTopOffset = 1;
  8. @RE.props.num() radiusBottomOffset = 1;
  9. @RE.props.num() heightOffset = 1;
  10. @RE.props.num() segments = 100;
  11. private _collisionResponse = true;
  12. @RE.props.checkbox()
  13. get collisionResponse() {
  14. return this._collisionResponse;
  15. };
  16. set collisionResponse(value: boolean) {
  17. this._collisionResponse = value;
  18. if (!this.shape) return;
  19. this.shape.collisionResponse = value;
  20. };
  21. worldScale = new THREE.Vector3();
  22. protected createShape() {
  23. this.object3d.getWorldScale(this.worldScale);
  24. this.shape = new CANNON.Cylinder(
  25. this.radiusTopOffset * this.worldScale.x,
  26. this.radiusBottomOffset * this.worldScale.x,
  27. this.heightOffset * this.worldScale.y,
  28. this.segments
  29. );
  30. this.shape.collisionResponse = this._collisionResponse;
  31. }
  32. }
  33. RE.registerComponent(CannonCylinder);