Unravel Engine C++ Reference
Loading...
Searching...
No Matches
particle_emitter_component.h
Go to the documentation of this file.
1#pragma once
2
5#include <graphics/texture.h>
7#include <bx/easing.h>
8#include <glm/vec3.hpp>
9#include <math/math.h>
10#include <base/basetypes.hpp>
11#include <array>
12
13
14namespace unravel
15{
16
21class particle_emitter_component : public component_crtp<particle_emitter_component, owned_component>
22{
23public:
29 static void on_create_component(entt::registry& r, entt::entity e);
30
36 static void on_destroy_component(entt::registry& r, entt::entity e);
37
42 void set_enabled(bool enabled);
43
48 auto is_enabled() const -> bool;
49
54 auto get_emitter_handle() const -> EmitterHandle;
55
61
66 auto get_shape() const -> EmitterShape::Enum;
67
73
79
84 void set_max_particles(uint32_t max_particles);
85
90 auto get_max_particles() const -> uint32_t;
91
92
93 // Particle emission properties
94 void set_emission_lifetime(std::chrono::duration<float> lifetime);
95 auto get_emission_lifetime() const -> std::chrono::duration<float>;
96
97 void set_gravity_scale(float scale);
98 auto get_gravity_scale() const -> float;
99
100 void set_emission_rate(float emission_rate);
101 auto get_emission_rate() const -> float;
102
103 void set_temporal_motion(float temporal_motion);
104 auto get_temporal_motion() const -> float;
105
106 void set_velocity_damping(float velocity_damping);
107 auto get_velocity_damping() const -> float;
108
109 void set_force_over_lifetime(const math::vec3& force);
110 auto get_force_over_lifetime() const -> math::vec3;
111
112 void set_emission_shape_scale(const math::vec3& scale);
113 auto get_emission_shape_scale() const -> math::vec3;
114
115 void set_size_by_speed_range(const frange_t& size_range);
116 auto get_size_by_speed_range() const -> const frange_t&;
117
118 void set_size_by_speed_velocity_range(const frange_t& velocity_range);
119 auto get_size_by_speed_velocity_range() const -> const frange_t&;
120
123
124 void set_color_by_speed_velocity_range(const frange_t& velocity_range);
125 auto get_color_by_speed_velocity_range() const -> const frange_t&;
126
129
130 void set_lifetime_by_emitter_speed_range(const frange_t& speed_range);
131 auto get_lifetime_by_emitter_speed_range() const -> const frange_t&;
132
133 // Lifetime properties
134 void set_lifetime(std::chrono::duration<float> lifetime);
135 auto get_lifetime() const -> std::chrono::duration<float>;
136
137 // Velocity properties
139 auto get_velocity_gradient() const -> const math::gradient<frange_t>&;
140
141 // Scale properties
142 void set_scale_gradient(const math::gradient<frange_t>& gradient);
143 auto get_scale_gradient() const -> const math::gradient<frange_t>&;
144
145 // Blend properties
146 void set_blend_gradient(const math::gradient<frange_t>& gradient);
147 auto get_blend_gradient() const -> const math::gradient<frange_t>&;
148
149 void set_blend_multiplier(float multiplier);
150 auto get_blend_multiplier() const -> float;
151
152 // Playback control
153 void play();
154 void stop();
155 void stop_and_reset();
156 void pause();
157 void resume();
158 auto is_playing() const -> bool;
159 auto is_paused() const -> bool;
160
161 // Loop control
162 void set_loop(bool loop);
163 auto is_loop() const -> bool;
164
165 // Color properties
167 auto get_color_gradient() const -> const math::gradient<math::color>&;
168
169 // Easing functions (only position easing remains - others handled by gradients)
170 void set_position_easing(bx::Easing::Enum easing);
171 auto get_position_easing() const -> bx::Easing::Enum;
172
173 // Simulation method properties
176
177 auto get_num_particles() const -> uint32_t;
178 auto get_world_bounds() const -> math::bbox;
179 auto get_updated_world_bounds(const math::transform& world_transform) const -> math::bbox;
180
181 // Sprite handle
182 void set_texture(const asset_handle<gfx::texture>& texture);
183 auto get_texture() const -> const asset_handle<gfx::texture>&;
184
189 void update_emitter(const math::transform& world_transform, delta_t dt);
190
195 auto get_uniforms() const -> const EmitterUniforms&;
196
200 void recreate_emitter();
201
205 void reset_emitter();
206
207private:
209 bool enabled_ = true;
210
213
216
218 uint32_t max_particles_ = 1024;
219
221 EmitterHandle emitter_handle_{UINT16_MAX};
222
224 EmitterUniforms uniforms_;
225
227};
228
229} // namespace unravel
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
Component that wraps particle system emitter functionality.
auto get_texture() const -> const asset_handle< gfx::texture > &
auto get_size_by_speed_range() const -> const frange_t &
void set_blend_gradient(const math::gradient< frange_t > &gradient)
void set_size_by_speed_range(const frange_t &size_range)
void set_color_by_speed_velocity_range(const frange_t &velocity_range)
void set_shape(EmitterShape::Enum shape)
Sets the emitter shape.
auto get_color_by_speed_velocity_range() const -> const frange_t &
void set_texture(const asset_handle< gfx::texture > &texture)
auto get_uniforms() const -> const EmitterUniforms &
Gets the emitter uniforms for direct access.
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
auto get_simulation_space() const -> SimulationSpace::Enum
void recreate_emitter()
Recreates the emitter with current shape and direction.
void set_lifetime(std::chrono::duration< float > lifetime)
auto get_max_particles() const -> uint32_t
Gets the maximum number of particles.
void update_emitter(const math::transform &world_transform, delta_t dt)
Updates the emitter with external transform data.
void set_color_by_speed_gradient(const math::gradient< math::color > &gradient)
auto get_lifetime_by_emitter_speed_gradient() const -> const math::gradient< float > &
void set_size_by_speed_velocity_range(const frange_t &velocity_range)
void set_enabled(bool enabled)
Sets whether the emitter is enabled.
void set_direction(EmitterDirection::Enum direction)
Sets the emitter direction.
void set_simulation_space(SimulationSpace::Enum space)
auto get_emitter_handle() const -> EmitterHandle
Gets the emitter handle.
void reset_emitter()
Resets the emitter, clearing all particles and resetting internal state.
void set_position_easing(bx::Easing::Enum easing)
auto get_scale_gradient() const -> const math::gradient< frange_t > &
void set_velocity_gradient(const math::gradient< frange_t > &gradient)
void set_force_over_lifetime(const math::vec3 &force)
void set_emission_shape_scale(const math::vec3 &scale)
auto get_shape() const -> EmitterShape::Enum
Gets the emitter shape.
void set_color_gradient(const math::gradient< math::color > &gradient)
auto is_enabled() const -> bool
Checks if the emitter is enabled.
auto get_direction() const -> EmitterDirection::Enum
Gets the emitter direction.
auto get_color_by_speed_gradient() const -> const math::gradient< math::color > &
auto get_velocity_gradient() const -> const math::gradient< frange_t > &
auto get_lifetime() const -> std::chrono::duration< float >
auto get_updated_world_bounds(const math::transform &world_transform) const -> math::bbox
void set_lifetime_by_emitter_speed_gradient(const math::gradient< float > &gradient)
void set_emission_lifetime(std::chrono::duration< float > lifetime)
auto get_color_gradient() const -> const math::gradient< math::color > &
auto get_blend_gradient() const -> const math::gradient< frange_t > &
auto get_size_by_speed_velocity_range() const -> const frange_t &
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
auto get_emission_lifetime() const -> std::chrono::duration< float >
void set_lifetime_by_emitter_speed_range(const frange_t &speed_range)
void set_scale_gradient(const math::gradient< frange_t > &gradient)
auto get_position_easing() const -> bx::Easing::Enum
auto get_lifetime_by_emitter_speed_range() const -> const frange_t &
void set_max_particles(uint32_t max_particles)
Sets the maximum number of particles.
std::chrono::duration< float > delta_t
float scale
Definition hub.cpp:25
Represents a handle to an asset, providing access and management functions.
Storage for box vector values and wraps up common functionality.
Definition bbox.h:21
CRTP (Curiously Recurring Template Pattern) base structure for components.