@woosh/meep-engine 2.108.0 → 2.108.3

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/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +650 -308
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +650 -308
  5. package/editor/tools/paint/TerrainHeightPaintTool.js +5 -5
  6. package/package.json +1 -1
  7. package/src/core/binary/float_to_uint8.d.ts +7 -0
  8. package/src/core/binary/float_to_uint8.d.ts.map +1 -0
  9. package/src/core/binary/{float2uint8.js → float_to_uint8.js} +1 -1
  10. package/src/core/binary/uint8_to_float.d.ts +7 -0
  11. package/src/core/binary/uint8_to_float.d.ts.map +1 -0
  12. package/src/core/binary/{uint82float.js → uint8_to_float.js} +1 -1
  13. package/src/core/binary/uint8_to_float.spec.d.ts +2 -0
  14. package/src/core/binary/uint8_to_float.spec.d.ts.map +1 -0
  15. package/src/core/binary/uint8_to_float.spec.js +7 -0
  16. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts +6 -0
  17. package/src/core/bvh2/binary/2/BinaryUint32BVH.d.ts.map +1 -1
  18. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +15 -3
  19. package/src/core/bvh2/bvh3/build_triangle_morton_codes.js +3 -3
  20. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
  21. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +25 -14
  22. package/src/core/codegen/codeToBlob.d.ts +8 -0
  23. package/src/core/codegen/codeToBlob.d.ts.map +1 -0
  24. package/src/core/codegen/codeToBlob.js +36 -0
  25. package/src/core/codegen/codeToURL.d.ts +8 -0
  26. package/src/core/codegen/codeToURL.d.ts.map +1 -0
  27. package/src/core/codegen/codeToURL.js +22 -0
  28. package/src/core/collection/array/arrayQuickSort.d.ts +0 -9
  29. package/src/core/collection/array/arrayQuickSort.d.ts.map +1 -1
  30. package/src/core/collection/array/arrayQuickSort.js +0 -73
  31. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts +10 -0
  32. package/src/core/collection/array/array_quick_sort_by_comparator.d.ts.map +1 -0
  33. package/src/core/collection/array/array_quick_sort_by_comparator.js +75 -0
  34. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts +8 -0
  35. package/src/core/collection/array/array_quick_sort_by_lookup.d.ts.map +1 -0
  36. package/src/core/collection/array/array_quick_sort_by_lookup.js +78 -0
  37. package/src/core/collection/array/array_shuffle.d.ts +8 -0
  38. package/src/core/collection/array/array_shuffle.d.ts.map +1 -0
  39. package/src/core/collection/array/array_shuffle.js +22 -0
  40. package/src/core/collection/array/array_shuffle.spec.d.ts +2 -0
  41. package/src/core/collection/array/array_shuffle.spec.d.ts.map +1 -0
  42. package/src/core/collection/array/{randomizeArrayElementOrder.spec.js → array_shuffle.spec.js} +4 -4
  43. package/src/core/collection/array/iterator/ArrayIteratorRandom.js +2 -2
  44. package/src/core/collection/array/randomMultipleFromArray.js +2 -2
  45. package/src/core/color/Color.js +9 -9
  46. package/src/core/color/hsv/hsv2rgb.js +4 -4
  47. package/src/core/color/rgb2uint24.js +4 -4
  48. package/src/core/color/sRGB/linear_to_sRGB.d.ts +1 -0
  49. package/src/core/color/sRGB/linear_to_sRGB.d.ts.map +1 -1
  50. package/src/core/color/sRGB/linear_to_sRGB.js +4 -4
  51. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +15 -0
  52. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts.map +1 -0
  53. package/src/core/geom/2d/triangle2d_get_barycentric.js +48 -0
  54. package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
  55. package/src/core/geom/3d/aabb/AABB3.js +4 -1
  56. package/src/core/geom/3d/aabb/aabb3_from_v3_array.d.ts.map +1 -1
  57. package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +2 -7
  58. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +3 -3
  59. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts +11 -0
  60. package/src/core/geom/3d/aabb3_compute_from_triangle.d.ts.map +1 -0
  61. package/src/core/geom/3d/aabb3_compute_from_triangle.js +43 -0
  62. package/src/core/geom/3d/shape/UnitSphereShape3D.d.ts.map +1 -1
  63. package/src/core/geom/3d/shape/UnitSphereShape3D.js +14 -14
  64. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.d.ts.map +1 -1
  65. package/src/core/geom/3d/sphere/harmonics/SH3_COEFFICIENTS.js +2 -0
  66. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +5 -5
  67. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +9 -0
  68. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts.map +1 -0
  69. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +17 -0
  70. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts +6 -3
  71. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.d.ts.map +1 -1
  72. package/src/core/geom/3d/tetrahedra/TetrahedralMesh.js +56 -18
  73. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts +1 -1
  74. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.d.ts.map +1 -1
  75. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_walk_towards_containing_tetrahedron.js +11 -4
  76. package/src/core/geom/3d/tetrahedra/{GetDepthForTetrahedronProbe.glsl → triangle/GetDepthForTetrahedronProbe.glsl} +17 -10
  77. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts +2 -0
  78. package/src/core/geom/3d/tetrahedra/triangle/prototype.d.ts.map +1 -0
  79. package/src/core/geom/3d/tetrahedra/triangle/prototype.js +128 -0
  80. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts +13 -0
  81. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts.map +1 -0
  82. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js +120 -0
  83. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts +3 -0
  84. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.d.ts.map +1 -0
  85. package/src/core/geom/3d/tetrahedra/triangle/triangle_encode_rasterized_depth.js +106 -0
  86. package/src/core/geom/Vector3.js +3 -3
  87. package/src/core/geom/random/randomPointInSphere.d.ts +1 -1
  88. package/src/core/geom/random/randomPointInSphere.js +2 -2
  89. package/src/core/geom/random/randomPointOnSphere.d.ts +3 -3
  90. package/src/core/geom/random/randomPointOnSphere.d.ts.map +1 -1
  91. package/src/core/geom/random/randomPointOnSphere.js +5 -9
  92. package/src/core/math/factorial.d.ts +7 -0
  93. package/src/core/math/factorial.d.ts.map +1 -0
  94. package/src/core/math/factorial.js +15 -0
  95. package/src/core/math/factorial.spec.d.ts +2 -0
  96. package/src/core/math/factorial.spec.d.ts.map +1 -0
  97. package/src/core/math/factorial.spec.js +9 -0
  98. package/src/core/model/DebouncedObservedBoolean.d.ts +1 -1
  99. package/src/core/model/DebouncedObservedBoolean.d.ts.map +1 -1
  100. package/src/core/model/node-graph/node/NodeDescription.d.ts +6 -4
  101. package/src/core/process/task/util/randomCountTask.js +3 -3
  102. package/src/core/process/worker/WorkerBuilder.d.ts.map +1 -1
  103. package/src/core/process/worker/WorkerBuilder.js +5 -35
  104. package/src/engine/EngineHarness.d.ts.map +1 -1
  105. package/src/engine/EngineHarness.js +7 -1
  106. package/src/engine/asset/loaders/ArrayBufferLoader.d.ts.map +1 -1
  107. package/src/engine/asset/loaders/ArrayBufferLoader.js +17 -10
  108. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.d.ts.map +1 -1
  109. package/src/engine/asset/loaders/material/TextureAttachmensByMaterialType.js +3 -0
  110. package/src/engine/asset/loaders/material/computeTextureEquality.d.ts.map +1 -1
  111. package/src/engine/asset/loaders/material/computeTextureEquality.js +8 -1
  112. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +4 -4
  113. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.d.ts.map +1 -1
  114. package/src/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +4 -0
  115. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.d.ts.map +1 -1
  116. package/src/engine/graphics/ecs/mesh-v2/render/adapters/AbstractRenderAdapter.js +3 -1
  117. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.d.ts.map +1 -1
  118. package/src/engine/graphics/ecs/sprite/SpriteSystemPE.js +7 -7
  119. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts +8 -0
  120. package/src/engine/graphics/filter/sampler2d_flipY_in_place.d.ts.map +1 -0
  121. package/src/engine/graphics/filter/{FlipArrayInPlace.js → sampler2d_flipY_in_place.js} +1 -1
  122. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.d.ts.map +1 -1
  123. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +5 -27
  124. package/src/engine/graphics/impostors/octahedral/bake/prepare_bake_material.js +3 -3
  125. package/src/engine/graphics/render/Lines.d.ts.map +1 -1
  126. package/src/engine/graphics/render/Lines.js +10 -2
  127. package/src/engine/graphics/sh3/SH3VisualisationMaterial.d.ts.map +1 -1
  128. package/src/engine/graphics/sh3/SH3VisualisationMaterial.js +9 -6
  129. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts +24 -0
  130. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.d.ts.map +1 -0
  131. package/src/engine/graphics/sh3/gi/material/MaterialTransformer.js +293 -0
  132. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts +6 -0
  133. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.d.ts.map +1 -0
  134. package/src/engine/graphics/sh3/gi/material/build_fragment_shader.js +71 -0
  135. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts +6 -0
  136. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.d.ts.map +1 -0
  137. package/src/engine/graphics/sh3/gi/material/build_vertex_shader.js +256 -0
  138. package/src/engine/graphics/sh3/gi/tetrahedral_mesh_to_texture.js +4 -4
  139. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +3 -1
  140. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  141. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +12 -1
  142. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  143. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +4 -5
  144. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts +2 -1
  145. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.d.ts.map +1 -1
  146. package/src/engine/graphics/sh3/lpv/build_probes_for_scene.js +6 -6
  147. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts +8 -0
  148. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.d.ts.map +1 -1
  149. package/src/engine/graphics/sh3/lpv/probe_volume_to_textures.js +3 -2
  150. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  151. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +9 -4
  152. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +3 -3
  153. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  154. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +2 -2
  155. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts +2 -2
  156. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.d.ts.map +1 -1
  157. package/src/engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js +18 -8
  158. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +14 -6
  159. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts +10 -0
  160. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.d.ts.map +1 -0
  161. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples.js +20 -0
  162. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts +10 -0
  163. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.d.ts.map +1 -0
  164. package/src/engine/graphics/sh3/path_tracer/sampling/generate_stratified_samples_2d.js +31 -0
  165. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts +9 -0
  166. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.d.ts.map +1 -0
  167. package/src/engine/graphics/sh3/path_tracer/sampling/make_stratified_sample.js +21 -0
  168. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +1 -1
  169. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.d.ts.map +1 -1
  170. package/src/engine/graphics/sh3/path_tracer/texture/sample_texture.js +2 -3
  171. package/src/engine/graphics/sh3/path_tracer/vec3_uint8_to_float.js +4 -4
  172. package/src/engine/graphics/sh3/prototypeSH3Probe.js +116 -19
  173. package/src/engine/graphics/texture/AttributeDataTexture.d.ts.map +1 -1
  174. package/src/engine/graphics/texture/AttributeDataTexture.js +8 -2
  175. package/src/engine/graphics/texture/computeThreeTextureFormat.js +2 -1
  176. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts +7 -0
  177. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.d.ts.map +1 -0
  178. package/src/engine/graphics/texture/computeThreeTextureFormatFromDataType.js +13 -0
  179. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts +9 -0
  180. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.d.ts.map +1 -0
  181. package/src/engine/graphics/texture/numericTypeFromBinaryDataType.js +31 -0
  182. package/src/engine/graphics/texture/sampler/Sampler2D.d.ts.map +1 -1
  183. package/src/engine/graphics/texture/sampler/Sampler2D.js +4 -4
  184. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  185. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +47 -19
  186. package/src/engine/graphics/texture/sampler/debug/prototypeSamplerFiltering.js +5 -33
  187. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts +11 -0
  188. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.d.ts.map +1 -0
  189. package/src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.js +41 -0
  190. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts +0 -4
  191. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.d.ts.map +1 -1
  192. package/src/engine/graphics/texture/virtual/VirtualTextureUsage.js +19 -30
  193. package/src/engine/network/convertPathToURL.d.ts +3 -1
  194. package/src/engine/network/convertPathToURL.d.ts.map +1 -1
  195. package/src/engine/network/convertPathToURL.js +68 -51
  196. package/src/engine/physics/fluid/SliceVisualiser.d.ts.map +1 -1
  197. package/src/engine/physics/fluid/SliceVisualiser.js +4 -4
  198. package/src/generation/filtering/numeric/CellFilterCache.d.ts.map +1 -1
  199. package/src/generation/filtering/numeric/CellFilterCache.js +1 -0
  200. package/src/core/binary/float2uint8.d.ts +0 -7
  201. package/src/core/binary/float2uint8.d.ts.map +0 -1
  202. package/src/core/binary/uint82float.d.ts +0 -7
  203. package/src/core/binary/uint82float.d.ts.map +0 -1
  204. package/src/core/binary/uint82float.spec.d.ts +0 -2
  205. package/src/core/binary/uint82float.spec.d.ts.map +0 -1
  206. package/src/core/binary/uint82float.spec.js +0 -7
  207. package/src/core/collection/array/randomizeArrayElementOrder.d.ts +0 -8
  208. package/src/core/collection/array/randomizeArrayElementOrder.d.ts.map +0 -1
  209. package/src/core/collection/array/randomizeArrayElementOrder.js +0 -24
  210. package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts +0 -2
  211. package/src/core/collection/array/randomizeArrayElementOrder.spec.d.ts.map +0 -1
  212. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts +0 -8
  213. package/src/engine/graphics/filter/FlipArrayInPlace.d.ts.map +0 -1
  214. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts +0 -3
  215. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.d.ts.map +0 -1
  216. package/src/engine/graphics/sh3/path_tracer/texture/SoftwareTextureCache.js +0 -3
@@ -1,11 +1,15 @@
1
+ import { GUI } from "dat.gui";
1
2
  import {
2
3
  ClampToEdgeWrapping,
3
4
  DataTexture,
4
5
  LinearFilter,
5
6
  MeshBasicMaterial,
7
+ MeshStandardMaterial,
6
8
  NearestFilter,
7
9
  PlaneBufferGeometry,
10
+ RepeatWrapping,
8
11
  RGBAFormat,
12
+ TextureLoader,
9
13
  UnsignedByteType
10
14
  } from "three";
11
15
  import '../../../../../../../css/game.scss';
@@ -13,7 +17,10 @@ import { BinaryBuffer } from "../../../core/binary/BinaryBuffer.js";
13
17
  import { array_copy } from "../../../core/collection/array/array_copy.js";
14
18
  import { is_typed_array_equals } from "../../../core/collection/array/typed/is_typed_array_equals.js";
15
19
  import { Color } from "../../../core/color/Color.js";
20
+ import { kelvin_to_rgb } from "../../../core/color/kelvin/kelvin_to_rgb.js";
21
+ import Quaternion from "../../../core/geom/Quaternion.js";
16
22
  import Vector3 from "../../../core/geom/Vector3.js";
23
+ import { max2 } from "../../../core/math/max2.js";
17
24
  import { randomFloatBetween } from "../../../core/math/random/randomFloatBetween.js";
18
25
  import { seededRandom } from "../../../core/math/random/seededRandom.js";
19
26
  import { number_pretty_print } from "../../../core/primitives/numbers/number_pretty_print.js";
@@ -27,6 +34,8 @@ import ViewportPositionSystem from "../../ecs/gui/position/ViewportPositionSyste
27
34
  import { TransformAttachmentSystem } from "../../ecs/transform-attachment/TransformAttachmentSystem.js";
28
35
  import { Transform } from "../../ecs/transform/Transform.js";
29
36
  import { EngineHarness } from "../../EngineHarness.js";
37
+ import { Camera } from "../ecs/camera/Camera.js";
38
+ import TopDownCameraController from "../ecs/camera/topdown/TopDownCameraController.js";
30
39
  import { Light } from "../ecs/light/Light.js";
31
40
  import LightSystem from "../ecs/light/LightSystem.js";
32
41
  import { LightType } from "../ecs/light/LightType.js";
@@ -37,10 +46,10 @@ import { ShadedGeometryFlags } from "../ecs/mesh-v2/ShadedGeometryFlags.js";
37
46
  import { ShadedGeometrySystem } from "../ecs/mesh-v2/ShadedGeometrySystem.js";
38
47
  import { three_object_to_entity_composition } from "../ecs/mesh-v2/three_object_to_entity_composition.js";
39
48
  import { GizmoRenderingPlugin } from "../render/gizmo/GizmoRenderingPlugin.js";
49
+ import { MaterialTransformer } from "./gi/material/MaterialTransformer.js";
40
50
  import { build_probes_for_scene } from "./lpv/build_probes_for_scene.js";
41
51
  import { LightProbeVolume } from "./lpv/LightProbeVolume.js";
42
52
  import { LightProbeVolumeSerializationAdapter } from "./lpv/LightProbeVolumeSerializationAdapter.js";
43
- import { probe_volume_to_textures } from "./lpv/probe_volume_to_textures.js";
44
53
 
45
54
  /**
46
55
  *
@@ -189,17 +198,22 @@ function make_test_texture(t = 1) {
189
198
  *
190
199
  * @param {Engine} engine
191
200
  * @param {string} path
201
+ * @param {LightProbeVolume} volume
192
202
  * @return {Promise<LightProbeVolume>}
193
203
  */
194
- async function getVolume({ engine, path }) {
204
+ async function getVolume({
205
+ engine,
206
+ path,
207
+ volume = new LightProbeVolume()
208
+ }) {
209
+
210
+ volume.clear();
195
211
 
196
212
  const key = `lpv:${path}`;
197
213
 
198
214
  const adapter = new LightProbeVolumeSerializationAdapter();
199
215
 
200
216
  if (await engine.storage.promiseContains(key)) {
201
- const volume = new LightProbeVolume();
202
-
203
217
  const data = await engine.storage.promiseLoadBinary(key);
204
218
 
205
219
  console.log(`LPV data size ${number_pretty_print(data.byteLength)} bytes`);
@@ -216,11 +230,12 @@ async function getVolume({ engine, path }) {
216
230
 
217
231
  const ecd = engine.entityManager.dataset;
218
232
 
219
- const volume = await build_probes_for_scene({
233
+ await build_probes_for_scene({
234
+ volume,
220
235
  engine,
221
236
  ecd,
222
237
  bounds: mesh_bounds,
223
- density: 10000
238
+ density: 3000
224
239
  });
225
240
 
226
241
  const buffer = new BinaryBuffer();
@@ -234,12 +249,65 @@ async function getVolume({ engine, path }) {
234
249
  return volume;
235
250
  }
236
251
 
252
+ /**
253
+ *
254
+ * @param {number} level
255
+ * @param {EntityComponentDataset} ecd
256
+ * @param {GraphicsEngine} graphics
257
+ */
258
+ function createFloor({ level, ecd, graphics }) {
259
+
260
+ const texture_frequency = 10;
261
+ const size = 1000;
262
+
263
+ const map = new TextureLoader().load('data/textures/utility/checkers_dark_grey_256x256.png', t => {
264
+ map.needsUpdate = true;
265
+
266
+ map.wrapS = RepeatWrapping;
267
+ map.wrapT = RepeatWrapping;
268
+
269
+ map.repeat.set(size / texture_frequency, size / texture_frequency);
270
+
271
+ map.matrixAutoUpdate = true;
272
+ });
273
+
274
+
275
+ const material = graphics.getMaterialManager().obtain(new MeshStandardMaterial({
276
+ map: map
277
+ })).getValue();
278
+
279
+ const geometry = new PlaneBufferGeometry(1, 1, 100, 100);
280
+
281
+ geometry.computeVertexNormals();
282
+ geometry.computeTangents();
283
+
284
+ new Entity()
285
+ .add(Transform.fromJSON({
286
+ position: {
287
+ x: 0,
288
+ y: level,
289
+ z: 0
290
+ },
291
+ rotation: Quaternion.fromEulerAngles(-Math.PI * 0.5, 0, 0),
292
+ scale: size
293
+ }))
294
+ .add(ShadedGeometry.from(geometry, material))
295
+ .build(ecd);
296
+
297
+ }
298
+
237
299
  /**
238
300
  *
239
301
  * @param {Engine} engine
240
302
  * @return {Promise<void>}
241
303
  */
242
304
  async function main(engine) {
305
+ const volume = new LightProbeVolume();
306
+
307
+ const transformer = new MaterialTransformer({ volume });
308
+
309
+ engine.graphics.getMaterialManager().addCompileStep(transformer);
310
+
243
311
  await EngineHarness.buildBasics({
244
312
  engine,
245
313
  enableWater: false,
@@ -254,13 +322,18 @@ async function main(engine) {
254
322
  // shadowmapResolution: 4096
255
323
  });
256
324
 
325
+ const sun_color = new Color();
326
+
327
+ kelvin_to_rgb(sun_color, 0, 6000);
328
+
257
329
  await EngineHarness.buildLights({
258
330
  engine,
259
331
  shadowmapResolution: 4096,
260
- ambientIntensity: 0.03,
261
- sun: Color.white,
262
- sunIntensity: 17,
263
- sunDirection: new Vector3(0.5, -1, 0.3)
332
+ ambientIntensity: 0.0,
333
+ sun: sun_color,
334
+ sunIntensity: 1.7,
335
+ // sunDirection: new Vector3(0.5, -1, 0.3)
336
+ sunDirection: new Vector3(1.2, -1,0.2 )
264
337
  })
265
338
 
266
339
  engine.graphics.getRenderer().setClearColor('#1e3441', 1);
@@ -272,16 +345,29 @@ async function main(engine) {
272
345
 
273
346
  // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
274
347
  // const path = 'data/models/sibenik/2/model.gltf';
275
- // const path = 'data/models/sibenik/3-window-less/model.gltf';
276
348
  // const path = 'data/models/vokselia_spawn/model.gltf';
277
- const path = 'data/models/sponza-pbr/gltf/sponza.glb';
278
349
  // const path = 'data/models/LowPolyTownshipSet/Town_Hall/model.gltf';
279
- // const path = 'data/models/Slaughter Mech/Slaugter Mech.gltf';
280
350
  // const path = 'data/models/pica_pica/pica_pica.gltf';
351
+ // const path = 'data/models/samples/low_poly_classroom/no-glass/model.gltf';
352
+ // const path = 'data/models/samples/just_a_girl/scene.gltf';
353
+ // const path = 'data/models/samples/slum_house/scene.gltf';
354
+ // const path = 'data/models/samples/jack_trigger/scene.gltf';
355
+ // const path = 'data/models/samples/cornell_box/scene.gltf';
356
+ // const path = 'data/models/samples/cyberpunk_bike/scene.gltf';
357
+ // const path = 'data/models/samples/sd_macross_city_standoff_diorama/scene.gltf';
358
+ // const path = 'data/models/Slaughter Mech/Slaugter Mech.gltf';
359
+ const path = 'data/models/sponza-pbr/gltf/sponza.glb';
360
+ // const path = 'data/models/samples/gi_box_01/model.glb';
361
+ // const path = 'data/models/samples/gi_box_01/model-thick-1.glb';
362
+ // const path = 'data/models/sibenik/3-window-less/model.gltf';
281
363
 
282
364
  const mesh_asset = await engine.assetManager.promise(path, 'model/gltf+json');
283
365
  const gltf = mesh_asset.gltf;
284
366
 
367
+ console.log(gltf);
368
+
369
+ // add floor
370
+
285
371
  // make_cornel_box(ecd);
286
372
 
287
373
  const mesh_entity = new Entity();
@@ -290,6 +376,11 @@ async function main(engine) {
290
376
  .add(SGMesh.fromURL(path))
291
377
  ;
292
378
 
379
+ createFloor({
380
+ level: mesh_asset.boundingBox.y0,
381
+ ecd,
382
+ graphics: engine.graphics
383
+ });
293
384
 
294
385
  const composition = three_object_to_entity_composition(gltf.scene);
295
386
 
@@ -307,6 +398,8 @@ async function main(engine) {
307
398
  });
308
399
 
309
400
  composition.transform.scale.setScalar(1);
401
+ //
402
+ // composition.transform.rotation.fromEulerAngles(0, Math.PI, 0);
310
403
 
311
404
  composition.build(ecd);
312
405
 
@@ -317,6 +410,10 @@ async function main(engine) {
317
410
  const model_footprint = Math.hypot(mesh_bounds.getExtentsX(), mesh_bounds.getExtentsY(), mesh_bounds.getExtentsZ());
318
411
 
319
412
 
413
+ const camera = ecd.getAnyComponent(Camera);
414
+ camera.component.clip_far = max2(100, model_footprint);
415
+ ecd.getComponent(camera.entity, TopDownCameraController).distanceMax = model_footprint * 1.1;
416
+
320
417
  const random = seededRandom();
321
418
 
322
419
  for (let i = 0; i < 0; i++) {
@@ -351,21 +448,21 @@ async function main(engine) {
351
448
 
352
449
  console.time('getVolume');
353
450
  // console.profile('getVolume');
354
- const volume = await getVolume({ engine, path });
451
+ await getVolume({ engine, path, volume });
355
452
  // console.profileEnd('getVolume');
356
453
  console.timeEnd('getVolume');
357
454
 
358
455
  console.log('LPV:', volume);
359
456
 
457
+ transformer.update();
458
+
360
459
 
361
460
  volume.visualize_probes({ ecd, size: model_footprint * 0.002 });
362
- // volume.visualize_mesh({ ecd , opacity: 0.2});
461
+ // volume.visualize_mesh({ ecd, opacity: 0.5 });
363
462
 
364
- console.time('prepareTextures');
365
- const textures = probe_volume_to_textures(volume);
366
- console.timeEnd('prepareTextures');
463
+ new GUI()
464
+ .add(transformer, 'intensity').min(0).max(10);
367
465
 
368
- console.log(textures);
369
466
 
370
467
  // mesh_entity.addEventListener(SGMeshEvents.AssetLoaded, build);
371
468
  //
@@ -1 +1 @@
1
- {"version":3,"file":"AttributeDataTexture.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/AttributeDataTexture.js"],"names":[],"mappings":"AAYA;IAwRI;;;;;;OAMG;IACH,+CAHW,MAAM,cACN,MAAM,GAHL,oBAAoB,CAO/B;IAhSD;;;;;OAKG;IACH,+CAHW,MAAM,cACN,MAAM,EA2ChB;IA/BG;;;;OAIG;IACH,eAAkB;IAElB,mBAAoB;IAEpB;;;;OAIG;IACH,uBAAkC;IAElC;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,qBAA8B;IAKlC;;;OAGG;IACH,0BAEC;IAED,cASC;IAED,0BAGC;IAED,2BAEC;IAED;;;OAGG;IACH,mBAFW,MAAM,QAwChB;IAED,cA4BC;IAED;;;;;;OAMG;IACH,yBALW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,GACN,OAAO,CAoCnB;IAED;;;;;OAKG;IACH,8BAJW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,QAmClB;IAED;;;OAGG;IACH,sBAFW,MAAM,QAgBhB;IAED;;;OAGG;IACH,sCAEC;IAED;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,oBAFY,MAAM,CAIjB;CAYJ;4BA9S0C,OAAO"}
1
+ {"version":3,"file":"AttributeDataTexture.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/AttributeDataTexture.js"],"names":[],"mappings":"AAaA;IA6RI;;;;;;OAMG;IACH,+CAHW,MAAM,cACN,MAAM,GAHL,oBAAoB,CAO/B;IArSD;;;;;OAKG;IACH,+CAHW,MAAM,cACN,MAAM,EA2ChB;IA/BG;;;;OAIG;IACH,eAAkB;IAElB,mBAAoB;IAEpB;;;;OAIG;IACH,uBAAkC;IAElC;;;;OAIG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,qBAA8B;IAKlC;;;OAGG;IACH,0BAEC;IAED,cASC;IAED,0BAGC;IAED,2BAEC;IAED;;;OAGG;IACH,mBAFW,MAAM,QAwChB;IAED,cAiCC;IAED;;;;;;OAMG;IACH,yBALW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,GACN,OAAO,CAoCnB;IAED;;;;;OAKG;IACH,8BAJW,MAAM,WACN,MAAM,EAAE,UACR,MAAM,EAAE,QAmClB;IAED;;;OAGG;IACH,sBAFW,MAAM,QAgBhB;IAED;;;OAGG;IACH,sCAEC;IAED;;;OAGG;IACH,2BAEC;IAED;;;OAGG;IACH,oBAFY,MAAM,CAIjB;CAYJ;4BApT0C,OAAO"}
@@ -5,7 +5,8 @@ import {
5
5
  } from "../../../core/binary/type/DataType2TypedArrayConstructorMapping.js";
6
6
  import { DataTypeByteSizes } from "../../../core/binary/type/DataTypeByteSizes.js";
7
7
  import { typed_array_copy } from "../../../core/collection/array/typed/typed_array_copy.js";
8
- import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
8
+
9
+ import { computeThreeTextureFormatFromDataType } from "./computeThreeTextureFormatFromDataType.js";
9
10
  import { computeThreeTextureInternalFormatFromDataType } from "./computeThreeTextureInternalFormatFromDataType.js";
10
11
  import { computeThreeTextureTypeFromDataType } from "./computeThreeTextureTypeFromDataType.js";
11
12
  import { normalized_internal_format } from "./normalized_internal_format.js";
@@ -140,7 +141,7 @@ export class AttributeDataTexture {
140
141
  const width = this.computeSlotWidth() * this.__column_count;
141
142
  const height = Math.ceil(this.__capacity / this.__column_count);
142
143
 
143
- const format = channelCountToThreeTextureFormat(spec.itemSize);
144
+ const format = computeThreeTextureFormatFromDataType(spec.type, spec.itemSize);
144
145
  const type = computeThreeTextureTypeFromDataType(spec.type);
145
146
 
146
147
  const array = new TypedArray(width * height * spec.itemSize);
@@ -151,12 +152,17 @@ export class AttributeDataTexture {
151
152
  texture.generateMipmaps = false;
152
153
  texture.minFilter = texture.magFilter = NearestFilter;
153
154
 
155
+ texture.format = format;
156
+ texture.type = type;
157
+
154
158
  if (spec.normalized) {
155
159
  texture.internalFormat = normalized_internal_format(spec.type, spec.itemSize);
156
160
  } else {
157
161
  texture.internalFormat = computeThreeTextureInternalFormatFromDataType(spec.type, spec.itemSize);
158
162
  }
159
163
 
164
+ texture.needsUpdate = true;
165
+
160
166
  this.__texture = texture;
161
167
 
162
168
 
@@ -1,6 +1,6 @@
1
1
  import { NumericType } from "../../../core/math/NumericType.js";
2
- import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
3
2
  import { channelCountToThreeTextureFormat } from "./channelCountToThreeTextureFormat.js";
3
+ import { channelCountToThreIntegerTextureType } from "./channelCountToThreIntegerTextureType.js";
4
4
 
5
5
  /**
6
6
  *
@@ -16,3 +16,4 @@ export function computeThreeTextureFormat(type, channel_count) {
16
16
  throw new Error(`Unsupported numeric type '${type}'`);
17
17
  }
18
18
  }
19
+
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @param {BinaryDataType} dt
4
+ * @param {number} channel_count
5
+ */
6
+ export function computeThreeTextureFormatFromDataType(dt: BinaryDataType, channel_count: number): number | import("three").PixelFormat;
7
+ //# sourceMappingURL=computeThreeTextureFormatFromDataType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"computeThreeTextureFormatFromDataType.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/computeThreeTextureFormatFromDataType.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,yFAFW,MAAM,wCAMhB"}
@@ -0,0 +1,13 @@
1
+ import { computeThreeTextureFormat } from "./computeThreeTextureFormat.js";
2
+ import { numericTypeFromBinaryDataType } from "./numericTypeFromBinaryDataType.js";
3
+
4
+ /**
5
+ *
6
+ * @param {BinaryDataType} dt
7
+ * @param {number} channel_count
8
+ */
9
+ export function computeThreeTextureFormatFromDataType(dt, channel_count) {
10
+ const numeric_type = numericTypeFromBinaryDataType(dt);
11
+
12
+ return computeThreeTextureFormat(numeric_type, channel_count);
13
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ *
3
+ * @param {BinaryDataType} dt
4
+ * @returns {NumericType}
5
+ */
6
+ export function numericTypeFromBinaryDataType(dt: BinaryDataType): NumericType;
7
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
8
+ import { NumericType } from "../../../core/math/NumericType.js";
9
+ //# sourceMappingURL=numericTypeFromBinaryDataType.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numericTypeFromBinaryDataType.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/numericTypeFromBinaryDataType.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,kDAHW,cAAc,GACZ,WAAW,CAwBvB;+BA9B8B,6CAA6C;4BAChD,mCAAmC"}
@@ -0,0 +1,31 @@
1
+ import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
2
+ import { NumericType } from "../../../core/math/NumericType.js";
3
+
4
+ /**
5
+ *
6
+ * @param {BinaryDataType} dt
7
+ * @returns {NumericType}
8
+ */
9
+ export function numericTypeFromBinaryDataType(dt) {
10
+
11
+ switch (dt) {
12
+ case BinaryDataType.Uint8:
13
+ case BinaryDataType.Uint16:
14
+ case BinaryDataType.Uint32:
15
+ return NumericType.Uint
16
+
17
+ case BinaryDataType.Int8:
18
+ case BinaryDataType.Int16:
19
+ case BinaryDataType.Int32:
20
+ return NumericType.Int;
21
+
22
+ case BinaryDataType.Float16:
23
+ case BinaryDataType.Float32:
24
+ case BinaryDataType.Float64:
25
+ return NumericType.Float;
26
+
27
+ default:
28
+ throw new Error(`Unsupported data type '${dt}'`);
29
+ }
30
+
31
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/Sampler2D.js"],"names":[],"mappings":"AAeA;;;;GAIG;AACH;IAk8BI;;;;;;OAMG;IACH,6DAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,sDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,uDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,uDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,qDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,sDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,sDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,wDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,wDAFY,SAAS,CAKpB;IA3iCD;;;;;;;OAOG;IACH,mBANW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,iBAAiB,GAAC,UAAU,GAAC,WAAW,GAAC,WAAW,GAAC,SAAS,GAAC,UAAU,GAAC,UAAU,GAAC,YAAY,GAAC,YAAY,aACzI,MAAM,UACN,MAAM,WACN,MAAM,EAmDhB;IA7BG;;;OAGG;IACH,cAAkB;IAElB;;;OAGG;IACH,eAAoB;IAEpB;;;OAGG;IACH,iBAAwB;IAExB;;;OAGG;IACH,MAFU,MAAM,EAAE,GAAC,iBAAiB,GAAC,UAAU,GAAC,WAAW,GAAC,WAAW,GAAC,SAAS,GAAC,UAAU,GAAC,UAAU,GAAC,YAAY,GAAC,YAAY,CAEjH;IAEhB;;;OAGG;IACH,SAFU,MAAM,CAEA;IAGpB;;;;;;;OAOG;IACH,OALW,MAAM,KACN,MAAM,UACN,qCAA+B,GAC7B,MAAM,CAIlB;IAED;;;;;OAKG;IACH,sBAJW,MAAM,KACN,MAAM,UACN,MAAM,EAAE,QAQlB;IAED;;;;;;OAMG;IACH,6BALW,MAAM,KACN,MAAM,WACN,MAAM,GACJ,MAAM,CAOlB;IAED;;;;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S,qHAoDnB;IAGD;;;;;;;OAOG;IACH,oEA8BC;IAED;;;;OAIG;IACH,2BAHW,MAAM,SACN,MAAM,QAYhB;IAED;;;;;;;OAOG;IACH,iEAFW,aAAc,QAqCxB;IAED;;;;;;OAMG;IACH,gBALW,MAAM,KACN,MAAM,WACN,MAAM,SACN,MAAM,QAqBhB;IAED;;;;;OAKG;IACH,OAJW,MAAM,KACN,MAAM,SACN,MAAM,EAAE,GAAC,YAAY,QAe/B;IAED;;;;;;;OAOG;IACH,wBALW,MAAM,WACN,MAAM,UACN,MAAM,sBAyBhB;IAED;;;;;OAKG;IACH,UAJW,MAAM,KACN,MAAM,iBACN,OAAO,QAyDjB;IAED;;;OAGG;IACH,mBAFY,MAAM,CAYjB;IAED;;;;OAIG;IACH,cAHW,SAAS,GACR,OAAO,CAYlB;IAED;;;OAGG;IACH,QAFY,MAAM,CAYjB;IAGD;;OAEG;IACH,SAFa,SAAS,CAerB;IAED;;;;;;MAUC;IAED;;;;;;aAwBC;IAgHL;;;OAGG;IACH,sBAFU,OAAO,CAEc;CAN9B;;kBAUS,MAAM"}
1
+ {"version":3,"file":"Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/Sampler2D.js"],"names":[],"mappings":"AAeA;;;;GAIG;AACH;IAk8BI;;;;;;OAMG;IACH,6DAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,sDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,uDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,uDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,qDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,sDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,sDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,wDAFY,SAAS,CAKpB;IAED;;;;;;OAMG;IACH,wDAFY,SAAS,CAKpB;IA3iCD;;;;;;;OAOG;IACH,mBANW,UAAU,MAAM,CA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;OAGG;IACH,QAFY,MAAM,CAYjB;IAGD;;OAEG;IACH,SAFa,SAAS,CAerB;IAED;;;;;;MAUC;IAED;;;;;;aAwBC;IAgHL;;;OAGG;IACH,sBAFU,OAAO,CAEc;CAN9B;;kBAUS,MAAM"}
@@ -321,7 +321,7 @@ export class Sampler2D {
321
321
  *
322
322
  * @param {number} u
323
323
  * @param {number} v
324
- * @param {number[]} result
324
+ * @param {number[]|Float32Array} result
325
325
  * @param {number} result_offset
326
326
  */
327
327
  sampleBilinearUV(u, v, result, result_offset = 0) {
@@ -396,8 +396,8 @@ export class Sampler2D {
396
396
  const clamped_x = clamp(x, 0, x_max);
397
397
  const clamped_y = clamp(y, 0, y_max);
398
398
 
399
- const x0 = clamped_x | 0;
400
- const y0 = clamped_y | 0;
399
+ const x0 = clamped_x >>> 0;
400
+ const y0 = clamped_y >>> 0;
401
401
 
402
402
  //
403
403
  const row0 = y0 * rowSize;
@@ -458,7 +458,7 @@ export class Sampler2D {
458
458
  *
459
459
  * @param {number} u
460
460
  * @param {number} v
461
- * @param {ArrayLike<number>} result
461
+ * @param {number[]|ArrayLike<number>} result
462
462
  */
463
463
  sampleNearestUV(u, v, result) {
464
464
  const w = this.width;
@@ -1 +1 @@
1
- {"version":3,"file":"convertTexture2Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js"],"names":[],"mappings":"AAUA;;;;;;;GAOG;AACH,mEALW,MAAM,WACN,MAAM,UACN,OAAO,GACN,SAAS,CAyEpB;0BArFyB,gBAAgB"}
1
+ {"version":3,"file":"convertTexture2Sampler2D.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,mEALW,MAAM,WACN,MAAM,UACN,OAAO,GACN,SAAS,CAkGpB;0BA/GyB,gBAAgB"}
@@ -1,8 +1,11 @@
1
- import { flipArrayInPlace } from "../../filter/FlipArrayInPlace.js";
2
1
  import ImageFilter from "../../filter/ImageFilter.js";
2
+ import { sampler2d_flipY_in_place } from "../../filter/sampler2d_flipY_in_place.js";
3
3
  import CopyShader from "../../postprocess/threejs/shaders/CopyShader.js";
4
4
  import { WebGLRendererPool } from "../../render/RendererPool.js";
5
+ import { formatToChannelCount } from "../formatToChannelCount.js";
6
+ import { sampler2d_scale } from "./resize/sampler2d_scale.js";
5
7
  import { Sampler2D } from "./Sampler2D.js";
8
+ import { sampler2d_ensure_uint8_RGBA } from "./sampler2d_ensure_uint8_RGBA.js";
6
9
 
7
10
 
8
11
  const DEFAULT_TEXTURE_WIDTH = 512;
@@ -25,6 +28,8 @@ export function convertTexture2Sampler2D(
25
28
  let _height = height;
26
29
  let _width = width;
27
30
 
31
+ const channel_count = formatToChannelCount(texture.format);
32
+
28
33
  // TODO take channel count into account
29
34
 
30
35
  if (_width === undefined || _height === undefined) {
@@ -59,32 +64,55 @@ export function convertTexture2Sampler2D(
59
64
 
60
65
  }
61
66
 
62
- // TODO add special case for DataTexture
63
67
 
64
- const built = WebGLRendererPool.global.use(renderer => {
68
+ let data;
65
69
 
66
- const ctx = renderer.getContext();
70
+ if (texture.isDataTexture === true) {
67
71
 
68
- //support for compressed textures
69
- ctx.getExtension("WEBGL_compressed_texture_s3tc");
72
+ // special case
73
+
74
+ const source = new Sampler2D(texture.image.data, channel_count, texture.image.width, texture.image.height);
75
+
76
+ let converted = sampler2d_ensure_uint8_RGBA(source);
77
+
78
+ if (converted.width !== _width || converted.height !== _height) {
79
+ const target = Sampler2D.uint8(4, _width, _height);
80
+
81
+ sampler2d_scale(converted, target);
82
+
83
+ converted = target;
84
+ }
85
+
86
+ data = converted.data;
87
+
88
+ } else {
89
+ const built = WebGLRendererPool.global.use(renderer => {
90
+
91
+ const ctx = renderer.getContext();
92
+
93
+ //support for compressed textures
94
+ ctx.getExtension("WEBGL_compressed_texture_s3tc");
95
+
96
+ return ImageFilter(renderer, _width, _height, {
97
+ vertexShader: CopyShader.vertexShader,
98
+ fragmentShader: CopyShader.fragmentShader,
99
+ uniforms: {
100
+ tDiffuse: {
101
+ value: texture,
102
+ type: 't'
103
+ },
104
+ opacity: { value: 1.0 }
105
+ }
106
+ });
70
107
 
71
- return ImageFilter(renderer, _width, _height, {
72
- vertexShader: CopyShader.vertexShader,
73
- fragmentShader: CopyShader.fragmentShader,
74
- uniforms: {
75
- tDiffuse: {
76
- value: texture,
77
- type: 't'
78
- },
79
- opacity: { value: 1.0 }
80
- }
81
108
  });
82
109
 
83
- });
110
+ data = built.array;
111
+ }
84
112
 
85
113
  if (flipY) {
86
- flipArrayInPlace(built.array, _width, _height);
114
+ sampler2d_flipY_in_place(data, _width, _height);
87
115
  }
88
116
 
89
- return new Sampler2D(built.array, 4, _width, _height);
117
+ return new Sampler2D(data, 4, _width, _height);
90
118
  }
@@ -16,6 +16,7 @@ import { sampler2d_scale_down_lanczos } from "../resize/sampler2d_scale_down_lan
16
16
  import { sampler2d_scale_down_mipmap } from "../resize/sampler2d_scale_down_mipmap.js";
17
17
  import { sampler2d_scale_generic } from "../resize/sampler2d_scale_generic.js";
18
18
  import { Sampler2D } from "../Sampler2D.js";
19
+ import { sampler2d_copy_rectangle } from "../sampler2d_copy_rectangle.js";
19
20
  import { debug_draw_sampler } from "./debug_draw_sampler.js";
20
21
  import { debug_draw_sampler_grid } from "./debug_draw_sampler_grid.js";
21
22
 
@@ -35,40 +36,11 @@ function setup_zoom_preview({ engine, sampler }) {
35
36
 
36
37
  const preview_container = debug_draw_sampler(engine, preview, 0, sampler.height);
37
38
  preview_container.transformOrigin.set(0, 0);
38
- // preview_container.scale.setScalar(20);
39
-
40
- /**
41
- *
42
- * @param {Sampler2D} source
43
- * @param {Sampler2D} target
44
- * @param {number} u0
45
- * @param {number} v0
46
- * @param {number} u1
47
- * @param {number} v1
48
- */
49
- function update_preview(
50
- source, target,
51
- u0, v0, u1, v1
52
- ) {
53
-
54
- const sample = [];
55
-
56
- for (let y = 0; y < target.height; y++) {
57
- for (let x = 0; x < target.width; x++) {
58
-
59
- const local_u = x / target.width;
60
- const local_v = y / target.height;
61
39
 
62
- source.sampleBilinearUV(local_u * (u1 - u0) + u0, local_v * (v1 - v0) + v0, sample);
63
-
64
- target.write(x, y, sample);
65
-
66
- }
67
- }
40
+ // preview_container.scale.setScalar(20);
68
41
 
69
- }
70
42
 
71
- function setPreviewPosition(x,y){
43
+ function setPreviewPosition(x, y) {
72
44
  const window_size = 0.1;
73
45
 
74
46
 
@@ -81,7 +53,7 @@ function setup_zoom_preview({ engine, sampler }) {
81
53
  const center_v = clamp(v, w_2, 1 - w_2);
82
54
 
83
55
 
84
- update_preview(
56
+ sampler2d_copy_rectangle(
85
57
  sampler, preview,
86
58
  center_u - w_2, center_v - w_2,
87
59
  center_u + w_2, center_v + w_2
@@ -89,7 +61,7 @@ function setup_zoom_preview({ engine, sampler }) {
89
61
 
90
62
  preview_container.$redraw();
91
63
 
92
- console.log(x,y);
64
+ console.log(x, y);
93
65
  }
94
66
 
95
67
  // setPreviewPosition(366,420);
@@ -0,0 +1,11 @@
1
+ /**
2
+ *
3
+ * @param {Sampler2D} source
4
+ * @param {Sampler2D} target
5
+ * @param {number} u0
6
+ * @param {number} v0
7
+ * @param {number} u1
8
+ * @param {number} v1
9
+ */
10
+ export function sampler2d_copy_rectangle(source: Sampler2D, target: Sampler2D, u0: number, v0: number, u1: number, v1: number): void;
11
+ //# sourceMappingURL=sampler2d_copy_rectangle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler2d_copy_rectangle.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/sampler2d_copy_rectangle.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,mFALW,MAAM,MACN,MAAM,MACN,MAAM,MACN,MAAM,QAiChB"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ *
3
+ * @param {Sampler2D} source
4
+ * @param {Sampler2D} target
5
+ * @param {number} u0
6
+ * @param {number} v0
7
+ * @param {number} u1
8
+ * @param {number} v1
9
+ */
10
+ export function sampler2d_copy_rectangle(
11
+ source, target,
12
+ u0, v0, u1, v1
13
+ ) {
14
+
15
+ const sample = [];
16
+
17
+ const target_height = target.height;
18
+ const target_width = target.width;
19
+
20
+ const v_span = v1 - v0;
21
+ const u_span = u1 - u0;
22
+
23
+ const v_multiplier = v_span / target_height;
24
+ const u_multiplier = u_span / target_width;
25
+
26
+ for (let y = 0; y < target_height; y++) {
27
+
28
+ const source_v = y * v_multiplier + v0;
29
+
30
+ for (let x = 0; x < target_width; x++) {
31
+
32
+ const source_u = x * u_multiplier + u0;
33
+
34
+ source.sampleBilinearUV(source_u, source_v, sample);
35
+
36
+ target.write(x, y, sample);
37
+
38
+ }
39
+ }
40
+
41
+ }