animate.lua 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. return {
  2. summary = 'Apply an animation to the pose of the Model.',
  3. description = [[
  4. Applies an animation to the current pose of the Model.
  5. The animation is evaluated at the specified timestamp, and mixed with the current pose of the
  6. Model using the alpha value. An alpha value of 1.0 will completely override the pose of the
  7. Model with the animation's pose.
  8. ]],
  9. arguments = {
  10. name = {
  11. type = 'string',
  12. description = 'The name of an animation.'
  13. },
  14. index = {
  15. type = 'number',
  16. description = 'The index of an animation.'
  17. },
  18. time = {
  19. type = 'number',
  20. description = 'The timestamp to evaluate the keyframes at, in seconds.'
  21. },
  22. alpha = {
  23. type = 'number',
  24. default = '1',
  25. description = 'How much of the animation to mix in, from 0 to 1.'
  26. }
  27. },
  28. returns = {},
  29. variants = {
  30. {
  31. arguments = { 'name', 'time', 'alpha' },
  32. returns = {}
  33. },
  34. {
  35. arguments = { 'index', 'time', 'alpha' },
  36. returns = {}
  37. }
  38. },
  39. notes = [[
  40. For animations to properly show up, use a Shader created with the `animated` flag set to `true`.
  41. See `lovr.graphics.newShader` for more.
  42. Animations are always mixed in with the current pose, and the pose only ever changes by calling
  43. `Model:animate` and `Model:pose`. To clear the pose of a Model to the default, use
  44. `Model:pose(nil)`.
  45. ]],
  46. examples = {
  47. {
  48. description = 'Render an animated model, with a custom speed.',
  49. code = [[
  50. function lovr.load()
  51. model = lovr.graphics.newModel('model.gltf')
  52. shader = lovr.graphics.newShader('unlit', { flags = { animated = true } })
  53. end
  54. function lovr.draw()
  55. local speed = 1.0
  56. model:animate(1, lovr.timer.getTime() * speed)
  57. model:draw()
  58. end
  59. ]]
  60. },
  61. {
  62. description = 'Mix from one animation to another, as the trigger is pressed.',
  63. code = [[
  64. function lovr.load()
  65. model = lovr.graphics.newModel('model.gltf')
  66. shader = lovr.graphics.newShader('unlit', { flags = { animated = true } })
  67. end
  68. function lovr.draw()
  69. local t = lovr.timer.getTime()
  70. local mix = lovr.headset.getAxis('right', 'trigger')
  71. model:pose()
  72. model:animate(1, t)
  73. model:animate(2, t, mix)
  74. model:draw()
  75. end
  76. ]]
  77. }
  78. },
  79. related = {
  80. 'Model:pose',
  81. 'Model:getAnimationCount',
  82. 'Model:getAnimationName',
  83. 'Model:getAnimationDuration'
  84. }
  85. }