ParticleAsset_ScriptBinding.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  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
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell 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
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleMethodGroupBeginWithDocs(ParticleAsset, AssetBase)
  23. //-----------------------------------------------------------------------------
  24. /// Particle asset accessors.
  25. //-----------------------------------------------------------------------------
  26. /*! Sets the life-mode of the particle effect.
  27. @param lifeMode The life-mode of the particle effect (either INFINITE, CYCLE, KILL or STOP.
  28. A life-mode of INFINITE causes the particle effect to last forever.
  29. A life-mode of CYCLE causes the particle effect to restart playing when its specified 'lifetime' has been reached.
  30. A life-mode of KILL causes the particle effect to be deleted when its specified 'lifetime' has been reached.
  31. A life-mode of STOP causes the particle effect to stop playing (but not be deleted) when its specified lifetime has been reached.
  32. @return No return value.
  33. */
  34. ConsoleMethodWithDocs(ParticleAsset, setLifeMode, ConsoleVoid, 3, 3, (lifeMode))
  35. {
  36. object->setLifeMode( ParticleAsset::getParticleAssetLifeModeEnum( argv[2] ) );
  37. }
  38. //-----------------------------------------------------------------------------
  39. /*! Gets the life-mode of the particle effect.
  40. @return The life-mode of the particle effect.
  41. */
  42. ConsoleMethodWithDocs( ParticleAsset, getLifeMode, ConsoleString, 2, 2, ())
  43. {
  44. return ParticleAsset::getParticleAssetLifeModeDescription( object->getLifeMode() );
  45. }
  46. //-----------------------------------------------------------------------------
  47. /*! Sets the lifetime of the particle effect.
  48. @param lifeTime The lifetime of the particle effect. This is used according to the 'lifeMode' setting.
  49. @return No return value.
  50. */
  51. ConsoleMethodWithDocs(ParticleAsset, setLifetime, ConsoleVoid, 3, 3, (lifeTime))
  52. {
  53. object->setLifetime( dAtof(argv[2]) );
  54. }
  55. //-----------------------------------------------------------------------------
  56. /*! Gets the lifetime of the particle effect.
  57. @return The lifetime of the particle effect.
  58. */
  59. ConsoleMethodWithDocs(ParticleAsset, getLifetime, ConsoleFloat, 2, 2, ())
  60. {
  61. return object->getLifetime();
  62. }
  63. //-----------------------------------------------------------------------------
  64. /// Particle asset fields.
  65. //-----------------------------------------------------------------------------
  66. /*! Gets the number of available selectable fields.
  67. @return The number of available selectable fields.
  68. */
  69. ConsoleMethodWithDocs(ParticleAsset, getSelectableFieldCount, ConsoleInt, 2, 2, ())
  70. {
  71. return object->getParticleFields().getFields().size();
  72. }
  73. //-----------------------------------------------------------------------------
  74. /*! Gets the selectable field at the specified index.
  75. @return The selectable field name at the specified index.
  76. */
  77. ConsoleMethodWithDocs(ParticleAsset, getSelectableFieldName, ConsoleString, 3, 3, (fieldIndex))
  78. {
  79. // Fetch the field hash.
  80. const ParticleAssetFieldCollection::typeFieldHash& fieldHash = object->getParticleFields().getFields();
  81. // Fetch the index.
  82. S32 fieldIndex = dAtoi( argv[2] );
  83. // Is the field index valid?
  84. if ( fieldIndex >= 0 && fieldIndex < (S32)fieldHash.size() )
  85. {
  86. // Yes, but because the fields are in a hash-table, we'll have to iterate and get O(index).
  87. for( ParticleAssetFieldCollection::typeFieldHash::const_iterator fieldItr = fieldHash.begin(); fieldItr != fieldHash.end(); ++fieldItr, --fieldIndex )
  88. {
  89. // Skip if this is not the field index we're looking for?
  90. if ( fieldIndex != 0 )
  91. continue;
  92. // Found it so return the field name.
  93. return fieldItr->value->getFieldName();
  94. }
  95. }
  96. // Warn.
  97. Con::warnf( "ParticleAsset::getSelectableFieldName() - Index '%d' is out of range.", fieldIndex );
  98. return StringTable->EmptyString;
  99. }
  100. //-----------------------------------------------------------------------------
  101. /*! Select the specified field by its name.
  102. @param fieldName The field name to use for the selection. Use an empty name to deselect to stop accidental changes.
  103. @return Whether the field was successfully selected or not.
  104. */
  105. ConsoleMethodWithDocs(ParticleAsset, selectField, ConsoleBool, 3, 3, (fieldName))
  106. {
  107. return object->getParticleFields().selectField( argv[2] ) != NULL;
  108. }
  109. //-----------------------------------------------------------------------------
  110. /*! Deselect any selected field. If no field is selected then nothing happens.
  111. @return No return value.
  112. */
  113. ConsoleMethodWithDocs(ParticleAsset, deselectField, ConsoleVoid, 2, 2, ())
  114. {
  115. object->getParticleFields().deselectField();
  116. }
  117. //-----------------------------------------------------------------------------
  118. /*! Gets the selected field name or nothing if no field is selected.
  119. @return The selected field name or nothing if no fields is selected.
  120. */
  121. ConsoleMethodWithDocs(ParticleAsset, getSelectedField, ConsoleString, 2, 2, ())
  122. {
  123. // Get the selected field.
  124. const ParticleAssetField* pParticleAssetField = object->getParticleFields().getSelectedField();
  125. return pParticleAssetField == NULL ? StringTable->EmptyString : pParticleAssetField->getFieldName();
  126. }
  127. //-----------------------------------------------------------------------------
  128. /*! Sets a single data-key at time-zero with the specified value. All existing keys are cleared.
  129. @param value The value to set the key to.
  130. @return Returns the index of the new data-key (always zero) or -1 on failure.
  131. */
  132. ConsoleMethodWithDocs(ParticleAsset, setSingleDataKey, ConsoleInt, 3, 3, (value))
  133. {
  134. return object->getParticleFields().setSingleDataKey( dAtof(argv[2]) );
  135. }
  136. //-----------------------------------------------------------------------------
  137. /*! Add Data-Key to Graph.
  138. @param time The key time.
  139. @param value The value at specified time
  140. @return Returns the index of the new data-key or -1 on failure.
  141. */
  142. ConsoleMethodWithDocs(ParticleAsset, addDataKey, ConsoleInt, 4, 4, (time, value))
  143. {
  144. return object->getParticleFields().addDataKey( dAtof(argv[2]), dAtof(argv[3]) );
  145. }
  146. //-----------------------------------------------------------------------------
  147. /*! Remove the data-key from the field.
  148. @param keyIndex The index of the data-key you want to remove.
  149. @return Whether the operation was successful or not.
  150. */
  151. ConsoleMethodWithDocs(ParticleAsset, removeDataKey, ConsoleBool, 3, 3, (keyIndex))
  152. {
  153. return object->getParticleFields().removeDataKey( dAtoi(argv[2]) );
  154. }
  155. //-----------------------------------------------------------------------------
  156. /*! Clears all data-key(s) from the field.
  157. @return Whether the operation was successful or not.
  158. */
  159. ConsoleMethodWithDocs(ParticleAsset, clearDataKeys, ConsoleBool, 2, 2, ())
  160. {
  161. return object->getParticleFields().clearDataKeys();
  162. }
  163. //-----------------------------------------------------------------------------
  164. /*! Set data-key value for the field.
  165. @param keyIndex The index of the key to be modified.
  166. @param value The value to change the key to.
  167. @return Whether the operation was successful or not.
  168. */
  169. ConsoleMethodWithDocs(ParticleAsset, setDataKeyValue, ConsoleBool, 4, 4, (keyIndex, value))
  170. {
  171. // Set Data Key.
  172. return object->getParticleFields().setDataKey( dAtoi(argv[2]), dAtof(argv[3]) );
  173. }
  174. //-----------------------------------------------------------------------------
  175. /*! Gets the data-key count.
  176. @return The number of data-keys in the currently selected field or -1 if no field is selected.
  177. */
  178. ConsoleMethodWithDocs(ParticleAsset, getDataKeyCount, ConsoleInt, 2, 2, ())
  179. {
  180. // Get Data Key Count.
  181. return object->getParticleFields().getDataKeyCount();
  182. }
  183. //-----------------------------------------------------------------------------
  184. /*! Gets the data-key at the specified index from the field.
  185. @param keyIndex The index of the data-key to be retrieved.
  186. @return The data-key comprising both the time and value or nothing if the key is invalid.
  187. */
  188. ConsoleMethodWithDocs(ParticleAsset, getDataKey, ConsoleString, 3, 3, (keyIndex))
  189. {
  190. // Fetch the key index.
  191. const S32 keyIndex = dAtoi(argv[2]);
  192. // Fetch the data-key.
  193. const ParticleAssetField::DataKey dataKey = object->getParticleFields().getDataKey( keyIndex );
  194. // Finish if the data-key is bad.
  195. if ( dataKey == ParticleAssetField::BadDataKey )
  196. return StringTable->EmptyString;
  197. // Create Returnable Buffer.
  198. char* pBuffer = Con::getReturnBuffer(32);
  199. // Format Buffer.
  200. dSprintf(pBuffer, 32, "%f %f", dataKey.mTime, dataKey.mValue );
  201. // Return buffer.
  202. return pBuffer;
  203. }
  204. //-----------------------------------------------------------------------------
  205. /*! Get the minimum value for the field.
  206. @return The minimum value for the field or always 0.0 if no field is selected.
  207. */
  208. ConsoleMethodWithDocs(ParticleAsset, getMinValue, ConsoleFloat, 2, 2, ())
  209. {
  210. return object->getParticleFields().getMinValue();
  211. }
  212. //-----------------------------------------------------------------------------
  213. /*! Get the maximum value for the field.
  214. @return The maximum value for the field or always 0.0 if no field is selected.
  215. */
  216. ConsoleMethodWithDocs(ParticleAsset, getMaxValue, ConsoleFloat, 2, 2, ())
  217. {
  218. return object->getParticleFields().getMaxValue();
  219. }
  220. //-----------------------------------------------------------------------------
  221. /*! Get the minimum time for the field.
  222. @return The minimum time for the field or always 0.0 if no field is selected.
  223. */
  224. ConsoleMethodWithDocs(ParticleAsset, getMinTime, ConsoleFloat, 2, 2, ())
  225. {
  226. return object->getParticleFields().getMinTime();
  227. }
  228. //-----------------------------------------------------------------------------
  229. /*! Get the maximum time for the field.
  230. @return The maximum time for the field or always 0.0 if no field is selected.
  231. */
  232. ConsoleMethodWithDocs(ParticleAsset, getMaxTime, ConsoleFloat, 2, 2, ())
  233. {
  234. return object->getParticleFields().getMaxTime();
  235. }
  236. //-----------------------------------------------------------------------------
  237. /*! Get the fields' value at the specified time.
  238. @param time The time to sample the field value at.
  239. @return The fields' value at the specified time or always 0.0 if no field is selected.
  240. */
  241. ConsoleMethodWithDocs(ParticleAsset, getFieldValue, ConsoleFloat, 3, 3, (time))
  242. {
  243. return object->getParticleFields().getFieldValue( dAtof(argv[2]) );
  244. }
  245. //-----------------------------------------------------------------------------
  246. /*! Sets the time period to repeat (cycle) the fields' values at.
  247. @return Whether the operation was successful or not.
  248. */
  249. ConsoleMethodWithDocs(ParticleAsset, setRepeatTime, ConsoleBool, 3, 3, (repeatTime))
  250. {
  251. return object->getParticleFields().setRepeatTime( dAtof(argv[2]) );
  252. }
  253. //-----------------------------------------------------------------------------
  254. /*! Gets the time period that the fields' value repeat (cycle) at.
  255. @return The time period that the fields' value repeat (cycle) at.
  256. */
  257. ConsoleMethodWithDocs(ParticleAsset, getRepeatTime, ConsoleFloat, 2, 2, ())
  258. {
  259. return object->getParticleFields().getRepeatTime();
  260. }
  261. //-----------------------------------------------------------------------------
  262. /*! Set the scaling of field values retrieved from the field. This does not alter the actual data-key values.
  263. @param valueScale The scale for field values retrieved from the field.
  264. @return Whether the operation was successful or not.
  265. */
  266. ConsoleMethodWithDocs(ParticleAsset, setValueScale, ConsoleBool, 3, 3, (valueScale))
  267. {
  268. return object->getParticleFields().setValueScale( dAtof(argv[2]) );
  269. }
  270. //-----------------------------------------------------------------------------
  271. /*! Gets the scaling of field values' retrieved from the field.
  272. @return The scaling of field values' retrieved from the field.
  273. */
  274. ConsoleMethodWithDocs(ParticleAsset, getValueScale, ConsoleFloat, 2, 2, ())
  275. {
  276. return object->getParticleFields().getValueScale();
  277. }
  278. //-----------------------------------------------------------------------------
  279. /// Emitter asset methods.
  280. //-----------------------------------------------------------------------------
  281. /*! Creates and add a new emitter.
  282. @return The new emitter that was added or 0 if failed.
  283. */
  284. ConsoleMethodWithDocs(ParticleAsset, createEmitter, ConsoleString, 2, 2, ())
  285. {
  286. // Find the emitter.
  287. ParticleAssetEmitter* pEmitter = object->createEmitter();
  288. return pEmitter == NULL ? StringTable->EmptyString : pEmitter->getIdString();
  289. }
  290. //-----------------------------------------------------------------------------
  291. /*! Adds an existing emitter.
  292. @param emitterId The emitter to add.
  293. @return On success it returns the ID of the emitter, or 0 if failed.
  294. */
  295. ConsoleMethodWithDocs(ParticleAsset, addEmitter, ConsoleBool, 3, 3, (emitterId))
  296. {
  297. // Find the emitter.
  298. ParticleAssetEmitter* pEmitter = Sim::findObject<ParticleAssetEmitter>( argv[2] );
  299. // Did we find the emitter?
  300. if ( pEmitter == NULL )
  301. {
  302. // No, so warn.
  303. Con::warnf( "ParticleAsset::addEmitter() - Could not find the emitter '%s'.", argv[2] );
  304. return false;
  305. }
  306. return object->addEmitter(pEmitter);
  307. }
  308. //-----------------------------------------------------------------------------
  309. /*! Removes an emitter.
  310. @param emitterId The emitter to remove.
  311. @return No return value.
  312. */
  313. ConsoleMethodWithDocs(ParticleAsset, removeEmitter, ConsoleBool, 3, 4, (emitterId, [bool deleteEmitter]))
  314. {
  315. // Find the emitter.
  316. ParticleAssetEmitter* pEmitter = Sim::findObject<ParticleAssetEmitter>( argv[2] );
  317. // Did we find the emitter?
  318. if ( pEmitter == NULL )
  319. {
  320. // No, so warn.
  321. Con::warnf( "ParticleAsset::removeEmitter() - Could not find the emitter '%s'.", argv[2] );
  322. return false;
  323. }
  324. bool deleteEmitter = true;
  325. if (argc > 3)
  326. deleteEmitter = dAtob(argv[3]);
  327. // Remove the emitter.
  328. object->removeEmitter( pEmitter, deleteEmitter );
  329. return true;
  330. }
  331. //-----------------------------------------------------------------------------
  332. /*! Clear all the emitters.
  333. @return No return Value.
  334. */
  335. ConsoleMethodWithDocs(ParticleAsset, clearEmitters, ConsoleVoid, 2, 2, ())
  336. {
  337. // Clear Emitters.
  338. object->clearEmitters();
  339. }
  340. //-----------------------------------------------------------------------------
  341. /*! Gets the emitter count.
  342. @return Returns the number of emitters as an integer.
  343. */
  344. ConsoleMethodWithDocs(ParticleAsset, getEmitterCount, ConsoleInt, 2, 2, ())
  345. {
  346. // Get Emitter Count.
  347. return object->getEmitterCount();
  348. }
  349. //-----------------------------------------------------------------------------
  350. /*! Gets the emitter at the specified index.
  351. @param emitterIndex The index for the desired emitter
  352. @return The emitter or 0 if not found.
  353. */
  354. ConsoleMethodWithDocs(ParticleAsset, getEmitter, ConsoleInt, 3, 3, (emitterIndex))
  355. {
  356. // Get the emitter.
  357. ParticleAssetEmitter* pEmitter = object->getEmitter( dAtoi(argv[2]) );
  358. return pEmitter == NULL ? 0 : pEmitter->getId();
  359. }
  360. //-----------------------------------------------------------------------------
  361. /*! Finds the emitter by its name.
  362. @param emitterName The name of the desired emitter.
  363. @return The emitter or 0 if not found.
  364. */
  365. ConsoleMethodWithDocs(ParticleAsset, findEmitter, ConsoleInt, 3, 3, (emitterName))
  366. {
  367. // Find the emitter.
  368. ParticleAssetEmitter* pEmitter = object->findEmitter( argv[2] );
  369. return pEmitter == NULL ? 0 : pEmitter->getId();
  370. }
  371. //-----------------------------------------------------------------------------
  372. /*! Moves the emitter order.
  373. @param fromEmitterIndex The source index of the emitter to move.
  374. @param toEmitterIndex The destination index to move the emitter to.
  375. @return No return value.
  376. */
  377. ConsoleMethodWithDocs(ParticleAsset, moveEmitter, ConsoleVoid, 4, 4, (fromEmitterIndex, toEmitterIndex))
  378. {
  379. // Move Emitter Object.
  380. object->moveEmitter( dAtoi(argv[2]), dAtoi(argv[3]) );
  381. }
  382. ConsoleMethodGroupEndWithDocs(ParticleAsset)