newTerrainShape.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. return {
  2. tag = 'shapes',
  3. summary = 'Create a new TerrainShape.',
  4. description = 'Creates a new TerrainShape.',
  5. arguments = {
  6. scale = {
  7. type = 'number',
  8. description = 'The width and depth of the terrain, in meters.'
  9. },
  10. heightmap = {
  11. type = 'Image',
  12. description = [[
  13. A heightmap image describing the terrain elevation at different points. The red channel
  14. brightness of each pixel determines the elevation at corresponding coordinates.
  15. ]]
  16. },
  17. stretch = {
  18. type = 'number',
  19. default = '1.0',
  20. description = [[
  21. A vertical multiplier for height values to obtain terrain height. When the image format has
  22. pixel values only in the 0 to 1 range, this can be used to scale the height to meters.
  23. ]]
  24. },
  25. callback = {
  26. type = 'function',
  27. arguments = {
  28. {
  29. name = 'x',
  30. type = 'number'
  31. },
  32. {
  33. name = 'z',
  34. type = 'number'
  35. }
  36. },
  37. returns = {
  38. name = 'height',
  39. type = 'number'
  40. },
  41. description = [[
  42. A function that computes terrain height from x and z coordinates. The x and z inputs will
  43. range from `-scale / 2` to `scale / 2`.
  44. ]]
  45. },
  46. samples = {
  47. type = 'number',
  48. default = '100',
  49. description = [[
  50. The number of samples taken across the x and z dimensions. More samples will result in
  51. higher terrain fidelity, but use more CPU and memory.
  52. ]]
  53. }
  54. },
  55. returns = {
  56. terrain = {
  57. type = 'TerrainShape',
  58. description = 'The new TerrainShape.'
  59. }
  60. },
  61. variants = {
  62. {
  63. description = 'Create a flat floor collider.',
  64. arguments = { 'scale' },
  65. returns = { 'terrain' }
  66. },
  67. {
  68. description = 'Create terrain from a heightmap image.',
  69. arguments = { 'scale', 'heightmap', 'stretch' },
  70. returns = { 'terrain' }
  71. },
  72. {
  73. description = 'Create terrain defined with a callback function.',
  74. arguments = { 'scale', 'callback', 'samples' },
  75. returns = { 'terrain' }
  76. }
  77. },
  78. notes = [[
  79. A Shape can be attached to a Collider using `Collider:addShape`.
  80. For immobile terrain use the `Collider:setKinematic`.
  81. ]],
  82. related = {
  83. 'TerrainShape',
  84. 'lovr.physics.newBoxShape',
  85. 'lovr.physics.newCapsuleShape',
  86. 'lovr.physics.newCylinderShape',
  87. 'lovr.physics.newMeshShape',
  88. 'lovr.physics.newSphereShape',
  89. 'lovr.data.newImage'
  90. }
  91. }