@woosh/meep-engine 2.133.3 → 2.134.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 (89) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -1
  2. package/package.json +2 -2
  3. package/src/core/binary/BinaryBuffer.d.ts +20 -0
  4. package/src/core/binary/BinaryBuffer.d.ts.map +1 -1
  5. package/src/core/binary/BinaryBuffer.js +50 -0
  6. package/src/core/binary/BitSet.d.ts +6 -0
  7. package/src/core/binary/BitSet.d.ts.map +1 -1
  8. package/src/core/binary/BitSet.js +38 -1
  9. package/src/core/binary/operations/bitCount.d.ts.map +1 -1
  10. package/src/core/binary/operations/bitCount.js +11 -6
  11. package/src/core/geom/3d/aabb/AABB3.d.ts +7 -1
  12. package/src/core/geom/3d/aabb/AABB3.d.ts.map +1 -1
  13. package/src/core/geom/3d/aabb/AABB3.js +14 -1
  14. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.d.ts +4 -4
  15. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.d.ts.map +1 -1
  16. package/src/core/geom/3d/topology/simplify/EdgeCollapseCandidate.js +2 -2
  17. package/src/core/geom/3d/topology/simplify/build_edge_collapse_candidates.d.ts +2 -2
  18. package/src/core/geom/3d/topology/simplify/build_edge_collapse_candidates.d.ts.map +1 -1
  19. package/src/core/geom/3d/topology/simplify/build_edge_collapse_candidates.js +1 -1
  20. package/src/core/geom/3d/topology/simplify/computeEdgeCollapseCost.d.ts +2 -2
  21. package/src/core/geom/3d/topology/simplify/computeEdgeCollapseCost.d.ts.map +1 -1
  22. package/src/core/geom/3d/topology/simplify/computeEdgeCollapseCost.js +1 -1
  23. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts +4 -4
  24. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.d.ts.map +1 -1
  25. package/src/core/geom/3d/topology/simplify/decimate_edge_collapse_snap.js +3 -3
  26. package/src/core/geom/3d/topology/simplify/quadratic/{Quadratic3.d.ts → Quadric3.d.ts} +55 -29
  27. package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.d.ts.map +1 -0
  28. package/src/core/geom/3d/topology/simplify/quadratic/Quadric3.js +307 -0
  29. package/src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.d.ts +7 -7
  30. package/src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.d.ts.map +1 -1
  31. package/src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js +39 -13
  32. package/src/core/geom/3d/topology/simplify/quadratic/compute_edge_collapse_cost_quadratic.d.ts +2 -2
  33. package/src/core/geom/3d/topology/simplify/quadratic/compute_edge_collapse_cost_quadratic.d.ts.map +1 -1
  34. package/src/core/geom/3d/topology/simplify/quadratic/compute_edge_collapse_cost_quadratic.js +1 -1
  35. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts +2 -2
  36. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.d.ts.map +1 -1
  37. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh.js +2 -2
  38. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh2.d.ts +4 -4
  39. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh2.d.ts.map +1 -1
  40. package/src/core/geom/3d/topology/simplify/simplifyTopoMesh2.js +5 -5
  41. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_face_normals.d.ts +8 -0
  42. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_face_normals.d.ts.map +1 -0
  43. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_face_normals.js +56 -0
  44. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadratics.d.ts +14 -0
  45. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadratics.d.ts.map +1 -0
  46. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_vertex_quadratics.js +95 -0
  47. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts +17 -0
  48. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.d.ts.map +1 -0
  49. package/src/core/geom/3d/topology/struct/binary/io/bt_mesh_simplify.js +352 -0
  50. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_collapse.d.ts +21 -0
  51. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_collapse.d.ts.map +1 -0
  52. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_collapse.js +52 -0
  53. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts +16 -0
  54. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.d.ts.map +1 -0
  55. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_edge_kill_parallels.js +90 -0
  56. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_fuse_duplicate_edges.d.ts +19 -0
  57. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_fuse_duplicate_edges.d.ts.map +1 -0
  58. package/src/core/geom/3d/topology/struct/binary/io/edge/bt_mesh_fuse_duplicate_edges.js +83 -0
  59. package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vert_fuse_duplicate_edges.d.ts +22 -0
  60. package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vert_fuse_duplicate_edges.d.ts.map +1 -0
  61. package/src/core/geom/3d/topology/struct/binary/io/vertex/bt_vert_fuse_duplicate_edges.js +148 -0
  62. package/src/core/geom/3d/topology/struct/binary/query/bt_face_get_incenter.js +4 -4
  63. package/src/core/geom/3d/topology/struct/binary/query/bt_faces_shared_loop.d.ts +15 -0
  64. package/src/core/geom/3d/topology/struct/binary/query/bt_faces_shared_loop.d.ts.map +1 -0
  65. package/src/core/geom/3d/topology/struct/binary/query/bt_faces_shared_loop.js +48 -0
  66. package/src/engine/ecs/terrain/ecs/Terrain.d.ts.map +1 -1
  67. package/src/engine/ecs/terrain/ecs/Terrain.js +6 -1
  68. package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.d.ts.map +1 -1
  69. package/src/engine/ecs/terrain/ecs/layers/TerrainLayer.js +10 -9
  70. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.d.ts.map +1 -1
  71. package/src/engine/ecs/terrain/ecs/layers/TerrainLayers.js +14 -11
  72. package/src/engine/graphics/ecs/water/WaterSystem.d.ts.map +1 -1
  73. package/src/engine/graphics/ecs/water/WaterSystem.js +3 -0
  74. package/src/engine/graphics/material/SplatMaterial.d.ts.map +1 -1
  75. package/src/engine/graphics/material/SplatMaterial.js +2 -4
  76. package/src/engine/graphics/shaders/TerrainShader.js +4 -11
  77. package/src/engine/navigation/mesh/NavigationMesh.d.ts +6 -4
  78. package/src/engine/navigation/mesh/NavigationMesh.d.ts.map +1 -1
  79. package/src/engine/navigation/mesh/NavigationMesh.js +212 -190
  80. package/src/engine/navigation/mesh/build/navmesh_build_topology.d.ts.map +1 -1
  81. package/src/engine/navigation/mesh/build/navmesh_build_topology.js +20 -7
  82. package/src/engine/navigation/mesh/bvh_query_nearest_face.d.ts +15 -0
  83. package/src/engine/navigation/mesh/bvh_query_nearest_face.d.ts.map +1 -0
  84. package/src/engine/navigation/mesh/bvh_query_nearest_face.js +131 -0
  85. package/src/engine/physics/gjk/gjk.d.ts +16 -0
  86. package/src/engine/physics/gjk/gjk.d.ts.map +1 -0
  87. package/src/engine/physics/gjk/gjk.js +378 -0
  88. package/src/core/geom/3d/topology/simplify/quadratic/Quadratic3.d.ts.map +0 -1
  89. package/src/core/geom/3d/topology/simplify/quadratic/Quadratic3.js +0 -302
@@ -0,0 +1,307 @@
1
+ import { vec3 } from "gl-matrix";
2
+ import { EPSILON } from "../../../../../math/EPSILON.js";
3
+ import { fabsf } from "../../../../../math/fabsf.js";
4
+
5
+ const scratch_m3 = new Float32Array(9);
6
+
7
+ /**
8
+ * Quadric Error Metric
9
+ * Upper-triangular portion of a symmetric 4x4 matrix encoding a quadric form.
10
+ *
11
+ * Layout (10 elements):
12
+ * [0]=a2 [1]=ab [2]=ac [3]=ad
13
+ * [4]=b2 [5]=bc [6]=bd
14
+ * [7]=c2 [8]=cd
15
+ * [9]=d2
16
+ */
17
+ export class Quadric3 extends Float64Array {
18
+ constructor() {
19
+ super(10);
20
+ }
21
+
22
+ get a2() {
23
+ return this[0];
24
+ }
25
+
26
+ set a2(v) {
27
+ this[0] = v;
28
+ }
29
+
30
+ get ab() {
31
+ return this[1];
32
+ }
33
+
34
+ set ab(v) {
35
+ this[1] = v;
36
+ }
37
+
38
+ get ac() {
39
+ return this[2];
40
+ }
41
+
42
+ set ac(v) {
43
+ this[2] = v;
44
+ }
45
+
46
+ get ad() {
47
+ return this[3];
48
+ }
49
+
50
+ set ad(v) {
51
+ this[3] = v;
52
+ }
53
+
54
+ get b2() {
55
+ return this[4];
56
+ }
57
+
58
+ set b2(v) {
59
+ this[4] = v;
60
+ }
61
+
62
+ get bc() {
63
+ return this[5];
64
+ }
65
+
66
+ set bc(v) {
67
+ this[5] = v;
68
+ }
69
+
70
+ get bd() {
71
+ return this[6];
72
+ }
73
+
74
+ set bd(v) {
75
+ this[6] = v;
76
+ }
77
+
78
+ get c2() {
79
+ return this[7];
80
+ }
81
+
82
+ set c2(v) {
83
+ this[7] = v;
84
+ }
85
+
86
+ get cd() {
87
+ return this[8];
88
+ }
89
+
90
+ set cd(v) {
91
+ this[8] = v;
92
+ }
93
+
94
+ get d2() {
95
+ return this[9];
96
+ }
97
+
98
+ set d2(v) {
99
+ this[9] = v;
100
+ }
101
+
102
+ /**
103
+ *
104
+ * @param {ArrayLike<number>|number[]|Float32Array} result
105
+ */
106
+ toVector3(result) {
107
+ result[0] = this[3];
108
+ result[1] = this[6];
109
+ result[2] = this[8];
110
+ }
111
+
112
+ /**
113
+ *
114
+ * @param {ArrayLike<number>|number[]|Float32Array} m3
115
+ */
116
+ toTensorM3(m3) {
117
+ const ab = this[1];
118
+ const ac = this[2];
119
+ const bc = this[5];
120
+
121
+ m3[0] = this[0];
122
+ m3[1] = ab;
123
+ m3[2] = ac;
124
+
125
+ m3[3] = ab;
126
+ m3[4] = this[4];
127
+ m3[5] = bc;
128
+
129
+ m3[6] = ac;
130
+ m3[7] = bc;
131
+ m3[8] = this[7];
132
+ }
133
+
134
+ /**
135
+ * Equivalent to taking a tensor followed by matrix inversion
136
+ * @param {ArrayLike<number>|number[]|Float32Array} m3
137
+ * @param {number} epsilon
138
+ * @returns {boolean} whether operation was successful or not
139
+ */
140
+ toTensorM3Inverse(m3, epsilon) {
141
+ const a2 = this[0];
142
+ const ab = this[1];
143
+ const ac = this[2];
144
+ const b2 = this[4];
145
+ const bc = this[5];
146
+ const c2 = this[7];
147
+
148
+ const det = a2 * (b2 * c2 - bc * bc) -
149
+ ab * (ab * c2 - ac * bc) +
150
+ ac * (ab * bc - ac * b2);
151
+
152
+ if (fabsf(det) > epsilon) {
153
+ // avoid division by zero
154
+
155
+ const invdet = 1.0 / det;
156
+
157
+ m3[0] = (b2 * c2 - bc * bc) * invdet;
158
+ m3[3] = (bc * ac - ab * c2) * invdet;
159
+ m3[6] = (ab * bc - b2 * ac) * invdet;
160
+
161
+ m3[1] = (ac * bc - ab * c2) * invdet;
162
+ m3[4] = (a2 * c2 - ac * ac) * invdet;
163
+ m3[7] = (ab * ac - a2 * bc) * invdet;
164
+
165
+ m3[2] = (ab * bc - ac * b2) * invdet;
166
+ m3[5] = (ac * ab - a2 * bc) * invdet;
167
+ m3[8] = (a2 * b2 - ab * ab) * invdet;
168
+
169
+ return true;
170
+ }
171
+
172
+ // determinant is zero, matrix is singular, cannot invert
173
+
174
+ return false;
175
+ }
176
+
177
+ /**
178
+ * Set from plane expressed as a 4 component vector
179
+ * @param {number} x plane normal
180
+ * @param {number} y plane normal
181
+ * @param {number} z plane normal
182
+ * @param {number} w plane offset
183
+ */
184
+ setFromVector4(x, y, z, w) {
185
+ this[0] = x * x;
186
+ this[1] = x * y;
187
+ this[2] = x * z;
188
+ this[3] = x * w;
189
+
190
+ this[4] = y * y;
191
+ this[5] = y * z;
192
+ this[6] = y * w;
193
+
194
+ this[7] = z * z;
195
+ this[8] = z * w;
196
+
197
+ this[9] = w * w;
198
+ }
199
+
200
+ /**
201
+ * Squared distance from the given point to plane encoded by the quadric
202
+ * @param {number} x
203
+ * @param {number} y
204
+ * @param {number} z
205
+ * @returns {number}
206
+ */
207
+ evaluate(x, y, z) {
208
+ // Evaluate vAv + 2bv + c
209
+
210
+ return (x * x * this[0]) + (2 * x * y * this[1]) + (2 * x * z * this[2]) + (2 * x * this[3]) // A
211
+ + (y * y * this[4]) + (2 * y * z * this[5]) + (2 * y * this[6]) // B
212
+ + (z * z * this[7]) + (2 * z * this[8]) // C
213
+ + this[9]; // D
214
+ }
215
+
216
+ /**
217
+ * Find the optimal vertex position based on the quadric
218
+ *
219
+ * @param {number[]} out vector3
220
+ * @returns {boolean}
221
+ */
222
+ optimize(out) {
223
+
224
+ // Based on Blender's implementation: https://github.com/blender/blender/blob/594f47ecd2d5367ca936cf6fc6ec8168c2b360d0/source/blender/blenlib/intern/quadric.c
225
+
226
+ if (this.toTensorM3Inverse(scratch_m3, EPSILON)) {
227
+
228
+ this.toVector3(out);
229
+
230
+ vec3.transformMat3(out, out, scratch_m3);
231
+ vec3.negate(out, out);
232
+
233
+ return true;
234
+ }
235
+
236
+ return false;
237
+
238
+ }
239
+
240
+ /**
241
+ *
242
+ * @param {Quadric3} Q
243
+ */
244
+ add(Q) {
245
+ this[0] += Q[0];
246
+ this[1] += Q[1];
247
+ this[2] += Q[2];
248
+ this[3] += Q[3];
249
+ this[4] += Q[4];
250
+ this[5] += Q[5];
251
+ this[6] += Q[6];
252
+ this[7] += Q[7];
253
+ this[8] += Q[8];
254
+ this[9] += Q[9];
255
+ }
256
+
257
+ /**
258
+ *
259
+ * @param {number} v
260
+ */
261
+ multiplyScalar(v) {
262
+ this[0] *= v;
263
+ this[1] *= v;
264
+ this[2] *= v;
265
+ this[3] *= v;
266
+ this[4] *= v;
267
+ this[5] *= v;
268
+ this[6] *= v;
269
+ this[7] *= v;
270
+ this[8] *= v;
271
+ this[9] *= v;
272
+ }
273
+
274
+ /**
275
+ *
276
+ * @returns {Quadric3}
277
+ */
278
+ clone() {
279
+ const r = new Quadric3();
280
+
281
+ r.copy(this);
282
+
283
+ return r;
284
+ }
285
+
286
+ /**
287
+ *
288
+ * @param {Quadric3} other
289
+ */
290
+ copy(other) {
291
+ this.set(other);
292
+ }
293
+
294
+ /**
295
+ * Set all matrix values to 0
296
+ */
297
+ clear() {
298
+ this.fill(0);
299
+ }
300
+ }
301
+
302
+ /**
303
+ * Useful for type checking
304
+ * @readonly
305
+ * @type {boolean}
306
+ */
307
+ Quadric3.prototype.isQuadric3 = true;
@@ -1,25 +1,25 @@
1
1
  /**
2
2
  *
3
- * @param {Map<number, Quadratic3>} destination
4
- * @param {Map<number, Quadratic3>} source
3
+ * @param {Map<number, Quadric3>} destination
4
+ * @param {Map<number, Quadric3>} source
5
5
  * @param {TopoMesh} mesh
6
6
  */
7
- export function deep_copy_vertex_quadratics(destination: Map<number, Quadratic3>, source: Map<number, Quadratic3>, mesh: TopoMesh): void;
7
+ export function deep_copy_vertex_quadratics(destination: Map<number, Quadric3>, source: Map<number, Quadric3>, mesh: TopoMesh): void;
8
8
  /**
9
9
  *
10
10
  * @param {TopoMesh} mesh
11
11
  * @param {TopoEdge[]} border_set
12
- * @param {Map<number, Quadratic3>} vertex_quadratics
12
+ * @param {Map<number, Quadric3>} vertex_quadratics
13
13
  * @param {number} [weight]
14
14
  */
15
- export function apply_border_penalties_to_vertex_quadrics(mesh: TopoMesh, border_set: TopoEdge[], vertex_quadratics: Map<number, Quadratic3>, weight?: number): void;
15
+ export function apply_border_penalties_to_vertex_quadrics(mesh: TopoMesh, border_set: TopoEdge[], vertex_quadratics: Map<number, Quadric3>, weight?: number): void;
16
16
  /**
17
17
  *
18
18
  * @param {TopoMesh} mesh
19
- * @param {Map<number, Quadratic3>} quadratics VertexID -> Quadratic map
19
+ * @param {Map<number, Quadric3>} quadratics VertexID -> Quadratic map
20
20
  * @param {boolean} [use_triangle_area]
21
21
  * @param {boolean} [use_border_constraints]
22
22
  */
23
23
  export function build_vertex_quadratics({ mesh, quadratics, use_triangle_area, use_border_constraints }: TopoMesh): void;
24
- import { Quadratic3 } from "./Quadratic3.js";
24
+ import { Quadric3 } from "./Quadric3.js";
25
25
  //# sourceMappingURL=build_vertex_quadratics.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build_vertex_quadratics.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,yDAJW,IAAI,MAAM,EAAE,UAAU,CAAC,UACvB,IAAI,MAAM,EAAE,UAAU,CAAC,wBAgBjC;AA8CD;;;;;;GAMG;AACH,sFAJW,UAAU,qBACV,IAAI,MAAM,EAAE,UAAU,CAAC,WACvB,MAAM,QAQhB;AAED;;;;;;GAMG;AACH,yHAwDC;2BAtJ0B,iBAAiB"}
1
+ {"version":3,"file":"build_vertex_quadratics.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/geom/3d/topology/simplify/quadratic/build_vertex_quadratics.js"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,yDAJW,IAAI,MAAM,EAAE,QAAQ,CAAC,UACrB,IAAI,MAAM,EAAE,QAAQ,CAAC,wBAgB/B;AA8CD;;;;;;GAMG;AACH,sFAJW,UAAU,qBACV,IAAI,MAAM,EAAE,QAAQ,CAAC,WACrB,MAAM,QAQhB;AA2BD;;;;;;GAMG;AACH,yHAwDC;yBA1KwB,eAAe"}
@@ -1,14 +1,15 @@
1
- import { Quadratic3 } from "./Quadratic3.js";
2
- import { tm_face_area } from "../../tm_face_area.js";
3
- import { assert } from "../../../../../assert.js";
4
- import { tm_face_normal } from "../../tm_face_normal.js";
5
1
  import { vec3 } from "gl-matrix";
2
+ import { assert } from "../../../../../assert.js";
3
+ import { v3_dot } from "../../../../vec3/v3_dot.js";
6
4
  import { query_edge_is_boundary } from "../../query/query_edge_is_boundary.js";
5
+ import { tm_face_area } from "../../tm_face_area.js";
6
+ import { tm_face_normal } from "../../tm_face_normal.js";
7
+ import { Quadric3 } from "./Quadric3.js";
7
8
 
8
9
  /**
9
10
  *
10
- * @param {Map<number, Quadratic3>} destination
11
- * @param {Map<number, Quadratic3>} source
11
+ * @param {Map<number, Quadric3>} destination
12
+ * @param {Map<number, Quadric3>} source
12
13
  * @param {TopoMesh} mesh
13
14
  */
14
15
  export function deep_copy_vertex_quadratics(destination, source, mesh) {
@@ -31,7 +32,7 @@ export function deep_copy_vertex_quadratics(destination, source, mesh) {
31
32
  * @see "Boundary and Texture Preserving Mesh Simplification Algorithm for Virtual Reality" by Kanchan Bahirat et.al. University of Texas/Dallas
32
33
  * @param {TopoEdge} edge
33
34
  * @param {number} weight
34
- * @param {Map<number, Quadratic3>} vertex_quadratics
35
+ * @param {Map<number, Quadric3>} vertex_quadratics
35
36
  */
36
37
  function apply_border_penalty_to_vertex_quadrics(edge, weight, vertex_quadratics) {
37
38
  const v0 = edge.v0;
@@ -57,7 +58,7 @@ function apply_border_penalty_to_vertex_quadrics(edge, weight, vertex_quadratics
57
58
 
58
59
  const d = -vec3.dot(abc, v0);
59
60
 
60
- const constraint = new Quadratic3();
61
+ const constraint = new Quadric3();
61
62
  constraint.setFromVector4(abc[0], abc[1], abc[2], d);
62
63
  constraint.multiplyScalar(vec3.length(edge_vector) * weight);
63
64
  // constraint.multiplyScalar(weight);
@@ -74,7 +75,7 @@ function apply_border_penalty_to_vertex_quadrics(edge, weight, vertex_quadratics
74
75
  *
75
76
  * @param {TopoMesh} mesh
76
77
  * @param {TopoEdge[]} border_set
77
- * @param {Map<number, Quadratic3>} vertex_quadratics
78
+ * @param {Map<number, Quadric3>} vertex_quadratics
78
79
  * @param {number} [weight]
79
80
  */
80
81
  export function apply_border_penalties_to_vertex_quadrics(mesh, border_set, vertex_quadratics, weight = 10) {
@@ -85,10 +86,35 @@ export function apply_border_penalties_to_vertex_quadrics(mesh, border_set, vert
85
86
  }
86
87
  }
87
88
 
89
+ /**
90
+ *
91
+ * @param {Quadric3} quadric
92
+ * @param {TopoTriangle} face
93
+ */
94
+ function quadric_set_from_face(quadric, face){
95
+ const v0 = face.vertices[0];
96
+
97
+ // compute triangle's plane
98
+ face.computeNormal();
99
+
100
+ // compute plane offset
101
+ const normal_x = face.normal[0];
102
+ const normal_y = face.normal[1];
103
+ const normal_z = face.normal[2];
104
+
105
+ const plane_constant = -v3_dot(
106
+ normal_x, normal_y, normal_z,
107
+
108
+ v0.x, v0.y, v0.z
109
+ );
110
+
111
+ quadric.setFromVector4(normal_x, normal_y, normal_z, plane_constant);
112
+ }
113
+
88
114
  /**
89
115
  *
90
116
  * @param {TopoMesh} mesh
91
- * @param {Map<number, Quadratic3>} quadratics VertexID -> Quadratic map
117
+ * @param {Map<number, Quadric3>} quadratics VertexID -> Quadratic map
92
118
  * @param {boolean} [use_triangle_area]
93
119
  * @param {boolean} [use_border_constraints]
94
120
  */
@@ -108,19 +134,19 @@ export function build_vertex_quadratics({
108
134
  for (i = 0; i < mesh_vertex_count; i++) {
109
135
  const mesh_vertex = mesh_vertices[i];
110
136
 
111
- const vertex_quadratic = new Quadratic3();
137
+ const vertex_quadratic = new Quadric3();
112
138
 
113
139
  quadratics.set(mesh_vertex.index, vertex_quadratic);
114
140
  }
115
141
 
116
142
  // compute values for quadratics
117
- const q = new Quadratic3();
143
+ const q = new Quadric3();
118
144
 
119
145
  const faces = mesh.getFaces();
120
146
 
121
147
  for (face of faces) {
122
148
 
123
- q.setFromFace(face);
149
+ quadric_set_from_face(q,face);
124
150
 
125
151
  if (use_triangle_area) {
126
152
  const triangle_area = tm_face_area(face);
@@ -3,8 +3,8 @@
3
3
  * @param {TopoVertex} v0
4
4
  * @param {TopoVertex} v1
5
5
  * @param {TopoVertex} target where to collapse v0 and v1 to
6
- * @param {Map<number,Quadratic3>} quadratics
6
+ * @param {Map<number,Quadric3>} quadratics
7
7
  * @returns {number}
8
8
  */
9
- export function compute_edge_collapse_cost_quadratic(v0: TopoVertex, v1: TopoVertex, target: TopoVertex, quadratics: Map<number, Quadratic3>): number;
9
+ export function compute_edge_collapse_cost_quadratic(v0: TopoVertex, v1: TopoVertex, target: TopoVertex, quadratics: Map<number, Quadric3>): number;
10
10
  //# sourceMappingURL=compute_edge_collapse_cost_quadratic.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"compute_edge_collapse_cost_quadratic.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/geom/3d/topology/simplify/quadratic/compute_edge_collapse_cost_quadratic.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qHAHW,IAAI,MAAM,aAAY,GACpB,MAAM,CAqBlB"}
1
+ {"version":3,"file":"compute_edge_collapse_cost_quadratic.d.ts","sourceRoot":"","sources":["../../../../../../../../src/core/geom/3d/topology/simplify/quadratic/compute_edge_collapse_cost_quadratic.js"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qHAHW,IAAI,MAAM,WAAU,GAClB,MAAM,CAqBlB"}
@@ -3,7 +3,7 @@
3
3
  * @param {TopoVertex} v0
4
4
  * @param {TopoVertex} v1
5
5
  * @param {TopoVertex} target where to collapse v0 and v1 to
6
- * @param {Map<number,Quadratic3>} quadratics
6
+ * @param {Map<number,Quadric3>} quadratics
7
7
  * @returns {number}
8
8
  */
9
9
  export function compute_edge_collapse_cost_quadratic(
@@ -8,10 +8,10 @@ export function extract_edge_cost(edge: EdgeCollapseCandidate): number;
8
8
  * @param {BinaryHeap<EdgeCollapseCandidate>} heap
9
9
  * @param {TopoMesh} mesh
10
10
  * @param {Map<TopoEdge, EdgeCollapseCandidate>} edge_to_collapse_map
11
- * @param {Map<number, Quadratic3>} vertex_quadratics
11
+ * @param {Map<number, Quadric3>} vertex_quadratics
12
12
  * @param {Set<number>} restricted_vertices
13
13
  */
14
- export function collapse_edges(number_faces_to_remove: number, heap: BinaryHeap<EdgeCollapseCandidate>, mesh: TopoMesh, edge_to_collapse_map: Map<TopoEdge, EdgeCollapseCandidate>, vertex_quadratics: Map<number, Quadratic3>, restricted_vertices: Set<number>): void;
14
+ export function collapse_edges(number_faces_to_remove: number, heap: BinaryHeap<EdgeCollapseCandidate>, mesh: TopoMesh, edge_to_collapse_map: Map<TopoEdge, EdgeCollapseCandidate>, vertex_quadratics: Map<number, Quadric3>, restricted_vertices: Set<number>): void;
15
15
  /**
16
16
  * Simplifies a given topology mesh by reducing number of faces. Preserves original vertices
17
17
  * NOTE: preserves outline of the mesh, that is the open edge
@@ -1 +1 @@
1
- {"version":3,"file":"simplifyTopoMesh.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/topology/simplify/simplifyTopoMesh.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH,wCAFW,qBAAqB,UAI/B;AAGD;;;;;;;GAOG;AACH,uDAPW,MAAM,QACN,WAAW,qBAAqB,CAAC,wCAEjC,cAAc,qBAAqB,CAAC,qBACpC,IAAI,MAAM,aAAa,uBACvB,IAAI,MAAM,CAAC,QAyKrB;AAED;;;;;;;GAOG;AACH,sEAHW,MAAM,wBACN,IAAI,MAAM,CAAC,QAwDrB;sCAhQqC,4BAA4B;uBAL3C,2CAA2C"}
1
+ {"version":3,"file":"simplifyTopoMesh.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/topology/simplify/simplifyTopoMesh.js"],"names":[],"mappings":"AAcA;;;GAGG;AACH,wCAFW,qBAAqB,UAI/B;AAGD;;;;;;;GAOG;AACH,uDAPW,MAAM,QACN,WAAW,qBAAqB,CAAC,wCAEjC,cAAc,qBAAqB,CAAC,qBACpC,IAAI,MAAM,WAAW,uBACrB,IAAI,MAAM,CAAC,QAyKrB;AAED;;;;;;;GAOG;AACH,sEAHW,MAAM,wBACN,IAAI,MAAM,CAAC,QAwDrB;sCAhQqC,4BAA4B;uBAL3C,2CAA2C"}
@@ -26,7 +26,7 @@ export function extract_edge_cost(edge) {
26
26
  * @param {BinaryHeap<EdgeCollapseCandidate>} heap
27
27
  * @param {TopoMesh} mesh
28
28
  * @param {Map<TopoEdge, EdgeCollapseCandidate>} edge_to_collapse_map
29
- * @param {Map<number, Quadratic3>} vertex_quadratics
29
+ * @param {Map<number, Quadric3>} vertex_quadratics
30
30
  * @param {Set<number>} restricted_vertices
31
31
  */
32
32
  export function collapse_edges(
@@ -231,7 +231,7 @@ export function simplifyTopoMesh(mesh, num_faces_to_remove, restricted_vertices
231
231
 
232
232
  /**
233
233
  *
234
- * @type {Map<number, Quadratic3>}
234
+ * @type {Map<number, Quadric3>}
235
235
  */
236
236
  const vertex_quadratics = new Map();
237
237
 
@@ -3,10 +3,10 @@
3
3
  * @param {Iterable<TopoEdge>} edges
4
4
  * @param {Set<number>} restricted_vertices
5
5
  * @param {Uint32Heap} heap
6
- * @param {Map<number, Quadratic3>} vertex_quadratics
6
+ * @param {Map<number, Quadric3>} vertex_quadratics
7
7
  * @param {Map<number,TopoEdge>} edge_lookup
8
8
  */
9
- export function edge_collapse_populate_heap(edges: Iterable<TopoEdge>, restricted_vertices: Set<number>, heap: Uint32Heap, vertex_quadratics: Map<number, Quadratic3>, edge_lookup: Map<number, TopoEdge>): void;
9
+ export function edge_collapse_populate_heap(edges: Iterable<TopoEdge>, restricted_vertices: Set<number>, heap: Uint32Heap, vertex_quadratics: Map<number, Quadric3>, edge_lookup: Map<number, TopoEdge>): void;
10
10
  /**
11
11
  *
12
12
  * @param {TopoMesh} mesh
@@ -14,9 +14,9 @@ export function edge_collapse_populate_heap(edges: Iterable<TopoEdge>, restricte
14
14
  * @param {Uint32Heap} heap
15
15
  * @param {Map<number,TopoEdge>} edge_lookup
16
16
  * @param {Set<number>} restricted_vertices
17
- * @param {Map<number, Quadratic3>} vertex_quadratics
17
+ * @param {Map<number, Quadric3>} vertex_quadratics
18
18
  */
19
- export function edge_collapse_reduce_face_count(mesh: TopoMesh, num_faces_to_remove: number, heap: Uint32Heap, edge_lookup: Map<number, TopoEdge>, restricted_vertices: Set<number>, vertex_quadratics: Map<number, Quadratic3>): void;
19
+ export function edge_collapse_reduce_face_count(mesh: TopoMesh, num_faces_to_remove: number, heap: Uint32Heap, edge_lookup: Map<number, TopoEdge>, restricted_vertices: Set<number>, vertex_quadratics: Map<number, Quadric3>): void;
20
20
  /**
21
21
  * Simplifies a given topology mesh by reducing number of faces. Preserves original vertices
22
22
  * NOTE: preserves outline of the mesh, that is the open edge
@@ -1 +1 @@
1
- {"version":3,"file":"simplifyTopoMesh2.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/topology/simplify/simplifyTopoMesh2.js"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,mDANW,kBAAkB,uBAClB,IAAI,MAAM,CAAC,QACX,UAAU,qBACV,IAAI,MAAM,aAAa,eACvB,IAAI,MAAM,WAAU,QAsB9B;AAED;;;;;;;;GAQG;AACH,qFANW,MAAM,QACN,UAAU,eACV,IAAI,MAAM,WAAU,uBACpB,IAAI,MAAM,CAAC,qBACX,IAAI,MAAM,aAAa,QAgCjC;AAED;;;;;;;GAOG;AACH,uEAHW,MAAM,wBACN,IAAI,MAAM,CAAC,QAgCrB;2BAtH0B,2CAA2C"}
1
+ {"version":3,"file":"simplifyTopoMesh2.d.ts","sourceRoot":"","sources":["../../../../../../../src/core/geom/3d/topology/simplify/simplifyTopoMesh2.js"],"names":[],"mappings":"AASA;;;;;;;GAOG;AACH,mDANW,kBAAkB,uBAClB,IAAI,MAAM,CAAC,QACX,UAAU,qBACV,IAAI,MAAM,WAAW,eACrB,IAAI,MAAM,WAAU,QAsB9B;AAED;;;;;;;;GAQG;AACH,qFANW,MAAM,QACN,UAAU,eACV,IAAI,MAAM,WAAU,uBACpB,IAAI,MAAM,CAAC,qBACX,IAAI,MAAM,WAAW,QAgC/B;AAED;;;;;;;GAOG;AACH,uEAHW,MAAM,wBACN,IAAI,MAAM,CAAC,QAgCrB;2BAtH0B,2CAA2C"}
@@ -1,18 +1,18 @@
1
1
  import { Uint32Heap } from "../../../../collection/heap/Uint32Heap.js";
2
- import { build_vertex_quadratics } from "./quadratic/build_vertex_quadratics.js";
2
+ import { max2 } from "../../../../math/max2.js";
3
3
  import {
4
4
  compute_edge_collapse_cost,
5
5
  decimate_edge_collapse_snap,
6
6
  edge_collapse_pick_target_vertex
7
7
  } from "./decimate_edge_collapse_snap.js";
8
- import { max2 } from "../../../../math/max2.js";
8
+ import { build_vertex_quadratics } from "./quadratic/build_vertex_quadratics.js";
9
9
 
10
10
  /**
11
11
  *
12
12
  * @param {Iterable<TopoEdge>} edges
13
13
  * @param {Set<number>} restricted_vertices
14
14
  * @param {Uint32Heap} heap
15
- * @param {Map<number, Quadratic3>} vertex_quadratics
15
+ * @param {Map<number, Quadric3>} vertex_quadratics
16
16
  * @param {Map<number,TopoEdge>} edge_lookup
17
17
  */
18
18
  export function edge_collapse_populate_heap(edges, restricted_vertices, heap, vertex_quadratics, edge_lookup) {
@@ -44,7 +44,7 @@ export function edge_collapse_populate_heap(edges, restricted_vertices, heap, ve
44
44
  * @param {Uint32Heap} heap
45
45
  * @param {Map<number,TopoEdge>} edge_lookup
46
46
  * @param {Set<number>} restricted_vertices
47
- * @param {Map<number, Quadratic3>} vertex_quadratics
47
+ * @param {Map<number, Quadric3>} vertex_quadratics
48
48
  */
49
49
  export function edge_collapse_reduce_face_count(mesh, num_faces_to_remove, heap, edge_lookup, restricted_vertices, vertex_quadratics) {
50
50
  const mesh_faces = mesh.getFaces();
@@ -99,7 +99,7 @@ export function simplifyTopoMesh2(mesh, num_faces_to_remove, restricted_vertices
99
99
  const heap = new Uint32Heap(mesh.getEdges().size);
100
100
  /**
101
101
  *
102
- * @type {Map<number, Quadratic3>}
102
+ * @type {Map<number, Quadric3>}
103
103
  */
104
104
  const vertex_quadratics = new Map();
105
105
 
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Compute face normals for all allocated triangular faces, overwriting any previous value.
3
+ * Non-triangular faces are left untouched.
4
+ *
5
+ * @param {BinaryTopology} mesh
6
+ */
7
+ export function bt_mesh_compute_face_normals(mesh: BinaryTopology): void;
8
+ //# sourceMappingURL=bt_mesh_compute_face_normals.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bt_mesh_compute_face_normals.d.ts","sourceRoot":"","sources":["../../../../../../../../../src/core/geom/3d/topology/struct/binary/io/bt_mesh_compute_face_normals.js"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,yEAwCC"}
@@ -0,0 +1,56 @@
1
+ import { assert } from "../../../../../../assert.js";
2
+ import { v3_compute_triangle_normal } from "../../../../triangle/v3_compute_triangle_normal.js";
3
+ import { NULL_POINTER } from "../BinaryTopology.js";
4
+
5
+ const scratch_normal = new Float32Array(3);
6
+ const scratch_coord_a = new Float32Array(3);
7
+ const scratch_coord_b = new Float32Array(3);
8
+ const scratch_coord_c = new Float32Array(3);
9
+
10
+ /**
11
+ * Compute face normals for all allocated triangular faces, overwriting any previous value.
12
+ * Non-triangular faces are left untouched.
13
+ *
14
+ * @param {BinaryTopology} mesh
15
+ */
16
+ export function bt_mesh_compute_face_normals(mesh) {
17
+ assert.defined(mesh, "mesh");
18
+ assert.notNull(mesh, "mesh");
19
+ assert.equal(mesh.isBinaryTopology, true, "mesh.isBinaryTopology !== true");
20
+
21
+ const face_pool = mesh.faces;
22
+ const face_count = face_pool.size;
23
+
24
+ for (let face_id = 0; face_id < face_count; face_id++) {
25
+ if (!face_pool.is_allocated(face_id)) {
26
+ continue;
27
+ }
28
+
29
+ const loop_a = mesh.face_read_loop(face_id);
30
+
31
+ if (loop_a === NULL_POINTER) {
32
+ continue;
33
+ }
34
+
35
+ const loop_b = mesh.loop_read_next(loop_a);
36
+ const loop_c = mesh.loop_read_next(loop_b);
37
+
38
+ // must be a triangle
39
+ if (mesh.loop_read_next(loop_c) !== loop_a) {
40
+ continue;
41
+ }
42
+
43
+ mesh.vertex_read_coordinate(scratch_coord_a, 0, mesh.loop_read_vertex(loop_a));
44
+ mesh.vertex_read_coordinate(scratch_coord_b, 0, mesh.loop_read_vertex(loop_b));
45
+ mesh.vertex_read_coordinate(scratch_coord_c, 0, mesh.loop_read_vertex(loop_c));
46
+
47
+ v3_compute_triangle_normal(
48
+ scratch_normal, 0,
49
+ scratch_coord_a[0], scratch_coord_a[1], scratch_coord_a[2],
50
+ scratch_coord_b[0], scratch_coord_b[1], scratch_coord_b[2],
51
+ scratch_coord_c[0], scratch_coord_c[1], scratch_coord_c[2]
52
+ );
53
+
54
+ mesh.face_write_normal(face_id, scratch_normal, 0);
55
+ }
56
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Compute a per-vertex quadric error metric from every allocated triangular face.
3
+ *
4
+ * For each triangular face the supporting plane (n, d) is derived from its loop
5
+ * vertices; the corresponding quadric is then accumulated onto each of those
6
+ * three vertices' Quadric3. Non-triangular faces are skipped.
7
+ *
8
+ * @param {BinaryTopology} mesh
9
+ * @returns {Quadric3[]} Array indexed by vertex ID. Entries for unallocated
10
+ * vertex slots are `undefined`.
11
+ */
12
+ export function bt_mesh_compute_vertex_quadratics(mesh: BinaryTopology): Quadric3[];
13
+ import { Quadric3 } from "../../../simplify/quadratic/Quadric3.js";
14
+ //# sourceMappingURL=bt_mesh_compute_vertex_quadratics.d.ts.map