visible_on_screen_notifier_3d.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**************************************************************************/
  2. /* visible_on_screen_notifier_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef VISIBLE_ON_SCREEN_NOTIFIER_3D_H
  31. #define VISIBLE_ON_SCREEN_NOTIFIER_3D_H
  32. #include "scene/3d/visual_instance_3d.h"
  33. class World3D;
  34. class Camera3D;
  35. class VisibleOnScreenNotifier3D : public VisualInstance3D {
  36. GDCLASS(VisibleOnScreenNotifier3D, VisualInstance3D);
  37. AABB aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
  38. private:
  39. bool on_screen = false;
  40. void _visibility_enter();
  41. void _visibility_exit();
  42. protected:
  43. virtual void _screen_enter() {}
  44. virtual void _screen_exit() {}
  45. void _notification(int p_what);
  46. static void _bind_methods();
  47. public:
  48. void set_aabb(const AABB &p_aabb);
  49. virtual AABB get_aabb() const override;
  50. bool is_on_screen() const;
  51. VisibleOnScreenNotifier3D();
  52. ~VisibleOnScreenNotifier3D();
  53. };
  54. class VisibleOnScreenEnabler3D : public VisibleOnScreenNotifier3D {
  55. GDCLASS(VisibleOnScreenEnabler3D, VisibleOnScreenNotifier3D);
  56. public:
  57. enum EnableMode {
  58. ENABLE_MODE_INHERIT,
  59. ENABLE_MODE_ALWAYS,
  60. ENABLE_MODE_WHEN_PAUSED,
  61. };
  62. protected:
  63. ObjectID node_id;
  64. virtual void _screen_enter() override;
  65. virtual void _screen_exit() override;
  66. EnableMode enable_mode = ENABLE_MODE_INHERIT;
  67. NodePath enable_node_path = NodePath("..");
  68. void _notification(int p_what);
  69. static void _bind_methods();
  70. void _update_enable_mode(bool p_enable);
  71. public:
  72. void set_enable_mode(EnableMode p_mode);
  73. EnableMode get_enable_mode();
  74. void set_enable_node_path(NodePath p_path);
  75. NodePath get_enable_node_path();
  76. VisibleOnScreenEnabler3D();
  77. };
  78. VARIANT_ENUM_CAST(VisibleOnScreenEnabler3D::EnableMode);
  79. #endif // VISIBLE_ON_SCREEN_NOTIFIER_3D_H