greasedLineTools.d.ts 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import { Vector3 } from "../Maths/math.vector";
  2. import type { AbstractMesh } from "../Meshes/abstractMesh";
  3. import type { IFontData } from "../Meshes/Builders/textBuilder";
  4. import type { FloatArray, IndicesArray } from "../types";
  5. import type { GreasedLinePoints } from "../Meshes/GreasedLine/greasedLineBaseMesh";
  6. import type { Color3 } from "../Maths/math.color";
  7. import { RawTexture } from "../Materials/Textures/rawTexture";
  8. import type { Scene } from "../scene";
  9. /**
  10. * Tool functions for GreasedLine
  11. */
  12. export declare class GreasedLineTools {
  13. /**
  14. * Converts GreasedLinePoints to number[][]
  15. * @param points GreasedLinePoints
  16. * @returns number[][] with x, y, z coordinates of the points, like [[x, y, z, x, y, z, ...], [x, y, z, ...]]
  17. */
  18. static ConvertPoints(points: GreasedLinePoints): number[][];
  19. /**
  20. * Omit zero length lines predicate for the MeshesToLines function
  21. * @param p1 point1 position of the face
  22. * @param p2 point2 position of the face
  23. * @param p3 point3 position of the face
  24. * @returns original points or null if any edge length is zero
  25. */
  26. static OmitZeroLengthPredicate(p1: Vector3, p2: Vector3, p3: Vector3): Vector3[][] | null;
  27. /**
  28. * Omit duplicate lines predicate for the MeshesToLines function
  29. * @param p1 point1 position of the face
  30. * @param p2 point2 position of the face
  31. * @param p3 point3 position of the face
  32. * @param points array of points to search in
  33. * @returns original points or null if any edge length is zero
  34. */
  35. static OmitDuplicatesPredicate(p1: Vector3, p2: Vector3, p3: Vector3, points: Vector3[][]): Vector3[][] | null;
  36. private static _SearchInPoints;
  37. /**
  38. * Gets mesh triangles as line positions
  39. * @param meshes array of meshes
  40. * @param predicate predicate function which decides whether to include the mesh triangle/face in the ouput
  41. * @returns array of arrays of points
  42. */
  43. static MeshesToLines(meshes: AbstractMesh[], predicate?: (p1: Vector3, p2: Vector3, p3: Vector3, points: Vector3[][], indiceIndex: number, vertexIndex: number, mesh: AbstractMesh, meshIndex: number, vertices: FloatArray, indices: IndicesArray) => Vector3[][]): Vector3[][];
  44. /**
  45. * Converts number coordinates to Vector3s
  46. * @param points number array of x, y, z, x, y z, ... coordinates
  47. * @returns Vector3 array
  48. */
  49. static ToVector3Array(points: number[] | number[][]): Vector3[] | Vector3[][];
  50. /**
  51. * Gets a number array from a Vector3 array.
  52. * You can you for example to convert your Vector3[] offsets to the required number[] for the offsets option.
  53. * @param points Vector3 array
  54. * @returns an array of x, y, z coordinates as numbers [x, y, z, x, y, z, x, y, z, ....]
  55. */
  56. static ToNumberArray(points: Vector3[]): number[];
  57. /**
  58. * Calculates the sum of points of every line and the number of points in each line.
  59. * This function is useful when you are drawing multiple lines in one mesh and you want
  60. * to know the counts. For example for creating an offsets table.
  61. * @param points point array
  62. * @returns points count info
  63. */
  64. static GetPointsCountInfo(points: number[][]): {
  65. total: number;
  66. counts: number[];
  67. };
  68. /**
  69. * Gets the length of the line counting all it's segments length
  70. * @param data array of line points
  71. * @returns length of the line
  72. */
  73. static GetLineLength(data: Vector3[] | number[]): number;
  74. /**
  75. * Gets the the length from the beginning to each point of the line as array.
  76. * @param data array of line points
  77. * @returns length array of the line
  78. */
  79. static GetLineLengthArray(data: number[]): Float32Array;
  80. /**
  81. * Divides a segment into smaller segments.
  82. * A segment is a part of the line between it's two points.
  83. * @param point1 first point of the line
  84. * @param point2 second point of the line
  85. * @param segmentCount number of segments we want to have in the divided line
  86. * @returns
  87. */
  88. static SegmentizeSegmentByCount(point1: Vector3, point2: Vector3, segmentCount: number): Vector3[];
  89. /**
  90. * Divides a line into segments.
  91. * A segment is a part of the line between it's two points.
  92. * @param what line points
  93. * @param segmentLength length of each segment of the resulting line (distance between two line points)
  94. * @returns line point
  95. */
  96. static SegmentizeLineBySegmentLength(what: Vector3[] | number[] | {
  97. point1: Vector3;
  98. point2: Vector3;
  99. length: number;
  100. }[], segmentLength: number): Vector3[];
  101. /**
  102. * Divides a line into segments.
  103. * A segment is a part of the line between it's two points.
  104. * @param what line points
  105. * @param segmentCount number of segments
  106. * @returns line point
  107. */
  108. static SegmentizeLineBySegmentCount(what: Vector3[] | number[], segmentCount: number): Vector3[];
  109. /**
  110. * Gets line segments.
  111. * A segment is a part of the line between it's two points.
  112. * @param points line points
  113. * @returns segments information of the line segment including starting point, ending point and the distance between them
  114. */
  115. static GetLineSegments(points: Vector3[]): {
  116. point1: Vector3;
  117. point2: Vector3;
  118. length: number;
  119. }[];
  120. /**
  121. * Gets the minimum and the maximum length of a line segment in the line.
  122. * A segment is a part of the line between it's two points.
  123. * @param points line points
  124. * @returns
  125. */
  126. static GetMinMaxSegmentLength(points: Vector3[]): {
  127. min: number;
  128. max: number;
  129. };
  130. /**
  131. * Finds the last visible position in world space of the line according to the visibility parameter
  132. * @param lineSegments segments of the line
  133. * @param lineLength total length of the line
  134. * @param visbility normalized value of visibility
  135. * @param localSpace if true the result will be in local space (default is false)
  136. * @returns world space coordinate of the last visible piece of the line
  137. */
  138. static GetPositionOnLineByVisibility(lineSegments: {
  139. point1: Vector3;
  140. point2: Vector3;
  141. length: number;
  142. }[], lineLength: number, visbility: number, localSpace?: boolean): Vector3;
  143. /**
  144. * Creates lines in a shape of circle/arc.
  145. * A segment is a part of the line between it's two points.
  146. * @param radiusX radiusX of the circle
  147. * @param segments number of segments in the circle
  148. * @param z z coordinate of the points. Defaults to 0.
  149. * @param radiusY radiusY of the circle - you can draw an oval if using different values
  150. * @param segmentAngle angle offset of the segments. Defaults to Math.PI * 2 / segments. Change this value to draw a part of the circle.
  151. * @returns line points
  152. */
  153. static GetCircleLinePoints(radiusX: number, segments: number, z?: number, radiusY?: number, segmentAngle?: number): Vector3[];
  154. /**
  155. * Gets line points in a shape of a bezier curve
  156. * @param p0 bezier point0
  157. * @param p1 bezier point1
  158. * @param p2 bezier point2
  159. * @param segments number of segments in the curve
  160. * @returns
  161. */
  162. static GetBezierLinePoints(p0: Vector3, p1: Vector3, p2: Vector3, segments: number): number[];
  163. /**
  164. *
  165. * @param position position of the arrow cap (mainly you want to create a triangle, set widthUp and widthDown to the same value and omit widthStartUp and widthStartDown)
  166. * @param direction direction which the arrow points to
  167. * @param length length (size) of the arrow cap itself
  168. * @param widthUp the arrow width above the line
  169. * @param widthDown the arrow width belove the line
  170. * @param widthStartUp the arrow width at the start of the arrow above the line. In most scenarios this is 0.
  171. * @param widthStartDown the arrow width at the start of the arrow below the line. In most scenarios this is 0.
  172. * @returns
  173. */
  174. static GetArrowCap(position: Vector3, direction: Vector3, length: number, widthUp: number, widthDown: number, widthStartUp?: number, widthStartDown?: number): {
  175. points: Vector3[];
  176. widths: number[];
  177. };
  178. /**
  179. * Gets 3D positions of points from a text and font
  180. * @param text Text
  181. * @param size Size of the font
  182. * @param resolution Resolution of the font
  183. * @param fontData defines the font data (can be generated with http://gero3.github.io/facetype.js/)
  184. * @param z z coordinate
  185. * @param includeInner include the inner parts of the font in the result. Default true. If false, only the outlines will be returned.
  186. * @returns number[][] of 3D positions
  187. */
  188. static GetPointsFromText(text: string, size: number, resolution: number, fontData: IFontData, z?: number, includeInner?: boolean): number[][];
  189. /**
  190. * Converts an array of Color3 to Uint8Array
  191. * @param colors Arrray of Color3
  192. * @returns Uin8Array of colors [r, g, b, a, r, g, b, a, ...]
  193. */
  194. static Color3toRGBAUint8(colors: Color3[]): Uint8Array;
  195. /**
  196. * Creates a RawTexture from an RGBA color array and sets it on the plugin material instance.
  197. * @param name name of the texture
  198. * @param colors Uint8Array of colors
  199. * @param colorsSampling sampling mode of the created texture
  200. * @param scene Scene
  201. * @returns the colors texture
  202. */
  203. static CreateColorsTexture(name: string, colors: Color3[], colorsSampling: number, scene: Scene): RawTexture;
  204. /**
  205. * A minimum size texture for the colors sampler2D when there is no colors texture defined yet.
  206. * For fast switching using the useColors property without the need to use defines.
  207. * @param scene Scene
  208. * @returns empty colors texture
  209. */
  210. static PrepareEmptyColorsTexture(scene: Scene): RawTexture;
  211. /**
  212. * Diposes the shared empty colors texture
  213. */
  214. static DisposeEmptyColorsTexture(): void;
  215. /**
  216. * Converts boolean to number.
  217. * @param bool the bool value
  218. * @returns 1 if true, 0 if false.
  219. */
  220. static BooleanToNumber(bool?: boolean): 0 | 1;
  221. }