CompositeSprite_ScriptBinding.h 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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(CompositeSprite, SceneObject)
  23. /*! Adds a sprite at the specified logical position.
  24. You must specify the correct number of arguments for the selected layout mode.
  25. The created sprite will be automatically selected.
  26. @param a b c d e f Logical positions #1 & #2 and four additional and optional arguments.
  27. @return The batch Id of the added sprite or zero if not successful.
  28. */
  29. ConsoleMethodWithDocs(CompositeSprite, addSprite, ConsoleInt, 2, 3, ( [a] [b] [c] [d] [e] [f] ))
  30. {
  31. if ( argc == 2 )
  32. return object->addSprite( SpriteBatchItem::LogicalPosition() );
  33. else
  34. return object->addSprite( SpriteBatchItem::LogicalPosition(argv[2]) );
  35. }
  36. //-----------------------------------------------------------------------------
  37. /*! Removes the selected sprite.
  38. @return Whether the sprite was removed or not.
  39. */
  40. ConsoleMethodWithDocs(CompositeSprite, removeSprite, ConsoleBool, 2, 2, ())
  41. {
  42. return object->removeSprite();
  43. }
  44. //-----------------------------------------------------------------------------
  45. /*! Removes all sprites.
  46. @return No return value.
  47. */
  48. ConsoleMethodWithDocs(CompositeSprite, clearSprites, ConsoleVoid, 2, 2, ())
  49. {
  50. return object->clearSprites();
  51. }
  52. //-----------------------------------------------------------------------------
  53. /*! Gets a count of sprites in the composite.
  54. @return The count of sprites in the composite.
  55. */
  56. ConsoleMethodWithDocs(CompositeSprite, getSpriteCount, ConsoleInt, 2, 2, ())
  57. {
  58. return object->getSpriteCount();
  59. }
  60. //-----------------------------------------------------------------------------
  61. /*! Sets the batch layout type.
  62. The render sort mode is used when isolated batch mode is on.
  63. @param batchLayoutType 'none', 'rect' or 'iso' layout types are valid.
  64. @return No return value.
  65. */
  66. ConsoleMethodWithDocs(CompositeSprite, setBatchLayout, ConsoleVoid, 3, 3, (batchLayoutType))
  67. {
  68. // Fetch the batch layout type/
  69. CompositeSprite::BatchLayoutType batchLayoutType = CompositeSprite::getBatchLayoutTypeEnum( argv[2] );
  70. // Sanity!
  71. if ( batchLayoutType == CompositeSprite::INVALID_LAYOUT )
  72. {
  73. // Warn.
  74. Con::warnf( "CompositeSprite::setBatchLayout() - Unknown batch layout type of '%s'.", argv[2] );
  75. return;
  76. }
  77. object->setBatchLayout( batchLayoutType );
  78. }
  79. //-----------------------------------------------------------------------------
  80. /*! Gets the batch layout type.
  81. @return The batch layout type.
  82. */
  83. ConsoleMethodWithDocs(CompositeSprite, getBatchLayout, ConsoleString, 2, 2, ())
  84. {
  85. return CompositeSprite::getBatchLayoutTypeDescription( object->getBatchLayout() );
  86. }
  87. //-----------------------------------------------------------------------------
  88. /*! Sets whether the sprites are rendered, isolated from other renderings as one batch or not.
  89. When in batch isolated mode, the sprites can be optionally sorted.
  90. @return No return value.
  91. */
  92. ConsoleMethodWithDocs(CompositeSprite, setBatchIsolated, ConsoleVoid, 3, 3, (bool batchIsolated))
  93. {
  94. // Fetch batch isolated.
  95. const bool batchIsolated = dAtob(argv[2]);
  96. object->setBatchIsolated( batchIsolated );
  97. }
  98. //-----------------------------------------------------------------------------
  99. /*! Gets whether the sprites are rendered, isolated from other renderings as one batch or not.
  100. @return Whether the sprites are rendered, isolated from other renderings as one batch or not.
  101. */
  102. ConsoleMethodWithDocs(CompositeSprite, getBatchIsolated, ConsoleBool, 2, 2, ())
  103. {
  104. return object->getBatchIsolated();
  105. }
  106. //-----------------------------------------------------------------------------
  107. /*! Sets whether the sprites are culled.
  108. For sprites that are off-screen this is considerably faster during render at the expense of memory.
  109. For small composites with a few sprites, the overhead is probably not worth it.
  110. @return No return value.
  111. */
  112. ConsoleMethodWithDocs(CompositeSprite, setBatchCulling, ConsoleVoid, 3, 3, (bool batchCulling))
  113. {
  114. // Fetch batch culling..
  115. const bool batchCulling = dAtob(argv[2]);
  116. STATIC_VOID_CAST_TO(CompositeSprite, SpriteBatch, object)->setBatchCulling( batchCulling );
  117. }
  118. //-----------------------------------------------------------------------------
  119. /*! Gets whether the sprites are render culled or not
  120. @return Whether the sprites are rendered culled or not.
  121. */
  122. ConsoleMethodWithDocs(CompositeSprite, getBatchCulling, ConsoleBool, 2, 2, ())
  123. {
  124. return object->getBatchCulling();
  125. }
  126. //-----------------------------------------------------------------------------
  127. /*! Sets the batch render sort mode.
  128. The render sort mode is used when isolated batch mode is on.
  129. @return No return value.
  130. */
  131. ConsoleMethodWithDocs(CompositeSprite, setBatchSortMode, ConsoleVoid, 3, 3, (renderSortMode))
  132. {
  133. // Fetch render sort mode.
  134. SceneRenderQueue::RenderSort batchSortMode = SceneRenderQueue::getRenderSortEnum( argv[2] );
  135. // Sanity!
  136. if ( batchSortMode == SceneRenderQueue::RENDER_SORT_INVALID )
  137. {
  138. // Warn.
  139. Con::warnf( "CompositeSprite::setBatchSortMode() - Unknown batch sort mode of '%s'.", argv[2] );
  140. return;
  141. }
  142. object->setBatchSortMode( batchSortMode );
  143. }
  144. //-----------------------------------------------------------------------------
  145. /*! Gets the batch render sort mode.
  146. @return The render sort mode.
  147. */
  148. ConsoleMethodWithDocs(CompositeSprite, getBatchSortMode, ConsoleString, 2, 2, ())
  149. {
  150. return SceneRenderQueue::getRenderSortDescription( object->getBatchSortMode() );
  151. }
  152. //-----------------------------------------------------------------------------
  153. /*! Sets the stride which scales the position at which sprites are created.
  154. @param strideX The default stride of the local X axis.
  155. @param strideY The default stride of the local Y axis.
  156. @return No return value.
  157. */
  158. ConsoleMethodWithDocs(CompositeSprite, setDefaultSpriteStride, ConsoleVoid, 3, 4, (float strideX, [float strideY]]))
  159. {
  160. Vector2 stride;
  161. // Fetch element count.
  162. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  163. // ("strideX strideY")
  164. if ( (elementCount == 2) && (argc == 3) )
  165. {
  166. stride.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  167. stride.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  168. }
  169. // (strideX, [strideY])
  170. else if (elementCount == 1)
  171. {
  172. stride.x = dAtof(argv[2]);
  173. if (argc > 3)
  174. stride.y = dAtof(argv[3]);
  175. else
  176. stride.y = stride.x;
  177. }
  178. // Invalid
  179. else
  180. {
  181. Con::warnf("CompositeSprite::setDefaultSpriteStride() - Invalid number of parameters!");
  182. return;
  183. }
  184. object->setDefaultSpriteStride( stride );
  185. }
  186. //-----------------------------------------------------------------------------
  187. /*! Gets the stride which scales the position at which sprites are created.
  188. @return (float strideX/float strideY) The stride which scales the position at which sprites are created.
  189. */
  190. ConsoleMethodWithDocs(CompositeSprite, getDefaultSpriteStride, ConsoleString, 2, 2, ())
  191. {
  192. return object->getDefaultSpriteStride().scriptThis();
  193. }
  194. //-----------------------------------------------------------------------------
  195. /*! Sets the size at which sprites are created.
  196. @param width The default width of sprites.
  197. @param height The default height of sprites
  198. @return No return value.
  199. */
  200. ConsoleMethodWithDocs(CompositeSprite, setDefaultSpriteSize, ConsoleVoid, 3, 4, (float width, [float height]))
  201. {
  202. Vector2 size;
  203. // Fetch element count.
  204. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  205. // ("width height")
  206. if ( (elementCount == 2) && (argc == 3) )
  207. {
  208. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  209. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  210. }
  211. // (width, [height])
  212. else if (elementCount == 1)
  213. {
  214. size.x = dAtof(argv[2]);
  215. if (argc > 3)
  216. size.y = dAtof(argv[3]);
  217. else
  218. size.y = size.x;
  219. }
  220. // Invalid
  221. else
  222. {
  223. Con::warnf("CompositeSprite::setDefaultSpriteSize() - Invalid number of parameters!");
  224. return;
  225. }
  226. object->setDefaultSpriteSize( size );
  227. }
  228. //-----------------------------------------------------------------------------
  229. /*! Gets the size at which sprites are created.
  230. @return (float width/float height) The size at which sprites are created.
  231. */
  232. ConsoleMethodWithDocs(CompositeSprite, getDefaultSpriteSize, ConsoleString, 2, 2, ())
  233. {
  234. return object->getDefaultSpriteSize().scriptThis();
  235. }
  236. //-----------------------------------------------------------------------------
  237. /*! Sets the angle at which sprites are created.
  238. @param angle The angle at which sprites are created.
  239. @return No return value.
  240. */
  241. ConsoleMethodWithDocs(CompositeSprite, setDefaultSpriteAngle, ConsoleVoid, 3, 3, (float angle))
  242. {
  243. // Fetch angle.
  244. const F32 angle = mDegToRad( dAtof(argv[2]) );
  245. static_cast<SpriteBatch*>(object)->setDefaultSpriteAngle( angle );
  246. }
  247. //-----------------------------------------------------------------------------
  248. /*! Gets the angle at which sprites are created.
  249. @return (float angle) The angle at which sprites are created.
  250. */
  251. ConsoleMethodWithDocs(CompositeSprite, getDefaultSpriteAngle, ConsoleFloat, 3, 3, ())
  252. {
  253. return mRadToDeg( static_cast<SpriteBatch*>(object)->getDefaultSpriteAngle() );
  254. }
  255. //-----------------------------------------------------------------------------
  256. /*! Selects a sprite at the specified logical position.
  257. @param a b c d e f Logical positions #1 & #2 and four additional and optional arguments.
  258. @return Whether the sprite was selected or not.
  259. */
  260. ConsoleMethodWithDocs(CompositeSprite, selectSprite, ConsoleBool, 3, 3, ( a b [c] [d] [e] [f] ))
  261. {
  262. return object->selectSprite( SpriteBatchItem::LogicalPosition(argv[2]) );
  263. }
  264. //-----------------------------------------------------------------------------
  265. /*! Selects a sprite with the specified batch Id.
  266. @param batchId The batch Id of the sprite to select.
  267. @return Whether the sprite was selected or not.
  268. */
  269. ConsoleMethodWithDocs(CompositeSprite, selectSpriteId, ConsoleBool, 3, 3, ( int batchId ))
  270. {
  271. return object->selectSpriteId( dAtoi(argv[2]) );
  272. }
  273. //-----------------------------------------------------------------------------
  274. /*! Selects a sprite with the specified name.
  275. @param name The name of the sprite.
  276. @return Whether the sprite was selected or not.
  277. */
  278. ConsoleMethodWithDocs(CompositeSprite, selectSpriteName, ConsoleBool, 3, 3, ( name ))
  279. {
  280. return object->selectSpriteName( argv[2] );
  281. }
  282. //-----------------------------------------------------------------------------
  283. /*! Deselects any selected sprite.
  284. This is not required but can be used to stop accidental changes to sprites.
  285. @return No return value.
  286. */
  287. ConsoleMethodWithDocs(CompositeSprite, deselectSprite, ConsoleVoid, 2, 2, ())
  288. {
  289. return object->deselectSprite();
  290. }
  291. //-----------------------------------------------------------------------------
  292. /*! Checks whether a sprite is selected or not.
  293. @return Whether a sprite is selected or not.
  294. */
  295. ConsoleMethodWithDocs(CompositeSprite, isSpriteSelected, ConsoleBool, 2, 2, ())
  296. {
  297. return object->isSpriteSelected();
  298. }
  299. //-----------------------------------------------------------------------------
  300. /*! Sets the sprite image and optional frame.
  301. @param imageAssetId The image to set the sprite to.
  302. @param imageFrame The image frame of the imageAssetId to set the sprite to.
  303. @return No return value.
  304. */
  305. ConsoleMethodWithDocs(CompositeSprite, setSpriteImage, ConsoleVoid, 3, 4, (imageAssetId, [imageFrame]))
  306. {
  307. // Was a frame specified?
  308. if (argc >= 4)
  309. {
  310. // Was it a number or a string?
  311. if (!dIsalpha(*argv[3]))
  312. {
  313. // Fetch the numerical frame and set the image
  314. const U32 frame = argc >= 4 ? dAtoi(argv[3]) : 0;
  315. object->setSpriteImage( argv[2], frame );
  316. }
  317. else
  318. {
  319. // Set the image and pass the named frame string
  320. object->setSpriteImage( argv[2], argv[3] );
  321. }
  322. }
  323. else
  324. {
  325. // Frame was not specified, use default 0 and set the image
  326. const U32 frame = 0;
  327. object->setSpriteImage( argv[2], frame );
  328. }
  329. }
  330. //-----------------------------------------------------------------------------
  331. /*! Gets the sprite image.
  332. @return The sprite image.
  333. */
  334. ConsoleMethodWithDocs(CompositeSprite, getSpriteImage, ConsoleString, 2, 2, ())
  335. {
  336. return object->getSpriteImage();
  337. }
  338. //-----------------------------------------------------------------------------
  339. /*! Sets the sprite image frame.
  340. @param imageFrame The image frame to set the sprite to.
  341. @return No return value.
  342. */
  343. ConsoleMethodWithDocs(CompositeSprite, setSpriteImageFrame, ConsoleVoid, 3, 3, (int imageFrame))
  344. {
  345. // Fetch frame.
  346. const U32 frame = dAtoi(argv[2]);
  347. object->setSpriteImageFrame( frame );
  348. }
  349. //-----------------------------------------------------------------------------
  350. /*! Gets the sprite image frame.
  351. @return The sprite image frame.
  352. */
  353. ConsoleMethodWithDocs(CompositeSprite, getSpriteImageFrame, ConsoleInt, 2, 2, ())
  354. {
  355. return object->getSpriteImageFrame();
  356. }
  357. //-----------------------------------------------------------------------------
  358. /*! Sets the sprite named image frame.
  359. @param namedFrame The named image frame to set the sprite to.
  360. @return No return value.
  361. */
  362. ConsoleMethodWithDocs(CompositeSprite, setSpriteNamedImageFrame, ConsoleVoid, 3, 3, (namedFrame))
  363. {
  364. object->setSpriteNamedImageFrame( argv[2] );
  365. }
  366. //-----------------------------------------------------------------------------
  367. /*! Gets the sprite named image frame.
  368. @return The sprite named image frame.
  369. */
  370. ConsoleMethodWithDocs(CompositeSprite, getSpriteNamedImageFrame, ConsoleString, 2, 2, ())
  371. {
  372. return object->getSpriteNamedImageFrame();
  373. }
  374. //-----------------------------------------------------------------------------
  375. /*! Sets the sprite animation.
  376. @param imageAssetId The animation to set the sprite to.
  377. @return No return value.
  378. */
  379. ConsoleMethodWithDocs(CompositeSprite, setSpriteAnimation, ConsoleVoid, 3, 4, (animationAssetId))
  380. {
  381. object->setSpriteAnimation( argv[2] );
  382. }
  383. //-----------------------------------------------------------------------------
  384. /*! Gets the sprite animation.
  385. @return The sprite animation.
  386. */
  387. ConsoleMethodWithDocs(CompositeSprite, getSpriteAnimation, ConsoleString, 2, 2, ())
  388. {
  389. return object->getSpriteAnimation();
  390. }
  391. //-----------------------------------------------------------------------------
  392. /*! Clears any image or animation asset from the sprite.
  393. @return No return value.
  394. */
  395. ConsoleMethodWithDocs(CompositeSprite, clearSpriteAsset, ConsoleVoid, 2, 2, ())
  396. {
  397. return object->clearSpriteAsset();
  398. }
  399. //-----------------------------------------------------------------------------
  400. /*! Sets whether the sprite is visible or not.
  401. @param visible Whether the sprite is visible or not.
  402. @return No return value.
  403. */
  404. ConsoleMethodWithDocs(CompositeSprite, setSpriteVisible, ConsoleVoid, 3, 3, (bool visible))
  405. {
  406. // Fetch visible.
  407. const bool visible = dAtob(argv[2]);
  408. object->setSpriteVisible( visible );
  409. }
  410. //-----------------------------------------------------------------------------
  411. /*! Gets whether the sprite is visible or not.
  412. @return Whether the sprite is visible or not.
  413. */
  414. ConsoleMethodWithDocs(CompositeSprite, getSpriteVisible, ConsoleBool, 2, 2, ())
  415. {
  416. return object->getSpriteVisible();
  417. }
  418. //-----------------------------------------------------------------------------
  419. /*! Sets the sprites local position.
  420. @param localX The local position X.
  421. @param localY The local position Y.
  422. @return No return value.
  423. */
  424. ConsoleMethodWithDocs(CompositeSprite, setSpriteLocalPosition, ConsoleVoid, 3, 4, (float localX, float localY))
  425. {
  426. Vector2 localPosition;
  427. // Fetch element count.
  428. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  429. // ("x y")
  430. if ( (elementCount == 2) && (argc == 3) )
  431. {
  432. localPosition.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  433. localPosition.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  434. }
  435. // (x, y)
  436. else if ( elementCount == 1 && (argc > 3) )
  437. {
  438. localPosition.x = dAtof(argv[2]);
  439. localPosition.y = dAtof(argv[3]);
  440. }
  441. // Invalid
  442. else
  443. {
  444. Con::warnf("CompositeSprite::setSpriteLocalPosition() - Invalid number of parameters!");
  445. return;
  446. }
  447. object->setSpriteLocalPosition( localPosition );
  448. }
  449. //-----------------------------------------------------------------------------
  450. /*! Gets the sprite local position.
  451. @return The sprite local position.
  452. */
  453. ConsoleMethodWithDocs(CompositeSprite, getSpriteLocalPosition, ConsoleString, 2, 2, ())
  454. {
  455. return object->getSpriteLocalPosition().scriptThis();
  456. }
  457. //-----------------------------------------------------------------------------
  458. /*! Gets the sprite logical position.
  459. @return The sprite logical position.
  460. */
  461. ConsoleMethodWithDocs(CompositeSprite, getSpriteLogicalPosition, ConsoleString, 2, 2, ())
  462. {
  463. return object->getSpriteLogicalPosition().getString();
  464. }
  465. //-----------------------------------------------------------------------------
  466. /*! Sets the sprites local angle.
  467. @param localAngle The sprite local angle.
  468. @return No return value.
  469. */
  470. ConsoleMethodWithDocs(CompositeSprite, setSpriteAngle, ConsoleVoid, 3, 3, (float localAngle))
  471. {
  472. // Fetch angle.
  473. const F32 angle = mDegToRad( dAtof(argv[2]) );
  474. object->setSpriteAngle( angle );
  475. }
  476. //-----------------------------------------------------------------------------
  477. /*! Gets the sprite local angle.
  478. @return The sprite local angle.
  479. */
  480. ConsoleMethodWithDocs(CompositeSprite, getSpriteAngle, ConsoleFloat, 2, 2, ())
  481. {
  482. return mRadToDeg( object->getSpriteAngle() );
  483. }
  484. //-----------------------------------------------------------------------------
  485. /*! Sets the sprites depth.
  486. @param depth The sprite depth.
  487. @return No return value.
  488. */
  489. ConsoleMethodWithDocs(CompositeSprite, setSpriteDepth, ConsoleVoid, 3, 3, (float depth))
  490. {
  491. // Fetch depth.
  492. const F32 depth = dAtof(argv[2]);
  493. object->setSpriteDepth( depth );
  494. }
  495. //-----------------------------------------------------------------------------
  496. /*! Gets the sprite depth.
  497. @return The sprite depth.
  498. */
  499. ConsoleMethodWithDocs(CompositeSprite, getSpriteDepth, ConsoleFloat, 2, 2, ())
  500. {
  501. return object->getSpriteDepth();
  502. }
  503. //-----------------------------------------------------------------------------
  504. /*! Sets the sprite size.
  505. @param width The sprite width.
  506. @param height The sprite height
  507. @return No return value.
  508. */
  509. ConsoleMethodWithDocs(CompositeSprite, setSpriteSize, ConsoleVoid, 3, 4, (float width, [float height]))
  510. {
  511. Vector2 size;
  512. // Fetch element count.
  513. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  514. // ("width height")
  515. if ( (elementCount == 2) && (argc == 3) )
  516. {
  517. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  518. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  519. }
  520. // (width, [height])
  521. else if (elementCount == 1)
  522. {
  523. size.x = dAtof(argv[2]);
  524. if (argc > 3)
  525. size.y = dAtof(argv[3]);
  526. else
  527. size.y = size.x;
  528. }
  529. // Invalid
  530. else
  531. {
  532. Con::warnf("CompositeSprite::setSpriteSize() - Invalid number of parameters!");
  533. return;
  534. }
  535. object->setSpriteSize( size );
  536. }
  537. //-----------------------------------------------------------------------------
  538. /*! Gets the sprite size.
  539. @return (float width/float height) The sprite size.
  540. */
  541. ConsoleMethodWithDocs(CompositeSprite, getSpriteSize, ConsoleString, 2, 2, ())
  542. {
  543. return object->getSpriteSize().scriptThis();
  544. }
  545. //-----------------------------------------------------------------------------
  546. /*! Sets whether the sprite is flipped along its local X axis or not.
  547. @param flipX Whether the sprite is flipped along its local X axis or not.
  548. @return No return value.
  549. */
  550. ConsoleMethodWithDocs(CompositeSprite, setSpriteFlipX, ConsoleVoid, 3, 3, (bool flipX))
  551. {
  552. // Fetch flipX.
  553. const bool flipX = dAtob(argv[2]);
  554. object->setSpriteFlipX( flipX );
  555. }
  556. //-----------------------------------------------------------------------------
  557. /*! Gets whether the sprite is flipped along its local X axis or not.
  558. @return Whether the sprite is flipped along its local X axis or not.
  559. */
  560. ConsoleMethodWithDocs(CompositeSprite, getSpriteFlipX, ConsoleBool, 2, 2, ())
  561. {
  562. return object->getSpriteFlipX();
  563. }
  564. //-----------------------------------------------------------------------------
  565. /*! Sets whether the sprite is flipped along its local Y axis or not.
  566. @param flipY Whether the sprite is flipped along its local Y axis or not.
  567. @return No return value.
  568. */
  569. ConsoleMethodWithDocs(CompositeSprite, setSpriteFlipY, ConsoleVoid, 3, 3, (bool flipY))
  570. {
  571. const bool flipY = dAtob(argv[2]);
  572. object->setSpriteFlipY( flipY );
  573. }
  574. //-----------------------------------------------------------------------------
  575. /*! Gets whether the sprite is flipped along its local Y axis or not.
  576. @return Whether the sprite is flipped along its local Y axis or not.
  577. */
  578. ConsoleMethodWithDocs(CompositeSprite, getSpriteFlipY, ConsoleBool, 2, 2, ())
  579. {
  580. return object->getSpriteFlipY();
  581. }
  582. //-----------------------------------------------------------------------------
  583. /*! Sets the sprites sort point.
  584. @param localX The local sort point X.
  585. @param localY The local sort point Y.
  586. @return No return value.
  587. */
  588. ConsoleMethodWithDocs(CompositeSprite, setSpriteSortPoint, ConsoleVoid, 3, 4, (float localX, float localY))
  589. {
  590. Vector2 sortPoint;
  591. // Fetch element count.
  592. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  593. // ("x y")
  594. if ( (elementCount == 2) && (argc == 3) )
  595. {
  596. sortPoint.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  597. sortPoint.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  598. }
  599. // (x, y)
  600. else if ( elementCount == 1 && (argc > 3) )
  601. {
  602. sortPoint.x = dAtof(argv[2]);
  603. sortPoint.y = dAtof(argv[3]);
  604. }
  605. // Invalid
  606. else
  607. {
  608. Con::warnf("CompositeSprite::setSpriteSortPoint() - Invalid number of parameters!");
  609. return;
  610. }
  611. object->setSpriteSortPoint( sortPoint );
  612. }
  613. //-----------------------------------------------------------------------------
  614. /*! Gets the sprite local sort point.
  615. @return The sprite local sort point.
  616. */
  617. ConsoleMethodWithDocs(CompositeSprite, getSpriteSortPoint, ConsoleString, 2, 2, ())
  618. {
  619. return object->getSpriteSortPoint().scriptThis();
  620. }
  621. //-----------------------------------------------------------------------------
  622. /*! Sets the name of the render group used to sort the sprite during rendering.
  623. @param renderGroup The name of the render group to use. Defaults to nothing.
  624. @return No return value.
  625. */
  626. ConsoleMethodWithDocs(CompositeSprite, setSpriteRenderGroup, ConsoleVoid, 3, 3, (renderGroup))
  627. {
  628. object->setSpriteRenderGroup( argv[2] );
  629. }
  630. //-----------------------------------------------------------------------------
  631. /*! Gets the name of the render group used to sort the sprite during rendering.
  632. @return The render group used to sort the object during rendering.
  633. */
  634. ConsoleMethodWithDocs(CompositeSprite, getSpriteRenderGroup, ConsoleString, 2, 2, ())
  635. {
  636. return object->getSpriteRenderGroup();
  637. }
  638. //-----------------------------------------------------------------------------
  639. /*! Sets whether sprite blending is on or not.
  640. @blendMode Whether sprite blending is on or not.
  641. @return No return Value.
  642. */
  643. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendMode, ConsoleVoid, 3, 3, (bool blendMode))
  644. {
  645. // Fetch blend mode.
  646. const bool blendMode = dAtob(argv[2]);
  647. object->setSpriteBlendMode( blendMode );
  648. }
  649. //-----------------------------------------------------------------------------
  650. /*! Gets whether sprite blending is on or not.
  651. @return (bool blendMode) Whether sprite blending is on or not.
  652. */
  653. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendMode, ConsoleBool, 2, 2, ())
  654. {
  655. return object->getSpriteBlendMode();
  656. }
  657. //-----------------------------------------------------------------------------
  658. /*! Sets the sprite source blend factor.
  659. @param srcBlend The sprite source blend factor.
  660. @return No return Value.
  661. */
  662. ConsoleMethodWithDocs(CompositeSprite, setSpriteSrcBlendFactor, ConsoleVoid, 3, 3, (srcBlend))
  663. {
  664. // Fetch source blend factor.
  665. GLenum blendFactor = SceneObject::getSrcBlendFactorEnum(argv[2]);
  666. object->setSpriteSrcBlendFactor( blendFactor );
  667. }
  668. //-----------------------------------------------------------------------------
  669. /*! Gets the sprite source blend factor.
  670. @return (srcBlend) The sprite source blend factor.
  671. */
  672. ConsoleMethodWithDocs(CompositeSprite, getSpriteSrcBlendFactor, ConsoleString, 2, 2, ())
  673. {
  674. return SceneObject::getSrcBlendFactorDescription( object->getSpriteSrcBlendFactor() );
  675. }
  676. //-----------------------------------------------------------------------------
  677. /*! Sets the sprite destination blend factor.
  678. @param dstBlend The sprite destination blend factor.
  679. @return No return Value.
  680. */
  681. ConsoleMethodWithDocs(CompositeSprite, setSpriteDstBlendFactor, ConsoleVoid, 3, 3, (dstBlend))
  682. {
  683. // Fetch destination blend factor.
  684. GLenum blendFactor = SceneObject::getDstBlendFactorEnum(argv[2]);
  685. object->setSpriteDstBlendFactor( blendFactor );
  686. }
  687. //-----------------------------------------------------------------------------
  688. /*! Gets the sprite destination blend factor.
  689. @return (dstBlend) The sprite destination blend factor.
  690. */
  691. ConsoleMethodWithDocs(CompositeSprite, getSpriteDstBlendFactor, ConsoleString, 2, 2, ())
  692. {
  693. return SceneObject::getDstBlendFactorDescription( object->getSpriteDstBlendFactor() );
  694. }
  695. //-----------------------------------------------------------------------------
  696. /*! or ( stockColorName ) - Sets the sprite blend color.
  697. @param red The red value.
  698. @param green The green value.
  699. @param blue The blue value.
  700. @param alpha The alpha value.
  701. @return No return Value.
  702. */
  703. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendColor, ConsoleVoid, 3, 6, (float red, float green, float blue, [float alpha = 1.0]))
  704. {
  705. // The colors.
  706. F32 red;
  707. F32 green;
  708. F32 blue;
  709. F32 alpha = 1.0f;
  710. // Space separated.
  711. if (argc == 3 )
  712. {
  713. // Grab the element count.
  714. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  715. // Has a single argument been specified?
  716. if ( elementCount == 1 )
  717. {
  718. // Is a sprite selected?
  719. if ( !object->isSpriteSelected() )
  720. {
  721. // No, so warn.
  722. Con::warnf("CompositeSprite::setSpriteBlendColor() - Cannot set sprite blend color as no sprite is selected." );
  723. return;
  724. }
  725. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getSpriteBlendColor()), 0, 1, &(argv[2]) );
  726. return;
  727. }
  728. // ("R G B [A]")
  729. if ((elementCount == 3) || (elementCount == 4))
  730. {
  731. // Extract the color.
  732. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  733. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  734. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  735. // Grab the alpha if it's there.
  736. if (elementCount > 3)
  737. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  738. }
  739. // Invalid.
  740. else
  741. {
  742. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  743. return;
  744. }
  745. }
  746. // (R, G, B)
  747. else if (argc >= 5)
  748. {
  749. red = dAtof(argv[2]);
  750. green = dAtof(argv[3]);
  751. blue = dAtof(argv[4]);
  752. // Grab the alpha if it's there.
  753. if (argc > 5)
  754. alpha = dAtof(argv[5]);
  755. }
  756. // Invalid.
  757. else
  758. {
  759. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  760. return;
  761. }
  762. // Set blend color.
  763. object->setSpriteBlendColor(ColorF(red, green, blue, alpha));
  764. }
  765. //-----------------------------------------------------------------------------
  766. /*! Gets the sprite blend color
  767. @param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
  768. @return (float red / float green / float blue / float alpha) The sprite blend color.
  769. */
  770. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendColor, ConsoleString, 2, 3, (allowColorNames))
  771. {
  772. // Get Blend color.
  773. ColorF blendColor = object->getSpriteBlendColor();
  774. // Fetch allow color names flag.
  775. const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
  776. // Are color names allowed?
  777. if ( allowColorNames )
  778. {
  779. // Yes, so fetch the field value.
  780. return Con::getData( TypeColorF, &blendColor, 0 );
  781. }
  782. // No, so fetch the raw color values.
  783. return blendColor.scriptThis();
  784. }
  785. //-----------------------------------------------------------------------------
  786. /*! Sets the sprite color alpha (transparency).
  787. The alpha value specifies directly the transparency of the image. A value of 1.0 will not affect the object and a value of 0.0 will make the object completely transparent.
  788. @param alpha The alpha value.
  789. @return No return Value.
  790. */
  791. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendAlpha, ConsoleVoid, 3, 3, (float alpha))
  792. {
  793. object->setSpriteBlendAlpha( dAtof(argv[2]) );
  794. }
  795. //-----------------------------------------------------------------------------
  796. /*! Gets the sprite color alpha (transparency).
  797. @return (float alpha) The alpha value, a range from 0.0 to 1.0. Less than zero if alpha testing is disabled.
  798. */
  799. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendAlpha, ConsoleFloat, 2, 2, ())
  800. {
  801. return object->getSpriteBlendAlpha();
  802. }
  803. //-----------------------------------------------------------------------------
  804. /*! Set the sprite alpha test.
  805. @param value Numeric value of 0.0 to 1.0 to turn on alpha testing. Less than zero to disable alpha testing.
  806. @return No return Value.
  807. */
  808. ConsoleMethodWithDocs(CompositeSprite, setSpriteAlphaTest, ConsoleVoid, 3, 3, (float alpha))
  809. {
  810. object->setSpriteAlphaTest(dAtof(argv[2]));
  811. }
  812. //-----------------------------------------------------------------------------
  813. /*! Gets the sprite alpha test.
  814. @return (S32) A value of 0 to 255 if alpha testing is enabled. <0 represents disabled alpha testing.
  815. */
  816. ConsoleMethodWithDocs(CompositeSprite, getSpriteAlphaTest, ConsoleFloat, 2, 2, ())
  817. {
  818. return object->getSpriteAlphaTest();
  819. }
  820. //-----------------------------------------------------------------------------
  821. /*! Set the sprite data object.
  822. NOTE: This object will be persisted alongside the composite sprite.
  823. To clear the object you can pass an empty string.
  824. @return No return Value.
  825. */
  826. ConsoleMethodWithDocs(CompositeSprite, setSpriteDataObject, ConsoleVoid, 3, 3, (object))
  827. {
  828. object->setSpriteDataObject( Sim::findObject( argv[2] ) );
  829. }
  830. //-----------------------------------------------------------------------------
  831. /*! Gets the sprite data object.
  832. @return The sprite data object.
  833. */
  834. ConsoleMethodWithDocs(CompositeSprite, getSpriteDataObject, ConsoleString, 2, 2, ())
  835. {
  836. return object->getSpriteDataObject()->getIdString();
  837. }
  838. //-----------------------------------------------------------------------------
  839. /*! Set the sprite name.
  840. This must be unique within this composite sprite instance. To clear the name you can pass an empty string.
  841. @return No return Value.
  842. */
  843. ConsoleMethodWithDocs(CompositeSprite, setSpriteName, ConsoleVoid, 3, 3, (name))
  844. {
  845. object->setSpriteName( argv[2] );
  846. }
  847. //-----------------------------------------------------------------------------
  848. /*! Gets the sprite name.
  849. @return The sprite name.
  850. */
  851. ConsoleMethodWithDocs(CompositeSprite, getSpriteName, ConsoleString, 2, 2, ())
  852. {
  853. return object->getSpriteName();
  854. }
  855. //-----------------------------------------------------------------------------
  856. /*! Gets the SpriteBatchId of the currently selected sprite.
  857. @returns The SpriteBatchId
  858. */
  859. ConsoleMethodWithDocs(CompositeSprite, getSpriteId, ConsoleInt, 2, 2, ())
  860. {
  861. return object->getSpriteId();
  862. }
  863. //-----------------------------------------------------------------------------
  864. /*! Picks sprites intersecting the specified point with optional group/layer masks.
  865. @param x/y The coordinate of the point as either (\x y\ or (x,y)
  866. @return Returns list of sprite Ids.
  867. */
  868. ConsoleMethodWithDocs(CompositeSprite, pickPoint, ConsoleString, 3, 4, (x / y ))
  869. {
  870. // Fetch sprite batch query and clear results.
  871. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  872. // Is the sprite batch query available?
  873. if ( pSpriteBatchQuery == NULL )
  874. {
  875. // No, so warn.
  876. Con::warnf( "CompositeSprite::pickPoint() - Cannot pick sprites if clipping mode is off." );
  877. // Return nothing.
  878. return NULL;
  879. }
  880. // The point.
  881. Vector2 point;
  882. // The index of the first optional parameter.
  883. U32 firstArg;
  884. // Grab the number of elements in the first parameter.
  885. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  886. // ("x y")
  887. if ((elementCount == 2) && (argc < 8))
  888. {
  889. point = Utility::mGetStringElementVector(argv[2]);
  890. firstArg = 3;
  891. }
  892. // (x, y)
  893. else if ((elementCount == 1) && (argc > 3))
  894. {
  895. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  896. firstArg = 4;
  897. }
  898. // Invalid
  899. else
  900. {
  901. Con::warnf("CompositeSprite::pickPoint() - Invalid number of parameters!");
  902. return NULL;
  903. }
  904. // Fetch the render transform.
  905. const b2Transform& renderTransform = object->getRenderTransform();
  906. // Transform into local space.
  907. point = b2MulT( renderTransform, point );
  908. // Perform query.
  909. pSpriteBatchQuery->queryPoint( point, true );
  910. // Fetch result count.
  911. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  912. // Finish if no results.
  913. if (resultCount == 0 )
  914. return NULL;
  915. // Fetch results.
  916. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  917. // Set Max Buffer Size.
  918. const U32 maxBufferSize = 4096;
  919. // Create Returnable Buffer.
  920. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  921. // Set Buffer Counter.
  922. U32 bufferCount = 0;
  923. // Add picked sprites.
  924. for ( U32 n = 0; n < resultCount; n++ )
  925. {
  926. // Output Object ID.
  927. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  928. // Finish early if we run out of buffer space.
  929. if ( bufferCount >= maxBufferSize )
  930. {
  931. // Warn.
  932. Con::warnf("CompositeSprite::pickPoint() - Too many items picked to return to scripts!");
  933. break;
  934. }
  935. }
  936. // Clear sprite batch query.
  937. pSpriteBatchQuery->clearQuery();
  938. // Return buffer.
  939. return pBuffer;
  940. }
  941. //-----------------------------------------------------------------------------
  942. /*! Picks sprites intersecting the specified area with optional group/layer masks.
  943. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  944. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  945. @return Returns list of sprite Ids.
  946. */
  947. ConsoleMethodWithDocs(CompositeSprite, pickArea, ConsoleString, 4, 6, (startx/y, endx/y ))
  948. {
  949. // Fetch sprite batch query and clear results.
  950. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  951. // Is the sprite batch query available?
  952. if ( pSpriteBatchQuery == NULL )
  953. {
  954. // No, so warn.
  955. Con::warnf( "CompositeSprite::pickArea() - Cannot pick sprites if clipping mode is off." );
  956. // Return nothing.
  957. return NULL;
  958. }
  959. // Upper left and lower right bound.
  960. Vector2 v1, v2;
  961. // The index of the first optional parameter.
  962. U32 firstArg;
  963. // Grab the number of elements in the first two parameters.
  964. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  965. U32 elementCount2 = 1;
  966. if (argc > 3)
  967. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  968. // ("x1 y1 x2 y2")
  969. if ((elementCount1 == 4) && (argc < 9))
  970. {
  971. v1 = Utility::mGetStringElementVector(argv[2]);
  972. v2 = Utility::mGetStringElementVector(argv[2], 2);
  973. firstArg = 3;
  974. }
  975. // ("x1 y1", "x2 y2")
  976. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  977. {
  978. v1 = Utility::mGetStringElementVector(argv[2]);
  979. v2 = Utility::mGetStringElementVector(argv[3]);
  980. firstArg = 4;
  981. }
  982. // (x1, y1, x2, y2)
  983. else if (argc > 5)
  984. {
  985. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  986. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  987. firstArg = 6;
  988. }
  989. // Invalid
  990. else
  991. {
  992. Con::warnf("CompositeSprite::pickArea() - Invalid number of parameters!");
  993. return NULL;
  994. }
  995. // Calculate normalized AABB.
  996. b2AABB aabb;
  997. aabb.lowerBound.x = getMin( v1.x, v2.x );
  998. aabb.lowerBound.y = getMin( v1.y, v2.y );
  999. aabb.upperBound.x = getMax( v1.x, v2.x );
  1000. aabb.upperBound.y = getMax( v1.y, v2.y );
  1001. // Calculate local OOBB.
  1002. b2Vec2 localOOBB[4];
  1003. CoreMath::mAABBtoOOBB( aabb, localOOBB );
  1004. CoreMath::mCalculateInverseOOBB( localOOBB, object->getRenderTransform(), localOOBB );
  1005. // Calculate local AABB.
  1006. b2AABB localAABB;
  1007. CoreMath::mOOBBtoAABB( localOOBB, localAABB );
  1008. // Convert OOBB to a PolygonShape
  1009. b2PolygonShape oobb_polygon;
  1010. oobb_polygon.Set(localOOBB, 4);
  1011. // Perform query.
  1012. pSpriteBatchQuery->queryOOBB( localAABB, oobb_polygon, true );
  1013. // Fetch result count.
  1014. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  1015. // Finish if no results.
  1016. if (resultCount == 0 )
  1017. return NULL;
  1018. // Fetch results.
  1019. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  1020. // Set Max Buffer Size.
  1021. const U32 maxBufferSize = 4096;
  1022. // Create Returnable Buffer.
  1023. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1024. // Set Buffer Counter.
  1025. U32 bufferCount = 0;
  1026. // Add picked objects.
  1027. for ( U32 n = 0; n < resultCount; n++ )
  1028. {
  1029. // Output Object ID.
  1030. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  1031. // Finish early if we run out of buffer space.
  1032. if ( bufferCount >= maxBufferSize )
  1033. {
  1034. // Warn.
  1035. Con::warnf("CompositeSprite::pickArea() - Too many items picked to return to scripts!");
  1036. break;
  1037. }
  1038. }
  1039. // Clear sprite batch query.
  1040. pSpriteBatchQuery->clearQuery();
  1041. // Return buffer.
  1042. return pBuffer;
  1043. }
  1044. //-----------------------------------------------------------------------------
  1045. /*! Picks sprites intersecting the specified ray with optional group/layer masks.
  1046. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  1047. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  1048. @return Returns list of sprite Ids
  1049. */
  1050. ConsoleMethodWithDocs(CompositeSprite, pickRay, ConsoleString, 4, 6, (startx/y, endx/y))
  1051. {
  1052. // Fetch sprite batch query and clear results.
  1053. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  1054. // Is the sprite batch query available?
  1055. if ( pSpriteBatchQuery == NULL )
  1056. {
  1057. // No, so warn.
  1058. Con::warnf( "CompositeSprite::pickRay() - Cannot pick sprites if clipping mode is off." );
  1059. // Return nothing.
  1060. return NULL;
  1061. }
  1062. // Upper left and lower right bound.
  1063. Vector2 v1, v2;
  1064. // The index of the first optional parameter.
  1065. U32 firstArg;
  1066. // Grab the number of elements in the first two parameters.
  1067. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  1068. U32 elementCount2 = 1;
  1069. if (argc > 3)
  1070. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  1071. // ("x1 y1 x2 y2")
  1072. if ((elementCount1 == 4) && (argc < 9))
  1073. {
  1074. v1 = Utility::mGetStringElementVector(argv[2]);
  1075. v2 = Utility::mGetStringElementVector(argv[2], 2);
  1076. firstArg = 3;
  1077. }
  1078. // ("x1 y1", "x2 y2")
  1079. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  1080. {
  1081. v1 = Utility::mGetStringElementVector(argv[2]);
  1082. v2 = Utility::mGetStringElementVector(argv[3]);
  1083. firstArg = 4;
  1084. }
  1085. // (x1, y1, x2, y2)
  1086. else if (argc > 5)
  1087. {
  1088. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1089. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  1090. firstArg = 6;
  1091. }
  1092. // Invalid
  1093. else
  1094. {
  1095. Con::warnf("CompositeSprite::pickRay() - Invalid number of parameters!");
  1096. return NULL;
  1097. }
  1098. // Fetch the render transform.
  1099. const b2Transform& renderTransform = object->getRenderTransform();
  1100. // Transform into local space.
  1101. v1 = b2MulT( renderTransform, v1 );
  1102. v2 = b2MulT( renderTransform, v2 );
  1103. // Perform query.
  1104. pSpriteBatchQuery->queryRay( v1, v2, true );
  1105. // Sanity!
  1106. AssertFatal( pSpriteBatchQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  1107. // Fetch result count.
  1108. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  1109. // Finish if no results.
  1110. if (resultCount == 0 )
  1111. return NULL;
  1112. // Sort ray-cast result.
  1113. pSpriteBatchQuery->sortRaycastQueryResult();
  1114. // Fetch results.
  1115. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  1116. // Set Max Buffer Size.
  1117. const U32 maxBufferSize = 4096;
  1118. // Create Returnable Buffer.
  1119. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1120. // Set Buffer Counter.
  1121. U32 bufferCount = 0;
  1122. // Add Picked Objects to List.
  1123. for ( U32 n = 0; n < resultCount; n++ )
  1124. {
  1125. // Output Object ID.
  1126. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  1127. // Finish early if we run out of buffer space.
  1128. if ( bufferCount >= maxBufferSize )
  1129. {
  1130. // Warn.
  1131. Con::warnf("CompositeSprite::pickRay() - Too many items picked to return to scripts!");
  1132. break;
  1133. }
  1134. }
  1135. // Clear sprite batch query.
  1136. pSpriteBatchQuery->clearQuery();
  1137. // Return buffer.
  1138. return pBuffer;
  1139. }
  1140. ConsoleMethodGroupEndWithDocs(CompositeSprite)