lua_api.rst 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624
  1. =================
  2. Lua API reference
  3. =================
  4. AnimationStateMachine
  5. =====================
  6. **instance** (asm, unit) : Id
  7. Returns the ID of the state machine owned by the *unit*, or ``nil``.
  8. **variable_id** (asm, state_machine, name) : Id
  9. Returns the ID of the variable *name* in the *state_machine*.
  10. **variable** (asm, state_machine, variable_id) : number
  11. Returns the value of the *variable_id* in the *state_machine*.
  12. **set_variable** (asm, state_machine, variable_id, value)
  13. Sets the *value* of the *variable_id* in the *state_machine*.
  14. **trigger** (asm, state_machine, event)
  15. Triggers the *event* in the *state_machine*.
  16. DebugLine
  17. =========
  18. **add_line** (debug_line, start, end, color)
  19. Adds a line from *start* to *end* with the given *color*.
  20. **add_axes** (debug_line, tm, length)
  21. Adds lines for each axis with the given *length*.
  22. **add_arc** (debug_line, center, radius, plane_normal, midpoint_normal, color, [circle_segments = 36]);
  23. Adds an arc at *center* with the given *radius* and *plane_normal* and *midpoint_normal* vectors.
  24. **add_circle** (debug_line, center, radius, normal, color, [segments = 36])
  25. Adds a circle at *center* with the given *radius* and *normal* vector.
  26. **add_cone** (debug_line, from, to, radius, color, [segments = 36, rays = 36])
  27. Adds a cone with the base centered at *from* and the tip at *to*.
  28. **add_sphere** (debug_line, center, radius, color, [segments = 36])
  29. Adds a sphere at *center* with the given *radius*.
  30. **add_obb** (debug_line, tm, half_extents, color)
  31. Adds an orientd bounding box. *tm* describes the position and orientation of
  32. the box. *half_extents* describes the size of the box along the axis.
  33. **add_frustum** (debug_line, mvp, color)
  34. Adds a frustum defined by *mvp*.
  35. **reset** (debug_line)
  36. Resets all the lines.
  37. **submit** (debug_line)
  38. Submits the lines to renderer for drawing.
  39. Device
  40. ======
  41. **argv** () : table
  42. Returns a table containing the command line parameters the engine was started with.
  43. **platform** () : string
  44. Returns a string identifying what platform the engine is running on.
  45. It can be either ``android``, ``html5``, ``linux`` or ``windows``
  46. **architecture** () : string
  47. Returns a string identifying what architecture the engine is running on.
  48. It can be either ``32-bit`` or ``64-bit``.
  49. **version** () : string
  50. Returns a string identifying the engine version.
  51. The form is "major.minor.micro".
  52. **build** () : string
  53. Returns a string identifying the engine build.
  54. It can be either ``debug``, ``development`` or ``release``.
  55. **quit** ([exit_code])
  56. Quits the application. On platforms that support it, *exit_code* is
  57. returned to the system after the application exits.
  58. **resolution** () : float, float
  59. Returns the main window resolution (width, height).
  60. **create_world** () : World
  61. Creates a new world.
  62. **destroy_world** (world)
  63. Destroys the given *world*.
  64. **render** (world, camera)
  65. Renders *world* using *camera*.
  66. **create_resource_package** (name) : ResourcePackage
  67. Returns the resource package with the given *package_name* name.
  68. **destroy_resource_package** (package)
  69. Destroy a previously created resource *package*.
  70. .. note::
  71. To unload the resources loaded by the package, you have to call
  72. ResourcePackage.unload() first.
  73. **screenshot** (path)
  74. Captures a screenshot of the main window's backbuffer and saves it at *path* in PNG format.
  75. The global callback ``screenshot (path)`` will be called after the file is written to disk.
  76. .. note::
  77. Only available in debug and development builds.
  78. **console_send** (table)
  79. Sends the given lua *table* to clients connected to the engine.
  80. Values can be either ``nil``, bool, number, string, table, array, Vector2, Vector3, Quaternion, Matrix4x4 or Color4.
  81. **can_get** (type, name) : bool
  82. Returns whether the resource (type, name) is loaded.
  83. When resource autoload is enabled it always returns true.
  84. **enable_resource_autoload** (enable)
  85. Sets whether resources should be automatically loaded when accessed.
  86. **temp_count** () : int, int, int
  87. Returns the number of temporary objects used by Lua.
  88. **set_temp_count** (nv, nq, nm)
  89. Sets the number of temporary objects used by Lua.
  90. **guid** () : string
  91. Returns a new GUID.
  92. **set_timestep_policy** (policy)
  93. Sets the timestep policy:
  94. * ``variable``: the timestep is the time it took for the previous frame to simulate. This is the default;
  95. * ``smoothed``: the timestep is computed as an average of the previous delta times.
  96. **set_timestep_smoothing** (num_samples, num_outliers, average_cap)
  97. Sets the number of samples to be averaged, the outliers to be excluded and the maximum
  98. allowed deviation in percent from the previous average. Given a delta time series DTs, and
  99. a previous average AVGp:
  100. * DTs = [ .33; .30; .32; .33; .24; .33; .25; .35; .33; .42 ]
  101. * AVGp = 0.33
  102. A call to set_smoothing(10, 2, 0.1) would compute the new average like so:
  103. 1. Remove the 2 minimum and maximum values in DTs;
  104. 2. Compute the average for the remaining 6 values in DTs: AVG = 0.323.
  105. 3. Smooth the newly computed average: AVG = lerp(AVGp, AVG, 0.1) = 0.329.
  106. Display
  107. =======
  108. **modes** () : table
  109. Returns an array of `DisplayMode`_ tables.
  110. **set_mode** (id)
  111. Sets the display mode *id*.
  112. The initial display mode is automatically reset when the program terminates.
  113. DisplayMode
  114. -----------
  115. DisplayMode is a lua table with 3 fields:
  116. * ``id``: The id of the display mode.
  117. * ``width``: The width of the display mode.
  118. * ``height``: The height of the display mode.
  119. Gui
  120. ===
  121. **move** (gui, pos)
  122. Moves the Gui to *pos*.
  123. **triangle** (gui, a, b, c [, color, depth])
  124. Draws a triangle defined by vertices *a*, *b* and *c*.
  125. Objects with a lower depth are drawn in front. If depth is omitted its value
  126. is set to 0.
  127. **triangle_3d** (gui, local_pose, a, b, c [, color, depth])
  128. Draws a 3D triangle defined by vertices *a*, *b* and *c*.
  129. **rect** (gui, pos, size [, color])
  130. Draws a rectangle.
  131. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  132. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  133. to 0.
  134. **rect_3d** (gui, local_pose, pos, size [, color, depth])
  135. Draws a 3D rectangle.
  136. **image** (gui, pos, size, material_resource [, color])
  137. Draws an image.
  138. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  139. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  140. to 0.
  141. **image_3d** (gui, local_pose, pos, size, material_resource [, color, depth])
  142. Draws a 3D image.
  143. **image_uv** (gui, pos, size, uv0, uv1, material_resource [, color])
  144. Draws an image with explicit UV coordinates.
  145. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  146. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  147. to 0.
  148. **image_3d_uv** (gui, local_pose, pos, size, uv0, uv1, material_resource [, color, depth])
  149. Draws a 3D image with explicit UV coordinates.
  150. **text** (gui, pos, font_size, str, font_resource [, material_resource , color])
  151. Draws text.
  152. If pos is a Vector3, the z element specifies the drawing depth. Objects with
  153. a lower depth are drawn in front. If pos is a Vector2, the z elements is set
  154. to 0.
  155. **text_extents** (gui, font_size, str, font_resource) : Vector2
  156. Returns the extents of the text *str* if drawn using *font_resource* at size
  157. *font_size*.
  158. **text_3d** (gui, local_pose, pos, font_size, str, font_resource [, material_resource, color, depth])
  159. Draws 3D text.
  160. **material** (material_resource) : Material
  161. Returns the material *material_resource*.
  162. Input
  163. =====
  164. **events** () : table
  165. Returns an array of `InputEvent`_ tables.
  166. InputEvent
  167. ----------
  168. InputEvent is a lua table with 4 fields:
  169. * ``id``: The id of the button or axis as returned by ``Keyboard.button_id()`` for example.
  170. * ``type``: One of the values from `InputEventType`_.
  171. * ``value``: The value of the axis as a Vector3 or ``nil`` when ``type`` is not an axis event.
  172. * ``device``: The input device that generated the event. This is one of ``Keyboard``, ``Mouse``, ``Pad1`` etc.
  173. InputEventType
  174. --------------
  175. * ``BUTTON_PRESSED``: A button has been pressed.
  176. * ``BUTTON_RELEASED``: A button has been released.
  177. * ``AXIS_CHANGED``: An axis changed its value.
  178. Keyboard
  179. --------
  180. **name** () : string
  181. Returns the name of keyboard.
  182. **connected** () : bool
  183. Returns whether the keyboard is connected and functioning.
  184. **num_buttons** () : int
  185. Returns the number of buttons of the keyboard.
  186. **num_axes** () : int
  187. Returns the number of axes of the keyboard.
  188. **pressed** (id) : bool
  189. Returns whether the button *id* is pressed in the current frame.
  190. **released** (id) : bool
  191. Returns whether the button *id* is released in the current frame.
  192. **any_pressed** () : bool
  193. Returns the *id* of the first button that was pressed in the current frame
  194. or ``nil`` if no buttons were pressed at all.
  195. **any_released** () : bool
  196. Returns the *id* of the first button that was released in the current frame
  197. or ``nil`` if no buttons were released at all.
  198. **button** (id) : float
  199. Returns the value of the button *id* in the range [0..1].
  200. **button_name** (id) : string
  201. Returns the name of the button *id*.
  202. **button_id** (name) : int
  203. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  204. Keyboard Button Names
  205. ~~~~~~~~~~~~~~~~~~~~~
  206. * ``tab``, ``enter``, ``escape``, ``space``, ``backspace``
  207. * ``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``
  208. * ``f1``, ``f2``, ``f3``, ``f4``, ``f5``, ``f6``, ``f7``, ``f8``, ``f9``, ``f10``, ``f11``, ``f12``
  209. * ``home``, ``left``, ``up``, ``right``, ``down``, ``page_up``, ``page_down``, ``ins``, ``del``, ``end``
  210. * ``ctrl_left``, ``ctrl_right``, ``shift_left``, ``shift_right``, ``caps_lock``, ``alt_left``, ``alt_right``, ``super_left``, ``super_right``
  211. * ``0``, ``1``, ``2``, ``3``, ``4``, ``5``, ``6``, ``7``, ``8``, ``9``
  212. * ``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``
  213. Keyboard Axis Names
  214. ~~~~~~~~~~~~~~~~~~~
  215. None.
  216. Mouse
  217. -----
  218. **name** () : string
  219. Returns the name of the mouse.
  220. **connected** () : bool
  221. Returns whether the mouse is connected and functioning.
  222. **num_buttons** () : int
  223. Returns the number of buttons of the mouse.
  224. **num_axes** () : int
  225. Returns the number of axes of the mouse.
  226. **pressed** (id) : bool
  227. Returns whether the button *id* is pressed in the current frame.
  228. **released** (id) : bool
  229. Returns whether the button *id* is released in the current frame.
  230. **any_pressed** () : bool
  231. Returns the *id* of the first button that was pressed in the current frame
  232. or ``nil`` if no buttons were pressed at all.
  233. **any_released** () : bool
  234. Returns the *id* of the first button that was released in the current frame
  235. or ``nil`` if no buttons were released at all.
  236. **button** (id) : float
  237. Returns the value of the button *id* in the range [0..1].
  238. **axis** (id) : Vector3
  239. Returns the value of the axis *id*.
  240. **button_name** (id) : string
  241. Returns the name of the button *id*.
  242. **axis_name** (id) : string
  243. Returns the name of the axis *id*.
  244. **button_id** (name) : int
  245. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  246. **axis_id** (name) : int
  247. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  248. Mouse Button Names
  249. ~~~~~~~~~~~~~~~~~~
  250. ``left``, ``middle``, ``right``, ``extra_1``, ``extra_2``
  251. Mouse Axis Names
  252. ~~~~~~~~~~~~~~~~
  253. * ``cursor``: Returns the cursor position (x, y) in screen coordinates.
  254. * ``cursor_delta``: Returns the delta of the cursor position (x, y) since last frame.
  255. * ``wheel``: Returns the movement of the mouse wheel in the y axis. Positive values of y mean upward scrolling, negative values mean downward scrolling.
  256. Touch
  257. -----
  258. **name** () : string
  259. Returns the name of the touch.
  260. **connected** () : bool
  261. Returns whether the touch is connected and functioning.
  262. **num_buttons** () : int
  263. Returns the number of buttons of the touch.
  264. **num_axes** () : int
  265. Returns the number of axes of the touch.
  266. **pressed** (id) : bool
  267. Returns whether the button *id* is pressed in the current frame.
  268. **released** (id) : bool
  269. Returns whether the button *id* is released in the current frame.
  270. **any_pressed** () : bool
  271. Returns the *id* of the first button that was pressed in the current frame
  272. or ``nil`` if no buttons were pressed at all.
  273. **any_released** () : bool
  274. Returns the *id* of the first button that was released in the current frame
  275. or ``nil`` if no buttons were released at all.
  276. **button** (id) : float
  277. Returns the value of the button *id* in the range [0..1].
  278. **axis** (id) : Vector3
  279. Returns the value of the axis *id*.
  280. **button_name** (id) : string
  281. Returns the name of the button *id*.
  282. **axis_name** (id) : string
  283. Returns the name of the axis *id*.
  284. **button_id** (name) : int
  285. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  286. **axis_id** (name) : int
  287. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  288. Pad1, Pad2, Pad3, Pad4
  289. ----------------------
  290. **name** () : string
  291. Returns the name of the pad.
  292. **connected** () : bool
  293. Returns whether the pad is connected and functioning.
  294. **num_buttons** () : int
  295. Returns the number of buttons of the pad.
  296. **num_axes** () : int
  297. Returns the number of axes of the pad.
  298. **pressed** (id) : bool
  299. Returns whether the button *id* is pressed in the current frame.
  300. **released** (id) : bool
  301. Returns whether the button *id* is released in the current frame.
  302. **any_pressed** () : bool
  303. Returns the *id* of the first button that was pressed in the current frame
  304. or ``nil`` if no buttons were pressed at all.
  305. **any_released** () : bool
  306. Returns the *id* of the first button that was released in the current frame
  307. or ``nil`` if no buttons were released at all.
  308. **button** (id) : float
  309. Returns the value of the button *id* in the range [0..1].
  310. **axis** (id) : Vector3
  311. Returns the value of the axis *id*.
  312. **button_name** (id) : string
  313. Returns the name of the button *id*.
  314. **axis_name** (id) : string
  315. Returns the name of the axis *id*.
  316. **button_id** (name) : int
  317. Returns the *id* of the button *name* or ``nil`` if no matching button is found.
  318. **axis_id** (name) : int
  319. Returns the *id* of the axis *name* or ``nil`` if no matching axis is found.
  320. **deadzone** (id) : deadzone_mode, deadzone_size
  321. Returns the deadzone mode and size for the axis *id*.
  322. **set_deadzone** (id, deadzone_mode, deadzone_size)
  323. Sets the *deadzone_mode* and *deadzone_size* for the axis *id*.
  324. Pad Button Names
  325. ~~~~~~~~~~~~~~~~
  326. * ``up``, ``down``, ``left``, ``right``
  327. * ``start``, ``back``, ``guide``
  328. * ``thumb_left``, ``thumb_right``
  329. * ``shoulder_left``, ``shoulder_right``
  330. * ``a``, ``b``, ``x``, ``y``
  331. Pad Axis Names
  332. ~~~~~~~~~~~~~~
  333. * ``left``, ``right``: Returns the direction (x, y) of the left or right thumbstick [-1; +1].
  334. * ``trigger_left``, ``trigger_right``: The z element represents the left or right trigger [0; +1].
  335. Material
  336. ========
  337. **set_float** (material, name, value)
  338. Sets the *value* of the variable *name*.
  339. **set_vector2** (material, name, value)
  340. Sets the *value* of the variable *name*.
  341. **set_vector3** (material, name, value)
  342. Sets the *value* of the variable *name*.
  343. **set_vector4** (material, name, value)
  344. Sets the *value* of the variable *name*.
  345. **set_matrix4x4** (material, name, value)
  346. Sets the *value* of the variable *name*.
  347. **set_texture** (material, sampler_name, texture_name)
  348. Sets the *texture_resource* of the sampler *sampler_name*.
  349. Math
  350. ====
  351. Vector3
  352. -------
  353. Constructors
  354. ~~~~~~~~~~~~
  355. **Vector3** (x, y, z) : Vector3
  356. Returns a new vector from individual elements.
  357. Functions
  358. ~~~~~~~~~
  359. **x** (v) : float
  360. Returns the x value of the vector.
  361. **y** (v) : float
  362. Returns the y value of the vector.
  363. **z** (v) : float
  364. Returns the z value of the vector.
  365. **.x** : float
  366. Returns/assigns the x value of the vector.
  367. **.y** : float
  368. Returns/assigns the y value of the vector.
  369. **.z** : float
  370. Returns/assigns the z value of the vector.
  371. **set_x** (v, x)
  372. Sets the value of the x value of the vector.
  373. **set_y** (v, y)
  374. Sets the value of the y value of the vector.
  375. **set_z** (v, z)
  376. Sets the value of the z value of the vector.
  377. **elements** (v) : float, float, float
  378. Returns the x, y and z elements of the vector.
  379. **add** (a, b) : Vector3
  380. Adds the vector *a* to *b* and returns the result.
  381. **subtract** (a, b) : Vector3
  382. Subtracts the vector *b* from *a* and returns the result.
  383. **multiply** (a, k) : Vector3
  384. Multiplies the vector *a* by the scalar *k* and returns the result.
  385. **dot** (a, b) : float
  386. Returns the dot product between the vectors *a* and *b*.
  387. **cross** (a, b) : Vector3
  388. Returns the cross product between the vectors *a* and *b*.
  389. **equal** (a, b) : bool
  390. Returns true whether the vectors *a* and *b* are equal.
  391. **length** (a) : float
  392. Returns the length of *a*.
  393. **length_squared** (a) : float
  394. Returns the squared length of *a*.
  395. **set_length** (a, len)
  396. Sets the length of *a* to *len*.
  397. **normalize** (a) : Vector3
  398. Normalizes *a* and returns the result.
  399. **distance** (a, b) : float
  400. Returns the distance between the points *a* and *b*.
  401. **distance_squared** (a, b) : float
  402. Returns the squared distance between the points *a* and *b*.
  403. **angle** (a, b) : float
  404. Returns the angle between the vectors *a* and *b*.
  405. **max** (a, b) : Vector3
  406. Returns a vector that contains the largest value for each element from *a* and *b*.
  407. **min** (a, b) : Vector3
  408. Returns a vector that contains the smallest value for each element from *a* and *b*.
  409. **lerp** (a, b, t) : Vector3
  410. Returns the linearly interpolated vector between *a* and *b* at time *t* in [0, 1].
  411. | **forward** () : Vector3
  412. | **backward** () : Vector3
  413. | **left** () : Vector3
  414. | **right** () : Vector3
  415. | **up** () : Vector3
  416. | **down** () : Vector3
  417. | Returns the corresponding semantic axis.
  418. **zero** () : Vector3
  419. Returns a vector with all values set to zero.
  420. **to_string** (v) : string
  421. Returns a string representing the vector *v*.
  422. Vector3Box
  423. ----------
  424. Constructors
  425. ~~~~~~~~~~~~
  426. **Vector3Box** () : Vector3Box
  427. Returns a new Vector3Box initialized with the zero vector.
  428. **Vector3Box** (v) : Vector3Box
  429. Returns a new Vector3Box from the Vector3 *v*.
  430. **Vector3Box** (x, y, z) : Vector3Box
  431. Returns a new Vector3Box from individual elements.
  432. Functions
  433. ~~~~~~~~~
  434. **store** (v)
  435. Stores the Vector3 *v* in the box.
  436. **store** (x, y, z)
  437. Stores Vector3(x, y, z) in the box.
  438. **unbox** () : Vector3
  439. Returns the stored vector from the box.
  440. Quaternion
  441. ----------
  442. Constructors
  443. ~~~~~~~~~~~~
  444. **Quaternion** (axis, angle) : Quaternion
  445. Returns a new quaternion from *axis* and *angle*.
  446. **from_elements** (x, y, z, w) : Quaternion
  447. Returns a new quaternion from individual elements.
  448. **from_axis_angle** (axis, angle) : Quaternion
  449. Returns a new quaternion from *axis* and *angle*.
  450. Functions
  451. ~~~~~~~~~
  452. **negate** (q) : Quaternion
  453. Negates the quaternion *q* and returns the result.
  454. **identity** () : Quaternion
  455. Returns the identity quaternion.
  456. **multiply** (a, b) : Quaternion
  457. Multiplies the quaternions *a* and *b*. (i.e. rotates first by *a* then by *b*).
  458. **multiply_by_scalar** (a, k) : Quaternion
  459. Multiplies the quaternion *a* by the scalar *k*.
  460. **dot** (a, b) : float
  461. Returns the dot product between quaternions *a* and *b*.
  462. **length** (q) : float
  463. Returns the length of *q*.
  464. **normalize** (q) : Quaternion
  465. Normalizes the quaternion *q* and returns the result.
  466. **conjugate** (q) : Quaternion
  467. Returns the conjugate of quaternion *q*.
  468. **inverse** (q) : Quaternion
  469. Returns the inverse of quaternion *q*.
  470. **power** (q, exp) : Quaternion
  471. Returns the quaternion *q* raised to the power of *exp*.
  472. **elements** (q) : float, float, float, float
  473. Returns the x, y, z and w elements of the quaternion.
  474. **look** (dir, [up]) : Quaternion
  475. Returns the quaternion describing the rotation needed to face towards *dir*.
  476. If *up* is not specified, Vector3.up() is used.
  477. **right** (q) : Vector3
  478. Returns the right axis of the rotation described by *q*.
  479. **up** (q) : Vector3
  480. Returns the up axis of the rotation described by *q*.
  481. **forward** (q) : Vector3
  482. Returns the forward axis of the rotation described by *q*.
  483. **lerp** (a, b, t) : Quaternion
  484. Returns the linearly interpolated quaternion between *a* and *b* at time *t* in [0, 1].
  485. It uses NLerp.
  486. **to_string** (q) : string
  487. Returns a string representing the quaternion *q*.
  488. QuaternionBox
  489. -------------
  490. Constructors
  491. ~~~~~~~~~~~~
  492. **QuaternionBox** () : QuaternionBox
  493. Returns a new QuaternionBox initialized with the identity quaternion.
  494. **QuaternionBox** (q) : QuaternionBox
  495. Returns a new QuaternionBox from the Quaternion *q*.
  496. **QuaternionBox** (x, y, z, w) : QuaternionBox
  497. Returns a new QuaternionBox from individual elements.
  498. Functions
  499. ~~~~~~~~~
  500. **store** (q)
  501. Stores the Quaternion *q* in the box.
  502. **store** (x, y, z, w)
  503. Stores Quaternion(x, y, z, w) in the box.
  504. **unbox** () : Quaternion
  505. Returns the stored quaternion from the box.
  506. Matrix4x4
  507. ---------
  508. Constructors
  509. ~~~~~~~~~~~~
  510. **Matrix4x4** (xx, xy, xz, xw, yx, yy, yz, yw, zx, zy, zz, zw, tx, ty, tz, tw) : Matrix4x4
  511. Returns a new matrix from individual elements.
  512. **from_quaternion** (q) : Matrix4x4
  513. Returns a new matrix from *q*.
  514. **from_translation** (t) : Matrix4x4
  515. Returns a new matrix from *t*.
  516. **from_quaternion_translation** (q, t) : Matrix4x4
  517. Returns a new matrix from *q* and *t*.
  518. **from_axes** (x, y, z, t) : Matrix4x4
  519. Returns a new matrix from *x*, *y*, *z* and *t*.
  520. Functions
  521. ~~~~~~~~~
  522. **copy** (m) : Matrix4x4
  523. Returns a copy of the matrix *m*.
  524. **add** (a, b) : Matrix4x4
  525. Adds the matrix *a* to *b* and returns the result.
  526. **subtract** (a, b) : Matrix4x4
  527. Subtracts the matrix *b* from *a* and returns the result.
  528. **multiply** (a, b) : Matrix4x4
  529. Multiplies the matrix *a* by *b* and returns the result. (i.e. transforms first by *a* then by *b*)
  530. **equal** (a, b) : bool
  531. Returns true whether the matrices *a* and *b* are equal.
  532. **transpose** (m) : Matrix4x4
  533. Transposes the matrix *m* and returns the result.
  534. **invert** (m) : Matrix4x4
  535. Inverts the matrix *m* and returns the result.
  536. **x** (m) : Vector3
  537. Returns the x axis of the matrix *m*.
  538. **y** (m) : Vector3
  539. Returns the y axis of the matrix *m*.
  540. **z** (m) : Vector3
  541. Returns the z axis of the matrix *m*.
  542. **set_x** (m, x)
  543. Sets the x axis of the matrix *m*.
  544. **set_y** (m, y)
  545. Sets the y axis of the matrix *m*.
  546. **set_z** (m, z)
  547. Sets the z axis of the matrix *m*.
  548. **translation** (m) : Vector3
  549. Returns the translation portion of the matrix *m*.
  550. **set_translation** (m, t)
  551. Sets the translation portion of the matrix *m*.
  552. **rotation** (m) : Quaternion
  553. Returns the rotation portion of the matrix *m*.
  554. **set_rotation** (m, r)
  555. Sets the rotation portion of the matrix *m*.
  556. **scale** (m) : Vector3
  557. Returns the scale of the matrix *m*.
  558. **set_scale** (m, r)
  559. Sets the scale of the matrix *m*.
  560. **identity** ()
  561. Returns the identity matrix.
  562. **transform** (m, v) : Vector3
  563. Transforms the vector *v* by the matrix *m* and returns the result.
  564. **to_string** (m) : string
  565. Returns a string representing the matrix *m*.
  566. Matrix4x4Box
  567. ------------
  568. Constructors
  569. ~~~~~~~~~~~~
  570. **Matrix4x4Box** () : Matrix4x4Box
  571. Returns a new Matrix4x4Box initialized with the identity matrix.
  572. **Matrix4x4Box** (m) : Matrix4x4Box
  573. Returns a new Matrix4x4Box from the Matrix4x4 *m*.
  574. Functions
  575. ~~~~~~~~~
  576. **store** (m)
  577. Stores the Matrix4x4 *m* in the box.
  578. **unbox** () : Matrix4x4
  579. Returns the stored matrix from the box.
  580. Color4
  581. ------
  582. Constructors
  583. ~~~~~~~~~~~~
  584. **Color4** (r, g, b, a) : Color4
  585. Returns a new Color4 from individual elements.
  586. Functions
  587. ~~~~~~~~~
  588. **lerp** (a, b, t) : Color4
  589. Returns the linearly interpolated color between *a* and *b* at time *t* in [0, 1].
  590. | **black** () : Color4
  591. | **white** () : Color4
  592. | **red** () : Color4
  593. | **green** () : Color4
  594. | **blue** () : Color4
  595. | **yellow** () : Color4
  596. | **orange** () : Color4
  597. | Returns the corresponding mnemonic color.
  598. **to_string** (c) : string
  599. Returns a string representing the color *c*.
  600. Math
  601. ----
  602. **ray_plane_intersection** (from, dir, point, normal) : float
  603. Returns the distance along ray (from, dir) to intersection point with plane defined by
  604. *point* and *normal* or -1.0 if no intersection.
  605. **ray_disc_intersection** (from, dir, center, radius, normal) : float
  606. Returns the distance along ray (from, dir) to intersection point with disc defined by
  607. *center*, *radius* and *normal* or -1.0 if no intersection.
  608. **ray_sphere_intersection** (from, dir, center, radius) : float
  609. Returns the distance along ray (from, dir) to intersection point with sphere defined by
  610. *center* and *radius* or -1.0 if no intersection.
  611. **ray_obb_intersection** (from, dir, tm, half_extents) : float
  612. Returns the distance along ray (from, dir) to intersection point with the oriented
  613. bounding box (tm, half_extents) or -1.0 if no intersection.
  614. **ray_triangle_intersection** (from, dir, v0, v1, v2) : float
  615. Returns the distance along ray (from, dir) to intersection point with the triangle
  616. (v0, v1, v2) or -1.0 if no intersection.
  617. **obb_intersects_frustum** (obb_tm, obb_half_extents, n0, d0, n1, d1, n2, d2, n3, d3, n4, d4, n4, d5) : bool
  618. Returns whether the oriented bounding box (obb_tm, obb_half_extents) intersects
  619. the frustum defined by the planes ((n0, d0), (n1, d1), ..., (n5, d5)). The
  620. planes be given in BRTLNF order, where B = bottom plane, R = right plane etc.
  621. **obb_vertices** (obb_tm, obb_half_extents) : v0, v1, v2, v3, v4, v5, v6, v7
  622. Returns the vertices of the oriented bounding box (obb_tm, obb_half_extents).
  623. **obb_merge** (a_tm, a_half_extents, b_tm, b_half_extents, ...) : Matrix4x4, Vector3
  624. Returns a new box which encloses both the box A (a_tm, a_half_extents) and B
  625. (b_tm, b_half_extents) and any number of boxes after B.
  626. Note that the returned OBB will have the same orientation as A and won't
  627. necessarily be the smallest enclosing box.
  628. PhysicsWorld
  629. =============
  630. **gravity** (pw) : Vector3
  631. Returns the gravity.
  632. **set_gravity** (pw, gravity)
  633. Sets the gravity.
  634. **cast_ray** (pw, from, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  635. Casts a ray into the physics world and returns the closest actor it intersects with.
  636. If *hit* is true the following return values contain the *collision_pos* in
  637. world space, the *normal* of the surface that was hit, the time of impact
  638. in [0..1] and the *unit* and the *actor* that was hit.
  639. **cast_ray_all** (pw, from, dir, length) : table
  640. Casts a ray into the physics world and returns all the
  641. actors it intersects with as an array of `RaycastHit`_ tables.
  642. **cast_sphere** (pw, from, radius, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  643. Casts a sphere into the physics world and returns the closest actor it intersects with.
  644. If *hit* is true the following return values contain the *collision_pos* in
  645. world space, the *normal* of the surface that was hit, the time of impact
  646. in [0..1] and the *unit* and the *actor* that was hit.
  647. **cast_box** (pw, from, half_extents, dir, length) : hit, collision_pos, normal, time, UnitId, Actor
  648. Casts a box into the physics world and returns the closest actor it intersects with.
  649. If *hit* is true the following return values contain the *collision_pos* in
  650. world space, the *normal* of the surface that was hit, the time of impact
  651. in [0..1] and the *unit* and the *actor* that was hit.
  652. **enable_debug_drawing** (pw, enable)
  653. Sets whether to *enable* debug drawing.
  654. RaycastHit
  655. ----------
  656. RaycastHit is a lua table with 5 fields:
  657. * ``[1]``: The collision position in world space.
  658. * ``[2]``: The normal of the surface that was hit.
  659. * ``[3]``: The time of impact in [0..1].
  660. * ``[4]``: The unit that was hit.
  661. * ``[5]``: The actor that was hit.
  662. Actor
  663. -----
  664. **actor_destroy** (pw, actor)
  665. Destroys the *actor* instance.
  666. **actor_instance** (pw, unit) : Id
  667. Returns the ID of the actor owned by the *unit*, or ``nil``.
  668. **actor_world_position** (pw, actor) : Vector3
  669. Returns the world position of the *actor*.
  670. **actor_world_rotation** (pw, actor) : Quaternion
  671. Returns the world rotation of the *actor*.
  672. **actor_world_pose** (pw, actor) : Matrix4x4
  673. Returns the world pose of the *actor*.
  674. **actor_teleport_world_position** (pw, actor, position)
  675. Teleports the *actor* to the given world *position*.
  676. **actor_teleport_world_rotation** (pw, actor, rotation)
  677. Teleports the *actor* to the given world *rotation*.
  678. **actor_teleport_world_pose** (pw, actor, pose)
  679. Teleports the *actor* to the given world *pose*.
  680. **actor_center_of_mass** (pw, actor) : Vector3
  681. Returns the center of mass of the *actor*.
  682. **actor_enable_gravity** (pw, actor)
  683. Enables gravity for the *actor*.
  684. **actor_disable_gravity** (pw, actor)
  685. Disables gravity for the *actor*.
  686. **actor_enable_collision** (pw, actor)
  687. Enables collision detection for the *actor*.
  688. **actor_disable_collision** (pw, actor)
  689. Disables collision detection for the *actor*.
  690. **actor_set_collision_filter** (pw, actor, name)
  691. Sets the collision filter of the *actor*.
  692. **actor_set_kinematic** (pw, actor, kinematic)
  693. Sets whether the *actor* is *kinematic* or not.
  694. .. note::
  695. This call has no effect on static actors.
  696. **actor_is_static** (pw, actor) : bool
  697. Returns whether the *actor* is static.
  698. **actor_is_dynamic** (pw, actor) bool
  699. Returns whether the *actor* is dynamic.
  700. **actor_is_kinematic** (pw, actor) : bool
  701. Returns whether the *actor* is kinematic (keyframed).
  702. **actor_is_nonkinematic** (pw, actor) : bool
  703. Returns whether the *actor* is nonkinematic (i.e. dynamic and not kinematic).
  704. **actor_linear_damping** (pw, actor) : float
  705. Returns the linear damping of the *actor*.
  706. **actor_set_linear_damping** (pw, actor, damping)
  707. Sets the linear *damping* of the *actor*.
  708. **actor_angular_damping** (pw, actor) : float
  709. Returns the angular damping rate of the *actor*.
  710. **actor_set_angular_damping** (pw, actor, rate)
  711. Sets the angular damping *rate* of the *actor*.
  712. **actor_linear_velocity** (pw, actor) : Vector3
  713. Returns the linear velocity of the *actor*.
  714. **actor_set_linear_velocity** (pw, actor, velocity)
  715. Sets the linear *velocity* of the *actor*.
  716. .. note::
  717. This call only affects nonkinematic actors.
  718. **actor_angular_velocity** (pw, actor) : Vector3
  719. Returns the angular velocity of the *actor*.
  720. **actor_set_angular_velocity** (pw, actor, velocity)
  721. Sets the angular *velocity* of the *actor*.
  722. .. note::
  723. This call only affects nonkinematic actors.
  724. **actor_add_impulse** (pw, actor, impulse)
  725. Adds a linear *impulse* (acting along the center of mass) to the *actor*.
  726. .. note::
  727. This call only affects nonkinematic actors.
  728. **actor_add_impulse_at** (pw, actor, impulse, position)
  729. Adds a linear *impulse* (acting along the world position *pos*) to the *actor*.
  730. .. note::
  731. This call only affects nonkinematic actors.
  732. **actor_add_torque_impulse** (pw, actor, impulse)
  733. Adds a torque *impulse* to the *actor*.
  734. **actor_push** (pw, actor, velocity, mass)
  735. Pushes the *actor* as if it was hit by a point object with the given *mass*
  736. travelling at the given *velocity*.
  737. .. note::
  738. This call only affects nonkinematic actors.
  739. **actor_push_at** (pw, actor, velocity, mass, position)
  740. Like push() but applies the force at the world *position*.
  741. .. note::
  742. This call only affects nonkinematic actors.
  743. **actor_is_sleeping** (pw, actor) : bool
  744. Returns whether the *actor* is sleeping.
  745. **actor_wake_up** (pw, actor)
  746. Wakes the *actor* up.
  747. **actor_debug_draw** (pw, actor, debug_line [, color])
  748. Adds the *actor*'s debug geometry to *lines*.
  749. Mover
  750. -----
  751. **mover_create** (pw, unit, height, radius, max_slope_angle, collision_filter) : Id
  752. Creates a new mover instance for the *unit*.
  753. **mover_destroy** (pw, mover)
  754. Destroys the *mover*.
  755. **mover** (pw, unit) : Id
  756. Returns the ID of the mover owned by the *unit*.
  757. **mover_radius** (pw, mover) : number
  758. Returns the radius of the *mover* capsule.
  759. **mover_max_slope_angle** (pw, mover) : number
  760. Returns the max slope angle of the *mover*.
  761. **mover_set_max_slope_angle** (pw, mover, angle)
  762. Sets the max slope *angle* of the *mover*.
  763. **mover_set_collision_filter** (pw, mover, filter)
  764. Sets the collision *filter* of the *mover*.
  765. **mover_position** (pw, mover) : Vector3
  766. Returns the position of the *mover*.
  767. **mover_set_position** (pw, mover, position)
  768. Teleports the *mover* to the specified *position*.
  769. **mover_move** (pw, mover, delta)
  770. Attempts to move the *mover* by the specified *delta* vector.
  771. The *mover* will slide against physical actors.
  772. **mover_collides_sides** (pw, mover) : bool
  773. Returns whether the *mover* collides sideways.
  774. **mover_collides_up** (pw, mover) : bool
  775. Returns whether the *mover* collides upwards.
  776. **mover_collides_down** (pw, mover) : bool
  777. Returns whether the *mover* collides downwards.
  778. **mover_debug_draw** (pw, mover, debug_line [, color])
  779. Adds the *mover*'s debug geometry to *lines*.
  780. Profiler
  781. ========
  782. **enter_scope** (name)
  783. Starts a new profile scope with the given *name*.
  784. **leave_scope** ()
  785. Ends the last profile scope.
  786. **record** (name, value)
  787. Records *value* with the given *name*. Value can be either number or Vector3.
  788. RenderWorld
  789. ===========
  790. **enable_debug_drawing** (rw, enable)
  791. Sets whether to *enable* debug drawing.
  792. Mesh
  793. ----
  794. **mesh_create** (rw, unit, mesh_resource, geometry_name, material_resource, visible) : Id
  795. Creates a new mesh instance for *unit* and returns its id.
  796. **mesh_destroy** (rw, mesh)
  797. Destroys the *mesh* instance.
  798. **mesh_instance** (rw, unit) : Id
  799. Returns the ID of the mesh owned by the *unit*, or ``nil``.
  800. **mesh_material** (rw, mesh) : Material
  801. Returns the material of the *mesh*.
  802. **mesh_set_material** (rw, mesh, material)
  803. Sets the *material* of the *mesh*.
  804. **mesh_set_visible** (rw, mesh, visible)
  805. Sets whether the *mesh* is *visible*.
  806. **mesh_set_cast_shadows** (rw, mesh, cast_shadows)
  807. Sets whether the *mesh* cast shadows.
  808. **mesh_obb** (rw, mesh) : Matrix4x4, Vector3
  809. Returns the Oriented-Bounding-Box of the *mesh* as (pose, half_extents).
  810. **mesh_cast_ray** (rw, mesh, from, dir) : float
  811. Returns the distance along ray (from, dir) to intersection point with the *mesh* or -1.0 if no intersection.
  812. Sprite
  813. ------
  814. **sprite_create** (rw, unit, sprite_resource, material_resource, visible) : Id
  815. Creates a new sprite instance for the *unit* and returns its id.
  816. **sprite_destroy** (rw, sprite)
  817. Destroys the *sprite* instance.
  818. **sprite_instance** (rw, unit) : Id
  819. Returns the ID of the sprite owned by the *unit*, or ``nil``.
  820. **sprite_material** (rw, sprite) : Material
  821. Returns the material of the *sprite*.
  822. **sprite_set_material** (rw, sprite, material)
  823. Sets the *material* of the *sprite*.
  824. **sprite_set_frame** (rw, sprite, index)
  825. Sets the frame *index* of the *sprite*.
  826. The *index* automatically wraps if it greater than the total number of
  827. frames in the sprite.
  828. **sprite_set_visible** (rw, sprite, visible)
  829. Sets whether the *sprite* is *visible*.
  830. **sprite_flip_x** (rw, sprite, flip)
  831. Sets whether to flip the *sprite* on the x-axis.
  832. **sprite_flip_y** (rw, sprite, flip)
  833. Sets whether to flip the *sprite* on the y-axis.
  834. **sprite_set_layer** (rw, sprite, layer)
  835. Sets the rendering *layer* of the *sprite*.
  836. **sprite_set_depth** (rw, sprite, depth)
  837. Sets the rendering *depth* of the *sprite*.
  838. **sprite_obb** (rw, sprite) : Matrix4x4, Vector3
  839. Returns the Oriented-Bounding-Box of the *sprite* as (pose, half_extents).
  840. **sprite_cast_ray** (rw, sprite, from, dir) : float, int, int
  841. Returns (t, layer, depth), where *t* is the distance along ray (from, dir) to
  842. intersection point with the *sprite* or -1.0 if no intersection.
  843. Light
  844. -----
  845. **light_create** (rw, unit, type, range, intensity, spot_angle, color) : Id
  846. Creates a new light for the *unit* and returns its id.
  847. Type can be either ``directional``, ``omni`` or ``spot``.
  848. **light_destroy** (rw, light)
  849. Destroys the *light* instance.
  850. **light_instance** (rw, unit) : Id
  851. Returns the ID of the light owned by the *unit*, or ``nil``.
  852. **light_type** (rw, light) : string
  853. Returns the type of the *light*.
  854. It can be either ``directional``, ``omni`` or ``spot``.
  855. **light_color** (rw, light) : Color4
  856. Returns the color of the *light*.
  857. **light_range** (rw, light) : float
  858. Returns the range of the *light*.
  859. **light_intensity** (rw, light) : float
  860. Returns the intensity of the *light*.
  861. **light_spot_angle** (rw, light) : float
  862. Returns the spot angle of the *light*.
  863. **light_shadow_bias** (rw, light) : float
  864. Returns the shadow bias of the *light*.
  865. **light_set_type** (rw, light, type)
  866. Sets the *type* of the *light*.
  867. **light_set_color** (rw, light, color)
  868. Sets the *color* of the *light*.
  869. **light_set_range** (rw, light, range)
  870. Sets the *range* of the *light*.
  871. **light_set_intensity** (rw, light, intensity)
  872. Sets the *intensity* of the *light*.
  873. **light_set_spot_angle** (rw, light, angle)
  874. Sets the spot *angle* of the *light*.
  875. **light_set_shadow_bias** (rw, light, bias)
  876. Sets the shadow *bias* of the *light*.
  877. **light_set_cast_shadows** (rw, light, cast_shadows)
  878. Sets whether the *light* casts shadows.
  879. **light_debug_draw** (rw, light, debug_line)
  880. Fills *debug_line* with debug lines from the *light*.
  881. Fog
  882. ---
  883. **fog_create** (rw, unit) : Id
  884. Creates a new fog instance for the *unit* and returns its id.
  885. Note that the fog component is limited to one instance per World. Every call
  886. to this function will overwrite any previously created fog instance.
  887. **fog_destroy** (rw, fog)
  888. Destroys the *fog* instance.
  889. **fog_instance** (rw, unit) : Id
  890. Returns the ID of the fog owned by the *unit*, or ``nil``.
  891. **fog_set_color** (rw, fog, color)
  892. Sets the *color* of the *fog*.
  893. **fog_set_density** (rw, fog, density)
  894. Sets the *density* of the *fog*.
  895. **fog_set_range_min** (rw, fog, range)
  896. Sets the minimum *range* of the *fog*.
  897. **fog_set_range_max** (rw, fog, range)
  898. Sets the maximum *range* of the *fog*.
  899. **fog_set_sun_blend** (rw, fog, sun_blend)
  900. Sets the sun *blend* of the *fog*.
  901. **fog_set_enabled** (rw, fog, enable)
  902. Sets whether the *fog* is *enabled*.
  903. ResourcePackage
  904. ===============
  905. **load** (package)
  906. Loads all the resources in the *package*.
  907. .. note::
  908. The resources are not immediately available after the call is made,
  909. instead, you have to poll for completion with has_loaded().
  910. **unload** (package)
  911. Unloads all the resources in the *package*.
  912. **flush** (package)
  913. Waits until the *package* has been loaded.
  914. **has_loaded** (package) : bool
  915. Returns whether the *package* has been loaded.
  916. SceneGraph
  917. ==========
  918. **create** (sg, unit, position, rotation, scale) : Id
  919. Creates the transform for the *unit* and returns its ID.
  920. **destroy** (sg, transform)
  921. Destroys the *transform* instance.
  922. **instance** (sg, unit) : Id
  923. Returns the ID of the transform owned by the *unit*, or ``nil``.
  924. **owner** (sg, transform) : UnitId
  925. Returns the unit that owns *transform*.
  926. **local_position** (sg, transform) : Vector3
  927. Returns the local position of the *transform*.
  928. **local_rotation** (sg, transform) : Quaternion
  929. Returns the local rotation of the *transform*.
  930. **local_scale** (sg, transform) : Vector3
  931. Returns the local scale of the *transform*.
  932. **local_pose** (sg, transform) : Matrix4x4
  933. Returns the local pose of the *transform*.
  934. **world_position** (sg, transform) : Vector3
  935. Returns the world position of the *transform*.
  936. **world_rotation** (sg, transform) : Quaternion
  937. Returns the world rotation of the *transform*.
  938. **world_pose** (sg, transform) : Matrix4x4
  939. Returns the world pose of the *transform*.
  940. **set_local_position** (sg, transform, position)
  941. Sets the local *position* of the *transform*.
  942. **set_local_rotation** (sg, transform, rotation)
  943. Sets the local *rotation* of the *transform*.
  944. **set_local_scale** (sg, transform, scale)
  945. Sets the local *scale* of the *transform*.
  946. **set_local_pose** (sg, transform, pose)
  947. Sets the local *pose* of the *transform*.
  948. **link** (sg, parent, child, child_local_position, child_local_rotation, child_local_scale)
  949. Links *child* to *parent*. After linking the child will follow its
  950. parent. Set child_local_* to modify the child position after it has been
  951. linked to the parent, otherwise che child will be positioned at the
  952. location of its parent.
  953. **unlink** (sg, child)
  954. Unlinks *child* from its parent if it has any. After unlinking, the local
  955. pose of the *child* is set to its previous world pose.
  956. **parent** (sg, child) : Id
  957. Returns the parent of the instance *child* or ``nil``
  958. if *child* has no parent.
  959. **first_child** (sg, parent) : Id
  960. Returns the first child of the instance *parent* or ``nil``
  961. if *parent* has no children.
  962. **next_sibling** (sg, child) : Id
  963. Returns the next sibling of the instance *child* or ``nil``
  964. if *child* has no sibling.
  965. SoundWorld
  966. ===========
  967. **stop_all** (sound_world)
  968. Stops all the sounds in the world.
  969. **pause_all** (sound_world)
  970. Pauses all the sounds in the world
  971. **resume_all** (sound_world)
  972. Resumes all previously paused sounds in the world.
  973. **is_playing** (sound_world, id) : bool
  974. Returns whether the sound *id* is playing.
  975. **set_group_volume** (sound_world, group, volume)
  976. Sets the *volume* of the sound *group*. The volume of the sounds within
  977. *group* is multiplied by the group's volume.
  978. UnitManager
  979. ===========
  980. **create** ([world]) : UnitId
  981. Creates a new empty unit. If *world* is specified, the unit will be owned by
  982. that world.
  983. **destroy** (unit)
  984. Destroys the given *unit*.
  985. **alive** (unit) : bool
  986. Returns whether the unit is alive.
  987. Window
  988. ======
  989. **show** ()
  990. Shows the window.
  991. **hide** ()
  992. Hides the window.
  993. **resize** (width, height)
  994. Resizes the window to *width* and *height*.
  995. **move** (x, y)
  996. Moves the window to *x* and *y*.
  997. **minimize** ()
  998. Minimizes the window.
  999. **maximize** ()
  1000. Maximizes the window.
  1001. **restore** ()
  1002. Restores the window.
  1003. **title** () : string
  1004. Returns the title of the window.
  1005. **set_title** (title)
  1006. Sets the title of the window.
  1007. **show_cursor** (show)
  1008. Sets whether to *show* the cursor.
  1009. **set_fullscreen** (fullscreen)
  1010. Sets whether the window is *fullscreen*.
  1011. **set_cursor** (cursor)
  1012. Sets the mouse *cursor* on this window. Cursor can be any of ``arrow``,
  1013. ``hand``, ``text_input``, ``corner_top_left``, ``corner_top_right``,
  1014. ``corner_bottom_left``, ``corner_bottom_right``, ``size_horizontal``,
  1015. ``size_vertical`` or ``wait``.
  1016. **set_cursor_mode** (cursor, mode)
  1017. Sets the mouse cursor *mode* on this window. Mode can be either ``normal``
  1018. or ``disabled``. Setting the mode to ``disabled`` hides the cursor and
  1019. automatically re-centers it every time it is moved.
  1020. World
  1021. =====
  1022. **spawn_unit** (world, name, [position, rotation, scale]) : UnitId
  1023. Spawns a new instance of the unit *name* at the given *position*, *rotation* and *scale*.
  1024. **spawn_empty_unit** (world) : UnitId
  1025. Spawns a new empty unit and returns its id.
  1026. **destroy_unit** (world, unit)
  1027. Destroys the given *unit*.
  1028. **num_units** (world) : int
  1029. Returns the number of units in the *world*.
  1030. **units** (world) : table
  1031. Returns all the the units in the world in a table.
  1032. **unit_by_name** (world, name) : UnitId
  1033. Returns the unit with the given Level Editor *name* or ``nil`` if no such unit is found.
  1034. If there are multiple units with the same name, a random one will be returned.
  1035. **update_animations** (world, dt)
  1036. Update all animations with *dt*.
  1037. **update_scene** (world, dt)
  1038. Updates the scene with *dt*.
  1039. **update** (world, dt)
  1040. Updates the world with *dt*.
  1041. **create_debug_line** (world, depth_test) : DebugLine
  1042. Creates a new DebugLine. *depth_test* controls whether to
  1043. enable depth test when rendering the lines.
  1044. **destroy_debug_line** (world, line)
  1045. Destroys the debug *line*.
  1046. **create_screen_gui** (world) : Gui
  1047. Creates a new Gui for 2D drawing.
  1048. **create_world_gui** (world) : Gui
  1049. Creates a new Gui for 3D drawing.
  1050. **destroy_gui** (world, gui)
  1051. Destroys the *gui*.
  1052. **scene_graph** (world) : SceneGraph
  1053. Returns the scene graph.
  1054. **render_world** (world) : RenderWorld
  1055. Returns the render sub-world.
  1056. **physics_world** (world) : PhysicsWorld
  1057. Returns the physics sub-world.
  1058. **sound_world** (world) : SoundWorld
  1059. Returns the sound sub-world.
  1060. **animation_state_machine** (world) : AnimationStateMachine
  1061. Returns the animation state machine.
  1062. Camera
  1063. ------
  1064. **camera_create** (world, unit, projection, fov, far_range, near_range) : Id
  1065. Creates a new camera for *unit* and returns its id.
  1066. Projection can be either ``orthographic`` or ``perspective``.
  1067. **camera_destroy** (world, camera)
  1068. Destroys the *camera* instance.
  1069. **camera_instance** (world, unit) : Id
  1070. Returns the ID of the camera owned by the *unit*, or ``nil``.
  1071. **camera_set_projection_type** (world, camera, projection)
  1072. Sets the projection type of the *camera*.
  1073. Projection can be either ``orthographic`` or ``perspective``.
  1074. **camera_projection_type** (world, camera) : string
  1075. Returns the projection type of the *camera*.
  1076. It can be either ``orthographic`` or ``perspective``.
  1077. **camera_fov** (world, camera) : float
  1078. Returns the field-of-view of the *camera* in degrees.
  1079. **camera_set_fov** (world, camera, fov)
  1080. Sets the field-of-view of the *camera* in degrees.
  1081. **camera_near_clip_distance** (world, camera) : float
  1082. Returns the near clip distance of the *camera*.
  1083. **camera_set_near_clip_distance** (world, camera, near)
  1084. Sets the near clip distance of the *camera*.
  1085. **camera_far_clip_distance** (world, camera) : float
  1086. Returns the far clip distance of the *camera*.
  1087. **camera_set_far_clip_distance** (world, camera, far)
  1088. Sets the far clip distance of the *camera*.
  1089. **camera_set_orthographic_size** (world, camera, half_size)
  1090. Sets the vertical *half_size* of the orthographic view volume.
  1091. The horizontal size is proportional to the viewport's aspect ratio.
  1092. **camera_screen_to_world** (world, camera, pos) : Vector3
  1093. Returns *pos* from screen-space to world-space coordinates.
  1094. **camera_world_to_screen** (world, camera, pos) : Vector3
  1095. Returns *pos* from world-space to screen-space coordinates.
  1096. Sound
  1097. -----
  1098. **play_sound** (world, name, [loop = false, volume = 1.0, range = 70.0, position = nil, group = nil]) : SoundInstanceId
  1099. Plays the sound with the given *name*. If the listener is further away than
  1100. *range* the sound will not be heard. If *position* is not specified the
  1101. sound will be played as a 2d-sound (i.e. no attenuation nor spatialization).
  1102. *group* is a string that identifies the sound's group, see ``SoundWorld.set_group_volume()``.
  1103. **stop_sound** (world, id)
  1104. Stops the sound with the given *id*.
  1105. **link_sound** (world, id, unit, node)
  1106. Links the sound *id* to the *node* of the given *unit*.
  1107. After this call, the sound *id* will follow the unit *unit*.
  1108. **set_listener_pose** (world, pose)
  1109. Sets the *pose* of the listener.
  1110. **set_sound_position** (world, id, position)
  1111. Sets the *position* of the sound *id*.
  1112. **set_sound_range** (world, id, range)
  1113. Sets the *range* of the sound *id*.
  1114. **set_sound_volume** (world, id, volume)
  1115. Sets the *volume* of the sound *id*.
  1116. Level
  1117. -----
  1118. **load_level** (world, name, [pos, rot]) : Level
  1119. Loads the level *name* into the world at the given *position* and *rotation*.
  1120. **destroy_level** (world, level)
  1121. Destroys a level previously loaded by load_level(). Only units directly
  1122. spawned by the level are unspawned.