@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
@@ -67733,6 +67733,60 @@ function sampler2d_ensure_uint8_RGBA(input) {
67733
67733
  const DEFAULT_TEXTURE_WIDTH = 512;
67734
67734
  const DEFAULT_TEXTURE_HEIGHT = 512;
67735
67735
 
67736
+ /**
67737
+ *
67738
+ * @param {THREE.DataTexture} texture
67739
+ * @param {number} channel_count
67740
+ * @param {number} _width
67741
+ * @param {number} _height
67742
+ * @returns {Sampler2D}
67743
+ */
67744
+ function data_texture_to_sampler(texture, channel_count, _width, _height) {
67745
+ const source = new Sampler2D(texture.image.data, channel_count, texture.image.width, texture.image.height);
67746
+
67747
+ let converted = sampler2d_ensure_uint8_RGBA(source);
67748
+
67749
+ if (converted.width !== _width || converted.height !== _height) {
67750
+ const target = Sampler2D.uint8(4, _width, _height);
67751
+
67752
+ sampler2d_scale(converted, target);
67753
+
67754
+ converted = target;
67755
+ }
67756
+ return converted;
67757
+ }
67758
+
67759
+ /**
67760
+ *
67761
+ * @param {THREE.Texture} texture
67762
+ * @param {number} channel_count
67763
+ * @param {number} _width
67764
+ * @param {number} _height
67765
+ * @returns {Sampler2D}
67766
+ */
67767
+ function html_image_texture_to_sampler(texture, channel_count, _width, _height) {
67768
+ /**
67769
+ *
67770
+ * @type {Image}
67771
+ */
67772
+ const img = texture.image;
67773
+
67774
+ const canvas = document.createElement('canvas');
67775
+
67776
+ canvas.width = _width;
67777
+ canvas.height = _height;
67778
+
67779
+ const ctx = canvas.getContext('2d');
67780
+
67781
+ ctx.drawImage(img, 0, 0, img.width, img.height, 0, 0, _width, _height);
67782
+
67783
+ const result = Sampler2D.uint8(4, _width, _height);
67784
+
67785
+ canvasDataToSampler(result, ctx);
67786
+
67787
+ return result;
67788
+ }
67789
+
67736
67790
  /**
67737
67791
  *
67738
67792
  * @param {Texture} texture
@@ -67752,8 +67806,6 @@ function convertTexture2Sampler2D(
67752
67806
 
67753
67807
  const channel_count = formatToChannelCount(texture.format);
67754
67808
 
67755
- // TODO take channel count into account
67756
-
67757
67809
  if (_width === undefined || _height === undefined) {
67758
67810
 
67759
67811
  //figure out texture size
@@ -67792,21 +67844,14 @@ function convertTexture2Sampler2D(
67792
67844
  if (texture.isDataTexture === true) {
67793
67845
 
67794
67846
  // special case
67847
+ const converted = data_texture_to_sampler(texture, channel_count, _width, _height);
67795
67848
 
67796
- const source = new Sampler2D(texture.image.data, channel_count, texture.image.width, texture.image.height);
67797
-
67798
- let converted = sampler2d_ensure_uint8_RGBA(source);
67799
-
67800
- if (converted.width !== _width || converted.height !== _height) {
67801
- const target = Sampler2D.uint8(4, _width, _height);
67802
-
67803
- sampler2d_scale(converted, target);
67849
+ data = converted.data;
67804
67850
 
67805
- converted = target;
67806
- }
67851
+ } else if (texture.image instanceof Image) {
67852
+ const converted = html_image_texture_to_sampler(texture, channel_count, _width, _height);
67807
67853
 
67808
67854
  data = converted.data;
67809
-
67810
67855
  } else {
67811
67856
  const built = WebGLRendererPool.global.use(renderer => {
67812
67857
 
@@ -84850,7 +84895,7 @@ class Deque {
84850
84895
  * @type {T[]}
84851
84896
  * @private
84852
84897
  */
84853
- #data=EMPTY_ARRAY;
84898
+ #data = EMPTY_ARRAY;
84854
84899
  /**
84855
84900
  *
84856
84901
  * @type {number}
@@ -85167,6 +85212,56 @@ class Deque {
85167
85212
  const last = this.#circular_previous_position(this.#tail);
85168
85213
  return this.#data[last];
85169
85214
  }
85215
+
85216
+ /**
85217
+ * Retrieved element by position from head. Where element at the head is position 0
85218
+ * @param {number} index
85219
+ * @returns {T|undefined} undefined if indexing element that is past the end, otherwise returns element at the position given
85220
+ */
85221
+ getElementByIndex(index) {
85222
+
85223
+ if (index >= this.size()) {
85224
+ // overflow
85225
+ return undefined;
85226
+ }
85227
+
85228
+ /**
85229
+ *
85230
+ * @type {number}
85231
+ */
85232
+ const position = (this.#head + index) % this.#data.length;
85233
+
85234
+ return this.#data[position];
85235
+ }
85236
+
85237
+ /**
85238
+ * Returns a copy of this queue represented as an array without gaps, with the head of the queue (first element) being at position 0
85239
+ * @param {T[]} [result]
85240
+ * @param {number} [result_offset]
85241
+ * @returns {T[]}
85242
+ */
85243
+ toArray(result = [], result_offset = 0) {
85244
+ const size = this.size();
85245
+
85246
+ for (let i = 0; i < size; i++) {
85247
+ result[i] = this.getElementByIndex(i);
85248
+ }
85249
+
85250
+ return result;
85251
+ }
85252
+
85253
+ /**
85254
+ *
85255
+ * @returns {Generator<T,void>}
85256
+ */
85257
+ * [Symbol.iterator]() {
85258
+
85259
+ const size = this.size();
85260
+
85261
+ for (let i = 0; i < size; i++) {
85262
+ yield this.getElementByIndex(i);
85263
+ }
85264
+ }
85170
85265
  }
85171
85266
 
85172
85267
  /*
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.109.3",
8
+ "version": "2.109.5",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1 +1 @@
1
- {"version":3,"file":"Deque.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/queue/Deque.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IA8BI;;;OAGG;IACH,uBAFW,MAAM,EAUhB;IAqFD;;;OAGG;IACH,WAFY,OAAO,CAIlB;IAED,cAeC;IAED;;OAEG;IACH,QAFa,MAAM,CAalB;IA+CD;;;;OAIG;IACH,UAHW,CAAC,GACC,OAAO,CAYnB;IA2BD;;;;OAIG;IACH,WAFa,OAAO,CAInB;IAED;;;OAGG;IACH,YAFW,CAAC,QAOX;IAED;;;OAGG;IACH,eAFa,CAAC,GAAC,SAAS,CAQvB;IAED;;;OAGG;IACH,YAFa,CAAC,GAAC,SAAS,CAIvB;IAED;;;OAGG;IACH,WAFW,CAAC,QAOX;IAED;;;OAGG;IACH,cAFa,CAAC,CASb;IAGD;;;OAGG;IACH,WAFa,CAAC,GAAC,SAAS,CAKvB;IAOL,gBAAoB;IACpB,uBAAoB;IACpB,eAAmB;IAEnB;;OAEG;IACH,sBAAmB;;CAblB"}
1
+ {"version":3,"file":"Deque.d.ts","sourceRoot":"","sources":["../../../../../src/core/collection/queue/Deque.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH;IA8BI;;;OAGG;IACH,uBAFW,MAAM,EAUhB;IAqFD;;;OAGG;IACH,WAFY,OAAO,CAIlB;IAED,cAeC;IAED;;OAEG;IACH,QAFa,MAAM,CAalB;IA+CD;;;;OAIG;IACH,UAHW,CAAC,GACC,OAAO,CAYnB;IA2BD;;;;OAIG;IACH,WAFa,OAAO,CAInB;IAED;;;OAGG;IACH,YAFW,CAAC,QAOX;IAED;;;OAGG;IACH,eAFa,CAAC,GAAC,SAAS,CAQvB;IAED;;;OAGG;IACH,YAFa,CAAC,GAAC,SAAS,CAIvB;IAED;;;OAGG;IACH,WAFW,CAAC,QAOX;IAED;;;OAGG;IACH,cAFa,CAAC,CASb;IAGD;;;OAGG;IACH,WAFa,CAAC,GAAC,SAAS,CAKvB;IAED;;;;OAIG;IACH,yBAHW,MAAM,GACJ,CAAC,GAAC,SAAS,CAiBvB;IAED;;;;;OAKG;IACH,iBAJW,CAAC,EAAE,kBACH,MAAM,GACJ,CAAC,EAAE,CAUf;IAoBL,gBAAoB;IACpB,uBAAoB;IACpB,eAAmB;IAEnB;;OAEG;IACH,sBAAmB;IAzBf;;;OAGG;IACH,qBAFa,UAAU,CAAC,EAAC,IAAI,CAAC,CAS7B;;CACJ"}
@@ -25,7 +25,7 @@ export class Deque {
25
25
  * @type {T[]}
26
26
  * @private
27
27
  */
28
- #data=EMPTY_ARRAY;
28
+ #data = EMPTY_ARRAY;
29
29
  /**
30
30
  *
31
31
  * @type {number}
@@ -344,6 +344,57 @@ export class Deque {
344
344
  const last = this.#circular_previous_position(this.#tail);
345
345
  return this.#data[last];
346
346
  }
347
+
348
+ /**
349
+ * Retrieved element by position from head. Where element at the head is position 0
350
+ * @param {number} index
351
+ * @returns {T|undefined} undefined if indexing element that is past the end, otherwise returns element at the position given
352
+ */
353
+ getElementByIndex(index) {
354
+ assert.isNonNegativeInteger(index, 'index');
355
+
356
+ if (index >= this.size()) {
357
+ // overflow
358
+ return undefined;
359
+ }
360
+
361
+ /**
362
+ *
363
+ * @type {number}
364
+ */
365
+ const position = (this.#head + index) % this.#data.length;
366
+
367
+ return this.#data[position];
368
+ }
369
+
370
+ /**
371
+ * Returns a copy of this queue represented as an array without gaps, with the head of the queue (first element) being at position 0
372
+ * @param {T[]} [result]
373
+ * @param {number} [result_offset]
374
+ * @returns {T[]}
375
+ */
376
+ toArray(result = [], result_offset = 0) {
377
+ const size = this.size();
378
+
379
+ for (let i = 0; i < size; i++) {
380
+ result[i] = this.getElementByIndex(i);
381
+ }
382
+
383
+ return result;
384
+ }
385
+
386
+ /**
387
+ *
388
+ * @returns {Generator<T,void>}
389
+ */
390
+ * [Symbol.iterator]() {
391
+
392
+ const size = this.size();
393
+
394
+ for (let i = 0; i < size; i++) {
395
+ yield this.getElementByIndex(i);
396
+ }
397
+ }
347
398
  }
348
399
 
349
400
  /*
@@ -245,3 +245,32 @@ test("fill queue beyond default size and then drain it", () => {
245
245
  expect(queue.pop()).toBe(3);
246
246
  expect(queue.size()).toBe(0);
247
247
  });
248
+
249
+
250
+ test("toArray", () => {
251
+
252
+ const q = new Deque(2);
253
+
254
+ expect(q.toArray()).toEqual([]);
255
+
256
+ q.addLast(1);
257
+
258
+ expect(q.toArray()).toEqual([1]);
259
+
260
+ q.addLast(7);
261
+
262
+ expect(q.toArray()).toEqual([1, 7]);
263
+
264
+ q.removeFirst();
265
+
266
+ expect(q.toArray()).toEqual([7]);
267
+ });
268
+
269
+ test("Symbol.iterator",()=>{
270
+ const q = new Deque();
271
+
272
+ q.addLast(1);
273
+ q.addLast(7);
274
+
275
+ expect(Array.from(q)).toEqual([1,7]);
276
+ });
@@ -1,25 +1,38 @@
1
1
  /**
2
2
  * 3D ray
3
3
  */
4
- export class Ray3 {
5
- origin: Vector3;
6
- direction: Vector3;
7
- get 0(): number;
8
- get 1(): number;
9
- get 2(): number;
10
- get 3(): number;
11
- get 4(): number;
12
- get 5(): number;
4
+ export class Ray3 extends Float32Array {
5
+ constructor();
6
+ set tMax(arg: any);
7
+ get tMax(): any;
8
+ 6: any;
9
+ get direction(): Float32Array;
10
+ get origin(): Float32Array;
11
+ /**
12
+ *
13
+ * @param {number} distance
14
+ */
15
+ shiftForward(distance: number): void;
13
16
  /**
14
17
  *
15
18
  * @param {number[]|mat4|Float32Array} m4
16
19
  */
17
20
  applyMatrix4(m4: number[] | mat4 | Float32Array): void;
21
+ /**
22
+ *
23
+ * @returns {Ray3}
24
+ */
25
+ clone(): Ray3;
18
26
  /**
19
27
  *
20
28
  * @param {Ray3} other
21
29
  */
22
30
  copy(other: Ray3): void;
31
+ /**
32
+ *
33
+ * @param {Ray3} other
34
+ * @returns {boolean}
35
+ */
36
+ equals(other: Ray3): boolean;
23
37
  }
24
- import Vector3 from "../Vector3.js";
25
38
  //# sourceMappingURL=Ray3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Ray3.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/3d/Ray3.js"],"names":[],"mappings":"AAEA;;GAEG;AACH;IACI,gBAAsB;IACtB,mBAAyB;IAEzB,gBAEC;IAED,gBAEC;IAED,gBAEC;IAED,gBAEC;IAED,gBAEC;IAED,gBAEC;IAED;;;OAGG;IACH,iBAFW,MAAM,EAAE,UAAM,YAAY,QAKpC;IAED;;;OAGG;IACH,YAFW,IAAI,QAKd;CACJ;oBAlDmB,eAAe"}
1
+ {"version":3,"file":"Ray3.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/3d/Ray3.js"],"names":[],"mappings":"AAKA;;GAEG;AACH;IACI,cAKC;IAMD,mBAEC;IAND,gBAEC;IAGG,OAAW;IAGf,8BAEC;IAED,2BAEC;IAED;;;OAGG;IACH,uBAFW,MAAM,QAMhB;IAED;;;OAGG;IACH,iBAFW,MAAM,EAAE,UAAM,YAAY,QAepC;IAED;;;OAGG;IACH,SAFa,IAAI,CAQhB;IAED;;;OAGG;IACH,YAFW,IAAI,QAId;IAED;;;;OAIG;IACH,cAHW,IAAI,GACF,OAAO,CAInB;CACJ"}
@@ -1,34 +1,43 @@
1
- import Vector3 from "../Vector3.js";
1
+ import { array_range_equal_strict } from "../../collection/array/array_range_equal_strict.js";
2
+ import { v3_matrix4_multiply } from "../vec3/v3_matrix4_multiply.js";
3
+ import { v3_matrix4_rotate } from "../vec3/v3_matrix4_rotate.js";
4
+ import { ray3_interval_array_apply_matrix4 } from "./ray/ray3_interval_array_apply_matrix4.js";
2
5
 
3
6
  /**
4
7
  * 3D ray
5
8
  */
6
- export class Ray3 {
7
- origin = new Vector3()
8
- direction = new Vector3()
9
+ export class Ray3 extends Float32Array {
10
+ constructor() {
11
+ super(7);
9
12
 
10
- get 0() {
11
- return this.origin.x
13
+ // make ray unbounded
14
+ this.tMax = Infinity;
12
15
  }
13
16
 
14
- get 1() {
15
- return this.origin.y
17
+ get tMax() {
18
+ return this[6];
16
19
  }
17
20
 
18
- get 2() {
19
- return this.origin.z
21
+ set tMax(v) {
22
+ this[6] = v;
20
23
  }
21
24
 
22
- get 3() {
23
- return this.direction.x
25
+ get direction() {
26
+ return new Float32Array(this.buffer, this.byteOffset + 3, 3);
24
27
  }
25
28
 
26
- get 4() {
27
- return this.direction.y
29
+ get origin() {
30
+ return new Float32Array(this.buffer, this.byteOffset, 3);
28
31
  }
29
32
 
30
- get 5() {
31
- return this.direction.z
33
+ /**
34
+ *
35
+ * @param {number} distance
36
+ */
37
+ shiftForward(distance) {
38
+ this[0] += this[3] * distance;
39
+ this[1] += this[4] * distance;
40
+ this[2] += this[5] * distance;
32
41
  }
33
42
 
34
43
  /**
@@ -36,8 +45,30 @@ export class Ray3 {
36
45
  * @param {number[]|mat4|Float32Array} m4
37
46
  */
38
47
  applyMatrix4(m4) {
39
- this.origin.applyMatrix4(m4);
40
- this.direction.applyDirectionMatrix4(m4);
48
+
49
+ if (this[6] !== Infinity) {
50
+
51
+ ray3_interval_array_apply_matrix4(this, 0, this, 0, m4);
52
+
53
+ } else {
54
+
55
+ // special case
56
+ v3_matrix4_multiply(this, 0, this, 0, m4);
57
+ v3_matrix4_rotate(this, 3, this, 3, m4);
58
+
59
+ }
60
+ }
61
+
62
+ /**
63
+ *
64
+ * @returns {Ray3}
65
+ */
66
+ clone() {
67
+ const r = new Ray3();
68
+
69
+ r.copy(this);
70
+
71
+ return r;
41
72
  }
42
73
 
43
74
  /**
@@ -45,7 +76,15 @@ export class Ray3 {
45
76
  * @param {Ray3} other
46
77
  */
47
78
  copy(other) {
48
- this.origin.copy(other.origin);
49
- this.direction.copy(other.direction);
79
+ this.set(other);
80
+ }
81
+
82
+ /**
83
+ *
84
+ * @param {Ray3} other
85
+ * @returns {boolean}
86
+ */
87
+ equals(other) {
88
+ return array_range_equal_strict(this, 0, other, 0, 7);
50
89
  }
51
90
  }
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  *
3
- * @param {number[]|ArrayLike<number>|Float32Array} output 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
3
+ * @param {number[]|ArrayLike<number>|Float32Array} output 7 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMax]
4
4
  * @param {number} output_offset
5
- * @param {number[]|ArrayLike<number>|Float32Array} input 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
5
+ * @param {number[]|ArrayLike<number>|Float32Array} input 7 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMax]
6
6
  * @param {number} input_offset
7
7
  * @param {number[]|ArrayLike<number>|Float32Array} m4 4x4 matrix
8
8
  * @returns {boolean} false if matrix transformation is impossible, such as when scale of the matrix is 0
@@ -1 +1 @@
1
- {"version":3,"file":"ray3_interval_array_apply_matrix4.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,0DAPW,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,iBACvC,MAAM,SACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,gBACvC,MAAM,MACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACrC,OAAO,CAqDnB"}
1
+ {"version":3,"file":"ray3_interval_array_apply_matrix4.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/ray/ray3_interval_array_apply_matrix4.js"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,0DAPW,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,iBACvC,MAAM,SACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,gBACvC,MAAM,MACN,MAAM,EAAE,GAAC,UAAU,MAAM,CAAC,GAAC,YAAY,GACrC,OAAO,CAoEnB"}
@@ -1,13 +1,17 @@
1
1
  /**
2
2
  *
3
- * @param {number[]|ArrayLike<number>|Float32Array} output 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
3
+ * @param {number[]|ArrayLike<number>|Float32Array} output 7 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMax]
4
4
  * @param {number} output_offset
5
- * @param {number[]|ArrayLike<number>|Float32Array} input 8 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMin, tMax]
5
+ * @param {number[]|ArrayLike<number>|Float32Array} input 7 component vector, [origin_x, origin_y, origin_z, direction_x, direction_y, direction_z, tMax]
6
6
  * @param {number} input_offset
7
7
  * @param {number[]|ArrayLike<number>|Float32Array} m4 4x4 matrix
8
8
  * @returns {boolean} false if matrix transformation is impossible, such as when scale of the matrix is 0
9
9
  */
10
- export function ray3_interval_array_apply_matrix4(output, output_offset, input, input_offset, m4) {
10
+ export function ray3_interval_array_apply_matrix4(
11
+ output, output_offset,
12
+ input, input_offset,
13
+ m4
14
+ ) {
11
15
  const origin_x = input[input_offset + 0];
12
16
  const origin_y = input[input_offset + 1];
13
17
  const origin_z = input[input_offset + 2];
@@ -16,46 +20,57 @@ export function ray3_interval_array_apply_matrix4(output, output_offset, input,
16
20
  const direction_y = input[input_offset + 4];
17
21
  const direction_z = input[input_offset + 5];
18
22
 
23
+ const t_max = input[input_offset + 6];
24
+
25
+
26
+ const in_min_x = origin_x ;
27
+ const in_min_y = origin_y ;
28
+ const in_min_z = origin_z ;
29
+
30
+ const in_max_x = origin_x + direction_x * t_max;
31
+ const in_max_y = origin_y + direction_y * t_max;
32
+ const in_max_z = origin_z + direction_z * t_max;
33
+
19
34
  // transform ray to local space (inlined for speed)
20
- const det = m4[3] * origin_x + m4[7] * origin_y + m4[11] * origin_z + m4[15];
35
+ const w0 = m4[3] * in_min_x + m4[7] * in_min_y + m4[11] * in_min_z + m4[15];
21
36
 
22
- if (det === 0) {
23
- return false;
24
- }
37
+ const inv_w0 = 1 / w0;
25
38
 
26
- const inv_w = 1 / det;
39
+ const out_min_x = (m4[0] * in_min_x + m4[4] * in_min_y + m4[8] * in_min_z + m4[12]) * inv_w0;
40
+ const out_min_y = (m4[1] * in_min_x + m4[5] * in_min_y + m4[9] * in_min_z + m4[13]) * inv_w0;
41
+ const out_min_z = (m4[2] * in_min_x + m4[6] * in_min_y + m4[10] * in_min_z + m4[14]) * inv_w0;
27
42
 
28
- const out_origin_x = (m4[0] * origin_x + m4[4] * origin_y + m4[8] * origin_z + m4[12]) * inv_w;
29
- const out_origin_y = (m4[1] * origin_x + m4[5] * origin_y + m4[9] * origin_z + m4[13]) * inv_w;
30
- const out_origin_z = (m4[2] * origin_x + m4[6] * origin_y + m4[10] * origin_z + m4[14]) * inv_w;
43
+ // transform ray to local space (inlined for speed)
44
+ const w1 = m4[3] * in_max_x + m4[7] * in_max_y + m4[11] * in_max_z + m4[15];
31
45
 
32
- const out_direction_x = m4[0] * direction_x + m4[4] * direction_y + m4[8] * direction_z;
33
- const out_direction_y = m4[1] * direction_x + m4[5] * direction_y + m4[9] * direction_z;
34
- const out_direction_z = m4[2] * direction_x + m4[6] * direction_y + m4[10] * direction_z;
46
+ const inv_w1 = 1 / w1;
35
47
 
36
- // normalize direction
37
- const out_direction_magnitude = Math.hypot(out_direction_x, out_direction_y, out_direction_z);
48
+ const out_max_x = (m4[0] * in_max_x + m4[4] * in_max_y + m4[8] * in_max_z + m4[12]) * inv_w1;
49
+ const out_max_y = (m4[1] * in_max_x + m4[5] * in_max_y + m4[9] * in_max_z + m4[13]) * inv_w1;
50
+ const out_max_z = (m4[2] * in_max_x + m4[6] * in_max_y + m4[10] * in_max_z + m4[14]) * inv_w1;
38
51
 
39
- if (out_direction_magnitude === 0) {
40
- return false;
41
- }
52
+ const delta_x = out_max_x - out_min_x;
53
+ const delta_y = out_max_y - out_min_y;
54
+ const delta_z = out_max_z - out_min_z;
55
+
56
+ // normalize direction
57
+ const out_direction_magnitude = Math.hypot(delta_x, delta_y, delta_z);
42
58
 
43
59
  const out_direction_magnitude_inverse = 1 / out_direction_magnitude;
44
60
 
45
- const out_direction_normalized_x = out_direction_x * out_direction_magnitude_inverse;
46
- const out_direction_normalized_y = out_direction_y * out_direction_magnitude_inverse;
47
- const out_direction_normalized_z = out_direction_z * out_direction_magnitude_inverse;
61
+ const out_direction_normalized_x = delta_x * out_direction_magnitude_inverse;
62
+ const out_direction_normalized_y = delta_y * out_direction_magnitude_inverse;
63
+ const out_direction_normalized_z = delta_z * out_direction_magnitude_inverse;
48
64
 
49
- output[output_offset + 0] = out_origin_x;
50
- output[output_offset + 1] = out_origin_y;
51
- output[output_offset + 2] = out_origin_z;
65
+ output[output_offset + 0] = out_min_x;
66
+ output[output_offset + 1] = out_min_y;
67
+ output[output_offset + 2] = out_min_z;
52
68
 
53
69
  output[output_offset + 3] = out_direction_normalized_x;
54
70
  output[output_offset + 4] = out_direction_normalized_y;
55
71
  output[output_offset + 5] = out_direction_normalized_z;
56
72
 
57
- // TODO implement
58
- throw new Error("Not Implemented")
73
+ output[output_offset + 6] = out_direction_magnitude;
59
74
 
60
75
  return true;
61
76
  }
@@ -60,8 +60,6 @@ async function main() {
60
60
  transform.matrix
61
61
  );
62
62
 
63
- await scene.build();
64
-
65
63
  const depth_map = new Uint32Array(4);
66
64
 
67
65
  trace_triangular_depth_map(depth_map, 0,
@@ -1 +1 @@
1
- {"version":3,"file":"trace_triangular_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js"],"names":[],"mappings":"AAMA;;;;;;;;;;GAUG;AACH,mDATW,WAAW,iBACX,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,UACrB,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,gCAyGhB"}
1
+ {"version":3,"file":"trace_triangular_depth_map.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/tetrahedra/triangle/trace_triangular_depth_map.js"],"names":[],"mappings":"AAOA;;;;;;;;;;GAUG;AACH,mDATW,WAAW,iBACX,MAAM,UACN,MAAM,EAAE,GAAC,YAAY,UACrB,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,gCA2GhB"}
@@ -1,8 +1,9 @@
1
1
  import { v3_length } from "../../../vec3/v3_length.js";
2
2
  import { ray3_array_compose } from "../../ray/ray3_array_compose.js";
3
+ import { Ray3 } from "../../Ray3.js";
3
4
 
4
5
  const scratch = [];
5
- const ray = [];
6
+ const ray = new Ray3();
6
7
 
7
8
  /**
8
9
  *
@@ -92,7 +93,9 @@ export function trace_triangular_depth_map(
92
93
  ray_direction_x, ray_direction_y, ray_direction_z
93
94
  );
94
95
 
95
- const distance = scene.trace(scratch, ray, 0, distance_to_target);
96
+ ray.tMax = distance_to_target;
97
+
98
+ const distance = scene.trace(scratch, ray);
96
99
 
97
100
  let depth;
98
101
  if (distance < 0) {
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Perform rotation on a direction vector using 3x3 portion of a 4x4 matrix
3
+ * @param {number[]|Float32Array} output
4
+ * @param {number} output_offset
5
+ * @param {number[]|Float32Array} input
6
+ * @param {number} input_offset
7
+ * @param {number[]|Float32Array} m4
8
+ */
9
+ export function v3_matrix4_rotate(output: number[] | Float32Array, output_offset: number, input: number[] | Float32Array, input_offset: number, m4: number[] | Float32Array): void;
10
+ //# sourceMappingURL=v3_matrix4_rotate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"v3_matrix4_rotate.d.ts","sourceRoot":"","sources":["../../../../../src/core/geom/vec3/v3_matrix4_rotate.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,0CANW,MAAM,EAAE,GAAC,YAAY,iBACrB,MAAM,SACN,MAAM,EAAE,GAAC,YAAY,gBACrB,MAAM,MACN,MAAM,EAAE,GAAC,YAAY,QAoB/B"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Perform rotation on a direction vector using 3x3 portion of a 4x4 matrix
3
+ * @param {number[]|Float32Array} output
4
+ * @param {number} output_offset
5
+ * @param {number[]|Float32Array} input
6
+ * @param {number} input_offset
7
+ * @param {number[]|Float32Array} m4
8
+ */
9
+ export function v3_matrix4_rotate(
10
+ output, output_offset,
11
+ input, input_offset,
12
+ m4
13
+ ) {
14
+ const x = input[input_offset];
15
+ const y = input[input_offset + 1];
16
+ const z = input[input_offset + 2];
17
+
18
+ const _x = m4[0] * x + m4[4] * y + m4[8] * z;
19
+ const _y = m4[1] * x + m4[5] * y + m4[9] * z;
20
+ const _z = m4[2] * x + m4[6] * y + m4[10] * z;
21
+
22
+ const norm = 1 / Math.hypot(_x, _y, _z);
23
+
24
+ output[output_offset] = _x * norm;
25
+ output[output_offset + 1] = _y * norm;
26
+ output[output_offset + 2] = _z * norm;
27
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"NodeDescription.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeDescription.js"],"names":[],"mappings":"AAwCA;IACI;;;OAGG;IACH,MAFU,MAAM,CAEN;IAEV;;;;;;OAMG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,iBAFU,IAAI,EAAE,CAEL;IAEX;;;OAGG;IACH,YAFU,wBAAwB,EAAE,CAEpB;IAEhB;;OAEG;IACH;QACI;;;WAGG;4BADO,OAAO,IAAI,CAAC;QAGtB;;;WAGG;8BADO,OAAO,IAAI,CAAC;MAGxB;IAEF;;;;OAIG;IACH,4CAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,sBAEC;IAED;;;;;;OAMG;IACH,sBALW,MAAM,QACN,qBAAqB,iBACrB,MAAM,GAAC,OAAO,GAAC,MAAM,GACnB,MAAM,CA0ClB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,wBAAwB,CAiBpC;IAGD;;;;;;OAMG;IACH,oDAHW,aAAa,GACX,MAAM,CA2BlB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,OAAO,CAuBnB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GACJ,IAAI,GAAC,IAAI,CAgBrB;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,IAAI,EAAE,CAwBjB;IAED;;;;OAIG;IACH,+BAHW,aAAa,GACZ,IAAI,EAAE,CAuBjB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,aACN,aAAa,GACZ,IAAI,GAAC,SAAS,CAmBzB;IAED;;;OAGG;IACH,YAFa,IAAI,EAAE,CAIlB;IAED;;;;OAIG;IACH,cAHW,eAAe,GACb,OAAO,CAYnB;IAED,mBAEC;IAED;;;;MAMC;IAED;;;;;;OAMG;IACH,8BALW,EAAE,gCAaZ;IAKL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAR1C;;;;qBAxYoB,WAAW;yCADS,yCAAyC;mBAH/D,kCAAkC;sCAEf,sCAAsC;8BAG9C,oBAAoB"}
1
+ {"version":3,"file":"NodeDescription.d.ts","sourceRoot":"","sources":["../../../../../../src/core/model/node-graph/node/NodeDescription.js"],"names":[],"mappings":"AAwCA;IACI;;;OAGG;IACH,MAFU,MAAM,CAEN;IAEV;;;;;;OAMG;IACH,IAFU,MAAM,CAEO;IAEvB;;;OAGG;IACH,iBAFU,IAAI,EAAE,CAEL;IAEX;;;OAGG;IACH,YAFU,wBAAwB,EAAE,CAEpB;IAEhB;;OAEG;IACH;QACI;;;WAGG;4BADO,OAAO,IAAI,CAAC;QAGtB;;;WAGG;8BADO,OAAO,IAAI,CAAC;MAGxB;IAEF;;;;OAIG;IACH,4CAEC;IAED;;;OAGG;IACH,uBAEC;IAED;;;OAGG;IACH,sBAEC;IAED;;;;;;OAMG;IACH,sBALW,MAAM,QACN,qBAAqB,iBACrB,MAAM,GAAC,OAAO,GAAC,MAAM,GACnB,MAAM,CA0ClB;IAED;;;;OAIG;IACH,iBAHW,MAAM,GACJ,wBAAwB,CAiBpC;IAGD;;;;;;OAMG;IACH,oDAHW,aAAa,GACX,MAAM,CA2BlB;IAED;;;;OAIG;IACH,eAHW,MAAM,GACJ,OAAO,CAuBnB;IAED;;;;OAIG;IACH,gBAHW,MAAM,GACJ,IAAI,GAAC,IAAI,CAgBrB;IAED;;;;OAIG;IACH,qBAHW,MAAM,GACL,IAAI,EAAE,CAwBjB;IAED;;;;;OAKG;IACH,+BAHW,aAAa,GACZ,OAAO,CAiBlB;IAED;;;;OAIG;IACH,+BAHW,aAAa,GACZ,IAAI,EAAE,CAuBjB;IAED;;;;;OAKG;IACH,iCAJW,MAAM,aACN,aAAa,GACZ,IAAI,GAAC,SAAS,CAmBzB;IAED;;;OAGG;IACH,YAFa,IAAI,EAAE,CAIlB;IAED;;;;OAIG;IACH,cAHW,eAAe,GACb,OAAO,CAYnB;IAED,mBAEC;IAED;;;;MAMC;IAED;;;;;;OAMG;IACH,8BALW,EAAE,gCAaZ;IAKL;;;OAGG;IACH,4BAFU,OAAO,CAE0B;CAR1C;;;;qBA/ZoB,WAAW;yCADS,yCAAyC;mBAH/D,kCAAkC;sCAEf,sCAAsC;8BAG9C,oBAAoB"}