@woosh/meep-engine 2.108.3 → 2.109.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 (130) hide show
  1. package/build/meep.cjs +91 -60
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +91 -60
  4. package/package.json +1 -1
  5. package/src/core/assert.d.ts +2 -2
  6. package/src/core/assert.d.ts.map +1 -1
  7. package/src/core/assert.js +1 -1
  8. package/src/core/binary/align_4.spec.d.ts +2 -0
  9. package/src/core/binary/align_4.spec.d.ts.map +1 -0
  10. package/src/core/binary/align_4.spec.js +20 -0
  11. package/src/core/binary/{de_interleave_bits_by_2.d.ts → de_interleave_2_bits.d.ts} +1 -1
  12. package/src/core/binary/de_interleave_2_bits.d.ts.map +1 -0
  13. package/src/core/binary/de_interleave_2_bits.spec.js +1 -1
  14. package/src/core/binary/hex2dec.spec.d.ts +2 -0
  15. package/src/core/binary/hex2dec.spec.d.ts.map +1 -0
  16. package/src/core/binary/hex2dec.spec.js +22 -0
  17. package/src/core/binary/split_by_2.spec.d.ts +2 -0
  18. package/src/core/binary/split_by_2.spec.d.ts.map +1 -0
  19. package/src/core/binary/split_by_2.spec.js +22 -0
  20. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts +4 -1
  21. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
  22. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +16 -7
  23. package/src/core/bvh2/bvh3/ebvh_build_hierarchy.js +1 -1
  24. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.d.ts.map +1 -1
  25. package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +12 -7
  26. package/src/core/geom/2d/circle/circle_circumference.d.ts +7 -0
  27. package/src/core/geom/2d/circle/circle_circumference.d.ts.map +1 -0
  28. package/src/core/geom/2d/circle/circle_circumference.js +12 -0
  29. package/src/core/geom/2d/compute_polygon_area_2d.d.ts.map +1 -1
  30. package/src/core/geom/2d/compute_polygon_area_2d.js +6 -4
  31. package/src/core/geom/2d/lt-grid/LooseTightGrid.js +1 -1
  32. package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +2 -2
  33. package/src/core/geom/2d/triangle2d_get_barycentric.js +2 -2
  34. package/src/core/geom/3d/Ray3.d.ts +19 -0
  35. package/src/core/geom/3d/Ray3.d.ts.map +1 -0
  36. package/src/core/geom/3d/Ray3.js +27 -0
  37. package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.d.ts +10 -0
  38. package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.d.ts.map +1 -0
  39. package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.js +35 -0
  40. package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.d.ts +1 -0
  41. package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.d.ts.map +1 -0
  42. package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.js +0 -0
  43. package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.d.ts +9 -0
  44. package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.d.ts.map +1 -0
  45. package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.js +25 -0
  46. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
  47. package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +2 -4
  48. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts +8 -0
  49. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts.map +1 -0
  50. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.js +94 -0
  51. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts +8 -0
  52. package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts.map +1 -0
  53. package/src/core/geom/3d/sphere/harmonics/{sh3_rotate.js → sh3_rotate_filament.js} +5 -2
  54. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +3 -3
  55. package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +3 -3
  56. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -1
  57. package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +29 -14
  58. package/src/core/geom/Quaternion.js +1 -1
  59. package/src/core/geom/vec3/v3_matrix4_multiply.d.ts +10 -0
  60. package/src/core/geom/vec3/v3_matrix4_multiply.d.ts.map +1 -0
  61. package/src/core/geom/vec3/v3_matrix4_multiply.js +27 -0
  62. package/src/core/geom/vec3/v3_shift_along_direction.d.ts +14 -0
  63. package/src/core/geom/vec3/v3_shift_along_direction.d.ts.map +1 -0
  64. package/src/core/geom/vec3/v3_shift_along_direction.js +23 -0
  65. package/src/core/math/compute_legendre_polynomial.d.ts +10 -0
  66. package/src/core/math/compute_legendre_polynomial.d.ts.map +1 -0
  67. package/src/core/math/compute_legendre_polynomial.js +46 -0
  68. package/src/core/math/statistics/softmax.d.ts +11 -0
  69. package/src/core/math/statistics/softmax.d.ts.map +1 -0
  70. package/src/core/math/statistics/softmax.js +24 -0
  71. package/src/core/math/statistics/softmax.spec.d.ts +2 -0
  72. package/src/core/math/statistics/softmax.spec.d.ts.map +1 -0
  73. package/src/core/math/statistics/softmax.spec.js +9 -0
  74. package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
  75. package/src/engine/ecs/transform/Transform.js +19 -4
  76. package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
  77. package/src/engine/graphics/ecs/camera/CameraSystem.js +25 -13
  78. package/src/engine/graphics/geometry/decode_attribute_value.d.ts +10 -0
  79. package/src/engine/graphics/geometry/decode_attribute_value.d.ts.map +1 -0
  80. package/src/engine/graphics/geometry/decode_attribute_value.js +28 -0
  81. package/src/engine/graphics/geometry/geometry_construct_triangle_normal.d.ts +11 -0
  82. package/src/engine/graphics/geometry/geometry_construct_triangle_normal.d.ts.map +1 -0
  83. package/src/engine/graphics/geometry/geometry_construct_triangle_normal.js +31 -0
  84. package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
  85. package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +0 -86
  86. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +1 -0
  87. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -1
  88. package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +6 -2
  89. package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.d.ts → BufferedGeometryBVH.d.ts} +9 -2
  90. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -0
  91. package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.js → BufferedGeometryBVH.js} +84 -5
  92. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts +6 -4
  93. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
  94. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +54 -8
  95. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +6 -10
  96. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  97. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +41 -47
  98. package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts +11 -0
  99. package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -0
  100. package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +102 -0
  101. package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts +9 -0
  102. package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts.map +1 -0
  103. package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js +17 -0
  104. package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.d.ts +31 -0
  105. package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.d.ts.map +1 -0
  106. package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.js +85 -0
  107. package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.d.ts +14 -0
  108. package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.d.ts.map +1 -0
  109. package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.js +17 -0
  110. package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.d.ts +7 -0
  111. package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.d.ts.map +1 -0
  112. package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.js +9 -0
  113. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +104 -9
  114. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +1 -2
  115. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
  116. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +50 -23
  117. package/src/engine/graphics/sh3/prototypeSH3Probe.js +62 -28
  118. package/src/engine/graphics/texture/formatToChannelCount.d.ts.map +1 -1
  119. package/src/engine/graphics/texture/formatToChannelCount.js +8 -1
  120. package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.d.ts +8 -0
  121. package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.d.ts.map +1 -0
  122. package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.js +10 -0
  123. package/src/engine/graphics/texture/sampler/sampler_multiply_vector.d.ts +8 -0
  124. package/src/engine/graphics/texture/sampler/sampler_multiply_vector.d.ts.map +1 -0
  125. package/src/engine/graphics/texture/sampler/sampler_multiply_vector.js +23 -0
  126. package/src/core/binary/de_interleave_bits_by_2.d.ts.map +0 -1
  127. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +0 -8
  128. package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +0 -1
  129. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.d.ts.map +0 -1
  130. /package/src/core/binary/{de_interleave_bits_by_2.js → de_interleave_2_bits.js} +0 -0
@@ -34,6 +34,7 @@ import { Transform } from "../../../ecs/transform/Transform.js";
34
34
  import { MouseEvents } from "../../../input/devices/events/MouseEvents.js";
35
35
  import { makeSimpleTaskProgressView } from "../../../makeSimpleTaskProgressView.js";
36
36
  import { Camera } from "../../ecs/camera/Camera.js";
37
+ import { three_camera_set_transform_rotation } from "../../ecs/camera/CameraSystem.js";
37
38
  import { makeGeometryIndexed } from "../../geometry/buffered/makeGeometryIndexed.js";
38
39
  import { DirectionalLight } from "../../render/forward_plus/model/DirectionalLight.js";
39
40
  import { sampler2d_scale } from "../../texture/sampler/resize/sampler2d_scale.js";
@@ -73,7 +74,7 @@ vCanvas.css({
73
74
  * How many rays to use per-pixel
74
75
  * @type {number}
75
76
  */
76
- const PIXEL_SAMPLE_COUNT = 64;
77
+ const PIXEL_SAMPLE_COUNT = 256;
77
78
 
78
79
  const scene = new PathTracedScene();
79
80
  const pt = new PathTracer();
@@ -164,10 +165,19 @@ function promise_gltf(url) {
164
165
  * @param {PathTracedScene} scene
165
166
  * @param {THREE.Camera} camera
166
167
  * @param {string} url
167
- * @param zoom
168
+ * @param {number} [zoom]
169
+ * @param {number} [floor_level]
170
+ * @param {Object} [sun]
168
171
  * @return {Promise<void>}
169
172
  */
170
- async function prepare_scene_gltf(scene, camera, url, zoom = 1) {
173
+ async function prepare_scene_gltf({
174
+ scene,
175
+ camera,
176
+ url,
177
+ zoom = 1,
178
+ floor_level = 0,
179
+ sun
180
+ }) {
171
181
  const gltf = await promise_gltf(url);
172
182
 
173
183
 
@@ -175,7 +185,7 @@ async function prepare_scene_gltf(scene, camera, url, zoom = 1) {
175
185
  color: '#ffceae'
176
186
  });
177
187
  scene.addMesh(new PlaneBufferGeometry(), ground_material, Transform.fromJSON({
178
- position: new Vector3(0, 0, 0),
188
+ position: new Vector3(0, floor_level, 0),
179
189
  scale: 5000,
180
190
  rotation: Quaternion.fromEulerAngles(-Math.PI / 2, 0, 0)
181
191
  }).matrix);
@@ -196,7 +206,7 @@ async function prepare_scene_gltf(scene, camera, url, zoom = 1) {
196
206
 
197
207
  box3.getBoundingSphere(sphere);
198
208
 
199
- scene.addLight(make_sun());
209
+ scene.addLight(make_sun(sun));
200
210
 
201
211
  camera.position.set(1, 1.3, 1)
202
212
  .normalize()
@@ -241,6 +251,88 @@ async function prepare_scene_lucy(scene, camera) {
241
251
  camera.lookAt(0, 0, 0);
242
252
  }
243
253
 
254
+
255
+ /**
256
+ *
257
+ * @param {THREE.Camera} camera
258
+ * @param {Transform} transform
259
+ */
260
+ function set_camera_from_transform(camera, transform) {
261
+ camera.position.copy(transform.position);
262
+ three_camera_set_transform_rotation(camera, transform.rotation);
263
+
264
+ camera.updateMatrixWorld();
265
+ }
266
+
267
+ /**
268
+ *
269
+ * @param {PathTracedScene} scene
270
+ * @param {THREE.Camera} camera
271
+ * @returns {Promise<void>}
272
+ */
273
+ async function prepare_gi_box_scene(scene, camera) {
274
+ const path = 'data/models/samples/gi_box_01/model.glb';
275
+ await prepare_scene_gltf({
276
+ scene: scene,
277
+ camera: camera,
278
+ url: path,
279
+ sun: {
280
+ direction: new Vector3(1.2, -1, 0.2)
281
+ }
282
+ });
283
+
284
+ const transform = Transform.fromJSON({
285
+ "position": { "x": -2.320852352090763, "y": 4.765851637629835, "z": 5.154489928319274 },
286
+ "rotation": {
287
+ "x": 0.00480805808535541,
288
+ "y": 0.9797795216336188,
289
+ "z": -0.19861114162102378,
290
+ "w": 0.02371889518587569
291
+ },
292
+ "scale": {
293
+ "x": 1, "y": 1, "z": 1
294
+ }
295
+ });
296
+
297
+ set_camera_from_transform(camera, transform);
298
+
299
+ }
300
+
301
+ /**
302
+ *
303
+ * @param {PathTracedScene} scene
304
+ * @param {THREE.Camera} camera
305
+ * @returns {Promise<void>}
306
+ */
307
+ async function prepare_sponza(scene, camera) {
308
+ const path = 'data/models/sponza-pbr/gltf/sponza.glb';
309
+ await prepare_scene_gltf({
310
+ scene: scene,
311
+ camera: camera,
312
+ url: path,
313
+ sun: {
314
+ direction: new Vector3(0.2, -1, 0.2)
315
+ }
316
+ });
317
+
318
+ const transform = Transform.fromJSON({
319
+ "position": {
320
+ "x": -5.888122646477855,
321
+ "y": 4.631130854487186,
322
+ "z": -0.35698656745007035
323
+ },
324
+ "rotation": {
325
+ "x": 0.10780203229473442,
326
+ "y": 0.6847605545801206,
327
+ "z": -0.10349143573419042,
328
+ "w": 0.7132820111666399
329
+ },
330
+ "scale": { "x": 1, "y": 1, "z": 1 }
331
+ });
332
+
333
+ set_camera_from_transform(camera, transform);
334
+ }
335
+
244
336
  /**
245
337
  * Ray-Tracing In One Weekend test scene
246
338
  * @param {PathTracer} pt
@@ -446,7 +538,7 @@ function* render(target, pt, camera, scene, progress = { current: 0, total: 0 })
446
538
  ray_direction.x, ray_direction.y, ray_direction.z
447
539
  );
448
540
 
449
- pt.path_trace(pixel_color, ray, Infinity, 3, 7, random, scene);
541
+ pt.path_trace(pixel_color, ray, Infinity, 1, 7, random, scene);
450
542
 
451
543
  pixel_accummulation[0] += pixel_color[0];
452
544
  pixel_accummulation[1] += pixel_color[1];
@@ -501,13 +593,16 @@ async function start_renderer(camera) {
501
593
  camera.aspect = vCanvas.size.x / vCanvas.size.y;
502
594
 
503
595
  // const path = 'data/models/LowPolyTownshipSet/Small_house/Small_house.gltf';
504
- const path = 'data/models/pica_pica/pica_pica.gltf';
596
+ // const path = 'data/models/pica_pica/pica_pica.gltf';
505
597
  // const path = 'data/models/road_bike/road_bike.gltf'; //large CAD-type model
506
598
 
507
599
  // await prepare_scene_lucy(scene, camera);
508
- // await prepare_scene_rtiow(pt, camera);
600
+ await prepare_scene_rtiow(pt, camera);
509
601
  // await prepare_scene_sphere_01(pt, camera);
510
- await prepare_scene_gltf(scene, camera, path);
602
+ // await prepare_gi_box_scene(scene, camera);
603
+ // await prepare_sponza(scene, camera);
604
+ // await prepare_scene_gltf(scene, camera, path);
605
+
511
606
 
512
607
  await scene.build();
513
608
  // pt.optimize();
@@ -2,10 +2,9 @@
2
2
  *
3
3
  * @param {number[]} out
4
4
  * @param {PathTracedMesh} mesh
5
- * @param {Map<number, Sampler2D>} textures
6
5
  * @param {number} primitive_id
7
6
  * @param {number} u
8
7
  * @param {number} v
9
8
  */
10
- export function sample_material(out: number[], mesh: PathTracedMesh, textures: Map<number, Sampler2D>, primitive_id: number, u: number, v: number): void;
9
+ export function sample_material(out: number[], mesh: PathTracedMesh, primitive_id: number, u: number, v: number): void;
11
10
  //# sourceMappingURL=sample_material.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,qCAPW,MAAM,EAAE,kCAER,IAAI,MAAM,YAAY,gBACtB,MAAM,KACN,MAAM,KACN,MAAM,QAqEhB"}
1
+ {"version":3,"file":"sample_material.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/texture/sample_material.js"],"names":[],"mappings":"AAuCA;;;;;;;GAOG;AACH,qCANW,MAAM,EAAE,sCAER,MAAM,KACN,MAAM,KACN,MAAM,QAmEhB"}
@@ -1,24 +1,53 @@
1
1
  import { vec3 } from "gl-matrix";
2
- import { array_copy } from "../../../../../core/collection/array/array_copy.js";
2
+ import { dataTypeFromTypedArray } from "../../../../../core/binary/type/dataTypeFromTypedArray.js";
3
+ import { decode_attribute_value } from "../../../geometry/decode_attribute_value.js";
4
+ import { geometry_construct_triangle_normal } from "../../../geometry/geometry_construct_triangle_normal.js";
3
5
  import { transform_normal_m4 } from "../ray_hit_apply_transform.js";
4
6
  import { sample_triangle_attribute } from "../sample_triangle_attribute.js";
5
- import { sample_texture } from "./sample_texture.js";
6
7
 
7
8
  const texture_uv = [0, 0];
8
- const color = [1, 1, 1];
9
+ const color = new Float64Array([1, 1, 1]);
10
+
11
+ /**
12
+ *
13
+ * @param {number[]} color
14
+ * @param {BufferAttribute} color_attribute
15
+ * @param {number} index_0
16
+ * @param {number} index_1
17
+ * @param {number} index_2
18
+ * @param {number} u
19
+ * @param {number} v
20
+ */
21
+ function sample_color_attribute(
22
+ color,
23
+ color_attribute,
24
+ index_0, index_1, index_2,
25
+ u, v
26
+ ) {
27
+ const color_array = color_attribute.array;
28
+ sample_triangle_attribute(color, 0, index_0, index_1, index_2, color_array, 3, u, v);
29
+
30
+ const type = dataTypeFromTypedArray(color_array);
31
+
32
+ for (let i = 0; i < 3; i++) {
33
+ color[i] = decode_attribute_value(
34
+ color[i], type, color_attribute.normalized
35
+ );
36
+ }
37
+
38
+ }
9
39
 
10
40
  /**
11
41
  *
12
42
  * @param {number[]} out
13
43
  * @param {PathTracedMesh} mesh
14
- * @param {Map<number, Sampler2D>} textures
15
44
  * @param {number} primitive_id
16
45
  * @param {number} u
17
46
  * @param {number} v
18
47
  */
19
48
  export function sample_material(
20
49
  out,
21
- mesh, textures,
50
+ mesh,
22
51
  primitive_id,
23
52
  u, v
24
53
  ) {
@@ -43,13 +72,16 @@ export function sample_material(
43
72
 
44
73
  sample_triangle_attribute(out, 3, index_0, index_1, index_2, normal_array, 3, u, v);
45
74
 
46
- // apply transform
47
- transform_normal_m4(out, 3, out, 3, mesh.transform);
48
75
  } else {
76
+ const position_attribute = geometry.getAttribute('position');
77
+
49
78
  // copy hit normal
50
- array_copy(hit, 3, out, 3, 3);
79
+ geometry_construct_triangle_normal(out, 3, index_0, index_1, index_2, position_attribute.array);
51
80
  }
52
81
 
82
+ // apply transform
83
+ transform_normal_m4(out, 3, out, 3, mesh.transform);
84
+
53
85
 
54
86
  const uv_attribute = geometry.getAttribute('uv');
55
87
 
@@ -62,25 +94,20 @@ export function sample_material(
62
94
  texture_uv[1] = 0;
63
95
  }
64
96
 
65
- const material = mesh.material;
97
+ const color_attribute = geometry.getAttribute('color');
66
98
 
67
- if (material.isMeshStandardMaterial || material.isMeshBasicMaterial) {
68
- const material_color = material.color;
99
+ if (color_attribute !== undefined) {
100
+ sample_color_attribute(color, color_attribute, index_0, index_1, index_2, u, v);
69
101
 
70
- out[0] *= material_color.r;
71
- out[1] *= material_color.g;
72
- out[2] *= material_color.b;
102
+ vec3.multiply(out, out, color);
103
+ }
73
104
 
74
- const diffuse_map = material.map;
105
+ const material = mesh.material;
75
106
 
76
- if (diffuse_map !== null) {
77
- const sampler2D = textures.get(diffuse_map.id);
78
107
 
79
- sample_texture(color, sampler2D, diffuse_map, texture_uv[0], texture_uv[1]);
108
+ const tex_diffuse = material.diffuse;
80
109
 
81
- vec3.multiply(out, out, color);
82
- }
83
- } else {
84
- // unsupported
85
- }
110
+ tex_diffuse.sample(color, texture_uv[0], texture_uv[1]);
111
+
112
+ vec3.multiply(out, out, color);
86
113
  }
@@ -3,6 +3,7 @@ import {
3
3
  ClampToEdgeWrapping,
4
4
  DataTexture,
5
5
  LinearFilter,
6
+ Matrix4,
6
7
  MeshBasicMaterial,
7
8
  MeshStandardMaterial,
8
9
  NearestFilter,
@@ -18,6 +19,7 @@ import { array_copy } from "../../../core/collection/array/array_copy.js";
18
19
  import { is_typed_array_equals } from "../../../core/collection/array/typed/is_typed_array_equals.js";
19
20
  import { Color } from "../../../core/color/Color.js";
20
21
  import { kelvin_to_rgb } from "../../../core/color/kelvin/kelvin_to_rgb.js";
22
+ import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
21
23
  import Quaternion from "../../../core/geom/Quaternion.js";
22
24
  import Vector3 from "../../../core/geom/Vector3.js";
23
25
  import { max2 } from "../../../core/math/max2.js";
@@ -235,7 +237,7 @@ async function getVolume({
235
237
  engine,
236
238
  ecd,
237
239
  bounds: mesh_bounds,
238
- density: 3000
240
+ density: 5000
239
241
  });
240
242
 
241
243
  const buffer = new BinaryBuffer();
@@ -251,14 +253,19 @@ async function getVolume({
251
253
 
252
254
  /**
253
255
  *
254
- * @param {number} level
255
256
  * @param {EntityComponentDataset} ecd
257
+ * @param {Vector3} [center]
258
+ * @param {Vector3} [size]
256
259
  * @param {GraphicsEngine} graphics
260
+ * @param {number} [texture_frequency]
257
261
  */
258
- function createFloor({ level, ecd, graphics }) {
259
-
260
- const texture_frequency = 10;
261
- const size = 1000;
262
+ function createFloor({
263
+ ecd,
264
+ graphics,
265
+ center = new Vector3(0, 0, 0),
266
+ size = new Vector3(1000, 1000, 1000),
267
+ texture_frequency = 1
268
+ }) {
262
269
 
263
270
  const map = new TextureLoader().load('data/textures/utility/checkers_dark_grey_256x256.png', t => {
264
271
  map.needsUpdate = true;
@@ -266,7 +273,7 @@ function createFloor({ level, ecd, graphics }) {
266
273
  map.wrapS = RepeatWrapping;
267
274
  map.wrapT = RepeatWrapping;
268
275
 
269
- map.repeat.set(size / texture_frequency, size / texture_frequency);
276
+ map.repeat.set(size.x / texture_frequency, size.z / texture_frequency);
270
277
 
271
278
  map.matrixAutoUpdate = true;
272
279
  });
@@ -276,19 +283,23 @@ function createFloor({ level, ecd, graphics }) {
276
283
  map: map
277
284
  })).getValue();
278
285
 
279
- const geometry = new PlaneBufferGeometry(1, 1, 100, 100);
286
+ const geometry = new PlaneBufferGeometry(1, 1, 1, 1);
287
+
288
+ const q = Quaternion.fromEulerAngles(-Math.PI * 0.5, 0, 0);
289
+
290
+ const m = new Matrix4();
291
+
292
+ compose_matrix4_array(m.elements, Vector3.zero, q, Vector3.one);
293
+
294
+ geometry.applyMatrix4(m);
280
295
 
281
296
  geometry.computeVertexNormals();
282
297
  geometry.computeTangents();
283
298
 
284
299
  new Entity()
285
300
  .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),
301
+ position: center.toJSON(),
302
+ // rotation: ,
292
303
  scale: size
293
304
  }))
294
305
  .add(ShadedGeometry.from(geometry, material))
@@ -324,16 +335,17 @@ async function main(engine) {
324
335
 
325
336
  const sun_color = new Color();
326
337
 
327
- kelvin_to_rgb(sun_color, 0, 6000);
338
+ kelvin_to_rgb(sun_color, 0, 5000);
328
339
 
329
340
  await EngineHarness.buildLights({
330
341
  engine,
331
342
  shadowmapResolution: 4096,
332
343
  ambientIntensity: 0.0,
333
344
  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 )
345
+ // sunIntensity: 1.7,
346
+ sunIntensity: 3,
347
+ // sunDirection: new Vector3(0.2, -1, 0.2)
348
+ sunDirection: new Vector3(1.2, -1, 0.2)
337
349
  })
338
350
 
339
351
  engine.graphics.getRenderer().setClearColor('#1e3441', 1);
@@ -356,10 +368,13 @@ async function main(engine) {
356
368
  // const path = 'data/models/samples/cyberpunk_bike/scene.gltf';
357
369
  // const path = 'data/models/samples/sd_macross_city_standoff_diorama/scene.gltf';
358
370
  // 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';
371
+ const path = 'data/models/samples/gi_box_01/model.glb';
361
372
  // const path = 'data/models/samples/gi_box_01/model-thick-1.glb';
362
373
  // const path = 'data/models/sibenik/3-window-less/model.gltf';
374
+ // const path = 'data/models/samples/ancient_bath_house_-_modular_set/scene.gltf';
375
+ // const path = 'data/models/samples/environment_-_library/scene.gltf';
376
+ // const path = 'data/models/samples/the_attic_environment/scene1.gltf';
377
+ // const path = 'data/models/sponza-pbr/gltf/sponza.glb';
363
378
 
364
379
  const mesh_asset = await engine.assetManager.promise(path, 'model/gltf+json');
365
380
  const gltf = mesh_asset.gltf;
@@ -376,11 +391,6 @@ async function main(engine) {
376
391
  .add(SGMesh.fromURL(path))
377
392
  ;
378
393
 
379
- createFloor({
380
- level: mesh_asset.boundingBox.y0,
381
- ecd,
382
- graphics: engine.graphics
383
- });
384
394
 
385
395
  const composition = three_object_to_entity_composition(gltf.scene);
386
396
 
@@ -404,15 +414,31 @@ async function main(engine) {
404
414
  composition.build(ecd);
405
415
 
406
416
 
417
+ /**
418
+ * @type {AABB3}
419
+ */
407
420
  const mesh_bounds = mesh_asset.boundingBox;
408
421
  // const mesh_bounds = new AABB3(0, 0, 0, 20, 20, 20);
409
422
 
423
+ createFloor({
424
+ center: new Vector3(mesh_bounds.getCenterX(), mesh_bounds.y0, mesh_bounds.getCenterZ()),
425
+ size: new Vector3(
426
+ max2(0.1, mesh_bounds.getExtentsX() * 2),
427
+ 1,
428
+ max2(0.1, mesh_bounds.getExtentsZ() * 2)
429
+ ),
430
+ ecd,
431
+ graphics: engine.graphics
432
+ });
433
+
410
434
  const model_footprint = Math.hypot(mesh_bounds.getExtentsX(), mesh_bounds.getExtentsY(), mesh_bounds.getExtentsZ());
411
435
 
412
436
 
413
437
  const camera = ecd.getAnyComponent(Camera);
414
438
  camera.component.clip_far = max2(100, model_footprint);
415
- ecd.getComponent(camera.entity, TopDownCameraController).distanceMax = model_footprint * 1.1;
439
+ const camera_controller = ecd.getComponent(camera.entity, TopDownCameraController);
440
+ camera_controller.distanceMax = model_footprint * 1.1;
441
+ mesh_bounds.getCenter(camera_controller.target)
416
442
 
417
443
  const random = seededRandom();
418
444
 
@@ -460,8 +486,16 @@ async function main(engine) {
460
486
  volume.visualize_probes({ ecd, size: model_footprint * 0.002 });
461
487
  // volume.visualize_mesh({ ecd, opacity: 0.5 });
462
488
 
463
- new GUI()
464
- .add(transformer, 'intensity').min(0).max(10);
489
+ const gui = new GUI();
490
+ gui.add(transformer, 'intensity').min(0).max(10);
491
+
492
+ gui.add({
493
+ capture_camera() {
494
+ const transform = ecd.getComponent(camera.entity, Transform);
495
+
496
+ console.log(JSON.stringify(transform.toJSON()))
497
+ }
498
+ }, "capture_camera");
465
499
 
466
500
 
467
501
  // mesh_entity.addEventListener(SGMeshEvents.AssetLoaded, build);
@@ -1 +1 @@
1
- {"version":3,"file":"formatToChannelCount.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/formatToChannelCount.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,6CAHW,MAAM,GACJ,MAAM,CAgBlB"}
1
+ {"version":3,"file":"formatToChannelCount.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/texture/formatToChannelCount.js"],"names":[],"mappings":"AASA;;;;GAIG;AACH,6CAHW,MAAM,GACJ,MAAM,CAgBlB"}
@@ -1,4 +1,11 @@
1
- import { RedFormat, RedIntegerFormat, RGBAFormat, RGBFormat, RGFormat } from "three";
1
+ import { RedFormat, RedIntegerFormat, RGBAFormat, RGFormat } from "three";
2
+
3
+
4
+ /**
5
+ * WebGL constant, declared explicitly to avoid issues with later THREE.js versions where it is absent
6
+ * @type {number}
7
+ */
8
+ const RGBFormat = 1022;
2
9
 
3
10
  /**
4
11
  *
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {number[]} data
4
+ * @returns {Sampler2D}
5
+ */
6
+ export function one_pixel_sampler_uint8(data: number[]): Sampler2D;
7
+ import { Sampler2D } from "./Sampler2D.js";
8
+ //# sourceMappingURL=one_pixel_sampler_uint8.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"one_pixel_sampler_uint8.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.js"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,8CAHW,MAAM,EAAE,GACN,SAAS,CAIrB;0BATyB,gBAAgB"}
@@ -0,0 +1,10 @@
1
+ import { Sampler2D } from "./Sampler2D.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]} data
6
+ * @returns {Sampler2D}
7
+ */
8
+ export function one_pixel_sampler_uint8(data) {
9
+ return new Sampler2D(new Uint8Array(data), data.length, 1, 1);
10
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ *
3
+ * @param {Sampler2D} output
4
+ * @param {Sampler2D} input
5
+ * @param {number[]} vector
6
+ */
7
+ export function sampler_multiply_vector(output: Sampler2D, input: Sampler2D, vector: number[]): void;
8
+ //# sourceMappingURL=sampler_multiply_vector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sampler_multiply_vector.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/texture/sampler/sampler_multiply_vector.js"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,qFAFW,MAAM,EAAE,QAkBlB"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ *
3
+ * @param {Sampler2D} output
4
+ * @param {Sampler2D} input
5
+ * @param {number[]} vector
6
+ */
7
+ export function sampler_multiply_vector(output, input, vector) {
8
+
9
+ const pixel_count = input.width * input.height;
10
+ const item_size = input.itemSize;
11
+
12
+ const input_data = input.data;
13
+ const output_data = output.data;
14
+
15
+ for (let i = 0; i < pixel_count; i++) {
16
+ const offset = i * item_size;
17
+ for (let j = 0; j < item_size; j++) {
18
+ const address = offset + j;
19
+ output_data[address] = input_data[address] * vector[j];
20
+ }
21
+ }
22
+
23
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"de_interleave_bits_by_2.d.ts","sourceRoot":"","sources":["../../../../src/core/binary/de_interleave_bits_by_2.js"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,kDAHW,MAAM,GACJ,MAAM,CAWlB"}
@@ -1,8 +0,0 @@
1
- /**
2
- *
3
- * @param {number[]|Float32Array} result sh3
4
- * @param {number[]} sh input
5
- * @param {number[]} rotation 3x3 rotation matrix
6
- */
7
- export function sh3_rotate(result: number[] | Float32Array, sh: number[], rotation: number[]): void;
8
- //# sourceMappingURL=sh3_rotate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sh3_rotate.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/sphere/harmonics/sh3_rotate.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,mCAJW,MAAM,EAAE,GAAC,YAAY,MACrB,MAAM,EAAE,YACR,MAAM,EAAE,QAqBlB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"GeometryBVHBatched.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js"],"names":[],"mappings":"AA4FA;IAEQ;;;;OAIG;IACH,cAAsB;IAEtB;;;;OAIG;IACH,mBAAsB;IAEtB;;;;OAIG;IACH,yBAA4B;IAE5B;;;;OAIG;IACH,6BAAgC;IAGhC;;;;OAIG;IACH,yBAAyB;IAG7B;;;OAGG;IACH,gBAFW,MAAM,cAAc,QAyB9B;IAGD;;;;;;;OAOG;IACH,gBANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CAwElB;CACJ"}