topotopo 0.3.0 → 0.4.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.
- package/NOTICE +30 -0
- package/README.md +35 -14
- package/dist/cli.js +28 -10
- package/dist/core/analysis.d.ts +5 -1
- package/dist/core/analysis.js +8 -3
- package/dist/core/bake.d.ts +2 -5
- package/dist/core/bake.js +12 -25
- package/dist/core/bevel.js +165 -97
- package/dist/core/geometry.js +1 -1
- package/dist/core/imageops.d.ts +6 -0
- package/dist/core/imageops.js +51 -0
- package/dist/core/materials.d.ts +4 -0
- package/dist/core/materials.js +11 -0
- package/dist/core/packed.js +11 -0
- package/dist/core/particles.d.ts +1 -1
- package/dist/core/particles.js +1 -1
- package/dist/core/rbd.js +13 -1
- package/dist/core/scatter.d.ts +1 -1
- package/dist/core/scatter.js +1 -1
- package/dist/core/scene.d.ts +20 -0
- package/dist/core/scene.js +71 -0
- package/dist/core/snippet-lib.d.ts +1 -1
- package/dist/core/snippet-lib.js +1 -1
- package/dist/core/solidify.d.ts +38 -0
- package/dist/core/solidify.js +356 -0
- package/dist/core/tangents.d.ts +52 -0
- package/dist/core/tangents.js +214 -0
- package/dist/core/texcoord.d.ts +4 -0
- package/dist/core/texcoord.js +14 -0
- package/dist/core/topology.d.ts +22 -0
- package/dist/core/topology.js +70 -7
- package/dist/core/traceimage.d.ts +7 -0
- package/dist/core/traceimage.js +221 -0
- package/dist/core/tritri.d.ts +5 -0
- package/dist/core/tritri.js +120 -0
- package/dist/core/uv.d.ts +13 -0
- package/dist/core/uv.js +3 -3
- package/dist/core/uvreport.d.ts +66 -0
- package/dist/core/uvreport.js +308 -0
- package/dist/core/xatlas.js +32 -2
- package/dist/gallery/app/gallery.css +100 -0
- package/dist/gallery/app/gallery.js +80 -0
- package/dist/gallery/bake.d.ts +34 -0
- package/dist/gallery/bake.js +144 -0
- package/dist/gallery/cli.d.ts +4 -0
- package/dist/gallery/cli.js +157 -0
- package/dist/gallery/library.d.ts +124 -0
- package/dist/gallery/library.js +366 -0
- package/dist/gallery/pages.d.ts +94 -0
- package/dist/gallery/pages.js +148 -0
- package/dist/gallery/server.d.ts +21 -0
- package/dist/gallery/server.js +391 -0
- package/dist/host/export-targets.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -1
- package/dist/inspect.d.ts +6 -1
- package/dist/inspect.js +13 -1
- package/dist/io/common.d.ts +8 -0
- package/dist/io/gltf.js +236 -19
- package/dist/io/targets.js +1 -1
- package/dist/mcp/docs.d.ts +1 -1
- package/dist/mcp/docs.js +58 -4
- package/dist/mcp/library.d.ts +12 -0
- package/dist/mcp/library.js +159 -0
- package/dist/mcp/server.js +29 -12
- package/dist/mcp/tools.js +16 -10
- package/dist/nodes/bake.js +56 -36
- package/dist/nodes/bevel.js +4 -3
- package/dist/nodes/code.js +1 -1
- package/dist/nodes/curves.js +7 -0
- package/dist/nodes/generate.js +1 -1
- package/dist/nodes/imageops.d.ts +1 -0
- package/dist/nodes/imageops.js +206 -0
- package/dist/nodes/index.d.ts +3 -0
- package/dist/nodes/index.js +3 -0
- package/dist/nodes/material.js +3 -0
- package/dist/nodes/measure.js +3 -2
- package/dist/nodes/rbd.js +1 -1
- package/dist/nodes/scene.d.ts +1 -0
- package/dist/nodes/scene.js +53 -0
- package/dist/nodes/solidify.d.ts +1 -0
- package/dist/nodes/solidify.js +52 -0
- package/dist/nodes/transform.js +5 -1
- package/dist/nodes/util.d.ts +1 -1
- package/dist/nodes/wasmcall.js +1 -1
- package/dist/render/options.js +1 -1
- package/dist/render/pbr.d.ts +28 -0
- package/dist/render/pbr.js +378 -0
- package/dist/render/preview.d.ts +58 -0
- package/dist/render/preview.js +24 -0
- package/dist/render/raster.d.ts +12 -2
- package/dist/render/raster.js +98 -11
- package/dist/render/texview.d.ts +1 -1
- package/dist/render/texview.js +7 -2
- package/dist/viewer/app/camera.js +1 -1
- package/dist/viewer/app/embed.js +80 -0
- package/dist/viewer/app/grid.js +1 -1
- package/dist/viewer/app/guides.js +1 -1
- package/dist/viewer/app/keymap.js +1 -1
- package/dist/viewer/app/layers.js +1 -1
- package/dist/viewer/app/main.js +1 -1
- package/dist/viewer/app/markers.js +1 -1
- package/dist/viewer/app/outliner.js +1 -1
- package/dist/viewer/app/props.js +1 -1
- package/dist/viewer/app/scene.js +6 -2
- package/dist/viewer/app/select.js +1 -1
- package/dist/viewer/app/selection.js +1 -1
- package/dist/viewer/app/status.js +1 -1
- package/dist/viewer/app/style.css +1 -1
- package/dist/viewer/app/units.js +1 -1
- package/dist/viewer/app/vars.js +1 -1
- package/dist/viewer/index.html +1 -1
- package/dist/viewer/server.d.ts +14 -2
- package/dist/viewer/server.js +30 -10
- package/dist/workspace.d.ts +13 -0
- package/dist/workspace.js +87 -1
- package/kernels/pkg/README.md +21 -28
- package/kernels/pkg-simd/README.md +21 -28
- package/package.json +9 -3
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { triangulate } from './topology.js';
|
|
2
|
+
/** Relative tolerances: a uv triangle is collapsed below this (doubled area / squared edges); an overlap counts above this fraction of the smaller triangle's area. */
|
|
3
|
+
const COLLAPSED_Q = 1e-9;
|
|
4
|
+
const OVERLAP_REL = 1e-7;
|
|
5
|
+
/** Area of the intersection of two counter-clockwise triangles (6 numbers each) by convex clipping. */
|
|
6
|
+
function triIntersectionArea(a, b) {
|
|
7
|
+
let poly = [a[0], a[1], a[2], a[3], a[4], a[5]];
|
|
8
|
+
for (let e = 0; e < 3 && poly.length >= 6; e++) {
|
|
9
|
+
const ax = b[e * 2], ay = b[e * 2 + 1], bx = b[((e + 1) % 3) * 2], by = b[((e + 1) % 3) * 2 + 1];
|
|
10
|
+
const out = [];
|
|
11
|
+
const n = poly.length / 2;
|
|
12
|
+
for (let i = 0; i < n; i++) {
|
|
13
|
+
const cx = poly[i * 2], cy = poly[i * 2 + 1], dx = poly[((i + 1) % n) * 2], dy = poly[((i + 1) % n) * 2 + 1];
|
|
14
|
+
const sc = (bx - ax) * (cy - ay) - (by - ay) * (cx - ax), sd = (bx - ax) * (dy - ay) - (by - ay) * (dx - ax);
|
|
15
|
+
if (sc >= 0)
|
|
16
|
+
out.push(cx, cy);
|
|
17
|
+
if ((sc >= 0) !== (sd >= 0)) {
|
|
18
|
+
const t = sc / (sc - sd);
|
|
19
|
+
out.push(cx + (dx - cx) * t, cy + (dy - cy) * t);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
poly = out;
|
|
23
|
+
}
|
|
24
|
+
if (poly.length < 6)
|
|
25
|
+
return 0;
|
|
26
|
+
let s = 0;
|
|
27
|
+
for (let i = 0, n = poly.length / 2; i < n; i++) {
|
|
28
|
+
const j = (i + 1) % n;
|
|
29
|
+
s += poly[i * 2] * poly[j * 2 + 1] - poly[j * 2] * poly[i * 2 + 1];
|
|
30
|
+
}
|
|
31
|
+
return Math.abs(s) / 2;
|
|
32
|
+
}
|
|
33
|
+
export function uvReport(g, o = {}, tri = triangulate(g)) {
|
|
34
|
+
const name = o.attribute || 'uv';
|
|
35
|
+
const maxEx = Math.max(0, Math.floor(o.maxExamples ?? 16)), maxTests = Math.max(0, Math.floor(o.maxPairTests ?? 4_000_000));
|
|
36
|
+
const res = o.resolution === undefined ? undefined : Array.isArray(o.resolution) ? [o.resolution[0], o.resolution[1]] : [o.resolution, o.resolution];
|
|
37
|
+
const { tris, triPrim } = tri, nt = tris.length / 3;
|
|
38
|
+
const rep = {
|
|
39
|
+
attribute: name, complete: true, reasons: [], missing: false, triangles: nt, nonFinite: 0, collapsed: 0, collapsedTriangles: [], mirrored: 0,
|
|
40
|
+
outOfTile: 0, tiles: [], charts: 0, uvArea: 0,
|
|
41
|
+
overlap: { pairs: 0, sameChartPairs: 0, area: 0, candidatePairs: 0, testedPairs: 0, examples: [] },
|
|
42
|
+
utilization: { method: 'none', value: 0, note: '' }, pieces: [], ...(res ? { resolution: res } : {}),
|
|
43
|
+
};
|
|
44
|
+
const f = g.findAttrib(name, ['vertex', 'point']);
|
|
45
|
+
if (!f || f.attr.type !== 'float' || f.attr.isArray) {
|
|
46
|
+
rep.missing = true;
|
|
47
|
+
rep.complete = false;
|
|
48
|
+
rep.reasons.push(`no float vertex or point attribute "${name}"`);
|
|
49
|
+
rep.utilization.note = 'no uv';
|
|
50
|
+
return rep;
|
|
51
|
+
}
|
|
52
|
+
const a = f.attr, d = a.data, sz = a.size;
|
|
53
|
+
const U = new Float64Array(nt * 6);
|
|
54
|
+
for (let c = 0; c < nt * 3; c++) {
|
|
55
|
+
const v = tris[c], i = (f.cls === 'vertex' ? v : g.vertexPoint[v]) * sz;
|
|
56
|
+
U[c * 2] = d[i];
|
|
57
|
+
U[c * 2 + 1] = sz > 1 ? d[i + 1] : 0;
|
|
58
|
+
}
|
|
59
|
+
// per triangle: validity, signed area, tiles
|
|
60
|
+
const ok = new Uint8Array(nt), signed = new Float64Array(nt), tiles = new Set();
|
|
61
|
+
let pos = 0, neg = 0;
|
|
62
|
+
for (let t = 0; t < nt; t++) {
|
|
63
|
+
const o6 = t * 6;
|
|
64
|
+
let finite = true;
|
|
65
|
+
for (let k = 0; k < 6; k++)
|
|
66
|
+
if (!Number.isFinite(U[o6 + k]))
|
|
67
|
+
finite = false;
|
|
68
|
+
if (!finite) {
|
|
69
|
+
rep.nonFinite++;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const du1 = U[o6 + 2] - U[o6], dv1 = U[o6 + 3] - U[o6 + 1], du2 = U[o6 + 4] - U[o6], dv2 = U[o6 + 5] - U[o6 + 1];
|
|
73
|
+
const cr = du1 * dv2 - du2 * dv1, e2 = du1 * du1 + dv1 * dv1 + du2 * du2 + dv2 * dv2 + (du2 - du1) ** 2 + (dv2 - dv1) ** 2;
|
|
74
|
+
let inside = true;
|
|
75
|
+
for (let k = 0; k < 3; k++) {
|
|
76
|
+
const u = U[o6 + k * 2], v = U[o6 + k * 2 + 1];
|
|
77
|
+
if (u < 0 || u > 1 || v < 0 || v > 1)
|
|
78
|
+
inside = false;
|
|
79
|
+
}
|
|
80
|
+
const cu = (U[o6] + U[o6 + 2] + U[o6 + 4]) / 3, cv = (U[o6 + 1] + U[o6 + 3] + U[o6 + 5]) / 3;
|
|
81
|
+
tiles.add(`${Math.floor(cu)},${Math.floor(cv)}`);
|
|
82
|
+
if (!inside)
|
|
83
|
+
rep.outOfTile++;
|
|
84
|
+
if (!(Math.abs(cr) > COLLAPSED_Q * e2)) {
|
|
85
|
+
rep.collapsed++;
|
|
86
|
+
if (rep.collapsedTriangles.length < maxEx)
|
|
87
|
+
rep.collapsedTriangles.push(t);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
ok[t] = 1;
|
|
91
|
+
signed[t] = cr / 2;
|
|
92
|
+
rep.uvArea += Math.abs(cr) / 2;
|
|
93
|
+
if (cr > 0)
|
|
94
|
+
pos++;
|
|
95
|
+
else
|
|
96
|
+
neg++;
|
|
97
|
+
}
|
|
98
|
+
rep.mirrored = Math.min(pos, neg);
|
|
99
|
+
rep.tiles = [...tiles].sort((x, y) => { const [a0, a1] = x.split(',').map(Number), [b0, b1] = y.split(',').map(Number); return a1 - b1 || a0 - b0; });
|
|
100
|
+
// charts: union triangles across uv-continuous edges (same two points, same uv at both)
|
|
101
|
+
const parent = Int32Array.from({ length: nt }, (_, i) => i);
|
|
102
|
+
const find = (x) => { while (parent[x] !== x) {
|
|
103
|
+
parent[x] = parent[parent[x]];
|
|
104
|
+
x = parent[x];
|
|
105
|
+
} return x; };
|
|
106
|
+
const cornerKey = (c) => `${g.vertexPoint[tris[c]]}:${U[c * 2]}:${U[c * 2 + 1]}`;
|
|
107
|
+
const corner = new Map(), cid = new Int32Array(nt * 3);
|
|
108
|
+
for (let c = 0; c < nt * 3; c++) {
|
|
109
|
+
const k = cornerKey(c);
|
|
110
|
+
let id = corner.get(k);
|
|
111
|
+
if (id === undefined) {
|
|
112
|
+
id = corner.size;
|
|
113
|
+
corner.set(k, id);
|
|
114
|
+
}
|
|
115
|
+
cid[c] = id;
|
|
116
|
+
}
|
|
117
|
+
const edgeOwner = new Map(), nc = corner.size;
|
|
118
|
+
for (let t = 0; t < nt; t++) {
|
|
119
|
+
if (!Number.isFinite(U[t * 6]) || !Number.isFinite(U[t * 6 + 2]) || !Number.isFinite(U[t * 6 + 4]))
|
|
120
|
+
continue;
|
|
121
|
+
for (let k = 0; k < 3; k++) {
|
|
122
|
+
const x = cid[t * 3 + k], y = cid[t * 3 + ((k + 1) % 3)];
|
|
123
|
+
const key = Math.min(x, y) * nc + Math.max(x, y);
|
|
124
|
+
const other = edgeOwner.get(key);
|
|
125
|
+
if (other === undefined)
|
|
126
|
+
edgeOwner.set(key, t);
|
|
127
|
+
else {
|
|
128
|
+
const ra = find(t), rb = find(other);
|
|
129
|
+
if (ra !== rb)
|
|
130
|
+
parent[rb] = ra;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
const roots = new Set();
|
|
135
|
+
for (let t = 0; t < nt; t++)
|
|
136
|
+
if (Number.isFinite(U[t * 6]) && Number.isFinite(U[t * 6 + 2]) && Number.isFinite(U[t * 6 + 4]))
|
|
137
|
+
roots.add(find(t));
|
|
138
|
+
rep.charts = roots.size;
|
|
139
|
+
// overlaps: grid candidates, exact clipping
|
|
140
|
+
const valid = [];
|
|
141
|
+
let minU = Infinity, minV = Infinity, maxU = -Infinity, maxV = -Infinity;
|
|
142
|
+
for (let t = 0; t < nt; t++)
|
|
143
|
+
if (ok[t]) {
|
|
144
|
+
valid.push(t);
|
|
145
|
+
for (let k = 0; k < 3; k++) {
|
|
146
|
+
const u = U[t * 6 + k * 2], v = U[t * 6 + k * 2 + 1];
|
|
147
|
+
if (u < minU)
|
|
148
|
+
minU = u;
|
|
149
|
+
if (u > maxU)
|
|
150
|
+
maxU = u;
|
|
151
|
+
if (v < minV)
|
|
152
|
+
minV = v;
|
|
153
|
+
if (v > maxV)
|
|
154
|
+
maxV = v;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
const ccw = new Float64Array(nt * 6);
|
|
158
|
+
for (const t of valid) {
|
|
159
|
+
const o6 = t * 6;
|
|
160
|
+
if (signed[t] > 0)
|
|
161
|
+
for (let k = 0; k < 6; k++)
|
|
162
|
+
ccw[o6 + k] = U[o6 + k];
|
|
163
|
+
else {
|
|
164
|
+
ccw[o6] = U[o6];
|
|
165
|
+
ccw[o6 + 1] = U[o6 + 1];
|
|
166
|
+
ccw[o6 + 2] = U[o6 + 4];
|
|
167
|
+
ccw[o6 + 3] = U[o6 + 5];
|
|
168
|
+
ccw[o6 + 4] = U[o6 + 2];
|
|
169
|
+
ccw[o6 + 5] = U[o6 + 3];
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (valid.length > 1) {
|
|
173
|
+
const span = Math.max(maxU - minU, maxV - minV, 1e-12);
|
|
174
|
+
const cells = Math.max(1, Math.min(1024, Math.ceil(Math.sqrt(valid.length / 2))));
|
|
175
|
+
const cs = span / cells;
|
|
176
|
+
const nx = Math.max(1, Math.min(1024, Math.ceil((maxU - minU) / cs) || 1)), ny = Math.max(1, Math.min(1024, Math.ceil((maxV - minV) / cs) || 1));
|
|
177
|
+
const cellOf = (u, n, lo) => Math.max(0, Math.min(n - 1, Math.floor((u - lo) / cs)));
|
|
178
|
+
const bb = new Float64Array(nt * 4);
|
|
179
|
+
const counts = new Int32Array(nx * ny + 1);
|
|
180
|
+
for (const t of valid) {
|
|
181
|
+
const o6 = t * 6;
|
|
182
|
+
const u0 = Math.min(U[o6], U[o6 + 2], U[o6 + 4]), u1 = Math.max(U[o6], U[o6 + 2], U[o6 + 4]), v0 = Math.min(U[o6 + 1], U[o6 + 3], U[o6 + 5]), v1 = Math.max(U[o6 + 1], U[o6 + 3], U[o6 + 5]);
|
|
183
|
+
bb[t * 4] = u0;
|
|
184
|
+
bb[t * 4 + 1] = v0;
|
|
185
|
+
bb[t * 4 + 2] = u1;
|
|
186
|
+
bb[t * 4 + 3] = v1;
|
|
187
|
+
for (let y = cellOf(v0, ny, minV); y <= cellOf(v1, ny, minV); y++)
|
|
188
|
+
for (let x = cellOf(u0, nx, minU); x <= cellOf(u1, nx, minU); x++)
|
|
189
|
+
counts[y * nx + x + 1]++;
|
|
190
|
+
}
|
|
191
|
+
for (let i = 0; i < nx * ny; i++)
|
|
192
|
+
counts[i + 1] += counts[i];
|
|
193
|
+
const items = new Int32Array(counts[nx * ny]), fill = counts.slice(0, nx * ny);
|
|
194
|
+
for (const t of valid) {
|
|
195
|
+
const u0 = bb[t * 4], v0 = bb[t * 4 + 1], u1 = bb[t * 4 + 2], v1 = bb[t * 4 + 3];
|
|
196
|
+
for (let y = cellOf(v0, ny, minV); y <= cellOf(v1, ny, minV); y++)
|
|
197
|
+
for (let x = cellOf(u0, nx, minU); x <= cellOf(u1, nx, minU); x++)
|
|
198
|
+
items[fill[y * nx + x]++] = t;
|
|
199
|
+
}
|
|
200
|
+
let tests = 0, stopped = false;
|
|
201
|
+
for (let c = 0; c < nx * ny; c++) {
|
|
202
|
+
const s = counts[c], e = counts[c + 1], cx = c % nx, cy = Math.floor(c / nx);
|
|
203
|
+
for (let i = s; i < e; i++)
|
|
204
|
+
for (let j = i + 1; j < e; j++) {
|
|
205
|
+
const ta = items[i], tb = items[j];
|
|
206
|
+
// bounding boxes overlap with positive extent, and this cell owns the pair
|
|
207
|
+
const lu = Math.max(bb[ta * 4], bb[tb * 4]), lv = Math.max(bb[ta * 4 + 1], bb[tb * 4 + 1]);
|
|
208
|
+
if (lu >= Math.min(bb[ta * 4 + 2], bb[tb * 4 + 2]) || lv >= Math.min(bb[ta * 4 + 3], bb[tb * 4 + 3]))
|
|
209
|
+
continue;
|
|
210
|
+
if (cellOf(lu, nx, minU) !== cx || cellOf(lv, ny, minV) !== cy)
|
|
211
|
+
continue;
|
|
212
|
+
rep.overlap.candidatePairs++;
|
|
213
|
+
if (tests >= maxTests) {
|
|
214
|
+
stopped = true;
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
tests++;
|
|
218
|
+
const A = triIntersectionArea(ccw.subarray(ta * 6, ta * 6 + 6), ccw.subarray(tb * 6, tb * 6 + 6));
|
|
219
|
+
if (A > OVERLAP_REL * Math.min(Math.abs(signed[ta]), Math.abs(signed[tb]))) {
|
|
220
|
+
const t0 = Math.min(ta, tb), t1 = Math.max(ta, tb), same = find(t0) === find(t1);
|
|
221
|
+
rep.overlap.pairs++;
|
|
222
|
+
rep.overlap.area += A;
|
|
223
|
+
if (same)
|
|
224
|
+
rep.overlap.sameChartPairs++;
|
|
225
|
+
if (rep.overlap.examples.length < maxEx)
|
|
226
|
+
rep.overlap.examples.push({ triangles: [t0, t1], prims: [triPrim[t0], triPrim[t1]], area: A, sameChart: same });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
rep.overlap.testedPairs = tests;
|
|
231
|
+
if (stopped) {
|
|
232
|
+
rep.complete = false;
|
|
233
|
+
rep.reasons.push(`overlap test stopped after ${tests.toLocaleString('en-US')} exact pair tests (maxPairTests) of ${rep.overlap.candidatePairs.toLocaleString('en-US')} candidate pairs`);
|
|
234
|
+
}
|
|
235
|
+
rep.overlap.examples.sort((x, y) => y.area - x.area || x.triangles[0] - y.triangles[0] || x.triangles[1] - y.triangles[1]);
|
|
236
|
+
}
|
|
237
|
+
// utilization
|
|
238
|
+
if (rep.overlap.pairs === 0 && rep.outOfTile === 0 && rep.complete) {
|
|
239
|
+
rep.utilization = { method: 'exact', value: rep.uvArea, note: 'sum of uv triangle areas in the unit tile (no overlaps, nothing outside)' };
|
|
240
|
+
}
|
|
241
|
+
else if (valid.length) {
|
|
242
|
+
const N = Math.max(16, Math.min(4096, Math.floor(o.rasterSize ?? 1024)));
|
|
243
|
+
const cov = new Uint8Array(N * N);
|
|
244
|
+
for (const t of valid) {
|
|
245
|
+
const o6 = t * 6, ax = ccw[o6] * N, ay = ccw[o6 + 1] * N, bx = ccw[o6 + 2] * N, by = ccw[o6 + 3] * N, cx = ccw[o6 + 4] * N, cy = ccw[o6 + 5] * N;
|
|
246
|
+
const x0 = Math.max(0, Math.floor(Math.min(ax, bx, cx))), x1 = Math.min(N - 1, Math.ceil(Math.max(ax, bx, cx))), y0 = Math.max(0, Math.floor(Math.min(ay, by, cy))), y1 = Math.min(N - 1, Math.ceil(Math.max(ay, by, cy)));
|
|
247
|
+
for (let y = y0; y <= y1; y++)
|
|
248
|
+
for (let x = x0; x <= x1; x++) {
|
|
249
|
+
const px = x + 0.5, py = y + 0.5;
|
|
250
|
+
if ((bx - ax) * (py - ay) - (by - ay) * (px - ax) >= 0 && (cx - bx) * (py - by) - (cy - by) * (px - bx) >= 0 && (ax - cx) * (py - cy) - (ay - cy) * (px - cx) >= 0)
|
|
251
|
+
cov[y * N + x] = 1;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
let k = 0;
|
|
255
|
+
for (let i = 0; i < cov.length; i++)
|
|
256
|
+
k += cov[i];
|
|
257
|
+
const why = [rep.overlap.pairs ? 'overlapping triangles' : '', rep.outOfTile ? 'triangles outside the unit tile (excluded from the estimate)' : '', rep.complete ? '' : 'an incomplete overlap test'].filter(Boolean).join(', ');
|
|
258
|
+
rep.utilization = { method: 'raster-estimate', value: k / (N * N), rasterSize: N, note: `ESTIMATE: fraction of ${N} × ${N} sample points of the unit tile covered (summed areas would count overlaps twice; because of ${why})` };
|
|
259
|
+
}
|
|
260
|
+
else
|
|
261
|
+
rep.utilization = { method: 'none', value: 0, note: 'no valid uv triangles' };
|
|
262
|
+
// per-piece surface and uv area, texel density
|
|
263
|
+
const pa = g.prims.get(o.pieceAttrib || 'name');
|
|
264
|
+
if (pa && pa.type === 'string') {
|
|
265
|
+
const by = new Map(), P = g.P, vp = g.vertexPoint;
|
|
266
|
+
for (let t = 0; t < nt; t++) {
|
|
267
|
+
const key = String(pa.get(triPrim[t]) ?? '');
|
|
268
|
+
let pc = by.get(key);
|
|
269
|
+
if (!pc) {
|
|
270
|
+
pc = { name: key, triangles: 0, surfaceArea: 0, uvArea: 0 };
|
|
271
|
+
by.set(key, pc);
|
|
272
|
+
}
|
|
273
|
+
const i0 = vp[tris[t * 3]] * 3, i1 = vp[tris[t * 3 + 1]] * 3, i2 = vp[tris[t * 3 + 2]] * 3;
|
|
274
|
+
const ux = P[i1] - P[i0], uy = P[i1 + 1] - P[i0 + 1], uz = P[i1 + 2] - P[i0 + 2], wx = P[i2] - P[i0], wy = P[i2 + 1] - P[i0 + 1], wz = P[i2 + 2] - P[i0 + 2];
|
|
275
|
+
pc.triangles++;
|
|
276
|
+
pc.surfaceArea += 0.5 * Math.hypot(uy * wz - uz * wy, uz * wx - ux * wz, ux * wy - uy * wx);
|
|
277
|
+
if (ok[t])
|
|
278
|
+
pc.uvArea += Math.abs(signed[t]);
|
|
279
|
+
}
|
|
280
|
+
rep.pieces = [...by.values()].sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0));
|
|
281
|
+
if (res)
|
|
282
|
+
for (const pc of rep.pieces)
|
|
283
|
+
pc.texelsPerMetre = pc.surfaceArea > 0 ? Math.sqrt((pc.uvArea * res[0] * res[1]) / pc.surfaceArea) : 0;
|
|
284
|
+
}
|
|
285
|
+
return rep;
|
|
286
|
+
}
|
|
287
|
+
/** Short text form of a report for inspect. */
|
|
288
|
+
export function uvReportText(r) {
|
|
289
|
+
const f = (x) => (Math.abs(x) >= 1e-3 || x === 0 ? +x.toPrecision(4) : x.toExponential(2));
|
|
290
|
+
const out = [`uv "${r.attribute}": ${r.complete ? 'COMPLETE' : 'INCOMPLETE'} analysis of ${r.triangles} triangles${r.reasons.length ? ` (${r.reasons.join('; ')})` : ''}`];
|
|
291
|
+
if (r.missing)
|
|
292
|
+
return out;
|
|
293
|
+
out.push(` ${r.charts} charts; tiles ${r.tiles.join(' ') || 'none'}; ${r.outOfTile} triangles outside 0..1; ${r.nonFinite} non-finite; ${r.collapsed} collapsed${r.collapsedTriangles.length ? ` (triangles ${r.collapsedTriangles.join(' ')}${r.collapsed > r.collapsedTriangles.length ? ' …' : ''})` : ''}; ${r.mirrored} mirrored`);
|
|
294
|
+
const ov = r.overlap;
|
|
295
|
+
out.push(` overlaps: ${ov.pairs} triangle pairs (${ov.sameChartPairs} within one chart), area ${f(ov.area)}; ${ov.testedPairs} of ${ov.candidatePairs} candidate pairs tested exactly`);
|
|
296
|
+
for (const e of ov.examples.slice(0, 8))
|
|
297
|
+
out.push(` triangles ${e.triangles[0]} × ${e.triangles[1]} (prims ${e.prims[0]} × ${e.prims[1]}${e.sameChart ? ', same chart' : ''}): area ${f(e.area)}`);
|
|
298
|
+
out.push(` utilization ${(r.utilization.value * 100).toFixed(2)}% (${r.utilization.method}${r.utilization.rasterSize ? ` ${r.utilization.rasterSize}²` : ''}): ${r.utilization.note}; uv area ${f(r.uvArea)}`);
|
|
299
|
+
if (r.pieces.length) {
|
|
300
|
+
const shown = r.pieces.slice(0, 24);
|
|
301
|
+
out.push(` pieces (${r.pieces.length})${r.resolution ? `, texel density at ${r.resolution[0]}×${r.resolution[1]}` : ''}:`);
|
|
302
|
+
for (const p of shown)
|
|
303
|
+
out.push(` ${p.name || '""'}: ${p.triangles} tris, surface ${f(p.surfaceArea)} m², uv ${f(p.uvArea)}${p.texelsPerMetre !== undefined ? `, ${f(p.texelsPerMetre)} texels/m` : ''}`);
|
|
304
|
+
if (r.pieces.length > shown.length)
|
|
305
|
+
out.push(` … ${r.pieces.length - shown.length} more`);
|
|
306
|
+
}
|
|
307
|
+
return out;
|
|
308
|
+
}
|
package/dist/core/xatlas.js
CHANGED
|
@@ -11,6 +11,21 @@ export async function loadXatlas() {
|
|
|
11
11
|
}
|
|
12
12
|
return modPromise;
|
|
13
13
|
}
|
|
14
|
+
/** Bounding-box diagonal small inputs are scaled up to before xatlas sees them (world units). */
|
|
15
|
+
const XATLAS_SIZE = 100;
|
|
16
|
+
/** The factor that brings a position list's bounding-box diagonal up to XATLAS_SIZE (1 when it is already larger). */
|
|
17
|
+
function xatlasScale(pos) {
|
|
18
|
+
const lo = [Infinity, Infinity, Infinity], hi = [-Infinity, -Infinity, -Infinity];
|
|
19
|
+
for (let i = 0; i < pos.length; i++) {
|
|
20
|
+
const a = i % 3;
|
|
21
|
+
if (pos[i] < lo[a])
|
|
22
|
+
lo[a] = pos[i];
|
|
23
|
+
if (pos[i] > hi[a])
|
|
24
|
+
hi[a] = pos[i];
|
|
25
|
+
}
|
|
26
|
+
const d = Math.hypot(hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]);
|
|
27
|
+
return d > 0 && d < XATLAS_SIZE ? XATLAS_SIZE / d : 1;
|
|
28
|
+
}
|
|
14
29
|
/**
|
|
15
30
|
* Run xatlas on the closed polygons of g (prims outside primMask are skipped). Input vertices are the
|
|
16
31
|
* geometry points, or per-vertex keys (`vertexKey[v]`, e.g. split along seams); `faceGroup[prim]`
|
|
@@ -42,6 +57,21 @@ export function runXatlas(X, g, chart, pack, opts = {}) {
|
|
|
42
57
|
};
|
|
43
58
|
if (!nt)
|
|
44
59
|
return result;
|
|
60
|
+
// xatlas compares positions and areas against absolute epsilons (about 1e-4 and 1.2e-7), so on a model a few
|
|
61
|
+
// centimetres across it welds bevel corners and drops small faces as degenerate. Scale small inputs up to a
|
|
62
|
+
// bounding-box diagonal of XATLAS_SIZE; the world-unit options scale with them, so the result is unchanged.
|
|
63
|
+
const k = xatlasScale(pos), repack = pack;
|
|
64
|
+
if (k !== 1) {
|
|
65
|
+
for (let i = 0; i < pos.length; i++)
|
|
66
|
+
pos[i] *= k;
|
|
67
|
+
chart = { ...chart };
|
|
68
|
+
if (chart.maxChartArea)
|
|
69
|
+
chart.maxChartArea *= k * k;
|
|
70
|
+
if (chart.maxBoundaryLength)
|
|
71
|
+
chart.maxBoundaryLength *= k;
|
|
72
|
+
if (pack?.texelsPerUnit)
|
|
73
|
+
pack = { ...pack, texelsPerUnit: pack.texelsPerUnit / k };
|
|
74
|
+
}
|
|
45
75
|
const atlas = X.createAtlas();
|
|
46
76
|
try {
|
|
47
77
|
const decl = { positions: Float32Array.from(pos), indices: idx };
|
|
@@ -71,8 +101,8 @@ export function runXatlas(X, g, chart, pack, opts = {}) {
|
|
|
71
101
|
result.triAtlas[t] = ov.atlasIndex;
|
|
72
102
|
}
|
|
73
103
|
}
|
|
74
|
-
if (opts.unmirror &&
|
|
75
|
-
unmirrorAndRepack(X, result, out, verts.length,
|
|
104
|
+
if (opts.unmirror && repack)
|
|
105
|
+
unmirrorAndRepack(X, result, out, verts.length, repack);
|
|
76
106
|
}
|
|
77
107
|
finally {
|
|
78
108
|
atlas.destroy();
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/* The gallery's pages (src/gallery/pages.ts): the viewer's neutral dark editor colours, a card grid, a project page
|
|
2
|
+
with the 3D view beside its details. One column below 860 px. */
|
|
3
|
+
:root {
|
|
4
|
+
--bg: #1f2124; --panel: #26282c; --panel2: #2c2f33; --line: #3a3d42; --text: #d6d9dd; --dim: #8c939b; --faint: #5d636b;
|
|
5
|
+
--view: #2b2d31; --accent: #f0a030; --accent-bg: rgba(240, 160, 48, 0.14); --err: #e5675f; --ok: #8fbf7f;
|
|
6
|
+
--font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
7
|
+
--mono: 12px/1.4 ui-monospace, Consolas, "SF Mono", monospace;
|
|
8
|
+
color-scheme: dark;
|
|
9
|
+
}
|
|
10
|
+
* { box-sizing: border-box; }
|
|
11
|
+
[hidden] { display: none !important; }
|
|
12
|
+
html, body { margin: 0; background: var(--bg); color: var(--text); font: var(--font); }
|
|
13
|
+
a { color: inherit; }
|
|
14
|
+
code, pre { font: var(--mono); }
|
|
15
|
+
h1, h2, h3 { font-weight: 600; line-height: 1.2; }
|
|
16
|
+
h1 { font-size: 24px; margin: 0 0 8px; }
|
|
17
|
+
h2 { font-size: 15px; margin: 28px 0 10px; color: var(--text); }
|
|
18
|
+
h3 { font-size: 13px; margin: 18px 0 8px; color: var(--dim); font-weight: 500; }
|
|
19
|
+
.count { color: var(--faint); font-weight: 400; font-size: 0.9em; margin-left: 4px; }
|
|
20
|
+
.dim { color: var(--dim); }
|
|
21
|
+
.small { font-size: 12px; }
|
|
22
|
+
.empty { color: var(--dim); }
|
|
23
|
+
|
|
24
|
+
.bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
|
|
25
|
+
.brand { text-decoration: none; color: var(--dim); white-space: nowrap; }
|
|
26
|
+
.brand b { color: var(--text); font-weight: 600; }
|
|
27
|
+
.crumbs { color: var(--dim); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
28
|
+
.crumbs a { color: var(--dim); }
|
|
29
|
+
#search { flex: 1; max-width: 420px; margin-left: auto; padding: 6px 10px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; }
|
|
30
|
+
#search:focus { outline: 1px solid var(--faint); }
|
|
31
|
+
|
|
32
|
+
.wrap { max-width: 1400px; margin: 0 auto; padding: 8px 16px 48px; }
|
|
33
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 0; }
|
|
34
|
+
.chip { padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); color: var(--dim); font: inherit; font-size: 12px; cursor: pointer; }
|
|
35
|
+
.chip[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-bg); }
|
|
36
|
+
.problems { margin: 14px 0 0; padding: 8px 12px; border: 1px solid var(--err); border-radius: 4px; color: var(--err); }
|
|
37
|
+
.problems ul { margin: 6px 0 0; padding-left: 18px; color: var(--text); font: var(--mono); }
|
|
38
|
+
|
|
39
|
+
.library h2 { font-size: 18px; margin-top: 28px; }
|
|
40
|
+
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
|
|
41
|
+
.card { display: flex; flex-direction: column; text-decoration: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
|
|
42
|
+
.card:hover { border-color: var(--faint); }
|
|
43
|
+
.card:focus-visible { outline: 2px solid var(--accent); }
|
|
44
|
+
.thumb { display: block; aspect-ratio: 1; background: var(--view); }
|
|
45
|
+
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
|
|
46
|
+
.meta { display: flex; flex-direction: column; gap: 3px; padding: 8px 10px 10px; min-width: 0; }
|
|
47
|
+
.title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
48
|
+
.sub { color: var(--dim); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
49
|
+
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 0; }
|
|
50
|
+
.tag { padding: 0 6px; border-radius: 3px; background: var(--panel2); color: var(--dim); font-size: 11px; line-height: 18px; }
|
|
51
|
+
.status { font-size: 11px; color: var(--dim); }
|
|
52
|
+
.status:empty { display: none; }
|
|
53
|
+
.s-failed { color: var(--err); }
|
|
54
|
+
.s-baking { color: var(--accent); }
|
|
55
|
+
|
|
56
|
+
.project { display: grid; gap: 24px; grid-template-columns: minmax(0, 1fr) 380px; grid-template-areas: "stage info" "more info"; padding-top: 16px; }
|
|
57
|
+
.stage { grid-area: stage; }
|
|
58
|
+
.view { display: block; width: 100%; aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 6px; background: var(--view); object-fit: contain; }
|
|
59
|
+
.info { grid-area: info; min-width: 0; }
|
|
60
|
+
.more { grid-area: more; min-width: 0; }
|
|
61
|
+
.desc { white-space: pre-line; margin: 0 0 10px; }
|
|
62
|
+
.links { margin: 10px 0; padding-left: 18px; }
|
|
63
|
+
.links a { color: var(--accent); }
|
|
64
|
+
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 8px; }
|
|
65
|
+
.btn { display: inline-block; padding: 6px 12px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; text-decoration: none; cursor: pointer; }
|
|
66
|
+
.btn:hover { border-color: var(--faint); }
|
|
67
|
+
.btn.primary { border-color: var(--accent); color: var(--accent); }
|
|
68
|
+
.btn:disabled { opacity: 0.5; cursor: default; }
|
|
69
|
+
.bake { color: var(--dim); font-size: 12px; margin: 6px 0; }
|
|
70
|
+
.bake.err { color: var(--err); }
|
|
71
|
+
pre.error, .warn pre { margin: 6px 0; padding: 8px; max-height: 200px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 4px; white-space: pre-wrap; }
|
|
72
|
+
pre.error { color: var(--err); }
|
|
73
|
+
.warn summary { color: var(--accent); font-size: 12px; cursor: pointer; }
|
|
74
|
+
.copy { display: grid; grid-template-columns: 70px minmax(0, 1fr) auto; align-items: center; gap: 6px; margin: 0 0 6px; }
|
|
75
|
+
.copy span { color: var(--dim); font-size: 12px; }
|
|
76
|
+
.copy input { min-width: 0; padding: 4px 6px; border-radius: 3px; border: 1px solid var(--line); background: var(--panel); color: var(--text); font: var(--mono); }
|
|
77
|
+
.copy button { padding: 4px 10px; border-radius: 3px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; }
|
|
78
|
+
.copy button.done { color: var(--ok); border-color: var(--ok); }
|
|
79
|
+
|
|
80
|
+
.shots { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
|
|
81
|
+
.shots a { display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--dim); font-size: 12px; min-width: 0; }
|
|
82
|
+
.shots img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 4px; border: 1px solid var(--line); background: var(--view); }
|
|
83
|
+
.shots span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
84
|
+
.files { list-style: none; margin: 0; padding: 0; }
|
|
85
|
+
.files li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px solid var(--line); }
|
|
86
|
+
.files li span { color: var(--dim); font-size: 12px; white-space: nowrap; }
|
|
87
|
+
.files a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
88
|
+
.graph h3 { color: var(--text); }
|
|
89
|
+
.vars { width: 100%; border-collapse: collapse; font-size: 13px; }
|
|
90
|
+
.vars th, .vars td { text-align: left; padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
|
|
91
|
+
.vars th { font-weight: 500; white-space: nowrap; }
|
|
92
|
+
.vars td:nth-child(2) { font: var(--mono); white-space: nowrap; }
|
|
93
|
+
.range { color: var(--faint); }
|
|
94
|
+
|
|
95
|
+
@media (max-width: 860px) {
|
|
96
|
+
.project { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "info" "more"; }
|
|
97
|
+
.bar { flex-wrap: wrap; }
|
|
98
|
+
#search { max-width: none; flex-basis: 100%; }
|
|
99
|
+
.grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
|
|
100
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// The gallery pages' script (src/gallery/pages.ts): search and tag filters on the grid, copy buttons and actions on a
|
|
2
|
+
// project page, and live updates from the server's event stream (a bake finished, projects added or removed).
|
|
3
|
+
const page = document.body.dataset.page;
|
|
4
|
+
const data = document.body.dataset.json ? JSON.parse(document.body.dataset.json) : {};
|
|
5
|
+
const $$ = (s) => [...document.querySelectorAll(s)];
|
|
6
|
+
|
|
7
|
+
if (page === 'gallery') {
|
|
8
|
+
const search = document.getElementById('search');
|
|
9
|
+
const chips = $$('.chip');
|
|
10
|
+
const filter = () => {
|
|
11
|
+
const words = search.value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
12
|
+
const tags = chips.filter((c) => c.getAttribute('aria-pressed') === 'true').map((c) => c.dataset.tag);
|
|
13
|
+
let shown = 0;
|
|
14
|
+
for (const card of $$('.card')) {
|
|
15
|
+
const own = card.dataset.tags.split('\n');
|
|
16
|
+
const ok = words.every((w) => card.dataset.hay.includes(w)) && tags.every((t) => own.includes(t));
|
|
17
|
+
card.hidden = !ok;
|
|
18
|
+
if (ok) shown++;
|
|
19
|
+
}
|
|
20
|
+
for (const sec of $$('.collection')) sec.hidden = !sec.querySelector('.card:not([hidden])');
|
|
21
|
+
document.getElementById('nomatch').hidden = shown > 0 || !$$('.card').length;
|
|
22
|
+
try { sessionStorage.setItem('gallery.filter', JSON.stringify({ q: search.value, tags })); } catch { /* storage blocked */ }
|
|
23
|
+
};
|
|
24
|
+
try {
|
|
25
|
+
const saved = JSON.parse(sessionStorage.getItem('gallery.filter') ?? 'null');
|
|
26
|
+
if (saved) { search.value = saved.q ?? ''; for (const c of chips) c.setAttribute('aria-pressed', String(saved.tags?.includes(c.dataset.tag) ?? false)); }
|
|
27
|
+
} catch { /* storage blocked */ }
|
|
28
|
+
search.addEventListener('input', filter);
|
|
29
|
+
for (const c of chips) c.addEventListener('click', () => { c.setAttribute('aria-pressed', String(c.getAttribute('aria-pressed') !== 'true')); filter(); });
|
|
30
|
+
document.addEventListener('keydown', (e) => { if (e.key === '/' && document.activeElement !== search) { e.preventDefault(); search.focus(); } });
|
|
31
|
+
filter();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (page === 'project') {
|
|
35
|
+
for (const b of $$('[data-copy]')) {
|
|
36
|
+
b.addEventListener('click', async () => {
|
|
37
|
+
const input = b.previousElementSibling;
|
|
38
|
+
input.select();
|
|
39
|
+
try { await navigator.clipboard.writeText(input.value); } catch { document.execCommand('copy'); }
|
|
40
|
+
b.textContent = 'Copied';
|
|
41
|
+
b.classList.add('done');
|
|
42
|
+
setTimeout(() => { b.textContent = 'Copy'; b.classList.remove('done'); }, 1500);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
for (const b of $$('[data-post]')) {
|
|
46
|
+
b.addEventListener('click', async () => {
|
|
47
|
+
b.disabled = true;
|
|
48
|
+
try {
|
|
49
|
+
const res = await fetch(`${location.pathname.replace(/\/$/, '')}/${b.dataset.post}`, { method: 'POST' });
|
|
50
|
+
const j = await res.json().catch(() => ({}));
|
|
51
|
+
if (b.dataset.post === 'bake') document.getElementById('bake').textContent = j.ok ? 'Baking…' : `Could not bake: ${j.error ?? res.status}`;
|
|
52
|
+
} finally { setTimeout(() => { b.disabled = false; }, 800); }
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// live updates: a finished bake reloads that project's thumbnail (grid) or the page (project); a changed list reloads
|
|
58
|
+
// the grid
|
|
59
|
+
const es = new EventSource('/api/events');
|
|
60
|
+
es.onmessage = (m) => {
|
|
61
|
+
let ev;
|
|
62
|
+
try { ev = JSON.parse(m.data); } catch { return; }
|
|
63
|
+
const key = `${data.lib}/${data.id}`;
|
|
64
|
+
if (page === 'gallery') {
|
|
65
|
+
if (ev.list) { location.reload(); return; }
|
|
66
|
+
if (ev.project) {
|
|
67
|
+
const card = document.querySelector(`.card[data-key="${CSS.escape(ev.project)}"]`);
|
|
68
|
+
if (!card) return;
|
|
69
|
+
const st = card.querySelector('.status');
|
|
70
|
+
if (ev.baking) { st.className = 'status s-baking'; st.textContent = 'baking…'; return; }
|
|
71
|
+
st.className = `status s-${ev.ok ? 'ok' : 'failed'}`;
|
|
72
|
+
st.textContent = ev.ok ? '' : 'bake failed';
|
|
73
|
+
const img = card.querySelector('img');
|
|
74
|
+
img.src = img.src.replace(/(\?v=[^&]*)?$/, `?v=${ev.version}`);
|
|
75
|
+
}
|
|
76
|
+
} else if (page === 'project') {
|
|
77
|
+
if (ev.project === key && ev.baking) document.getElementById('bake').textContent = 'Baking…';
|
|
78
|
+
else if ((ev.project === key && !ev.baking) || ev.changed?.includes(key)) location.reload();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import '../nodes/index.ts';
|
|
2
|
+
import type { BakeState } from './library.ts';
|
|
3
|
+
export declare const THUMB_SIZE = 512;
|
|
4
|
+
/** a preview.glb above this is not written (the page shows the thumbnail instead) */
|
|
5
|
+
export declare const MAX_PREVIEW_GLB: number;
|
|
6
|
+
/** a bake child is stopped after this */
|
|
7
|
+
export declare const BAKE_TIMEOUT_MS = 300000;
|
|
8
|
+
/** the simulation limit inside a bake child (the engine's default is 600 s per node) */
|
|
9
|
+
export declare const BAKE_SIM_TIMEOUT_MS = 120000;
|
|
10
|
+
/** Bake one project in this process. Never throws for a graph problem: the result (also in bake.json) says. */
|
|
11
|
+
export declare function bakeProject(dir: string): Promise<BakeState>;
|
|
12
|
+
export interface BakeQueueOptions {
|
|
13
|
+
/** called after each bake with the project folder and its new state (null: the child died without one) */
|
|
14
|
+
onDone?: (dir: string, state: BakeState | null) => void;
|
|
15
|
+
timeoutMs?: number;
|
|
16
|
+
log?: (msg: string) => void;
|
|
17
|
+
}
|
|
18
|
+
/** Bakes in child processes, one at a time, each project once however often it is asked for meanwhile. */
|
|
19
|
+
export declare class BakeQueue {
|
|
20
|
+
private queue;
|
|
21
|
+
private running;
|
|
22
|
+
private child;
|
|
23
|
+
private closed;
|
|
24
|
+
private opts;
|
|
25
|
+
constructor(opts?: BakeQueueOptions);
|
|
26
|
+
/** Ask for a bake; true when it was queued now (false: queued or running already). */
|
|
27
|
+
add(dir: string): boolean;
|
|
28
|
+
pending(dir: string): boolean;
|
|
29
|
+
get size(): number;
|
|
30
|
+
/** Resolves when nothing is queued or running. */
|
|
31
|
+
idle(): Promise<void>;
|
|
32
|
+
close(): void;
|
|
33
|
+
private next;
|
|
34
|
+
}
|