main.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. local options = {
  2. ['2_Bone_IK'] = {
  3. devices = {
  4. head = {
  5. position = { -.03, 1.6, .1 }
  6. }
  7. }
  8. },
  9. FPS_Controls = false,
  10. Window_HUD = false
  11. }
  12. function lovr.load()
  13. lovr.audio.stop('playback')
  14. local width, height = 360, 400
  15. local backbuffer = lovr.graphics.newTexture(width, height, { usage = { 'sample', 'render', 'transfer' } })
  16. local pass = lovr.graphics.newPass({ backbuffer, depth = 'd32fs8' })
  17. for i, category in ipairs(lovr.filesystem.getDirectoryItems('/')) do
  18. if lovr.filesystem.isDirectory(category) and not category:match('^%.') then
  19. for j, project in ipairs(lovr.filesystem.getDirectoryItems(category)) do
  20. local path = table.concat({ category, project }, '/')
  21. local file = path .. '/main.lua'
  22. print(('Snapping %s...'):format(path))
  23. if options[project] ~= false then
  24. local ok, chunk = pcall(lovr.filesystem.load, file)
  25. if not ok then
  26. print(string.format('Could not parse %q (%s)', file, chunk))
  27. else
  28. local env
  29. env = setmetatable({
  30. lovr = setmetatable({
  31. headset = setmetatable({
  32. getDriver = function()
  33. return 'openxr'
  34. end,
  35. getName = function()
  36. return 'Extremely Spooky Headset You Have Never Heard Of!!'
  37. end,
  38. getOriginType = function()
  39. return 'floor'
  40. end,
  41. getDisplayWidth = function()
  42. return width
  43. end,
  44. getDisplayHeight = function()
  45. return height
  46. end,
  47. getDisplayDimensions = function()
  48. return width, height
  49. end,
  50. getViewCount = function()
  51. return 1
  52. end,
  53. getViewPose = function()
  54. return env.lovr.headset.getPose('head')
  55. end,
  56. getViewAngles = function()
  57. return .5, .5, .5, .5
  58. end,
  59. isTracked = function(device)
  60. local o = options[project]
  61. device = (device or 'head'):gsub('^hand/', ''):gsub('/point$', '')
  62. return device == 'head' or (o and o.devices and o.devices[device])
  63. end,
  64. getPose = function(device)
  65. device = device or 'head'
  66. local defaultPose = {
  67. head = { 0, 1.7, 0; 0, 0, 0, 0 }
  68. }
  69. if not options[project] or not options[project].devices or not options[project].devices[device] then
  70. return unpack(defaultPose[device] or { 0, 0, 0; 0, 0, 0, 0 })
  71. end
  72. local d = options[project].devices[device]
  73. if d.pose then
  74. return unpack(d.pose)
  75. else
  76. local x, y, z, angle, ax, ay, az = 0, 0, 0, 0, 0, 0, 0
  77. if d.position then
  78. x, y, z = unpack(d.position)
  79. end
  80. if d.orientation then
  81. angle, ax, ay, az = unpack(d.orientation)
  82. elseif d.target then
  83. angle, ax, ay, az = select(7, mat4():target(vec3(x, y, z), vec3(unpack(d.target))):unpack())
  84. end
  85. return x, y, z, angle, ax, ay, az
  86. end
  87. end,
  88. getPosition = function(device)
  89. local x, y, z = env.lovr.headset.getPose(device)
  90. return x, y, z
  91. end,
  92. getOrientation = function(device)
  93. local angle, ax, ay, az = select(4, env.lovr.headset.getPose(device))
  94. return angle, ax, ay, az
  95. end,
  96. getVelocity = function(device)
  97. return 0, 0, 0
  98. end,
  99. getAngularVelocity = function(device)
  100. return 0, 0, 0
  101. end,
  102. isDown = function(device, button)
  103. return false
  104. end,
  105. wasPressed = function(device, button)
  106. return false
  107. end,
  108. wasReleased = function(device, button)
  109. return false
  110. end,
  111. isTouched = function(device, button)
  112. return false
  113. end,
  114. getAxis = function(device, axis)
  115. return 0, 0
  116. end,
  117. getSkeleton = function(device)
  118. return nil
  119. end,
  120. vibrate = function(device, strength, duration, frequency)
  121. -- thanks...
  122. end,
  123. newModel = function(device, options)
  124. return nil
  125. end,
  126. animate = function(model)
  127. return false
  128. end,
  129. isFocused = function()
  130. return true
  131. end,
  132. update = function()
  133. return 0
  134. end,
  135. getTime = function()
  136. return 0
  137. end,
  138. getDeltaTime = function()
  139. return 0
  140. end,
  141. getPass = function()
  142. for i = 1, env.lovr.headset.getViewCount() do
  143. pass:setViewPose(i, env.lovr.headset.getViewPose(i))
  144. pass:setProjection(i, env.lovr.headset.getViewAngles(i))
  145. end
  146. return pass
  147. end,
  148. submit = function()
  149. --
  150. end,
  151. getHands = function()
  152. return { 'hand/left', 'hand/right' }
  153. end
  154. }, { __index = lovr.headset }),
  155. load = function() end,
  156. update = function() end,
  157. draw = function() end,
  158. require = function(module)
  159. if module:match('/') then
  160. return require(path .. '/' .. module)
  161. else
  162. return require(path:gsub('/', '.') .. '.' .. module)
  163. end
  164. end
  165. }, { __index = lovr })
  166. }, { __index = _G })
  167. setfenv(chunk, env)
  168. lovr.graphics.setBackgroundColor(0, 0, 0, 1)
  169. pass:setClear(0x000000)
  170. lovr.filesystem.mount(lovr.filesystem.getRealDirectory(path) .. '/' .. path, '/', false)
  171. local ok, result = pcall(chunk)
  172. if not ok then
  173. print(('Failed to run main.lua for %s (%s)'):format(project, result))
  174. else
  175. local ok, thread = pcall(setfenv(env.lovr.run, env))
  176. if not ok or not thread then
  177. print(('\tFailed to run lovr.run for %s (%s)'):format(project, thread))
  178. else
  179. local ok, result = pcall(thread)
  180. if not ok then
  181. print(('\tFailed to run main loop for %s (%s)'):format(project, result))
  182. end
  183. local image = backbuffer:getPixels()
  184. lovr.filesystem.write(project .. '.png', image:encode())
  185. end
  186. end
  187. lovr.filesystem.unmount(path)
  188. lovr.graphics.submit()
  189. end
  190. end
  191. end
  192. end
  193. end
  194. lovr.event.quit()
  195. print('Done')
  196. end