nodeGeometryBlock.d.ts 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import type { NodeGeometryBlockConnectionPointTypes } from "./Enums/nodeGeometryConnectionPointTypes";
  2. import { NodeGeometryConnectionPoint } from "./nodeGeometryBlockConnectionPoint";
  3. import type { NodeGeometryBuildState } from "./nodeGeometryBuildState";
  4. import { Observable } from "../../Misc/observable";
  5. import type { Nullable } from "../../types";
  6. /**
  7. * Defines a block that can be used inside a node based geometry
  8. */
  9. export declare class NodeGeometryBlock {
  10. private _name;
  11. private _buildId;
  12. protected _isInput: boolean;
  13. protected _isTeleportOut: boolean;
  14. protected _isTeleportIn: boolean;
  15. protected _isDebug: boolean;
  16. protected _isUnique: boolean;
  17. private _buildExecutionTime;
  18. /**
  19. * Gets an observable raised when the block is built
  20. */
  21. onBuildObservable: Observable<NodeGeometryBlock>;
  22. /** @internal */
  23. _inputs: NodeGeometryConnectionPoint[];
  24. /** @internal */
  25. _outputs: NodeGeometryConnectionPoint[];
  26. /** @internal */
  27. _preparationId: number;
  28. /** @internal */
  29. _codeVariableName: string;
  30. /**
  31. * Gets the time spent to build this block (in ms)
  32. */
  33. get buildExecutionTime(): number;
  34. /**
  35. * Gets the list of input points
  36. */
  37. get inputs(): NodeGeometryConnectionPoint[];
  38. /** Gets the list of output points */
  39. get outputs(): NodeGeometryConnectionPoint[];
  40. /**
  41. * Gets or sets the unique id of the node
  42. */
  43. uniqueId: number;
  44. /**
  45. * Gets or set the name of the block
  46. */
  47. get name(): string;
  48. set name(value: string);
  49. /**
  50. * Gets a boolean indicating if this block is an input
  51. */
  52. get isInput(): boolean;
  53. /**
  54. * Gets a boolean indicating if this block is a teleport out
  55. */
  56. get isTeleportOut(): boolean;
  57. /**
  58. * Gets a boolean indicating if this block is a teleport in
  59. */
  60. get isTeleportIn(): boolean;
  61. /**
  62. * Gets a boolean indicating if this block is a debug block
  63. */
  64. get isDebug(): boolean;
  65. /**
  66. * Gets a boolean indicating that this block can only be used once per NodeGeometry
  67. */
  68. get isUnique(): boolean;
  69. /**
  70. * A free comment about the block
  71. */
  72. comments: string;
  73. /** Gets or sets a boolean indicating that this input can be edited from a collapsed frame */
  74. visibleOnFrame: boolean;
  75. /**
  76. * Gets the current class name e.g. "NodeGeometryBlock"
  77. * @returns the class name
  78. */
  79. getClassName(): string;
  80. protected _inputRename(name: string): string;
  81. protected _outputRename(name: string): string;
  82. /**
  83. * Checks if the current block is an ancestor of a given block
  84. * @param block defines the potential descendant block to check
  85. * @returns true if block is a descendant
  86. */
  87. isAnAncestorOf(block: NodeGeometryBlock): boolean;
  88. /**
  89. * Checks if the current block is an ancestor of a given type
  90. * @param type defines the potential type to check
  91. * @returns true if block is a descendant
  92. */
  93. isAnAncestorOfType(type: string): boolean;
  94. /**
  95. * Get the first descendant using a predicate
  96. * @param predicate defines the predicate to check
  97. * @returns descendant or null if none found
  98. */
  99. getDescendantOfPredicate(predicate: (block: NodeGeometryBlock) => boolean): Nullable<NodeGeometryBlock>;
  100. /**
  101. * Creates a new NodeGeometryBlock
  102. * @param name defines the block name
  103. */
  104. constructor(name: string);
  105. /**
  106. * Register a new input. Must be called inside a block constructor
  107. * @param name defines the connection point name
  108. * @param type defines the connection point type
  109. * @param isOptional defines a boolean indicating that this input can be omitted
  110. * @param value value to return if there is no connection
  111. * @param valueMin min value accepted for value
  112. * @param valueMax max value accepted for value
  113. * @returns the current block
  114. */
  115. registerInput(name: string, type: NodeGeometryBlockConnectionPointTypes, isOptional?: boolean, value?: any, valueMin?: any, valueMax?: any): this;
  116. /**
  117. * Register a new output. Must be called inside a block constructor
  118. * @param name defines the connection point name
  119. * @param type defines the connection point type
  120. * @param point an already created connection point. If not provided, create a new one
  121. * @returns the current block
  122. */
  123. registerOutput(name: string, type: NodeGeometryBlockConnectionPointTypes, point?: NodeGeometryConnectionPoint): this;
  124. protected _buildBlock(state: NodeGeometryBuildState): void;
  125. protected _customBuildStep(state: NodeGeometryBuildState): void;
  126. /**
  127. * Build the current node and generate the vertex data
  128. * @param state defines the current generation state
  129. * @returns true if already built
  130. */
  131. build(state: NodeGeometryBuildState): boolean;
  132. protected _linkConnectionTypes(inputIndex0: number, inputIndex1: number, looseCoupling?: boolean): void;
  133. /**
  134. * Initialize the block and prepare the context for build
  135. */
  136. initialize(): void;
  137. /**
  138. * Lets the block try to connect some inputs automatically
  139. */
  140. autoConfigure(): void;
  141. /**
  142. * Find an input by its name
  143. * @param name defines the name of the input to look for
  144. * @returns the input or null if not found
  145. */
  146. getInputByName(name: string): NodeGeometryConnectionPoint | null;
  147. /**
  148. * Find an output by its name
  149. * @param name defines the name of the output to look for
  150. * @returns the output or null if not found
  151. */
  152. getOutputByName(name: string): NodeGeometryConnectionPoint | null;
  153. /**
  154. * Serializes this block in a JSON representation
  155. * @returns the serialized block object
  156. */
  157. serialize(): any;
  158. /**
  159. * @internal
  160. */
  161. _deserialize(serializationObject: any): void;
  162. private _deserializePortDisplayNamesAndExposedOnFrame;
  163. protected _dumpPropertiesCode(): string;
  164. /**
  165. * @internal
  166. */
  167. _dumpCodeForOutputConnections(alreadyDumped: NodeGeometryBlock[]): string;
  168. /**
  169. * @internal
  170. */
  171. _dumpCode(uniqueNames: string[], alreadyDumped: NodeGeometryBlock[]): string;
  172. /**
  173. * Clone the current block to a new identical block
  174. * @returns a copy of the current block
  175. */
  176. clone(): NodeGeometryBlock | null;
  177. /**
  178. * Release resources
  179. */
  180. dispose(): void;
  181. }