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