载入中...
搜索中...
未找到
ParticleEmitter.cpp
浏览该文件的文档.
4
11#include "common/Module.h"
12#include "common/ParticleSdf.h"
13#include "graphics/Canvas.h"
15#include "graphics/Graphics.h"
16#include "graphics/Texture.h"
17#include "ik/Skeleton2D.h"
18#include "ik/Skeleton3D.h"
19
20#include <cmath>
21#include <cstdio>
22#include <random>
23#include <string>
24
25namespace eve::particles {
26
27namespace {
28constexpr float kPi = 3.14159265358979323846f;
29constexpr float kEps = 1e-6f;
30
31float randRange(std::mt19937 &rng, float a, float b) {
32 if (a == b) return a;
33 std::uniform_real_distribution<float> dist(a, b);
34 return dist(rng);
35}
36
37int randIndex(std::mt19937 &rng, int n) {
38 if (n <= 1) return 0;
39 std::uniform_int_distribution<int> dist(0, n - 1);
40 return dist(rng);
41}
42
43float hashNoise2(int ix, int iy) {
44 unsigned h = unsigned(ix) * 374761393u + unsigned(iy) * 668265263u;
45 h = (h ^ (h >> 13)) * 1274126177u;
46 return (float((h ^ (h >> 16)) & 0xFFFFFFu) / float(0x1000000u)) * 2.f - 1.f;
47}
48
50float smoothNoise2(float x, float y) {
51 const int ix = int(std::floor(x));
52 const int iy = int(std::floor(y));
53 const float fx = x - float(ix);
54 const float fy = y - float(iy);
55 const float sx = fx * fx * (3.f - 2.f * fx);
56 const float sy = fy * fy * (3.f - 2.f * fy);
57 const float n00 = hashNoise2(ix, iy);
58 const float n10 = hashNoise2(ix + 1, iy);
59 const float n01 = hashNoise2(ix, iy + 1);
60 const float n11 = hashNoise2(ix + 1, iy + 1);
61 const float a = n00 + (n10 - n00) * sx;
62 const float b = n01 + (n11 - n01) * sx;
63 return a + (b - a) * sy;
64}
65
66std::string normalizePlane(const std::string &plane) {
67 if (plane == "xz" || plane == "yz") return plane;
68 return "xy";
69}
70
71const char* gpuFeatureFallbackReason(const ParticleEmitter::Config& cfg, const ParticleEmitter::Draw& draw) {
72 if (draw.canvas != nullptr) return "canvas";
73 if (draw.shader != nullptr) return "custom_shader";
74 if (cfg.sdfField != nullptr) return "sdf";
75 if (cfg.collisionMode != "none" || cfg.collisionBoundsEnabled || cfg.worldCollision)
76 return "collision";
77 if (!cfg.forceFields.empty()) return "force_fields";
78 if (!cfg.subEmitters.empty()) return "sub_emitters";
79 if (cfg.lights.enabled) return "particle_lights";
80 if (!cfg.velocityCurve.empty() || !cfg.sizeCurve.empty() || !cfg.rotationCurve.empty() ||
81 !cfg.colorGradient.empty())
82 return "curves";
83 if (cfg.materialMode == "distortion") return "distortion_material";
84 if (cfg.materialMode != "unlit") return "lit_material";
85 return "";
86}
87
88void projectToPlane(float x, float y, float z, const std::string &plane, float scale, float &ox,
89 float &oy) {
90 if (plane == "xz") {
91 ox = x * scale;
92 oy = z * scale;
93 } else if (plane == "yz") {
94 ox = y * scale;
95 oy = z * scale;
96 } else {
97 ox = x * scale;
98 oy = y * scale;
99 }
100}
101
102void quatRotateVec(float qx, float qy, float qz, float qw, float vx, float vy, float vz, float &ox,
103 float &oy, float &oz) {
104 const float ix = qw * vx + qy * vz - qz * vy;
105 const float iy = qw * vy + qz * vx - qx * vz;
106 const float iz = qw * vz + qx * vy - qy * vx;
107 const float iw = -qx * vx - qy * vy - qz * vz;
108 ox = ix * qw + iw * -qx + iy * -qz - iz * -qy;
109 oy = iy * qw + iw * -qy + iz * -qx - ix * -qz;
110 oz = iz * qw + iw * -qz + ix * -qy - iy * -qx;
111}
112
113void sampleEmissionOffset(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &sim, float &ox,
114 float &oy) {
115 ox = 0.f;
116 oy = 0.f;
117 if (cfg.areaX <= 0.f && cfg.areaY <= 0.f) return;
118 if (cfg.areaType == "ellipse") {
119 const float a = randRange(sim.rng, 0.f, kPi * 2.f);
120 const float r = std::sqrt(randRange(sim.rng, 0.f, 1.f));
121 ox = std::cos(a) * cfg.areaX * r;
122 oy = std::sin(a) * cfg.areaY * r;
123 } else if (cfg.areaType == "rect") {
124 ox = randRange(sim.rng, -cfg.areaX, cfg.areaX);
125 oy = randRange(sim.rng, -cfg.areaY, cfg.areaY);
126 } else if (cfg.areaType == "line") {
127 ox = randRange(sim.rng, -cfg.areaX, cfg.areaX);
128 oy = 0.f;
129 } else if (cfg.areaType == "ring") {
130 const float a = randRange(sim.rng, 0.f, kPi * 2.f);
131 const float rx = cfg.areaX > 0.f ? cfg.areaX : 1.f;
132 const float ry = cfg.areaY > 0.f ? cfg.areaY : rx;
133 ox = std::cos(a) * rx;
134 oy = std::sin(a) * ry;
135 }
136}
137
138void rebuildSkinCandidates(ParticleEmitter::SkinSource &src) {
139 src.candidates.clear();
140 src.candidatesDirty = false;
141 if (!src.skin || src.skin->getVertexCount() <= 0) return;
142
143 const int n = src.skin->getVertexCount();
144 const int influences = src.skin->getInfluenceCount();
145 if (src.filterBone < 0) {
146 src.candidates.reserve(static_cast<size_t>(n));
147 for (int v = 0; v < n; ++v) src.candidates.push_back(v);
148 return;
149 }
150
151 src.candidates.reserve(static_cast<size_t>(n / 4 + 1));
152 for (int v = 0; v < n; ++v) {
153 float w = 0.f;
154 for (int i = 0; i < influences; ++i) {
155 if (src.skin->getVertexBone(v, i) == src.filterBone) {
156 w += src.skin->getVertexWeight(v, i);
157 }
158 }
159 if (w >= src.minWeight) src.candidates.push_back(v);
160 }
161}
162
163bool ensureSkinCache(ParticleEmitter::SkinSource &src) {
164 if (!src.enabled || !src.skin || !src.pose) return false;
165 if (src.candidatesDirty) rebuildSkinCandidates(src);
166 if (src.candidates.empty()) return false;
167 // Always refresh skinned positions from the live pose (caller must have
168 // computeWorld()'d). Cheap relative to VFX; keeps surface following animation.
169 return src.skin->updateSkinnedPositions(src.pose);
170}
171
172void fillParticleMotion(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &sim, Particle &p) {
173 p.lifetime = randRange(sim.rng, cfg.lifeMin, cfg.lifeMax);
174 if (p.lifetime <= 0.f) p.lifetime = 1e-4f;
175 p.life = p.lifetime;
176 p.ax = randRange(sim.rng, cfg.accelXMin, cfg.accelXMax);
177 p.ay = randRange(sim.rng, cfg.accelYMin, cfg.accelYMax);
178 p.radial = randRange(sim.rng, cfg.radialMin, cfg.radialMax);
179 p.tangential = randRange(sim.rng, cfg.tangentialMin, cfg.tangentialMax);
180 p.spin = randRange(sim.rng, cfg.spinMin, cfg.spinMax);
181 p.rot = randRange(sim.rng, cfg.startRotMin, cfg.startRotMax) * (kPi / 180.f);
182
183 const int totalFrames = cfg.hframes > 0 && cfg.vframes > 0 ? cfg.hframes * cfg.vframes : 1;
184 if (cfg.frameRandomStart > 0.f && totalFrames > 1) {
185 const float frac = cfg.frameRandomStart > 1.f ? 1.f : cfg.frameRandomStart;
186 p.frame = randRange(sim.rng, 0.f, frac) * float(totalFrames);
187 } else {
188 p.frame = 0.f;
189 }
190 p.noisePhase = randRange(sim.rng, 0.f, 1000.f);
191
192 float sizeMul = 1.f;
193 if (cfg.sizeVariation > 0.f) {
194 const float v = cfg.sizeVariation > 1.f ? 1.f : cfg.sizeVariation;
195 sizeMul = 1.f + randRange(sim.rng, -v, v);
196 if (sizeMul < 0.01f) sizeMul = 0.01f;
197 }
198 p.size = sizeMul * cfg.resolvedParameterScale("size");
199
200 const float half = cfg.spread * 0.5f;
201 const float angle = cfg.direction + randRange(sim.rng, -half, half);
202 const float speed = randRange(sim.rng, cfg.speedMin, cfg.speedMax) * cfg.resolvedParameterScale("speed");
203 p.vx = std::cos(angle) * speed;
204 p.vy = std::sin(angle) * speed;
205}
206
207void clearAttachSources(ParticleEmitter::Attach &a) {
209 a.pose = nullptr;
210 a.skeleton = nullptr;
211 a.spine = nullptr;
212 a.ik2d = nullptr;
213 a.ik3d = nullptr;
214 a.boneIndex = -1;
215 a.enabled = false;
216}
217
218void syncAnimPoseAttach(ParticleEmitter::Config &cfg, ParticleEmitter::Attach &attach) {
219 if (!attach.pose || attach.boneIndex < 0 || attach.boneIndex >= attach.pose->getBoneCount())
220 return;
221 const auto &w = attach.pose->world(attach.boneIndex);
222 float ox = attach.offsetX, oy = attach.offsetY, oz = attach.offsetZ;
223 float wx, wy, wz;
225 projectToPlane(wx, wy, wz, attach.plane, attach.scale, cfg.x, cfg.y);
226
227 if (attach.followRotation) {
228 float fx, fy, fz;
229 quatRotateVec(w.qx, w.qy, w.qz, w.qw, 1.f, 0.f, 0.f, fx, fy, fz);
230 float ax, ay;
231 projectToPlane(fx, fy, fz, attach.plane, 1.f, ax, ay);
232 if (ax * ax + ay * ay > kEps) cfg.direction = std::atan2(ay, ax);
233 }
234}
235
236void syncSpineAttach(ParticleEmitter::Config &cfg, ParticleEmitter::Attach &attach) {
237 if (!attach.spine || attach.boneIndex < 0 || attach.boneIndex >= attach.spine->getBoneCount())
238 return;
239 float a, b, c, d;
240 attach.spine->getBoneWorldMatrix(attach.boneIndex, a, b, c, d);
241 const float wx =
242 attach.spine->getBoneWorldX(attach.boneIndex) + a * attach.offsetX + b * attach.offsetY;
243 const float wy =
244 attach.spine->getBoneWorldY(attach.boneIndex) + c * attach.offsetX + d * attach.offsetY;
245 // Spine is already 2D pixel space; scale still applies, plane ignored (xy).
246 cfg.x = wx * attach.scale;
247 cfg.y = wy * attach.scale;
248
249 if (attach.followRotation) {
250 // World rotation is degrees → particle direction radians.
251 cfg.direction = attach.spine->getBoneWorldRotation(attach.boneIndex) * (kPi / 180.f);
252 }
253}
254
255void syncIk2DAttach(ParticleEmitter::Config &cfg, ParticleEmitter::Attach &attach) {
256 if (!attach.ik2d || attach.boneIndex < 0 || attach.boneIndex >= attach.ik2d->getBoneCount())
257 return;
258 float ox = attach.offsetX;
259 float oy = attach.offsetY;
260 if (attach.followRotation || (ox != 0.f || oy != 0.f)) {
261 const float fx = attach.ik2d->getOrientationX(attach.boneIndex);
262 const float fy = attach.ik2d->getOrientationY(attach.boneIndex);
263 const float len2 = fx * fx + fy * fy;
264 if (len2 > kEps) {
265 const float inv = 1.f / std::sqrt(len2);
266 const float ux = fx * inv;
267 const float uy = fy * inv;
268 // Local +X along bone forward, +Y perpendicular.
269 const float rx = ox * ux - oy * uy;
270 const float ry = ox * uy + oy * ux;
271 ox = rx;
272 oy = ry;
273 if (attach.followRotation) cfg.direction = std::atan2(uy, ux);
274 }
275 }
276 cfg.x = (attach.ik2d->getX(attach.boneIndex) + ox) * attach.scale;
277 cfg.y = (attach.ik2d->getY(attach.boneIndex) + oy) * attach.scale;
278}
279
280void syncIk3DAttach(ParticleEmitter::Config &cfg, ParticleEmitter::Attach &attach) {
281 if (!attach.ik3d || attach.boneIndex < 0 || attach.boneIndex >= attach.ik3d->getBoneCount())
282 return;
283 float ox = attach.offsetX;
284 float oy = attach.offsetY;
285 float oz = attach.offsetZ;
286 const float fx = attach.ik3d->getOrientationX(attach.boneIndex);
287 const float fy = attach.ik3d->getOrientationY(attach.boneIndex);
288 const float fz = attach.ik3d->getOrientationZ(attach.boneIndex);
289 const float len2 = fx * fx + fy * fy + fz * fz;
290 if (len2 > kEps && (ox != 0.f || oy != 0.f || oz != 0.f || attach.followRotation)) {
291 const float inv = 1.f / std::sqrt(len2);
292 const float ux = fx * inv, uy = fy * inv, uz = fz * inv;
293 // Offset: along-bone (ox) + world remainder (oy/oz as translation extras).
294 const float wx = attach.ik3d->getX(attach.boneIndex) + ux * ox + oy;
295 const float wy = attach.ik3d->getY(attach.boneIndex) + uy * ox + oz;
296 const float wz = attach.ik3d->getZ(attach.boneIndex) + uz * ox;
297 projectToPlane(wx, wy, wz, attach.plane, attach.scale, cfg.x, cfg.y);
298 if (attach.followRotation) {
299 float ax, ay;
300 projectToPlane(ux, uy, uz, attach.plane, 1.f, ax, ay);
301 if (ax * ax + ay * ay > kEps) cfg.direction = std::atan2(ay, ax);
302 }
303 return;
304 }
305 projectToPlane(attach.ik3d->getX(attach.boneIndex) + ox, attach.ik3d->getY(attach.boneIndex) + oy,
306 attach.ik3d->getZ(attach.boneIndex) + oz, attach.plane, attach.scale, cfg.x,
307 cfg.y);
308}
309
310void fireSubEmitter(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &sourceSim, const std::string &trigger, float x,
311 float y, float vx, float vy) {
312 static int g_subDepth = 0;
313 if (g_subDepth >= 8) return; // cycle guard (A→B→A chains)
314 for (const auto &se : cfg.subEmitters) {
315 if (!se.target || se.trigger != trigger) continue;
316 // Self-referencing sub-emitters would corrupt the compaction loop.
317 if (se.target == cfg.entity) continue;
318 auto tc = se.target->config();
319 auto ts = se.target->sim();
320 if (ts->alive >= int(ts->particles.size())) continue;
321 // A sub-emitter birth occurs at the source's executed step boundary, even if
322 // the target is visited later by the scheduler. Never advance its own clock.
323 struct RestoreRecordingTime {
324 double &time;
325 double previous;
326 ~RestoreRecordingTime() { time = previous; }
327 } restore{ts->recordingSeconds, ts->recordingSeconds};
328 if (ts->recording.state() == ParticleRecordState::Recording) {
329 if (sourceSim.recording.state() != ParticleRecordState::Recording ||
330 ts->recordingSeconds > sourceSim.recordingSeconds)
331 ts->recording.invalidate();
332 else
333 ts->recordingSeconds = sourceSim.recordingSeconds;
334 }
335 ++g_subDepth;
336 const bool spawned = spawnParticleAt(*tc, *ts, x, y);
337 --g_subDepth;
338 if (spawned && se.inheritVelocity > 0.f) {
339 Particle &p = ts->particles[size_t(ts->alive - 1)];
340 p.vx += vx * se.inheritVelocity;
341 p.vy += vy * se.inheritVelocity;
343 }
344 }
345}
346
347} // namespace
348
349namespace {
350WorldCollisionFn g_worldCollision = nullptr;
351} // namespace
352
353void setWorldCollisionResolver(WorldCollisionFn fn) { g_worldCollision = fn; }
354
355WorldCollisionFn getWorldCollisionResolver() { return g_worldCollision; }
356
358 if (sim.nextBirthSerial == 0) {
360 return false;
361 }
362 if (sim.spawnQuota == 0) {
364 return false;
365 }
366 if (sim.alive >= int(sim.particles.size())) return false;
367
368 Particle &p = sim.particles[size_t(sim.alive++)];
369 p.birthSerial = sim.nextBirthSerial++;
370 if (sim.spawnQuota > 0) --sim.spawnQuota;
371 ++sim.spawnedThisFrame;
372 float ox = 0.f, oy = 0.f;
373 sampleEmissionOffset(cfg, sim, ox, oy);
374 p.x = x + ox;
375 p.y = y + oy;
376 fillParticleMotion(cfg, sim, p);
378 fireSubEmitter(cfg, sim, "birth", p.x, p.y, p.vx, p.vy);
379 return true;
380}
381
383 if (sim.nextBirthSerial == 0) {
385 return false;
386 }
387 if (sim.spawnQuota == 0) {
389 return false;
390 }
391 // Prefer skin surface when configured on the owning entity.
392 if (cfg.entity) {
393 auto skinComp = cfg.entity->skinSource();
394 if (skinComp->enabled) {
395 float sx = cfg.x, sy = cfg.y;
396 if (sampleSkinSpawn(*skinComp, sim, sx, sy)) {
397 return spawnParticleAt(cfg, sim, sx, sy);
398 }
399 }
400 }
401 return spawnParticleAt(cfg, sim, cfg.x, cfg.y);
402}
403
405 float &outY) {
406 if (!ensureSkinCache(skinSrc)) return false;
407 const int vi = skinSrc.candidates[static_cast<size_t>(randIndex(sim.rng, int(skinSrc.candidates.size())))];
408 const float wx = skinSrc.skin->getSkinnedPositionX(vi);
409 const float wy = skinSrc.skin->getSkinnedPositionY(vi);
410 const float wz = skinSrc.skin->getSkinnedPositionZ(vi);
411 projectToPlane(wx, wy, wz, skinSrc.plane, skinSrc.scale, outX, outY);
412 return true;
413}
414
417 if (attach.enabled) {
418 switch (attach.kind) {
420 syncAnimPoseAttach(cfg, attach);
421 break;
423 syncSpineAttach(cfg, attach);
424 break;
426 syncIk2DAttach(cfg, attach);
427 break;
429 syncIk3DAttach(cfg, attach);
430 break;
432 default:
433 break;
434 }
435 }
436
437 if (skinSrc.enabled && skinSrc.skin && skinSrc.pose) {
438 ensureSkinCache(skinSrc);
439 }
440}
441
443 if (sim.paused || dt <= 0.f) return;
444 if (cfg.maxDeltaTime > 0.f && dt > cfg.maxDeltaTime) dt = cfg.maxDeltaTime;
445
447 const double next = sim.recordingSeconds + dt;
448 if (!std::isfinite(next) || next <= sim.recordingSeconds)
449 sim.recording.invalidate();
450 else
451 sim.recordingSeconds = next;
452 }
453 // Emitter velocity for inheritVelocity (before lastX/lastY refresh).
454 float emitVx = 0.f, emitVy = 0.f;
455 if (cfg.inheritVelocity > 0.f && sim.hasLastPos) {
456 emitVx = (cfg.x - sim.lastX) / dt;
457 emitVy = (cfg.y - sim.lastY) / dt;
458 }
459 const bool localSpace = cfg.simSpace == "local";
460 const float localDx = localSpace && sim.hasLastPos ? cfg.x - sim.lastX : 0.f;
461 const float localDy = localSpace && sim.hasLastPos ? cfg.y - sim.lastY : 0.f;
462
463 const float damp = cfg.damping > 0.f ? (cfg.damping > 1.f ? 1.f : cfg.damping) : 0.f;
464 const float dampFactor = damp > 0.f ? std::max(0.f, 1.f - damp * dt) : 1.f;
465 const float noiseFreq = cfg.noiseFrequency > 0.f ? cfg.noiseFrequency : 1.f;
466 const bool hasCollision =
467 cfg.collisionMode != "none" &&
468 (cfg.worldCollision || cfg.collisionBoundsEnabled || cfg.sdfField != nullptr);
469 const bool bounce = cfg.collisionMode == "bounce";
470 const bool killMode = cfg.collisionMode == "kill";
471 const bool stopMode = cfg.collisionMode == "stop";
472 const float cRadius = cfg.collisionRadius;
473 const float lifeLoss = cfg.collisionLifetimeLoss;
474
475 int write = 0;
476 for (int i = 0; i < sim.alive; ++i) {
477 Particle &p = sim.particles[size_t(i)];
478 p.life -= dt;
479 if (p.life <= 0.f) {
481 fireSubEmitter(cfg, sim, "death", p.x, p.y, p.vx, p.vy);
482 continue;
483 }
484
485 if (localSpace && (localDx != 0.f || localDy != 0.f)) {
486 p.x += localDx;
487 p.y += localDy;
488 }
489
490 float ax = p.ax + cfg.gravityX;
491 float ay = p.ay + cfg.gravityY;
492 const float dx = p.x - cfg.x;
493 const float dy = p.y - cfg.y;
494 const float len2 = dx * dx + dy * dy;
495 if (len2 > kEps) {
496 const float inv = 1.f / std::sqrt(len2);
497 const float rdx = dx * inv;
498 const float rdy = dy * inv;
499 ax += rdx * p.radial - rdy * p.tangential;
500 ay += rdy * p.radial + rdx * p.tangential;
501 }
502
503 if (cfg.noiseStrength != 0.f) {
504 const float t = sim.emitterAge * cfg.noiseSpeed;
505 ax += smoothNoise2(p.x * noiseFreq + t, p.y * noiseFreq + p.noisePhase) *
506 cfg.noiseStrength;
507 ay += smoothNoise2(p.y * noiseFreq + t, p.x * noiseFreq - p.noisePhase) *
508 cfg.noiseStrength;
509 }
510
511 // Radial force fields (strength > 0 attract, < 0 repel).
512 for (const auto &f : cfg.forceFields) {
513 if (f.radius <= 0.f || f.strength == 0.f) continue;
514 const float fdx = f.x - p.x;
515 const float fdy = f.y - p.y;
516 const float dist = std::sqrt(fdx * fdx + fdy * fdy);
517 if (dist >= f.radius) continue;
518 const float fall = std::pow(1.f - dist / f.radius, f.falloff > 0.f ? f.falloff : 1.f);
519 const float inv = dist > kEps ? 1.f / dist : 0.f;
520 ax += fdx * inv * f.strength * fall;
521 ay += fdy * inv * f.strength * fall;
522 }
523
524 p.vx += ax * dt;
525 p.vy += ay * dt;
526
527 // Velocity-over-lifetime multiplier (applied as a smooth ratio).
528 if (!cfg.velocityCurve.empty() && p.lifetime > 0.f) {
529 const float tNew = 1.f - (p.life / p.lifetime);
530 const float tOld = tNew - dt / p.lifetime;
531 const float vOld = cfg.velocityCurve.sample(tOld, 1.f);
532 const float vNew = cfg.velocityCurve.sample(tNew, 1.f);
533 if (vOld > 1e-4f) {
534 const float ratio = vNew / vOld;
535 p.vx *= ratio;
536 p.vy *= ratio;
537 }
538 }
539
540 if (dampFactor != 1.f) {
541 p.vx *= dampFactor;
542 p.vy *= dampFactor;
543 }
544 if (cfg.limitVelocity > 0.f) {
545 const float sp2 = p.vx * p.vx + p.vy * p.vy;
546 const float max2 = cfg.limitVelocity * cfg.limitVelocity;
547 if (sp2 > max2) {
548 const float s = std::sqrt(max2 / sp2);
549 p.vx *= s;
550 p.vy *= s;
551 }
552 }
553
554 p.x += p.vx * dt;
555 p.y += p.vy * dt;
556 p.rot += p.spin * dt;
557 p.frame += cfg.frameRate * dt;
558
559 if (hasCollision) {
560 const float scale = p.size > 0.f ? p.size : 1.f;
561 const float rad =
562 cRadius > 0.f ? cRadius : std::max(cfg.particleW, cfg.particleH) * 0.5f * scale;
563 float nx = 0.f, ny = 0.f;
564 bool hit = false;
565 if (cfg.worldCollision) {
567 if (fn(p.x, p.y, rad, nx, ny)) hit = true;
568 }
569 if (!hit && cfg.sdfField != nullptr) {
570 const float distance = cfg.sdfField->sample(p.x, p.y);
571 if (std::isfinite(distance) && distance < rad) {
572 float gx = 0.f, gy = 0.f;
573 if (cfg.sdfField->gradient(p.x, p.y, gx, gy) ==
575 nx = gx;
576 ny = gy;
577 const float push = rad - distance;
578 p.x += nx * push;
579 p.y += ny * push;
580 hit = true;
581 } else {
582 hit = true;
583 }
584 }
585 }
586 if (!hit && cfg.collisionBoundsEnabled) {
587 if (p.x - rad < cfg.boundsMinX) {
588 nx += 1.f;
589 p.x = cfg.boundsMinX + rad;
590 hit = true;
591 } else if (p.x + rad > cfg.boundsMaxX) {
592 nx += -1.f;
593 p.x = cfg.boundsMaxX - rad;
594 hit = true;
595 }
596 if (p.y - rad < cfg.boundsMinY) {
597 ny += 1.f;
598 p.y = cfg.boundsMinY + rad;
599 hit = true;
600 } else if (p.y + rad > cfg.boundsMaxY) {
601 ny += -1.f;
602 p.y = cfg.boundsMaxY - rad;
603 hit = true;
604 }
605 const float nlen = std::sqrt(nx * nx + ny * ny);
606 if (nlen > kEps) {
607 nx /= nlen;
608 ny /= nlen;
609 }
610 }
611 if (hit) {
612 fireSubEmitter(cfg, sim, "collision", p.x, p.y, p.vx, p.vy);
613 if (killMode) {
615 continue;
616 }
617 if (stopMode) {
618 p.vx = 0.f;
619 p.vy = 0.f;
620 } else if (bounce && (nx != 0.f || ny != 0.f)) {
621 const float dot = p.vx * nx + p.vy * ny;
622 p.vx = (p.vx - 2.f * dot * nx) * cfg.collisionRestitution;
623 p.vy = (p.vy - 2.f * dot * ny) * cfg.collisionRestitution;
624 }
625 if (lifeLoss > 0.f) {
626 p.life -= p.lifetime * lifeLoss;
627 if (p.life <= 0.f) {
629 continue;
630 }
631 }
632 }
633 }
634
635 if (write != i) sim.particles[size_t(write)] = p;
636 ++write;
637 }
638 sim.alive = write;
639
640 if (!sim.active) {
641 for (int i = 0; i < sim.alive; ++i)
643 sim.lastX = cfg.x;
644 sim.lastY = cfg.y;
645 sim.hasLastPos = true;
646 return;
647 }
648
649 sim.emitterAge += dt;
650
651 // Timed bursts fire once while the emitter is active.
652 auto spawnWithInherit = [&]() {
653 const bool spawned = spawnParticle(cfg, sim);
654 if (spawned && cfg.inheritVelocity > 0.f && sim.alive > 0) {
655 Particle &np = sim.particles[size_t(sim.alive - 1)];
656 np.vx += emitVx * cfg.inheritVelocity;
657 np.vy += emitVy * cfg.inheritVelocity;
658 }
659 return spawned;
660 };
661 for (auto &b : cfg.bursts) {
662 if (!b.emitted && b.count > 0 && sim.emitterAge >= b.time) {
663 b.emitted = true;
664 for (int k = 0; k < b.count; ++k) {
665 if (sim.alive >= int(sim.particles.size())) break;
666 if (!spawnWithInherit()) break;
667 }
668 }
669 }
670
671 const float emissionScale = cfg.resolvedParameterScale("emission");
672 if (cfg.emissionRate > 0.f && emissionScale > 0.f) {
673 sim.emitAccum += cfg.emissionRate * emissionScale * dt;
674 while (sim.emitAccum >= 1.f) {
675 if (sim.alive >= int(sim.particles.size())) {
676 if (cfg.overflowMode == "pause") break; // keep accum; retry next frame
677 if (cfg.overflowMode == "warn" && !sim.overflowWarned) {
678 sim.overflowWarned = true;
679 std::fprintf(stderr,
680 "[particles] buffer overflow (emissionRate=%.1f, buffer=%d)\n",
681 cfg.emissionRate, int(sim.particles.size()));
682 }
683 sim.emitAccum = 0.f;
684 break;
685 }
686 if (!spawnWithInherit()) {
687 sim.emitAccum = 0.f;
688 break;
689 }
690 sim.emitAccum -= 1.f;
691 }
692 }
693
694 // Rate over distance is accumulated in particle units and spawned at
695 // evenly spaced points along the emitter's travelled segment. This avoids
696 // the frame-rate-dependent clumps produced by spawning every item at the
697 // current endpoint (important for weapon trails and wheel dust).
698 const float distanceRate = cfg.emissionRateOverDistance * emissionScale;
699 if (distanceRate > 0.f && sim.hasLastPos) {
700 const float moveX = cfg.x - sim.lastX;
701 const float moveY = cfg.y - sim.lastY;
702 const float distance = std::sqrt(moveX * moveX + moveY * moveY);
703 const float prior = sim.distanceEmitAccum;
704 const float total = prior + distance * distanceRate;
705 const int wanted = int(std::floor(total));
706 sim.distanceEmitAccum = total - float(wanted);
707 const float firstDistance = prior > 0.f ? (1.f - prior) / distanceRate : 1.f / distanceRate;
708 for (int i = 0; i < wanted; ++i) {
709 if (sim.alive >= int(sim.particles.size())) {
710 if (cfg.overflowMode == "pause")
711 sim.distanceEmitAccum += float(wanted - i);
712 else if (cfg.overflowMode == "warn" && !sim.overflowWarned) {
713 sim.overflowWarned = true;
714 std::fprintf(stderr, "[particles] distance emission overflow (rate=%.2f, buffer=%d)\n",
715 cfg.emissionRateOverDistance, int(sim.particles.size()));
716 }
717 break;
718 }
719 float spawnX = cfg.x;
720 float spawnY = cfg.y;
721 if (distance > kEps && !localSpace) {
722 const float along = firstDistance + float(i) / distanceRate;
723 const float alpha = std::min(1.f, along / distance);
724 spawnX = sim.lastX + moveX * alpha;
725 spawnY = sim.lastY + moveY * alpha;
726 }
727 const bool spawned = spawnParticleAt(cfg, sim, spawnX, spawnY);
728 if (!spawned) break;
729 if (cfg.inheritVelocity > 0.f && sim.alive > 0) {
730 Particle& np = sim.particles[size_t(sim.alive - 1)];
731 np.vx += emitVx * cfg.inheritVelocity;
732 np.vy += emitVy * cfg.inheritVelocity;
733 }
734 }
735 }
736
737 // Expire AFTER this frame's emission so a short-lived emitter still
738 // releases the particles due during its final frame.
739 if (cfg.emitterLife >= 0.f && sim.emitterAge >= cfg.emitterLife) {
740 if (cfg.looping && cfg.emitterLife > 0.f) {
741 sim.emitterAge = std::fmod(sim.emitterAge, cfg.emitterLife);
742 for (auto& b : cfg.bursts) b.emitted = false;
743 } else {
744 sim.active = false;
745 sim.emitAccum = 0.f;
746 sim.distanceEmitAccum = 0.f;
747 }
748 }
749
750 for (int i = 0; i < sim.alive; ++i)
752 sim.lastX = cfg.x;
753 sim.lastY = cfg.y;
754 sim.hasLastPos = true;
755}
756
758 ParticleEmitter *e = ParticleEmitter::create();
759 e->config()->entity = e;
760 const int n = bufferSize > 0 ? bufferSize : 1;
761 e->sim()->particles.resize(size_t(n));
762 std::random_device rd;
763 const int seed = static_cast<int>(rd());
764 e->sim()->activeSeed = seed;
765 e->sim()->rng.seed(static_cast<std::mt19937::result_type>(seed));
766 // Touch Draw / Attach / SkinSource so system views see fully initialized emitters.
767 (void)e->draw();
768 (void)e->attach();
769 (void)e->skinSource();
770 (void)e->lights();
771 (void)e->gpuSim();
772 return e;
773}
774
776 auto gpu = gpuSim();
777 if (gpu->residentHandle != 0) {
778 auto* gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
779 if (gfx)
780 if (auto* gp = gfx->gpuParticles()) gp->releaseGpuParticleEmitter(gpu->residentHandle);
781 gpu->residentHandle = 0;
782 gpu->residentActive = false;
783 gpu->estimatedAlive = 0;
784 gpu->deathTimes.clear();
785 }
786 ecs::DestroyEntity(this);
787}
788
789void ParticleEmitter::setPosition(float x, float y) {
790 config()->x = x;
791 config()->y = y;
792}
793
794void ParticleEmitter::moveTo(float x, float y) { setPosition(x, y); }
795
796float ParticleEmitter::getX() { return config()->x; }
797float ParticleEmitter::getY() { return config()->y; }
798
800 config()->emissionRate = rate < 0.f ? 0.f : rate;
801}
802
803float ParticleEmitter::getEmissionRate() { return config()->emissionRate; }
804
805void ParticleEmitter::setParticleLifetime(float minLife, float maxLife) {
806 auto c = config();
807 c->lifeMin = minLife < 0.f ? 0.f : minLife;
808 c->lifeMax = maxLife < c->lifeMin ? c->lifeMin : maxLife;
809}
810
811float ParticleEmitter::getParticleLifetimeMin() { return config()->lifeMin; }
812float ParticleEmitter::getParticleLifetimeMax() { return config()->lifeMax; }
813
814void ParticleEmitter::setEmitterLifetime(float seconds) { config()->emitterLife = seconds; }
815float ParticleEmitter::getEmitterLifetime() { return config()->emitterLife; }
816
817void ParticleEmitter::setDirection(float radians) { config()->direction = radians; }
818float ParticleEmitter::getDirection() { return config()->direction; }
819
820void ParticleEmitter::setSpread(float radians) {
821 config()->spread = radians < 0.f ? 0.f : radians;
822}
823float ParticleEmitter::getSpread() { return config()->spread; }
824
825void ParticleEmitter::setSpeed(float minSpeed, float maxSpeed) {
826 auto c = config();
827 c->speedMin = minSpeed;
828 c->speedMax = maxSpeed < minSpeed ? minSpeed : maxSpeed;
829}
830
831void ParticleEmitter::setLinearAcceleration(float xmin, float ymin, float xmax, float ymax) {
832 auto c = config();
833 c->accelXMin = xmin;
834 c->accelYMin = ymin;
835 c->accelXMax = xmax < xmin ? xmin : xmax;
836 c->accelYMax = ymax < ymin ? ymin : ymax;
837}
838
839void ParticleEmitter::setRadialAcceleration(float minA, float maxA) {
840 auto c = config();
841 c->radialMin = minA;
842 c->radialMax = maxA < minA ? minA : maxA;
843}
844
845void ParticleEmitter::setTangentialAcceleration(float minA, float maxA) {
846 auto c = config();
847 c->tangentialMin = minA;
848 c->tangentialMax = maxA < minA ? minA : maxA;
849}
850
851void ParticleEmitter::setEmissionArea(const std::string &type, float x, float y) {
852 auto c = config();
853 if (type == "ellipse" || type == "rect" || type == "line" || type == "ring")
854 c->areaType = type;
855 else
856 c->areaType = "none";
857 c->areaX = x < 0.f ? 0.f : x;
858 c->areaY = y < 0.f ? 0.f : y;
859}
860
861std::string ParticleEmitter::getEmissionAreaType() { return config()->areaType; }
862float ParticleEmitter::getEmissionAreaX() { return config()->areaX; }
863float ParticleEmitter::getEmissionAreaY() { return config()->areaY; }
864
866 auto c = config();
867 c->particleW = width > 0.f ? width : 1.f;
868 c->particleH = height > 0.f ? height : 1.f;
869}
870
871float ParticleEmitter::getParticleWidth() { return config()->particleW; }
872float ParticleEmitter::getParticleHeight() { return config()->particleH; }
873
874void ParticleEmitter::setSizes(float startScale, float endScale) {
875 config()->sizeStart = startScale;
876 config()->sizeEnd = endScale;
877}
878
880 config()->sizeVariation = variation < 0.f ? 0.f : (variation > 1.f ? 1.f : variation);
881}
882float ParticleEmitter::getSizeVariation() { return config()->sizeVariation; }
883
884void ParticleEmitter::setSpin(float minSpin, float maxSpin) {
885 auto c = config();
886 c->spinMin = minSpin;
887 c->spinMax = maxSpin < minSpin ? minSpin : maxSpin;
888}
889
890void ParticleEmitter::setStartRotation(float minDeg, float maxDeg) {
891 auto c = config();
892 c->startRotMin = minDeg;
893 c->startRotMax = maxDeg < minDeg ? minDeg : maxDeg;
894}
895
897 if (count <= 0) return;
898 config()->bursts.push_back(Config::Burst{time < 0.f ? 0.f : time, count, false});
899}
900
901void ParticleEmitter::clearBursts() { config()->bursts.clear(); }
902
903void ParticleEmitter::setPrewarm(float seconds) {
904 config()->prewarmSeconds = seconds < 0.f ? 0.f : seconds;
905}
906
907float ParticleEmitter::getPrewarmSeconds() { return config()->prewarmSeconds; }
908
909void ParticleEmitter::setGravity(float x, float y) {
910 auto c = config();
911 c->gravityX = x;
912 c->gravityY = y;
913}
914
915void ParticleEmitter::setDamping(float perSecond) {
916 config()->damping = perSecond < 0.f ? 0.f : perSecond;
917}
918
920 config()->limitVelocity = maxSpeed < 0.f ? 0.f : maxSpeed;
921}
922
923void ParticleEmitter::clearVelocityCurve() { config()->velocityCurve.clear(); }
924
926 config()->velocityCurve.add(t, v);
927}
928
930 config()->inheritVelocity =
931 fraction < 0.f ? 0.f : (fraction > 1.f ? 1.f : fraction);
932}
933
934void ParticleEmitter::setSimulationSpace(const std::string &space) {
935 config()->simSpace = space == "local" ? "local" : "world";
936}
937
938void ParticleEmitter::setNoise(float strength, float frequency, float speed) {
939 auto c = config();
940 c->noiseStrength = strength;
941 c->noiseFrequency = frequency > 0.f ? frequency : 1.f;
942 c->noiseSpeed = speed;
943}
944
946 config()->gpuSimulation = enable;
947 auto gpu = gpuSim();
948 gpu->enabled = enable;
949 if (!enable && gpu->residentHandle != 0) {
950 auto* gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
951 if (gfx)
952 if (auto* gp = gfx->gpuParticles()) gp->releaseGpuParticleEmitter(gpu->residentHandle);
953 gpu->residentHandle = 0;
954 gpu->residentActive = false;
955 gpu->estimatedAlive = 0;
956 gpu->timeline = 0.0;
957 gpu->deathTimes.clear();
958 }
959}
960
961bool ParticleEmitter::getGpuSimulation() { return config()->gpuSimulation; }
962
963bool ParticleEmitter::isGpuSimulationActive() { return gpuSim()->residentActive; }
964
965bool ParticleEmitter::isGpuFeatureSetSupported() { return gpuFeatureFallbackReason(*config(), *draw())[0] == '\0'; }
966
967std::string ParticleEmitter::getSimulationBackend() { return gpuSim()->residentActive ? "gpu" : "cpu"; }
968
970 if (gpuSim()->residentActive) return {};
971 if (!config()->gpuSimulation) return "disabled";
972 if (const char* reason = gpuFeatureFallbackReason(*config(), *draw()); reason[0] != '\0') return reason;
973 auto* gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
974 if (!gfx || !gfx->gpuParticles() || !gfx->gpuParticles()->supportsGpuParticles()) return "backend_unavailable";
975 return "pending_activation";
976}
977
978void ParticleEmitter::setFloatParameter(const std::string& name, float value) {
979 if (!name.empty()) config()->floatParameters[name] = value;
980}
981
982float ParticleEmitter::getFloatParameter(const std::string& name, float fallback) {
983 auto found = config()->floatParameters.find(name);
984 return found == config()->floatParameters.end() ? fallback : found->second;
985}
986
987bool ParticleEmitter::hasFloatParameter(const std::string& name) {
988 return config()->floatParameters.find(name) != config()->floatParameters.end();
989}
990
991void ParticleEmitter::clearFloatParameters() { config()->floatParameters.clear(); }
992
993void ParticleEmitter::bindFloatParameter(const std::string& name, const std::string& target, float scale,
994 float offset) {
995 if (name.empty()) return;
996 if (target != "emission" && target != "speed" && target != "size" && target != "playback") return;
997 config()->parameterBindings[target] = Config::ParameterBinding{name, scale, offset};
998}
999
1000void ParticleEmitter::clearFloatParameterBindings() { config()->parameterBindings.clear(); }
1001
1003 return config()->resolvedParameterScale(target);
1004}
1005
1006void ParticleEmitter::setCollision(const std::string &mode, float radius, float restitution,
1007 float lifetimeLoss) {
1008 auto c = config();
1009 c->collisionMode =
1010 (mode == "kill" || mode == "bounce" || mode == "stop") ? mode : "none";
1011 c->collisionRadius = radius < 0.f ? 0.f : radius;
1012 c->collisionRestitution = restitution < 0.f ? 0.f : restitution;
1013 c->collisionLifetimeLoss =
1014 lifetimeLoss < 0.f ? 0.f : (lifetimeLoss > 1.f ? 1.f : lifetimeLoss);
1015}
1016
1017void ParticleEmitter::setCollisionBounds(bool enabled, float minX, float minY, float maxX,
1018 float maxY) {
1019 auto c = config();
1020 c->collisionBoundsEnabled = enabled;
1021 c->boundsMinX = minX;
1022 c->boundsMinY = minY;
1023 c->boundsMaxX = maxX;
1024 c->boundsMaxY = maxY;
1025}
1026
1027void ParticleEmitter::setWorldCollision(bool enabled) { config()->worldCollision = enabled; }
1028
1029void ParticleEmitter::setSdfField(eve::IParticleSdfField* field) { config()->sdfField = field; }
1030
1032
1033void ParticleEmitter::setMotionVectorPolicy(const std::string& policy) {
1034 config()->motionVectorPolicy =
1035 (policy == "velocity" || policy == "spawn_delta") ? policy : "none";
1036}
1037
1039 const auto& policy = config()->motionVectorPolicy;
1040 return (policy == "velocity" || policy == "spawn_delta") ? policy : "none";
1041}
1042
1044 // Policy is authored and queryable; the graphics velocity-buffer path is not
1045 // wired yet, so activation stays false until a backend writes motion vectors.
1046 return false;
1047}
1048
1049void ParticleEmitter::setRenderMode(const std::string &mode, float stretchFactor) {
1050 auto c = config();
1051 c->renderMode = (mode == "stretched" || mode == "velocity") ? "stretched"
1052 : mode == "axis" ? "axis"
1053 : mode == "ribbon" ? "ribbon"
1054 : "billboard";
1055 c->stretchFactor = stretchFactor < 0.f ? 0.f : stretchFactor;
1056}
1057
1058void ParticleEmitter::setRibbon(float width, float minSegmentLength) {
1059 auto c = config();
1060 c->renderMode = "ribbon";
1061 c->ribbonWidth = width < 0.f ? 0.f : width;
1062 c->ribbonMinSegmentLength = minSegmentLength < 0.f ? 0.f : minSegmentLength;
1063}
1064
1065void ParticleEmitter::setRenderAxis(float degrees) { config()->renderAxisDegrees = degrees; }
1066
1067void ParticleEmitter::setSortMode(const std::string& mode) {
1068 config()->sortMode = (mode == "oldest" || mode == "youngest" || mode == "distance") ? mode : "none";
1069}
1070
1071std::string ParticleEmitter::getSortMode() { return config()->sortMode; }
1072
1073void ParticleEmitter::setMaterialMode(const std::string& mode) {
1074 config()->materialMode = (mode == "lit" || mode == "distortion") ? mode : "unlit";
1075}
1076
1077std::string ParticleEmitter::getMaterialMode() { return config()->materialMode; }
1078
1079void ParticleEmitter::setDistortionStrength(float strengthPixels) {
1080 config()->distortionStrength = std::max(0.f, strengthPixels);
1081}
1082
1083float ParticleEmitter::getDistortionStrength() { return config()->distortionStrength; }
1084
1085void ParticleEmitter::setOverflowMode(const std::string &mode) {
1086 config()->overflowMode =
1087 (mode == "pause" || mode == "warn") ? mode : "drop";
1088}
1089
1091 config()->maxDeltaTime = seconds < 0.f ? 0.f : seconds;
1092}
1093
1095 float inheritVelocity) {
1096 if (!target || target == this) return;
1098 se.target = target;
1099 se.trigger = (trigger == "death" || trigger == "collision") ? trigger : "birth";
1100 se.inheritVelocity = inheritVelocity < 0.f ? 0.f : (inheritVelocity > 1.f ? 1.f : inheritVelocity);
1101 config()->subEmitters.push_back(se);
1102}
1103
1104void ParticleEmitter::clearSubEmitters() { config()->subEmitters.clear(); }
1105
1106void ParticleEmitter::addForceField(float x, float y, float radius, float strength,
1107 float falloff) {
1108 if (radius <= 0.f || strength == 0.f) return;
1110 f.x = x;
1111 f.y = y;
1112 f.radius = radius;
1113 f.strength = strength;
1114 f.falloff = falloff > 0.f ? falloff : 1.f;
1115 config()->forceFields.push_back(f);
1116}
1117
1118void ParticleEmitter::clearForceFields() { config()->forceFields.clear(); }
1119
1122
1123void ParticleEmitter::setLights(bool enabled, float radius, float intensity, float r, float g,
1124 float b, int maxLights) {
1125 auto c = config();
1126 c->lights.enabled = enabled;
1127 c->lights.radius = radius > 0.f ? radius : 0.f;
1128 c->lights.intensity = intensity;
1129 c->lights.r = r;
1130 c->lights.g = g;
1131 c->lights.b = b;
1132 c->lights.max = maxLights > 0 ? maxLights : 0;
1133}
1134
1135bool ParticleEmitter::getLightsEnabled() { return config()->lights.enabled; }
1136
1137void ParticleEmitter::setBlendMode(const std::string &mode) {
1138 if (mode == "additive")
1139 draw()->blend = BlendMode::Additive;
1140 else if (mode == "opaque")
1141 draw()->blend = BlendMode::Opaque;
1142 else if (mode == "premultiplied" || mode == "premultiplied_alpha")
1143 draw()->blend = BlendMode::Premultiplied;
1144 else if (mode == "multiply")
1145 draw()->blend = BlendMode::Multiply;
1146 else
1147 draw()->blend = BlendMode::Alpha;
1148}
1149
1151 switch (draw()->blend) {
1153 return "additive";
1154 case BlendMode::Opaque:
1155 return "opaque";
1157 return "premultiplied";
1159 return "multiply";
1160 case BlendMode::Alpha:
1161 default:
1162 return "alpha";
1163 }
1164}
1165
1166void ParticleEmitter::setFlipbook(int h, int v, float framesPerSecond, float randomStart) {
1167 auto c = config();
1168 c->hframes = h > 0 ? h : 1;
1169 c->vframes = v > 0 ? v : 1;
1170 c->frameRate = framesPerSecond;
1171 c->frameRandomStart = randomStart < 0.f ? 0.f : (randomStart > 1.f ? 1.f : randomStart);
1172}
1173
1174void ParticleEmitter::clearColorGradient() { config()->colorGradient.clear(); }
1175
1176void ParticleEmitter::addColorStop(float t, float r, float g, float b, float a) {
1177 config()->colorGradient.add(t, r, g, b, a);
1178}
1179
1180void ParticleEmitter::clearSizeCurve() { config()->sizeCurve.clear(); }
1181
1182void ParticleEmitter::addSizeCurvePoint(float t, float v) { config()->sizeCurve.add(t, v); }
1183
1184void ParticleEmitter::clearRotationCurve() { config()->rotationCurve.clear(); }
1185
1187 config()->rotationCurve.add(t, v);
1188}
1189
1190void ParticleEmitter::setColorStart(float r, float g, float b, float a) {
1191 config()->colorStart = Color(r, g, b, a);
1192}
1193
1194void ParticleEmitter::setColorEnd(float r, float g, float b, float a) {
1195 config()->colorEnd = Color(r, g, b, a);
1196}
1197
1200
1203
1204void ParticleEmitter::setCanvas(graphics::Canvas *canvas) { draw()->canvas = canvas; }
1206
1208int ParticleEmitter::getLayer() { return draw()->layer; }
1209
1211bool ParticleEmitter::isVisible() { return draw()->visible; }
1212
1213void ParticleEmitter::applyPreset(const std::string &name) {
1214 if (name == "spark") {
1215 setEmissionRate(80.f);
1216 setParticleLifetime(0.2f, 0.6f);
1217 setEmitterLifetime(-1.f);
1218 setDirection(-kPi * 0.5f);
1219 setSpread(kPi * 0.6f);
1220 setSpeed(60.f, 180.f);
1221 setLinearAcceleration(-20.f, 40.f, 20.f, 120.f);
1222 setRadialAcceleration(0.f, 0.f);
1223 setTangentialAcceleration(0.f, 0.f);
1224 setEmissionArea("none", 0.f, 0.f);
1225 setParticleSize(4.f, 4.f);
1226 setSizes(1.f, 0.2f);
1227 setSizeVariation(0.3f);
1228 setSpin(-8.f, 8.f);
1229 setColorStart(1.f, 0.9f, 0.3f, 1.f);
1230 setColorEnd(1.f, 0.2f, 0.f, 0.f);
1231 } else if (name == "smoke") {
1232 setEmissionRate(25.f);
1233 setParticleLifetime(1.5f, 3.f);
1234 setEmitterLifetime(-1.f);
1235 setDirection(-kPi * 0.5f);
1236 setSpread(0.4f);
1237 setSpeed(10.f, 40.f);
1238 setLinearAcceleration(-5.f, -30.f, 5.f, -10.f);
1239 setRadialAcceleration(-5.f, 5.f);
1240 setTangentialAcceleration(-10.f, 10.f);
1241 setEmissionArea("ellipse", 12.f, 4.f);
1242 setParticleSize(16.f, 16.f);
1243 setSizes(0.5f, 2.f);
1244 setSizeVariation(0.4f);
1245 setSpin(-1.f, 1.f);
1246 setColorStart(0.5f, 0.5f, 0.5f, 0.5f);
1247 setColorEnd(0.3f, 0.3f, 0.3f, 0.f);
1248 } else if (name == "fire") {
1249 setEmissionRate(60.f);
1250 setParticleLifetime(0.4f, 1.0f);
1251 setEmitterLifetime(-1.f);
1252 setDirection(-kPi * 0.5f);
1253 setSpread(0.5f);
1254 setSpeed(20.f, 80.f);
1255 setLinearAcceleration(-15.f, -80.f, 15.f, -20.f);
1256 setRadialAcceleration(-20.f, 10.f);
1257 setTangentialAcceleration(-30.f, 30.f);
1258 setEmissionArea("ellipse", 20.f, 8.f);
1259 setParticleSize(10.f, 10.f);
1260 setSizes(1.2f, 0.3f);
1261 setSizeVariation(0.25f);
1262 setSpin(-2.f, 2.f);
1263 setColorStart(1.f, 0.7f, 0.1f, 1.f);
1264 setColorEnd(1.f, 0.1f, 0.f, 0.f);
1265 }
1266}
1267
1268bool ParticleEmitter::applyConfig(const std::string &json) {
1269 return applyConfigText(this, json, nullptr);
1270}
1271
1272void ParticleEmitter::setSoftParticles(bool enabled, float particleDepth, float fadeDistance) {
1273 auto c = config();
1274 c->softParticles = enabled;
1275 c->softParticleDepth = std::clamp(particleDepth, 0.f, 1.f);
1276 c->softFadeDistance = std::max(fadeDistance, 1e-5f);
1277}
1278
1280 if (!config()->softParticles || !gpuSim()->residentActive) return false;
1281 auto* gfx = eve::ModuleManager::getInstance<eve::graphics::Graphics>("Graphics");
1282 return gfx && gfx->getSceneLinearDepthTexture() != nullptr;
1283}
1284
1285bool ParticleEmitter::loadConfig(const std::string &path) {
1286 return loadConfigFile(this, path, nullptr);
1287}
1288
1289bool ParticleEmitter::reloadConfig() { return reloadConfigFile(this, nullptr); }
1290
1291void ParticleEmitter::setAutoReload(bool enable) { resource()->autoReload = enable; }
1292bool ParticleEmitter::getAutoReload() { return resource()->autoReload; }
1293std::string ParticleEmitter::getConfigPath() { return resource()->path; }
1294
1296 auto *const buffer = storage ? storage->getComponentBuffer<Resource>() : nullptr;
1297 if (!buffer || id >= buffer->size()) return "unbound";
1298 switch (buffer->get(id).lastReloadObservation) {
1299 case Resource::ReloadObservation::Unbound: return "unbound";
1300 case Resource::ReloadObservation::AutoReloadDisabled: return "auto_reload_disabled";
1301 case Resource::ReloadObservation::MtimePollingUnchanged: return "mtime_polling_unchanged";
1302 case Resource::ReloadObservation::MtimePollingReloaded: return "mtime_polling_reloaded";
1303 case Resource::ReloadObservation::MtimeUnavailable: return "mtime_unavailable";
1304 case Resource::ReloadObservation::MtimePollingReloadFailed: return "mtime_polling_reload_failed";
1305 }
1306 return "unbound";
1307}
1308
1310 auto a = attach();
1311 clearAttachSources(*a);
1312 a->kind = Attach::Kind::AnimPose;
1313 a->pose = pose;
1314 a->boneIndex = boneIndex;
1315 a->enabled = pose != nullptr && boneIndex >= 0;
1316 if (!a->enabled) a->kind = Attach::Kind::None;
1317 if (a->enabled) syncAttach();
1318}
1319
1321 animation::AnimSkeleton *skeleton,
1322 const std::string &boneName) {
1323 auto a = attach();
1324 a->skeleton = skeleton;
1325 int idx = -1;
1326 if (skeleton) idx = skeleton->findBone(boneName);
1328 // Preserve skeleton pointer for name lookups after attachToBone cleared sources.
1329 attach()->skeleton = skeleton;
1330}
1331
1333 auto a = attach();
1334 clearAttachSources(*a);
1335 a->kind = Attach::Kind::Spine;
1336 a->spine = spine;
1337 a->boneIndex = boneIndex;
1338 a->enabled = spine != nullptr && boneIndex >= 0 && boneIndex < spine->getBoneCount();
1339 if (!a->enabled) a->kind = Attach::Kind::None;
1340 if (a->enabled) syncAttach();
1341}
1342
1344 const std::string &boneName) {
1345 int idx = -1;
1346 if (spine && spine->getData()) idx = spine->getData()->findBone(boneName);
1347 attachToSpineBone(spine, idx);
1348}
1349
1351 auto a = attach();
1352 clearAttachSources(*a);
1353 a->kind = Attach::Kind::Ik2D;
1354 a->ik2d = skeleton;
1355 a->boneIndex = boneId;
1356 a->enabled = skeleton != nullptr && boneId >= 0 && boneId < skeleton->getBoneCount();
1357 if (!a->enabled) a->kind = Attach::Kind::None;
1358 if (a->enabled) syncAttach();
1359}
1360
1362 auto a = attach();
1363 clearAttachSources(*a);
1364 a->kind = Attach::Kind::Ik3D;
1365 a->ik3d = skeleton;
1366 a->boneIndex = boneId;
1367 a->enabled = skeleton != nullptr && boneId >= 0 && boneId < skeleton->getBoneCount();
1368 if (!a->enabled) a->kind = Attach::Kind::None;
1369 if (a->enabled) syncAttach();
1370}
1371
1372void ParticleEmitter::setAttachOffset(float x, float y, float z) {
1373 auto a = attach();
1374 a->offsetX = x;
1375 a->offsetY = y;
1376 a->offsetZ = z;
1377 if (a->enabled) syncAttach();
1378}
1379
1380void ParticleEmitter::setAttachPlane(const std::string &plane) {
1381 attach()->plane = normalizePlane(plane);
1382 if (attach()->enabled) syncAttach();
1383}
1384
1386 attach()->scale = scale;
1387 if (attach()->enabled) syncAttach();
1388}
1389
1391 attach()->followRotation = enable;
1392 if (attach()->enabled) syncAttach();
1393}
1394
1396 clearAttachSources(*attach());
1397}
1398
1399bool ParticleEmitter::isAttached() { return attach()->enabled; }
1400int ParticleEmitter::getAttachBone() { return attach()->boneIndex; }
1401
1403 switch (attach()->kind) {
1405 return "anim";
1407 return "spine";
1408 case Attach::Kind::Ik2D:
1409 return "ik2d";
1410 case Attach::Kind::Ik3D:
1411 return "ik3d";
1412 case Attach::Kind::None:
1413 default:
1414 return "none";
1415 }
1416}
1417
1419 syncEmitterSources(*config(), *sim(), *attach(), *skinSource());
1420}
1421
1423 auto s = skinSource();
1424 s->skin = skin;
1425 s->pose = pose;
1426 s->enabled = skin != nullptr && pose != nullptr;
1427 s->candidatesDirty = true;
1428 s->lastSkinnedFrame = -1;
1429}
1430
1431void ParticleEmitter::setSkinBoneFilter(int skeletonBoneIndex, float minWeight) {
1432 auto s = skinSource();
1433 s->filterBone = skeletonBoneIndex;
1434 s->minWeight = minWeight < 0.f ? 0.f : minWeight;
1435 s->candidatesDirty = true;
1436}
1437
1439 const std::string &boneName, float minWeight) {
1440 auto s = skinSource();
1441 s->skeleton = skeleton;
1442 int idx = -1;
1443 if (skeleton) idx = skeleton->findBone(boneName);
1444 setSkinBoneFilter(idx, minWeight);
1445}
1446
1447void ParticleEmitter::setSkinPlane(const std::string &plane) {
1448 skinSource()->plane = normalizePlane(plane);
1449}
1450
1451void ParticleEmitter::setSkinScale(float scale) { skinSource()->scale = scale; }
1452
1454 auto s = skinSource();
1455 s->enabled = false;
1456 s->skin = nullptr;
1457 s->pose = nullptr;
1458 s->filterBone = -1;
1459 s->candidates.clear();
1460 s->candidatesDirty = true;
1461}
1462
1463bool ParticleEmitter::hasSkinSource() { return skinSource()->enabled; }
1464
1466 if (count <= 0) return;
1467 auto s = skinSource();
1468 if (!s->enabled) return;
1469 auto c = config();
1470 auto simc = sim();
1471 for (int i = 0; i < count; ++i) {
1472 float sx = c->x, sy = c->y;
1473 if (!sampleSkinSpawn(*s, *simc, sx, sy)) break;
1474 spawnParticleAt(*c, *simc, sx, sy);
1475 }
1476}
1477
1478} // namespace eve::particles
double z
double y
double x
LogicalId target
float w
Definition AnimClip.cpp:738
eve::EntitySpatialPose pose
const std::string & s
float degrees
Definition CardTypes.cpp:38
glm::vec4 p[6]
std::string name
Definition ECS.cpp:154
float strength
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
std::uint32_t spawned
glm::vec3 n
Definition Grass.cpp:63
double r
float v
std::int32_t c
float blend
int h
std::uint32_t height
std::uint32_t width
float ratio
std::function< void(b3JointId, const Numbers &)> write
size_t offset
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
double radius
Definition MeleeHit.cpp:42
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
MeshVfxBatchedDraw draw
std::shared_ptr< OceanGpuSpectrum > gpu
glm::dvec3 dx
double dt
std::shared_ptr< const OceanSprayFrame > previous
gpgpu::Gpgpu & gp
Definition OnnxGpgpu.cpp:42
std::unique_ptr< gpgpu::GpuBuffer > buffer
Definition OnnxGpgpu.cpp:26
Texture * texture
TileLayer * layer
int idx
float f
std::string path
Definition PlayHost.cpp:111
bool hit
Object::Ptr value
float d
float t
Shader * shader
bool found
std::string kind
std::string resource
float dy
Definition Shadow.cpp:151
double restitution
int count
bool visible
uint32_t seed
Definition TreeMesh.cpp:276
double oy
double ox
float fraction
Borrowed 2D signed-distance field consumed by particle collision.
Definition ParticleSdf.h:25
virtual ParticleSdfGradientStatus gradient(float x, float y, float &outNx, float &outNy) const =0
Approximate outward unit gradient at a world-space position.
virtual float sample(float x, float y) const =0
Sample signed distance at a world-space particle position.
Evaluated local (and optional world) pose for an AnimSkeleton. Script type: AnimPose.
Definition AnimPose.h:17
3D bone hierarchy + bind-pose local TRS for skeletal animation. Independent of ik::Skeleton3D (FABRIK...
int findBone(const std::string &name) const
Finds bone.
CPU linear-blend skinning binding for one mesh against an AnimSkeleton.
Definition AnimSkin.h:47
float getSkinnedPositionX(int vertexIndex) const
Cached skinned position component (requires updateSkinnedPositions).
Definition AnimSkin.cpp:258
float getSkinnedPositionZ(int vertexIndex) const
Returns the skinned position z.
Definition AnimSkin.cpp:268
float getSkinnedPositionY(int vertexIndex) const
Returns the skinned position y.
Definition AnimSkin.cpp:263
int findBone(const std::string &name) const
Finds bone.
Runtime Spine skeleton pose (local + world bone transforms, slot attachments). Script type: SpineSkel...
int getBoneCount() const
Returns the bone count.
SpineSkeletonData * getData() const
Returns the data.
Declarative 2D camera (viewport center + zoom).
Canvas public API.
Definition Canvas.h:17
Custom GPU program.
Definition Shader.h:41
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
Script-facing 2D skeleton + pose state. Bone indices are stable after each createBone / topological r...
Definition Skeleton2D.h:16
int getBoneCount() const
Number of bones currently in the skeleton.
Script-facing 3D skeleton + pose state. Local angles are yaw/pitch in the parent bone frame.
Definition Skeleton3D.h:15
int getBoneCount() const
Number of bones currently in the skeleton.
float sample(float t, float fallback) const
Sample at normalized t; fallback is returned when the curve is empty.
ECS emitter entity. Script configures components; ParticleSimSystem / ParticleRenderSystem drive per-...
void applyPreset(const std::string &name)
Named preset: "spark" / "smoke" / "fire". Unknown → no-op.
std::string getSortMode()
Return the configured transparent ordering policy.
void addSizeCurvePoint(float t, float v)
void setDistortionStrength(float strengthPixels)
Set the maximum scene-color refraction offset in screen pixels.
void setFlipbook(int hframes, int vframes, float framesPerSecond=0.f, float randomStart=0.f)
void addColorStop(float t, float r, float g, float b, float a)
void setSkinBoneFilter(int skeletonBoneIndex, float minWeight=0.f)
void setLimitVelocity(float maxSpeed)
graphics::Texture * getNormalTexture()
Return the configured particle normal map.
void addVelocityCurvePoint(float t, float v)
void setFloatParameter(const std::string &name, float value)
Set a named gameplay/VFX float parameter without rebuilding the emitter.
void attachToSkeleton2D(eve::ik::Skeleton2D *skeleton, int boneId)
void attachToSkeleton3D(eve::ik::Skeleton3D *skeleton, int boneId)
std::string getMotionVectorPolicy()
Return the normalized motion-vector policy.
float getFloatParameter(const std::string &name, float fallback=0.f)
Return a named float parameter, or fallback when absent.
void setSpin(float minSpin, float maxSpin)
eve::IParticleSdfField * getSdfField()
Return the borrowed SDF field, or null. @ownership Borrowed. The emitter does not own the field; do n...
void setTexture(graphics::Texture *texture)
bool isGpuFeatureSetSupported()
Return whether the configured feature set can use resident GPU simulation.
std::string getSimulationBackend()
Return "gpu" for active resident simulation, otherwise "cpu".
void bindFloatParameter(const std::string &name, const std::string &target, float scale=1.f, float offset=0.f)
Bind a parameter to emission, speed, size, or playback scaling.
float getDistortionStrength()
Return the configured scene-color refraction offset in screen pixels.
void clearFloatParameters()
Remove all exposed float values.
void setPosition(float x, float y)
void setRenderMode(const std::string &mode, float stretchFactor=1.f)
void attachToSpineBone(animation::SpineSkeleton *spine, int boneIndex)
void setNormalTexture(graphics::Texture *texture)
Set an optional tangent-space normal map for lit particles.
static ParticleEmitter * createEmitter(int bufferSize=1000)
void setMaterialMode(const std::string &mode)
Select particle shading: "unlit", "lit", or scene-color "distortion".
void setSkinBoneFilterByName(animation::AnimSkeleton *skeleton, const std::string &boneName, float minWeight=0.f)
bool loadConfig(const std::string &path)
void setCollisionBounds(bool enabled, float minX, float minY, float maxX, float maxY)
std::string getAttachKind()
"none" | "anim" | "spine" | "ik2d" | "ik3d"
bool isSoftParticlesActive()
True when soft particles have both a resident renderer and scene depth.
void setSkinPlane(const std::string &plane)
void setSizes(float startScale, float endScale)
void setRenderAxis(float degrees)
Set the fixed screen-space orientation used by render mode "axis".
void setRadialAcceleration(float minA, float maxA)
bool isGpuSimulationActive()
Return true after this emitter has migrated to a resident GPU backend.
void setSpeed(float minSpeed, float maxSpeed)
void setBlendMode(const std::string &mode)
void addForceField(float x, float y, float radius, float strength, float falloff=1.f)
void setCanvas(graphics::Canvas *canvas)
void attachToBone(animation::AnimPose *pose, int boneIndex)
void setOverflowMode(const std::string &mode)
void setStartRotation(float minDeg, float maxDeg)
void setCamera(graphics::Camera2D *camera)
float getResolvedParameterScale(const std::string &target)
Return the resolved non-negative multiplier for a supported target.
void setLinearAcceleration(float xmin, float ymin, float xmax, float ymax)
void emitFromSkin(int count)
Burst-emit count particles from the current skinned surface.
std::string getGpuFallbackReason()
Explain CPU fallback; empty means GPU active, "pending_activation" means eligible.
void syncAttach()
Sync Config.x/y (and direction) from the attached bone. Also called by ParticleSimSystem.
void setTangentialAcceleration(float minA, float maxA)
bool hasFloatParameter(const std::string &name)
Return whether a named float parameter exists.
bool applyConfig(const std::string &json)
void setSkinSource(animation::AnimSkin *skin, animation::AnimPose *pose)
void addRotationCurvePoint(float t, float v)
void setSoftParticles(bool enabled, float particleDepth=0.5f, float fadeDistance=0.05f)
Fade resident particles where they intersect sampled scene depth.
std::string getConfigReloadObservation() const
Return the explicit config reload observation state.
void setCollision(const std::string &mode, float radius=0.f, float restitution=0.6f, float lifetimeLoss=0.f)
void addSubEmitter(ParticleEmitter *target, const std::string &trigger, float inheritVelocity=0.f)
void setColorEnd(float r, float g, float b, float a=1.f)
std::string getMaterialMode()
Return the normalized particle shading mode.
void setEmissionArea(const std::string &type, float x, float y)
void setColorStart(float r, float g, float b, float a=1.f)
void setNoise(float strength, float frequency=1.f, float speed=1.f)
void setSortMode(const std::string &mode)
Select stable per-emitter transparent ordering.
void attachToSpineBoneByName(animation::SpineSkeleton *spine, const std::string &boneName)
void setShader(graphics::Shader *shader)
void setMotionVectorPolicy(const std::string &policy)
Set motion-vector policy: none, velocity, or spawn_delta.
void clearFloatParameterBindings()
Remove all parameter-to-runtime bindings.
void setSizeVariation(float variation)
void attachToBoneByName(animation::AnimPose *pose, animation::AnimSkeleton *skeleton, const std::string &boneName)
void setSimulationSpace(const std::string &space)
void setAttachOffset(float x, float y, float z)
void setLights(bool enabled, float radius=120.f, float intensity=1.f, float r=1.f, float g=1.f, float b=1.f, int maxLights=4)
bool isMotionVectorActive()
True when a graphics path is actually writing motion vectors.
void setRibbon(float width=1.f, float minSegmentLength=1.f)
Configure connected ribbon rendering and switch to ribbon mode.
void setParticleLifetime(float minLife, float maxLife)
void addBurst(float time, int count)
void setAttachPlane(const std::string &plane)
void setSdfField(eve::IParticleSdfField *field)
Bind a borrowed SDF field for particle collision sampling.
void setInheritVelocity(float fraction)
void setGravity(float x, float y)
void setParticleSize(float width, float height)
void invalidate() noexcept
Mark active recording invalid after a producer failure; disabled journals remain disabled.
ParticleRecordState state() const noexcept
Current lifecycle and failure state.
bool spawnParticle(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &sim)
Spawn particle.
void setWorldCollisionResolver(WorldCollisionFn fn)
Sets the world collision resolver.
bool loadConfigFile(ParticleEmitter *emitter, const std::string &path, std::string *error)
Read path via Filesystem, apply, and bind Resource.path + modtime for hot reload. Returns false if fi...
bool(*)(float x, float y, float radius, float &nx, float &ny) WorldCollisionFn
World collision query used by emitters with worldCollision enabled.
bool reloadConfigFile(ParticleEmitter *emitter, std::string *error)
Re-read Resource.path if set; updates modtime.
void stepEmitterSim(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &sim, float dt)
Step emitter sim.
void recordParticleEvent(const ParticleEmitter::Config &config, ParticleEmitter::Sim &sim, const Particle &particle, ParticleRecordEventKind kind)
Internal simulation hook; captures at Sim recordingSeconds and records sticky failures....
bool applyConfigText(ParticleEmitter *emitter, const std::string &json, std::string *error)
Parse JSON text and apply.
WorldCollisionFn getWorldCollisionResolver()
Returns the world collision resolver.
bool sampleSkinSpawn(ParticleEmitter::SkinSource &skinSrc, ParticleEmitter::Sim &sim, float &outX, float &outY)
Sample skin spawn.
void syncEmitterSources(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &, ParticleEmitter::Attach &attach, ParticleEmitter::SkinSource &skinSrc)
Sync bone attach + refresh skin cache; call before stepEmitterSim when using Attach/SkinSource.
bool spawnParticleAt(ParticleEmitter::Config &cfg, ParticleEmitter::Sim &sim, float x, float y)
Spawn particle at.
glm::vec4 Color
Render-neutral RGBA color shared by graphics-facing modules.
Definition RenderTypes.h:8
@ Defined
Finite outward unit gradient written to the output components.
SettlementPipeline::Stage fn
bool enabled
void transformPoint(float x, float y, float z, float &ox, float &oy, float &oz) const
Transform point.
Definition AnimMath.h:205
static constexpr Mat4 fromTRS(const TransformTRS &t) noexcept
From trs.
Definition AnimMath.h:163
Optional bone attachment. When enabled, syncAttach() writes Config.x/y (and optionally direction) fro...
Timed burst emission (fired once while the emitter is active).
Radial attract/repel force fields (strength > 0 attract, < 0 repel).
Script-linked sub-emitters (birth / death / collision triggers).
float limitVelocity
Max speed; 0 = unlimited. Applied after forces each step.
float maxDeltaTime
Cap per-step delta time (0 = unlimited).
float noiseStrength
Turbulence: random per-particle acceleration scaled by strength.
float resolvedParameterScale(const std::string &target) const
Resolved parameter scale.
eve::IParticleSdfField * sdfField
Borrowed 2D SDF used as an additional collision solid. @ownership Borrowed. Cleared by the caller bef...
std::string simSpace
"world" (default) or "local" (particles track the emitter).
std::string overflowMode
Buffer-full strategy: "drop" (default) | "pause" | "warn".
ParticleCurve velocityCurve
Optional speed multiplier curve over lifetime.
float emissionRateOverDistance
Distance-based emission in particles per world unit (0 = disabled).
float inheritVelocity
Fraction [0,1] of the emitter's current velocity added to new particles.
float damping
Per-second velocity damping fraction in [0,1].
bool looping
Restart the emitter timeline after emitterLife instead of stopping.
float gravityX
Gravity applied every step (world units/s²).
bool worldCollision
Query the engine-level world collision resolver each step.
std::string collisionMode
"none" | "kill" | "bounce" | "stop" on collision.
Bound config file for hot reload (empty path = unbound).
int spawnQuota
Temporary automatic-spawn quota set by ParticleSimSystem (-1 = unlimited).
double recordingSeconds
Explicit accumulated executed simulation dt since recording preparation.
ParticleEventJournal recording
Optional bounded recording owner; disabled by default, independent of emitter looping/reset age.
std::uint64_t nextBirthSerial
Sole CPU birth counter; reset/start/stop preserve it. Zero means exhausted, never wrap to a reused ID...
Optional skinned-mesh surface source. When enabled, newly spawned particles sample random (optionally...
std::vector< int > candidates
Vertex indices eligible for sampling (rebuilt when filter changes).
Single live particle (CPU simulation).