@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
|
@@ -5,6 +5,7 @@ import { ResourceAccessKind } from "../../../../core/model/ResourceAccessKind.js
|
|
|
5
5
|
import { ResourceAccessSpecification } from "../../../../core/model/ResourceAccessSpecification.js";
|
|
6
6
|
import { System } from '../../../ecs/System.js';
|
|
7
7
|
import { Transform } from '../../../ecs/transform/Transform.js';
|
|
8
|
+
import { threeUpdateTransform } from "../../util/threeUpdateTransform.js";
|
|
8
9
|
import { auto_set_camera_clipping_planes } from "./auto_set_camera_clipping_planes.js";
|
|
9
10
|
import { build_three_camera_object } from "./build_three_camera_object.js";
|
|
10
11
|
import { Camera } from './Camera.js';
|
|
@@ -13,6 +14,29 @@ import { invertQuaternionOrientation } from "./InvertQuaternionOrientation.js";
|
|
|
13
14
|
import { set_camera_aspect_ratio } from "./set_camera_aspect_ratio.js";
|
|
14
15
|
import { update_camera_transform } from "./update_camera_transform.js";
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {THREE.Camera} object
|
|
20
|
+
* @param {Quaternion} rotation
|
|
21
|
+
*/
|
|
22
|
+
export function three_camera_set_transform_rotation(object, rotation) {
|
|
23
|
+
|
|
24
|
+
/*
|
|
25
|
+
NOTE: I'm not sure why, but three.js camera points in the opposite direction to normal objects
|
|
26
|
+
See: https://github.com/mrdoob/three.js/blob/412b99a7f26e117ea97f40eb53d010ab81aa3279/src/core/Object3D.js#L282
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
invertQuaternionOrientation(object.quaternion, rotation);
|
|
30
|
+
|
|
31
|
+
object.rotation.setFromQuaternion(object.quaternion);
|
|
32
|
+
|
|
33
|
+
// rotation.__setThreeEuler(camera.object.rotation); // seems unnecessary, based on Object3D.lookAt implementation
|
|
34
|
+
// camera.object.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
35
|
+
|
|
36
|
+
object.updateProjectionMatrix();
|
|
37
|
+
threeUpdateTransform(object);
|
|
38
|
+
}
|
|
39
|
+
|
|
16
40
|
export class CameraSystem extends System {
|
|
17
41
|
/**
|
|
18
42
|
*
|
|
@@ -104,19 +128,7 @@ export class CameraSystem extends System {
|
|
|
104
128
|
function synchronizeRotation() {
|
|
105
129
|
const rotation = transform.rotation;
|
|
106
130
|
|
|
107
|
-
|
|
108
|
-
NOTE: I'm not sure why, but three.js camera points in the opposite direction to normal objects
|
|
109
|
-
See: https://github.com/mrdoob/three.js/blob/412b99a7f26e117ea97f40eb53d010ab81aa3279/src/core/Object3D.js#L282
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
invertQuaternionOrientation(camera.object.quaternion, rotation);
|
|
113
|
-
|
|
114
|
-
camera.object.rotation.setFromQuaternion(camera.object.quaternion);
|
|
115
|
-
|
|
116
|
-
// rotation.__setThreeEuler(camera.object.rotation); // seems unnecessary, based on Object3D.lookAt implementation
|
|
117
|
-
// camera.object.quaternion.set(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
118
|
-
|
|
119
|
-
update_camera_transform(camera);
|
|
131
|
+
three_camera_set_transform_rotation(camera.object, rotation);
|
|
120
132
|
}
|
|
121
133
|
|
|
122
134
|
function rebuild() {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number} input
|
|
4
|
+
* @param {BinaryDataType} raw_type
|
|
5
|
+
* @param {boolean} normalized
|
|
6
|
+
* @returns {number}
|
|
7
|
+
*/
|
|
8
|
+
export function decode_attribute_value(input: number, raw_type: BinaryDataType, normalized: boolean): number;
|
|
9
|
+
import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
|
|
10
|
+
//# sourceMappingURL=decode_attribute_value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode_attribute_value.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/geometry/decode_attribute_value.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AACH,8CALW,MAAM,YACN,cAAc,cACd,OAAO,GACL,MAAM,CAkBlB;+BA3B8B,6CAA6C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { BinaryDataType } from "../../../core/binary/type/BinaryDataType.js";
|
|
2
|
+
import { UINT16_MAX } from "../../../core/binary/UINT16_MAX.js";
|
|
3
|
+
import { UINT32_MAX } from "../../../core/binary/UINT32_MAX.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* @param {number} input
|
|
8
|
+
* @param {BinaryDataType} raw_type
|
|
9
|
+
* @param {boolean} normalized
|
|
10
|
+
* @returns {number}
|
|
11
|
+
*/
|
|
12
|
+
export function decode_attribute_value(input, raw_type, normalized) {
|
|
13
|
+
if (!normalized) {
|
|
14
|
+
return input;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
switch (raw_type) {
|
|
18
|
+
case BinaryDataType.Float32:
|
|
19
|
+
case BinaryDataType.Float64:
|
|
20
|
+
return input;
|
|
21
|
+
case BinaryDataType.Uint16:
|
|
22
|
+
return input / UINT16_MAX;
|
|
23
|
+
case BinaryDataType.Uint32:
|
|
24
|
+
return input / UINT32_MAX;
|
|
25
|
+
default:
|
|
26
|
+
throw new Error(`Unsupported data type ${raw_type}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {number[]|Float32Array} out
|
|
4
|
+
* @param {number} out_offset
|
|
5
|
+
* @param {number} a
|
|
6
|
+
* @param {number} b
|
|
7
|
+
* @param {number} c
|
|
8
|
+
* @param {number[]|Float32Array} positions
|
|
9
|
+
*/
|
|
10
|
+
export function geometry_construct_triangle_normal(out: number[] | Float32Array, out_offset: number, a: number, b: number, c: number, positions: number[] | Float32Array): void;
|
|
11
|
+
//# sourceMappingURL=geometry_construct_triangle_normal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry_construct_triangle_normal.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/geometry/geometry_construct_triangle_normal.js"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wDAPW,MAAM,EAAE,GAAC,YAAY,cACrB,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,aACN,MAAM,EAAE,GAAC,YAAY,QAqB/B"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { v3_compute_triangle_normal } from "../../../core/geom/3d/v3_compute_triangle_normal.js";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {number[]|Float32Array} out
|
|
6
|
+
* @param {number} out_offset
|
|
7
|
+
* @param {number} a
|
|
8
|
+
* @param {number} b
|
|
9
|
+
* @param {number} c
|
|
10
|
+
* @param {number[]|Float32Array} positions
|
|
11
|
+
*/
|
|
12
|
+
export function geometry_construct_triangle_normal(out, out_offset, a, b, c, positions) {
|
|
13
|
+
|
|
14
|
+
const a_address = a * 3;
|
|
15
|
+
const b_address = b * 3;
|
|
16
|
+
const c_address = c * 3;
|
|
17
|
+
|
|
18
|
+
const ax = positions[a_address];
|
|
19
|
+
const ay = positions[a_address + 1];
|
|
20
|
+
const az = positions[a_address + 2];
|
|
21
|
+
|
|
22
|
+
const bx = positions[b_address];
|
|
23
|
+
const by = positions[b_address + 1];
|
|
24
|
+
const bz = positions[b_address + 2];
|
|
25
|
+
|
|
26
|
+
const cx = positions[c_address];
|
|
27
|
+
const cy = positions[c_address + 1];
|
|
28
|
+
const cz = positions[c_address + 2];
|
|
29
|
+
|
|
30
|
+
v3_compute_triangle_normal(out, out_offset, ax, ay, az, bx, by, bz, cx, cy, cz);
|
|
31
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fromCubeRenderTarget.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/sh3/fromCubeRenderTarget.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fromCubeRenderTarget.d.ts","sourceRoot":"","sources":["../../../../../src/engine/graphics/sh3/fromCubeRenderTarget.js"],"names":[],"mappings":"AAQA;;;;;;GAMG;AACH,2CALW,UAAU,YACV,MAAM,aAAa,oBACnB,MAAM,qBAAqB,GAC1B,YAAY,CAgIvB"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { sh3_basis_at } from "../../../core/geom/3d/sphere/harmonics/sh3_basis_at.js";
|
|
2
2
|
import { sh3_dering_optimize_positive } from "../../../core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js";
|
|
3
|
+
import { sh3_vector_accumulate } from "../../../core/geom/3d/sphere/harmonics/sh3_vector_accumulate.js";
|
|
4
|
+
import { vector_scale_array } from "../../../core/geom/vec/vector_scale_array.js";
|
|
3
5
|
import { v3_length_sqr } from "../../../core/geom/vec3/v3_length_sqr.js";
|
|
4
6
|
|
|
7
|
+
const scratch_color = new Float32Array(3);
|
|
8
|
+
|
|
5
9
|
/**
|
|
6
10
|
*
|
|
7
11
|
* @param {Uint8Array} data
|
|
@@ -110,20 +114,17 @@ export function fromCubeRenderTarget(
|
|
|
110
114
|
// 0.003921 constant value is 1/255, a conversion value from UINT8 to normalized float
|
|
111
115
|
const weight_conv = weight * 0.00392156862745098;
|
|
112
116
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
scratch_color[0] = data[i] * weight_conv;
|
|
118
|
+
scratch_color[1] = data[i + 1] * weight_conv;
|
|
119
|
+
scratch_color[2] = data[i + 2] * weight_conv;
|
|
116
120
|
|
|
117
121
|
// accumulate
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
coefficients[j3 + 2] += sh_basis[j] * color_b;
|
|
125
|
-
|
|
126
|
-
}
|
|
122
|
+
sh3_vector_accumulate(
|
|
123
|
+
coefficients, 0,
|
|
124
|
+
sh_basis, 0,
|
|
125
|
+
scratch_color, 0,
|
|
126
|
+
3
|
|
127
|
+
);
|
|
127
128
|
|
|
128
129
|
}
|
|
129
130
|
|
|
@@ -132,11 +133,7 @@ export function fromCubeRenderTarget(
|
|
|
132
133
|
// normalize
|
|
133
134
|
const norm = (4 * Math.PI) / total_weight;
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
coefficients[j] *= norm;
|
|
138
|
-
|
|
139
|
-
}
|
|
136
|
+
vector_scale_array(coefficients, 0, coefficients, 0, 27, norm);
|
|
140
137
|
|
|
141
138
|
sh3_dering_optimize_positive(coefficients, 0, coefficients, 0, 3);
|
|
142
139
|
|
|
@@ -40,11 +40,11 @@ export class LightProbeVolume {
|
|
|
40
40
|
bake(ecd: EntityComponentDataset): TaskGroup;
|
|
41
41
|
/**
|
|
42
42
|
*
|
|
43
|
-
* @param {EntityComponentDataset} ecd
|
|
44
43
|
* @param {number} size
|
|
45
44
|
* @param {boolean} shadow
|
|
45
|
+
* @returns {EntityNode}
|
|
46
46
|
*/
|
|
47
|
-
visualize_probes({
|
|
47
|
+
visualize_probes({ size, shadow }: number): EntityNode;
|
|
48
48
|
/**
|
|
49
49
|
*
|
|
50
50
|
* @param {EntityComponentDataset} ecd
|
|
@@ -62,4 +62,5 @@ export class LightProbeVolume {
|
|
|
62
62
|
}
|
|
63
63
|
import { TetrahedralMesh } from "../../../../core/geom/3d/tetrahedra/TetrahedralMesh.js";
|
|
64
64
|
import TaskGroup from "../../../../core/process/task/TaskGroup.js";
|
|
65
|
+
import { EntityNode } from "../../../ecs/parent/EntityNode.js";
|
|
65
66
|
//# sourceMappingURL=LightProbeVolume.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LightProbeVolume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolume.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"LightProbeVolume.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/LightProbeVolume.js"],"names":[],"mappings":"AA6DA;IAGI,sBAEC;IAGG,mBAAqB;IAErB,wBAAmC;IAEnC,oBAAsB;IAEtB,iBAAiB;IAGrB,cAQC;IAED;;;OAGG;IACH,4BAEC;IAED,oBAEC;IAED,uBAEC;IAMD,uBAEC;IAND,oBAEC;IAMD;;;;;OAKG;IACH,aAJW,MAAM,KACN,MAAM,KACN,MAAM,QAchB;IAED;;;;;OAKG;IACH,mBAJW,MAAM,UACN,MAAM,EAAE,iBACR,MAAM,QAIhB;IAED;;OAEG;IACH,mBAaC;IAGD;;;;OAIG;IACH,mCAHa,SAAS,CA8CrB;IAED;;;;;OAKG;IACH,mCAJW,MAAM,GAEJ,UAAU,CAsBtB;IAED;;;;;OAKG;IACH,sEAkBC;IAED;;;;OAIG;IACH,oCAFa,SAAS,CAKrB;;CACJ;gCA1Q+B,wDAAwD;sBAClE,4CAA4C;2BAKvC,mCAAmC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LineBasicMaterial } from "three";
|
|
2
2
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
3
|
-
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
4
3
|
import {
|
|
5
4
|
build_tetrahedral_mesh_buffer_geometry
|
|
6
5
|
} from "../../../../core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js";
|
|
@@ -13,106 +12,22 @@ import { actionTask } from "../../../../core/process/task/util/actionTask.js";
|
|
|
13
12
|
import { countTask } from "../../../../core/process/task/util/countTask.js";
|
|
14
13
|
import { promiseTask } from "../../../../core/process/task/util/promiseTask.js";
|
|
15
14
|
import Entity from "../../../ecs/Entity.js";
|
|
15
|
+
import { EntityNode } from "../../../ecs/parent/EntityNode.js";
|
|
16
16
|
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
17
17
|
import { DrawMode } from "../../ecs/mesh-v2/DrawMode.js";
|
|
18
18
|
import { ShadedGeometry } from "../../ecs/mesh-v2/ShadedGeometry.js";
|
|
19
19
|
import { ShadedGeometryFlags } from "../../ecs/mesh-v2/ShadedGeometryFlags.js";
|
|
20
|
-
import {
|
|
20
|
+
import { sh3_make_shaded_geometry } from "../visualise_spherical_harmonic_sphere.js";
|
|
21
21
|
import { PathTracerProbeRenderer } from "./PathTracerProbeRenderer.js";
|
|
22
22
|
|
|
23
|
-
const TEMP_CONTACT = new SurfacePoint3();
|
|
24
|
-
|
|
25
23
|
|
|
26
24
|
class Baker {
|
|
27
25
|
constructor() {
|
|
28
|
-
/**
|
|
29
|
-
*
|
|
30
|
-
* @type {EntityComponentDataset|null}
|
|
31
|
-
* @private
|
|
32
|
-
*/
|
|
33
|
-
this.__ecd = null;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
*
|
|
37
|
-
* @type {BVH|null}
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
this.__bvh = null;
|
|
41
|
-
|
|
42
|
-
this.__min_bounce_count = 3;
|
|
43
|
-
this.__max_bounce_count = 100;
|
|
44
26
|
|
|
45
27
|
// this._ren = new WebGLCubeProbeRenderer();
|
|
46
28
|
this._ren = new PathTracerProbeRenderer();
|
|
47
29
|
}
|
|
48
30
|
|
|
49
|
-
/**
|
|
50
|
-
* @param {BVH} bvh
|
|
51
|
-
*/
|
|
52
|
-
set_bvh(bvh) {
|
|
53
|
-
this.__bvh = bvh;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
build_spatial() {
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param {number[]} irradiance RGB irradiance result is written here
|
|
63
|
-
* @param {number} bounce_count number of reflections before this trace
|
|
64
|
-
* @param {number} origin_x
|
|
65
|
-
* @param {number} origin_y
|
|
66
|
-
* @param {number} origin_z
|
|
67
|
-
* @param {number} direction_x
|
|
68
|
-
* @param {number} direction_y
|
|
69
|
-
* @param {number} direction_z
|
|
70
|
-
*/
|
|
71
|
-
trace_ray(irradiance, bounce_count,
|
|
72
|
-
origin_x, origin_y, origin_z,
|
|
73
|
-
direction_x, direction_y, direction_z) {
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
if (!this.ray_cast(TEMP_CONTACT, origin_x, origin_y, origin_z, direction_x, direction_y, direction_z)) {
|
|
78
|
-
// no hit, assume irradiance is zeroed - black
|
|
79
|
-
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// record irradiance
|
|
84
|
-
|
|
85
|
-
// reflect ray around normal
|
|
86
|
-
// TODO apply BDRF to compute reflected ray
|
|
87
|
-
|
|
88
|
-
if (bounce_count > this.__max_bounce_count) {
|
|
89
|
-
// terminate
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
*
|
|
96
|
-
* @param contact
|
|
97
|
-
* @param origin_x
|
|
98
|
-
* @param origin_y
|
|
99
|
-
* @param origin_z
|
|
100
|
-
* @param direction_x
|
|
101
|
-
* @param direction_y
|
|
102
|
-
* @param direction_z
|
|
103
|
-
* @returns {boolean}
|
|
104
|
-
*/
|
|
105
|
-
ray_cast(contact,
|
|
106
|
-
origin_x, origin_y, origin_z,
|
|
107
|
-
direction_x, direction_y, direction_z
|
|
108
|
-
) {
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
prepare_scene() {
|
|
113
|
-
|
|
114
|
-
}
|
|
115
|
-
|
|
116
31
|
/**
|
|
117
32
|
*
|
|
118
33
|
* @param {number[]} position
|
|
@@ -296,21 +211,30 @@ export class LightProbeVolume {
|
|
|
296
211
|
|
|
297
212
|
/**
|
|
298
213
|
*
|
|
299
|
-
* @param {EntityComponentDataset} ecd
|
|
300
214
|
* @param {number} size
|
|
301
215
|
* @param {boolean} shadow
|
|
216
|
+
* @returns {EntityNode}
|
|
302
217
|
*/
|
|
303
|
-
visualize_probes({
|
|
218
|
+
visualize_probes({ size = 0.2, shadow = false }) {
|
|
219
|
+
const parent = new EntityNode();
|
|
220
|
+
parent.entity.add(new Transform());
|
|
221
|
+
|
|
304
222
|
for (let i = 0; i < this.__length; i++) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
223
|
+
const probe_node = new EntityNode();
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
probe_node.entity.add(new Transform());
|
|
227
|
+
probe_node.entity.add(
|
|
228
|
+
sh3_make_shaded_geometry(this.__probe_data, i * 3 * 9, shadow)
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
probe_node.transform.position.fromArray(this.__positions, i * 3);
|
|
232
|
+
probe_node.transform.scale.setScalar(size);
|
|
233
|
+
|
|
234
|
+
parent.addChild(probe_node);
|
|
313
235
|
}
|
|
236
|
+
|
|
237
|
+
return parent;
|
|
314
238
|
}
|
|
315
239
|
|
|
316
240
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PathTracerProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/PathTracerProbeRenderer.js"],"names":[],"mappings":"AAyBA;IACI,mBAA0B;IAC1B,qBAAmB;IACnB,qBAAyB;IAEzB,uBAA6B;IAE7B,iFAkCC;IASD,4BAsCC;CACJ;8BAlG6B,oBAAoB;2BADvB,8BAA8B;gCADzB,mCAAmC"}
|
|
@@ -3,7 +3,9 @@ import { sh3_basis_at } from "../../../../core/geom/3d/sphere/harmonics/sh3_basi
|
|
|
3
3
|
import {
|
|
4
4
|
sh3_dering_optimize_positive
|
|
5
5
|
} from "../../../../core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js";
|
|
6
|
+
import { sh3_vector_accumulate } from "../../../../core/geom/3d/sphere/harmonics/sh3_vector_accumulate.js";
|
|
6
7
|
import { randomPointOnSphere } from "../../../../core/geom/random/randomPointOnSphere.js";
|
|
8
|
+
import { vector_scale_array } from "../../../../core/geom/vec/vector_scale_array.js";
|
|
7
9
|
import { seededRandom } from "../../../../core/math/random/seededRandom.js";
|
|
8
10
|
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
9
11
|
import { Light } from "../../ecs/light/Light.js";
|
|
@@ -47,26 +49,17 @@ export class PathTracerProbeRenderer extends ProbeRenderer {
|
|
|
47
49
|
sh3_basis_at(ray[3], ray[4], ray[5], sh_basis);
|
|
48
50
|
|
|
49
51
|
// accumulate
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
coefficients[j3] += projected_coefficient * sampled_irradiance[0];
|
|
57
|
-
coefficients[j3 + 1] += projected_coefficient * sampled_irradiance[1];
|
|
58
|
-
coefficients[j3 + 2] += projected_coefficient * sampled_irradiance[2];
|
|
59
|
-
|
|
60
|
-
}
|
|
52
|
+
sh3_vector_accumulate(
|
|
53
|
+
coefficients, 0,
|
|
54
|
+
sh_basis, 0,
|
|
55
|
+
sampled_irradiance, 0, 3
|
|
56
|
+
);
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
// Area of a unit sphere is (4*PI)
|
|
64
|
-
|
|
65
60
|
const normalization_weight = (4 * Math.PI) / this.sample_count;
|
|
66
61
|
|
|
67
|
-
|
|
68
|
-
coefficients[i] *= normalization_weight;
|
|
69
|
-
}
|
|
62
|
+
vector_scale_array(coefficients, 0, coefficients, 0, 27, normalization_weight);
|
|
70
63
|
|
|
71
64
|
sh3_dering_optimize_positive(coefficients, 0, coefficients, 0, 3);
|
|
72
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebGLCubeProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"WebGLCubeProbeRenderer.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/lpv/WebGLCubeProbeRenderer.js"],"names":[],"mappings":"AAwBA;IACI,iCA0CC;IApCG;;;;OAIG;IACH,mBAAsB;IAEtB,qCASE;IAEF;;;;OAIG;IACH,wBAA8F;IAG9F,0BAAiE;IAEjE;;;;OAIG;IACH,gBAA0B;IA8C9B,mBAMC;CA6CJ;8BA3I6B,oBAAoB;sCAb3C,OAAO;2BAAP,OAAO"}
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
VSMShadowMap,
|
|
9
9
|
WebGLCubeRenderTarget
|
|
10
10
|
} from "three";
|
|
11
|
+
import { assert } from "../../../../core/assert.js";
|
|
11
12
|
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
12
13
|
import { Transform } from "../../../ecs/transform/Transform.js";
|
|
13
14
|
import { three_set_shadow_resolution } from "../../ecs/light/binding/three/ThreeLightBinding.js";
|
|
@@ -22,9 +23,12 @@ import { fromCubeRenderTarget } from "../fromCubeRenderTarget.js";
|
|
|
22
23
|
import { ProbeRenderer } from "./ProbeRenderer.js";
|
|
23
24
|
|
|
24
25
|
export class WebGLCubeProbeRenderer extends ProbeRenderer {
|
|
25
|
-
constructor() {
|
|
26
|
+
constructor(resolution = 32) {
|
|
26
27
|
|
|
27
28
|
super();
|
|
29
|
+
|
|
30
|
+
assert.isNonNegativeInteger(resolution, 'resolution');
|
|
31
|
+
|
|
28
32
|
/**
|
|
29
33
|
*
|
|
30
34
|
* @type {THREE.WebGLRenderer|null}
|
|
@@ -32,7 +36,7 @@ export class WebGLCubeProbeRenderer extends ProbeRenderer {
|
|
|
32
36
|
*/
|
|
33
37
|
this.__renderer = null;
|
|
34
38
|
|
|
35
|
-
this.render_target = new WebGLCubeRenderTarget(
|
|
39
|
+
this.render_target = new WebGLCubeRenderTarget(resolution, {
|
|
36
40
|
format: RGBAFormat,
|
|
37
41
|
minFilter: LinearFilter,
|
|
38
42
|
magFilter: LinearFilter,
|
package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.d.ts → BufferedGeometryBVH.d.ts}
RENAMED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
export class
|
|
1
|
+
export class BufferedGeometryBVH {
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {AABB3|number[]} out
|
|
5
|
+
*/
|
|
6
|
+
getBounds(out: AABB3 | number[]): void;
|
|
2
7
|
/**
|
|
3
8
|
*
|
|
4
9
|
* @type {BVH}
|
|
@@ -43,5 +48,7 @@ export class GeometryBVHBatched {
|
|
|
43
48
|
* @returns {number} distance along the ray, negative if no hit
|
|
44
49
|
*/
|
|
45
50
|
raycast(output: number[], ray: number[], min_distance: number, max_distance: number): number;
|
|
51
|
+
#private;
|
|
46
52
|
}
|
|
47
|
-
|
|
53
|
+
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
54
|
+
//# sourceMappingURL=BufferedGeometryBVH.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BufferedGeometryBVH.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/sh3/path_tracer/BufferedGeometryBVH.js"],"names":[],"mappings":"AA8IA;IAQI;;;OAGG;IACH,eAFW,KAAK,GAAC,MAAM,EAAE,QAIxB;IAGG;;;;OAIG;IACH,cAAsB;IAEtB;;;;OAIG;IACH,mBAAsB;IAEtB;;;;OAIG;IACH,yBAA4B;IAE5B;;;;OAIG;IACH,6BAAgC;IAGhC;;;;OAIG;IACH,yBAAyB;IAG7B;;;OAGG;IACH,gBAFW,MAAM,cAAc,QAiC9B;IAGD;;;;;;;OAOG;IACH,gBANW,MAAM,EAAE,OACR,MAAM,EAAE,gBACR,MAAM,gBACN,MAAM,GACJ,MAAM,CA8ElB;;CACJ;sBAzTqB,wCAAwC"}
|
package/src/engine/graphics/sh3/path_tracer/{GeometryBVHBatched.js → BufferedGeometryBVH.js}
RENAMED
|
@@ -1,22 +1,72 @@
|
|
|
1
|
+
import { split_by_3 } from "../../../../core/binary/split_by_3.js";
|
|
1
2
|
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
2
3
|
import { ebvh_build_for_geometry_morton } from "../../../../core/bvh2/bvh3/ebvh_build_for_geometry_morton.js";
|
|
3
4
|
import { bvh_query_user_data_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_ray.js";
|
|
5
|
+
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
6
|
+
import { array_quick_sort_by_comparator } from "../../../../core/collection/array/array_quick_sort_by_comparator.js";
|
|
7
|
+
import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
|
|
4
8
|
|
|
5
9
|
import {
|
|
6
10
|
computeTriangleRayIntersectionBarycentricGeometry
|
|
7
11
|
} from "../../../../core/geom/3d/triangle/computeTriangleRayIntersectionBarycentricGeometry.js";
|
|
12
|
+
import { v3_distance_sqr } from "../../../../core/geom/vec3/v3_distance_sqr.js";
|
|
8
13
|
|
|
9
14
|
/**
|
|
10
15
|
*
|
|
11
|
-
* @type {number[]}
|
|
16
|
+
* @type {number[]|Uint32Array}
|
|
12
17
|
*/
|
|
13
|
-
const scratch_uint32_array =
|
|
18
|
+
const scratch_uint32_array = new Uint32Array(4096);
|
|
14
19
|
/**
|
|
15
20
|
*
|
|
16
21
|
* @type {number[]}
|
|
17
22
|
*/
|
|
18
23
|
const v3_scratch_0 = [];
|
|
19
24
|
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @param {number[]} triangles
|
|
28
|
+
* @param {number} offset
|
|
29
|
+
* @param {number} count
|
|
30
|
+
* @param {number} point_x
|
|
31
|
+
* @param {number} point_y
|
|
32
|
+
* @param {number} point_z
|
|
33
|
+
* @param morton_codes
|
|
34
|
+
* @param bounds
|
|
35
|
+
*/
|
|
36
|
+
function sort_triangles_by_distance_to_point(
|
|
37
|
+
triangles, offset, count,
|
|
38
|
+
morton_codes, bounds,
|
|
39
|
+
point_x, point_y, point_z,
|
|
40
|
+
) {
|
|
41
|
+
const bounds_x0 = bounds.x0;
|
|
42
|
+
const bounds_y0 = bounds.y0;
|
|
43
|
+
const bounds_z0 = bounds.z0;
|
|
44
|
+
|
|
45
|
+
const bounds_scale_x = bounds.getExtentsX() / 1023;
|
|
46
|
+
const bounds_scale_y = bounds.getExtentsY() / 1023;
|
|
47
|
+
const bounds_scale_z = bounds.getExtentsZ() / 1023;
|
|
48
|
+
|
|
49
|
+
array_quick_sort_by_comparator(scratch_uint32_array, (a, b) => {
|
|
50
|
+
|
|
51
|
+
const morton_a = morton_codes[a];
|
|
52
|
+
const morton_b = morton_codes[b];
|
|
53
|
+
|
|
54
|
+
const ax = bounds_x0 + bounds_scale_x * split_by_3(morton_a);
|
|
55
|
+
const ay = bounds_y0 + bounds_scale_y * split_by_3(morton_a >>> 1);
|
|
56
|
+
const az = bounds_z0 + bounds_scale_z * split_by_3(morton_a >>> 2);
|
|
57
|
+
|
|
58
|
+
const bx = bounds_x0 + bounds_scale_x * split_by_3(morton_b);
|
|
59
|
+
const by = bounds_y0 + bounds_scale_y * split_by_3(morton_b >>> 1);
|
|
60
|
+
const bz = bounds_z0 + bounds_scale_z * split_by_3(morton_b >>> 2);
|
|
61
|
+
|
|
62
|
+
const delta_a = v3_distance_sqr(ax, ay, az, point_x, point_y, point_z);
|
|
63
|
+
const delta_b = v3_distance_sqr(bx, by, bz, point_x, point_y, point_z);
|
|
64
|
+
|
|
65
|
+
return delta_b - delta_a;
|
|
66
|
+
}, undefined, offset, count - 1);
|
|
67
|
+
|
|
68
|
+
}
|
|
69
|
+
|
|
20
70
|
/**
|
|
21
71
|
*
|
|
22
72
|
* @param {number[]} output
|
|
@@ -90,7 +140,22 @@ function construct_ray_hit(
|
|
|
90
140
|
output[9] = face_index;
|
|
91
141
|
}
|
|
92
142
|
|
|
93
|
-
export class
|
|
143
|
+
export class BufferedGeometryBVH {
|
|
144
|
+
/**
|
|
145
|
+
* @type {Uint32Array}
|
|
146
|
+
*/
|
|
147
|
+
#morton_codes
|
|
148
|
+
|
|
149
|
+
#bounds = new AABB3()
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
*
|
|
153
|
+
* @param {AABB3|number[]} out
|
|
154
|
+
*/
|
|
155
|
+
getBounds(out) {
|
|
156
|
+
array_copy(this.#bounds, 0, out, 0, 6);
|
|
157
|
+
}
|
|
158
|
+
|
|
94
159
|
constructor() {
|
|
95
160
|
/**
|
|
96
161
|
*
|
|
@@ -148,9 +213,17 @@ export class GeometryBVHBatched {
|
|
|
148
213
|
|
|
149
214
|
this.__triangle_count = index_array.length / 3;
|
|
150
215
|
|
|
216
|
+
this.#morton_codes = new Uint32Array(this.__triangle_count);
|
|
217
|
+
|
|
151
218
|
const bvh = this.__bvh;
|
|
152
219
|
|
|
153
|
-
ebvh_build_for_geometry_morton(
|
|
220
|
+
ebvh_build_for_geometry_morton(
|
|
221
|
+
bvh,
|
|
222
|
+
index_array,
|
|
223
|
+
array_positions,
|
|
224
|
+
this.#morton_codes,
|
|
225
|
+
this.#bounds
|
|
226
|
+
);
|
|
154
227
|
//
|
|
155
228
|
// ebvh_build_for_geometry_incremental(bvh, index_array, array_positions, 1);
|
|
156
229
|
|
|
@@ -201,6 +274,13 @@ export class GeometryBVHBatched {
|
|
|
201
274
|
let best_u = 0;
|
|
202
275
|
let best_v = 0;
|
|
203
276
|
|
|
277
|
+
// sort triangles by distance to origin
|
|
278
|
+
if (count > 64) {
|
|
279
|
+
// encode
|
|
280
|
+
sort_triangles_by_distance_to_point(scratch_uint32_array, 0, count, this.#morton_codes, this.#bounds, origin_x, origin_y, origin_z);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
|
|
204
284
|
// check triangles found via BVH
|
|
205
285
|
for (let i = 0; i < count; i++) {
|
|
206
286
|
const triangle_index = scratch_uint32_array[i];
|
|
@@ -225,7 +305,6 @@ export class GeometryBVHBatched {
|
|
|
225
305
|
best_index = triangle_index;
|
|
226
306
|
best_u = v3_scratch_0[1];
|
|
227
307
|
best_v = v3_scratch_0[2];
|
|
228
|
-
|
|
229
308
|
}
|
|
230
309
|
}
|
|
231
310
|
|