ParticleEffect.cpp 18 KB

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