assetContainer.d.ts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. import { AbstractScene } from "./abstractScene";
  2. import type { Scene } from "./scene";
  3. import { Mesh } from "./Meshes/mesh";
  4. import type { Skeleton } from "./Bones/skeleton";
  5. import type { AnimationGroup } from "./Animations/animationGroup";
  6. import type { Animatable } from "./Animations/animatable";
  7. import type { Nullable } from "./types";
  8. import type { Node } from "./node";
  9. /**
  10. * Set of assets to keep when moving a scene into an asset container.
  11. */
  12. export declare class KeepAssets extends AbstractScene {
  13. }
  14. /**
  15. * Class used to store the output of the AssetContainer.instantiateAllMeshesToScene function
  16. */
  17. export declare class InstantiatedEntries {
  18. /**
  19. * List of new root nodes (eg. nodes with no parent)
  20. */
  21. rootNodes: Node[];
  22. /**
  23. * List of new skeletons
  24. */
  25. skeletons: Skeleton[];
  26. /**
  27. * List of new animation groups
  28. */
  29. animationGroups: AnimationGroup[];
  30. /**
  31. * Disposes the instantiated entries from the scene
  32. */
  33. dispose(): void;
  34. }
  35. /**
  36. * Container with a set of assets that can be added or removed from a scene.
  37. */
  38. export declare class AssetContainer extends AbstractScene {
  39. private _wasAddedToScene;
  40. private _onContextRestoredObserver;
  41. /**
  42. * The scene the AssetContainer belongs to.
  43. */
  44. scene: Scene;
  45. /**
  46. * Instantiates an AssetContainer.
  47. * @param scene The scene the AssetContainer belongs to.
  48. */
  49. constructor(scene?: Nullable<Scene>);
  50. /**
  51. * Given a list of nodes, return a topological sorting of them.
  52. * @param nodes
  53. * @returns a sorted array of nodes
  54. */
  55. private _topologicalSort;
  56. private _addNodeAndDescendantsToList;
  57. /**
  58. * Check if a specific node is contained in this asset container.
  59. * @param node the node to check
  60. * @returns true if the node is contained in this container, otherwise false.
  61. */
  62. private _isNodeInContainer;
  63. /**
  64. * For every node in the scene, check if its parent node is also in the scene.
  65. * @returns true if every node's parent is also in the scene, otherwise false.
  66. */
  67. private _isValidHierarchy;
  68. /**
  69. * Instantiate or clone all meshes and add the new ones to the scene.
  70. * Skeletons and animation groups will all be cloned
  71. * @param nameFunction defines an optional function used to get new names for clones
  72. * @param cloneMaterials defines an optional boolean that defines if materials must be cloned as well (false by default)
  73. * @param options defines an optional list of options to control how to instantiate / clone models
  74. * @param options.doNotInstantiate defines if the model must be instantiated or just cloned
  75. * @param options.predicate defines a predicate used to filter whih mesh to instantiate/clone
  76. * @returns a list of rootNodes, skeletons and animation groups that were duplicated
  77. */
  78. instantiateModelsToScene(nameFunction?: (sourceName: string) => string, cloneMaterials?: boolean, options?: {
  79. doNotInstantiate?: boolean | ((node: Node) => boolean);
  80. predicate?: (entity: any) => boolean;
  81. }): InstantiatedEntries;
  82. /**
  83. * Adds all the assets from the container to the scene.
  84. */
  85. addAllToScene(): void;
  86. /**
  87. * Adds assets from the container to the scene.
  88. * @param predicate defines a predicate used to select which entity will be added (can be null)
  89. */
  90. addToScene(predicate?: Nullable<(entity: any) => boolean>): void;
  91. /**
  92. * Removes all the assets in the container from the scene
  93. */
  94. removeAllFromScene(): void;
  95. /**
  96. * Removes assets in the container from the scene
  97. * @param predicate defines a predicate used to select which entity will be added (can be null)
  98. */
  99. removeFromScene(predicate?: Nullable<(entity: any) => boolean>): void;
  100. /**
  101. * Disposes all the assets in the container
  102. */
  103. dispose(): void;
  104. private _moveAssets;
  105. /**
  106. * Removes all the assets contained in the scene and adds them to the container.
  107. * @param keepAssets Set of assets to keep in the scene. (default: empty)
  108. */
  109. moveAllFromScene(keepAssets?: KeepAssets): void;
  110. /**
  111. * Adds all meshes in the asset container to a root mesh that can be used to position all the contained meshes. The root mesh is then added to the front of the meshes in the assetContainer.
  112. * @returns the root mesh
  113. */
  114. createRootMesh(): Mesh;
  115. /**
  116. * Merge animations (direct and animation groups) from this asset container into a scene
  117. * @param scene is the instance of BABYLON.Scene to append to (default: last created scene)
  118. * @param animatables set of animatables to retarget to a node from the scene
  119. * @param targetConverter defines a function used to convert animation targets from the asset container to the scene (default: search node by name)
  120. * @returns an array of the new AnimationGroup added to the scene (empty array if none)
  121. */
  122. mergeAnimationsTo(scene: Nullable<Scene> | undefined, animatables: Animatable[], targetConverter?: Nullable<(target: any) => Nullable<Node>>): AnimationGroup[];
  123. /**
  124. * @since 6.15.0
  125. * This method checks for any node that has no parent
  126. * and is not in the rootNodes array, and adds the node
  127. * there, if so.
  128. */
  129. populateRootNodes(): void;
  130. /**
  131. * @since 6.26.0
  132. * Given a root asset, this method will traverse its hierarchy and add it, its children and any materials/skeletons/animation groups to the container.
  133. * @param root root node
  134. */
  135. addAllAssetsToContainer(root: Node): void;
  136. }