lua_api.rst 37 KB

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