@woosh/meep-engine 2.107.0 → 2.108.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 (231) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/build/meep.cjs +78 -46
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +78 -47
  5. package/package.json +1 -1
  6. package/src/core/binary/int32_to_binary_string.d.ts +3 -2
  7. package/src/core/binary/int32_to_binary_string.d.ts.map +1 -1
  8. package/src/core/binary/int32_to_binary_string.js +18 -14
  9. package/src/core/binary/split_by_3.spec.d.ts +2 -0
  10. package/src/core/binary/split_by_3.spec.d.ts.map +1 -0
  11. package/src/core/binary/split_by_3.spec.js +22 -0
  12. package/src/core/binary/to_half_float_uint16.d.ts.map +1 -1
  13. package/src/core/binary/to_half_float_uint16.js +7 -5
  14. package/src/core/collection/array/isArrayEqualStrict.d.ts.map +1 -1
  15. package/src/core/collection/array/isArrayEqualStrict.js +2 -2
  16. package/src/core/color/Color.d.ts.map +1 -1
  17. package/src/core/color/Color.js +7 -2
  18. package/src/core/color/hsv/rgb2hsv.d.ts +3 -3
  19. package/src/core/color/hsv/rgb2hsv.d.ts.map +1 -1
  20. package/src/core/color/hsv/rgb2hsv.js +11 -18
  21. package/src/core/color/rgb_to_luminance.d.ts +9 -0
  22. package/src/core/color/rgb_to_luminance.d.ts.map +1 -0
  23. package/src/core/color/rgb_to_luminance.js +10 -0
  24. package/src/core/geom/3d/sphere/harmonics/README.md +16 -2
  25. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts +6 -0
  26. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -0
  27. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +15 -0
  28. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.d.ts.map +1 -1
  29. package/src/core/geom/3d/sphere/harmonics/sh3_basis_at.js +21 -9
  30. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts +3 -3
  31. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
  32. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +35 -206
  33. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +8 -0
  34. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +1 -0
  35. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.js +29 -0
  36. package/src/core/geom/3d/sphere/harmonics/sh3_sample_by_direction.js +10 -10
  37. package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts +8 -0
  38. package/src/core/geom/3d/sphere/harmonics/sh_index.d.ts.map +1 -0
  39. package/src/core/geom/3d/sphere/harmonics/sh_index.js +9 -0
  40. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts +8 -0
  41. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.d.ts.map +1 -0
  42. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band1.js +44 -0
  43. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts +8 -0
  44. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.d.ts.map +1 -0
  45. package/src/core/geom/3d/sphere/harmonics/sh_rotate_band2.js +86 -0
  46. package/src/core/geom/3d/sphere/in_sphere3d_robust.d.ts.map +1 -1
  47. package/src/core/geom/3d/sphere/in_sphere3d_robust.js +2 -1
  48. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +20 -1
  49. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  50. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +53 -7
  51. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.spec.js +2 -2
  52. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts +1 -1
  53. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.d.ts.map +1 -1
  54. package/src/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js +12 -7
  55. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts +13 -0
  56. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -0
  57. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +135 -0
  58. package/src/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +38 -24
  59. package/src/core/geom/3d/tetrahedra/{compute_circumsphere.d.ts → tetrahedron_compute_circumsphere.d.ts} +3 -5
  60. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_circumsphere.d.ts.map +1 -0
  61. package/src/core/geom/3d/tetrahedra/{compute_circumsphere.js → tetrahedron_compute_circumsphere.js} +2 -4
  62. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.d.ts.map +1 -1
  63. package/src/core/geom/3d/tetrahedra/tetrahedron_compute_signed_volume.js +3 -1
  64. package/src/core/geom/Vector3.d.ts.map +1 -1
  65. package/src/core/geom/Vector3.js +1 -0
  66. package/src/core/geom/mat3/m3_multiply_vec3.d.ts +8 -0
  67. package/src/core/geom/mat3/m3_multiply_vec3.d.ts.map +1 -0
  68. package/src/core/geom/mat3/m3_multiply_vec3.js +21 -0
  69. package/src/core/geom/vec2/v2_cross_product.d.ts +15 -0
  70. package/src/core/geom/vec2/v2_cross_product.d.ts.map +1 -0
  71. package/src/core/geom/vec2/v2_cross_product.js +21 -0
  72. package/src/core/geom/vec3/v3_slerp.d.ts +1 -0
  73. package/src/core/geom/vec3/v3_slerp.d.ts.map +1 -1
  74. package/src/core/geom/vec3/v3_slerp.js +1 -0
  75. package/src/core/graph/MultiNode.d.ts +1 -1
  76. package/src/core/graph/MultiNode.js +1 -1
  77. package/src/core/graph/WeightedEdge.d.ts +6 -4
  78. package/src/core/graph/WeightedEdge.d.ts.map +1 -1
  79. package/src/core/graph/WeightedEdge.js +3 -0
  80. package/src/core/graph/coloring/colorizeGraph.js +19 -19
  81. package/src/core/graph/convert_graph_to_dot_string.d.ts +1 -1
  82. package/src/core/graph/convert_graph_to_dot_string.d.ts.map +1 -1
  83. package/src/core/graph/convert_graph_to_dot_string.js +10 -6
  84. package/src/core/graph/graph_compute_adjacency_matrix.d.ts +9 -0
  85. package/src/core/graph/graph_compute_adjacency_matrix.d.ts.map +1 -0
  86. package/src/core/graph/{graph_adjacency_matrix.js → graph_compute_adjacency_matrix.js} +1 -2
  87. package/src/core/graph/graph_compute_degree_matrix.d.ts +10 -0
  88. package/src/core/graph/graph_compute_degree_matrix.d.ts.map +1 -0
  89. package/src/core/graph/graph_compute_degree_matrix.js +23 -0
  90. package/src/core/graph/graph_compute_distance_matrix.d.ts +13 -0
  91. package/src/core/graph/graph_compute_distance_matrix.d.ts.map +1 -0
  92. package/src/core/graph/graph_compute_distance_matrix.js +103 -0
  93. package/src/core/graph/{graph_laplacian_matrix.d.ts → graph_compute_laplacian_matrix.d.ts} +2 -2
  94. package/src/core/graph/graph_compute_laplacian_matrix.d.ts.map +1 -0
  95. package/src/core/graph/{graph_laplacian_matrix.js → graph_compute_laplacian_matrix.js} +6 -6
  96. package/src/core/graph/graph_k_means_cluster.d.ts.map +1 -1
  97. package/src/core/graph/graph_k_means_cluster.js +4 -119
  98. package/src/core/graph/{coarsen_graph.d.ts → mn_graph_coarsen.d.ts} +2 -2
  99. package/src/core/graph/mn_graph_coarsen.d.ts.map +1 -0
  100. package/src/core/graph/{coarsen_graph.js → mn_graph_coarsen.js} +1 -1
  101. package/src/core/graph/mn_graph_coarsen.spec.d.ts +2 -0
  102. package/src/core/graph/mn_graph_coarsen.spec.d.ts.map +1 -0
  103. package/src/core/graph/{coarsen_graph.spec.js → mn_graph_coarsen.spec.js} +4 -4
  104. package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts +1 -0
  105. package/src/core/graph/mn_graph_collapse_weighted_edge.d.ts.map +1 -1
  106. package/src/core/graph/mn_graph_collapse_weighted_edge.js +7 -1
  107. package/src/core/math/physics/brdf/brdf_burley.d.ts.map +1 -1
  108. package/src/core/math/physics/brdf/brdf_burley.js +9 -1
  109. package/src/core/math/physics/brdf/{D_GGX.d.ts → diffuse_GGX.d.ts} +2 -2
  110. package/src/core/math/physics/brdf/diffuse_GGX.d.ts.map +1 -0
  111. package/src/core/math/physics/brdf/{D_GGX.js → diffuse_GGX.js} +1 -1
  112. package/src/core/math/physics/brdf/fresnel_Schlick.d.ts +3 -0
  113. package/src/core/math/physics/brdf/fresnel_Schlick.d.ts.map +1 -0
  114. package/src/core/math/physics/brdf/fresnel_Schlick.js +3 -0
  115. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts +9 -0
  116. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.d.ts.map +1 -0
  117. package/src/core/math/physics/brdf/fresnel_Schlick_optimized.js +12 -0
  118. package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts +9 -0
  119. package/src/core/math/physics/brdf/fresnel_Schlick_original.d.ts.map +1 -0
  120. package/src/core/math/physics/brdf/fresnel_Schlick_original.js +10 -0
  121. package/src/core/math/physics/bsdf/bsdf_schlick.d.ts.map +1 -1
  122. package/src/core/math/physics/bsdf/bsdf_schlick.js +3 -11
  123. package/src/core/math/physics/ior_to_reflectivity.d.ts +7 -0
  124. package/src/core/math/physics/ior_to_reflectivity.d.ts.map +1 -0
  125. package/src/core/math/physics/ior_to_reflectivity.js +9 -0
  126. package/src/core/math/physics/pdf/README.md +1 -0
  127. package/src/core/math/physics/pdf/pdf_GGX.d.ts +16 -0
  128. package/src/core/math/physics/pdf/pdf_GGX.d.ts.map +1 -0
  129. package/src/core/math/physics/pdf/pdf_GGX.js +25 -0
  130. package/src/core/math/physics/reflectivity_to_ior.d.ts +7 -0
  131. package/src/core/math/physics/reflectivity_to_ior.d.ts.map +1 -0
  132. package/src/core/math/physics/reflectivity_to_ior.js +8 -0
  133. package/src/engine/EngineHarness.d.ts +10 -1
  134. package/src/engine/EngineHarness.d.ts.map +1 -1
  135. package/src/engine/EngineHarness.js +16 -11
  136. package/src/engine/asset/loaders/image/png/PNGReader.d.ts +25 -11
  137. package/src/engine/asset/loaders/image/png/PNGReader.d.ts.map +1 -1
  138. package/src/engine/asset/loaders/image/png/PNGReader.js +38 -24
  139. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +2 -0
  140. package/src/engine/graphics/GraphicsEngine.js +1 -1
  141. package/src/engine/graphics/ecs/light/LightSystem.d.ts.map +1 -1
  142. package/src/engine/graphics/ecs/light/LightSystem.js +2 -3
  143. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts +6 -0
  144. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.d.ts.map +1 -1
  145. package/src/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +22 -11
  146. package/src/engine/graphics/render/forward_plus/model/DirectionalLight.d.ts.map +1 -1
  147. package/src/engine/graphics/render/forward_plus/model/DirectionalLight.js +25 -25
  148. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts +9 -0
  149. package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts.map +1 -0
  150. package/src/engine/graphics/sh3/fromCubeRenderTarget.js +145 -0
  151. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts +8 -0
  152. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.d.ts.map +1 -0
  153. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +51 -0
  154. package/src/engine/graphics/sh3/{LightProbeVolume.d.ts → lpv/LightProbeVolume.d.ts} +18 -7
  155. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -0
  156. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +340 -0
  157. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts +18 -0
  158. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.d.ts.map +1 -0
  159. package/src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.js +44 -0
  160. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +12 -0
  161. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -0
  162. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +123 -0
  163. package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts +29 -0
  164. package/src/engine/graphics/sh3/lpv/ProbeRenderer.d.ts.map +1 -0
  165. package/src/engine/graphics/sh3/lpv/ProbeRenderer.js +35 -0
  166. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +27 -0
  167. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -0
  168. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +158 -0
  169. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +11 -0
  170. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -0
  171. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +127 -0
  172. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +12 -0
  173. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -0
  174. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +89 -0
  175. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +90 -0
  176. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -0
  177. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +352 -0
  178. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +5 -91
  179. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  180. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +41 -477
  181. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts +1 -0
  182. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.d.ts.map +1 -1
  183. package/src/engine/graphics/sh3/path_tracer/make_one_vector3.js +6 -3
  184. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +26 -58
  185. package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.d.ts.map +1 -1
  186. package/src/engine/graphics/sh3/path_tracer/random_in_hemisphere.js +7 -1
  187. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts +2 -2
  188. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.d.ts.map +1 -1
  189. package/src/engine/graphics/sh3/path_tracer/sample_triangle_attribute.js +1 -1
  190. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +3 -0
  191. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +1 -0
  192. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +3 -0
  193. package/src/engine/graphics/sh3/path_tracer/texture/apply_texture_clamping_to_coordinate.d.ts.map +1 -0
  194. package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.js → texture/apply_texture_clamping_to_coordinate.js} +2 -2
  195. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +11 -0
  196. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -0
  197. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +86 -0
  198. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts +10 -0
  199. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -0
  200. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +56 -0
  201. package/src/engine/graphics/sh3/prototypeSH3Probe.js +87 -195
  202. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts +5 -5
  203. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.d.ts.map +1 -1
  204. package/src/engine/graphics/sh3/sky/hosek/sky_hosek_compute_irradiance_by_direction.js +8 -8
  205. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts +13 -0
  206. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts.map +1 -0
  207. package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.js +54 -0
  208. package/src/engine/graphics/texture/AttributeDataTexture.d.ts +2 -2
  209. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  210. package/src/engine/graphics/texture/AttributeDataTexture.js +11 -11
  211. package/src/engine/input/ecs/systems/InputControllerSystem.js +1 -1
  212. package/src/view/elements/ColorPickerView.d.ts.map +1 -1
  213. package/src/view/elements/ColorPickerView.js +7 -7
  214. package/src/core/geom/3d/tetrahedra/compute_circumsphere.d.ts.map +0 -1
  215. package/src/core/graph/coarsen_graph.d.ts.map +0 -1
  216. package/src/core/graph/coarsen_graph.spec.d.ts +0 -2
  217. package/src/core/graph/coarsen_graph.spec.d.ts.map +0 -1
  218. package/src/core/graph/graph_adjacency_matrix.d.ts +0 -9
  219. package/src/core/graph/graph_adjacency_matrix.d.ts.map +0 -1
  220. package/src/core/graph/graph_degree_matrix.d.ts +0 -9
  221. package/src/core/graph/graph_degree_matrix.d.ts.map +0 -1
  222. package/src/core/graph/graph_degree_matrix.js +0 -18
  223. package/src/core/graph/graph_laplacian_matrix.d.ts.map +0 -1
  224. package/src/core/math/physics/brdf/D_GGX.d.ts.map +0 -1
  225. package/src/engine/graphics/sh3/LightProbeVolume.d.ts.map +0 -1
  226. package/src/engine/graphics/sh3/LightProbeVolume.js +0 -609
  227. package/src/engine/graphics/sh3/path_tracer/apply_texture_clamping_to_coordinate.d.ts.map +0 -1
  228. package/src/engine/graphics/sh3/visualise_probe.d.ts +0 -12
  229. package/src/engine/graphics/sh3/visualise_probe.d.ts.map +0 -1
  230. package/src/engine/graphics/sh3/visualise_probe.js +0 -40
  231. /package/src/engine/graphics/sh3/path_tracer/{apply_texture_clamping_to_coordinate.d.ts → texture/apply_texture_clamping_to_coordinate.d.ts} +0 -0
@@ -0,0 +1,340 @@
1
+ import { LineBasicMaterial } from "three";
2
+ import { array_copy } from "../../../../core/collection/array/array_copy.js";
3
+ import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
4
+ import {
5
+ build_tetrahedral_mesh_buffer_geometry
6
+ } from "../../../../core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js";
7
+ import {
8
+ compute_delaunay_tetrahedral_mesh
9
+ } from "../../../../core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js";
10
+ import { TetrahedralMesh } from "../../../../core/geom/3d/tetrahedra/TetrahedralMesh.js";
11
+ import TaskGroup from "../../../../core/process/task/TaskGroup.js";
12
+ import { actionTask } from "../../../../core/process/task/util/actionTask.js";
13
+ import { countTask } from "../../../../core/process/task/util/countTask.js";
14
+ import { promiseTask } from "../../../../core/process/task/util/promiseTask.js";
15
+ import Entity from "../../../ecs/Entity.js";
16
+ import { Transform } from "../../../ecs/transform/Transform.js";
17
+ import { DrawMode } from "../../ecs/mesh-v2/DrawMode.js";
18
+ import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
19
+ import { ShadedGeometryFlags } from "../../ecs/mesh-v2/ShadedGeometryFlags.js";
20
+ import { visualise_spherical_harmonic_sphere } from "../visualise_spherical_harmonic_sphere.js";
21
+ import { PathTracerProbeRenderer } from "./PathTracerProbeRenderer.js";
22
+
23
+ const TEMP_CONTACT = new SurfacePoint3();
24
+
25
+
26
+ class Baker {
27
+ constructor() {
28
+ /**
29
+ *
30
+ * @type {EntityComponentDataset|null}
31
+ * @private
32
+ */
33
+ this.__ecd = null;
34
+
35
+ /**
36
+ *
37
+ * @type {BVH|null}
38
+ * @private
39
+ */
40
+ this.__bvh = null;
41
+
42
+ this.__min_bounce_count = 3;
43
+ this.__max_bounce_count = 100;
44
+
45
+ this._ren = new PathTracerProbeRenderer();
46
+ }
47
+
48
+ /**
49
+ * @param {BVH} bvh
50
+ */
51
+ set_bvh(bvh) {
52
+ this.__bvh = bvh;
53
+ }
54
+
55
+ build_spatial() {
56
+
57
+ }
58
+
59
+ /**
60
+ *
61
+ * @param {number[]} irradiance RGB irradiance result is written here
62
+ * @param {number} bounce_count number of reflections before this trace
63
+ * @param {number} origin_x
64
+ * @param {number} origin_y
65
+ * @param {number} origin_z
66
+ * @param {number} direction_x
67
+ * @param {number} direction_y
68
+ * @param {number} direction_z
69
+ */
70
+ trace_ray(irradiance, bounce_count,
71
+ origin_x, origin_y, origin_z,
72
+ direction_x, direction_y, direction_z) {
73
+
74
+ //
75
+
76
+ if (!this.ray_cast(TEMP_CONTACT, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z)) {
77
+ // no hit, assume irradiance is zeroed - black
78
+
79
+ return;
80
+ }
81
+
82
+ // record irradiance
83
+
84
+ // reflect ray around normal
85
+ // TODO apply BDRF to compute reflected ray
86
+
87
+ if (bounce_count > this.__max_bounce_count) {
88
+ // terminate
89
+ }
90
+
91
+ }
92
+
93
+ /**
94
+ *
95
+ * @param contact
96
+ * @param origin_x
97
+ * @param origin_y
98
+ * @param origin_z
99
+ * @param direction_x
100
+ * @param direction_y
101
+ * @param direction_z
102
+ * @returns {boolean}
103
+ */
104
+ ray_cast(contact,
105
+ origin_x, origin_y, origin_z,
106
+ direction_x, direction_y, direction_z
107
+ ) {
108
+
109
+ }
110
+
111
+ prepare_scene() {
112
+
113
+ }
114
+
115
+ /**
116
+ *
117
+ * @param {number[]} position
118
+ * @param {number} position_offset
119
+ * @param {number[]} output
120
+ * @param {number} output_offset
121
+ */
122
+ bake_sh3_cube(
123
+ position, position_offset,
124
+ output, output_offset
125
+ ) {
126
+
127
+ this._ren.bake(position, position_offset, output, output_offset);
128
+
129
+ }
130
+
131
+ /**
132
+ *
133
+ */
134
+ async prepare(ecd) {
135
+
136
+ this._ren.build_scene(ecd);
137
+
138
+ await this._ren.bake_start();
139
+ }
140
+
141
+ finish() {
142
+ this._ren.bake_end();
143
+ }
144
+ }
145
+
146
+ export class LightProbeVolume {
147
+ constructor() {
148
+ this.__positions = [];
149
+
150
+ this.__mesh = new TetrahedralMesh();
151
+
152
+ this.__probe_data = [];
153
+
154
+ this.__length = 0;
155
+ }
156
+
157
+ clear() {
158
+ this.__positions.splice(0, this.__positions.length);
159
+ this.__probe_data.splice(0, this.__probe_data.length);
160
+ this.__mesh.clear();
161
+
162
+ this.__length = 0;
163
+ }
164
+
165
+ /**
166
+ *
167
+ * @return {TetrahedralMesh}
168
+ */
169
+ get mesh() {
170
+ return this.__mesh;
171
+ }
172
+
173
+ get points() {
174
+ return this.__positions;
175
+ }
176
+
177
+ get harmonics() {
178
+ return this.__probe_data;
179
+ }
180
+
181
+ get count() {
182
+ return this.__length;
183
+ }
184
+
185
+ set count(v) {
186
+ this.__length = v;
187
+ }
188
+
189
+ /**
190
+ *
191
+ * @param {number} x
192
+ * @param {number} y
193
+ * @param {number} z
194
+ */
195
+ add_point(x, y, z) {
196
+ const i = this.__length;
197
+
198
+ this.__positions[i * 3] = x;
199
+ this.__positions[i * 3 + 1] = y;
200
+ this.__positions[i * 3 + 2] = z;
201
+
202
+ for (let j = 0; j < 9 * 3; j++) {
203
+ this.__probe_data[i * 9 * 3 + j] = 1; // fill with white
204
+ }
205
+
206
+ this.__length++;
207
+ }
208
+
209
+ /**
210
+ *
211
+ * @param {number} index
212
+ * @param {number[]} source
213
+ * @param {number} source_offset
214
+ */
215
+ white_probe(index, source, source_offset) {
216
+ array_copy(source, source_offset, this.__probe_data, index * 9 * 3, 9 * 3);
217
+ }
218
+
219
+ /**
220
+ * Build tetrahedral mesh
221
+ */
222
+ build_mesh() {
223
+
224
+ const t0 = performance.now();
225
+ compute_delaunay_tetrahedral_mesh(this.__mesh, this.__positions, this.__length);
226
+
227
+ const t1 = performance.now();
228
+
229
+ // optional step to improve memory utilization
230
+ this.__mesh.compact();
231
+
232
+ const t2 = performance.now();
233
+
234
+ console.log(`Tetrahedral mesh (${this.__length} points, ${this.__mesh.size()} tets) build took ${t2 - t0}ms`);
235
+ }
236
+
237
+
238
+ /**
239
+ * Bake light probes
240
+ * @returns {TaskGroup}
241
+ * @param {EntityComponentDataset} ecd
242
+ */
243
+ bake(ecd) {
244
+ const baker = new Baker();
245
+ // baker.set_bvh(entityManager.getSystem(ShadedGeometrySystem).__bvh_binary);
246
+
247
+
248
+ const tPrepare = promiseTask(new Promise(async (resolve, reject) => {
249
+ await baker.prepare(ecd);
250
+
251
+ resolve();
252
+ }), 'Prepare');
253
+
254
+
255
+ const probe_count = this.__length;
256
+ const tBake = countTask(0, probe_count, (i) => {
257
+
258
+ baker.bake_sh3_cube(
259
+ this.__positions, i * 3,
260
+ this.__probe_data, i * 9 * 3
261
+ );
262
+
263
+ });
264
+ tBake.estimatedDuration = probe_count;
265
+
266
+ tBake.promise().then(() => {
267
+
268
+ const duration = tBake.__executedCpuTime;
269
+
270
+ console.log(`Baked ${probe_count} probes in ${duration}ms, ~${(duration / probe_count).toFixed(2)}ms per probe`);
271
+
272
+ })
273
+
274
+ const tFinish = actionTask(() => {
275
+ baker.finish();
276
+ });
277
+
278
+ tFinish.addDependency(tBake);
279
+ tBake.addDependency(tPrepare);
280
+
281
+ return new TaskGroup([
282
+ tPrepare, tBake, tFinish
283
+ ], "LightProbeVolume Bake");
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @param {EntityComponentDataset} ecd
289
+ * @param {number} size
290
+ * @param {boolean} shadow
291
+ */
292
+ visualize_probes({ ecd, size = 0.2, shadow = false }) {
293
+ for (let i = 0; i < this.__length; i++) {
294
+ visualise_spherical_harmonic_sphere({
295
+ size,
296
+ position: this.__positions,
297
+ position_offset: i * 3,
298
+ sh: this.__probe_data,
299
+ sh_offset: i * 3 * 9,
300
+ shadow: shadow
301
+ }).build(ecd);
302
+ }
303
+ }
304
+
305
+ /**
306
+ *
307
+ * @param {EntityComponentDataset} ecd
308
+ * @param {string|number} color CSS color definition
309
+ * @param {number} opacity
310
+ */
311
+ visualize_mesh({ ecd, color = '#FF00FF', opacity = 0.35 }) {
312
+
313
+ const geometry = build_tetrahedral_mesh_buffer_geometry(this.__mesh, this.__positions);
314
+
315
+ const sg = ShadedGeometry.from(geometry, new LineBasicMaterial({
316
+ color: color,
317
+ transparent: true,
318
+ opacity,
319
+ depthWrite: false
320
+ }), DrawMode.LineSegments);
321
+
322
+ sg.clearFlag(ShadedGeometryFlags.CastShadow);
323
+ sg.clearFlag(ShadedGeometryFlags.ReceiveShadow);
324
+
325
+ new Entity()
326
+ .add(sg)
327
+ .add(new Transform())
328
+ .build(ecd);
329
+ }
330
+
331
+ /**
332
+ *
333
+ * @returns {TaskGroup}
334
+ * @param {EntityComponentDataset} ecd
335
+ */
336
+ build(ecd) {
337
+ this.build_mesh();
338
+ return this.bake(ecd);
339
+ }
340
+ }
@@ -0,0 +1,18 @@
1
+ export class LightProbeVolumeSerializationAdapter extends BinaryClassSerializationAdapter {
2
+ klass: typeof LightProbeVolume;
3
+ /**
4
+ *
5
+ * @param buffer
6
+ * @param {LightProbeVolume} value
7
+ */
8
+ serialize(buffer: any, value: LightProbeVolume): void;
9
+ /**
10
+ *
11
+ * @param buffer
12
+ * @param {LightProbeVolume} value
13
+ */
14
+ deserialize(buffer: any, value: LightProbeVolume): void;
15
+ }
16
+ import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
17
+ import { LightProbeVolume } from "./LightProbeVolume.js";
18
+ //# sourceMappingURL=LightProbeVolumeSerializationAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LightProbeVolumeSerializationAdapter.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolumeSerializationAdapter.js"],"names":[],"mappings":"AAGA;IAEI,+BAAwB;IAGxB;;;;OAIG;IACH,8BAFW,gBAAgB,QAY1B;IAED;;;;OAIG;IACH,gCAFW,gBAAgB,QAc1B;CACJ;gDA3C+C,gEAAgE;iCAC/E,uBAAuB"}
@@ -0,0 +1,44 @@
1
+ import { BinaryClassSerializationAdapter } from "../../../ecs/storage/binary/BinaryClassSerializationAdapter.js";
2
+ import { LightProbeVolume } from "./LightProbeVolume.js";
3
+
4
+ export class LightProbeVolumeSerializationAdapter extends BinaryClassSerializationAdapter {
5
+
6
+ klass = LightProbeVolume
7
+ version = 0
8
+
9
+ /**
10
+ *
11
+ * @param buffer
12
+ * @param {LightProbeVolume} value
13
+ */
14
+ serialize(buffer, value) {
15
+ const count = value.count;
16
+
17
+ buffer.writeUint32(count);
18
+ // write probe position data
19
+ buffer.writeFloat32Array(value.points, 0, count * 3);
20
+ // probe values
21
+ buffer.writeFloat32Array(value.harmonics, 0, count * 27);
22
+
23
+ value.mesh.serialize(buffer);
24
+ }
25
+
26
+ /**
27
+ *
28
+ * @param buffer
29
+ * @param {LightProbeVolume} value
30
+ */
31
+ deserialize(buffer, value) {
32
+ value.clear();
33
+
34
+ const count = buffer.readUint32();
35
+
36
+ value.count = count;
37
+
38
+ buffer.readFloat32Array(value.points, 0, count * 3);
39
+ buffer.readFloat32Array(value.harmonics, 0, count * 27);
40
+
41
+
42
+ value.mesh.deserialize(buffer);
43
+ }
44
+ }
@@ -0,0 +1,12 @@
1
+ export class PathTracerProbeRenderer extends ProbeRenderer {
2
+ tracer: PathTracer;
3
+ sample_count: number;
4
+ random: () => number;
5
+ scene: PathTracedScene;
6
+ bake(position: any, position_offset: any, output: any, output_offset: any): void;
7
+ build_scene(ecd: any): void;
8
+ }
9
+ import { ProbeRenderer } from "./ProbeRenderer.js";
10
+ import { PathTracer } from "../path_tracer/PathTracer.js";
11
+ import { PathTracedScene } from "../path_tracer/PathTracedScene.js";
12
+ //# sourceMappingURL=PathTracerProbeRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AAoBA;IACI,mBAA0B;IAC1B,qBAAoB;IACpB,qBAAyB;IAEzB,uBAA6B;IAE7B,iFA+CC;IASD,4BAsCC;CACJ;8BA5G6B,oBAAoB;2BADvB,8BAA8B;gCADzB,mCAAmC"}
@@ -0,0 +1,123 @@
1
+ import { array_copy } from "../../../../core/collection/array/array_copy.js";
2
+ import { sh3_basis_at } from "../../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
3
+ import {
4
+ sh3_dering_optimize_positive
5
+ } from "../../../../core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js";
6
+ import { randomPointOnSphere } from "../../../../core/geom/random/randomPointOnSphere.js";
7
+ import { seededRandom } from "../../../../core/math/random/seededRandom.js";
8
+ import { Transform } from "../../../ecs/transform/Transform.js";
9
+ import { Light } from "../../ecs/light/Light.js";
10
+ import { LightType } from "../../ecs/light/LightType.js";
11
+ import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
12
+ import { DirectionalLight } from "../../render/forward_plus/model/DirectionalLight.js";
13
+ import { PathTracedScene } from "../path_tracer/PathTracedScene.js";
14
+ import { PathTracer } from "../path_tracer/PathTracer.js";
15
+ import { ProbeRenderer } from "./ProbeRenderer.js";
16
+
17
+ const __shared_buffer = new ArrayBuffer((27 + 9) * 8);
18
+ const sh_basis = new Float64Array(__shared_buffer, 0, 9);
19
+ const coefficients = new Float64Array(__shared_buffer, 9 * 8, 27);
20
+
21
+ export class PathTracerProbeRenderer extends ProbeRenderer {
22
+ tracer = new PathTracer();
23
+ sample_count = 1000;
24
+ random = seededRandom(0);
25
+
26
+ scene = new PathTracedScene()
27
+
28
+ bake(position, position_offset, output, output_offset) {
29
+
30
+ const tracer = this.tracer;
31
+
32
+ const ray = [];
33
+
34
+ const direct_light = [];
35
+
36
+ array_copy(position, position_offset, ray, 0, 3);
37
+
38
+ const sampled_irradiance = [];
39
+
40
+ coefficients.fill(0);
41
+
42
+ for (let i = 0; i < this.sample_count; i++) {
43
+
44
+ randomPointOnSphere(this.random, ray, 3);
45
+
46
+ tracer.path_trace(sampled_irradiance, ray, Infinity, 1, 7, this.random, this.scene);
47
+
48
+ sh3_basis_at(ray[3], ray[4], ray[5], sh_basis);
49
+
50
+ // accumulate
51
+ for (let j = 0; j < 9; j++) {
52
+
53
+ const j3 = j * 3;
54
+
55
+ const projected_coefficient = sh_basis[j];
56
+
57
+ coefficients[j3] += projected_coefficient * sampled_irradiance[0];
58
+ coefficients[j3 + 1] += projected_coefficient * sampled_irradiance[1];
59
+ coefficients[j3 + 2] += projected_coefficient * sampled_irradiance[2];
60
+
61
+ }
62
+ }
63
+
64
+ // Area of a unit sphere is (4*PI)
65
+
66
+ const normalization_weight = (4 * Math.PI) / this.sample_count;
67
+
68
+ for (let i = 0; i < 27; i++) {
69
+ coefficients[i] *= normalization_weight;
70
+ }
71
+
72
+ sh3_dering_optimize_positive(coefficients, 0, coefficients, 0, 3);
73
+
74
+ array_copy(coefficients, 0, output, output_offset, 27);
75
+ }
76
+
77
+ bake_end() {
78
+ }
79
+
80
+ bake_start() {
81
+ return this.scene.build();
82
+ }
83
+
84
+ build_scene(ecd) {
85
+
86
+ const scene = this.scene;
87
+
88
+ ecd.traverseEntities([ShadedGeometry, Transform],
89
+ /**
90
+ *
91
+ * @param {ShadedGeometry} sg
92
+ * @param {Transform} transform
93
+ */
94
+ (sg, transform) => {
95
+
96
+ scene.addMesh(sg.geometry, sg.material, transform.matrix)
97
+
98
+ });
99
+
100
+
101
+ ecd.traverseEntities([Light, Transform],
102
+ /**
103
+ *
104
+ * @param {Light} light
105
+ * @param {Transform} transform
106
+ */
107
+ (light, transform) => {
108
+
109
+ if (light.type.getValue() === LightType.DIRECTION) {
110
+
111
+ const l = new DirectionalLight();
112
+
113
+ l.color.copy(light.color);
114
+ l.direction.copy(transform.forward);
115
+ l.intensity.copy(light.intensity);
116
+
117
+ scene.addLight(l);
118
+ }
119
+
120
+ });
121
+
122
+ }
123
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @abstract
3
+ */
4
+ export class ProbeRenderer {
5
+ /**
6
+ *
7
+ * @param {EntityComponentDataset} ecd
8
+ * @abstract
9
+ */
10
+ build_scene(ecd: EntityComponentDataset): void;
11
+ /**
12
+ * @abstract
13
+ */
14
+ bake_start(): Promise<void>;
15
+ /**
16
+ * @abstract
17
+ */
18
+ bake_end(): void;
19
+ /**
20
+ *
21
+ * @param {number[]} position
22
+ * @param {number} position_offset
23
+ * @param {number[]} output
24
+ * @param {number} output_offset
25
+ * @abstract
26
+ */
27
+ bake(position: number[], position_offset: number, output: number[], output_offset: number): void;
28
+ }
29
+ //# sourceMappingURL=ProbeRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/ProbeRenderer.js"],"names":[],"mappings":"AAAA;;GAEG;AACH;IACI;;;;OAIG;IACH,+CACC;IAED;;OAEG;IACH,4BACC;IAED;;OAEG;IACH,iBACC;IAED;;;;;;;OAOG;IACH,eANW,MAAM,EAAE,mBACR,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAIhB;CACJ"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @abstract
3
+ */
4
+ export class ProbeRenderer {
5
+ /**
6
+ *
7
+ * @param {EntityComponentDataset} ecd
8
+ * @abstract
9
+ */
10
+ build_scene(ecd) {
11
+ }
12
+
13
+ /**
14
+ * @abstract
15
+ */
16
+ async bake_start() {
17
+ }
18
+
19
+ /**
20
+ * @abstract
21
+ */
22
+ bake_end() {
23
+ }
24
+
25
+ /**
26
+ *
27
+ * @param {number[]} position
28
+ * @param {number} position_offset
29
+ * @param {number[]} output
30
+ * @param {number} output_offset
31
+ * @abstract
32
+ */
33
+ bake(position, position_offset, output, output_offset) {
34
+ }
35
+ }
@@ -0,0 +1,27 @@
1
+ export class WebGLCubeProbeRenderer extends ProbeRenderer {
2
+ /**
3
+ *
4
+ * @type {THREE.WebGLRenderer|null}
5
+ * @private
6
+ */
7
+ private __renderer;
8
+ render_target: WebGLCubeRenderTarget;
9
+ /**
10
+ * Used to read out GPU memory for each face
11
+ * @type {Uint8Array}
12
+ * @private
13
+ */
14
+ private __cube_face_raw;
15
+ __cube_camera: CubeCamera;
16
+ /**
17
+ *
18
+ * @type {Scene}
19
+ * @private
20
+ */
21
+ private __scene;
22
+ bake_start(): void;
23
+ }
24
+ import { ProbeRenderer } from "./ProbeRenderer.js";
25
+ import { WebGLCubeRenderTarget } from "three";
26
+ import { CubeCamera } from "three";
27
+ //# sourceMappingURL=WebGLCubeProbeRenderer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebGLCubeProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js"],"names":[],"mappings":"AAuBA;IAIQ;;;;OAIG;IACH,mBAAsB;IAEtB,qCASE;IAEF;;;;OAIG;IACH,wBAA8F;IAG9F,0BAAiE;IAEjE;;;;OAIG;IACH,gBAA0B;IA8C9B,mBAMC;CA6CJ;8BAxI6B,oBAAoB;sCAZ3C,OAAO;2BAAP,OAAO"}