meshDebugPluginMaterial.d.ts 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import { MaterialPluginBase } from "./materialPluginBase";
  2. import type { Scene } from "../scene";
  3. import type { UniformBuffer } from "./uniformBuffer";
  4. import type { Nullable } from "../types";
  5. import { MaterialDefines } from "./materialDefines";
  6. import type { PBRBaseMaterial } from "./PBR/pbrBaseMaterial";
  7. import type { StandardMaterial } from "./standardMaterial";
  8. import { Color3 } from "../Maths/math.js";
  9. import type { Mesh } from "../Meshes/mesh.js";
  10. import type { AbstractMesh } from "../Meshes/abstractMesh.js";
  11. /**
  12. * Supported visualizations of MeshDebugPluginMaterial
  13. */
  14. export declare enum MeshDebugMode {
  15. /**
  16. * Material without any mesh debug visualization
  17. */
  18. NONE = 0,
  19. /**
  20. * A wireframe of the mesh
  21. * NOTE: For this mode to work correctly, convertToUnIndexedMesh() or MeshDebugPluginMaterial.PrepareMeshForTrianglesAndVerticesMode() must first be called on mesh.
  22. */
  23. TRIANGLES = 1,
  24. /**
  25. * Points drawn over vertices of mesh
  26. * NOTE: For this mode to work correctly, MeshDebugPluginMaterial.PrepareMeshForTrianglesAndVerticesMode() must first be called on mesh.
  27. */
  28. VERTICES = 2,
  29. /**
  30. * A wireframe of the mesh, with points drawn over vertices
  31. * NOTE: For this mode to work correctly, MeshDebugPluginMaterial.PrepareMeshForTrianglesAndVerticesMode() must first be called on mesh.
  32. */
  33. TRIANGLES_VERTICES = 3,
  34. /**
  35. * A checkerboard grid of the mesh's UV set 0
  36. */
  37. UV0 = 4,
  38. /**
  39. * A checkerboard grid of the mesh's UV set 1
  40. */
  41. UV1 = 5,
  42. /**
  43. * The mesh's vertex colors displayed as the primary texture
  44. */
  45. VERTEXCOLORS = 6,
  46. /**
  47. * An arbitrary, distinguishable color to identify the material
  48. */
  49. MATERIALIDS = 7
  50. }
  51. /**
  52. * Options for MeshDebugPluginMaterial visualizations
  53. */
  54. export interface MeshDebugOptions {
  55. /**
  56. * The mesh debug visualization.
  57. * Defaults to NONE.
  58. */
  59. mode?: MeshDebugMode;
  60. /**
  61. * Whether the mesh debug visualization should multiply with color underneath.
  62. * Defaults to true.
  63. */
  64. multiply?: boolean;
  65. /**
  66. * Diffuse color used to shade the mesh.
  67. * Defaults to (1.0, 1.0, 1.0).
  68. */
  69. shadedDiffuseColor?: Color3;
  70. /**
  71. * Specular color used to shade the mesh.
  72. * Defaults to (0.8, 0.8, 0.8).
  73. */
  74. shadedSpecularColor?: Color3;
  75. /**
  76. * Specular power used to shade the mesh.
  77. * Defaults to 10.
  78. */
  79. shadedSpecularPower?: number;
  80. /**
  81. * Width of edge lines in TRIANGLES and TRIANGLE_VERTICES modes.
  82. * Defaults to 0.7.
  83. */
  84. wireframeThickness?: number;
  85. /**
  86. * Color of edge lines in TRIANGLES mode.
  87. * Defaults to (0.0, 0.0, 0.0).
  88. */
  89. wireframeTrianglesColor?: Color3;
  90. /**
  91. * Color of edge lines in TRIANGLES_VERTICES modes.
  92. * Defaults to (0.8, 0.8, 0.8).
  93. */
  94. wireframeVerticesColor?: Color3;
  95. /**
  96. * Color of vertices in TRIANGLES_VERTICES and VERTICES mode.
  97. * Defaults to (0.0, 0.0, 0.0).
  98. */
  99. vertexColor?: Color3;
  100. /**
  101. * Radius of dots drawn over vertices in TRIANGLE_VERTICES and VERTICES mode.
  102. * Defaults to 1.2.
  103. */
  104. vertexRadius?: number;
  105. /**
  106. * Size of tiles in UV1 or UV2 modes.
  107. * Defaults to 20.
  108. */
  109. uvScale?: number;
  110. /**
  111. * 1st color of checkerboard grid in UV1 or UV2 modes.
  112. * Defaults to (1.0, 1.0, 1.0).
  113. */
  114. uvPrimaryColor?: Color3;
  115. /**
  116. * 2nd color of checkerboard grid in UV1 or UV2 modes.
  117. * Defaults to (0.5, 0.5, 0.5).
  118. */
  119. uvSecondaryColor?: Color3;
  120. }
  121. /** @internal */
  122. declare class MeshDebugDefines extends MaterialDefines {
  123. /**
  124. * Current mesh debug visualization.
  125. * Defaults to NONE.
  126. */
  127. DBG_MODE: MeshDebugMode;
  128. /**
  129. * Whether the mesh debug visualization multiplies with colors underneath.
  130. * Defaults to true.
  131. */
  132. DBG_MULTIPLY: boolean;
  133. /**
  134. * Whether the mesh debug plugin is enabled in the material.
  135. * Defaults to true.
  136. */
  137. DBG_ENABLED: boolean;
  138. }
  139. /**
  140. * Plugin that implements various mesh debug visualizations,
  141. * List of available visualizations can be found in MeshDebugMode enum.
  142. */
  143. export declare class MeshDebugPluginMaterial extends MaterialPluginBase {
  144. /**
  145. * Total number of instances of the plugin.
  146. * Starts at 0.
  147. */
  148. private static _PluginCount;
  149. /**
  150. * Color palette used for MATERIALIDS mode.
  151. * Defaults to `defaultMaterialColors`
  152. */
  153. static MaterialColors: Color3[];
  154. /**
  155. * Material ID color of this plugin instance.
  156. * Taken from index `_PluginCount` of `MaterialColors` at time of instantiation.
  157. */
  158. private _materialColor;
  159. /**
  160. * Whether the mesh debug plugin is enabled in the material.
  161. * Defaults to true in constructor.
  162. */
  163. private _isEnabled;
  164. private _mode;
  165. /**
  166. * The mesh debug visualization.
  167. * Defaults to NONE.
  168. */
  169. mode: MeshDebugMode;
  170. private _multiply;
  171. /**
  172. * Whether the mesh debug visualization should multiply with color underneath.
  173. * Defaults to true.
  174. */
  175. multiply: boolean;
  176. /**
  177. * Diffuse color used to shade the mesh.
  178. * Defaults to (1.0, 1.0, 1.0).
  179. */
  180. shadedDiffuseColor: Color3;
  181. /**
  182. * Specular color used to shade the mesh.
  183. * Defaults to (0.8, 0.8, 0.8).
  184. */
  185. shadedSpecularColor: Color3;
  186. /**
  187. * Specular power used to shade the mesh.
  188. * Defaults to 10.
  189. */
  190. shadedSpecularPower: number;
  191. /**
  192. * Width of edge lines in TRIANGLES and TRIANGLE_VERTICES modes.
  193. * Defaults to 0.7.
  194. */
  195. wireframeThickness: number;
  196. /**
  197. * Color of edge lines in TRIANGLES mode.
  198. * Defaults to (0.0, 0.0, 0.0).
  199. */
  200. wireframeTrianglesColor: Color3;
  201. /**
  202. * Color of edge lines in TRIANGLES_VERTICES modes.
  203. * Defaults to (0.8, 0.8, 0.8).
  204. */
  205. wireframeVerticesColor: Color3;
  206. /**
  207. * Color of vertices in TRIANGLES_VERTICES and VERTICES mode.
  208. * Defaults to (0.0, 0.0, 0.0).
  209. */
  210. vertexColor: Color3;
  211. /**
  212. * Radius of dots drawn over vertices in TRIANGLE_VERTICES and VERTICES mode.
  213. * Defaults to 1.2.
  214. */
  215. vertexRadius: number;
  216. /**
  217. * Size of tiles in UV1 or UV2 modes.
  218. * Defaults to 20.
  219. */
  220. uvScale: number;
  221. /**
  222. * 1st color of checkerboard grid in UV1 or UV2 modes.
  223. * Defaults to (1.0, 1.0, 1.0).
  224. */
  225. uvPrimaryColor: Color3;
  226. /**
  227. * 2nd color of checkerboard grid in UV1 or UV2 modes.
  228. * Defaults to (0.5, 0.5, 0.5).
  229. */
  230. uvSecondaryColor: Color3;
  231. /** @internal */
  232. protected _markAllDefinesAsDirty(): void;
  233. /**
  234. * Creates a new MeshDebugPluginMaterial
  235. * @param material Material to attach the mesh debug plugin to
  236. * @param options Options for the mesh debug plugin
  237. */
  238. constructor(material: PBRBaseMaterial | StandardMaterial, options?: MeshDebugOptions);
  239. /**
  240. * Get the class name
  241. * @returns Class name
  242. */
  243. getClassName(): string;
  244. /**
  245. * Gets whether the mesh debug plugin is enabled in the material.
  246. */
  247. get isEnabled(): boolean;
  248. /**
  249. * Sets whether the mesh debug plugin is enabled in the material.
  250. * @param value enabled
  251. */
  252. set isEnabled(value: boolean);
  253. /**
  254. * Prepare the defines
  255. * @param defines Mesh debug defines
  256. * @param scene Scene
  257. * @param mesh Mesh associated with material
  258. */
  259. prepareDefines(defines: MeshDebugDefines, scene: Scene, mesh: AbstractMesh): void;
  260. /**
  261. * Get the shader attributes
  262. * @param attributes Array of attributes
  263. */
  264. getAttributes(attributes: string[]): void;
  265. /**
  266. * Get the shader uniforms
  267. * @returns Uniforms
  268. */
  269. getUniforms(): {
  270. ubo: {
  271. name: string;
  272. size: number;
  273. type: string;
  274. }[];
  275. fragment: string;
  276. };
  277. /**
  278. * Bind the uniform buffer
  279. * @param uniformBuffer Uniform buffer
  280. */
  281. bindForSubMesh(uniformBuffer: UniformBuffer): void;
  282. /**
  283. * Get shader code
  284. * @param shaderType "vertex" or "fragment"
  285. * @returns Shader code
  286. */
  287. getCustomCode(shaderType: string): Nullable<{
  288. [pointName: string]: string;
  289. }>;
  290. /**
  291. * Resets static variables of the plugin to their original state
  292. */
  293. static Reset(): void;
  294. /**
  295. * Renders triangles in a mesh 3 times by tripling the indices in the index buffer.
  296. * Used to prepare a mesh to be rendered in `TRIANGLES`, `VERTICES`, or `TRIANGLES_VERTICES` modes.
  297. * NOTE: This is a destructive operation. The mesh's index buffer and vertex buffers are modified, and a new vertex buffer is allocated.
  298. * If you'd like the ability to revert these changes, toggle the optional `returnRollback` flag.
  299. * @param mesh the mesh to target
  300. * @param returnRollback whether or not to return a function that reverts mesh to its initial state. Default: false.
  301. * @returns a rollback function if `returnRollback` is true, otherwise an empty function.
  302. */
  303. static PrepareMeshForTrianglesAndVerticesMode(mesh: Mesh, returnRollback?: boolean): () => void;
  304. }
  305. export {};