lua_api.rst 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. =================
  2. Lua API reference
  3. =================
  4. AnimationStateMachine
  5. =====================
  6. **instance** (asm, unit) : Id
  7. Returns the ID of the state machine owned by the *unit*, or ``nil``.
  8. **variable_id** (asm, state_machine, name) : Id
  9. Returns the ID of the variable *name* in the *state_machine*.
  10. **variable** (asm, state_machine, variable_id) : number
  11. Returns the value of the *variable_id* in the *state_machine*.
  12. **set_variable** (asm, state_machine, variable_id, value)
  13. Sets the *value* of the *variable_id* in the *state_machine*.
  14. **trigger** (asm, state_machine, event)
  15. Triggers the *event* in the *state_machine*.
  16. DebugLine
  17. =========
  18. **add_line** (debug_line, start, end, color)
  19. Adds a line from *start* to *end* with the given *color*.
  20. **add_axes** (debug_line, tm, length)
  21. Adds lines for each axis with the given *length*.
  22. **add_arc** (debug_line, center, radius, plane_normal, midpoint_normal, color, [circle_segments = 36]);
  23. Adds an arc at *center* with the given *radius* and *plane_normal* and *midpoint_normal* vectors.
  24. **add_circle** (debug_line, center, radius, normal, color, [segments = 36])
  25. Adds a circle at *center* with the given *radius* and *normal* vector.
  26. **add_cone** (debug_line, from, to, radius, color, [segments = 36, rays = 36])
  27. Adds a cone with the base centered at *from* and the tip at *to*.
  28. **add_sphere** (debug_line, center, radius, color, [segments = 36])
  29. Adds a sphere at *center* with the given *radius*.
  30. **add_obb** (debug_line, tm, half_extents, color)
  31. Adds an orientd bounding box. *tm* describes the position and orientation of
  32. the box. *half_extents* describes the size of the box along the axis.
  33. **add_frustum** (debug_line, mvp, color)
  34. Adds a frustum defined by *mvp*.
  35. **reset** (debug_line)
  36. Resets all the lines.
  37. **submit** (debug_line)
  38. Submits the lines to renderer for drawing.
  39. Device
  40. ======
  41. **argv** () : table
  42. Returns a table containing the command line parameters the engine was started with.
  43. **platform** () : string
  44. Returns a string identifying what platform the engine is running on.
  45. It can be either ``android``, ``linux`` or ``windows``
  46. **architecture** () : string
  47. Returns a string identifying what architecture the engine is running on.
  48. It can be either ``32-bit`` or ``64-bit``.
  49. **version** () : string
  50. Returns a string identifying the engine version.
  51. The form is "major.minor.micro".
  52. **quit** ([exit_code])
  53. Quits the application. On platforms that support it, *exit_code* is
  54. returned to the system after the application exits.
  55. **resolution** () : float, float
  56. Returns the main window resolution (width, height).
  57. **create_world** () : World
  58. Creates a new world.
  59. **destroy_world** (world)
  60. Destroys the given *world*.
  61. **render** (world, camera)
  62. Renders *world* using *camera*.
  63. **create_resource_package** (name) : ResourcePackage
  64. Returns the resource package with the given *package_name* name.
  65. **destroy_resource_package** (package)
  66. Destroy a previously created resource *package*.
  67. .. note::
  68. To unload the resources loaded by the package, you have to call
  69. ResourcePackage.unload() first.
  70. **screenshot** (path)
  71. Captures a screenshot of the main window's backbuffer and saves it at *path* in PNG format.
  72. The global callback ``screenshot (path)`` will be called after the file is written to disk.
  73. .. note::
  74. Only available in debug and development builds.
  75. **console_send** (table)
  76. Sends the given lua *table* to clients connected to the engine.
  77. Values can be either ``nil``, bool, number, string, table, array, Vector2, Vector3, Quaternion, Matrix4x4 or Color4.
  78. **can_get** (type, name) : bool
  79. Returns whether the resource (type, name) is loaded.
  80. When resource autoload is enabled it always returns true.
  81. **enable_resource_autoload** (enable)
  82. Sets whether resources should be automatically loaded when accessed.
  83. **temp_count** () : int, int, int
  84. Returns the number of temporary objects used by Lua.
  85. **set_temp_count** (nv, nq, nm)
  86. Sets the number of temporary objects used by Lua.
  87. **guid** () : string
  88. Returns a new GUID.
  89. **set_timestep_policy** (policy)
  90. Sets the timestep policy:
  91. * ``variable``: the timestep is the time it took for the previous frame to simulate. This is the default;
  92. * ``smoothed``: the timestep is computed as an average of the previous delta times.
  93. **set_timestep_smoothing** (num_samples, num_outliers, average_cap)
  94. Sets the number of samples to be averaged, the outliers to be excluded and the maximum
  95. allowed deviation in percent from the previous average. Given a delta time series DTs, and
  96. a previous average AVGp:
  97. * DTs = [ .33; .30; .32; .33; .24; .33; .25; .35; .33; .42 ]
  98. * AVGp = 0.33
  99. A call to set_smoothing(10, 2, 0.1) would compute the new average like so:
  100. 1. Remove the 2 minimum and maximum values in DTs;
  101. 2. Compute the average for the remaining 6 values in DTs: AVG = 0.323.
  102. 3. Smooth the newly computed average: AVG = lerp(AVGp, AVG, 0.1) = 0.329.
  103. Display
  104. =======
  105. **modes** () : table
  106. Returns an array of `DisplayMode`_ tables.
  107. **set_mode** (id)
  108. Sets the display mode *id*.
  109. The initial display mode is automatically reset when the program terminates.
  110. DisplayMode
  111. -----------
  112. DisplayMode is a lua table with 3 fields:
  113. * ``id``: The id of the display mode.
  114. * ``width``: The width of the display mode.
  115. * ``height``: The height of the display mode.
  116. Gui
  117. ===
  118. **move** (gui, pos)
  119. Moves the Gui to *pos*.
  120. **triangle** (gui, a, b, c [, color, depth])
  121. Draws a triangle defined by vertices *a*, *b* and *c*.
  122. Objects with a lower depth are drawn in front. If depth is omitted its value
  123. is set to 0.
  124. **triangle_3d** (gui, local_pose, a, b, c [, color, depth])
  125. Draws a 3D triangle defined by vertices *a*, *b* and *c*.
  126. **rect** (gui, pos, size [, color])
  127. Draws a rectangle.
  128. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  129. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  130. to 0.
  131. **rect_3d** (gui, local_pose, pos, size [, color, depth])
  132. Draws a 3D rectangle.
  133. **image** (gui, pos, size, material_resource [, color])
  134. Draws an image.
  135. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  136. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  137. to 0.
  138. **image_3d** (gui, local_pose, pos, size, material_resource [, color, depth])
  139. Draws a 3D image.
  140. **image_uv** (gui, pos, size, uv0, uv1, material_resource [, color])
  141. Draws an image with explicit UV coordinates.
  142. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  143. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  144. to 0.
  145. **image_3d_uv** (gui, local_pose, pos, size, uv0, uv1, material_resource [, color, depth])
  146. Draws a 3D image with explicit UV coordinates.
  147. **text** (gui, pos, font_size, str, font_resource [, material_resource , color])
  148. Draws text.
  149. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  150. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  151. to 0.
  152. **text_extents** (gui, font_size, str, font_resource) : Vector2
  153. Returns the extents of the text *str* if drawn using *font_resource* at size
  154. *font_size*.
  155. **text_3d** (gui, local_pose, pos, font_size, str, font_resource [, material_resource, color, depth])
  156. Draws 3D text.
  157. **material** (material_resource) : Material
  158. Returns the material *material_resource*.
  159. Input
  160. =====
  161. **events** () : table
  162. Returns an array of `InputEvent`_ tables.
  163. InputEvent
  164. ----------
  165. InputEvent is a lua table with 4 fields:
  166. * ``id``: The id of the button or axis as returned by ``Keyboard.button_id()`` for example.
  167. * ``type``: One of the values from `InputEventType`_.
  168. * ``value``: The value of the axis as a Vector3 or ``nil`` when ``type`` is not an axis event.
  169. * ``device``: The input device that generated the event. This is one of ``Keyboard``, ``Mouse``, ``Pad1`` etc.
  170. InputEventType
  171. --------------
  172. * ``BUTTON_PRESSED``: A button has been pressed.
  173. * ``BUTTON_RELEASED``: A button has been released.
  174. * ``AXIS_CHANGED``: An axis changed its value.
  175. Keyboard
  176. --------
  177. **name** () : string
  178. Returns the name of keyboard.
  179. **connected** () : bool
  180. Returns whether the keyboard is connected and functioning.
  181. **num_buttons** () : int
  182. Returns the number of buttons of the keyboard.
  183. **num_axes** () : int
  184. Returns the number of axes of the keyboard.
  185. **pressed** (id) : bool
  186. Returns whether the button *id* is pressed in the current frame.
  187. **released** (id) : bool
  188. Returns whether the button *id* is released in the current frame.
  189. **any_pressed** () : bool
  190. Returns the *id* of the first button that was pressed in the current frame
  191. or ``nil`` if no buttons were pressed at all.
  192. **any_released** () : bool
  193. Returns the *id* of the first button that was released in the current frame
  194. or ``nil`` if no buttons were released at all.
  195. **button** (id) : float
  196. Returns the value of the button *id* in the range [0..1].
  197. **button_name** (id) : string
  198. Returns the name of the button *id*.
  199. **button_id** (name) : int
  200. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  201. Keyboard Button Names
  202. ~~~~~~~~~~~~~~~~~~~~~
  203. * ``tab``, ``enter``, ``escape``, ``space``, ``backspace``
  204. * ``num_lock``, ``numpad_enter``, ``numpad_.``, ``numpad_*``, ``numpad_+``, ``numpad_-``, ``numpad_/``, ``numpad_0``, ``numpad_1``, ``numpad_2``, ``numpad_3``, ``numpad_4``, ``numpad_5``, ``numpad_6``, ``numpad_7``, ``numpad_8``, ``numpad_9``
  205. * ``f1``, ``f2``, ``f3``, ``f4``, ``f5``, ``f6``, ``f7``, ``f8``, ``f9``, ``f10``, ``f11``, ``f12``
  206. * ``home``, ``left``, ``up``, ``right``, ``down``, ``page_up``, ``page_down``, ``ins``, ``del``, ``end``
  207. * ``ctrl_left``, ``ctrl_right``, ``shift_left``, ``shift_right``, ``caps_lock``, ``alt_left``, ``alt_right``, ``super_left``, ``super_right``
  208. * ``0``, ``1``, ``2``, ``3``, ``4``, ``5``, ``6``, ``7``, ``8``, ``9``
  209. * ``a``, ``b``, ``c``, ``d``, ``e``, ``f``, ``g``, ``h``, ``i``, ``j``, ``k``, ``l``, ``m``, ``n``, ``o``, ``p``, ``q``, ``r``, ``s``, ``t``, ``u``, ``v``, ``w``, ``x``, ``y``, ``z``
  210. Keyboard Axis Names
  211. ~~~~~~~~~~~~~~~~~~~
  212. None.
  213. Mouse
  214. -----
  215. **name** () : string
  216. Returns the name of the mouse.
  217. **connected** () : bool
  218. Returns whether the mouse is connected and functioning.
  219. **num_buttons** () : int
  220. Returns the number of buttons of the mouse.
  221. **num_axes** () : int
  222. Returns the number of axes of the mouse.
  223. **pressed** (id) : bool
  224. Returns whether the button *id* is pressed in the current frame.
  225. **released** (id) : bool
  226. Returns whether the button *id* is released in the current frame.
  227. **any_pressed** () : bool
  228. Returns the *id* of the first button that was pressed in the current frame
  229. or ``nil`` if no buttons were pressed at all.
  230. **any_released** () : bool
  231. Returns the *id* of the first button that was released in the current frame
  232. or ``nil`` if no buttons were released at all.
  233. **button** (id) : float
  234. Returns the value of the button *id* in the range [0..1].
  235. **axis** (id) : Vector3
  236. Returns the value of the axis *id*.
  237. **button_name** (id) : string
  238. Returns the name of the button *id*.
  239. **axis_name** (id) : string
  240. Returns the name of the axis *id*.
  241. **button_id** (name) : int
  242. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  243. **axis_id** (name) : int
  244. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  245. Mouse Button Names
  246. ~~~~~~~~~~~~~~~~~~
  247. ``left``, ``middle``, ``right``, ``extra_1``, ``extra_2``
  248. Mouse Axis Names
  249. ~~~~~~~~~~~~~~~~
  250. * ``cursor``: Returns the cursor position (x, y) in screen coordinates.
  251. * ``cursor_delta``: Returns the delta of the cursor position (x, y) since last frame.
  252. * ``wheel``: Returns the movement of the mouse wheel in the y axis. Positive values of y mean upward scrolling, negative values mean downward scrolling.
  253. Touch
  254. -----
  255. **name** () : string
  256. Returns the name of the touch.
  257. **connected** () : bool
  258. Returns whether the touch is connected and functioning.
  259. **num_buttons** () : int
  260. Returns the number of buttons of the touch.
  261. **num_axes** () : int
  262. Returns the number of axes of the touch.
  263. **pressed** (id) : bool
  264. Returns whether the button *id* is pressed in the current frame.
  265. **released** (id) : bool
  266. Returns whether the button *id* is released in the current frame.
  267. **any_pressed** () : bool
  268. Returns the *id* of the first button that was pressed in the current frame
  269. or ``nil`` if no buttons were pressed at all.
  270. **any_released** () : bool
  271. Returns the *id* of the first button that was released in the current frame
  272. or ``nil`` if no buttons were released at all.
  273. **button** (id) : float
  274. Returns the value of the button *id* in the range [0..1].
  275. **axis** (id) : Vector3
  276. Returns the value of the axis *id*.
  277. **button_name** (id) : string
  278. Returns the name of the button *id*.
  279. **axis_name** (id) : string
  280. Returns the name of the axis *id*.
  281. **button_id** (name) : int
  282. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  283. **axis_id** (name) : int
  284. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  285. Pad1, Pad2, Pad3, Pad4
  286. ----------------------
  287. **name** () : string
  288. Returns the name of the pad.
  289. **connected** () : bool
  290. Returns whether the pad is connected and functioning.
  291. **num_buttons** () : int
  292. Returns the number of buttons of the pad.
  293. **num_axes** () : int
  294. Returns the number of axes of the pad.
  295. **pressed** (id) : bool
  296. Returns whether the button *id* is pressed in the current frame.
  297. **released** (id) : bool
  298. Returns whether the button *id* is released in the current frame.
  299. **any_pressed** () : bool
  300. Returns the *id* of the first button that was pressed in the current frame
  301. or ``nil`` if no buttons were pressed at all.
  302. **any_released** () : bool
  303. Returns the *id* of the first button that was released in the current frame
  304. or ``nil`` if no buttons were released at all.
  305. **button** (id) : float
  306. Returns the value of the button *id* in the range [0..1].
  307. **axis** (id) : Vector3
  308. Returns the value of the axis *id*.
  309. **button_name** (id) : string
  310. Returns the name of the button *id*.
  311. **axis_name** (id) : string
  312. Returns the name of the axis *id*.
  313. **button_id** (name) : int
  314. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  315. **axis_id** (name) : int
  316. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  317. **deadzone** (id) : deadzone_mode, deadzone_size
  318. Returns the deadzone mode and size for the axis *id*.
  319. **set_deadzone** (id, deadzone_mode, deadzone_size)
  320. Sets the *deadzone_mode* and *deadzone_size* for the axis *id*.
  321. Pad Button Names
  322. ~~~~~~~~~~~~~~~~
  323. * ``up``, ``down``, ``left``, ``right``
  324. * ``start``, ``back``, ``guide``
  325. * ``thumb_left``, ``thumb_right``
  326. * ``shoulder_left``, ``shoulder_right``
  327. * ``a``, ``b``, ``x``, ``y``
  328. Pad Axis Names
  329. ~~~~~~~~~~~~~~
  330. * ``left``, ``right``: Returns the direction (x, y) of the left or right thumbstick [-1; +1].
  331. * ``trigger_left``, ``trigger_right``: The z element represents the left or right trigger [0; +1].
  332. Material
  333. ========
  334. **set_float** (material, name, value)
  335. Sets the *value* of the variable *name*.
  336. **set_vector2** (material, name, value)
  337. Sets the *value* of the variable *name*.
  338. **set_vector3** (material, name, value)
  339. Sets the *value* of the variable *name*.
  340. **set_vector4** (material, name, value)
  341. Sets the *value* of the variable *name*.
  342. **set_matrix4x4** (material, name, value)
  343. Sets the *value* of the variable *name*.
  344. **set_texture** (material, sampler_name, texture_name)
  345. Sets the *texture_resource* of the sampler *sampler_name*.
  346. Math
  347. ====
  348. Vector3
  349. -------
  350. Constructors
  351. ~~~~~~~~~~~~
  352. **Vector3** (x, y, z) : Vector3
  353. Returns a new vector from individual elements.
  354. Functions
  355. ~~~~~~~~~
  356. **x** (v) : float
  357. Returns the x value of the vector.
  358. **y** (v) : float
  359. Returns the y value of the vector.
  360. **z** (v) : float
  361. Returns the z value of the vector.
  362. **.x** : float
  363. Returns/assigns the x value of the vector.
  364. **.y** : float
  365. Returns/assigns the y value of the vector.
  366. **.z** : float
  367. Returns/assigns the z value of the vector.
  368. **set_x** (v, x)
  369. Sets the value of the x value of the vector.
  370. **set_y** (v, y)
  371. Sets the value of the y value of the vector.
  372. **set_z** (v, z)
  373. Sets the value of the z value of the vector.
  374. **elements** (v) : float, float, float
  375. Returns the x, y and z elements of the vector.
  376. **add** (a, b) : Vector3
  377. Adds the vector *a* to *b* and returns the result.
  378. **subtract** (a, b) : Vector3
  379. Subtracts the vector *b* from *a* and returns the result.
  380. **multiply** (a, k) : Vector3
  381. Multiplies the vector *a* by the scalar *k* and returns the result.
  382. **dot** (a, b) : float
  383. Returns the dot product between the vectors *a* and *b*.
  384. **cross** (a, b) : Vector3
  385. Returns the cross product between the vectors *a* and *b*.
  386. **equal** (a, b) : bool
  387. Returns true whether the vectors *a* and *b* are equal.
  388. **length** (a) : float
  389. Returns the length of *a*.
  390. **length_squared** (a) : float
  391. Returns the squared length of *a*.
  392. **set_length** (a, len)
  393. Sets the length of *a* to *len*.
  394. **normalize** (a) : Vector3
  395. Normalizes *a* and returns the result.
  396. **distance** (a, b) : float
  397. Returns the distance between the points *a* and *b*.
  398. **distance_squared** (a, b) : float
  399. Returns the squared distance between the points *a* and *b*.
  400. **angle** (a, b) : float
  401. Returns the angle between the vectors *a* and *b*.
  402. **max** (a, b) : Vector3
  403. Returns a vector that contains the largest value for each element from *a* and *b*.
  404. **min** (a, b) : Vector3
  405. Returns a vector that contains the smallest value for each element from *a* and *b*.
  406. **lerp** (a, b, t) : Vector3
  407. Returns the linearly interpolated vector between *a* and *b* at time *t* in [0, 1].
  408. | **forward** () : Vector3
  409. | **backward** () : Vector3
  410. | **left** () : Vector3
  411. | **right** () : Vector3
  412. | **up** () : Vector3
  413. | **down** () : Vector3
  414. | Returns the corresponding semantic axis.
  415. **zero** () : Vector3
  416. Returns a vector with all values set to zero.
  417. **to_string** (v) : string
  418. Returns a string representing the vector *v*.
  419. Vector3Box
  420. ----------
  421. Constructors
  422. ~~~~~~~~~~~~
  423. **Vector3Box** () : Vector3Box
  424. Returns a new Vector3Box initialized with the zero vector.
  425. **Vector3Box** (v) : Vector3Box
  426. Returns a new Vector3Box from the Vector3 *v*.
  427. **Vector3Box** (x, y, z) : Vector3Box
  428. Returns a new Vector3Box from individual elements.
  429. Functions
  430. ~~~~~~~~~
  431. **store** (v)
  432. Stores the Vector3 *v* in the box.
  433. **store** (x, y, z)
  434. Stores Vector3(x, y, z) in the box.
  435. **unbox** () : Vector3
  436. Returns the stored vector from the box.
  437. Quaternion
  438. ----------
  439. Constructors
  440. ~~~~~~~~~~~~
  441. **Quaternion** (axis, angle) : Quaternion
  442. Returns a new quaternion from *axis* and *angle*.
  443. **from_elements** (x, y, z, w) : Quaternion
  444. Returns a new quaternion from individual elements.
  445. **from_axis_angle** (axis, angle) : Quaternion
  446. Returns a new quaternion from *axis* and *angle*.
  447. Functions
  448. ~~~~~~~~~
  449. **negate** (q) : Quaternion
  450. Negates the quaternion *q* and returns the result.
  451. **identity** () : Quaternion
  452. Returns the identity quaternion.
  453. **multiply** (a, b) : Quaternion
  454. Multiplies the quaternions *a* and *b*. (i.e. rotates first by *a* then by *b*).
  455. **multiply_by_scalar** (a, k) : Quaternion
  456. Multiplies the quaternion *a* by the scalar *k*.
  457. **dot** (a, b) : float
  458. Returns the dot product between quaternions *a* and *b*.
  459. **length** (q) : float
  460. Returns the length of *q*.
  461. **normalize** (q) : Quaternion
  462. Normalizes the quaternion *q* and returns the result.
  463. **conjugate** (q) : Quaternion
  464. Returns the conjugate of quaternion *q*.
  465. **inverse** (q) : Quaternion
  466. Returns the inverse of quaternion *q*.
  467. **power** (q, exp) : Quaternion
  468. Returns the quaternion *q* raised to the power of *exp*.
  469. **elements** (q) : float, float, float, float
  470. Returns the x, y, z and w elements of the quaternion.
  471. **look** (dir, [up]) : Quaternion
  472. Returns the quaternion describing the rotation needed to face towards *dir*.
  473. If *up* is not specified, Vector3.up() is used.
  474. **right** (q) : Vector3
  475. Returns the right axis of the rotation described by *q*.
  476. **up** (q) : Vector3
  477. Returns the up axis of the rotation described by *q*.
  478. **forward** (q) : Vector3
  479. Returns the forward axis of the rotation described by *q*.
  480. **lerp** (a, b, t) : Quaternion
  481. Returns the linearly interpolated quaternion between *a* and *b* at time *t* in [0, 1].
  482. It uses NLerp.
  483. **to_string** (q) : string
  484. Returns a string representing the quaternion *q*.
  485. QuaternionBox
  486. -------------
  487. Constructors
  488. ~~~~~~~~~~~~
  489. **QuaternionBox** () : QuaternionBox
  490. Returns a new QuaternionBox initialized with the identity quaternion.
  491. **QuaternionBox** (q) : QuaternionBox
  492. Returns a new QuaternionBox from the Quaternion *q*.
  493. **QuaternionBox** (x, y, z, w) : QuaternionBox
  494. Returns a new QuaternionBox from individual elements.
  495. Functions
  496. ~~~~~~~~~
  497. **store** (q)
  498. Stores the Quaternion *q* in the box.
  499. **store** (x, y, z, w)
  500. Stores Quaternion(x, y, z, w) in the box.
  501. **unbox** () : Quaternion
  502. Returns the stored quaternion from the box.
  503. Matrix4x4
  504. ---------
  505. Constructors
  506. ~~~~~~~~~~~~
  507. **Matrix4x4** (xx, xy, xz, xw, yx, yy, yz, yw, zx, zy, zz, zw, tx, ty, tz, tw) : Matrix4x4
  508. Returns a new matrix from individual elements.
  509. **from_quaternion** (q) : Matrix4x4
  510. Returns a new matrix from *q*.
  511. **from_translation** (t) : Matrix4x4
  512. Returns a new matrix from *t*.
  513. **from_quaternion_translation** (q, t) : Matrix4x4
  514. Returns a new matrix from *q* and *t*.
  515. **from_axes** (x, y, z, t) : Matrix4x4
  516. Returns a new matrix from *x*, *y*, *z* and *t*.
  517. Functions
  518. ~~~~~~~~~
  519. **copy** (m) : Matrix4x4
  520. Returns a copy of the matrix *m*.
  521. **add** (a, b) : Matrix4x4
  522. Adds the matrix *a* to *b* and returns the result.
  523. **subtract** (a, b) : Matrix4x4
  524. Subtracts the matrix *b* from *a* and returns the result.
  525. **multiply** (a, b) : Matrix4x4
  526. Multiplies the matrix *a* by *b* and returns the result. (i.e. transforms first by *a* then by *b*)
  527. **equal** (a, b) : bool
  528. Returns true whether the matrices *a* and *b* are equal.
  529. **transpose** (m) : Matrix4x4
  530. Transposes the matrix *m* and returns the result.
  531. **invert** (m) : Matrix4x4
  532. Inverts the matrix *m* and returns the result.
  533. **x** (m) : Vector3
  534. Returns the x axis of the matrix *m*.
  535. **y** (m) : Vector3
  536. Returns the y axis of the matrix *m*.
  537. **z** (m) : Vector3
  538. Returns the z axis of the matrix *m*.
  539. **set_x** (m, x)
  540. Sets the x axis of the matrix *m*.
  541. **set_y** (m, y)
  542. Sets the y axis of the matrix *m*.
  543. **set_z** (m, z)
  544. Sets the z axis of the matrix *m*.
  545. **translation** (m) : Vector3
  546. Returns the translation portion of the matrix *m*.
  547. **set_translation** (m, t)
  548. Sets the translation portion of the matrix *m*.
  549. **rotation** (m) : Quaternion
  550. Returns the rotation portion of the matrix *m*.
  551. **set_rotation** (m, r)
  552. Sets the rotation portion of the matrix *m*.
  553. **scale** (m) : Vector3
  554. Returns the scale of the matrix *m*.
  555. **set_scale** (m, r)
  556. Sets the scale of the matrix *m*.
  557. **identity** ()
  558. Returns the identity matrix.
  559. **transform** (m, v) : Vector3
  560. Transforms the vector *v* by the matrix *m* and returns the result.
  561. **to_string** (m) : string
  562. Returns a string representing the matrix *m*.
  563. Matrix4x4Box
  564. ------------
  565. Constructors
  566. ~~~~~~~~~~~~
  567. **Matrix4x4Box** () : Matrix4x4Box
  568. Returns a new Matrix4x4Box initialized with the identity matrix.
  569. **Matrix4x4Box** (m) : Matrix4x4Box
  570. Returns a new Matrix4x4Box from the Matrix4x4 *m*.
  571. Functions
  572. ~~~~~~~~~
  573. **store** (m)
  574. Stores the Matrix4x4 *m* in the box.
  575. **unbox** () : Matrix4x4
  576. Returns the stored matrix from the box.
  577. Color4
  578. ------
  579. Constructors
  580. ~~~~~~~~~~~~
  581. **Color4** (r, g, b, a) : Color4
  582. Returns a new Color4 from individual elements.
  583. Functions
  584. ~~~~~~~~~
  585. **lerp** (a, b, t) : Color4
  586. Returns the linearly interpolated color between *a* and *b* at time *t* in [0, 1].
  587. | **black** () : Color4
  588. | **white** () : Color4
  589. | **red** () : Color4
  590. | **green** () : Color4
  591. | **blue** () : Color4
  592. | **yellow** () : Color4
  593. | **orange** () : Color4
  594. | Returns the corresponding mnemonic color.
  595. **to_string** (c) : string
  596. Returns a string representing the color *c*.
  597. Math
  598. ----
  599. **ray_plane_intersection** (from, dir, point, normal) : float
  600. Returns the distance along ray (from, dir) to intersection point with plane defined by
  601. *point* and *normal* or -1.0 if no intersection.
  602. **ray_disc_intersection** (from, dir, center, radius, normal) : float
  603. Returns the distance along ray (from, dir) to intersection point with disc defined by
  604. *center*, *radius* and *normal* or -1.0 if no intersection.
  605. **ray_sphere_intersection** (from, dir, center, radius) : float
  606. Returns the distance along ray (from, dir) to intersection point with sphere defined by
  607. *center* and *radius* or -1.0 if no intersection.
  608. **ray_obb_intersection** (from, dir, tm, half_extents) : float
  609. Returns the distance along ray (from, dir) to intersection point with the oriented
  610. bounding box (tm, half_extents) or -1.0 if no intersection.
  611. **ray_triangle_intersection** (from, dir, v0, v1, v2) : float
  612. Returns the distance along ray (from, dir) to intersection point with the triangle
  613. (v0, v1, v2) or -1.0 if no intersection.
  614. **obb_intersects_frustum** (obb_tm, obb_half_extents, n0, d0, n1, d1, n2, d2, n3, d3, n4, d4, n4, d5) : bool
  615. Returns whether the oriented bounding box (obb_tm, obb_half_extents) intersects
  616. the frustum defined by the planes ((n0, d0), (n1, d1), ..., (n5, d5)). The
  617. planes be given in BRTLNF order, where B = bottom plane, R = right plane etc.
  618. **obb_vertices** (obb_tm, obb_half_extents) : v0, v1, v2, v3, v4, v5, v6, v7
  619. Returns the vertices of the oriented bounding box (obb_tm, obb_half_extents).
  620. **obb_merge** (a_tm, a_half_extents, b_tm, b_half_extents, ...) : Matrix4x4, Vector3
  621. Returns a new box which encloses both the box A (a_tm, a_half_extents) and B
  622. (b_tm, b_half_extents) and any number of boxes after B.
  623. Note that the returned OBB will have the same orientation as A and won't
  624. necessarily be the smallest enclosing box.
  625. PhysicsWorld
  626. =============
  627. **gravity** (pw) : Vector3
  628. Returns the gravity.
  629. **set_gravity** (pw, gravity)
  630. Sets the gravity.
  631. **cast_ray** (pw, from, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  632. Casts a ray into the physics world and returns the closest actor it intersects with.
  633. If *hit* is true the following return values contain the *collision_pos* in
  634. world space, the *normal* of the surface that was hit, the time of impact
  635. in [0..1] and the *unit* and the *actor* that was hit.
  636. **cast_ray_all** (pw, from, dir, length) : table
  637. Casts a ray into the physics world and returns all the
  638. actors it intersects with as an array of `RaycastHit`_ tables.
  639. **cast_sphere** (pw, from, radius, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  640. Casts a sphere into the physics world and returns the closest actor it intersects with.
  641. If *hit* is true the following return values contain the *collision_pos* in
  642. world space, the *normal* of the surface that was hit, the time of impact
  643. in [0..1] and the *unit* and the *actor* that was hit.
  644. **cast_box** (pw, from, half_extents, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  645. Casts a box into the physics world and returns the closest actor it intersects with.
  646. If *hit* is true the following return values contain the *collision_pos* in
  647. world space, the *normal* of the surface that was hit, the time of impact
  648. in [0..1] and the *unit* and the *actor* that was hit.
  649. **enable_debug_drawing** (pw, enable)
  650. Sets whether to *enable* debug drawing.
  651. RaycastHit
  652. ----------
  653. RaycastHit is a lua table with 5 fields:
  654. * ``[1]``: The collision position in world space.
  655. * ``[2]``: The normal of the surface that was hit.
  656. * ``[3]``: The time of impact in [0..1].
  657. * ``[4]``: The unit that was hit.
  658. * ``[5]``: The actor that was hit.
  659. Actor
  660. -----
  661. **actor_destroy** (pw, actor)
  662. Destroys the *actor* instance.
  663. **actor_instance** (pw, unit) : Id
  664. Returns the ID of the actor owned by the *unit*, or ``nil``.
  665. **actor_world_position** (pw, actor) : Vector3
  666. Returns the world position of the *actor*.
  667. **actor_world_rotation** (pw, actor) : Quaternion
  668. Returns the world rotation of the *actor*.
  669. **actor_world_pose** (pw, actor) : Matrix4x4
  670. Returns the world pose of the *actor*.
  671. **actor_teleport_world_position** (pw, actor, position)
  672. Teleports the *actor* to the given world *position*.
  673. **actor_teleport_world_rotation** (pw, actor, rotation)
  674. Teleports the *actor* to the given world *rotation*.
  675. **actor_teleport_world_pose** (pw, actor, pose)
  676. Teleports the *actor* to the given world *pose*.
  677. **actor_center_of_mass** (pw, actor) : Vector3
  678. Returns the center of mass of the *actor*.
  679. **actor_enable_gravity** (pw, actor)
  680. Enables gravity for the *actor*.
  681. **actor_disable_gravity** (pw, actor)
  682. Disables gravity for the *actor*.
  683. **actor_enable_collision** (pw, actor)
  684. Enables collision detection for the *actor*.
  685. **actor_disable_collision** (pw, actor)
  686. Disables collision detection for the *actor*.
  687. **actor_set_collision_filter** (pw, actor, name)
  688. Sets the collision filter of the *actor*.
  689. **actor_set_kinematic** (pw, actor, kinematic)
  690. Sets whether the *actor* is *kinematic* or not.
  691. .. note::
  692. This call has no effect on static actors.
  693. **actor_is_static** (pw, actor) : bool
  694. Returns whether the *actor* is static.
  695. **actor_is_dynamic** (pw, actor) bool
  696. Returns whether the *actor* is dynamic.
  697. **actor_is_kinematic** (pw, actor) : bool
  698. Returns whether the *actor* is kinematic (keyframed).
  699. **actor_is_nonkinematic** (pw, actor) : bool
  700. Returns whether the *actor* is nonkinematic (i.e. dynamic and not kinematic).
  701. **actor_linear_damping** (pw, actor) : float
  702. Returns the linear damping of the *actor*.
  703. **actor_set_linear_damping** (pw, actor, damping)
  704. Sets the linear *damping* of the *actor*.
  705. **actor_angular_damping** (pw, actor) : float
  706. Returns the angular damping rate of the *actor*.
  707. **actor_set_angular_damping** (pw, actor, rate)
  708. Sets the angular damping *rate* of the *actor*.
  709. **actor_linear_velocity** (pw, actor) : Vector3
  710. Returns the linear velocity of the *actor*.
  711. **actor_set_linear_velocity** (pw, actor, velocity)
  712. Sets the linear *velocity* of the *actor*.
  713. .. note::
  714. This call only affects nonkinematic actors.
  715. **actor_angular_velocity** (pw, actor) : Vector3
  716. Returns the angular velocity of the *actor*.
  717. **actor_set_angular_velocity** (pw, actor, velocity)
  718. Sets the angular *velocity* of the *actor*.
  719. .. note::
  720. This call only affects nonkinematic actors.
  721. **actor_add_impulse** (pw, actor, impulse)
  722. Adds a linear *impulse* (acting along the center of mass) to the *actor*.
  723. .. note::
  724. This call only affects nonkinematic actors.
  725. **actor_add_impulse_at** (pw, actor, impulse, position)
  726. Adds a linear *impulse* (acting along the world position *pos*) to the *actor*.
  727. .. note::
  728. This call only affects nonkinematic actors.
  729. **actor_add_torque_impulse** (pw, actor, impulse)
  730. Adds a torque *impulse* to the *actor*.
  731. **actor_push** (pw, actor, velocity, mass)
  732. Pushes the *actor* as if it was hit by a point object with the given *mass*
  733. travelling at the given *velocity*.
  734. .. note::
  735. This call only affects nonkinematic actors.
  736. **actor_push_at** (pw, actor, velocity, mass, position)
  737. Like push() but applies the force at the world *position*.
  738. .. note::
  739. This call only affects nonkinematic actors.
  740. **actor_is_sleeping** (pw, actor) : bool
  741. Returns whether the *actor* is sleeping.
  742. **actor_wake_up** (pw, actor)
  743. Wakes the *actor* up.
  744. Mover
  745. -----
  746. **mover_create** (pw, unit, height, radius, max_slope_angle, collision_filter) : Id
  747. Creates a new mover instance for the *unit*.
  748. **mover_destroy** (pw, mover)
  749. Destroys the *mover*.
  750. **mover** (pw, unit) : Id
  751. Returns the ID of the mover owned by the *unit*.
  752. **mover_radius** (pw, mover) : number
  753. Returns the radius of the *mover* capsule.
  754. **mover_max_slope_angle** (pw, mover) : number
  755. Returns the max slope angle of the *mover*.
  756. **mover_set_max_slope_angle** (pw, mover, angle)
  757. Sets the max slope *angle* of the *mover*.
  758. **mover_set_collision_filter** (pw, mover, filter)
  759. Sets the collision *filter* of the *mover*.
  760. **mover_position** (pw, mover) : Vector3
  761. Returns the position of the *mover*.
  762. **mover_set_position** (pw, mover, position)
  763. Teleports the *mover* to the specified *position*.
  764. **mover_move** (pw, mover, delta)
  765. Attempts to move the *mover* by the specified *delta* vector.
  766. The *mover* will slide against physical actors.
  767. **mover_collides_sides** (pw, mover) : bool
  768. Returns whether the *mover* collides sideways.
  769. **mover_collides_up** (pw, mover) : bool
  770. Returns whether the *mover* collides upwards.
  771. **mover_collides_down** (pw, mover) : bool
  772. Returns whether the *mover* collides downwards.
  773. Profiler
  774. ========
  775. **enter_scope** (name)
  776. Starts a new profile scope with the given *name*.
  777. **leave_scope** ()
  778. Ends the last profile scope.
  779. **record** (name, value)
  780. Records *value* with the given *name*. Value can be either number or Vector3.
  781. RenderWorld
  782. ===========
  783. **enable_debug_drawing** (rw, enable)
  784. Sets whether to *enable* debug drawing.
  785. Mesh
  786. ----
  787. **mesh_create** (rw, unit, mesh_resource, geometry_name, material_resource, visible) : Id
  788. Creates a new mesh instance for *unit* and returns its id.
  789. **mesh_destroy** (rw, mesh)
  790. Destroys the *mesh* instance.
  791. **mesh_instance** (rw, unit) : Id
  792. Returns the ID of the mesh owned by the *unit*, or ``nil``.
  793. **mesh_material** (rw, mesh) : Material
  794. Returns the material of the *mesh*.
  795. **mesh_set_material** (rw, mesh, material)
  796. Sets the *material* of the *mesh*.
  797. **mesh_set_visible** (rw, mesh, visible)
  798. Sets whether the *mesh* is *visible*.
  799. **mesh_set_cast_shadows** (rw, mesh, cast_shadows)
  800. Sets whether the *mesh* cast shadows.
  801. **mesh_obb** (rw, mesh) : Matrix4x4, Vector3
  802. Returns the Oriented-Bounding-Box of the *mesh* as (pose, half_extents).
  803. **mesh_cast_ray** (rw, mesh, from, dir) : float
  804. Returns the distance along ray (from, dir) to intersection point with the *mesh* or -1.0 if no intersection.
  805. Sprite
  806. ------
  807. **sprite_create** (rw, unit, sprite_resource, material_resource, visible) : Id
  808. Creates a new sprite instance for the *unit* and returns its id.
  809. **sprite_destroy** (rw, sprite)
  810. Destroys the *sprite* instance.
  811. **sprite_instance** (rw, unit) : Id
  812. Returns the ID of the sprite owned by the *unit*, or ``nil``.
  813. **sprite_material** (rw, sprite) : Material
  814. Returns the material of the *sprite*.
  815. **sprite_set_material** (rw, sprite, material)
  816. Sets the *material* of the *sprite*.
  817. **sprite_set_frame** (rw, sprite, index)
  818. Sets the frame *index* of the *sprite*.
  819. The *index* automatically wraps if it greater than the total number of
  820. frames in the sprite.
  821. **sprite_set_visible** (rw, sprite, visible)
  822. Sets whether the *sprite* is *visible*.
  823. **sprite_flip_x** (rw, sprite, flip)
  824. Sets whether to flip the *sprite* on the x-axis.
  825. **sprite_flip_y** (rw, sprite, flip)
  826. Sets whether to flip the *sprite* on the y-axis.
  827. **sprite_set_layer** (rw, sprite, layer)
  828. Sets the rendering *layer* of the *sprite*.
  829. **sprite_set_depth** (rw, sprite, depth)
  830. Sets the rendering *depth* of the *sprite*.
  831. **sprite_obb** (rw, sprite) : Matrix4x4, Vector3
  832. Returns the Oriented-Bounding-Box of the *sprite* as (pose, half_extents).
  833. **sprite_cast_ray** (rw, sprite, from, dir) : float, int, int
  834. Returns (t, layer, depth), where *t* is the distance along ray (from, dir) to
  835. intersection point with the *sprite* or -1.0 if no intersection.
  836. Light
  837. -----
  838. **light_create** (rw, unit, type, range, intensity, spot_angle, color) : Id
  839. Creates a new light for the *unit* and returns its id.
  840. Type can be either ``directional``, ``omni`` or ``spot``.
  841. **light_destroy** (rw, light)
  842. Destroys the *light* instance.
  843. **light_instance** (rw, unit) : Id
  844. Returns the ID of the light owned by the *unit*, or ``nil``.
  845. **light_type** (rw, light) : string
  846. Returns the type of the *light*.
  847. It can be either ``directional``, ``omni`` or ``spot``.
  848. **light_color** (rw, light) : Color4
  849. Returns the color of the *light*.
  850. **light_range** (rw, light) : float
  851. Returns the range of the *light*.
  852. **light_intensity** (rw, light) : float
  853. Returns the intensity of the *light*.
  854. **light_spot_angle** (rw, light) : float
  855. Returns the spot angle of the *light*.
  856. **light_shadow_bias** (rw, light) : float
  857. Returns the shadow bias of the *light*.
  858. **light_set_type** (rw, light, type)
  859. Sets the *type* of the *light*.
  860. **light_set_color** (rw, light, color)
  861. Sets the *color* of the *light*.
  862. **light_set_range** (rw, light, range)
  863. Sets the *range* of the *light*.
  864. **light_set_intensity** (rw, light, intensity)
  865. Sets the *intensity* of the *light*.
  866. **light_set_spot_angle** (rw, light, angle)
  867. Sets the spot *angle* of the *light*.
  868. **light_set_shadow_bias** (rw, light, bias)
  869. Sets the shadow *bias* of the *light*.
  870. **light_set_cast_shadows** (rw, light, cast_shadows)
  871. Sets whether the *light* casts shadows.
  872. **light_debug_draw** (rw, light, debug_line)
  873. Fills *debug_line* with debug lines from the *light*.
  874. Fog
  875. ---
  876. **fog_create** (rw, unit) : Id
  877. Creates a new fog instance for the *unit* and returns its id.
  878. Note that the fog component is limited to one instance per World. Every call
  879. to this function will overwrite any previously created fog instance.
  880. **fog_destroy** (rw, fog)
  881. Destroys the *fog* instance.
  882. **fog_instance** (rw, unit) : Id
  883. Returns the ID of the fog owned by the *unit*, or ``nil``.
  884. **fog_set_color** (rw, fog, color)
  885. Sets the *color* of the *fog*.
  886. **fog_set_density** (rw, fog, density)
  887. Sets the *density* of the *fog*.
  888. **fog_set_range_min** (rw, fog, range)
  889. Sets the minimum *range* of the *fog*.
  890. **fog_set_range_max** (rw, fog, range)
  891. Sets the maximum *range* of the *fog*.
  892. **fog_set_sun_blend** (rw, fog, sun_blend)
  893. Sets the sun *blend* of the *fog*.
  894. **fog_set_enabled** (rw, fog, enable)
  895. Sets whether the *fog* is *enabled*.
  896. ResourcePackage
  897. ===============
  898. **load** (package)
  899. Loads all the resources in the *package*.
  900. .. note::
  901. The resources are not immediately available after the call is made,
  902. instead, you have to poll for completion with has_loaded().
  903. **unload** (package)
  904. Unloads all the resources in the *package*.
  905. **flush** (package)
  906. Waits until the *package* has been loaded.
  907. **has_loaded** (package) : bool
  908. Returns whether the *package* has been loaded.
  909. SceneGraph
  910. ==========
  911. **create** (sg, unit, position, rotation, scale) : Id
  912. Creates the transform for the *unit* and returns its ID.
  913. **destroy** (sg, transform)
  914. Destroys the *transform* instance.
  915. **instance** (sg, unit) : Id
  916. Returns the ID of the transform owned by the *unit*, or ``nil``.
  917. **owner** (sg, transform) : UnitId
  918. Returns the unit that owns *transform*.
  919. **local_position** (sg, transform) : Vector3
  920. Returns the local position of the *transform*.
  921. **local_rotation** (sg, transform) : Quaternion
  922. Returns the local rotation of the *transform*.
  923. **local_scale** (sg, transform) : Vector3
  924. Returns the local scale of the *transform*.
  925. **local_pose** (sg, transform) : Matrix4x4
  926. Returns the local pose of the *transform*.
  927. **world_position** (sg, transform) : Vector3
  928. Returns the world position of the *transform*.
  929. **world_rotation** (sg, transform) : Quaternion
  930. Returns the world rotation of the *transform*.
  931. **world_pose** (sg, transform) : Matrix4x4
  932. Returns the world pose of the *transform*.
  933. **set_local_position** (sg, transform, position)
  934. Sets the local *position* of the *transform*.
  935. **set_local_rotation** (sg, transform, rotation)
  936. Sets the local *rotation* of the *transform*.
  937. **set_local_scale** (sg, transform, scale)
  938. Sets the local *scale* of the *transform*.
  939. **set_local_pose** (sg, transform, pose)
  940. Sets the local *pose* of the *transform*.
  941. **link** (sg, parent, child, child_local_position, child_local_rotation, child_local_scale)
  942. Links *child* to *parent*. After linking the child will follow its
  943. parent. Set child_local_* to modify the child position after it has been
  944. linked to the parent, otherwise che child will be positioned at the
  945. location of its parent.
  946. **unlink** (sg, child)
  947. Unlinks *child* from its parent if it has any. After unlinking, the local
  948. pose of the *child* is set to its previous world pose.
  949. **parent** (sg, child) : Id
  950. Returns the parent of the instance *child* or ``nil``
  951. if *child* has no parent.
  952. **first_child** (sg, parent) : Id
  953. Returns the first child of the instance *parent* or ``nil``
  954. if *parent* has no children.
  955. **next_sibling** (sg, child) : Id
  956. Returns the next sibling of the instance *child* or ``nil``
  957. if *child* has no sibling.
  958. SoundWorld
  959. ===========
  960. **stop_all** (sound_world)
  961. Stops all the sounds in the world.
  962. **pause_all** (sound_world)
  963. Pauses all the sounds in the world
  964. **resume_all** (sound_world)
  965. Resumes all previously paused sounds in the world.
  966. **is_playing** (sound_world, id) : bool
  967. Returns whether the sound *id* is playing.
  968. **set_group_volume** (sound_world, group, volume)
  969. Sets the *volume* of the sound *group*. The volume of the sounds within
  970. *group* is multiplied by the group's volume.
  971. UnitManager
  972. ===========
  973. **create** ([world]) : UnitId
  974. Creates a new empty unit. If *world* is specified, the unit will be owned by
  975. that world.
  976. **destroy** (unit)
  977. Destroys the given *unit*.
  978. **alive** (unit) : bool
  979. Returns whether the unit is alive.
  980. Window
  981. ======
  982. **show** ()
  983. Shows the window.
  984. **hide** ()
  985. Hides the window.
  986. **resize** (width, height)
  987. Resizes the window to *width* and *height*.
  988. **move** (x, y)
  989. Moves the window to *x* and *y*.
  990. **minimize** ()
  991. Minimizes the window.
  992. **maximize** ()
  993. Maximizes the window.
  994. **restore** ()
  995. Restores the window.
  996. **title** () : string
  997. Returns the title of the window.
  998. **set_title** (title)
  999. Sets the title of the window.
  1000. **show_cursor** (show)
  1001. Sets whether to *show* the cursor.
  1002. **set_fullscreen** (fullscreen)
  1003. Sets whether the window is *fullscreen*.
  1004. **set_cursor** (cursor)
  1005. Sets the mouse *cursor* on this window. Cursor can be any of ``arrow``,
  1006. ``hand``, ``text_input``, ``corner_top_left``, ``corner_top_right``,
  1007. ``corner_bottom_left``, ``corner_bottom_right``, ``size_horizontal``,
  1008. ``size_vertical`` or ``wait``.
  1009. **set_cursor_mode** (cursor, mode)
  1010. Sets the mouse cursor *mode* on this window. Mode can be either ``normal``
  1011. or ``disabled``. Setting the mode to ``disabled`` hides the cursor and
  1012. automatically re-centers it every time it is moved.
  1013. World
  1014. =====
  1015. **spawn_unit** (world, name, [position, rotation, scale]) : UnitId
  1016. Spawns a new instance of the unit *name* at the given *position*, *rotation* and *scale*.
  1017. **spawn_empty_unit** (world) : UnitId
  1018. Spawns a new empty unit and returns its id.
  1019. **destroy_unit** (world, unit)
  1020. Destroys the given *unit*.
  1021. **num_units** (world) : int
  1022. Returns the number of units in the *world*.
  1023. **units** (world) : table
  1024. Returns all the the units in the world in a table.
  1025. **unit_by_name** (world, name) : UnitId
  1026. Returns the unit with the given Level Editor *name* or ``nil`` if no such unit is found.
  1027. If there are multiple units with the same name, a random one will be returned.
  1028. **update_animations** (world, dt)
  1029. Update all animations with *dt*.
  1030. **update_scene** (world, dt)
  1031. Updates the scene with *dt*.
  1032. **update** (world, dt)
  1033. Updates the world with *dt*.
  1034. **create_debug_line** (world, depth_test) : DebugLine
  1035. Creates a new DebugLine. *depth_test* controls whether to
  1036. enable depth test when rendering the lines.
  1037. **destroy_debug_line** (world, line)
  1038. Destroys the debug *line*.
  1039. **create_screen_gui** (world) : Gui
  1040. Creates a new Gui for 2D drawing.
  1041. **create_world_gui** (world) : Gui
  1042. Creates a new Gui for 3D drawing.
  1043. **destroy_gui** (world, gui)
  1044. Destroys the *gui*.
  1045. **scene_graph** (world) : SceneGraph
  1046. Returns the scene graph.
  1047. **render_world** (world) : RenderWorld
  1048. Returns the render sub-world.
  1049. **physics_world** (world) : PhysicsWorld
  1050. Returns the physics sub-world.
  1051. **sound_world** (world) : SoundWorld
  1052. Returns the sound sub-world.
  1053. **animation_state_machine** (world) : AnimationStateMachine
  1054. Returns the animation state machine.
  1055. Camera
  1056. ------
  1057. **camera_create** (world, unit, projection, fov, far_range, near_range) : Id
  1058. Creates a new camera for *unit* and returns its id.
  1059. Projection can be either ``orthographic`` or ``perspective``.
  1060. **camera_destroy** (world, camera)
  1061. Destroys the *camera* instance.
  1062. **camera_instance** (world, unit) : Id
  1063. Returns the ID of the camera owned by the *unit*, or ``nil``.
  1064. **camera_set_projection_type** (world, camera, projection)
  1065. Sets the projection type of the *camera*.
  1066. Projection can be either ``orthographic`` or ``perspective``.
  1067. **camera_projection_type** (world, camera) : string
  1068. Returns the projection type of the *camera*.
  1069. It can be either ``orthographic`` or ``perspective``.
  1070. **camera_fov** (world, camera) : float
  1071. Returns the field-of-view of the *camera* in degrees.
  1072. **camera_set_fov** (world, camera, fov)
  1073. Sets the field-of-view of the *camera* in degrees.
  1074. **camera_near_clip_distance** (world, camera) : float
  1075. Returns the near clip distance of the *camera*.
  1076. **camera_set_near_clip_distance** (world, camera, near)
  1077. Sets the near clip distance of the *camera*.
  1078. **camera_far_clip_distance** (world, camera) : float
  1079. Returns the far clip distance of the *camera*.
  1080. **camera_set_far_clip_distance** (world, camera, far)
  1081. Sets the far clip distance of the *camera*.
  1082. **camera_set_orthographic_size** (world, camera, half_size)
  1083. Sets the vertical *half_size* of the orthographic view volume.
  1084. The horizontal size is proportional to the viewport's aspect ratio.
  1085. **camera_screen_to_world** (world, camera, pos) : Vector3
  1086. Returns *pos* from screen-space to world-space coordinates.
  1087. **camera_world_to_screen** (world, camera, pos) : Vector3
  1088. Returns *pos* from world-space to screen-space coordinates.
  1089. Sound
  1090. -----
  1091. **play_sound** (world, name, [loop = false, volume = 1.0, range = 70.0, position = nil, group = nil]) : SoundInstanceId
  1092. Plays the sound with the given *name*. If the listener is further away than
  1093. *range* the sound will not be heard. If *position* is not specified the
  1094. sound will be played as a 2d-sound (i.e. no attenuation nor spatialization).
  1095. *group* is a string that identifies the sound's group, see ``SoundWorld.set_group_volume()``.
  1096. **stop_sound** (world, id)
  1097. Stops the sound with the given *id*.
  1098. **link_sound** (world, id, unit, node)
  1099. Links the sound *id* to the *node* of the given *unit*.
  1100. After this call, the sound *id* will follow the unit *unit*.
  1101. **set_listener_pose** (world, pose)
  1102. Sets the *pose* of the listener.
  1103. **set_sound_position** (world, id, position)
  1104. Sets the *position* of the sound *id*.
  1105. **set_sound_range** (world, id, range)
  1106. Sets the *range* of the sound *id*.
  1107. **set_sound_volume** (world, id, volume)
  1108. Sets the *volume* of the sound *id*.
  1109. Level
  1110. -----
  1111. **load_level** (world, name, [pos, rot]) : Level
  1112. Loads the level *name* into the world at the given *position* and *rotation*.
  1113. **destroy_level** (world, level)
  1114. Destroys a level previously loaded by load_level(). Only units directly
  1115. spawned by the level are unspawned.