@woosh/meep-engine 3.64.1 → 3.65.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/build/bundle-worker-image-decoder.js +1 -1
  3. package/build/bundle-worker-terrain.js +1 -1
  4. package/package.json +1 -1
  5. package/src/core/binary/BinaryBuffer.d.ts +5 -0
  6. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  7. package/src/core/binary/BinaryBuffer.js +39 -5
  8. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.d.ts +65 -6
  9. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.d.ts.map +1 -1
  10. package/src/core/geom/3d/topology/struct/binary/io/bt_boundary_loop.js +451 -101
  11. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts +4 -2
  12. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.d.ts.map +1 -1
  13. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_close_boundary_holes.js +4 -2
  14. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.d.ts +8 -1
  15. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.d.ts.map +1 -1
  16. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_fill_small_holes.js +45 -10
  17. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.d.ts.map +1 -1
  18. package/src/core/geom/3d/topology/struct/binary/query/bt_mesh_face_find_path_polyanya.js +237 -119
  19. package/src/engine/graphics/ecs/grass/GrassSpecies.d.ts +143 -0
  20. package/src/engine/graphics/ecs/grass/GrassSpecies.d.ts.map +1 -0
  21. package/src/engine/graphics/ecs/grass/GrassSpecies.js +189 -0
  22. package/src/engine/graphics/ecs/grass/GrassSurface.d.ts +25 -0
  23. package/src/engine/graphics/ecs/grass/GrassSurface.d.ts.map +1 -0
  24. package/src/engine/graphics/ecs/grass/GrassSurface.js +32 -0
  25. package/src/engine/graphics/ecs/grass/GroundCover.d.ts +68 -0
  26. package/src/engine/graphics/ecs/grass/GroundCover.d.ts.map +1 -0
  27. package/src/engine/graphics/ecs/grass/GroundCover.js +85 -0
  28. package/src/engine/graphics3/GrassSurfaceSystem.d.ts +153 -0
  29. package/src/engine/graphics3/GrassSurfaceSystem.d.ts.map +1 -0
  30. package/src/engine/graphics3/GrassSurfaceSystem.js +1076 -0
  31. package/src/engine/graphics3/GroundCoverSystem.d.ts +33 -0
  32. package/src/engine/graphics3/GroundCoverSystem.d.ts.map +1 -0
  33. package/src/engine/graphics3/GroundCoverSystem.js +58 -0
  34. package/src/engine/network/NetworkSession.d.ts.map +1 -1
  35. package/src/engine/network/NetworkSession.js +372 -110
  36. package/src/engine/network/orchestrator/NetworkPeer.d.ts.map +1 -1
  37. package/src/engine/network/orchestrator/NetworkPeer.js +6 -1
  38. package/src/engine/network/orchestrator/ServerAuthoritativeClient.d.ts.map +1 -1
  39. package/src/engine/network/orchestrator/ServerAuthoritativeClient.js +9 -2
  40. package/src/engine/network/orchestrator/ServerAuthoritativeServer.d.ts.map +1 -1
  41. package/src/engine/network/orchestrator/ServerAuthoritativeServer.js +325 -140
  42. package/src/engine/network/sim/SimActionExecutor.d.ts +4 -1
  43. package/src/engine/network/sim/SimActionExecutor.d.ts.map +1 -1
  44. package/src/engine/network/sim/SimActionExecutor.js +65 -9
  45. package/src/engine/network/state/PredictionHistory.d.ts.map +1 -1
  46. package/src/engine/network/state/PredictionHistory.js +6 -1
  47. package/src/engine/network/time/AdaptiveRenderDelay.d.ts +25 -14
  48. package/src/engine/network/time/AdaptiveRenderDelay.d.ts.map +1 -1
  49. package/src/engine/network/time/AdaptiveRenderDelay.js +38 -20
  50. package/src/engine/network/time/RenderPlayout.d.ts +23 -3
  51. package/src/engine/network/time/RenderPlayout.d.ts.map +1 -1
  52. package/src/engine/network/time/RenderPlayout.js +40 -4
  53. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  54. package/src/engine/physics/fluid/obstacle/chunk_fluid_obstacle_record.d.ts +5 -1
  55. package/src/engine/physics/fluid/obstacle/chunk_fluid_obstacle_record.d.ts.map +1 -1
  56. package/src/engine/physics/fluid/obstacle/chunk_fluid_obstacle_record.js +27 -1
  57. package/src/shade/device/shader/ShaderModuleCompiler.d.ts +2 -0
  58. package/src/shade/device/shader/ShaderModuleCompiler.d.ts.map +1 -1
  59. package/src/shade/device/shader/ShaderModuleCompiler.js +25 -2
  60. package/src/shade/playground/grass_surfaces/index.html +75 -0
  61. package/src/shade/playground/grass_surfaces/main.d.ts +2 -0
  62. package/src/shade/playground/grass_surfaces/main.d.ts.map +1 -0
  63. package/src/shade/playground/grass_surfaces/main.js +593 -0
  64. package/src/shade/playground/grass_surfaces/read_grass_surfaces.d.ts +62 -0
  65. package/src/shade/playground/grass_surfaces/read_grass_surfaces.d.ts.map +1 -0
  66. package/src/shade/playground/grass_surfaces/read_grass_surfaces.js +188 -0
  67. package/src/shade/playground/probe_clipmap_box/README.md +5 -1
  68. package/src/shade/playground/probe_clipmap_box/index.html +12 -0
  69. package/src/shade/playground/probe_clipmap_box/main.d.ts.map +1 -1
  70. package/src/shade/playground/probe_clipmap_box/main.js +15 -0
  71. package/src/shade/playground/probe_clipmap_box/scene.d.ts +8 -1
  72. package/src/shade/playground/probe_clipmap_box/scene.d.ts.map +1 -1
  73. package/src/shade/playground/probe_clipmap_box/scene.js +74 -6
  74. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  75. package/src/shade/renderer/Renderer.js +47 -43
  76. package/src/shade/renderer/extension/ViewTextures.d.ts +12 -5
  77. package/src/shade/renderer/extension/ViewTextures.d.ts.map +1 -1
  78. package/src/shade/renderer/extension/ViewTextures.js +19 -5
  79. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +3 -1
  80. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts.map +1 -1
  81. package/src/shade/renderer/fluid/GPUFluidCascadeStack.js +6 -1
  82. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -0
  83. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts.map +1 -1
  84. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.js +10 -0
  85. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts +7 -1
  86. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.d.ts.map +1 -1
  87. package/src/shade/renderer/geometry/sdf/GPUGeometrySDFManager.js +46 -15
  88. package/src/shade/renderer/geometry/sdf/bundle/ModelCacheBundle.d.ts +3 -2
  89. package/src/shade/renderer/geometry/sdf/bundle/ModelCacheBundle.d.ts.map +1 -1
  90. package/src/shade/renderer/geometry/sdf/bundle/ModelCacheBundle.js +3 -2
  91. package/src/shade/renderer/geometry/sdf/bundle/model_cache_bundle_sort_morton.d.ts +22 -0
  92. package/src/shade/renderer/geometry/sdf/bundle/model_cache_bundle_sort_morton.d.ts.map +1 -0
  93. package/src/shade/renderer/geometry/sdf/bundle/model_cache_bundle_sort_morton.js +247 -0
  94. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +50 -0
  95. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts.map +1 -1
  96. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.js +101 -0
  97. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts +2 -1
  98. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.d.ts.map +1 -1
  99. package/src/shade/renderer/global_illumination/probe_clipmap/ProbeClipmapSettings.js +2 -1
  100. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts +8 -0
  101. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.d.ts.map +1 -1
  102. package/src/shade/renderer/global_illumination/probe_clipmap/brick/GPUBrickClipmap.js +12 -0
  103. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts +12 -6
  104. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.d.ts.map +1 -1
  105. package/src/shade/renderer/global_illumination/probe_clipmap/brick/chunk_brick_clipmap_trace.js +35 -29
  106. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_clipmap.d.ts.map +1 -1
  107. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_clipmap.js +4 -2
  108. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_material.d.ts.map +1 -1
  109. package/src/shade/renderer/global_illumination/probe_clipmap/debug/graph_probe_clipmap_debug_brick_material.js +6 -4
  110. package/src/shade/renderer/global_illumination/probe_clipmap/material/GPUBrickMaterial.d.ts.map +1 -1
  111. package/src/shade/renderer/global_illumination/probe_clipmap/material/GPUBrickMaterial.js +2 -1
  112. package/src/shade/renderer/global_illumination/probe_clipmap/material/chunk_brick_material.d.ts +6 -5
  113. package/src/shade/renderer/global_illumination/probe_clipmap/material/chunk_brick_material.d.ts.map +1 -1
  114. package/src/shade/renderer/global_illumination/probe_clipmap/material/chunk_brick_material.js +15 -14
  115. package/src/shade/renderer/global_illumination/probe_clipmap/material/shader_brick_material_gather.d.ts.map +1 -1
  116. package/src/shade/renderer/global_illumination/probe_clipmap/material/shader_brick_material_gather.js +4 -2
  117. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts +19 -2
  118. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.d.ts.map +1 -1
  119. package/src/shade/renderer/global_illumination/probe_clipmap/probe/GPUProbeClipmap.js +128 -10
  120. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts +19 -1
  121. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.d.ts.map +1 -1
  122. package/src/shade/renderer/global_illumination/probe_clipmap/probe/PROBE_CLIPMAP.js +27 -2
  123. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts +19 -11
  124. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.d.ts.map +1 -1
  125. package/src/shade/renderer/global_illumination/probe_clipmap/probe/ProbeClipmapScreenWants.js +35 -11
  126. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.d.ts.map +1 -1
  127. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap.js +3 -1
  128. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_box_cages.d.ts +40 -0
  129. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_box_cages.d.ts.map +1 -0
  130. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_box_cages.js +174 -0
  131. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_material.d.ts +4 -4
  132. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_hit_material.js +10 -10
  133. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_parallax.d.ts +31 -0
  134. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_parallax.d.ts.map +1 -0
  135. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_parallax.js +54 -0
  136. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.d.ts +8 -4
  137. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.d.ts.map +1 -1
  138. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_sample_radiance.js +10 -21
  139. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.d.ts +7 -2
  140. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.d.ts.map +1 -1
  141. package/src/shade/renderer/global_illumination/probe_clipmap/probe/chunk_probe_clipmap_want.js +33 -29
  142. package/src/shade/renderer/global_illumination/probe_clipmap/probe/graph_probe_clipmap_want_meshlets.d.ts +28 -0
  143. package/src/shade/renderer/global_illumination/probe_clipmap/probe/graph_probe_clipmap_want_meshlets.d.ts.map +1 -0
  144. package/src/shade/renderer/global_illumination/probe_clipmap/probe/graph_probe_clipmap_want_meshlets.js +138 -0
  145. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts +13 -9
  146. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.d.ts.map +1 -1
  147. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_due.js +18 -11
  148. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_light.js +1 -1
  149. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.d.ts.map +1 -1
  150. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_relocate.js +4 -2
  151. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_retire.d.ts.map +1 -1
  152. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_retire.js +2 -3
  153. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.d.ts +5 -3
  154. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.d.ts.map +1 -1
  155. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_schedule.js +15 -30
  156. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_shade.js +1 -1
  157. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.d.ts.map +1 -1
  158. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_trace.js +4 -2
  159. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts +11 -0
  160. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.d.ts.map +1 -1
  161. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want.js +29 -2
  162. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_late.d.ts +40 -0
  163. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_late.d.ts.map +1 -0
  164. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_late.js +126 -0
  165. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_meshlets.d.ts +36 -0
  166. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_meshlets.d.ts.map +1 -0
  167. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_want_meshlets.js +221 -0
  168. package/src/shade/renderer/gpu_primitive/age_eviction/chunk_age_eviction.d.ts +40 -0
  169. package/src/shade/renderer/gpu_primitive/age_eviction/chunk_age_eviction.d.ts.map +1 -0
  170. package/src/shade/renderer/gpu_primitive/age_eviction/chunk_age_eviction.js +86 -0
  171. package/src/shade/renderer/grass/blade/GPUGrassBlades.d.ts +135 -0
  172. package/src/shade/renderer/grass/blade/GPUGrassBlades.d.ts.map +1 -0
  173. package/src/shade/renderer/grass/blade/GPUGrassBlades.js +676 -0
  174. package/src/shade/renderer/grass/blade/GRASS_BLADE.d.ts +145 -0
  175. package/src/shade/renderer/grass/blade/GRASS_BLADE.d.ts.map +1 -0
  176. package/src/shade/renderer/grass/blade/GRASS_BLADE.js +179 -0
  177. package/src/shade/renderer/grass/blade/chunk_grass_blade.d.ts +63 -0
  178. package/src/shade/renderer/grass/blade/chunk_grass_blade.d.ts.map +1 -0
  179. package/src/shade/renderer/grass/blade/chunk_grass_blade.js +244 -0
  180. package/src/shade/renderer/grass/blade/chunk_grass_blade_wind.d.ts +58 -0
  181. package/src/shade/renderer/grass/blade/chunk_grass_blade_wind.d.ts.map +1 -0
  182. package/src/shade/renderer/grass/blade/chunk_grass_blade_wind.js +174 -0
  183. package/src/shade/renderer/grass/blade/grass_blade_id_draw.d.ts +25 -0
  184. package/src/shade/renderer/grass/blade/grass_blade_id_draw.d.ts.map +1 -0
  185. package/src/shade/renderer/grass/blade/grass_blade_id_draw.js +133 -0
  186. package/src/shade/renderer/grass/blade/grass_blade_mechanics.d.ts +80 -0
  187. package/src/shade/renderer/grass/blade/grass_blade_mechanics.d.ts.map +1 -0
  188. package/src/shade/renderer/grass/blade/grass_blade_mechanics.js +92 -0
  189. package/src/shade/renderer/grass/blade/grass_blade_resolve.d.ts +29 -0
  190. package/src/shade/renderer/grass/blade/grass_blade_resolve.d.ts.map +1 -0
  191. package/src/shade/renderer/grass/blade/grass_blade_resolve.js +175 -0
  192. package/src/shade/renderer/grass/blade/shader_grass_blade_draw_args.d.ts +14 -0
  193. package/src/shade/renderer/grass/blade/shader_grass_blade_draw_args.d.ts.map +1 -0
  194. package/src/shade/renderer/grass/blade/shader_grass_blade_draw_args.js +45 -0
  195. package/src/shade/renderer/grass/blade/shader_grass_blade_expand.d.ts +61 -0
  196. package/src/shade/renderer/grass/blade/shader_grass_blade_expand.d.ts.map +1 -0
  197. package/src/shade/renderer/grass/blade/shader_grass_blade_expand.js +340 -0
  198. package/src/shade/renderer/grass/blade/shader_grass_cell_count.d.ts +46 -0
  199. package/src/shade/renderer/grass/blade/shader_grass_cell_count.d.ts.map +1 -0
  200. package/src/shade/renderer/grass/blade/shader_grass_cell_count.js +280 -0
  201. package/src/shade/renderer/grass/population/chunk_grass_population.d.ts +60 -0
  202. package/src/shade/renderer/grass/population/chunk_grass_population.d.ts.map +1 -0
  203. package/src/shade/renderer/grass/population/chunk_grass_population.js +171 -0
  204. package/src/shade/renderer/grass/press/GPUGrassPress.d.ts +99 -0
  205. package/src/shade/renderer/grass/press/GPUGrassPress.d.ts.map +1 -0
  206. package/src/shade/renderer/grass/press/GPUGrassPress.js +436 -0
  207. package/src/shade/renderer/grass/press/GRASS_PRESS.d.ts +179 -0
  208. package/src/shade/renderer/grass/press/GRASS_PRESS.d.ts.map +1 -0
  209. package/src/shade/renderer/grass/press/GRASS_PRESS.js +217 -0
  210. package/src/shade/renderer/grass/press/chunk_grass_press.d.ts +65 -0
  211. package/src/shade/renderer/grass/press/chunk_grass_press.d.ts.map +1 -0
  212. package/src/shade/renderer/grass/press/chunk_grass_press.js +296 -0
  213. package/src/shade/renderer/grass/press/shader_grass_press_mark.d.ts +31 -0
  214. package/src/shade/renderer/grass/press/shader_grass_press_mark.d.ts.map +1 -0
  215. package/src/shade/renderer/grass/press/shader_grass_press_mark.js +169 -0
  216. package/src/shade/renderer/grass/press/shader_grass_press_stamp.d.ts +27 -0
  217. package/src/shade/renderer/grass/press/shader_grass_press_stamp.d.ts.map +1 -0
  218. package/src/shade/renderer/grass/press/shader_grass_press_stamp.js +183 -0
  219. package/src/shade/renderer/grass/surface/GPUGrassSurfaces.d.ts +193 -0
  220. package/src/shade/renderer/grass/surface/GPUGrassSurfaces.d.ts.map +1 -0
  221. package/src/shade/renderer/grass/surface/GPUGrassSurfaces.js +1253 -0
  222. package/src/shade/renderer/grass/surface/GRASS_SURFACE.d.ts +211 -0
  223. package/src/shade/renderer/grass/surface/GRASS_SURFACE.d.ts.map +1 -0
  224. package/src/shade/renderer/grass/surface/GRASS_SURFACE.js +241 -0
  225. package/src/shade/renderer/grass/surface/GRASS_SURFACE_VIEW.d.ts +82 -0
  226. package/src/shade/renderer/grass/surface/GRASS_SURFACE_VIEW.d.ts.map +1 -0
  227. package/src/shade/renderer/grass/surface/GRASS_SURFACE_VIEW.js +111 -0
  228. package/src/shade/renderer/grass/surface/chunk_grass_column_cross.d.ts +39 -0
  229. package/src/shade/renderer/grass/surface/chunk_grass_column_cross.d.ts.map +1 -0
  230. package/src/shade/renderer/grass/surface/chunk_grass_column_cross.js +85 -0
  231. package/src/shade/renderer/grass/surface/chunk_grass_directory.d.ts +29 -0
  232. package/src/shade/renderer/grass/surface/chunk_grass_directory.d.ts.map +1 -0
  233. package/src/shade/renderer/grass/surface/chunk_grass_directory.js +112 -0
  234. package/src/shade/renderer/grass/surface/chunk_grass_slot.d.ts +27 -0
  235. package/src/shade/renderer/grass/surface/chunk_grass_slot.d.ts.map +1 -0
  236. package/src/shade/renderer/grass/surface/chunk_grass_slot.js +50 -0
  237. package/src/shade/renderer/grass/surface/chunk_grass_surface_frame.d.ts +21 -0
  238. package/src/shade/renderer/grass/surface/chunk_grass_surface_frame.d.ts.map +1 -0
  239. package/src/shade/renderer/grass/surface/chunk_grass_surface_frame.js +41 -0
  240. package/src/shade/renderer/grass/surface/chunk_grass_surface_window.d.ts +32 -0
  241. package/src/shade/renderer/grass/surface/chunk_grass_surface_window.d.ts.map +1 -0
  242. package/src/shade/renderer/grass/surface/chunk_grass_surface_window.js +136 -0
  243. package/src/shade/renderer/grass/surface/chunk_grass_surfel.d.ts +37 -0
  244. package/src/shade/renderer/grass/surface/chunk_grass_surfel.d.ts.map +1 -0
  245. package/src/shade/renderer/grass/surface/chunk_grass_surfel.js +85 -0
  246. package/src/shade/renderer/grass/surface/chunk_grass_tile.d.ts +25 -0
  247. package/src/shade/renderer/grass/surface/chunk_grass_tile.d.ts.map +1 -0
  248. package/src/shade/renderer/grass/surface/chunk_grass_tile.js +52 -0
  249. package/src/shade/renderer/grass/surface/shader_grass_directory_fill.d.ts +23 -0
  250. package/src/shade/renderer/grass/surface/shader_grass_directory_fill.d.ts.map +1 -0
  251. package/src/shade/renderer/grass/surface/shader_grass_directory_fill.js +87 -0
  252. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.d.ts +43 -0
  253. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.d.ts.map +1 -0
  254. package/src/shade/renderer/grass/surface/shader_grass_surface_bake.js +265 -0
  255. package/src/shade/renderer/grass/surface/shader_grass_surface_bake_command.d.ts +13 -0
  256. package/src/shade/renderer/grass/surface/shader_grass_surface_bake_command.d.ts.map +1 -0
  257. package/src/shade/renderer/grass/surface/shader_grass_surface_bake_command.js +49 -0
  258. package/src/shade/renderer/grass/surface/shader_grass_surface_invalidate.d.ts +62 -0
  259. package/src/shade/renderer/grass/surface/shader_grass_surface_invalidate.d.ts.map +1 -0
  260. package/src/shade/renderer/grass/surface/shader_grass_surface_invalidate.js +162 -0
  261. package/src/shade/renderer/grass/surface/shader_grass_surface_retire.d.ts +40 -0
  262. package/src/shade/renderer/grass/surface/shader_grass_surface_retire.d.ts.map +1 -0
  263. package/src/shade/renderer/grass/surface/shader_grass_surface_retire.js +155 -0
  264. package/src/shade/renderer/grass/surface/shader_grass_surface_schedule.d.ts +19 -0
  265. package/src/shade/renderer/grass/surface/shader_grass_surface_schedule.d.ts.map +1 -0
  266. package/src/shade/renderer/grass/surface/shader_grass_surface_schedule.js +58 -0
  267. package/src/shade/renderer/grass/surface/shader_grass_surface_want.d.ts +30 -0
  268. package/src/shade/renderer/grass/surface/shader_grass_surface_want.d.ts.map +1 -0
  269. package/src/shade/renderer/grass/surface/shader_grass_surface_want.js +251 -0
  270. package/src/shade/renderer/grass/surface/shader_grass_surface_window_count.d.ts +21 -0
  271. package/src/shade/renderer/grass/surface/shader_grass_surface_window_count.d.ts.map +1 -0
  272. package/src/shade/renderer/grass/surface/shader_grass_surface_window_count.js +75 -0
  273. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.d.ts.map +1 -1
  274. package/src/shade/renderer/postprocess/velocity/graph_add_per_object_velocity.js +4 -23
  275. package/src/shade/renderer/postprocess/velocity/view_velocity_matrices.d.ts +12 -0
  276. package/src/shade/renderer/postprocess/velocity/view_velocity_matrices.d.ts.map +1 -0
  277. package/src/shade/renderer/postprocess/velocity/view_velocity_matrices.js +29 -0
  278. package/src/shade/renderer/rasterize/native/avboit/graph_rasterize_meshes_transparent_avboit.d.ts.map +1 -1
  279. package/src/shade/renderer/rasterize/native/avboit/graph_rasterize_meshes_transparent_avboit.js +22 -0
  280. package/src/shade/renderer/scene/GPUSceneContext.d.ts.map +1 -1
  281. package/src/shade/renderer/scene/GPUSceneContext.js +3 -0
  282. package/src/shade/renderer/scene/GRASS_SURFACE_PARAMS_STRUCT.d.ts +27 -0
  283. package/src/shade/renderer/scene/GRASS_SURFACE_PARAMS_STRUCT.d.ts.map +1 -0
  284. package/src/shade/renderer/scene/GRASS_SURFACE_PARAMS_STRUCT.js +38 -0
  285. package/src/shade/renderer/scene/MESH_GROUND_COVER_STRUCT.d.ts +28 -0
  286. package/src/shade/renderer/scene/MESH_GROUND_COVER_STRUCT.d.ts.map +1 -0
  287. package/src/shade/renderer/scene/MESH_GROUND_COVER_STRUCT.js +58 -0
  288. package/src/shade/renderer/scene/SCENE_DATABASE_SPEC.d.ts.map +1 -1
  289. package/src/shade/renderer/scene/SCENE_DATABASE_SPEC.js +8 -0
  290. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.d.ts +37 -0
  291. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.d.ts.map +1 -0
  292. package/src/shade/renderer/shader/chunk/geometry/ray/chunk_ray_query_nearest_among.js +148 -0
  293. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_line_span.d.ts +20 -0
  294. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_line_span.d.ts.map +1 -0
  295. package/src/shade/renderer/shader/chunk/sdf/chunk_shape_record_line_span.js +169 -0
  296. package/src/shade/renderer/texture/atlas/chunk_tile_atlas_slot_origin.d.ts +18 -0
  297. package/src/shade/renderer/texture/atlas/chunk_tile_atlas_slot_origin.d.ts.map +1 -1
  298. package/src/shade/renderer/texture/atlas/chunk_tile_atlas_slot_origin.js +28 -0
  299. package/src/shade/renderer/texture/atlas/tile_atlas_slot_shift.d.ts +13 -0
  300. package/src/shade/renderer/texture/atlas/tile_atlas_slot_shift.d.ts.map +1 -0
  301. package/src/shade/renderer/texture/atlas/tile_atlas_slot_shift.js +22 -0
  302. package/src/shade/renderer/water/GPUWaterRenderer.d.ts.map +1 -1
  303. package/src/shade/renderer/water/GPUWaterRenderer.js +4 -0
  304. package/src/shade/renderer/wind/GPUSceneWind.d.ts +52 -5
  305. package/src/shade/renderer/wind/GPUSceneWind.d.ts.map +1 -1
  306. package/src/shade/renderer/wind/GPUSceneWind.js +164 -8
  307. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.d.ts +3 -1
  308. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.d.ts.map +1 -1
  309. package/src/shade/renderer/wind/WIND_FIELD_UNIFORM.js +3 -1
  310. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts +2 -1
  311. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.d.ts.map +1 -1
  312. package/src/shade/renderer/wind/chunk_wind_field_sample_cascades.js +18 -13
  313. package/src/shade/renderer/wind/chunk_wind_field_sample_previous.d.ts +13 -0
  314. package/src/shade/renderer/wind/chunk_wind_field_sample_previous.d.ts.map +1 -0
  315. package/src/shade/renderer/wind/chunk_wind_field_sample_previous.js +23 -0
  316. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.d.ts +1 -0
  317. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.d.ts.map +1 -1
  318. package/src/shade/renderer/wind/chunk_wind_field_sample_uniform.js +6 -1
  319. package/src/shade/renderer/wind/wind_field_add_resources.d.ts +11 -0
  320. package/src/shade/renderer/wind/wind_field_add_resources.d.ts.map +1 -1
  321. package/src/shade/renderer/wind/wind_field_add_resources.js +15 -0
  322. package/src/shade/wgsl/emulator/WGSLJavaScriptCompiler.js +1 -1
  323. package/src/shade/wgsl/emulator/WGSLLanguageCore.d.ts.map +1 -1
  324. package/src/shade/wgsl/emulator/WGSLLanguageCore.js +2 -0
@@ -0,0 +1,593 @@
1
+ import { Color } from "../../../core/color/Color.js";
2
+ import { BoxShape3D } from "../../../core/geom/3d/shape/BoxShape3D.js";
3
+ import { SphereShape3D } from "../../../core/geom/3d/shape/SphereShape3D.js";
4
+ import Quaternion from "../../../core/geom/Quaternion.js";
5
+ import Vector3 from "../../../core/geom/Vector3.js";
6
+ import { DEG_TO_RAD } from "../../../core/math/DEG_TO_RAD.js";
7
+ import { Entity } from "../../../engine/ecs/Entity.js";
8
+ import { EntityComponentDataset } from "../../../engine/ecs/EntityComponentDataset.js";
9
+ import { EntityManager } from "../../../engine/ecs/EntityManager.js";
10
+ import { t64_announce_change } from "../../../engine/ecs/transform/t64_announce_change.js";
11
+ import { Transform64 } from "../../../engine/ecs/transform/Transform64.js";
12
+ import { GrassSpecies } from "../../../engine/graphics/ecs/grass/GrassSpecies.js";
13
+ import { GrassSurface } from "../../../engine/graphics/ecs/grass/GrassSurface.js";
14
+ import { GroundCover } from "../../../engine/graphics/ecs/grass/GroundCover.js";
15
+ import { Light } from "../../../engine/graphics/ecs/light/Light.js";
16
+ import { LightType } from "../../../engine/graphics/ecs/light/LightType.js";
17
+ import { ShadedGeometry } from "../../../engine/graphics/ecs/mesh-v2/ShadedGeometry.js";
18
+ import { GPUFluidSystem } from "../../../engine/graphics3/GPUFluidSystem.js";
19
+ import { GraphicsEngine } from "../../../engine/graphics3/GraphicsEngine.js";
20
+ import { GrassSurfaceSystem } from "../../../engine/graphics3/GrassSurfaceSystem.js";
21
+ import { GroundCoverSystem } from "../../../engine/graphics3/GroundCoverSystem.js";
22
+ import { LightSystem } from "../../../engine/graphics3/LightSystem.js";
23
+ import { ShadedGeometrySystem } from "../../../engine/graphics3/ShadedGeometrySystem.js";
24
+ import { Collider } from "../../../engine/physics/ecs/Collider.js";
25
+ import { RigidBody } from "../../../engine/physics/ecs/RigidBody.js";
26
+ import { FluidEffectorsComponent } from "../../../engine/physics/fluid/ecs/FluidEffectorsComponent.js";
27
+ import { FluidEffectorsSystem } from "../../../engine/physics/fluid/ecs/FluidEffectorsSystem.js";
28
+ import { FluidObstacle } from "../../../engine/physics/fluid/ecs/FluidObstacle.js";
29
+ import { GPUFluidComponent } from "../../../engine/physics/fluid/ecs/GPUFluidComponent.js";
30
+ import { GlobalFluidEffector } from "../../../engine/physics/fluid/effector/GlobalFluidEffector.js";
31
+ import { OrbitalCameraController } from "../../renderer/camera/orbital/OrbitalCameraController.js";
32
+ import { create_frame_loop } from "../../renderer/create_frame_loop.js";
33
+ import { MeshletGeometry } from "../../renderer/geometry/MeshletGeometry.js";
34
+ import { MeshoptClusterizer } from "../../renderer/geometry/meshlet/build/meshoptimizer/meshopt_clusterizer.js";
35
+ import { meshlet_geometry_build_from_geometry } from "../../renderer/geometry/meshlet_geometry_build_from_geometry.js";
36
+ import { make_box_geometry } from "../../renderer/geometry/primitives/make_box_geometry.js";
37
+ import { make_plane_geometry } from "../../renderer/geometry/primitives/make_plane_geometry.js";
38
+ import { make_uv_sphere_geometry } from "../../renderer/geometry/primitives/make_uv_sphere_geometry.js";
39
+ import { ShadeDrawSide } from "../../renderer/material/ShadeDrawSide.js";
40
+ import { StandardShadeMaterial } from "../../renderer/material/StandardShadeMaterial.js";
41
+ import { TransparencyMode } from "../../renderer/material/TransparencyMode.js";
42
+ import { row_of_entity } from "../../renderer/scene/rows/GPUSceneRows.js";
43
+ import { Scene } from "../../renderer/scene/Scene.js";
44
+ import { read_grass_surfaces } from "./read_grass_surfaces.js";
45
+
46
+ /**
47
+ * Grass surfaces on a small set, laid out so that every way a column can meet ground is in view and has a
48
+ * known answer.
49
+ *
50
+ * **The field** is one surface of four members: two 16 m sheets that meet along x = 0, a boulder sunk
51
+ * through the first, and a hill standing 3 m over the second with a cave under it. A slab hangs over part
52
+ * of the first sheet and is no member. **The platform** is another surface, two sheets and a crate, that
53
+ * circles and turns as one.
54
+ *
55
+ * **The wind** is the scene's: a steady wind with a gust on it, and a fluid about the field that the
56
+ * boulder and the hill stand in, so the grass in their lee is in their wake. `globalThis.weather` is the
57
+ * wind's effector.
58
+ *
59
+ * **The roller** is a ball that rolls round a ring on the field's first sheet, an obstacle in the air and
60
+ * no member of the field: the grass under it is pressed down and stands back up behind it.
61
+ * `globalThis.__roller_still` holds it where it is.
62
+ *
63
+ * `globalThis.world` names every entity and says where each piece is, and `globalThis.read_grass()` reads
64
+ * the surfaces' pool off the device, so a check can hold what was baked against what was built.
65
+ *
66
+ * Serve the workspace with `npm run dev --workspace @woosh/meep-engine` and open
67
+ * `/src/shade/playground/grass_surfaces/index.html`.
68
+ */
69
+
70
+ const CAMERA = {
71
+ position: new Vector3(-4, 7, 22),
72
+ target: new Vector3(2, 1, 0),
73
+ fov_degrees: 50,
74
+ };
75
+
76
+ /**
77
+ * Where the pieces are, in metres. Boxes are `[low, high]`.
78
+ */
79
+ const LAYOUT = {
80
+ sheet_a: [[-16, 0, -8], [0, 0, 8]],
81
+ sheet_b: [[0, 0, -8], [16, 0, 8]],
82
+ boulder: [[-8, -1, 2], [-5, 2, 5]],
83
+ hill: [[4, 3, -4], [12, 7, 4]],
84
+ slab: [[-14, 4, -7], [-10, 4.5, -3]],
85
+ roller: {
86
+ // the ring it rolls round, on the ground
87
+ centre: [-3, 0, -3.5],
88
+ ring: 3,
89
+ radius: 0.6,
90
+ // how far its lowest point is under the ground
91
+ sunk: 0.05,
92
+ // seconds a lap
93
+ period: 14,
94
+ },
95
+ platform: {
96
+ centre: [0, 6, -22],
97
+ radius: 6,
98
+ // seconds a lap
99
+ period: 20,
100
+ // the platform's own frame
101
+ sheet_a: [[-6, 0, -3], [0, 0, 3]],
102
+ sheet_b: [[0, 0, -3], [6, 0, 3]],
103
+ crate: [[1, -0.5, -1], [3, 1, 1]],
104
+ },
105
+ };
106
+
107
+ const element = id => document.getElementById(id);
108
+
109
+ const view_size = () => [Math.max(1, window.innerWidth), Math.max(1, window.innerHeight)];
110
+
111
+ /**
112
+ * @param {number[]} position
113
+ * @param {Quaternion} [rotation]
114
+ * @returns {Transform64}
115
+ */
116
+ function placed(position, rotation = new Quaternion()) {
117
+ const transform = new Transform64();
118
+
119
+ transform.setTranslation(position[0], position[1], position[2]);
120
+ transform.setRotation(rotation.x, rotation.y, rotation.z, rotation.w);
121
+ transform.updateMatrix();
122
+
123
+ return transform;
124
+ }
125
+
126
+ /**
127
+ * @param {object} geometry
128
+ * @returns {MeshletGeometry}
129
+ */
130
+ function meshlets(geometry) {
131
+ const built = new MeshletGeometry();
132
+
133
+ meshlet_geometry_build_from_geometry(geometry, built);
134
+
135
+ return built;
136
+ }
137
+
138
+ /**
139
+ * @param {Color} diffuse
140
+ * @returns {StandardShadeMaterial}
141
+ */
142
+ function material(diffuse) {
143
+ const result = new StandardShadeMaterial();
144
+
145
+ result.diffuse_color.copy(diffuse);
146
+ result.roughness_factor = 0.85;
147
+ result.metallic_factor = 0;
148
+ result.transparency_mode = TransparencyMode.Opaque;
149
+ result.draw_side = ShadeDrawSide.Double;
150
+
151
+ return result;
152
+ }
153
+
154
+ /**
155
+ * @param {MeshletGeometry} geometry
156
+ * @param {StandardShadeMaterial} material_instance
157
+ * @returns {ShadedGeometry}
158
+ */
159
+ function shaded(geometry, material_instance) {
160
+ const component = new ShadedGeometry();
161
+
162
+ component.geometry = geometry;
163
+ component.material = material_instance;
164
+
165
+ return component;
166
+ }
167
+
168
+ const centre_of = box => [0, 1, 2].map(axis => (box[0][axis] + box[1][axis]) / 2);
169
+ const extent_of = box => [0, 1, 2].map(axis => box[1][axis] - box[0][axis]);
170
+
171
+ // a plane is made in its own xy; a quarter turn about x lays it flat, facing up
172
+ const FLAT = Quaternion.fromAxisAngle(Vector3.right, -Math.PI / 2);
173
+
174
+ /**
175
+ * @param {EntityComponentDataset} dataset
176
+ */
177
+ function build_world(dataset) {
178
+ const earth = material(new Color(0.30, 0.26, 0.20, 1));
179
+ const rock = material(new Color(0.45, 0.45, 0.47, 1));
180
+ const wood = material(new Color(0.50, 0.38, 0.24, 1));
181
+ const concrete = material(new Color(0.6, 0.6, 0.6, 1));
182
+
183
+ const species = GrassSpecies.from({ blade_length: 0.4, blade_width: 0.015, density: 300 });
184
+
185
+ /** What stands in the wind: a box as large as the piece. */
186
+ const windbreak = box => {
187
+ const collider = new Collider();
188
+ const extent = extent_of(box);
189
+
190
+ collider.shape = BoxShape3D.from(extent[0] / 2, extent[1] / 2, extent[2] / 2);
191
+
192
+ return collider;
193
+ };
194
+
195
+ const sheet = box => shaded(meshlets(make_plane_geometry(extent_of(box)[0], extent_of(box)[2])), earth);
196
+ const block = (box, material_instance) => shaded(meshlets(make_box_geometry(...extent_of(box))), material_instance);
197
+
198
+ const world = { species, field: {}, platform: {} };
199
+
200
+ // ---- the field ----
201
+
202
+ world.field.surface = new Entity()
203
+ .add(new Transform64())
204
+ .add(new GrassSurface())
205
+ .build(dataset);
206
+
207
+ const field_cover = grows => GroundCover.from({ surface: world.field.surface, species: grows ? species : null });
208
+
209
+ world.field.sheet_a = new Entity()
210
+ .add(placed(centre_of(LAYOUT.sheet_a), FLAT))
211
+ .add(sheet(LAYOUT.sheet_a))
212
+ .add(field_cover(true))
213
+ .build(dataset);
214
+
215
+ world.field.sheet_b = new Entity()
216
+ .add(placed(centre_of(LAYOUT.sheet_b), FLAT))
217
+ .add(sheet(LAYOUT.sheet_b))
218
+ .add(field_cover(true))
219
+ .build(dataset);
220
+
221
+ // sunk through the first sheet: nothing grows on it, and nothing through it
222
+ world.field.boulder = new Entity()
223
+ .add(placed(centre_of(LAYOUT.boulder)))
224
+ .add(block(LAYOUT.boulder, rock))
225
+ .add(field_cover(false))
226
+ .add(new FluidObstacle())
227
+ .add(windbreak(LAYOUT.boulder))
228
+ .add(new RigidBody())
229
+ .build(dataset);
230
+
231
+ // standing over the second sheet: grass on its top, and on the cave's floor under it
232
+ world.field.hill = new Entity()
233
+ .add(placed(centre_of(LAYOUT.hill)))
234
+ .add(block(LAYOUT.hill, earth))
235
+ .add(field_cover(true))
236
+ .add(new FluidObstacle())
237
+ .add(windbreak(LAYOUT.hill))
238
+ .add(new RigidBody())
239
+ .build(dataset);
240
+
241
+ // over the first sheet, and no member: the field's columns pass it by
242
+ world.field.slab = new Entity()
243
+ .add(placed(centre_of(LAYOUT.slab)))
244
+ .add(block(LAYOUT.slab, concrete))
245
+ .build(dataset);
246
+
247
+ // ---- the roller ----
248
+
249
+ const roller = LAYOUT.roller;
250
+
251
+ const roller_transform = new Transform64();
252
+ const roller_body = new RigidBody();
253
+
254
+ const roller_collider = new Collider();
255
+
256
+ roller_collider.shape = SphereShape3D.from(roller.radius);
257
+
258
+ world.field.roller = new Entity()
259
+ .add(roller_transform)
260
+ .add(shaded(meshlets(make_uv_sphere_geometry(roller.radius, 32, 16)), wood))
261
+ .add(new FluidObstacle())
262
+ .add(roller_collider)
263
+ .add(roller_body)
264
+ .build(dataset);
265
+
266
+ const roll = new Quaternion();
267
+ const roll_axis = new Vector3();
268
+
269
+ /**
270
+ * Put the roller where it is at a time, moving and turning as a ball that rolls there does.
271
+ *
272
+ * @param {number} time seconds
273
+ */
274
+ world.field.roll = time => {
275
+ const rate = 2 * Math.PI / roller.period;
276
+ const angle = rate * time;
277
+
278
+ const out_x = Math.cos(angle);
279
+ const out_z = Math.sin(angle);
280
+
281
+ // along the ring
282
+ const speed = rate * roller.ring;
283
+ const way_x = -out_z;
284
+ const way_z = out_x;
285
+
286
+ // it rolls about the axis across its way, a turn for every circumference of ground
287
+ roll_axis.set(way_z, 0, -way_x);
288
+ roll.fromAxisAngle(roll_axis, speed * time / roller.radius);
289
+
290
+ roller_transform.setTranslation(roller.centre[0] + roller.ring * out_x, roller.radius - roller.sunk, roller.centre[2] + roller.ring * out_z);
291
+ roller_transform.setRotation(roll.x, roll.y, roll.z, roll.w);
292
+ roller_transform.updateMatrix();
293
+
294
+ roller_body.linearVelocity[0] = speed * way_x;
295
+ roller_body.linearVelocity[2] = speed * way_z;
296
+
297
+ roller_body.angularVelocity[0] = roll_axis.x * speed / roller.radius;
298
+ roller_body.angularVelocity[2] = roll_axis.z * speed / roller.radius;
299
+
300
+ t64_announce_change(dataset, world.field.roller);
301
+ };
302
+
303
+ world.field.roll(0);
304
+
305
+ // ---- the platform ----
306
+
307
+ const platform = LAYOUT.platform;
308
+
309
+ const platform_transform = new Transform64();
310
+
311
+ world.platform.surface = new Entity()
312
+ .add(platform_transform)
313
+ .add(new GrassSurface())
314
+ .build(dataset);
315
+
316
+ const platform_cover = grows => GroundCover.from({ surface: world.platform.surface, species: grows ? species : null });
317
+
318
+ /** @type {{entity: number, transform: Transform64, local: number[], flat: boolean}[]} */
319
+ const riders = [];
320
+
321
+ const ride = (name, box, component, grows, flat) => {
322
+ const transform = new Transform64();
323
+
324
+ const entity = new Entity()
325
+ .add(transform)
326
+ .add(component)
327
+ .add(platform_cover(grows))
328
+ .build(dataset);
329
+
330
+ world.platform[name] = entity;
331
+
332
+ riders.push({ entity, transform, local: centre_of(box), flat });
333
+ };
334
+
335
+ ride("sheet_a", platform.sheet_a, sheet(platform.sheet_a), true, true);
336
+ ride("sheet_b", platform.sheet_b, sheet(platform.sheet_b), true, true);
337
+ ride("crate", platform.crate, block(platform.crate, wood), false, false);
338
+
339
+ const turn = new Quaternion();
340
+ const rider_rotation = new Quaternion();
341
+ const offset = new Vector3();
342
+
343
+ /**
344
+ * Put the platform, and everything that rides it, where it is at a time.
345
+ *
346
+ * @param {number} time seconds
347
+ */
348
+ world.platform.pose = time => {
349
+ const angle = 2 * Math.PI * time / platform.period;
350
+
351
+ const x = platform.centre[0] + platform.radius * Math.cos(angle);
352
+ const y = platform.centre[1] + Math.sin(angle * 3);
353
+ const z = platform.centre[2] + platform.radius * Math.sin(angle);
354
+
355
+ // it turns as it goes, twice a lap
356
+ turn.fromAxisAngle(Vector3.up, angle * 2);
357
+
358
+ platform_transform.setTranslation(x, y, z);
359
+ platform_transform.setRotation(turn.x, turn.y, turn.z, turn.w);
360
+ platform_transform.updateMatrix();
361
+
362
+ t64_announce_change(dataset, world.platform.surface);
363
+
364
+ for (const rider of riders) {
365
+ offset.set(rider.local[0], rider.local[1], rider.local[2]);
366
+ offset.applyQuaternion(turn);
367
+
368
+ if (rider.flat) {
369
+ rider_rotation.multiplyQuaternions(turn, FLAT);
370
+ } else {
371
+ rider_rotation.copy(turn);
372
+ }
373
+
374
+ rider.transform.setTranslation(x + offset.x, y + offset.y, z + offset.z);
375
+ rider.transform.setRotation(rider_rotation.x, rider_rotation.y, rider_rotation.z, rider_rotation.w);
376
+ rider.transform.updateMatrix();
377
+
378
+ t64_announce_change(dataset, rider.entity);
379
+ }
380
+ };
381
+
382
+ world.platform.pose(0);
383
+
384
+ // ---- the wind ----
385
+
386
+ const weather = new GlobalFluidEffector();
387
+
388
+ weather.wind = [4, 0, 1.5];
389
+ weather.drag = 0.5;
390
+ weather.gust = 1.5;
391
+ weather.gust_period = 4;
392
+
393
+ const effectors = new FluidEffectorsComponent();
394
+
395
+ effectors.addEffector(weather);
396
+
397
+ world.weather = weather;
398
+
399
+ new Entity()
400
+ .add(effectors)
401
+ .build(dataset);
402
+
403
+ // the air about the field: half-metre cells for 16 m each way and 8 m up and down, and two coarser shells
404
+ const air = new GPUFluidComponent();
405
+
406
+ air.resolution = [64, 32, 64];
407
+ air.cell_size = 0.5;
408
+ air.cascade_count = 3;
409
+
410
+ world.air = new Entity()
411
+ .add(placed([0, 4, 0]))
412
+ .add(air)
413
+ .build(dataset);
414
+
415
+ // ---- light ----
416
+
417
+ const sun = new Light();
418
+
419
+ sun.type.set(LightType.DIRECTION);
420
+ sun.color.setRGB(1, 0.97, 0.92);
421
+ sun.intensity.set(2.5);
422
+ sun.castShadow.set(true);
423
+
424
+ const rotation = new Quaternion();
425
+
426
+ rotation.fromUnitVectors(Vector3.forward, new Vector3(-0.4, -1, -0.6).normalize());
427
+ rotation.normalize();
428
+
429
+ new Entity()
430
+ .add(placed([0, 20, 0], rotation))
431
+ .add(sun)
432
+ .build(dataset);
433
+
434
+ // the rows the device knows the pieces by
435
+ world.rows = {};
436
+
437
+ for (const group of ["field", "platform"]) {
438
+ world.rows[group] = {};
439
+
440
+ for (const [name, entity] of Object.entries(world[group])) {
441
+ if (typeof entity === "number") {
442
+ world.rows[group][name] = row_of_entity(entity);
443
+ }
444
+ }
445
+ }
446
+
447
+ return world;
448
+ }
449
+
450
+ function show_message(text) {
451
+ const message = element("message");
452
+
453
+ message.textContent = text;
454
+ message.style.display = "grid";
455
+ }
456
+
457
+ async function main() {
458
+ await MeshoptClusterizer.ready;
459
+
460
+ const graphics = new GraphicsEngine();
461
+ const scene = new Scene();
462
+
463
+ element("viewport").appendChild(graphics.viewport.el);
464
+
465
+ const [width, height] = view_size();
466
+
467
+ graphics.viewport.size.set(width, height);
468
+
469
+ const dataset = new EntityComponentDataset();
470
+ const entities = new EntityManager();
471
+
472
+ const grass = new GrassSurfaceSystem(graphics, scene);
473
+
474
+ entities.addSystem(new ShadedGeometrySystem(graphics, scene));
475
+ entities.addSystem(new LightSystem(graphics, scene));
476
+ entities.addSystem(new FluidEffectorsSystem());
477
+ entities.addSystem(new GPUFluidSystem(graphics, scene));
478
+ entities.addSystem(grass);
479
+ entities.addSystem(new GroundCoverSystem());
480
+ entities.attachDataset(dataset);
481
+
482
+ await new Promise((resolve, reject) => entities.startup(resolve, reject));
483
+
484
+ const world = build_world(dataset);
485
+
486
+ const camera = graphics.camera.camera;
487
+
488
+ camera.near = 0.05;
489
+ camera.far = 500;
490
+ camera.fov = CAMERA.fov_degrees * DEG_TO_RAD;
491
+
492
+ const controller = new OrbitalCameraController(camera, document.body);
493
+
494
+ controller.look(CAMERA.position, CAMERA.target);
495
+
496
+ document.body.focus();
497
+
498
+ Object.assign(globalThis, { graphics, scene, dataset, entities, grass, world, camera, controller, LAYOUT, weather: world.weather });
499
+
500
+ graphics.on.contextFailed.add(failure => show_message("There will be no rendering.\n\n" + failure.message));
501
+
502
+ try {
503
+ await graphics.start();
504
+ } catch (e) {
505
+ console.error(e);
506
+
507
+ return;
508
+ }
509
+
510
+ const renderer = graphics.renderer;
511
+
512
+ renderer.feature_automatic_exposure_enabled = false;
513
+ renderer.exposure_compensation = 0;
514
+
515
+ globalThis.renderer = renderer;
516
+
517
+ renderer.graphics.device.lost?.then(info => show_message("The GPU device was lost.\n\n" + (info?.message ?? "")));
518
+
519
+ /**
520
+ * The surfaces' pool, read off the device.
521
+ *
522
+ * @param {boolean} [with_surfels]
523
+ */
524
+ globalThis.read_grass = (with_surfels = false) => read_grass_surfaces(renderer.graphics.device, grass.surfaces, with_surfels);
525
+
526
+ let frames = 0;
527
+ let time = 0;
528
+
529
+ // `__platform_still` holds the platform where it is, `__roller_still` the roller
530
+ globalThis.__platform_still = false;
531
+ globalThis.__roller_still = false;
532
+
533
+ let roller_time = 0;
534
+
535
+ /**
536
+ * One frame: the platform, the camera, every system's update, the render.
537
+ *
538
+ * @param {number} time_delta seconds
539
+ */
540
+ function step(time_delta) {
541
+ const [w, h] = view_size();
542
+
543
+ if (w !== graphics.viewport.size.x || h !== graphics.viewport.size.y) {
544
+ graphics.viewport.size.set(w, h);
545
+ }
546
+
547
+ if (!globalThis.__platform_still) {
548
+ time += Math.min(time_delta, 0.05);
549
+
550
+ world.platform.pose(time);
551
+ }
552
+
553
+ if (!globalThis.__roller_still) {
554
+ roller_time += Math.min(time_delta, 0.05);
555
+
556
+ world.field.roll(roller_time);
557
+ }
558
+
559
+ controller.update();
560
+
561
+ entities.update(Math.min(time_delta, 0.05));
562
+
563
+ graphics.render(time_delta);
564
+
565
+ frames++;
566
+
567
+ globalThis.__frames = frames;
568
+ globalThis.__time = time;
569
+ }
570
+
571
+ // `__paused` hands the frames to whoever drives `step`, such as a timing probe
572
+ globalThis.step = step;
573
+ globalThis.__paused = false;
574
+
575
+ const status = element("status");
576
+
577
+ create_frame_loop(time_delta => {
578
+ if (!globalThis.__paused) {
579
+ step(time_delta);
580
+ }
581
+
582
+ if (frames % 30 === 0 && grass.surfaces !== null) {
583
+ status.textContent = `surfaces ${grass.surfaces.surface_count} slots ${grass.surfaces.slot_capacity}`;
584
+ }
585
+ });
586
+
587
+ globalThis.bench_ready = true;
588
+ }
589
+
590
+ main().catch(e => {
591
+ console.error(e);
592
+ show_message(String(e?.stack ?? e));
593
+ });
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Read the grass surfaces' pool off the device: its counters, every slot that is not free, and on request
3
+ * the surfels the slots hold. A playground's inspection tool; nothing in a frame calls it.
4
+ *
5
+ * @param {GPUDevice} device
6
+ * @param {import("../../renderer/grass/surface/GPUGrassSurfaces.js").GPUGrassSurfaces} surfaces
7
+ * @param {boolean} [with_surfels] also read the atlas, and give every slot its `surfels`
8
+ * @returns {Promise<{capacity: number, free_count: number, starved: number, baked: number, removed: number, listed: number, slots: (GrassSlotReading & {surfels?: GrassSurfelReading[]})[]}>}
9
+ * `removed` is the records taken out of the directory since the pool was made, `listed` the records it holds
10
+ */
11
+ export function read_grass_surfaces(device: GPUDevice, surfaces: import("../../renderer/grass/surface/GPUGrassSurfaces.js").GPUGrassSurfaces, with_surfels?: boolean): Promise<{
12
+ capacity: number;
13
+ free_count: number;
14
+ starved: number;
15
+ baked: number;
16
+ removed: number;
17
+ listed: number;
18
+ slots: (GrassSlotReading & {
19
+ surfels?: GrassSurfelReading[];
20
+ })[];
21
+ }>;
22
+ export type GrassSlotReading = {
23
+ slot: number;
24
+ /**
25
+ * the surface's `transforms` row
26
+ */
27
+ surface: number;
28
+ level: number;
29
+ layer: number;
30
+ /**
31
+ * `[x, z]`, in tiles of the level
32
+ */
33
+ tile: number[];
34
+ /**
35
+ * `GRASS_SLOT_STATE_*`
36
+ */
37
+ state: number;
38
+ wanted_frame: number;
39
+ layer_count: number;
40
+ surfel_count: number;
41
+ };
42
+ export type GrassSurfelReading = {
43
+ /**
44
+ * column along the tile's x, `[0, GRASS_TILE_COLUMNS)`
45
+ */
46
+ x: number;
47
+ /**
48
+ * column along the tile's z
49
+ */
50
+ z: number;
51
+ /**
52
+ * along the frame's up axis
53
+ */
54
+ height: number;
55
+ /**
56
+ * the member's `meshes` row
57
+ */
58
+ member: number;
59
+ clear_height: number;
60
+ density: number;
61
+ };
62
+ //# sourceMappingURL=read_grass_surfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read_grass_surfaces.d.ts","sourceRoot":"","sources":["../../../../../src/shade/playground/grass_surfaces/read_grass_surfaces.js"],"names":[],"mappings":"AAqEA;;;;;;;;;GASG;AACH,iEALW,OAAO,kDAAkD,EAAE,gBAAgB,iBAC3E,OAAO,GACL,QAAQ;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,CAAC,gBAAgB,GAAG;QAAC,OAAO,CAAC,EAAE,kBAAkB,EAAE,CAAA;KAAC,CAAC,EAAE,CAAA;CAAC,CAAC,CA+G5L;;UAtKa,MAAM;;;;aACN,MAAM;WACN,MAAM;WACN,MAAM;;;;UACN,MAAM,EAAE;;;;WACR,MAAM;kBACN,MAAM;iBACN,MAAM;kBACN,MAAM;;;;;;OAKN,MAAM;;;;OACN,MAAM;;;;YACN,MAAM;;;;YACN,MAAM;kBACN,MAAM;aACN,MAAM"}