light_occluder_2d.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /**************************************************************************/
  2. /* light_occluder_2d.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 LIGHT_OCCLUDER_2D_H
  31. #define LIGHT_OCCLUDER_2D_H
  32. #include "scene/2d/node_2d.h"
  33. class OccluderPolygon2D : public Resource {
  34. GDCLASS(OccluderPolygon2D, Resource);
  35. public:
  36. enum CullMode {
  37. CULL_DISABLED,
  38. CULL_CLOCKWISE,
  39. CULL_COUNTER_CLOCKWISE
  40. };
  41. private:
  42. RID occ_polygon;
  43. Vector<Vector2> polygon;
  44. bool closed = true;
  45. CullMode cull = CULL_DISABLED;
  46. mutable Rect2 item_rect;
  47. mutable bool rect_cache_dirty = true;
  48. protected:
  49. static void _bind_methods();
  50. public:
  51. #ifdef DEBUG_ENABLED
  52. virtual Rect2 _edit_get_rect() const;
  53. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const;
  54. #endif // DEBUG_ENABLED
  55. void set_polygon(const Vector<Vector2> &p_polygon);
  56. Vector<Vector2> get_polygon() const;
  57. void set_closed(bool p_closed);
  58. bool is_closed() const;
  59. void set_cull_mode(CullMode p_mode);
  60. CullMode get_cull_mode() const;
  61. virtual RID get_rid() const override;
  62. OccluderPolygon2D();
  63. ~OccluderPolygon2D();
  64. };
  65. VARIANT_ENUM_CAST(OccluderPolygon2D::CullMode);
  66. class LightOccluder2D : public Node2D {
  67. GDCLASS(LightOccluder2D, Node2D);
  68. RID occluder;
  69. int mask = 1;
  70. Ref<OccluderPolygon2D> occluder_polygon;
  71. bool sdf_collision = false;
  72. void _poly_changed();
  73. virtual void _physics_interpolated_changed() override;
  74. protected:
  75. void _notification(int p_what);
  76. static void _bind_methods();
  77. public:
  78. #ifdef DEBUG_ENABLED
  79. virtual Rect2 _edit_get_rect() const override;
  80. virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const override;
  81. #endif // DEBUG_ENABLED
  82. void set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon);
  83. Ref<OccluderPolygon2D> get_occluder_polygon() const;
  84. void set_occluder_light_mask(int p_mask);
  85. int get_occluder_light_mask() const;
  86. void set_as_sdf_collision(bool p_enable);
  87. bool is_set_as_sdf_collision() const;
  88. PackedStringArray get_configuration_warnings() const override;
  89. LightOccluder2D();
  90. ~LightOccluder2D();
  91. };
  92. #endif // LIGHT_OCCLUDER_2D_H