lua_api.rst 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  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. **obb_intersects_frustum** (obb_tm, obb_half_extents, n0, d0, n1, d1, n2, d2, n3, d3, n4, d4, n4, d5) : bool
  548. Returns whether the oriented bounding box (obb_tm, obb_half_extents) intersects
  549. the frustum defined by the planes ((n0, d0), (n1, d1), ..., (n5, d5)). The
  550. planes be given in BRTLNF order, where B = bottom plane, R = right plane etc.
  551. PhysicsWorld
  552. =============
  553. **gravity** (pw) : Vector3
  554. Returns the gravity.
  555. **set_gravity** (pw, gravity)
  556. Sets the gravity.
  557. **cast_ray** (pw, from, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  558. Casts a ray into the physics world and returns the closest actor it intersects with.
  559. If *hit* is true the following return values contain the *collision_pos* in
  560. world space, the *normal* of the surface that was hit, the time of impact
  561. in [0..1] and the *unit* and the *actor* that was hit.
  562. **cast_ray_all** (pw, from, dir, length) : table
  563. Casts a ray into the physics world and returns all the
  564. actors it intersects with as an array of `RaycastHit`_ tables.
  565. **cast_sphere** (pw, from, radius, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  566. Casts a sphere into the physics world and returns the closest actor it intersects with.
  567. If *hit* is true the following return values contain the *collision_pos* in
  568. world space, the *normal* of the surface that was hit, the time of impact
  569. in [0..1] and the *unit* and the *actor* that was hit.
  570. **cast_box** (pw, from, half_extents, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  571. Casts a box into the physics world and returns the closest actor it intersects with.
  572. If *hit* is true the following return values contain the *collision_pos* in
  573. world space, the *normal* of the surface that was hit, the time of impact
  574. in [0..1] and the *unit* and the *actor* that was hit.
  575. **enable_debug_drawing** (pw, enable)
  576. Sets whether to *enable* debug drawing.
  577. RaycastHit
  578. ----------
  579. RaycastHit is a lua table with 5 fields:
  580. * ``[1]``: The collision position in world space.
  581. * ``[2]``: The normal of the surface that was hit.
  582. * ``[3]``: The time of impact in [0..1].
  583. * ``[4]``: The unit that was hit.
  584. * ``[5]``: The actor that was hit.
  585. Actor
  586. -----
  587. **actor_destroy** (pw, actor)
  588. Destroys the *actor* instance.
  589. **actor_instance** (pw, unit) : Id
  590. Returns the ID of the actor owned by the *unit*, or ``nil``.
  591. **actor_world_position** (pw, actor) : Vector3
  592. Returns the world position of the *actor*.
  593. **actor_world_rotation** (pw, actor) : Quaternion
  594. Returns the world rotation of the *actor*.
  595. **actor_world_pose** (pw, actor) : Matrix4x4
  596. Returns the world pose of the *actor*.
  597. **actor_teleport_world_position** (pw, actor, position)
  598. Teleports the *actor* to the given world *position*.
  599. **actor_teleport_world_rotation** (pw, actor, rotation)
  600. Teleports the *actor* to the given world *rotation*.
  601. **actor_teleport_world_pose** (pw, actor, pose)
  602. Teleports the *actor* to the given world *pose*.
  603. **actor_center_of_mass** (pw, actor) : Vector3
  604. Returns the center of mass of the *actor*.
  605. **actor_enable_gravity** (pw, actor)
  606. Enables gravity for the *actor*.
  607. **actor_disable_gravity** (pw, actor)
  608. Disables gravity for the *actor*.
  609. **actor_enable_collision** (pw, actor)
  610. Enables collision detection for the *actor*.
  611. **actor_disable_collision** (pw, actor)
  612. Disables collision detection for the *actor*.
  613. **actor_set_collision_filter** (pw, actor, name)
  614. Sets the collision filter of the *actor*.
  615. **actor_set_kinematic** (pw, actor, kinematic)
  616. Sets whether the *actor* is *kinematic* or not.
  617. .. note::
  618. This call has no effect on static actors.
  619. **actor_is_static** (pw, actor) : bool
  620. Returns whether the *actor* is static.
  621. **actor_is_dynamic** (pw, actor) bool
  622. Returns whether the *actor* is dynamic.
  623. **actor_is_kinematic** (pw, actor) : bool
  624. Returns whether the *actor* is kinematic (keyframed).
  625. **actor_is_nonkinematic** (pw, actor) : bool
  626. Returns whether the *actor* is nonkinematic (i.e. dynamic and not kinematic).
  627. **actor_linear_damping** (pw, actor) : float
  628. Returns the linear damping of the *actor*.
  629. **actor_set_linear_damping** (pw, actor, damping)
  630. Sets the linear *damping* of the *actor*.
  631. **actor_angular_damping** (pw, actor) : float
  632. Returns the angular damping rate of the *actor*.
  633. **actor_set_angular_damping** (pw, actor, rate)
  634. Sets the angular damping *rate* of the *actor*.
  635. **actor_linear_velocity** (pw, actor) : Vector3
  636. Returns the linear velocity of the *actor*.
  637. **actor_set_linear_velocity** (pw, actor, velocity)
  638. Sets the linear *velocity* of the *actor*.
  639. .. note::
  640. This call only affects nonkinematic actors.
  641. **actor_angular_velocity** (pw, actor) : Vector3
  642. Returns the angular velocity of the *actor*.
  643. **actor_set_angular_velocity** (pw, actor, velocity)
  644. Sets the angular *velocity* of the *actor*.
  645. .. note::
  646. This call only affects nonkinematic actors.
  647. **actor_add_impulse** (pw, actor, impulse)
  648. Adds a linear *impulse* (acting along the center of mass) to the *actor*.
  649. .. note::
  650. This call only affects nonkinematic actors.
  651. **actor_add_impulse_at** (pw, actor, impulse, position)
  652. Adds a linear *impulse* (acting along the world position *pos*) to the *actor*.
  653. .. note::
  654. This call only affects nonkinematic actors.
  655. **actor_add_torque_impulse** (pw, actor, impulse)
  656. Adds a torque *impulse* to the *actor*.
  657. **actor_push** (pw, actor, velocity, mass)
  658. Pushes the *actor* as if it was hit by a point object with the given *mass*
  659. travelling at the given *velocity*.
  660. .. note::
  661. This call only affects nonkinematic actors.
  662. **actor_push_at** (pw, actor, velocity, mass, position)
  663. Like push() but applies the force at the world *position*.
  664. .. note::
  665. This call only affects nonkinematic actors.
  666. **actor_is_sleeping** (pw, actor) : bool
  667. Returns whether the *actor* is sleeping.
  668. **actor_wake_up** (pw, actor)
  669. Wakes the *actor* up.
  670. Profiler
  671. ========
  672. **enter_scope** (name)
  673. Starts a new profile scope with the given *name*.
  674. **leave_scope** ()
  675. Ends the last profile scope.
  676. **record** (name, value)
  677. Records *value* with the given *name*. Value can be either number or Vector3.
  678. RenderWorld
  679. ===========
  680. **enable_debug_drawing** (rw, enable)
  681. Sets whether to *enable* debug drawing.
  682. Mesh
  683. ----
  684. **mesh_create** (rw, unit, mesh_resource, geometry_name, material_resource, visible, pose) : Id
  685. Creates a new mesh instance for *unit* and returns its id.
  686. **mesh_destroy** (rw, mesh)
  687. Destroys the *mesh* instance.
  688. **mesh_instance** (rw, unit) : Id
  689. Returns the ID of the mesh owned by the *unit*, or ``nil``.
  690. **mesh_material** (rw, mesh) : Material
  691. Returns the material of the *mesh*.
  692. **mesh_set_material** (rw, mesh, material)
  693. Sets the *material* of the *mesh*.
  694. **mesh_set_visible** (rw, mesh, visible)
  695. Sets whether the *mesh* is *visible*.
  696. **mesh_obb** (rw, mesh) : Matrix4x4, Vector3
  697. Returns the Oriented-Bounding-Box of the *mesh* as (pose, half_extents).
  698. **mesh_cast_ray** (rw, mesh, from, dir) : float
  699. Returns the distance along ray (from, dir) to intersection point with the *mesh* or -1.0 if no intersection.
  700. Sprite
  701. ------
  702. **sprite_create** (rw, unit, sprite_resource, material_resource, visible, pose) : Id
  703. Creates a new sprite instance for the *unit* and returns its id.
  704. **sprite_destroy** (rw, sprite)
  705. Destroys the *sprite* instance.
  706. **sprite_instance** (rw, unit) : Id
  707. Returns the ID of the sprite owned by the *unit*, or ``nil``.
  708. **sprite_material** (rw, sprite) : Material
  709. Returns the material of the *sprite*.
  710. **sprite_set_material** (rw, sprite, material)
  711. Sets the *material* of the *sprite*.
  712. **sprite_set_frame** (rw, sprite, index)
  713. Sets the frame *index* of the *sprite*.
  714. The *index* automatically wraps if it greater than the total number of
  715. frames in the sprite.
  716. **sprite_set_visible** (rw, sprite, visible)
  717. Sets whether the *sprite* is *visible*.
  718. **sprite_flip_x** (rw, sprite, flip)
  719. Sets whether to flip the *sprite* on the x-axis.
  720. **sprite_flip_y** (rw, sprite, flip)
  721. Sets whether to flip the *sprite* on the y-axis.
  722. **sprite_set_layer** (rw, sprite, layer)
  723. Sets the rendering *layer* of the *sprite*.
  724. **sprite_set_depth** (rw, sprite, depth)
  725. Sets the rendering *depth* of the *sprite*.
  726. **sprite_obb** (rw, sprite) : Matrix4x4, Vector3
  727. Returns the Oriented-Bounding-Box of the *sprite* as (pose, half_extents).
  728. **sprite_cast_ray** (rw, sprite, from, dir) : float, int, int
  729. Returns (t, layer, depth), where *t* is the distance along ray (from, dir) to
  730. intersection point with the *sprite* or -1.0 if no intersection.
  731. Light
  732. -----
  733. **light_create** (rw, unit, type, range, intensity, spot_angle, color, pose) : Id
  734. Creates a new light for the *unit* and returns its id.
  735. Type can be either ``directional``, ``omni`` or ``spot``.
  736. **light_destroy** (rw, light)
  737. Destroys the *light* instance.
  738. **light_instance** (rw, unit) : Id
  739. Returns the ID of the light owned by the *unit*, or ``nil``.
  740. **light_type** (rw, light) : string
  741. Returns the type of the *light*.
  742. It can be either ``directional``, ``omni`` or ``spot``.
  743. **light_color** (rw, light) : Color4
  744. Returns the color of the *light*.
  745. **light_range** (rw, light) : float
  746. Returns the range of the *light*.
  747. **light_intensity** (rw, light) : float
  748. Returns the intensity of the *light*.
  749. **light_spot_angle** (rw, light) : float
  750. Returns the spot angle of the *light*.
  751. **light_set_type** (rw, light, type)
  752. Sets the *type* of the *light*.
  753. **light_set_color** (rw, light, color)
  754. Sets the *color* of the *light*.
  755. **light_set_range** (rw, light, range)
  756. Sets the *range* of the *light*.
  757. **light_set_intensity** (rw, light, intensity)
  758. Sets the *intensity* of the *light*.
  759. **light_set_spot_angle** (rw, light, angle)
  760. Sets the spot *angle* of the *light*.
  761. **light_debug_draw** (rw, light, debug_line)
  762. Fills *debug_line* with debug lines from the *light*.
  763. ResourcePackage
  764. ===============
  765. **load** (package)
  766. Loads all the resources in the *package*.
  767. .. note::
  768. The resources are not immediately available after the call is made,
  769. instead, you have to poll for completion with has_loaded().
  770. **unload** (package)
  771. Unloads all the resources in the *package*.
  772. **flush** (package)
  773. Waits until the *package* has been loaded.
  774. **has_loaded** (package) : bool
  775. Returns whether the *package* has been loaded.
  776. SceneGraph
  777. ==========
  778. **create** (sg, unit, position, rotation, scale) : Id
  779. Creates the transform for the *unit* and returns its ID.
  780. **destroy** (sg, transform)
  781. Destroys the *transform* instance.
  782. **instance** (sg, unit) : Id
  783. Returns the ID of the transform owned by the *unit*, or ``nil``.
  784. **local_position** (sg, transform) : Vector3
  785. Returns the local position of the *transform*.
  786. **local_rotation** (sg, transform) : Quaternion
  787. Returns the local rotation of the *transform*.
  788. **local_scale** (sg, transform) : Vector3
  789. Returns the local scale of the *transform*.
  790. **local_pose** (sg, transform) : Matrix4x4
  791. Returns the local pose of the *transform*.
  792. **world_position** (sg, transform) : Vector3
  793. Returns the world position of the *transform*.
  794. **world_rotation** (sg, transform) : Quaternion
  795. Returns the world rotation of the *transform*.
  796. **world_pose** (sg, transform) : Matrix4x4
  797. Returns the world pose of the *transform*.
  798. **set_local_position** (sg, transform, position)
  799. Sets the local *position* of the *transform*.
  800. **set_local_rotation** (sg, transform, rotation)
  801. Sets the local *rotation* of the *transform*.
  802. **set_local_scale** (sg, transform, scale)
  803. Sets the local *scale* of the *transform*.
  804. **set_local_pose** (sg, transform, pose)
  805. Sets the local *pose* of the *transform*.
  806. **link** (sg, parent, child, child_local_position, child_local_rotation, child_local_scale)
  807. Links `child` to `parent`. After linking the child will follow its
  808. parent. Set child_local_* to modify the child position after it has been
  809. linked to the parent, otherwise che child will be positioned at the
  810. location of its parent.
  811. **unlink** (sg, child)
  812. Unlinks `child` from its parent if it has any. After unlinking, the local
  813. pose of the @a child is set to its previous world pose.
  814. SoundWorld
  815. ===========
  816. **stop_all** (sound_world)
  817. Stops all the sounds in the world.
  818. **pause_all** (sound_world)
  819. Pauses all the sounds in the world
  820. **resume_all** (sound_world)
  821. Resumes all previously paused sounds in the world.
  822. **is_playing** (sound_world, id) : bool
  823. Returns whether the sound *id* is playing.
  824. UnitManager
  825. ===========
  826. **create** ([world]) : UnitId
  827. Creates a new empty unit. If *world* is specified, the unit will be owned by
  828. that world.
  829. **destroy** (unit)
  830. Destroys the given *unit*.
  831. **alive** (unit) : bool
  832. Returns whether the unit is alive.
  833. Window
  834. ======
  835. **show** ()
  836. Shows the window.
  837. **hide** ()
  838. Hides the window.
  839. **resize** (width, height)
  840. Resizes the window to *width* and *height*.
  841. **move** (x, y)
  842. Moves the window to *x* and *y*.
  843. **minimize** ()
  844. Minimizes the window.
  845. **maximize** ()
  846. Maximizes the window.
  847. **restore** ()
  848. Restores the window.
  849. **title** () : string
  850. Returns the title of the window.
  851. **set_title** (title)
  852. Sets the title of the window.
  853. **show_cursor** (show)
  854. Sets whether to *show* the cursor.
  855. **set_fullscreen** (fullscreen)
  856. Sets whether the window is *fullscreen*.
  857. **set_cursor** (cursor)
  858. Sets the mouse *cursor* on this window.
  859. **set_cursor_mode** (cursor, mode)
  860. Sets the mouse cursor *mode* on this window.
  861. Mode can be either ``normal`` or ``disabled``.
  862. World
  863. =====
  864. **spawn_unit** (world, name, [position, rotation, scale]) : UnitId
  865. Spawns a new instance of the unit *name* at the given *position*, *rotation* and *scale*.
  866. **spawn_empty_unit** (world) : UnitId
  867. Spawns a new empty unit and returns its id.
  868. **destroy_unit** (world, unit)
  869. Destroys the given *unit*.
  870. **num_units** (world) : int
  871. Returns the number of units in the *world*.
  872. **units** (world) : table
  873. Returns all the the units in the world in a table.
  874. **unit_by_name** (world, name) : UnitId
  875. Returns the unit with the given Level Editor *name* or ``nil`` if no such unit is found.
  876. If there are multiple units with the same name, a random one will be returned.
  877. **update_animations** (world, dt)
  878. Update all animations with *dt*.
  879. **update_scene** (world, dt)
  880. Updates the scene with *dt*.
  881. **update** (world, dt)
  882. Updates the world with *dt*.
  883. **create_debug_line** (world, depth_test) : DebugLine
  884. Creates a new DebugLine. *depth_test* controls whether to
  885. enable depth test when rendering the lines.
  886. **destroy_debug_line** (world, line)
  887. Destroys the debug *line*.
  888. **create_screen_gui** (world) : Gui
  889. Creates a new Gui.
  890. **scene_graph** (world) : SceneGraph
  891. Returns the scene graph.
  892. **render_world** (world) : RenderWorld
  893. Returns the render sub-world.
  894. **physics_world** (world) : PhysicsWorld
  895. Returns the physics sub-world.
  896. **sound_world** (world) : SoundWorld
  897. Returns the sound sub-world.
  898. **animation_state_machine** (world) : AnimationStateMachine
  899. Returns the animation state machine.
  900. Camera
  901. ------
  902. **camera_create** (world, unit, projection, fov, far_range, near_range, pose) : Id
  903. Creates a new camera for *unit* and returns its id.
  904. Projection can be either ``orthographic`` or ``perspective``.
  905. **camera_instance** (world, unit) : Id
  906. Returns the ID of the camera owned by the *unit*, or ``nil``.
  907. **camera_set_projection_type** (world, camera, projection)
  908. Sets the projection type of the *camera*.
  909. Projection can be either ``orthographic`` or ``perspective``.
  910. **camera_projection_type** (world, camera) : string
  911. Returns the projection type of the *camera*.
  912. It can be either ``orthographic`` or ``perspective``.
  913. **camera_fov** (world, camera) : float
  914. Returns the field-of-view of the *camera* in degrees.
  915. **camera_set_fov** (world, camera, fov)
  916. Sets the field-of-view of the *camera* in degrees.
  917. **camera_near_clip_distance** (world, camera) : float
  918. Returns the near clip distance of the *camera*.
  919. **camera_set_near_clip_distance** (world, camera, near)
  920. Sets the near clip distance of the *camera*.
  921. **camera_far_clip_distance** (world, camera) : float
  922. Returns the far clip distance of the *camera*.
  923. **camera_set_far_clip_distance** (world, camera, far)
  924. Sets the far clip distance of the *camera*.
  925. **camera_set_orthographic_size** (world, camera, half_size)
  926. Sets the vertical *half_size* of the orthographic view volume.
  927. The horizontal size is proportional to the viewport's aspect ratio.
  928. **camera_screen_to_world** (world, camera, pos) : Vector3
  929. Returns *pos* from screen-space to world-space coordinates.
  930. **camera_world_to_screen** (world, camera, pos) : Vector3
  931. Returns *pos* from world-space to screen-space coordinates.
  932. Sound
  933. -----
  934. **play_sound** (world, name, [loop, volume, position, range]) : SoundInstanceId
  935. Plays the sound with the given *name* at the given *position*, with the given
  936. *volume* and *range*. *loop* controls whether the sound must loop or not.
  937. **stop_sound** (world, id)
  938. Stops the sound with the given *id*.
  939. **link_sound** (world, id, unit, node)
  940. Links the sound *id* to the *node* of the given *unit*.
  941. After this call, the sound *id* will follow the unit *unit*.
  942. **set_listener_pose** (world, pose)
  943. Sets the *pose* of the listener.
  944. **set_sound_position** (world, id, position)
  945. Sets the *position* of the sound *id*.
  946. **set_sound_range** (world, id, range)
  947. Sets the *range* of the sound *id*.
  948. **set_sound_volume** (world, id, volume)
  949. Sets the *volume* of the sound *id*.
  950. Level
  951. -----
  952. **load_level** (world, name, [pos, rot]) : Level
  953. Loads the level *name* into the world at the given *position* and *rotation*.