0.2.0-dev Download ZIP
225 lines ·7.9 KB Raw
| 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 | #pragma once |
| 32 | |
| 33 | #include "scene/3d/visual_instance_3d.h" |
| 34 | #include "scene/resources/3d/skin.h" |
| 35 | |
| 36 | class Mesh; |
| 37 | |
| 38 | class GPUParticles3D : public GeometryInstance3D { |
| 39 | private: |
| 40 | GDCLASS(GPUParticles3D, GeometryInstance3D); |
| 41 | |
| 42 | public: |
| 43 | enum DrawOrder { |
| 44 | DRAW_ORDER_INDEX, |
| 45 | DRAW_ORDER_LIFETIME, |
| 46 | DRAW_ORDER_REVERSE_LIFETIME, |
| 47 | DRAW_ORDER_VIEW_DEPTH, |
| 48 | }; |
| 49 | |
| 50 | enum TransformAlign { |
| 51 | TRANSFORM_ALIGN_DISABLED = RSE::PARTICLES_TRANSFORM_ALIGN_DISABLED, |
| 52 | TRANSFORM_ALIGN_Z_BILLBOARD = RSE::PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD, |
| 53 | TRANSFORM_ALIGN_Y_TO_VELOCITY = RSE::PARTICLES_TRANSFORM_ALIGN_Y_TO_VELOCITY, |
| 54 | TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY = RSE::PARTICLES_TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY, |
| 55 | TRANSFORM_ALIGN_LOCAL_BILLBOARD = RSE::PARTICLES_TRANSFORM_ALIGN_LOCAL_BILLBOARD, |
| 56 | }; |
| 57 | |
| 58 | enum { |
| 59 | MAX_DRAW_PASSES = 4 |
| 60 | }; |
| 61 | |
| 62 | private: |
| 63 | RID particles; |
| 64 | |
| 65 | bool emitting = false; |
| 66 | bool active = false; |
| 67 | bool signal_canceled = false; |
| 68 | bool one_shot = false; |
| 69 | int amount = 0; |
| 70 | float amount_ratio = 1.0; |
| 71 | double lifetime = 0.0; |
| 72 | double pre_process_time = 0.0; |
| 73 | real_t explosiveness_ratio = 0.0; |
| 74 | real_t randomness_ratio = 0.0; |
| 75 | double speed_scale = 0.0; |
| 76 | AABB visibility_aabb; |
| 77 | bool local_coords = false; |
| 78 | int fixed_fps = 0; |
| 79 | bool fractional_delta = false; |
| 80 | bool interpolate = true; |
| 81 | NodePath sub_emitter; |
| 82 | real_t collision_base_size = 0.01; |
| 83 | uint32_t seed = 0; |
| 84 | bool use_fixed_seed = false; |
| 85 | |
| 86 | bool trail_enabled = false; |
| 87 | double trail_lifetime = 0.3; |
| 88 | |
| 89 | TransformAlign transform_align = TRANSFORM_ALIGN_DISABLED; |
| 90 | RSE::ParticlesTransformAlignCustomSrc transform_align_channel_filter = RSE::ParticlesTransformAlignCustomSrc::PARTICLES_ALIGN_CHANNEL_FILTER_X; |
| 91 | RSE::ParticlesTransformAlignAxis transform_align_axis = RSE::ParticlesTransformAlignAxis::PARTICLES_ALIGN_AXIS_Y; |
| 92 | bool transform_align_use_velocity = true; |
| 93 | |
| 94 | Ref<Material> process_material; |
| 95 | |
| 96 | DrawOrder draw_order = DRAW_ORDER_INDEX; |
| 97 | |
| 98 | Vector<Ref<Mesh>> draw_passes; |
| 99 | Ref<Skin> skin; |
| 100 | |
| 101 | double time = 0.0; |
| 102 | double emission_time = 0.0; |
| 103 | double active_time = 0.0; |
| 104 | float interp_to_end_factor = 0; |
| 105 | Vector3 previous_velocity; |
| 106 | Vector3 previous_position; |
| 107 | |
| 108 | void _attach_sub_emitter(); |
| 109 | |
| 110 | void _skinning_changed(); |
| 111 | |
| 112 | protected: |
| 113 | static void _bind_methods(); |
| 114 | void _notification(int p_what); |
| 115 | void _validate_property(PropertyInfo &p_property) const; |
| 116 | |
| 117 | #ifndef DISABLE_DEPRECATED |
| 118 | void _restart_bind_compat_92089(); |
| 119 | void _request_particles_process_bind_compat_109142(real_t p_time); |
| 120 | static void _bind_compatibility_methods(); |
| 121 | #endif |
| 122 | |
| 123 | public: |
| 124 | AABB get_aabb() const override; |
| 125 | |
| 126 | void set_emitting(bool p_emitting); |
| 127 | void set_amount(int p_amount); |
| 128 | void set_lifetime(double p_lifetime); |
| 129 | void set_one_shot(bool p_one_shot); |
| 130 | void set_pre_process_time(double p_time); |
| 131 | void set_explosiveness_ratio(real_t p_ratio); |
| 132 | void set_randomness_ratio(real_t p_ratio); |
| 133 | void set_visibility_aabb(const AABB &p_aabb); |
| 134 | void set_use_local_coordinates(bool p_enable); |
| 135 | void set_process_material(const Ref<Material> &p_material); |
| 136 | void set_speed_scale(double p_scale); |
| 137 | void set_collision_base_size(real_t p_ratio); |
| 138 | void set_trail_enabled(bool p_enabled); |
| 139 | void set_trail_lifetime(double p_seconds); |
| 140 | void set_interp_to_end(float p_interp); |
| 141 | |
| 142 | bool is_emitting() const; |
| 143 | int get_amount() const; |
| 144 | |
| 145 | double get_lifetime() const; |
| 146 | bool get_one_shot() const; |
| 147 | double get_pre_process_time() const; |
| 148 | real_t get_explosiveness_ratio() const; |
| 149 | real_t get_randomness_ratio() const; |
| 150 | AABB get_visibility_aabb() const; |
| 151 | bool get_use_local_coordinates() const; |
| 152 | Ref<Material> get_process_material() const; |
| 153 | double get_speed_scale() const; |
| 154 | real_t get_collision_base_size() const; |
| 155 | bool is_trail_enabled() const; |
| 156 | double get_trail_lifetime() const; |
| 157 | float get_interp_to_end() const; |
| 158 | |
| 159 | void set_amount_ratio(float p_ratio); |
| 160 | float get_amount_ratio() const; |
| 161 | |
| 162 | void set_fixed_fps(int p_count); |
| 163 | int get_fixed_fps() const; |
| 164 | |
| 165 | void set_fractional_delta(bool p_enable); |
| 166 | bool get_fractional_delta() const; |
| 167 | |
| 168 | void set_interpolate(bool p_enable); |
| 169 | bool get_interpolate() const; |
| 170 | |
| 171 | void set_draw_order(DrawOrder p_order); |
| 172 | DrawOrder get_draw_order() const; |
| 173 | |
| 174 | void set_draw_passes(int p_count); |
| 175 | int get_draw_passes() const; |
| 176 | |
| 177 | void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh); |
| 178 | Ref<Mesh> get_draw_pass_mesh(int p_pass) const; |
| 179 | |
| 180 | PackedStringArray get_configuration_warnings() const override; |
| 181 | |
| 182 | void set_sub_emitter(const NodePath &p_path); |
| 183 | NodePath get_sub_emitter() const; |
| 184 | |
| 185 | void set_skin(const Ref<Skin> &p_skin); |
| 186 | Ref<Skin> get_skin() const; |
| 187 | |
| 188 | void set_transform_align(TransformAlign p_align); |
| 189 | TransformAlign get_transform_align() const; |
| 190 | |
| 191 | void set_transform_align_channel_filter(RSE::ParticlesTransformAlignCustomSrc p_align_channel_filter); |
| 192 | RSE::ParticlesTransformAlignCustomSrc get_transform_align_channel_filter() const; |
| 193 | |
| 194 | void set_transform_align_axis(RSE::ParticlesTransformAlignAxis p_axis); |
| 195 | RSE::ParticlesTransformAlignAxis get_transform_align_axis() const; |
| 196 | |
| 197 | void restart(bool p_keep_seed = false); |
| 198 | |
| 199 | void set_use_fixed_seed(bool p_use_fixed_seed); |
| 200 | bool get_use_fixed_seed() const; |
| 201 | |
| 202 | void set_seed(uint32_t p_seed); |
| 203 | uint32_t get_seed() const; |
| 204 | void request_particles_process(real_t p_requested_process_time, real_t p_request_process_time_residual = 0.0f); |
| 205 | |
| 206 | enum EmitFlags { |
| 207 | EMIT_FLAG_POSITION = RSE::PARTICLES_EMIT_FLAG_POSITION, |
| 208 | EMIT_FLAG_ROTATION_SCALE = RSE::PARTICLES_EMIT_FLAG_ROTATION_SCALE, |
| 209 | EMIT_FLAG_VELOCITY = RSE::PARTICLES_EMIT_FLAG_VELOCITY, |
| 210 | EMIT_FLAG_COLOR = RSE::PARTICLES_EMIT_FLAG_COLOR, |
| 211 | EMIT_FLAG_CUSTOM = RSE::PARTICLES_EMIT_FLAG_CUSTOM |
| 212 | }; |
| 213 | |
| 214 | void emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags); |
| 215 | |
| 216 | AABB capture_aabb() const; |
| 217 | void convert_from_particles(Node *p_particles); |
| 218 | |
| 219 | GPUParticles3D(); |
| 220 | ~GPUParticles3D(); |
| 221 | }; |
| 222 | |
| 223 | VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder) |
| 224 | VARIANT_ENUM_CAST(GPUParticles3D::TransformAlign) |
| 225 | VARIANT_ENUM_CAST(GPUParticles3D::EmitFlags) |