@woosh/meep-engine 2.119.41 → 2.119.43

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.119.41",
8
+ "version": "2.119.43",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -1,10 +1,15 @@
1
1
  /**
2
2
  * Computations of screen-space pixel area covered by a sphere
3
3
  * NOTE: Port of GLSL code by Ingo Quilez. Source: http://www.iquilezles.org/www/articles/sphereproj/sphereproj.htm
4
- * @param {Vector4} sph Sphere in world space
5
- * @param {Matrix4} cam camera transform matrix (world to camera)(inverse world matrix of camera)
4
+ * @param {number[]|{0:number,1:number,2:number,3:number}} sph Sphere in world space
5
+ * @param {number[]|Float32Array} cam camera transform matrix (world to camera)(inverse world matrix of camera)
6
6
  * @param {number} fl focal length (fov in Radians)
7
7
  * @returns {number} area on the screen as a fraction, 1=entire screen, 0=zero area
8
8
  */
9
- export function sphere_project(sph: Vector4, cam: Matrix4, fl: number): number;
9
+ export function sphere_project(sph: number[] | {
10
+ 0: number;
11
+ 1: number;
12
+ 2: number;
13
+ 3: number;
14
+ }, cam: number[] | Float32Array, fl: number): number;
10
15
  //# sourceMappingURL=sphere_project.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sphere_project.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/sphere/sphere_project.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,+DAHW,MAAM,GACJ,MAAM,CA0BlB"}
1
+ {"version":3,"file":"sphere_project.d.ts","sourceRoot":"","sources":["../../../../../../src/core/geom/3d/sphere/sphere_project.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,oCALW,MAAM,EAAE,GAAC;IAAC,CAAC,EAAC,MAAM,CAAC;IAAA,CAAC,EAAC,MAAM,CAAC;IAAA,CAAC,EAAC,MAAM,CAAC;IAAA,CAAC,EAAC,MAAM,CAAA;CAAC,OAC9C,MAAM,EAAE,GAAC,YAAY,MACrB,MAAM,GACJ,MAAM,CAoClB"}
@@ -7,23 +7,26 @@ const v4 = [];
7
7
  /**
8
8
  * Computations of screen-space pixel area covered by a sphere
9
9
  * NOTE: Port of GLSL code by Ingo Quilez. Source: http://www.iquilezles.org/www/articles/sphereproj/sphereproj.htm
10
- * @param {Vector4} sph Sphere in world space
11
- * @param {Matrix4} cam camera transform matrix (world to camera)(inverse world matrix of camera)
10
+ * @param {number[]|{0:number,1:number,2:number,3:number}} sph Sphere in world space
11
+ * @param {number[]|Float32Array} cam camera transform matrix (world to camera)(inverse world matrix of camera)
12
12
  * @param {number} fl focal length (fov in Radians)
13
13
  * @returns {number} area on the screen as a fraction, 1=entire screen, 0=zero area
14
14
  */
15
15
  export function sphere_project(sph, cam, fl) {
16
16
  assert.notNull(cam, 'cam');
17
+ assert.isNumber(fl, 'fl');
18
+ assert.greaterThan(fl, 0, 'fl');
17
19
 
18
- v4[0] = sph.x;
19
- v4[1] = sph.y;
20
- v4[2] = sph.z;
20
+ v4[0] = sph[0];
21
+ v4[1] = sph[1];
22
+ v4[2] = sph[2];
21
23
  v4[3] = 1;
22
24
 
23
25
  //transform to camera space
24
- v4_multiply_mat4(v4, v4, cam.elements);
26
+ v4_multiply_mat4(v4, v4, cam);
25
27
 
26
- const r2 = sph.w * sph.w;
28
+ const r = sph[3];
29
+ const r2 = r * r;
27
30
 
28
31
  const v4_x = v4[0];
29
32
  const v4_y = v4[1];
@@ -33,7 +36,14 @@ export function sphere_project(sph, cam, fl) {
33
36
 
34
37
  const l2 = v3_dot(v4_x, v4_y, v4_z, v4_x, v4_y, v4_z);
35
38
 
36
- const area = -Math.PI * fl * fl * r2 * Math.sqrt(Math.abs((l2 - r2) / (r2 - z2))) / (r2 - z2);
39
+ const rz2 = r2 - z2;
37
40
 
38
- return area;
41
+ if (rz2 === 0) {
42
+ // avoid division by 0
43
+ return 0;
44
+ }
45
+
46
+ const area = -Math.PI * fl * fl * r2 * Math.sqrt(Math.abs((l2 - r2) / rz2)) / rz2;
47
+
48
+ return Math.abs(area);
39
49
  }
@@ -54,7 +54,7 @@ export class Quadratic3 {
54
54
  /**
55
55
  * Find optimal vertex position based on the quadratic
56
56
  *
57
- * Based on Bleder's implementation: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/blenlib/intern/quadric.c
57
+ * Based on Blender's implementation: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/blenlib/intern/quadric.c
58
58
  *
59
59
  * @param {number[]} out
60
60
  * @returns {boolean}
@@ -1 +1 @@
1
- {"version":3,"file":"Quadratic3.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/geom/3d/topology/simplify/quadratic/Quadratic3.js"],"names":[],"mappings":"AAQA;;;GAGG;AACH;IAGI,WAAO;IACP,WAAO;IACP,WAAO;IACP,WAAO;IAGP,WAAO;IACP,WAAO;IACP,WAAO;IAGP,WAAO;IACP,WAAO;IAGP,WAAO;IAGP;;;OAGG;IACH,kBAFW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,YAAY,QAMjD;IAED;;;OAGG;IACH,eAFW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,YAAY,QAcjD;IAED;;;;;OAKG;IACH,sBAJW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,YAAY,WACvC,MAAM,GACJ,OAAO,CAkCnB;IAED;;;;;;OAMG;IACH,kBALW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB;IAED;;;OAGG;IACH,sCAmBC;IAED;;;;;;OAMG;IACH,YALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CASlB;IAED;;;;;;;OAOG;IACH,cAHW,MAAM,EAAE,GACN,OAAO,CAiBnB;IAED;;;OAGG;IACH,OAFW,UAAU,QAuBpB;IAED;;;OAGG;IACH,kBAFW,MAAM,QAoBhB;IAED;;;OAGG;IACH,SAFa,UAAU,CAQtB;IAED;;;OAGG;IACH,YAFW,UAAU,QAqBpB;IAED;;OAEG;IACH,cAmBC;CACJ"}
1
+ {"version":3,"file":"Quadratic3.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/geom/3d/topology/simplify/quadratic/Quadratic3.js"],"names":[],"mappings":"AASA;;;GAGG;AACH;IAGI,WAAO;IACP,WAAO;IACP,WAAO;IACP,WAAO;IAGP,WAAO;IACP,WAAO;IACP,WAAO;IAGP,WAAO;IACP,WAAO;IAGP,WAAO;IAGP;;;OAGG;IACH,kBAFW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,YAAY,QAMjD;IAED;;;OAGG;IACH,eAFW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,YAAY,QAcjD;IAED;;;;;OAKG;IACH,sBAJW,UAAU,MAAM,CAAC,GAAC,MAAM,EAAE,GAAC,YAAY,WACvC,MAAM,GACJ,OAAO,CAkCnB;IAED;;;;;;OAMG;IACH,kBALW,MAAM,KACN,MAAM,KACN,MAAM,KACN,MAAM,QAgBhB;IAED;;;OAGG;IACH,sCAmBC;IAED;;;;;;OAMG;IACH,YALW,MAAM,KACN,MAAM,KACN,MAAM,GACJ,MAAM,CASlB;IAED;;;;;;;OAOG;IACH,cAHW,MAAM,EAAE,GACN,OAAO,CAgBnB;IAED;;;OAGG;IACH,OAFW,UAAU,QAuBpB;IAED;;;OAGG;IACH,kBAFW,MAAM,QAoBhB;IAED;;;OAGG;IACH,SAFa,UAAU,CAQtB;IAED;;;OAGG;IACH,YAFW,UAAU,QAqBpB;IAED;;OAEG;IACH,cAmBC;CACJ"}
@@ -5,6 +5,7 @@ import { v3_dot } from "../../../../vec3/v3_dot.js";
5
5
  import { compute_triangle_normal } from "../../../compute_triangle_normal.js";
6
6
 
7
7
  const scratch_v3 = new Float32Array(3);
8
+ const scratch_m3 = new Float32Array(9);
8
9
 
9
10
  /**
10
11
  * Quadric Error Metric
@@ -166,19 +167,18 @@ export class Quadratic3 {
166
167
  /**
167
168
  * Find optimal vertex position based on the quadratic
168
169
  *
169
- * Based on Bleder's implementation: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/blenlib/intern/quadric.c
170
+ * Based on Blender's implementation: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/blenlib/intern/quadric.c
170
171
  *
171
172
  * @param {number[]} out
172
173
  * @returns {boolean}
173
174
  */
174
175
  optimize(out) {
175
- const m = new Float32Array(9);
176
176
 
177
- if (this.toTensorM3Inverse(m, EPSILON)) {
177
+ if (this.toTensorM3Inverse(scratch_m3, EPSILON)) {
178
178
 
179
179
  this.toVector3(out);
180
180
 
181
- vec3.transformMat3(out, out, m);
181
+ vec3.transformMat3(out, out, scratch_m3);
182
182
  vec3.negate(out, out);
183
183
 
184
184
  return true;
@@ -286,7 +286,7 @@ class AnimationSystem extends System {
286
286
  v4boundingSphere.multiplyScalar(scaleMax);
287
287
  v4boundingSphere.add3(position);
288
288
 
289
- const area = sphere_project(v4boundingSphere, cameraMatrix, focalLength);
289
+ const area = sphere_project(v4boundingSphere, cameraMatrix.elements, focalLength);
290
290
  const inPixels = area * viewportSize.x * viewportSize.y;
291
291
  return inPixels;
292
292
  }
@@ -240,7 +240,7 @@ export class AnimationGraphSystem extends System {
240
240
  v4boundingSphere.multiplyScalar(scaleMax);
241
241
  v4boundingSphere.add3(position);
242
242
 
243
- const area = sphere_project(v4boundingSphere, cameraMatrix, this.__focalLength);
243
+ const area = sphere_project(v4boundingSphere, cameraMatrix.elements, this.__focalLength);
244
244
 
245
245
  /**
246
246
  *
@@ -1 +1 @@
1
- {"version":3,"file":"query_bvh_geometry_nearest.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;;GAWG;AACH,uFARW,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,EAAE,GAAC,WAAW,GAAC,WAAW,KAChC,MAAM,KACN,MAAM,KACN,MAAM,gBACN,MAAM,GACL,OAAO,CA8KlB"}
1
+ {"version":3,"file":"query_bvh_geometry_nearest.d.ts","sourceRoot":"","sources":["../../../../../../../src/engine/graphics/geometry/buffered/query/query_bvh_geometry_nearest.js"],"names":[],"mappings":"AAwBA;;;;;;;;;;;GAWG;AACH,uFARW,MAAM,EAAE,GAAC,YAAY,WACrB,MAAM,EAAE,GAAC,WAAW,GAAC,WAAW,KAChC,MAAM,KACN,MAAM,KACN,MAAM,gBACN,MAAM,GACL,OAAO,CA+KlB"}
@@ -140,10 +140,11 @@ export function query_bvh_geometry_nearest(
140
140
  // leaf node
141
141
  // read triangle data
142
142
  const triangle_index = uint32[address + COLUMN_USER_DATA];
143
+ const index_offset = triangle_index*3;
143
144
 
144
- const a = indices[triangle_index];
145
- const b = indices[triangle_index + 1];
146
- const c = indices[triangle_index + 2];
145
+ const a = indices[index_offset];
146
+ const b = indices[index_offset + 1];
147
+ const c = indices[index_offset + 2];
147
148
 
148
149
 
149
150
  const a_address = a * 3;