2
0

CompositeSprite_ScriptBinding.h 43 KB

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