ParticleEmitter.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2012 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Context.h"
  25. #include "Log.h"
  26. #include "Material.h"
  27. #include "MemoryBuffer.h"
  28. #include "ParticleEmitter.h"
  29. #include "Profiler.h"
  30. #include "ResourceCache.h"
  31. #include "Scene.h"
  32. #include "SceneEvents.h"
  33. #include "XMLFile.h"
  34. #include "DebugNew.h"
  35. namespace Urho3D
  36. {
  37. OBJECTTYPESTATIC(ParticleEmitter);
  38. ParticleEmitter::ParticleEmitter(Context* context) :
  39. BillboardSet(context),
  40. emitterType_(EMITTER_POINT),
  41. emitterSize_(Vector3::ZERO),
  42. directionMin_(Vector3(-1.0f, -1.0f, -1.0f)),
  43. directionMax_(Vector3(1.0f, 1.0f, 1.0f)),
  44. constanceForce_(Vector3::ZERO),
  45. sizeMin_(Vector2(0.1f, 0.1f)),
  46. sizeMax_(Vector2(0.1f, 0.1f)),
  47. dampingForce_(0.0f),
  48. emitterRadius_(0.0f),
  49. periodTimer_(0.0f),
  50. emissionTimer_(0.0f),
  51. activeTime_(0.0f),
  52. inactiveTime_(0.0f),
  53. intervalMin_(0.1f),
  54. intervalMax_(0.1f),
  55. timeToLiveMin_(1.0f),
  56. timeToLiveMax_(1.0f),
  57. velocityMin_(1.0f),
  58. velocityMax_(1.0f),
  59. rotationMin_(0.0f),
  60. rotationMax_(0.0f),
  61. rotationSpeedMin_(0.0f),
  62. rotationSpeedMax_(0.0f),
  63. sizeAdd_(0.0f),
  64. sizeMul_(1.0f),
  65. active_(true),
  66. updateInvisible_(false),
  67. lastTimeStep_(0.0f),
  68. lastUpdateFrameNumber_(M_MAX_UNSIGNED)
  69. {
  70. SetParticleColor(Color(1.0f, 1.0f, 1.0f));
  71. SetNumParticles(10);
  72. }
  73. ParticleEmitter::~ParticleEmitter()
  74. {
  75. }
  76. void ParticleEmitter::RegisterObject(Context* context)
  77. {
  78. context->RegisterFactory<ParticleEmitter>();
  79. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_RESOURCEREF, "Parameter Source", GetParameterSourceAttr, SetParameterSourceAttr, ResourceRef, ResourceRef(XMLFile::GetTypeStatic()), AM_DEFAULT);
  80. ATTRIBUTE(ParticleEmitter, VAR_BOOL, "Is Active", active_, true, AM_DEFAULT);
  81. ATTRIBUTE(ParticleEmitter, VAR_BOOL, "Is Visible", visible_, true, AM_DEFAULT);
  82. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_BOOL, "Can Be Occluded", IsOccludee, SetOccludee, bool, true, AM_DEFAULT);
  83. ATTRIBUTE(ParticleEmitter, VAR_BOOL, "Cast Shadows", castShadows_, false, AM_DEFAULT);
  84. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_FLOAT, "Draw Distance", GetDrawDistance, SetDrawDistance, float, 0.0f, AM_DEFAULT);
  85. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_FLOAT, "Shadow Distance", GetShadowDistance, SetShadowDistance, float, 0.0f, AM_DEFAULT);
  86. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_FLOAT, "Animation LOD Bias", GetAnimationLodBias, SetAnimationLodBias, float, 1.0f, AM_DEFAULT);
  87. ATTRIBUTE(ParticleEmitter, VAR_FLOAT, "Period Timer", periodTimer_, 0.0f, AM_DEFAULT | AM_NOEDIT);
  88. ATTRIBUTE(ParticleEmitter, VAR_FLOAT, "Emission Timer", emissionTimer_, 0.0f, AM_DEFAULT | AM_NOEDIT);
  89. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_VARIANTVECTOR, "Particles", GetParticlesAttr, SetParticlesAttr, VariantVector, VariantVector(), AM_FILE | AM_NOEDIT);
  90. ACCESSOR_ATTRIBUTE(ParticleEmitter, VAR_VARIANTVECTOR, "Billboards", GetBillboardsAttr, SetBillboardsAttr, VariantVector, VariantVector(), AM_FILE | AM_NOEDIT);
  91. }
  92. void ParticleEmitter::Update(const FrameInfo& frame)
  93. {
  94. // If there is an amount mismatch between particles and billboards, correct it
  95. if (particles_.Size() != billboards_.Size())
  96. SetNumBillboards(particles_.Size());
  97. bool needBillboardUpdate = false;
  98. // Check active/inactive period switching
  99. periodTimer_ += lastTimeStep_;
  100. if (active_)
  101. {
  102. if (activeTime_ && periodTimer_ >= activeTime_)
  103. {
  104. active_ = false;
  105. periodTimer_ -= activeTime_;
  106. }
  107. }
  108. else
  109. {
  110. if (inactiveTime_ && periodTimer_ >= inactiveTime_)
  111. {
  112. active_ = true;
  113. periodTimer_ -= inactiveTime_;
  114. }
  115. }
  116. // Check for emitting a new particle
  117. if (active_)
  118. {
  119. emissionTimer_ += lastTimeStep_;
  120. if (emissionTimer_ > 0.0f)
  121. {
  122. emissionTimer_ -= Lerp(intervalMin_, intervalMax_, Random(1.0f));
  123. if (EmitNewParticle())
  124. needBillboardUpdate = true;
  125. }
  126. }
  127. // Update existing particles
  128. Vector3 relativeConstantForce = node_->GetWorldRotation().Inverse() * constanceForce_;
  129. // If billboards are not relative, apply scaling to the position update
  130. Vector3 scaleVector = Vector3::ONE;
  131. if (scaled_ && !relative_)
  132. scaleVector = node_->GetWorldScale();
  133. for (unsigned i = 0; i < particles_.Size(); ++i)
  134. {
  135. Particle& particle = particles_[i];
  136. Billboard& billboard = billboards_[i];
  137. if (billboard.enabled_)
  138. {
  139. needBillboardUpdate = true;
  140. // Time to live
  141. if (particle.timer_ >= particle.timeToLive_)
  142. {
  143. billboard.enabled_ = false;
  144. continue;
  145. }
  146. particle.timer_ += lastTimeStep_;
  147. // Velocity & position
  148. if (constanceForce_ != Vector3::ZERO)
  149. {
  150. if (relative_)
  151. particle.velocity_ += lastTimeStep_ * relativeConstantForce;
  152. else
  153. particle.velocity_ += lastTimeStep_ * constanceForce_;
  154. }
  155. if (dampingForce_ != 0.0f)
  156. {
  157. Vector3 force = -dampingForce_ * particle.velocity_;
  158. particle.velocity_ += lastTimeStep_ * force;
  159. }
  160. billboard.position_ += lastTimeStep_ * particle.velocity_ * scaleVector;
  161. // Rotation
  162. billboard.rotation_ += lastTimeStep_ * particle.rotationSpeed_;
  163. // Scaling
  164. if (sizeAdd_ != 0.0f || sizeMul_ != 1.0f)
  165. {
  166. particle.scale_ += lastTimeStep_ * sizeAdd_;
  167. if (sizeMul_ != 1.0f)
  168. particle.scale_ *= (lastTimeStep_ * (sizeMul_ - 1.0f)) + 1.0f;
  169. billboard.size_ = particle.size_ * particle.scale_;
  170. }
  171. // Color interpolation
  172. unsigned& index = particle.colorIndex_;
  173. if (index < colors_.Size())
  174. {
  175. if (index < colors_.Size() - 1)
  176. {
  177. if (particle.timer_ >= colors_[index + 1].time_)
  178. ++index;
  179. }
  180. if (index < colors_.Size() - 1)
  181. billboard.color_ = colors_[index].interpolate(colors_[index + 1], particle.timer_);
  182. else
  183. billboard.color_ = colors_[index].color_;
  184. }
  185. // Texture animation
  186. unsigned& texIndex = particle.texIndex_;
  187. if (textureAnimation_.Size() && texIndex < textureAnimation_.Size() - 1)
  188. {
  189. if (particle.timer_ >= textureAnimation_[texIndex + 1].time_)
  190. {
  191. billboard.uv_ = textureAnimation_[texIndex + 1].uv_;
  192. ++texIndex;
  193. }
  194. }
  195. }
  196. }
  197. if (needBillboardUpdate)
  198. Updated();
  199. }
  200. bool ParticleEmitter::LoadParameters(XMLFile* file)
  201. {
  202. ResourceCache* cache = GetSubsystem<ResourceCache>();
  203. if (!file || !cache)
  204. return false;
  205. XMLElement rootElem = file->GetRoot();
  206. if (!rootElem)
  207. return false;
  208. parameterSource_ = file;
  209. if (rootElem.HasChild("material"))
  210. SetMaterial(cache->GetResource<Material>(rootElem.GetChild("material").GetAttribute("name")));
  211. if (rootElem.HasChild("numparticles"))
  212. SetNumParticles(rootElem.GetChild("numparticles").GetInt("value"));
  213. if (rootElem.HasChild("updateinvisible"))
  214. updateInvisible_ = rootElem.GetChild("updateinvisible").GetBool("enable");
  215. if (rootElem.HasChild("relative"))
  216. relative_ = rootElem.GetChild("relative").GetBool("enable");
  217. if (rootElem.HasChild("scaled"))
  218. scaled_ = rootElem.GetChild("scaled").GetBool("enable");
  219. if (rootElem.HasChild("sorted"))
  220. sorted_ = rootElem.GetChild("sorted").GetBool("enable");
  221. if (rootElem.HasChild("animlodbias"))
  222. SetAnimationLodBias(rootElem.GetChild("relative").GetFloat("value"));
  223. if (rootElem.HasChild("emittertype"))
  224. {
  225. String type = rootElem.GetChild("emittertype").GetAttributeLower("value");
  226. if (type == "point")
  227. emitterType_ = EMITTER_POINT;
  228. else if (type == "box")
  229. emitterType_ = EMITTER_BOX;
  230. else if (type == "sphere")
  231. emitterType_ = EMITTER_SPHERE;
  232. else
  233. LOGERROR("Unknown particle emitter type " + type);
  234. }
  235. if (rootElem.HasChild("emittersize"))
  236. emitterSize_ = rootElem.GetChild("emittersize").GetVector3("value");
  237. if (rootElem.HasChild("direction"))
  238. GetVector3MinMax(rootElem.GetChild("direction"), directionMin_, directionMax_);
  239. if (rootElem.HasChild("constantforce"))
  240. constanceForce_ = rootElem.GetChild("constantforce").GetVector3("value");
  241. if (rootElem.HasChild("dampingforce"))
  242. dampingForce_ = rootElem.GetChild("dampingforce").GetFloat("value");
  243. if (rootElem.HasChild("activetime"))
  244. activeTime_ = rootElem.GetChild("activetime").GetFloat("value");
  245. if (activeTime_ < 0.0f)
  246. activeTime_ = M_INFINITY;
  247. if (rootElem.HasChild("inactivetime"))
  248. inactiveTime_ = rootElem.GetChild("inactivetime").GetFloat("value");
  249. if (inactiveTime_ < 0.0f)
  250. inactiveTime_ = M_INFINITY;
  251. if (rootElem.HasChild("interval"))
  252. GetFloatMinMax(rootElem.GetChild("interval"), intervalMin_, intervalMax_);
  253. if (rootElem.HasChild("particlesize"))
  254. GetVector2MinMax(rootElem.GetChild("particlesize"), sizeMin_, sizeMax_);
  255. if (rootElem.HasChild("timetolive"))
  256. GetFloatMinMax(rootElem.GetChild("timetolive"), timeToLiveMin_, timeToLiveMax_);
  257. if (rootElem.HasChild("velocity"))
  258. GetFloatMinMax(rootElem.GetChild("velocity"), velocityMin_, velocityMax_);
  259. if (rootElem.HasChild("rotation"))
  260. GetFloatMinMax(rootElem.GetChild("rotation"), rotationMin_, rotationMax_);
  261. if (rootElem.HasChild("rotationspeed"))
  262. GetFloatMinMax(rootElem.GetChild("rotationspeed"), rotationSpeedMin_, rotationSpeedMax_);
  263. if (rootElem.HasChild("sizedelta"))
  264. {
  265. XMLElement deltaElem = rootElem.GetChild("sizedelta");
  266. if (deltaElem.HasAttribute("add"))
  267. sizeAdd_ = deltaElem.GetFloat("add");
  268. if (deltaElem.HasAttribute("mul"))
  269. sizeMul_ = deltaElem.GetFloat("mul");
  270. }
  271. if (rootElem.HasChild("color"))
  272. SetParticleColor(rootElem.GetChild("color").GetColor("value"));
  273. if (rootElem.HasChild("colorfade"))
  274. {
  275. Vector<ColorFade> fades;
  276. XMLElement colorFadeElem = rootElem.GetChild("colorfade");
  277. while (colorFadeElem)
  278. {
  279. ColorFade fade;
  280. fade.color_ = colorFadeElem.GetColor("color");
  281. fade.time_ = colorFadeElem.GetFloat("time");
  282. fades.Push(fade);
  283. colorFadeElem = colorFadeElem.GetNext("colorfade");
  284. }
  285. SetParticleColors(fades);
  286. }
  287. if (rootElem.HasChild("texanim"))
  288. {
  289. Vector<TextureAnimation> animations;
  290. XMLElement animElem = rootElem.GetChild("texanim");
  291. while (animElem)
  292. {
  293. TextureAnimation animation;
  294. animation.uv_ = animElem.GetRect("uv");
  295. animation.time_ = animElem.GetFloat("time");
  296. animations.Push(animation);
  297. animElem = animElem.GetNext("texanim");
  298. }
  299. textureAnimation_ = animations;
  300. }
  301. MarkNetworkUpdate();
  302. return true;
  303. }
  304. void ParticleEmitter::SetActive(bool enable, bool resetPeriod)
  305. {
  306. if (enable != active_ || resetPeriod)
  307. {
  308. active_ = enable;
  309. periodTimer_ = 0.0f;
  310. MarkNetworkUpdate();
  311. }
  312. }
  313. void ParticleEmitter::SetParameterSourceAttr(ResourceRef value)
  314. {
  315. ResourceCache* cache = GetSubsystem<ResourceCache>();
  316. LoadParameters(cache->GetResource<XMLFile>(value.id_));
  317. }
  318. void ParticleEmitter::SetParticlesAttr(VariantVector value)
  319. {
  320. unsigned index = 0;
  321. SetNumParticles(value[index++].GetInt());
  322. for (PODVector<Particle>::Iterator i = particles_.Begin(); i != particles_.End() && index < value.Size(); ++i)
  323. {
  324. i->velocity_ = value[index++].GetVector3();
  325. i->size_ = value[index++].GetVector2();
  326. i->timer_ = value[index++].GetFloat();
  327. i->timeToLive_ = value[index++].GetFloat();
  328. i->scale_ = value[index++].GetFloat();
  329. i->rotationSpeed_ = value[index++].GetFloat();
  330. i->colorIndex_ = value[index++].GetInt();
  331. i->texIndex_ = value[index++].GetInt();
  332. }
  333. }
  334. ResourceRef ParticleEmitter::GetParameterSourceAttr() const
  335. {
  336. return GetResourceRef(parameterSource_, XMLFile::GetTypeStatic());
  337. }
  338. VariantVector ParticleEmitter::GetParticlesAttr() const
  339. {
  340. VariantVector ret;
  341. ret.Push(particles_.Size());
  342. for (PODVector<Particle>::ConstIterator i = particles_.Begin(); i != particles_.End(); ++i)
  343. {
  344. ret.Push(i->velocity_);
  345. ret.Push(i->size_);
  346. ret.Push(i->timer_);
  347. ret.Push(i->timeToLive_);
  348. ret.Push(i->scale_);
  349. ret.Push(i->rotationSpeed_);
  350. ret.Push(i->colorIndex_);
  351. ret.Push(i->texIndex_);
  352. }
  353. return ret;
  354. }
  355. void ParticleEmitter::OnNodeSet(Node* node)
  356. {
  357. BillboardSet::OnNodeSet(node);
  358. if (node)
  359. {
  360. Scene* scene = GetScene();
  361. if (scene)
  362. SubscribeToEvent(scene, E_SCENEPOSTUPDATE, HANDLER(ParticleEmitter, HandleScenePostUpdate));
  363. }
  364. }
  365. void ParticleEmitter::SetNumParticles(int num)
  366. {
  367. num = Max(num, 0);
  368. particles_.Resize(num);
  369. SetNumBillboards(num);
  370. }
  371. void ParticleEmitter::SetParticleColor(const Color& color)
  372. {
  373. ColorFade newColor;
  374. newColor.color_ = color;
  375. newColor.time_ = 0.0f;
  376. colors_.Clear();
  377. colors_.Push(newColor);
  378. }
  379. void ParticleEmitter::SetParticleColors(const Vector<ColorFade>& colors)
  380. {
  381. if (!colors.Size())
  382. return;
  383. colors_ = colors;
  384. }
  385. bool ParticleEmitter::EmitNewParticle()
  386. {
  387. unsigned index = GetFreeParticle();
  388. if (index >= particles_.Size())
  389. return false;
  390. Particle& particle = particles_[index];
  391. Billboard& billboard = billboards_[index];
  392. Vector3 startPos;
  393. Vector3 startDir;
  394. switch (emitterType_)
  395. {
  396. case EMITTER_POINT:
  397. startPos = Vector3::ZERO;
  398. break;
  399. case EMITTER_BOX:
  400. startPos = Vector3(
  401. Random(emitterSize_.x_) - emitterSize_.x_ * 0.5f,
  402. Random(emitterSize_.y_) - emitterSize_.y_ * 0.5f,
  403. Random(emitterSize_.z_) - emitterSize_.z_ * 0.5f
  404. );
  405. break;
  406. case EMITTER_SPHERE:
  407. {
  408. Vector3 dir(
  409. Random(2.0f) - 1.0f,
  410. Random(2.0f) - 1.0f,
  411. Random(2.0f) - 1.0f
  412. );
  413. dir.Normalize();
  414. startPos = Random(emitterRadius_) * dir;
  415. }
  416. break;
  417. }
  418. startDir = Vector3(
  419. Lerp(directionMin_.x_, directionMax_.x_, Random(1.0f)),
  420. Lerp(directionMin_.y_, directionMax_.y_, Random(1.0f)),
  421. Lerp(directionMin_.z_, directionMax_.z_, Random(1.0f))
  422. );
  423. startDir.Normalize();
  424. if (!relative_)
  425. {
  426. startPos = node_->GetWorldTransform() * startPos;
  427. startDir = node_->GetWorldRotation() * startDir;
  428. };
  429. particle.velocity_ = Lerp(velocityMin_, velocityMax_, Random(1.0f)) * startDir;
  430. particle.size_ = sizeMin_.Lerp(sizeMax_, Random(1.0f));
  431. particle.timer_ = 0.0f;
  432. particle.timeToLive_ = Lerp(timeToLiveMin_, timeToLiveMax_, Random(1.0f));
  433. particle.scale_ = 1.0f;
  434. particle.rotationSpeed_ = Lerp(rotationSpeedMin_, rotationSpeedMax_, Random(1.0f));
  435. particle.colorIndex_ = 0;
  436. particle.texIndex_ = 0;
  437. billboard.position_ = startPos;
  438. billboard.size_ = particles_[index].size_;
  439. billboard.uv_ = textureAnimation_.Size() ? textureAnimation_[0].uv_ : Rect::POSITIVE;
  440. billboard.rotation_ = Lerp(rotationMin_, rotationMax_, Random(1.0f));
  441. billboard.color_ = colors_[0].color_;
  442. billboard.enabled_ = true;
  443. return true;
  444. }
  445. unsigned ParticleEmitter::GetFreeParticle() const
  446. {
  447. for (unsigned i = 0; i < billboards_.Size(); ++i)
  448. {
  449. if (!billboards_[i].enabled_)
  450. return i;
  451. }
  452. return M_MAX_UNSIGNED;
  453. }
  454. void ParticleEmitter::GetFloatMinMax(const XMLElement& element, float& minValue, float& maxValue)
  455. {
  456. if (element.IsNull())
  457. return;
  458. if (element.HasAttribute("value"))
  459. minValue = maxValue = element.GetFloat("value");
  460. if (element.HasAttribute("min") && element.HasAttribute("max"))
  461. {
  462. minValue = element.GetFloat("min");
  463. maxValue = element.GetFloat("max");
  464. }
  465. }
  466. void ParticleEmitter::GetVector2MinMax(const XMLElement& element, Vector2& minValue, Vector2& maxValue)
  467. {
  468. if (element.IsNull())
  469. return;
  470. if (element.HasAttribute("value"))
  471. minValue = maxValue = element.GetVector2("value");
  472. if (element.HasAttribute("min") && element.HasAttribute("max"))
  473. {
  474. minValue = element.GetVector2("min");
  475. maxValue = element.GetVector2("max");
  476. }
  477. }
  478. void ParticleEmitter::GetVector3MinMax(const XMLElement& element, Vector3& minValue, Vector3& maxValue)
  479. {
  480. if (element.IsNull())
  481. return;
  482. if (element.HasAttribute("value"))
  483. minValue = maxValue = element.GetVector3("value");
  484. if (element.HasAttribute("min") && element.HasAttribute("max"))
  485. {
  486. minValue = element.GetVector3("min");
  487. maxValue = element.GetVector3("max");
  488. }
  489. }
  490. void ParticleEmitter::HandleScenePostUpdate(StringHash eventType, VariantMap& eventData)
  491. {
  492. // Store scene's timestep and use it instead of global timestep, as time scale may be other than 1
  493. using namespace ScenePostUpdate;
  494. lastTimeStep_ = eventData[P_TIMESTEP].GetFloat();
  495. // If no invisible update, check that the billboardset is in view (framenumber has changed)
  496. if (updateInvisible_ || viewFrameNumber_ != lastUpdateFrameNumber_)
  497. {
  498. lastUpdateFrameNumber_ = viewFrameNumber_;
  499. MarkForUpdate();
  500. }
  501. }
  502. }