greasedLineBaseMesh.d.ts 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import type { Scene } from "../../scene";
  2. import type { IGreasedLineMaterial } from "../../Materials/GreasedLine/greasedLineMaterialInterfaces";
  3. import { Mesh } from "../mesh";
  4. import { Buffer } from "../../Buffers/buffer";
  5. import type { Vector3 } from "../../Maths/math.vector";
  6. import { VertexData } from "../mesh.vertexData";
  7. import type { AbstractEngine } from "../../Engines/abstractEngine";
  8. import type { FloatArray, IndicesArray } from "../../types";
  9. /**
  10. * In POINTS_MODE_POINTS every array of points will become the center (backbone) of the ribbon. The ribbon will be expanded by `width / 2` to `+direction` and `-direction` as well.
  11. * In POINTS_MODE_PATHS every array of points specifies an edge. These will be used to build one ribbon.
  12. */
  13. export declare enum GreasedLineRibbonPointsMode {
  14. POINTS_MODE_POINTS = 0,
  15. POINTS_MODE_PATHS = 1
  16. }
  17. /**
  18. * FACES_MODE_SINGLE_SIDED single sided with back face culling. Default value.
  19. * FACES_MODE_SINGLE_SIDED_NO_BACKFACE_CULLING single sided without back face culling. Sets backFaceCulling = false on the material so it affects all line ribbons added to the line ribbon instance.
  20. * FACES_MODE_DOUBLE_SIDED extra back faces are created. This doubles the amount of faces of the mesh.
  21. */
  22. export declare enum GreasedLineRibbonFacesMode {
  23. FACES_MODE_SINGLE_SIDED = 0,
  24. FACES_MODE_SINGLE_SIDED_NO_BACKFACE_CULLING = 1,
  25. FACES_MODE_DOUBLE_SIDED = 2
  26. }
  27. /**
  28. * Only with POINTS_MODE_PATHS.
  29. * AUTO_DIRECTIONS_FROM_FIRST_SEGMENT sets the direction (slope) of the ribbon from the direction of the first line segment. Recommended.
  30. * AUTO_DIRECTIONS_FROM_ALL_SEGMENTS in this mode the direction (slope) will be calculated for each line segment according to the direction vector between each point of the line segments. Slow method.
  31. * AUTO_DIRECTIONS_ENHANCED in this mode the direction (slope) will be calculated for each line segment according to the direction vector between each point of the line segments using a more sophisitcaed algorithm. Slowest method.
  32. * AUTO_DIRECTIONS_FACE_TO in this mode the direction (slope) will be calculated for each line segment according to the direction vector between each point of the line segments and a direction (face-to) vector specified in direction. The resulting line will face to the direction of this face-to vector.
  33. * AUTO_DIRECTIONS_NONE you have to set the direction (slope) manually. Recommended.
  34. */
  35. export declare enum GreasedLineRibbonAutoDirectionMode {
  36. AUTO_DIRECTIONS_FROM_FIRST_SEGMENT = 0,
  37. AUTO_DIRECTIONS_FROM_ALL_SEGMENTS = 1,
  38. AUTO_DIRECTIONS_ENHANCED = 2,
  39. AUTO_DIRECTIONS_FACE_TO = 3,
  40. AUTO_DIRECTIONS_NONE = 99
  41. }
  42. export type GreasedLineRibbonOptions = {
  43. /**
  44. * Defines how the points are processed.
  45. * In GreasedLineRibbonPointsMode.POINTS_MODE_POINTS every array of points will become the center of the ribbon. The ribbon will be expanded by width/2 to +direction and -direction as well.
  46. * In GreasedLineRibbonPointsMode.POINTS_MODE_PATHS every array of points is one path. These will be used to buuid one ribbon.
  47. */
  48. pointsMode?: GreasedLineRibbonPointsMode;
  49. /**
  50. * Normalized directions of the slopes of the non camera facing lines.
  51. */
  52. directions?: Vector3[] | Vector3;
  53. /**
  54. * Defines the calculation mode of the directions which the line will be thickened to.
  55. */
  56. directionsAutoMode?: GreasedLineRibbonAutoDirectionMode;
  57. /**
  58. * Width of the ribbon.
  59. */
  60. width?: number;
  61. /**
  62. * Controls how the faces are created.
  63. * GreasedLineRibbonFacesMode.FACES_MODE_SINGLE_SIDED = single sided with back face culling. Default value.
  64. * GreasedLineRibbonFacesMode.FACES_MODE_SINGLE_SIDED_NO_BACKFACE_CULLING = single sided without back face culling
  65. * GreasedLineRibbonFacesMode.FACES_MODE_DOUBLE_SIDED = extra back faces are created. This doubles the amount of faces of the mesh.
  66. */
  67. facesMode?: GreasedLineRibbonFacesMode;
  68. /**
  69. * If true, the path will be closed.
  70. */
  71. closePath?: boolean;
  72. /**
  73. * If true, normals will be computed when creating the vertex buffers.
  74. * This results to smooth shading of the mesh.
  75. */
  76. smoothShading?: boolean;
  77. };
  78. export type GreasedLinePoints = Vector3[] | Vector3[][] | Float32Array | Float32Array[] | number[][] | number[];
  79. /**
  80. * Options for creating a GreasedLineMesh
  81. */
  82. export interface GreasedLineMeshOptions {
  83. /**
  84. * Points of the line.
  85. */
  86. points: GreasedLinePoints;
  87. /**
  88. * Each line segment (from point to point) can have it's width multiplier. Final width = widths[segmentIdx] * width.
  89. * Defaults to empty array.
  90. */
  91. widths?: number[];
  92. /**
  93. * If instance is specified, lines are added to the specified instance.
  94. * Defaults to undefined.
  95. */
  96. instance?: GreasedLineBaseMesh;
  97. /**
  98. * You can manually set the color pointers so you can control which segment/part
  99. * will use which color from the colors material option
  100. */
  101. colorPointers?: number[];
  102. /**
  103. * UVs for the mesh
  104. */
  105. uvs?: FloatArray;
  106. /**
  107. * If true, offsets and widths are updatable.
  108. * Defaults to false.
  109. */
  110. updatable?: boolean;
  111. /**
  112. * Use when @see instance is specified.
  113. * If true, the line will be rendered only after calling instance.updateLazy(). If false, line will be rerendered after every call to @see CreateGreasedLine
  114. * Defaults to false.
  115. */
  116. lazy?: boolean;
  117. /**
  118. * The options for the ribbon which will be used as a line.
  119. * If this option is set the line switches automatically to a non camera facing mode.
  120. */
  121. ribbonOptions?: GreasedLineRibbonOptions;
  122. }
  123. /**
  124. * GreasedLineBaseMesh
  125. */
  126. export declare abstract class GreasedLineBaseMesh extends Mesh {
  127. readonly name: string;
  128. protected _options: GreasedLineMeshOptions;
  129. protected _vertexPositions: FloatArray;
  130. protected _indices: IndicesArray;
  131. protected _uvs: FloatArray;
  132. protected _points: number[][];
  133. protected _offsets: number[];
  134. protected _colorPointers: number[];
  135. protected _widths: number[];
  136. protected _offsetsBuffer?: Buffer;
  137. protected _widthsBuffer?: Buffer;
  138. protected _colorPointersBuffer?: Buffer;
  139. protected _lazy: boolean;
  140. protected _updatable: boolean;
  141. protected _engine: AbstractEngine;
  142. constructor(name: string, scene: Scene, _options: GreasedLineMeshOptions);
  143. /**
  144. * "GreasedLineMesh"
  145. * @returns "GreasedLineMesh"
  146. */
  147. getClassName(): string;
  148. protected abstract _setPoints(points: number[][], options?: GreasedLineMeshOptions): void;
  149. protected abstract _updateColorPointers(): void;
  150. protected abstract _updateWidths(): void;
  151. protected _updateWidthsWithValue(defaulValue: number): void;
  152. /**
  153. * Updated a lazy line. Rerenders the line and updates boundinfo as well.
  154. */
  155. updateLazy(): void;
  156. /**
  157. * Adds new points to the line. It doesn't rerenders the line if in lazy mode.
  158. * @param points points table
  159. * @param options optional options
  160. */
  161. addPoints(points: number[][], options?: GreasedLineMeshOptions): void;
  162. /**
  163. * Dispose the line and it's resources
  164. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  165. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  166. */
  167. dispose(doNotRecurse?: boolean, disposeMaterialAndTextures?: boolean): void;
  168. /**
  169. * @returns true if the mesh was created in lazy mode
  170. */
  171. isLazy(): boolean;
  172. /**
  173. * Returns the UVs
  174. */
  175. get uvs(): FloatArray;
  176. /**
  177. * Sets the UVs
  178. * @param uvs the UVs
  179. */
  180. set uvs(uvs: FloatArray);
  181. /**
  182. * Returns the points offsets
  183. * Return the points offsets
  184. */
  185. get offsets(): number[];
  186. /**
  187. * Sets point offests
  188. * @param offsets offset table [x,y,z, x,y,z, ....]
  189. */
  190. set offsets(offsets: number[]);
  191. /**
  192. * Gets widths at each line point like [widthLower, widthUpper, widthLower, widthUpper, ...]
  193. */
  194. get widths(): number[];
  195. /**
  196. * Sets widths at each line point
  197. * @param widths width table [widthLower, widthUpper, widthLower, widthUpper ...]
  198. */
  199. set widths(widths: number[]);
  200. /**
  201. * Gets the color pointer. Each vertex need a color pointer. These color pointers points to the colors in the color table @see colors
  202. */
  203. get colorPointers(): number[];
  204. /**
  205. * Sets the color pointer
  206. * @param colorPointers array of color pointer in the colors array. One pointer for every vertex is needed.
  207. */
  208. set colorPointers(colorPointers: number[]);
  209. /**
  210. * Gets the pluginMaterial associated with line
  211. */
  212. get greasedLineMaterial(): IGreasedLineMaterial | undefined;
  213. /**
  214. * Return copy the points.
  215. */
  216. get points(): number[][];
  217. /**
  218. * Sets line points and rerenders the line.
  219. * @param points points table
  220. * @param options optional options
  221. */
  222. setPoints(points: number[][], options?: GreasedLineMeshOptions): void;
  223. protected _initGreasedLine(): void;
  224. protected _createLineOptions(): GreasedLineMeshOptions;
  225. /**
  226. * Serializes this GreasedLineMesh
  227. * @param serializationObject object to write serialization to
  228. */
  229. serialize(serializationObject: any): void;
  230. protected _createVertexBuffers(computeNormals?: boolean): VertexData;
  231. protected _createOffsetsBuffer(offsets: number[]): void;
  232. }