@woosh/meep-engine 2.35.17 → 2.36.2
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/binary/BinaryBuffer.js +42 -17
- package/core/bvh2/BinaryNode.js +1 -1
- package/core/bvh2/aabb3/AABB3.js +2 -2
- package/core/bvh2/aabb3/aabb3_array_combine.js +20 -0
- package/core/bvh2/aabb3/aabb3_array_intersects_frustum_array.js +20 -0
- package/core/bvh2/aabb3/aabb3_array_intersects_ray.js +1 -0
- package/core/bvh2/aabb3/aabb3_array_intersects_ray_array.js +14 -0
- package/core/bvh2/{aabb3_combined_surface_area.js → aabb3/aabb3_combined_surface_area.js} +3 -3
- package/core/bvh2/aabb3/aabb3_intersects_frustum_array.js +1 -19
- package/core/bvh2/bvh3/BVHNodeProxy.js +53 -0
- package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +848 -0
- package/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.spec.js +142 -0
- package/core/bvh2/bvh3/bvh_query_leaves_generic.js +79 -0
- package/core/bvh2/bvh3/bvh_query_leaves_ray.js +95 -0
- package/core/bvh2/bvh3/query/BVHQuery.js +11 -0
- package/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +36 -0
- package/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +36 -0
- package/core/collection/array/copyArray.js +2 -2
- package/core/collection/table/RowFirstTable.js +25 -7
- package/core/collection/table/RowFirstTableSpec.js +4 -4
- package/core/geom/3d/aabb/aabb3_matrix4_project.spec.js +1 -1
- package/{engine/graphics/util → core/geom/3d/aabb}/computeBoundingBoxFromVertexData.js +1 -1
- package/core/geom/3d/compose_matrix4_array.js +53 -0
- package/{engine/graphics/util → core/geom/3d}/decompose_matrix_4_array.js +0 -0
- package/core/geom/AABB2.d.ts +2 -0
- package/core/geom/Vector1.js +2 -3
- package/core/geom/Vector3.js +5 -1
- package/core/process/undo/ActionProcessor.js +31 -3
- package/core/process/undo/ActionProcessor.spec.js +1 -1
- package/engine/animation/curve/AnimationCurve.js +40 -1
- package/engine/animation/curve/Keyframe.js +19 -0
- package/engine/animation/curve/compression/animation_curve_to_float_array.js +35 -0
- package/engine/animation/curve/compression/downsample_float_array.js +50 -0
- package/engine/animation/curve/compression/downsample_float_array_curve_by_error.js +147 -0
- package/engine/animation/curve/compression/downsample_float_array_curve_by_error.spec.js +47 -0
- package/engine/animation/curve/compression/prototypeCurveCompression.js +154 -0
- package/engine/animation/curve/draw/build_curve_editor.js +316 -0
- package/engine/animation/curve/draw/build_plot_entity_from_array.js +47 -0
- package/engine/animation/curve/draw/build_tangent_editor.js +115 -0
- package/engine/animation/curve/draw/draw_grid.js +27 -0
- package/engine/animation/curve/draw/draw_label.js +17 -0
- package/engine/animation/curve/draw/plot_array.js +76 -0
- package/engine/animation/curve/draw/plot_data.js +49 -0
- package/engine/asset/loaders/GLTFAssetLoader.js +3 -0
- package/engine/asset/loaders/gltf/GLTFAssetTransformMikkTSpaceTangents.js +27 -0
- package/engine/ecs/EntityComponentDataset.js +7 -4
- package/engine/ecs/foliage/InstancedFoliage.js +1 -1
- package/engine/ecs/foliage/ViewState.js +1 -1
- package/engine/ecs/parent/EntityNode.d.ts +7 -3
- package/engine/ecs/parent/EntityNode.js +21 -0
- package/engine/ecs/parent/entity_node_compute_bounding_box.js +41 -0
- package/engine/ecs/transform/Transform.js +2 -2
- package/engine/graphics/ecs/highlight/HighlightDefinition.d.ts +10 -0
- package/engine/graphics/ecs/highlight/HighlightDefinition.js +18 -8
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +5 -0
- package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +46 -12
- package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +81 -95
- package/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +16 -5
- package/engine/graphics/ecs/mesh-v2/render/adapters/InstancedRendererAdapter.js +2 -0
- package/engine/graphics/ecs/mesh-v2/sample/load_gltf.js +1 -0
- package/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +1 -1
- package/engine/graphics/ecs/path/tube/build/computeFrenetFrames.js +1 -2
- package/engine/graphics/geometry/MikkT/MikkTSpace.js +2210 -0
- package/engine/graphics/geometry/MikkT/MikkTSpace.spec.js +22 -0
- package/engine/graphics/geometry/MikkT/buffer_geometry_ensure_tangents.js +34 -0
- package/engine/graphics/geometry/MikkT/buffer_geometry_generate_tangents.js +28 -0
- package/engine/graphics/{compute_geometry_polycount.js → geometry/compute_geometry_polycount.js} +0 -0
- package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +34 -3
- package/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +1 -1
- package/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.js +83 -0
- package/engine/graphics/micron/format/serialization/collection/geometry_collection_serialization.spec.js +24 -0
- package/engine/graphics/micron/plugin/GLTFAssetTransformer.js +42 -19
- package/engine/graphics/micron/plugin/GLTF_MICRON_ID_FIELD.js +5 -0
- package/engine/graphics/micron/plugin/MicronRenderPlugin.js +0 -4
- package/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +10 -0
- package/engine/graphics/micron/prototypeVirtualGeometry.js +5 -3
- package/engine/graphics/micron/render/refinement/ActivePatchList.js +2 -2
- package/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +2 -2
- package/engine/graphics/micron/render/v1/MicronRenderContext.js +0 -6
- package/engine/graphics/render/forward_plus/LightManager.js +3 -1
- package/engine/graphics/util/composeMatrix4.js +1 -53
- package/engine/graphics/util/composeMatrix4RotationScale.js +1 -1
- package/engine/intelligence/blackboard/AbstractBlackboard.js +9 -0
- package/engine/notify/Notification.js +1 -1
- package/engine/ui/DraggableAspect.js +4 -1
- package/engine/ui/notification/ViewEmitter.js +7 -1
- package/engine/ui/notification/notificationGenerator.js +1 -1
- package/engine/ui/scene/SceneGUIContext.js +11 -130
- package/engine/ui/scene/initializeNotifications.js +141 -0
- package/package.json +1 -1
- package/view/elements/notify/NotificationView.js +1 -2
|
@@ -56,13 +56,16 @@ function validateIndexValue(index, name) {
|
|
|
56
56
|
* @param {BitSet} mask
|
|
57
57
|
* @returns {boolean} true if mask matches completely, false otherwise
|
|
58
58
|
*/
|
|
59
|
-
function matchComponentMask(
|
|
59
|
+
function matchComponentMask(
|
|
60
|
+
componentOccupancy,
|
|
61
|
+
entityIndex,
|
|
62
|
+
componentTypeCount,
|
|
63
|
+
mask
|
|
64
|
+
) {
|
|
60
65
|
const offset = entityIndex * componentTypeCount;
|
|
61
66
|
|
|
62
|
-
let componentIndex;
|
|
63
|
-
|
|
64
67
|
for (
|
|
65
|
-
componentIndex = mask.nextSetBit(0);
|
|
68
|
+
let componentIndex = mask.nextSetBit(0);
|
|
66
69
|
componentIndex !== -1;
|
|
67
70
|
componentIndex = mask.nextSetBit(componentIndex + 1)
|
|
68
71
|
) {
|
|
@@ -11,9 +11,9 @@ import { deserializeBinaryNodeFromBinaryBuffer } from "../../../core/bvh2/serial
|
|
|
11
11
|
import { computeGeometryBoundingSphereMiniball } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
|
|
12
12
|
import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
|
|
13
13
|
import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
|
|
14
|
-
import { compose_matrix4_array } from "../../graphics/util/composeMatrix4.js";
|
|
15
14
|
import { aabb3_from_v3_array_transformed } from "../../../core/bvh2/aabb3/aabb3_from_v3_array_transformed.js";
|
|
16
15
|
import { ViewState } from "./ViewState.js";
|
|
16
|
+
import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
19
|
* @readonly
|
|
@@ -2,8 +2,8 @@ import { BitSet } from "../../../core/binary/BitSet.js";
|
|
|
2
2
|
import { InstancedMeshGroup } from "../../graphics/geometry/instancing/InstancedMeshGroup.js";
|
|
3
3
|
import { queryBinaryNode_FrustumIntersections_Data } from "../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
|
|
4
4
|
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
5
|
-
import { compose_matrix4_array } from "../../graphics/util/composeMatrix4.js";
|
|
6
5
|
import Vector3 from "../../../core/geom/Vector3.js";
|
|
6
|
+
import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
@@ -5,15 +5,19 @@ import {Transform} from "../transform/Transform";
|
|
|
5
5
|
export class EntityNode {
|
|
6
6
|
constructor(entity?: EntityBuilder)
|
|
7
7
|
|
|
8
|
-
parent: EntityNode | null
|
|
9
|
-
entity: EntityBuilder
|
|
8
|
+
readonly parent: EntityNode | null
|
|
9
|
+
readonly entity: EntityBuilder
|
|
10
10
|
|
|
11
|
-
transform: Transform
|
|
11
|
+
readonly transform: Transform
|
|
12
|
+
|
|
13
|
+
readonly children: Readonly<EntityNode[]>
|
|
12
14
|
|
|
13
15
|
addChild(node: EntityNode): boolean
|
|
14
16
|
|
|
15
17
|
removeChild(node: EntityNode): boolean
|
|
16
18
|
|
|
19
|
+
traverseChildren(visitor: (EntityNode) => void, thisArg?: any): void
|
|
20
|
+
|
|
17
21
|
build(ecd: EntityComponentDataset): void
|
|
18
22
|
|
|
19
23
|
destroy(): void
|
|
@@ -41,6 +41,23 @@ export class EntityNode {
|
|
|
41
41
|
this.__transform = new Transform();
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {(EntityNode) => *} visitor
|
|
47
|
+
* @param {*} [context]
|
|
48
|
+
*/
|
|
49
|
+
traverseChildren(visitor, context) {
|
|
50
|
+
this.__children.forEach(visitor, context);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @return {Readonly<EntityNode[]>}
|
|
56
|
+
*/
|
|
57
|
+
get children() {
|
|
58
|
+
return this.__children;
|
|
59
|
+
}
|
|
60
|
+
|
|
44
61
|
/**
|
|
45
62
|
*
|
|
46
63
|
* @private
|
|
@@ -162,6 +179,10 @@ export class EntityNode {
|
|
|
162
179
|
}
|
|
163
180
|
}
|
|
164
181
|
|
|
182
|
+
/**
|
|
183
|
+
*
|
|
184
|
+
* @return {EntityBuilder}
|
|
185
|
+
*/
|
|
165
186
|
get entity() {
|
|
166
187
|
return this.__entity;
|
|
167
188
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ShadedGeometry } from "../../graphics/ecs/mesh-v2/ShadedGeometry.js";
|
|
2
|
+
import { AABB3 } from "../../../core/bvh2/aabb3/AABB3.js";
|
|
3
|
+
|
|
4
|
+
const scratch_aabb3 = new AABB3();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* @param {AABB3} out
|
|
9
|
+
* @param {EntityNode} root
|
|
10
|
+
*/
|
|
11
|
+
export function entity_node_expand_bounding_box_to_fit(out, root) {
|
|
12
|
+
const sg = root.entity.getComponent(ShadedGeometry);
|
|
13
|
+
|
|
14
|
+
if (sg !== null) {
|
|
15
|
+
sg.getBoundingBox(scratch_aabb3);
|
|
16
|
+
|
|
17
|
+
out.expandToFit(scratch_aabb3);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const children = root.children;
|
|
21
|
+
const child_count = children.length;
|
|
22
|
+
|
|
23
|
+
for (let i = 0; i < child_count; i++) {
|
|
24
|
+
const child = children[i];
|
|
25
|
+
|
|
26
|
+
entity_node_expand_bounding_box_to_fit(out, child);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
*
|
|
32
|
+
* @param {AABB3} out
|
|
33
|
+
* @param {EntityNode} root
|
|
34
|
+
*/
|
|
35
|
+
export function entity_node_compute_bounding_box(out, root) {
|
|
36
|
+
// init bounds
|
|
37
|
+
out.setNegativelyInfiniteBounds();
|
|
38
|
+
|
|
39
|
+
// expand bounds to fit the tree
|
|
40
|
+
entity_node_expand_bounding_box_to_fit(out, root);
|
|
41
|
+
}
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
|
|
5
5
|
import Vector3 from "../../../core/geom/Vector3.js";
|
|
6
6
|
import Quaternion from "../../../core/geom/Quaternion.js";
|
|
7
|
-
import {
|
|
8
|
-
import { decompose_matrix_4_array } from "../../graphics/util/decompose_matrix_4_array.js";
|
|
7
|
+
import { decompose_matrix_4_array } from "../../../core/geom/3d/decompose_matrix_4_array.js";
|
|
9
8
|
import { mat4 } from "gl-matrix";
|
|
9
|
+
import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
|
|
10
10
|
|
|
11
11
|
const delta = new Vector3();
|
|
12
12
|
|
|
@@ -3,4 +3,14 @@ import {Color} from "../../../../core/color/Color";
|
|
|
3
3
|
export class HighlightDefinition {
|
|
4
4
|
color: Color
|
|
5
5
|
opacity: number
|
|
6
|
+
|
|
7
|
+
static rgba(r: number, g: number, b: number, a?: number): HighlightDefinition
|
|
8
|
+
|
|
9
|
+
equals(other: HighlightDefinition): boolean
|
|
10
|
+
|
|
11
|
+
hash(): number
|
|
12
|
+
|
|
13
|
+
fromJSON(json: any): void
|
|
14
|
+
|
|
15
|
+
toJSON(): any
|
|
6
16
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Color } from "../../../../core/color/Color.js";
|
|
2
2
|
import { assert } from "../../../../core/assert.js";
|
|
3
|
-
import { COMPONENT_SERIALIZATION_TRANSIENT_FIELD } from "../../../ecs/storage/COMPONENT_SERIALIZATION_TRANSIENT_FIELD.js";
|
|
4
3
|
import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
|
|
5
4
|
import { computeHashFloat } from "../../../../core/math/hash/computeHashFloat.js";
|
|
6
5
|
|
|
@@ -8,7 +7,7 @@ export class HighlightDefinition {
|
|
|
8
7
|
constructor() {
|
|
9
8
|
|
|
10
9
|
/**
|
|
11
|
-
*
|
|
10
|
+
* @readonly
|
|
12
11
|
* @type {Color}
|
|
13
12
|
*/
|
|
14
13
|
this.color = new Color();
|
|
@@ -18,12 +17,6 @@ export class HighlightDefinition {
|
|
|
18
17
|
* @type {number}
|
|
19
18
|
*/
|
|
20
19
|
this.opacity = 1;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @type {boolean}
|
|
25
|
-
*/
|
|
26
|
-
this[COMPONENT_SERIALIZATION_TRANSIENT_FIELD] = false;
|
|
27
20
|
}
|
|
28
21
|
|
|
29
22
|
/**
|
|
@@ -73,4 +66,21 @@ export class HighlightDefinition {
|
|
|
73
66
|
|
|
74
67
|
return r;
|
|
75
68
|
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
*
|
|
72
|
+
* @param {number} r
|
|
73
|
+
* @param {number} g
|
|
74
|
+
* @param {number} b
|
|
75
|
+
* @param {number} [a]
|
|
76
|
+
* @return {HighlightDefinition}
|
|
77
|
+
*/
|
|
78
|
+
static rgba(r, g, b, a = 1) {
|
|
79
|
+
const result = new HighlightDefinition();
|
|
80
|
+
|
|
81
|
+
result.color.setRGB(r, g, b);
|
|
82
|
+
result.opacity = a;
|
|
83
|
+
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
76
86
|
}
|
|
@@ -5,8 +5,13 @@ export class ShadedGeometry {
|
|
|
5
5
|
readonly geometry: BufferGeometry
|
|
6
6
|
readonly material: Material
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated
|
|
10
|
+
*/
|
|
8
11
|
readonly bvh: Readonly<AABB3>
|
|
9
12
|
|
|
13
|
+
getBoundingBox(destination: AABB3): void
|
|
14
|
+
|
|
10
15
|
from(geometry: BufferGeometry, material: Material): void
|
|
11
16
|
|
|
12
17
|
static from(geometry: BufferGeometry, material: Material): ShadedGeometry
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { updateNodeByMatrix4AndBBB } from "../mesh/updateNodeByTransformAndBBB.js";
|
|
2
1
|
import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
|
|
3
2
|
import { AABB3 } from "../../../../core/bvh2/aabb3/AABB3.js";
|
|
4
3
|
import { DrawMode } from "./DrawMode.js";
|
|
5
4
|
import { ShadedGeometryFlags } from "./ShadedGeometryFlags.js";
|
|
5
|
+
import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
|
|
6
6
|
|
|
7
7
|
const _aabb3 = new AABB3();
|
|
8
8
|
|
|
9
|
+
const scratch_aabb3_array = new Float32Array(6);
|
|
10
|
+
|
|
9
11
|
const DEFAULT_FLAGS = ShadedGeometryFlags.CastShadow
|
|
10
12
|
| ShadedGeometryFlags.ReceiveShadow
|
|
11
13
|
;
|
|
@@ -36,6 +38,15 @@ export class ShadedGeometry {
|
|
|
36
38
|
*/
|
|
37
39
|
this.__bvh_leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
|
|
38
40
|
|
|
41
|
+
this.__bvh_leaf_id = -1;
|
|
42
|
+
/**
|
|
43
|
+
*
|
|
44
|
+
* @type {ExplicitBinaryBoundingVolumeHierarchy|null}
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
this.__bvh_tree = null;
|
|
48
|
+
this.__bvh_aabb = new Float32Array(6);
|
|
49
|
+
|
|
39
50
|
/**
|
|
40
51
|
* Transient, assigned in the system
|
|
41
52
|
* @type {number}
|
|
@@ -75,7 +86,7 @@ export class ShadedGeometry {
|
|
|
75
86
|
* @deprecated
|
|
76
87
|
* @private
|
|
77
88
|
*/
|
|
78
|
-
get __cached_object(){
|
|
89
|
+
get __cached_object() {
|
|
79
90
|
throw new Error('Deprecated');
|
|
80
91
|
}
|
|
81
92
|
|
|
@@ -155,10 +166,22 @@ export class ShadedGeometry {
|
|
|
155
166
|
return this.__transform;
|
|
156
167
|
}
|
|
157
168
|
|
|
169
|
+
/**
|
|
170
|
+
* @deprecated
|
|
171
|
+
* @returns {LeafNode<ShadedGeometry>}
|
|
172
|
+
*/
|
|
158
173
|
get bvh() {
|
|
159
174
|
return this.__bvh_leaf;
|
|
160
175
|
}
|
|
161
176
|
|
|
177
|
+
/**
|
|
178
|
+
*
|
|
179
|
+
* @param {AABB3} destination
|
|
180
|
+
*/
|
|
181
|
+
getBoundingBox(destination) {
|
|
182
|
+
destination.copy(this.__bvh_leaf);
|
|
183
|
+
}
|
|
184
|
+
|
|
162
185
|
/**
|
|
163
186
|
*
|
|
164
187
|
* @param {THREE.BufferGeometry} geometry
|
|
@@ -195,22 +218,33 @@ export class ShadedGeometry {
|
|
|
195
218
|
//
|
|
196
219
|
this.__c_transform.toMatrix4(this.__transform);
|
|
197
220
|
|
|
221
|
+
this.update_bounds();
|
|
222
|
+
|
|
223
|
+
this.__bvh_tree.node_move_aabb(this.__bvh_leaf_id, this.__bvh_aabb);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
update_bounds() {
|
|
198
227
|
// update bounds
|
|
199
228
|
const gbb = this.geometry.boundingBox;
|
|
200
229
|
|
|
201
230
|
const min = gbb.min;
|
|
202
231
|
const max = gbb.max;
|
|
203
232
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
233
|
+
const x0 = min.x;
|
|
234
|
+
const y0 = min.y;
|
|
235
|
+
const z0 = min.z;
|
|
236
|
+
const x1 = max.x;
|
|
237
|
+
const y1 = max.y;
|
|
238
|
+
const z1 = max.z;
|
|
239
|
+
|
|
240
|
+
scratch_aabb3_array[0] = x0;
|
|
241
|
+
scratch_aabb3_array[1] = y0;
|
|
242
|
+
scratch_aabb3_array[2] = z0;
|
|
243
|
+
scratch_aabb3_array[3] = x1;
|
|
244
|
+
scratch_aabb3_array[4] = y1;
|
|
245
|
+
scratch_aabb3_array[5] = z1;
|
|
246
|
+
|
|
247
|
+
aabb3_matrix4_project(this.__bvh_aabb, scratch_aabb3_array, this.__transform);
|
|
214
248
|
}
|
|
215
249
|
}
|
|
216
250
|
|
|
@@ -6,24 +6,14 @@ import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
|
|
|
6
6
|
import { v3_distance_sqr } from "../../../../core/geom/v3_distance_sqr.js";
|
|
7
7
|
import { mat4 } from "gl-matrix";
|
|
8
8
|
import { returnTrue } from "../../../../core/function/Functions.js";
|
|
9
|
-
import { aabb3_intersects_ray } from "../../../../core/bvh2/aabb3/aabb3_intersects_ray.js";
|
|
10
9
|
import { ShadedGeometryRendererContext } from "./render/ShadedGeometryRendererContext.js";
|
|
11
|
-
import { BinaryNode } from "../../../../core/bvh2/BinaryNode.js";
|
|
12
10
|
import { assert } from "../../../../core/assert.js";
|
|
13
11
|
import { ray3_array_compose } from "../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
14
12
|
import { ray3_array_apply_matrix4 } from "../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
13
|
+
import { ExplicitBinaryBoundingVolumeHierarchy } from "../../../../core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
14
|
+
import { bvh_query_leaves_generic } from "../../../../core/bvh2/bvh3/bvh_query_leaves_generic.js";
|
|
15
|
+
import { BVHQueryIntersectsRay } from "../../../../core/bvh2/bvh3/query/BVHQueryIntersectsRay.js";
|
|
15
16
|
|
|
16
|
-
/**
|
|
17
|
-
*
|
|
18
|
-
* @type {BinaryNode|LeafNode[]}
|
|
19
|
-
*/
|
|
20
|
-
const traversal_stack = [];
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
* @type {number}
|
|
25
|
-
*/
|
|
26
|
-
let traversal_cursor = 0;
|
|
27
17
|
|
|
28
18
|
/**
|
|
29
19
|
*
|
|
@@ -38,7 +28,6 @@ const scratch_point = new SurfacePoint3();
|
|
|
38
28
|
const scratch_m4 = new Float32Array(16);
|
|
39
29
|
|
|
40
30
|
const scratch_ray_0 = new Float32Array(6);
|
|
41
|
-
const scratch_ray_1 = new Float32Array(6);
|
|
42
31
|
|
|
43
32
|
export class ShadedGeometrySystem extends System {
|
|
44
33
|
/**
|
|
@@ -70,9 +59,6 @@ export class ShadedGeometrySystem extends System {
|
|
|
70
59
|
*/
|
|
71
60
|
this.__view_contexts = new Map();
|
|
72
61
|
|
|
73
|
-
this.__bvh = new BinaryNode();
|
|
74
|
-
this.__bvh.setNegativelyInfiniteBounds();
|
|
75
|
-
|
|
76
62
|
/**
|
|
77
63
|
*
|
|
78
64
|
* @type {Map<number, function():AbstractRenderAdapter>}
|
|
@@ -86,6 +72,13 @@ export class ShadedGeometrySystem extends System {
|
|
|
86
72
|
* @private
|
|
87
73
|
*/
|
|
88
74
|
this.__geometry_usage_counters = new Map();
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
*
|
|
78
|
+
* @type {ExplicitBinaryBoundingVolumeHierarchy}
|
|
79
|
+
* @private
|
|
80
|
+
*/
|
|
81
|
+
this.__bvh_binary = new ExplicitBinaryBoundingVolumeHierarchy();
|
|
89
82
|
}
|
|
90
83
|
|
|
91
84
|
/**
|
|
@@ -178,7 +171,13 @@ export class ShadedGeometrySystem extends System {
|
|
|
178
171
|
this.__render_layer.buildVisibleSet = ((destination, destination_offset, view) => {
|
|
179
172
|
const ctx = this.__view_contexts.get(view);
|
|
180
173
|
|
|
181
|
-
|
|
174
|
+
const ecd = entityManager.dataset;
|
|
175
|
+
|
|
176
|
+
if (ecd === null) {
|
|
177
|
+
return 0;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return ctx.collect(destination, destination_offset, graphics.renderer, view, this.__bvh_binary, ecd);
|
|
182
181
|
});
|
|
183
182
|
|
|
184
183
|
readyCallback();
|
|
@@ -211,7 +210,8 @@ export class ShadedGeometrySystem extends System {
|
|
|
211
210
|
t.rotation.onChanged.add(sg.updateTransform, sg);
|
|
212
211
|
t.scale.onChanged.add(sg.updateTransform, sg);
|
|
213
212
|
|
|
214
|
-
sg.
|
|
213
|
+
t.toMatrix4(sg.__transform);
|
|
214
|
+
sg.update_bounds();
|
|
215
215
|
|
|
216
216
|
const leaf_node = sg.bvh;
|
|
217
217
|
|
|
@@ -221,7 +221,15 @@ export class ShadedGeometrySystem extends System {
|
|
|
221
221
|
// remember entity for lookups
|
|
222
222
|
sg.__entity = entity;
|
|
223
223
|
|
|
224
|
-
|
|
224
|
+
// insert BVH entry
|
|
225
|
+
const bvh_node_id = this.__bvh_binary.allocate_node();
|
|
226
|
+
this.__bvh_binary.node_set_aabb(bvh_node_id, sg.__bvh_aabb);
|
|
227
|
+
this.__bvh_binary.insert_leaf(bvh_node_id);
|
|
228
|
+
this.__bvh_binary.node_set_user_data(bvh_node_id, entity);
|
|
229
|
+
|
|
230
|
+
sg.__bvh_tree = this.__bvh_binary;
|
|
231
|
+
sg.__bvh_leaf_id = bvh_node_id;
|
|
232
|
+
|
|
225
233
|
|
|
226
234
|
// update usage count
|
|
227
235
|
const geometry_id = sg.geometry.id;
|
|
@@ -242,7 +250,10 @@ export class ShadedGeometrySystem extends System {
|
|
|
242
250
|
t.rotation.onChanged.remove(sg.updateTransform, sg);
|
|
243
251
|
t.scale.onChanged.remove(sg.updateTransform, sg);
|
|
244
252
|
|
|
245
|
-
|
|
253
|
+
// disconnect BVH
|
|
254
|
+
const node_id = sg.__bvh_leaf_id;
|
|
255
|
+
this.__bvh_binary.remove_leaf(node_id);
|
|
256
|
+
this.__bvh_binary.release_node(node_id);
|
|
246
257
|
|
|
247
258
|
const geometry_id = sg.geometry.id;
|
|
248
259
|
const count_existing = this.__geometry_usage_counters.get(geometry_id);
|
|
@@ -279,107 +290,82 @@ export class ShadedGeometrySystem extends System {
|
|
|
279
290
|
direction_x, direction_y, direction_z,
|
|
280
291
|
filter_function = returnTrue, filter_function_context
|
|
281
292
|
) {
|
|
282
|
-
const root_bvh = this.__bvh;
|
|
283
|
-
const stack_frame_address = traversal_cursor;
|
|
284
|
-
|
|
285
|
-
traversal_stack[traversal_cursor++] = root_bvh;
|
|
286
293
|
|
|
287
294
|
let best_distance = Infinity;
|
|
288
295
|
let found_hit = false;
|
|
289
296
|
let best_result = null;
|
|
290
297
|
|
|
291
|
-
|
|
292
|
-
traversal_cursor--;
|
|
298
|
+
const hits = [];
|
|
293
299
|
|
|
294
|
-
|
|
295
|
-
*
|
|
296
|
-
* @type {BinaryNode|LeafNode<ShadedGeometry>}
|
|
297
|
-
*/
|
|
298
|
-
const node = traversal_stack[traversal_cursor];
|
|
300
|
+
const hit_count = bvh_query_leaves_generic(hits, 0, this.__bvh_binary, BVHQueryIntersectsRay.from([origin_x, origin_y, origin_z, direction_x, direction_y, direction_z]));
|
|
299
301
|
|
|
300
|
-
|
|
301
|
-
const intersects = aabb3_intersects_ray(
|
|
302
|
-
node.x0, node.y0, node.z0,
|
|
303
|
-
node.x1, node.y1, node.z1,
|
|
304
|
-
origin_x, origin_y, origin_z,
|
|
305
|
-
direction_x, direction_y, direction_z
|
|
306
|
-
);
|
|
302
|
+
const ecd = this.entityManager.dataset;
|
|
307
303
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
304
|
+
if (ecd === null) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
311
307
|
|
|
312
|
-
|
|
313
|
-
if (node.right !== null) {
|
|
314
|
-
traversal_stack[traversal_cursor++] = node.right;
|
|
315
|
-
}
|
|
316
|
-
if (node.left !== null) {
|
|
317
|
-
traversal_stack[traversal_cursor++] = node.left;
|
|
318
|
-
}
|
|
319
|
-
} else {
|
|
320
|
-
// leaf node
|
|
308
|
+
const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
|
|
321
309
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
* @type {ShadedGeometry}
|
|
325
|
-
*/
|
|
326
|
-
const sg = node.object;
|
|
310
|
+
for (let i = 0; i < hit_count; i++) {
|
|
311
|
+
const node_id = hits[i];
|
|
327
312
|
|
|
328
|
-
|
|
313
|
+
const entity = this.__bvh_binary.node_get_user_data(node_id);
|
|
329
314
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
315
|
+
/**
|
|
316
|
+
*
|
|
317
|
+
* @type {ShadedGeometry}
|
|
318
|
+
*/
|
|
319
|
+
const sg = ecd.getComponentByIndex(entity, sg_component_index);
|
|
334
320
|
|
|
335
|
-
|
|
321
|
+
if (!filter_function.call(filter_function_context, entity, sg)) {
|
|
322
|
+
// filtered out
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
336
325
|
|
|
337
|
-
|
|
338
|
-
mat4.invert(scratch_m4, m4);
|
|
326
|
+
const m4 = sg.transform;
|
|
339
327
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
origin_x, origin_y, origin_z,
|
|
343
|
-
direction_x, direction_y, direction_z
|
|
344
|
-
);
|
|
328
|
+
// get transform in local space
|
|
329
|
+
mat4.invert(scratch_m4, m4);
|
|
345
330
|
|
|
346
|
-
|
|
347
|
-
|
|
331
|
+
ray3_array_compose(
|
|
332
|
+
scratch_ray_0,
|
|
333
|
+
origin_x, origin_y, origin_z,
|
|
334
|
+
direction_x, direction_y, direction_z
|
|
335
|
+
);
|
|
348
336
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
sg.geometry,
|
|
352
|
-
scratch_ray_0
|
|
353
|
-
);
|
|
337
|
+
// transform ray to local space
|
|
338
|
+
ray3_array_apply_matrix4(scratch_ray_0, scratch_ray_0, scratch_m4);
|
|
354
339
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
340
|
+
const geometry_hit_found = GeometrySpatialQueryAccelerator.INSTANCE.queryRaycastNearest_array(
|
|
341
|
+
scratch_point,
|
|
342
|
+
sg.geometry,
|
|
343
|
+
scratch_ray_0
|
|
344
|
+
);
|
|
358
345
|
|
|
359
|
-
|
|
360
|
-
|
|
346
|
+
if (!geometry_hit_found) {
|
|
347
|
+
continue;
|
|
348
|
+
}
|
|
361
349
|
|
|
362
|
-
|
|
350
|
+
// transform hit contact into global space
|
|
351
|
+
scratch_point.applyMatrix4(m4);
|
|
363
352
|
|
|
364
|
-
|
|
353
|
+
found_hit = true;
|
|
365
354
|
|
|
366
|
-
|
|
367
|
-
hit_position.x, hit_position.y, hit_position.z,
|
|
368
|
-
origin_x, origin_y, origin_z
|
|
369
|
-
);
|
|
355
|
+
const hit_position = scratch_point.position;
|
|
370
356
|
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
}
|
|
357
|
+
const distance_sqr = v3_distance_sqr(
|
|
358
|
+
hit_position.x, hit_position.y, hit_position.z,
|
|
359
|
+
origin_x, origin_y, origin_z
|
|
360
|
+
);
|
|
376
361
|
|
|
362
|
+
if (distance_sqr < best_distance) {
|
|
363
|
+
contact.copy(scratch_point);
|
|
364
|
+
best_result = sg;
|
|
365
|
+
best_distance = distance_sqr;
|
|
377
366
|
}
|
|
378
367
|
}
|
|
379
368
|
|
|
380
|
-
// drop stack frame
|
|
381
|
-
traversal_cursor = stack_frame_address;
|
|
382
|
-
|
|
383
369
|
if (found_hit) {
|
|
384
370
|
return {
|
|
385
371
|
entity: best_result.__entity,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { queryBinaryNode_FrustumIntersections_Data } from "../../../../../core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js";
|
|
2
1
|
import { AbstractRenderAdapter } from "./adapters/AbstractRenderAdapter.js";
|
|
3
2
|
import { InstancedRendererAdapter } from "./adapters/InstancedRendererAdapter.js";
|
|
4
3
|
import { GenericRendererAdapter } from "./adapters/GenericRendererAdapter.js";
|
|
5
4
|
import { assert } from "../../../../../core/assert.js";
|
|
5
|
+
import { bvh_query_leaves_generic } from "../../../../../core/bvh2/bvh3/bvh_query_leaves_generic.js";
|
|
6
|
+
import { BVHQueryIntersectsFrustum } from "../../../../../core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js";
|
|
7
|
+
import { ShadedGeometry } from "../ShadedGeometry.js";
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* 1 - collect visible meshes
|
|
@@ -66,9 +68,10 @@ export class ShadedGeometryRendererContext {
|
|
|
66
68
|
* @param {number} destination_offset
|
|
67
69
|
* @param {THREE.WebGLRenderer} renderer
|
|
68
70
|
* @param {CameraView} view
|
|
69
|
-
* @param {
|
|
71
|
+
* @param {ExplicitBinaryBoundingVolumeHierarchy} bvh
|
|
72
|
+
* @param {EntityComponentDataset} ecd
|
|
70
73
|
*/
|
|
71
|
-
collect(destination, destination_offset, renderer, view, bvh) {
|
|
74
|
+
collect(destination, destination_offset, renderer, view, bvh, ecd) {
|
|
72
75
|
const adapters = this.adapters;
|
|
73
76
|
const adapter_count = adapters.length;
|
|
74
77
|
|
|
@@ -84,14 +87,22 @@ export class ShadedGeometryRendererContext {
|
|
|
84
87
|
|
|
85
88
|
const data = [];
|
|
86
89
|
|
|
87
|
-
const
|
|
90
|
+
const query = BVHQueryIntersectsFrustum.from(view.frustum);
|
|
91
|
+
|
|
92
|
+
const intersection_count = bvh_query_leaves_generic(data, 0, bvh, query);
|
|
93
|
+
|
|
94
|
+
const sg_component_index = ecd.computeComponentTypeIndex(ShadedGeometry);
|
|
88
95
|
|
|
89
96
|
for (i = 0; i < intersection_count; i++) {
|
|
97
|
+
const node_index = data[i];
|
|
98
|
+
|
|
99
|
+
const entity = bvh.node_get_user_data(node_index);
|
|
100
|
+
|
|
90
101
|
/**
|
|
91
102
|
*
|
|
92
103
|
* @type {ShadedGeometry}
|
|
93
104
|
*/
|
|
94
|
-
const sg =
|
|
105
|
+
const sg = ecd.getComponentByIndex(entity, sg_component_index);
|
|
95
106
|
|
|
96
107
|
const adapter = adapters[sg.draw_method];
|
|
97
108
|
|
|
@@ -3,6 +3,7 @@ import { HashMap } from "../../../../../../core/collection/HashMap.js";
|
|
|
3
3
|
import { InstancedMeshGroup } from "../../../../geometry/instancing/InstancedMeshGroup.js";
|
|
4
4
|
import { ShadedGeometryFlags } from "../../ShadedGeometryFlags.js";
|
|
5
5
|
import { DrawMode } from "../../DrawMode.js";
|
|
6
|
+
import { StreamDrawUsage } from "three";
|
|
6
7
|
|
|
7
8
|
const INSTANCED_EQUALITY_FLAGS = ShadedGeometryFlags.CastShadow
|
|
8
9
|
| ShadedGeometryFlags.ReceiveShadow
|
|
@@ -89,6 +90,7 @@ export class InstancedRendererAdapter extends AbstractRenderAdapter {
|
|
|
89
90
|
}
|
|
90
91
|
|
|
91
92
|
im = new InstancedMeshGroup();
|
|
93
|
+
im.instance_usage = StreamDrawUsage;
|
|
92
94
|
im.shrinkFactor = 0; // prevent shrinking as we're essentially rebuilding this geometry frame
|
|
93
95
|
|
|
94
96
|
im.setMaterial(sg.material);
|