lua_api.rst 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383
  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])
  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. **add_unit** (debug_line, tm, name, color)
  36. Adds the meshes from the unit *name*.
  37. **reset** (debug_line)
  38. Resets all the lines.
  39. **submit** (debug_line)
  40. Submits the lines to renderer for drawing.
  41. Device
  42. ======
  43. **argv** () : table
  44. Returns a table containing the command line parameters the engine was started with.
  45. **platform** () : string
  46. Returns a string identifying what platform the engine is running on.
  47. It can be either ``android``, ``linux`` or ``windows``
  48. **architecture** () : string
  49. Returns a string identifying what architecture the engine is running on.
  50. It can be either ``32-bit`` or ``64-bit``.
  51. **version** () : string
  52. Returns a string identifying the engine version.
  53. The form is "major.minor.micro".
  54. **quit** ()
  55. Quits the application.
  56. **resolution** () : float, float
  57. Returns the main window resolution (width, height).
  58. **create_world** () : World
  59. Creates a new world.
  60. **destroy_world** (world)
  61. Destroys the given *world*.
  62. **render** (world, camera)
  63. Renders *world* using *camera*.
  64. **create_resource_package** (name) : ResourcePackage
  65. Returns the resource package with the given *package_name* name.
  66. **destroy_resource_package** (package)
  67. Destroy a previously created resource *package*.
  68. .. note::
  69. To unload the resources loaded by the package, you have to call
  70. ResourcePackage.unload() first.
  71. **console_send** (table)
  72. Sends the given lua *table* to clients connected to the engine.
  73. Values can be either ``nil``, bool, number, string, table, array, Vector2, Vector3, Quaternion, Matrix4x4 or Color4.
  74. **can_get** (type, name) : bool
  75. Returns whether the resource (type, name) is loaded.
  76. When resource autoload is enabled it always returns true.
  77. **enable_resource_autoload** (enable)
  78. Sets whether resources should be automatically loaded when accessed.
  79. **temp_count** () : int, int, int
  80. Returns the number of temporary objects used by Lua.
  81. **set_temp_count** (nv, nq, nm)
  82. Sets the number of temporary objects used by Lua.
  83. **guid** () : string
  84. Returns a new GUID.
  85. Display
  86. =======
  87. **modes** () : table
  88. Returns an array of `DisplayMode`_ tables.
  89. **set_mode** (id)
  90. Sets the display mode *id*.
  91. The initial display mode is automatically reset when the program terminates.
  92. DisplayMode
  93. -----------
  94. DisplayMode is a lua table with 3 fields:
  95. * ``id``: The id of the display mode.
  96. * ``width``: The width of the display mode.
  97. * ``height``: The height of the display mode.
  98. Gui
  99. ===
  100. **move** (gui, pos)
  101. Moves the Gui to *pos*.
  102. **triangle** (gui, a, b, c, color)
  103. Draws a triangle defined by vertices *a*, *b* and *c*.
  104. **rect** (gui, pos, size, color)
  105. Draws a rectangle.
  106. **image** (gui, pos, size, material_resource, color)
  107. Draws an image.
  108. **image_uv** (gui, pos, size, uv0, uv1, material_resource, color)
  109. Draws an image with explicit UV coordinates.
  110. **text** (gui, pos, font_size, str, font_resource, material_resource, color)
  111. Draws text.
  112. Input
  113. =====
  114. Keyboard
  115. --------
  116. **name** () : string
  117. Returns the name of keyboard.
  118. **connected** () : bool
  119. Returns whether the keyboard is connected and functioning.
  120. **num_buttons** () : int
  121. Returns the number of buttons of the keyboard.
  122. **num_axes** () : int
  123. Returns the number of axes of the keyboard.
  124. **pressed** (id) : bool
  125. Returns whether the button *id* is pressed in the current frame.
  126. **released** (id) : bool
  127. Returns whether the button *id* is released in the current frame.
  128. **any_pressed** () : bool
  129. Returns the *id* of the first button that was pressed in the current frame
  130. or ``nil`` if no buttons were pressed at all.
  131. **any_released** () : bool
  132. Returns the *id* of the first button that was released in the current frame
  133. or ``nil`` if no buttons were released at all.
  134. **button** (id) : float
  135. Returns the value of the button *id* in the range [0..1].
  136. **button_name** (id) : string
  137. Returns the name of the button *id*.
  138. **button_id** (name) : int
  139. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  140. Keyboard Button Names
  141. ~~~~~~~~~~~~~~~~~~~~~
  142. * ``tab``, ``enter``, ``escape``, ``space``, ``backspace``
  143. * ``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``
  144. * ``f1``, ``f2``, ``f3``, ``f4``, ``f5``, ``f6``, ``f7``, ``f8``, ``f9``, ``f10``, ``f11``, ``f12``
  145. * ``home``, ``left``, ``up``, ``right``, ``down``, ``page_up``, ``page_down``, ``ins``, ``del``, ``end``
  146. * ``ctrl_left``, ``ctrl_right``, ``shift_left``, ``shift_right``, ``caps_lock``, ``alt_left``, ``alt_right``, ``super_left``, ``super_right``
  147. * ``0``, ``1``, ``2``, ``3``, ``4``, ``5``, ``6``, ``7``, ``8``, ``9``
  148. * ``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``
  149. Keyboard Axis Names
  150. ~~~~~~~~~~~~~~~~~~~
  151. None.
  152. Mouse
  153. -----
  154. **name** () : string
  155. Returns the name of the mouse.
  156. **connected** () : bool
  157. Returns whether the mouse is connected and functioning.
  158. **num_buttons** () : int
  159. Returns the number of buttons of the mouse.
  160. **num_axes** () : int
  161. Returns the number of axes of the mouse.
  162. **pressed** (id) : bool
  163. Returns whether the button *id* is pressed in the current frame.
  164. **released** (id) : bool
  165. Returns whether the button *id* is released in the current frame.
  166. **any_pressed** () : bool
  167. Returns the *id* of the first button that was pressed in the current frame
  168. or ``nil`` if no buttons were pressed at all.
  169. **any_released** () : bool
  170. Returns the *id* of the first button that was released in the current frame
  171. or ``nil`` if no buttons were released at all.
  172. **button** (id) : float
  173. Returns the value of the button *id* in the range [0..1].
  174. **axis** (id) : Vector3
  175. Returns the value of the axis *id*.
  176. **button_name** (id) : string
  177. Returns the name of the button *id*.
  178. **axis_name** (id) : string
  179. Returns the name of the axis *id*.
  180. **button_id** (name) : int
  181. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  182. **axis_id** (name) : int
  183. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  184. Mouse Button Names
  185. ~~~~~~~~~~~~~~~~~~
  186. ``left``, ``middle``, ``right``, ``extra_1``, ``extra_2``
  187. Mouse Axis Names
  188. ~~~~~~~~~~~~~~~~
  189. * ``cursor``: Returns the cursor position (x, y) in screen coordinates.
  190. * ``cursor_delta``: Returns the delta of the cursor position (x, y) since last frame.
  191. * ``wheel``: Returns the movement of the mouse wheel in the y axis. Positive values of y mean upward scrolling, negative values mean downward scrolling.
  192. Touch
  193. -----
  194. **name** () : string
  195. Returns the name of the touch.
  196. **connected** () : bool
  197. Returns whether the touch is connected and functioning.
  198. **num_buttons** () : int
  199. Returns the number of buttons of the touch.
  200. **num_axes** () : int
  201. Returns the number of axes of the touch.
  202. **pressed** (id) : bool
  203. Returns whether the button *id* is pressed in the current frame.
  204. **released** (id) : bool
  205. Returns whether the button *id* is released in the current frame.
  206. **any_pressed** () : bool
  207. Returns the *id* of the first button that was pressed in the current frame
  208. or ``nil`` if no buttons were pressed at all.
  209. **any_released** () : bool
  210. Returns the *id* of the first button that was released in the current frame
  211. or ``nil`` if no buttons were released at all.
  212. **button** (id) : float
  213. Returns the value of the button *id* in the range [0..1].
  214. **axis** (id) : Vector3
  215. Returns the value of the axis *id*.
  216. **button_name** (id) : string
  217. Returns the name of the button *id*.
  218. **axis_name** (id) : string
  219. Returns the name of the axis *id*.
  220. **button_id** (name) : int
  221. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  222. **axis_id** (name) : int
  223. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  224. Pad1, Pad2, Pad3, Pad4
  225. ----------------------
  226. **name** () : string
  227. Returns the name of the pad.
  228. **connected** () : bool
  229. Returns whether the pad is connected and functioning.
  230. **num_buttons** () : int
  231. Returns the number of buttons of the pad.
  232. **num_axes** () : int
  233. Returns the number of axes of the pad.
  234. **pressed** (id) : bool
  235. Returns whether the button *id* is pressed in the current frame.
  236. **released** (id) : bool
  237. Returns whether the button *id* is released in the current frame.
  238. **any_pressed** () : bool
  239. Returns the *id* of the first button that was pressed in the current frame
  240. or ``nil`` if no buttons were pressed at all.
  241. **any_released** () : bool
  242. Returns the *id* of the first button that was released in the current frame
  243. or ``nil`` if no buttons were released at all.
  244. **button** (id) : float
  245. Returns the value of the button *id* in the range [0..1].
  246. **axis** (id) : Vector3
  247. Returns the value of the axis *id*.
  248. **button_name** (id) : string
  249. Returns the name of the button *id*.
  250. **axis_name** (id) : string
  251. Returns the name of the axis *id*.
  252. **button_id** (name) : int
  253. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  254. **axis_id** (name) : int
  255. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  256. **deadzone** (id) : deadzone_mode, deadzone_size
  257. Returns the deadzone mode and size for the axis *id*.
  258. **set_deadzone** (id, deadzone_mode, deadzone_size)
  259. Sets the *deadzone_mode* and *deadzone_size* for the axis *id*.
  260. Pad Button Names
  261. ~~~~~~~~~~~~~~~~
  262. * ``up``, ``down``, ``left``, ``right``
  263. * ``start``, ``back``, ``guide``
  264. * ``thumb_left``, ``thumb_right``
  265. * ``shoulder_left``, ``shoulder_right``
  266. * ``a``, ``b``, ``x``, ``y``
  267. Pad Axis Names
  268. ~~~~~~~~~~~~~~
  269. * ``left``, ``right``: Returns the direction (x, y) of the left or right thumbstick [-1; +1].
  270. * ``trigger_left``, ``trigger_right``: The z element represents the left or right trigger [0; +1].
  271. Material
  272. ========
  273. **set_float** (material, name, value)
  274. Sets the *value* of the variable *name*.
  275. **set_vector2** (material, name, value)
  276. Sets the *value* of the variable *name*.
  277. **set_vector3** (material, name, value)
  278. Sets the *value* of the variable *name*.
  279. **set_vector4** (material, name, value)
  280. Sets the *value* of the variable *name*.
  281. **set_matrix4x4** (material, name, value)
  282. Sets the *value* of the variable *name*.
  283. Math
  284. ====
  285. Vector3
  286. -------
  287. Constructors
  288. ~~~~~~~~~~~~
  289. **Vector3** (x, y, z) : Vector3
  290. Returns a new vector from individual elements.
  291. Functions
  292. ~~~~~~~~~
  293. **x** (v) : float
  294. Returns the x value of the vector.
  295. **y** (v) : float
  296. Returns the y value of the vector.
  297. **z** (v) : float
  298. Returns the z value of the vector.
  299. **.x** : float
  300. Returns/assigns the x value of the vector.
  301. **.y** : float
  302. Returns/assigns the y value of the vector.
  303. **.z** : float
  304. Returns/assigns the z value of the vector.
  305. **set_x** (v, x)
  306. Sets the value of the x value of the vector.
  307. **set_y** (v, y)
  308. Sets the value of the y value of the vector.
  309. **set_z** (v, z)
  310. Sets the value of the z value of the vector.
  311. **elements** (v) : float, float, float
  312. Returns the x, y and z elements of the vector.
  313. **add** (a, b) : Vector3
  314. Adds the vector *a* to *b* and returns the result.
  315. **subtract** (a, b) : Vector3
  316. Subtracts the vector *b* from *a* and returns the result.
  317. **multiply** (a, k) : Vector3
  318. Multiplies the vector *a* by the scalar *k* and returns the result.
  319. **dot** (a, b) : float
  320. Returns the dot product between the vectors *a* and *b*.
  321. **cross** (a, b) : Vector3
  322. Returns the cross product between the vectors *a* and *b*.
  323. **equal** (a, b) : bool
  324. Returns true whether the vectors *a* and *b* are equal.
  325. **length** (a) : float
  326. Returns the length of *a*.
  327. **length_squared** (a) : float
  328. Returns the squared length of *a*.
  329. **set_length** (a, len)
  330. Sets the length of *a* to *len*.
  331. **normalize** (a) : Vector3
  332. Normalizes *a* and returns the result.
  333. **distance** (a, b) : float
  334. Returns the distance between the points *a* and *b*.
  335. **distance_squared** (a, b) : float
  336. Returns the squared distance between the points *a* and *b*.
  337. **angle** (a, b) : float
  338. Returns the angle between the vectors *a* and *b*.
  339. **max** (a, b) : Vector3
  340. Returns a vector that contains the largest value for each element from *a* and *b*.
  341. **min** (a, b) : Vector3
  342. Returns a vector that contains the smallest value for each element from *a* and *b*.
  343. **lerp** (a, b, t) : Vector3
  344. Returns the linearly interpolated vector between *a* and *b* at time *t* in [0, 1].
  345. | **forward** () : Vector3
  346. | **backward** () : Vector3
  347. | **left** () : Vector3
  348. | **right** () : Vector3
  349. | **up** () : Vector3
  350. | **down** () : Vector3
  351. | Returns the corresponding semantic axis.
  352. **zero** () : Vector3
  353. Returns a vector with all values set to zero.
  354. **to_string** (v) : string
  355. Returns a string representing the vector *v*.
  356. Vector3Box
  357. ----------
  358. Constructors
  359. ~~~~~~~~~~~~
  360. **Vector3Box** () : Vector3Box
  361. Returns a new Vector3Box initialized with the zero vector.
  362. **Vector3Box** (v) : Vector3Box
  363. Returns a new Vector3Box from the Vector3 *v*.
  364. **Vector3Box** (x, y, z) : Vector3Box
  365. Returns a new Vector3Box from individual elements.
  366. Functions
  367. ~~~~~~~~~
  368. **store** (v)
  369. Stores the Vector3 *v* in the box.
  370. **store** (x, y, z)
  371. Stores Vector3(x, y, z) in the box.
  372. **unbox** () : Vector3
  373. Returns the stored vector from the box.
  374. Quaternion
  375. ----------
  376. Constructors
  377. ~~~~~~~~~~~~
  378. **Quaternion** (axis, angle) : Quaternion
  379. Returns a new quaternion from *axis* and *angle*.
  380. **from_elements** (x, y, z, w) : Quaternion
  381. Returns a new quaternion from individual elements.
  382. **from_axis_angle** (axis, angle) : Quaternion
  383. Returns a new quaternion from *axis* and *angle*.
  384. Functions
  385. ~~~~~~~~~
  386. **negate** (q) : Quaternion
  387. Negates the quaternion *q* and returns the result.
  388. **identity** () : Quaternion
  389. Returns the identity quaternion.
  390. **multiply** (a, b) : Quaternion
  391. Multiplies the quaternions *a* and *b*. (i.e. rotates first by *a* then by *b*).
  392. **multiply_by_scalar** (a, k) : Quaternion
  393. Multiplies the quaternion *a* by the scalar *k*.
  394. **dot** (a, b) : float
  395. Returns the dot product between quaternions *a* and *b*.
  396. **length** (q) : float
  397. Returns the length of *q*.
  398. **normalize** (q) : Quaternion
  399. Normalizes the quaternion *q* and returns the result.
  400. **conjugate** (q) : Quaternion
  401. Returns the conjugate of quaternion *q*.
  402. **inverse** (q) : Quaternion
  403. Returns the inverse of quaternion *q*.
  404. **power** (q, exp) : Quaternion
  405. Returns the quaternion *q* raised to the power of *exp*.
  406. **elements** (q) : float, float, float, float
  407. Returns the x, y, z and w elements of the quaternion.
  408. **look** (dir, [up]) : Quaternion
  409. Returns the quaternion describing the rotation needed to face towards *dir*.
  410. If *up* is not specified, Vector3.up() is used.
  411. **right** (q) : Vector3
  412. Returns the right axis of the rotation described by *q*.
  413. **up** (q) : Vector3
  414. Returns the up axis of the rotation described by *q*.
  415. **forward** (q) : Vector3
  416. Returns the forward axis of the rotation described by *q*.
  417. **lerp** (a, b, t) : Quaternion
  418. Returns the linearly interpolated quaternion between *a* and *b* at time *t* in [0, 1].
  419. It uses NLerp.
  420. **to_string** (q) : string
  421. Returns a string representing the quaternion *q*.
  422. QuaternionBox
  423. -------------
  424. Constructors
  425. ~~~~~~~~~~~~
  426. **QuaternionBox** () : QuaternionBox
  427. Returns a new QuaternionBox initialized with the identity quaternion.
  428. **QuaternionBox** (q) : QuaternionBox
  429. Returns a new QuaternionBox from the Quaternion *q*.
  430. **QuaternionBox** (x, y, z, w) : QuaternionBox
  431. Returns a new QuaternionBox from individual elements.
  432. Functions
  433. ~~~~~~~~~
  434. **store** (q)
  435. Stores the Quaternion *q* in the box.
  436. **store** (x, y, z, w)
  437. Stores Quaternion(x, y, z, w) in the box.
  438. **unbox** () : Quaternion
  439. Returns the stored quaternion from the box.
  440. Matrix4x4
  441. ---------
  442. Constructors
  443. ~~~~~~~~~~~~
  444. **Matrix4x4** (xx, xy, xz, xw, yx, yy, yz, yw, zx, zy, zz, zw, tx, ty, tz, tw) : Matrix4x4
  445. Returns a new matrix from individual elements.
  446. **from_quaternion** (q) : Matrix4x4
  447. Returns a new matrix from *q*.
  448. **from_translation** (t) : Matrix4x4
  449. Returns a new matrix from *t*.
  450. **from_quaternion_translation** (q, t) : Matrix4x4
  451. Returns a new matrix from *q* and *t*.
  452. **from_axes** (x, y, z, t) : Matrix4x4
  453. Returns a new matrix from *x*, *y*, *z* and *t*.
  454. Functions
  455. ~~~~~~~~~
  456. **copy** (m) : Matrix4x4
  457. Returns a copy of the matrix *m*.
  458. **add** (a, b) : Matrix4x4
  459. Adds the matrix *a* to *b* and returns the result.
  460. **subtract** (a, b) : Matrix4x4
  461. Subtracts the matrix *b* from *a* and returns the result.
  462. **multiply** (a, b) : Matrix4x4
  463. Multiplies the matrix *a* by *b* and returns the result. (i.e. transforms first by *a* then by *b*)
  464. **equal** (a, b) : bool
  465. Returns true whether the matrices *a* and *b* are equal.
  466. **transpose** (m) : Matrix4x4
  467. Transposes the matrix *m* and returns the result.
  468. **invert** (m) : Matrix4x4
  469. Inverts the matrix *m* and returns the result.
  470. **x** (m) : Vector3
  471. Returns the x axis of the matrix *m*.
  472. **y** (m) : Vector3
  473. Returns the y axis of the matrix *m*.
  474. **z** (m) : Vector3
  475. Returns the z axis of the matrix *m*.
  476. **set_x** (m, x)
  477. Sets the x axis of the matrix *m*.
  478. **set_y** (m, y)
  479. Sets the y axis of the matrix *m*.
  480. **set_z** (m, z)
  481. Sets the z axis of the matrix *m*.
  482. **rotation** (m) : Quaternion
  483. Returns the rotation portion of the matrix *m*.
  484. **set_rotation** (m, r)
  485. Sets the rotation portion of the matrix *m*.
  486. **translation** (m) : Vector3
  487. Returns the translation portion of the matrix *m*.
  488. **set_translation** (m, t)
  489. Sets the translation portion of the matrix *m*.
  490. **identity** ()
  491. Returns the identity matrix.
  492. **transform** (m, v) : Vector3
  493. Transforms the vector *v* by the matrix *m* and returns the result.
  494. **to_string** (m) : string
  495. Returns a string representing the matrix *m*.
  496. Matrix4x4Box
  497. ------------
  498. Constructors
  499. ~~~~~~~~~~~~
  500. **Matrix4x4Box** () : Matrix4x4Box
  501. Returns a new Matrix4x4Box initialized with the identity matrix.
  502. **Matrix4x4Box** (m) : Matrix4x4Box
  503. Returns a new Matrix4x4Box from the Matrix4x4 *m*.
  504. Functions
  505. ~~~~~~~~~
  506. **store** (m)
  507. Stores the Matrix4x4 *m* in the box.
  508. **unbox** () : Matrix4x4
  509. Returns the stored matrix from the box.
  510. Color4
  511. ------
  512. Constructors
  513. ~~~~~~~~~~~~
  514. **Color4** (r, g, b, a) : Color4
  515. Returns a new Color4 from individual elements.
  516. Functions
  517. ~~~~~~~~~
  518. **lerp** (a, b, t) : Color4
  519. Returns the linearly interpolated color between *a* and *b* at time *t* in [0, 1].
  520. | **black** () : Color4
  521. | **white** () : Color4
  522. | **red** () : Color4
  523. | **green** () : Color4
  524. | **blue** () : Color4
  525. | **yellow** () : Color4
  526. | **orange** () : Color4
  527. | Returns the corresponding mnemonic color.
  528. **to_string** (c) : string
  529. Returns a string representing the color *c*.
  530. Math
  531. ----
  532. **ray_plane_intersection** (from, dir, point, normal) : float
  533. Returns the distance along ray (from, dir) to intersection point with plane defined by
  534. *point* and *normal* or -1.0 if no intersection.
  535. **ray_disc_intersection** (from, dir, center, radius, normal) : float
  536. Returns the distance along ray (from, dir) to intersection point with disc defined by
  537. *center*, *radius* and *normal* or -1.0 if no intersection.
  538. **ray_sphere_intersection** (from, dir, center, radius) : float
  539. Returns the distance along ray (from, dir) to intersection point with sphere defined by
  540. *center* and *radius* or -1.0 if no intersection.
  541. **ray_obb_intersection** (from, dir, tm, half_extents) : float
  542. Returns the distance along ray (from, dir) to intersection point with the oriented
  543. bounding box (tm, half_extents) or -1.0 if no intersection.
  544. **ray_triangle_intersection** (from, dir, v0, v1, v2) : float
  545. Returns the distance along ray (from, dir) to intersection point with the triangle
  546. (v0, v1, v2) or -1.0 if no intersection.
  547. PhysicsWorld
  548. =============
  549. **gravity** (pw) : Vector3
  550. Returns the gravity.
  551. **set_gravity** (pw, gravity)
  552. Sets the gravity.
  553. **cast_ray** (pw, from, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  554. Casts a ray into the physics world and returns the closest actor it intersects with.
  555. If *hit* is true the following return values contain the *collision_pos* in
  556. world space, the *normal* of the surface that was hit, the time of impact
  557. in [0..1] and the *unit* and the *actor* that was hit.
  558. **cast_ray_all** (pw, from, dir, length) : table
  559. Casts a ray into the physics world and returns all the
  560. actors it intersects with as an array of `RaycastHit`_ tables.
  561. **cast_sphere** (pw, from, radius, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  562. Casts a sphere into the physics world and returns the closest actor it intersects with.
  563. If *hit* is true the following return values contain the *collision_pos* in
  564. world space, the *normal* of the surface that was hit, the time of impact
  565. in [0..1] and the *unit* and the *actor* that was hit.
  566. **cast_box** (pw, from, half_extents, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  567. Casts a box into the physics world and returns the closest actor it intersects with.
  568. If *hit* is true the following return values contain the *collision_pos* in
  569. world space, the *normal* of the surface that was hit, the time of impact
  570. in [0..1] and the *unit* and the *actor* that was hit.
  571. **enable_debug_drawing** (pw, enable)
  572. Sets whether to *enable* debug drawing.
  573. RaycastHit
  574. ----------
  575. RaycastHit is a lua table with 5 fields:
  576. * ``[1]``: The collision position in world space.
  577. * ``[2]``: The normal of the surface that was hit.
  578. * ``[3]``: The time of impact in [0..1].
  579. * ``[4]``: The unit that was hit.
  580. * ``[5]``: The actor that was hit.
  581. Actor
  582. -----
  583. **actor_destroy** (pw, actor)
  584. Destroys the *actor* instance.
  585. **actor_instance** (pw, unit) : Id
  586. Returns the ID of the actor owned by the *unit*, or ``nil``.
  587. **actor_world_position** (pw, actor) : Vector3
  588. Returns the world position of the *actor*.
  589. **actor_world_rotation** (pw, actor) : Quaternion
  590. Returns the world rotation of the *actor*.
  591. **actor_world_pose** (pw, actor) : Matrix4x4
  592. Returns the world pose of the *actor*.
  593. **actor_teleport_world_position** (pw, actor, position)
  594. Teleports the *actor* to the given world *position*.
  595. **actor_teleport_world_rotation** (pw, actor, rotation)
  596. Teleports the *actor* to the given world *rotation*.
  597. **actor_teleport_world_pose** (pw, actor, pose)
  598. Teleports the *actor* to the given world *pose*.
  599. **actor_center_of_mass** (pw, actor) : Vector3
  600. Returns the center of mass of the *actor*.
  601. **actor_enable_gravity** (pw, actor)
  602. Enables gravity for the *actor*.
  603. **actor_disable_gravity** (pw, actor)
  604. Disables gravity for the *actor*.
  605. **actor_enable_collision** (pw, actor)
  606. Enables collision detection for the *actor*.
  607. **actor_disable_collision** (pw, actor)
  608. Disables collision detection for the *actor*.
  609. **actor_set_collision_filter** (pw, actor, name)
  610. Sets the collision filter of the *actor*.
  611. **actor_set_kinematic** (pw, actor, kinematic)
  612. Sets whether the *actor* is *kinematic* or not.
  613. .. note::
  614. This call has no effect on static actors.
  615. **actor_is_static** (pw, actor) : bool
  616. Returns whether the *actor* is static.
  617. **actor_is_dynamic** (pw, actor) bool
  618. Returns whether the *actor* is dynamic.
  619. **actor_is_kinematic** (pw, actor) : bool
  620. Returns whether the *actor* is kinematic (keyframed).
  621. **actor_is_nonkinematic** (pw, actor) : bool
  622. Returns whether the *actor* is nonkinematic (i.e. dynamic and not kinematic).
  623. **actor_linear_damping** (pw, actor) : float
  624. Returns the linear damping of the *actor*.
  625. **actor_set_linear_damping** (pw, actor, damping)
  626. Sets the linear *damping* of the *actor*.
  627. **actor_angular_damping** (pw, actor) : float
  628. Returns the angular damping rate of the *actor*.
  629. **actor_set_angular_damping** (pw, actor, rate)
  630. Sets the angular damping *rate* of the *actor*.
  631. **actor_linear_velocity** (pw, actor) : Vector3
  632. Returns the linear velocity of the *actor*.
  633. **actor_set_linear_velocity** (pw, actor, velocity)
  634. Sets the linear *velocity* of the *actor*.
  635. .. note::
  636. This call only affects nonkinematic actors.
  637. **actor_angular_velocity** (pw, actor) : Vector3
  638. Returns the angular velocity of the *actor*.
  639. **actor_set_angular_velocity** (pw, actor, velocity)
  640. Sets the angular *velocity* of the *actor*.
  641. .. note::
  642. This call only affects nonkinematic actors.
  643. **actor_add_impulse** (pw, actor, impulse)
  644. Adds a linear *impulse* (acting along the center of mass) to the *actor*.
  645. .. note::
  646. This call only affects nonkinematic actors.
  647. **actor_add_impulse_at** (pw, actor, impulse, position)
  648. Adds a linear *impulse* (acting along the world position *pos*) to the *actor*.
  649. .. note::
  650. This call only affects nonkinematic actors.
  651. **actor_add_torque_impulse** (pw, actor, impulse)
  652. Adds a torque *impulse* to the *actor*.
  653. **actor_push** (pw, actor, velocity, mass)
  654. Pushes the *actor* as if it was hit by a point object with the given *mass*
  655. travelling at the given *velocity*.
  656. .. note::
  657. This call only affects nonkinematic actors.
  658. **actor_push_at** (pw, actor, velocity, mass, position)
  659. Like push() but applies the force at the world *position*.
  660. .. note::
  661. This call only affects nonkinematic actors.
  662. **actor_is_sleeping** (pw, actor) : bool
  663. Returns whether the *actor* is sleeping.
  664. **actor_wake_up** (pw, actor)
  665. Wakes the *actor* up.
  666. Profiler
  667. ========
  668. **enter_scope** (name)
  669. Starts a new profile scope with the given *name*.
  670. **leave_scope** ()
  671. Ends the last profile scope.
  672. **record** (name, value)
  673. Records *value* with the given *name*. Value can be either number or Vector3.
  674. RenderWorld
  675. ===========
  676. **enable_debug_drawing** (rw, enable)
  677. Sets whether to *enable* debug drawing.
  678. Mesh
  679. ----
  680. **mesh_create** (rw, unit, mesh_resource, geometry_name, material_resource, visible, pose) : Id
  681. Creates a new mesh instance for *unit* and returns its id.
  682. **mesh_destroy** (rw, mesh)
  683. Destroys the *mesh* instance.
  684. **mesh_instance** (rw, unit) : Id
  685. Returns the ID of the mesh owned by the *unit*, or ``nil``.
  686. **mesh_material** (rw, mesh) : Material
  687. Returns the material of the *mesh*.
  688. **mesh_set_material** (rw, mesh, material)
  689. Sets the *material* of the *mesh*.
  690. **mesh_set_visible** (rw, mesh, visible)
  691. Sets whether the *mesh* is *visible*.
  692. **mesh_obb** (rw, mesh) : Matrix4x4, Vector3
  693. Returns the Oriented-Bounding-Box of the *mesh* as (pose, half_extents).
  694. **mesh_cast_ray** (rw, mesh, from, dir) : float
  695. Returns the distance along ray (from, dir) to intersection point with the *mesh* or -1.0 if no intersection.
  696. Sprite
  697. ------
  698. **sprite_create** (rw, unit, sprite_resource, material_resource, visible, pose) : Id
  699. Creates a new sprite instance for the *unit* and returns its id.
  700. **sprite_destroy** (rw, sprite)
  701. Destroys the *sprite* instance.
  702. **sprite_instance** (rw, unit) : Id
  703. Returns the ID of the sprite owned by the *unit*, or ``nil``.
  704. **sprite_material** (rw, sprite) : Material
  705. Returns the material of the *sprite*.
  706. **sprite_set_material** (rw, sprite, material)
  707. Sets the *material* of the *sprite*.
  708. **sprite_set_frame** (rw, sprite, index)
  709. Sets the frame *index* of the *sprite*.
  710. The *index* automatically wraps if it greater than the total number of
  711. frames in the sprite.
  712. **sprite_set_visible** (rw, sprite, visible)
  713. Sets whether the *sprite* is *visible*.
  714. **sprite_flip_x** (rw, sprite, flip)
  715. Sets whether to flip the *sprite* on the x-axis.
  716. **sprite_flip_y** (rw, sprite, flip)
  717. Sets whether to flip the *sprite* on the y-axis.
  718. **sprite_set_layer** (rw, sprite, layer)
  719. Sets the rendering *layer* of the *sprite*.
  720. **sprite_set_depth** (rw, sprite, depth)
  721. Sets the rendering *depth* of the *sprite*.
  722. **sprite_obb** (rw, sprite) : Matrix4x4, Vector3
  723. Returns the Oriented-Bounding-Box of the *sprite* as (pose, half_extents).
  724. **sprite_cast_ray** (rw, sprite, from, dir) : float, int, int
  725. Returns (t, layer, depth), where *t* is the distance along ray (from, dir) to
  726. intersection point with the *sprite* or -1.0 if no intersection.
  727. Light
  728. -----
  729. **light_create** (rw, unit, type, range, intensity, spot_angle, color, pose) : Id
  730. Creates a new light for the *unit* and returns its id.
  731. Type can be either ``directional``, ``omni`` or ``spot``.
  732. **light_destroy** (rw, light)
  733. Destroys the *light* instance.
  734. **light_instance** (rw, unit) : Id
  735. Returns the ID of the light owned by the *unit*, or ``nil``.
  736. **light_type** (rw, light) : string
  737. Returns the type of the *light*.
  738. It can be either ``directional``, ``omni`` or ``spot``.
  739. **light_color** (rw, light) : Color4
  740. Returns the color of the *light*.
  741. **light_range** (rw, light) : float
  742. Returns the range of the *light*.
  743. **light_intensity** (rw, light) : float
  744. Returns the intensity of the *light*.
  745. **light_spot_angle** (rw, light) : float
  746. Returns the spot angle of the *light*.
  747. **light_set_type** (rw, light, type)
  748. Sets the *type* of the *light*.
  749. **light_set_color** (rw, light, color)
  750. Sets the *color* of the *light*.
  751. **light_set_range** (rw, light, range)
  752. Sets the *range* of the *light*.
  753. **light_set_intensity** (rw, light, intensity)
  754. Sets the *intensity* of the *light*.
  755. **light_set_spot_angle** (rw, light, angle)
  756. Sets the spot *angle* of the *light*.
  757. **light_debug_draw** (rw, light, debug_line)
  758. Fills *debug_line* with debug lines from the *light*.
  759. ResourcePackage
  760. ===============
  761. **load** (package)
  762. Loads all the resources in the *package*.
  763. .. note::
  764. The resources are not immediately available after the call is made,
  765. instead, you have to poll for completion with has_loaded().
  766. **unload** (package)
  767. Unloads all the resources in the *package*.
  768. **flush** (package)
  769. Waits until the *package* has been loaded.
  770. **has_loaded** (package) : bool
  771. Returns whether the *package* has been loaded.
  772. SceneGraph
  773. ==========
  774. **create** (sg, unit, position, rotation, scale) : Id
  775. Creates the transform for the *unit* and returns its ID.
  776. **destroy** (sg, transform)
  777. Destroys the *transform* instance.
  778. **instance** (sg, unit) : Id
  779. Returns the ID of the transform owned by the *unit*, or ``nil``.
  780. **local_position** (sg, transform) : Vector3
  781. Returns the local position of the *transform*.
  782. **local_rotation** (sg, transform) : Quaternion
  783. Returns the local rotation of the *transform*.
  784. **local_scale** (sg, transform) : Vector3
  785. Returns the local scale of the *transform*.
  786. **local_pose** (sg, transform) : Matrix4x4
  787. Returns the local pose of the *transform*.
  788. **world_position** (sg, transform) : Vector3
  789. Returns the world position of the *transform*.
  790. **world_rotation** (sg, transform) : Quaternion
  791. Returns the world rotation of the *transform*.
  792. **world_pose** (sg, transform) : Matrix4x4
  793. Returns the world pose of the *transform*.
  794. **set_local_position** (sg, transform, position)
  795. Sets the local *position* of the *transform*.
  796. **set_local_rotation** (sg, transform, rotation)
  797. Sets the local *rotation* of the *transform*.
  798. **set_local_scale** (sg, transform, scale)
  799. Sets the local *scale* of the *transform*.
  800. **set_local_pose** (sg, transform, pose)
  801. Sets the local *pose* of the *transform*.
  802. **link** (sg, child, parent)
  803. Links the transform *child* to the transform *parent*.
  804. **unlink** (sg, transform)
  805. Unlinks the *transform* from its parent if it has any.
  806. After unlinking, the local pose of the *transform* is set to its previous
  807. world pose.
  808. SoundWorld
  809. ===========
  810. **stop_all** (sound_world)
  811. Stops all the sounds in the world.
  812. **pause_all** (sound_world)
  813. Pauses all the sounds in the world
  814. **resume_all** (sound_world)
  815. Resumes all previously paused sounds in the world.
  816. **is_playing** (sound_world, id) : bool
  817. Returns whether the sound *id* is playing.
  818. UnitManager
  819. ===========
  820. **create** ([world]) : UnitId
  821. Creates a new empty unit. If *world* is specified, the unit will be owned by
  822. that world.
  823. **destroy** (unit)
  824. Destroys the given *unit*.
  825. **alive** (unit) : bool
  826. Returns whether the unit is alive.
  827. Window
  828. ======
  829. **show** ()
  830. Shows the window.
  831. **hide** ()
  832. Hides the window.
  833. **resize** (width, height)
  834. Resizes the window to *width* and *height*.
  835. **move** (x, y)
  836. Moves the window to *x* and *y*.
  837. **minimize** ()
  838. Minimizes the window.
  839. **maximize** ()
  840. Maximizes the window.
  841. **restore** ()
  842. Restores the window.
  843. **title** () : string
  844. Returns the title of the window.
  845. **set_title** (title)
  846. Sets the title of the window.
  847. **show_cursor** (show)
  848. Sets whether to *show* the cursor.
  849. **set_fullscreen** (fullscreen)
  850. Sets whether the window is *fullscreen*.
  851. **set_cursor** (cursor)
  852. Sets the mouse *cursor* on this window.
  853. **set_cursor_mode** (cursor, mode)
  854. Sets the mouse cursor *mode* on this window.
  855. Mode can be either ``normal`` or ``disabled``.
  856. World
  857. =====
  858. **spawn_unit** (world, name, [position, rotation, scale]) : UnitId
  859. Spawns a new instance of the unit *name* at the given *position*, *rotation* and *scale*.
  860. **spawn_empty_unit** (world) : UnitId
  861. Spawns a new empty unit and returns its id.
  862. **destroy_unit** (world, unit)
  863. Destroys the given *unit*.
  864. **num_units** (world) : int
  865. Returns the number of units in the *world*.
  866. **units** (world) : table
  867. Returns all the the units in the world in a table.
  868. **unit_by_name** (world, name) : UnitId
  869. Returns the unit with the given Level Editor *name* or ``nil`` if no such unit is found.
  870. If there are multiple units with the same name, a random one will be returned.
  871. **update_animations** (world, dt)
  872. Update all animations with *dt*.
  873. **update_scene** (world, dt)
  874. Updates the scene with *dt*.
  875. **update** (world, dt)
  876. Updates the world with *dt*.
  877. **create_debug_line** (world, depth_test) : DebugLine
  878. Creates a new DebugLine. *depth_test* controls whether to
  879. enable depth test when rendering the lines.
  880. **destroy_debug_line** (world, line)
  881. Destroys the debug *line*.
  882. **create_screen_gui** (world) : Gui
  883. Creates a new Gui.
  884. **scene_graph** (world) : SceneGraph
  885. Returns the scene graph.
  886. **render_world** (world) : RenderWorld
  887. Returns the render sub-world.
  888. **physics_world** (world) : PhysicsWorld
  889. Returns the physics sub-world.
  890. **sound_world** (world) : SoundWorld
  891. Returns the sound sub-world.
  892. **animation_state_machine** (world) : AnimationStateMachine
  893. Returns the animation state machine.
  894. Camera
  895. ------
  896. **camera_create** (world, unit, projection, fov, far_range, near_range, pose) : Id
  897. Creates a new camera for *unit* and returns its id.
  898. Projection can be either ``orthographic`` or ``perspective``.
  899. **camera_instance** (world, unit) : Id
  900. Returns the ID of the camera owned by the *unit*, or ``nil``.
  901. **camera_set_projection_type** (world, camera, projection)
  902. Sets the projection type of the *camera*.
  903. Projection can be either ``orthographic`` or ``perspective``.
  904. **camera_projection_type** (world, camera) : string
  905. Returns the projection type of the *camera*.
  906. It can be either ``orthographic`` or ``perspective``.
  907. **camera_fov** (world, camera) : float
  908. Returns the field-of-view of the *camera* in degrees.
  909. **camera_set_fov** (world, camera, fov)
  910. Sets the field-of-view of the *camera* in degrees.
  911. **camera_near_clip_distance** (world, camera) : float
  912. Returns the near clip distance of the *camera*.
  913. **camera_set_near_clip_distance** (world, camera, near)
  914. Sets the near clip distance of the *camera*.
  915. **camera_far_clip_distance** (world, camera) : float
  916. Returns the far clip distance of the *camera*.
  917. **camera_set_far_clip_distance** (world, camera, far)
  918. Sets the far clip distance of the *camera*.
  919. **camera_set_orthographic_size** (world, camera, half_size)
  920. Sets the vertical *half_size* of the orthographic view volume.
  921. The horizontal size is proportional to the viewport's aspect ratio.
  922. **camera_screen_to_world** (world, camera, pos) : Vector3
  923. Returns *pos* from screen-space to world-space coordinates.
  924. **camera_world_to_screen** (world, camera, pos) : Vector3
  925. Returns *pos* from world-space to screen-space coordinates.
  926. Sound
  927. -----
  928. **play_sound** (world, name, [loop, volume, position, range]) : SoundInstanceId
  929. Plays the sound with the given *name* at the given *position*, with the given
  930. *volume* and *range*. *loop* controls whether the sound must loop or not.
  931. **stop_sound** (world, id)
  932. Stops the sound with the given *id*.
  933. **link_sound** (world, id, unit, node)
  934. Links the sound *id* to the *node* of the given *unit*.
  935. After this call, the sound *id* will follow the unit *unit*.
  936. **set_listener_pose** (world, pose)
  937. Sets the *pose* of the listener.
  938. **set_sound_position** (world, id, position)
  939. Sets the *position* of the sound *id*.
  940. **set_sound_range** (world, id, range)
  941. Sets the *range* of the sound *id*.
  942. **set_sound_volume** (world, id, volume)
  943. Sets the *volume* of the sound *id*.
  944. Level
  945. -----
  946. **load_level** (world, name, [pos, rot]) : Level
  947. Loads the level *name* into the world at the given *position* and *rotation*.