math.path.d.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. import type { DeepImmutable, Nullable } from "../types";
  2. import { Vector2, Vector3 } from "./math.vector";
  3. import type { Vector4 } from "./math.vector";
  4. /**
  5. * Defines potential orientation for back face culling
  6. */
  7. export declare enum Orientation {
  8. /**
  9. * Clockwise
  10. */
  11. CW = 0,
  12. /** Counter clockwise */
  13. CCW = 1
  14. }
  15. /** Class used to represent a Bezier curve */
  16. export declare class BezierCurve {
  17. /**
  18. * Returns the cubic Bezier interpolated value (float) at "t" (float) from the given x1, y1, x2, y2 floats
  19. * @param t defines the time
  20. * @param x1 defines the left coordinate on X axis
  21. * @param y1 defines the left coordinate on Y axis
  22. * @param x2 defines the right coordinate on X axis
  23. * @param y2 defines the right coordinate on Y axis
  24. * @returns the interpolated value
  25. */
  26. static Interpolate(t: number, x1: number, y1: number, x2: number, y2: number): number;
  27. }
  28. /**
  29. * Defines angle representation
  30. */
  31. export declare class Angle {
  32. private _radians;
  33. /**
  34. * Creates an Angle object of "radians" radians (float).
  35. * @param radians the angle in radians
  36. */
  37. constructor(radians: number);
  38. /**
  39. * Get value in degrees
  40. * @returns the Angle value in degrees (float)
  41. */
  42. degrees(): number;
  43. /**
  44. * Get value in radians
  45. * @returns the Angle value in radians (float)
  46. */
  47. radians(): number;
  48. /**
  49. * Gets a new Angle object with a value of the angle (in radians) between the line connecting the two points and the x-axis
  50. * @param a defines first point as the origin
  51. * @param b defines point
  52. * @returns a new Angle
  53. */
  54. static BetweenTwoPoints(a: DeepImmutable<Vector2>, b: DeepImmutable<Vector2>): Angle;
  55. /**
  56. * Gets the angle between the two vectors
  57. * @param a defines first vector
  58. * @param b defines vector
  59. * @returns Returns an new Angle between 0 and PI
  60. */
  61. static BetweenTwoVectors<Vec extends Vector2 | Vector3 | Vector4>(a: DeepImmutable<Vec>, b: DeepImmutable<Vec>): Angle;
  62. /**
  63. * Gets a new Angle object from the given float in radians
  64. * @param radians defines the angle value in radians
  65. * @returns a new Angle
  66. */
  67. static FromRadians(radians: number): Angle;
  68. /**
  69. * Gets a new Angle object from the given float in degrees
  70. * @param degrees defines the angle value in degrees
  71. * @returns a new Angle
  72. */
  73. static FromDegrees(degrees: number): Angle;
  74. }
  75. /**
  76. * This represents an arc in a 2d space.
  77. */
  78. export declare class Arc2 {
  79. /** Defines the start point of the arc */
  80. startPoint: Vector2;
  81. /** Defines the mid point of the arc */
  82. midPoint: Vector2;
  83. /** Defines the end point of the arc */
  84. endPoint: Vector2;
  85. /**
  86. * Defines the center point of the arc.
  87. */
  88. centerPoint: Vector2;
  89. /**
  90. * Defines the radius of the arc.
  91. */
  92. radius: number;
  93. /**
  94. * Defines the angle of the arc (from mid point to end point).
  95. */
  96. angle: Angle;
  97. /**
  98. * Defines the start angle of the arc (from start point to middle point).
  99. */
  100. startAngle: Angle;
  101. /**
  102. * Defines the orientation of the arc (clock wise/counter clock wise).
  103. */
  104. orientation: Orientation;
  105. /**
  106. * Creates an Arc object from the three given points : start, middle and end.
  107. * @param startPoint Defines the start point of the arc
  108. * @param midPoint Defines the middle point of the arc
  109. * @param endPoint Defines the end point of the arc
  110. */
  111. constructor(
  112. /** Defines the start point of the arc */
  113. startPoint: Vector2,
  114. /** Defines the mid point of the arc */
  115. midPoint: Vector2,
  116. /** Defines the end point of the arc */
  117. endPoint: Vector2);
  118. }
  119. /**
  120. * Represents a 2D path made up of multiple 2D points
  121. */
  122. export declare class Path2 {
  123. private _points;
  124. private _length;
  125. /**
  126. * If the path start and end point are the same
  127. */
  128. closed: boolean;
  129. /**
  130. * Creates a Path2 object from the starting 2D coordinates x and y.
  131. * @param x the starting points x value
  132. * @param y the starting points y value
  133. */
  134. constructor(x: number, y: number);
  135. /**
  136. * Adds a new segment until the given coordinates (x, y) to the current Path2.
  137. * @param x the added points x value
  138. * @param y the added points y value
  139. * @returns the updated Path2.
  140. */
  141. addLineTo(x: number, y: number): Path2;
  142. /**
  143. * Adds _numberOfSegments_ segments according to the arc definition (middle point coordinates, end point coordinates, the arc start point being the current Path2 last point) to the current Path2.
  144. * @param midX middle point x value
  145. * @param midY middle point y value
  146. * @param endX end point x value
  147. * @param endY end point y value
  148. * @param numberOfSegments (default: 36)
  149. * @returns the updated Path2.
  150. */
  151. addArcTo(midX: number, midY: number, endX: number, endY: number, numberOfSegments?: number): Path2;
  152. /**
  153. * Adds _numberOfSegments_ segments according to the quadratic curve definition to the current Path2.
  154. * @param controlX control point x value
  155. * @param controlY control point y value
  156. * @param endX end point x value
  157. * @param endY end point y value
  158. * @param numberOfSegments (default: 36)
  159. * @returns the updated Path2.
  160. */
  161. addQuadraticCurveTo(controlX: number, controlY: number, endX: number, endY: number, numberOfSegments?: number): Path2;
  162. /**
  163. * Adds _numberOfSegments_ segments according to the bezier curve definition to the current Path2.
  164. * @param originTangentX tangent vector at the origin point x value
  165. * @param originTangentY tangent vector at the origin point y value
  166. * @param destinationTangentX tangent vector at the destination point x value
  167. * @param destinationTangentY tangent vector at the destination point y value
  168. * @param endX end point x value
  169. * @param endY end point y value
  170. * @param numberOfSegments (default: 36)
  171. * @returns the updated Path2.
  172. */
  173. addBezierCurveTo(originTangentX: number, originTangentY: number, destinationTangentX: number, destinationTangentY: number, endX: number, endY: number, numberOfSegments?: number): Path2;
  174. /**
  175. * Defines if a given point is inside the polygon defines by the path
  176. * @param point defines the point to test
  177. * @returns true if the point is inside
  178. */
  179. isPointInside(point: Vector2): boolean;
  180. /**
  181. * Closes the Path2.
  182. * @returns the Path2.
  183. */
  184. close(): Path2;
  185. /**
  186. * Gets the sum of the distance between each sequential point in the path
  187. * @returns the Path2 total length (float).
  188. */
  189. length(): number;
  190. /**
  191. * Gets the area of the polygon defined by the path
  192. * @returns area value
  193. */
  194. area(): number;
  195. /**
  196. * Gets the points which construct the path
  197. * @returns the Path2 internal array of points.
  198. */
  199. getPoints(): Vector2[];
  200. /**
  201. * Retrieves the point at the distance aways from the starting point
  202. * @param normalizedLengthPosition the length along the path to retrieve the point from
  203. * @returns a new Vector2 located at a percentage of the Path2 total length on this path.
  204. */
  205. getPointAtLengthPosition(normalizedLengthPosition: number): Vector2;
  206. /**
  207. * Creates a new path starting from an x and y position
  208. * @param x starting x value
  209. * @param y starting y value
  210. * @returns a new Path2 starting at the coordinates (x, y).
  211. */
  212. static StartingAt(x: number, y: number): Path2;
  213. }
  214. /**
  215. * Represents a 3D path made up of multiple 3D points
  216. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D
  217. */
  218. export declare class Path3D {
  219. /**
  220. * an array of Vector3, the curve axis of the Path3D
  221. */
  222. path: Vector3[];
  223. private _curve;
  224. private _distances;
  225. private _tangents;
  226. private _normals;
  227. private _binormals;
  228. private _raw;
  229. private _alignTangentsWithPath;
  230. private readonly _pointAtData;
  231. /**
  232. * new Path3D(path, normal, raw)
  233. * Creates a Path3D. A Path3D is a logical math object, so not a mesh.
  234. * please read the description in the tutorial : https://doc.babylonjs.com/features/featuresDeepDive/mesh/path3D
  235. * @param path an array of Vector3, the curve axis of the Path3D
  236. * @param firstNormal (options) Vector3, the first wanted normal to the curve. Ex (0, 1, 0) for a vertical normal.
  237. * @param raw (optional, default false) : boolean, if true the returned Path3D isn't normalized. Useful to depict path acceleration or speed.
  238. * @param alignTangentsWithPath (optional, default false) : boolean, if true the tangents will be aligned with the path.
  239. */
  240. constructor(
  241. /**
  242. * an array of Vector3, the curve axis of the Path3D
  243. */
  244. path: Vector3[], firstNormal?: Nullable<Vector3>, raw?: boolean, alignTangentsWithPath?: boolean);
  245. /**
  246. * Returns the Path3D array of successive Vector3 designing its curve.
  247. * @returns the Path3D array of successive Vector3 designing its curve.
  248. */
  249. getCurve(): Vector3[];
  250. /**
  251. * Returns the Path3D array of successive Vector3 designing its curve.
  252. * @returns the Path3D array of successive Vector3 designing its curve.
  253. */
  254. getPoints(): Vector3[];
  255. /**
  256. * @returns the computed length (float) of the path.
  257. */
  258. length(): number;
  259. /**
  260. * Returns an array populated with tangent vectors on each Path3D curve point.
  261. * @returns an array populated with tangent vectors on each Path3D curve point.
  262. */
  263. getTangents(): Vector3[];
  264. /**
  265. * Returns an array populated with normal vectors on each Path3D curve point.
  266. * @returns an array populated with normal vectors on each Path3D curve point.
  267. */
  268. getNormals(): Vector3[];
  269. /**
  270. * Returns an array populated with binormal vectors on each Path3D curve point.
  271. * @returns an array populated with binormal vectors on each Path3D curve point.
  272. */
  273. getBinormals(): Vector3[];
  274. /**
  275. * Returns an array populated with distances (float) of the i-th point from the first curve point.
  276. * @returns an array populated with distances (float) of the i-th point from the first curve point.
  277. */
  278. getDistances(): number[];
  279. /**
  280. * Returns an interpolated point along this path
  281. * @param position the position of the point along this path, from 0.0 to 1.0
  282. * @returns a new Vector3 as the point
  283. */
  284. getPointAt(position: number): Vector3;
  285. /**
  286. * Returns the tangent vector of an interpolated Path3D curve point at the specified position along this path.
  287. * @param position the position of the point along this path, from 0.0 to 1.0
  288. * @param interpolated (optional, default false) : boolean, if true returns an interpolated tangent instead of the tangent of the previous path point.
  289. * @returns a tangent vector corresponding to the interpolated Path3D curve point, if not interpolated, the tangent is taken from the precomputed tangents array.
  290. */
  291. getTangentAt(position: number, interpolated?: boolean): Vector3;
  292. /**
  293. * Returns the tangent vector of an interpolated Path3D curve point at the specified position along this path.
  294. * @param position the position of the point along this path, from 0.0 to 1.0
  295. * @param interpolated (optional, default false) : boolean, if true returns an interpolated normal instead of the normal of the previous path point.
  296. * @returns a normal vector corresponding to the interpolated Path3D curve point, if not interpolated, the normal is taken from the precomputed normals array.
  297. */
  298. getNormalAt(position: number, interpolated?: boolean): Vector3;
  299. /**
  300. * Returns the binormal vector of an interpolated Path3D curve point at the specified position along this path.
  301. * @param position the position of the point along this path, from 0.0 to 1.0
  302. * @param interpolated (optional, default false) : boolean, if true returns an interpolated binormal instead of the binormal of the previous path point.
  303. * @returns a binormal vector corresponding to the interpolated Path3D curve point, if not interpolated, the binormal is taken from the precomputed binormals array.
  304. */
  305. getBinormalAt(position: number, interpolated?: boolean): Vector3;
  306. /**
  307. * Returns the distance (float) of an interpolated Path3D curve point at the specified position along this path.
  308. * @param position the position of the point along this path, from 0.0 to 1.0
  309. * @returns the distance of the interpolated Path3D curve point at the specified position along this path.
  310. */
  311. getDistanceAt(position: number): number;
  312. /**
  313. * Returns the array index of the previous point of an interpolated point along this path
  314. * @param position the position of the point to interpolate along this path, from 0.0 to 1.0
  315. * @returns the array index
  316. */
  317. getPreviousPointIndexAt(position: number): number;
  318. /**
  319. * Returns the position of an interpolated point relative to the two path points it lies between, from 0.0 (point A) to 1.0 (point B)
  320. * @param position the position of the point to interpolate along this path, from 0.0 to 1.0
  321. * @returns the sub position
  322. */
  323. getSubPositionAt(position: number): number;
  324. /**
  325. * Returns the position of the closest virtual point on this path to an arbitrary Vector3, from 0.0 to 1.0
  326. * @param target the vector of which to get the closest position to
  327. * @returns the position of the closest virtual point on this path to the target vector
  328. */
  329. getClosestPositionTo(target: Vector3): number;
  330. /**
  331. * Returns a sub path (slice) of this path
  332. * @param start the position of the fist path point, from 0.0 to 1.0, or a negative value, which will get wrapped around from the end of the path to 0.0 to 1.0 values
  333. * @param end the position of the last path point, from 0.0 to 1.0, or a negative value, which will get wrapped around from the end of the path to 0.0 to 1.0 values
  334. * @returns a sub path (slice) of this path
  335. */
  336. slice(start?: number, end?: number): Path3D;
  337. /**
  338. * Forces the Path3D tangent, normal, binormal and distance recomputation.
  339. * @param path path which all values are copied into the curves points
  340. * @param firstNormal which should be projected onto the curve
  341. * @param alignTangentsWithPath (optional, default false) : boolean, if true the tangents will be aligned with the path
  342. * @returns the same object updated.
  343. */
  344. update(path: Vector3[], firstNormal?: Nullable<Vector3>, alignTangentsWithPath?: boolean): Path3D;
  345. private _compute;
  346. private _getFirstNonNullVector;
  347. private _getLastNonNullVector;
  348. private _normalVector;
  349. /**
  350. * Updates the point at data for an interpolated point along this curve
  351. * @param position the position of the point along this curve, from 0.0 to 1.0
  352. * @param interpolateTNB
  353. * @interpolateTNB whether to compute the interpolated tangent, normal and binormal
  354. * @returns the (updated) point at data
  355. */
  356. private _updatePointAtData;
  357. /**
  358. * Updates the point at data from the specified parameters
  359. * @param position where along the path the interpolated point is, from 0.0 to 1.0
  360. * @param subPosition
  361. * @param point the interpolated point
  362. * @param parentIndex the index of an existing curve point that is on, or else positionally the first behind, the interpolated point
  363. * @param interpolateTNB whether to compute the interpolated tangent, normal and binormal
  364. * @returns the (updated) point at data
  365. */
  366. private _setPointAtData;
  367. /**
  368. * Updates the point at interpolation matrix for the tangents, normals and binormals
  369. */
  370. private _updateInterpolationMatrix;
  371. }
  372. /**
  373. * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.
  374. * A Curve3 is designed from a series of successive Vector3.
  375. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves
  376. */
  377. export declare class Curve3 {
  378. private _points;
  379. private _length;
  380. /**
  381. * Returns a Curve3 object along a Quadratic Bezier curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#quadratic-bezier-curve
  382. * @param v0 (Vector3) the origin point of the Quadratic Bezier
  383. * @param v1 (Vector3) the control point
  384. * @param v2 (Vector3) the end point of the Quadratic Bezier
  385. * @param nbPoints (integer) the wanted number of points in the curve
  386. * @returns the created Curve3
  387. */
  388. static CreateQuadraticBezier(v0: DeepImmutable<Vector3>, v1: DeepImmutable<Vector3>, v2: DeepImmutable<Vector3>, nbPoints: number): Curve3;
  389. /**
  390. * Returns a Curve3 object along a Cubic Bezier curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#cubic-bezier-curve
  391. * @param v0 (Vector3) the origin point of the Cubic Bezier
  392. * @param v1 (Vector3) the first control point
  393. * @param v2 (Vector3) the second control point
  394. * @param v3 (Vector3) the end point of the Cubic Bezier
  395. * @param nbPoints (integer) the wanted number of points in the curve
  396. * @returns the created Curve3
  397. */
  398. static CreateCubicBezier(v0: DeepImmutable<Vector3>, v1: DeepImmutable<Vector3>, v2: DeepImmutable<Vector3>, v3: DeepImmutable<Vector3>, nbPoints: number): Curve3;
  399. /**
  400. * Returns a Curve3 object along a Hermite Spline curve : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#hermite-spline
  401. * @param p1 (Vector3) the origin point of the Hermite Spline
  402. * @param t1 (Vector3) the tangent vector at the origin point
  403. * @param p2 (Vector3) the end point of the Hermite Spline
  404. * @param t2 (Vector3) the tangent vector at the end point
  405. * @param nSeg (integer) the number of curve segments or nSeg + 1 points in the array
  406. * @returns the created Curve3
  407. */
  408. static CreateHermiteSpline(p1: DeepImmutable<Vector3>, t1: DeepImmutable<Vector3>, p2: DeepImmutable<Vector3>, t2: DeepImmutable<Vector3>, nSeg: number): Curve3;
  409. /**
  410. * Returns a Curve3 object along a CatmullRom Spline curve :
  411. * @param points (array of Vector3) the points the spline must pass through. At least, four points required
  412. * @param nbPoints (integer) the wanted number of points between each curve control points
  413. * @param closed (boolean) optional with default false, when true forms a closed loop from the points
  414. * @returns the created Curve3
  415. */
  416. static CreateCatmullRomSpline(points: DeepImmutable<Vector3[]>, nbPoints: number, closed?: boolean): Curve3;
  417. /**
  418. * Returns a Curve3 object along an arc through three vector3 points:
  419. * The three points should not be colinear. When they are the Curve3 is empty.
  420. * @param first (Vector3) the first point the arc must pass through.
  421. * @param second (Vector3) the second point the arc must pass through.
  422. * @param third (Vector3) the third point the arc must pass through.
  423. * @param steps (number) the larger the number of steps the more detailed the arc.
  424. * @param closed (boolean) optional with default false, when true forms the chord from the first and third point
  425. * @param fullCircle Circle (boolean) optional with default false, when true forms the complete circle through the three points
  426. * @returns the created Curve3
  427. */
  428. static ArcThru3Points(first: Vector3, second: Vector3, third: Vector3, steps?: number, closed?: boolean, fullCircle?: boolean): Curve3;
  429. /**
  430. * A Curve3 object is a logical object, so not a mesh, to handle curves in the 3D geometric space.
  431. * A Curve3 is designed from a series of successive Vector3.
  432. * Tuto : https://doc.babylonjs.com/features/featuresDeepDive/mesh/drawCurves#curve3-object
  433. * @param points points which make up the curve
  434. */
  435. constructor(points: Vector3[]);
  436. /**
  437. * @returns the Curve3 stored array of successive Vector3
  438. */
  439. getPoints(): Vector3[];
  440. /**
  441. * @returns the computed length (float) of the curve.
  442. */
  443. length(): number;
  444. /**
  445. * Returns a new instance of Curve3 object : var curve = curveA.continue(curveB);
  446. * This new Curve3 is built by translating and sticking the curveB at the end of the curveA.
  447. * curveA and curveB keep unchanged.
  448. * @param curve the curve to continue from this curve
  449. * @returns the newly constructed curve
  450. */
  451. continue(curve: DeepImmutable<Curve3>): Curve3;
  452. private _computeLength;
  453. }