CCPUEmitterTranslator.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2016 Chukong Technologies Inc.
  4. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  5. http://www.cocos2d-x.org
  6. Permission is hereby granted, free of charge, to any person obtaining a copy
  7. of this software and associated documentation files (the "Software"), to deal
  8. in the Software without restriction, including without limitation the rights
  9. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. copies of the Software, and to permit persons to whom the Software is
  11. furnished to do so, subject to the following conditions:
  12. The above copyright notice and this permission notice shall be included in
  13. all copies or substantial portions of the Software.
  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 "CCPUEmitterTranslator.h"
  23. #include "extensions/Particle3D/PU/CCPUParticleSystem3D.h"
  24. #include "extensions/Particle3D/PU/CCPUDynamicAttribute.h"
  25. #include "extensions/Particle3D/PU/CCPUDynamicAttributeTranslator.h"
  26. #include "extensions/Particle3D/PU/CCPUEmitterManager.h"
  27. NS_CC_BEGIN
  28. PUEmitterTranslator::PUEmitterTranslator()
  29. :_emitter(nullptr)
  30. {
  31. }
  32. //-------------------------------------------------------------------------
  33. void PUEmitterTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
  34. {
  35. PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
  36. PUObjectAbstractNode* parent = obj->parent ? reinterpret_cast<PUObjectAbstractNode*>(obj->parent) : 0;
  37. // The name of the obj is the type of the emitter
  38. // Remark: This can be solved by using a listener, so that obj->values is filled with type + name. Something for later
  39. std::string type;
  40. if(!obj->name.empty())
  41. {
  42. type = obj->name;
  43. }
  44. //// Get the factory
  45. //ParticleEmitterFactory* particleEmitterFactory = ParticleSystemManager::getSingletonPtr()->getEmitterFactory(type);
  46. //if (!particleEmitterFactory)
  47. //{
  48. // compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
  49. // return;
  50. //}
  51. PUScriptTranslator *particleEmitterTranlator = PUEmitterManager::Instance()->getTranslator(type);
  52. if (!particleEmitterTranlator) return;
  53. //// Create the emitter
  54. //mEmitter = ParticleSystemManager::getSingletonPtr()->createEmitter(type);
  55. //if (!mEmitter)
  56. //{
  57. // compiler->addError(ScriptCompiler::CE_INVALIDPARAMETERS, obj->file, obj->line);
  58. // return;
  59. //}
  60. _emitter = PUEmitterManager::Instance()->createEmitter(type);
  61. if (!_emitter) return;
  62. _emitter->setEmitterType(type);
  63. if (parent && parent->context)
  64. {
  65. PUParticleSystem3D* system = static_cast<PUParticleSystem3D*>(parent->context);
  66. system->addEmitter(_emitter);
  67. }
  68. // The first value is the (optional) name
  69. std::string name;
  70. if(!obj->values.empty())
  71. {
  72. getString(*obj->values.front(), &name);
  73. _emitter->setName(name);
  74. }
  75. // Set it in the context
  76. obj->context = _emitter;
  77. // Run through properties
  78. for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
  79. {
  80. if((*i)->type == ANT_PROPERTY)
  81. {
  82. PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
  83. if (prop->name == token[TOKEN_ENABLED])
  84. {
  85. // Property: enabled
  86. if (passValidateProperty(compiler, prop, token[TOKEN_ENABLED], VAL_BOOL))
  87. {
  88. bool val;
  89. if(getBoolean(*prop->values.front(), &val))
  90. {
  91. _emitter->setEnabled(val);
  92. }
  93. }
  94. }
  95. else if (prop->name == token[TOKEN_POSITION])
  96. {
  97. // Property: position
  98. if (passValidateProperty(compiler, prop, token[TOKEN_POSITION], VAL_VECTOR3))
  99. {
  100. Vec3 val;
  101. if(getVector3(prop->values.begin(), prop->values.end(), &val))
  102. {
  103. //mEmitter->position = val;
  104. //mEmitter->originalPosition = val;
  105. _emitter->setLocalPosition(val);
  106. }
  107. }
  108. }
  109. else if (prop->name == token[TOKEN_EMITTER_DIRECTION])
  110. {
  111. // Property: direction
  112. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_DIRECTION], VAL_VECTOR3))
  113. {
  114. Vec3 val;
  115. if(getVector3(prop->values.begin(), prop->values.end(), &val))
  116. {
  117. _emitter->setParticleDirection(val);
  118. }
  119. }
  120. }
  121. else if (prop->name == token[TOKEN_EMITTER_ORIENTATION])
  122. {
  123. // Property: orientation
  124. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION], VAL_QUATERNION))
  125. {
  126. Quaternion val;
  127. if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
  128. {
  129. _emitter->setParticleOrientation(val);
  130. }
  131. }
  132. }
  133. else if (prop->name == token[TOKEN_EMITTER_START_ORIENTATION_RANGE])
  134. {
  135. // Property: start_orientation_range
  136. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_ORIENTATION_RANGE], VAL_QUATERNION))
  137. {
  138. Quaternion val;
  139. if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
  140. {
  141. _emitter->setParticleOrientationRangeStart(val);
  142. }
  143. }
  144. }
  145. else if (prop->name == token[TOKEN_EMITTER_ORIENTATION_RANGE_START])
  146. {
  147. // Property: range_start_orientation (deprecated and replaced by start_orientation_range)
  148. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION_RANGE_START], VAL_QUATERNION))
  149. {
  150. Quaternion val;
  151. if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
  152. {
  153. _emitter->setParticleOrientationRangeStart(val);
  154. }
  155. }
  156. }
  157. else if (prop->name == token[TOKEN_EMITTER_END_ORIENTATION_RANGE])
  158. {
  159. // Property: end_orientation_range
  160. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_ORIENTATION_RANGE], VAL_QUATERNION))
  161. {
  162. Quaternion val;
  163. if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
  164. {
  165. _emitter->setParticleOrientationRangeEnd(val);
  166. }
  167. }
  168. }
  169. else if (prop->name == token[TOKEN_EMITTER_ORIENTATION_RANGE_END])
  170. {
  171. // Property: range_end_orientation (deprecated and replaced by end_orientation_range)
  172. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ORIENTATION_RANGE_END], VAL_QUATERNION))
  173. {
  174. Quaternion val;
  175. if(getQuaternion(prop->values.begin(), prop->values.end(), &val))
  176. {
  177. _emitter->setParticleOrientationRangeEnd(val);
  178. }
  179. }
  180. }
  181. else if (prop->name == token[TOKEN_EMITTER_EMISSION_RATE])
  182. {
  183. // Property: emission_rate
  184. // If it is a property, it is a fixed value
  185. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_EMISSION_RATE], VAL_REAL))
  186. {
  187. float val = 0.0f;
  188. if(getFloat(*prop->values.front(), &val))
  189. {
  190. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  191. dynamicAttributeFixed->setValue(val);
  192. _emitter->setDynEmissionRate(dynamicAttributeFixed);
  193. }
  194. }
  195. }
  196. else if (prop->name == token[TOKEN_TIME_TO_LIVE])
  197. {
  198. // Property: time_to_live
  199. // If it is a property, it is a fixed value
  200. if (passValidateProperty(compiler, prop, token[TOKEN_TIME_TO_LIVE], VAL_REAL))
  201. {
  202. float val = 0.0f;
  203. if(getFloat(*prop->values.front(), &val))
  204. {
  205. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  206. dynamicAttributeFixed->setValue(val);
  207. _emitter->setDynTotalTimeToLive(dynamicAttributeFixed);
  208. }
  209. }
  210. }
  211. else if (prop->name == token[TOKEN_EMITTER_MASS])
  212. {
  213. // Property: mass
  214. // If it is a property, it is a fixed value
  215. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_MASS], VAL_REAL))
  216. {
  217. float val = 0.0f;
  218. if(getFloat(*prop->values.front(), &val))
  219. {
  220. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  221. dynamicAttributeFixed->setValue(val);
  222. _emitter->setDynParticleMass(dynamicAttributeFixed);
  223. }
  224. }
  225. }
  226. else if (prop->name == token[TOKEN_EMITTER_START_TEXCOORDS_RANGE])
  227. {
  228. // Property: start_texture_coords_range
  229. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_TEXCOORDS_RANGE], VAL_UINT))
  230. {
  231. unsigned int val = 0;
  232. if(getUInt(*prop->values.front(), &val))
  233. {
  234. _emitter->setParticleTextureCoordsRangeStart(val);
  235. }
  236. }
  237. }
  238. else if (prop->name == token[TOKEN_EMITTER_START_TEXCOORDS])
  239. {
  240. // Property: start_texture_coords (deprecated and replaced by start_texture_coords_range)
  241. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_TEXCOORDS], VAL_UINT))
  242. {
  243. unsigned int val = 0;
  244. if(getUInt(*prop->values.front(), &val))
  245. {
  246. _emitter->setParticleTextureCoordsRangeStart(val);
  247. }
  248. }
  249. }
  250. else if (prop->name == token[TOKEN_EMITTER_END_TEXCOORDS_RANGE])
  251. {
  252. // Property: end_texture_coords_range
  253. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_TEXCOORDS_RANGE], VAL_UINT))
  254. {
  255. unsigned int val = 0;
  256. if(getUInt(*prop->values.front(), &val))
  257. {
  258. _emitter->setParticleTextureCoordsRangeEnd(val);
  259. }
  260. }
  261. }
  262. else if (prop->name == token[TOKEN_EMITTER_END_TEXCOORDS])
  263. {
  264. // Property: end_texture_coords (deprecated and replaced by end_texture_coords_range)
  265. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_TEXCOORDS], VAL_UINT))
  266. {
  267. unsigned int val = 0;
  268. if(getUInt(*prop->values.front(), &val))
  269. {
  270. _emitter->setParticleTextureCoordsRangeEnd(val);
  271. }
  272. }
  273. }
  274. else if (prop->name == token[TOKEN_EMITTER_TEXCOORDS])
  275. {
  276. // Property: texture_coords
  277. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_TEXCOORDS], VAL_UINT))
  278. {
  279. unsigned int val = 0;
  280. if(getUInt(*prop->values.front(), &val))
  281. {
  282. _emitter->setParticleTextureCoords(val);
  283. }
  284. }
  285. }
  286. else if (prop->name == token[TOKEN_EMITTER_START_COLOUR_RANGE])
  287. {
  288. // Property: start_colour_range
  289. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_START_COLOUR_RANGE], VAL_COLOURVALUE))
  290. {
  291. Vec4 val;
  292. if(getVector4(prop->values.begin(), prop->values.end(), &val))
  293. {
  294. _emitter->setParticleColorRangeStart(val);
  295. }
  296. }
  297. }
  298. else if (prop->name == token[TOKEN_EMITTER_END_COLOUR_RANGE])
  299. {
  300. // Property: end_colour_range
  301. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_END_COLOUR_RANGE], VAL_COLOURVALUE))
  302. {
  303. Vec4 val;
  304. if(getVector4(prop->values.begin(), prop->values.end(), &val))
  305. {
  306. _emitter->setParticleColorRangeEnd(val);
  307. }
  308. }
  309. }
  310. else if (prop->name == token[TOKEN_EMITTER_COLOUR])
  311. {
  312. // Property: colour
  313. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_COLOUR], VAL_COLOURVALUE))
  314. {
  315. Vec4 val;
  316. if(getVector4(prop->values.begin(), prop->values.end(), &val))
  317. {
  318. _emitter->setParticleColor(val);
  319. }
  320. }
  321. }
  322. else if (prop->name == token[TOKEN_VELOCITY])
  323. {
  324. // Property: velocity
  325. // If it is a property, it is a fixed value
  326. if (passValidateProperty(compiler, prop, token[TOKEN_VELOCITY], VAL_REAL))
  327. {
  328. float val = 0.0f;
  329. if(getFloat(*prop->values.front(), &val))
  330. {
  331. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  332. dynamicAttributeFixed->setValue(val);
  333. _emitter->setDynVelocity(dynamicAttributeFixed);
  334. }
  335. }
  336. }
  337. else if (prop->name == token[TOKEN_EMITTER_DURATION])
  338. {
  339. // Property: duration
  340. // If it is a property, it is a fixed value
  341. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_DURATION], VAL_REAL))
  342. {
  343. float val = 0.0f;
  344. if(getFloat(*prop->values.front(), &val))
  345. {
  346. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  347. dynamicAttributeFixed->setValue(val);
  348. _emitter->setDynDuration(dynamicAttributeFixed);
  349. }
  350. }
  351. }
  352. else if (prop->name == token[TOKEN_EMITTER_REPEAT_DELAY])
  353. {
  354. // Property: repeat_delay
  355. // If it is a property, it is a fixed value
  356. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_REPEAT_DELAY], VAL_REAL))
  357. {
  358. float val = 0.0f;
  359. if(getFloat(*prop->values.front(), &val))
  360. {
  361. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  362. dynamicAttributeFixed->setValue(val);
  363. _emitter->setDynRepeatDelay(dynamicAttributeFixed);
  364. }
  365. }
  366. }
  367. else if (prop->name == token[TOKEN_EMITTER_EMITS])
  368. {
  369. // Property: emits
  370. if (passValidatePropertyNumberOfValues(compiler, prop, token[TOKEN_EMITTER_EMITS], 2))
  371. {
  372. std::string particleType;
  373. PUAbstractNodeList::const_iterator it = prop->values.begin();
  374. if (getString(**it, &particleType))
  375. {
  376. if (particleType == token[TOKEN_VISUAL_PARTICLE])
  377. {
  378. _emitter->setEmitsType(PUParticle3D::PT_VISUAL);
  379. }
  380. else if (particleType == token[TOKEN_EMITTER_PARTICLE])
  381. {
  382. _emitter->setEmitsType(PUParticle3D::PT_EMITTER);
  383. }
  384. else if (particleType == token[TOKEN_AFFECTOR_PARTICLE])
  385. {
  386. _emitter->setEmitsType(PUParticle3D::PT_AFFECTOR);
  387. }
  388. else if (particleType == token[TOKEN_TECHNIQUE_PARTICLE])
  389. {
  390. _emitter->setEmitsType(PUParticle3D::PT_TECHNIQUE);
  391. }
  392. else if (particleType == token[TOKEN_SYSTEM_PARTICLE])
  393. {
  394. _emitter->setEmitsType(PUParticle3D::PT_SYSTEM);
  395. }
  396. ++it;
  397. if (getString(**it, &name))
  398. {
  399. _emitter->setEmitsName(name);
  400. }
  401. }
  402. }
  403. }
  404. else if (prop->name == token[TOKEN_ANGLE])
  405. {
  406. // Property: angle
  407. // If it is a property, it is a fixed value
  408. if (passValidateProperty(compiler, prop, token[TOKEN_ANGLE], VAL_REAL))
  409. {
  410. float val = 0.0f;
  411. if(getFloat(*prop->values.front(), &val))
  412. {
  413. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  414. dynamicAttributeFixed->setValue(val);
  415. _emitter->setDynAngle(dynamicAttributeFixed);
  416. }
  417. }
  418. }
  419. else if (prop->name == token[TOKEN_EMITTER_ALL_PARTICLE_DIM])
  420. {
  421. // Property: all_particle_dimensions
  422. // If it is a property, it is a fixed value
  423. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_ALL_PARTICLE_DIM], VAL_REAL))
  424. {
  425. float val = 0.0f;
  426. if(getFloat(*prop->values.front(), &val))
  427. {
  428. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  429. dynamicAttributeFixed->setValue(val);
  430. _emitter->setDynParticleAllDimensions(dynamicAttributeFixed);
  431. }
  432. }
  433. }
  434. else if (prop->name == token[TOKEN_EMITTER_PARTICLE_WIDTH])
  435. {
  436. // Property: particle_width
  437. // If it is a property, it is a fixed value
  438. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_WIDTH], VAL_REAL))
  439. {
  440. float val = 0.0f;
  441. if(getFloat(*prop->values.front(), &val))
  442. {
  443. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  444. dynamicAttributeFixed->setValue(val);
  445. _emitter->setDynParticleWidth(dynamicAttributeFixed);
  446. }
  447. }
  448. }
  449. else if (prop->name == token[TOKEN_EMITTER_PARTICLE_HEIGHT])
  450. {
  451. // Property: particle_height
  452. // If it is a property, it is a fixed value
  453. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_HEIGHT], VAL_REAL))
  454. {
  455. float val = 0.0f;
  456. if(getFloat(*prop->values.front(), &val))
  457. {
  458. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  459. dynamicAttributeFixed->setValue(val);
  460. _emitter->setDynParticleHeight(dynamicAttributeFixed);
  461. }
  462. }
  463. }
  464. else if (prop->name == token[TOKEN_EMITTER_PARTICLE_DEPTH])
  465. {
  466. // Property: particle_depth
  467. // If it is a property, it is a fixed value
  468. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_PARTICLE_DEPTH], VAL_REAL))
  469. {
  470. float val = 0.0f;
  471. if(getFloat(*prop->values.front(), &val))
  472. {
  473. PUDynamicAttributeFixed* dynamicAttributeFixed = new (std::nothrow) PUDynamicAttributeFixed();
  474. dynamicAttributeFixed->setValue(val);
  475. _emitter->setDynParticleDepth(dynamicAttributeFixed);
  476. }
  477. }
  478. }
  479. else if (prop->name == token[TOKEN_EMITTER_AUTO_DIRECTION])
  480. {
  481. // Property: auto_direction
  482. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_AUTO_DIRECTION], VAL_BOOL))
  483. {
  484. bool val;
  485. if(getBoolean(*prop->values.front(), &val))
  486. {
  487. _emitter->setAutoDirection(val);
  488. }
  489. }
  490. }
  491. else if (prop->name == token[TOKEN_KEEP_LOCAL])
  492. {
  493. // Property: keep_local
  494. if (passValidateProperty(compiler, prop, token[TOKEN_KEEP_LOCAL], VAL_BOOL))
  495. {
  496. bool val;
  497. if(getBoolean(*prop->values.front(), &val))
  498. {
  499. _emitter->setKeepLocal(val);
  500. }
  501. }
  502. }
  503. else if (prop->name == token[TOKEN_EMITTER_FORCE_EMISSION])
  504. {
  505. // Property: force_emission
  506. if (passValidateProperty(compiler, prop, token[TOKEN_EMITTER_FORCE_EMISSION], VAL_BOOL))
  507. {
  508. bool val;
  509. if(getBoolean(*prop->values.front(), &val))
  510. {
  511. _emitter->setForceEmission(val);
  512. }
  513. }
  514. }
  515. else if (particleEmitterTranlator->translateChildProperty(compiler, *i))
  516. {
  517. // Parsed the property by another translator; do nothing
  518. }
  519. else
  520. {
  521. errorUnexpectedProperty(compiler, prop);
  522. }
  523. }
  524. else if((*i)->type == ANT_OBJECT)
  525. {
  526. PUObjectAbstractNode* child = reinterpret_cast<PUObjectAbstractNode*>((*i));
  527. PUDynamicAttributeTranslator dynamicAttributeTranslator;
  528. if (child->cls == token[TOKEN_EMITTER_EMISSION_RATE])
  529. {
  530. // Property: emission_rate
  531. dynamicAttributeTranslator.translate(compiler, *i);
  532. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  533. _emitter->setDynEmissionRate(dynamicAttribute);
  534. }
  535. else if (child->cls == token[TOKEN_TIME_TO_LIVE])
  536. {
  537. // Property: time_to_live
  538. dynamicAttributeTranslator.translate(compiler, *i);
  539. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  540. _emitter->setDynTotalTimeToLive(dynamicAttribute);
  541. }
  542. else if (child->cls == token[TOKEN_EMITTER_MASS])
  543. {
  544. // Property: mass
  545. dynamicAttributeTranslator.translate(compiler, *i);
  546. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  547. _emitter->setDynParticleMass(dynamicAttribute);
  548. }
  549. else if (child->cls == token[TOKEN_VELOCITY])
  550. {
  551. // Property: velocity
  552. dynamicAttributeTranslator.translate(compiler, *i);
  553. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  554. _emitter->setDynVelocity(dynamicAttribute);
  555. }
  556. else if (child->cls == token[TOKEN_EMITTER_DURATION])
  557. {
  558. // Property: duration
  559. dynamicAttributeTranslator.translate(compiler, *i);
  560. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  561. _emitter->setDynDuration(dynamicAttribute);
  562. }
  563. else if (child->cls == token[TOKEN_EMITTER_REPEAT_DELAY])
  564. {
  565. // Property: repeat_delay
  566. dynamicAttributeTranslator.translate(compiler, *i);
  567. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  568. _emitter->setDynRepeatDelay(dynamicAttribute);
  569. }
  570. else if (child->cls == token[TOKEN_ANGLE])
  571. {
  572. // Property: angle
  573. dynamicAttributeTranslator.translate(compiler, *i);
  574. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  575. _emitter->setDynAngle(dynamicAttribute);
  576. }
  577. else if (child->cls == token[TOKEN_EMITTER_ALL_PARTICLE_DIM])
  578. {
  579. // Property: all_particle_dimensions
  580. dynamicAttributeTranslator.translate(compiler, *i);
  581. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  582. _emitter->setDynParticleAllDimensions(dynamicAttribute);
  583. }
  584. else if (child->cls == token[TOKEN_EMITTER_PARTICLE_WIDTH])
  585. {
  586. // Property: particle_width
  587. dynamicAttributeTranslator.translate(compiler, *i);
  588. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  589. _emitter->setDynParticleWidth(dynamicAttribute);
  590. }
  591. else if (child->cls == token[TOKEN_EMITTER_PARTICLE_HEIGHT])
  592. {
  593. // Property: particle_height
  594. dynamicAttributeTranslator.translate(compiler, *i);
  595. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  596. _emitter->setDynParticleHeight(dynamicAttribute);
  597. }
  598. else if (child->cls == token[TOKEN_EMITTER_PARTICLE_DEPTH])
  599. {
  600. // Property: particle_depth
  601. dynamicAttributeTranslator.translate(compiler, *i);
  602. PUDynamicAttribute* dynamicAttribute = static_cast<PUDynamicAttribute*>(child->context);
  603. _emitter->setDynParticleDepth(dynamicAttribute);
  604. }
  605. else if (child->cls == token[TOKEN_CAMERA_DEPENDENCY])
  606. {
  607. //// Property: it can only be a camera_dependency for emission rate
  608. //CameraDependency* cameraDependency = PU_NEW_T(CameraDependency, MEMCATEGORY_SCRIPTING)();
  609. //child->context = Any(cameraDependency);
  610. //CameraDependencyTranslator cameraDependencyTranslator;
  611. //cameraDependencyTranslator.translate(compiler, *i);
  612. //Real threshold = cameraDependency->getThreshold();
  613. //mEmitter->setEmissionRateCameraDependency(threshold * threshold, cameraDependency->isIncrease());
  614. //// Delete the camera dependency
  615. //PU_DELETE_T(cameraDependency, CameraDependency, MEMCATEGORY_SCRIPTING);
  616. }
  617. else if (particleEmitterTranlator->translateChildObject(compiler, *i))
  618. {
  619. // Parsed the object by another translator; do nothing
  620. }
  621. else
  622. {
  623. processNode(compiler, *i);
  624. }
  625. }
  626. else
  627. {
  628. errorUnexpectedToken(compiler, *i);
  629. }
  630. }
  631. }
  632. NS_CC_END