ParticleEmitter.cpp 20 KB

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