@woosh/meep-engine 2.118.0 → 2.118.1
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 +1 -1
- package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.d.ts +4 -4
- package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.d.ts.map +1 -1
- package/src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js +32 -30
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Move UVs to reduce stretching
|
|
3
3
|
*
|
|
4
|
-
* @param {Float32Array} positions
|
|
5
|
-
* @param {Float32Array} uvs
|
|
6
|
-
* @param {Uint16Array} faces
|
|
4
|
+
* @param {Float64Array|Float32Array|number[]} positions
|
|
5
|
+
* @param {Float64Array|Float32Array|number[]} uvs
|
|
6
|
+
* @param {Uint16Array|Uint32Array|number[]} faces
|
|
7
7
|
* @param {number} [steps] Number of optimization passes to perform
|
|
8
8
|
*/
|
|
9
|
-
export function geometry_optimize_uv_tension(positions: Float32Array, uvs: Float32Array, faces: Uint16Array, steps?: number): void;
|
|
9
|
+
export function geometry_optimize_uv_tension(positions: Float64Array | Float32Array | number[], uvs: Float64Array | Float32Array | number[], faces: Uint16Array | Uint32Array | number[], steps?: number): void;
|
|
10
10
|
//# sourceMappingURL=geometry_optimize_uv_tension.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry_optimize_uv_tension.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wDALW,YAAY,
|
|
1
|
+
{"version":3,"file":"geometry_optimize_uv_tension.d.ts","sourceRoot":"","sources":["../../../../../../src/engine/graphics/geometry/optimization/geometry_optimize_uv_tension.js"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wDALW,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,OAClC,YAAY,GAAC,YAAY,GAAC,MAAM,EAAE,SAClC,WAAW,GAAC,WAAW,GAAC,MAAM,EAAE,UAChC,MAAM,QA0EhB"}
|
|
@@ -5,9 +5,9 @@ import { TopoMesh } from "../../../../core/geom/3d/topology/struct/TopoMesh.js";
|
|
|
5
5
|
/**
|
|
6
6
|
* Move UVs to reduce stretching
|
|
7
7
|
*
|
|
8
|
-
* @param {Float32Array} positions
|
|
9
|
-
* @param {Float32Array} uvs
|
|
10
|
-
* @param {Uint16Array} faces
|
|
8
|
+
* @param {Float64Array|Float32Array|number[]} positions
|
|
9
|
+
* @param {Float64Array|Float32Array|number[]} uvs
|
|
10
|
+
* @param {Uint16Array|Uint32Array|number[]} faces
|
|
11
11
|
* @param {number} [steps] Number of optimization passes to perform
|
|
12
12
|
*/
|
|
13
13
|
export function geometry_optimize_uv_tension(
|
|
@@ -23,61 +23,63 @@ export function geometry_optimize_uv_tension(
|
|
|
23
23
|
topo.build(positions, faces);
|
|
24
24
|
topo.computeEdgeSquaredLengths();
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const vertex_count = positions.length / 3;
|
|
27
27
|
|
|
28
28
|
for (let i = 0; i < steps; i++) {
|
|
29
29
|
|
|
30
|
-
loop_vertices: for (let j = 0; j <
|
|
30
|
+
loop_vertices: for (let j = 0; j < vertex_count; j++) {
|
|
31
31
|
|
|
32
|
-
const
|
|
32
|
+
const v0 = topo.vertices[j];
|
|
33
33
|
|
|
34
34
|
// 1) get attached edges
|
|
35
35
|
|
|
36
|
-
const
|
|
36
|
+
const attached_edges = v0.edges;
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const attached_edge_count = attached_edges.length;
|
|
39
39
|
|
|
40
|
-
if (
|
|
40
|
+
if (attached_edge_count === 0) {
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
// Compute neighbour UV weight based on edge length
|
|
45
45
|
|
|
46
|
-
let
|
|
47
|
-
let
|
|
46
|
+
let sum_u = 0;
|
|
47
|
+
let sum_v = 0;
|
|
48
48
|
|
|
49
|
-
let
|
|
49
|
+
let weight_sum = 0;
|
|
50
50
|
|
|
51
|
-
for (let k = 0; k <
|
|
52
|
-
const attachedEdge = attachedEdges[k];
|
|
51
|
+
for (let k = 0; k < attached_edge_count; k++) {
|
|
53
52
|
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
const edge = attached_edges[k];
|
|
54
|
+
|
|
55
|
+
if (query_edge_is_boundary(edge)) {
|
|
56
|
+
// edge vertex, no adjustment possible
|
|
56
57
|
continue loop_vertices;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
const
|
|
60
|
+
const v1 = query_edge_other_vertex(edge, v0);
|
|
60
61
|
|
|
61
|
-
const
|
|
62
|
+
const other_uv_address = v1.index * 2;
|
|
62
63
|
|
|
63
|
-
const u = uvs[
|
|
64
|
-
const v = uvs[
|
|
64
|
+
const u = uvs[other_uv_address];
|
|
65
|
+
const v = uvs[other_uv_address + 1];
|
|
65
66
|
|
|
66
|
-
const weight = 1 /
|
|
67
|
+
const weight = 1 / edge.lengthSqr;
|
|
67
68
|
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
sum_u += u * weight;
|
|
70
|
+
sum_v += v * weight;
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
weight_sum += weight;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
//compute new UV position to equalize the vertex distance
|
|
75
|
-
const u =
|
|
76
|
-
const v =
|
|
75
|
+
// compute new UV position to equalize the vertex distance
|
|
76
|
+
const u = sum_u / weight_sum;
|
|
77
|
+
const v = sum_v / weight_sum;
|
|
78
|
+
|
|
79
|
+
const uv_address = v0.index * 2;
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
uvs[
|
|
80
|
-
uvs[uvAddress + 1] = v;
|
|
81
|
+
uvs[uv_address] = u;
|
|
82
|
+
uvs[uv_address + 1] = v;
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|