Scene_ScriptBinding.h 132 KB

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