lua_api.rst 37 KB

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