mesh.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. return {
  2. tag = 'drawing',
  3. summary = 'Draw a mesh.',
  4. description = 'Draws a mesh.',
  5. arguments = {
  6. vertices = {
  7. type = 'Buffer',
  8. default = 'nil',
  9. description = 'The buffer containing the vertices to draw.'
  10. },
  11. indices = {
  12. type = 'Buffer',
  13. description = 'The buffer containing the vertex indices to draw.'
  14. },
  15. draws = {
  16. type = 'Buffer',
  17. description = 'The buffer containing indirect draw commands.'
  18. },
  19. drawcount = {
  20. type = 'number',
  21. description = 'The number of indirect draws to draw.'
  22. },
  23. offset = {
  24. type = 'number',
  25. description = 'A byte offset into the draw buffer.'
  26. },
  27. stride = {
  28. type = 'number',
  29. description = 'The number of bytes between consecutive elements in the draw buffer.'
  30. },
  31. x = {
  32. type = 'number',
  33. default = '0',
  34. description = 'The x coordinate of the position to draw the mesh at.'
  35. },
  36. y = {
  37. type = 'number',
  38. default = '0',
  39. description = 'The y coordinate of the position to draw the mesh at.'
  40. },
  41. z = {
  42. type = 'number',
  43. default = '0',
  44. description = 'The z coordinate of the position to draw the mesh at.'
  45. },
  46. scale = {
  47. type = 'number',
  48. default = '1',
  49. description = 'The scale of the mesh.'
  50. },
  51. angle = {
  52. type = 'number',
  53. default = '0',
  54. description = 'The number of radians the mesh is rotated around its rotational axis.'
  55. },
  56. ax = {
  57. type = 'number',
  58. default = '0',
  59. description = 'The x component of the axis of rotation.'
  60. },
  61. ay = {
  62. type = 'number',
  63. default = '1',
  64. description = 'The y component of the axis of rotation.'
  65. },
  66. az = {
  67. type = 'number',
  68. default = '0',
  69. description = 'The z component of the axis of rotation.'
  70. },
  71. position = {
  72. type = 'Vec3',
  73. description = 'The position to draw the mesh at.'
  74. },
  75. scales = {
  76. type = 'Vec3',
  77. description = 'The scale of the mesh.'
  78. },
  79. orientation = {
  80. type = 'Quat',
  81. description = 'The orientation of the mesh.'
  82. },
  83. transform = {
  84. type = 'Mat4',
  85. description = 'The transform to apply to the mesh.'
  86. },
  87. start = {
  88. type = 'number',
  89. default = '1',
  90. description = [[
  91. The 1-based index of the first vertex to render from the vertex buffer (or the first index,
  92. when using an index buffer).
  93. ]]
  94. },
  95. count = {
  96. type = 'number',
  97. default = 'nil',
  98. description = [[
  99. The number of vertices to render (or the number of indices, when using an index buffer).
  100. When `nil`, as many vertices or indices as possible will be drawn (based on the length of
  101. the Buffers and `start`).
  102. ]]
  103. },
  104. vertexcount = {
  105. type = 'number',
  106. description = 'The number of vertices to draw.'
  107. },
  108. indexcount = {
  109. type = 'number',
  110. description = 'The number of indices to draw.'
  111. },
  112. instances = {
  113. type = 'number',
  114. default = '1',
  115. description = 'The number of copies of the mesh to render.'
  116. },
  117. base = {
  118. type = 'number',
  119. default = '0',
  120. description = 'A base offset to apply to vertex indices.'
  121. }
  122. },
  123. returns = {},
  124. variants = {
  125. {
  126. description = 'Draw a range of vertices from a Buffer, using numbers for the transform.',
  127. arguments = { 'vertices', 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az', 'start', 'count', 'instances' },
  128. returns = {}
  129. },
  130. {
  131. description = 'Draw a range of vertices from a Buffer, using vector types for the transform.',
  132. arguments = { 'vertices', 'position', 'scales', 'orientation', 'start', 'count', 'instances' },
  133. returns = {}
  134. },
  135. {
  136. description = 'Draw a range of vertices from a Buffer, using a matrix for the transform.',
  137. arguments = { 'vertices', 'transform', 'start', 'count', 'instances' },
  138. returns = {}
  139. },
  140. {
  141. description = [[
  142. Draw a mesh using a vertex buffer and an index buffer, using numbers for the transform.
  143. ]],
  144. arguments = { 'vertices', 'indices', 'x', 'y', 'z', 'scale', 'angle', 'ax', 'ay', 'az', 'start', 'count', 'instances', 'base' },
  145. returns = {}
  146. },
  147. {
  148. description = [[
  149. Draw a mesh using a vertex buffer and an index buffer, using vector types for the transform.
  150. ]],
  151. arguments = { 'vertices', 'indices', 'position', 'scales', 'orientation', 'start', 'count', 'instances', 'base' },
  152. returns = {}
  153. },
  154. {
  155. description = [[
  156. Draw a mesh using a vertex buffer and an index buffer, using a matrix for the transform.
  157. ]],
  158. arguments = { 'vertices', 'indices', 'transform', 'start', 'count', 'instances', 'base' },
  159. returns = {}
  160. },
  161. {
  162. description = [[
  163. Perform indirect draws. `drawcount` meshes from the vertex and index buffer will be drawn,
  164. using parameters starting from `offset` bytes in the `draws` buffer.
  165. ]],
  166. arguments = { 'vertices', 'indices', 'draws', 'drawcount', 'offset', 'stride' },
  167. returns = {}
  168. }
  169. },
  170. notes = [[
  171. The index buffer defines the order the vertices are drawn in. It can be used to reorder, reuse,
  172. or omit vertices from the mesh.
  173. When drawing without a vertex buffer, the `VertexIndex` variable can be used in shaders to
  174. compute the position of each vertex, possibly by reading data from other `Buffer` or `Texture`
  175. resources.
  176. The active `DrawMode` controls whether the vertices are drawn as points, lines, or triangles.
  177. The active `Material` is applied to the mesh.
  178. ]],
  179. example = [[
  180. function lovr.load()
  181. local vertices = {
  182. vec3( 0, .4, 0), vec4(1, 0, 0, 1),
  183. vec3(-.5, -.4, 0), vec4(0, 1, 0, 1),
  184. vec3( .5, -.4, 0), vec4(0, 0, 1, 1)
  185. }
  186. local format = {
  187. { name = 'VertexPosition', type = 'vec3' },
  188. { name = 'VertexColor', type = 'vec4' }
  189. }
  190. triangle = lovr.graphics.newBuffer(format, vertices)
  191. end
  192. function lovr.draw(pass)
  193. pass:mesh(triangle, 0, 1.7, -1)
  194. end
  195. ]]
  196. }