Debian Codegraph @

scene/3d/gpu_particles_collision_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* gpu_particles_collision_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 "core/templates/local_vector.h"
34 #include "scene/3d/visual_instance_3d.h"
35
36 class GPUParticlesCollision3D : public VisualInstance3D {
37 GDCLASS(GPUParticlesCollision3D, VisualInstance3D);
38
39 uint32_t cull_mask = 0xFFFFFFFF;
40 RID collision;
41
42 protected:
43 _FORCE_INLINE_ RID _get_collision() { return collision; }
44 static void _bind_methods();
45
46 GPUParticlesCollision3D(RS::ParticlesCollisionType p_type);
47
48 public:
49 void set_cull_mask(uint32_t p_cull_mask);
50 uint32_t get_cull_mask() const;
51
52 ~GPUParticlesCollision3D();
53 };
54
55 class GPUParticlesCollisionSphere3D : public GPUParticlesCollision3D {
56 GDCLASS(GPUParticlesCollisionSphere3D, GPUParticlesCollision3D);
57
58 real_t radius = 1.0;
59
60 protected:
61 static void _bind_methods();
62
63 public:
64 void set_radius(real_t p_radius);
65 real_t get_radius() const;
66
67 virtual AABB get_aabb() const override;
68
69 GPUParticlesCollisionSphere3D();
70 ~GPUParticlesCollisionSphere3D();
71 };
72
73 class GPUParticlesCollisionBox3D : public GPUParticlesCollision3D {
74 GDCLASS(GPUParticlesCollisionBox3D, GPUParticlesCollision3D);
75
76 Vector3 size = Vector3(2, 2, 2);
77
78 protected:
79 static void _bind_methods();
80 #ifndef DISABLE_DEPRECATED
81 bool _set(const StringName &p_name, const Variant &p_value);
82 bool _get(const StringName &p_name, Variant &r_property) const;
83 #endif // DISABLE_DEPRECATED
84
85 public:
86 void set_size(const Vector3 &p_size);
87 Vector3 get_size() const;
88
89 virtual AABB get_aabb() const override;
90
91 GPUParticlesCollisionBox3D();
92 ~GPUParticlesCollisionBox3D();
93 };
94
95 class GPUParticlesCollisionSDF3D : public GPUParticlesCollision3D {
96 GDCLASS(GPUParticlesCollisionSDF3D, GPUParticlesCollision3D);
97
98 public:
99 enum Resolution {
100 RESOLUTION_16,
101 RESOLUTION_32,
102 RESOLUTION_64,
103 RESOLUTION_128,
104 RESOLUTION_256,
105 RESOLUTION_512,
106 RESOLUTION_MAX,
107 };
108
109 typedef void (*BakeBeginFunc)(int);
110 typedef void (*BakeStepFunc)(int, const String &);
111 typedef void (*BakeEndFunc)();
112
113 private:
114 Vector3 size = Vector3(2, 2, 2);
115 Resolution resolution = RESOLUTION_64;
116 uint32_t bake_mask = 0xFFFFFFFF;
117 Ref<Texture3D> texture;
118 float thickness = 1.0;
119
120 struct PlotMesh {
121 Ref<Mesh> mesh;
122 Transform3D local_xform;
123 };
124
125 void _find_meshes(const AABB &p_aabb, Node *p_at_node, List<PlotMesh> &plot_meshes);
126
127 struct BVH {
128 enum {
129 LEAF_BIT = 1 << 30,
130 LEAF_MASK = LEAF_BIT - 1
131 };
132 AABB bounds;
133 uint32_t children[2] = {};
134 };
135
136 struct FacePos {
137 Vector3 center;
138 uint32_t index = 0;
139 };
140
141 struct FaceSort {
142 uint32_t axis = 0;
143 bool operator()(const FacePos &p_left, const FacePos &p_right) const {
144 return p_left.center[axis] < p_right.center[axis];
145 }
146 };
147
148 uint32_t _create_bvh(LocalVector<BVH> &bvh_tree, FacePos *p_faces, uint32_t p_face_count, const Face3 *p_triangles, float p_thickness);
149
150 struct ComputeSDFParams {
151 float *cells = nullptr;
152 Vector3i size;
153 float cell_size = 0.0;
154 Vector3 cell_offset;
155 const BVH *bvh = nullptr;
156 const Face3 *triangles = nullptr;
157 float thickness = 0.0;
158 };
159
160 void _find_closest_distance(const Vector3 &p_pos, const BVH *p_bvh, uint32_t p_bvh_cell, const Face3 *p_triangles, float p_thickness, float &r_closest_distance);
161 void _compute_sdf_z(uint32_t p_z, ComputeSDFParams *params);
162 void _compute_sdf(ComputeSDFParams *params);
163
164 protected:
165 static void _bind_methods();
166 #ifndef DISABLE_DEPRECATED
167 bool _set(const StringName &p_name, const Variant &p_value);
168 bool _get(const StringName &p_name, Variant &r_property) const;
169 #endif // DISABLE_DEPRECATED
170
171 public:
172 virtual PackedStringArray get_configuration_warnings() const override;
173
174 void set_thickness(float p_thickness);
175 float get_thickness() const;
176
177 void set_size(const Vector3 &p_size);
178 Vector3 get_size() const;
179
180 void set_resolution(Resolution p_resolution);
181 Resolution get_resolution() const;
182
183 void set_bake_mask(uint32_t p_mask);
184 uint32_t get_bake_mask() const;
185
186 void set_bake_mask_value(int p_layer_number, bool p_enable);
187 bool get_bake_mask_value(int p_layer_number) const;
188
189 void set_texture(const Ref<Texture3D> &p_texture);
190 Ref<Texture3D> get_texture() const;
191
192 Vector3i get_estimated_cell_size() const;
193 Ref<Image> bake();
194
195 virtual AABB get_aabb() const override;
196
197 static BakeBeginFunc bake_begin_function;
198 static BakeStepFunc bake_step_function;
199 static BakeEndFunc bake_end_function;
200
201 GPUParticlesCollisionSDF3D();
202 ~GPUParticlesCollisionSDF3D();
203 };
204
205 VARIANT_ENUM_CAST(GPUParticlesCollisionSDF3D::Resolution)
206
207 class GPUParticlesCollisionHeightField3D : public GPUParticlesCollision3D {
208 GDCLASS(GPUParticlesCollisionHeightField3D, GPUParticlesCollision3D);
209
210 public:
211 enum Resolution {
212 RESOLUTION_256,
213 RESOLUTION_512,
214 RESOLUTION_1024,
215 RESOLUTION_2048,
216 RESOLUTION_4096,
217 RESOLUTION_8192,
218 RESOLUTION_MAX,
219 };
220
221 enum UpdateMode {
222 UPDATE_MODE_WHEN_MOVED,
223 UPDATE_MODE_ALWAYS,
224 };
225
226 private:
227 uint32_t heightfield_mask = (1 << 20) - 1; // Only the first 20 bits are set by default to ignore editor layers.
228 Vector3 size = Vector3(2, 2, 2);
229 Resolution resolution = RESOLUTION_1024;
230 bool follow_camera_mode = false;
231
232 UpdateMode update_mode = UPDATE_MODE_WHEN_MOVED;
233
234 protected:
235 void _notification(int p_what);
236 static void _bind_methods();
237 #ifndef DISABLE_DEPRECATED
238 bool _set(const StringName &p_name, const Variant &p_value);
239 bool _get(const StringName &p_name, Variant &r_property) const;
240 #endif // DISABLE_DEPRECATED
241
242 public:
243 void set_size(const Vector3 &p_size);
244 Vector3 get_size() const;
245
246 void set_resolution(Resolution p_resolution);
247 Resolution get_resolution() const;
248
249 void set_update_mode(UpdateMode p_update_mode);
250 UpdateMode get_update_mode() const;
251
252 void set_heightfield_mask(uint32_t p_heightfield_mask);
253 uint32_t get_heightfield_mask() const;
254
255 void set_heightfield_mask_value(int p_layer_number, bool p_value);
256 bool get_heightfield_mask_value(int p_layer_number) const;
257
258 void set_follow_camera_enabled(bool p_enabled);
259 bool is_follow_camera_enabled() const;
260
261 virtual AABB get_aabb() const override;
262
263 GPUParticlesCollisionHeightField3D();
264 ~GPUParticlesCollisionHeightField3D();
265 };
266
267 VARIANT_ENUM_CAST(GPUParticlesCollisionHeightField3D::Resolution)
268 VARIANT_ENUM_CAST(GPUParticlesCollisionHeightField3D::UpdateMode)
269
270 class GPUParticlesAttractor3D : public VisualInstance3D {
271 GDCLASS(GPUParticlesAttractor3D, VisualInstance3D);
272
273 uint32_t cull_mask = 0xFFFFFFFF;
274 RID collision;
275 real_t strength = 1.0;
276 real_t attenuation = 1.0;
277 real_t directionality = 0.0;
278
279 protected:
280 _FORCE_INLINE_ RID _get_collision() { return collision; }
281 static void _bind_methods();
282
283 GPUParticlesAttractor3D(RS::ParticlesCollisionType p_type);
284
285 public:
286 void set_cull_mask(uint32_t p_cull_mask);
287 uint32_t get_cull_mask() const;
288
289 void set_strength(real_t p_strength);
290 real_t get_strength() const;
291
292 void set_attenuation(real_t p_attenuation);
293 real_t get_attenuation() const;
294
295 void set_directionality(real_t p_directionality);
296 real_t get_directionality() const;
297
298 ~GPUParticlesAttractor3D();
299 };
300
301 class GPUParticlesAttractorSphere3D : public GPUParticlesAttractor3D {
302 GDCLASS(GPUParticlesAttractorSphere3D, GPUParticlesAttractor3D);
303
304 real_t radius = 1.0;
305
306 protected:
307 static void _bind_methods();
308
309 public:
310 void set_radius(real_t p_radius);
311 real_t get_radius() const;
312
313 virtual AABB get_aabb() const override;
314
315 GPUParticlesAttractorSphere3D();
316 ~GPUParticlesAttractorSphere3D();
317 };
318
319 class GPUParticlesAttractorBox3D : public GPUParticlesAttractor3D {
320 GDCLASS(GPUParticlesAttractorBox3D, GPUParticlesAttractor3D);
321
322 Vector3 size = Vector3(2, 2, 2);
323
324 protected:
325 static void _bind_methods();
326 #ifndef DISABLE_DEPRECATED
327 bool _set(const StringName &p_name, const Variant &p_value);
328 bool _get(const StringName &p_name, Variant &r_property) const;
329 #endif // DISABLE_DEPRECATED
330
331 public:
332 void set_size(const Vector3 &p_size);
333 Vector3 get_size() const;
334
335 virtual AABB get_aabb() const override;
336
337 GPUParticlesAttractorBox3D();
338 ~GPUParticlesAttractorBox3D();
339 };
340
341 class GPUParticlesAttractorVectorField3D : public GPUParticlesAttractor3D {
342 GDCLASS(GPUParticlesAttractorVectorField3D, GPUParticlesAttractor3D);
343
344 Vector3 size = Vector3(2, 2, 2);
345 Ref<Texture3D> texture;
346
347 protected:
348 static void _bind_methods();
349 #ifndef DISABLE_DEPRECATED
350 bool _set(const StringName &p_name, const Variant &p_value);
351 bool _get(const StringName &p_name, Variant &r_property) const;
352 #endif // DISABLE_DEPRECATED
353
354 public:
355 void set_size(const Vector3 &p_size);
356 Vector3 get_size() const;
357
358 void set_texture(const Ref<Texture3D> &p_texture);
359 Ref<Texture3D> get_texture() const;
360
361 virtual AABB get_aabb() const override;
362
363 GPUParticlesAttractorVectorField3D();
364 ~GPUParticlesAttractorVectorField3D();
365 };