@woosh/meep-engine 2.108.4 → 2.109.1
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.
- package/build/meep.cjs +101 -61
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +101 -61
- package/package.json +1 -1
- package/src/core/assert.d.ts +2 -2
- package/src/core/assert.d.ts.map +1 -1
- package/src/core/assert.js +1 -1
- package/src/core/binary/BitSet.d.ts +6 -0
- package/src/core/binary/BitSet.d.ts.map +1 -1
- package/src/core/binary/BitSet.js +14 -42
- package/src/core/binary/align_32.d.ts +7 -0
- package/src/core/binary/align_32.d.ts.map +1 -0
- package/src/core/binary/align_32.js +8 -0
- package/src/core/binary/align_32.spec.d.ts +2 -0
- package/src/core/binary/align_32.spec.d.ts.map +1 -0
- package/src/core/binary/align_32.spec.js +11 -0
- package/src/core/binary/align_4.js +2 -1
- package/src/core/binary/align_4.spec.d.ts +2 -0
- package/src/core/binary/align_4.spec.d.ts.map +1 -0
- package/src/core/binary/align_4.spec.js +20 -0
- package/src/core/binary/{de_interleave_bits_by_2.d.ts → de_interleave_2_bits.d.ts} +1 -1
- package/src/core/binary/de_interleave_2_bits.d.ts.map +1 -0
- package/src/core/binary/de_interleave_2_bits.spec.js +1 -1
- package/src/core/binary/hex2dec.spec.d.ts +2 -0
- package/src/core/binary/hex2dec.spec.d.ts.map +1 -0
- package/src/core/binary/hex2dec.spec.js +22 -0
- package/src/core/binary/lsb_32.d.ts +9 -0
- package/src/core/binary/lsb_32.d.ts.map +1 -0
- package/src/core/binary/lsb_32.js +12 -0
- package/src/core/binary/msb_32.d.ts +2 -0
- package/src/core/binary/msb_32.d.ts.map +1 -0
- package/src/core/binary/msb_32.js +20 -0
- package/src/core/binary/msb_lut_de_bruijn.d.ts +7 -0
- package/src/core/binary/msb_lut_de_bruijn.d.ts.map +1 -0
- package/src/core/binary/msb_lut_de_bruijn.js +9 -0
- package/src/core/binary/split_by_2.spec.d.ts +2 -0
- package/src/core/binary/split_by_2.spec.d.ts.map +1 -0
- package/src/core/binary/split_by_2.spec.js +22 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts +4 -1
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +16 -7
- package/src/core/bvh2/bvh3/ebvh_build_hierarchy.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.d.ts.map +1 -1
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_ray.js +12 -7
- package/src/core/geom/2d/circle/circle_circumference.d.ts +7 -0
- package/src/core/geom/2d/circle/circle_circumference.d.ts.map +1 -0
- package/src/core/geom/2d/circle/circle_circumference.js +12 -0
- package/src/core/geom/2d/compute_polygon_area_2d.d.ts.map +1 -1
- package/src/core/geom/2d/compute_polygon_area_2d.js +6 -4
- package/src/core/geom/2d/lt-grid/LooseTightGrid.js +1 -1
- package/src/core/geom/2d/triangle2d_get_barycentric.d.ts +2 -2
- package/src/core/geom/2d/triangle2d_get_barycentric.js +2 -2
- package/src/core/geom/3d/Ray3.d.ts +19 -0
- package/src/core/geom/3d/Ray3.d.ts.map +1 -0
- package/src/core/geom/3d/Ray3.js +27 -0
- package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.d.ts +10 -0
- package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.d.ts.map +1 -0
- package/src/core/geom/3d/ray/ray3_shift_origin_along_direction.js +35 -0
- package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.d.ts +1 -0
- package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/compute_legendre_polynomial.js +0 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.d.ts +9 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_convolve_with_cosine_kernel.js +26 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.d.ts.map +1 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +2 -4
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_bl.js +94 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts +8 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate_filament.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/{sh3_rotate.js → sh3_rotate_filament.js} +5 -2
- package/src/core/geom/3d/sphere/harmonics/sh3_vector_accumulate.d.ts +12 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_vector_accumulate.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_vector_accumulate.js +40 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_vector_accumulate.spec.d.ts +2 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_vector_accumulate.spec.d.ts.map +1 -0
- package/src/core/geom/3d/sphere/harmonics/sh3_vector_accumulate.spec.js +27 -0
- package/src/core/geom/3d/sphere/harmonics/sh_compute_K.d.ts +3 -3
- package/src/core/geom/3d/sphere/harmonics/sh_compute_K.js +3 -3
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.d.ts.map +1 -1
- package/src/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_build_from_grid.js +29 -14
- package/src/core/geom/Quaternion.js +1 -1
- package/src/core/geom/vec/vector_copy.d.ts +10 -0
- package/src/core/geom/vec/vector_copy.d.ts.map +1 -0
- package/src/core/geom/vec/vector_copy.js +13 -0
- package/src/core/{math/vector_nd_dot.d.ts → geom/vec/vector_dot.d.ts} +2 -2
- package/src/core/geom/vec/vector_dot.d.ts.map +1 -0
- package/src/core/{math/vector_nd_dot.js → geom/vec/vector_dot.js} +1 -1
- package/src/core/{math/vector_nd_normalize.d.ts → geom/vec/vector_normalize.d.ts} +2 -2
- package/src/core/geom/vec/vector_normalize.d.ts.map +1 -0
- package/src/core/{math/vector_nd_normalize.js → geom/vec/vector_normalize.js} +1 -1
- package/src/core/geom/vec/vector_normalize.spec.d.ts +2 -0
- package/src/core/geom/vec/vector_normalize.spec.d.ts.map +1 -0
- package/src/core/{math/vector_nd_normalize.spec.js → geom/vec/vector_normalize.spec.js} +3 -3
- package/src/core/geom/vec/vector_scale_array.d.ts +11 -0
- package/src/core/geom/vec/vector_scale_array.d.ts.map +1 -0
- package/src/core/geom/vec/vector_scale_array.js +31 -0
- package/src/core/geom/vec3/v3_dot_array_array.js +2 -0
- package/src/core/geom/vec3/v3_matrix4_multiply.d.ts +10 -0
- package/src/core/geom/vec3/v3_matrix4_multiply.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_matrix4_multiply.js +27 -0
- package/src/core/geom/vec3/v3_shift_along_direction.d.ts +14 -0
- package/src/core/geom/vec3/v3_shift_along_direction.d.ts.map +1 -0
- package/src/core/geom/vec3/v3_shift_along_direction.js +23 -0
- package/src/core/math/compute_legendre_polynomial.d.ts +10 -0
- package/src/core/math/compute_legendre_polynomial.d.ts.map +1 -0
- package/src/core/math/compute_legendre_polynomial.js +46 -0
- package/src/core/math/statistics/softmax.d.ts +11 -0
- package/src/core/math/statistics/softmax.d.ts.map +1 -0
- package/src/core/math/statistics/softmax.js +24 -0
- package/src/core/math/statistics/softmax.spec.d.ts +2 -0
- package/src/core/math/statistics/softmax.spec.d.ts.map +1 -0
- package/src/core/math/statistics/softmax.spec.js +9 -0
- package/src/core/model/node-graph/node/NodeInstance.d.ts.map +1 -1
- package/src/core/model/node-graph/node/NodeInstance.js +18 -0
- package/src/engine/ecs/transform/Transform.d.ts.map +1 -1
- package/src/engine/ecs/transform/Transform.js +19 -4
- package/src/engine/graphics/ecs/camera/CameraSystem.d.ts.map +1 -1
- package/src/engine/graphics/ecs/camera/CameraSystem.js +25 -13
- package/src/engine/graphics/geometry/decode_attribute_value.d.ts +10 -0
- package/src/engine/graphics/geometry/decode_attribute_value.d.ts.map +1 -0
- package/src/engine/graphics/geometry/decode_attribute_value.js +28 -0
- package/src/engine/graphics/geometry/geometry_construct_triangle_normal.d.ts +11 -0
- package/src/engine/graphics/geometry/geometry_construct_triangle_normal.d.ts.map +1 -0
- package/src/engine/graphics/geometry/geometry_construct_triangle_normal.js +31 -0
- package/src/engine/graphics/sh3/fromCubeRenderTarget.d.ts.map +1 -1
- package/src/engine/graphics/sh3/fromCubeRenderTarget.js +14 -17
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts +3 -2
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/LightProbeVolume.js +21 -97
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js +8 -15
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts +1 -0
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.d.ts.map +1 -1
- package/src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js +6 -2
- package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.d.ts → BufferedGeometryBVH.d.ts} +9 -2
- package/src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.js → BufferedGeometryBVH.js} +84 -5
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts +6 -4
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedMesh.js +54 -8
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts +6 -10
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/PathTracedScene.js +41 -47
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts +11 -0
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js +102 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts +9 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js +17 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.d.ts +31 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/StandardTexture.js +85 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.d.ts +14 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureFilter.js +17 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.d.ts +7 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.d.ts.map +1 -0
- package/src/engine/graphics/sh3/path_tracer/material/TextureWrapping.js +9 -0
- package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +104 -9
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts +1 -2
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.d.ts.map +1 -1
- package/src/engine/graphics/sh3/path_tracer/texture/sample_material.js +50 -23
- package/src/engine/graphics/sh3/prototypeSH3Probe.js +79 -29
- package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts +11 -1
- package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.d.ts.map +1 -1
- package/src/engine/graphics/sh3/visualise_spherical_harmonic_sphere.js +33 -16
- package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.d.ts +8 -0
- package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/one_pixel_sampler_uint8.js +10 -0
- package/src/engine/graphics/texture/sampler/sampler_multiply_vector.d.ts +8 -0
- package/src/engine/graphics/texture/sampler/sampler_multiply_vector.d.ts.map +1 -0
- package/src/engine/graphics/texture/sampler/sampler_multiply_vector.js +23 -0
- package/src/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.d.ts.map +1 -1
- package/src/engine/sound/material/detector/terrain/TerrainSoundMaterialSurfaceDetector.js +6 -6
- package/src/core/binary/de_interleave_bits_by_2.d.ts.map +0 -1
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts +0 -8
- package/src/core/geom/3d/sphere/harmonics/sh3_rotate.d.ts.map +0 -1
- package/src/core/math/vector_nd_dot.d.ts.map +0 -1
- package/src/core/math/vector_nd_normalize.d.ts.map +0 -1
- package/src/core/math/vector_nd_normalize.spec.d.ts +0 -2
- package/src/core/math/vector_nd_normalize.spec.d.ts.map +0 -1
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.d.ts.map +0 -1
- /package/src/core/binary/{de_interleave_bits_by_2.js → de_interleave_2_bits.js} +0 -0
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export class PathTracedMesh {
|
|
2
|
+
aabb: AABB3;
|
|
2
3
|
/**
|
|
3
4
|
*
|
|
4
|
-
* @type {
|
|
5
|
+
* @type {BufferedGeometryBVH|null}
|
|
5
6
|
*/
|
|
6
|
-
geo_bvh:
|
|
7
|
+
geo_bvh: BufferedGeometryBVH | null;
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
9
10
|
* @type {THREE.BufferGeometry|null}
|
|
@@ -11,9 +12,9 @@ export class PathTracedMesh {
|
|
|
11
12
|
geometry: THREE.BufferGeometry | null;
|
|
12
13
|
/**
|
|
13
14
|
*
|
|
14
|
-
* @type {
|
|
15
|
+
* @type {StandardMaterial|null}
|
|
15
16
|
*/
|
|
16
|
-
material:
|
|
17
|
+
material: StandardMaterial | null;
|
|
17
18
|
__transform_inverse: Float32Array;
|
|
18
19
|
__transform: Float32Array;
|
|
19
20
|
__local_scale_inverse: number;
|
|
@@ -34,4 +35,5 @@ export class PathTracedMesh {
|
|
|
34
35
|
*/
|
|
35
36
|
hit(out: number[], ray: number[], min_distance: number, max_distance: number): number;
|
|
36
37
|
}
|
|
38
|
+
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
37
39
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"PathTracedMesh.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedMesh.js"],"names":[],"mappings":"AAcA;IACI,YAAmB;IAIf;;;OAGG;IACH,SAFU,sBAAoB,IAAI,CAEf;IAEnB;;;OAGG;IACH,UAFU,MAAM,cAAc,GAAC,IAAI,CAEf;IAEpB;;;OAGG;IACH,UAFU,mBAAiB,IAAI,CAEX;IAIpB,kCAA0D;IAC1D,0BAAuD;IACvD,8BAA8B;IAE9B;;;OAGG;IACH,IAFU,MAAM,CAEW;IAG/B,iCAgBC;IAED,8BAEC;IAED;;;;;;;OAOG;IACH,SANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CAuDlB;CACJ;sBApIqB,wCAAwC"}
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
2
1
|
import { mat4 } from "gl-matrix";
|
|
2
|
+
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
3
|
+
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
3
4
|
import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
5
|
+
import { ray3_shift_origin_along_direction } from "../../../../core/geom/3d/ray/ray3_shift_origin_along_direction.js";
|
|
6
|
+
import { v3_distance } from "../../../../core/geom/vec3/v3_distance.js";
|
|
7
|
+
import { v3_matrix4_multiply } from "../../../../core/geom/vec3/v3_matrix4_multiply.js";
|
|
8
|
+
import { v3_shift_along_direction } from "../../../../core/geom/vec3/v3_shift_along_direction.js";
|
|
4
9
|
import { ray_hit_apply_transform } from "./ray_hit_apply_transform.js";
|
|
5
10
|
|
|
6
11
|
const local_ray = new Float32Array(6);
|
|
12
|
+
const scratch_v3 = new Float32Array(3);
|
|
7
13
|
let mesh_id_counter = 0;
|
|
8
14
|
|
|
9
15
|
export class PathTracedMesh {
|
|
16
|
+
aabb = new AABB3();
|
|
17
|
+
|
|
10
18
|
constructor() {
|
|
11
19
|
|
|
12
20
|
/**
|
|
13
21
|
*
|
|
14
|
-
* @type {
|
|
22
|
+
* @type {BufferedGeometryBVH|null}
|
|
15
23
|
*/
|
|
16
24
|
this.geo_bvh = null;
|
|
17
25
|
|
|
@@ -23,7 +31,7 @@ export class PathTracedMesh {
|
|
|
23
31
|
|
|
24
32
|
/**
|
|
25
33
|
*
|
|
26
|
-
* @type {
|
|
34
|
+
* @type {StandardMaterial|null}
|
|
27
35
|
*/
|
|
28
36
|
this.material = null;
|
|
29
37
|
|
|
@@ -51,7 +59,11 @@ export class PathTracedMesh {
|
|
|
51
59
|
const scale_y = Math.hypot(m4[4], m4[5], m4[6]);
|
|
52
60
|
const scale_z = Math.hypot(m4[8], m4[9], m4[10]);
|
|
53
61
|
|
|
54
|
-
this.__local_scale_inverse = Math.
|
|
62
|
+
this.__local_scale_inverse = Math.max(scale_x, scale_y, scale_z);
|
|
63
|
+
|
|
64
|
+
// get bounds
|
|
65
|
+
this.geo_bvh.getBounds(this.aabb);
|
|
66
|
+
this.aabb.applyMatrix4(m);
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
get transform() {
|
|
@@ -69,11 +81,37 @@ export class PathTracedMesh {
|
|
|
69
81
|
hit(out, ray, min_distance, max_distance) {
|
|
70
82
|
//transform ray
|
|
71
83
|
const m4 = this.__transform_inverse;
|
|
72
|
-
ray3_array_apply_matrix4(local_ray,0, ray,0, m4);
|
|
73
84
|
|
|
74
|
-
const scale_d = this.__local_scale_inverse;
|
|
75
85
|
|
|
76
|
-
|
|
86
|
+
// shift ray forward by "min distance"
|
|
87
|
+
ray3_shift_origin_along_direction(local_ray, 0, ray, 0, min_distance);
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
ray3_array_apply_matrix4(local_ray, 0, local_ray, 0, m4);
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
let max_distance_local = Infinity;
|
|
94
|
+
|
|
95
|
+
if (max_distance !== Infinity) {
|
|
96
|
+
// compute position of point at max_distance along the ray
|
|
97
|
+
v3_shift_along_direction(
|
|
98
|
+
scratch_v3, 0,
|
|
99
|
+
ray[0], ray[1], ray[2],
|
|
100
|
+
ray[3], ray[4], ray[5],
|
|
101
|
+
max_distance
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
// move far point into local coordinate space
|
|
105
|
+
v3_matrix4_multiply(scratch_v3, 0, scratch_v3, 0, m4);
|
|
106
|
+
|
|
107
|
+
// compute far distance in local space
|
|
108
|
+
max_distance_local = v3_distance(
|
|
109
|
+
local_ray[0], local_ray[1], local_ray[2],
|
|
110
|
+
scratch_v3[0], scratch_v3[1], scratch_v3[2]
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
let distance_to_hit = this.geo_bvh.raycast(out, local_ray, 0, max_distance_local);
|
|
77
115
|
|
|
78
116
|
if (distance_to_hit >= 0) {
|
|
79
117
|
// transform output
|
|
@@ -81,9 +119,17 @@ export class PathTracedMesh {
|
|
|
81
119
|
|
|
82
120
|
out[10] = this.id;
|
|
83
121
|
|
|
84
|
-
distance_to_hit
|
|
122
|
+
distance_to_hit = v3_distance(
|
|
123
|
+
ray[0], ray[1], ray[2],
|
|
124
|
+
out[0], out[1], out[2]
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
if (distance_to_hit > max_distance) {
|
|
128
|
+
return -1;
|
|
129
|
+
}
|
|
85
130
|
}
|
|
86
131
|
|
|
132
|
+
|
|
87
133
|
return distance_to_hit;
|
|
88
134
|
}
|
|
89
135
|
}
|
|
@@ -16,14 +16,9 @@ export class PathTracedScene {
|
|
|
16
16
|
__lights: AbstractLight[];
|
|
17
17
|
/**
|
|
18
18
|
*
|
|
19
|
-
* @type {Map<THREE.BufferGeometry,
|
|
19
|
+
* @type {Map<THREE.BufferGeometry, BufferedGeometryBVH>}
|
|
20
20
|
*/
|
|
21
|
-
geo_cache: Map<THREE.BufferGeometry,
|
|
22
|
-
/**
|
|
23
|
-
* Maps {@link Texture.id} to relevant sampler
|
|
24
|
-
* @type {Map<number, Sampler2D>}
|
|
25
|
-
*/
|
|
26
|
-
textures: Map<number, Sampler2D>;
|
|
21
|
+
geo_cache: Map<THREE.BufferGeometry, BufferedGeometryBVH>;
|
|
27
22
|
/**
|
|
28
23
|
*
|
|
29
24
|
* @type {function}
|
|
@@ -35,9 +30,9 @@ export class PathTracedScene {
|
|
|
35
30
|
/**
|
|
36
31
|
*
|
|
37
32
|
* @param {THREE.BufferGeometry} geo
|
|
38
|
-
* @return {
|
|
33
|
+
* @return {BufferedGeometryBVH}
|
|
39
34
|
*/
|
|
40
|
-
obtainGeometryBVH(geo: THREE.BufferGeometry):
|
|
35
|
+
obtainGeometryBVH(geo: THREE.BufferGeometry): BufferedGeometryBVH;
|
|
41
36
|
/**
|
|
42
37
|
*
|
|
43
38
|
* @param {AbstractLight} light
|
|
@@ -82,9 +77,10 @@ export class PathTracedScene {
|
|
|
82
77
|
* @returns {boolean}
|
|
83
78
|
*/
|
|
84
79
|
sample_lights(out: number[], out_offset: number, ray: number[], ray_address: number): boolean;
|
|
80
|
+
#private;
|
|
85
81
|
}
|
|
86
82
|
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
87
83
|
import { PathTracedMesh } from "./PathTracedMesh.js";
|
|
88
84
|
import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
|
|
89
|
-
import {
|
|
85
|
+
import { BufferedGeometryBVH } from "./BufferedGeometryBVH.js";
|
|
90
86
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"PathTracedScene.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/PathTracedScene.js"],"names":[],"mappings":"AA8BA;IAGI;;;OAGG;IACH,eAFU,GAAG,CAEa;IAE1B;;;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;IAatB;;;;OAIG;IACH,6BAA6C;IAE7C,iBAGC;IAED,uBAMC;IAED;;;;OAIG;IACH,uBAHW,MAAM,cAAc,GACnB,mBAAmB,CAmB9B;IAED;;;OAGG;IACH,gBAFW,aAAa,QAMvB;IAED;;;;;OAKG;IACH,aAJW,MAAM,cAAc,YACpB,MAAM,QAAQ,aACd,OAAK,MAAM,EAAE,QA8CvB;IAED;;;;OAIG;IACH,qBAHW,MAAM,EAAE,OACR,MAAM,EAAE,QAyBlB;IAED;;;;;;;OAOG;IACH,WANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACL,MAAM,CAqDjB;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;oBA7VmB,mCAAmC;+BAkBxB,qBAAqB;8BALtB,kDAAkD;oCAE5C,0BAA0B"}
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { assert } from "../../../../core/assert.js";
|
|
2
2
|
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
3
3
|
import { ebvh_sort_for_traversal_depth_first } from "../../../../core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js";
|
|
4
|
-
import {
|
|
4
|
+
import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
5
|
+
import { Cache } from "../../../../core/cache/Cache.js";
|
|
5
6
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
7
|
+
import { strictEquals } from "../../../../core/function/strictEquals.js";
|
|
6
8
|
import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
9
|
+
import {
|
|
10
|
+
aabb3_unsigned_distance_sqr_to_point
|
|
11
|
+
} from "../../../../core/geom/3d/aabb/aabb3_unsigned_distance_sqr_to_point.js";
|
|
7
12
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
8
13
|
import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
|
|
9
|
-
import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
10
14
|
import { compute_geometry_polycount } from "../../geometry/compute_geometry_polycount.js";
|
|
11
15
|
import { AbstractLight } from "../../render/forward_plus/model/AbstractLight.js";
|
|
12
|
-
import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2Sampler2D.js";
|
|
13
16
|
import { ensureGeometryBoundingBox } from "../../util/ensureGeometryBoundingBox.js";
|
|
14
|
-
import {
|
|
17
|
+
import { BufferedGeometryBVH } from "./BufferedGeometryBVH.js";
|
|
15
18
|
import { make_vector3 } from "./make_one_vector3.js";
|
|
19
|
+
import { MaterialConverter } from "./material/MaterialConverter.js";
|
|
16
20
|
import { PathTracedMesh } from "./PathTracedMesh.js";
|
|
17
21
|
import { sample_material } from "./texture/sample_material.js";
|
|
18
22
|
|
|
@@ -21,6 +25,9 @@ const _ray_1 = [];
|
|
|
21
25
|
const tmp_0 = [];
|
|
22
26
|
const null_output = [];
|
|
23
27
|
|
|
28
|
+
const DEFAULT_CONVERTER = new MaterialConverter();
|
|
29
|
+
|
|
30
|
+
|
|
24
31
|
export class PathTracedScene {
|
|
25
32
|
|
|
26
33
|
|
|
@@ -44,16 +51,20 @@ export class PathTracedScene {
|
|
|
44
51
|
|
|
45
52
|
/**
|
|
46
53
|
*
|
|
47
|
-
* @type {Map<THREE.BufferGeometry,
|
|
54
|
+
* @type {Map<THREE.BufferGeometry, BufferedGeometryBVH>}
|
|
48
55
|
*/
|
|
49
56
|
geo_cache = new Map();
|
|
50
57
|
|
|
51
58
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @type {
|
|
59
|
+
*
|
|
60
|
+
* @type {Cache<THREE.Material, StandardMaterial>}
|
|
54
61
|
*/
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
#material_cache = new Cache({
|
|
63
|
+
keyEqualityFunction: strictEquals,
|
|
64
|
+
keyHashFunction(mat) {
|
|
65
|
+
return mat.id
|
|
66
|
+
}
|
|
67
|
+
});
|
|
57
68
|
|
|
58
69
|
/**
|
|
59
70
|
*
|
|
@@ -72,44 +83,13 @@ export class PathTracedScene {
|
|
|
72
83
|
for (const [id, mesh] of this.meshes) {
|
|
73
84
|
const material = mesh.material;
|
|
74
85
|
|
|
75
|
-
//patch textures
|
|
76
|
-
const materialType = material.type;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @type {TextureAttachment[]}
|
|
81
|
-
*/
|
|
82
|
-
const attachments = TextureAttachmentsByMaterialType[materialType];
|
|
83
|
-
|
|
84
|
-
if (attachments === undefined) {
|
|
85
|
-
// unsupported
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
for (let i = 0; i < attachments.length; i++) {
|
|
90
|
-
const attachment = attachments[i];
|
|
91
|
-
|
|
92
|
-
const texture = attachment.read(material);
|
|
93
|
-
|
|
94
|
-
if (texture === undefined || texture === null) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (this.textures.has(texture.id)) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const sampler2D = convertTexture2Sampler2D(texture, undefined, undefined, false);
|
|
103
|
-
|
|
104
|
-
this.textures.set(texture.id, sampler2D);
|
|
105
|
-
}
|
|
106
86
|
}
|
|
107
87
|
}
|
|
108
88
|
|
|
109
89
|
/**
|
|
110
90
|
*
|
|
111
91
|
* @param {THREE.BufferGeometry} geo
|
|
112
|
-
* @return {
|
|
92
|
+
* @return {BufferedGeometryBVH}
|
|
113
93
|
*/
|
|
114
94
|
obtainGeometryBVH(geo) {
|
|
115
95
|
const cached = this.geo_cache.get(geo);
|
|
@@ -118,7 +98,7 @@ export class PathTracedScene {
|
|
|
118
98
|
return cached;
|
|
119
99
|
}
|
|
120
100
|
|
|
121
|
-
const bvh = new
|
|
101
|
+
const bvh = new BufferedGeometryBVH();
|
|
122
102
|
|
|
123
103
|
const label = `bvh build ${compute_geometry_polycount(geo)}`;
|
|
124
104
|
console.time(label);
|
|
@@ -151,12 +131,13 @@ export class PathTracedScene {
|
|
|
151
131
|
|
|
152
132
|
const mesh = new PathTracedMesh();
|
|
153
133
|
mesh.geometry = geo;
|
|
154
|
-
mesh.material = material;
|
|
155
|
-
mesh.transform = transform;
|
|
156
134
|
|
|
135
|
+
mesh.material = this.#material_cache.getOrCompute(material, DEFAULT_CONVERTER.convert, DEFAULT_CONVERTER);
|
|
157
136
|
|
|
158
137
|
mesh.geo_bvh = this.obtainGeometryBVH(geo);
|
|
159
138
|
|
|
139
|
+
mesh.transform = transform;
|
|
140
|
+
|
|
160
141
|
const bvh = this.bvh_top_level;
|
|
161
142
|
|
|
162
143
|
const bvh_node_id = bvh.allocate_node();
|
|
@@ -217,7 +198,7 @@ export class PathTracedScene {
|
|
|
217
198
|
return;
|
|
218
199
|
}
|
|
219
200
|
|
|
220
|
-
sample_material(out, mesh,
|
|
201
|
+
sample_material(out, mesh, primitive_id, u, v);
|
|
221
202
|
|
|
222
203
|
}
|
|
223
204
|
|
|
@@ -232,7 +213,7 @@ export class PathTracedScene {
|
|
|
232
213
|
trace(out, ray, min_distance, max_distance) {
|
|
233
214
|
const bvh = this.bvh_top_level;
|
|
234
215
|
|
|
235
|
-
const hit_count =
|
|
216
|
+
const hit_count = bvh_query_leaves_ray(
|
|
236
217
|
bvh, bvh.root,
|
|
237
218
|
temp_ray_results, 0,
|
|
238
219
|
ray[0], ray[1], ray[2],
|
|
@@ -244,7 +225,20 @@ export class PathTracedScene {
|
|
|
244
225
|
|
|
245
226
|
|
|
246
227
|
for (let i = 0; i < hit_count; i++) {
|
|
247
|
-
const
|
|
228
|
+
const node = temp_ray_results[i];
|
|
229
|
+
|
|
230
|
+
bvh.node_get_aabb(node, tmp_0);
|
|
231
|
+
|
|
232
|
+
if (aabb3_unsigned_distance_sqr_to_point(
|
|
233
|
+
tmp_0[0], tmp_0[1], tmp_0[2],
|
|
234
|
+
tmp_0[3], tmp_0[4], tmp_0[5],
|
|
235
|
+
ray[0], ray[1], ray[2]
|
|
236
|
+
) > nearest_hit_distance * nearest_hit_distance) {
|
|
237
|
+
// bounds of the mesh are too far
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const node_user_data = bvh.node_get_user_data(node);
|
|
248
242
|
|
|
249
243
|
const mesh = this.meshes.get(node_user_data);
|
|
250
244
|
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class MaterialConverter {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {THREE.Material} material
|
|
5
|
+
* @returns {StandardMaterial}
|
|
6
|
+
*/
|
|
7
|
+
convert(material: THREE.Material): StandardMaterial;
|
|
8
|
+
#private;
|
|
9
|
+
}
|
|
10
|
+
import { StandardMaterial } from "./StandardMaterial.js";
|
|
11
|
+
//# sourceMappingURL=MaterialConverter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaterialConverter.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/MaterialConverter.js"],"names":[],"mappings":"AASA;IA4BI;;;;OAIG;IACH,kBAHW,MAAM,QAAQ,GACZ,gBAAgB,CA2D5B;;CAEJ;iCA/FgC,uBAAuB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Color } from "three";
|
|
2
|
+
import {
|
|
3
|
+
TextureAttachmentsByMaterialType
|
|
4
|
+
} from "../../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
5
|
+
import { convertTexture2Sampler2D } from "../../../texture/sampler/convertTexture2Sampler2D.js";
|
|
6
|
+
import { sampler_multiply_vector } from "../../../texture/sampler/sampler_multiply_vector.js";
|
|
7
|
+
import { StandardMaterial } from "./StandardMaterial.js";
|
|
8
|
+
import { StandardTexture } from "./StandardTexture.js";
|
|
9
|
+
|
|
10
|
+
export class MaterialConverter {
|
|
11
|
+
/**
|
|
12
|
+
* Maps {@link Texture.id} to relevant sampler
|
|
13
|
+
* @type {Map<number, StandardTexture>}
|
|
14
|
+
*/
|
|
15
|
+
#textures = new Map();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {THREE.Texture} texture
|
|
20
|
+
* @returns {StandardTexture}
|
|
21
|
+
*/
|
|
22
|
+
#ensure_texture(texture) {
|
|
23
|
+
const existing = this.#textures.get(texture.id);
|
|
24
|
+
|
|
25
|
+
if (existing !== undefined) {
|
|
26
|
+
return existing
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const sampler2D = convertTexture2Sampler2D(texture, undefined, undefined, false);
|
|
30
|
+
|
|
31
|
+
const st = StandardTexture.from(sampler2D);
|
|
32
|
+
|
|
33
|
+
this.#textures.set(texture.id, st);
|
|
34
|
+
|
|
35
|
+
return st;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {THREE.Material} material
|
|
41
|
+
* @returns {StandardMaterial}
|
|
42
|
+
*/
|
|
43
|
+
convert(material) {
|
|
44
|
+
|
|
45
|
+
const result = new StandardMaterial();
|
|
46
|
+
|
|
47
|
+
//patch textures
|
|
48
|
+
const materialType = material.type;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @type {TextureAttachment[]}
|
|
53
|
+
*/
|
|
54
|
+
const attachments = TextureAttachmentsByMaterialType[materialType];
|
|
55
|
+
|
|
56
|
+
if (attachments !== undefined) {
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < attachments.length; i++) {
|
|
59
|
+
const attachment = attachments[i];
|
|
60
|
+
|
|
61
|
+
const texture = attachment.read(material);
|
|
62
|
+
|
|
63
|
+
if (texture === undefined || texture === null) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const sampler = this.#ensure_texture(texture);
|
|
68
|
+
|
|
69
|
+
const name = attachment.name;
|
|
70
|
+
|
|
71
|
+
if (name === "diffuse") {
|
|
72
|
+
result.diffuse = sampler;
|
|
73
|
+
} else if (name === "normal") {
|
|
74
|
+
result.normal = sampler;
|
|
75
|
+
} else if (name === "metalness") {
|
|
76
|
+
result.metalness = sampler;
|
|
77
|
+
} else if (name === "roughness") {
|
|
78
|
+
result.roughness = sampler;
|
|
79
|
+
} else if (name === "emissive") {
|
|
80
|
+
result.emissive = sampler;
|
|
81
|
+
} else {
|
|
82
|
+
// unused
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (material.color !== undefined && !material.color.equals(new Color(1, 1, 1))) {
|
|
90
|
+
const tinted_diffuse = result.diffuse.clone();
|
|
91
|
+
|
|
92
|
+
tinted_diffuse.sampler = tinted_diffuse.sampler.clone();
|
|
93
|
+
|
|
94
|
+
sampler_multiply_vector(tinted_diffuse.sampler, result.diffuse.sampler, material.color.toArray());
|
|
95
|
+
|
|
96
|
+
result.diffuse = tinted_diffuse;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return result;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class StandardMaterial {
|
|
2
|
+
diffuse: StandardTexture;
|
|
3
|
+
normal: StandardTexture;
|
|
4
|
+
emissive: StandardTexture;
|
|
5
|
+
roughness: StandardTexture;
|
|
6
|
+
metalness: StandardTexture;
|
|
7
|
+
}
|
|
8
|
+
import { StandardTexture } from "./StandardTexture.js";
|
|
9
|
+
//# sourceMappingURL=StandardMaterial.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardMaterial.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/StandardMaterial.js"],"names":[],"mappings":"AASA;IACI,yBAA+C;IAC/C,wBAA6C;IAC7C,0BAAiD;IACjD,2BAAmD;IACnD,2BAAmD;CACtD;gCAd+B,sBAAsB"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { one_pixel_sampler_uint8 } from "../../../texture/sampler/one_pixel_sampler_uint8.js";
|
|
2
|
+
import { StandardTexture } from "./StandardTexture.js";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_DIFFUSE = one_pixel_sampler_uint8([255, 255, 255, 255]);
|
|
5
|
+
const DEFAULT_NORMAL = one_pixel_sampler_uint8([0, 0, 255]);
|
|
6
|
+
const DEFAULT_EMISSIVE = one_pixel_sampler_uint8([0, 0, 0]);
|
|
7
|
+
const DEFAULT_ROUGHNESS = one_pixel_sampler_uint8([255]);
|
|
8
|
+
const DEFAULT_METALNESS = one_pixel_sampler_uint8([0]);
|
|
9
|
+
|
|
10
|
+
export class StandardMaterial {
|
|
11
|
+
diffuse = StandardTexture.from(DEFAULT_DIFFUSE)
|
|
12
|
+
normal = StandardTexture.from(DEFAULT_NORMAL)
|
|
13
|
+
emissive = StandardTexture.from(DEFAULT_EMISSIVE)
|
|
14
|
+
roughness = StandardTexture.from(DEFAULT_ROUGHNESS)
|
|
15
|
+
metalness = StandardTexture.from(DEFAULT_METALNESS)
|
|
16
|
+
}
|
|
17
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export class StandardTexture {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {Sampler2D} sampler
|
|
5
|
+
* @returns {StandardTexture}
|
|
6
|
+
*/
|
|
7
|
+
static from(sampler: Sampler2D): StandardTexture;
|
|
8
|
+
/**
|
|
9
|
+
* @type {Sampler2D}
|
|
10
|
+
*/
|
|
11
|
+
sampler: Sampler2D;
|
|
12
|
+
magFilter: number;
|
|
13
|
+
type: BinaryDataType;
|
|
14
|
+
wrapS: number;
|
|
15
|
+
wrapT: number;
|
|
16
|
+
/**
|
|
17
|
+
*
|
|
18
|
+
* @param {StandardTexture} other
|
|
19
|
+
*/
|
|
20
|
+
copy(other: StandardTexture): void;
|
|
21
|
+
clone(): StandardTexture;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param {number[]|Float32Array} out
|
|
25
|
+
* @param {number} u
|
|
26
|
+
* @param {number} v
|
|
27
|
+
*/
|
|
28
|
+
sample(out: number[] | Float32Array, u: number, v: number): void;
|
|
29
|
+
}
|
|
30
|
+
import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
|
|
31
|
+
//# sourceMappingURL=StandardTexture.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StandardTexture.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/StandardTexture.js"],"names":[],"mappings":"AAOA;IA8BI;;;;OAIG;IACH,iCAFa,eAAe,CAQ3B;IAxCD;;OAEG;IACH,mBAAO;IACP,kBAAsC;IACtC,qBAA2B;IAC3B,cAA2C;IAC3C,cAA2C;IAE3C;;;OAGG;IACH,YAFW,eAAe,QAQzB;IAED,yBAMC;IAeD;;;;;OAKG;IACH,YAJW,MAAM,EAAE,GAAC,YAAY,KACrB,MAAM,KACN,MAAM,QA6BhB;CACJ;+BAnF8B,mDAAmD"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { LinearFilter, LinearMipmapLinearFilter, NearestFilter, NearestMipMapLinearFilter } from "three";
|
|
2
|
+
import { BinaryDataType } from "../../../../../core/binary/type/BinaryDataType.js";
|
|
3
|
+
import { apply_texture_clamping_to_coordinate } from "../texture/apply_texture_clamping_to_coordinate.js";
|
|
4
|
+
import { vec3_uint8_to_float } from "../vec3_uint8_to_float.js";
|
|
5
|
+
import { TextureFilter } from "./TextureFilter.js";
|
|
6
|
+
import { TextureWrapping } from "./TextureWrapping.js";
|
|
7
|
+
|
|
8
|
+
export class StandardTexture {
|
|
9
|
+
/**
|
|
10
|
+
* @type {Sampler2D}
|
|
11
|
+
*/
|
|
12
|
+
sampler
|
|
13
|
+
magFilter = TextureFilter.LinearFilter
|
|
14
|
+
type = BinaryDataType.Uint8
|
|
15
|
+
wrapS = TextureWrapping.ClampToEdgeWrapping
|
|
16
|
+
wrapT = TextureWrapping.ClampToEdgeWrapping
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
*
|
|
20
|
+
* @param {StandardTexture} other
|
|
21
|
+
*/
|
|
22
|
+
copy(other) {
|
|
23
|
+
this.sampler = other.sampler
|
|
24
|
+
this.magFilter = other.magFilter
|
|
25
|
+
this.type = other.type
|
|
26
|
+
this.wrapS = other.wrapS
|
|
27
|
+
this.wrapT = other.wrapT
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
clone() {
|
|
31
|
+
const r = new StandardTexture();
|
|
32
|
+
|
|
33
|
+
r.copy(this);
|
|
34
|
+
|
|
35
|
+
return r;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {Sampler2D} sampler
|
|
41
|
+
* @returns {StandardTexture}
|
|
42
|
+
*/
|
|
43
|
+
static from(sampler) {
|
|
44
|
+
const texture = new StandardTexture();
|
|
45
|
+
|
|
46
|
+
texture.sampler = sampler;
|
|
47
|
+
|
|
48
|
+
return texture;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {number[]|Float32Array} out
|
|
54
|
+
* @param {number} u
|
|
55
|
+
* @param {number} v
|
|
56
|
+
*/
|
|
57
|
+
sample(out, u, v) {
|
|
58
|
+
|
|
59
|
+
const _u = apply_texture_clamping_to_coordinate(this.wrapS, u);
|
|
60
|
+
const _v = apply_texture_clamping_to_coordinate(this.wrapT, v);
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const magFilter = this.magFilter;
|
|
64
|
+
|
|
65
|
+
const sampler = this.sampler;
|
|
66
|
+
|
|
67
|
+
switch (magFilter) {
|
|
68
|
+
default:
|
|
69
|
+
case NearestFilter:
|
|
70
|
+
case NearestMipMapLinearFilter:
|
|
71
|
+
sampler.sampleNearestUV(_u, _v, out);
|
|
72
|
+
break;
|
|
73
|
+
|
|
74
|
+
case LinearFilter:
|
|
75
|
+
case LinearMipmapLinearFilter:
|
|
76
|
+
|
|
77
|
+
sampler.sampleBilinearUV(_u, _v, out);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (this.type === BinaryDataType.Uint8) {
|
|
82
|
+
vec3_uint8_to_float(out, out);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type TextureFilter = number;
|
|
2
|
+
export namespace TextureFilter {
|
|
3
|
+
let NearestFilter: number;
|
|
4
|
+
let NearestMipmapNearestFilter: number;
|
|
5
|
+
let NearestMipMapNearestFilter: number;
|
|
6
|
+
let NearestMipmapLinearFilter: number;
|
|
7
|
+
let NearestMipMapLinearFilter: number;
|
|
8
|
+
let LinearFilter: number;
|
|
9
|
+
let LinearMipmapNearestFilter: number;
|
|
10
|
+
let LinearMipMapNearestFilter: number;
|
|
11
|
+
let LinearMipmapLinearFilter: number;
|
|
12
|
+
let LinearMipMapLinearFilter: number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=TextureFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TextureFilter.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/sh3/path_tracer/material/TextureFilter.js"],"names":[],"mappings":"4BACU,MAAM"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enum {number}
|
|
3
|
+
*/
|
|
4
|
+
export const TextureFilter = {
|
|
5
|
+
|
|
6
|
+
NearestFilter: 1003,
|
|
7
|
+
NearestMipmapNearestFilter: 1004,
|
|
8
|
+
NearestMipMapNearestFilter: 1004,
|
|
9
|
+
NearestMipmapLinearFilter: 1005,
|
|
10
|
+
NearestMipMapLinearFilter: 1005,
|
|
11
|
+
LinearFilter: 1006,
|
|
12
|
+
LinearMipmapNearestFilter: 1007,
|
|
13
|
+
LinearMipMapNearestFilter: 1007,
|
|
14
|
+
LinearMipmapLinearFilter: 1008,
|
|
15
|
+
LinearMipMapLinearFilter: 1008
|
|
16
|
+
|
|
17
|
+
};
|