node.d.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. import type { Scene } from "./scene";
  2. import type { Nullable } from "./types";
  3. import { Matrix, Vector3 } from "./Maths/math.vector";
  4. import type { AbstractEngine } from "./Engines/abstractEngine";
  5. import type { IBehaviorAware, Behavior } from "./Behaviors/behavior";
  6. import { Observable } from "./Misc/observable";
  7. import type { AbstractActionManager } from "./Actions/abstractActionManager";
  8. import type { IInspectable } from "./Misc/iInspectable";
  9. import type { AbstractScene } from "./abstractScene";
  10. import type { IAccessibilityTag } from "./IAccessibilityTag";
  11. import type { AnimationRange } from "./Animations/animationRange";
  12. import type { AnimationPropertiesOverride } from "./Animations/animationPropertiesOverride";
  13. import type { AbstractMesh } from "./Meshes/abstractMesh";
  14. import type { Animation } from "./Animations/animation";
  15. import type { Animatable } from "./Animations/animatable";
  16. /**
  17. * Defines how a node can be built from a string name.
  18. */
  19. export type NodeConstructor = (name: string, scene: Scene, options?: any) => () => Node;
  20. /**
  21. * Node is the basic class for all scene objects (Mesh, Light, Camera.)
  22. */
  23. export declare class Node implements IBehaviorAware<Node> {
  24. protected _isDirty: boolean;
  25. /**
  26. * @internal
  27. */
  28. static _AnimationRangeFactory: (_name: string, _from: number, _to: number) => AnimationRange;
  29. private static _NodeConstructors;
  30. /**
  31. * Add a new node constructor
  32. * @param type defines the type name of the node to construct
  33. * @param constructorFunc defines the constructor function
  34. */
  35. static AddNodeConstructor(type: string, constructorFunc: NodeConstructor): void;
  36. /**
  37. * Returns a node constructor based on type name
  38. * @param type defines the type name
  39. * @param name defines the new node name
  40. * @param scene defines the hosting scene
  41. * @param options defines optional options to transmit to constructors
  42. * @returns the new constructor or null
  43. */
  44. static Construct(type: string, name: string, scene: Scene, options?: any): Nullable<() => Node>;
  45. private _nodeDataStorage;
  46. /**
  47. * Gets or sets the name of the node
  48. */
  49. name: string;
  50. /**
  51. * Gets or sets the id of the node
  52. */
  53. id: string;
  54. /**
  55. * Gets or sets the unique id of the node
  56. */
  57. uniqueId: number;
  58. /**
  59. * Gets or sets a string used to store user defined state for the node
  60. */
  61. state: string;
  62. /**
  63. * Gets or sets an object used to store user defined information for the node
  64. */
  65. metadata: any;
  66. /** @internal */
  67. _internalMetadata: any;
  68. /**
  69. * For internal use only. Please do not use.
  70. */
  71. reservedDataStore: any;
  72. /**
  73. * List of inspectable custom properties (used by the Inspector)
  74. * @see https://doc.babylonjs.com/toolsAndResources/inspector#extensibility
  75. */
  76. inspectableCustomProperties: IInspectable[];
  77. /**
  78. * Gets or sets the accessibility tag to describe the node for accessibility purpose.
  79. */
  80. set accessibilityTag(value: Nullable<IAccessibilityTag>);
  81. get accessibilityTag(): Nullable<IAccessibilityTag>;
  82. protected _accessibilityTag: Nullable<IAccessibilityTag>;
  83. /**
  84. * Observable fired when an accessibility tag is changed
  85. */
  86. onAccessibilityTagChangedObservable: Observable<Nullable<IAccessibilityTag>>;
  87. /**
  88. * Gets or sets a boolean used to define if the node must be serialized
  89. */
  90. get doNotSerialize(): boolean;
  91. set doNotSerialize(value: boolean);
  92. /** @internal */
  93. _parentContainer: Nullable<AbstractScene>;
  94. /**
  95. * Gets a list of Animations associated with the node
  96. */
  97. animations: Animation[];
  98. protected _ranges: {
  99. [name: string]: Nullable<AnimationRange>;
  100. };
  101. /**
  102. * Callback raised when the node is ready to be used
  103. */
  104. onReady: Nullable<(node: Node) => void>;
  105. /** @internal */
  106. _currentRenderId: number;
  107. private _parentUpdateId;
  108. /** @internal */
  109. _childUpdateId: number;
  110. /** @internal */
  111. _waitingParentId: Nullable<string>;
  112. /** @internal */
  113. _waitingParentInstanceIndex: Nullable<string>;
  114. /** @internal */
  115. _waitingParsedUniqueId: Nullable<number>;
  116. /** @internal */
  117. _scene: Scene;
  118. /** @internal */
  119. _cache: any;
  120. protected _parentNode: Nullable<Node>;
  121. /** @internal */
  122. protected _children: Nullable<Node[]>;
  123. /** @internal */
  124. _worldMatrix: Matrix;
  125. /** @internal */
  126. _worldMatrixDeterminant: number;
  127. /** @internal */
  128. _worldMatrixDeterminantIsDirty: boolean;
  129. /**
  130. * Gets a boolean indicating if the node has been disposed
  131. * @returns true if the node was disposed
  132. */
  133. isDisposed(): boolean;
  134. /**
  135. * Gets or sets the parent of the node (without keeping the current position in the scene)
  136. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/transforms/parent_pivot/parent
  137. */
  138. set parent(parent: Nullable<Node>);
  139. get parent(): Nullable<Node>;
  140. /**
  141. * @internal
  142. */
  143. _serializeAsParent(serializationObject: any): void;
  144. /** @internal */
  145. _addToSceneRootNodes(): void;
  146. /** @internal */
  147. _removeFromSceneRootNodes(): void;
  148. private _animationPropertiesOverride;
  149. /**
  150. * Gets or sets the animation properties override
  151. */
  152. get animationPropertiesOverride(): Nullable<AnimationPropertiesOverride>;
  153. set animationPropertiesOverride(value: Nullable<AnimationPropertiesOverride>);
  154. /**
  155. * Gets a string identifying the name of the class
  156. * @returns "Node" string
  157. */
  158. getClassName(): string;
  159. /** @internal */
  160. readonly _isNode = true;
  161. /**
  162. * An event triggered when the mesh is disposed
  163. */
  164. onDisposeObservable: Observable<Node>;
  165. private _onDisposeObserver;
  166. /**
  167. * Sets a callback that will be raised when the node will be disposed
  168. */
  169. set onDispose(callback: () => void);
  170. /**
  171. * An event triggered when the enabled state of the node changes
  172. */
  173. get onEnabledStateChangedObservable(): Observable<boolean>;
  174. /**
  175. * An event triggered when the node is cloned
  176. */
  177. get onClonedObservable(): Observable<Node>;
  178. /**
  179. * Creates a new Node
  180. * @param name the name and id to be given to this node
  181. * @param scene the scene this node will be added to
  182. */
  183. constructor(name: string, scene?: Nullable<Scene>);
  184. /**
  185. * Gets the scene of the node
  186. * @returns a scene
  187. */
  188. getScene(): Scene;
  189. /**
  190. * Gets the engine of the node
  191. * @returns a Engine
  192. */
  193. getEngine(): AbstractEngine;
  194. private _behaviors;
  195. /**
  196. * Attach a behavior to the node
  197. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors
  198. * @param behavior defines the behavior to attach
  199. * @param attachImmediately defines that the behavior must be attached even if the scene is still loading
  200. * @returns the current Node
  201. */
  202. addBehavior(behavior: Behavior<Node>, attachImmediately?: boolean): Node;
  203. /**
  204. * Remove an attached behavior
  205. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors
  206. * @param behavior defines the behavior to attach
  207. * @returns the current Node
  208. */
  209. removeBehavior(behavior: Behavior<Node>): Node;
  210. /**
  211. * Gets the list of attached behaviors
  212. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors
  213. */
  214. get behaviors(): Behavior<Node>[];
  215. /**
  216. * Gets an attached behavior by name
  217. * @param name defines the name of the behavior to look for
  218. * @see https://doc.babylonjs.com/features/featuresDeepDive/behaviors
  219. * @returns null if behavior was not found else the requested behavior
  220. */
  221. getBehaviorByName(name: string): Nullable<Behavior<Node>>;
  222. /**
  223. * Returns the latest update of the World matrix
  224. * @returns a Matrix
  225. */
  226. getWorldMatrix(): Matrix;
  227. /** @internal */
  228. _getWorldMatrixDeterminant(): number;
  229. /**
  230. * Returns directly the latest state of the mesh World matrix.
  231. * A Matrix is returned.
  232. */
  233. get worldMatrixFromCache(): Matrix;
  234. /** @internal */
  235. _initCache(): void;
  236. /**
  237. * @internal
  238. */
  239. updateCache(force?: boolean): void;
  240. /**
  241. * @internal
  242. */
  243. _getActionManagerForTrigger(trigger?: number, _initialCall?: boolean): Nullable<AbstractActionManager>;
  244. /**
  245. * @internal
  246. */
  247. _updateCache(_ignoreParentClass?: boolean): void;
  248. /** @internal */
  249. _isSynchronized(): boolean;
  250. /** @internal */
  251. _markSyncedWithParent(): void;
  252. /** @internal */
  253. isSynchronizedWithParent(): boolean;
  254. /** @internal */
  255. isSynchronized(): boolean;
  256. /**
  257. * Is this node ready to be used/rendered
  258. * @param _completeCheck defines if a complete check (including materials and lights) has to be done (false by default)
  259. * @returns true if the node is ready
  260. */
  261. isReady(_completeCheck?: boolean): boolean;
  262. /**
  263. * Flag the node as dirty (Forcing it to update everything)
  264. * @param _property helps children apply precise "dirtyfication"
  265. * @returns this node
  266. */
  267. markAsDirty(_property?: string): Node;
  268. /**
  269. * Is this node enabled?
  270. * If the node has a parent, all ancestors will be checked and false will be returned if any are false (not enabled), otherwise will return true
  271. * @param checkAncestors indicates if this method should check the ancestors. The default is to check the ancestors. If set to false, the method will return the value of this node without checking ancestors
  272. * @returns whether this node (and its parent) is enabled
  273. */
  274. isEnabled(checkAncestors?: boolean): boolean;
  275. /** @internal */
  276. protected _syncParentEnabledState(): void;
  277. /**
  278. * Set the enabled state of this node
  279. * @param value defines the new enabled state
  280. */
  281. setEnabled(value: boolean): void;
  282. /**
  283. * Is this node a descendant of the given node?
  284. * The function will iterate up the hierarchy until the ancestor was found or no more parents defined
  285. * @param ancestor defines the parent node to inspect
  286. * @returns a boolean indicating if this node is a descendant of the given node
  287. */
  288. isDescendantOf(ancestor: Node): boolean;
  289. /**
  290. * @internal
  291. */
  292. _getDescendants(results: Node[], directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): void;
  293. /**
  294. * Will return all nodes that have this node as ascendant
  295. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  296. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  297. * @returns all children nodes of all types
  298. */
  299. getDescendants<T extends Node>(directDescendantsOnly?: boolean, predicate?: (node: Node) => node is T): T[];
  300. /**
  301. * Will return all nodes that have this node as ascendant
  302. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered
  303. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  304. * @returns all children nodes of all types
  305. */
  306. getDescendants(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): Node[];
  307. /**
  308. * Get all child-meshes of this node
  309. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: false)
  310. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  311. * @returns an array of AbstractMesh
  312. */
  313. getChildMeshes<T extends AbstractMesh>(directDescendantsOnly?: boolean, predicate?: (node: Node) => node is T): T[];
  314. /**
  315. * Get all child-meshes of this node
  316. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: false)
  317. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  318. * @returns an array of AbstractMesh
  319. */
  320. getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[];
  321. /**
  322. * Get all direct children of this node
  323. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  324. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)
  325. * @returns an array of Node
  326. */
  327. getChildren<T extends Node>(predicate?: (node: Node) => node is T, directDescendantsOnly?: boolean): T[];
  328. /**
  329. * Get all direct children of this node
  330. * @param predicate defines an optional predicate that will be called on every evaluated child, the predicate must return true for a given child to be part of the result, otherwise it will be ignored
  331. * @param directDescendantsOnly defines if true only direct descendants of 'this' will be considered, if false direct and also indirect (children of children, an so on in a recursive manner) descendants of 'this' will be considered (Default: true)
  332. * @returns an array of Node
  333. */
  334. getChildren(predicate?: (node: Node) => boolean, directDescendantsOnly?: boolean): Node[];
  335. /**
  336. * @internal
  337. */
  338. _setReady(state: boolean): void;
  339. /**
  340. * Get an animation by name
  341. * @param name defines the name of the animation to look for
  342. * @returns null if not found else the requested animation
  343. */
  344. getAnimationByName(name: string): Nullable<Animation>;
  345. /**
  346. * Creates an animation range for this node
  347. * @param name defines the name of the range
  348. * @param from defines the starting key
  349. * @param to defines the end key
  350. */
  351. createAnimationRange(name: string, from: number, to: number): void;
  352. /**
  353. * Delete a specific animation range
  354. * @param name defines the name of the range to delete
  355. * @param deleteFrames defines if animation frames from the range must be deleted as well
  356. */
  357. deleteAnimationRange(name: string, deleteFrames?: boolean): void;
  358. /**
  359. * Get an animation range by name
  360. * @param name defines the name of the animation range to look for
  361. * @returns null if not found else the requested animation range
  362. */
  363. getAnimationRange(name: string): Nullable<AnimationRange>;
  364. /**
  365. * Clone the current node
  366. * @param name Name of the new clone
  367. * @param newParent New parent for the clone
  368. * @param doNotCloneChildren Do not clone children hierarchy
  369. * @returns the new transform node
  370. */
  371. clone(name: string, newParent: Nullable<Node>, doNotCloneChildren?: boolean): Nullable<Node>;
  372. /**
  373. * Gets the list of all animation ranges defined on this node
  374. * @returns an array
  375. */
  376. getAnimationRanges(): Nullable<AnimationRange>[];
  377. /**
  378. * Will start the animation sequence
  379. * @param name defines the range frames for animation sequence
  380. * @param loop defines if the animation should loop (false by default)
  381. * @param speedRatio defines the speed factor in which to run the animation (1 by default)
  382. * @param onAnimationEnd defines a function to be executed when the animation ended (undefined by default)
  383. * @returns the object created for this animation. If range does not exist, it will return null
  384. */
  385. beginAnimation(name: string, loop?: boolean, speedRatio?: number, onAnimationEnd?: () => void): Nullable<Animatable>;
  386. /**
  387. * Serialize animation ranges into a JSON compatible object
  388. * @returns serialization object
  389. */
  390. serializeAnimationRanges(): any;
  391. /**
  392. * Computes the world matrix of the node
  393. * @param _force defines if the cache version should be invalidated forcing the world matrix to be created from scratch
  394. * @returns the world matrix
  395. */
  396. computeWorldMatrix(_force?: boolean): Matrix;
  397. /**
  398. * Releases resources associated with this node.
  399. * @param doNotRecurse Set to true to not recurse into each children (recurse into each children by default)
  400. * @param disposeMaterialAndTextures Set to true to also dispose referenced materials and textures (false by default)
  401. */
  402. dispose(doNotRecurse?: boolean, disposeMaterialAndTextures?: boolean): void;
  403. /**
  404. * Parse animation range data from a serialization object and store them into a given node
  405. * @param node defines where to store the animation ranges
  406. * @param parsedNode defines the serialization object to read data from
  407. * @param _scene defines the hosting scene
  408. */
  409. static ParseAnimationRanges(node: Node, parsedNode: any, _scene: Scene): void;
  410. /**
  411. * Return the minimum and maximum world vectors of the entire hierarchy under current node
  412. * @param includeDescendants Include bounding info from descendants as well (true by default)
  413. * @param predicate defines a callback function that can be customize to filter what meshes should be included in the list used to compute the bounding vectors
  414. * @returns the new bounding vectors
  415. */
  416. getHierarchyBoundingVectors(includeDescendants?: boolean, predicate?: Nullable<(abstractMesh: AbstractMesh) => boolean>): {
  417. min: Vector3;
  418. max: Vector3;
  419. };
  420. }