@woosh/meep-engine 2.63.0 → 2.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/meep.cjs +5357 -5350
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +5357 -5350
- package/package.json +1 -1
- package/src/core/binary/UINT16_MAX.js +5 -0
- package/src/core/bvh2/BinaryNode.js +14 -14
- package/src/core/bvh2/LeafNode.js +4 -4
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.d.ts → BVH.d.ts} +1 -1
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.js → BVH.js} +7 -7
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.spec.js → BVH.spec.js} +20 -20
- package/src/core/bvh2/bvh3/{EBBVHLeafProxy.js → BvhClient.js} +3 -3
- package/src/core/bvh2/bvh3/BvhClient.spec.js +51 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +2 -2
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +4 -4
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +3 -3
- package/src/core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js +2 -8
- package/src/core/bvh2/bvh3/query/BVHQuery.js +1 -1
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +8 -10
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +7 -7
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsSphere.js +37 -0
- package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +3 -8
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +13 -5
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.spec.js +29 -0
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +3 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.spec.js +3 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +3 -3
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +4 -4
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +3 -3
- package/src/core/collection/list/List.js +9 -3
- package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +11 -4
- package/src/core/geom/Vector2.js +6 -4
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +22 -24
- package/src/engine/graphics/ecs/mesh/Mesh.js +8 -8
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +3 -5
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +6 -6
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +3 -3
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +16 -18
- package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +5 -5
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +9 -11
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +51 -88
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +41 -72
- package/src/engine/graphics/particles/particular/engine/emitter/write_particle_patch_uv.js +28 -0
- package/src/engine/graphics/render/forward_plus/LightManager.js +30 -32
- package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +3 -3
- package/src/engine/graphics/sh3/LightProbeVolume.js +19 -19
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +4 -6
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +17 -19
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +18 -16
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +20 -22
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +0 -81
- package/src/engine/ecs/foliage/Foliage.js +0 -151
- package/src/engine/ecs/foliage/FoliageLoader.js +0 -39
- package/src/engine/ecs/foliage/FoliageVisibilitySetBuilder.js +0 -27
- package/src/engine/ecs/foliage/ImpostorFoliage.js +0 -106
- package/src/engine/ecs/foliage/InstancedFoliage.js +0 -395
- package/src/engine/ecs/foliage/ViewState.js +0 -181
- package/src/engine/ecs/foliage/ecs/Foliage2System.js +0 -333
- package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +0 -70
- package/src/engine/ecs/foliage/ecs/InstancedMeshLayer.js +0 -138
- package/src/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +0 -28
- package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +0 -64
- package/src/engine/ecs/foliage/ecs/optimizeIndividualMeshesEntitiesToInstances.js +0 -233
- package/src/engine/save/storage/GooglePlayStorage.js +0 -47
- package/src/engine/save/storage/JsonStringCodec.js +0 -24
- /package/src/engine/sound/ecs/emitter/{SoundEmitter.spec.js → SoundEmitterSerializationAdapter.spec.js} +0 -0
|
@@ -1,15 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ExplicitBinaryBoundingVolumeHierarchy
|
|
3
|
-
} from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
4
|
-
import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
5
|
-
import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
6
|
-
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
7
1
|
import { mat4, vec3 } from "gl-matrix";
|
|
8
|
-
import { ensureGeometryBoundingBox } from "../../util/ensureGeometryBoundingBox.js";
|
|
9
|
-
import { GeometryBVHBatched } from "./GeometryBVHBatched.js";
|
|
10
|
-
import { PathTracedMesh } from "./PathTracedMesh.js";
|
|
11
|
-
import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
12
|
-
import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2Sampler2D.js";
|
|
13
2
|
import {
|
|
14
3
|
LinearEncoding,
|
|
15
4
|
LinearFilter,
|
|
@@ -19,16 +8,25 @@ import {
|
|
|
19
8
|
sRGBEncoding,
|
|
20
9
|
UnsignedByteType
|
|
21
10
|
} from "three";
|
|
22
|
-
import {
|
|
23
|
-
import { sample_triangle_attribute } from "./sample_triangle_attribute.js";
|
|
24
|
-
import { vec3_uint8_to_float } from "./vec3_uint8_to_float.js";
|
|
25
|
-
import { apply_texture_clamping_to_coordinate } from "./apply_texture_clamping_to_coordinate.js";
|
|
11
|
+
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
26
12
|
import { ebvh_sort_for_traversal_depth_first } from "../../../../core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js";
|
|
13
|
+
import { bvh_query_leaves_ray } from "../../../../core/bvh2/bvh3/query/bvh_query_leaves_ray.js";
|
|
14
|
+
import { array_copy } from "../../../../core/collection/array/array_copy.js";
|
|
15
|
+
import { linear_to_sRGB } from "../../../../core/color/sRGB/linear_to_sRGB.js";
|
|
16
|
+
import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
17
|
+
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
27
18
|
import { v3_dot } from "../../../../core/geom/vec3/v3_dot.js";
|
|
19
|
+
import { TextureAttachmentsByMaterialType } from "../../../asset/loaders/material/TextureAttachmensByMaterialType.js";
|
|
20
|
+
import { convertTexture2Sampler2D } from "../../texture/sampler/convertTexture2Sampler2D.js";
|
|
21
|
+
import { ensureGeometryBoundingBox } from "../../util/ensureGeometryBoundingBox.js";
|
|
22
|
+
import { apply_texture_clamping_to_coordinate } from "./apply_texture_clamping_to_coordinate.js";
|
|
23
|
+
import { GeometryBVHBatched } from "./GeometryBVHBatched.js";
|
|
24
|
+
import { getBiasedNormalSample } from "./getBiasedNormalSample.js";
|
|
28
25
|
import { make_one_vector3 } from "./make_one_vector3.js";
|
|
26
|
+
import { PathTracedMesh } from "./PathTracedMesh.js";
|
|
29
27
|
import { transform_normal_m4 } from "./ray_hit_apply_transform.js";
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
28
|
+
import { sample_triangle_attribute } from "./sample_triangle_attribute.js";
|
|
29
|
+
import { vec3_uint8_to_float } from "./vec3_uint8_to_float.js";
|
|
32
30
|
|
|
33
31
|
/*
|
|
34
32
|
Ray hit data layout:
|
|
@@ -69,9 +67,9 @@ export class PathTracer {
|
|
|
69
67
|
|
|
70
68
|
/**
|
|
71
69
|
*
|
|
72
|
-
* @type {
|
|
70
|
+
* @type {BVH}
|
|
73
71
|
*/
|
|
74
|
-
this.bvh_top_level = new
|
|
72
|
+
this.bvh_top_level = new BVH();
|
|
75
73
|
|
|
76
74
|
/**
|
|
77
75
|
*
|
|
@@ -3,25 +3,27 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import {computeHashIntegerArray} from "../../../../core/collection/array/computeHashIntegerArray.js";
|
|
6
|
+
import { BvhClient } from "../../../../core/bvh2/bvh3/BvhClient.js";
|
|
7
|
+
import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
|
|
8
8
|
import List from '../../../../core/collection/list/List.js';
|
|
9
|
-
import {aabb3_array_compute_from_sphere} from "../../../../core/geom/3d/aabb/aabb3_array_compute_from_sphere.js";
|
|
9
|
+
import { aabb3_array_compute_from_sphere } from "../../../../core/geom/3d/aabb/aabb3_array_compute_from_sphere.js";
|
|
10
10
|
import Vector1 from "../../../../core/geom/Vector1.js";
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
interpolate_irradiance_linear
|
|
13
|
+
} from "../../../../core/math/physics/irradiance/interpolate_irradiance_linear.js";
|
|
12
14
|
import {
|
|
13
15
|
interpolate_irradiance_lograrithmic
|
|
14
16
|
} from "../../../../core/math/physics/irradiance/interpolate_irradiance_lograrithmic.js";
|
|
15
|
-
import {interpolate_irradiance_smith} from "../../../../core/math/physics/irradiance/interpolate_irradiance_smith.js";
|
|
16
|
-
import {objectKeyByValue} from "../../../../core/model/object/objectKeyByValue.js";
|
|
17
|
-
import {computeHashFloat} from "../../../../core/primitives/numbers/computeHashFloat.js";
|
|
18
|
-
import {number_compare_ascending} from "../../../../core/primitives/numbers/number_compare_ascending.js";
|
|
19
|
-
import {compareStrings} from "../../../../core/primitives/strings/compareStrings.js";
|
|
20
|
-
import {computeStringHash} from "../../../../core/primitives/strings/computeStringHash.js";
|
|
21
|
-
import {SoundAttenuationFunction} from "./SoundAttenuationFunction.js";
|
|
22
|
-
import {SoundEmitterFlags} from "./SoundEmitterFlags.js";
|
|
23
|
-
import {SoundPanningModelType} from "./SoundPanningModelType.js";
|
|
24
|
-
import {SoundTrack} from "./SoundTrack.js";
|
|
17
|
+
import { interpolate_irradiance_smith } from "../../../../core/math/physics/irradiance/interpolate_irradiance_smith.js";
|
|
18
|
+
import { objectKeyByValue } from "../../../../core/model/object/objectKeyByValue.js";
|
|
19
|
+
import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
|
|
20
|
+
import { number_compare_ascending } from "../../../../core/primitives/numbers/number_compare_ascending.js";
|
|
21
|
+
import { compareStrings } from "../../../../core/primitives/strings/compareStrings.js";
|
|
22
|
+
import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
|
|
23
|
+
import { SoundAttenuationFunction } from "./SoundAttenuationFunction.js";
|
|
24
|
+
import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
|
|
25
|
+
import { SoundPanningModelType } from "./SoundPanningModelType.js";
|
|
26
|
+
import { SoundTrack } from "./SoundTrack.js";
|
|
25
27
|
|
|
26
28
|
const DEFAULT_DISTANCE_MIN = 1;
|
|
27
29
|
const DEFAULT_DISTANCE_MAX = 10000;
|
|
@@ -116,9 +118,9 @@ export class SoundEmitter {
|
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
120
|
* @readonly
|
|
119
|
-
* @type {
|
|
121
|
+
* @type {BvhClient}
|
|
120
122
|
*/
|
|
121
|
-
bvh = new
|
|
123
|
+
bvh = new BvhClient();
|
|
122
124
|
|
|
123
125
|
/**
|
|
124
126
|
*
|
|
@@ -5,24 +5,21 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
} from "../../../../core/bvh2/bvh3/
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
} from "
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {System} from '../../../ecs/System.js';
|
|
18
|
-
import {Transform} from '../../../ecs/transform/Transform.js';
|
|
19
|
-
import {IncrementalDeltaSet} from "../../../graphics/render/visibility/IncrementalDeltaSet.js";
|
|
8
|
+
import { BVH } from "../../../../core/bvh2/bvh3/BVH.js";
|
|
9
|
+
import { bvh_query_user_data_generic } from "../../../../core/bvh2/bvh3/query/bvh_query_user_data_generic.js";
|
|
10
|
+
import { BVHQueryIntersectsSphere } from "../../../../core/bvh2/bvh3/query/BVHQueryIntersectsSphere.js";
|
|
11
|
+
import { invokeObjectCompare } from "../../../../core/model/object/invokeObjectCompare.js";
|
|
12
|
+
import { GameAssetType } from "../../../asset/GameAssetType.js";
|
|
13
|
+
import { SoundAssetLoader } from "../../../asset/loaders/SoundAssetLoader.js";
|
|
14
|
+
import { System } from '../../../ecs/System.js';
|
|
15
|
+
import { Transform } from '../../../ecs/transform/Transform.js';
|
|
16
|
+
import { IncrementalDeltaSet } from "../../../graphics/render/visibility/IncrementalDeltaSet.js";
|
|
20
17
|
import SoundListener from "../SoundListener.js";
|
|
21
|
-
import {SoundEmitter} from './SoundEmitter.js';
|
|
22
|
-
import {SoundEmitterChannel} from "./SoundEmitterChannel.js";
|
|
23
|
-
import {SoundEmitterComponentContext} from "./SoundEmitterComponentContext.js";
|
|
24
|
-
import {SoundEmitterFlags} from "./SoundEmitterFlags.js";
|
|
25
|
-
import {SoundTrackFlags} from "./SoundTrackFlags.js";
|
|
18
|
+
import { SoundEmitter } from './SoundEmitter.js';
|
|
19
|
+
import { SoundEmitterChannel } from "./SoundEmitterChannel.js";
|
|
20
|
+
import { SoundEmitterComponentContext } from "./SoundEmitterComponentContext.js";
|
|
21
|
+
import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
|
|
22
|
+
import { SoundTrackFlags } from "./SoundTrackFlags.js";
|
|
26
23
|
|
|
27
24
|
/**
|
|
28
25
|
* @readonly
|
|
@@ -92,10 +89,10 @@ export class SoundEmitterSystem extends System {
|
|
|
92
89
|
|
|
93
90
|
/**
|
|
94
91
|
* Spatial index
|
|
95
|
-
* @type {
|
|
92
|
+
* @type {BVH}
|
|
96
93
|
* @private
|
|
97
94
|
*/
|
|
98
|
-
this.__bvh = new
|
|
95
|
+
this.__bvh = new BVH();
|
|
99
96
|
|
|
100
97
|
/**
|
|
101
98
|
* Number of currently linked entities
|
|
@@ -272,9 +269,11 @@ export class SoundEmitterSystem extends System {
|
|
|
272
269
|
|
|
273
270
|
const listenerPosition = listenerTransform.position;
|
|
274
271
|
|
|
275
|
-
const
|
|
272
|
+
const query = BVHQueryIntersectsSphere.from([listenerPosition.x, listenerPosition.y, listenerPosition.z, 0]);
|
|
273
|
+
|
|
274
|
+
const matchCount = bvh_query_user_data_generic(
|
|
276
275
|
scratch_array, 0,
|
|
277
|
-
this.__bvh,
|
|
276
|
+
this.__bvh, this.__bvh.root, query
|
|
278
277
|
);
|
|
279
278
|
|
|
280
279
|
for (let i = 0; i < matchCount; i++) {
|
|
@@ -362,6 +361,5 @@ export class SoundEmitterSystem extends System {
|
|
|
362
361
|
}
|
|
363
362
|
|
|
364
363
|
|
|
365
|
-
|
|
366
364
|
}
|
|
367
365
|
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import {SCRATCH_UINT32_TRAVERSAL_STACK} from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
|
-
import {aabb3_array_intersects_sphere_array} from "../../../geom/3d/aabb/aabb3_array_intersects_sphere_array.js";
|
|
3
|
-
import {NULL_NODE} from "../ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
4
|
-
import {bvh_collect_user_data} from "./bvh_collect_user_data.js";
|
|
5
|
-
|
|
6
|
-
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
7
|
-
|
|
8
|
-
const scratch_aabb = new Float32Array(6);
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
*
|
|
12
|
-
* @param {number[]} result
|
|
13
|
-
* @param {number} result_offset
|
|
14
|
-
* @param {ExplicitBinaryBoundingVolumeHierarchy} bvh
|
|
15
|
-
* @param {number[]|Float32Array} sphere
|
|
16
|
-
*/
|
|
17
|
-
export function bvh_query_user_data_overlaps_sphere(
|
|
18
|
-
result,
|
|
19
|
-
result_offset,
|
|
20
|
-
bvh,
|
|
21
|
-
sphere
|
|
22
|
-
) {
|
|
23
|
-
const root = bvh.root;
|
|
24
|
-
|
|
25
|
-
if (root === NULL_NODE) {
|
|
26
|
-
return 0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
*
|
|
31
|
-
* @type {number}
|
|
32
|
-
*/
|
|
33
|
-
const stack_top = stack.pointer++;
|
|
34
|
-
|
|
35
|
-
stack[stack_top] = root;
|
|
36
|
-
|
|
37
|
-
let result_cursor = result_offset;
|
|
38
|
-
|
|
39
|
-
while (stack.pointer > stack_top) {
|
|
40
|
-
stack.pointer--;
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
*
|
|
44
|
-
* @type {number}
|
|
45
|
-
*/
|
|
46
|
-
const node = stack[stack.pointer];
|
|
47
|
-
|
|
48
|
-
// test node against the ray
|
|
49
|
-
bvh.node_get_aabb(node, scratch_aabb);
|
|
50
|
-
const intersection = aabb3_array_intersects_sphere_array(scratch_aabb, sphere);
|
|
51
|
-
|
|
52
|
-
if (intersection === 0) {
|
|
53
|
-
// fully outside
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const node_is_leaf = bvh.node_is_leaf(node);
|
|
58
|
-
|
|
59
|
-
if (node_is_leaf) {
|
|
60
|
-
// leaf node
|
|
61
|
-
result[result_cursor++] = bvh.node_get_user_data(node);
|
|
62
|
-
|
|
63
|
-
} else if (intersection === 2) {
|
|
64
|
-
// fully inside, fast collection path
|
|
65
|
-
result_cursor += bvh_collect_user_data(result, result_cursor, bvh, node);
|
|
66
|
-
} else {
|
|
67
|
-
// partially inside
|
|
68
|
-
// read in-order
|
|
69
|
-
const child1 = bvh.node_get_child1(node);
|
|
70
|
-
const child2 = bvh.node_get_child2(node);
|
|
71
|
-
|
|
72
|
-
// write to stack in reverse order, so that fist child ends up being visited first
|
|
73
|
-
stack[stack.pointer++] = child1;
|
|
74
|
-
stack[stack.pointer++] = child2;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// drop stack frame
|
|
79
|
-
|
|
80
|
-
return result_cursor - result_offset;
|
|
81
|
-
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 18/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
import SampleTraverser from '../../graphics/texture/sampler/SampleTraverser.js';
|
|
5
|
-
import QuadGeometry from '../../graphics/geometry/QuadGeometry.js';
|
|
6
|
-
import * as THREE from 'three';
|
|
7
|
-
|
|
8
|
-
import ThreeFactory from '../../graphics/three/ThreeFactory.js';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
function makeCombinedGeometry(templateGeometry, normalAlign, width, height, count, scale, heightMap, material) {
|
|
12
|
-
const geometry = new THREE.Geometry();
|
|
13
|
-
|
|
14
|
-
const scaleMatrix = new THREE.Matrix4();
|
|
15
|
-
scaleMatrix.makeScale(scale.x, scale.y, scale.z);
|
|
16
|
-
|
|
17
|
-
function process(x, z) {
|
|
18
|
-
const y = heightMap.sampleHeight(x, z);
|
|
19
|
-
const pos = new THREE.Vector3(x, y, z);
|
|
20
|
-
//
|
|
21
|
-
const g = templateGeometry.clone();
|
|
22
|
-
//transform
|
|
23
|
-
const m = new THREE.Matrix4();
|
|
24
|
-
if (normalAlign) {
|
|
25
|
-
const normal = heightMap.sampleNormal(x, z);
|
|
26
|
-
m.lookAt(normal, new THREE.Vector3(), new THREE.Vector3(0, 1, 0));
|
|
27
|
-
}
|
|
28
|
-
m.setPosition(pos);
|
|
29
|
-
m.multiply(scaleMatrix);
|
|
30
|
-
g.applyMatrix4(m);
|
|
31
|
-
geometry.merge(g);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
createPieces(process, count, width, height);
|
|
35
|
-
const mesh = new THREE.Mesh(geometry, material);
|
|
36
|
-
return mesh;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function makeMultiMesh(templateGeometry, normalAlign, width, height, count, scale, heightMap, material) {
|
|
40
|
-
const object = new THREE.Object3D();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
function process(x, z) {
|
|
44
|
-
const y = heightMap.sampleHeight(x, z);
|
|
45
|
-
//
|
|
46
|
-
const m = new THREE.Mesh(templateGeometry, material);
|
|
47
|
-
//transform
|
|
48
|
-
if (normalAlign) {
|
|
49
|
-
const normal = heightMap.sampleNormal(x, z);
|
|
50
|
-
m.lookAt(normal, new THREE.Vector3(), new THREE.Vector3(0, 1, 0));
|
|
51
|
-
}
|
|
52
|
-
m.position.set(x, y, z);
|
|
53
|
-
m.scale.set(scale.x, scale.y, scale.z);
|
|
54
|
-
object.add(m);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
createPieces(process, count, width, height);
|
|
58
|
-
|
|
59
|
-
return object;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function createPieces(process, count, width, height) {
|
|
63
|
-
for (let i = 0; i < count; i++) {
|
|
64
|
-
const x = width * Math.random();
|
|
65
|
-
const z = height * Math.random();
|
|
66
|
-
process(x, z);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const alignToVector = (function () {
|
|
72
|
-
const matrix4 = new THREE.Matrix4();
|
|
73
|
-
|
|
74
|
-
function alignToVector(mesh, direction) {
|
|
75
|
-
matrix4.identity();
|
|
76
|
-
|
|
77
|
-
const el = matrix4.elements;
|
|
78
|
-
el[4] = direction.x;
|
|
79
|
-
el[5] = direction.y;
|
|
80
|
-
el[6] = direction.z;
|
|
81
|
-
mesh.rotation.setFromRotationMatrix(matrix4, 'XZY');
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return alignToVector;
|
|
85
|
-
})();
|
|
86
|
-
|
|
87
|
-
const Foliage = function (options, mask, quadTree, caster) {
|
|
88
|
-
|
|
89
|
-
const size = options.size || 1;
|
|
90
|
-
const randomRotateY = options.randomRotateY !== void 0 ? options.randomRotateY : false;
|
|
91
|
-
|
|
92
|
-
const templateGeometry = options.geometry || new QuadGeometry(1, 1);
|
|
93
|
-
let boundingSphere = templateGeometry.boundingSphere;
|
|
94
|
-
if (boundingSphere === void 0 || boundingSphere === null) {
|
|
95
|
-
boundingSphere = templateGeometry.computeBoundingSphere();
|
|
96
|
-
}
|
|
97
|
-
const scaleFactor = 1 / (boundingSphere.radius * 2);
|
|
98
|
-
const material = options.material;
|
|
99
|
-
const density = options.density;
|
|
100
|
-
const densityMap = options.densityMap;
|
|
101
|
-
const normalAlign = options.normalAlign !== void 0 ? options.normalAlign : true;
|
|
102
|
-
const castShadow = options.castShadow !== void 0 ? options.castShadow : false;
|
|
103
|
-
const receiveShadow = options.receiveShadow !== void 0 ? options.receiveShadow : false;
|
|
104
|
-
//
|
|
105
|
-
|
|
106
|
-
const mapSize = new THREE.Vector2(options.width, options.height);
|
|
107
|
-
//
|
|
108
|
-
const object = new THREE.Object3D();
|
|
109
|
-
|
|
110
|
-
const mapWidth = mapSize.x;
|
|
111
|
-
const mapHeight = mapSize.y;
|
|
112
|
-
|
|
113
|
-
function process(u, v, size) {
|
|
114
|
-
const x = u * mapWidth;
|
|
115
|
-
const z = v * mapHeight;
|
|
116
|
-
caster(x, z, function (hit, normal, geometry) {
|
|
117
|
-
const y = hit.y;
|
|
118
|
-
//
|
|
119
|
-
const m = ThreeFactory.createMesh(templateGeometry, material);
|
|
120
|
-
//transform
|
|
121
|
-
if (normalAlign) {
|
|
122
|
-
// m.lookAt(normal, new THREE.Vector3(), new THREE.Vector3(0, 1, 0));
|
|
123
|
-
alignToVector(m, normal);
|
|
124
|
-
}
|
|
125
|
-
if (randomRotateY) {
|
|
126
|
-
m.rotation.y = Math.PI * 2 * Math.random();
|
|
127
|
-
}
|
|
128
|
-
m.position.set(x, y, z);
|
|
129
|
-
m.castShadow = castShadow;
|
|
130
|
-
m.receiveShadow = receiveShadow;
|
|
131
|
-
const scale = scaleFactor * size;
|
|
132
|
-
m.scale.set(scale, scale, scale);
|
|
133
|
-
object.add(m);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
//console.time('generating foliage');
|
|
139
|
-
const sampleTraverser = new SampleTraverser();
|
|
140
|
-
sampleTraverser.resolveSpace = true;
|
|
141
|
-
sampleTraverser.resolveSpaceSizeMin = size.min;
|
|
142
|
-
sampleTraverser.resolveSpaceSizeMax = size.max;
|
|
143
|
-
sampleTraverser.mask = mask;
|
|
144
|
-
sampleTraverser.quadTree = quadTree;
|
|
145
|
-
|
|
146
|
-
sampleTraverser.traverse(densityMap, density, mapSize, process);
|
|
147
|
-
//console.timeEnd('generating foliage');
|
|
148
|
-
//
|
|
149
|
-
return object;
|
|
150
|
-
};
|
|
151
|
-
export default Foliage;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 21/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
import * as THREE from 'three';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const Loader = function () {
|
|
8
|
-
function load(options, callback) {
|
|
9
|
-
const url = options.url;
|
|
10
|
-
const density = options.density;
|
|
11
|
-
const normalAlign = options.normalAlign;
|
|
12
|
-
const size = options.size;
|
|
13
|
-
const densityMap = options.densityMap;
|
|
14
|
-
const randomRotateY = options.randomRotateY;
|
|
15
|
-
const loader = new THREE.JSONLoader();
|
|
16
|
-
loader.load(url, function (geometry, materials) {
|
|
17
|
-
const material = new THREE.MultiMaterial(materials);
|
|
18
|
-
|
|
19
|
-
callback({
|
|
20
|
-
density: density,
|
|
21
|
-
material: material,
|
|
22
|
-
geometry: geometry,
|
|
23
|
-
normalAlign: normalAlign,
|
|
24
|
-
densityMap: densityMap,
|
|
25
|
-
size: size,
|
|
26
|
-
width: options.width,
|
|
27
|
-
height: options.height,
|
|
28
|
-
randomRotateY: randomRotateY,
|
|
29
|
-
castShadow: options.castShadow,
|
|
30
|
-
receiveShadow: options.receiveShadow
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
this.load = load;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export default Loader;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BVHVisitor } from "../../../core/bvh2/traversal/BVHVisitor.js";
|
|
2
|
-
import { BitSet } from "../../../core/binary/BitSet.js";
|
|
3
|
-
|
|
4
|
-
export class FoliageVisibilitySetBuilder extends BVHVisitor {
|
|
5
|
-
constructor() {
|
|
6
|
-
super();
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @type {BitSet}
|
|
11
|
-
*/
|
|
12
|
-
this.visibleSet = new BitSet();
|
|
13
|
-
//prevent re-allocation
|
|
14
|
-
this.visibleSet.preventShrink();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
initialize() {
|
|
18
|
-
this.visibleSet.reset();
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
visitLeaf(node) {
|
|
22
|
-
const index = node.object;
|
|
23
|
-
|
|
24
|
-
//TODO check screen space size to decide if element should be seen or not
|
|
25
|
-
this.visibleSet.set(index, true);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 24/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Created by Alex on 18/10/2014.
|
|
6
|
-
*/
|
|
7
|
-
import SampleTraverser from '../../graphics/texture/sampler/SampleTraverser.js';
|
|
8
|
-
import {
|
|
9
|
-
Box3 as ThreeBox3,
|
|
10
|
-
BufferAttribute,
|
|
11
|
-
BufferGeometry,
|
|
12
|
-
NormalBlending,
|
|
13
|
-
PointCloud,
|
|
14
|
-
PointCloudMaterial,
|
|
15
|
-
Sphere as ThreeSphere,
|
|
16
|
-
Vector3 as ThreeVector3,
|
|
17
|
-
VertexColors
|
|
18
|
-
} from 'three';
|
|
19
|
-
import Vector2 from "../../../core/geom/Vector2.js";
|
|
20
|
-
import Vector4 from "../../../core/geom/Vector4.js";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @deprecated use other options, such as ShadedMesh with INSTANCED draw mode or dedicated instanced mesh system such as Foliage2System
|
|
24
|
-
* @constructor
|
|
25
|
-
*/
|
|
26
|
-
const Foliage = function (options) {
|
|
27
|
-
const size = options.size || 1;
|
|
28
|
-
const lightMap = options.lightMap;
|
|
29
|
-
const texture = options.texture;
|
|
30
|
-
const density = options.density;
|
|
31
|
-
const densityMap = options.densityMap;
|
|
32
|
-
const heightMap = options.heightMap;
|
|
33
|
-
let zRange = options.zRange;
|
|
34
|
-
let normalAlign = options.normalAlign !== void 0 ? options.normalAlign : true;
|
|
35
|
-
//
|
|
36
|
-
const mapSize = new Vector2(options.width, options.height);
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
console.time('generating impostor foliage');
|
|
40
|
-
const geometry = new BufferGeometry();
|
|
41
|
-
const _vertices = [];
|
|
42
|
-
const _colors = [];
|
|
43
|
-
let i = 0;
|
|
44
|
-
|
|
45
|
-
const offsetY = 0.00001;
|
|
46
|
-
|
|
47
|
-
const color = new Vector4();
|
|
48
|
-
|
|
49
|
-
function process(x, y, z, u, v) {
|
|
50
|
-
const iX = i++,
|
|
51
|
-
iY = i++,
|
|
52
|
-
iZ = i++;
|
|
53
|
-
_vertices[iX] = x;
|
|
54
|
-
_vertices[iY] = y + offsetY;
|
|
55
|
-
_vertices[iZ] = z;
|
|
56
|
-
//colors
|
|
57
|
-
lightMap.sample(u, v, color);
|
|
58
|
-
_colors[iX] = color.x / 255;
|
|
59
|
-
_colors[iY] = color.y / 255;
|
|
60
|
-
_colors[iZ] = color.z / 255;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const sampleTraverser = new SampleTraverser();
|
|
64
|
-
sampleTraverser.resolveSpace = true;
|
|
65
|
-
sampleTraverser.resolveSpaceSize = density / size;
|
|
66
|
-
sampleTraverser.traverse(heightMap, densityMap, density, mapSize, process);
|
|
67
|
-
|
|
68
|
-
const vertices = new Float32Array(i);
|
|
69
|
-
const colors = new Float32Array(i);
|
|
70
|
-
//copy
|
|
71
|
-
vertices.set(_vertices, 0);
|
|
72
|
-
colors.set(_colors, 0);
|
|
73
|
-
console.log("impostor count: " + i);
|
|
74
|
-
|
|
75
|
-
geometry.setAttribute('position', new BufferAttribute(vertices, 3));
|
|
76
|
-
//if color map is present - use it
|
|
77
|
-
geometry.setAttribute('color', new BufferAttribute(colors, 3));
|
|
78
|
-
|
|
79
|
-
//bake bounding box and sphere to save computation time
|
|
80
|
-
const center = new ThreeVector3(mapSize.x / 2, zRange / 2 - offsetY, mapSize.y / 2);
|
|
81
|
-
geometry.boundingSphere = new ThreeSphere(center, center.length());
|
|
82
|
-
geometry.boundingBox = new ThreeBox3(new ThreeVector3(0, -zRange / 2 + offsetY, 0), new ThreeVector3(mapSize.x, zRange / 2 + offsetY, mapSize.y));
|
|
83
|
-
|
|
84
|
-
const mat = new PointCloudMaterial({
|
|
85
|
-
size: size,
|
|
86
|
-
map: texture,
|
|
87
|
-
blending: NormalBlending,
|
|
88
|
-
depthTest: true,
|
|
89
|
-
depthWrite: false,
|
|
90
|
-
alphaTest: 0.5,
|
|
91
|
-
sizeAttenuation: true,
|
|
92
|
-
vertexColors: VertexColors,
|
|
93
|
-
transparent: true
|
|
94
|
-
//
|
|
95
|
-
//polygonOffset: true,
|
|
96
|
-
//polygonOffsetFactor: -4,
|
|
97
|
-
//polygonOffsetUnits: -4
|
|
98
|
-
});
|
|
99
|
-
mat.color.setHSL(1, 1, 1);
|
|
100
|
-
|
|
101
|
-
const mesh = new PointCloud(geometry, mat);
|
|
102
|
-
console.timeEnd('generating impostor foliage');
|
|
103
|
-
//
|
|
104
|
-
return mesh;
|
|
105
|
-
};
|
|
106
|
-
export default Foliage;
|