载入中...
搜索中...
未找到
MeshParticleEmitter.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "graphics/Color.h"
6
7#include <glm/mat4x4.hpp>
8#include <glm/vec3.hpp>
9
10#include <cstdint>
11#include <span>
12#include <vector>
13
14namespace eve::stylize {
15
17enum class MeshParticleShape : std::uint8_t { Point, Sphere, Box, Cone };
18
21 float timeSeconds = 0.f;
22 std::uint32_t count = 0;
23};
24
27 float time = 0.f;
28 float value = 1.f;
29};
30
33 float time = 0.f;
35};
36
39 std::uint32_t capacity = 1024;
40 float emissionRate = 0.f;
41 float lifetimeMin = 1.f;
42 float lifetimeMax = 1.f;
43 float speedMin = 0.f;
44 float speedMax = 0.f;
45 glm::vec3 direction{0.f, 1.f, 0.f};
47 glm::vec3 boxExtents{0.5f};
48 float sphereRadius = 0.5f;
49 float coneAngleRadians = 0.5f;
50 glm::vec3 gravity{0.f};
51 float damping = 0.f;
52 float rotationMinRadians = 0.f;
53 float rotationMaxRadians = 0.f;
54 float angularVelocityMin = 0.f;
55 float angularVelocityMax = 0.f;
56 float scaleStart = 1.f;
57 float scaleEnd = 0.f;
59 graphics::Color colorEnd{1.f, 1.f, 1.f, 0.f};
61 std::vector<MeshParticleScalarKey> scaleCurve;
63 std::vector<MeshParticleScalarKey> velocityCurve;
65 std::vector<MeshParticleColorKey> colorGradient;
66 float fixedStepSeconds = 1.f / 60.f;
67 std::uint32_t maximumSubsteps = 8;
68 std::uint32_t randomSeed = 1;
70 bool looping = false;
71 std::vector<MeshParticleBurst> bursts;
72};
73
76 std::uint64_t stableId = 0;
77 glm::mat4 model{1.f};
79 float normalizedAge = 0.f;
80};
81
84 std::uint32_t simulatedSteps = 0;
85 std::uint32_t spawned = 0;
86 std::uint32_t expired = 0;
87 std::uint32_t dropped = 0;
88 std::uint32_t alive = 0;
90};
91
101public:
104
107
108 // Class-level dllexport instantiates every member, and the implicitly declared
109 // copy assignment would instantiate `std::vector<Particle>::operator=`, which
110 // needs a complete `Particle` -- but `Particle` is only forward declared here
111 // (defined in the .cpp), so that is `error C2036: unknown size` in every TU that
112 // includes this header. A user-declared destructor does *not* suppress the
113 // implicit copy assignment. The emitter owns live particle state and was never
114 // copied anywhere in the tree, so deleting the copy operations preserves the
115 // existing semantics without requiring the private type to be complete.
118
120 void start();
121
123 void stop() noexcept { emitting_ = false; }
124
126 void reset();
127
129 void setOrigin(const glm::vec3& origin) noexcept { origin_ = origin; }
130
136 [[nodiscard]] std::uint32_t emit(std::uint32_t count);
137
143 [[nodiscard]] MeshParticleAdvanceReport advance(float deltaSeconds);
144
146 [[nodiscard]] std::vector<MeshParticleInstance> snapshot() const;
147
149 [[nodiscard]] const MeshParticleEmitterConfig& config() const noexcept { return config_; }
150
152 [[nodiscard]] std::size_t size() const noexcept;
153
154private:
155 struct Particle;
156
157 void simulateStep(float dt, MeshParticleAdvanceReport& report);
158 [[nodiscard]] std::uint32_t spawn(std::uint32_t count, MeshParticleAdvanceReport* report);
159 [[nodiscard]] float randomUnit();
160 [[nodiscard]] glm::vec3 randomDirection();
161 [[nodiscard]] glm::vec3 spawnOffset();
162
164 std::vector<Particle> particles_;
165 glm::vec3 origin_{0.f};
166 std::uint32_t randomState_ = 1;
167 std::uint64_t nextStableId_ = 1;
168 float accumulator_ = 0.f;
169 float timeline_ = 0.f;
170 float emissionAccumulator_ = 0.f;
171 std::size_t nextBurst_ = 0;
172 bool emitting_ = false;
173};
174
175} // namespace eve::stylize
Duration start
#define EVENGINE_API_WORLD
Definition Export.h:109
V3 origin
Definition RoadBake.cpp:138
std::uint32_t count
float size
Definition TreeMesh.cpp:156
CPU-authoritative deterministic 3D mesh-particle emitter.
void setOrigin(const glm::vec3 &origin) noexcept
Set the world-space origin copied by subsequent simulation steps.
const MeshParticleEmitterConfig & config() const noexcept
Return immutable sanitized configuration.
MeshParticleEmitter & operator=(const MeshParticleEmitter &)=delete
void stop() noexcept
Stop automatic emission while allowing existing particles to expire.
~MeshParticleEmitter()
Destroy owned particle state after its private type is complete.
MeshParticleEmitter(const MeshParticleEmitter &)=delete
eve::Color Color
RGBA color used by every graphics draw call. Lives inside eve::graphics so including a graphics heade...
Definition Color.h:13
MeshParticleShape
Built-in volume used to place and orient newly spawned mesh particles.
Observable result of advancing one mesh-particle emitter.
One repeatable emission event on an emitter timeline.
One normalized-time color key used by mesh-particle gradients.
Deterministic simulation and emission settings for a 3D mesh emitter.
std::vector< MeshParticleBurst > bursts
std::vector< MeshParticleScalarKey > velocityCurve
Optional normalized-age velocity multiplier; empty evaluates to one.
std::vector< MeshParticleScalarKey > scaleCurve
Optional normalized-age scale multiplier; empty uses scaleStart/scaleEnd.
std::vector< MeshParticleColorKey > colorGradient
Optional normalized-age color gradient; empty uses colorStart/colorEnd.
Render-facing immutable state of one live mesh particle.
One normalized-time scalar key used by mesh-particle lifetime curves.