ParticleEffect.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. //
  2. // Copyright (c) 2008-2014 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 "ParticleEffect.h"
  27. #include "ResourceCache.h"
  28. #include "XMLFile.h"
  29. #include "DebugNew.h"
  30. namespace Urho3D
  31. {
  32. static const char* emitterTypeNames[] =
  33. {
  34. "Sphere",
  35. "Box",
  36. 0
  37. };
  38. static const Vector2 DEFAULT_PARTICLE_SIZE(0.1f, 0.1f);
  39. static const float DEFAULT_EMISSION_RATE = 10.0f;
  40. static const float MIN_EMISSION_RATE = 0.01f;
  41. static const float DEFAULT_TIME_TO_LIVE = 1.0f;
  42. static const float DEFAULT_VELOCITY = 1.0f;
  43. static const Vector3 DEFAULT_DIRECTION_MIN(-1.0f, -1.0f, -1.0f);
  44. static const Vector3 DEFAULT_DIRECTION_MAX(1.0f, 1.0f, 1.0f);
  45. ParticleEffect::ParticleEffect(Context* context) :
  46. Resource(context),
  47. numParticles_(DEFAULT_NUM_PARTICLES),
  48. updateInvisible_(false),
  49. relative_(true),
  50. scaled_(true),
  51. sorted_(false),
  52. animationLodBias_(0.0f),
  53. emitterType_(EMITTER_SPHERE),
  54. emitterSize_(Vector3::ZERO),
  55. directionMin_(DEFAULT_DIRECTION_MIN),
  56. directionMax_(DEFAULT_DIRECTION_MAX),
  57. constantForce_(Vector3::ZERO),
  58. dampingForce_(0.0f),
  59. activeTime_(0.0f),
  60. inactiveTime_(0.0f),
  61. emissionRateMin_(DEFAULT_EMISSION_RATE),
  62. emissionRateMax_(DEFAULT_EMISSION_RATE),
  63. sizeMin_(DEFAULT_PARTICLE_SIZE),
  64. sizeMax_(DEFAULT_PARTICLE_SIZE),
  65. timeToLiveMin_(DEFAULT_TIME_TO_LIVE),
  66. timeToLiveMax_(DEFAULT_TIME_TO_LIVE),
  67. velocityMin_(DEFAULT_VELOCITY),
  68. velocityMax_(DEFAULT_VELOCITY),
  69. rotationMin_(0.0f),
  70. rotationMax_(0.0f),
  71. rotationSpeedMin_(0.0f),
  72. rotationSpeedMax_(0.0f),
  73. sizeAdd_(0.0f),
  74. sizeMul_(1.0f)
  75. {
  76. }
  77. ParticleEffect::~ParticleEffect()
  78. {
  79. }
  80. void ParticleEffect::RegisterObject(Context* context)
  81. {
  82. context->RegisterFactory<ParticleEffect>();
  83. }
  84. bool ParticleEffect::BeginLoad(Deserializer& source)
  85. {
  86. loadMaterialName_.Clear();
  87. XMLFile file(context_);
  88. if (!file.Load(source))
  89. {
  90. LOGERROR("Load particle effect file failed");
  91. return false;
  92. }
  93. XMLElement rootElem = file.GetRoot();
  94. if (!rootElem)
  95. {
  96. LOGERROR("Particle emitter parameter file does not have a valid root element");
  97. return false;
  98. }
  99. // Reset to defaults first so that missing parameters in case of a live reload behave as expected
  100. material_.Reset();
  101. numParticles_ = DEFAULT_NUM_PARTICLES;
  102. updateInvisible_ = false;
  103. relative_ = true;
  104. scaled_ = true;
  105. sorted_ = false;
  106. animationLodBias_ = 0.0f;
  107. emitterType_ = EMITTER_SPHERE;
  108. emitterSize_ = Vector3::ZERO;
  109. directionMin_ = DEFAULT_DIRECTION_MIN;
  110. directionMax_ = DEFAULT_DIRECTION_MAX;
  111. constantForce_ = Vector3::ZERO;
  112. dampingForce_ = 0.0f;
  113. activeTime_ = 0.0f;
  114. inactiveTime_ = 0.0;
  115. emissionRateMin_ = DEFAULT_EMISSION_RATE;
  116. emissionRateMax_ = DEFAULT_EMISSION_RATE;
  117. sizeMin_ = DEFAULT_PARTICLE_SIZE;
  118. sizeMax_ = DEFAULT_PARTICLE_SIZE;
  119. timeToLiveMin_ = DEFAULT_TIME_TO_LIVE;
  120. timeToLiveMax_ = DEFAULT_TIME_TO_LIVE;
  121. velocityMin_ = DEFAULT_VELOCITY;
  122. velocityMax_ = DEFAULT_VELOCITY;
  123. rotationMin_ = 0.0f;
  124. rotationMax_ = 0.0f;
  125. rotationSpeedMin_ = 0.0f;
  126. rotationSpeedMax_ = 0.0f;
  127. sizeAdd_ = 0.0f;
  128. sizeMul_ = 1.0f;
  129. colorFrames_.Clear();
  130. textureFrames_.Clear();
  131. if (rootElem.HasChild("material"))
  132. {
  133. loadMaterialName_ = rootElem.GetChild("material").GetAttribute("name");
  134. // If async loading, can not GetResource() the material. But can do a background request for it
  135. if (GetAsyncLoadState() == ASYNC_LOADING)
  136. GetSubsystem<ResourceCache>()->BackgroundLoadResource<Material>(loadMaterialName_, true, this);
  137. }
  138. if (rootElem.HasChild("numparticles"))
  139. SetNumParticles(rootElem.GetChild("numparticles").GetInt("value"));
  140. if (rootElem.HasChild("updateinvisible"))
  141. updateInvisible_ = rootElem.GetChild("updateinvisible").GetBool("enable");
  142. if (rootElem.HasChild("relative"))
  143. relative_ = rootElem.GetChild("relative").GetBool("enable");
  144. if (rootElem.HasChild("scaled"))
  145. scaled_ = rootElem.GetChild("scaled").GetBool("enable");
  146. if (rootElem.HasChild("sorted"))
  147. sorted_ = rootElem.GetChild("sorted").GetBool("enable");
  148. if (rootElem.HasChild("animlodbias"))
  149. SetAnimationLodBias(rootElem.GetChild("animlodbias").GetFloat("value"));
  150. if (rootElem.HasChild("emittertype"))
  151. {
  152. String type = rootElem.GetChild("emittertype").GetAttributeLower("value");
  153. if (type == "point")
  154. {
  155. // Point emitter type is deprecated, handled as zero sized sphere
  156. emitterType_ = EMITTER_SPHERE;
  157. emitterSize_ = Vector3::ZERO;
  158. }
  159. else if (type == "box")
  160. emitterType_ = EMITTER_BOX;
  161. else if (type == "sphere")
  162. emitterType_ = EMITTER_SPHERE;
  163. else
  164. LOGERROR("Unknown particle emitter type " + type);
  165. }
  166. if (rootElem.HasChild("emittersize"))
  167. emitterSize_ = rootElem.GetChild("emittersize").GetVector3("value");
  168. if (rootElem.HasChild("emitterradius"))
  169. emitterSize_.x_ = emitterSize_.y_ = emitterSize_.z_ = rootElem.GetChild("emitterradius").GetFloat("value");
  170. if (rootElem.HasChild("direction"))
  171. GetVector3MinMax(rootElem.GetChild("direction"), directionMin_, directionMax_);
  172. if (rootElem.HasChild("constantforce"))
  173. constantForce_ = rootElem.GetChild("constantforce").GetVector3("value");
  174. if (rootElem.HasChild("dampingforce"))
  175. dampingForce_ = rootElem.GetChild("dampingforce").GetFloat("value");
  176. if (rootElem.HasChild("activetime"))
  177. activeTime_ = rootElem.GetChild("activetime").GetFloat("value");
  178. if (activeTime_ < 0.0f)
  179. activeTime_ = M_INFINITY;
  180. if (rootElem.HasChild("inactivetime"))
  181. inactiveTime_ = rootElem.GetChild("inactivetime").GetFloat("value");
  182. if (inactiveTime_ < 0.0f)
  183. inactiveTime_ = M_INFINITY;
  184. if (rootElem.HasChild("emissionrate"))
  185. GetFloatMinMax(rootElem.GetChild("emissionrate"), emissionRateMin_, emissionRateMax_);
  186. if (rootElem.HasChild("interval"))
  187. {
  188. float intervalMin = 0.0f;
  189. float intervalMax = 0.0f;
  190. GetFloatMinMax(rootElem.GetChild("interval"), intervalMin, intervalMax);
  191. emissionRateMax_ = 1.0f / intervalMin;
  192. emissionRateMin_ = 1.0f / intervalMax;
  193. }
  194. if (rootElem.HasChild("particlesize"))
  195. GetVector2MinMax(rootElem.GetChild("particlesize"), sizeMin_, sizeMax_);
  196. if (rootElem.HasChild("timetolive"))
  197. GetFloatMinMax(rootElem.GetChild("timetolive"), timeToLiveMin_, timeToLiveMax_);
  198. if (rootElem.HasChild("velocity"))
  199. GetFloatMinMax(rootElem.GetChild("velocity"), velocityMin_, velocityMax_);
  200. if (rootElem.HasChild("rotation"))
  201. GetFloatMinMax(rootElem.GetChild("rotation"), rotationMin_, rotationMax_);
  202. if (rootElem.HasChild("rotationspeed"))
  203. GetFloatMinMax(rootElem.GetChild("rotationspeed"), rotationSpeedMin_, rotationSpeedMax_);
  204. if (rootElem.HasChild("sizedelta"))
  205. {
  206. XMLElement deltaElem = rootElem.GetChild("sizedelta");
  207. if (deltaElem.HasAttribute("add"))
  208. sizeAdd_ = deltaElem.GetFloat("add");
  209. if (deltaElem.HasAttribute("mul"))
  210. sizeMul_ = deltaElem.GetFloat("mul");
  211. }
  212. if (rootElem.HasChild("color"))
  213. {
  214. ColorFrame colorFrame(rootElem.GetChild("color").GetColor("value"));
  215. SetColorFrame(0, colorFrame);
  216. }
  217. if (rootElem.HasChild("colorfade"))
  218. {
  219. Vector<ColorFrame> fades;
  220. for (XMLElement colorFadeElem = rootElem.GetChild("colorfade"); colorFadeElem; colorFadeElem = colorFadeElem.GetNext("colorfade"))
  221. fades.Push(ColorFrame(colorFadeElem.GetColor("color"), colorFadeElem.GetFloat("time")));
  222. SetColorFrames(fades);
  223. }
  224. if (colorFrames_.Empty())
  225. colorFrames_.Push(ColorFrame(Color::WHITE));
  226. if (rootElem.HasChild("texanim"))
  227. {
  228. Vector<TextureFrame> animations;
  229. for (XMLElement animElem = rootElem.GetChild("texanim"); animElem; animElem = animElem.GetNext("texanim"))
  230. {
  231. TextureFrame animation;
  232. animation.uv_ = animElem.GetRect("uv");
  233. animation.time_ = animElem.GetFloat("time");
  234. animations.Push(animation);
  235. }
  236. SetTextureFrames(animations);
  237. }
  238. return true;
  239. }
  240. bool ParticleEffect::EndLoad()
  241. {
  242. // Apply the material now
  243. if (!loadMaterialName_.Empty())
  244. {
  245. SetMaterial(GetSubsystem<ResourceCache>()->GetResource<Material>(loadMaterialName_));
  246. loadMaterialName_.Clear();
  247. }
  248. return true;
  249. }
  250. bool ParticleEffect::Save(Serializer& dest) const
  251. {
  252. XMLFile file(context_);
  253. XMLElement rootElem = file.CreateRoot("particleeffect");
  254. XMLElement childElem = rootElem.CreateChild("material");
  255. childElem.SetAttribute("name", GetResourceName(material_));
  256. childElem = rootElem.CreateChild("numparticles");
  257. childElem.SetInt("value", numParticles_);
  258. childElem = rootElem.CreateChild("updateinvisible");
  259. childElem.SetBool("enable", updateInvisible_);
  260. childElem = rootElem.CreateChild("relative");
  261. childElem.SetBool("enable", relative_);
  262. childElem = rootElem.CreateChild("scaled");
  263. childElem.SetBool("enable", scaled_);
  264. childElem = rootElem.CreateChild("sorted");
  265. childElem.SetBool("enable", sorted_);
  266. childElem = rootElem.CreateChild("animlodbias");
  267. childElem.SetFloat("value", animationLodBias_);
  268. childElem = rootElem.CreateChild("emittertype");
  269. childElem.SetAttribute("value", emitterTypeNames[emitterType_]);
  270. childElem = rootElem.CreateChild("emittersize");
  271. childElem.SetVector3("value", emitterSize_);
  272. childElem = rootElem.CreateChild("direction");
  273. childElem.SetVector3("min", directionMin_);
  274. childElem.SetVector3("max", directionMax_);
  275. childElem = rootElem.CreateChild("constantforce");
  276. childElem.SetVector3("value", constantForce_);
  277. childElem = rootElem.CreateChild("dampingforce");
  278. childElem.SetFloat("value", dampingForce_);
  279. childElem = rootElem.CreateChild("activetime");
  280. childElem.SetFloat("value", activeTime_);
  281. childElem = rootElem.CreateChild("inactivetime");
  282. childElem.SetFloat("value", inactiveTime_);
  283. childElem = rootElem.CreateChild("emissionrate");
  284. childElem.SetFloat("min", emissionRateMin_);
  285. childElem.SetFloat("max", emissionRateMax_);
  286. childElem = rootElem.CreateChild("particlesize");
  287. childElem.SetVector2("min", sizeMin_);
  288. childElem.SetVector2("max", sizeMax_);
  289. childElem = rootElem.CreateChild("timetolive");
  290. childElem.SetFloat("min", timeToLiveMin_);
  291. childElem.SetFloat("max", timeToLiveMax_);
  292. childElem = rootElem.CreateChild("velocity");
  293. childElem.SetFloat("min", velocityMin_);
  294. childElem.SetFloat("max", velocityMax_);
  295. childElem = rootElem.CreateChild("rotation");
  296. childElem.SetFloat("min", rotationMin_);
  297. childElem.SetFloat("max", rotationMax_);
  298. childElem = rootElem.CreateChild("rotationspeed");
  299. childElem.SetFloat("min", rotationSpeedMin_);
  300. childElem.SetFloat("max", rotationSpeedMax_);
  301. childElem = rootElem.CreateChild("sizedelta");
  302. childElem.SetFloat("add", sizeAdd_);
  303. childElem.SetFloat("mul", sizeMul_);
  304. if (colorFrames_.Size() == 1)
  305. {
  306. childElem = rootElem.CreateChild("color");
  307. childElem.SetColor("value", colorFrames_[0].color_);
  308. }
  309. if (colorFrames_.Size() > 1)
  310. {
  311. for (unsigned i = 0; i < colorFrames_.Size(); ++i)
  312. {
  313. childElem = rootElem.CreateChild("colorfade");
  314. childElem.SetColor("color", colorFrames_[i].color_);
  315. childElem.SetFloat("time", colorFrames_[i].time_);
  316. }
  317. }
  318. for (unsigned i = 0; i < textureFrames_.Size(); ++i)
  319. {
  320. childElem = rootElem.CreateChild("texanim");
  321. childElem.SetRect("uv", textureFrames_[i].uv_);
  322. childElem.SetFloat("time", textureFrames_[i].time_);
  323. }
  324. return file.Save(dest);
  325. }
  326. void ParticleEffect::SetMaterial(Material* material)
  327. {
  328. material_ = material;
  329. }
  330. void ParticleEffect::SetNumParticles(unsigned num)
  331. {
  332. numParticles_ = Max(0, num);
  333. }
  334. void ParticleEffect::SetUpdateInvisible(bool enable)
  335. {
  336. updateInvisible_ = enable;
  337. }
  338. void ParticleEffect::SetRelative(bool enable)
  339. {
  340. relative_ = enable;
  341. }
  342. void ParticleEffect::SetScaled(bool enable)
  343. {
  344. scaled_ = enable;
  345. }
  346. void ParticleEffect::SetSorted(bool enable)
  347. {
  348. sorted_ = enable;
  349. }
  350. void ParticleEffect::SetAnimationLodBias(float lodBias)
  351. {
  352. animationLodBias_ = lodBias;
  353. }
  354. void ParticleEffect::SetEmitterType(EmitterType type)
  355. {
  356. emitterType_ = type;
  357. }
  358. void ParticleEffect::SetEmitterSize(const Vector3& size)
  359. {
  360. emitterSize_ = size;
  361. }
  362. void ParticleEffect::SetMinDirection(const Vector3& direction)
  363. {
  364. directionMin_ = direction;
  365. }
  366. void ParticleEffect::SetMaxDirection(const Vector3& direction)
  367. {
  368. directionMax_ = direction;
  369. }
  370. void ParticleEffect::SetConstantForce(const Vector3& force)
  371. {
  372. constantForce_ = force;
  373. }
  374. void ParticleEffect::SetDampingForce(float force)
  375. {
  376. dampingForce_ = force;
  377. }
  378. void ParticleEffect::SetActiveTime(float time)
  379. {
  380. activeTime_ = time;
  381. }
  382. void ParticleEffect::SetInactiveTime(float time)
  383. {
  384. inactiveTime_ = time;
  385. }
  386. void ParticleEffect::SetMinEmissionRate(float rate)
  387. {
  388. emissionRateMin_ = Max(rate, MIN_EMISSION_RATE);
  389. }
  390. void ParticleEffect::SetMaxEmissionRate(float rate)
  391. {
  392. emissionRateMax_ = Max(rate, MIN_EMISSION_RATE);
  393. }
  394. void ParticleEffect::SetMinParticleSize(const Vector2& size)
  395. {
  396. sizeMin_ = size;
  397. }
  398. void ParticleEffect::SetMaxParticleSize(const Vector2& size)
  399. {
  400. sizeMax_ = size;
  401. }
  402. void ParticleEffect::SetMinTimeToLive(float time)
  403. {
  404. timeToLiveMin_ = Max(time, 0.0f);
  405. }
  406. void ParticleEffect::SetMaxTimeToLive(float time)
  407. {
  408. timeToLiveMax_ = Max(time, 0.0f);
  409. }
  410. void ParticleEffect::SetMinVelocity(float velocity)
  411. {
  412. velocityMin_ = velocity;
  413. }
  414. void ParticleEffect::SetMaxVelocity(float velocity)
  415. {
  416. velocityMax_ = velocity;
  417. }
  418. void ParticleEffect::SetMinRotation(float rotation)
  419. {
  420. rotationMin_ = rotation;
  421. }
  422. void ParticleEffect::SetMaxRotation(float rotation)
  423. {
  424. rotationMax_ = rotation;
  425. }
  426. void ParticleEffect::SetMinRotationSpeed(float speed)
  427. {
  428. rotationSpeedMin_ = speed;
  429. }
  430. void ParticleEffect::SetMaxRotationSpeed(float speed)
  431. {
  432. rotationSpeedMax_ = speed;
  433. }
  434. void ParticleEffect::SetSizeAdd(float sizeAdd)
  435. {
  436. sizeAdd_ = sizeAdd;
  437. }
  438. void ParticleEffect::SetSizeMul(float sizeMul)
  439. {
  440. sizeMul_ = sizeMul;
  441. }
  442. void ParticleEffect::SetColorFrames(const Vector<ColorFrame>& colorFrames)
  443. {
  444. colorFrames_ = colorFrames;
  445. }
  446. void ParticleEffect::SetColorFrame(unsigned index, const ColorFrame& colorFrame)
  447. {
  448. if (colorFrames_.Size() < index + 1)
  449. colorFrames_.Resize(index + 1);
  450. colorFrames_[index] = colorFrame;
  451. }
  452. void ParticleEffect::SetTextureFrames(const Vector<TextureFrame>& textureFrames)
  453. {
  454. textureFrames_ = textureFrames;
  455. }
  456. void ParticleEffect::SetTextureFrame(unsigned index, const TextureFrame& textureFrame)
  457. {
  458. if (textureFrames_.Size() < index + 1)
  459. textureFrames_.Resize(index + 1);
  460. textureFrames_[index] = textureFrame;
  461. }
  462. const ColorFrame* ParticleEffect::GetColorFrame(unsigned index) const
  463. {
  464. return index < colorFrames_.Size() ? &colorFrames_[index] : (ColorFrame*)0;
  465. }
  466. const TextureFrame* ParticleEffect::GetTextureFrame(unsigned index) const
  467. {
  468. return index < colorFrames_.Size() ? &textureFrames_[index] : (TextureFrame*)0;
  469. }
  470. Vector3 ParticleEffect::GetRandomDirection() const
  471. {
  472. return Vector3(
  473. Lerp(directionMin_.x_, directionMax_.x_, Random(1.0f)),
  474. Lerp(directionMin_.y_, directionMax_.y_, Random(1.0f)),
  475. Lerp(directionMin_.z_, directionMax_.z_, Random(1.0f))
  476. );
  477. }
  478. Vector2 ParticleEffect::GetRandomSize() const
  479. {
  480. return sizeMin_.Lerp(sizeMax_, Random(1.0f));
  481. }
  482. float ParticleEffect::GetRandomVelocity() const
  483. {
  484. return Lerp(velocityMin_, velocityMax_, Random(1.0f));
  485. }
  486. float ParticleEffect::GetRandomTimeToLive() const
  487. {
  488. return Lerp(timeToLiveMin_, timeToLiveMax_, Random(1.0f));
  489. }
  490. float ParticleEffect::GetRandomRotationSpeed() const
  491. {
  492. return Lerp(rotationSpeedMin_, rotationSpeedMax_, Random(1.0f));
  493. }
  494. float ParticleEffect::GetRandomRotation() const
  495. {
  496. return Lerp(rotationMin_, rotationMax_, Random(1.0f));
  497. }
  498. void ParticleEffect::GetFloatMinMax(const XMLElement& element, float& minValue, float& maxValue)
  499. {
  500. if (element.IsNull())
  501. return;
  502. if (element.HasAttribute("value"))
  503. minValue = maxValue = element.GetFloat("value");
  504. if (element.HasAttribute("min") && element.HasAttribute("max"))
  505. {
  506. minValue = element.GetFloat("min");
  507. maxValue = element.GetFloat("max");
  508. }
  509. }
  510. void ParticleEffect::GetVector2MinMax(const XMLElement& element, Vector2& minValue, Vector2& maxValue)
  511. {
  512. if (element.IsNull())
  513. return;
  514. if (element.HasAttribute("value"))
  515. minValue = maxValue = element.GetVector2("value");
  516. if (element.HasAttribute("min") && element.HasAttribute("max"))
  517. {
  518. minValue = element.GetVector2("min");
  519. maxValue = element.GetVector2("max");
  520. }
  521. }
  522. void ParticleEffect::GetVector3MinMax(const XMLElement& element, Vector3& minValue, Vector3& maxValue)
  523. {
  524. if (element.IsNull())
  525. return;
  526. if (element.HasAttribute("value"))
  527. minValue = maxValue = element.GetVector3("value");
  528. if (element.HasAttribute("min") && element.HasAttribute("max"))
  529. {
  530. minValue = element.GetVector3("min");
  531. maxValue = element.GetVector3("max");
  532. }
  533. }
  534. }