nodeGeometry.d.ts 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. import { Observable } from "../../Misc/observable";
  2. import type { Nullable } from "../../types";
  3. import { Mesh } from "../mesh";
  4. import type { Scene } from "../../scene";
  5. import { GeometryOutputBlock } from "./Blocks/geometryOutputBlock";
  6. import type { NodeGeometryBlock } from "./nodeGeometryBlock";
  7. import type { GeometryInputBlock } from "./Blocks/geometryInputBlock";
  8. import type { Color4 } from "../../Maths/math.color";
  9. /**
  10. * Interface used to configure the node geometry editor
  11. */
  12. export interface INodeGeometryEditorOptions {
  13. /** Define the URL to load node editor script from */
  14. editorURL?: string;
  15. /** Additional configuration for the NGE */
  16. nodeGeometryEditorConfig?: {
  17. backgroundColor?: Color4;
  18. hostScene?: Scene;
  19. hostMesh?: Mesh;
  20. };
  21. }
  22. /**
  23. * Defines a node based geometry
  24. * @see demo at https://playground.babylonjs.com#PYY6XE#69
  25. */
  26. export declare class NodeGeometry {
  27. private static _BuildIdGenerator;
  28. private _buildId;
  29. private _buildWasSuccessful;
  30. private _vertexData;
  31. private _buildExecutionTime;
  32. /** Define the Url to load node editor script */
  33. static EditorURL: string;
  34. /** Define the Url to load snippets */
  35. static SnippetUrl: string;
  36. private BJSNODEGEOMETRYEDITOR;
  37. /** @returns the inspector from bundle or global */
  38. private _getGlobalNodeGeometryEditor;
  39. /**
  40. * Gets the time spent to build this block (in ms)
  41. */
  42. get buildExecutionTime(): number;
  43. /**
  44. * Gets or sets data used by visual editor
  45. * @see https://nge.babylonjs.com
  46. */
  47. editorData: any;
  48. /**
  49. * Gets an array of blocks that needs to be serialized even if they are not yet connected
  50. */
  51. attachedBlocks: NodeGeometryBlock[];
  52. /**
  53. * Observable raised when the geometry is built
  54. */
  55. onBuildObservable: Observable<NodeGeometry>;
  56. /** Gets or sets the GeometryOutputBlock used to gather the final geometry data */
  57. outputBlock: Nullable<GeometryOutputBlock>;
  58. /**
  59. * Snippet ID if the material was created from the snippet server
  60. */
  61. snippetId: string;
  62. /**
  63. * The name of the geometry
  64. */
  65. name: string;
  66. /**
  67. * A free comment about the geometry
  68. */
  69. comment: string;
  70. /**
  71. * Creates a new geometry
  72. * @param name defines the name of the geometry
  73. */
  74. constructor(name: string);
  75. /**
  76. * Gets the current class name of the geometry e.g. "NodeGeometry"
  77. * @returns the class name
  78. */
  79. getClassName(): string;
  80. /**
  81. * Get a block by its name
  82. * @param name defines the name of the block to retrieve
  83. * @returns the required block or null if not found
  84. */
  85. getBlockByName(name: string): NodeGeometryBlock | null;
  86. /**
  87. * Get a block using a predicate
  88. * @param predicate defines the predicate used to find the good candidate
  89. * @returns the required block or null if not found
  90. */
  91. getBlockByPredicate(predicate: (block: NodeGeometryBlock) => boolean): NodeGeometryBlock | null;
  92. /**
  93. * Gets the list of input blocks attached to this material
  94. * @returns an array of InputBlocks
  95. */
  96. getInputBlocks(): GeometryInputBlock[];
  97. /**
  98. * Launch the node geometry editor
  99. * @param config Define the configuration of the editor
  100. * @returns a promise fulfilled when the node editor is visible
  101. */
  102. edit(config?: INodeGeometryEditorOptions): Promise<void>;
  103. /**
  104. * Creates the node editor window.
  105. * @param additionalConfig Additional configuration for the NGE
  106. */
  107. private _createNodeEditor;
  108. /**
  109. * Build the final geometry
  110. * @param verbose defines if the build should log activity
  111. * @param updateBuildId defines if the internal build Id should be updated (default is true)
  112. * @param autoConfigure defines if the autoConfigure method should be called when initializing blocks (default is false)
  113. */
  114. build(verbose?: boolean, updateBuildId?: boolean, autoConfigure?: boolean): void;
  115. /**
  116. * Creates a mesh from the geometry blocks
  117. * @param name defines the name of the mesh
  118. * @param scene The scene the mesh is scoped to
  119. * @returns The new mesh
  120. */
  121. createMesh(name: string, scene?: Nullable<Scene>): Nullable<Mesh>;
  122. /**
  123. * Creates a mesh from the geometry blocks
  124. * @param mesh the mesh to update
  125. * @returns True if successfully updated
  126. */
  127. updateMesh(mesh: Mesh): false | Mesh;
  128. private _initializeBlock;
  129. /**
  130. * Clear the current geometry
  131. */
  132. clear(): void;
  133. /**
  134. * Remove a block from the current geometry
  135. * @param block defines the block to remove
  136. */
  137. removeBlock(block: NodeGeometryBlock): void;
  138. /**
  139. * Clear the current graph and load a new one from a serialization object
  140. * @param source defines the JSON representation of the geometry
  141. * @param merge defines whether or not the source must be merged or replace the current content
  142. */
  143. parseSerializedObject(source: any, merge?: boolean): void;
  144. private _restoreConnections;
  145. /**
  146. * Generate a string containing the code declaration required to create an equivalent of this geometry
  147. * @returns a string
  148. */
  149. generateCode(): string;
  150. private _gatherBlocks;
  151. /**
  152. * Clear the current geometry and set it to a default state
  153. */
  154. setToDefault(): void;
  155. /**
  156. * Makes a duplicate of the current geometry.
  157. * @param name defines the name to use for the new geometry
  158. * @returns the new geometry
  159. */
  160. clone(name: string): NodeGeometry;
  161. /**
  162. * Serializes this geometry in a JSON representation
  163. * @param selectedBlocks defines the list of blocks to save (if null the whole geometry will be saved)
  164. * @returns the serialized geometry object
  165. */
  166. serialize(selectedBlocks?: NodeGeometryBlock[]): any;
  167. /**
  168. * Disposes the ressources
  169. */
  170. dispose(): void;
  171. /**
  172. * Creates a new node geometry set to default basic configuration
  173. * @param name defines the name of the geometry
  174. * @returns a new NodeGeometry
  175. */
  176. static CreateDefault(name: string): NodeGeometry;
  177. /**
  178. * Creates a node geometry from parsed geometry data
  179. * @param source defines the JSON representation of the geometry
  180. * @returns a new node geometry
  181. */
  182. static Parse(source: any): NodeGeometry;
  183. /**
  184. * Creates a node geometry from a snippet saved by the node geometry editor
  185. * @param snippetId defines the snippet to load
  186. * @param nodeGeometry defines a node geometry to update (instead of creating a new one)
  187. * @param skipBuild defines whether to build the node geometry
  188. * @returns a promise that will resolve to the new node geometry
  189. */
  190. static ParseFromSnippetAsync(snippetId: string, nodeGeometry?: NodeGeometry, skipBuild?: boolean): Promise<NodeGeometry>;
  191. }