CompositeSprite_ScriptBinding.h 44 KB

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