lua_api.rst 47 KB

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