newMesh.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. return {
  2. tag = 'graphics-objects',
  3. summary = 'Create a new Mesh.',
  4. description = [[
  5. Creates a Mesh. The capacity of the Mesh must be provided upfront, using either a vertex count
  6. or the vertex data itself. A custom vertex format can be given to specify the set of attributes
  7. in each vertex, which get sent to the vertex shader. If the format isn't given, the default
  8. vertex format will be used:
  9. {
  10. { 'VertexPosition', 'vec3' },
  11. { 'VertexNormal', 'vec3' },
  12. { 'VertexUV', 'vec2' }
  13. }
  14. ]],
  15. arguments = {
  16. format = {
  17. type = 'table',
  18. description = [[
  19. A table of attributes describing the format of each vertex. Each attribute is a table that
  20. must have `name` and `type` keys, where the name is a string and the type is a `DataType`.
  21. Attributes can also have an `offset` key, which is a byte offset relative to the start of
  22. the vertex. As a shorthand, the name and type can be given as a pair without keys.
  23. Additionally, the format can have a `stride` key to set the number of bytes between
  24. subsequent vertices.
  25. ]]
  26. },
  27. count = {
  28. type = 'number',
  29. description = 'The number of vertices in the Mesh.'
  30. },
  31. vertices = {
  32. type = 'table',
  33. description = [[
  34. A table of vertices, formatted according to the vertex format. The length of the table will
  35. be used to set the vertex count of the Mesh.
  36. ]]
  37. },
  38. blob = {
  39. type = 'Blob',
  40. description = [[
  41. A Blob containing vertex data, formatted according to the vertex format. The size of the
  42. Blob will be used to set the vertex count of the Mesh, and must be a multiple of the vertex
  43. size.
  44. ]]
  45. },
  46. buffer = {
  47. type = 'Buffer',
  48. description = [[
  49. A Buffer containing vertex data. Its length will be used as the vertex count, and its
  50. format will be used as the vertex format.
  51. ]]
  52. },
  53. storage = {
  54. type = 'MeshStorage',
  55. default = [['cpu']],
  56. description = 'The storage mode of the Mesh.'
  57. }
  58. },
  59. returns = {
  60. mesh = {
  61. type = 'Mesh',
  62. description = 'The new Mesh.'
  63. }
  64. },
  65. variants = {
  66. {
  67. arguments = { 'count', 'storage' },
  68. returns = { 'mesh' }
  69. },
  70. {
  71. arguments = { 'vertices', 'storage' },
  72. returns = { 'mesh' }
  73. },
  74. {
  75. arguments = { 'blob', 'storage' },
  76. returns = { 'mesh' }
  77. },
  78. {
  79. arguments = { 'format', 'count', 'storage' },
  80. returns = { 'mesh' }
  81. },
  82. {
  83. arguments = { 'format', 'vertices', 'storage' },
  84. returns = { 'mesh' }
  85. },
  86. {
  87. arguments = { 'format', 'blob', 'storage' },
  88. returns = { 'mesh' }
  89. },
  90. {
  91. arguments = { 'buffer' },
  92. returns = { 'mesh' }
  93. }
  94. },
  95. notes = 'The Mesh will always use the `gpu` storage mode if it\'s created from a vertex buffer.',
  96. example = [[
  97. function lovr.load()
  98. mesh = lovr.graphics.newMesh({
  99. { 'VertexPosition', 'vec3' },
  100. { 'VertexColor', 'vec4' }
  101. }, {
  102. { 0, .4, 0 , 1, 0, 0, 1 },
  103. { -.5, -.4, 0 , 0, 1, 0, 1 },
  104. { .5, -.4, 0 , 0, 0, 1, 1 }
  105. })
  106. end
  107. function lovr.draw(pass)
  108. pass:draw(mesh, 0, 1.7, -1)
  109. end
  110. ]],
  111. related = {
  112. 'lovr.graphics.newBuffer',
  113. 'lovr.graphics.newModel'
  114. }
  115. }