castingResult.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { Vector3 } from "../Maths/math.vector.js";
  2. /**
  3. * Base class for results of casts.
  4. */
  5. export class CastingResult {
  6. constructor() {
  7. this._hasHit = false;
  8. this._hitNormal = Vector3.Zero();
  9. this._hitPoint = Vector3.Zero();
  10. this._triangleIndex = -1;
  11. }
  12. /**
  13. * Gets the hit point.
  14. */
  15. get hitPoint() {
  16. return this._hitPoint;
  17. }
  18. /**
  19. * Gets the hit normal.
  20. */
  21. get hitNormal() {
  22. return this._hitNormal;
  23. }
  24. /**
  25. * Gets if there was a hit
  26. */
  27. get hasHit() {
  28. return this._hasHit;
  29. }
  30. /*
  31. * The index of the original triangle which was hit. Will be -1 if contact point is not on a mesh shape
  32. */
  33. get triangleIndex() {
  34. return this._triangleIndex;
  35. }
  36. /**
  37. * Sets the hit data
  38. * @param hitNormal defines the normal in world space
  39. * @param hitPoint defines the point in world space
  40. * @param triangleIndex defines the index of the triangle in case of mesh shape
  41. */
  42. setHitData(hitNormal, hitPoint, triangleIndex) {
  43. this._hasHit = true;
  44. this._hitNormal.set(hitNormal.x, hitNormal.y, hitNormal.z);
  45. this._hitPoint.set(hitPoint.x, hitPoint.y, hitPoint.z);
  46. this._triangleIndex = triangleIndex ?? -1;
  47. }
  48. /**
  49. * Resets all the values to default
  50. */
  51. reset() {
  52. this._hasHit = false;
  53. this._hitNormal.setAll(0);
  54. this._hitPoint.setAll(0);
  55. this._triangleIndex = -1;
  56. this.body = undefined;
  57. this.bodyIndex = undefined;
  58. this.shape = undefined;
  59. }
  60. }
  61. //# sourceMappingURL=castingResult.js.map