@woosh/meep-engine 2.109.3 → 2.109.5

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 (73) hide show
  1. package/build/meep.cjs +109 -14
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +109 -14
  4. package/package.json +1 -1
  5. package/src/core/collection/queue/Deque.d.ts.map +1 -1
  6. package/src/core/collection/queue/Deque.js +52 -1
  7. package/src/core/collection/queue/Deque.spec.js +29 -0
  8. package/src/core/geom/3d/Ray3.d.ts +23 -10
  9. package/src/core/geom/3d/Ray3.d.ts.map +1 -1
  10. package/src/core/geom/3d/Ray3.js +59 -20
  11. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts +2 -2
  12. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.d.ts.map +1 -1
  13. package/src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js +42 -27
  14. package/src/core/geom/3d/tetrahedra/triangle/prototype.js +0 -2
  15. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.d.ts.map +1 -1
  16. package/src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js +5 -2
  17. package/src/core/geom/vec3/v3_matrix4_rotate.d.ts +10 -0
  18. package/src/core/geom/vec3/v3_matrix4_rotate.d.ts.map +1 -0
  19. package/src/core/geom/vec3/v3_matrix4_rotate.js +27 -0
  20. package/src/core/model/node-graph/node/NodeDescription.d.ts.map +1 -1
  21. package/src/core/model/node-graph/node/NodeDescription.js +23 -0
  22. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts +1 -0
  23. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
  24. package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +5 -3
  25. package/src/engine/graphics/sh3/lpv/sh3_bake_depth.d.ts.map +1 -1
  26. package/src/engine/graphics/sh3/lpv/sh3_bake_depth.js +2 -1
  27. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts +9 -4
  28. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -1
  29. package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js +61 -6
  30. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts +11 -4
  31. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
  32. package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +28 -36
  33. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +17 -8
  34. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
  35. package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +83 -44
  36. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts +3 -3
  37. package/src/engine/graphics/sh3/path_tracer/PathTracer.d.ts.map +1 -1
  38. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +40 -33
  39. package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -1
  40. package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +43 -40
  41. package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts +14 -0
  42. package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts.map +1 -1
  43. package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js +34 -1
  44. package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts +21 -0
  45. package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.d.ts.map +1 -0
  46. package/src/engine/graphics/sh3/path_tracer/prepare_scene_gltf.js +107 -0
  47. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +22 -122
  48. package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.d.ts +0 -9
  49. package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.d.ts.map +1 -1
  50. package/src/engine/graphics/sh3/path_tracer/ray_hit_apply_transform.js +2 -28
  51. package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.d.ts +0 -9
  52. package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.d.ts.map +1 -1
  53. package/src/engine/graphics/sh3/path_tracer/sampling/getBiasedNormalSample.js +0 -39
  54. package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.d.ts +10 -0
  55. package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.d.ts.map +1 -0
  56. package/src/engine/graphics/sh3/path_tracer/sampling/getCosineDirection.js +41 -0
  57. package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.d.ts +10 -0
  58. package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.d.ts.map +1 -0
  59. package/src/engine/graphics/sh3/path_tracer/sampling/v3_orthonormal_matrix_from_normal.js +45 -0
  60. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
  61. package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +28 -8
  62. package/src/engine/graphics/sh3/prototypeSH3Probe.js +7 -5
  63. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.d.ts.map +1 -1
  64. package/src/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +62 -13
  65. package/src/engine/graphics/three/material/iterate_three_material_textures.d.ts +10 -0
  66. package/src/engine/graphics/three/material/iterate_three_material_textures.d.ts.map +1 -0
  67. package/src/engine/graphics/three/material/iterate_three_material_textures.js +33 -0
  68. package/src/core/math/max4.d.ts +0 -10
  69. package/src/core/math/max4.d.ts.map +0 -1
  70. package/src/core/math/max4.js +0 -24
  71. package/src/core/math/min4.d.ts +0 -10
  72. package/src/core/math/min4.d.ts.map +0 -1
  73. package/src/core/math/min4.js +0 -23
@@ -291,6 +291,29 @@ export class NodeDescription {
291
291
  return result;
292
292
  }
293
293
 
294
+ /**
295
+ * Useful for checking if a node has inputs/outputs
296
+ * Does not allocate and terminates early, so performance characteristics are very good
297
+ * @param {PortDirection} direction
298
+ * @return {boolean}
299
+ */
300
+ hasPortsByDirection(direction) {
301
+ assert.enum(direction, PortDirection, 'direction');
302
+
303
+ const ports = this.ports;
304
+ const port_count = ports.length;
305
+
306
+ for (let i = 0; i < port_count; i++) {
307
+ const port = ports[i];
308
+
309
+ if (port.direction === direction) {
310
+ return true;
311
+ }
312
+ }
313
+
314
+ return false;
315
+ }
316
+
294
317
  /**
295
318
  *
296
319
  * @param {PortDirection} direction
@@ -5,6 +5,7 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
5
5
  scene: PathTracedScene;
6
6
  bake_depth(position: any, position_offset: any, output: any, output_offset: any): void;
7
7
  bake(position: any, position_offset: any, output: any, output_offset: any): void;
8
+ bake_start(): void;
8
9
  build_scene(ecd: any): void;
9
10
  }
10
11
  import { ProbeRenderer } from "./ProbeRenderer.js";
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AA0BA;IACI,mBAA0B;IAC1B,qBAAmB;IACnB,qBAAyB;IAEzB,uBAA6B;IAE7B,uFAoBC;IAED,iFAmCC;IASD,4BAsCC;CACJ;8BA1H6B,oBAAoB;2BADvB,8BAA8B;gCADzB,mCAAmC"}
1
+ {"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AA2BA;IACI,mBAA0B;IAC1B,qBAAmB;IACnB,qBAAyB;IAEzB,uBAA6B;IAE7B,uFAoBC;IAED,iFAqCC;IAKD,mBACC;IAED,4BAsCC;CACJ;8BA3H6B,oBAAoB;2BADvB,8BAA8B;gCADzB,mCAAmC"}
@@ -1,4 +1,5 @@
1
1
  import { array_copy } from "../../../../core/collection/array/array_copy.js";
2
+ import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
2
3
  import { sh3_basis_at } from "../../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
3
4
  import {
4
5
  sh3_dering_optimize_positive
@@ -21,7 +22,7 @@ const __shared_buffer = new ArrayBuffer((27 + 9) * 8);
21
22
  const sh_basis = new Float64Array(__shared_buffer, 0, 9);
22
23
  const coefficients = new Float64Array(__shared_buffer, 9 * 8, 27);
23
24
 
24
- const ray = new Float32Array(6);
25
+ const ray = new Ray3();
25
26
  const sampled_irradiance = new Float32Array(3);
26
27
 
27
28
  export class PathTracerProbeRenderer extends ProbeRenderer {
@@ -67,8 +68,10 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
67
68
  for (let i = 0; i < this.sample_count; i++) {
68
69
 
69
70
  randomPointOnSphere(this.random, ray, 3);
71
+ ray.tMax = Infinity;
72
+ ray.tMin = 0;
70
73
 
71
- tracer.path_trace(sampled_irradiance, ray, Infinity, 1, 7, this.random, this.scene);
74
+ tracer.path_trace(sampled_irradiance, ray, 1, 7, this.random, this.scene);
72
75
 
73
76
  sh3_basis_at(ray[3], ray[4], ray[5], sh_basis);
74
77
 
@@ -94,7 +97,6 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
94
97
  }
95
98
 
96
99
  bake_start() {
97
- return this.scene.build();
98
100
  }
99
101
 
100
102
  build_scene(ecd) {
@@ -1 +1 @@
1
- {"version":3,"file":"sh3_bake_depth.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/sh3_bake_depth.js"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,uCATW,MAAM,EAAE,iBACR,MAAM,sCAEN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,eACN,MAAM,QAqDhB"}
1
+ {"version":3,"file":"sh3_bake_depth.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/sh3_bake_depth.js"],"names":[],"mappings":"AAQA;;;;;;;;;;GAUG;AACH,uCATW,MAAM,EAAE,iBACR,MAAM,sCAEN,MAAM,cACN,MAAM,cACN,MAAM,cACN,MAAM,eACN,MAAM,QAsDhB"}
@@ -32,6 +32,7 @@ export function sh3_bake_depth(
32
32
  const sh = new Float32Array(9);
33
33
 
34
34
  ray.origin.set(position_x, position_y, position_z);
35
+ ray.tMax = max_depth;
35
36
 
36
37
  const encoder = new OctahedralUvEncoder();
37
38
 
@@ -42,7 +43,7 @@ export function sh3_bake_depth(
42
43
 
43
44
  encoder.uv_to_unit(ray.direction, [u, v])
44
45
 
45
- let distance = scene.trace(ray_hit, ray, 0, max_depth);
46
+ let distance = scene.trace(ray_hit, ray);
46
47
 
47
48
  if (distance < 0) {
48
49
  distance = 100;
@@ -33,15 +33,20 @@ export class BufferedGeometryBVH {
33
33
  * @param {THREE.BufferGeometry} geometry
34
34
  */
35
35
  build(geometry: THREE.BufferGeometry): void;
36
+ /**
37
+ * Tests ray for occlusion
38
+ * Returns true if ray hits anything at all
39
+ * @param {Ray3} ray
40
+ * @returns {boolean}
41
+ */
42
+ occluded(ray: Ray3): boolean;
36
43
  /**
37
44
  * NOTE: raycast is performed in local coordinate space
38
45
  * @param {number[]} output
39
- * @param {number[]} ray
40
- * @param {number} min_distance
41
- * @param {number} max_distance
46
+ * @param {number[]|Ray3} ray
42
47
  * @returns {number} distance along the ray, negative if no hit
43
48
  */
44
- raycast(output: number[], ray: number[], min_distance: number, max_distance: number): number;
49
+ raycast(output: number[], ray: number[] | Ray3): number;
45
50
  #private;
46
51
  }
47
52
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
@@ -1 +1 @@
1
- {"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AAwBA;IAkBI;;;OAGG;IACH,eAFW,KAAK,GAAC,MAAM,EAAE,QAIxB;IAIG;;;;OAIG;IACH,mBAAsB;IAEtB;;;;OAIG;IACH,yBAA4B;IAE5B;;;;OAIG;IACH,6BAAgC;IAGhC;;;;OAIG;IACH,yBAAyB;IAG7B;;;OAGG;IACH,gBAFW,MAAM,cAAc,QAsC9B;IAGD;;;;;;;OAOG;IACH,gBANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CAyElB;;CACJ;sBAzMqB,wCAAwC"}
1
+ {"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AAwBA;IAkBI;;;OAGG;IACH,eAFW,KAAK,GAAC,MAAM,EAAE,QAIxB;IAIG;;;;OAIG;IACH,mBAAsB;IAEtB;;;;OAIG;IACH,yBAA4B;IAE5B;;;;OAIG;IACH,6BAAgC;IAGhC;;;;OAIG;IACH,yBAAyB;IAG7B;;;OAGG;IACH,gBAFW,MAAM,cAAc,QAsC9B;IAED;;;;;OAKG;IACH,qBAFa,OAAO,CAkDnB;IAED;;;;;OAKG;IACH,gBAJW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,GACX,MAAM,CA2ElB;;CACJ;sBAhQqB,wCAAwC"}
@@ -122,16 +122,69 @@ export class BufferedGeometryBVH {
122
122
  r.toArray(this.#bounds_sphere);
123
123
  }
124
124
 
125
+ /**
126
+ * Tests ray for occlusion
127
+ * Returns true if ray hits anything at all
128
+ * @param {Ray3} ray
129
+ * @returns {boolean}
130
+ */
131
+ occluded(ray) {
132
+ const indices = this.__geometry_index;
133
+ const positions = this.__geometry_positions;
134
+
135
+ const origin_x = ray[0];
136
+ const origin_y = ray[1];
137
+ const origin_z = ray[2];
138
+
139
+ const direction_x = ray[3];
140
+ const direction_y = ray[4];
141
+ const direction_z = ray[5];
142
+
143
+ const max_distance = ray[6];
144
+
145
+ const bvh = this.#bvh;
146
+
147
+ const count = bvh_query_user_data_ray_segment(
148
+ bvh, bvh.root,
149
+ scratch_uint32_array, 0,
150
+ origin_x, origin_y, origin_z,
151
+ direction_x, direction_y, direction_z,
152
+ 0, max_distance
153
+ );
154
+
155
+ // check triangles found via BVH
156
+ for (let i = 0; i < count; i++) {
157
+ const triangle_index = scratch_uint32_array[i];
158
+
159
+ const intersection_found = computeTriangleRayIntersectionBarycentricGeometry(
160
+ v3_scratch_0,
161
+ origin_x, origin_y, origin_z,
162
+ direction_x, direction_y, direction_z,
163
+ indices, triangle_index,
164
+ positions
165
+ );
166
+
167
+ if (!intersection_found) {
168
+ continue;
169
+ }
170
+
171
+ const t = v3_scratch_0[0];
172
+
173
+ if (t < max_distance && t > 0) {
174
+ return true;
175
+ }
176
+ }
177
+
178
+ return false;
179
+ }
125
180
 
126
181
  /**
127
182
  * NOTE: raycast is performed in local coordinate space
128
183
  * @param {number[]} output
129
- * @param {number[]} ray
130
- * @param {number} min_distance
131
- * @param {number} max_distance
184
+ * @param {number[]|Ray3} ray
132
185
  * @returns {number} distance along the ray, negative if no hit
133
186
  */
134
- raycast(output, ray, min_distance, max_distance) {
187
+ raycast(output, ray) {
135
188
 
136
189
  const indices = this.__geometry_index;
137
190
  const positions = this.__geometry_positions;
@@ -144,6 +197,8 @@ export class BufferedGeometryBVH {
144
197
  const direction_y = ray[4];
145
198
  const direction_z = ray[5];
146
199
 
200
+ const max_distance = ray[6];
201
+
147
202
  const bvh = this.#bvh;
148
203
 
149
204
  const count = bvh_query_user_data_ray_segment(
@@ -151,7 +206,7 @@ export class BufferedGeometryBVH {
151
206
  scratch_uint32_array, 0,
152
207
  origin_x, origin_y, origin_z,
153
208
  direction_x, direction_y, direction_z,
154
- min_distance, max_distance
209
+ 0, max_distance
155
210
  );
156
211
 
157
212
  if (count === 0) {
@@ -184,7 +239,7 @@ export class BufferedGeometryBVH {
184
239
 
185
240
  const t = v3_scratch_0[0];
186
241
 
187
- if (t < nearest_hit_distance && t > min_distance) {
242
+ if (t < nearest_hit_distance && t > 0) {
188
243
  nearest_hit_distance = t;
189
244
 
190
245
  best_index = triangle_index;
@@ -24,20 +24,27 @@ export class PathTracedMesh {
24
24
  * @type {StandardMaterial|null}
25
25
  */
26
26
  material: StandardMaterial | null;
27
+ get transform_inverse(): Float32Array;
27
28
  build_tight_bounds(): void;
28
29
  update_bounds(): void;
29
30
  set transform(arg: Float32Array);
30
31
  get transform(): Float32Array;
32
+ /**
33
+ *
34
+ * @param {Ray3} ray
35
+ * @returns {boolean}
36
+ */
37
+ occluded(ray: Ray3): boolean;
31
38
  /**
32
39
  *
33
40
  * @param {number[]} out
34
- * @param {number[]} ray
35
- * @param {number} min_distance
36
- * @param {number} max_distance
41
+ * @param {number[]|Ray3} ray
42
+ * @param {number} ray_limit overrides Ray.tMax
37
43
  * @returns {number} distance along the ray to contact
38
44
  */
39
- hit(out: number[], ray: number[], min_distance: number, max_distance: number): number;
45
+ hit(out: number[], ray: number[] | Ray3, ray_limit: number): number;
40
46
  #private;
41
47
  }
42
48
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
49
+ import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
43
50
  //# sourceMappingURL=PathTracedMesh.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"AAmBA;IACI;;;OAGG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,KAAK,CAEI;IAEnB;;;OAGG;IACH,KAFU,sBAAoB,IAAI,CAEvB;IAGX;;;OAGG;IACH,UAFU,MAAM,cAAc,GAAC,IAAI,CAEnB;IAEhB;;;OAGG;IACH,UAFU,mBAAiB,IAAI,CAEf;IAKhB,2BAqBC;IAED,sBAGC;IAED,iCAQC;IAED,8BAEC;IAED;;;;;;;OAOG;IACH,SANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CAmDlB;;CACJ;sBAxJqB,wCAAwC"}
1
+ {"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"AAeA;IACI;;;OAGG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,MAFU,KAAK,CAEI;IAEnB;;;OAGG;IACH,KAFU,sBAAoB,IAAI,CAEvB;IAGX;;;OAGG;IACH,UAFU,MAAM,cAAc,GAAC,IAAI,CAEnB;IAEhB;;;OAGG;IACH,UAFU,mBAAiB,IAAI,CAEf;IAKhB,sCAEC;IAED,2BAqBC;IAED,sBAGC;IAED,iCAQC;IAED,8BAEC;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAWnB;IAED;;;;;;OAMG;IACH,SALW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,aACb,MAAM,GACJ,MAAM,CA4BlB;;CACJ;sBAhJqB,wCAAwC;qBAIzC,kCAAkC"}
@@ -4,17 +4,13 @@ import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
4
4
  import { aabb3_from_v3_array_transformed } from "../../../../core/geom/3d/aabb/aabb3_from_v3_array_transformed.js";
5
5
  import { decompose_matrix_4_array } from "../../../../core/geom/3d/decompose_matrix_4_array.js";
6
6
  import { allocate_m4 } from "../../../../core/geom/3d/mat4/allocate_m4.js";
7
- import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
8
- import { ray3_shift_origin_along_direction } from "../../../../core/geom/3d/ray/ray3_shift_origin_along_direction.js";
7
+ import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
9
8
  import Quaternion from "../../../../core/geom/Quaternion.js";
10
- import { v3_array_displace_in_direction } from "../../../../core/geom/vec3/v3_array_displace_in_direction.js";
11
9
  import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
12
- import { v3_matrix4_multiply } from "../../../../core/geom/vec3/v3_matrix4_multiply.js";
13
10
  import Vector3 from "../../../../core/geom/Vector3.js";
14
11
  import { ray_hit_apply_transform } from "./ray_hit_apply_transform.js";
15
12
 
16
- const local_ray = new Float32Array(6);
17
- const scratch_v3 = new Float32Array(3);
13
+ const local_ray = new Ray3();
18
14
  let mesh_id_counter = 0;
19
15
 
20
16
  export class PathTracedMesh {
@@ -52,6 +48,10 @@ export class PathTracedMesh {
52
48
  #transform = allocate_m4();
53
49
  #transform_inverse = allocate_m4();
54
50
 
51
+ get transform_inverse() {
52
+ return this.#transform_inverse;
53
+ }
54
+
55
55
  build_tight_bounds() {
56
56
  const position = new Vector3();
57
57
  const rotation = new Quaternion();
@@ -96,45 +96,37 @@ export class PathTracedMesh {
96
96
 
97
97
  /**
98
98
  *
99
- * @param {number[]} out
100
- * @param {number[]} ray
101
- * @param {number} min_distance
102
- * @param {number} max_distance
103
- * @returns {number} distance along the ray to contact
99
+ * @param {Ray3} ray
100
+ * @returns {boolean}
104
101
  */
105
- hit(out, ray, min_distance, max_distance) {
106
- //transform ray
107
- const m4 = this.#transform_inverse;
108
-
109
- // shift ray forward by "min distance"
110
- ray3_shift_origin_along_direction(local_ray, 0, ray, 0, min_distance);
102
+ occluded(ray) {
111
103
 
104
+ const m4 = this.#transform_inverse;
112
105
 
113
- ray3_array_apply_matrix4(local_ray, 0, local_ray, 0, m4);
106
+ local_ray.copy(ray);
107
+ local_ray.applyMatrix4(m4);
114
108
 
109
+ return this.bvh.occluded(local_ray);
115
110
 
116
- let max_distance_local = Infinity;
111
+ }
117
112
 
118
- if (max_distance !== Infinity) {
119
- // compute position of point at max_distance along the ray
120
- v3_array_displace_in_direction(
121
- scratch_v3, 0,
122
- ray[0], ray[1], ray[2],
123
- ray[3], ray[4], ray[5],
124
- max_distance-min_distance
125
- );
113
+ /**
114
+ *
115
+ * @param {number[]} out
116
+ * @param {number[]|Ray3} ray
117
+ * @param {number} ray_limit overrides Ray.tMax
118
+ * @returns {number} distance along the ray to contact
119
+ */
120
+ hit(out, ray, ray_limit) {
121
+ //transform ray
122
+ const m4 = this.#transform_inverse;
126
123
 
127
- // move far point into local coordinate space
128
- v3_matrix4_multiply(scratch_v3, 0, scratch_v3, 0, m4);
124
+ local_ray.copy(ray);
125
+ local_ray.tMax = ray_limit;
129
126
 
130
- // compute far distance in local space
131
- max_distance_local = v3_distance(
132
- local_ray[0], local_ray[1], local_ray[2],
133
- scratch_v3[0], scratch_v3[1], scratch_v3[2]
134
- );
135
- }
127
+ local_ray.applyMatrix4(m4);
136
128
 
137
- let distance_to_hit = this.bvh.raycast(out, local_ray, 0, max_distance_local);
129
+ let distance_to_hit = this.bvh.raycast(out, local_ray);
138
130
 
139
131
  if (distance_to_hit >= 0) {
140
132
  // transform output
@@ -26,7 +26,6 @@ export class PathTracedScene {
26
26
  */
27
27
  private __background_sampler;
28
28
  optimize(): void;
29
- build(): Promise<void>;
30
29
  /**
31
30
  *
32
31
  * @param {THREE.BufferGeometry} geo
@@ -56,6 +55,12 @@ export class PathTracedScene {
56
55
  * @returns {boolean}
57
56
  */
58
57
  removeMesh(mesh: PathTracedMesh): boolean;
58
+ /**
59
+ * Retrieves pre-cached material or build one from scratch, caches it and returns the result
60
+ * @param {THREE.Material} material
61
+ * @returns {StandardMaterial}
62
+ */
63
+ obtainMaterial(material: THREE.Material): StandardMaterial;
59
64
  /**
60
65
  *
61
66
  * @param {THREE.BufferGeometry} geometry
@@ -67,17 +72,22 @@ export class PathTracedScene {
67
72
  *
68
73
  * @param {number[]} out [color_r, color_g, color_b, normal_x, normal_y, normal_z]
69
74
  * @param {number[]} hit
75
+ * @param {Ray3} incoming_ray
70
76
  */
71
- sample_material(out: number[], hit: number[]): void;
77
+ sample_material(out: number[], hit: number[], incoming_ray: Ray3): void;
78
+ /**
79
+ * Tests ray for occlusion
80
+ * @param {Ray3} ray
81
+ * @returns {boolean}
82
+ */
83
+ occluded(ray: Ray3): boolean;
72
84
  /**
73
85
  *
74
86
  * @param {number[]} out
75
87
  * @param {number[]|Ray3} ray
76
- * @param {number} min_distance
77
- * @param {number} max_distance
78
88
  * @return {number} distance to contact, or -1 if no contact found
79
89
  */
80
- trace(out: number[], ray: number[] | Ray3, min_distance: number, max_distance: number): number;
90
+ trace(out: number[], ray: number[] | Ray3): number;
81
91
  /**
82
92
  *
83
93
  * @param {number[]} out
@@ -91,14 +101,13 @@ export class PathTracedScene {
91
101
  * @param {number[]} out
92
102
  * @param {number} out_offset
93
103
  * @param {number[]} ray
94
- * @param {number} ray_address
95
- * @returns {boolean}
96
104
  */
97
- sample_lights(out: number[], out_offset: number, ray: number[], ray_address: number): boolean;
105
+ sample_lights(out: number[], out_offset: number, ray: number[]): void;
98
106
  #private;
99
107
  }
100
108
  import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
101
109
  import { PathTracedMesh } from "./PathTracedMesh.js";
102
110
  import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
103
111
  import { BufferedGeometryBVH } from "./BufferedGeometryBVH.js";
112
+ import { Ray3 } from "../../../../core/geom/3d/Ray3.js";
104
113
  //# sourceMappingURL=PathTracedScene.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AA6CA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAiF7C,iBAOC;IAED,uBAEC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;OAIG;IACH,qBAHW,MAAM,EAAE,OACR,MAAM,EAAE,QAyBlB;IAED;;;;;;;OAOG;IACH,WANW,MAAM,EAAE,OACR,MAAM,EAAE,OAAK,gBACb,MAAM,gBACN,MAAM,GACL,MAAM,CA8CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;;;OAOG;IACH,mBANW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,eACR,MAAM,GACJ,OAAO,CAmEnB;;CACJ;oBA9d8B,mCAAmC;+BAiBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B"}
1
+ {"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AAgCA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAG1B;;;OAGG;IACH,QAFU,IAAI,MAAM,EAAE,cAAc,CAAC,CAElB;IAEnB;;;OAGG;IACH,UAFU,aAAa,EAAE,CAEX;IAEd;;;OAGG;IACH,WAFU,IAAI,MAAM,cAAc,EAAE,mBAAmB,CAAC,CAElC;IAmBtB;;;;OAIG;IACH,6BAA6C;IAiF7C,iBAOC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAInB;IAED;;;;OAIG;IACH,cAHW,cAAc,GACZ,OAAO,CAiCnB;IAED;;;;OAIG;IACH,iBAHW,cAAc,GACZ,OAAO,CAgBnB;IAED;;;;OAIG;IACH,yBAHW,MAAM,QAAQ,oBAKxB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QAavB;IAED;;;;;OAKG;IACH,qBAJW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,IAAI,QAgCd;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAsCnB;IAED;;;;;OAKG;IACH,WAJW,MAAM,EAAE,OACR,MAAM,EAAE,GAAC,IAAI,GACZ,MAAM,CA+CjB;IAED;;;;;;OAMG;IACH,uBALW,MAAM,EAAE,cACR,MAAM,aACN,MAAM,EAAE,oBACR,MAAM,QAIhB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,EAAE,cACR,MAAM,OACN,MAAM,EAAE,QAkElB;;CACJ;oBArgB8B,mCAAmC;+BAkBnC,qBAAqB;8BAJtB,kDAAkD;oCAC5C,0BAA0B;qBALzC,kCAAkC"}