@woosh/meep-engine 2.34.12 → 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) {
@@ -0,0 +1,7 @@
1
+ /**
2
+ *
3
+ * @param {THREE.Color} c
4
+ */
5
+ export function computeHashColor(c) {
6
+ return c.getHex();
7
+ }
@@ -1,9 +1,9 @@
1
1
  import { planesEqual } from "./planesEqual.js";
2
- import { computeTextureEquality } from "./computeTextureEquality.js";
3
2
  import { isArraysEqualWithComparator } from "../../../../core/collection/array/isArraysEqualWithComparator.js";
3
+ import { computeTextureEqualityById } from "./computeTextureEqualityById.js";
4
4
 
5
5
  /**
6
- *
6
+ * NOTE: does not do deep comparison on textures, only checks the IDs
7
7
  * @param {Material|MeshStandardMaterial|MeshDepthMaterial|MeshMatcapMaterial} a
8
8
  * @param {Material|MeshStandardMaterial|MeshDepthMaterial|MeshMatcapMaterial} b
9
9
  * @returns {boolean}
@@ -76,28 +76,28 @@ export function computeMaterialEquality(a, b) {
76
76
  || a.wireframeLinewidth !== b.wireframeLinewidth
77
77
  || a.morphTargets !== b.morphTargets
78
78
  || a.morphNormals !== b.morphNormals
79
- || !computeTextureEquality(a.roughnessMap, b.roughnessMap)
80
- || !computeTextureEquality(a.metalnessMap, b.metalnessMap)
81
- || !computeTextureEquality(a.alphaMap, b.alphaMap)
82
- || !computeTextureEquality(a.envMap, b.envMap)
83
- || !computeTextureEquality(a.displacementMap, b.displacementMap)
84
- || !computeTextureEquality(a.normalMap, b.normalMap)
85
- || !computeTextureEquality(a.emissiveMap, b.emissiveMap)
86
- || !computeTextureEquality(a.bumpMap, b.bumpMap)
87
- || !computeTextureEquality(a.aoMap, b.aoMap)
88
- || !computeTextureEquality(a.map, b.map)
89
- || !computeTextureEquality(a.lightMap, b.lightMap)
79
+ || !computeTextureEqualityById(a.roughnessMap, b.roughnessMap)
80
+ || !computeTextureEqualityById(a.metalnessMap, b.metalnessMap)
81
+ || !computeTextureEqualityById(a.alphaMap, b.alphaMap)
82
+ || !computeTextureEqualityById(a.envMap, b.envMap)
83
+ || !computeTextureEqualityById(a.displacementMap, b.displacementMap)
84
+ || !computeTextureEqualityById(a.normalMap, b.normalMap)
85
+ || !computeTextureEqualityById(a.emissiveMap, b.emissiveMap)
86
+ || !computeTextureEqualityById(a.bumpMap, b.bumpMap)
87
+ || !computeTextureEqualityById(a.aoMap, b.aoMap)
88
+ || !computeTextureEqualityById(a.map, b.map)
89
+ || !computeTextureEqualityById(a.lightMap, b.lightMap)
90
90
  ) {
91
91
  return false;
92
92
  }
93
93
  } else if (a.isMeshDepthMaterial) {
94
94
  if (
95
- !computeTextureEquality(a.alphaMap, b.alphaMap)
95
+ !computeTextureEqualityById(a.alphaMap, b.alphaMap)
96
96
  || a.depthPacking !== b.depthPacking
97
- || !computeTextureEquality(a.displacementMap, b.displacementMap)
97
+ || !computeTextureEqualityById(a.displacementMap, b.displacementMap)
98
98
  || a.displacementScale !== b.displacementScale
99
99
  || a.displacementBias !== b.displacementBias
100
- || !computeTextureEquality(a.map, b.map)
100
+ || !computeTextureEqualityById(a.map, b.map)
101
101
  || a.morphTargets !== b.morphTargets
102
102
  || a.wireframe !== b.wireframe
103
103
  || a.wireframeLinewidth !== b.wireframeLinewidth
@@ -107,15 +107,15 @@ export function computeMaterialEquality(a, b) {
107
107
  } else if (a.isMeshMatcapMaterial) {
108
108
  if (
109
109
  !a.color.equals(b.color)
110
- || !computeTextureEquality(a.matcap, b.matcap)
111
- || !computeTextureEquality(a.map, b.map)
112
- || !computeTextureEquality(a.bumpMap, b.bumpMap)
113
- || !computeTextureEquality(a.normalMap, b.normalMap)
110
+ || !computeTextureEqualityById(a.matcap, b.matcap)
111
+ || !computeTextureEqualityById(a.map, b.map)
112
+ || !computeTextureEqualityById(a.bumpMap, b.bumpMap)
113
+ || !computeTextureEqualityById(a.normalMap, b.normalMap)
114
114
  || !a.normalScale.equals(b.normalScale)
115
- || !computeTextureEquality(a.displacementMap, b.displacementMap)
115
+ || !computeTextureEqualityById(a.displacementMap, b.displacementMap)
116
116
  || a.displacementScale !== b.displacementScale
117
117
  || a.displacementBias !== b.displacementBias
118
- || !computeTextureEquality(a.alphaMap, b.alphaMap)
118
+ || !computeTextureEqualityById(a.alphaMap, b.alphaMap)
119
119
  || a.morphTargets !== b.morphTargets
120
120
  || a.morphNormals !== b.morphNormals
121
121
  || a.flatShading !== b.flatShading
@@ -1,9 +1,10 @@
1
1
  import { planeHash } from "./planeHash.js";
2
- import { computeTextureHash } from "./computeTextureHash.js";
3
2
  import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
4
3
  import { computeHashArray } from "../../../../core/collection/array/computeHashArray.js";
5
4
  import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
6
5
  import { computeHashFloat } from "../../../../core/math/hash/computeHashFloat.js";
6
+ import { textureHashById } from "./textureHashById.js";
7
+ import { computeHashColor } from "./computeHashColor.js";
7
8
 
8
9
  /**
9
10
  *
@@ -46,21 +47,22 @@ export function computeMaterialHash(material) {
46
47
 
47
48
 
48
49
  if (material.isMeshStandardMaterial) {
49
- //TODO extend hash
50
50
  hash = computeHashIntegerArray(
51
51
  hash,
52
- computeTextureHash(material.map),
53
- computeTextureHash(material.lightMap),
54
- computeTextureHash(material.aoMap),
55
- computeTextureHash(material.emissiveMap),
56
- computeTextureHash(material.bumpMap),
57
- computeTextureHash(material.normalMap),
58
- computeTextureHash(material.displacementMap),
59
- computeTextureHash(material.roughnessMap),
60
- computeTextureHash(material.metalnessMap),
61
- computeTextureHash(material.alphaMap),
52
+ computeHashColor(material.color),
53
+ computeHashFloat(material.roughness),
54
+ computeHashFloat(material.metalness),
55
+ textureHashById(material.map),
56
+ textureHashById(material.lightMap),
57
+ computeHashFloat(material.lightMapIntensity),
58
+ textureHashById(material.aoMap),
59
+ computeHashFloat(material.aoMapIntensity),
60
+ computeHashColor(material.emissive),
61
+ computeHashFloat(material.emissiveIntensity),
62
+ textureHashById(material.emissiveMap),
62
63
  computeHashFloat(material.envMapIntensity),
63
- computeTextureHash(material.envMap)
64
+ textureHashById(material.bumpMap),
65
+ textureHashById(material.normalMap),
64
66
  );
65
67
  } else if (material.isShaderMaterial) {
66
68
  hash ^= material.lights ? 0 : 1;
@@ -0,0 +1,22 @@
1
+ /**
2
+ *
3
+ * @param {Texture} a
4
+ * @param {Texture} b
5
+ * @returns {boolean}
6
+ */
7
+ export function computeTextureEqualityById(a, b) {
8
+ if (a === b) {
9
+ return true;
10
+ }
11
+
12
+ if (
13
+ a === null
14
+ || b === null
15
+ || a === undefined
16
+ || b === undefined
17
+ ) {
18
+ return false;
19
+ }
20
+
21
+ return a.id === b.id;
22
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ *
3
+ * @param {THREE.Texture} texture
4
+ * @return {number}
5
+ */
6
+ export function textureHashById(texture) {
7
+ if (texture === undefined || texture === null) {
8
+ return 0;
9
+ }
10
+
11
+ return texture.id;
12
+ }
@@ -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
  }
@@ -1,5 +1,26 @@
1
1
  export class Sampler2D {
2
+ readonly height: number
3
+ readonly width: number
4
+
5
+ readonly itemSize: number
6
+
2
7
  readChannel(x: number, y: number, channel: number): number
3
8
 
4
9
  writeChannel(x: number, y: number, channel: number, value: number): void
10
+
11
+ static uint8clamped(itemSize: number, width: number, height: number): Sampler2D
12
+
13
+ static uint8(itemSize: number, width: number, height: number): Sampler2D
14
+
15
+ static uint16(itemSize: number, width: number, height: number): Sampler2D
16
+
17
+ static uint32(itemSize: number, width: number, height: number): Sampler2D
18
+
19
+ static int8(itemSize: number, width: number, height: number): Sampler2D
20
+
21
+ static int16(itemSize: number, width: number, height: number): Sampler2D
22
+
23
+ static int32(itemSize: number, width: number, height: number): Sampler2D
24
+
25
+ static float32(itemSize: number, width: number, height: number): Sampler2D
5
26
  }
@@ -133,7 +133,7 @@ function sampleTriangleBottomRight(p1, p2, p3, dx, dy) {
133
133
 
134
134
  /**
135
135
  *
136
- * @param {Array.<Number>|Uint8ClampedArray|Uint8Array|Uint16Array|Int8Array|Float32Array} data
136
+ * @param {ArrayLike<number>|number[]|Uint8ClampedArray|Uint8Array|Uint16Array|Int8Array|Int16Array|Int32Array|Float32Array|Float64Array} data
137
137
  * @param {int} itemSize
138
138
  * @param {int} width
139
139
  * @param {int} height
@@ -255,6 +255,18 @@ Sampler2D.int16 = function (itemSize, width, height) {
255
255
  const sampler = new Sampler2D(data, itemSize, width, height);
256
256
  return sampler;
257
257
  };
258
+ /**
259
+ *
260
+ * @param {int} itemSize
261
+ * @param {int} width
262
+ * @param {int} height
263
+ * @return {Sampler2D}
264
+ */
265
+ Sampler2D.int32 = function (itemSize, width, height) {
266
+ const data = new Int32Array(width * height * itemSize);
267
+ const sampler = new Sampler2D(data, itemSize, width, height);
268
+ return sampler;
269
+ };
258
270
 
259
271
  /**
260
272
  *
@@ -268,6 +280,18 @@ Sampler2D.float32 = function (itemSize, width, height) {
268
280
  const sampler = new Sampler2D(data, itemSize, width, height);
269
281
  return sampler;
270
282
  };
283
+ /**
284
+ *
285
+ * @param {int} itemSize
286
+ * @param {int} width
287
+ * @param {int} height
288
+ * @return {Sampler2D}
289
+ */
290
+ Sampler2D.float64 = function (itemSize, width, height) {
291
+ const data = new Float64Array(width * height * itemSize);
292
+ const sampler = new Sampler2D(data, itemSize, width, height);
293
+ return sampler;
294
+ };
271
295
 
272
296
  /**
273
297
  *
@@ -54,7 +54,7 @@ export class GridTaskGenerator {
54
54
  * @returns {Task|TaskGroup}
55
55
  */
56
56
  build(grid, ecd, seed) {
57
-
57
+ throw new Error('Not Implemented');
58
58
  }
59
59
  }
60
60
 
@@ -0,0 +1,8 @@
1
+ import { GridTaskGenerator } from "../GridTaskGenerator.js";
2
+ import { emptyTask } from "../../../core/process/task/TaskUtils.js";
3
+
4
+ export class NoopGridTaskGenerator extends GridTaskGenerator {
5
+ build(grid, ecd, seed) {
6
+ return emptyTask('empty');
7
+ }
8
+ }
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.12",
8
+ "version": "2.34.16",
9
9
  "dependencies": {
10
10
  "gl-matrix": "3.4.3",
11
11
  "fast-levenshtein": "2.0.6",