lua_api.rst 36 KB

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