spriteSceneComponent.d.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import type { Nullable } from "../types";
  2. import { Observable } from "../Misc/observable";
  3. import { Scene } from "../scene";
  4. import type { Sprite } from "./sprite";
  5. import type { ISpriteManager } from "./spriteManager";
  6. import { Ray } from "../Culling/ray";
  7. import type { Camera } from "../Cameras/camera";
  8. import { PickingInfo } from "../Collisions/pickingInfo";
  9. import type { ISceneComponent } from "../sceneComponent";
  10. declare module "../scene" {
  11. interface Scene {
  12. /** @internal */
  13. _pointerOverSprite: Nullable<Sprite>;
  14. /** @internal */
  15. _pickedDownSprite: Nullable<Sprite>;
  16. /** @internal */
  17. _tempSpritePickingRay: Nullable<Ray>;
  18. /**
  19. * All of the sprite managers added to this scene
  20. * @see https://doc.babylonjs.com/features/featuresDeepDive/sprites
  21. */
  22. spriteManagers?: Array<ISpriteManager>;
  23. /**
  24. * An event triggered when sprites rendering is about to start
  25. * Note: This event can be trigger more than once per frame (because sprites can be rendered by render target textures as well)
  26. */
  27. onBeforeSpritesRenderingObservable: Observable<Scene>;
  28. /**
  29. * An event triggered when sprites rendering is done
  30. * Note: This event can be trigger more than once per frame (because sprites can be rendered by render target textures as well)
  31. */
  32. onAfterSpritesRenderingObservable: Observable<Scene>;
  33. /** @internal */
  34. _internalPickSprites(ray: Ray, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean, camera?: Camera): Nullable<PickingInfo>;
  35. /** Launch a ray to try to pick a sprite in the scene
  36. * @param x position on screen
  37. * @param y position on screen
  38. * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
  39. * @param fastCheck defines if the first intersection will be used (and not the closest)
  40. * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
  41. * @returns a PickingInfo
  42. */
  43. pickSprite(x: number, y: number, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean, camera?: Camera): Nullable<PickingInfo>;
  44. /** Use the given ray to pick a sprite in the scene
  45. * @param ray The ray (in world space) to use to pick meshes
  46. * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
  47. * @param fastCheck defines if the first intersection will be used (and not the closest)
  48. * @param camera camera to use. Can be set to null. In this case, the scene.activeCamera will be used
  49. * @returns a PickingInfo
  50. */
  51. pickSpriteWithRay(ray: Ray, predicate?: (sprite: Sprite) => boolean, fastCheck?: boolean, camera?: Camera): Nullable<PickingInfo>;
  52. /** @internal */
  53. _internalMultiPickSprites(ray: Ray, predicate?: (sprite: Sprite) => boolean, camera?: Camera): Nullable<PickingInfo[]>;
  54. /** Launch a ray to try to pick sprites in the scene
  55. * @param x position on screen
  56. * @param y position on screen
  57. * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
  58. * @param camera camera to use for computing the picking ray. Can be set to null. In this case, the scene.activeCamera will be used
  59. * @returns a PickingInfo array
  60. */
  61. multiPickSprite(x: number, y: number, predicate?: (sprite: Sprite) => boolean, camera?: Camera): Nullable<PickingInfo[]>;
  62. /** Use the given ray to pick sprites in the scene
  63. * @param ray The ray (in world space) to use to pick meshes
  64. * @param predicate Predicate function used to determine eligible sprites. Can be set to null. In this case, a sprite must have isPickable set to true
  65. * @param camera camera to use. Can be set to null. In this case, the scene.activeCamera will be used
  66. * @returns a PickingInfo array
  67. */
  68. multiPickSpriteWithRay(ray: Ray, predicate?: (sprite: Sprite) => boolean, camera?: Camera): Nullable<PickingInfo[]>;
  69. /**
  70. * Force the sprite under the pointer
  71. * @param sprite defines the sprite to use
  72. */
  73. setPointerOverSprite(sprite: Nullable<Sprite>): void;
  74. /**
  75. * Gets the sprite under the pointer
  76. * @returns a Sprite or null if no sprite is under the pointer
  77. */
  78. getPointerOverSprite(): Nullable<Sprite>;
  79. }
  80. }
  81. /**
  82. * Defines the sprite scene component responsible to manage sprites
  83. * in a given scene.
  84. */
  85. export declare class SpriteSceneComponent implements ISceneComponent {
  86. /**
  87. * The component name helpfull to identify the component in the list of scene components.
  88. */
  89. readonly name = "Sprite";
  90. /**
  91. * The scene the component belongs to.
  92. */
  93. scene: Scene;
  94. /** @internal */
  95. private _spritePredicate;
  96. /**
  97. * Creates a new instance of the component for the given scene
  98. * @param scene Defines the scene to register the component in
  99. */
  100. constructor(scene: Scene);
  101. /**
  102. * Registers the component in a given scene
  103. */
  104. register(): void;
  105. /**
  106. * Rebuilds the elements related to this component in case of
  107. * context lost for instance.
  108. */
  109. rebuild(): void;
  110. /**
  111. * Disposes the component and the associated resources.
  112. */
  113. dispose(): void;
  114. private _pickSpriteButKeepRay;
  115. private _pointerMove;
  116. private _pointerDown;
  117. private _pointerUp;
  118. }