CompositeSprite_ScriptBinding.h 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345
  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, [int imageFrame]))
  306. {
  307. // Fetch frame.
  308. const U32 frame = argc >=4 ? dAtoi(argv[3]) : 0;
  309. object->setSpriteImage( argv[2], frame );
  310. }
  311. //-----------------------------------------------------------------------------
  312. /*! Gets the sprite image.
  313. @return The sprite image.
  314. */
  315. ConsoleMethodWithDocs(CompositeSprite, getSpriteImage, ConsoleString, 2, 2, ())
  316. {
  317. return object->getSpriteImage();
  318. }
  319. //-----------------------------------------------------------------------------
  320. /*! Sets the sprite image frame.
  321. @param imageFrame The image frame to set the sprite to.
  322. @return No return value.
  323. */
  324. ConsoleMethodWithDocs(CompositeSprite, setSpriteImageFrame, ConsoleVoid, 3, 3, (int imageFrame))
  325. {
  326. // Fetch frame.
  327. const U32 frame = dAtoi(argv[2]);
  328. object->setSpriteImageFrame( frame );
  329. }
  330. //-----------------------------------------------------------------------------
  331. /*! Gets the sprite image frame.
  332. @return The sprite image frame.
  333. */
  334. ConsoleMethodWithDocs(CompositeSprite, getSpriteImageFrame, ConsoleInt, 2, 2, ())
  335. {
  336. return object->getSpriteImageFrame();
  337. }
  338. //-----------------------------------------------------------------------------
  339. /*! Sets the sprite animation.
  340. @param imageAssetId The animation to set the sprite to.
  341. @return No return value.
  342. */
  343. ConsoleMethodWithDocs(CompositeSprite, setSpriteAnimation, ConsoleVoid, 3, 4, (animationAssetId))
  344. {
  345. object->setSpriteAnimation( argv[2] );
  346. }
  347. //-----------------------------------------------------------------------------
  348. /*! Gets the sprite animation.
  349. @return The sprite animation.
  350. */
  351. ConsoleMethodWithDocs(CompositeSprite, getSpriteAnimation, ConsoleString, 2, 2, ())
  352. {
  353. return object->getSpriteAnimation();
  354. }
  355. //-----------------------------------------------------------------------------
  356. /*! Clears any image or animation asset from the sprite.
  357. @return No return value.
  358. */
  359. ConsoleMethodWithDocs(CompositeSprite, clearSpriteAsset, ConsoleVoid, 2, 2, ())
  360. {
  361. return object->clearSpriteAsset();
  362. }
  363. //-----------------------------------------------------------------------------
  364. /*! Sets whether the sprite is visible or not.
  365. @param visible Whether the sprite is visible or not.
  366. @return No return value.
  367. */
  368. ConsoleMethodWithDocs(CompositeSprite, setSpriteVisible, ConsoleVoid, 3, 3, (bool visible))
  369. {
  370. // Fetch visible.
  371. const bool visible = dAtob(argv[2]);
  372. object->setSpriteVisible( visible );
  373. }
  374. //-----------------------------------------------------------------------------
  375. /*! Gets whether the sprite is visible or not.
  376. @return Whether the sprite is visible or not.
  377. */
  378. ConsoleMethodWithDocs(CompositeSprite, getSpriteVisible, ConsoleBool, 2, 2, ())
  379. {
  380. return object->getSpriteVisible();
  381. }
  382. //-----------------------------------------------------------------------------
  383. /*! Sets the sprites local position.
  384. @param localX The local position X.
  385. @param localY The local position Y.
  386. @return No return value.
  387. */
  388. ConsoleMethodWithDocs(CompositeSprite, setSpriteLocalPosition, ConsoleVoid, 3, 4, (float localX, float localY))
  389. {
  390. Vector2 localPosition;
  391. // Fetch element count.
  392. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  393. // ("x y")
  394. if ( (elementCount == 2) && (argc == 3) )
  395. {
  396. localPosition.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  397. localPosition.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  398. }
  399. // (x, y)
  400. else if ( elementCount == 1 && (argc > 3) )
  401. {
  402. localPosition.x = dAtof(argv[2]);
  403. localPosition.y = dAtof(argv[3]);
  404. }
  405. // Invalid
  406. else
  407. {
  408. Con::warnf("CompositeSprite::setSpriteLocalPosition() - Invalid number of parameters!");
  409. return;
  410. }
  411. object->setSpriteLocalPosition( localPosition );
  412. }
  413. //-----------------------------------------------------------------------------
  414. /*! Gets the sprite local position.
  415. @return The sprite local position.
  416. */
  417. ConsoleMethodWithDocs(CompositeSprite, getSpriteLocalPosition, ConsoleString, 2, 2, ())
  418. {
  419. return object->getSpriteLocalPosition().scriptThis();
  420. }
  421. //-----------------------------------------------------------------------------
  422. /*! Sets the sprites local angle.
  423. @param localAngle The sprite local angle.
  424. @return No return value.
  425. */
  426. ConsoleMethodWithDocs(CompositeSprite, setSpriteAngle, ConsoleVoid, 3, 3, (float localAngle))
  427. {
  428. // Fetch angle.
  429. const F32 angle = mDegToRad( dAtof(argv[2]) );
  430. object->setSpriteAngle( angle );
  431. }
  432. //-----------------------------------------------------------------------------
  433. /*! Gets the sprite local angle.
  434. @return The sprite local angle.
  435. */
  436. ConsoleMethodWithDocs(CompositeSprite, getSpriteAngle, ConsoleFloat, 2, 2, ())
  437. {
  438. return mRadToDeg( object->getSpriteAngle() );
  439. }
  440. //-----------------------------------------------------------------------------
  441. /*! Sets the sprites depth.
  442. @param depth The sprite depth.
  443. @return No return value.
  444. */
  445. ConsoleMethodWithDocs(CompositeSprite, setSpriteDepth, ConsoleVoid, 3, 3, (float depth))
  446. {
  447. // Fetch depth.
  448. const F32 depth = dAtof(argv[2]);
  449. object->setSpriteDepth( depth );
  450. }
  451. //-----------------------------------------------------------------------------
  452. /*! Gets the sprite depth.
  453. @return The sprite depth.
  454. */
  455. ConsoleMethodWithDocs(CompositeSprite, getSpriteDepth, ConsoleFloat, 2, 2, ())
  456. {
  457. return object->getSpriteDepth();
  458. }
  459. //-----------------------------------------------------------------------------
  460. /*! Sets the sprite size.
  461. @param width The sprite width.
  462. @param height The sprite height
  463. @return No return value.
  464. */
  465. ConsoleMethodWithDocs(CompositeSprite, setSpriteSize, ConsoleVoid, 3, 4, (float width, [float height]))
  466. {
  467. Vector2 size;
  468. // Fetch element count.
  469. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  470. // ("width height")
  471. if ( (elementCount == 2) && (argc == 3) )
  472. {
  473. size.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  474. size.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  475. }
  476. // (width, [height])
  477. else if (elementCount == 1)
  478. {
  479. size.x = dAtof(argv[2]);
  480. if (argc > 3)
  481. size.y = dAtof(argv[3]);
  482. else
  483. size.y = size.x;
  484. }
  485. // Invalid
  486. else
  487. {
  488. Con::warnf("CompositeSprite::setSpriteSize() - Invalid number of parameters!");
  489. return;
  490. }
  491. object->setSpriteSize( size );
  492. }
  493. //-----------------------------------------------------------------------------
  494. /*! Gets the sprite size.
  495. @return (float width/float height) The sprite size.
  496. */
  497. ConsoleMethodWithDocs(CompositeSprite, getSpriteSize, ConsoleString, 2, 2, ())
  498. {
  499. return object->getSpriteSize().scriptThis();
  500. }
  501. //-----------------------------------------------------------------------------
  502. /*! Sets whether the sprite is flipped along its local X axis or not.
  503. @param flipX Whether the sprite is flipped along its local X axis or not.
  504. @return No return value.
  505. */
  506. ConsoleMethodWithDocs(CompositeSprite, setSpriteFlipX, ConsoleVoid, 3, 3, (bool flipX))
  507. {
  508. // Fetch flipX.
  509. const bool flipX = dAtob(argv[2]);
  510. object->setSpriteFlipX( flipX );
  511. }
  512. //-----------------------------------------------------------------------------
  513. /*! Gets whether the sprite is flipped along its local X axis or not.
  514. @return Whether the sprite is flipped along its local X axis or not.
  515. */
  516. ConsoleMethodWithDocs(CompositeSprite, getSpriteFlipX, ConsoleBool, 2, 2, ())
  517. {
  518. return object->getSpriteFlipX();
  519. }
  520. //-----------------------------------------------------------------------------
  521. /*! Sets whether the sprite is flipped along its local Y axis or not.
  522. @param flipY Whether the sprite is flipped along its local Y axis or not.
  523. @return No return value.
  524. */
  525. ConsoleMethodWithDocs(CompositeSprite, setSpriteFlipY, ConsoleVoid, 3, 3, (bool flipY))
  526. {
  527. const bool flipY = dAtob(argv[2]);
  528. object->setSpriteFlipY( flipY );
  529. }
  530. //-----------------------------------------------------------------------------
  531. /*! Gets whether the sprite is flipped along its local Y axis or not.
  532. @return Whether the sprite is flipped along its local Y axis or not.
  533. */
  534. ConsoleMethodWithDocs(CompositeSprite, getSpriteFlipY, ConsoleBool, 2, 2, ())
  535. {
  536. return object->getSpriteFlipY();
  537. }
  538. //-----------------------------------------------------------------------------
  539. /*! Sets the sprites sort point.
  540. @param localX The local sort point X.
  541. @param localY The local sort point Y.
  542. @return No return value.
  543. */
  544. ConsoleMethodWithDocs(CompositeSprite, setSpriteSortPoint, ConsoleVoid, 3, 4, (float localX, float localY))
  545. {
  546. Vector2 sortPoint;
  547. // Fetch element count.
  548. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  549. // ("x y")
  550. if ( (elementCount == 2) && (argc == 3) )
  551. {
  552. sortPoint.x = dAtof(Utility::mGetStringElement(argv[2], 0));
  553. sortPoint.y = dAtof(Utility::mGetStringElement(argv[2], 1));
  554. }
  555. // (x, y)
  556. else if ( elementCount == 1 && (argc > 3) )
  557. {
  558. sortPoint.x = dAtof(argv[2]);
  559. sortPoint.y = dAtof(argv[3]);
  560. }
  561. // Invalid
  562. else
  563. {
  564. Con::warnf("CompositeSprite::setSpriteSortPoint() - Invalid number of parameters!");
  565. return;
  566. }
  567. object->setSpriteSortPoint( sortPoint );
  568. }
  569. //-----------------------------------------------------------------------------
  570. /*! Gets the sprite local sort point.
  571. @return The sprite local sort point.
  572. */
  573. ConsoleMethodWithDocs(CompositeSprite, getSpriteSortPoint, ConsoleString, 2, 2, ())
  574. {
  575. return object->getSpriteSortPoint().scriptThis();
  576. }
  577. //-----------------------------------------------------------------------------
  578. /*! Sets the name of the render group used to sort the sprite during rendering.
  579. @param renderGroup The name of the render group to use. Defaults to nothing.
  580. @return No return value.
  581. */
  582. ConsoleMethodWithDocs(CompositeSprite, setSpriteRenderGroup, ConsoleVoid, 3, 3, (renderGroup))
  583. {
  584. object->setSpriteRenderGroup( argv[2] );
  585. }
  586. //-----------------------------------------------------------------------------
  587. /*! Gets the name of the render group used to sort the sprite during rendering.
  588. @return The render group used to sort the object during rendering.
  589. */
  590. ConsoleMethodWithDocs(CompositeSprite, getSpriteRenderGroup, ConsoleString, 2, 2, ())
  591. {
  592. return object->getSpriteRenderGroup();
  593. }
  594. //-----------------------------------------------------------------------------
  595. /*! Sets whether sprite blending is on or not.
  596. @blendMode Whether sprite blending is on or not.
  597. @return No return Value.
  598. */
  599. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendMode, ConsoleVoid, 3, 3, (bool blendMode))
  600. {
  601. // Fetch blend mode.
  602. const bool blendMode = dAtob(argv[2]);
  603. object->setSpriteBlendMode( blendMode );
  604. }
  605. //-----------------------------------------------------------------------------
  606. /*! Gets whether sprite blending is on or not.
  607. @return (bool blendMode) Whether sprite blending is on or not.
  608. */
  609. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendMode, ConsoleBool, 2, 2, ())
  610. {
  611. return object->getSpriteBlendMode();
  612. }
  613. //-----------------------------------------------------------------------------
  614. /*! Sets the sprite source blend factor.
  615. @param srcBlend The sprite source blend factor.
  616. @return No return Value.
  617. */
  618. ConsoleMethodWithDocs(CompositeSprite, setSpriteSrcBlendFactor, ConsoleVoid, 3, 3, (srcBlend))
  619. {
  620. // Fetch source blend factor.
  621. GLenum blendFactor = SceneObject::getSrcBlendFactorEnum(argv[2]);
  622. object->setSpriteSrcBlendFactor( blendFactor );
  623. }
  624. //-----------------------------------------------------------------------------
  625. /*! Gets the sprite source blend factor.
  626. @return (srcBlend) The sprite source blend factor.
  627. */
  628. ConsoleMethodWithDocs(CompositeSprite, getSpriteSrcBlendFactor, ConsoleString, 2, 2, ())
  629. {
  630. return SceneObject::getSrcBlendFactorDescription( object->getSpriteSrcBlendFactor() );
  631. }
  632. //-----------------------------------------------------------------------------
  633. /*! Sets the sprite destination blend factor.
  634. @param dstBlend The sprite destination blend factor.
  635. @return No return Value.
  636. */
  637. ConsoleMethodWithDocs(CompositeSprite, setSpriteDstBlendFactor, ConsoleVoid, 3, 3, (dstBlend))
  638. {
  639. // Fetch destination blend factor.
  640. GLenum blendFactor = SceneObject::getDstBlendFactorEnum(argv[2]);
  641. object->setSpriteDstBlendFactor( blendFactor );
  642. }
  643. //-----------------------------------------------------------------------------
  644. /*! Gets the sprite destination blend factor.
  645. @return (dstBlend) The sprite destination blend factor.
  646. */
  647. ConsoleMethodWithDocs(CompositeSprite, getSpriteDstBlendFactor, ConsoleString, 2, 2, ())
  648. {
  649. return SceneObject::getDstBlendFactorDescription( object->getSpriteDstBlendFactor() );
  650. }
  651. //-----------------------------------------------------------------------------
  652. /*! or ( stockColorName ) - Sets the sprite blend color.
  653. @param red The red value.
  654. @param green The green value.
  655. @param blue The blue value.
  656. @param alpha The alpha value.
  657. @return No return Value.
  658. */
  659. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendColor, ConsoleVoid, 3, 6, (float red, float green, float blue, [float alpha = 1.0]))
  660. {
  661. // The colors.
  662. F32 red;
  663. F32 green;
  664. F32 blue;
  665. F32 alpha = 1.0f;
  666. // Space separated.
  667. if (argc == 3 )
  668. {
  669. // Grab the element count.
  670. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  671. // Has a single argument been specified?
  672. if ( elementCount == 1 )
  673. {
  674. // Is a sprite selected?
  675. if ( !object->isSpriteSelected() )
  676. {
  677. // No, so warn.
  678. Con::warnf("CompositeSprite::setSpriteBlendColor() - Cannot set sprite blend color as no sprite is selected." );
  679. return;
  680. }
  681. Con::setData( TypeColorF, &const_cast<ColorF&>(object->getSpriteBlendColor()), 0, 1, &(argv[2]) );
  682. return;
  683. }
  684. // ("R G B [A]")
  685. if ((elementCount == 3) || (elementCount == 4))
  686. {
  687. // Extract the color.
  688. red = dAtof(Utility::mGetStringElement(argv[2], 0));
  689. green = dAtof(Utility::mGetStringElement(argv[2], 1));
  690. blue = dAtof(Utility::mGetStringElement(argv[2], 2));
  691. // Grab the alpha if it's there.
  692. if (elementCount > 3)
  693. alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
  694. }
  695. // Invalid.
  696. else
  697. {
  698. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  699. return;
  700. }
  701. }
  702. // (R, G, B)
  703. else if (argc >= 5)
  704. {
  705. red = dAtof(argv[2]);
  706. green = dAtof(argv[3]);
  707. blue = dAtof(argv[4]);
  708. // Grab the alpha if it's there.
  709. if (argc > 5)
  710. alpha = dAtof(argv[5]);
  711. }
  712. // Invalid.
  713. else
  714. {
  715. Con::warnf("SceneObject::setBlendColor() - Invalid Number of parameters!");
  716. return;
  717. }
  718. // Set blend color.
  719. object->setSpriteBlendColor(ColorF(red, green, blue, alpha));
  720. }
  721. //-----------------------------------------------------------------------------
  722. /*! Gets the sprite blend color
  723. @param allowColorNames Whether to allow stock color names to be returned or not. Optional: Defaults to false.
  724. @return (float red / float green / float blue / float alpha) The sprite blend color.
  725. */
  726. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendColor, ConsoleString, 2, 3, (allowColorNames))
  727. {
  728. // Get Blend color.
  729. ColorF blendColor = object->getSpriteBlendColor();
  730. // Fetch allow color names flag.
  731. const bool allowColorNames = (argc > 2) ? dAtob(argv[2] ) : false;
  732. // Are color names allowed?
  733. if ( allowColorNames )
  734. {
  735. // Yes, so fetch the field value.
  736. return Con::getData( TypeColorF, &blendColor, 0 );
  737. }
  738. // No, so fetch the raw color values.
  739. return blendColor.scriptThis();
  740. }
  741. //-----------------------------------------------------------------------------
  742. /*! Sets the sprite color alpha (transparency).
  743. 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.
  744. @param alpha The alpha value.
  745. @return No return Value.
  746. */
  747. ConsoleMethodWithDocs(CompositeSprite, setSpriteBlendAlpha, ConsoleVoid, 3, 3, (float alpha))
  748. {
  749. object->setSpriteBlendAlpha( dAtof(argv[2]) );
  750. }
  751. //-----------------------------------------------------------------------------
  752. /*! Gets the sprite color alpha (transparency).
  753. @return (float alpha) The alpha value, a range from 0.0 to 1.0. Less than zero if alpha testing is disabled.
  754. */
  755. ConsoleMethodWithDocs(CompositeSprite, getSpriteBlendAlpha, ConsoleFloat, 2, 2, ())
  756. {
  757. return object->getSpriteBlendAlpha();
  758. }
  759. //-----------------------------------------------------------------------------
  760. /*! Set the sprite alpha test.
  761. @param value Numeric value of 0.0 to 1.0 to turn on alpha testing. Less than zero to disable alpha testing.
  762. @return No return Value.
  763. */
  764. ConsoleMethodWithDocs(CompositeSprite, setSpriteAlphaTest, ConsoleVoid, 3, 3, (float alpha))
  765. {
  766. object->setSpriteAlphaTest(dAtof(argv[2]));
  767. }
  768. //-----------------------------------------------------------------------------
  769. /*! Gets the sprite alpha test.
  770. @return (S32) A value of 0 to 255 if alpha testing is enabled. <0 represents disabled alpha testing.
  771. */
  772. ConsoleMethodWithDocs(CompositeSprite, getSpriteAlphaTest, ConsoleFloat, 2, 2, ())
  773. {
  774. return object->getSpriteAlphaTest();
  775. }
  776. //-----------------------------------------------------------------------------
  777. /*! Set the sprite data object.
  778. NOTE: This object will be persisted alongside the composite sprite.
  779. To clear the object you can pass an empty string.
  780. @return No return Value.
  781. */
  782. ConsoleMethodWithDocs(CompositeSprite, setSpriteDataObject, ConsoleVoid, 3, 3, (object))
  783. {
  784. object->setSpriteDataObject( Sim::findObject( argv[2] ) );
  785. }
  786. //-----------------------------------------------------------------------------
  787. /*! Gets the sprite data object.
  788. @return The sprite data object.
  789. */
  790. ConsoleMethodWithDocs(CompositeSprite, getSpriteDataObject, ConsoleString, 2, 2, ())
  791. {
  792. return object->getSpriteDataObject()->getIdString();
  793. }
  794. //-----------------------------------------------------------------------------
  795. /*! Set the sprite name.
  796. This must be unique within this composite sprite instance. To clear the name you can pass an empty string.
  797. @return No return Value.
  798. */
  799. ConsoleMethodWithDocs(CompositeSprite, setSpriteName, ConsoleVoid, 3, 3, (name))
  800. {
  801. object->setSpriteName( argv[2] );
  802. }
  803. //-----------------------------------------------------------------------------
  804. /*! Gets the sprite name.
  805. @return The sprite name.
  806. */
  807. ConsoleMethodWithDocs(CompositeSprite, getSpriteName, ConsoleString, 2, 2, ())
  808. {
  809. return object->getSpriteName();
  810. }
  811. //-----------------------------------------------------------------------------
  812. /*! Picks sprites intersecting the specified point with optional group/layer masks.
  813. @param x/y The coordinate of the point as either (\x y\ or (x,y)
  814. @return Returns list of sprite Ids.
  815. */
  816. ConsoleMethodWithDocs(CompositeSprite, pickPoint, ConsoleString, 3, 4, (x / y ))
  817. {
  818. // Fetch sprite batch query and clear results.
  819. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  820. // Is the sprite batch query available?
  821. if ( pSpriteBatchQuery == NULL )
  822. {
  823. // No, so warn.
  824. Con::warnf( "CompositeSprite::pickPoint() - Cannot pick sprites if clipping mode is off." );
  825. // Return nothing.
  826. return NULL;
  827. }
  828. // The point.
  829. Vector2 point;
  830. // The index of the first optional parameter.
  831. U32 firstArg;
  832. // Grab the number of elements in the first parameter.
  833. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  834. // ("x y")
  835. if ((elementCount == 2) && (argc < 8))
  836. {
  837. point = Utility::mGetStringElementVector(argv[2]);
  838. firstArg = 3;
  839. }
  840. // (x, y)
  841. else if ((elementCount == 1) && (argc > 3))
  842. {
  843. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  844. firstArg = 4;
  845. }
  846. // Invalid
  847. else
  848. {
  849. Con::warnf("CompositeSprite::pickPoint() - Invalid number of parameters!");
  850. return NULL;
  851. }
  852. // Fetch the render transform.
  853. const b2Transform& renderTransform = object->getRenderTransform();
  854. // Transform into local space.
  855. point = b2MulT( renderTransform, point );
  856. // Perform query.
  857. pSpriteBatchQuery->queryPoint( point, true );
  858. // Fetch result count.
  859. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  860. // Finish if no results.
  861. if (resultCount == 0 )
  862. return NULL;
  863. // Fetch results.
  864. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  865. // Set Max Buffer Size.
  866. const U32 maxBufferSize = 4096;
  867. // Create Returnable Buffer.
  868. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  869. // Set Buffer Counter.
  870. U32 bufferCount = 0;
  871. // Add picked sprites.
  872. for ( U32 n = 0; n < resultCount; n++ )
  873. {
  874. // Output Object ID.
  875. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  876. // Finish early if we run out of buffer space.
  877. if ( bufferCount >= maxBufferSize )
  878. {
  879. // Warn.
  880. Con::warnf("CompositeSprite::pickPoint() - Too many items picked to return to scripts!");
  881. break;
  882. }
  883. }
  884. // Clear sprite batch query.
  885. pSpriteBatchQuery->clearQuery();
  886. // Return buffer.
  887. return pBuffer;
  888. }
  889. //-----------------------------------------------------------------------------
  890. /*! Picks sprites intersecting the specified area with optional group/layer masks.
  891. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  892. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  893. @return Returns list of sprite Ids.
  894. */
  895. ConsoleMethodWithDocs(CompositeSprite, pickArea, ConsoleString, 4, 6, (startx/y, endx/y ))
  896. {
  897. // Fetch sprite batch query and clear results.
  898. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  899. // Is the sprite batch query available?
  900. if ( pSpriteBatchQuery == NULL )
  901. {
  902. // No, so warn.
  903. Con::warnf( "CompositeSprite::pickArea() - Cannot pick sprites if clipping mode is off." );
  904. // Return nothing.
  905. return NULL;
  906. }
  907. // Upper left and lower right bound.
  908. Vector2 v1, v2;
  909. // The index of the first optional parameter.
  910. U32 firstArg;
  911. // Grab the number of elements in the first two parameters.
  912. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  913. U32 elementCount2 = 1;
  914. if (argc > 3)
  915. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  916. // ("x1 y1 x2 y2")
  917. if ((elementCount1 == 4) && (argc < 9))
  918. {
  919. v1 = Utility::mGetStringElementVector(argv[2]);
  920. v2 = Utility::mGetStringElementVector(argv[2], 2);
  921. firstArg = 3;
  922. }
  923. // ("x1 y1", "x2 y2")
  924. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  925. {
  926. v1 = Utility::mGetStringElementVector(argv[2]);
  927. v2 = Utility::mGetStringElementVector(argv[3]);
  928. firstArg = 4;
  929. }
  930. // (x1, y1, x2, y2)
  931. else if (argc > 5)
  932. {
  933. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  934. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  935. firstArg = 6;
  936. }
  937. // Invalid
  938. else
  939. {
  940. Con::warnf("CompositeSprite::pickArea() - Invalid number of parameters!");
  941. return NULL;
  942. }
  943. // Calculate normalized AABB.
  944. b2AABB aabb;
  945. aabb.lowerBound.x = getMin( v1.x, v2.x );
  946. aabb.lowerBound.y = getMin( v1.y, v2.y );
  947. aabb.upperBound.x = getMax( v1.x, v2.x );
  948. aabb.upperBound.y = getMax( v1.y, v2.y );
  949. // Calculate local OOBB.
  950. b2Vec2 localOOBB[4];
  951. CoreMath::mAABBtoOOBB( aabb, localOOBB );
  952. CoreMath::mCalculateInverseOOBB( localOOBB, object->getRenderTransform(), localOOBB );
  953. // Calculate local AABB.
  954. b2AABB localAABB;
  955. CoreMath::mOOBBtoAABB( localOOBB, localAABB );
  956. // Convert OOBB to a PolygonShape
  957. b2PolygonShape oobb_polygon;
  958. oobb_polygon.Set(localOOBB, 4);
  959. // Perform query.
  960. pSpriteBatchQuery->queryOOBB( localAABB, oobb_polygon, true );
  961. // Fetch result count.
  962. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  963. // Finish if no results.
  964. if (resultCount == 0 )
  965. return NULL;
  966. // Fetch results.
  967. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  968. // Set Max Buffer Size.
  969. const U32 maxBufferSize = 4096;
  970. // Create Returnable Buffer.
  971. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  972. // Set Buffer Counter.
  973. U32 bufferCount = 0;
  974. // Add picked objects.
  975. for ( U32 n = 0; n < resultCount; n++ )
  976. {
  977. // Output Object ID.
  978. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  979. // Finish early if we run out of buffer space.
  980. if ( bufferCount >= maxBufferSize )
  981. {
  982. // Warn.
  983. Con::warnf("CompositeSprite::pickArea() - Too many items picked to return to scripts!");
  984. break;
  985. }
  986. }
  987. // Clear sprite batch query.
  988. pSpriteBatchQuery->clearQuery();
  989. // Return buffer.
  990. return pBuffer;
  991. }
  992. //-----------------------------------------------------------------------------
  993. /*! Picks sprites intersecting the specified ray with optional group/layer masks.
  994. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  995. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  996. @return Returns list of sprite Ids
  997. */
  998. ConsoleMethodWithDocs(CompositeSprite, pickRay, ConsoleString, 4, 6, (startx/y, endx/y))
  999. {
  1000. // Fetch sprite batch query and clear results.
  1001. SpriteBatchQuery* pSpriteBatchQuery = object->getSpriteBatchQuery( true );
  1002. // Is the sprite batch query available?
  1003. if ( pSpriteBatchQuery == NULL )
  1004. {
  1005. // No, so warn.
  1006. Con::warnf( "CompositeSprite::pickRay() - Cannot pick sprites if clipping mode is off." );
  1007. // Return nothing.
  1008. return NULL;
  1009. }
  1010. // Upper left and lower right bound.
  1011. Vector2 v1, v2;
  1012. // The index of the first optional parameter.
  1013. U32 firstArg;
  1014. // Grab the number of elements in the first two parameters.
  1015. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  1016. U32 elementCount2 = 1;
  1017. if (argc > 3)
  1018. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  1019. // ("x1 y1 x2 y2")
  1020. if ((elementCount1 == 4) && (argc < 9))
  1021. {
  1022. v1 = Utility::mGetStringElementVector(argv[2]);
  1023. v2 = Utility::mGetStringElementVector(argv[2], 2);
  1024. firstArg = 3;
  1025. }
  1026. // ("x1 y1", "x2 y2")
  1027. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  1028. {
  1029. v1 = Utility::mGetStringElementVector(argv[2]);
  1030. v2 = Utility::mGetStringElementVector(argv[3]);
  1031. firstArg = 4;
  1032. }
  1033. // (x1, y1, x2, y2)
  1034. else if (argc > 5)
  1035. {
  1036. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1037. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  1038. firstArg = 6;
  1039. }
  1040. // Invalid
  1041. else
  1042. {
  1043. Con::warnf("CompositeSprite::pickRay() - Invalid number of parameters!");
  1044. return NULL;
  1045. }
  1046. // Fetch the render transform.
  1047. const b2Transform& renderTransform = object->getRenderTransform();
  1048. // Transform into local space.
  1049. v1 = b2MulT( renderTransform, v1 );
  1050. v2 = b2MulT( renderTransform, v2 );
  1051. // Perform query.
  1052. pSpriteBatchQuery->queryRay( v1, v2, true );
  1053. // Sanity!
  1054. AssertFatal( pSpriteBatchQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  1055. // Fetch result count.
  1056. const U32 resultCount = pSpriteBatchQuery->getQueryResultsCount();
  1057. // Finish if no results.
  1058. if (resultCount == 0 )
  1059. return NULL;
  1060. // Sort ray-cast result.
  1061. pSpriteBatchQuery->sortRaycastQueryResult();
  1062. // Fetch results.
  1063. typeSpriteBatchQueryResultVector& queryResults = pSpriteBatchQuery->getQueryResults();
  1064. // Set Max Buffer Size.
  1065. const U32 maxBufferSize = 4096;
  1066. // Create Returnable Buffer.
  1067. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1068. // Set Buffer Counter.
  1069. U32 bufferCount = 0;
  1070. // Add Picked Objects to List.
  1071. for ( U32 n = 0; n < resultCount; n++ )
  1072. {
  1073. // Output Object ID.
  1074. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSpriteBatchItem->getBatchId() );
  1075. // Finish early if we run out of buffer space.
  1076. if ( bufferCount >= maxBufferSize )
  1077. {
  1078. // Warn.
  1079. Con::warnf("CompositeSprite::pickRay() - Too many items picked to return to scripts!");
  1080. break;
  1081. }
  1082. }
  1083. // Clear sprite batch query.
  1084. pSpriteBatchQuery->clearQuery();
  1085. // Return buffer.
  1086. return pBuffer;
  1087. }
  1088. ConsoleMethodGroupEndWithDocs(CompositeSprite)