@woosh/meep-engine 2.67.0 → 2.68.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.
Files changed (50) hide show
  1. package/build/meep.cjs +0 -1
  2. package/build/meep.module.js +0 -1
  3. package/package.json +1 -1
  4. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
  5. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
  6. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
  7. package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
  8. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
  9. package/src/core/bvh2/BVHTasks.js +0 -65
  10. package/src/core/bvh2/BinaryNode.d.ts +0 -13
  11. package/src/core/bvh2/BinaryNode.js +0 -1188
  12. package/src/core/bvh2/BinaryNode.spec.js +0 -309
  13. package/src/core/bvh2/LeafNode.d.ts +0 -7
  14. package/src/core/bvh2/LeafNode.js +0 -147
  15. package/src/core/bvh2/Node.d.ts +0 -9
  16. package/src/core/bvh2/Node.js +0 -196
  17. package/src/core/bvh2/NodeValidator.js +0 -197
  18. package/src/core/bvh2/StacklessTraverser.js +0 -154
  19. package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
  20. package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
  21. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
  22. package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
  23. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
  24. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
  25. package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
  26. package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
  27. package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
  28. package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
  29. package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
  30. package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
  31. package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
  32. package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
  33. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
  34. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
  35. package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
  36. package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
  37. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
  38. package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
  39. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
  40. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
  41. package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
  42. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
  43. package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
  44. package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
  45. package/src/core/geom/2d/bvh/Node2.js +0 -51
  46. package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
  47. package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
  48. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
  49. package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
  50. 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,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;