@woosh/meep-engine 3.75.0 → 3.76.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 (216) hide show
  1. package/package.json +1 -1
  2. package/src/engine/asset/GameAssetType.d.ts +1 -0
  3. package/src/engine/asset/GameAssetType.js +5 -1
  4. package/src/engine/asset/loaders/GroomAssetLoader.d.ts +33 -0
  5. package/src/engine/asset/loaders/GroomAssetLoader.d.ts.map +1 -0
  6. package/src/engine/asset/loaders/GroomAssetLoader.js +99 -0
  7. package/src/engine/graphics/ecs/hair/Hair.d.ts +47 -0
  8. package/src/engine/graphics/ecs/hair/Hair.d.ts.map +1 -0
  9. package/src/engine/graphics/ecs/hair/Hair.js +61 -0
  10. package/src/engine/graphics/hair/Groom.d.ts +130 -0
  11. package/src/engine/graphics/hair/Groom.d.ts.map +1 -0
  12. package/src/engine/graphics/hair/Groom.js +193 -0
  13. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts +24 -0
  14. package/src/engine/graphics/hair/GroomSerializationAdapter.d.ts.map +1 -0
  15. package/src/engine/graphics/hair/GroomSerializationAdapter.js +77 -0
  16. package/src/engine/graphics/hair/groom_build_group.d.ts +85 -0
  17. package/src/engine/graphics/hair/groom_build_group.d.ts.map +1 -0
  18. package/src/engine/graphics/hair/groom_build_group.js +487 -0
  19. package/src/engine/graphics/hair/groom_generate_scalp.d.ts +29 -0
  20. package/src/engine/graphics/hair/groom_generate_scalp.d.ts.map +1 -0
  21. package/src/engine/graphics/hair/groom_generate_scalp.js +184 -0
  22. package/src/engine/graphics/hair/groom_rank_order.d.ts +15 -0
  23. package/src/engine/graphics/hair/groom_rank_order.d.ts.map +1 -0
  24. package/src/engine/graphics/hair/groom_rank_order.js +53 -0
  25. package/src/engine/graphics/hair/groom_root_spacing.d.ts +12 -0
  26. package/src/engine/graphics/hair/groom_root_spacing.d.ts.map +1 -0
  27. package/src/engine/graphics/hair/groom_root_spacing.js +120 -0
  28. package/src/engine/graphics3/HairSystem.d.ts +102 -0
  29. package/src/engine/graphics3/HairSystem.d.ts.map +1 -0
  30. package/src/engine/graphics3/HairSystem.js +456 -0
  31. package/src/engine/physics/fluid/ecs/FluidObstacleSystem.d.ts +4 -4
  32. package/src/shade/assets/textures/hair_scattering.bin +0 -0
  33. package/src/shade/device/pipeline/PipelineEnquiry.d.ts +11 -0
  34. package/src/shade/device/pipeline/PipelineEnquiry.d.ts.map +1 -1
  35. package/src/shade/device/pipeline/PipelineEnquiry.js +13 -0
  36. package/src/shade/playground/hair/index.html +50 -0
  37. package/src/shade/playground/hair/main.d.ts +2 -0
  38. package/src/shade/playground/hair/main.d.ts.map +1 -0
  39. package/src/shade/playground/hair/main.js +274 -0
  40. package/src/shade/playground/screen_probes/README.md +54 -0
  41. package/src/shade/playground/screen_probes/index.html +271 -0
  42. package/src/shade/playground/screen_probes/main.d.ts +8 -0
  43. package/src/shade/playground/screen_probes/main.d.ts.map +1 -0
  44. package/src/shade/playground/screen_probes/main.js +527 -0
  45. package/src/shade/renderer/Renderer.d.ts.map +1 -1
  46. package/src/shade/renderer/Renderer.js +54 -8
  47. package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.d.ts +6 -0
  48. package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.d.ts.map +1 -1
  49. package/src/shade/renderer/STATIC_GRAPHICS_ENGINE_ASSETS.js +10 -0
  50. package/src/shade/renderer/acoustics/GPUAcousticLattice.d.ts +1 -1
  51. package/src/shade/renderer/acoustics/GPUAcousticProbes.d.ts +1 -1
  52. package/src/shade/renderer/acoustics/GPUAcoustics.d.ts +1 -1
  53. package/src/shade/renderer/deferred/chunk_read_gBuffer_material.d.ts.map +1 -1
  54. package/src/shade/renderer/deferred/chunk_read_gBuffer_material.js +3 -1
  55. package/src/shade/renderer/deferred/chunk_shade_direct_lights.d.ts +23 -0
  56. package/src/shade/renderer/deferred/chunk_shade_direct_lights.d.ts.map +1 -0
  57. package/src/shade/renderer/deferred/chunk_shade_direct_lights.js +111 -0
  58. package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts +17 -6
  59. package/src/shade/renderer/deferred/chunk_shade_directional_lights.d.ts.map +1 -1
  60. package/src/shade/renderer/deferred/chunk_shade_directional_lights.js +26 -21
  61. package/src/shade/renderer/deferred/chunk_shade_standard_material_direct.d.ts +12 -22
  62. package/src/shade/renderer/deferred/chunk_shade_standard_material_direct.d.ts.map +1 -1
  63. package/src/shade/renderer/deferred/chunk_shade_standard_material_direct.js +20 -100
  64. package/src/shade/renderer/deferred/chunk_shade_standard_material_direct_restir.d.ts.map +1 -1
  65. package/src/shade/renderer/deferred/chunk_shade_standard_material_direct_restir.js +6 -4
  66. package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.d.ts +15 -0
  67. package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.d.ts.map +1 -0
  68. package/src/shade/renderer/deferred/chunk_standard_material_direct_light_lobe.js +47 -0
  69. package/src/shade/renderer/extension/ViewLighting.d.ts +101 -0
  70. package/src/shade/renderer/extension/ViewLighting.d.ts.map +1 -0
  71. package/src/shade/renderer/extension/ViewLighting.js +168 -0
  72. package/src/shade/renderer/fluid/GPUFluidCascade.d.ts +3 -3
  73. package/src/shade/renderer/fluid/GPUFluidCascadeStack.d.ts +1 -1
  74. package/src/shade/renderer/fluid/forcing/GPUFluidForcing.d.ts +7 -7
  75. package/src/shade/renderer/fluid/pressure/GPUFluidPressureSolve.d.ts +1 -1
  76. package/src/shade/renderer/fluid/query/GPUFluidQueries.d.ts +1 -1
  77. package/src/shade/renderer/global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.d.ts.map +1 -1
  78. package/src/shade/renderer/global_illumination/brick4/gpu/draw/shader_brick4_indirect_lighting.js +3 -1
  79. package/src/shade/renderer/global_illumination/probe_clipmap/GPUProbeClipmapGI.d.ts +1 -1
  80. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_indirect_lighting.d.ts.map +1 -1
  81. package/src/shade/renderer/global_illumination/probe_clipmap/probe/shader_probe_clipmap_indirect_lighting.js +3 -1
  82. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts +15 -7
  83. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.d.ts.map +1 -1
  84. package/src/shade/renderer/global_illumination/screen_probe/GPUScreenProbeGI.js +40 -9
  85. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts +23 -0
  86. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.d.ts.map +1 -1
  87. package/src/shade/renderer/global_illumination/screen_probe/SCREEN_PROBE.js +26 -0
  88. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.d.ts +1 -0
  89. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeDebugView.js +6 -0
  90. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts +13 -1
  91. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.d.ts.map +1 -1
  92. package/src/shade/renderer/global_illumination/screen_probe/ScreenProbeSettings.js +23 -1
  93. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.d.ts.map +1 -1
  94. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe.js +2 -0
  95. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.d.ts +29 -0
  96. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.d.ts.map +1 -0
  97. package/src/shade/renderer/global_illumination/screen_probe/chunk_screen_probe_rough_specular.js +102 -0
  98. package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.d.ts +8 -1
  99. package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.d.ts.map +1 -1
  100. package/src/shade/renderer/global_illumination/screen_probe/graph_screen_probe_debug_view.js +27 -1
  101. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts +4 -1
  102. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.d.ts.map +1 -1
  103. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_gather.js +4 -1
  104. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.d.ts +11 -5
  105. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.d.ts.map +1 -1
  106. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_indirect_lighting.js +28 -10
  107. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts +36 -2
  108. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.d.ts.map +1 -1
  109. package/src/shade/renderer/global_illumination/screen_probe/shader_screen_probe_resolve.js +149 -4
  110. package/src/shade/renderer/global_illumination/shader_resolve_indirect_lighting.d.ts.map +1 -1
  111. package/src/shade/renderer/global_illumination/shader_resolve_indirect_lighting.js +3 -1
  112. package/src/shade/renderer/hair/GPUHairSystem.d.ts +159 -0
  113. package/src/shade/renderer/hair/GPUHairSystem.d.ts.map +1 -0
  114. package/src/shade/renderer/hair/GPUHairSystem.js +1132 -0
  115. package/src/shade/renderer/hair/HAIR.d.ts +102 -0
  116. package/src/shade/renderer/hair/HAIR.d.ts.map +1 -0
  117. package/src/shade/renderer/hair/HAIR.js +115 -0
  118. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts +17 -0
  119. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.d.ts.map +1 -0
  120. package/src/shade/renderer/hair/HAIR_DATABASE_SPEC.js +71 -0
  121. package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts +11 -0
  122. package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.d.ts.map +1 -0
  123. package/src/shade/renderer/hair/HAIR_FRAME_STRUCTS.js +48 -0
  124. package/src/shade/renderer/hair/HairFrame.d.ts +41 -0
  125. package/src/shade/renderer/hair/HairFrame.d.ts.map +1 -0
  126. package/src/shade/renderer/hair/HairFrame.js +76 -0
  127. package/src/shade/renderer/hair/chunk_hair_bsdf.d.ts +42 -0
  128. package/src/shade/renderer/hair/chunk_hair_bsdf.d.ts.map +1 -0
  129. package/src/shade/renderer/hair/chunk_hair_bsdf.js +170 -0
  130. package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts +30 -0
  131. package/src/shade/renderer/hair/chunk_hair_dual_scattering.d.ts.map +1 -0
  132. package/src/shade/renderer/hair/chunk_hair_dual_scattering.js +131 -0
  133. package/src/shade/renderer/hair/chunk_hair_pixel.d.ts +32 -0
  134. package/src/shade/renderer/hair/chunk_hair_pixel.d.ts.map +1 -0
  135. package/src/shade/renderer/hair/chunk_hair_pixel.js +116 -0
  136. package/src/shade/renderer/hair/chunk_hair_strand.d.ts +40 -0
  137. package/src/shade/renderer/hair/chunk_hair_strand.d.ts.map +1 -0
  138. package/src/shade/renderer/hair/chunk_hair_strand.js +85 -0
  139. package/src/shade/renderer/hair/chunk_hair_volume.d.ts +31 -0
  140. package/src/shade/renderer/hair/chunk_hair_volume.d.ts.map +1 -0
  141. package/src/shade/renderer/hair/chunk_hair_volume.js +106 -0
  142. package/src/shade/renderer/hair/hair_id_draw.d.ts +24 -0
  143. package/src/shade/renderer/hair/hair_id_draw.d.ts.map +1 -0
  144. package/src/shade/renderer/hair/hair_id_draw.js +135 -0
  145. package/src/shade/renderer/hair/hair_lighting.d.ts +53 -0
  146. package/src/shade/renderer/hair/hair_lighting.d.ts.map +1 -0
  147. package/src/shade/renderer/hair/hair_lighting.js +270 -0
  148. package/src/shade/renderer/hair/hair_scattering_lut.d.ts +75 -0
  149. package/src/shade/renderer/hair/hair_scattering_lut.d.ts.map +1 -0
  150. package/src/shade/renderer/hair/hair_scattering_lut.js +271 -0
  151. package/src/shade/renderer/hair/hair_stamp.d.ts +33 -0
  152. package/src/shade/renderer/hair/hair_stamp.d.ts.map +1 -0
  153. package/src/shade/renderer/hair/hair_stamp.js +175 -0
  154. package/src/shade/renderer/hair/shader_hair_classes.d.ts +21 -0
  155. package/src/shade/renderer/hair/shader_hair_classes.d.ts.map +1 -0
  156. package/src/shade/renderer/hair/shader_hair_classes.js +86 -0
  157. package/src/shade/renderer/hair/shader_hair_cull.d.ts +31 -0
  158. package/src/shade/renderer/hair/shader_hair_cull.d.ts.map +1 -0
  159. package/src/shade/renderer/hair/shader_hair_cull.js +194 -0
  160. package/src/shade/renderer/hair/shader_hair_lod.d.ts +33 -0
  161. package/src/shade/renderer/hair/shader_hair_lod.d.ts.map +1 -0
  162. package/src/shade/renderer/hair/shader_hair_lod.js +268 -0
  163. package/src/shade/renderer/hair/shader_hair_volume.d.ts +28 -0
  164. package/src/shade/renderer/hair/shader_hair_volume.d.ts.map +1 -0
  165. package/src/shade/renderer/hair/shader_hair_volume.js +167 -0
  166. package/src/shade/renderer/loader/gltf/tiny-gltf.d.ts +1 -1
  167. package/src/shade/renderer/loader/usd/usd_build_scene.d.ts +31 -0
  168. package/src/shade/renderer/loader/usd/usd_build_scene.d.ts.map +1 -1
  169. package/src/shade/renderer/loader/usd/usd_build_scene.js +36 -21
  170. package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts +60 -0
  171. package/src/shade/renderer/loader/usd/usd_groom_extension.d.ts.map +1 -0
  172. package/src/shade/renderer/loader/usd/usd_groom_extension.js +417 -0
  173. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.d.ts.map +1 -1
  174. package/src/shade/renderer/path_tracer/shader/chunk_sample_material_data.js +4 -1
  175. package/src/shade/renderer/path_tracer/shader/chunk_shading_closure_from_material_data.d.ts.map +1 -1
  176. package/src/shade/renderer/path_tracer/shader/chunk_shading_closure_from_material_data.js +3 -1
  177. package/src/shade/renderer/postprocess/nss/NSS.d.ts +1 -1
  178. package/src/shade/renderer/postprocess/ssr/SSR.d.ts +4 -1
  179. package/src/shade/renderer/postprocess/ssr/SSR.d.ts.map +1 -1
  180. package/src/shade/renderer/postprocess/ssr/SSR.js +9 -0
  181. package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.d.ts +16 -1
  182. package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.d.ts.map +1 -1
  183. package/src/shade/renderer/postprocess/ssr/resolve/chunk_ssr_sample_radiance.js +47 -3
  184. package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader.d.ts.map +1 -1
  185. package/src/shade/renderer/postprocess/ssr/resolve/ssr_resolve_shader.js +5 -3
  186. package/src/shade/renderer/postprocess/ssr/ssr_combine_shader.d.ts.map +1 -1
  187. package/src/shade/renderer/postprocess/ssr/ssr_combine_shader.js +6 -5
  188. package/src/shade/renderer/rasterize/forward/chunk_forward_shade_standard_fragment.d.ts.map +1 -1
  189. package/src/shade/renderer/rasterize/forward/chunk_forward_shade_standard_fragment.js +5 -2
  190. package/src/shade/renderer/rasterize/native/avboit/avboit_draw_fragment_body.d.ts.map +1 -1
  191. package/src/shade/renderer/rasterize/native/avboit/avboit_draw_fragment_body.js +5 -0
  192. package/src/shade/renderer/rasterize/native/avboit/shader_avboit_splat.d.ts.map +1 -1
  193. package/src/shade/renderer/rasterize/native/avboit/shader_avboit_splat.js +4 -1
  194. package/src/shade/renderer/rasterize/native/oit/oit_resolve_fragment_body.d.ts.map +1 -1
  195. package/src/shade/renderer/rasterize/native/oit/oit_resolve_fragment_body.js +5 -1
  196. package/src/shade/renderer/rasterize/native/oit/shader_oit_generate_moments.d.ts.map +1 -1
  197. package/src/shade/renderer/rasterize/native/oit/shader_oit_generate_moments.js +7 -4
  198. package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.d.ts +13 -8
  199. package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.d.ts.map +1 -1
  200. package/src/shade/renderer/shader/chunk/brdf/chunk_shadowed_F90.js +18 -14
  201. package/src/shade/renderer/shader/chunk/light/chunk_compute_multiscattering_specular.d.ts +3 -2
  202. package/src/shade/renderer/shader/chunk/light/chunk_compute_multiscattering_specular.d.ts.map +1 -1
  203. package/src/shade/renderer/shader/chunk/light/chunk_compute_multiscattering_specular.js +12 -4
  204. package/src/shade/renderer/shader/chunk/material/MATERIAL_SHADING_INFO_STRUCT.d.ts.map +1 -1
  205. package/src/shade/renderer/shader/chunk/material/MATERIAL_SHADING_INFO_STRUCT.js +1 -0
  206. package/src/shade/renderer/shader/chunk/material/chunk_compute_indirect_specular.js +1 -1
  207. package/src/shade/renderer/shader/chunk/material/chunk_metalness_to_specular_F90.d.ts +16 -0
  208. package/src/shade/renderer/shader/chunk/material/chunk_metalness_to_specular_F90.d.ts.map +1 -0
  209. package/src/shade/renderer/shader/chunk/material/chunk_metalness_to_specular_F90.js +25 -0
  210. package/src/shade/renderer/shader/chunk/material/chunk_re_direct_multiscatter.js +2 -2
  211. package/src/shade/renderer/shader/compiler/ShaderSwitch.d.ts +1 -1
  212. package/src/shade/renderer/shader/compiler/ShaderSwitchSet.d.ts +1 -1
  213. package/src/shade/renderer/shader/resource/ShaderResourceDescriptor.d.ts +1 -1
  214. package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_sample_point2.d.ts +2 -2
  215. package/src/shade/renderer/shadow/map/shader/chunk_shadowmap_sample_point2.js +2 -2
  216. package/src/shade/renderer/water/query/GPUWaterQueries.d.ts +1 -1
@@ -0,0 +1,184 @@
1
+ import { assert } from "../../../core/assert.js";
2
+ import { seededRandom_Mulberry32 } from "../../../core/math/random/seededRandom_Mulberry32.js";
3
+ import { Groom } from "./Groom.js";
4
+ import { groom_build_group } from "./groom_build_group.js";
5
+
6
+ /**
7
+ * The golden angle, radians: successive roots turn by it about the vertical.
8
+ * @type {number}
9
+ */
10
+ const GOLDEN_ANGLE = Math.PI * (3 - Math.sqrt(5));
11
+
12
+ /**
13
+ * A head of hair to test and measure with: strands rooted over the top of a sphere, each laid down the sphere
14
+ * from its root and falling under its own weight once past the side, with a gentle wave of its own.
15
+ *
16
+ * The sphere is centred on the origin. Deterministic in `seed`.
17
+ *
18
+ * @param {Object} [options]
19
+ * @param {number} [options.strand_count]
20
+ * @param {number} [options.point_count] points a strand, `2^k + 1`
21
+ * @param {number} [options.radius] of the sphere, metres
22
+ * @param {number} [options.length] of a strand, metres
23
+ * @param {number} [options.width] of a strand at its root, metres
24
+ * @param {number} [options.taper] how much of its width a strand loses over its last third, 0 to 1
25
+ * @param {number} [options.cap] how far down from the top roots grow, as the angle from the vertical, radians
26
+ * @param {number} [options.seed]
27
+ * @returns {Groom}
28
+ */
29
+ export function groom_generate_scalp({
30
+ strand_count = 10000,
31
+ point_count = 33,
32
+ radius = 0.09,
33
+ length = 0.25,
34
+ width = 70e-6,
35
+ taper = 0.8,
36
+ cap = 1.75,
37
+ seed = 1,
38
+ } = {}) {
39
+ assert.isPositiveInteger(strand_count, 'strand_count');
40
+ assert.greaterThan(radius, 0, 'radius');
41
+ assert.greaterThan(length, 0, 'length');
42
+
43
+ const random = seededRandom_Mulberry32(seed);
44
+
45
+ // points each curve is laid down with before it is resampled to point_count
46
+ const raw = 64;
47
+ const step = length / (raw - 1);
48
+
49
+ const positions = new Float64Array(strand_count * raw * 3);
50
+ const widths = new Float64Array(strand_count * raw);
51
+ const counts = new Uint32Array(strand_count).fill(raw);
52
+ const variation = new Uint8Array(strand_count);
53
+
54
+ const cos_cap = Math.cos(cap);
55
+
56
+ for (let c = 0; c < strand_count; c++) {
57
+ // equal areas of the cap a root, stratified down it and turned by the golden angle round it
58
+ const u = (c + random()) / strand_count;
59
+ const cos_theta = 1 - u * (1 - cos_cap);
60
+ const sin_theta = Math.sqrt(Math.max(0, 1 - cos_theta * cos_theta));
61
+ const phi = c * GOLDEN_ANGLE + (random() - 0.5) * 0.2;
62
+
63
+ const nx = sin_theta * Math.cos(phi);
64
+ const ny = cos_theta;
65
+ const nz = sin_theta * Math.sin(phi);
66
+
67
+ // down the sphere from the root; straight out from the crown at the very top
68
+ let tx = -ny * nx;
69
+ let ty = 1 - ny * ny;
70
+ let tz = -ny * nz;
71
+
72
+ tx = -tx;
73
+ ty = -ty;
74
+ tz = -tz;
75
+
76
+ let t_length = Math.hypot(tx, ty, tz);
77
+
78
+ if (t_length < 1e-4) {
79
+ tx = Math.cos(phi);
80
+ ty = 0;
81
+ tz = Math.sin(phi);
82
+ t_length = 1;
83
+ }
84
+
85
+ tx /= t_length;
86
+ ty /= t_length;
87
+ tz /= t_length;
88
+
89
+ // leaves the scalp a little lifted from it
90
+ let dx = tx + nx * 0.35;
91
+ let dy = ty + ny * 0.35;
92
+ let dz = tz + nz * 0.35;
93
+
94
+ const d_length = Math.hypot(dx, dy, dz);
95
+
96
+ dx /= d_length;
97
+ dy /= d_length;
98
+ dz /= d_length;
99
+
100
+ // a layer of its own over the scalp, and a wave of its own across its way
101
+ const lift = 0.002 + random() * 0.006;
102
+ const wave_amplitude = 0.15 + random() * 0.25;
103
+ const wave_frequency = 30 + random() * 30;
104
+ const wave_phase = random() * Math.PI * 2;
105
+
106
+ let px = nx * radius;
107
+ let py = ny * radius;
108
+ let pz = nz * radius;
109
+
110
+ for (let i = 0; i < raw; i++) {
111
+ const at = c * raw + i;
112
+
113
+ positions[at * 3] = px;
114
+ positions[at * 3 + 1] = py;
115
+ positions[at * 3 + 2] = pz;
116
+
117
+ const t = i / (raw - 1);
118
+
119
+ widths[at] = width * (t < 2 / 3 ? 1 : 1 - (t - 2 / 3) * 3 * taper);
120
+
121
+ // the wave turns the way about the vertical, its weight pulls it down
122
+ const wave = wave_amplitude * Math.sin(i * step * wave_frequency + wave_phase);
123
+
124
+ let bx = -dz;
125
+ let bz = dx;
126
+ const b_length = Math.hypot(bx, bz);
127
+
128
+ if (b_length > 1e-6) {
129
+ bx /= b_length;
130
+ bz /= b_length;
131
+ }
132
+
133
+ dx += bx * wave * step * 20;
134
+ dz += bz * wave * step * 20;
135
+ dy -= 9 * step;
136
+
137
+ let length_d = Math.hypot(dx, dy, dz);
138
+
139
+ dx /= length_d;
140
+ dy /= length_d;
141
+ dz /= length_d;
142
+
143
+ px += dx * step;
144
+ py += dy * step;
145
+ pz += dz * step;
146
+
147
+ // never inside the head: pushed out to its layer, and its way turned along the surface
148
+ const r = Math.hypot(px, py, pz);
149
+ const floor = radius + lift * Math.min(1, t * 4 + 0.25);
150
+
151
+ if (r < floor) {
152
+ const ox = px / r;
153
+ const oy = py / r;
154
+ const oz = pz / r;
155
+
156
+ px = ox * floor;
157
+ py = oy * floor;
158
+ pz = oz * floor;
159
+
160
+ const inward = dx * ox + dy * oy + dz * oz;
161
+
162
+ if (inward < 0) {
163
+ dx -= ox * inward;
164
+ dy -= oy * inward;
165
+ dz -= oz * inward;
166
+
167
+ length_d = Math.hypot(dx, dy, dz);
168
+
169
+ dx /= length_d;
170
+ dy /= length_d;
171
+ dz /= length_d;
172
+ }
173
+ }
174
+ }
175
+
176
+ variation[c] = Math.max(0, Math.min(255, Math.round(128 + (random() - 0.5) * 96)));
177
+ }
178
+
179
+ const groom = new Groom();
180
+
181
+ groom.add(groom_build_group({ positions, counts, widths, variation }, { name: "scalp", point_count }));
182
+
183
+ return groom;
184
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The order to store strands in so that every prefix of them is spread evenly over the scalp.
3
+ *
4
+ * The roots are sorted along a Morton curve through `bounds`, and the strand at place `s` of that sort is given the
5
+ * rank `s` has in the bit-reversed order of `0 .. 2^b - 1`, `b` the bits `count` needs. Any first `2^j` ranks then
6
+ * fall one in each of `2^j` runs of equal length along the curve, and any first `n` within one of that: a stratified
7
+ * prefix, which follows where the roots are dense because the runs are runs of strands, not of space.
8
+ *
9
+ * @param {Float32Array|Float64Array|number[]} roots x, y, z a strand
10
+ * @param {number} count strands
11
+ * @param {ArrayLike<number>} bounds min x, y, z, then max x, y, z; holds every root
12
+ * @returns {Uint32Array} by rank, the strand's index in `roots`
13
+ */
14
+ export function groom_rank_order(roots: Float32Array | Float64Array | number[], count: number, bounds: ArrayLike<number>): Uint32Array;
15
+ //# sourceMappingURL=groom_rank_order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groom_rank_order.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/groom_rank_order.js"],"names":[],"mappings":"AAIA;;;;;;;;;;;;GAYG;AACH,wCALW,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,SAClC,MAAM,UACN,UAAU,MAAM,CAAC,GACf,WAAW,CAqCvB"}
@@ -0,0 +1,53 @@
1
+ import { assert } from "../../../core/assert.js";
2
+ import { reverse_bits_uint32 } from "../../../core/binary/reverse_bits_uint32.js";
3
+ import { v3_morton_encode_bounded } from "../../../core/geom/3d/morton/v3_morton_encode_bounded.js";
4
+
5
+ /**
6
+ * The order to store strands in so that every prefix of them is spread evenly over the scalp.
7
+ *
8
+ * The roots are sorted along a Morton curve through `bounds`, and the strand at place `s` of that sort is given the
9
+ * rank `s` has in the bit-reversed order of `0 .. 2^b - 1`, `b` the bits `count` needs. Any first `2^j` ranks then
10
+ * fall one in each of `2^j` runs of equal length along the curve, and any first `n` within one of that: a stratified
11
+ * prefix, which follows where the roots are dense because the runs are runs of strands, not of space.
12
+ *
13
+ * @param {Float32Array|Float64Array|number[]} roots x, y, z a strand
14
+ * @param {number} count strands
15
+ * @param {ArrayLike<number>} bounds min x, y, z, then max x, y, z; holds every root
16
+ * @returns {Uint32Array} by rank, the strand's index in `roots`
17
+ */
18
+ export function groom_rank_order(roots, count, bounds) {
19
+ assert.isNonNegativeInteger(count, 'count');
20
+ assert.greaterThanOrEqual(roots.length, count * 3, 'roots holds a point a strand');
21
+
22
+ const codes = new Uint32Array(count);
23
+ const by_curve = new Uint32Array(count);
24
+
25
+ for (let i = 0; i < count; i++) {
26
+ codes[i] = v3_morton_encode_bounded(roots[i * 3], roots[i * 3 + 1], roots[i * 3 + 2], bounds);
27
+ by_curve[i] = i;
28
+ }
29
+
30
+ // ties in the code are broken by index, so the order does not depend on the sort's stability
31
+ by_curve.sort((a, b) => (codes[a] - codes[b]) || (a - b));
32
+
33
+ const bits = count > 1 ? Math.ceil(Math.log2(count)) : 0;
34
+
35
+ // the place along the curve each rank takes, ranks in bit-reversed order of the places
36
+ const keys = new Uint32Array(count);
37
+ const places = new Uint32Array(count);
38
+
39
+ for (let s = 0; s < count; s++) {
40
+ keys[s] = bits === 0 ? 0 : reverse_bits_uint32(s) >>> (32 - bits);
41
+ places[s] = s;
42
+ }
43
+
44
+ places.sort((a, b) => keys[a] - keys[b]);
45
+
46
+ const order = new Uint32Array(count);
47
+
48
+ for (let rank = 0; rank < count; rank++) {
49
+ order[rank] = by_curve[places[rank]];
50
+ }
51
+
52
+ return order;
53
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * How far apart a group's strands grow: the median distance from a root to the nearest other root, metres, from the
3
+ * roots as quantized. Zero for a group of one strand.
4
+ *
5
+ * Found through a grid of cells about as wide as the roots would be apart spread evenly over the roots' box seen as
6
+ * a surface, each root against the 27 cells around its own; a root with no other within them takes none.
7
+ *
8
+ * @param {import("./Groom.js").GroomGroup} group
9
+ * @returns {number}
10
+ */
11
+ export function groom_root_spacing(group: import("./Groom.js").GroomGroup): number;
12
+ //# sourceMappingURL=groom_root_spacing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"groom_root_spacing.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/hair/groom_root_spacing.js"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,0CAHW,OAAO,YAAY,EAAE,UAAU,GAC7B,MAAM,CA+GlB"}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * How far apart a group's strands grow: the median distance from a root to the nearest other root, metres, from the
3
+ * roots as quantized. Zero for a group of one strand.
4
+ *
5
+ * Found through a grid of cells about as wide as the roots would be apart spread evenly over the roots' box seen as
6
+ * a surface, each root against the 27 cells around its own; a root with no other within them takes none.
7
+ *
8
+ * @param {import("./Groom.js").GroomGroup} group
9
+ * @returns {number}
10
+ */
11
+ export function groom_root_spacing(group) {
12
+ const n = group.strand_count;
13
+
14
+ if (n < 2) {
15
+ return 0;
16
+ }
17
+
18
+ const roots = new Float64Array(n * 3);
19
+
20
+ for (let s = 0; s < n; s++) {
21
+ group.read_point(roots, s * 3, s, 0);
22
+ }
23
+
24
+ let x0 = Infinity, y0 = Infinity, z0 = Infinity;
25
+ let x1 = -Infinity, y1 = -Infinity, z1 = -Infinity;
26
+
27
+ for (let s = 0; s < n; s++) {
28
+ const x = roots[s * 3], y = roots[s * 3 + 1], z = roots[s * 3 + 2];
29
+
30
+ x0 = Math.min(x0, x); y0 = Math.min(y0, y); z0 = Math.min(z0, z);
31
+ x1 = Math.max(x1, x); y1 = Math.max(y1, y); z1 = Math.max(z1, z);
32
+ }
33
+
34
+ const diagonal = Math.hypot(x1 - x0, y1 - y0, z1 - z0);
35
+
36
+ if (diagonal <= 0) {
37
+ return 0;
38
+ }
39
+
40
+ // roots lie on a surface: n of them over about the box's diagonal squared
41
+ const cell = diagonal / Math.sqrt(n);
42
+
43
+ const nx = Math.max(1, Math.ceil((x1 - x0) / cell));
44
+ const ny = Math.max(1, Math.ceil((y1 - y0) / cell));
45
+ const nz = Math.max(1, Math.ceil((z1 - z0) / cell));
46
+
47
+ const cell_of = s => {
48
+ const cx = Math.min(nx - 1, Math.floor((roots[s * 3] - x0) / cell));
49
+ const cy = Math.min(ny - 1, Math.floor((roots[s * 3 + 1] - y0) / cell));
50
+ const cz = Math.min(nz - 1, Math.floor((roots[s * 3 + 2] - z0) / cell));
51
+
52
+ return [cx, cy, cz];
53
+ };
54
+
55
+ const buckets = new Map();
56
+
57
+ for (let s = 0; s < n; s++) {
58
+ const [cx, cy, cz] = cell_of(s);
59
+ const key = (cz * ny + cy) * nx + cx;
60
+
61
+ let bucket = buckets.get(key);
62
+
63
+ if (bucket === undefined) {
64
+ bucket = [];
65
+ buckets.set(key, bucket);
66
+ }
67
+
68
+ bucket.push(s);
69
+ }
70
+
71
+ const nearest = [];
72
+
73
+ for (let s = 0; s < n; s++) {
74
+ const [cx, cy, cz] = cell_of(s);
75
+
76
+ let best = Infinity;
77
+
78
+ for (let dz = -1; dz <= 1; dz++) {
79
+ for (let dy = -1; dy <= 1; dy++) {
80
+ for (let dx = -1; dx <= 1; dx++) {
81
+ const x = cx + dx, y = cy + dy, z = cz + dz;
82
+
83
+ if (x < 0 || y < 0 || z < 0 || x >= nx || y >= ny || z >= nz) {
84
+ continue;
85
+ }
86
+
87
+ const bucket = buckets.get((z * ny + y) * nx + x);
88
+
89
+ if (bucket === undefined) {
90
+ continue;
91
+ }
92
+
93
+ for (const o of bucket) {
94
+ if (o === s) {
95
+ continue;
96
+ }
97
+
98
+ const d = Math.hypot(roots[o * 3] - roots[s * 3], roots[o * 3 + 1] - roots[s * 3 + 1], roots[o * 3 + 2] - roots[s * 3 + 2]);
99
+
100
+ if (d < best) {
101
+ best = d;
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+
108
+ if (best < Infinity) {
109
+ nearest.push(best);
110
+ }
111
+ }
112
+
113
+ if (nearest.length === 0) {
114
+ return 0;
115
+ }
116
+
117
+ nearest.sort((a, b) => a - b);
118
+
119
+ return nearest[nearest.length >> 1];
120
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Draws the hair into the G-buffer, after whatever else writes it at the phase: the decals composite before it, so
3
+ * none lands on a strand.
4
+ */
5
+ export class HairDrawExtension extends RenderExtension {
6
+ /**
7
+ * @param {HairSystem} system
8
+ */
9
+ constructor(system: HairSystem);
10
+ record(frame: any): void;
11
+ enquirePipelines(enquiry: any): void;
12
+ #private;
13
+ }
14
+ /**
15
+ * Lights the hair the frame drew, before the phase's other extensions take the lit frame as their input.
16
+ */
17
+ export class HairLightingExtension extends RenderExtension {
18
+ /**
19
+ * @param {HairSystem} system
20
+ */
21
+ constructor(system: HairSystem);
22
+ record(frame: any): void;
23
+ enquirePipelines(enquiry: any): void;
24
+ #private;
25
+ }
26
+ /**
27
+ * Draws every {@link Hair}: its groom's strands carried by the entity's `transforms` row, thinned and widened with
28
+ * distance so the hair's area on screen is kept, drawn into the G-buffer as ids and lit after the frame's lighting by
29
+ * a hair BSDF of its own. Nothing per strand happens on the CPU.
30
+ *
31
+ * **What is the CPU's:** registering an entity's hair with the scene context's {@link GPUHairSystem} — its groom
32
+ * uploaded once however many wear it, a row a group, the entity's transform row held through {@link EntityRowHold} —
33
+ * and comparing each component's fields once a tick with what was staged. A replaced groom registers the hair anew.
34
+ *
35
+ * **The strands follow announced transforms**, as meshes do: the GPU row is where the hair reads its entity's
36
+ * matrix, and a transform write reaches it when it is announced.
37
+ */
38
+ export class HairSystem extends System<any> {
39
+ /**
40
+ * @param {import("./GraphicsEngine.js").GraphicsEngine} graphics
41
+ * @param {import("../../shade/renderer/scene/Scene.js").Scene} scene the scene the hair's entities are in
42
+ */
43
+ constructor(graphics: import("./GraphicsEngine.js").GraphicsEngine, scene: import("../../shade/renderer/scene/Scene.js").Scene);
44
+ dependencies: (typeof Transform64 | typeof Hair)[];
45
+ /**
46
+ * The runtime the scene's hair is registered with, or null while there is no scene context.
47
+ *
48
+ * @returns {GPUHairSystem|null}
49
+ */
50
+ get runtime(): GPUHairSystem;
51
+ startup(entityManager: any): Promise<void>;
52
+ shutdown(entityManager: any): Promise<void>;
53
+ /**
54
+ * @param {Hair} hair
55
+ * @param {Transform64} transform
56
+ * @param {number} entity
57
+ */
58
+ link(hair: Hair, transform: Transform64, entity: number): void;
59
+ /**
60
+ * @param {Hair} hair
61
+ * @param {Transform64} transform
62
+ * @param {number} entity
63
+ */
64
+ unlink(hair: Hair, transform: Transform64, entity: number): void;
65
+ /**
66
+ * Register what is waiting, and restage every hair whose component changed.
67
+ */
68
+ update(): void;
69
+ /**
70
+ * Record the frame's hair into its G-buffer — called by the draw extension.
71
+ *
72
+ * @param {import("../../shade/renderer/extension/FrameContext.js").FrameContext} frame
73
+ */
74
+ record_draw(frame: import("../../shade/renderer/extension/FrameContext.js").FrameContext): void;
75
+ /**
76
+ * Record the light of the hair the frame drew — called by the lighting extension.
77
+ *
78
+ * @param {import("../../shade/renderer/extension/FrameContext.js").FrameContext} frame
79
+ */
80
+ record_light(frame: import("../../shade/renderer/extension/FrameContext.js").FrameContext): void;
81
+ #private;
82
+ }
83
+ export type HairEntry = {
84
+ entity: number;
85
+ hair: Hair;
86
+ /**
87
+ * the entity's row, kept current as it moves
88
+ */
89
+ hold: EntityRowHold;
90
+ /**
91
+ * the hair in the
92
+ * runtime, or null while it is not registered
93
+ */
94
+ context: import("../../shade/renderer/hair/GPUHairSystem.js").GPUHairContext | null;
95
+ };
96
+ import { RenderExtension } from "../../shade/renderer/extension/RenderExtension.js";
97
+ import { System } from "../ecs/System.js";
98
+ import { Transform64 } from "../ecs/transform/Transform64.js";
99
+ import { Hair } from "../graphics/ecs/hair/Hair.js";
100
+ import { GPUHairSystem } from "../../shade/renderer/hair/GPUHairSystem.js";
101
+ import { EntityRowHold } from "./EntityRowHold.js";
102
+ //# sourceMappingURL=HairSystem.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HairSystem.d.ts","sourceRoot":"","sources":["../../../../src/engine/graphics3/HairSystem.js"],"names":[],"mappings":"AAmCA;;;GAGG;AACH;IAUI;;OAEG;IACH,oBAFW,UAAU,EAMpB;IAED,yBAEC;IAED,qCAEC;;CACJ;AAED;;GAEG;AACH;IAUI;;OAEG;IACH,oBAFW,UAAU,EAMpB;IAED,yBAEC;IAED,qCAIC;;CACJ;AAED;;;;;;;;;;;GAWG;AACH;IA4CI;;;OAGG;IACH,sBAHW,OAAO,qBAAqB,EAAE,cAAc,SAC5C,OAAO,qCAAqC,EAAE,KAAK,EAW7D;IAxDD,mDAAmC;IA0DnC;;;;OAIG;IACH,6BAEC;IAED,2CAQC;IAED,4CAaC;IA2BD;;;;OAIG;IACH,WAJW,IAAI,aACJ,WAAW,UACX,MAAM,QAiBhB;IAED;;;;OAIG;IACH,aAJW,IAAI,aACJ,WAAW,UACX,MAAM,QAIhB;IAED;;OAEG;IACH,eAYC;IAED;;;;OAIG;IACH,mBAFW,OAAO,gDAAgD,EAAE,YAAY,QAoB/E;IAED;;;;OAIG;IACH,oBAFW,OAAO,gDAAgD,EAAE,YAAY,QAQ/E;;CA6IJ;;YA1ba,MAAM;UACN,IAAI;;;;UACJ,aAAa;;;;;aACb,OAAO,4CAA4C,EAAE,cAAc,GAAC,IAAI;;gCAdtD,mDAAmD;uBAI5D,kBAAkB;4BACb,iCAAiC;qBACxC,8BAA8B;8BALP,4CAA4C;8BAM1D,oBAAoB"}