Debian Codegraph @

scene/3d/occluder_instance_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* occluder_instance_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
31 #pragma once
32
33 #include "scene/3d/visual_instance_3d.h"
34
35 class Occluder3D : public Resource {
36 GDCLASS(Occluder3D, Resource);
37 RES_BASE_EXTENSION("occ");
38
39 RID occluder;
40 PackedVector3Array vertices;
41 PackedInt32Array indices;
42 AABB aabb;
43
44 mutable Ref<ArrayMesh> debug_mesh;
45 mutable Vector<Vector3> debug_lines;
46
47 protected:
48 void _update();
49 virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) = 0;
50
51 void _notification(int p_what);
52
53 public:
54 PackedVector3Array get_vertices() const;
55 PackedInt32Array get_indices() const;
56
57 Vector<Vector3> get_debug_lines() const;
58 Ref<ArrayMesh> get_debug_mesh() const;
59 AABB get_aabb() const;
60
61 virtual RID get_rid() const override;
62 Occluder3D();
63 virtual ~Occluder3D();
64 };
65
66 class ArrayOccluder3D : public Occluder3D {
67 GDCLASS(ArrayOccluder3D, Occluder3D);
68
69 PackedVector3Array vertices;
70 PackedInt32Array indices;
71
72 protected:
73 virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
74 static void _bind_methods();
75
76 public:
77 void set_arrays(PackedVector3Array p_vertices, PackedInt32Array p_indices);
78 void set_vertices(PackedVector3Array p_vertices);
79 void set_indices(PackedInt32Array p_indices);
80
81 ArrayOccluder3D();
82 ~ArrayOccluder3D();
83 };
84
85 class QuadOccluder3D : public Occluder3D {
86 GDCLASS(QuadOccluder3D, Occluder3D);
87
88 private:
89 Size2 size = Vector2(1.0f, 1.0f);
90
91 protected:
92 virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
93 static void _bind_methods();
94
95 public:
96 Size2 get_size() const;
97 void set_size(const Size2 &p_size);
98
99 QuadOccluder3D();
100 ~QuadOccluder3D();
101 };
102
103 class BoxOccluder3D : public Occluder3D {
104 GDCLASS(BoxOccluder3D, Occluder3D);
105
106 private:
107 Vector3 size = Vector3(1.0f, 1.0f, 1.0f);
108
109 protected:
110 virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
111 static void _bind_methods();
112
113 public:
114 Vector3 get_size() const;
115 void set_size(const Vector3 &p_size);
116
117 BoxOccluder3D();
118 ~BoxOccluder3D();
119 };
120
121 class SphereOccluder3D : public Occluder3D {
122 GDCLASS(SphereOccluder3D, Occluder3D);
123
124 private:
125 static constexpr int RINGS = 7;
126 static constexpr int RADIAL_SEGMENTS = 7;
127 float radius = 1.0f;
128
129 protected:
130 virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
131 static void _bind_methods();
132
133 public:
134 float get_radius() const;
135 void set_radius(float p_radius);
136
137 SphereOccluder3D();
138 ~SphereOccluder3D();
139 };
140
141 class PolygonOccluder3D : public Occluder3D {
142 GDCLASS(PolygonOccluder3D, Occluder3D);
143
144 private:
145 Vector<Vector2> polygon;
146
147 bool _has_editable_3d_polygon_no_depth() const;
148
149 protected:
150 virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
151 static void _bind_methods();
152
153 public:
154 void set_polygon(const Vector<Vector2> &p_polygon);
155 Vector<Vector2> get_polygon() const;
156
157 PolygonOccluder3D();
158 ~PolygonOccluder3D();
159 };
160
161 class OccluderInstance3D : public VisualInstance3D {
162 GDCLASS(OccluderInstance3D, VisualInstance3D);
163
164 private:
165 Ref<Occluder3D> occluder;
166 uint32_t bake_mask = 0xFFFFFFFF;
167 float bake_simplification_dist = 0.1f;
168
169 void _occluder_changed();
170
171 static bool _bake_material_check(Ref<Material> p_material);
172 static void _bake_surface(const Transform3D &p_transform, Array p_surface_arrays, Ref<Material> p_material, float p_simplification_dist, PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
173 void _bake_node(Node *p_node, PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
174
175 bool _is_editable_3d_polygon() const;
176 Ref<Resource> _get_editable_3d_polygon_resource() const;
177
178 protected:
179 static void _bind_methods();
180
181 public:
182 virtual PackedStringArray get_configuration_warnings() const override;
183
184 enum BakeError {
185 BAKE_ERROR_OK,
186 BAKE_ERROR_NO_SAVE_PATH,
187 BAKE_ERROR_NO_MESHES,
188 BAKE_ERROR_CANT_SAVE,
189 };
190
191 void set_occluder(const Ref<Occluder3D> &p_occluder);
192 Ref<Occluder3D> get_occluder() const;
193
194 virtual AABB get_aabb() const override;
195
196 void set_bake_mask(uint32_t p_mask);
197 uint32_t get_bake_mask() const;
198
199 void set_bake_simplification_distance(float p_dist);
200 float get_bake_simplification_distance() const;
201
202 void set_bake_mask_value(int p_layer_number, bool p_enable);
203 bool get_bake_mask_value(int p_layer_number) const;
204
205 BakeError bake_scene(Node *p_from_node, String p_occluder_path = "");
206 static void bake_single_node(const Node3D *p_node, float p_simplification_distance, PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
207
208 OccluderInstance3D();
209 ~OccluderInstance3D();
210 };