@woosh/meep-engine 2.34.32 → 2.34.36
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/core/assert.js +11 -0
- package/core/binary/BitSet.js +5 -0
- package/core/bvh2/BinaryNode.js +210 -74
- package/core/bvh2/Node.d.ts +3 -0
- package/core/bvh2/aabb3/AABB3.js +50 -4
- package/core/bvh2/aabb3/AABB3Math.js +1 -1
- package/core/bvh2/aabb3/aabb3_from_v3_array.js +34 -0
- package/core/bvh2/aabb3/aabb3_from_v3_array_transformed.js +39 -0
- package/core/bvh2/aabb3/aabb3_intersects_frustum_degree.js +46 -0
- package/core/bvh2/transform/RotationOptimizer.js +2 -262
- package/core/bvh2/transform/tryRotateSingleNode.js +259 -0
- package/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +16 -35
- package/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +52 -0
- package/core/collection/list/List.js +0 -34
- package/core/events/signal/Signal.js +1 -1
- package/core/geom/3d/aabb/aabb3_matrix4_project.js +2 -3
- package/core/geom/Quaternion.d.ts +2 -0
- package/engine/Engine.js +5 -0
- package/engine/asset/loaders/ArrayBufferLoader.js +7 -0
- package/engine/asset/loaders/image/ImageRGBADataLoader.js +11 -6
- package/engine/development/performance/AbstractMetric.js +4 -0
- package/engine/development/performance/RingBufferMetric.js +4 -0
- package/engine/ecs/EntityBuilder.js +12 -5
- package/engine/ecs/EntityComponentDataset.js +26 -6
- package/engine/ecs/attachment/AttachmentSystem.js +1 -1
- package/engine/ecs/attachment/TransformAttachmentBinding.js +0 -1
- package/engine/ecs/foliage/FoliageVisibilitySetBuilder.js +1 -31
- package/engine/ecs/foliage/InstancedFoliage.js +81 -152
- package/engine/ecs/foliage/ViewState.js +190 -0
- package/engine/ecs/foliage/ecs/Foliage2System.js +80 -12
- package/engine/ecs/foliage/ecs/InstancedMeshComponent.js +30 -0
- package/engine/ecs/foliage/ecs/InstancedMeshLayer.js +16 -0
- package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +2 -2
- package/engine/ecs/parent/EntityNode.js +31 -49
- package/engine/ecs/sockets/AttachmentSockets.js +11 -1
- package/engine/ecs/transform-attachment/TransformAttachment.js +88 -0
- package/engine/ecs/transform-attachment/TransformAttachmentSystem.js +59 -0
- package/engine/graphics/GraphicsEngine.js +23 -2
- package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +2 -19
- package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +21 -21
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +9 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometryFlags.js +4 -1
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +3 -0
- package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +40 -8
- package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +3 -3
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +17 -11
- package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +1 -34
- package/engine/graphics/micron/build/fill_patch_geometry_data.js +19 -6
- package/engine/graphics/micron/format/MicronGeometry.js +21 -0
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -3
- package/engine/graphics/micron/prototypeVirtualGeometry.js +69 -1
- package/engine/graphics/render/layers/RenderLayer.js +22 -85
- package/engine/graphics/render/visibility/VisibilityComputer.js +23 -103
- package/engine/sound/ecs/emitter/SoundEmitterSystem.js +1 -1
- package/package.json +1 -1
- package/samples/terrain/editor.js +0 -1
|
@@ -10,10 +10,9 @@ import { ShadedGeometry } from "./ShadedGeometry.js";
|
|
|
10
10
|
export function three_object_to_entity_composition(root) {
|
|
11
11
|
const node = new EntityNode();
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
transform.fromMatrix4(root.matrix.elements);
|
|
13
|
+
node.transform.fromMatrix4(root.matrix.elements);
|
|
15
14
|
|
|
16
|
-
node.entity.add(
|
|
15
|
+
node.entity.add(new Transform());
|
|
17
16
|
|
|
18
17
|
if (root.isMesh) {
|
|
19
18
|
if (root.isSkinnedMesh) {
|
|
@@ -30,6 +29,7 @@ export function three_object_to_entity_composition(root) {
|
|
|
30
29
|
|
|
31
30
|
const child_node = three_object_to_entity_composition(child);
|
|
32
31
|
|
|
32
|
+
|
|
33
33
|
node.addChild(child_node);
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -320,11 +320,13 @@ export class InstancedMeshGroup {
|
|
|
320
320
|
|
|
321
321
|
const lastIndex = this.count - 1;
|
|
322
322
|
|
|
323
|
+
const references = this.references;
|
|
324
|
+
|
|
323
325
|
if (index === lastIndex) {
|
|
324
326
|
//easy case, reference is placed at the end, no swap needed, we can just forget about it
|
|
325
|
-
delete
|
|
327
|
+
delete references[index];
|
|
326
328
|
} else {
|
|
327
|
-
//not at the end, move
|
|
329
|
+
//not at the end, move the very last reference to this place, effectively shrinking the set
|
|
328
330
|
const index3 = index * 3;
|
|
329
331
|
const start3 = lastIndex * 3;
|
|
330
332
|
const end3 = start3 + 3;
|
|
@@ -333,26 +335,30 @@ export class InstancedMeshGroup {
|
|
|
333
335
|
const start4 = lastIndex * 4;
|
|
334
336
|
const end4 = start4 + 4;
|
|
335
337
|
|
|
336
|
-
this.__attributePosition
|
|
337
|
-
this.__attributeRotation
|
|
338
|
-
this.__attributeScale
|
|
338
|
+
const a_position = this.__attributePosition;
|
|
339
|
+
const a_rotation = this.__attributeRotation;
|
|
340
|
+
const a_scale = this.__attributeScale;
|
|
341
|
+
|
|
342
|
+
a_position.array.copyWithin(index3, start3, end3);
|
|
343
|
+
a_rotation.array.copyWithin(index4, start4, end4);
|
|
344
|
+
a_scale.array.copyWithin(index3, start3, end3);
|
|
339
345
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
346
|
+
a_position.needsUpdate = true;
|
|
347
|
+
a_rotation.needsUpdate = true;
|
|
348
|
+
a_scale.needsUpdate = true;
|
|
343
349
|
|
|
344
350
|
//update moved reference index
|
|
345
|
-
const movedReference =
|
|
351
|
+
const movedReference = references[lastIndex];
|
|
346
352
|
|
|
347
353
|
if (movedReference === undefined) {
|
|
348
354
|
//moved reference not found
|
|
349
355
|
throw new Error(`Moved reference was not found`);
|
|
350
356
|
}
|
|
351
357
|
|
|
352
|
-
delete
|
|
358
|
+
delete references[lastIndex];
|
|
353
359
|
|
|
354
360
|
//assume the place of removed reference
|
|
355
|
-
|
|
361
|
+
references[index] = movedReference;
|
|
356
362
|
this.indices[movedReference] = index;
|
|
357
363
|
}
|
|
358
364
|
|
|
@@ -14,8 +14,7 @@ import { build_leaf_patches_metis } from "./clustering/build_leaf_patches_metis.
|
|
|
14
14
|
import { compute_buffer_geometry_byte_size } from "../../geometry/buffered/compute_buffer_geometry_byte_size.js";
|
|
15
15
|
import { deinterleaveBufferGeometry } from "../../geometry/buffered/deinterleaveBufferGeometry.js";
|
|
16
16
|
import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
|
|
17
|
-
import {
|
|
18
|
-
import { max2 } from "../../../../core/math/max2.js";
|
|
17
|
+
import { aabb3_from_v3_array } from "../../../../core/bvh2/aabb3/aabb3_from_v3_array.js";
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* Returns current time in milliseconds
|
|
@@ -118,38 +117,6 @@ function attributes_from_buffer_geometry(buffer_geometry) {
|
|
|
118
117
|
|
|
119
118
|
const PRINT_VERBOSE_STATS = false;
|
|
120
119
|
|
|
121
|
-
/**
|
|
122
|
-
*
|
|
123
|
-
* @param {AABB3} result
|
|
124
|
-
* @param {number[]|ArrayLike<number>} input
|
|
125
|
-
* @param {number} input_length
|
|
126
|
-
*/
|
|
127
|
-
function aabb3_from_v3_array(result, input, input_length) {
|
|
128
|
-
let x0 = Infinity;
|
|
129
|
-
let y0 = Infinity;
|
|
130
|
-
let z0 = Infinity;
|
|
131
|
-
|
|
132
|
-
let x1 = -Infinity;
|
|
133
|
-
let y1 = -Infinity;
|
|
134
|
-
let z1 = -Infinity;
|
|
135
|
-
|
|
136
|
-
for (let i = 0; i < input_length; i += 3) {
|
|
137
|
-
const x = input[i];
|
|
138
|
-
const y = input[i + 1];
|
|
139
|
-
const z = input[i + 2];
|
|
140
|
-
|
|
141
|
-
x0 = min2(x, x0);
|
|
142
|
-
y0 = min2(y, y0);
|
|
143
|
-
z0 = min2(z, z0);
|
|
144
|
-
|
|
145
|
-
x1 = max2(x, x1);
|
|
146
|
-
y1 = max2(y, y1);
|
|
147
|
-
z1 = max2(z, z1);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
result.setBounds(x0, y0, z0, x1, y1, z1);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
120
|
/**
|
|
154
121
|
*
|
|
155
122
|
* @param {THREE.BufferGeometry} input
|
|
@@ -113,6 +113,15 @@ function normalize_to_int8(value) {
|
|
|
113
113
|
return Math.round(value * 127);
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
*
|
|
118
|
+
* @param {number} value
|
|
119
|
+
* @return {number}
|
|
120
|
+
*/
|
|
121
|
+
function normalize_to_uint8(value) {
|
|
122
|
+
return Math.round(value * 255);
|
|
123
|
+
}
|
|
124
|
+
|
|
116
125
|
/**
|
|
117
126
|
* @enum {function(number):number}
|
|
118
127
|
*/
|
|
@@ -120,6 +129,7 @@ const DataConverterType = {
|
|
|
120
129
|
None: passThrough,
|
|
121
130
|
Number2HalfFloat: to_half_float_uint16,
|
|
122
131
|
Normalize2Int8: normalize_to_int8,
|
|
132
|
+
Normalize2Uint8: normalize_to_uint8,
|
|
123
133
|
ResampleNormalized_Uint16_to_Uint8: resample_normalized_uint16_to_uint8
|
|
124
134
|
};
|
|
125
135
|
|
|
@@ -130,30 +140,33 @@ const DataConverterType = {
|
|
|
130
140
|
* @returns {DataConverterType}
|
|
131
141
|
*/
|
|
132
142
|
function compute_attribute_data_converter(source, spec) {
|
|
133
|
-
|
|
143
|
+
const target_type = spec.type;
|
|
144
|
+
if (target_type === DataType.Float16) {
|
|
134
145
|
return DataConverterType.Number2HalfFloat;
|
|
135
146
|
} else if (spec.normalized && !source.normalized) {
|
|
136
147
|
// source data can be normalized but isn't
|
|
137
|
-
if (
|
|
148
|
+
if (target_type === DataType.Int8) {
|
|
138
149
|
return DataConverterType.Normalize2Int8;
|
|
150
|
+
} else if (target_type === DataType.Uint8) {
|
|
151
|
+
return DataConverterType.Normalize2Uint8;
|
|
139
152
|
} else {
|
|
140
|
-
throw new Error(`Unsupported normalized type '${
|
|
153
|
+
throw new Error(`Unsupported normalized type '${target_type}'`);
|
|
141
154
|
}
|
|
142
155
|
} else {
|
|
143
156
|
const source_array = source.array;
|
|
144
157
|
|
|
145
158
|
const source_type = typedArrayToDataType(source_array);
|
|
146
159
|
|
|
147
|
-
const target_byte_size = dataTypeByteSize(
|
|
160
|
+
const target_byte_size = dataTypeByteSize(target_type);
|
|
148
161
|
const source_byte_size = dataTypeByteSize(source_type)
|
|
149
162
|
|
|
150
163
|
if (target_byte_size !== source_byte_size) {
|
|
151
164
|
// wrong data size
|
|
152
165
|
|
|
153
|
-
if (
|
|
166
|
+
if (target_type === DataType.Uint8 && source_type === DataType.Uint16) {
|
|
154
167
|
return DataConverterType.ResampleNormalized_Uint16_to_Uint8;
|
|
155
168
|
} else {
|
|
156
|
-
throw new Error(`Unsupported conversion ${source_type} -> `);
|
|
169
|
+
throw new Error(`Unsupported conversion ${source_type} -> ${target_type}`);
|
|
157
170
|
}
|
|
158
171
|
|
|
159
172
|
} else {
|
|
@@ -4,6 +4,7 @@ import { computeTriangleRayIntersection } from "../../../../core/geom/3d/triangl
|
|
|
4
4
|
import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
5
5
|
import { aabb3_array_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_array_intersects_ray.js";
|
|
6
6
|
import { sphere_array_intersects_ray } from "../../../../core/geom/3d/sphere/sphere_array_intersects_ray.js";
|
|
7
|
+
import { BitSet } from "../../../../core/binary/BitSet.js";
|
|
7
8
|
|
|
8
9
|
let id_counter = 0;
|
|
9
10
|
|
|
@@ -13,6 +14,13 @@ let id_counter = 0;
|
|
|
13
14
|
*/
|
|
14
15
|
const scratch_traversal_stack = [];
|
|
15
16
|
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @type {BitSet}
|
|
20
|
+
*/
|
|
21
|
+
const scratch_traversal_bitset = new BitSet();
|
|
22
|
+
scratch_traversal_bitset.preventShrink();
|
|
23
|
+
|
|
16
24
|
export class MicronGeometry {
|
|
17
25
|
constructor() {
|
|
18
26
|
/**
|
|
@@ -79,6 +87,7 @@ export class MicronGeometry {
|
|
|
79
87
|
origin_x, origin_y, origin_z,
|
|
80
88
|
direction_x, direction_y, direction_z
|
|
81
89
|
) {
|
|
90
|
+
|
|
82
91
|
let i;
|
|
83
92
|
let stack_cursor = 1;
|
|
84
93
|
|
|
@@ -99,6 +108,11 @@ export class MicronGeometry {
|
|
|
99
108
|
// check that position attribute actually exists
|
|
100
109
|
assert.isNonNegativeInteger(position_attribute_index, 'position_attribute_index');
|
|
101
110
|
|
|
111
|
+
const included_set = scratch_traversal_bitset;
|
|
112
|
+
included_set.reset();
|
|
113
|
+
|
|
114
|
+
included_set.set(this.root.id, true);
|
|
115
|
+
|
|
102
116
|
const temp_hit = new SurfacePoint3();
|
|
103
117
|
|
|
104
118
|
while (stack_cursor > 0) {
|
|
@@ -106,6 +120,7 @@ export class MicronGeometry {
|
|
|
106
120
|
|
|
107
121
|
const patch = stack[stack_cursor];
|
|
108
122
|
|
|
123
|
+
|
|
109
124
|
if (patch.lod === 0) {
|
|
110
125
|
// LOD 0 - source geometry
|
|
111
126
|
|
|
@@ -206,9 +221,15 @@ export class MicronGeometry {
|
|
|
206
221
|
for (i = 0; i < child_count; i++) {
|
|
207
222
|
const child = children[i];
|
|
208
223
|
|
|
224
|
+
if (included_set.get(child.id)) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
|
|
209
228
|
// push to stack
|
|
210
229
|
stack[stack_cursor] = child;
|
|
211
230
|
|
|
231
|
+
included_set.set(child.id, true);
|
|
232
|
+
|
|
212
233
|
stack_cursor++;
|
|
213
234
|
}
|
|
214
235
|
}
|
|
@@ -2,7 +2,6 @@ import { EnginePlugin } from "../../../plugin/EnginePlugin.js";
|
|
|
2
2
|
import { VGThreeRenderer } from "../render/v1/VGThreeRenderer.js";
|
|
3
3
|
import { RenderLayer } from "../../render/layers/RenderLayer.js";
|
|
4
4
|
import { RenderPassType } from "../../render/RenderPassType.js";
|
|
5
|
-
import { SOURCE_RENDER_LAYER_PROPERTY } from "../../render/visibility/VisibilityComputer.js";
|
|
6
5
|
import { AssetTransformer } from "../../../asset/AssetTransformer.js";
|
|
7
6
|
import { convert_three_object_to_micron } from "../convert_three_object_to_micron.js";
|
|
8
7
|
import { Cache } from "../../../../core/cache/Cache.js";
|
|
@@ -180,8 +179,6 @@ export class MicronRenderPlugin extends EnginePlugin {
|
|
|
180
179
|
|
|
181
180
|
const mesh = ctx.mesh;
|
|
182
181
|
|
|
183
|
-
mesh[SOURCE_RENDER_LAYER_PROPERTY] = layer;
|
|
184
|
-
|
|
185
182
|
visibleSet.elements.push(mesh);
|
|
186
183
|
visibleSet.size++;
|
|
187
184
|
|
|
@@ -20,6 +20,8 @@ import {
|
|
|
20
20
|
SphereGeometry,
|
|
21
21
|
sRGBEncoding,
|
|
22
22
|
TextureLoader,
|
|
23
|
+
Vector2,
|
|
24
|
+
Vector3,
|
|
23
25
|
VSMShadowMap,
|
|
24
26
|
WebGLRenderer
|
|
25
27
|
} from "three";
|
|
@@ -46,6 +48,8 @@ import { CanvasView } from "../../../view/elements/CanvasView.js";
|
|
|
46
48
|
import { Sampler2D } from "../texture/sampler/Sampler2D.js";
|
|
47
49
|
import { downsampleSampler2D } from "../texture/sampler/downsampleSampler2D.js";
|
|
48
50
|
import { ShadowMapRenderer } from "../shadows/ShadowMapRenderer.js";
|
|
51
|
+
import { MouseEvents } from "../../input/devices/events/MouseEvents.js";
|
|
52
|
+
import { mat4 } from "gl-matrix";
|
|
49
53
|
|
|
50
54
|
const background = new TextureLoader().load('data/textures/utility/checkers_white_grey_256x256.png');
|
|
51
55
|
background.repeat.set(50, 30);
|
|
@@ -473,7 +477,8 @@ function init() {
|
|
|
473
477
|
// gltf_sample('moicon/03_Jan_22_Demo/3-area_ground_floor/model.gltf');
|
|
474
478
|
// gltf_sample('moicon/03_Jan_22_Demo/4-area_1st_floor/model.gltf');
|
|
475
479
|
// gltf_sample('moicon/03_Jan_22_Demo/8-assets/model.gltf');
|
|
476
|
-
gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
|
|
480
|
+
// gltf_sample('moicon/03_Jan_22_Demo/worker_test/model.gltf');
|
|
481
|
+
gltf_sample('moicon/A4/A4/model.gltf');
|
|
477
482
|
|
|
478
483
|
document.addEventListener("mousemove", onDocumentMouseMove);
|
|
479
484
|
|
|
@@ -735,6 +740,7 @@ shadowmapRenderer.onBeforeRender.add((renderer, camera, scene) => {
|
|
|
735
740
|
vgtr.render();
|
|
736
741
|
});
|
|
737
742
|
|
|
743
|
+
|
|
738
744
|
function render() {
|
|
739
745
|
if (orbitControls !== undefined) {
|
|
740
746
|
orbitControls.update();
|
|
@@ -790,3 +796,65 @@ function render() {
|
|
|
790
796
|
// console.log(`patches:${active_patches.length}, polycount:${polycount}`);
|
|
791
797
|
}
|
|
792
798
|
|
|
799
|
+
window.document.body.addEventListener(MouseEvents.Move, ({ clientX, clientY }) => {
|
|
800
|
+
const direction = new Vector3();
|
|
801
|
+
|
|
802
|
+
const viewport_size = new Vector2();
|
|
803
|
+
|
|
804
|
+
renderer.getSize(viewport_size);
|
|
805
|
+
|
|
806
|
+
const v2_nx = (clientX / viewport_size.x) * 2 - 1;
|
|
807
|
+
const v2_ny = -(clientY / viewport_size.y) * 2 + 1;
|
|
808
|
+
|
|
809
|
+
direction.set(v2_nx, v2_ny, 0.5);
|
|
810
|
+
|
|
811
|
+
direction.unproject(camera);
|
|
812
|
+
|
|
813
|
+
direction.sub(camera.position);
|
|
814
|
+
|
|
815
|
+
direction.normalize();
|
|
816
|
+
|
|
817
|
+
const origin_x = camera.position.x;
|
|
818
|
+
const origin_y = camera.position.y;
|
|
819
|
+
const origin_z = camera.position.z;
|
|
820
|
+
|
|
821
|
+
const direction_x = direction.x;
|
|
822
|
+
const direction_y = direction.y;
|
|
823
|
+
const direction_z = direction.z;
|
|
824
|
+
|
|
825
|
+
const hits = [];
|
|
826
|
+
scene.traverse(o => {
|
|
827
|
+
if (o.isMicronMesh) {
|
|
828
|
+
/**
|
|
829
|
+
* @type {MicronGeometry}
|
|
830
|
+
*/
|
|
831
|
+
const micron_geo = o.geometry;
|
|
832
|
+
|
|
833
|
+
const scratch_m4 = new Float32Array(16);
|
|
834
|
+
|
|
835
|
+
// get transform in local space
|
|
836
|
+
mat4.invert(scratch_m4, o.matrixWorld);
|
|
837
|
+
|
|
838
|
+
// transform ray to local space
|
|
839
|
+
const local_origin_x = scratch_m4[0] * origin_x + scratch_m4[4] * origin_y + scratch_m4[8] * origin_z + scratch_m4[12];
|
|
840
|
+
const local_origin_y = scratch_m4[1] * origin_x + scratch_m4[5] * origin_y + scratch_m4[9] * origin_z + scratch_m4[13];
|
|
841
|
+
const local_origin_z = scratch_m4[2] * origin_x + scratch_m4[6] * origin_y + scratch_m4[10] * origin_z + scratch_m4[14];
|
|
842
|
+
|
|
843
|
+
const local_direction_x = scratch_m4[0] * direction_x + scratch_m4[4] * direction_y + scratch_m4[8] * direction_z;
|
|
844
|
+
const local_direction_y = scratch_m4[1] * direction_x + scratch_m4[5] * direction_y + scratch_m4[9] * direction_z;
|
|
845
|
+
const local_direction_z = scratch_m4[2] * direction_x + scratch_m4[6] * direction_y + scratch_m4[10] * direction_z;
|
|
846
|
+
// NOTE: direction is not normalized
|
|
847
|
+
|
|
848
|
+
const point = micron_geo.raycast(local_origin_x, local_origin_y, local_origin_z, local_direction_x, local_direction_y, local_direction_z);
|
|
849
|
+
|
|
850
|
+
Array.prototype.push.apply(hits, point.map(p => {
|
|
851
|
+
return { position: p.position.toJSON(), geometry: micron_geo.id, instance: o.id };
|
|
852
|
+
}));
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
|
|
856
|
+
if (hits.length > 0) {
|
|
857
|
+
console.log(`HITS: ${hits.map(JSON.stringify).join(',')}`);
|
|
858
|
+
}
|
|
859
|
+
});
|
|
860
|
+
|
|
@@ -6,73 +6,19 @@
|
|
|
6
6
|
import { BinaryNode } from '../../../../core/bvh2/BinaryNode.js';
|
|
7
7
|
import { RenderPassType } from "../RenderPassType.js";
|
|
8
8
|
import { IncrementalDeltaSet } from "../visibility/IncrementalDeltaSet.js";
|
|
9
|
-
import {
|
|
10
|
-
import { noop, passThrough } from "../../../../core/function/Functions.js";
|
|
11
|
-
import { ThreeFrustumsIntersectionBVHVisitor } from "../../../../core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js";
|
|
9
|
+
import { passThrough } from "../../../../core/function/Functions.js";
|
|
12
10
|
import { traverseBinaryNodeUsingVisitor } from "../../../../core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js";
|
|
13
11
|
import { ThreeClippingPlaneComputingBVHVisitor } from "../../../../core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js";
|
|
14
12
|
import { RenderLayerState } from "./RenderLayerState.js";
|
|
15
13
|
import { compare_three_objects } from "../../three/compare_three_objects.js";
|
|
14
|
+
import { queryBinaryNode_FrustumIntersections_Data } from "../../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
|
|
16
15
|
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
* @type {Function[]}
|
|
25
|
-
*/
|
|
26
|
-
this.filters = [];
|
|
27
|
-
this.filterCount = 0;
|
|
28
|
-
|
|
29
|
-
this.callback = noop;
|
|
30
|
-
this.callbackContext = null;
|
|
31
|
-
|
|
32
|
-
this.reader = passThrough;
|
|
33
|
-
|
|
34
|
-
this.count = 0;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
initialize() {
|
|
38
|
-
this.filterCount = this.filters.length;
|
|
39
|
-
this.count = 0;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
visitLeaf(leaf) {
|
|
43
|
-
const numFilters = this.filterCount;
|
|
44
|
-
|
|
45
|
-
const filters = this.filters;
|
|
46
|
-
|
|
47
|
-
for (let i = 0; i < numFilters; i++) {
|
|
48
|
-
const filterFunction = filters[i];
|
|
49
|
-
|
|
50
|
-
const visibilityFlag = filterFunction(leaf);
|
|
51
|
-
|
|
52
|
-
if (!visibilityFlag) {
|
|
53
|
-
//not visible, skip
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const object = leaf.object;
|
|
59
|
-
|
|
60
|
-
if (object === null) {
|
|
61
|
-
// no payload on the BVH leaf
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const renderable = this.reader(object);
|
|
66
|
-
|
|
67
|
-
if (renderable === null) {
|
|
68
|
-
// no renderable on the payload
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
this.count++;
|
|
73
|
-
this.callback.call(this.callbackContext, renderable, leaf);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @type {*[]}
|
|
20
|
+
*/
|
|
21
|
+
const scratch_array = [];
|
|
76
22
|
|
|
77
23
|
export class RenderLayer {
|
|
78
24
|
constructor() {
|
|
@@ -119,18 +65,6 @@ export class RenderLayer {
|
|
|
119
65
|
* @type {RenderPassType|number}
|
|
120
66
|
*/
|
|
121
67
|
this.renderPass = RenderPassType.Opaque;
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* @private
|
|
125
|
-
* @type {VisibleLeafCollector}
|
|
126
|
-
*/
|
|
127
|
-
this.visibilityCollector = new VisibleLeafCollector();
|
|
128
|
-
/**
|
|
129
|
-
* @private
|
|
130
|
-
* @type {ThreeFrustumsIntersectionBVHVisitor}
|
|
131
|
-
*/
|
|
132
|
-
this.bvhVisibilityVisitor = new ThreeFrustumsIntersectionBVHVisitor();
|
|
133
|
-
this.bvhVisibilityVisitor.collector = this.visibilityCollector;
|
|
134
68
|
}
|
|
135
69
|
|
|
136
70
|
/**
|
|
@@ -178,29 +112,32 @@ export class RenderLayer {
|
|
|
178
112
|
|
|
179
113
|
/**
|
|
180
114
|
*
|
|
181
|
-
* @param {
|
|
182
|
-
* @param {function
|
|
183
|
-
* @param {function(Object3D, NodeDescription)} callback
|
|
115
|
+
* @param {CameraView} view
|
|
116
|
+
* @param {function(THREE.Object3D)} callback
|
|
184
117
|
* @param {*} [callbackContext]
|
|
185
118
|
*/
|
|
186
|
-
buildVisibleSet(
|
|
119
|
+
buildVisibleSet(view, callback, callbackContext) {
|
|
120
|
+
const frustum = view.frustum;
|
|
121
|
+
|
|
187
122
|
const reader = this.extractRenderable;
|
|
188
123
|
|
|
189
124
|
|
|
190
125
|
if (typeof reader === "function") {
|
|
191
|
-
this.visibilityCollector.callback = callback;
|
|
192
|
-
this.visibilityCollector.callbackContext = callbackContext;
|
|
193
126
|
|
|
194
|
-
this.
|
|
195
|
-
this.visibilityCollector.reader = reader;
|
|
127
|
+
const hits = queryBinaryNode_FrustumIntersections_Data(scratch_array, 0, this.bvh, frustum);
|
|
196
128
|
|
|
197
|
-
|
|
129
|
+
for (let i = 0; i < hits; i++) {
|
|
130
|
+
const datum = scratch_array[i];
|
|
198
131
|
|
|
199
|
-
|
|
132
|
+
const object3D = reader(datum);
|
|
200
133
|
|
|
201
|
-
|
|
134
|
+
if (!object3D) {
|
|
135
|
+
// null or undefined
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
202
138
|
|
|
203
|
-
|
|
139
|
+
callback.call(callbackContext, object3D);
|
|
140
|
+
}
|
|
204
141
|
|
|
205
142
|
}
|
|
206
143
|
|