lua_api.rst 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325
  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_raycast** (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_frame** (rw, unit, index)
  432. Sets the frame *index* of the sprite.
  433. **sprite_set_visible** (rw, unit, visible)
  434. Sets whether the sprite is *visible*.
  435. **sprite_flip_x** (rw, unit, flip)
  436. Sets whether to flip the sprite on the x-axis.
  437. **sprite_flip_y** (rw, unit, flip)
  438. Sets whether to flip the sprite on the y-axis.
  439. **sprite_set_layer** (rw, unit, layer)
  440. Sets the layer of the sprite.
  441. **sprite_set_depth** (rw, unit, depth)
  442. Sets the depth of the sprite.
  443. **sprite_obb** (rw, unit) : Matrix4x4, Vector3
  444. Returns the OBB of the sprite as (pose, half_extents).
  445. **sprite_raycast** (rw, unit, from, dir) : float, int, int
  446. Returns (t, layer, depth), where *t* is the distance along ray (from, dir) to
  447. intersection point with the sprite or -1.0 if no intersection.
  448. Light
  449. -----
  450. **light_create** (rw, unit, type, range, intensity, spot_angle, color, pose) : Id
  451. Creates a new light for the *unit* and returns its id.
  452. Type can be either ``directional``, ``omni`` or ``spot``.
  453. **light_destroy** (rw, unit)
  454. Destroys the light of the *unit*.
  455. **light_instances** (rw, unit) : Id
  456. Returns the IDs for all the lights of the *unit*.
  457. **light_type** (rw, unit) : string
  458. Returns the type of the light of the *unit*.
  459. It can be either ``directional``, ``omni`` or ``spot``.
  460. **light_color** (rw, unit) : Color4
  461. Returns the color of the light.
  462. **light_range** (rw, unit) : float
  463. Returns the range of the light.
  464. **light_intensity** (rw, unit) : float
  465. Returns the intensity of the light.
  466. **light_spot_angle** (rw, unit) : float
  467. Returns the spot angle of the light.
  468. **light_set_type** (rw, unit, type)
  469. Sets the *type* of the light.
  470. **light_set_color** (rw, unit, color)
  471. Sets the *color* of the light.
  472. **light_set_range** (rw, unit, range)
  473. Sets the *range* of the light.
  474. **light_set_intensity** (rw, unit, intensity)
  475. Sets the *intensity* of the light.
  476. **light_set_spot_angle** (rw, unit, angle)
  477. Sets the spot *angle* of the light.
  478. **light_debug_draw** (rw, unit, debug_line)
  479. Fills *debug_line* with debug lines from the light.
  480. PhysicsWorld
  481. =============
  482. **gravity** (pw) : Vector3
  483. Returns the gravity.
  484. **set_gravity** (pw, gravity)
  485. Sets the gravity.
  486. **cast_ray** (pw, from, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  487. Casts a ray into the physics world and returns the closest actor it intersects with.
  488. If *hit* is true the following return values contain the *collision_pos* in
  489. world space, the *normal* of the surface that was hit, the time of impact
  490. in [0..1] and the *unit* and the *actor* that was hit.
  491. **cast_ray_all** (pw, from, dir, length) : table
  492. Casts a ray into the physics world and returns all the
  493. actors it intersects with as an array of `RaycastHit`_ tables.
  494. **cast_sphere** (pw, from, radius, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  495. Casts a sphere into the physics world and returns the closest actor it intersects with.
  496. If *hit* is true the following return values contain the *collision_pos* in
  497. world space, the *normal* of the surface that was hit, the time of impact
  498. in [0..1] and the *unit* and the *actor* that was hit.
  499. **cast_box** (pw, from, half_extents, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  500. Casts a box into the physics world and returns the closest actor it intersects with.
  501. If *hit* is true the following return values contain the *collision_pos* in
  502. world space, the *normal* of the surface that was hit, the time of impact
  503. in [0..1] and the *unit* and the *actor* that was hit.
  504. **enable_debug_drawing** (pw, enable)
  505. Sets whether to *enable* debug drawing.
  506. RaycastHit
  507. ----------
  508. RaycastHit is a lua table with 3 fields:
  509. * ``[1]``: The collision position in world space.
  510. * ``[2]``: The normal of the surface that was hit.
  511. * ``[3]``: The time of impact in [0..1].
  512. * ``[4]``: The unit that was hit.
  513. * ``[5]``: The actor that was hit.
  514. Actor
  515. -----
  516. **actor_instances** (pw, unit) : Id
  517. Returns the IDs for all the actors of the *unit*.
  518. **actor_world_position** (pw, actor) : Vector3
  519. Returns the world position of the actor.
  520. **actor_world_rotation** (pw, actor) : Quaternion
  521. Returns the world rotation of the actor.
  522. **actor_world_pose** (pw, actor) : Matrix4x4
  523. Returns the world pose of the actor.
  524. **actor_teleport_world_position** (pw, actor, position)
  525. Teleports the actor to the given world position.
  526. **actor_teleport_world_rotation** (pw, actor, rotation)
  527. Teleports the actor to the given world rotation.
  528. **actor_teleport_world_pose** (pw, actor, pose)
  529. Teleports the actor to the given world pose.
  530. **actor_center_of_mass** (pw, actor) : Vector3
  531. Returns the center of mass of the actor.
  532. **actor_enable_gravity** (pw, actor)
  533. Enables gravity for the actor.
  534. **actor_disable_gravity** (pw, actor)
  535. Disables gravity for the actor.
  536. **actor_enable_collision** (pw, actor)
  537. Enables collision detection for the actor.
  538. **actor_disable_collision** (pw, actor)
  539. Disables collision detection for the actor.
  540. **actor_set_collision_filter** (pw, actor, name)
  541. Sets the collision filter of the actor.
  542. **actor_set_kinematic** (pw, actor, kinematic)
  543. Sets whether the actor is kinematic or not.
  544. .. note::
  545. This call has no effect on static actors.
  546. **actor_is_static** (pw, actor) : bool
  547. Returns whether the actor is static.
  548. **actor_is_dynamic** (pw, actor) bool
  549. Returns whether the actor is dynamic.
  550. **actor_is_kinematic** (pw, actor) : bool
  551. Returns whether the actor is kinematic (keyframed).
  552. **actor_is_nonkinematic** (pw, actor) : bool
  553. Returns whether the actor is nonkinematic (i.e. dynamic and not kinematic).
  554. **actor_linear_damping** (pw, actor) : float
  555. Returns the linear damping of the actor.
  556. **actor_set_linear_damping** (pw, actor, damping)
  557. Sets the linear damping of the actor.
  558. **actor_angular_damping** (pw, actor) : float
  559. Returns the angular damping of the actor.
  560. **actor_set_angular_damping** (pw, actor, rate)
  561. Sets the angular damping of the actor.
  562. **actor_linear_velocity** (pw, actor) : Vector3
  563. Returns the linear velocity of the actor.
  564. **actor_set_linear_velocity** (pw, actor, velocity)
  565. Sets the linear velocity of the actor.
  566. .. note::
  567. This call only affects nonkinematic actors.
  568. **actor_angular_velocity** (pw, actor) : Vector3
  569. Returns the angular velocity of the actor.
  570. **actor_set_angular_velocity** (pw, actor, velocity)
  571. Sets the angular velocity of the actor.
  572. .. note::
  573. This call only affects nonkinematic actors.
  574. **actor_add_impulse** (pw, actor, impulse)
  575. Adds a linear impulse (acting along the center of mass) to the actor.
  576. .. note::
  577. This call only affects nonkinematic actors.
  578. **actor_add_impulse_at** (pw, actor, impulse, position)
  579. Adds a linear impulse (acting along the world position *pos*) to the actor.
  580. .. note::
  581. This call only affects nonkinematic actors.
  582. **actor_add_torque_impulse** (pw, actor, impulse)
  583. Adds a torque impulse to the actor.
  584. **actor_push** (pw, actor, velocity, mass)
  585. Pushes the actor as if it was hit by a point object with the given *mass*
  586. travelling at the given *velocity*.
  587. .. note::
  588. This call only affects nonkinematic actors.
  589. **actor_push_at** (pw, actor, velocity, mass, position)
  590. Like push() but applies the force at the world position *pos*.
  591. .. note::
  592. This call only affects nonkinematic actors.
  593. **actor_is_sleeping** (pw, actor) : bool
  594. Returns whether the actor is sleeping.
  595. **actor_wake_up** (pw, actor)
  596. Wakes the actor up.
  597. SoundWorld
  598. ===========
  599. **stop_all** (sound_world)
  600. Stops all the sounds in the world.
  601. **pause_all** (sound_world)
  602. Pauses all the sounds in the world
  603. **resume_all** (sound_world)
  604. Resumes all previously paused sounds in the world.
  605. **is_playing** (sound_world, id) : bool
  606. Returns whether the sound *id* is playing.
  607. AnimationStateMachine
  608. =====================
  609. **variable_id** (state_machine, unit, name) : Id
  610. Returns the ID of the variable *name* in the *state_machine*.
  611. **variable** (state_machine, unit, variable_id) : number
  612. Returns the value of the *variable_id* in the *state_machine*.
  613. **set_variable** (state_machine, unit, variable_id, value)
  614. Sets the *value* of the *variable_id* in the *state_machine*.
  615. **trigger** (state_machine, unit, name)
  616. Triggers the event *name* in the *state_machine*.
  617. ResourcePackage
  618. ===============
  619. **load** (package)
  620. Loads all the resources in the *package*.
  621. .. note::
  622. The resources are not immediately available after the call is made,
  623. instead, you have to poll for completion with has_loaded().
  624. **unload** (package)
  625. Unloads all the resources in the *package*.
  626. **flush** (package)
  627. Waits until the *package* has been loaded.
  628. **has_loaded** (package) : bool
  629. Returns whether the *package* has been loaded.
  630. Device
  631. ======
  632. **argv** () : table
  633. Returns a table containing the command line parameters the engine was started with.
  634. **platform** () : string
  635. Returns a string identifying what platform the engine is running on.
  636. It can be either ``android``, ``linux`` or ``windows``
  637. **architecture** () : string
  638. Returns a string identifying what architecture the engine is running on.
  639. It can be either ``32-bit`` or ``64-bit``.
  640. **version** () : string
  641. Returns a string identifying the engine version.
  642. The form is "major.minor.micro".
  643. **quit** ()
  644. Quits the application.
  645. **resolution** () : float, float
  646. Returns the main window resolution (width, height).
  647. **create_world** () : World
  648. Creates a new world.
  649. **destroy_world** (world)
  650. Destroys the given *world*.
  651. **render** (world, camera)
  652. Renders *world* using *camera*.
  653. **create_resource_package** (name) : ResourcePackage
  654. Returns the resource package with the given *package_name* name.
  655. **destroy_resource_package** (package)
  656. Destroy a previously created resource *package*.
  657. .. note::
  658. To unload the resources loaded by the package, you have to call
  659. ResourcePackage.unload() first.
  660. **console_send** (table)
  661. Sends the given lua *table* to clients connected to the engine.
  662. Values can be either ``nil``, bool, number, string, table, array, Vector2, Vector3, Quaternion, Matrix4x4 or Color4.
  663. **can_get** (type, name) : bool
  664. Returns whether the resource (type, name) is loaded.
  665. When resource autoload is enabled it always returns true.
  666. **enable_resource_autoload** (enable)
  667. Sets whether resources should be automatically loaded when accessed.
  668. **temp_count** () : int, int, int
  669. Returns the number of temporary objects used by Lua.
  670. **set_temp_count** (nv, nq, nm)
  671. Sets the number of temporary objects used by Lua.
  672. **guid** () : string
  673. Returns a new GUID.
  674. Gui
  675. ===
  676. **move** (gui, pos)
  677. Moves the Gui to *pos*.
  678. **triangle** (gui, a, b, c, color)
  679. Draws a triangle defined by vertices *a*, *b* and *c*.
  680. **rect** (gui, pos, size, color)
  681. Draws a rectangle.
  682. **image** (gui, pos, size, material_resource, color)
  683. Draws an image.
  684. **image_uv** (gui, pos, size, uv0, uv1, material_resource, color)
  685. Draws an image with explicit UV coordinates.
  686. **text** (gui, pos, font_size, str, font_resource, material_resource, color)
  687. Draws text.
  688. DebugLine
  689. =========
  690. **add_line** (debug_line, start, end, color)
  691. Adds a line from *start* to *end* with the given *color*.
  692. **add_axes** (debug_line, tm, length)
  693. Adds lines for each axis with the given *length*.
  694. **add_arc** (debug_line, center, radius, plane_normal, midpoint_normal, color, [circle_segments = 36]);
  695. Adds an arc at *center* with the given *radius* and *plane_normal* and *midpoint_normal* vectors.
  696. **add_circle** (debug_line, center, radius, normal, color, [segments = 36])
  697. Adds a circle at *center* with the given *radius* and *normal* vector.
  698. **add_cone** (debug_line, from, to, radius, color, [segments = 36])
  699. Adds a cone with the base centered at *from* and the tip at *to*.
  700. **add_sphere** (debug_line, center, radius, color, [segments = 36])
  701. Adds a sphere at *center* with the given *radius*.
  702. **add_obb** (debug_line, tm, half_extents, color)
  703. Adds an orientd bounding box. *tm* describes the position and orientation of
  704. the box. *half_extents* describes the size of the box along the axis.
  705. **add_frustum** (debug_line, mvp, color)
  706. Adds a frustum defined by *mvp*.
  707. **add_unit** (debug_line, tm, name, color)
  708. Adds the meshes from the unit *name*.
  709. **reset** (debug_line)
  710. Resets all the lines.
  711. **submit** (debug_line)
  712. Submits the lines to renderer for drawing.
  713. Input
  714. =====
  715. Keyboard
  716. --------
  717. **name** () : string
  718. Returns the name of keyboard.
  719. **connected** () : bool
  720. Returns whether the keyboard is connected and functioning.
  721. **num_buttons** () : int
  722. Returns the number of buttons of the keyboard.
  723. **num_axes** () : int
  724. Returns the number of axes of the keyboard.
  725. **pressed** (id) : bool
  726. Returns whether the button *id* is pressed in the current frame.
  727. **released** (id) : bool
  728. Returns whether the button *id* is released in the current frame.
  729. **any_pressed** () : bool
  730. Returns whether any button is pressed in the current frame.
  731. **any_released** () : bool
  732. Returns whether any button is released in the current frame.
  733. **button** (id) : float
  734. Returns the value of the button *id* in the range [0..1].
  735. **button_name** (id) : string
  736. Returns the name of the button *id*.
  737. **button_id** (name) : int
  738. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  739. Keyboard Button Names
  740. ~~~~~~~~~~~~~~~~~~~~~
  741. * ``tab``, ``enter``, ``escape``, ``space``, ``backspace``
  742. * ``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``
  743. * ``f1``, ``f2``, ``f3``, ``f4``, ``f5``, ``f6``, ``f7``, ``f8``, ``f9``, ``f10``, ``f11``, ``f12``
  744. * ``home``, ``left``, ``up``, ``right``, ``down``, ``page_up``, ``page_down``, ``ins``, ``del``, ``end``
  745. * ``ctrl_left``, ``ctrl_right``, ``shift_left``, ``shift_right``, ``caps_lock``, ``alt_left``, ``alt_right``, ``super_left``, ``super_right``
  746. * ``0``, ``1``, ``2``, ``3``, ``4``, ``5``, ``6``, ``7``, ``8``, ``9``
  747. * ``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``
  748. Keyboard Axis Names
  749. ~~~~~~~~~~~~~~~~~~~
  750. None.
  751. Mouse
  752. -----
  753. **name** () : string
  754. Returns the name of the mouse.
  755. **connected** () : bool
  756. Returns whether the mouse is connected and functioning.
  757. **num_buttons** () : int
  758. Returns the number of buttons of the mouse.
  759. **num_axes** () : int
  760. Returns the number of axes of the mouse.
  761. **pressed** (id) : bool
  762. Returns whether the button *id* is pressed in the current frame.
  763. **released** (id) : bool
  764. Returns whether the button *id* is released in the current frame.
  765. **any_pressed** () : bool
  766. Returns whether any button is pressed in the current frame.
  767. **any_released** () : bool
  768. Returns whether any button is released in the current frame.
  769. **button** (id) : float
  770. Returns the value of the button *id* in the range [0..1].
  771. **axis** (id) : Vector3
  772. Returns the value of the axis *id*.
  773. **button_name** (id) : string
  774. Returns the name of the button *id*.
  775. **axis_name** (id) : string
  776. Returns the name of the axis *id*.
  777. **button_id** (name) : int
  778. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  779. **axis_id** (name) : int
  780. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  781. Mouse Button Names
  782. ~~~~~~~~~~~~~~~~~~
  783. ``left``, ``middle``, ``right``, ``extra_1``, ``extra_2``
  784. Mouse Axis Names
  785. ~~~~~~~~~~~~~~~~
  786. * ``cursor``: Returns the cursor position (x, y) in screen coordinates.
  787. * ``cursor_delta``: Returns the delta of the cursor position (x, y) since last frame.
  788. * ``wheel``: Returns the movement of the mouse wheel in the y axis. Positive values of y mean upward scrolling, negative values mean downward scrolling.
  789. Touch
  790. -----
  791. **name** () : string
  792. Returns the name of the touch.
  793. **connected** () : bool
  794. Returns whether the touch is connected and functioning.
  795. **num_buttons** () : int
  796. Returns the number of buttons of the touch.
  797. **num_axes** () : int
  798. Returns the number of axes of the touch.
  799. **pressed** (id) : bool
  800. Returns whether the button *id* is pressed in the current frame.
  801. **released** (id) : bool
  802. Returns whether the button *id* is released in the current frame.
  803. **any_pressed** () : bool
  804. Returns whether any button is pressed in the current frame.
  805. **any_released** () : bool
  806. Returns whether any button is released in the current frame.
  807. **button** (id) : float
  808. Returns the value of the button *id* in the range [0..1].
  809. **axis** (id) : Vector3
  810. Returns the value of the axis *id*.
  811. **button_name** (id) : string
  812. Returns the name of the button *id*.
  813. **axis_name** (id) : string
  814. Returns the name of the axis *id*.
  815. **button_id** (name) : int
  816. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  817. **axis_id** (name) : int
  818. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  819. Pad1, Pad2, Pad3, Pad4
  820. ----------------------
  821. **name** () : string
  822. Returns the name of the pad.
  823. **connected** () : bool
  824. Returns whether the pad is connected and functioning.
  825. **num_buttons** () : int
  826. Returns the number of buttons of the pad.
  827. **num_axes** () : int
  828. Returns the number of axes of the pad.
  829. **pressed** (id) : bool
  830. Returns whether the button *id* is pressed in the current frame.
  831. **released** (id) : bool
  832. Returns whether the button *id* is released in the current frame.
  833. **any_pressed** () : bool
  834. Returns whether any button is pressed in the current frame.
  835. **any_released** () : bool
  836. Returns whether any button is released in the current frame.
  837. **button** (id) : float
  838. Returns the value of the button *id* in the range [0..1].
  839. **axis** (id) : Vector3
  840. Returns the value of the axis *id*.
  841. **button_name** (id) : string
  842. Returns the name of the button *id*.
  843. **axis_name** (id) : string
  844. Returns the name of the axis *id*.
  845. **button_id** (name) : int
  846. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  847. **axis_id** (name) : int
  848. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  849. **deadzone** (id) : deadzone_mode, deadzone_size
  850. Returns the deadzone mode and size for the axis *id*.
  851. **set_deadzone** (id, deadzone_mode, deadzone_size)
  852. Sets the *deadzone_mode* and *deadzone_size* for the axis *id*.
  853. Pad Button Names
  854. ~~~~~~~~~~~~~~~~
  855. * ``up``, ``down``, ``left``, ``right``
  856. * ``start``, ``back``, ``guide``
  857. * ``thumb_left``, ``thumb_right``
  858. * ``shoulder_left``, ``shoulder_right``
  859. * ``a``, ``b``, ``x``, ``y``
  860. Pad Axis Names
  861. ~~~~~~~~~~~~~~
  862. * ``left``, ``right``: Returns the direction (x, y) of the left or right thumbstick [-1; +1].
  863. * ``trigger_left``, ``trigger_right``: The z element represents the left or right trigger [0; +1].
  864. Profiler
  865. ========
  866. **enter_scope** (name)
  867. Starts a new profile scope with the given *name*.
  868. **leave_scope** ()
  869. Ends the last profile scope.
  870. **record** (name, value)
  871. Records *value* with the given *name*. Value can be either number or Vector3.
  872. Display
  873. =======
  874. **modes** () : table
  875. Returns an array of `DisplayMode`_ tables.
  876. **set_mode** (id)
  877. Sets the display mode *id*.
  878. The initial display mode is automatically reset when the program terminates.
  879. DisplayMode
  880. -----------
  881. DisplayMode is a lua table with 3 fields:
  882. * ``id``: The id of the display mode.
  883. * ``width``: The width of the display mode.
  884. * ``height``: The height of the display mode.
  885. Window
  886. ======
  887. **show** ()
  888. Shows the window.
  889. **hide** ()
  890. Hides the window.
  891. **resize** (width, height)
  892. Resizes the window to *width* and *height*.
  893. **move** (x, y)
  894. Moves the window to *x* and *y*.
  895. **minimize** ()
  896. Minimizes the window.
  897. **restore** ()
  898. Restores the window.
  899. **title** () : string
  900. Returns the title of the window.
  901. **set_title** (title)
  902. Sets the title of the window.
  903. **show_cursor** (show)
  904. Sets whether to *show* the cursor.