2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
2020-03-26 22:49:16 +01:00
|
|
|
/* gpu_particles_3d.h */
|
2014-02-10 02:10:30 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#ifndef GPU_PARTICLES_3D_H
|
|
|
|
#define GPU_PARTICLES_3D_H
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
2021-04-27 17:43:49 +02:00
|
|
|
#include "scene/resources/skin.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
class GPUParticles3D : public GeometryInstance3D {
|
2017-04-07 04:36:37 +02:00
|
|
|
private:
|
2020-03-26 22:49:16 +01:00
|
|
|
GDCLASS(GPUParticles3D, GeometryInstance3D);
|
2017-04-07 04:36:37 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2017-04-07 04:36:37 +02:00
|
|
|
enum DrawOrder {
|
|
|
|
DRAW_ORDER_INDEX,
|
|
|
|
DRAW_ORDER_LIFETIME,
|
2021-05-20 16:25:06 +02:00
|
|
|
DRAW_ORDER_REVERSE_LIFETIME,
|
2017-04-07 04:36:37 +02:00
|
|
|
DRAW_ORDER_VIEW_DEPTH,
|
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-04-27 17:43:49 +02:00
|
|
|
enum TransformAlign {
|
|
|
|
TRANSFORM_ALIGN_DISABLED,
|
|
|
|
TRANSFORM_ALIGN_Z_BILLBOARD,
|
|
|
|
TRANSFORM_ALIGN_Y_TO_VELOCITY,
|
|
|
|
TRANSFORM_ALIGN_Z_BILLBOARD_Y_TO_VELOCITY
|
|
|
|
};
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
enum {
|
|
|
|
MAX_DRAW_PASSES = 4
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
RID particles;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2023-05-08 21:11:34 +02:00
|
|
|
bool emitting = false;
|
|
|
|
bool active = false;
|
2023-09-12 08:54:18 +02:00
|
|
|
bool signal_canceled = false;
|
2023-05-08 21:11:34 +02:00
|
|
|
bool one_shot = false;
|
2022-05-02 16:28:25 +02:00
|
|
|
int amount = 0;
|
2023-08-13 13:08:52 +02:00
|
|
|
float amount_ratio = 1.0;
|
2022-05-02 16:28:25 +02:00
|
|
|
double lifetime = 0.0;
|
|
|
|
double pre_process_time = 0.0;
|
|
|
|
real_t explosiveness_ratio = 0.0;
|
|
|
|
real_t randomness_ratio = 0.0;
|
|
|
|
double speed_scale = 0.0;
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB visibility_aabb;
|
2022-05-02 16:28:25 +02:00
|
|
|
bool local_coords = false;
|
|
|
|
int fixed_fps = 0;
|
|
|
|
bool fractional_delta = false;
|
2021-04-27 17:43:49 +02:00
|
|
|
bool interpolate = true;
|
2020-09-06 14:18:10 +02:00
|
|
|
NodePath sub_emitter;
|
2021-08-12 16:07:47 +02:00
|
|
|
real_t collision_base_size = 0.01;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2021-04-27 17:43:49 +02:00
|
|
|
bool trail_enabled = false;
|
2022-11-06 21:57:08 +01:00
|
|
|
double trail_lifetime = 0.3;
|
2021-04-27 17:43:49 +02:00
|
|
|
|
|
|
|
TransformAlign transform_align = TRANSFORM_ALIGN_DISABLED;
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
Ref<Material> process_material;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2022-11-08 07:40:03 +01:00
|
|
|
DrawOrder draw_order = DRAW_ORDER_INDEX;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-03-17 07:33:00 +01:00
|
|
|
Vector<Ref<Mesh>> draw_passes;
|
2021-04-27 17:43:49 +02:00
|
|
|
Ref<Skin> skin;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2023-05-08 21:11:34 +02:00
|
|
|
double time = 0.0;
|
|
|
|
double emission_time = 0.0;
|
|
|
|
double active_time = 0.0;
|
2023-08-13 13:08:52 +02:00
|
|
|
float interp_to_end_factor = 0;
|
2023-12-23 18:04:24 +01:00
|
|
|
Vector3 previous_velocity;
|
2023-08-13 13:08:52 +02:00
|
|
|
Vector3 previous_position;
|
2023-05-08 21:11:34 +02:00
|
|
|
|
2020-09-06 14:18:10 +02:00
|
|
|
void _attach_sub_emitter();
|
|
|
|
|
2021-04-27 17:43:49 +02:00
|
|
|
void _skinning_changed();
|
|
|
|
|
2016-03-09 00:00:52 +01:00
|
|
|
protected:
|
2014-02-10 02:10:30 +01:00
|
|
|
static void _bind_methods();
|
2017-08-08 00:01:30 +02:00
|
|
|
void _notification(int p_what);
|
2022-08-12 22:57:11 +02:00
|
|
|
void _validate_property(PropertyInfo &p_property) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
public:
|
2020-07-10 12:34:39 +02:00
|
|
|
AABB get_aabb() const override;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_emitting(bool p_emitting);
|
2014-02-10 02:10:30 +01:00
|
|
|
void set_amount(int p_amount);
|
2021-02-02 03:16:37 +01:00
|
|
|
void set_lifetime(double p_lifetime);
|
2017-08-11 21:10:05 +02:00
|
|
|
void set_one_shot(bool p_one_shot);
|
2021-02-02 03:16:37 +01:00
|
|
|
void set_pre_process_time(double p_time);
|
2021-08-12 16:07:47 +02:00
|
|
|
void set_explosiveness_ratio(real_t p_ratio);
|
|
|
|
void set_randomness_ratio(real_t p_ratio);
|
2017-11-17 03:09:00 +01:00
|
|
|
void set_visibility_aabb(const AABB &p_aabb);
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_use_local_coordinates(bool p_enable);
|
|
|
|
void set_process_material(const Ref<Material> &p_material);
|
2021-02-02 03:16:37 +01:00
|
|
|
void set_speed_scale(double p_scale);
|
2021-08-12 16:07:47 +02:00
|
|
|
void set_collision_base_size(real_t p_ratio);
|
2021-05-20 16:25:06 +02:00
|
|
|
void set_trail_enabled(bool p_enabled);
|
2022-11-06 21:57:08 +01:00
|
|
|
void set_trail_lifetime(double p_seconds);
|
2023-08-13 13:08:52 +02:00
|
|
|
void set_interp_to_end(float p_interp);
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool is_emitting() const;
|
2017-04-07 04:36:37 +02:00
|
|
|
int get_amount() const;
|
2023-08-13 13:08:52 +02:00
|
|
|
|
2021-02-02 03:16:37 +01:00
|
|
|
double get_lifetime() const;
|
2017-06-25 13:01:15 +02:00
|
|
|
bool get_one_shot() const;
|
2021-02-02 03:16:37 +01:00
|
|
|
double get_pre_process_time() const;
|
2021-08-12 16:07:47 +02:00
|
|
|
real_t get_explosiveness_ratio() const;
|
|
|
|
real_t get_randomness_ratio() const;
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB get_visibility_aabb() const;
|
2017-04-07 04:36:37 +02:00
|
|
|
bool get_use_local_coordinates() const;
|
|
|
|
Ref<Material> get_process_material() const;
|
2021-02-02 03:16:37 +01:00
|
|
|
double get_speed_scale() const;
|
2021-08-12 16:07:47 +02:00
|
|
|
real_t get_collision_base_size() const;
|
2021-04-27 17:43:49 +02:00
|
|
|
bool is_trail_enabled() const;
|
2022-11-06 21:57:08 +01:00
|
|
|
double get_trail_lifetime() const;
|
2023-08-13 13:08:52 +02:00
|
|
|
float get_interp_to_end() const;
|
|
|
|
|
|
|
|
void set_amount_ratio(float p_ratio);
|
|
|
|
float get_amount_ratio() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_fixed_fps(int p_count);
|
|
|
|
int get_fixed_fps() const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_fractional_delta(bool p_enable);
|
|
|
|
bool get_fractional_delta() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-04-27 17:43:49 +02:00
|
|
|
void set_interpolate(bool p_enable);
|
|
|
|
bool get_interpolate() const;
|
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_draw_order(DrawOrder p_order);
|
|
|
|
DrawOrder get_draw_order() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_draw_passes(int p_count);
|
|
|
|
int get_draw_passes() const;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-04-07 04:36:37 +02:00
|
|
|
void set_draw_pass_mesh(int p_pass, const Ref<Mesh> &p_mesh);
|
|
|
|
Ref<Mesh> get_draw_pass_mesh(int p_pass) const;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2024-02-17 19:03:21 +01:00
|
|
|
PackedStringArray get_configuration_warnings() const override;
|
2017-04-09 03:38:11 +02:00
|
|
|
|
2020-09-06 14:18:10 +02:00
|
|
|
void set_sub_emitter(const NodePath &p_path);
|
|
|
|
NodePath get_sub_emitter() const;
|
|
|
|
|
2021-04-27 17:43:49 +02:00
|
|
|
void set_skin(const Ref<Skin> &p_skin);
|
|
|
|
Ref<Skin> get_skin() const;
|
|
|
|
|
|
|
|
void set_transform_align(TransformAlign p_align);
|
|
|
|
TransformAlign get_transform_align() const;
|
|
|
|
|
2017-06-25 13:01:15 +02:00
|
|
|
void restart();
|
|
|
|
|
2020-09-06 14:18:10 +02:00
|
|
|
enum EmitFlags {
|
|
|
|
EMIT_FLAG_POSITION = RS::PARTICLES_EMIT_FLAG_POSITION,
|
|
|
|
EMIT_FLAG_ROTATION_SCALE = RS::PARTICLES_EMIT_FLAG_ROTATION_SCALE,
|
|
|
|
EMIT_FLAG_VELOCITY = RS::PARTICLES_EMIT_FLAG_VELOCITY,
|
|
|
|
EMIT_FLAG_COLOR = RS::PARTICLES_EMIT_FLAG_COLOR,
|
|
|
|
EMIT_FLAG_CUSTOM = RS::PARTICLES_EMIT_FLAG_CUSTOM
|
|
|
|
};
|
|
|
|
|
2020-10-17 07:08:21 +02:00
|
|
|
void emit_particle(const Transform3D &p_transform, const Vector3 &p_velocity, const Color &p_color, const Color &p_custom, uint32_t p_emit_flags);
|
2020-09-06 14:18:10 +02:00
|
|
|
|
2017-11-17 03:09:00 +01:00
|
|
|
AABB capture_aabb() const;
|
2023-08-19 10:55:49 +02:00
|
|
|
void convert_from_particles(Node *p_particles);
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
GPUParticles3D();
|
|
|
|
~GPUParticles3D();
|
2017-04-07 04:36:37 +02:00
|
|
|
};
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
VARIANT_ENUM_CAST(GPUParticles3D::DrawOrder)
|
2021-04-27 17:43:49 +02:00
|
|
|
VARIANT_ENUM_CAST(GPUParticles3D::TransformAlign)
|
2020-09-06 14:18:10 +02:00
|
|
|
VARIANT_ENUM_CAST(GPUParticles3D::EmitFlags)
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-23 23:41:51 +02:00
|
|
|
#endif // GPU_PARTICLES_3D_H
|