2
0

CompositeSprite_ScriptBinding.h 46 KB

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