groundBuilder.d.ts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import type { Scene } from "../../scene";
  2. import { Color3 } from "../../Maths/math.color";
  3. import { Mesh } from "../mesh";
  4. import { VertexData } from "../mesh.vertexData";
  5. import { GroundMesh } from "../groundMesh";
  6. import type { Nullable } from "../../types";
  7. /**
  8. * Creates the VertexData for a Ground
  9. * @param options an object used to set the following optional parameters for the Ground, required but can be empty
  10. * @param options.width the width (x direction) of the ground, optional, default 1
  11. * @param options.height the height (z direction) of the ground, optional, default 1
  12. * @param options.subdivisions the number of subdivisions per side, optional, default 1
  13. * @param options.subdivisionsX the number of subdivisions in the x direction, overrides options.subdivisions, optional, default undefined
  14. * @param options.subdivisionsY the number of subdivisions in the y direction, overrides options.subdivisions, optional, default undefined
  15. * @returns the VertexData of the Ground
  16. */
  17. export declare function CreateGroundVertexData(options: {
  18. width?: number;
  19. height?: number;
  20. subdivisions?: number;
  21. subdivisionsX?: number;
  22. subdivisionsY?: number;
  23. }): VertexData;
  24. /**
  25. * Creates the VertexData for a TiledGround by subdividing the ground into tiles
  26. * @param options an object used to set the following optional parameters for the Ground
  27. * @param options.xmin ground minimum X coordinate, default -1
  28. * @param options.zmin ground minimum Z coordinate, default -1
  29. * @param options.xmax ground maximum X coordinate, default 1
  30. * @param options.zmax ground maximum Z coordinate, default 1
  31. * @param options.subdivisions a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the ground width and height creating 'tiles', default {w: 6, h: 6}
  32. * @param options.subdivisions.w positive integer, default 6
  33. * @param options.subdivisions.h positive integer, default 6
  34. * @param options.precision a javascript object {w: positive integer, h: positive integer}, `w` and `h` are the numbers of subdivisions on the tile width and height, default {w: 2, h: 2}
  35. * @param options.precision.w positive integer, default 2
  36. * @param options.precision.h positive integer, default 2
  37. * @returns the VertexData of the TiledGround
  38. */
  39. export declare function CreateTiledGroundVertexData(options: {
  40. xmin: number;
  41. zmin: number;
  42. xmax: number;
  43. zmax: number;
  44. subdivisions?: {
  45. w: number;
  46. h: number;
  47. };
  48. precision?: {
  49. w: number;
  50. h: number;
  51. };
  52. }): VertexData;
  53. /**
  54. * Creates the VertexData of the Ground designed from a heightmap
  55. * @param options an object used to set the following parameters for the Ground, required and provided by CreateGroundFromHeightMap
  56. * @param options.width the width (x direction) of the ground
  57. * @param options.height the height (z direction) of the ground
  58. * @param options.subdivisions the number of subdivisions per side
  59. * @param options.minHeight the minimum altitude on the ground, optional, default 0
  60. * @param options.maxHeight the maximum altitude on the ground, optional default 1
  61. * @param options.colorFilter the filter to apply to the image pixel colors to compute the height, optional Color3, default (0.3, 0.59, 0.11)
  62. * @param options.buffer the array holding the image color data
  63. * @param options.bufferWidth the width of image
  64. * @param options.bufferHeight the height of image
  65. * @param options.alphaFilter Remove any data where the alpha channel is below this value, defaults 0 (all data visible)
  66. * @param options.heightBuffer a array of floats where the height data can be saved, if its length is greater than zero.
  67. * @returns the VertexData of the Ground designed from a heightmap
  68. */
  69. export declare function CreateGroundFromHeightMapVertexData(options: {
  70. width: number;
  71. height: number;
  72. subdivisions: number;
  73. minHeight: number;
  74. maxHeight: number;
  75. colorFilter: Color3;
  76. buffer: Uint8Array;
  77. bufferWidth: number;
  78. bufferHeight: number;
  79. alphaFilter: number;
  80. heightBuffer?: Float32Array;
  81. }): VertexData;
  82. /**
  83. * Creates a ground mesh
  84. * @param name defines the name of the mesh
  85. * @param options defines the options used to create the mesh
  86. * @param options.width set the width size (float, default 1)
  87. * @param options.height set the height size (float, default 1)
  88. * @param options.subdivisions sets the number of subdivision per side (default 1)
  89. * @param options.subdivisionsX sets the number of subdivision on the X axis (overrides subdivisions)
  90. * @param options.subdivisionsY sets the number of subdivision on the Y axis (overrides subdivisions)
  91. * @param options.updatable defines if the mesh must be flagged as updatable (default false)
  92. * @param scene defines the hosting scene
  93. * @returns the ground mesh
  94. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#ground
  95. */
  96. export declare function CreateGround(name: string, options?: {
  97. width?: number;
  98. height?: number;
  99. subdivisions?: number;
  100. subdivisionsX?: number;
  101. subdivisionsY?: number;
  102. updatable?: boolean;
  103. }, scene?: Scene): GroundMesh;
  104. /**
  105. * Creates a tiled ground mesh
  106. * @param name defines the name of the mesh
  107. * @param options defines the options used to create the mesh
  108. * @param options.xmin ground minimum X coordinate (float, default -1)
  109. * @param options.zmin ground minimum Z coordinate (float, default -1)
  110. * @param options.xmax ground maximum X coordinate (float, default 1)
  111. * @param options.zmax ground maximum Z coordinate (float, default 1)
  112. * @param options.subdivisions a javascript object `{w: positive integer, h: positive integer}` (default `{w: 6, h: 6}`). `w` and `h` are the numbers of subdivisions on the ground width and height. Each subdivision is called a tile
  113. * @param options.subdivisions.w positive integer, default 6
  114. * @param options.subdivisions.h positive integer, default 6
  115. * @param options.precision a javascript object `{w: positive integer, h: positive integer}` (default `{w: 2, h: 2}`). `w` and `h` are the numbers of subdivisions on the ground width and height of each tile
  116. * @param options.precision.w positive integer, default 2
  117. * @param options.precision.h positive integer, default 2
  118. * @param options.updatable boolean, default false, true if the mesh must be flagged as updatable
  119. * @param scene defines the hosting scene
  120. * @returns the tiled ground mesh
  121. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#tiled-ground
  122. */
  123. export declare function CreateTiledGround(name: string, options: {
  124. xmin: number;
  125. zmin: number;
  126. xmax: number;
  127. zmax: number;
  128. subdivisions?: {
  129. w: number;
  130. h: number;
  131. };
  132. precision?: {
  133. w: number;
  134. h: number;
  135. };
  136. updatable?: boolean;
  137. }, scene?: Nullable<Scene>): Mesh;
  138. /**
  139. * Creates a ground mesh from a height map. The height map download can take some frames,
  140. * so the mesh is not immediately ready. To wait for the mesh to be completely built,
  141. * you should use the `onReady` callback option.
  142. * @param name defines the name of the mesh
  143. * @param url sets the URL of the height map image resource.
  144. * @param options defines the options used to create the mesh
  145. * @param options.width sets the ground width size (positive float, default 10)
  146. * @param options.height sets the ground height size (positive float, default 10)
  147. * @param options.subdivisions sets the number of subdivision per side (positive integer, default 1)
  148. * @param options.minHeight is the minimum altitude on the ground (float, default 0)
  149. * @param options.maxHeight is the maximum altitude on the ground (float, default 1)
  150. * @param options.colorFilter is the filter to apply to the image pixel colors to compute the height (optional Color3, default (0.3, 0.59, 0.11) )
  151. * @param options.alphaFilter will filter any data where the alpha channel is below this value, defaults 0 (all data visible)
  152. * @param options.updatable defines if the mesh must be flagged as updatable
  153. * @param options.onReady is a javascript callback function that will be called once the mesh is just built (the height map download can last some time)
  154. * @param options.onError is a javascript callback function that will be called if there is an error
  155. * @param options.passHeightBufferInCallback a boolean that indicates if the calculated height data will be passed in the onReady callback. Useful if you need the height data for physics, for example.
  156. * @param scene defines the hosting scene
  157. * @returns the ground mesh
  158. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set/height_map
  159. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#ground-from-a-height-map
  160. */
  161. export declare function CreateGroundFromHeightMap(name: string, url: string | {
  162. data: Uint8Array;
  163. width: number;
  164. height: number;
  165. }, options?: {
  166. width?: number;
  167. height?: number;
  168. subdivisions?: number;
  169. minHeight?: number;
  170. maxHeight?: number;
  171. colorFilter?: Color3;
  172. alphaFilter?: number;
  173. updatable?: boolean;
  174. onReady?: (mesh: GroundMesh, heightBuffer?: Float32Array) => void;
  175. onError?: (message?: string, exception?: any) => void;
  176. passHeightBufferInCallback?: boolean;
  177. }, scene?: Nullable<Scene>): GroundMesh;
  178. /**
  179. * Class containing static functions to help procedurally build meshes
  180. * @deprecated use the functions directly from the module
  181. */
  182. export declare const GroundBuilder: {
  183. CreateGround: typeof CreateGround;
  184. CreateGroundFromHeightMap: typeof CreateGroundFromHeightMap;
  185. CreateTiledGround: typeof CreateTiledGround;
  186. };