1/**************************************************************************/
2/* gpu_particles_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#ifndef GPU_PARTICLES_3D_H
32#define GPU_PARTICLES_3D_H
33
34#include "scene/3d/visual_instance_3d.h"
35#include "scene/resources/skin.h"
36
37class GPUParticles3D : public GeometryInstance3D {
38private:
39 GDCLASS(GPUParticles3D, GeometryInstance3D);
40
41public:
42 enum DrawOrder {
43 DRAW_ORDER_INDEX,
44 DRAW_ORDER_LIFETIME,
45 DRAW_ORDER_REVERSE_LIFETIME,
46 DRAW_ORDER_VIEW_DEPTH,
47 };
48
49 enum TransformAlign {
50 TRANSFORM_ALIGN_DISABLED,
51 TRANSFORM_ALIGN_Z_BILLBOARD,
52 TRANSFORM_ALIGN_Y_TO_VELOCITY,
53 TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY
54 };
55
56 enum {
57 MAX_DRAW_PASSES = 4
58 };
59
60private:
61 RID particles;
62
63 bool emitting = false;
64 bool active = false;
65 bool signal_canceled = false;
66 bool one_shot = false;
67 int amount = 0;
68 double lifetime = 0.0;
69 double pre_process_time = 0.0;
70 real_t explosiveness_ratio = 0.0;
71 real_t randomness_ratio = 0.0;
72 double speed_scale = 0.0;
73 AABB visibility_aabb;
74 bool local_coords = false;
75 int fixed_fps = 0;
76 bool fractional_delta = false;
77 bool interpolate = true;
78 NodePath sub_emitter;
79 real_t collision_base_size = 0.01;
80
81 bool trail_enabled = false;
82 double trail_lifetime = 0.3;
83
84 TransformAlign transform_align = TRANSFORM_ALIGN_DISABLED;
85
86 Ref<Material> process_material;
87
88 DrawOrder draw_order = DRAW_ORDER_INDEX;
89
90 Vector<Ref<Mesh>> draw_passes;
91 Ref<Skin> skin;
92
93 double time = 0.0;
94 double emission_time = 0.0;
95 double active_time = 0.0;
96
97 void _attach_sub_emitter();
98
99 void _skinning_changed();
100
101protected:
102 static void _bind_methods();
103 void _notification(int p_what);
104 void _validate_property(PropertyInfo &p_property) const;
105
106public:
107 AABB get_aabb() const override;
108
109 void set_emitting(bool p_emitting);
110 void set_amount(int p_amount);
111 void set_lifetime(double p_lifetime);
112 void set_one_shot(bool p_one_shot);
113 void set_pre_process_time(double p_time);
114 void set_explosiveness_ratio(real_t p_ratio);
115 void set_randomness_ratio(real_t p_ratio);
116 void set_visibility_aabb(const AABB &p_aabb);
117 void set_use_local_coordinates(bool p_enable);
118 void set_process_material(const Ref<Material> &p_material);
119 void set_speed_scale(double p_scale);
120 void set_collision_base_size(real_t p_ratio);
121 void set_trail_enabled(bool p_enabled);
122 void set_trail_lifetime(double p_seconds);
123
124 bool is_emitting() const;
125 int get_amount() const;
126 double get_lifetime() const;
127 bool get_one_shot() const;
128 double get_pre_process_time() const;
129 real_t get_explosiveness_ratio() const;
130 real_t get_randomness_ratio() const;
131 AABB get_visibility_aabb() const;
132 bool get_use_local_coordinates() const;
133 Ref<Material> get_process_material() const;
134 double get_speed_scale() const;
135 real_t get_collision_base_size() const;
136 bool is_trail_enabled() const;
137 double get_trail_lifetime() const;
138
139 void set_fixed_fps(int p_count);
140 int get_fixed_fps() const;
141
142 void set_fractional_delta(bool p_enable);
143 bool get_fractional_delta() const;
144
145 void set_interpolate(bool p_enable);
146 bool get_interpolate() const;
147
148 void set_draw_order(DrawOrder p_order);
149 DrawOrder get_draw_order() const;
150
151 void set_draw_passes(int p_count);
152 int get_draw_passes() const;
153
154 void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh);
155 Ref<Mesh> get_draw_pass_mesh(int p_pass) const;
156
157 PackedStringArray get_configuration_warnings() const override;
158
159 void set_sub_emitter(const NodePath &p_path);
160 NodePath get_sub_emitter() const;
161
162 void set_skin(const Ref<Skin> &p_skin);
163 Ref<Skin> get_skin() const;
164
165 void set_transform_align(TransformAlign p_align);
166 TransformAlign get_transform_align() const;
167
168 void restart();
169
170 enum EmitFlags {
171 EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION,
172 EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE,
173 EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY,
174 EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR,
175 EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM
176 };
177
178 void emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
179
180 AABB capture_aabb() const;
181 void convert_from_particles(Node *p_particles);
182
183 GPUParticles3D();
184 ~GPUParticles3D();
185};
186
187VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder)
188VARIANT_ENUM_CAST(GPUParticles3D::TransformAlign)
189VARIANT_ENUM_CAST(GPUParticles3D::EmitFlags)
190
191#endif // GPU_PARTICLES_3D_H
192