physicsRaycastResult.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import { Vector3 } from "../Maths/math.vector.js";
  2. import { CastingResult } from "./castingResult.js";
  3. /**
  4. * Holds the data for the raycast result
  5. * @see https://doc.babylonjs.com/features/featuresDeepDive/physics/usingPhysicsEngine
  6. */
  7. export class PhysicsRaycastResult extends CastingResult {
  8. constructor() {
  9. super(...arguments);
  10. this._hitDistance = 0;
  11. this._rayFromWorld = Vector3.Zero();
  12. this._rayToWorld = Vector3.Zero();
  13. }
  14. /**
  15. * Gets the distance from the hit
  16. */
  17. get hitDistance() {
  18. return this._hitDistance;
  19. }
  20. /**
  21. * Gets the hit normal/direction in the world
  22. */
  23. get hitNormalWorld() {
  24. return this._hitNormal;
  25. }
  26. /**
  27. * Gets the hit point in the world
  28. */
  29. get hitPointWorld() {
  30. return this._hitPoint;
  31. }
  32. /**
  33. * Gets the ray "start point" of the ray in the world
  34. */
  35. get rayFromWorld() {
  36. return this._rayFromWorld;
  37. }
  38. /**
  39. * Gets the ray "end point" of the ray in the world
  40. */
  41. get rayToWorld() {
  42. return this._rayToWorld;
  43. }
  44. /**
  45. * Sets the distance from the start point to the hit point
  46. * @param distance defines the distance to set
  47. */
  48. setHitDistance(distance) {
  49. this._hitDistance = distance;
  50. }
  51. /**
  52. * Calculates the distance manually
  53. */
  54. calculateHitDistance() {
  55. this._hitDistance = Vector3.Distance(this._rayFromWorld, this._hitPoint);
  56. }
  57. /**
  58. * Resets all the values to default
  59. * @param from The from point on world space
  60. * @param to The to point on world space
  61. */
  62. reset(from = Vector3.Zero(), to = Vector3.Zero()) {
  63. super.reset();
  64. this._rayFromWorld.copyFrom(from);
  65. this._rayToWorld.copyFrom(to);
  66. this._hitDistance = 0;
  67. }
  68. }
  69. //# sourceMappingURL=physicsRaycastResult.js.map