Scene_ScriptBinding.h 117 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592
  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(Scene, BehaviorComponent)
  23. /*! Gets the system-wide scene count.
  24. @return The system-wide scene count.
  25. */
  26. ConsoleFunctionWithDocs( getGlobalSceneCount, ConsoleInt, 1, 1, ())
  27. {
  28. return Scene::getGlobalSceneCount();
  29. }
  30. //-----------------------------------------------------------------------------
  31. /*! The gravity force to apply to all objects in the scene.
  32. @param forceX/forceY The direction and magnitude of the force in each direction. Formatted as either (\forceX forceY\ or (forceX, forceY)
  33. @return No return value.
  34. */
  35. ConsoleMethodWithDocs(Scene, setGravity, ConsoleVoid, 3, 4, (forceX / forceY))
  36. {
  37. // The force.
  38. Vector2 force;
  39. // Grab the element count.
  40. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  41. // ("forceX forceY")
  42. if (elementCount == 1)
  43. {
  44. force = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  45. }
  46. else if (elementCount == 2)
  47. {
  48. force = Utility::mGetStringElementVector(argv[2]);
  49. }
  50. // Invalid
  51. else
  52. {
  53. Con::warnf("SceneObject::setGravity() - Invalid number of parameters!");
  54. return;
  55. }
  56. // Set gravity.
  57. object->setGravity(force);
  58. }
  59. //-----------------------------------------------------------------------------
  60. /*! Gets the gravity force applied to all objects in the scene.
  61. @return The gravity force applied to all objects in the scene.
  62. */
  63. ConsoleMethodWithDocs(Scene, getGravity, ConsoleString, 2, 2, ())
  64. {
  65. return Vector2(object->getGravity()).scriptThis();
  66. }
  67. //-----------------------------------------------------------------------------
  68. /*! Sets the number of velocity iterations the physics solver uses.
  69. @return No return value.
  70. */
  71. ConsoleMethodWithDocs(Scene, setVelocityIterations, ConsoleVoid, 3, 3, (int iterations))
  72. {
  73. object->setVelocityIterations( dAtoi(argv[2]) );
  74. }
  75. //-----------------------------------------------------------------------------
  76. /*! Gets the number of velocity iterations the physics solver uses.
  77. (@return The number of velocity iterations the physics solver uses.
  78. */
  79. ConsoleMethodWithDocs(Scene, getVelocityIterations, ConsoleInt, 2, 2, ())
  80. {
  81. return object->getVelocityIterations();
  82. }
  83. //-----------------------------------------------------------------------------
  84. /*! Sets the number of position iterations the physics solver uses.
  85. @return No return value.
  86. */
  87. ConsoleMethodWithDocs(Scene, setPositionIterations, ConsoleVoid, 3, 3, (int iterations))
  88. {
  89. object->setPositionIterations( dAtoi(argv[2]) );
  90. }
  91. //-----------------------------------------------------------------------------
  92. /*! Gets the number of position iterations the physics solver uses.
  93. (@return The number of position iterations the physics solver uses.
  94. */
  95. ConsoleMethodWithDocs(Scene, getPositionIterations, ConsoleInt, 2, 2, ())
  96. {
  97. return object->getPositionIterations();
  98. }
  99. //-----------------------------------------------------------------------------
  100. /*! Add the SceneObject to the scene.
  101. @param sceneObject The SceneObject to add to the scene.
  102. @return No return value.
  103. */
  104. ConsoleMethodWithDocs(Scene, add, ConsoleVoid, 3, 3, (sceneObject))
  105. {
  106. // Find the specified object.
  107. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  108. // Did we find the object?
  109. if ( !pSceneObject )
  110. {
  111. // No, so warn.
  112. Con::warnf("Scene::addToScene() - Could not find the specified object '%s'.", argv[2]);
  113. return;
  114. }
  115. // Add to Scene.
  116. object->addToScene( pSceneObject );
  117. }
  118. //-----------------------------------------------------------------------------
  119. /*! Remove the SceneObject from the scene.
  120. @param sceneObject The SceneObject to remove from the scene.
  121. @return No return value.
  122. */
  123. ConsoleMethodWithDocs(Scene, remove, ConsoleVoid, 3, 3, (sceneObject))
  124. {
  125. // Find the specified object.
  126. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  127. // Did we find the object?
  128. if ( !pSceneObject )
  129. {
  130. // No, so warn.
  131. Con::warnf("Scene::removeFromScene() - Could not find the specified object '%s'.", argv[2]);
  132. return;
  133. }
  134. // Remove from Scene.
  135. object->removeFromScene( pSceneObject );
  136. }
  137. //-----------------------------------------------------------------------------
  138. /*! Clear the scene of all scene objects.
  139. @param deleteObjects A boolean flag that sets whether to delete the objects as well as remove them from the scene (default is true).
  140. @return No return value.
  141. */
  142. ConsoleMethodWithDocs(Scene, clear, ConsoleVoid, 2, 3, ([deleteObjects]))
  143. {
  144. // Calculate 'Delete Objects' flag.
  145. bool deleteObjects;
  146. if ( argc >= 3 )
  147. deleteObjects = dAtob( argv[2] );
  148. else
  149. deleteObjects = true;
  150. // Clear Scene.
  151. object->clearScene( deleteObjects );
  152. }
  153. //-----------------------------------------------------------------------------
  154. /*! Gets the count of scene objects in the scnee.
  155. @return Returns the number of scene objects in current scene as an integer.
  156. */
  157. ConsoleMethodWithDocs(Scene, getCount, ConsoleInt, 2, 2, ())
  158. {
  159. // Get Scene Object-Count.
  160. return object->getSceneObjectCount();
  161. }
  162. //-----------------------------------------------------------------------------
  163. /*! Gets the scene object at the selected index.
  164. @param sceneObjectIndex The index of the desired object
  165. @return The scene object at the specified index.
  166. */
  167. ConsoleMethodWithDocs(Scene, getObject, ConsoleInt, 3, 3, (sceneObjectIndex))
  168. {
  169. // Fetch Object Index.
  170. const U32 objectIndex = dAtoi(argv[2]);
  171. // Fetch scene object count.
  172. const U32 sceneObjectCount = object->getSceneObjectCount();
  173. // Sanity!
  174. if ( objectIndex >= sceneObjectCount )
  175. {
  176. // Error so warn.
  177. Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d) as there are only (%d) object(s) in the scene!", objectIndex, sceneObjectCount );
  178. // Return no object.
  179. return 0;
  180. }
  181. // Fetch Scene Object.
  182. const SceneObject* pSceneObject = object->getSceneObject( objectIndex );
  183. // Check Object.
  184. if ( pSceneObject != NULL )
  185. {
  186. // No error so return object id.
  187. return pSceneObject->getId();
  188. }
  189. else
  190. {
  191. // Error so warn.
  192. Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d)!", objectIndex);
  193. // Return no object.
  194. return 0;
  195. }
  196. }
  197. //-----------------------------------------------------------------------------
  198. /*! Gets the Scene Object-List.
  199. @return Returns a string with a list of object IDs
  200. */
  201. ConsoleMethodWithDocs(Scene, getSceneObjectList, ConsoleString, 2, 2, ())
  202. {
  203. // Scene Object-List.
  204. Vector<SceneObject*> objList;
  205. // Finish here if there are no scene objects.
  206. U32 objCount = object->getSceneObjects( objList );
  207. if( objCount == 0 )
  208. return NULL;
  209. // Our return buffer will be 6 times the size of our object list (4 for Id (+1 for future size?) + 1 for space).
  210. U32 maxBufferSize = objCount * 12;
  211. // Create Returnable Buffer.
  212. char *pBuffer = Con::getReturnBuffer( maxBufferSize );
  213. // Set Buffer Counter.
  214. U32 bufferCount = 0;
  215. // Iterate through the list and generate an id string list to return
  216. for ( S32 n = 0; n < objList.size(); n++ )
  217. {
  218. // Output Object ID.
  219. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", objList[n]->getId() );
  220. // Finish early if we run out of buffer space.
  221. if ( bufferCount >= maxBufferSize )
  222. {
  223. // Warn.
  224. Con::warnf("Scene::getSceneObjectList() - Not enough space to return all %d objects!", objList.size());
  225. break;
  226. }
  227. }
  228. // Return buffer.
  229. return pBuffer;
  230. }
  231. //-----------------------------------------------------------------------------
  232. /*! Gets the number of assets set to preload for this scene.
  233. @return The number of assets set to preload for this scene.
  234. */
  235. ConsoleMethodWithDocs(Scene, getAssetPreloadCount, ConsoleInt, 2, 2, ())
  236. {
  237. return object->getAssetPreloadCount();
  238. }
  239. //-----------------------------------------------------------------------------
  240. /*! Gets the asset to be preloaded at the specified index.
  241. @param index The index of the preloaded asset.
  242. @return The asset to be preloaded at the specified index.
  243. */
  244. ConsoleMethodWithDocs(Scene, getAssetPreload, ConsoleString, 3, 3, (index))
  245. {
  246. // Fetch preload index.
  247. const S32 index = dAtoi(argv[2]);
  248. // Fetch the asset pointer.
  249. const AssetPtr<AssetBase>* pAssetPtr = object->getAssetPreload( index );
  250. return pAssetPtr == NULL ? NULL : pAssetPtr->getAssetId();
  251. }
  252. //-----------------------------------------------------------------------------
  253. /*! Adds the asset Id so that it is preloaded when the scene is loaded.
  254. The asset loaded immediately by this operation. Duplicate assets are ignored.
  255. @param assetId The asset Id to be added.
  256. @return No return value.
  257. */
  258. ConsoleMethodWithDocs(Scene, addAssetPreload, ConsoleVoid, 3, 3, (assetId))
  259. {
  260. // Fetch asset Id.
  261. const char* pAssetId = argv[2];
  262. // Add asset preload.
  263. object->addAssetPreload( pAssetId );
  264. }
  265. //-----------------------------------------------------------------------------
  266. /*! Removes the asset Id from being preloaded when the scene is loaded.
  267. The asset may be unloaded immediately by this operation if it has no other references.
  268. @param assetId The asset Id to be removed.
  269. @return No return value.
  270. */
  271. ConsoleMethodWithDocs(Scene, removeAssetPreload, ConsoleVoid, 3, 3, (assetId))
  272. {
  273. // Fetch asset Id.
  274. const char* pAssetId = argv[2];
  275. // Remove asset preload.
  276. object->removeAssetPreload( pAssetId );
  277. }
  278. //-----------------------------------------------------------------------------
  279. /*! Clears all assets added as a preload.
  280. @return No return value.
  281. */
  282. ConsoleMethodWithDocs(Scene, clearAssetPreloads, ConsoleVoid, 2, 2, ())
  283. {
  284. // Clear asset preloads.
  285. object->clearAssetPreloads();
  286. }
  287. //-----------------------------------------------------------------------------
  288. /*! Merges the specified scene into this scene by cloning the scenes contents.
  289. */
  290. ConsoleMethodWithDocs(Scene, mergeScene, ConsoleVoid, 3, 3, (scene))
  291. {
  292. // Find the specified scene.
  293. Scene* pScene = Sim::findObject<Scene>( argv[2] );
  294. // Did we find the scene?
  295. if ( pScene == NULL )
  296. {
  297. // No, so warn.
  298. Con::warnf( "Scene::mergeScene() - Could not find the specified scene '%s'.", argv[2] );
  299. return;
  300. }
  301. object->mergeScene( pScene );
  302. }
  303. //-----------------------------------------------------------------------------
  304. /*! Gets the Scene Controllers.
  305. @return Gets the scene controllers.
  306. */
  307. ConsoleMethodWithDocs(Scene, getControllers, ConsoleString, 2, 2, ())
  308. {
  309. // Fetch the scene controllers.
  310. SimSet* pControllerSet = object->getControllers();
  311. return ( pControllerSet == NULL ) ? StringTable->EmptyString : pControllerSet->getIdString();
  312. }
  313. //-----------------------------------------------------------------------------
  314. /*! Gets the Scene Time.
  315. @return Returns the time as a floating point number
  316. */
  317. ConsoleMethodWithDocs(Scene, getSceneTime, ConsoleFloat, 2, 2, ())
  318. {
  319. // Get Scene Time.
  320. return object->getSceneTime();
  321. }
  322. //-----------------------------------------------------------------------------
  323. /*! Sets scene pause status.
  324. @return No return value.
  325. */
  326. ConsoleMethodWithDocs(Scene, setScenePause, ConsoleVoid, 3, 3, (status))
  327. {
  328. // Set Scene Pause.
  329. object->setScenePause( dAtob(argv[2]) );
  330. }
  331. //-----------------------------------------------------------------------------
  332. /*! Gets scene pause status.
  333. @return Returns a boolean value. True if pause status, false otherwise.
  334. */
  335. ConsoleMethodWithDocs(Scene, getScenePause, ConsoleBool, 2, 2, ())
  336. {
  337. // Get Scene Pause.
  338. return object->getScenePause();
  339. }
  340. //-----------------------------------------------------------------------------
  341. /*! Gets the joint count.
  342. @return Returns no value
  343. */
  344. ConsoleMethodWithDocs(Scene, getJointCount, ConsoleInt, 2, 2, ())
  345. {
  346. return object->getJointCount();
  347. }
  348. //-----------------------------------------------------------------------------
  349. /*! Gets whether the joint Id is valid or not.
  350. @param jointId The Id of the joint.
  351. @return whether the joint Id is valid or not.
  352. */
  353. ConsoleMethodWithDocs(Scene, isJoint, ConsoleBool, 3, 3, (int jointId))
  354. {
  355. // Fetch joint Id.
  356. const S32 jointId = dAtoi( argv[2] );
  357. return object->findJoint( jointId ) != NULL;
  358. }
  359. //-----------------------------------------------------------------------------
  360. /*! Gets the joint type of the specified joint Id.
  361. @param jointId The Id of the joint.
  362. @return The type of joint of the specified joint Id.
  363. */
  364. ConsoleMethodWithDocs(Scene, getJointType, ConsoleString, 3, 3, (int jointId))
  365. {
  366. // Fetch joint Id.
  367. const S32 jointId = dAtoi( argv[2] );
  368. // Fetch joint type.
  369. const b2JointType jointType = object->getJointType( jointId );
  370. // Ignore if invalid joint.
  371. if ( jointType == e_unknownJoint )
  372. return StringTable->EmptyString;
  373. return Scene::getJointTypeDescription( jointType );
  374. }
  375. //-----------------------------------------------------------------------------
  376. /*! Deletes the specified joint Id.
  377. @param jointId The Id of the joint.
  378. @return Whether the joint was successfully deleted or not.
  379. */
  380. ConsoleMethodWithDocs(Scene, deleteJoint, ConsoleBool, 3, 3, (int jointId))
  381. {
  382. // Fetch joint Id.
  383. const S32 jointId = dAtoi( argv[2] );
  384. return object->deleteJoint( jointId );
  385. }
  386. //-----------------------------------------------------------------------------
  387. /*! Creates a distance joint.
  388. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  389. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  390. @param localAnchorA The local point of the first scene object where the joint connects.
  391. @param localAnchorB The local point of the second scene object where the joint connects.
  392. @param distance The distance the joint should maintain between scene objects. The default is the distance currently between the scene objects.
  393. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).
  394. @param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.
  395. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  396. @return The joint Id (-1 if error).
  397. */
  398. ConsoleMethodWithDocs(Scene, createDistanceJoint, ConsoleInt, 4, 12, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [distance], [frequency], [dampingRatio], [collideConnected]))
  399. {
  400. // Fetch scene object references.
  401. const char* sceneObjectA = argv[2];
  402. const char* sceneObjectB = argv[3];
  403. SceneObject* pSceneObjectA = NULL;
  404. SceneObject* pSceneObjectB = NULL;
  405. // Fetch scene object.
  406. if ( *sceneObjectA != 0 )
  407. {
  408. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  409. if ( !pSceneObjectA )
  410. Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectA);
  411. }
  412. // Fetch scene object.
  413. if (*sceneObjectB != 0 )
  414. {
  415. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  416. if ( !pSceneObjectB )
  417. Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectB);
  418. }
  419. if ( argc == 4 )
  420. {
  421. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB );
  422. }
  423. // Local anchor A.
  424. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  425. b2Vec2 localAnchorA;
  426. S32 nextArg = 5;
  427. if ( anchorAElementCount == 1 && argc > 5 )
  428. {
  429. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  430. nextArg = 6;
  431. }
  432. else if ( anchorAElementCount == 2 )
  433. {
  434. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  435. }
  436. // Invalid
  437. else
  438. {
  439. Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
  440. return -1;
  441. }
  442. if ( argc <= nextArg )
  443. {
  444. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  445. }
  446. // Local anchor B.
  447. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  448. b2Vec2 localAnchorB;
  449. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  450. {
  451. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  452. nextArg += 2;
  453. }
  454. else if ( anchorBElementCount == 2 )
  455. {
  456. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  457. }
  458. // Invalid
  459. else
  460. {
  461. Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
  462. return -1;
  463. }
  464. if ( argc <= nextArg )
  465. {
  466. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  467. }
  468. // Fetch length.
  469. const F32 length = dAtof(argv[nextArg++]);
  470. if ( argc <= nextArg )
  471. {
  472. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length );
  473. }
  474. // Fetch frequency (Hertz).
  475. const F32 frequency = dAtof(argv[nextArg++]);
  476. if ( argc <= nextArg )
  477. {
  478. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency );
  479. }
  480. // Fetch damping ratio.
  481. const F32 dampingRatio = dAtof(argv[nextArg++]);
  482. if ( argc <= nextArg )
  483. {
  484. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio );
  485. }
  486. // Fetch collide connected.
  487. const bool collideConnected = dAtob(argv[nextArg++]);
  488. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio, collideConnected );
  489. }
  490. //-----------------------------------------------------------------------------
  491. /*! Sets the distance the joint should maintain between scene objects.
  492. @param jointId The Id of the joint to use.
  493. @param length The length the joint should maintain between scene objects.
  494. @return Returns no value.
  495. */
  496. ConsoleMethodWithDocs(Scene, setDistanceJointLength, ConsoleVoid, 4, 4, (jointId, length))
  497. {
  498. // Fetch joint Id.
  499. const S32 jointId = dAtoi(argv[2]);
  500. // Fetch args.
  501. const F32 length = dAtof(argv[3]);
  502. // Access joint.
  503. object->setDistanceJointLength( jointId, length );
  504. }
  505. //-----------------------------------------------------------------------------
  506. /*! Gets the distance the joint should maintain between scene objects.
  507. @param jointId The Id of the joint to use.
  508. @return Returns the distance the joint should maintain between scene objects (-1 indicates error).
  509. */
  510. ConsoleMethodWithDocs(Scene, getDistanceJointLength, ConsoleFloat, 3, 3, (jointId))
  511. {
  512. // Fetch joint Id.
  513. const S32 jointId = dAtoi(argv[2]);
  514. // Access joint.
  515. return object->getDistanceJointLength( jointId );
  516. }
  517. //-----------------------------------------------------------------------------
  518. /*! Sets the mass-spring-damper frequency in Hertz.
  519. @param jointId The Id of the joint to use.
  520. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.
  521. @return Returns no value.
  522. */
  523. ConsoleMethodWithDocs(Scene, setDistanceJointFrequency, ConsoleVoid, 4, 4, (jointId, frequency))
  524. {
  525. // Fetch joint Id.
  526. const S32 jointId = dAtoi(argv[2]);
  527. // Fetch args.
  528. const F32 frequency = dAtof(argv[3]);
  529. // Access joint.
  530. object->setDistanceJointFrequency( jointId, frequency );
  531. }
  532. //-----------------------------------------------------------------------------
  533. /*! Gets the mass-spring-damper frequency in Hertz.
  534. @param jointId The Id of the joint to use.
  535. @return Returns the mass-spring-damper frequency in Hertz (-1 indicates error).
  536. */
  537. ConsoleMethodWithDocs(Scene, getDistanceJointFrequency, ConsoleFloat, 3, 3, (jointId))
  538. {
  539. // Fetch joint Id.
  540. const S32 jointId = dAtoi(argv[2]);
  541. // Access joint.
  542. return object->getDistanceJointFrequency( jointId );
  543. }
  544. //-----------------------------------------------------------------------------
  545. /*! Sets the damping ratio.
  546. @param jointId The Id of the joint to use.
  547. @param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.
  548. @return Returns no value.
  549. */
  550. ConsoleMethodWithDocs(Scene, setDistanceJointDampingRatio, ConsoleVoid, 4, 4, (jointId, dampingRatio))
  551. {
  552. // Fetch joint Id.
  553. const S32 jointId = dAtoi(argv[2]);
  554. // Fetch args.
  555. const F32 dampingRatio = dAtof(argv[3]);
  556. // Access joint.
  557. object->setDistanceJointDampingRatio( jointId, dampingRatio );
  558. }
  559. //-----------------------------------------------------------------------------
  560. /*! Gets the damping ratio.
  561. @param jointId The Id of the joint to use.
  562. @return Returns the damping ratio (-1 indicates error).
  563. */
  564. ConsoleMethodWithDocs(Scene, getDistanceJointDampingRatio, ConsoleFloat, 3, 3, (jointId))
  565. {
  566. // Fetch joint Id.
  567. const S32 jointId = dAtoi(argv[2]);
  568. // Access joint.
  569. return object->getDistanceJointDampingRatio( jointId );
  570. }
  571. //-----------------------------------------------------------------------------
  572. /*! Creates a rope joint.
  573. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  574. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  575. @param localAnchorA The local point of the first scene object where the joint connects.
  576. @param localAnchorB The local point of the second scene object where the joint connects.
  577. @param maxLength The maximum rigid length of the rope.
  578. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  579. @return The joint Id (-1 if error).
  580. */
  581. ConsoleMethodWithDocs(Scene, createRopeJoint, ConsoleInt, 4, 10, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxLength], [collideConnected]))
  582. {
  583. // Fetch scene object references.
  584. const char* sceneObjectA = argv[2];
  585. const char* sceneObjectB = argv[3];
  586. SceneObject* pSceneObjectA = NULL;
  587. SceneObject* pSceneObjectB = NULL;
  588. // Fetch scene object.
  589. if ( *sceneObjectA != 0 )
  590. {
  591. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  592. if ( !pSceneObjectA )
  593. Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectA);
  594. }
  595. // Fetch scene object.
  596. if (*sceneObjectB != 0 )
  597. {
  598. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  599. if ( !pSceneObjectB )
  600. Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectB);
  601. }
  602. if ( argc == 4 )
  603. {
  604. return object->createRopeJoint( pSceneObjectA, pSceneObjectB );
  605. }
  606. // Local anchor A.
  607. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  608. b2Vec2 localAnchorA;
  609. S32 nextArg = 5;
  610. if ( anchorAElementCount == 1 && argc > 5 )
  611. {
  612. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  613. nextArg = 6;
  614. }
  615. else if ( anchorAElementCount == 2 )
  616. {
  617. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  618. }
  619. // Invalid
  620. else
  621. {
  622. Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
  623. return -1;
  624. }
  625. if ( argc <= nextArg )
  626. {
  627. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  628. }
  629. // Local anchor B.
  630. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  631. b2Vec2 localAnchorB;
  632. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  633. {
  634. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  635. nextArg += 2;
  636. }
  637. else if ( anchorBElementCount == 2 )
  638. {
  639. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  640. }
  641. // Invalid
  642. else
  643. {
  644. Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
  645. return -1;
  646. }
  647. if ( argc <= nextArg )
  648. {
  649. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  650. }
  651. // Fetch maximum length.
  652. const F32 maxLength = dAtof(argv[nextArg++]);
  653. if ( argc <= nextArg )
  654. {
  655. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength );
  656. }
  657. // Fetch collide connected.
  658. const bool collideConnected = dAtob(argv[nextArg++]);
  659. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength, collideConnected );
  660. }
  661. //-----------------------------------------------------------------------------
  662. /*! Sets the maximum rigid length of the rope.
  663. @param jointId The Id of the joint to use.
  664. @param maxLength The maximum rigid length of the rope.
  665. @return Returns no value.
  666. */
  667. ConsoleMethodWithDocs(Scene, setRopeJointMaxLength, ConsoleVoid, 4, 4, (jointId, maxLength))
  668. {
  669. // Fetch joint Id.
  670. const S32 jointId = dAtoi(argv[2]);
  671. // Fetch args.
  672. const F32 maxLength = dAtof(argv[3]);
  673. // Access joint.
  674. object->setRopeJointMaxLength( jointId, maxLength );
  675. }
  676. //-----------------------------------------------------------------------------
  677. /*! Gets the maximum rigid length of the rope.
  678. @param jointId The Id of the joint to use.
  679. @return Returns the maximum rigid length of the rope (-1 indicates error).
  680. */
  681. ConsoleMethodWithDocs(Scene, getRopeJointMaxLength, ConsoleFloat, 3, 3, (jointId))
  682. {
  683. // Fetch joint Id.
  684. const S32 jointId = dAtoi(argv[2]);
  685. // Access joint.
  686. return object->getRopeJointMaxLength( jointId );
  687. }
  688. //-----------------------------------------------------------------------------
  689. /*! Creates a revolute joint.
  690. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  691. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  692. @param localAnchorA The local point of the first scene object where the joint connects.
  693. @param localAnchorB The local point of the second scene object where the joint connects.
  694. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  695. @return The joint Id (-1 if error).
  696. */
  697. ConsoleMethodWithDocs(Scene, createRevoluteJoint, ConsoleInt, 4, 9, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [collideConnected]))
  698. {
  699. // Fetch scene object references.
  700. const char* sceneObjectA = argv[2];
  701. const char* sceneObjectB = argv[3];
  702. SceneObject* pSceneObjectA = NULL;
  703. SceneObject* pSceneObjectB = NULL;
  704. // Fetch scene object.
  705. if ( *sceneObjectA != 0 )
  706. {
  707. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  708. if ( !pSceneObjectA )
  709. Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectA);
  710. }
  711. // Fetch scene object.
  712. if ( *sceneObjectB != 0 )
  713. {
  714. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  715. if ( !pSceneObjectB )
  716. Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectB);
  717. }
  718. if ( argc == 4 )
  719. {
  720. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB );
  721. }
  722. // Local anchor A.
  723. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  724. b2Vec2 localAnchorA;
  725. S32 nextArg = 5;
  726. if ( anchorAElementCount == 1 && argc > 5 )
  727. {
  728. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  729. nextArg = 6;
  730. }
  731. else if ( anchorAElementCount == 2 )
  732. {
  733. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  734. }
  735. // Invalid
  736. else
  737. {
  738. Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
  739. return -1;
  740. }
  741. if ( argc <= nextArg )
  742. {
  743. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  744. }
  745. // Local anchor B.
  746. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  747. b2Vec2 localAnchorB;
  748. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  749. {
  750. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  751. nextArg += 2;
  752. }
  753. else if ( anchorBElementCount == 2 )
  754. {
  755. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  756. }
  757. // Invalid
  758. else
  759. {
  760. Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
  761. return -1;
  762. }
  763. if ( argc <= nextArg )
  764. {
  765. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  766. }
  767. // Fetch collide connected.
  768. const bool collideConnected = dAtob(argv[nextArg++]);
  769. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, collideConnected );
  770. }
  771. //-----------------------------------------------------------------------------
  772. /*! Sets whether the joint has angular limits or not and the limits themselves.
  773. @param jointId The Id of the joint to use.
  774. @param enableLimit Whether the joint has angular limits or not.
  775. @param lowerAngle The lower angle of the angular limit.
  776. @param upperAngle The upper angle of the angular limit.
  777. @return Returns no value.
  778. */
  779. ConsoleMethodWithDocs(Scene, setRevoluteJointLimit, ConsoleVoid, 4, 6, (jointId, enableLimit, [lowerAngle], [upperAngle]))
  780. {
  781. // Fetch joint Id.
  782. const S32 jointId = dAtoi(argv[2]);
  783. // Fetch args.
  784. const bool enableLimit = dAtob(argv[3]);
  785. const F32 lowerAngle = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  786. const F32 upperAngle = argc > 5 ? mDegToRad( dAtof(argv[5]) ) : lowerAngle;
  787. // Access joint.
  788. object->setRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle );
  789. }
  790. //-----------------------------------------------------------------------------
  791. /*! Gets whether the joint has angular limits or not and the limits themselves.
  792. @param jointId The Id of the joint to use.
  793. @return Returns whether the joint has angular limits or not and the limits themselves (empty string indicates error).
  794. */
  795. ConsoleMethodWithDocs(Scene, getRevoluteJointLimit, ConsoleString, 3, 3, (jointId))
  796. {
  797. // Fetch joint Id.
  798. const S32 jointId = dAtoi(argv[2]);
  799. // Args.
  800. bool enableLimit;
  801. F32 lowerAngle;
  802. F32 upperAngle;
  803. // Access joint.
  804. if ( !object->getRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle ) )
  805. {
  806. return NULL;
  807. }
  808. // Format output.
  809. char* pBuffer = Con::getReturnBuffer(64);
  810. dSprintf( pBuffer, 64, "%d %g %g", enableLimit, mRadToDeg(lowerAngle), mRadToDeg(upperAngle) );
  811. return pBuffer;
  812. }
  813. //-----------------------------------------------------------------------------
  814. /*! Sets whether the joint has a motor or not and the motor settings.
  815. @param jointId The Id of the joint to use.
  816. @param enableMotor Whether the joint has a motor or not.
  817. @param motorSpeed The motor speed (degrees per/sec).
  818. @param maxMotorTorque The maximum motor torque used to achieve the specified motor speed (N-m).
  819. @return Returns no value.
  820. */
  821. ConsoleMethodWithDocs(Scene, setRevoluteJointMotor, ConsoleVoid, 4, 6, (jointId, enableMotor, [motorSpeed], [maxMotorTorque]))
  822. {
  823. // Fetch joint Id.
  824. const S32 jointId = dAtoi(argv[2]);
  825. // Fetch args.
  826. const bool enableMotor = dAtob(argv[3]);
  827. const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  828. const F32 maxMotorTorque = argc > 5 ? dAtof(argv[5]) : 0.0f;
  829. // Access joint.
  830. object->setRevoluteJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque );
  831. }
  832. //-----------------------------------------------------------------------------
  833. /*! Gets whether the joint has a motor or not and the motor settings.
  834. @param jointId The Id of the joint to use.
  835. @return Returns whether the joint has a motor or not and the motor settings (empty string indicates error).
  836. */
  837. ConsoleMethodWithDocs(Scene, getRevoluteJointMotor, ConsoleString, 3, 3, (jointId))
  838. {
  839. // Fetch joint Id.
  840. const S32 jointId = dAtoi(argv[2]);
  841. // Args.
  842. bool enableMotor;
  843. F32 motorSpeed;
  844. F32 maxMotorTorque;
  845. // Access joint.
  846. if ( !object->getRevoluteJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque ) )
  847. {
  848. return NULL;
  849. }
  850. // Format output.
  851. char* pBuffer = Con::getReturnBuffer(64);
  852. dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorTorque );
  853. return pBuffer;
  854. }
  855. //-----------------------------------------------------------------------------
  856. /*! Gets the current angle of a revolute joint.
  857. @param jointId The Id of the joint to use.
  858. @return Returns the joint angle.
  859. */
  860. ConsoleMethodWithDocs(Scene, getRevoluteJointAngle, ConsoleFloat, 3, 3, (jointId))
  861. {
  862. // Fetch joint Id.
  863. const S32 jointId = dAtoi(argv[2]);
  864. // Access joint.
  865. return object->getRevoluteJointAngle( jointId );
  866. }
  867. //-----------------------------------------------------------------------------
  868. /*! Gets the current speed of a revolute joint.
  869. @param jointId The Id of the joint to use.
  870. @return Returns the joint speed as Angular Velocity
  871. */
  872. ConsoleMethodWithDocs(Scene, getRevoluteJointSpeed, ConsoleFloat, 3, 3, (jointId))
  873. {
  874. // Fetch joint Id.
  875. const S32 jointId = dAtoi(argv[2]);
  876. // Access joint.
  877. return object->getRevoluteJointSpeed( jointId );
  878. }
  879. //-----------------------------------------------------------------------------
  880. /*! Creates a weld joint.
  881. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  882. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  883. @param localAnchorA The local point of the first scene object where the joint connects.
  884. @param localAnchorB The local point of the second scene object where the joint connects.
  885. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).
  886. @param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.
  887. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  888. @return The joint Id (-1 if error).
  889. */
  890. ConsoleMethodWithDocs(Scene, createWeldJoint, ConsoleInt, 4, 11, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [frequency], [dampingRatio], [collideConnected]))
  891. {
  892. // Fetch scene object references.
  893. const char* sceneObjectA = argv[2];
  894. const char* sceneObjectB = argv[3];
  895. SceneObject* pSceneObjectA = NULL;
  896. SceneObject* pSceneObjectB = NULL;
  897. // Fetch scene object.
  898. if ( *sceneObjectA != 0 )
  899. {
  900. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  901. if ( !pSceneObjectA )
  902. Con::warnf("Scene::createWeldJoint() - Could not find scene object %d.", sceneObjectA);
  903. }
  904. // Fetch scene object.
  905. if ( *sceneObjectB != 0 )
  906. {
  907. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  908. if ( !pSceneObjectB )
  909. Con::warnf("Scene::createWeldJoint() - Could not find scene object %d.", sceneObjectB);
  910. }
  911. if ( argc == 4 )
  912. {
  913. return object->createWeldJoint( pSceneObjectA, pSceneObjectB );
  914. }
  915. // Local anchor A.
  916. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  917. b2Vec2 localAnchorA;
  918. S32 nextArg = 5;
  919. if ( anchorAElementCount == 1 && argc > 5 )
  920. {
  921. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  922. nextArg = 6;
  923. }
  924. else if ( anchorAElementCount == 2 )
  925. {
  926. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  927. }
  928. // Invalid
  929. else
  930. {
  931. Con::warnf("Scene::createWeldJoint() - Invalid number of parameters!");
  932. return -1;
  933. }
  934. if ( argc <= nextArg )
  935. {
  936. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  937. }
  938. // Local anchor B.
  939. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  940. b2Vec2 localAnchorB;
  941. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  942. {
  943. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  944. nextArg += 2;
  945. }
  946. else if ( anchorBElementCount == 2 )
  947. {
  948. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  949. }
  950. // Invalid
  951. else
  952. {
  953. Con::warnf("Scene::createWeldJoint() - Invalid number of parameters!");
  954. return -1;
  955. }
  956. if ( argc <= nextArg )
  957. {
  958. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  959. }
  960. // Fetch frequency (Hertz).
  961. const F32 frequency = dAtof(argv[nextArg++]);
  962. if ( argc <= nextArg )
  963. {
  964. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency );
  965. }
  966. // Fetch damping ratio.
  967. const F32 dampingRatio = dAtof(argv[nextArg++]);
  968. if ( argc <= nextArg )
  969. {
  970. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency, dampingRatio );
  971. }
  972. // Fetch collide connected.
  973. const bool collideConnected = dAtob(argv[nextArg++]);
  974. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency, dampingRatio, collideConnected );
  975. }
  976. //-----------------------------------------------------------------------------
  977. /*! Sets the mass-spring-damper frequency in Hertz.
  978. @param jointId The Id of the joint to use.
  979. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.
  980. @return Returns no value.
  981. */
  982. ConsoleMethodWithDocs(Scene, setWeldJointFrequency, ConsoleVoid, 4, 4, (jointId, frequency))
  983. {
  984. // Fetch joint Id.
  985. const S32 jointId = dAtoi(argv[2]);
  986. // Fetch args.
  987. const F32 frequency = dAtof(argv[3]);
  988. // Access joint.
  989. object->setWeldJointFrequency( jointId, frequency );
  990. }
  991. //-----------------------------------------------------------------------------
  992. /*! Gets the mass-spring-damper frequency in Hertz.
  993. @param jointId The Id of the joint to use.
  994. @return Returns the mass-spring-damper frequency in Hertz (-1 indicates error).
  995. */
  996. ConsoleMethodWithDocs(Scene, getWeldJointFrequency, ConsoleFloat, 3, 3, (jointId))
  997. {
  998. // Fetch joint Id.
  999. const S32 jointId = dAtoi(argv[2]);
  1000. // Access joint.
  1001. return object->getWeldJointFrequency( jointId );
  1002. }
  1003. //-----------------------------------------------------------------------------
  1004. /*! Sets the damping ratio.
  1005. @param jointId The Id of the joint to use.
  1006. @param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.
  1007. @return Returns no value.
  1008. */
  1009. ConsoleMethodWithDocs(Scene, setWeldJointDampingRatio, ConsoleVoid, 4, 4, (jointId, dampingRatio))
  1010. {
  1011. // Fetch joint Id.
  1012. const S32 jointId = dAtoi(argv[2]);
  1013. // Fetch args.
  1014. const F32 dampingRatio = dAtof(argv[3]);
  1015. // Access joint.
  1016. object->setWeldJointDampingRatio( jointId, dampingRatio );
  1017. }
  1018. //-----------------------------------------------------------------------------
  1019. /*! Gets the damping ratio.
  1020. @param jointId The Id of the joint to use.
  1021. @return Returns the damping ratio (-1 indicates error).
  1022. */
  1023. ConsoleMethodWithDocs(Scene, getWeldJointDampingRatio, ConsoleFloat, 3, 3, (jointId))
  1024. {
  1025. // Fetch joint Id.
  1026. const S32 jointId = dAtoi(argv[2]);
  1027. // Access joint.
  1028. return object->getWeldJointDampingRatio( jointId );
  1029. }
  1030. //-----------------------------------------------------------------------------
  1031. /*! Creates a wheel joint.
  1032. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1033. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1034. @param localAnchorA The local point of the first scene object where the joint connects.
  1035. @param localAnchorB The local point of the second scene object where the joint connects.
  1036. @param worldAxis The world axis of the wheel suspension spring.
  1037. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  1038. @return The joint Id (-1 if error).
  1039. */
  1040. ConsoleMethodWithDocs(Scene, createWheelJoint, ConsoleInt, 7, 11, (sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldAxis X/Y, [collideConnected]))
  1041. {
  1042. // Fetch scene object references.
  1043. const char* sceneObjectA = argv[2];
  1044. const char* sceneObjectB = argv[3];
  1045. SceneObject* pSceneObjectA = NULL;
  1046. SceneObject* pSceneObjectB = NULL;
  1047. // Fetch scene object.
  1048. if ( *sceneObjectA != 0 )
  1049. {
  1050. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1051. if ( !pSceneObjectA )
  1052. Con::warnf("Scene::createWheelJoint() - Could not find scene object %d.", sceneObjectA);
  1053. }
  1054. // Fetch scene object.
  1055. if ( *sceneObjectB != 0 )
  1056. {
  1057. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1058. if ( !pSceneObjectB )
  1059. Con::warnf("Scene::createWheelJoint() - Could not find scene object %d.", sceneObjectB);
  1060. }
  1061. // Local anchor A.
  1062. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1063. b2Vec2 localAnchorA;
  1064. S32 nextArg = 5;
  1065. if ( anchorAElementCount == 1 && argc > 5 )
  1066. {
  1067. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1068. nextArg = 6;
  1069. }
  1070. else if ( anchorAElementCount == 2 )
  1071. {
  1072. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1073. }
  1074. // Invalid
  1075. else
  1076. {
  1077. Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
  1078. return -1;
  1079. }
  1080. // Local anchor B.
  1081. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1082. b2Vec2 localAnchorB;
  1083. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1084. {
  1085. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1086. nextArg += 2;
  1087. }
  1088. else if ( anchorBElementCount == 2 )
  1089. {
  1090. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1091. }
  1092. // Invalid
  1093. else
  1094. {
  1095. Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
  1096. return -1;
  1097. }
  1098. // World axis.
  1099. const U32 worldAxisElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1100. b2Vec2 worldAxis;
  1101. if ( worldAxisElementCount == 1 && argc > (nextArg+1) )
  1102. {
  1103. worldAxis.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1104. nextArg += 2;
  1105. }
  1106. else if ( worldAxisElementCount == 2 )
  1107. {
  1108. worldAxis = Utility::mGetStringElementVector(argv[nextArg++]);
  1109. }
  1110. // Invalid
  1111. else
  1112. {
  1113. Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
  1114. return -1;
  1115. }
  1116. if ( argc <= nextArg )
  1117. {
  1118. return object->createWheelJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis );
  1119. }
  1120. // Fetch collide connected.
  1121. const bool collideConnected = dAtob(argv[nextArg++]);
  1122. return object->createWheelJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis, collideConnected );
  1123. }
  1124. //-----------------------------------------------------------------------------
  1125. /*! Sets whether the joint has a motor or not and the motor settings.
  1126. @param jointId The Id of the joint to use.
  1127. @param enableMotor Whether the joint has a motor or not.
  1128. @param motorSpeed The motor speed (degrees per/sec).
  1129. @param maxMotorTorque The maximum motor torque used to achieve the specified motor speed (N-m).
  1130. @return Returns no value.
  1131. */
  1132. ConsoleMethodWithDocs(Scene, setWheelJointMotor, ConsoleVoid, 4, 6, (jointId, enableMotor, [motorSpeed], [maxMotorTorque]))
  1133. {
  1134. // Fetch joint Id.
  1135. const S32 jointId = dAtoi(argv[2]);
  1136. // Fetch args.
  1137. const bool enableMotor = dAtob(argv[3]);
  1138. const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  1139. const F32 maxMotorTorque = argc > 5 ? dAtof(argv[5]) : 0.0f;
  1140. // Access joint.
  1141. object->setWheelJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque );
  1142. }
  1143. //-----------------------------------------------------------------------------
  1144. /*! Gets whether the joint has a motor or not and the motor settings.
  1145. @param jointId The Id of the joint to use.
  1146. @return Returns whether the joint has a motor or not and the motor settings (empty string indicates error).
  1147. */
  1148. ConsoleMethodWithDocs(Scene, getWheelJointMotor, ConsoleString, 3, 3, (jointId))
  1149. {
  1150. // Fetch joint Id.
  1151. const S32 jointId = dAtoi(argv[2]);
  1152. // Args.
  1153. bool enableMotor;
  1154. F32 motorSpeed;
  1155. F32 maxMotorTorque;
  1156. // Access joint.
  1157. if ( !object->getWheelJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque ) )
  1158. {
  1159. return NULL;
  1160. }
  1161. // Format output.
  1162. char* pBuffer = Con::getReturnBuffer(64);
  1163. dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorTorque );
  1164. return pBuffer;
  1165. }
  1166. //-----------------------------------------------------------------------------
  1167. /*! Sets the mass-spring-damper frequency in Hertz.
  1168. @param jointId The Id of the joint to use.
  1169. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.
  1170. @return Returns no value.
  1171. */
  1172. ConsoleMethodWithDocs(Scene, setWheelJointFrequency, ConsoleVoid, 4, 4, (jointId, frequency))
  1173. {
  1174. // Fetch joint Id.
  1175. const S32 jointId = dAtoi(argv[2]);
  1176. // Fetch args.
  1177. const F32 frequency = dAtof(argv[3]);
  1178. // Access joint.
  1179. object->setWheelJointFrequency( jointId, frequency );
  1180. }
  1181. //-----------------------------------------------------------------------------
  1182. /*! Gets the mass-spring-damper frequency in Hertz.
  1183. @param jointId The Id of the joint to use.
  1184. @return Returns the mass-spring-damper frequency in Hertz (-1 indicates error).
  1185. */
  1186. ConsoleMethodWithDocs(Scene, getWheelJointFrequency, ConsoleFloat, 3, 3, (jointId))
  1187. {
  1188. // Fetch joint Id.
  1189. const S32 jointId = dAtoi(argv[2]);
  1190. // Access joint.
  1191. return object->getWheelJointFrequency( jointId );
  1192. }
  1193. //-----------------------------------------------------------------------------
  1194. /*! Sets the damping ratio.
  1195. @param jointId The Id of the joint to use.
  1196. @param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.
  1197. @return Returns no value.
  1198. */
  1199. ConsoleMethodWithDocs(Scene, setWheelJointDampingRatio, ConsoleVoid, 4, 4, (jointId, dampingRatio))
  1200. {
  1201. // Fetch joint Id.
  1202. const S32 jointId = dAtoi(argv[2]);
  1203. // Fetch args.
  1204. const F32 dampingRatio = dAtof(argv[3]);
  1205. // Access joint.
  1206. object->setWheelJointDampingRatio( jointId, dampingRatio );
  1207. }
  1208. //-----------------------------------------------------------------------------
  1209. /*! Gets the damping ratio.
  1210. @param jointId The Id of the joint to use.
  1211. @return Returns the damping ratio (-1 indicates error).
  1212. */
  1213. ConsoleMethodWithDocs(Scene, getWheelJointDampingRatio, ConsoleFloat, 3, 3, (jointId))
  1214. {
  1215. // Fetch joint Id.
  1216. const S32 jointId = dAtoi(argv[2]);
  1217. // Access joint.
  1218. return object->getWheelJointDampingRatio( jointId );
  1219. }
  1220. //-----------------------------------------------------------------------------
  1221. /*! Creates a friction joint.
  1222. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1223. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1224. @param localAnchorA The local point of the first scene object where the joint connects.
  1225. @param localAnchorB The local point of the second scene object where the joint connects.
  1226. @param maxForce The maximum friction force (N).
  1227. @param maxTorque The maximum torque force (N-m).
  1228. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  1229. @return The joint Id (-1 if error).
  1230. */
  1231. ConsoleMethodWithDocs(Scene, createFrictionJoint, ConsoleInt, 4, 11, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxForce], [maxTorque], [collideConnected]))
  1232. {
  1233. // Fetch scene object references.
  1234. const char* sceneObjectA = argv[2];
  1235. const char* sceneObjectB = argv[3];
  1236. SceneObject* pSceneObjectA = NULL;
  1237. SceneObject* pSceneObjectB = NULL;
  1238. // Fetch scene object.
  1239. if ( *sceneObjectA != 0 )
  1240. {
  1241. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1242. if ( !pSceneObjectA )
  1243. Con::warnf("Scene::createFrictionJoint() - Could not find scene object %d.", sceneObjectA);
  1244. }
  1245. // Fetch scene object.
  1246. if ( *sceneObjectB != 0 )
  1247. {
  1248. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1249. if ( !pSceneObjectB )
  1250. Con::warnf("Scene::createFrictionJoint() - Could not find scene object %d.", sceneObjectB);
  1251. }
  1252. if ( argc == 4 )
  1253. {
  1254. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB );
  1255. }
  1256. // Local anchor A.
  1257. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1258. b2Vec2 localAnchorA;
  1259. S32 nextArg = 5;
  1260. if ( anchorAElementCount == 1 && argc > 5 )
  1261. {
  1262. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1263. nextArg = 6;
  1264. }
  1265. else if ( anchorAElementCount == 2 )
  1266. {
  1267. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1268. }
  1269. // Invalid
  1270. else
  1271. {
  1272. Con::warnf("Scene::createFrictionJoint() - Invalid number of parameters!");
  1273. return -1;
  1274. }
  1275. if ( argc <= nextArg )
  1276. {
  1277. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  1278. }
  1279. // Local anchor B.
  1280. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1281. b2Vec2 localAnchorB;
  1282. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1283. {
  1284. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1285. nextArg += 2;
  1286. }
  1287. else if ( anchorBElementCount == 2 )
  1288. {
  1289. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1290. }
  1291. // Invalid
  1292. else
  1293. {
  1294. Con::warnf("Scene::createFrictionJoint() - Invalid number of parameters!");
  1295. return -1;
  1296. }
  1297. // Fetch maximum force.
  1298. const F32 maxForce = dAtof(argv[nextArg++]);
  1299. if ( argc <= nextArg )
  1300. {
  1301. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce );
  1302. }
  1303. // Fetch maximum torque.
  1304. const F32 maxTorque = dAtof(argv[nextArg++]);
  1305. if ( argc <= nextArg )
  1306. {
  1307. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce, maxTorque );
  1308. }
  1309. // Fetch collide connected.
  1310. const bool collideConnected = dAtob(argv[nextArg++]);
  1311. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce, maxTorque, collideConnected );
  1312. }
  1313. //-----------------------------------------------------------------------------
  1314. /*! Sets the maximum friction force.
  1315. @param jointId The Id of the joint to use.
  1316. @param maxForce The maximum friction force (N).
  1317. @return Returns no value.
  1318. */
  1319. ConsoleMethodWithDocs(Scene, setFrictionJointMaxForce, ConsoleVoid, 4, 4, (jointId, maxForce))
  1320. {
  1321. // Fetch joint Id.
  1322. const S32 jointId = dAtoi(argv[2]);
  1323. // Fetch args.
  1324. const F32 maxForce = dAtof(argv[3]);
  1325. // Access joint.
  1326. object->setFrictionJointMaxForce( jointId, maxForce );
  1327. }
  1328. //-----------------------------------------------------------------------------
  1329. /*! Sets the maximum friction force.
  1330. @param jointId The Id of the joint to use.
  1331. @return Returns the maximum friction force (-1 indicates error).
  1332. */
  1333. ConsoleMethodWithDocs(Scene, getFrictionJointMaxForce, ConsoleFloat, 3, 3, (jointId))
  1334. {
  1335. // Fetch joint Id.
  1336. const S32 jointId = dAtoi(argv[2]);
  1337. // Access joint.
  1338. return object->getFrictionJointMaxForce( jointId );
  1339. }
  1340. //-----------------------------------------------------------------------------
  1341. /*! Sets the maximum torque force.
  1342. @param jointId The Id of the joint to use.
  1343. @param maxTorque The maximum torque force (N).
  1344. @return Returns no value.
  1345. */
  1346. ConsoleMethodWithDocs(Scene, setFrictionJointMaxTorque, ConsoleVoid, 4, 4, (jointId, maxTorque))
  1347. {
  1348. // Fetch joint Id.
  1349. const S32 jointId = dAtoi(argv[2]);
  1350. // Fetch args.
  1351. const F32 maxTorque = dAtof(argv[3]);
  1352. // Access joint.
  1353. object->setFrictionJointMaxTorque( jointId, maxTorque );
  1354. }
  1355. //-----------------------------------------------------------------------------
  1356. /*! Gets the maximum torque force.
  1357. @param jointId The Id of the joint to use.
  1358. @return Returns the maximum torque force (-1 indicates error).
  1359. */
  1360. ConsoleMethodWithDocs(Scene, getFrictionJointMaxTorque, ConsoleFloat, 3, 3, (jointId))
  1361. {
  1362. // Fetch joint Id.
  1363. const S32 jointId = dAtoi(argv[2]);
  1364. // Access joint.
  1365. return object->getFrictionJointMaxTorque( jointId );
  1366. }
  1367. //-----------------------------------------------------------------------------
  1368. /*! Creates a prismatic joint.
  1369. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1370. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1371. @param localAnchorA The local point of the first scene object where the joint connects.
  1372. @param localAnchorB The local point of the second scene object where the joint connects.
  1373. @param worldAxis The world axis defining the translational degree of freedom.
  1374. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  1375. @return The joint Id (-1 if error).
  1376. */
  1377. ConsoleMethodWithDocs(Scene, createPrismaticJoint, ConsoleInt, 7, 11, (sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldAxis X/Y, [collideConnected]))
  1378. {
  1379. // Fetch scene object references.
  1380. const char* sceneObjectA = argv[2];
  1381. const char* sceneObjectB = argv[3];
  1382. SceneObject* pSceneObjectA = NULL;
  1383. SceneObject* pSceneObjectB = NULL;
  1384. // Fetch scene object.
  1385. if ( *sceneObjectA != 0 )
  1386. {
  1387. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1388. if ( !pSceneObjectA )
  1389. Con::warnf("Scene::createPrismaticJoint() - Could not find scene object %d.", sceneObjectA);
  1390. }
  1391. // Fetch scene object.
  1392. if ( *sceneObjectB != 0 )
  1393. {
  1394. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1395. if ( !pSceneObjectB )
  1396. Con::warnf("Scene::createPrismaticJoint() - Could not find scene object %d.", sceneObjectB);
  1397. }
  1398. // Local anchor A.
  1399. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1400. b2Vec2 localAnchorA;
  1401. S32 nextArg = 5;
  1402. if ( anchorAElementCount == 1 && argc > 5 )
  1403. {
  1404. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1405. nextArg = 6;
  1406. }
  1407. else if ( anchorAElementCount == 2 )
  1408. {
  1409. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1410. }
  1411. // Invalid
  1412. else
  1413. {
  1414. Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
  1415. return -1;
  1416. }
  1417. // Local anchor B.
  1418. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1419. b2Vec2 localAnchorB;
  1420. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1421. {
  1422. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1423. nextArg += 2;
  1424. }
  1425. else if ( anchorBElementCount == 2 )
  1426. {
  1427. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1428. }
  1429. // Invalid
  1430. else
  1431. {
  1432. Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
  1433. return -1;
  1434. }
  1435. // World axis.
  1436. const U32 worldAxisElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1437. b2Vec2 worldAxis;
  1438. if ( worldAxisElementCount == 1 && argc > (nextArg+1) )
  1439. {
  1440. worldAxis.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1441. nextArg += 2;
  1442. }
  1443. else if ( worldAxisElementCount == 2 )
  1444. {
  1445. worldAxis = Utility::mGetStringElementVector(argv[nextArg++]);
  1446. }
  1447. // Invalid
  1448. else
  1449. {
  1450. Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
  1451. return -1;
  1452. }
  1453. if ( argc <= nextArg )
  1454. {
  1455. return object->createPrismaticJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis );
  1456. }
  1457. // Fetch collide connected.
  1458. const bool collideConnected = dAtob(argv[nextArg++]);
  1459. return object->createPrismaticJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis, collideConnected );
  1460. }
  1461. //-----------------------------------------------------------------------------
  1462. /*! Sets whether the joint has translational limits or not and the limits themselves.
  1463. @param jointId The Id of the joint to use.
  1464. @param enableLimit Whether the joint has angular limits or not.
  1465. @param lowerTranslation The lower translation limit.
  1466. @param upperTranslation The upper translation limit.
  1467. @return Returns no value.
  1468. */
  1469. ConsoleMethodWithDocs(Scene, setPrismaticJointLimit, ConsoleVoid, 4, 6, (jointId, enableLimit, [lowerTranslation], [upperTranslation]))
  1470. {
  1471. // Fetch joint Id.
  1472. const S32 jointId = dAtoi(argv[2]);
  1473. // Fetch args.
  1474. const bool enableLimit = dAtob(argv[3]);
  1475. const F32 lowerTranslation = argc > 4 ? dAtof(argv[4]) : 0.0f;
  1476. const F32 upperTranslation = argc > 5 ? dAtof(argv[5]) : lowerTranslation;
  1477. // Access joint.
  1478. object->setPrismaticJointLimit( jointId, enableLimit, lowerTranslation, upperTranslation );
  1479. }
  1480. //-----------------------------------------------------------------------------
  1481. /*! Gets whether the joint has translational limits or not and the limits themselves.
  1482. @return Returns whether the joint has translational limits or not and the limits themselves (empty string indicates error).
  1483. */
  1484. ConsoleMethodWithDocs(Scene, getPrismaticJointLimit, ConsoleString, 3, 3, (jointId))
  1485. {
  1486. // Fetch joint Id.
  1487. const S32 jointId = dAtoi(argv[2]);
  1488. // Args.
  1489. bool enableLimit;
  1490. F32 lowerTranslation;
  1491. F32 upperTranslation;
  1492. // Access joint.
  1493. if ( !object->getPrismaticJointLimit( jointId, enableLimit, lowerTranslation, upperTranslation ) )
  1494. {
  1495. return NULL;
  1496. }
  1497. // Format output.
  1498. char* pBuffer = Con::getReturnBuffer(64);
  1499. dSprintf( pBuffer, 64, "%d %g %g", enableLimit, lowerTranslation, upperTranslation );
  1500. return pBuffer;
  1501. }
  1502. //-----------------------------------------------------------------------------
  1503. /*! Sets whether the joint has a motor or not and the motor settings.
  1504. @param jointId The Id of the joint to use.
  1505. @param enableMotor Whether the joint has a motor or not.
  1506. @param motorSpeed The motor speed (degrees per/sec).
  1507. @param maxMotorForce The maximum motor force used to achieve the specified motor speed (N-m).
  1508. @return Returns no value.
  1509. */
  1510. ConsoleMethodWithDocs(Scene, setPrismaticJointMotor, ConsoleVoid, 4, 6, (jointId, enableMotor, [motorSpeed], [maxMotorForce]))
  1511. {
  1512. // Fetch joint Id.
  1513. const S32 jointId = dAtoi(argv[2]);
  1514. // Fetch args.
  1515. const bool enableMotor = dAtob(argv[3]);
  1516. const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  1517. const F32 maxMotorForce = argc > 5 ? dAtof(argv[5]) : 0.0f;
  1518. // Access joint.
  1519. object->setPrismaticJointMotor( jointId, enableMotor, motorSpeed, maxMotorForce );
  1520. }
  1521. //-----------------------------------------------------------------------------
  1522. /*! Gets whether the joint has a motor or not and the motor settings.
  1523. @return Returns whether the joint has a motor or not and the motor settings (empty string indicates error).
  1524. */
  1525. ConsoleMethodWithDocs(Scene, getPrismaticJointMotor, ConsoleString, 3, 3, (jointId))
  1526. {
  1527. // Fetch joint Id.
  1528. const S32 jointId = dAtoi(argv[2]);
  1529. // Args.
  1530. bool enableMotor;
  1531. F32 motorSpeed;
  1532. F32 maxMotorForce;
  1533. // Access joint.
  1534. if ( !object->getPrismaticJointMotor( jointId, enableMotor, motorSpeed, maxMotorForce ) )
  1535. {
  1536. return NULL;
  1537. }
  1538. // Format output.
  1539. char* pBuffer = Con::getReturnBuffer(64);
  1540. dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorForce );
  1541. return pBuffer;
  1542. }
  1543. //-----------------------------------------------------------------------------
  1544. /*! Creates a pulley joint.
  1545. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1546. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1547. @param localAnchorA The local point of the first scene object where the joint connects.
  1548. @param localAnchorB The local point of the second scene object where the joint connects.
  1549. @param worldGroundAnchorA The world point of the first ground anchor. This point never moves.
  1550. @param worldGroundAnchorB The world point of the second ground anchor. This point never moves.
  1551. @param ratio The pulley ratio used to simulate a block-and-tackle pulley.
  1552. @param lengthA The reference pulley length for the segment attached to scene object A. Defaults to the distance between the first scene object and the first ground anchor.
  1553. @param lengthB The reference pulley length for the segment attached to scene object B. Defaults to the distance between the second scene object and the second ground anchor.
  1554. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  1555. @return The joint Id (-1 if error).
  1556. */
  1557. ConsoleMethodWithDocs(Scene, createPulleyJoint, ConsoleInt, 9, 16, (sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldGroundAnchorA X/Y, worldGroundAnchorB X/Y, ratio, [lengthA], [lengthB], [collideConnected]))
  1558. {
  1559. // Fetch scene object references.
  1560. const char* sceneObjectA = argv[2];
  1561. const char* sceneObjectB = argv[3];
  1562. SceneObject* pSceneObjectA = NULL;
  1563. SceneObject* pSceneObjectB = NULL;
  1564. // Fetch scene object.
  1565. if ( *sceneObjectA != 0 )
  1566. {
  1567. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1568. if ( !pSceneObjectA )
  1569. Con::warnf("Scene::createPulleyJoint() - Could not find scene object %d.", sceneObjectA);
  1570. }
  1571. // Fetch scene object.
  1572. if ( *sceneObjectB != 0 )
  1573. {
  1574. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1575. if ( !pSceneObjectB )
  1576. Con::warnf("Scene::createPulleyJoint() - Could not find scene object %d.", sceneObjectB);
  1577. }
  1578. // Local anchor A.
  1579. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1580. b2Vec2 localAnchorA;
  1581. S32 nextArg = 5;
  1582. if ( anchorAElementCount == 1 && argc > 5 )
  1583. {
  1584. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1585. nextArg = 6;
  1586. }
  1587. else if ( anchorAElementCount == 2 )
  1588. {
  1589. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1590. }
  1591. // Invalid
  1592. else
  1593. {
  1594. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1595. return -1;
  1596. }
  1597. // Local anchor B.
  1598. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1599. b2Vec2 localAnchorB;
  1600. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1601. {
  1602. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1603. nextArg += 2;
  1604. }
  1605. else if ( anchorBElementCount == 2 )
  1606. {
  1607. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1608. }
  1609. // Invalid
  1610. else
  1611. {
  1612. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1613. return -1;
  1614. }
  1615. // World ground anchor A.
  1616. const U32 worldGroundAnchorAElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1617. b2Vec2 worldGroundAnchorA;
  1618. if ( worldGroundAnchorAElementCount == 1 && argc > (nextArg+1) )
  1619. {
  1620. worldGroundAnchorA.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1621. nextArg += 2;
  1622. }
  1623. else if ( worldGroundAnchorAElementCount == 2 )
  1624. {
  1625. worldGroundAnchorA = Utility::mGetStringElementVector(argv[nextArg++]);
  1626. }
  1627. // Invalid
  1628. else
  1629. {
  1630. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1631. return -1;
  1632. }
  1633. // World ground anchor B.
  1634. const U32 worldGroundAnchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1635. b2Vec2 worldGroundAnchorB;
  1636. if ( worldGroundAnchorBElementCount == 1 && argc > (nextArg+1) )
  1637. {
  1638. worldGroundAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1639. nextArg += 2;
  1640. }
  1641. else if ( worldGroundAnchorBElementCount == 2 )
  1642. {
  1643. worldGroundAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1644. }
  1645. // Invalid
  1646. else
  1647. {
  1648. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1649. return -1;
  1650. }
  1651. // Fetch maximum ratio.
  1652. const F32 ratio = dAtof(argv[nextArg++]);
  1653. if ( argc <= nextArg )
  1654. {
  1655. return object->createPulleyJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldGroundAnchorA, worldGroundAnchorB, ratio );
  1656. }
  1657. // Fetch collide connected.
  1658. const bool collideConnected = dAtob(argv[nextArg++]);
  1659. return object->createPulleyJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldGroundAnchorA, worldGroundAnchorB, ratio, collideConnected );
  1660. }
  1661. //-----------------------------------------------------------------------------
  1662. /*! Creates a target joint.
  1663. @param sceneObject The scene object to connect to the joint.
  1664. @param worldTarget The world point target to move the scene object to.
  1665. @param maxForce The maximum force the joint should use to position the scene object at the target.
  1666. @param useCenterOfMass Whether to use the center of mass as the point which the joint is attached or not. Defaults to false.
  1667. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default=0.7).
  1668. @param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.
  1669. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  1670. @return The joint Id (-1 if error).
  1671. */
  1672. ConsoleMethodWithDocs(Scene, createTargetJoint, ConsoleInt, 5, 10, (sceneObject, worldTarget X/Y, maxForce, [useCenterOfMass?], [frequency], [dampingRatio], [collideConnected]))
  1673. {
  1674. // Fetch scene object.
  1675. SceneObject* pSceneObject = Sim::findObject<SceneObject>(argv[2]);
  1676. // Check scene object.
  1677. if ( !pSceneObject )
  1678. {
  1679. Con::warnf("Scene::createTargetJoint() - Could not find scene object %d.", argv[2]);
  1680. return -1;
  1681. }
  1682. // World target.
  1683. const U32 worldTargetElementCount = Utility::mGetStringElementCount(argv[3]);
  1684. b2Vec2 worldTarget;
  1685. S32 nextArg = 4;
  1686. if ( worldTargetElementCount == 1 && argc > 5 )
  1687. {
  1688. worldTarget.Set( dAtof(argv[3]), dAtof(argv[4]) );
  1689. nextArg = 5;
  1690. }
  1691. else if ( worldTargetElementCount == 2 )
  1692. {
  1693. worldTarget = Utility::mGetStringElementVector(argv[3]);
  1694. }
  1695. // Invalid
  1696. else
  1697. {
  1698. Con::warnf("Scene::createTargetJoint() - Invalid number of parameters!");
  1699. return -1;
  1700. }
  1701. // Fetch maximum force.
  1702. const F32 maxForce = dAtof(argv[nextArg++]);
  1703. if ( argc <= nextArg )
  1704. {
  1705. return object->createTargetJoint( pSceneObject, worldTarget, maxForce );
  1706. }
  1707. // Fetch the center-of-mass flag.
  1708. const bool centerOfMass = dAtob(argv[nextArg++]);
  1709. if ( argc <= nextArg )
  1710. {
  1711. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, centerOfMass );
  1712. }
  1713. // Fetch frequency (Hertz).
  1714. const F32 frequency = dAtof(argv[nextArg++]);
  1715. if ( argc <= nextArg )
  1716. {
  1717. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, centerOfMass, frequency );
  1718. }
  1719. // Fetch damping ratio.
  1720. const F32 dampingRatio = dAtof(argv[nextArg++]);
  1721. if ( argc <= nextArg )
  1722. {
  1723. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, centerOfMass, frequency, dampingRatio );
  1724. }
  1725. // Fetch collide connected.
  1726. const bool collideConnected = dAtob(argv[nextArg++]);
  1727. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, centerOfMass, frequency, dampingRatio, collideConnected );
  1728. }
  1729. //-----------------------------------------------------------------------------
  1730. /*! Sets the target world point for the scene object.
  1731. @param jointId The Id of the joint to use.
  1732. @param worldTarget The target world point to move the scene object to.
  1733. @return Returns no value.
  1734. */
  1735. ConsoleMethodWithDocs(Scene, setTargetJointTarget, ConsoleVoid, 4, 5, (jointId, worldTarget X/Y))
  1736. {
  1737. // Fetch joint Id.
  1738. const S32 jointId = dAtoi(argv[2]);
  1739. // World target.
  1740. const U32 worldTargetElementCount = Utility::mGetStringElementCount(argv[3]);
  1741. b2Vec2 worldTarget;
  1742. if ( worldTargetElementCount == 1 && argc > 5 )
  1743. {
  1744. worldTarget.Set( dAtof(argv[3]), dAtof(argv[4]) );
  1745. }
  1746. else if ( worldTargetElementCount == 2 )
  1747. {
  1748. worldTarget = Utility::mGetStringElementVector(argv[3]);
  1749. }
  1750. // Invalid
  1751. else
  1752. {
  1753. Con::warnf("Scene::setTargetJointTarget() - Invalid number of parameters!");
  1754. }
  1755. // Access joint.
  1756. object->setTargetJointTarget( jointId, worldTarget );
  1757. }
  1758. //-----------------------------------------------------------------------------
  1759. /*! Gets the target world point for the scene object.
  1760. @param jointId The Id of the joint to use.
  1761. @return Returns the target world point for the scene object (always 0,0 if error).
  1762. */
  1763. ConsoleMethodWithDocs(Scene, getTargetJointTarget, ConsoleString, 3, 3, (jointId))
  1764. {
  1765. // Fetch joint Id.
  1766. const S32 jointId = dAtoi(argv[2]);
  1767. // Access joint.
  1768. const Vector2 worldTarget = object->getTargetJointTarget( jointId );
  1769. return worldTarget.scriptThis();
  1770. }
  1771. //-----------------------------------------------------------------------------
  1772. /*! Sets the mass-spring-damper frequency in Hertz.
  1773. @param jointId The Id of the joint to use.
  1774. @param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.
  1775. @return Returns no value.
  1776. */
  1777. ConsoleMethodWithDocs(Scene, setTargetJointFrequency, ConsoleVoid, 4, 4, (jointId, frequency))
  1778. {
  1779. // Fetch joint Id.
  1780. const S32 jointId = dAtoi(argv[2]);
  1781. // Fetch args.
  1782. const F32 frequency = dAtof(argv[3]);
  1783. // Access joint.
  1784. object->setTargetJointFrequency( jointId, frequency );
  1785. }
  1786. //-----------------------------------------------------------------------------
  1787. /*! Gets the mass-spring-damper frequency in Hertz.
  1788. @param jointId The Id of the joint to use.
  1789. @return Returns the mass-spring-damper frequency in Hertz (-1 indicates error).
  1790. */
  1791. ConsoleMethodWithDocs(Scene, getTargetJointFrequency, ConsoleFloat, 3, 3, (jointId))
  1792. {
  1793. // Fetch joint Id.
  1794. const S32 jointId = dAtoi(argv[2]);
  1795. // Access joint.
  1796. return object->getTargetJointFrequency( jointId );
  1797. }
  1798. //-----------------------------------------------------------------------------
  1799. /*! Sets the damping ratio.
  1800. @param jointId The Id of the joint to use.
  1801. @param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.
  1802. @return Returns no value.
  1803. */
  1804. ConsoleMethodWithDocs(Scene, setTargetJointDampingRatio, ConsoleVoid, 4, 4, (jointId, dampingRatio))
  1805. {
  1806. // Fetch joint Id.
  1807. const S32 jointId = dAtoi(argv[2]);
  1808. // Fetch args.
  1809. const F32 dampingRatio = dAtof(argv[3]);
  1810. // Access joint.
  1811. object->setTargetJointDampingRatio( jointId, dampingRatio );
  1812. }
  1813. //-----------------------------------------------------------------------------
  1814. /*! Sets the damping ratio.
  1815. @param jointId The Id of the joint to use.
  1816. @return Returns the damping ratio (-1 indicates error).
  1817. */
  1818. ConsoleMethodWithDocs(Scene, getTargetJointDampingRatio, ConsoleFloat, 3, 3, (jointId))
  1819. {
  1820. // Fetch joint Id.
  1821. const S32 jointId = dAtoi(argv[2]);
  1822. // Access joint.
  1823. return object->getTargetJointDampingRatio( jointId );
  1824. }
  1825. //-----------------------------------------------------------------------------
  1826. /*! Creates a motor joint.
  1827. @param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1828. @param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
  1829. @param linearOffsetX/Y The linear offset in sceneObjectA space.
  1830. @param angularOffset The angularOffset between the bodies.
  1831. @param maxForce The maximum friction force (N).
  1832. @param maxTorque The maximum torque force (N-m).
  1833. @param correctionFactor The correction factor (tolerance).
  1834. @param collideConnected Whether the scene objects can collide with each other while connected with this joint.
  1835. @return The joint Id (-1 if error).
  1836. */
  1837. ConsoleMethodWithDocs(Scene, createMotorJoint, ConsoleInt, 4, 11, (sceneObjectA, sceneObjectB, [linearOffset X/Y], [angularOffset], [maxForce], [maxTorque], [correctionFactor], [collideConnected]))
  1838. {
  1839. // Fetch scene object references.
  1840. const char* sceneObjectA = argv[2];
  1841. const char* sceneObjectB = argv[3];
  1842. SceneObject* pSceneObjectA = NULL;
  1843. SceneObject* pSceneObjectB = NULL;
  1844. // Fetch scene object.
  1845. if ( *sceneObjectA != 0 )
  1846. {
  1847. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1848. if ( !pSceneObjectA )
  1849. Con::warnf("Scene::createMotorJoint() - Could not find scene object %d.", sceneObjectA);
  1850. }
  1851. // Fetch scene object.
  1852. if ( *sceneObjectB != 0 )
  1853. {
  1854. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1855. if ( !pSceneObjectB )
  1856. Con::warnf("Scene::createMotorJoint() - Could not find scene object %d.", sceneObjectB);
  1857. }
  1858. if ( argc == 4 )
  1859. {
  1860. return object->createMotorJoint( pSceneObjectA, pSceneObjectB );
  1861. }
  1862. // Linear offset.
  1863. const U32 linearOffsetElementCount = Utility::mGetStringElementCount(argv[4]);
  1864. b2Vec2 linearOffset;
  1865. S32 nextArg = 5;
  1866. if ( linearOffsetElementCount == 1 && argc > 5 )
  1867. {
  1868. linearOffset.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1869. nextArg = 6;
  1870. }
  1871. else if ( linearOffsetElementCount == 2 )
  1872. {
  1873. linearOffset = Utility::mGetStringElementVector(argv[4]);
  1874. }
  1875. // Invalid
  1876. else
  1877. {
  1878. Con::warnf("Scene::createMotorJoint() - Invalid number of parameters!");
  1879. return -1;
  1880. }
  1881. if ( argc <= nextArg )
  1882. {
  1883. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset );
  1884. }
  1885. // Fetch angular offset.
  1886. const F32 angularOffset = mDegToRad( dAtof(argv[nextArg++]) );
  1887. if ( argc <= nextArg )
  1888. {
  1889. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset );
  1890. }
  1891. // Fetch maximum force.
  1892. const F32 maxForce = dAtof(argv[nextArg++]);
  1893. if ( argc <= nextArg )
  1894. {
  1895. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce );
  1896. }
  1897. // Fetch maximum torque.
  1898. const F32 maxTorque = dAtof(argv[nextArg++]);
  1899. if ( argc <= nextArg )
  1900. {
  1901. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce, maxTorque );
  1902. }
  1903. // Fetch collide connected.
  1904. const bool collideConnected = dAtob(argv[nextArg++]);
  1905. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce, maxTorque, collideConnected );
  1906. }
  1907. //-----------------------------------------------------------------------------
  1908. /*! Sets the linear offset in sceneObjectA space.
  1909. @param jointId The Id of the joint to use.
  1910. @param linearOffsetX/Y The linear offset in sceneObjectA space.
  1911. @return Returns no value.
  1912. */
  1913. ConsoleMethodWithDocs(Scene, setMotorJointLinearOffset, ConsoleVoid, 4, 5, (jointId, linearOffset X/Y))
  1914. {
  1915. // Fetch joint Id.
  1916. const S32 jointId = dAtoi(argv[2]);
  1917. // Linear offset.
  1918. const U32 linearOffsetElementCount = Utility::mGetStringElementCount(argv[3]);
  1919. b2Vec2 linearOffset;
  1920. if ( linearOffsetElementCount == 1 && argc > 5 )
  1921. {
  1922. linearOffset.Set( dAtof(argv[3]), dAtof(argv[4]) );
  1923. }
  1924. else if ( linearOffsetElementCount == 2 )
  1925. {
  1926. linearOffset = Utility::mGetStringElementVector(argv[3]);
  1927. }
  1928. // Invalid
  1929. else
  1930. {
  1931. Con::warnf("Scene::setMotorJointLinearOffset() - Invalid number of parameters!");
  1932. }
  1933. // Access joint.
  1934. object->setMotorJointLinearOffset( jointId, linearOffset );
  1935. }
  1936. //-----------------------------------------------------------------------------
  1937. /*! Gets the linear offset in sceneObjectA space.
  1938. @param jointId The Id of the joint to use.
  1939. @return Returns the linear offset in sceneObjectA space (always 0,0 if error).
  1940. */
  1941. ConsoleMethodWithDocs(Scene, getMotorJointLinearOffset, ConsoleString, 3, 3, (jointId))
  1942. {
  1943. // Fetch joint Id.
  1944. const S32 jointId = dAtoi(argv[2]);
  1945. // Access joint.
  1946. const Vector2 linearOffset = object->getMotorJointLinearOffset( jointId );
  1947. return linearOffset.scriptThis();
  1948. }
  1949. //-----------------------------------------------------------------------------
  1950. /*! Sets the angularOffset between the bodies.
  1951. @param jointId The Id of the joint to use.
  1952. @param angularOffset The angularOffset between the bodies.
  1953. @return Returns no value.
  1954. */
  1955. ConsoleMethodWithDocs(Scene, setMotorJointAngularOffset, ConsoleVoid, 4, 4, (jointId, angularOffset))
  1956. {
  1957. // Fetch joint Id.
  1958. const S32 jointId = dAtoi(argv[2]);
  1959. // Fetch args.
  1960. const F32 angularOffset = mDegToRad(dAtof(argv[3]));
  1961. // Access joint.
  1962. object->setMotorJointAngularOffset( jointId, angularOffset );
  1963. }
  1964. //-----------------------------------------------------------------------------
  1965. /*! Gets angularOffset between the bodies.
  1966. @param jointId The Id of the joint to use.
  1967. @return Returns the angularOffset between the bodies (-1 indicates error).
  1968. */
  1969. ConsoleMethodWithDocs(Scene, getMotorJointAngularOffset, ConsoleFloat, 3, 3, (jointId))
  1970. {
  1971. // Fetch joint Id.
  1972. const S32 jointId = dAtoi(argv[2]);
  1973. // Access joint.
  1974. return mRadToDeg( object->getMotorJointAngularOffset( jointId ) );
  1975. }
  1976. //-----------------------------------------------------------------------------
  1977. /*! Sets the maximum motor force.
  1978. @param jointId The Id of the joint to use.
  1979. @param maxForce The maximum motor force (N).
  1980. @return Returns no value.
  1981. */
  1982. ConsoleMethodWithDocs(Scene, setMotorJointMaxForce, ConsoleVoid, 4, 4, (jointId, maxForce))
  1983. {
  1984. // Fetch joint Id.
  1985. const S32 jointId = dAtoi(argv[2]);
  1986. // Fetch args.
  1987. const F32 maxForce = dAtof(argv[3]);
  1988. // Access joint.
  1989. object->setMotorJointMaxForce( jointId, maxForce );
  1990. }
  1991. //-----------------------------------------------------------------------------
  1992. /*! Sets the maximum motor force.
  1993. @param jointId The Id of the joint to use.
  1994. @return Returns the maximum motor force (-1 indicates error).
  1995. */
  1996. ConsoleMethodWithDocs(Scene, getMotorJointMaxForce, ConsoleFloat, 3, 3, (jointId))
  1997. {
  1998. // Fetch joint Id.
  1999. const S32 jointId = dAtoi(argv[2]);
  2000. // Access joint.
  2001. return object->getMotorJointMaxForce( jointId );
  2002. }
  2003. //-----------------------------------------------------------------------------
  2004. /*! Sets the maximum motor torque force.
  2005. @param jointId The Id of the joint to use.
  2006. @param maxTorque The maximum motor torque force (N).
  2007. @return Returns no value.
  2008. */
  2009. ConsoleMethodWithDocs(Scene, setMotorJointMaxTorque, ConsoleVoid, 4, 4, (jointId, maxTorque))
  2010. {
  2011. // Fetch joint Id.
  2012. const S32 jointId = dAtoi(argv[2]);
  2013. // Fetch args.
  2014. const F32 maxTorque = dAtof(argv[3]);
  2015. // Access joint.
  2016. object->setMotorJointMaxTorque( jointId, maxTorque );
  2017. }
  2018. //-----------------------------------------------------------------------------
  2019. /*! Gets the maximum motor torque force.
  2020. @param jointId The Id of the joint to use.
  2021. @return Returns the maximum motor torque force (-1 indicates error).
  2022. */
  2023. ConsoleMethodWithDocs(Scene, getMotorJointMaxTorque, ConsoleFloat, 3, 3, (jointId))
  2024. {
  2025. // Fetch joint Id.
  2026. const S32 jointId = dAtoi(argv[2]);
  2027. // Access joint.
  2028. return object->getMotorJointMaxTorque( jointId );
  2029. }
  2030. //-----------------------------------------------------------------------------
  2031. /*! Picks objects intersecting the specified area with optional group/layer masks.
  2032. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  2033. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  2034. @param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.
  2035. @param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.
  2036. @param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'oobb').
  2037. @return Returns list of object IDs.
  2038. */
  2039. ConsoleMethodWithDocs(Scene, pickArea, ConsoleString, 4, 9, (startx/y, endx/y, [sceneGroupMask], [sceneLayerMask], [pickMode] ))
  2040. {
  2041. // Upper left and lower right bound.
  2042. Vector2 v1, v2;
  2043. // The index of the first optional parameter.
  2044. U32 firstArg;
  2045. // Grab the number of elements in the first two parameters.
  2046. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  2047. U32 elementCount2 = 1;
  2048. if (argc > 3)
  2049. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  2050. // ("x1 y1 x2 y2")
  2051. if ((elementCount1 == 4) && (argc < 9))
  2052. {
  2053. v1 = Utility::mGetStringElementVector(argv[2]);
  2054. v2 = Utility::mGetStringElementVector(argv[2], 2);
  2055. firstArg = 3;
  2056. }
  2057. // ("x1 y1", "x2 y2")
  2058. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  2059. {
  2060. v1 = Utility::mGetStringElementVector(argv[2]);
  2061. v2 = Utility::mGetStringElementVector(argv[3]);
  2062. firstArg = 4;
  2063. }
  2064. // (x1, y1, x2, y2)
  2065. else if (argc > 5)
  2066. {
  2067. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2068. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  2069. firstArg = 6;
  2070. }
  2071. // Invalid
  2072. else
  2073. {
  2074. Con::warnf("Scene::pickArea() - Invalid number of parameters!");
  2075. return NULL;
  2076. }
  2077. // Calculate scene group mask.
  2078. U32 sceneGroupMask = MASK_ALL;
  2079. if ( (U32)argc > firstArg )
  2080. {
  2081. if ( *argv[firstArg] != 0 )
  2082. sceneGroupMask = dAtoi(argv[firstArg]);
  2083. }
  2084. // Calculate scene layer mask.
  2085. U32 sceneLayerMask = MASK_ALL;
  2086. if ( (U32)argc > (firstArg + 1) )
  2087. {
  2088. if ( *argv[firstArg + 1] != 0 )
  2089. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2090. }
  2091. // Calculate pick mode.
  2092. Scene::PickMode pickMode = Scene::PICK_OOBB;
  2093. if ( (U32)argc > (firstArg + 2))
  2094. {
  2095. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  2096. }
  2097. if ( pickMode == Scene::PICK_INVALID )
  2098. {
  2099. Con::warnf("Scene::pickArea() - Invalid pick mode of %s", argv[firstArg + 2]);
  2100. pickMode = Scene::PICK_OOBB;
  2101. }
  2102. // Fetch world query and clear results.
  2103. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2104. // Set filter.
  2105. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2106. pWorldQuery->setQueryFilter( queryFilter );
  2107. // Calculate normalized AABB.
  2108. b2AABB aabb;
  2109. aabb.lowerBound.x = getMin( v1.x, v2.x );
  2110. aabb.lowerBound.y = getMin( v1.y, v2.y );
  2111. aabb.upperBound.x = getMax( v1.x, v2.x );
  2112. aabb.upperBound.y = getMax( v1.y, v2.y );
  2113. // Perform query.
  2114. if ( pickMode == Scene::PICK_ANY )
  2115. {
  2116. pWorldQuery->anyQueryAABB( aabb );
  2117. }
  2118. else if ( pickMode == Scene::PICK_AABB )
  2119. {
  2120. pWorldQuery->aabbQueryAABB( aabb );
  2121. }
  2122. else if ( pickMode == Scene::PICK_OOBB )
  2123. {
  2124. pWorldQuery->oobbQueryAABB( aabb );
  2125. }
  2126. else if ( pickMode == Scene::PICK_COLLISION )
  2127. {
  2128. pWorldQuery->collisionQueryAABB( aabb );
  2129. }
  2130. else
  2131. {
  2132. AssertFatal( false, "Unsupported pick mode." );
  2133. }
  2134. // Fetch result count.
  2135. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2136. // Finish if no results.
  2137. if ( resultCount == 0 )
  2138. return NULL;
  2139. // Fetch results.
  2140. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2141. // Set Max Buffer Size.
  2142. const U32 maxBufferSize = 4096;
  2143. // Create Returnable Buffer.
  2144. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2145. // Set Buffer Counter.
  2146. U32 bufferCount = 0;
  2147. // Add picked objects.
  2148. for ( U32 n = 0; n < resultCount; n++ )
  2149. {
  2150. // Output Object ID.
  2151. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  2152. // Finish early if we run out of buffer space.
  2153. if ( bufferCount >= maxBufferSize )
  2154. {
  2155. // Warn.
  2156. Con::warnf("Scene::pickArea() - Too many items picked to return to scripts!");
  2157. break;
  2158. }
  2159. }
  2160. // Clear world query.
  2161. pWorldQuery->clearQuery();
  2162. // Return buffer.
  2163. return pBuffer;
  2164. }
  2165. //-----------------------------------------------------------------------------
  2166. /*! Picks objects intersecting the specified ray with optional group/layer masks.
  2167. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  2168. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  2169. @param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.
  2170. @param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.
  2171. @param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'oobb').
  2172. @return Returns list of object IDs.
  2173. */
  2174. ConsoleMethodWithDocs(Scene, pickRay, ConsoleString, 4, 9, (startx/y, endx/y, [sceneGroupMask], [sceneLayerMask], [pickMode] ))
  2175. {
  2176. // Upper left and lower right bound.
  2177. Vector2 v1, v2;
  2178. // The index of the first optional parameter.
  2179. U32 firstArg;
  2180. // Grab the number of elements in the first two parameters.
  2181. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  2182. U32 elementCount2 = 1;
  2183. if (argc > 3)
  2184. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  2185. // ("x1 y1 x2 y2")
  2186. if ((elementCount1 == 4) && (argc < 9))
  2187. {
  2188. v1 = Utility::mGetStringElementVector(argv[2]);
  2189. v2 = Utility::mGetStringElementVector(argv[2], 2);
  2190. firstArg = 3;
  2191. }
  2192. // ("x1 y1", "x2 y2")
  2193. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  2194. {
  2195. v1 = Utility::mGetStringElementVector(argv[2]);
  2196. v2 = Utility::mGetStringElementVector(argv[3]);
  2197. firstArg = 4;
  2198. }
  2199. // (x1, y1, x2, y2)
  2200. else if (argc > 5)
  2201. {
  2202. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2203. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  2204. firstArg = 6;
  2205. }
  2206. // Invalid
  2207. else
  2208. {
  2209. Con::warnf("Scene::pickRay() - Invalid number of parameters!");
  2210. return NULL;
  2211. }
  2212. // Calculate scene group mask.
  2213. U32 sceneGroupMask = MASK_ALL;
  2214. if ( (U32)argc > firstArg )
  2215. {
  2216. if ( *argv[firstArg] != 0 )
  2217. sceneGroupMask = dAtoi(argv[firstArg]);
  2218. }
  2219. // Calculate scene layer mask.
  2220. U32 sceneLayerMask = MASK_ALL;
  2221. if ( (U32)argc > (firstArg + 1) )
  2222. {
  2223. if ( *argv[firstArg + 1] != 0 )
  2224. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2225. }
  2226. // Calculate pick mode.
  2227. Scene::PickMode pickMode = Scene::PICK_OOBB;
  2228. if ( (U32)argc > (firstArg + 2))
  2229. {
  2230. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  2231. }
  2232. if ( pickMode == Scene::PICK_INVALID )
  2233. {
  2234. Con::warnf("Scene::pickRay() - Invalid pick mode of %s", argv[firstArg + 2]);
  2235. pickMode = Scene::PICK_OOBB;
  2236. }
  2237. // Fetch world query and clear results.
  2238. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2239. // Set filter.
  2240. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2241. pWorldQuery->setQueryFilter( queryFilter );
  2242. // Perform query.
  2243. if ( pickMode == Scene::PICK_ANY )
  2244. {
  2245. pWorldQuery->anyQueryRay( v1, v2 );
  2246. }
  2247. else if ( pickMode == Scene::PICK_AABB )
  2248. {
  2249. pWorldQuery->aabbQueryRay( v1, v2 );
  2250. }
  2251. else if ( pickMode == Scene::PICK_OOBB )
  2252. {
  2253. pWorldQuery->oobbQueryRay( v1, v2 );
  2254. }
  2255. else if ( pickMode == Scene::PICK_COLLISION )
  2256. {
  2257. pWorldQuery->collisionQueryRay( v1, v2 );
  2258. }
  2259. else
  2260. {
  2261. AssertFatal( false, "Unsupported pick mode." );
  2262. }
  2263. // Sanity!
  2264. AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  2265. // Fetch result count.
  2266. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2267. // Finish if no results.
  2268. if ( resultCount == 0 )
  2269. return NULL;
  2270. // Sort ray-cast result.
  2271. pWorldQuery->sortRaycastQueryResult();
  2272. // Fetch results.
  2273. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2274. // Set Max Buffer Size.
  2275. const U32 maxBufferSize = 4096;
  2276. // Create Returnable Buffer.
  2277. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2278. // Set Buffer Counter.
  2279. U32 bufferCount = 0;
  2280. // Add Picked Objects to List.
  2281. for ( U32 n = 0; n < resultCount; n++ )
  2282. {
  2283. // Output Object ID.
  2284. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  2285. // Finish early if we run out of buffer space.
  2286. if ( bufferCount >= maxBufferSize )
  2287. {
  2288. // Warn.
  2289. Con::warnf("Scene::pickRay() - Too many items picked to return to scripts!");
  2290. break;
  2291. }
  2292. }
  2293. // Clear world query.
  2294. pWorldQuery->clearQuery();
  2295. // Return buffer.
  2296. return pBuffer;
  2297. }
  2298. //-----------------------------------------------------------------------------
  2299. /*! Picks objects intersecting the specified point with optional group/layer masks.
  2300. @param x/y The coordinate of the point as either (\x y\ or (x,y)
  2301. @param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.
  2302. @param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.
  2303. @param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'ooabb').
  2304. @return Returns list of object IDs.
  2305. */
  2306. ConsoleMethodWithDocs(Scene, pickPoint, ConsoleString, 3, 7, (x / y, [sceneGroupMask], [sceneLayerMask], [pickMode] ))
  2307. {
  2308. // The point.
  2309. Vector2 point;
  2310. // The index of the first optional parameter.
  2311. U32 firstArg;
  2312. // Grab the number of elements in the first parameter.
  2313. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2314. // ("x y")
  2315. if ((elementCount == 2) && (argc < 8))
  2316. {
  2317. point = Utility::mGetStringElementVector(argv[2]);
  2318. firstArg = 3;
  2319. }
  2320. // (x, y)
  2321. else if ((elementCount == 1) && (argc > 3))
  2322. {
  2323. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2324. firstArg = 4;
  2325. }
  2326. // Invalid
  2327. else
  2328. {
  2329. Con::warnf("Scene::pickPoint() - Invalid number of parameters!");
  2330. return NULL;
  2331. }
  2332. // Calculate scene group mask.
  2333. U32 sceneGroupMask = MASK_ALL;
  2334. if ( (U32)argc > firstArg )
  2335. {
  2336. if ( *argv[firstArg] != 0 )
  2337. sceneGroupMask = dAtoi(argv[firstArg]);
  2338. }
  2339. // Calculate scene layer mask.
  2340. U32 sceneLayerMask = MASK_ALL;
  2341. if ( (U32)argc > (firstArg + 1) )
  2342. {
  2343. if ( *argv[firstArg + 1] != 0 )
  2344. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2345. }
  2346. // Calculate pick mode.
  2347. Scene::PickMode pickMode = Scene::PICK_OOBB;
  2348. if ( (U32)argc > (firstArg + 2 ))
  2349. {
  2350. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  2351. }
  2352. if ( pickMode == Scene::PICK_INVALID )
  2353. {
  2354. Con::warnf("Scene::pickPoint() - Invalid pick mode of %s", argv[firstArg + 2]);
  2355. pickMode = Scene::PICK_OOBB;
  2356. }
  2357. // Fetch world query and clear results.
  2358. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2359. // Set filter.
  2360. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2361. pWorldQuery->setQueryFilter( queryFilter );
  2362. // Perform query.
  2363. if ( pickMode == Scene::PICK_ANY )
  2364. {
  2365. pWorldQuery->anyQueryPoint( point );
  2366. }
  2367. else if ( pickMode == Scene::PICK_AABB )
  2368. {
  2369. pWorldQuery->aabbQueryPoint( point );
  2370. }
  2371. else if ( pickMode == Scene::PICK_OOBB )
  2372. {
  2373. pWorldQuery->oobbQueryPoint( point );
  2374. }
  2375. else if ( pickMode == Scene::PICK_COLLISION )
  2376. {
  2377. pWorldQuery->collisionQueryPoint( point );
  2378. }
  2379. else
  2380. {
  2381. AssertFatal( false, "Unsupported pick mode." );
  2382. }
  2383. // Fetch result count.
  2384. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2385. // Finish if no results.
  2386. if ( resultCount == 0 )
  2387. return NULL;
  2388. // Fetch results.
  2389. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2390. // Set Max Buffer Size.
  2391. const U32 maxBufferSize = 4096;
  2392. // Create Returnable Buffer.
  2393. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2394. // Set Buffer Counter.
  2395. U32 bufferCount = 0;
  2396. // Add Picked Objects to List.
  2397. for ( U32 n = 0; n < resultCount; n++ )
  2398. {
  2399. // Output Object ID.
  2400. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  2401. // Finish early if we run out of buffer space.
  2402. if ( bufferCount >= maxBufferSize )
  2403. {
  2404. // Warn.
  2405. Con::warnf("Scene::pickPoint() - Too many items picked to return to scripts!");
  2406. break;
  2407. }
  2408. }
  2409. // Clear world query.
  2410. pWorldQuery->clearQuery();
  2411. // Return buffer.
  2412. return pBuffer;
  2413. }
  2414. //-----------------------------------------------------------------------------
  2415. /*! Picks objects intersecting the specified circle with optional group/layer masks.
  2416. @param x/y The coordinate of the point as either (\x y\ or (x,y)
  2417. @param radius The radius of the circle.
  2418. @param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.
  2419. @param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.
  2420. @param pickMode Optional mode 'any', 'aabb', 'oobb' or 'collision' (default is 'ooabb').
  2421. @return Returns list of object IDs.
  2422. */
  2423. ConsoleMethodWithDocs(Scene, pickCircle, ConsoleString, 4, 8, (x / y, radius, [sceneGroupMask], [sceneLayerMask], [pickMode] ))
  2424. {
  2425. // The point.
  2426. Vector2 point;
  2427. // The index of the first optional parameter.
  2428. U32 firstArg;
  2429. // Grab the number of elements in the first parameter.
  2430. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2431. // ("x y")
  2432. if ((elementCount == 2) && (argc < 8))
  2433. {
  2434. point = Utility::mGetStringElementVector(argv[2]);
  2435. firstArg = 3;
  2436. }
  2437. // (x, y)
  2438. else if ((elementCount == 1) && (argc > 3))
  2439. {
  2440. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2441. firstArg = 4;
  2442. }
  2443. // Invalid
  2444. else
  2445. {
  2446. Con::warnf("Scene::pickPoint() - Invalid number of parameters!");
  2447. return NULL;
  2448. }
  2449. // Fetch radius.
  2450. const F32 radius = dAtof(argv[firstArg++]);
  2451. // Check radius.
  2452. if ( radius <= 0.0f )
  2453. {
  2454. Con::warnf( "Scene::pickCircle() Radius must be greater than zero." );
  2455. return StringTable->EmptyString;
  2456. }
  2457. // Calculate scene group mask.
  2458. U32 sceneGroupMask = MASK_ALL;
  2459. if ( (U32)argc > firstArg )
  2460. {
  2461. if ( *argv[firstArg] != 0 )
  2462. sceneGroupMask = dAtoi(argv[firstArg]);
  2463. }
  2464. // Calculate scene layer mask.
  2465. U32 sceneLayerMask = MASK_ALL;
  2466. if ( (U32)argc > (firstArg + 1) )
  2467. {
  2468. if ( *argv[firstArg + 1] != 0 )
  2469. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2470. }
  2471. // Calculate pick mode.
  2472. Scene::PickMode pickMode = Scene::PICK_OOBB;
  2473. if ( (U32)argc > (firstArg + 2 ))
  2474. {
  2475. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  2476. }
  2477. if ( pickMode == Scene::PICK_INVALID )
  2478. {
  2479. Con::warnf("Scene::pickPoint() - Invalid pick mode of %s", argv[firstArg + 2]);
  2480. pickMode = Scene::PICK_OOBB;
  2481. }
  2482. // Fetch world query and clear results.
  2483. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2484. // Set filter.
  2485. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2486. pWorldQuery->setQueryFilter( queryFilter );
  2487. // Perform query.
  2488. if ( pickMode == Scene::PICK_ANY )
  2489. {
  2490. pWorldQuery->anyQueryCircle( point, radius );
  2491. }
  2492. else if ( pickMode == Scene::PICK_AABB )
  2493. {
  2494. pWorldQuery->aabbQueryCircle( point, radius );
  2495. }
  2496. else if ( pickMode == Scene::PICK_OOBB )
  2497. {
  2498. pWorldQuery->oobbQueryCircle( point, radius );
  2499. }
  2500. else if ( pickMode == Scene::PICK_COLLISION )
  2501. {
  2502. pWorldQuery->collisionQueryCircle( point, radius );
  2503. }
  2504. else
  2505. {
  2506. AssertFatal( false, "Unsupported pick mode." );
  2507. }
  2508. // Fetch result count.
  2509. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2510. // Finish if no results.
  2511. if ( resultCount == 0 )
  2512. return NULL;
  2513. // Fetch results.
  2514. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2515. // Set Max Buffer Size.
  2516. const U32 maxBufferSize = 4096;
  2517. // Create Returnable Buffer.
  2518. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2519. // Set Buffer Counter.
  2520. U32 bufferCount = 0;
  2521. // Add Picked Objects to List.
  2522. for ( U32 n = 0; n < resultCount; n++ )
  2523. {
  2524. // Output Object ID.
  2525. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  2526. // Finish early if we run out of buffer space.
  2527. if ( bufferCount >= maxBufferSize )
  2528. {
  2529. // Warn.
  2530. Con::warnf("Scene::pickPoint() - Too many items picked to return to scripts!");
  2531. break;
  2532. }
  2533. }
  2534. // Clear world query.
  2535. pWorldQuery->clearQuery();
  2536. // Return buffer.
  2537. return pBuffer;
  2538. }
  2539. //-----------------------------------------------------------------------------
  2540. /*! Picks objects with collision shapes intersecting the specified ray with optional group/layer masks.
  2541. Unlike other pick methods, this returns the complete detail for each object encountered, returning the collision point, normal and fraction of the ray intersection.
  2542. @param startx/y The coordinates of the start point as either (\x y\ or (x,y)
  2543. @param endx/y The coordinates of the end point as either (\x y\ or (x,y)
  2544. @param sceneGroupMask Optional scene group mask. (-1) or empty string selects all groups.
  2545. @param sceneLayerMask Optional scene layer mask. (-1) or empty string selects all layers.
  2546. @return Returns a list of objects in blocks of detail items where each block represents a single object and its collision detail in the format:
  2547. <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> etc.
  2548. */
  2549. ConsoleMethodWithDocs(Scene, pickRayCollision, ConsoleString, 4, 8, (startx/y, endx/y, [sceneGroupMask], [sceneLayerMask] ))
  2550. {
  2551. // Upper left and lower right bound.
  2552. Vector2 v1, v2;
  2553. // The index of the first optional parameter.
  2554. U32 firstArg;
  2555. // Grab the number of elements in the first two parameters.
  2556. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  2557. U32 elementCount2 = 1;
  2558. if (argc > 3)
  2559. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  2560. // ("x1 y1 x2 y2")
  2561. if ((elementCount1 == 4) && (argc < 9))
  2562. {
  2563. v1 = Utility::mGetStringElementVector(argv[2]);
  2564. v2 = Utility::mGetStringElementVector(argv[2], 2);
  2565. firstArg = 3;
  2566. }
  2567. // ("x1 y1", "x2 y2")
  2568. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 9))
  2569. {
  2570. v1 = Utility::mGetStringElementVector(argv[2]);
  2571. v2 = Utility::mGetStringElementVector(argv[3]);
  2572. firstArg = 4;
  2573. }
  2574. // (x1, y1, x2, y2)
  2575. else if (argc > 5)
  2576. {
  2577. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2578. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  2579. firstArg = 6;
  2580. }
  2581. // Invalid
  2582. else
  2583. {
  2584. Con::warnf("Scene::pickRayCollision() - Invalid number of parameters!");
  2585. return NULL;
  2586. }
  2587. // Calculate scene group mask.
  2588. U32 sceneGroupMask = MASK_ALL;
  2589. if ( (U32)argc > firstArg )
  2590. {
  2591. if ( *argv[firstArg] != 0 )
  2592. sceneGroupMask = dAtoi(argv[firstArg]);
  2593. }
  2594. // Calculate scene layer mask.
  2595. U32 sceneLayerMask = MASK_ALL;
  2596. if ( (U32)argc > (firstArg + 1) )
  2597. {
  2598. if ( *argv[firstArg + 1] != 0 )
  2599. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2600. }
  2601. // Fetch world query and clear results.
  2602. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2603. // Set filter.
  2604. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2605. pWorldQuery->setQueryFilter( queryFilter );
  2606. // Perform query.
  2607. pWorldQuery->collisionQueryRay( v1, v2 );
  2608. // Sanity!
  2609. AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  2610. // Fetch result count.
  2611. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2612. // Finish if no results.
  2613. if ( resultCount == 0 )
  2614. return NULL;
  2615. // Sort ray-cast result.
  2616. pWorldQuery->sortRaycastQueryResult();
  2617. // Fetch results.
  2618. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2619. // Set Max Buffer Size.
  2620. const U32 maxBufferSize = 4096;
  2621. // Create Returnable Buffer.
  2622. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2623. // Set Buffer Counter.
  2624. U32 bufferCount = 0;
  2625. // Add Picked Objects to List.
  2626. for ( U32 n = 0; n < resultCount; n++ )
  2627. {
  2628. // Fetch query result.
  2629. const WorldQueryResult& queryResult = queryResults[n];
  2630. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d %g %g %g %g %g %d ",
  2631. queryResult.mpSceneObject->getId(),
  2632. queryResult.mPoint.x, queryResult.mPoint.y,
  2633. queryResult.mNormal.x, queryResult.mNormal.y,
  2634. queryResult.mFraction,
  2635. queryResult.mShapeIndex );
  2636. // Finish early if we run out of buffer space.
  2637. if ( bufferCount >= maxBufferSize )
  2638. {
  2639. // Warn.
  2640. Con::warnf("Scene::pickRayCollision() - Too many items picked to return to scripts!");
  2641. break;
  2642. }
  2643. }
  2644. // Clear world query.
  2645. pWorldQuery->clearQuery();
  2646. // Return buffer.
  2647. return pBuffer;
  2648. }
  2649. //-----------------------------------------------------------------------------
  2650. /*! Sets Debug option(s) on.
  2651. @param debugOptions Either a list of debug modes (comma-separated), or a string with the modes (space-separated)
  2652. @return No return value.
  2653. */
  2654. ConsoleMethodWithDocs(Scene, setDebugOn, ConsoleVoid, 3, 2 + DEBUG_MODE_COUNT, (debugOptions))
  2655. {
  2656. // Reset the mask.
  2657. U32 mask = 0;
  2658. // Grab the element count of the first parameter.
  2659. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2660. // Make sure we get at least one number.
  2661. if (elementCount < 1)
  2662. {
  2663. Con::warnf( "Scene::setDebugOn() - Invalid number of parameters!" );
  2664. return;
  2665. }
  2666. // Space-separated list.
  2667. if (argc == 3)
  2668. {
  2669. // Convert the string to a mask.
  2670. for (U32 i = 0; i < elementCount; i++)
  2671. {
  2672. // Fetch the debug option.
  2673. const char* pDebugOption = Utility::mGetStringElement( argv[2], i );
  2674. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( pDebugOption );
  2675. // Is the option valid?
  2676. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2677. {
  2678. // No, so warn.
  2679. Con::warnf( "Scene::setDebugOn() - Invalid debug option '%s' specified.", pDebugOption );
  2680. continue;
  2681. }
  2682. // Merge into mask.
  2683. mask |= debugOption;
  2684. }
  2685. }
  2686. // Comma-separated list.
  2687. else
  2688. {
  2689. // Convert the list to a mask.
  2690. for (U32 i = 2; i < (U32)argc; i++)
  2691. {
  2692. // Fetch the debug option.
  2693. const char* pDebugOption = argv[i];
  2694. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( argv[i] );
  2695. // Is the option valid?
  2696. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2697. {
  2698. // No, so warn.
  2699. Con::warnf( "Scene::setDebugOn() - Invalid debug option '%s' specified.", pDebugOption );
  2700. continue;
  2701. }
  2702. // Merge into mask.
  2703. mask |= debugOption;
  2704. }
  2705. }
  2706. // Set debug mask.
  2707. object->setDebugOn(mask);
  2708. }
  2709. //-----------------------------------------------------------------------------
  2710. /*! Sets Debug options(s) off.
  2711. @param debugOptions Either a list of debug modes to turn off (comma-separated) or a string (space-separated)
  2712. @return No return value.
  2713. */
  2714. ConsoleMethodWithDocs(Scene, setDebugOff, ConsoleVoid, 3, 2 + DEBUG_MODE_COUNT, (debugOptions))
  2715. {
  2716. // Reset the mask.
  2717. U32 mask = 0;
  2718. // Grab the element count of the first parameter.
  2719. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2720. // Make sure we get at least one number.
  2721. if (elementCount < 1)
  2722. {
  2723. Con::warnf( "Scene::setDebugOff() - Invalid number of parameters!" );
  2724. return;
  2725. }
  2726. // Space-separated list.
  2727. if (argc == 3)
  2728. {
  2729. // Convert the string to a mask.
  2730. for (U32 i = 0; i < elementCount; i++)
  2731. {
  2732. // Fetch the debug option.
  2733. const char* pDebugOption = Utility::mGetStringElement( argv[2], i );
  2734. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( pDebugOption );
  2735. // Is the option valid?
  2736. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2737. {
  2738. // No, so warn.
  2739. Con::warnf( "Scene::setDebugOff() - Invalid debug option '%s' specified.", pDebugOption );
  2740. continue;
  2741. }
  2742. // Merge into mask.
  2743. mask |= debugOption;
  2744. }
  2745. }
  2746. // Comma-separated list.
  2747. else
  2748. {
  2749. // Convert the list to a mask.
  2750. for (U32 i = 2; i < (U32)argc; i++)
  2751. {
  2752. // Fetch the debug option.
  2753. const char* pDebugOption = argv[i];
  2754. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( argv[i] );
  2755. // Is the option valid?
  2756. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2757. {
  2758. // No, so warn.
  2759. Con::warnf( "Scene::setDebugOff() - Invalid debug option '%s' specified.", pDebugOption );
  2760. continue;
  2761. }
  2762. // Merge into mask.
  2763. mask |= debugOption;
  2764. }
  2765. }
  2766. // Set debug mask.
  2767. object->setDebugOff(mask);
  2768. }
  2769. //-----------------------------------------------------------------------------
  2770. /*! Gets the state of the debug modes.
  2771. @return Returns a space separated list of debug modes that are active.
  2772. */
  2773. ConsoleMethodWithDocs(Scene, getDebugOn, ConsoleString, 2, 2, ())
  2774. {
  2775. // Fetch debug mask,.
  2776. const U32 debugMask = object->getDebugMask();
  2777. // Fetch a return buffer.
  2778. S32 bufferSize = 1024;
  2779. char* pReturnBuffer = Con::getReturnBuffer(bufferSize);
  2780. *pReturnBuffer = 0;
  2781. char* pWriteCursor = pReturnBuffer;
  2782. // Iterate debug mask.
  2783. for( U32 bit = 0; bit < 32; ++bit )
  2784. {
  2785. // Calculate debug mask bit.
  2786. const S32 debugBit = 1 << bit;
  2787. if ( (debugMask & debugBit) == 0 )
  2788. continue;
  2789. // Format option.
  2790. const S32 size = dSprintf( pWriteCursor, bufferSize, "%s ", object->getDebugOptionDescription( (Scene::DebugOption)debugBit ) );
  2791. bufferSize -= size;
  2792. pWriteCursor += size;
  2793. }
  2794. return pReturnBuffer;
  2795. }
  2796. //-----------------------------------------------------------------------------
  2797. /*! Sets the scene object to monitor in the debug metrics.
  2798. @param SceneObject The scene object to monitor in the debug metrics.
  2799. @return No return value.
  2800. */
  2801. ConsoleMethodWithDocs(Scene, setDebugSceneObject, ConsoleVoid, 3, 3, (sceneObject))
  2802. {
  2803. // Fetch scene object Id.
  2804. const SimObjectId sceneObjectId = dAtoi(argv[2]);
  2805. // Find scene object.
  2806. SceneObject* pSceneObject = dynamic_cast<SceneObject*>( Sim::findObject(sceneObjectId) );
  2807. // Sanity!
  2808. if ( !pSceneObject )
  2809. {
  2810. Con::warnf("Scene::setDebugSceneObject() - Could not find scene object %d.", sceneObjectId);
  2811. return;
  2812. }
  2813. // Set debug object.
  2814. object->setDebugSceneObject( pSceneObject );
  2815. }
  2816. //-----------------------------------------------------------------------------
  2817. /*! ( Gets the scene object being monitored in the debug metrics.
  2818. @return The scene object being monitored in the debug metrics (zero if none being monitored).
  2819. */
  2820. ConsoleMethodWithDocs(Scene, getDebugSceneObject, ConsoleInt, 2, 2, ())
  2821. {
  2822. // Fetch scene object.
  2823. SceneObject* pSceneObject = object->getDebugSceneObject();
  2824. if ( pSceneObject == NULL )
  2825. return 0;
  2826. return pSceneObject->getId();
  2827. }
  2828. //-----------------------------------------------------------------------------
  2829. /*! Sets the layer to use the specified render sort mode.
  2830. @param layer The layer to modify.
  2831. @param sortMode The sort mode to use on the specified layer.
  2832. @return No return value.
  2833. */
  2834. ConsoleMethodWithDocs(Scene, setLayerSortMode, ConsoleVoid, 4, 4, (layer, sortMode))
  2835. {
  2836. // Fetch the layer.
  2837. const U32 layer = dAtoi(argv[2]);
  2838. // Fetch the sort mode.
  2839. const SceneRenderQueue::RenderSort sortMode = SceneRenderQueue::getRenderSortEnum( argv[3] );
  2840. object->setLayerSortMode( layer, sortMode );
  2841. }
  2842. //-----------------------------------------------------------------------------
  2843. /*! Gets the render sort mode for the specified layer.
  2844. @param layer The layer to retrieve.
  2845. @return The render sort mode for the specified layer.
  2846. */
  2847. ConsoleMethodWithDocs(Scene, getLayerSortMode, ConsoleString, 3, 3, (layer))
  2848. {
  2849. // Fetch the layer.
  2850. const U32 layer = dAtoi(argv[2]);
  2851. // Fetch the sort mode.
  2852. return SceneRenderQueue::getRenderSortDescription( object->getLayerSortMode( layer ) );
  2853. }
  2854. //-----------------------------------------------------------------------------
  2855. /*! Resets the debug statistics.
  2856. @return No return value.
  2857. */
  2858. ConsoleMethodWithDocs(Scene, resetDebugStats, ConsoleVoid, 2, 2, ())
  2859. {
  2860. object->resetDebugStats();
  2861. }
  2862. //-----------------------------------------------------------------------------
  2863. /*! Gets the current average frames-per-second.
  2864. @return The current average frames-per-second.
  2865. */
  2866. ConsoleMethodWithDocs(Scene, getFPS, ConsoleFloat, 2, 2, ())
  2867. {
  2868. return object->getDebugStats().fps;
  2869. }
  2870. //-----------------------------------------------------------------------------
  2871. /*! Gets the minimum average frames-per-second.
  2872. @return The minimum Faverage frames-per-second.
  2873. */
  2874. ConsoleMethodWithDocs(Scene, getMinFPS, ConsoleFloat, 2, 2, ())
  2875. {
  2876. return object->getDebugStats().minFPS;
  2877. }
  2878. //-----------------------------------------------------------------------------
  2879. /*! Gets the maximum average frames-per-second.
  2880. @return The average frames-per-second.
  2881. */
  2882. ConsoleMethodWithDocs(Scene, getMaxFPS, ConsoleFloat, 2, 2, ())
  2883. {
  2884. return object->getDebugStats().maxFPS;
  2885. }
  2886. //-----------------------------------------------------------------------------
  2887. /*! Gets the current rendered frame count.
  2888. @return The current rendered frame count.
  2889. */
  2890. ConsoleMethodWithDocs(Scene, getFrameCount, ConsoleInt, 2, 2, ())
  2891. {
  2892. return (S32)object->getDebugStats().frameCount;
  2893. }
  2894. //-----------------------------------------------------------------------------
  2895. /*! Sets whether render batching is enabled or not.
  2896. @param enabled Whether render batching is enabled or not.
  2897. return No return value.
  2898. */
  2899. ConsoleMethodWithDocs(Scene, setBatchingEnabled, ConsoleVoid, 3, 3, ( bool enabled ))
  2900. {
  2901. // Fetch args.
  2902. const bool enabled = dAtob(argv[2]);
  2903. // Sets batching enabled.
  2904. object->setBatchingEnabled( enabled );
  2905. }
  2906. //-----------------------------------------------------------------------------
  2907. /*! Gets whether render batching is enabled or not.
  2908. return Whether render batching is enabled or not.
  2909. */
  2910. ConsoleMethodWithDocs(Scene, getBatchingEnabled, ConsoleBool, 2, 2, ())
  2911. {
  2912. // Gets batching enabled.
  2913. return object->getBatchingEnabled();
  2914. }
  2915. //-----------------------------------------------------------------------------
  2916. /*! Sets whether this is an editor scene.
  2917. @return No return value.
  2918. */
  2919. ConsoleMethodWithDocs(Scene, setIsEditorScene, ConsoleVoid, 3, 3, ())
  2920. {
  2921. object->setIsEditorScene(dAtob(argv[2]));
  2922. }
  2923. //-----------------------------------------------------------------------------
  2924. /*! Creates the specified scene-object derived type and adds it to the scene.
  2925. @return The scene-object or NULL if not created.
  2926. */
  2927. ConsoleMethodWithDocs(Scene, create, ConsoleString, 3, 3, (type))
  2928. {
  2929. // Create the scene object.
  2930. SceneObject* pSceneObject = object->create( argv[2] );
  2931. return pSceneObject == NULL ? NULL : pSceneObject->getIdString();
  2932. }
  2933. ConsoleMethodGroupEndWithDocs(Scene)