ParticleEmitter.cpp 20 KB

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