lua_api.txt 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  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, parent, child, child_local_position, child_local_rotation, child_local_scale)
  803. Links `child` to `parent`. After linking the child will follow its
  804. parent. Set child_local_* to modify the child position after it has been
  805. linked to the parent, otherwise che child will be positioned at the
  806. location of its parent.
  807. **unlink** (sg, child)
  808. Unlinks `child` from its parent if it has any. After unlinking, the local
  809. pose of the @a child is set to its previous world pose.
  810. SoundWorld
  811. ===========
  812. **stop_all** (sound_world)
  813. Stops all the sounds in the world.
  814. **pause_all** (sound_world)
  815. Pauses all the sounds in the world
  816. **resume_all** (sound_world)
  817. Resumes all previously paused sounds in the world.
  818. **is_playing** (sound_world, id) : bool
  819. Returns whether the sound *id* is playing.
  820. UnitManager
  821. ===========
  822. **create** ([world]) : UnitId
  823. Creates a new empty unit. If *world* is specified, the unit will be owned by
  824. that world.
  825. **destroy** (unit)
  826. Destroys the given *unit*.
  827. **alive** (unit) : bool
  828. Returns whether the unit is alive.
  829. Window
  830. ======
  831. **show** ()
  832. Shows the window.
  833. **hide** ()
  834. Hides the window.
  835. **resize** (width, height)
  836. Resizes the window to *width* and *height*.
  837. **move** (x, y)
  838. Moves the window to *x* and *y*.
  839. **minimize** ()
  840. Minimizes the window.
  841. **maximize** ()
  842. Maximizes the window.
  843. **restore** ()
  844. Restores the window.
  845. **title** () : string
  846. Returns the title of the window.
  847. **set_title** (title)
  848. Sets the title of the window.
  849. **show_cursor** (show)
  850. Sets whether to *show* the cursor.
  851. **set_fullscreen** (fullscreen)
  852. Sets whether the window is *fullscreen*.
  853. **set_cursor** (cursor)
  854. Sets the mouse *cursor* on this window.
  855. **set_cursor_mode** (cursor, mode)
  856. Sets the mouse cursor *mode* on this window.
  857. Mode can be either ``normal`` or ``disabled``.
  858. World
  859. =====
  860. **spawn_unit** (world, name, [position, rotation, scale]) : UnitId
  861. Spawns a new instance of the unit *name* at the given *position*, *rotation* and *scale*.
  862. **spawn_empty_unit** (world) : UnitId
  863. Spawns a new empty unit and returns its id.
  864. **destroy_unit** (world, unit)
  865. Destroys the given *unit*.
  866. **num_units** (world) : int
  867. Returns the number of units in the *world*.
  868. **units** (world) : table
  869. Returns all the the units in the world in a table.
  870. **unit_by_name** (world, name) : UnitId
  871. Returns the unit with the given Level Editor *name* or ``nil`` if no such unit is found.
  872. If there are multiple units with the same name, a random one will be returned.
  873. **update_animations** (world, dt)
  874. Update all animations with *dt*.
  875. **update_scene** (world, dt)
  876. Updates the scene with *dt*.
  877. **update** (world, dt)
  878. Updates the world with *dt*.
  879. **create_debug_line** (world, depth_test) : DebugLine
  880. Creates a new DebugLine. *depth_test* controls whether to
  881. enable depth test when rendering the lines.
  882. **destroy_debug_line** (world, line)
  883. Destroys the debug *line*.
  884. **create_screen_gui** (world) : Gui
  885. Creates a new Gui.
  886. **scene_graph** (world) : SceneGraph
  887. Returns the scene graph.
  888. **render_world** (world) : RenderWorld
  889. Returns the render sub-world.
  890. **physics_world** (world) : PhysicsWorld
  891. Returns the physics sub-world.
  892. **sound_world** (world) : SoundWorld
  893. Returns the sound sub-world.
  894. **animation_state_machine** (world) : AnimationStateMachine
  895. Returns the animation state machine.
  896. Camera
  897. ------
  898. **camera_create** (world, unit, projection, fov, far_range, near_range, pose) : Id
  899. Creates a new camera for *unit* and returns its id.
  900. Projection can be either ``orthographic`` or ``perspective``.
  901. **camera_instance** (world, unit) : Id
  902. Returns the ID of the camera owned by the *unit*, or ``nil``.
  903. **camera_set_projection_type** (world, camera, projection)
  904. Sets the projection type of the *camera*.
  905. Projection can be either ``orthographic`` or ``perspective``.
  906. **camera_projection_type** (world, camera) : string
  907. Returns the projection type of the *camera*.
  908. It can be either ``orthographic`` or ``perspective``.
  909. **camera_fov** (world, camera) : float
  910. Returns the field-of-view of the *camera* in degrees.
  911. **camera_set_fov** (world, camera, fov)
  912. Sets the field-of-view of the *camera* in degrees.
  913. **camera_near_clip_distance** (world, camera) : float
  914. Returns the near clip distance of the *camera*.
  915. **camera_set_near_clip_distance** (world, camera, near)
  916. Sets the near clip distance of the *camera*.
  917. **camera_far_clip_distance** (world, camera) : float
  918. Returns the far clip distance of the *camera*.
  919. **camera_set_far_clip_distance** (world, camera, far)
  920. Sets the far clip distance of the *camera*.
  921. **camera_set_orthographic_size** (world, camera, half_size)
  922. Sets the vertical *half_size* of the orthographic view volume.
  923. The horizontal size is proportional to the viewport's aspect ratio.
  924. **camera_screen_to_world** (world, camera, pos) : Vector3
  925. Returns *pos* from screen-space to world-space coordinates.
  926. **camera_world_to_screen** (world, camera, pos) : Vector3
  927. Returns *pos* from world-space to screen-space coordinates.
  928. Sound
  929. -----
  930. **play_sound** (world, name, [loop, volume, position, range]) : SoundInstanceId
  931. Plays the sound with the given *name* at the given *position*, with the given
  932. *volume* and *range*. *loop* controls whether the sound must loop or not.
  933. **stop_sound** (world, id)
  934. Stops the sound with the given *id*.
  935. **link_sound** (world, id, unit, node)
  936. Links the sound *id* to the *node* of the given *unit*.
  937. After this call, the sound *id* will follow the unit *unit*.
  938. **set_listener_pose** (world, pose)
  939. Sets the *pose* of the listener.
  940. **set_sound_position** (world, id, position)
  941. Sets the *position* of the sound *id*.
  942. **set_sound_range** (world, id, range)
  943. Sets the *range* of the sound *id*.
  944. **set_sound_volume** (world, id, volume)
  945. Sets the *volume* of the sound *id*.
  946. Level
  947. -----
  948. **load_level** (world, name, [pos, rot]) : Level
  949. Loads the level *name* into the world at the given *position* and *rotation*.