lua_api.rst 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372
  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, scale]) : UnitId
  278. Spawns a new instance of the unit *name* at the given *position*, *rotation* and *scale*.
  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. **unit_by_name** (world, name) : UnitId
  288. Returns the unit with the given Level Editor *name* or ``nil`` if no such unit is found.
  289. If there are multiple units with the same name, a random one will be returned.
  290. **update_animations** (world, dt)
  291. Update all animations with *dt*.
  292. **update_scene** (world, dt)
  293. Updates the scene with *dt*.
  294. **update** (world, dt)
  295. Updates the world with *dt*.
  296. **create_debug_line** (world, depth_test) : DebugLine
  297. Creates a new DebugLine. *depth_test* controls whether to
  298. enable depth test when rendering the lines.
  299. **destroy_debug_line** (world, line)
  300. Destroys the debug *line*.
  301. **create_screen_gui** (world) : Gui
  302. Creates a new Gui.
  303. **scene_graph** (world) : SceneGraph
  304. Returns the scene graph.
  305. **render_world** (world) : RenderWorld
  306. Returns the render sub-world.
  307. **physics_world** (world) : PhysicsWorld
  308. Returns the physics sub-world.
  309. **sound_world** (world) : SoundWorld
  310. Returns the sound sub-world.
  311. **animation_state_machine** (world) : AnimationStateMachine
  312. Returns the animation state machine.
  313. Camera
  314. ------
  315. **camera_create** (world, unit, projection, fov, far_range, near_range, pose) : Id
  316. Creates a new camera for *unit* and returns its id.
  317. Projection can be either ``orthographic`` or ``perspective``.
  318. **camera_instances** (world, unit) : Id
  319. Returns the IDs for all the cameras of the *unit*.
  320. **camera_set_projection_type** (world, unit, projection)
  321. Sets the projection type of the camera.
  322. Projection can be either ``orthographic`` or ``perspective``.
  323. **camera_projection_type** (world, unit) : string
  324. Returns the projection type of the camera.
  325. It can be either ``orthographic`` or ``perspective``.
  326. **camera_fov** (world, unit) : float
  327. Returns the field-of-view of the camera in degrees.
  328. **camera_set_fov** (world, unit, fov)
  329. Sets the field-of-view of the camera in degrees.
  330. **camera_near_clip_distance** (world, unit) : float
  331. Returns the near clip distance of the camera.
  332. **camera_set_near_clip_distance** (world, unit, near)
  333. Sets the near clip distance of the camera.
  334. **camera_far_clip_distance** (world, unit) : float
  335. Returns the far clip distance of the camera.
  336. **camera_set_far_clip_distance** (world, unit, far)
  337. Sets the far clip distance of the camera.
  338. **camera_set_orthographic_size** (world, unit, half_size)
  339. Sets the vertical *half_size* of the orthographic view volume.
  340. The horizontal size is proportional to the viewport's aspect ratio.
  341. **camera_screen_to_world** (world, unit, pos) : Vector3
  342. Returns *pos* from screen-space to world-space coordinates.
  343. **camera_world_to_screen** (world, unit, pos) : Vector3
  344. Returns *pos* from world-space to screen-space coordinates.
  345. Sound
  346. -----
  347. **play_sound** (world, name, [loop, volume, position, range]) : SoundInstanceId
  348. Plays the sound with the given *name* at the given *position*, with the given
  349. *volume* and *range*. *loop* controls whether the sound must loop or not.
  350. **stop_sound** (world, id)
  351. Stops the sound with the given *id*.
  352. **link_sound** (world, id, unit, node)
  353. Links the sound *id* to the *node* of the given *unit*.
  354. After this call, the sound *id* will follow the unit *unit*.
  355. **set_listener_pose** (world, pose)
  356. Sets the *pose* of the listener.
  357. **set_sound_position** (world, id, position)
  358. Sets the *position* of the sound *id*.
  359. **set_sound_range** (world, id, range)
  360. Sets the *range* of the sound *id*.
  361. **set_sound_volume** (world, id, volume)
  362. Sets the *volume* of the sound *id*.
  363. Level
  364. -----
  365. **load_level** (world, name, [pos, rot]) : Level
  366. Loads the level *name* into the world at the given *position* and *rotation*.
  367. SceneGraph
  368. ==========
  369. **create** (sg, unit, position, rotation, scale) : Id
  370. Creates the transform for the *unit* and returns its ID.
  371. **destroy** (sg, unit, id)
  372. Destroys the transform for the *unit*. The transform *id* is ignored.
  373. **instances** (sg, unit) : Id
  374. Returns the IDs for all the transforms of the *unit*.
  375. **local_position** (sg, unit) : Vector3
  376. Returns the local position of the *unit*.
  377. **local_rotation** (sg, unit) : Quaternion
  378. Returns the local rotation of the *unit*.
  379. **local_scale** (sg, unit) : Vector3
  380. Returns the local scale of the *unit*.
  381. **local_pose** (sg, unit) : Matrix4x4
  382. Returns the local pose of the *unit*.
  383. **world_position** (sg, unit) : Vector3
  384. Returns the world position of the *unit*.
  385. **world_rotation** (sg, unit) : Quaternion
  386. Returns the world rotation of the *unit*.
  387. **world_pose** (sg, unit) : Matrix4x4
  388. Returns the world pose of the *unit*.
  389. **set_local_position** (sg, unit, position)
  390. Sets the local *position* of the *unit*.
  391. **set_local_rotation** (sg, unit, rotation)
  392. Sets the local *rotation* of the *unit*.
  393. **set_local_scale** (sg, unit, scale)
  394. Sets the local *scale* of the *unit*.
  395. **set_local_pose** (sg, unit, pose)
  396. Sets the local *pose* of the *unit*.
  397. **link** (sg, child, parent)
  398. Links the unit *child* to the unit *parent*.
  399. **unlink** (sg, unit)
  400. Unlinks the *unit* from its parent if it has any.
  401. After unlinking, the @a unit's local pose is set to its previous world pose.
  402. Material
  403. ========
  404. **set_float** (material, name, value)
  405. Sets the *value* of the variable *name*.
  406. **set_vector2** (material, name, value)
  407. Sets the *value* of the variable *name*.
  408. **set_vector3** (material, name, value)
  409. Sets the *value* of the variable *name*.
  410. **set_vector4** (material, name, value)
  411. Sets the *value* of the variable *name*.
  412. **set_matrix4x4** (material, name, value)
  413. Sets the *value* of the variable *name*.
  414. RenderWorld
  415. ===========
  416. **enable_debug_drawing** (rw, enable)
  417. Sets whether to *enable* debug drawing.
  418. Mesh
  419. ----
  420. **mesh_create** (rw, unit, mesh_resource, geometry_name, material_resource, visible, pose) : Id
  421. Creates a new mesh instance for *unit* and returns its id.
  422. **mesh_destroy** (rw, id)
  423. Destroys the mesh *id*.
  424. **mesh_instances** (rw, unit) : Id
  425. Returns the IDs for all the meshes of the *unit*.
  426. **mesh_material** (rw, id) : Material
  427. Returns the material of the mesh *id*.
  428. **mesh_set_material** (rw, id, material)
  429. Sets the *material* of the mesh *id*.
  430. **mesh_set_visible** (rw, id, visible)
  431. Sets whether the mesh *id* is *visible*.
  432. **mesh_obb** (rw, id) : Matrix4x4, Vector3
  433. Returns the OBB of the mesh *id* as (pose, half_extents).
  434. **mesh_cast_ray** (rw, id, from, dir) : float
  435. Returns the distance along ray (from, dir) to intersection point with the mesh *id* or -1.0 if no intersection.
  436. Sprite
  437. ------
  438. **sprite_create** (rw, unit, sprite_resource, material_resource, visible, pose) : Id
  439. Creates a new sprite instance for the *unit* and returns its id.
  440. **sprite_destroy** (rw, unit)
  441. Destroys the sprite of the *unit*.
  442. **sprite_instances** (rw, unit) : Id
  443. Returns the IDs for all the sprites of the *unit*.
  444. **sprite_material** (rw, unit) : Material
  445. Returns the material of the sprite.
  446. **sprite_set_material** (rw, unit, material)
  447. Sets the *material* of the sprite.
  448. **sprite_set_frame** (rw, unit, index)
  449. Sets the frame *index* of the sprite.
  450. The *index* automatically wraps if it greater than
  451. the total number of frames in the sprite.
  452. **sprite_set_visible** (rw, unit, visible)
  453. Sets whether the sprite is *visible*.
  454. **sprite_flip_x** (rw, unit, flip)
  455. Sets whether to flip the sprite on the x-axis.
  456. **sprite_flip_y** (rw, unit, flip)
  457. Sets whether to flip the sprite on the y-axis.
  458. **sprite_set_layer** (rw, unit, layer)
  459. Sets the layer of the sprite.
  460. **sprite_set_depth** (rw, unit, depth)
  461. Sets the depth of the sprite.
  462. **sprite_obb** (rw, unit) : Matrix4x4, Vector3
  463. Returns the OBB of the sprite as (pose, half_extents).
  464. **sprite_cast_ray** (rw, unit, from, dir) : float, int, int
  465. Returns (t, layer, depth), where *t* is the distance along ray (from, dir) to
  466. intersection point with the sprite or -1.0 if no intersection.
  467. Light
  468. -----
  469. **light_create** (rw, unit, type, range, intensity, spot_angle, color, pose) : Id
  470. Creates a new light for the *unit* and returns its id.
  471. Type can be either ``directional``, ``omni`` or ``spot``.
  472. **light_destroy** (rw, unit)
  473. Destroys the light of the *unit*.
  474. **light_instances** (rw, unit) : Id
  475. Returns the IDs for all the lights of the *unit*.
  476. **light_type** (rw, unit) : string
  477. Returns the type of the light of the *unit*.
  478. It can be either ``directional``, ``omni`` or ``spot``.
  479. **light_color** (rw, unit) : Color4
  480. Returns the color of the light.
  481. **light_range** (rw, unit) : float
  482. Returns the range of the light.
  483. **light_intensity** (rw, unit) : float
  484. Returns the intensity of the light.
  485. **light_spot_angle** (rw, unit) : float
  486. Returns the spot angle of the light.
  487. **light_set_type** (rw, unit, type)
  488. Sets the *type* of the light.
  489. **light_set_color** (rw, unit, color)
  490. Sets the *color* of the light.
  491. **light_set_range** (rw, unit, range)
  492. Sets the *range* of the light.
  493. **light_set_intensity** (rw, unit, intensity)
  494. Sets the *intensity* of the light.
  495. **light_set_spot_angle** (rw, unit, angle)
  496. Sets the spot *angle* of the light.
  497. **light_debug_draw** (rw, unit, debug_line)
  498. Fills *debug_line* with debug lines from the light.
  499. PhysicsWorld
  500. =============
  501. **gravity** (pw) : Vector3
  502. Returns the gravity.
  503. **set_gravity** (pw, gravity)
  504. Sets the gravity.
  505. **cast_ray** (pw, from, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  506. Casts a ray into the physics world and returns the closest actor it intersects with.
  507. If *hit* is true the following return values contain the *collision_pos* in
  508. world space, the *normal* of the surface that was hit, the time of impact
  509. in [0..1] and the *unit* and the *actor* that was hit.
  510. **cast_ray_all** (pw, from, dir, length) : table
  511. Casts a ray into the physics world and returns all the
  512. actors it intersects with as an array of `RaycastHit`_ tables.
  513. **cast_sphere** (pw, from, radius, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  514. Casts a sphere into the physics world and returns the closest actor it intersects with.
  515. If *hit* is true the following return values contain the *collision_pos* in
  516. world space, the *normal* of the surface that was hit, the time of impact
  517. in [0..1] and the *unit* and the *actor* that was hit.
  518. **cast_box** (pw, from, half_extents, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  519. Casts a box into the physics world and returns the closest actor it intersects with.
  520. If *hit* is true the following return values contain the *collision_pos* in
  521. world space, the *normal* of the surface that was hit, the time of impact
  522. in [0..1] and the *unit* and the *actor* that was hit.
  523. **enable_debug_drawing** (pw, enable)
  524. Sets whether to *enable* debug drawing.
  525. RaycastHit
  526. ----------
  527. RaycastHit is a lua table with 5 fields:
  528. * ``[1]``: The collision position in world space.
  529. * ``[2]``: The normal of the surface that was hit.
  530. * ``[3]``: The time of impact in [0..1].
  531. * ``[4]``: The unit that was hit.
  532. * ``[5]``: The actor that was hit.
  533. Actor
  534. -----
  535. **actor_destroy** (pw, actor)
  536. Destroys the *actor* of the *unit*.
  537. **actor_instances** (pw, unit) : Id
  538. Returns the IDs for all the actors of the *unit*.
  539. **actor_world_position** (pw, actor) : Vector3
  540. Returns the world position of the actor.
  541. **actor_world_rotation** (pw, actor) : Quaternion
  542. Returns the world rotation of the actor.
  543. **actor_world_pose** (pw, actor) : Matrix4x4
  544. Returns the world pose of the actor.
  545. **actor_teleport_world_position** (pw, actor, position)
  546. Teleports the actor to the given world position.
  547. **actor_teleport_world_rotation** (pw, actor, rotation)
  548. Teleports the actor to the given world rotation.
  549. **actor_teleport_world_pose** (pw, actor, pose)
  550. Teleports the actor to the given world pose.
  551. **actor_center_of_mass** (pw, actor) : Vector3
  552. Returns the center of mass of the actor.
  553. **actor_enable_gravity** (pw, actor)
  554. Enables gravity for the actor.
  555. **actor_disable_gravity** (pw, actor)
  556. Disables gravity for the actor.
  557. **actor_enable_collision** (pw, actor)
  558. Enables collision detection for the actor.
  559. **actor_disable_collision** (pw, actor)
  560. Disables collision detection for the actor.
  561. **actor_set_collision_filter** (pw, actor, name)
  562. Sets the collision filter of the actor.
  563. **actor_set_kinematic** (pw, actor, kinematic)
  564. Sets whether the actor is kinematic or not.
  565. .. note::
  566. This call has no effect on static actors.
  567. **actor_is_static** (pw, actor) : bool
  568. Returns whether the actor is static.
  569. **actor_is_dynamic** (pw, actor) bool
  570. Returns whether the actor is dynamic.
  571. **actor_is_kinematic** (pw, actor) : bool
  572. Returns whether the actor is kinematic (keyframed).
  573. **actor_is_nonkinematic** (pw, actor) : bool
  574. Returns whether the actor is nonkinematic (i.e. dynamic and not kinematic).
  575. **actor_linear_damping** (pw, actor) : float
  576. Returns the linear damping of the actor.
  577. **actor_set_linear_damping** (pw, actor, damping)
  578. Sets the linear damping of the actor.
  579. **actor_angular_damping** (pw, actor) : float
  580. Returns the angular damping of the actor.
  581. **actor_set_angular_damping** (pw, actor, rate)
  582. Sets the angular damping of the actor.
  583. **actor_linear_velocity** (pw, actor) : Vector3
  584. Returns the linear velocity of the actor.
  585. **actor_set_linear_velocity** (pw, actor, velocity)
  586. Sets the linear velocity of the actor.
  587. .. note::
  588. This call only affects nonkinematic actors.
  589. **actor_angular_velocity** (pw, actor) : Vector3
  590. Returns the angular velocity of the actor.
  591. **actor_set_angular_velocity** (pw, actor, velocity)
  592. Sets the angular velocity of the actor.
  593. .. note::
  594. This call only affects nonkinematic actors.
  595. **actor_add_impulse** (pw, actor, impulse)
  596. Adds a linear impulse (acting along the center of mass) to the actor.
  597. .. note::
  598. This call only affects nonkinematic actors.
  599. **actor_add_impulse_at** (pw, actor, impulse, position)
  600. Adds a linear impulse (acting along the world position *pos*) to the actor.
  601. .. note::
  602. This call only affects nonkinematic actors.
  603. **actor_add_torque_impulse** (pw, actor, impulse)
  604. Adds a torque impulse to the actor.
  605. **actor_push** (pw, actor, velocity, mass)
  606. Pushes the actor as if it was hit by a point object with the given *mass*
  607. travelling at the given *velocity*.
  608. .. note::
  609. This call only affects nonkinematic actors.
  610. **actor_push_at** (pw, actor, velocity, mass, position)
  611. Like push() but applies the force at the world position *pos*.
  612. .. note::
  613. This call only affects nonkinematic actors.
  614. **actor_is_sleeping** (pw, actor) : bool
  615. Returns whether the actor is sleeping.
  616. **actor_wake_up** (pw, actor)
  617. Wakes the actor up.
  618. SoundWorld
  619. ===========
  620. **stop_all** (sound_world)
  621. Stops all the sounds in the world.
  622. **pause_all** (sound_world)
  623. Pauses all the sounds in the world
  624. **resume_all** (sound_world)
  625. Resumes all previously paused sounds in the world.
  626. **is_playing** (sound_world, id) : bool
  627. Returns whether the sound *id* is playing.
  628. AnimationStateMachine
  629. =====================
  630. **variable_id** (state_machine, unit, name) : Id
  631. Returns the ID of the variable *name* in the *state_machine*.
  632. **variable** (state_machine, unit, variable_id) : number
  633. Returns the value of the *variable_id* in the *state_machine*.
  634. **set_variable** (state_machine, unit, variable_id, value)
  635. Sets the *value* of the *variable_id* in the *state_machine*.
  636. **trigger** (state_machine, unit, name)
  637. Triggers the event *name* in the *state_machine*.
  638. ResourcePackage
  639. ===============
  640. **load** (package)
  641. Loads all the resources in the *package*.
  642. .. note::
  643. The resources are not immediately available after the call is made,
  644. instead, you have to poll for completion with has_loaded().
  645. **unload** (package)
  646. Unloads all the resources in the *package*.
  647. **flush** (package)
  648. Waits until the *package* has been loaded.
  649. **has_loaded** (package) : bool
  650. Returns whether the *package* has been loaded.
  651. Device
  652. ======
  653. **argv** () : table
  654. Returns a table containing the command line parameters the engine was started with.
  655. **platform** () : string
  656. Returns a string identifying what platform the engine is running on.
  657. It can be either ``android``, ``linux`` or ``windows``
  658. **architecture** () : string
  659. Returns a string identifying what architecture the engine is running on.
  660. It can be either ``32-bit`` or ``64-bit``.
  661. **version** () : string
  662. Returns a string identifying the engine version.
  663. The form is "major.minor.micro".
  664. **quit** ()
  665. Quits the application.
  666. **resolution** () : float, float
  667. Returns the main window resolution (width, height).
  668. **create_world** () : World
  669. Creates a new world.
  670. **destroy_world** (world)
  671. Destroys the given *world*.
  672. **render** (world, camera)
  673. Renders *world* using *camera*.
  674. **create_resource_package** (name) : ResourcePackage
  675. Returns the resource package with the given *package_name* name.
  676. **destroy_resource_package** (package)
  677. Destroy a previously created resource *package*.
  678. .. note::
  679. To unload the resources loaded by the package, you have to call
  680. ResourcePackage.unload() first.
  681. **console_send** (table)
  682. Sends the given lua *table* to clients connected to the engine.
  683. Values can be either ``nil``, bool, number, string, table, array, Vector2, Vector3, Quaternion, Matrix4x4 or Color4.
  684. **can_get** (type, name) : bool
  685. Returns whether the resource (type, name) is loaded.
  686. When resource autoload is enabled it always returns true.
  687. **enable_resource_autoload** (enable)
  688. Sets whether resources should be automatically loaded when accessed.
  689. **temp_count** () : int, int, int
  690. Returns the number of temporary objects used by Lua.
  691. **set_temp_count** (nv, nq, nm)
  692. Sets the number of temporary objects used by Lua.
  693. **guid** () : string
  694. Returns a new GUID.
  695. Gui
  696. ===
  697. **move** (gui, pos)
  698. Moves the Gui to *pos*.
  699. **triangle** (gui, a, b, c, color)
  700. Draws a triangle defined by vertices *a*, *b* and *c*.
  701. **rect** (gui, pos, size, color)
  702. Draws a rectangle.
  703. **image** (gui, pos, size, material_resource, color)
  704. Draws an image.
  705. **image_uv** (gui, pos, size, uv0, uv1, material_resource, color)
  706. Draws an image with explicit UV coordinates.
  707. **text** (gui, pos, font_size, str, font_resource, material_resource, color)
  708. Draws text.
  709. DebugLine
  710. =========
  711. **add_line** (debug_line, start, end, color)
  712. Adds a line from *start* to *end* with the given *color*.
  713. **add_axes** (debug_line, tm, length)
  714. Adds lines for each axis with the given *length*.
  715. **add_arc** (debug_line, center, radius, plane_normal, midpoint_normal, color, [circle_segments = 36]);
  716. Adds an arc at *center* with the given *radius* and *plane_normal* and *midpoint_normal* vectors.
  717. **add_circle** (debug_line, center, radius, normal, color, [segments = 36])
  718. Adds a circle at *center* with the given *radius* and *normal* vector.
  719. **add_cone** (debug_line, from, to, radius, color, [segments = 36])
  720. Adds a cone with the base centered at *from* and the tip at *to*.
  721. **add_sphere** (debug_line, center, radius, color, [segments = 36])
  722. Adds a sphere at *center* with the given *radius*.
  723. **add_obb** (debug_line, tm, half_extents, color)
  724. Adds an orientd bounding box. *tm* describes the position and orientation of
  725. the box. *half_extents* describes the size of the box along the axis.
  726. **add_frustum** (debug_line, mvp, color)
  727. Adds a frustum defined by *mvp*.
  728. **add_unit** (debug_line, tm, name, color)
  729. Adds the meshes from the unit *name*.
  730. **reset** (debug_line)
  731. Resets all the lines.
  732. **submit** (debug_line)
  733. Submits the lines to renderer for drawing.
  734. Input
  735. =====
  736. Keyboard
  737. --------
  738. **name** () : string
  739. Returns the name of keyboard.
  740. **connected** () : bool
  741. Returns whether the keyboard is connected and functioning.
  742. **num_buttons** () : int
  743. Returns the number of buttons of the keyboard.
  744. **num_axes** () : int
  745. Returns the number of axes of the keyboard.
  746. **pressed** (id) : bool
  747. Returns whether the button *id* is pressed in the current frame.
  748. **released** (id) : bool
  749. Returns whether the button *id* is released in the current frame.
  750. **any_pressed** () : bool
  751. Returns the *id* of the first button that was pressed in the current frame
  752. or ``nil`` if no buttons were pressed at all.
  753. **any_released** () : bool
  754. Returns the *id* of the first button that was released in the current frame
  755. or ``nil`` if no buttons were released at all.
  756. **button** (id) : float
  757. Returns the value of the button *id* in the range [0..1].
  758. **button_name** (id) : string
  759. Returns the name of the button *id*.
  760. **button_id** (name) : int
  761. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  762. Keyboard Button Names
  763. ~~~~~~~~~~~~~~~~~~~~~
  764. * ``tab``, ``enter``, ``escape``, ``space``, ``backspace``
  765. * ``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``
  766. * ``f1``, ``f2``, ``f3``, ``f4``, ``f5``, ``f6``, ``f7``, ``f8``, ``f9``, ``f10``, ``f11``, ``f12``
  767. * ``home``, ``left``, ``up``, ``right``, ``down``, ``page_up``, ``page_down``, ``ins``, ``del``, ``end``
  768. * ``ctrl_left``, ``ctrl_right``, ``shift_left``, ``shift_right``, ``caps_lock``, ``alt_left``, ``alt_right``, ``super_left``, ``super_right``
  769. * ``0``, ``1``, ``2``, ``3``, ``4``, ``5``, ``6``, ``7``, ``8``, ``9``
  770. * ``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``
  771. Keyboard Axis Names
  772. ~~~~~~~~~~~~~~~~~~~
  773. None.
  774. Mouse
  775. -----
  776. **name** () : string
  777. Returns the name of the mouse.
  778. **connected** () : bool
  779. Returns whether the mouse is connected and functioning.
  780. **num_buttons** () : int
  781. Returns the number of buttons of the mouse.
  782. **num_axes** () : int
  783. Returns the number of axes of the mouse.
  784. **pressed** (id) : bool
  785. Returns whether the button *id* is pressed in the current frame.
  786. **released** (id) : bool
  787. Returns whether the button *id* is released in the current frame.
  788. **any_pressed** () : bool
  789. Returns the *id* of the first button that was pressed in the current frame
  790. or ``nil`` if no buttons were pressed at all.
  791. **any_released** () : bool
  792. Returns the *id* of the first button that was released in the current frame
  793. or ``nil`` if no buttons were released at all.
  794. **button** (id) : float
  795. Returns the value of the button *id* in the range [0..1].
  796. **axis** (id) : Vector3
  797. Returns the value of the axis *id*.
  798. **button_name** (id) : string
  799. Returns the name of the button *id*.
  800. **axis_name** (id) : string
  801. Returns the name of the axis *id*.
  802. **button_id** (name) : int
  803. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  804. **axis_id** (name) : int
  805. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  806. Mouse Button Names
  807. ~~~~~~~~~~~~~~~~~~
  808. ``left``, ``middle``, ``right``, ``extra_1``, ``extra_2``
  809. Mouse Axis Names
  810. ~~~~~~~~~~~~~~~~
  811. * ``cursor``: Returns the cursor position (x, y) in screen coordinates.
  812. * ``cursor_delta``: Returns the delta of the cursor position (x, y) since last frame.
  813. * ``wheel``: Returns the movement of the mouse wheel in the y axis. Positive values of y mean upward scrolling, negative values mean downward scrolling.
  814. Touch
  815. -----
  816. **name** () : string
  817. Returns the name of the touch.
  818. **connected** () : bool
  819. Returns whether the touch is connected and functioning.
  820. **num_buttons** () : int
  821. Returns the number of buttons of the touch.
  822. **num_axes** () : int
  823. Returns the number of axes of the touch.
  824. **pressed** (id) : bool
  825. Returns whether the button *id* is pressed in the current frame.
  826. **released** (id) : bool
  827. Returns whether the button *id* is released in the current frame.
  828. **any_pressed** () : bool
  829. Returns the *id* of the first button that was pressed in the current frame
  830. or ``nil`` if no buttons were pressed at all.
  831. **any_released** () : bool
  832. Returns the *id* of the first button that was released in the current frame
  833. or ``nil`` if no buttons were released at all.
  834. **button** (id) : float
  835. Returns the value of the button *id* in the range [0..1].
  836. **axis** (id) : Vector3
  837. Returns the value of the axis *id*.
  838. **button_name** (id) : string
  839. Returns the name of the button *id*.
  840. **axis_name** (id) : string
  841. Returns the name of the axis *id*.
  842. **button_id** (name) : int
  843. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  844. **axis_id** (name) : int
  845. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  846. Pad1, Pad2, Pad3, Pad4
  847. ----------------------
  848. **name** () : string
  849. Returns the name of the pad.
  850. **connected** () : bool
  851. Returns whether the pad is connected and functioning.
  852. **num_buttons** () : int
  853. Returns the number of buttons of the pad.
  854. **num_axes** () : int
  855. Returns the number of axes of the pad.
  856. **pressed** (id) : bool
  857. Returns whether the button *id* is pressed in the current frame.
  858. **released** (id) : bool
  859. Returns whether the button *id* is released in the current frame.
  860. **any_pressed** () : bool
  861. Returns the *id* of the first button that was pressed in the current frame
  862. or ``nil`` if no buttons were pressed at all.
  863. **any_released** () : bool
  864. Returns the *id* of the first button that was released in the current frame
  865. or ``nil`` if no buttons were released at all.
  866. **button** (id) : float
  867. Returns the value of the button *id* in the range [0..1].
  868. **axis** (id) : Vector3
  869. Returns the value of the axis *id*.
  870. **button_name** (id) : string
  871. Returns the name of the button *id*.
  872. **axis_name** (id) : string
  873. Returns the name of the axis *id*.
  874. **button_id** (name) : int
  875. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  876. **axis_id** (name) : int
  877. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  878. **deadzone** (id) : deadzone_mode, deadzone_size
  879. Returns the deadzone mode and size for the axis *id*.
  880. **set_deadzone** (id, deadzone_mode, deadzone_size)
  881. Sets the *deadzone_mode* and *deadzone_size* for the axis *id*.
  882. Pad Button Names
  883. ~~~~~~~~~~~~~~~~
  884. * ``up``, ``down``, ``left``, ``right``
  885. * ``start``, ``back``, ``guide``
  886. * ``thumb_left``, ``thumb_right``
  887. * ``shoulder_left``, ``shoulder_right``
  888. * ``a``, ``b``, ``x``, ``y``
  889. Pad Axis Names
  890. ~~~~~~~~~~~~~~
  891. * ``left``, ``right``: Returns the direction (x, y) of the left or right thumbstick [-1; +1].
  892. * ``trigger_left``, ``trigger_right``: The z element represents the left or right trigger [0; +1].
  893. Profiler
  894. ========
  895. **enter_scope** (name)
  896. Starts a new profile scope with the given *name*.
  897. **leave_scope** ()
  898. Ends the last profile scope.
  899. **record** (name, value)
  900. Records *value* with the given *name*. Value can be either number or Vector3.
  901. Display
  902. =======
  903. **modes** () : table
  904. Returns an array of `DisplayMode`_ tables.
  905. **set_mode** (id)
  906. Sets the display mode *id*.
  907. The initial display mode is automatically reset when the program terminates.
  908. DisplayMode
  909. -----------
  910. DisplayMode is a lua table with 3 fields:
  911. * ``id``: The id of the display mode.
  912. * ``width``: The width of the display mode.
  913. * ``height``: The height of the display mode.
  914. Window
  915. ======
  916. **show** ()
  917. Shows the window.
  918. **hide** ()
  919. Hides the window.
  920. **resize** (width, height)
  921. Resizes the window to *width* and *height*.
  922. **move** (x, y)
  923. Moves the window to *x* and *y*.
  924. **minimize** ()
  925. Minimizes the window.
  926. **maximize** ()
  927. Maximizes the window.
  928. **restore** ()
  929. Restores the window.
  930. **title** () : string
  931. Returns the title of the window.
  932. **set_title** (title)
  933. Sets the title of the window.
  934. **show_cursor** (show)
  935. Sets whether to *show* the cursor.
  936. **set_fullscreen** (fullscreen)
  937. Sets whether the window is *fullscreen*.
  938. **set_cursor** (cursor)
  939. Sets the mouse *cursor* on this window.