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