@woosh/meep-engine 2.69.0 → 2.70.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.
@@ -546,11 +546,7 @@ class Vector2 {
546
546
  const x = computeHashFloat(this.x);
547
547
  const y = computeHashFloat(this.y);
548
548
 
549
- let hash = ((x << 5) - x) + y;
550
-
551
- hash |= 0; //convert to 32bit int
552
-
553
- return hash;
549
+ return ((x << 5) - x) + y;
554
550
  }
555
551
 
556
552
  /**
@@ -561,8 +557,11 @@ class Vector2 {
561
557
  const sin = Math.sin(angle);
562
558
  const cos = Math.cos(angle);
563
559
 
564
- const x = this.x * cos - this.y * sin
565
- const y = this.x * sin + this.y * cos;
560
+ const _x = this.x;
561
+ const _y = this.y;
562
+
563
+ const x = _x * cos - _y * sin
564
+ const y = _x * sin + _y * cos;
566
565
 
567
566
  this.set(x, y);
568
567
  }
@@ -5,17 +5,19 @@
5
5
 
6
6
  import { assert } from "../assert.js";
7
7
  import Signal from "../events/signal/Signal.js";
8
+ import { EPSILON } from "../math/EPSILON.js";
9
+ import { epsilonEquals } from "../math/epsilonEquals.js";
8
10
  import { lerp } from "../math/lerp.js";
9
11
  import { sign } from "../math/sign.js";
12
+ import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
13
+ import { v3_angle_between } from "./vec3/v3_angle_between.js";
14
+ import { v3_binary_equality_decode } from "./vec3/v3_binary_equality_decode.js";
15
+ import { v3_binary_equality_encode } from "./vec3/v3_binary_equality_encode.js";
10
16
  import { v3_dot } from "./vec3/v3_dot.js";
11
- import { v3_length_sqr } from "./vec3/v3_length_sqr.js";
12
17
  import { v3_length } from "./vec3/v3_length.js";
13
- import { v3_angle_between } from "./vec3/v3_angle_between.js";
18
+ import { v3_length_sqr } from "./vec3/v3_length_sqr.js";
14
19
  import { v3_lerp } from "./vec3/v3_lerp.js";
15
20
  import { v3_slerp } from "./vec3/v3_slerp.js";
16
- import { computeHashFloat } from "../primitives/numbers/computeHashFloat.js";
17
- import { epsilonEquals } from "../math/epsilonEquals.js";
18
- import { EPSILON } from "../math/EPSILON.js";
19
21
 
20
22
  class Vector3 {
21
23
  /**
@@ -856,100 +858,31 @@ class Vector3 {
856
858
  /**
857
859
  *
858
860
  * @param {BinaryBuffer} buffer
861
+ * @deprecated use dedicated method directly instead
859
862
  */
860
863
  toBinaryBufferFloat32_EqualityEncoded(buffer) {
861
864
  const x = this.x;
862
865
  const y = this.y;
863
866
  const z = this.z;
864
867
 
865
- let header = 0;
866
-
867
- if (x === y) {
868
- header |= 1;
869
- }
870
-
871
- if (y === z) {
872
- header |= 2;
873
- }
874
-
875
- if (x === z) {
876
- header |= 4;
877
- }
878
-
879
- buffer.writeUint8(header);
880
-
881
- if ((header & 7) === 7) {
882
- //all components are the same
883
- buffer.writeFloat32(x);
884
- } else if (header === 1) {
885
- //X and Y are the same, Z is different
886
- buffer.writeFloat32(x);
887
- buffer.writeFloat32(z);
888
- } else if (header === 2) {
889
- //Y and Z are the same, X is different
890
- buffer.writeFloat32(x);
891
- buffer.writeFloat32(y);
892
- } else if (header === 4) {
893
- //X and Z are the same, Y is different
894
- buffer.writeFloat32(x);
895
- buffer.writeFloat32(y);
896
- } else {
897
- //scale components are different
898
- buffer.writeFloat32(x);
899
- buffer.writeFloat32(y);
900
- buffer.writeFloat32(z);
901
- }
868
+ v3_binary_equality_encode(buffer, x, y, z);
902
869
  }
903
870
 
904
871
  /**
905
872
  * Uses an extra byte for a header. Only writes unique components. Useful for things like scale where all components usually have the same value
906
873
  * @param {BinaryBuffer} buffer
874
+ * @deprecated use dedicated method directly instead
907
875
  */
908
876
  fromBinaryBufferFloat32_EqualityEncoded(buffer) {
909
- const header = buffer.readUint8();
910
-
911
- let x = 0;
912
- let y = 0;
913
- let z = 0;
914
-
915
- if ((header & 7) === 7) {
916
- //all scale components are the same
917
- x = buffer.readFloat32();
918
- y = x;
919
- z = x;
920
- } else if ((header & 1) === 1) {
921
- //X and Y are the same, Z is different
922
- x = buffer.readFloat32();
923
- y = x;
924
- z = buffer.readFloat32();
925
- } else if ((header & 2) === 2) {
926
- //Y and Z are the same, X is different
927
- x = buffer.readFloat32();
928
- y = buffer.readFloat32();
929
- z = y;
930
- } else if ((header & 4) === 4) {
931
- //X and Z are the same, Y is different
932
- x = buffer.readFloat32();
933
- y = buffer.readFloat32();
934
- z = x;
935
- } else {
936
- //scale components are different
937
- x = buffer.readFloat32();
938
- y = buffer.readFloat32();
939
- z = buffer.readFloat32();
940
- }
941
-
942
- this.set(x, y, z);
877
+ v3_binary_equality_decode(buffer, this, 0);
943
878
  }
944
879
 
945
880
  hash() {
946
- let hash = computeHashFloat(this.x);
947
-
948
- hash = ((hash << 5) - hash) + computeHashFloat(this.y);
949
-
950
- hash = ((hash << 5) - hash) + computeHashFloat(this.z);
881
+ const x = computeHashFloat(this.x);
882
+ const y = computeHashFloat(this.y);
883
+ const z = computeHashFloat(this.z);
951
884
 
952
- return hash;
885
+ return x ^ (y << 1) ^ (z << 2);
953
886
  }
954
887
 
955
888
 
@@ -0,0 +1,44 @@
1
+ /**
2
+ *
3
+ * @param {BinaryBuffer} buffer
4
+ * @param {number[]} result
5
+ * @param {number} result_offset
6
+ */
7
+ export function v3_binary_equality_decode(buffer, result, result_offset) {
8
+ const header = buffer.readUint8();
9
+
10
+ let x = 0;
11
+ let y = 0;
12
+ let z = 0;
13
+
14
+ if ((header & 7) === 7) {
15
+ //all scale components are the same
16
+ x = buffer.readFloat32();
17
+ y = x;
18
+ z = x;
19
+ } else if ((header & 1) === 1) {
20
+ //X and Y are the same, Z is different
21
+ x = buffer.readFloat32();
22
+ y = x;
23
+ z = buffer.readFloat32();
24
+ } else if ((header & 2) === 2) {
25
+ //Y and Z are the same, X is different
26
+ x = buffer.readFloat32();
27
+ y = buffer.readFloat32();
28
+ z = y;
29
+ } else if ((header & 4) === 4) {
30
+ //X and Z are the same, Y is different
31
+ x = buffer.readFloat32();
32
+ y = buffer.readFloat32();
33
+ z = x;
34
+ } else {
35
+ //scale components are different
36
+ x = buffer.readFloat32();
37
+ y = buffer.readFloat32();
38
+ z = buffer.readFloat32();
39
+ }
40
+
41
+ result[result_offset] = x;
42
+ result[result_offset + 1] = y;
43
+ result[result_offset + 2] = z;
44
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ *
3
+ * @param {BinaryBuffer} buffer
4
+ * @param {number} x
5
+ * @param {number} y
6
+ * @param {number} z
7
+ */
8
+ export function v3_binary_equality_encode(buffer, x, y, z){
9
+
10
+ let header = 0;
11
+
12
+ if (x === y) {
13
+ header |= 1;
14
+ }
15
+
16
+ if (y === z) {
17
+ header |= 2;
18
+ }
19
+
20
+ if (x === z) {
21
+ header |= 4;
22
+ }
23
+
24
+ buffer.writeUint8(header);
25
+
26
+ if ((header & 7) === 7) {
27
+ //all components are the same
28
+ buffer.writeFloat32(x);
29
+ } else if (header === 1) {
30
+ //X and Y are the same, Z is different
31
+ buffer.writeFloat32(x);
32
+ buffer.writeFloat32(z);
33
+ } else if (header === 2) {
34
+ //Y and Z are the same, X is different
35
+ buffer.writeFloat32(x);
36
+ buffer.writeFloat32(y);
37
+ } else if (header === 4) {
38
+ //X and Z are the same, Y is different
39
+ buffer.writeFloat32(x);
40
+ buffer.writeFloat32(y);
41
+ } else {
42
+ //scale components are different
43
+ buffer.writeFloat32(x);
44
+ buffer.writeFloat32(y);
45
+ buffer.writeFloat32(z);
46
+ }
47
+ }
@@ -5,10 +5,10 @@
5
5
  */
6
6
  export function computeHashFloat(v) {
7
7
  //we break the number up into fractional and whole parts
8
- const fraction = v % 1;
9
-
10
8
  const whole = v | 0;
11
9
 
10
+ const fraction = v - whole;
11
+
12
12
  //fractional part is scaled up into int32 range, this inexact method, as it will produce 0 hash for values below a certain threshold
13
13
  const fractionHash = fraction * 1367130550;
14
14
 
@@ -2,15 +2,15 @@
2
2
  * Created by Alex on 02/04/2014.
3
3
  */
4
4
 
5
- import {assert} from "../../../core/assert.js";
6
- import {compose_matrix4_array} from "../../../core/geom/3d/compose_matrix4_array.js";
7
- import {decompose_matrix_4_array} from "../../../core/geom/3d/decompose_matrix_4_array.js";
8
- import {allocate_transform_m4} from "../../../core/geom/3d/matrix/allocate_transform_m4.js";
9
- import {m4_multiply} from "../../../core/geom/3d/matrix/m4_multiply.js";
10
- import {MATRIX_4_IDENTITY} from "../../../core/geom/3d/matrix/MATRIX_4_IDENTITY.js";
5
+ import { assert } from "../../../core/assert.js";
6
+ import { compose_matrix4_array } from "../../../core/geom/3d/compose_matrix4_array.js";
7
+ import { decompose_matrix_4_array } from "../../../core/geom/3d/decompose_matrix_4_array.js";
8
+ import { allocate_transform_m4 } from "../../../core/geom/3d/matrix/allocate_transform_m4.js";
9
+ import { m4_multiply } from "../../../core/geom/3d/matrix/m4_multiply.js";
10
+ import { MATRIX_4_IDENTITY } from "../../../core/geom/3d/matrix/MATRIX_4_IDENTITY.js";
11
11
  import Quaternion from "../../../core/geom/Quaternion.js";
12
12
  import Vector3 from "../../../core/geom/Vector3.js";
13
- import {TransformFlags} from "./TransformFlags.js";
13
+ import { TransformFlags } from "./TransformFlags.js";
14
14
 
15
15
  /**
16
16
  *
@@ -261,8 +261,7 @@ export class Transform {
261
261
  * @returns {boolean}
262
262
  */
263
263
  equals(other) {
264
- return other.isTransform
265
- && this.position.equals(other.position)
264
+ return this.position.equals(other.position)
266
265
  && this.rotation.equals(other.rotation)
267
266
  && this.scale.equals(other.scale);
268
267
  }
@@ -1,3 +1,7 @@
1
+ import { quat_decode_from_uint32 } from "../../../core/geom/3d/quaternion/quat_decode_from_uint32.js";
2
+ import { quat_encode_to_uint32 } from "../../../core/geom/3d/quaternion/quat_encode_to_uint32.js";
3
+ import { v3_binary_equality_decode } from "../../../core/geom/vec3/v3_binary_equality_decode.js";
4
+ import { v3_binary_equality_encode } from "../../../core/geom/vec3/v3_binary_equality_encode.js";
1
5
  import { BinaryClassSerializationAdapter } from "../storage/binary/BinaryClassSerializationAdapter.js";
2
6
  import { Transform } from "./Transform.js";
3
7
 
@@ -23,11 +27,19 @@ export class TransformSerializationAdapter extends BinaryClassSerializationAdapt
23
27
  buffer.writeFloat64(positionY);
24
28
  buffer.writeFloat64(positionZ);
25
29
 
26
- const encodedRotation = value.rotation.encodeToUint32();
30
+ const rotation = value.rotation;
31
+ const encoded_rotation = quat_encode_to_uint32(
32
+ rotation.x,
33
+ rotation.y,
34
+ rotation.z,
35
+ rotation.w
36
+ );
27
37
 
28
- buffer.writeUint32(encodedRotation);
38
+ buffer.writeUint32(encoded_rotation);
29
39
 
30
- value.scale.toBinaryBufferFloat32_EqualityEncoded(buffer);
40
+ const scale = value.scale;
41
+
42
+ v3_binary_equality_encode(buffer, scale.x, scale.y, scale.z);
31
43
  }
32
44
 
33
45
  /**
@@ -40,12 +52,11 @@ export class TransformSerializationAdapter extends BinaryClassSerializationAdapt
40
52
  const positionY = buffer.readFloat64();
41
53
  const positionZ = buffer.readFloat64();
42
54
 
43
- const encodedRotation = buffer.readUint32();
55
+ const encoded_rotation = buffer.readUint32();
44
56
 
45
- value.scale.fromBinaryBufferFloat32_EqualityEncoded(buffer);
57
+ v3_binary_equality_decode(buffer, value.scale, 0);
46
58
 
59
+ quat_decode_from_uint32(value.rotation, 0, encoded_rotation);
47
60
  value.position.set(positionX, positionY, positionZ);
48
-
49
- value.rotation.decodeFromUint32(encodedRotation);
50
61
  }
51
62
  }
@@ -3,10 +3,8 @@
3
3
  */
4
4
  import { assert } from "../../../../core/assert.js";
5
5
  import { BvhClient } from "../../../../core/bvh2/bvh3/BvhClient.js";
6
- import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
7
6
  import { AABB3 } from "../../../../core/geom/3d/aabb/AABB3.js";
8
7
  import { aabb3_matrix4_project } from "../../../../core/geom/3d/aabb/aabb3_matrix4_project.js";
9
- import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
10
8
  import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
11
9
  import { Transform } from "../../../ecs/transform/Transform.js";
12
10
  import { applyTransformToThreeObject } from "./applyTransformToThreeObject.js";
@@ -25,6 +23,15 @@ export const MeshFlags = {
25
23
 
26
24
  const DEFAULT_FLAGS = 0;
27
25
 
26
+ /**
27
+ *
28
+ * @type {number}
29
+ */
30
+ const EQUALITY_FLAGS =
31
+ MeshFlags.CastShadow
32
+ | MeshFlags.ReceiveShadow
33
+ ;
34
+
28
35
  /**
29
36
  * Traversal stack
30
37
  * @type {Object3D[]}
@@ -255,13 +262,7 @@ class Mesh {
255
262
  }
256
263
 
257
264
  hash() {
258
- let urlHash = computeStringHash(this.url);
259
- return computeHashIntegerArray(
260
- urlHash,
261
- this.castShadow ? 1 : 0,
262
- this.receiveShadow ? 1 : 0,
263
- computeHashFloat(this.opacity)
264
- );
265
+ return computeStringHash(this.url) ^ this.flags;
265
266
  }
266
267
 
267
268
  /**
@@ -271,9 +272,8 @@ class Mesh {
271
272
  */
272
273
  equals(other) {
273
274
  return this.url === other.url
275
+ && (this.flags & EQUALITY_FLAGS) === (other.flags & EQUALITY_FLAGS)
274
276
  && this.opacity === other.opacity
275
- && this.castShadow === other.castShadow
276
- && this.receiveShadow === other.receiveShadow
277
277
  ;
278
278
  }
279
279