@woosh/meep-engine 2.67.0 → 2.69.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/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +698 -1270
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +698 -1270
- package/package.json +1 -1
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +55 -28
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +3 -3
- package/src/core/bvh2/binary/2/bvh32_query_user_data_overlaps_clipping_volume.js +94 -0
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +17 -18
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +4 -2
- package/src/core/geom/3d/aabb/AABB3.js +14 -14
- package/src/core/geom/3d/aabb/aabb3_array_intersects_clipping_volume_array.js +30 -0
- package/src/core/geom/3d/aabb/aabb3_intersects_clipping_volume_array.js +51 -0
- package/src/core/geom/3d/frustum/{read_frustum_planes_to_array.js → read_three_planes_to_array.js} +5 -3
- package/src/core/geom/3d/triangle/triangle_intersects_clipping_volume.js +51 -0
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +9 -46
- package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts +2 -2
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +79 -36
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.js +88 -0
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +108 -0
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +4 -30
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_unindexed_geometry.js +30 -0
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +41 -0
- package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
- package/src/engine/graphics/render/view/CameraView.js +8 -8
- package/src/core/bvh2/BVHTasks.js +0 -65
- package/src/core/bvh2/BinaryNode.d.ts +0 -13
- package/src/core/bvh2/BinaryNode.js +0 -1188
- package/src/core/bvh2/BinaryNode.spec.js +0 -309
- package/src/core/bvh2/LeafNode.d.ts +0 -7
- package/src/core/bvh2/LeafNode.js +0 -147
- package/src/core/bvh2/Node.d.ts +0 -9
- package/src/core/bvh2/Node.js +0 -196
- package/src/core/bvh2/NodeValidator.js +0 -197
- package/src/core/bvh2/StacklessTraverser.js +0 -154
- package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
- package/src/core/bvh2/binary/BinaryBVH.js +0 -281
- package/src/core/bvh2/binary/IndexedBinaryBVH.js +0 -407
- package/src/core/bvh2/binary/IndexedBinaryBVH.spec.js +0 -27
- package/src/core/bvh2/binary/IndexedBinaryBVHVisitor.js +0 -11
- package/src/core/bvh2/binary/NodeType.js +0 -8
- package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +0 -59
- package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
- package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
- package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
- package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
- package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
- package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
- package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
- package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
- package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
- package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
- package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
- package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
- package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
- package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
- package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
- package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
- package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
- package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
- package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
- package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
- package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
- package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
- package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
- package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
- package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
- package/src/core/geom/2d/bvh/Node2.js +0 -51
- package/src/core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js +0 -20
- package/src/core/geom/3d/aabb/aabb3_intersects_frustum_array.js +0 -35
- package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
- package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +0 -195
- package/src/engine/graphics/geometry/buffered/query/GeometryVisitor.js +0 -87
- package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +0 -206
- package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
- package/src/engine/graphics/geometry/bvh/buffered/BinaryBVHFromBufferGeometry.js +0 -123
- package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +0 -133
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { mat4 } from "gl-matrix";
|
|
2
|
-
|
|
3
|
-
import { Vector3 as ThreeVector3 } from 'three';
|
|
4
|
-
import { assert } from "../../../../../core/assert.js";
|
|
5
|
-
import { array_copy } from "../../../../../core/collection/array/array_copy.js";
|
|
6
|
-
import { MATRIX_4_IDENTITY } from "../../../../../core/geom/3d/matrix/MATRIX_4_IDENTITY.js";
|
|
7
|
-
import { ray3_array_apply_matrix4 } from "../../../../../core/geom/3d/ray/ray3_array_apply_matrix4.js";
|
|
8
|
-
import { ray3_array_compose } from "../../../../../core/geom/3d/ray/ray3_array_compose.js";
|
|
9
|
-
import { SurfacePoint3 } from "../../../../../core/geom/3d/SurfacePoint3.js";
|
|
10
|
-
import { rayTriangleIntersection } from "../../../../../core/geom/3d/triangle/rayTriangleIntersection.js";
|
|
11
|
-
import { v3_length } from "../../../../../core/geom/vec3/v3_length.js";
|
|
12
|
-
import Vector3 from "../../../../../core/geom/Vector3.js";
|
|
13
|
-
|
|
14
|
-
const hit = new ThreeVector3();
|
|
15
|
-
|
|
16
|
-
const vA = new ThreeVector3(),
|
|
17
|
-
vB = new ThreeVector3(),
|
|
18
|
-
vC = new ThreeVector3();
|
|
19
|
-
|
|
20
|
-
const ray_tmp = [];
|
|
21
|
-
const m4_tmp = [];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
*
|
|
25
|
-
* @param {number[]|Uint8Array|Uint16Array|Uint32Array} indices
|
|
26
|
-
* @param {number[]|Float32Array|Float64Array} vertices
|
|
27
|
-
* @param {number} index
|
|
28
|
-
*/
|
|
29
|
-
function bindGeometryFace(indices, vertices, index) {
|
|
30
|
-
const index3 = index * 3;
|
|
31
|
-
|
|
32
|
-
assert.lessThan(index3, indices.length, 'index underflow');
|
|
33
|
-
|
|
34
|
-
const a = indices[index3] * 3;
|
|
35
|
-
const b = indices[index3 + 1] * 3;
|
|
36
|
-
const c = indices[index3 + 2] * 3;
|
|
37
|
-
|
|
38
|
-
vA.set(vertices[a], vertices[a + 1], vertices[a + 2]);
|
|
39
|
-
vB.set(vertices[b], vertices[b + 1], vertices[b + 2]);
|
|
40
|
-
vC.set(vertices[c], vertices[c + 1], vertices[c + 2]);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const vNormal = new Vector3();
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
* @param {number[]} indices
|
|
48
|
-
* @param {number[]} normals
|
|
49
|
-
* @param {number} index
|
|
50
|
-
*/
|
|
51
|
-
function bindGeometryFaceNormal(indices, normals, index) {
|
|
52
|
-
|
|
53
|
-
const index3 = index * 3;
|
|
54
|
-
|
|
55
|
-
const a = indices[index3] * 3;
|
|
56
|
-
const b = indices[index3 + 1] * 3;
|
|
57
|
-
const c = indices[index3 + 2] * 3;
|
|
58
|
-
|
|
59
|
-
//read vertex normals
|
|
60
|
-
const naX = normals[a];
|
|
61
|
-
const naY = normals[a + 1];
|
|
62
|
-
const naZ = normals[a + 2];
|
|
63
|
-
|
|
64
|
-
const nbX = normals[b];
|
|
65
|
-
const nbY = normals[b + 1];
|
|
66
|
-
const nbZ = normals[b + 2];
|
|
67
|
-
|
|
68
|
-
const ncX = normals[c];
|
|
69
|
-
const ncY = normals[c + 1];
|
|
70
|
-
const ncZ = normals[c + 2];
|
|
71
|
-
|
|
72
|
-
//add normals
|
|
73
|
-
const nsX = (naX + nbX + ncX);
|
|
74
|
-
const nsY = (naY + nbY + ncY);
|
|
75
|
-
const nsZ = (naZ + nbZ + ncZ);
|
|
76
|
-
|
|
77
|
-
//normalize
|
|
78
|
-
const l = v3_length(nsX, nsY, nsZ);
|
|
79
|
-
const m = 1 / l;
|
|
80
|
-
|
|
81
|
-
const nx = nsX * m;
|
|
82
|
-
const ny = nsY * m;
|
|
83
|
-
const nz = nsZ * m;
|
|
84
|
-
|
|
85
|
-
vNormal.set(nx, ny, nz);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
function extractFaceIndexFromLeaf_default(leaf) {
|
|
90
|
-
return leaf.object;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export class BVHGeometryRaycaster {
|
|
94
|
-
constructor() {
|
|
95
|
-
/**
|
|
96
|
-
*
|
|
97
|
-
* @type {BufferGeometry|null}
|
|
98
|
-
*/
|
|
99
|
-
this.geometry = null;
|
|
100
|
-
/**
|
|
101
|
-
*
|
|
102
|
-
* @type {BinaryNode|null}
|
|
103
|
-
*/
|
|
104
|
-
this.bvh = null;
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
*
|
|
108
|
-
* @type {Vector2|null}
|
|
109
|
-
*/
|
|
110
|
-
this.position = null;
|
|
111
|
-
/**
|
|
112
|
-
*
|
|
113
|
-
* @type {Vector2|null}
|
|
114
|
-
*/
|
|
115
|
-
this.scale = null;
|
|
116
|
-
/**
|
|
117
|
-
*
|
|
118
|
-
* @type {number}
|
|
119
|
-
*/
|
|
120
|
-
this.resolution = 0;
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
*
|
|
124
|
-
* @type {Vector2|null}
|
|
125
|
-
*/
|
|
126
|
-
this.size = null;
|
|
127
|
-
|
|
128
|
-
this.__bestDistance = 0;
|
|
129
|
-
this.__bestPosition = new Vector3();
|
|
130
|
-
this.__bestIndex = 0;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.origin = new Vector3();
|
|
134
|
-
this.direction = new Vector3();
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
*
|
|
138
|
-
* @type {Float32Array}
|
|
139
|
-
*/
|
|
140
|
-
this.transform = new Float32Array(16);
|
|
141
|
-
|
|
142
|
-
array_copy(MATRIX_4_IDENTITY, 0, this.transform, 0, 16);
|
|
143
|
-
|
|
144
|
-
this.extractFaceIndexFromLeaf = extractFaceIndexFromLeaf_default;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
* @param {*} leaf
|
|
150
|
-
*/
|
|
151
|
-
visitLeafIntersection(leaf) {
|
|
152
|
-
|
|
153
|
-
const geometry = this.geometry;
|
|
154
|
-
|
|
155
|
-
const geometryIndices = geometry.getIndex().array;
|
|
156
|
-
const geometryVertices = geometry.getAttribute('position').array;
|
|
157
|
-
|
|
158
|
-
const extractFaceIndexFromLeaf = this.extractFaceIndexFromLeaf;
|
|
159
|
-
|
|
160
|
-
const index = extractFaceIndexFromLeaf(leaf);
|
|
161
|
-
|
|
162
|
-
bindGeometryFace(geometryIndices, geometryVertices, index);
|
|
163
|
-
|
|
164
|
-
const hitFound = rayTriangleIntersection(hit, this.origin, this.direction, vA, vB, vC);
|
|
165
|
-
|
|
166
|
-
if (hitFound) {
|
|
167
|
-
|
|
168
|
-
const d = this.origin.distanceSqrTo(hit);
|
|
169
|
-
if (d < this.__bestDistance) {
|
|
170
|
-
this.__bestDistance = d;
|
|
171
|
-
this.__bestPosition.copy(hit);
|
|
172
|
-
this.__bestIndex = index;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
*
|
|
180
|
-
* @param {SurfacePoint3} hit
|
|
181
|
-
* @param {number} originX
|
|
182
|
-
* @param {number} originY
|
|
183
|
-
* @param {number} originZ
|
|
184
|
-
* @param {number} directionX
|
|
185
|
-
* @param {number} directionY
|
|
186
|
-
* @param {number} directionZ
|
|
187
|
-
* @returns {boolean}
|
|
188
|
-
*/
|
|
189
|
-
raycast(
|
|
190
|
-
hit,
|
|
191
|
-
originX, originY, originZ,
|
|
192
|
-
directionX, directionY, directionZ
|
|
193
|
-
) {
|
|
194
|
-
|
|
195
|
-
mat4.invert(m4_tmp, this.transform);
|
|
196
|
-
|
|
197
|
-
ray3_array_compose(
|
|
198
|
-
ray_tmp,
|
|
199
|
-
originX, originY, originZ,
|
|
200
|
-
directionX, directionY, directionZ
|
|
201
|
-
);
|
|
202
|
-
|
|
203
|
-
ray3_array_apply_matrix4(ray_tmp, 0,ray_tmp,0, m4_tmp);
|
|
204
|
-
|
|
205
|
-
const _originX = ray_tmp[0];
|
|
206
|
-
const _originY = ray_tmp[1];
|
|
207
|
-
const _originZ = ray_tmp[2];
|
|
208
|
-
|
|
209
|
-
const _directionX = ray_tmp[3];
|
|
210
|
-
const _directionY = ray_tmp[4];
|
|
211
|
-
const _directionZ = ray_tmp[5];
|
|
212
|
-
|
|
213
|
-
this.origin.set(_originX, _originY, _originZ);
|
|
214
|
-
this.direction.set(_directionX, _directionY, _directionZ);
|
|
215
|
-
|
|
216
|
-
this.__bestDistance = Number.POSITIVE_INFINITY;
|
|
217
|
-
|
|
218
|
-
this.bvh.traverseRayLeafIntersections(_originX, _originY, _originZ, _directionX, _directionY, _directionZ, this.visitLeafIntersection, this);
|
|
219
|
-
|
|
220
|
-
if (this.__bestDistance !== Number.POSITIVE_INFINITY) {
|
|
221
|
-
|
|
222
|
-
const geometry = this.geometry;
|
|
223
|
-
|
|
224
|
-
const geometryIndices = geometry.getIndex().array;
|
|
225
|
-
const geometryNormals = geometry.getAttribute('normal').array;
|
|
226
|
-
|
|
227
|
-
bindGeometryFaceNormal(geometryIndices, geometryNormals, this.__bestIndex);
|
|
228
|
-
|
|
229
|
-
hit.position.copy(this.__bestPosition);
|
|
230
|
-
hit.normal.copy(vNormal);
|
|
231
|
-
|
|
232
|
-
hit.applyMatrix4(this.transform);
|
|
233
|
-
|
|
234
|
-
return true;
|
|
235
|
-
} else {
|
|
236
|
-
//no hit
|
|
237
|
-
return false;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 29/05/2016.
|
|
3
|
-
*/
|
|
4
|
-
import IndexedBinaryBVH from '../../../../../core/bvh2/binary/IndexedBinaryBVH.js';
|
|
5
|
-
import { min3 } from "../../../../../core/math/min3.js";
|
|
6
|
-
import { max3 } from "../../../../../core/math/max3.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param {Float32Array|Float64Array|Array.<Number>} vertices
|
|
11
|
-
* @param {Uint8Array|Uint16Array|Uint32Array|Array.<Number>} indices
|
|
12
|
-
* @returns {IndexedBinaryBVH}
|
|
13
|
-
*/
|
|
14
|
-
function buildUnsorted(vertices, indices) {
|
|
15
|
-
//
|
|
16
|
-
const numNodes = indices.length / 3;
|
|
17
|
-
|
|
18
|
-
const tree = new IndexedBinaryBVH();
|
|
19
|
-
tree.initialize(numNodes);
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < numNodes; i++) {
|
|
22
|
-
|
|
23
|
-
const index3 = i * 3;
|
|
24
|
-
|
|
25
|
-
// read triangle vertex indices
|
|
26
|
-
const iA = indices[index3];
|
|
27
|
-
const iB = indices[index3 + 1];
|
|
28
|
-
const iC = indices[index3 + 2];
|
|
29
|
-
|
|
30
|
-
const a = iA * 3;
|
|
31
|
-
const b = iB * 3;
|
|
32
|
-
const c = iC * 3;
|
|
33
|
-
|
|
34
|
-
// read actual positions of each vertex
|
|
35
|
-
const aX = vertices[a];
|
|
36
|
-
const aY = vertices[a + 1];
|
|
37
|
-
const aZ = vertices[a + 2];
|
|
38
|
-
|
|
39
|
-
const bX = vertices[b];
|
|
40
|
-
const bY = vertices[b + 1];
|
|
41
|
-
const bZ = vertices[b + 2];
|
|
42
|
-
|
|
43
|
-
const cX = vertices[c];
|
|
44
|
-
const cY = vertices[c + 1];
|
|
45
|
-
const cZ = vertices[c + 2];
|
|
46
|
-
|
|
47
|
-
// compute bounds of the triangle
|
|
48
|
-
const x0 = min3(aX, bX, cX);
|
|
49
|
-
const y0 = min3(aY, bY, cY);
|
|
50
|
-
const z0 = min3(aZ, bZ, cZ);
|
|
51
|
-
|
|
52
|
-
const x1 = max3(aX, bX, cX);
|
|
53
|
-
const y1 = max3(aY, bY, cY);
|
|
54
|
-
const z1 = max3(aZ, bZ, cZ);
|
|
55
|
-
|
|
56
|
-
tree.writeLeaf(i, x0, y0, z0, x1, y1, z1);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// finalize build
|
|
60
|
-
tree.unsortedBuiltIntermediate();
|
|
61
|
-
|
|
62
|
-
return tree;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {Float32Array|Float64Array|Array.<Number>} vertices
|
|
68
|
-
* @returns {IndexedBinaryBVH}
|
|
69
|
-
*/
|
|
70
|
-
export function buildUnsortedUnindexed(vertices) {
|
|
71
|
-
//
|
|
72
|
-
const numNodes = vertices.length / 9;
|
|
73
|
-
|
|
74
|
-
const tree = new IndexedBinaryBVH();
|
|
75
|
-
tree.initialize(numNodes);
|
|
76
|
-
|
|
77
|
-
for (let i = 0; i < numNodes; i++) {
|
|
78
|
-
|
|
79
|
-
const index3 = i * 3;
|
|
80
|
-
|
|
81
|
-
// read triangle vertex indices
|
|
82
|
-
const iA = index3;
|
|
83
|
-
const iB = index3 + 1;
|
|
84
|
-
const iC = index3 + 2;
|
|
85
|
-
|
|
86
|
-
const a = iA * 3;
|
|
87
|
-
const b = iB * 3;
|
|
88
|
-
const c = iC * 3;
|
|
89
|
-
|
|
90
|
-
// read actual positions of each vertex
|
|
91
|
-
const aX = vertices[a];
|
|
92
|
-
const aY = vertices[a + 1];
|
|
93
|
-
const aZ = vertices[a + 2];
|
|
94
|
-
|
|
95
|
-
const bX = vertices[b];
|
|
96
|
-
const bY = vertices[b + 1];
|
|
97
|
-
const bZ = vertices[b + 2];
|
|
98
|
-
|
|
99
|
-
const cX = vertices[c];
|
|
100
|
-
const cY = vertices[c + 1];
|
|
101
|
-
const cZ = vertices[c + 2];
|
|
102
|
-
|
|
103
|
-
// compute bounds of the triangle
|
|
104
|
-
const x0 = min3(aX, bX, cX);
|
|
105
|
-
const y0 = min3(aY, bY, cY);
|
|
106
|
-
const z0 = min3(aZ, bZ, cZ);
|
|
107
|
-
|
|
108
|
-
const x1 = max3(aX, bX, cX);
|
|
109
|
-
const y1 = max3(aY, bY, cY);
|
|
110
|
-
const z1 = max3(aZ, bZ, cZ);
|
|
111
|
-
|
|
112
|
-
tree.writeLeaf(i, x0, y0, z0, x1, y1, z1);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// finalize build
|
|
116
|
-
tree.unsortedBuiltIntermediate();
|
|
117
|
-
|
|
118
|
-
return tree;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export {
|
|
122
|
-
buildUnsorted
|
|
123
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 29/05/2016.
|
|
3
|
-
*/
|
|
4
|
-
import { max3 } from "../../../../../core/math/max3.js";
|
|
5
|
-
import { min3 } from "../../../../../core/math/min3.js";
|
|
6
|
-
|
|
7
|
-
const makeTriangle = (function () {
|
|
8
|
-
|
|
9
|
-
let x0, y0, z0, x1, y1, z1;
|
|
10
|
-
|
|
11
|
-
let aX, aY, aZ, bX, bY, bZ, cX, cY, cZ;
|
|
12
|
-
|
|
13
|
-
function setFaceBounds(a, b, c, vertices, callback) {
|
|
14
|
-
aX = vertices[a];
|
|
15
|
-
aY = vertices[a + 1];
|
|
16
|
-
aZ = vertices[a + 2];
|
|
17
|
-
|
|
18
|
-
bX = vertices[b];
|
|
19
|
-
bY = vertices[b + 1];
|
|
20
|
-
bZ = vertices[b + 2];
|
|
21
|
-
|
|
22
|
-
cX = vertices[c];
|
|
23
|
-
cY = vertices[c + 1];
|
|
24
|
-
cZ = vertices[c + 2];
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
x0 = min3(aX, bX, cX);
|
|
28
|
-
y0 = min3(aY, bY, cY);
|
|
29
|
-
z0 = min3(aZ, bZ, cZ);
|
|
30
|
-
|
|
31
|
-
x1 = max3(aX, bX, cX);
|
|
32
|
-
y1 = max3(aY, bY, cY);
|
|
33
|
-
z1 = max3(aZ, bZ, cZ);
|
|
34
|
-
|
|
35
|
-
return callback(x0, y0, z0, x1, y1, z1);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return setFaceBounds;
|
|
39
|
-
})();
|
|
40
|
-
|
|
41
|
-
export default {
|
|
42
|
-
compute: makeTriangle
|
|
43
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
aabb3_compute_distance_above_plane_max
|
|
3
|
-
} from "../../../../../core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js";
|
|
4
|
-
import { point_light_inside_volume } from "./point_light_inside_volume.js";
|
|
5
|
-
import { spot_light_inside_volume } from "./spot_light_inside_volume.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
* @type {(BinaryNode|LeafNode)[]}
|
|
10
|
-
*/
|
|
11
|
-
const stack = [];
|
|
12
|
-
|
|
13
|
-
let stackPointer = 0;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Most of the data is in flat continuous array for cache coherence
|
|
17
|
-
* @param {LightRenderMetadata[]} destination
|
|
18
|
-
* @param {number} destination_offset
|
|
19
|
-
* @param {BinaryNode<LightRenderMetadata>} root
|
|
20
|
-
* @param {number[]|Float32Array|Float64Array} planes
|
|
21
|
-
* @param {number[]|Float32Array|Float64Array} points
|
|
22
|
-
* @returns {number} number of items added to the destination, non-negative integer
|
|
23
|
-
*/
|
|
24
|
-
export function query_bvh_frustum_from_objects(
|
|
25
|
-
destination,
|
|
26
|
-
destination_offset,
|
|
27
|
-
root, planes, points
|
|
28
|
-
) {
|
|
29
|
-
let i = 0;
|
|
30
|
-
let j = 0;
|
|
31
|
-
// read out points
|
|
32
|
-
const stackOffset = stackPointer;
|
|
33
|
-
|
|
34
|
-
stack[stackPointer] = root;
|
|
35
|
-
|
|
36
|
-
stackPointer++;
|
|
37
|
-
|
|
38
|
-
stack_loop:while (stackPointer-- > stackOffset) {
|
|
39
|
-
|
|
40
|
-
// query_bvh_frustum_from_objects.iteration_count++;
|
|
41
|
-
|
|
42
|
-
const n = stack[stackPointer];
|
|
43
|
-
|
|
44
|
-
if (n.isBinaryNode === true) {
|
|
45
|
-
|
|
46
|
-
for (j = 0; j < 6; j++) {
|
|
47
|
-
|
|
48
|
-
const plane_address = j * 4;
|
|
49
|
-
|
|
50
|
-
const plane_normal_x = planes[plane_address];
|
|
51
|
-
const plane_normal_y = planes[plane_address + 1];
|
|
52
|
-
const plane_normal_z = planes[plane_address + 2];
|
|
53
|
-
const plane_constant = planes[plane_address + 3];
|
|
54
|
-
|
|
55
|
-
const distanceAbovePlane = aabb3_compute_distance_above_plane_max(
|
|
56
|
-
plane_normal_x, plane_normal_y, plane_normal_z, plane_constant,
|
|
57
|
-
n.x0, n.y0, n.z0,
|
|
58
|
-
n.x1, n.y1, n.z1
|
|
59
|
-
);
|
|
60
|
-
|
|
61
|
-
if (distanceAbovePlane < 0) {
|
|
62
|
-
// node is below the plane
|
|
63
|
-
|
|
64
|
-
// query_bvh_frustum_from_objects.rejection_count++;
|
|
65
|
-
|
|
66
|
-
continue stack_loop;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (n.right !== null) {
|
|
72
|
-
stack[stackPointer] = n.right;
|
|
73
|
-
stackPointer++;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (n.left !== null) {
|
|
77
|
-
stack[stackPointer] = n.left;
|
|
78
|
-
stackPointer++
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
} else {
|
|
82
|
-
|
|
83
|
-
// leaf node
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
*
|
|
87
|
-
* @type {LightRenderMetadata}
|
|
88
|
-
*/
|
|
89
|
-
const light_data = n.object;
|
|
90
|
-
|
|
91
|
-
const light = light_data.light;
|
|
92
|
-
|
|
93
|
-
if (light.isPointLight) {
|
|
94
|
-
|
|
95
|
-
const light_position = light.position;
|
|
96
|
-
|
|
97
|
-
const light_x = light_position.x;
|
|
98
|
-
const light_y = light_position.y;
|
|
99
|
-
const light_z = light_position.z;
|
|
100
|
-
|
|
101
|
-
const radius = light.radius.getValue();
|
|
102
|
-
|
|
103
|
-
if (!point_light_inside_volume(light_x, light_y, light_z, radius, points, planes)) {
|
|
104
|
-
continue;
|
|
105
|
-
}
|
|
106
|
-
} else if (light.isSpotLight) {
|
|
107
|
-
if (!spot_light_inside_volume(light, points, planes)) {
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
destination[destination_offset + i] = light_data;
|
|
113
|
-
|
|
114
|
-
i++;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
//drop the stack frame
|
|
120
|
-
stackPointer = stackOffset;
|
|
121
|
-
|
|
122
|
-
return i;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
query_bvh_frustum_from_objects.iteration_count = 0;
|
|
126
|
-
query_bvh_frustum_from_objects.rejection_count = 0;
|
|
127
|
-
query_bvh_frustum_from_objects.rejection_sphere_count = 0;
|
|
128
|
-
query_bvh_frustum_from_objects.plane_tests = 0;
|
|
129
|
-
query_bvh_frustum_from_objects.plane_tests_early_exits = 0;
|
|
130
|
-
query_bvh_frustum_from_objects.checks_sphere = 0;
|
|
131
|
-
query_bvh_frustum_from_objects.checks_sphere_plane = 0;
|
|
132
|
-
query_bvh_frustum_from_objects.checks_sphere_frustum_corner = 0;
|
|
133
|
-
query_bvh_frustum_from_objects.checks_sphere_frustum_edge = 0;
|