subMesh.d.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import type { Nullable, IndicesArray, DeepImmutable, FloatArray } from "../types";
  2. import type { Matrix, Vector3 } from "../Maths/math.vector";
  3. import { IntersectionInfo } from "../Collisions/intersectionInfo";
  4. import type { ICullable } from "../Culling/boundingInfo";
  5. import { BoundingInfo } from "../Culling/boundingInfo";
  6. import type { Effect } from "../Materials/effect";
  7. import type { DataBuffer } from "../Buffers/dataBuffer";
  8. import type { Plane } from "../Maths/math.plane";
  9. import { DrawWrapper } from "../Materials/drawWrapper";
  10. import type { IMaterialContext } from "../Engines/IMaterialContext";
  11. import type { Collider } from "../Collisions/collider";
  12. import type { Material } from "../Materials/material";
  13. import type { MaterialDefines } from "../Materials/materialDefines";
  14. import type { AbstractMesh } from "./abstractMesh";
  15. import type { Mesh } from "./mesh";
  16. import type { Ray } from "../Culling/ray";
  17. import type { TrianglePickingPredicate } from "../Culling/ray";
  18. import type { AbstractEngine } from "../Engines/abstractEngine.js";
  19. /**
  20. * Defines a subdivision inside a mesh
  21. */
  22. export declare class SubMesh implements ICullable {
  23. /** the material index to use */
  24. materialIndex: number;
  25. /** vertex index start */
  26. verticesStart: number;
  27. /** vertices count */
  28. verticesCount: number;
  29. /** index start */
  30. indexStart: number;
  31. /** indices count */
  32. indexCount: number;
  33. private _engine;
  34. /** @internal */
  35. _drawWrappers: Array<DrawWrapper>;
  36. private _mainDrawWrapperOverride;
  37. /**
  38. * Gets material defines used by the effect associated to the sub mesh
  39. */
  40. get materialDefines(): Nullable<MaterialDefines>;
  41. /**
  42. * Sets material defines used by the effect associated to the sub mesh
  43. */
  44. set materialDefines(defines: Nullable<MaterialDefines>);
  45. /**
  46. * @internal
  47. */
  48. _getDrawWrapper(passId?: number, createIfNotExisting?: boolean): DrawWrapper | undefined;
  49. /**
  50. * @internal
  51. */
  52. _removeDrawWrapper(passId: number, disposeWrapper?: boolean): void;
  53. /**
  54. * Gets associated (main) effect (possibly the effect override if defined)
  55. */
  56. get effect(): Nullable<Effect>;
  57. /** @internal */
  58. get _drawWrapper(): DrawWrapper;
  59. /** @internal */
  60. get _drawWrapperOverride(): Nullable<DrawWrapper>;
  61. /**
  62. * @internal
  63. */
  64. _setMainDrawWrapperOverride(wrapper: Nullable<DrawWrapper>): void;
  65. /**
  66. * Sets associated effect (effect used to render this submesh)
  67. * @param effect defines the effect to associate with
  68. * @param defines defines the set of defines used to compile this effect
  69. * @param materialContext material context associated to the effect
  70. * @param resetContext true to reset the draw context
  71. */
  72. setEffect(effect: Nullable<Effect>, defines?: Nullable<string | MaterialDefines>, materialContext?: IMaterialContext, resetContext?: boolean): void;
  73. /**
  74. * Resets the draw wrappers cache
  75. * @param passId If provided, releases only the draw wrapper corresponding to this render pass id
  76. */
  77. resetDrawCache(passId?: number): void;
  78. /** @internal */
  79. _linesIndexCount: number;
  80. private _mesh;
  81. private _renderingMesh;
  82. private _boundingInfo;
  83. private _linesIndexBuffer;
  84. /** @internal */
  85. _lastColliderWorldVertices: Nullable<Vector3[]>;
  86. /** @internal */
  87. _trianglePlanes: Plane[];
  88. /** @internal */
  89. _lastColliderTransformMatrix: Nullable<Matrix>;
  90. /** @internal */
  91. _wasDispatched: boolean;
  92. /** @internal */
  93. _renderId: number;
  94. /** @internal */
  95. _alphaIndex: number;
  96. /** @internal */
  97. _distanceToCamera: number;
  98. /** @internal */
  99. _id: number;
  100. private _currentMaterial;
  101. /**
  102. * Add a new submesh to a mesh
  103. * @param materialIndex defines the material index to use
  104. * @param verticesStart defines vertex index start
  105. * @param verticesCount defines vertices count
  106. * @param indexStart defines index start
  107. * @param indexCount defines indices count
  108. * @param mesh defines the parent mesh
  109. * @param renderingMesh defines an optional rendering mesh
  110. * @param createBoundingBox defines if bounding box should be created for this submesh
  111. * @returns the new submesh
  112. */
  113. static AddToMesh(materialIndex: number, verticesStart: number, verticesCount: number, indexStart: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox?: boolean): SubMesh;
  114. /**
  115. * Creates a new submesh
  116. * @param materialIndex defines the material index to use
  117. * @param verticesStart defines vertex index start
  118. * @param verticesCount defines vertices count
  119. * @param indexStart defines index start
  120. * @param indexCount defines indices count
  121. * @param mesh defines the parent mesh
  122. * @param renderingMesh defines an optional rendering mesh
  123. * @param createBoundingBox defines if bounding box should be created for this submesh
  124. * @param addToMesh defines a boolean indicating that the submesh must be added to the mesh.subMeshes array (true by default)
  125. */
  126. constructor(
  127. /** the material index to use */
  128. materialIndex: number,
  129. /** vertex index start */
  130. verticesStart: number,
  131. /** vertices count */
  132. verticesCount: number,
  133. /** index start */
  134. indexStart: number,
  135. /** indices count */
  136. indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox?: boolean, addToMesh?: boolean);
  137. /**
  138. * Returns true if this submesh covers the entire parent mesh
  139. * @ignorenaming
  140. */
  141. get IsGlobal(): boolean;
  142. /**
  143. * Returns the submesh BoundingInfo object
  144. * @returns current bounding info (or mesh's one if the submesh is global)
  145. */
  146. getBoundingInfo(): BoundingInfo;
  147. /**
  148. * Sets the submesh BoundingInfo
  149. * @param boundingInfo defines the new bounding info to use
  150. * @returns the SubMesh
  151. */
  152. setBoundingInfo(boundingInfo: BoundingInfo): SubMesh;
  153. /**
  154. * Returns the mesh of the current submesh
  155. * @returns the parent mesh
  156. */
  157. getMesh(): AbstractMesh;
  158. /**
  159. * Returns the rendering mesh of the submesh
  160. * @returns the rendering mesh (could be different from parent mesh)
  161. */
  162. getRenderingMesh(): Mesh;
  163. /**
  164. * Returns the replacement mesh of the submesh
  165. * @returns the replacement mesh (could be different from parent mesh)
  166. */
  167. getReplacementMesh(): Nullable<AbstractMesh>;
  168. /**
  169. * Returns the effective mesh of the submesh
  170. * @returns the effective mesh (could be different from parent mesh)
  171. */
  172. getEffectiveMesh(): AbstractMesh;
  173. /**
  174. * Returns the submesh material
  175. * @param getDefaultMaterial Defines whether or not to get the default material if nothing has been defined.
  176. * @returns null or the current material
  177. */
  178. getMaterial(getDefaultMaterial?: boolean): Nullable<Material>;
  179. private _isMultiMaterial;
  180. /**
  181. * Sets a new updated BoundingInfo object to the submesh
  182. * @param data defines an optional position array to use to determine the bounding info
  183. * @returns the SubMesh
  184. */
  185. refreshBoundingInfo(data?: Nullable<FloatArray>): SubMesh;
  186. /**
  187. * @internal
  188. */
  189. _checkCollision(collider: Collider): boolean;
  190. /**
  191. * Updates the submesh BoundingInfo
  192. * @param world defines the world matrix to use to update the bounding info
  193. * @returns the submesh
  194. */
  195. updateBoundingInfo(world: DeepImmutable<Matrix>): SubMesh;
  196. /**
  197. * True is the submesh bounding box intersects the frustum defined by the passed array of planes.
  198. * @param frustumPlanes defines the frustum planes
  199. * @returns true if the submesh is intersecting with the frustum
  200. */
  201. isInFrustum(frustumPlanes: Plane[]): boolean;
  202. /**
  203. * True is the submesh bounding box is completely inside the frustum defined by the passed array of planes
  204. * @param frustumPlanes defines the frustum planes
  205. * @returns true if the submesh is inside the frustum
  206. */
  207. isCompletelyInFrustum(frustumPlanes: Plane[]): boolean;
  208. /**
  209. * Renders the submesh
  210. * @param enableAlphaMode defines if alpha needs to be used
  211. * @returns the submesh
  212. */
  213. render(enableAlphaMode: boolean): SubMesh;
  214. /**
  215. * @internal
  216. */
  217. _getLinesIndexBuffer(indices: IndicesArray, engine: AbstractEngine): DataBuffer;
  218. /**
  219. * Checks if the submesh intersects with a ray
  220. * @param ray defines the ray to test
  221. * @returns true is the passed ray intersects the submesh bounding box
  222. */
  223. canIntersects(ray: Ray): boolean;
  224. /**
  225. * Intersects current submesh with a ray
  226. * @param ray defines the ray to test
  227. * @param positions defines mesh's positions array
  228. * @param indices defines mesh's indices array
  229. * @param fastCheck defines if the first intersection will be used (and not the closest)
  230. * @param trianglePredicate defines an optional predicate used to select faces when a mesh intersection is detected
  231. * @returns intersection info or null if no intersection
  232. */
  233. intersects(ray: Ray, positions: Vector3[], indices: IndicesArray, fastCheck?: boolean, trianglePredicate?: TrianglePickingPredicate): Nullable<IntersectionInfo>;
  234. /**
  235. * @internal
  236. */
  237. private _intersectLines;
  238. /**
  239. * @internal
  240. */
  241. private _intersectUnIndexedLines;
  242. /**
  243. * @internal
  244. */
  245. private _intersectTriangles;
  246. /**
  247. * @internal
  248. */
  249. private _intersectUnIndexedTriangles;
  250. /** @internal */
  251. _rebuild(): void;
  252. /**
  253. * Creates a new submesh from the passed mesh
  254. * @param newMesh defines the new hosting mesh
  255. * @param newRenderingMesh defines an optional rendering mesh
  256. * @returns the new submesh
  257. */
  258. clone(newMesh: AbstractMesh, newRenderingMesh?: Mesh): SubMesh;
  259. /**
  260. * Release associated resources
  261. */
  262. dispose(): void;
  263. /**
  264. * Gets the class name
  265. * @returns the string "SubMesh".
  266. */
  267. getClassName(): string;
  268. /**
  269. * Creates a new submesh from indices data
  270. * @param materialIndex the index of the main mesh material
  271. * @param startIndex the index where to start the copy in the mesh indices array
  272. * @param indexCount the number of indices to copy then from the startIndex
  273. * @param mesh the main mesh to create the submesh from
  274. * @param renderingMesh the optional rendering mesh
  275. * @param createBoundingBox defines if bounding box should be created for this submesh
  276. * @returns a new submesh
  277. */
  278. static CreateFromIndices(materialIndex: number, startIndex: number, indexCount: number, mesh: AbstractMesh, renderingMesh?: Mesh, createBoundingBox?: boolean): SubMesh;
  279. }