CCPUParticleSystem3DTranslator.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 "CCPUParticleSystem3DTranslator.h"
  23. NS_CC_BEGIN
  24. PUParticleSystem3DTranslator::PUParticleSystem3DTranslator()
  25. {
  26. }
  27. PUParticleSystem3DTranslator::~PUParticleSystem3DTranslator()
  28. {
  29. }
  30. void PUParticleSystem3DTranslator::translate(PUScriptCompiler* compiler, PUAbstractNode *node)
  31. {
  32. if (typeid(*node) != typeid(PUObjectAbstractNode))
  33. return;
  34. PUObjectAbstractNode* obj = reinterpret_cast<PUObjectAbstractNode*>(node);
  35. if(obj->name.empty())
  36. {
  37. return;
  38. }
  39. //// Create a particle system with the given name
  40. //_system = PUParticleSystem3D::create();
  41. //PUParticleSystem3DBuilder::Instance()->PUParticleSystem3DList.push_back(_system);
  42. //if (!mSystem)
  43. //{
  44. // return;
  45. //}
  46. obj->context = _system;
  47. _system->setName(obj->name);
  48. for(PUAbstractNodeList::iterator i = obj->children.begin(); i != obj->children.end(); ++i)
  49. {
  50. if((*i)->type == ANT_PROPERTY)
  51. {
  52. PUPropertyAbstractNode* prop = reinterpret_cast<PUPropertyAbstractNode*>((*i));
  53. // if (prop->name == token[TOKEN_PS_ITERATION_INTERVAL])
  54. // {
  55. // // Property: iteration_interval
  56. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_ITERATION_INTERVAL], VAL_REAL))
  57. // {
  58. // Real val = 0.0f;
  59. // if(getReal(prop->values.front(), &val))
  60. // {
  61. // mSystem->setIterationInterval(val);
  62. // }
  63. // }
  64. // }
  65. // else if (prop->name == token[TOKEN_PS_NONVIS_UPDATE_TIMEOUT])
  66. // {
  67. // // Property: nonvisible_update_timeout
  68. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_NONVIS_UPDATE_TIMEOUT], VAL_REAL))
  69. // {
  70. // Real val = 0.0f;
  71. // if(getReal(prop->values.front(), &val))
  72. // {
  73. // mSystem->setNonVisibleUpdateTimeout(val);
  74. // }
  75. // }
  76. // }
  77. // else if (prop->name == token[TOKEN_PS_FIXED_TIMEOUT])
  78. // {
  79. // // Property: fixed_timeout
  80. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_FIXED_TIMEOUT], VAL_REAL))
  81. // {
  82. // Real val = 0.0f;
  83. // if(getReal(prop->values.front(), &val))
  84. // {
  85. // mSystem->setFixedTimeout(val);
  86. // }
  87. // }
  88. // }
  89. // else if (prop->name == token[TOKEN_PS_LOD_DISTANCES])
  90. // {
  91. // // Property: lod_distances
  92. // if (passValidatePropertyNoValues(compiler, prop, token[TOKEN_PS_LOD_DISTANCES]))
  93. // {
  94. // for(PUAbstractNodeList::iterator j = prop->values.begin(); j != prop->values.end(); ++j)
  95. // {
  96. // Real val = 0.0f;
  97. // if(getReal(*j, &val))
  98. // {
  99. // mSystem->addLodDistance(val);
  100. // }
  101. // else
  102. // {
  103. // compiler->addError(PUScriptCompiler::CE_NUMBEREXPECTED, prop->file, prop->line,
  104. // "PU Compiler: lod_distances expects only numbers as arguments");
  105. // }
  106. // }
  107. // }
  108. // }
  109. // else if (prop->name == token[TOKEN_PS_MAIN_CAMERA_NAME])
  110. // {
  111. // // Property: main_camera_name
  112. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_MAIN_CAMERA_NAME], VAL_STRING))
  113. // {
  114. // String val;
  115. // if(getString(prop->values.front(), &val))
  116. // {
  117. // mSystem->setMainCameraName(val);
  118. // }
  119. // }
  120. // }
  121. // else if (prop->name == token[TOKEN_PS_SMOOTH_LOD])
  122. // {
  123. // // Property: smooth_lod
  124. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_SMOOTH_LOD], VAL_BOOL))
  125. // {
  126. // bool val;
  127. // if(getBoolean(prop->values.front(), &val))
  128. // {
  129. // mSystem->setSmoothLod(val);
  130. // }
  131. // }
  132. // }
  133. // else if (prop->name == token[TOKEN_PS_FAST_FORWARD])
  134. // {
  135. // // Property: fast_forward
  136. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_SCALE], VAL_VECTOR2))
  137. // {
  138. // Vector2 val;
  139. // if(getVector2(prop->values.begin(), prop->values.end(), &val))
  140. // {
  141. // mSystem->setFastForward(val.x, val.y);
  142. // }
  143. // }
  144. // }
  145. if (prop->name == token[TOKEN_PS_SCALE])
  146. {
  147. // Property: scale
  148. if (passValidateProperty(compiler, prop, token[TOKEN_PS_SCALE], VAL_VECTOR3))
  149. {
  150. Vec3 val;
  151. if(getVector3(prop->values.begin(), prop->values.end(), &val))
  152. {
  153. _system->setScaleX(val.x);
  154. _system->setScaleY(val.y);
  155. _system->setScaleZ(val.z);
  156. }
  157. }
  158. }
  159. else if (prop->name == token[TOKEN_PS_SCALE_VELOCITY])
  160. {
  161. // Property: scale_velocity
  162. if (passValidateProperty(compiler, prop, token[TOKEN_PS_ITERATION_INTERVAL], VAL_REAL))
  163. {
  164. float val = 0.0f;
  165. if(getFloat(*prop->values.front(), &val))
  166. {
  167. _system->setParticleSystemScaleVelocity(val);
  168. }
  169. }
  170. }
  171. // else if (prop->name == token[TOKEN_PS_SCALE_TIME])
  172. // {
  173. // // Property: scale_time
  174. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_SCALE_TIME], VAL_REAL))
  175. // {
  176. // Real val = 0.0f;
  177. // if(getReal(prop->values.front(), &val))
  178. // {
  179. // mSystem->setScaleTime(val);
  180. // }
  181. // }
  182. // }
  183. else if (prop->name == token[TOKEN_KEEP_LOCAL])
  184. {
  185. // Property: keep_local
  186. if (passValidateProperty(compiler, prop, token[TOKEN_KEEP_LOCAL], VAL_BOOL))
  187. {
  188. bool val;
  189. if(getBoolean(*prop->values.front(), &val))
  190. {
  191. _system->setKeepLocal(val);
  192. }
  193. }
  194. }
  195. // else if (prop->name == token[TOKEN_PS_TIGHT_BOUNDING_BOX])
  196. // {
  197. // // Property: tight_bounding_box
  198. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_TIGHT_BOUNDING_BOX], VAL_BOOL))
  199. // {
  200. // bool val;
  201. // if(getBoolean(prop->values.front(), &val))
  202. // {
  203. // mSystem->setTightBoundingBox(val);
  204. // }
  205. // }
  206. // }
  207. // else if (prop->name == token[TOKEN_PS_CATEGORY])
  208. // {
  209. // // Property: category
  210. // if (passValidateProperty(compiler, prop, token[TOKEN_PS_CATEGORY], VAL_STRING))
  211. // {
  212. // String val;
  213. // if(getString(prop->values.front(), &val))
  214. // {
  215. // mSystem->setCategory(val);
  216. // }
  217. // }
  218. // }
  219. // else if (prop->name == token[TOKEN_USE_ALIAS])
  220. // {
  221. // // Property: use_alias
  222. // // The alias can only be a technique
  223. // if (passValidateProperty(compiler, prop, token[TOKEN_USE_ALIAS], VAL_STRING))
  224. // {
  225. // String val;
  226. // if(getString(prop->values.front(), &val))
  227. // {
  228. // IAlias* alias = ParticleSystemManager::getSingletonPtr()->getAlias(val);
  229. // if (alias->getAliasType() == IAlias::AT_TECHNIQUE)
  230. // {
  231. // ParticleTechnique* technique = static_cast<ParticleTechnique*>(alias);
  232. // ParticleTechnique* newTechnique = ParticleSystemManager::getSingletonPtr()->cloneTechnique(technique);
  233. // mSystem->addTechnique(newTechnique);
  234. // }
  235. // }
  236. // }
  237. // }
  238. // else
  239. // {
  240. // errorUnexpectedProperty(compiler, prop);
  241. // }
  242. }
  243. else if((*i)->type == ANT_OBJECT)
  244. {
  245. processNode(compiler, *i);
  246. }
  247. else
  248. {
  249. errorUnexpectedToken(compiler, *i);
  250. }
  251. }
  252. }
  253. NS_CC_END