@woosh/meep-engine 2.34.15 → 2.34.16

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.
@@ -140,7 +140,23 @@ export default class IndexedBinaryBVH {
140
140
  }
141
141
 
142
142
  /**
143
- *
143
+ * Sets bounds of a given leaf
144
+ * NOTE: to build tree, must call {@link #unsortedBuiltIntermediate} after all leaves are set
145
+ * @param {number} leaf_index
146
+ * @param {number} x0
147
+ * @param {number} y0
148
+ * @param {number} z0
149
+ * @param {number} x1
150
+ * @param {number} y1
151
+ * @param {number} z1
152
+ */
153
+ writeLeaf(leaf_index, x0, y0, z0, x1, y1, z1) {
154
+ const offset = this.binaryNodeCount * 6 + leaf_index * 6;
155
+ writeBox(this.data, offset, x0, y0, z0, x1, y1, z1);
156
+ }
157
+
158
+ /**
159
+ * @deprecated use {@link #writeLeaf} instead followed by {@link #unsortedBuiltIntermediate}
144
160
  * @param {function(index:number,offset:number,data:*, writeBox:function):*} visitor
145
161
  */
146
162
  setLeafs(visitor) {
@@ -3,6 +3,7 @@ import { buildUnsorted } from "../../bvh/buffered/BinaryBVHFromBufferGeometry.js
3
3
  import { ClippingPlaneContainmentComputingVisitor } from "./ClippingPlaneContainmentComputingVisitor.js";
4
4
  import { RaycastNearestHitComputingVisitor } from "./RaycastNearestHitComputingVisitor.js";
5
5
  import { assert } from "../../../../../core/assert.js";
6
+ import { deinterleaveBufferAttribute } from "../deinterleaveBufferAttribute.js";
6
7
 
7
8
  export class GeometrySpatialQueryAccelerator {
8
9
  constructor(cache_size = 100 * 1024 * 1024) {
@@ -153,8 +154,14 @@ export class GeometrySpatialQueryAccelerator {
153
154
  * @returns {IndexedBinaryBVH}
154
155
  */
155
156
  __buildBVH(geometry) {
156
- const vertices = geometry.getAttribute('position').array;
157
- const indices = geometry.getIndex().array;
157
+ const position_attribute = geometry.getAttribute('position');
158
+ const index_attribute = geometry.getIndex();
159
+
160
+ const de_interleaved_position_attribute = deinterleaveBufferAttribute(position_attribute);
161
+ const de_interleaved_index_attribute = deinterleaveBufferAttribute(index_attribute);
162
+
163
+ const vertices = de_interleaved_position_attribute.array;
164
+ const indices = de_interleaved_index_attribute.array;
158
165
 
159
166
  return buildUnsorted(vertices, indices);
160
167
  }
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Created by Alex on 29/05/2016.
3
3
  */
4
- import IndexedTriangleBoundsComputer from './IndexedTraingleBoundsComputer.js';
5
4
  import IndexedBinaryBVH from '../../../../../core/bvh2/binary/IndexedBinaryBVH.js';
6
-
7
- const makeTriangle = IndexedTriangleBoundsComputer.compute;
5
+ import { min3 } from "../../../../../core/math/min3.js";
6
+ import { max3 } from "../../../../../core/math/max3.js";
8
7
 
9
8
  /**
10
9
  *
@@ -19,20 +18,46 @@ function buildUnsorted(vertices, indices) {
19
18
  const tree = new IndexedBinaryBVH();
20
19
  tree.initialize(numNodes);
21
20
 
22
- tree.setLeafs(function (i, offset, data, writeBox) {
21
+ for (let i = 0; i < numNodes; i++) {
23
22
 
24
23
  const index3 = i * 3;
25
24
 
25
+ // read triangle vertex indices
26
26
  const iA = indices[index3];
27
27
  const iB = indices[index3 + 1];
28
28
  const iC = indices[index3 + 2];
29
29
 
30
- makeTriangle(iA * 3, iB * 3, iC * 3, vertices, function (x0, y0, z0, x1, y1, z1) {
31
- writeBox(data, offset, x0, y0, z0, x1, y1, z1);
32
- });
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
+ }
33
58
 
34
- return i;
35
- });
59
+ // finalize build
60
+ tree.unsortedBuiltIntermediate();
36
61
 
37
62
  return tree;
38
63
  }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "productName": "Meep",
6
6
  "description": "production-ready JavaScript game engine based on Entity Component System Architecture",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.34.15",
8
+ "version": "2.34.16",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",