fast-mesh-wasm 0.5.3 → 0.7.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/README.md +2 -1
- package/dist/{client-f895H_yB.js → client-DFgvktkT.js} +183 -10
- package/dist/{client-D7yfPOyU.d.ts → client-nvmbhtn-.d.ts} +87 -14
- package/dist/{engine-BcJ5W6kS.js → engine-BL5_sWAf.js} +21 -6
- package/dist/io.d.ts +218 -5
- package/dist/io.js +3121 -12
- package/dist/{mesh-B3QP93wx.d.ts → mesh-BHTFxsXc.d.ts} +5 -2
- package/dist/{mesh-hPWBQPaN.js → mesh-DIWD2F5-.js} +51 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +3 -2
- package/dist/{protocol-Dt0zgang.d.ts → protocol-DFR0JDAS.d.ts} +9 -1
- package/dist/r3f.d.ts +3 -3
- package/dist/r3f.js +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{scene-CXtM_bxV.js → scene-DUsj6uJD.js} +421 -29
- package/dist/{scene-like-Dq9_SaUL.d.ts → scene-like-CR_Dpohm.d.ts} +999 -133
- package/dist/{store-CIW19oCh.d.ts → store-8HWG90Jg.d.ts} +14 -3
- package/dist/{store-C9h7GFFl.js → store-BAzHRRkt.js} +18 -2
- package/dist/store.d.ts +3 -3
- package/dist/store.js +1 -1
- package/dist/three.d.ts +2 -2
- package/dist/three.js +1 -1
- package/dist/views-BSy-Qeg8.js +584 -0
- package/dist/wasm/fast_mesh_wasm.d.ts +21 -1
- package/dist/wasm/fast_mesh_wasm.js +50 -1
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +3 -0
- package/dist/wasm-threads/fast_mesh_wasm.d.ts +21 -1
- package/dist/wasm-threads/fast_mesh_wasm.js +50 -1
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +3 -0
- package/dist/web.d.ts +2 -2
- package/dist/web.js +3 -2
- package/dist/worker-engine.d.ts +5 -3
- package/dist/worker-engine.js +1 -1
- package/dist/worker-entry.js +1 -1
- package/dist/worker.d.ts +1 -1
- package/dist/worker.js +1 -1
- package/package.json +1 -1
- package/dist/views-mp7Mf8CQ.js +0 -209
|
@@ -0,0 +1,584 @@
|
|
|
1
|
+
import { c as wasmMemory, n as call, t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
+
import { n as DEFAULT_NAN, t as DEFAULT_BASE } from "./colormap-Dr5V3bvs.js";
|
|
3
|
+
// src/domains/align.ts
|
|
4
|
+
/** Builds an {@link AlignDomain} backed by `backend`. */
|
|
5
|
+
function createAlignDomain(backend) {
|
|
6
|
+
return { register: (moving, fixed, options) => backend.register(moving, fixed, options) };
|
|
7
|
+
}
|
|
8
|
+
// src/domains/boolean.ts
|
|
9
|
+
function unsupportedError(isAsync, name) {
|
|
10
|
+
const err = new FastMeshError("INVALID_ARGUMENT", `${name} requires synchronous Scene (worker boolean/cut RPCs are not enabled)`);
|
|
11
|
+
if (isAsync) return Promise.reject(err);
|
|
12
|
+
throw err;
|
|
13
|
+
}
|
|
14
|
+
/** Builds a callable {@link BooleanDomain} backed by `backend`. */
|
|
15
|
+
function createBooleanDomain(backend) {
|
|
16
|
+
const runBoolean = (target, source, op) => {
|
|
17
|
+
if (backend.boolean === void 0) return unsupportedError(backend.isAsync, `boolean("${op}")`);
|
|
18
|
+
return backend.boolean(target, source, op);
|
|
19
|
+
};
|
|
20
|
+
const cut = (mesh, plane, options) => {
|
|
21
|
+
if (backend.cutByPlane === void 0) return unsupportedError(backend.isAsync, "boolean.cut");
|
|
22
|
+
return backend.cutByPlane(mesh, plane, options);
|
|
23
|
+
};
|
|
24
|
+
return Object.assign(runBoolean, {
|
|
25
|
+
union: (target, source) => runBoolean(target, source, "union"),
|
|
26
|
+
difference: (target, source) => runBoolean(target, source, "subtract"),
|
|
27
|
+
subtract: (target, source) => runBoolean(target, source, "subtract"),
|
|
28
|
+
intersection: (target, source) => runBoolean(target, source, "intersect"),
|
|
29
|
+
intersect: (target, source) => runBoolean(target, source, "intersect"),
|
|
30
|
+
cut,
|
|
31
|
+
cutByPlane: cut,
|
|
32
|
+
offset: (mesh, options) => backend.repair(mesh, {
|
|
33
|
+
op: "offset",
|
|
34
|
+
...options
|
|
35
|
+
}),
|
|
36
|
+
shell: (mesh, thickness) => backend.repair(mesh, {
|
|
37
|
+
op: "shell",
|
|
38
|
+
thickness: typeof thickness === "number" ? thickness : thickness.thickness
|
|
39
|
+
})
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
// src/domains/deform.ts
|
|
43
|
+
/** Builds a {@link DeformDomain} backed by `backend`. */
|
|
44
|
+
function createDeformDomain(backend) {
|
|
45
|
+
const relax = (mesh, op) => backend.sculpt(mesh, {
|
|
46
|
+
op: "relax",
|
|
47
|
+
...op
|
|
48
|
+
});
|
|
49
|
+
const protectFn = ((meshOrOp, opOrProtection, maybeProtection) => {
|
|
50
|
+
if (maybeProtection !== void 0) {
|
|
51
|
+
const mesh = meshOrOp;
|
|
52
|
+
const op = {
|
|
53
|
+
...opOrProtection,
|
|
54
|
+
protect: maybeProtection
|
|
55
|
+
};
|
|
56
|
+
return backend.sculpt(mesh, op);
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...meshOrOp,
|
|
60
|
+
protect: opOrProtection
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
inflate: (mesh, op) => backend.sculpt(mesh, {
|
|
65
|
+
op: "inflate",
|
|
66
|
+
...op
|
|
67
|
+
}),
|
|
68
|
+
smooth: (mesh, op) => backend.sculpt(mesh, {
|
|
69
|
+
op: "smooth",
|
|
70
|
+
...op
|
|
71
|
+
}),
|
|
72
|
+
relax,
|
|
73
|
+
relaxed: relax,
|
|
74
|
+
grab: (mesh, op) => backend.sculpt(mesh, {
|
|
75
|
+
op: "grab",
|
|
76
|
+
...op
|
|
77
|
+
}),
|
|
78
|
+
flatten: (mesh, op) => backend.sculpt(mesh, {
|
|
79
|
+
op: "flatten",
|
|
80
|
+
...op
|
|
81
|
+
}),
|
|
82
|
+
crease: (mesh, op) => backend.sculpt(mesh, {
|
|
83
|
+
op: "crease",
|
|
84
|
+
...op
|
|
85
|
+
}),
|
|
86
|
+
clay: (mesh, op) => backend.sculpt(mesh, {
|
|
87
|
+
op: "clay",
|
|
88
|
+
...op
|
|
89
|
+
}),
|
|
90
|
+
twist: (mesh, op) => backend.sculpt(mesh, {
|
|
91
|
+
op: "twist",
|
|
92
|
+
...op
|
|
93
|
+
}),
|
|
94
|
+
protect: protectFn
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
// src/domains/inspect.ts
|
|
98
|
+
/** Builds an {@link InspectDomain} backed by `backend`. */
|
|
99
|
+
function createInspectDomain(backend) {
|
|
100
|
+
return {
|
|
101
|
+
analyze: (mesh, options) => backend.analyze(mesh, options),
|
|
102
|
+
measure: (mesh) => backend.measure(mesh),
|
|
103
|
+
bounds: (mesh) => backend.bounds(mesh),
|
|
104
|
+
raycast: (origin, direction, options) => backend.raycast(origin, direction, options),
|
|
105
|
+
closestPoint: (point, options) => backend.closestPoint(point, options),
|
|
106
|
+
meshDistance: (a, b, options) => backend.meshDistance(a, b, options),
|
|
107
|
+
intersects: (a, b) => backend.intersects(a, b),
|
|
108
|
+
findContacts: (options) => backend.findContacts(options),
|
|
109
|
+
addDistanceField: (desc) => backend.addDistanceField(desc),
|
|
110
|
+
addThicknessField: (desc) => {
|
|
111
|
+
if (backend.addThicknessField === void 0) throw new FastMeshError("INVALID_ARGUMENT", "addThicknessField requires synchronous Scene (worker RPC not enabled)");
|
|
112
|
+
return backend.addThicknessField(desc);
|
|
113
|
+
},
|
|
114
|
+
addCurvatureField: (desc) => {
|
|
115
|
+
if (backend.addCurvatureField === void 0) throw new FastMeshError("INVALID_ARGUMENT", "addCurvatureField requires synchronous Scene (worker RPC not enabled)");
|
|
116
|
+
return backend.addCurvatureField(desc);
|
|
117
|
+
},
|
|
118
|
+
removeField: (field) => backend.removeField(field),
|
|
119
|
+
fieldValues: (field) => backend.fieldValues(field),
|
|
120
|
+
fieldNearest: (field) => backend.fieldNearest(field),
|
|
121
|
+
fieldStatus: (field) => backend.fieldStatus(field),
|
|
122
|
+
fieldTargetStatus: (field) => backend.fieldTargetStatus(field),
|
|
123
|
+
setColoring: (mesh, rule) => backend.setColoring(mesh, rule),
|
|
124
|
+
coloring: (mesh) => backend.coloring(mesh),
|
|
125
|
+
addSection: (desc) => backend.addSection(desc),
|
|
126
|
+
setSectionPlane: (section, plane) => backend.setSectionPlane(section, plane),
|
|
127
|
+
sectionPlane: (section) => backend.sectionPlane(section),
|
|
128
|
+
setSectionMeshes: (section, meshes) => backend.setSectionMeshes(section, meshes),
|
|
129
|
+
setSectionFill: (section, fill) => backend.setSectionFill(section, fill),
|
|
130
|
+
removeSection: (section) => backend.removeSection(section),
|
|
131
|
+
section: (section, mesh) => backend.section(section, mesh),
|
|
132
|
+
sectionGap: (section, a, b) => backend.sectionGap(section, a, b),
|
|
133
|
+
updateSections: () => backend.updateSections?.()
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
// src/domains/remesh.ts
|
|
137
|
+
/** Builds a {@link RemeshDomain} backed by `backend`. */
|
|
138
|
+
function createRemeshDomain(backend) {
|
|
139
|
+
const region = (mesh, options) => backend.repair(mesh, {
|
|
140
|
+
op: "remesh",
|
|
141
|
+
...options
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
remesh: region,
|
|
145
|
+
region,
|
|
146
|
+
simplify: (mesh, options) => backend.repair(mesh, {
|
|
147
|
+
op: "simplify",
|
|
148
|
+
...options
|
|
149
|
+
}),
|
|
150
|
+
subdivide: (mesh, options = {}) => backend.repair(mesh, {
|
|
151
|
+
op: "subdivide",
|
|
152
|
+
...options
|
|
153
|
+
}),
|
|
154
|
+
voxel: (mesh, options = {}) => backend.repair(mesh, {
|
|
155
|
+
op: "offset",
|
|
156
|
+
distance: 0,
|
|
157
|
+
algorithm: options.algorithm ?? "fhEdt",
|
|
158
|
+
voxelSize: options.voxelSize,
|
|
159
|
+
maxVoxels: options.maxVoxels
|
|
160
|
+
})
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
// src/domains/repair.ts
|
|
164
|
+
function isPromiseLike$1(value) {
|
|
165
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
166
|
+
}
|
|
167
|
+
/** Builds a callable {@link RepairDomain} backed by `backend`. */
|
|
168
|
+
function createRepairDomain(backend) {
|
|
169
|
+
const callable = ((mesh, op) => backend.repair(mesh, op));
|
|
170
|
+
const bridgeLoops = (mesh, options) => backend.repair(mesh, {
|
|
171
|
+
op: "bridgeLoops",
|
|
172
|
+
...options
|
|
173
|
+
});
|
|
174
|
+
return Object.assign(callable, {
|
|
175
|
+
analyze: (mesh, options) => backend.analyze(mesh, options),
|
|
176
|
+
autoRepair: (mesh, options = {}) => backend.repair(mesh, {
|
|
177
|
+
kind: "auto",
|
|
178
|
+
...options
|
|
179
|
+
}),
|
|
180
|
+
clean: (mesh, options = {}) => {
|
|
181
|
+
const degOp = {
|
|
182
|
+
op: "removeDegenerate",
|
|
183
|
+
areaEpsilon: options.areaEpsilon,
|
|
184
|
+
removeUnusedVertices: options.removeUnusedVertices
|
|
185
|
+
};
|
|
186
|
+
if (options.minTriangles === void 0 && options.minArea === void 0) {
|
|
187
|
+
const res = backend.repair(mesh, degOp);
|
|
188
|
+
const mapDegenerate = (degenerate) => ({
|
|
189
|
+
degenerate,
|
|
190
|
+
components: {
|
|
191
|
+
removedComponents: 0,
|
|
192
|
+
removedTriangles: 0,
|
|
193
|
+
removedVertices: 0
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
return isPromiseLike$1(res) ? res.then(mapDegenerate) : mapDegenerate(res);
|
|
197
|
+
}
|
|
198
|
+
const res = backend.repair(mesh, [degOp, {
|
|
199
|
+
op: "removeSmallComponents",
|
|
200
|
+
minTriangles: options.minTriangles,
|
|
201
|
+
minArea: options.minArea,
|
|
202
|
+
keepLargest: options.keepLargest
|
|
203
|
+
}]);
|
|
204
|
+
const mapReport = ([degenerate, components]) => ({
|
|
205
|
+
degenerate,
|
|
206
|
+
components
|
|
207
|
+
});
|
|
208
|
+
return isPromiseLike$1(res) ? res.then(mapReport) : mapReport(res);
|
|
209
|
+
},
|
|
210
|
+
weld: (mesh, tolerance) => backend.repair(mesh, {
|
|
211
|
+
op: "weld",
|
|
212
|
+
tolerance
|
|
213
|
+
}),
|
|
214
|
+
removeDegenerate: (mesh, options = {}) => backend.repair(mesh, {
|
|
215
|
+
op: "removeDegenerate",
|
|
216
|
+
...options
|
|
217
|
+
}),
|
|
218
|
+
removeSmallComponents: (mesh, options = {}) => backend.repair(mesh, {
|
|
219
|
+
op: "removeSmallComponents",
|
|
220
|
+
...options
|
|
221
|
+
}),
|
|
222
|
+
orient: (mesh) => backend.repair(mesh, { op: "orient" }),
|
|
223
|
+
fillHoles: (mesh, options = {}) => backend.repair(mesh, {
|
|
224
|
+
op: "fillHoles",
|
|
225
|
+
...options
|
|
226
|
+
}),
|
|
227
|
+
bridge: bridgeLoops,
|
|
228
|
+
bridgeLoops,
|
|
229
|
+
join: (target, source, options) => backend.join(target, source, options),
|
|
230
|
+
makeManifold: (mesh, options = {}) => backend.repair(mesh, {
|
|
231
|
+
op: "makeManifold",
|
|
232
|
+
...options
|
|
233
|
+
}),
|
|
234
|
+
resolveSelfIntersections: (mesh, options = {}) => backend.repair(mesh, {
|
|
235
|
+
op: "resolveSelfIntersections",
|
|
236
|
+
...options
|
|
237
|
+
}),
|
|
238
|
+
cleanupSlivers: (mesh, options = {}) => backend.repair(mesh, {
|
|
239
|
+
op: "cleanupSlivers",
|
|
240
|
+
...options
|
|
241
|
+
})
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
// src/domains/sculpt.ts
|
|
245
|
+
function isPromiseLike(value) {
|
|
246
|
+
return typeof value === "object" && value !== null && "then" in value && typeof value.then === "function";
|
|
247
|
+
}
|
|
248
|
+
/** Builds a callable {@link SculptDomain} backed by `backend`. */
|
|
249
|
+
function createSculptDomain(backend) {
|
|
250
|
+
const callable = ((mesh, op) => backend.sculpt(mesh, op));
|
|
251
|
+
let strokeDepth = 0;
|
|
252
|
+
const filterFn = ((meshOrOp, opOrFilter, maybeFilter) => {
|
|
253
|
+
if (maybeFilter !== void 0) {
|
|
254
|
+
const mesh = meshOrOp;
|
|
255
|
+
const op = {
|
|
256
|
+
...opOrFilter,
|
|
257
|
+
filter: maybeFilter
|
|
258
|
+
};
|
|
259
|
+
return backend.sculpt(mesh, op);
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
...meshOrOp,
|
|
263
|
+
filter: opOrFilter
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
return Object.assign(callable, {
|
|
267
|
+
beginStroke: (mesh, options = {}) => {
|
|
268
|
+
const grouped = (options.groupStep ?? true) && backend.beginStep !== void 0;
|
|
269
|
+
if (grouped) {
|
|
270
|
+
backend.beginStep?.();
|
|
271
|
+
strokeDepth++;
|
|
272
|
+
}
|
|
273
|
+
const rollback = () => {
|
|
274
|
+
if (grouped && strokeDepth > 0) {
|
|
275
|
+
strokeDepth--;
|
|
276
|
+
try {
|
|
277
|
+
backend.cancelStep?.();
|
|
278
|
+
} catch {}
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
try {
|
|
282
|
+
const res = backend.sculpt(mesh, {
|
|
283
|
+
op: "captureStrokeState",
|
|
284
|
+
onlyIfMissing: options.onlyIfMissing
|
|
285
|
+
});
|
|
286
|
+
if (!options.captureRestSizes) {
|
|
287
|
+
if (isPromiseLike(res)) return res.catch((err) => {
|
|
288
|
+
rollback();
|
|
289
|
+
throw err;
|
|
290
|
+
});
|
|
291
|
+
return res;
|
|
292
|
+
}
|
|
293
|
+
if (isPromiseLike(res)) return res.then((report) => backend.sculpt(mesh, {
|
|
294
|
+
op: "captureRestSizes",
|
|
295
|
+
onlyIfMissing: options.onlyIfMissing
|
|
296
|
+
}).then(() => report)).catch((err) => {
|
|
297
|
+
rollback();
|
|
298
|
+
throw err;
|
|
299
|
+
});
|
|
300
|
+
backend.sculpt(mesh, {
|
|
301
|
+
op: "captureRestSizes",
|
|
302
|
+
onlyIfMissing: options.onlyIfMissing
|
|
303
|
+
});
|
|
304
|
+
return res;
|
|
305
|
+
} catch (err) {
|
|
306
|
+
rollback();
|
|
307
|
+
throw err;
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
dab: callable,
|
|
311
|
+
endStroke: () => {
|
|
312
|
+
if (strokeDepth > 0 && backend.endStep !== void 0) {
|
|
313
|
+
strokeDepth--;
|
|
314
|
+
backend.endStep();
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
cancelStroke: () => {
|
|
318
|
+
if (strokeDepth > 0 && backend.cancelStep !== void 0) {
|
|
319
|
+
strokeDepth = 0;
|
|
320
|
+
backend.cancelStep();
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
throw new FastMeshError("STEP_NOT_OPEN", backend.cancelStep === void 0 ? "cancelStroke requires synchronous Scene step history" : "no active sculpt stroke");
|
|
324
|
+
},
|
|
325
|
+
filter: filterFn,
|
|
326
|
+
inflate: (mesh, op) => backend.sculpt(mesh, {
|
|
327
|
+
op: "inflate",
|
|
328
|
+
...op
|
|
329
|
+
}),
|
|
330
|
+
smooth: (mesh, op) => backend.sculpt(mesh, {
|
|
331
|
+
op: "smooth",
|
|
332
|
+
...op
|
|
333
|
+
}),
|
|
334
|
+
relax: (mesh, op) => backend.sculpt(mesh, {
|
|
335
|
+
op: "relax",
|
|
336
|
+
...op
|
|
337
|
+
}),
|
|
338
|
+
grab: (mesh, op) => backend.sculpt(mesh, {
|
|
339
|
+
op: "grab",
|
|
340
|
+
...op
|
|
341
|
+
}),
|
|
342
|
+
flatten: (mesh, op) => backend.sculpt(mesh, {
|
|
343
|
+
op: "flatten",
|
|
344
|
+
...op
|
|
345
|
+
}),
|
|
346
|
+
crease: (mesh, op) => backend.sculpt(mesh, {
|
|
347
|
+
op: "crease",
|
|
348
|
+
...op
|
|
349
|
+
}),
|
|
350
|
+
clay: (mesh, op) => backend.sculpt(mesh, {
|
|
351
|
+
op: "clay",
|
|
352
|
+
...op
|
|
353
|
+
}),
|
|
354
|
+
twist: (mesh, op) => backend.sculpt(mesh, {
|
|
355
|
+
op: "twist",
|
|
356
|
+
...op
|
|
357
|
+
}),
|
|
358
|
+
captureStrokeState: (mesh, options = {}) => backend.sculpt(mesh, {
|
|
359
|
+
op: "captureStrokeState",
|
|
360
|
+
...options
|
|
361
|
+
}),
|
|
362
|
+
captureRestSizes: (mesh, options = {}) => backend.sculpt(mesh, {
|
|
363
|
+
op: "captureRestSizes",
|
|
364
|
+
...options
|
|
365
|
+
}),
|
|
366
|
+
splitStretched: (mesh, op) => backend.sculpt(mesh, {
|
|
367
|
+
op: "splitStretched",
|
|
368
|
+
...op
|
|
369
|
+
}),
|
|
370
|
+
verticesInSphere: (mesh, center, radius) => backend.verticesInSphere(mesh, center, radius)
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
// src/register.ts
|
|
374
|
+
function invalid$1(message) {
|
|
375
|
+
return new FastMeshError("INVALID_ARGUMENT", message);
|
|
376
|
+
}
|
|
377
|
+
function isNumber(v) {
|
|
378
|
+
return typeof v === "number" && !Number.isNaN(v);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Throws `INVALID_ARGUMENT` for an option out of range or for one mesh twice.
|
|
382
|
+
* Unset options are valid: they take their defaults.
|
|
383
|
+
*/
|
|
384
|
+
function checkRegisterOptions(sameMesh, o) {
|
|
385
|
+
if (sameMesh) throw invalid$1("cannot register a mesh to itself");
|
|
386
|
+
const { maxIterations: it, tolerance: tol, overlap, maxDistance: far, maxSamples: cap, maxRmse: rmse } = o;
|
|
387
|
+
if (it !== void 0 && !(Number.isInteger(it) && it >= 0)) throw invalid$1("maxIterations must be a non-negative integer");
|
|
388
|
+
if (tol !== void 0 && !(isNumber(tol) && Number.isFinite(tol) && tol >= 0)) throw invalid$1("tolerance must be finite and zero or greater");
|
|
389
|
+
if (overlap !== void 0 && !(isNumber(overlap) && overlap > 0 && overlap <= 1)) throw invalid$1("overlap must be in (0, 1]");
|
|
390
|
+
if (far !== void 0 && !(isNumber(far) && far > 0)) throw invalid$1("maxDistance must be positive");
|
|
391
|
+
if (cap !== void 0 && !(Number.isInteger(cap) && cap >= 1)) throw invalid$1("maxSamples must be a positive integer");
|
|
392
|
+
if (rmse !== void 0 && !(isNumber(rmse) && rmse >= 0)) throw invalid$1("maxRmse must be zero or greater");
|
|
393
|
+
if (o.apply !== void 0 && typeof o.apply !== "boolean") throw invalid$1("apply must be a boolean");
|
|
394
|
+
}
|
|
395
|
+
// src/handles.ts
|
|
396
|
+
/**
|
|
397
|
+
* A mesh in a {@link Scene}. Opaque: pass it to the scene's methods. The same
|
|
398
|
+
* mesh always gives the same handle object, so handles compare with `===`.
|
|
399
|
+
*/
|
|
400
|
+
var MeshHandle = class {};
|
|
401
|
+
/**
|
|
402
|
+
* A field in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle}.
|
|
403
|
+
* The scene keeps every field handle it gave out for its own lifetime, even
|
|
404
|
+
* after the field is removed, so a removal in a change record names the same
|
|
405
|
+
* object you hold.
|
|
406
|
+
*/
|
|
407
|
+
var FieldHandle = class {};
|
|
408
|
+
/**
|
|
409
|
+
* A section in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle},
|
|
410
|
+
* and kept for the scene's lifetime like {@link FieldHandle}.
|
|
411
|
+
*/
|
|
412
|
+
var SectionHandle = class {};
|
|
413
|
+
/** A quaternion as a row-major rotation matrix, normalised first, in f64. */
|
|
414
|
+
function quatToMat3(q) {
|
|
415
|
+
const n = Math.hypot(q[0], q[1], q[2], q[3]);
|
|
416
|
+
if (!(n > 0) || !Number.isFinite(n)) throw new FastMeshError("INVALID_ARGUMENT", "quaternion must be non-zero and finite");
|
|
417
|
+
const x = q[0] / n;
|
|
418
|
+
const y = q[1] / n;
|
|
419
|
+
const z = q[2] / n;
|
|
420
|
+
const w = q[3] / n;
|
|
421
|
+
return [
|
|
422
|
+
1 - 2 * (y * y + z * z),
|
|
423
|
+
2 * (x * y - z * w),
|
|
424
|
+
2 * (x * z + y * w),
|
|
425
|
+
2 * (x * y + z * w),
|
|
426
|
+
1 - 2 * (x * x + z * z),
|
|
427
|
+
2 * (y * z - x * w),
|
|
428
|
+
2 * (x * z - y * w),
|
|
429
|
+
2 * (y * z + x * w),
|
|
430
|
+
1 - 2 * (x * x + y * y)
|
|
431
|
+
];
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* A placement rotation as 9 numbers, row-major (a quaternion converted in
|
|
435
|
+
* f64). Internal: shared with the Worker client, not part of the public API.
|
|
436
|
+
*/
|
|
437
|
+
function rotationMatrix(rotation) {
|
|
438
|
+
if (rotation.length === 4) return quatToMat3(rotation);
|
|
439
|
+
if (rotation.length === 9) return Array.from(rotation);
|
|
440
|
+
throw new FastMeshError("INVALID_ARGUMENT", "rotation must be a 3×3 matrix (9 numbers) or a quaternion (4 numbers)");
|
|
441
|
+
}
|
|
442
|
+
/** A distance field's target or targets (`DistanceFieldDesc.to`), as a list. Internal. */
|
|
443
|
+
function targetsOf(to) {
|
|
444
|
+
return Array.isArray(to) ? to : [to];
|
|
445
|
+
}
|
|
446
|
+
// src/rule.ts
|
|
447
|
+
const MAPS = {
|
|
448
|
+
turbo: 0,
|
|
449
|
+
viridis: 1,
|
|
450
|
+
coolwarm: 2,
|
|
451
|
+
grayscale: 3
|
|
452
|
+
};
|
|
453
|
+
const OUT_OF_RANGE = {
|
|
454
|
+
clamp: 0,
|
|
455
|
+
base: 1
|
|
456
|
+
};
|
|
457
|
+
function invalid(message) {
|
|
458
|
+
return new FastMeshError("INVALID_ARGUMENT", message);
|
|
459
|
+
}
|
|
460
|
+
/** The code of a string option in `table`, or `INVALID_ARGUMENT` naming `what`. */
|
|
461
|
+
function codeIn(table, value, what) {
|
|
462
|
+
if (!Object.hasOwn(table, value)) throw invalid(`${what} must be one of ${Object.keys(table).join(", ")}`);
|
|
463
|
+
return table[value];
|
|
464
|
+
}
|
|
465
|
+
/** A colour rule as the binding's `(map, rule)`: see `parse_rule` in the Rust crate. */
|
|
466
|
+
function encodeRule(rule) {
|
|
467
|
+
if (rule.range?.length !== 2) throw invalid("range must be [lo, hi]");
|
|
468
|
+
if (rule.center !== void 0 && Number.isNaN(rule.center)) throw invalid("color center must lie within the range");
|
|
469
|
+
const base = rule.base ?? DEFAULT_BASE;
|
|
470
|
+
const nan = rule.nan ?? DEFAULT_NAN;
|
|
471
|
+
if (base.length !== 4) throw invalid("base must have 4 channels");
|
|
472
|
+
if (nan.length !== 4) throw invalid("nan must have 4 channels");
|
|
473
|
+
const values = [
|
|
474
|
+
rule.range[0],
|
|
475
|
+
rule.range[1],
|
|
476
|
+
rule.center ?? NaN,
|
|
477
|
+
codeIn(OUT_OF_RANGE, rule.below ?? "clamp", "below"),
|
|
478
|
+
codeIn(OUT_OF_RANGE, rule.above ?? "base", "above"),
|
|
479
|
+
...base,
|
|
480
|
+
...nan
|
|
481
|
+
];
|
|
482
|
+
let map;
|
|
483
|
+
if (typeof rule.map === "string") map = codeIn(MAPS, rule.map, "map");
|
|
484
|
+
else if (typeof rule.map === "object" && rule.map !== null && Array.isArray(rule.map.stops)) {
|
|
485
|
+
map = 4;
|
|
486
|
+
for (const stop of rule.map.stops) {
|
|
487
|
+
if (!Array.isArray(stop) || stop.length !== 2) throw invalid("each stop must be [t, rgba]");
|
|
488
|
+
const [t, color] = stop;
|
|
489
|
+
if (typeof color !== "object" || color === null || color.length !== 4) throw invalid("stop colours must have 4 channels");
|
|
490
|
+
values.push(t, ...Array.from(color));
|
|
491
|
+
}
|
|
492
|
+
} else throw invalid("map must be \"turbo\", \"viridis\", \"coolwarm\", \"grayscale\" or { stops }");
|
|
493
|
+
return {
|
|
494
|
+
map,
|
|
495
|
+
values: Float32Array.from(values)
|
|
496
|
+
};
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* A deep, frozen copy of a colour rule (the field handle kept, not frozen):
|
|
500
|
+
* its range and colours, and a custom map's stops with their colours, so
|
|
501
|
+
* later changes to the caller's object do not leak in and callers of
|
|
502
|
+
* `coloring()` cannot change it. Colours given as typed arrays become plain
|
|
503
|
+
* arrays (a typed array cannot be frozen). Copies what it is given; the
|
|
504
|
+
* engine checks it.
|
|
505
|
+
*/
|
|
506
|
+
function copyRule(rule) {
|
|
507
|
+
const frozen = (x) => Array.isArray(x) || ArrayBuffer.isView(x) ? Object.freeze(Array.from(x)) : x;
|
|
508
|
+
const copy = { ...rule };
|
|
509
|
+
for (const [k, v] of Object.entries(copy)) if (k !== "field") copy[k] = frozen(v);
|
|
510
|
+
const stops = rule.map?.stops;
|
|
511
|
+
if (Array.isArray(stops)) copy.map = Object.freeze({ stops: Object.freeze(stops.map((stop) => Array.isArray(stop) ? Object.freeze(stop.map(frozen)) : stop)) });
|
|
512
|
+
return Object.freeze(copy);
|
|
513
|
+
}
|
|
514
|
+
/** @internal The argument of `setFieldInteraction`, checked. */
|
|
515
|
+
function checkInteractionPoints(points) {
|
|
516
|
+
if (points !== null && (!Number.isInteger(points) || points < 1 || points >= 2 ** 32)) throw new FastMeshError("INVALID_ARGUMENT", "an interaction's points must be null or an integer in [1, 2^32)");
|
|
517
|
+
return points;
|
|
518
|
+
}
|
|
519
|
+
// src/views.ts
|
|
520
|
+
/**
|
|
521
|
+
* Debug-mode check of kept views. The scene bumps the epoch on every call
|
|
522
|
+
* that may allocate or move buffers; a guarded view is a `Proxy` over the
|
|
523
|
+
* typed array that, on every access, warns (once per guard) when the epoch
|
|
524
|
+
* moved since the view was made, or the memory growth detached it.
|
|
525
|
+
*/
|
|
526
|
+
var ViewGuard = class {
|
|
527
|
+
#epoch = 0;
|
|
528
|
+
#warned = false;
|
|
529
|
+
/** A scene call that may allocate or move buffers is about to run. */
|
|
530
|
+
bump() {
|
|
531
|
+
this.#epoch++;
|
|
532
|
+
}
|
|
533
|
+
/** `view`, checked on every access. */
|
|
534
|
+
wrap(view) {
|
|
535
|
+
const born = this.#epoch;
|
|
536
|
+
const attached = view.byteLength > 0;
|
|
537
|
+
const check = () => {
|
|
538
|
+
if (!this.#warned && (this.#epoch !== born || attached && view.byteLength === 0)) {
|
|
539
|
+
this.#warned = true;
|
|
540
|
+
console.warn("fast-mesh-wasm: a render view was read after a scene call that may have moved or freed its buffer, so it may read other data or be empty. Views are only valid until the next scene call: re-acquire them right before use (scene.views(mesh).positions() etc.) and do not keep them.");
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
return new Proxy(view, {
|
|
544
|
+
get(target, key) {
|
|
545
|
+
check();
|
|
546
|
+
const value = Reflect.get(target, key, target);
|
|
547
|
+
return typeof value === "function" ? value.bind(target) : value;
|
|
548
|
+
},
|
|
549
|
+
set(target, key, value) {
|
|
550
|
+
check();
|
|
551
|
+
return Reflect.set(target, key, value, target);
|
|
552
|
+
},
|
|
553
|
+
has(target, key) {
|
|
554
|
+
check();
|
|
555
|
+
return Reflect.has(target, key);
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
/**
|
|
561
|
+
* The views of mesh `(index, generation)`. `scene` returns the live raw scene
|
|
562
|
+
* (it throws once the scene is freed); every getter goes through it.
|
|
563
|
+
*/
|
|
564
|
+
function meshViews(scene, index, generation, guard) {
|
|
565
|
+
const build = (make, ptr, len) => {
|
|
566
|
+
const s = scene();
|
|
567
|
+
const p = call(() => ptr(s));
|
|
568
|
+
if (p === 0) return null;
|
|
569
|
+
const view = make(wasmMemory().buffer, p, call(() => len(s)));
|
|
570
|
+
return guard === void 0 ? view : guard.wrap(view);
|
|
571
|
+
};
|
|
572
|
+
const f32 = (b, p, n) => new Float32Array(b, p, n);
|
|
573
|
+
const u8 = (b, p, n) => new Uint8Array(b, p, n);
|
|
574
|
+
const u32 = (b, p, n) => new Uint32Array(b, p, n);
|
|
575
|
+
return {
|
|
576
|
+
positions: () => build(f32, (s) => s.positions_ptr(index, generation), (s) => s.positions_len(index, generation)),
|
|
577
|
+
normals: () => build(f32, (s) => s.normals_ptr(index, generation), (s) => s.normals_len(index, generation)),
|
|
578
|
+
colors: () => build(u8, (s) => s.colors_ptr(index, generation), (s) => s.colors_len(index, generation)),
|
|
579
|
+
values: () => build(f32, (s) => s.values_ptr(index, generation), (s) => s.values_len(index, generation)),
|
|
580
|
+
uvs: () => build(f32, (s) => s.uvs_ptr(index, generation), (s) => s.uvs_len(index, generation)),
|
|
581
|
+
indices: () => build(u32, (s) => s.indices_ptr(index, generation), (s) => s.indices_len(index, generation))
|
|
582
|
+
};
|
|
583
|
+
}
|
|
584
|
+
export { createBooleanDomain as _, encodeRule as a, SectionHandle as c, checkRegisterOptions as d, createSculptDomain as f, createDeformDomain as g, createInspectDomain as h, copyRule as i, rotationMatrix as l, createRemeshDomain as m, meshViews as n, FieldHandle as o, createRepairDomain as p, checkInteractionPoints as r, MeshHandle as s, ViewGuard as t, targetsOf as u, createAlignDomain as v };
|
|
@@ -200,7 +200,8 @@ export class WasmScene {
|
|
|
200
200
|
* the same placement. Returns `[kept index, kept generation, added
|
|
201
201
|
* index, added generation, kept triangles, removed triangles, cap
|
|
202
202
|
* triangles]`. With `cap` (the usual case) both openings are closed
|
|
203
|
-
* with flat, unfaired patches
|
|
203
|
+
* with flat, unfaired patches, across UV seams on a mesh with UVs;
|
|
204
|
+
* without it both parts keep the open rim.
|
|
204
205
|
* The cut undoes in one step; the added mesh stays, like the removed
|
|
205
206
|
* source of [`WasmScene::join`].
|
|
206
207
|
*/
|
|
@@ -363,6 +364,11 @@ export class WasmScene {
|
|
|
363
364
|
* off.
|
|
364
365
|
*/
|
|
365
366
|
normals_ptr(index: number, generation: number): number;
|
|
367
|
+
/**
|
|
368
|
+
* The mesh's origin: its stored positions are relative to it, and
|
|
369
|
+
* `setPositions` takes positions with it added back.
|
|
370
|
+
*/
|
|
371
|
+
origin(index: number, generation: number): Float64Array;
|
|
366
372
|
/**
|
|
367
373
|
* The placement: the row-major rotation (9 values), then the
|
|
368
374
|
* translation (3 values), then the scale (3 values).
|
|
@@ -448,6 +454,11 @@ export class WasmScene {
|
|
|
448
454
|
* [`Scene::set_defer_fields`].
|
|
449
455
|
*/
|
|
450
456
|
set_defer_fields(on: boolean): void;
|
|
457
|
+
/**
|
|
458
|
+
* Starts (a budget of `points`) or ends (`undefined`) an interaction; see
|
|
459
|
+
* [`Scene::set_field_interaction`].
|
|
460
|
+
*/
|
|
461
|
+
set_field_interaction(points?: number | null): void;
|
|
451
462
|
/**
|
|
452
463
|
* Sets when the mesh's BVH, normals, fields and sections follow its
|
|
453
464
|
* edits: 0 (Eager), 1 (Lazy) or 2 (Manual).
|
|
@@ -524,6 +535,12 @@ export class WasmScene {
|
|
|
524
535
|
* Vertex slots, alive or dead: the length of the vertex buffers.
|
|
525
536
|
*/
|
|
526
537
|
vertex_slots(index: number, generation: number): number;
|
|
538
|
+
/**
|
|
539
|
+
* Live triangle-used vertex ids of a mesh inside the closed local-space
|
|
540
|
+
* sphere `(cx, cy, cz, radius)`, in ascending order. Brings a Lazy BVH up
|
|
541
|
+
* to date first; refuses a stale Manual BVH with `STALE_BVH`.
|
|
542
|
+
*/
|
|
543
|
+
vertices_in_sphere(index: number, generation: number, cx: number, cy: number, cz: number, radius: number): Uint32Array;
|
|
527
544
|
/**
|
|
528
545
|
* Removes a field never computed, reporting nothing; `false` (nothing
|
|
529
546
|
* done) when it was computed or colours its mesh. See
|
|
@@ -609,6 +626,7 @@ export interface InitOutput {
|
|
|
609
626
|
readonly wasmscene_new: () => number;
|
|
610
627
|
readonly wasmscene_normals_len: (a: number, b: number, c: number) => [number, number, number];
|
|
611
628
|
readonly wasmscene_normals_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
629
|
+
readonly wasmscene_origin: (a: number, b: number, c: number) => [number, number, number, number];
|
|
612
630
|
readonly wasmscene_placement: (a: number, b: number, c: number) => [number, number, number, number];
|
|
613
631
|
readonly wasmscene_positions_len: (a: number, b: number, c: number) => [number, number, number];
|
|
614
632
|
readonly wasmscene_positions_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
@@ -624,6 +642,7 @@ export interface InitOutput {
|
|
|
624
642
|
readonly wasmscene_section_gap: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
625
643
|
readonly wasmscene_set_coloring: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number];
|
|
626
644
|
readonly wasmscene_set_defer_fields: (a: number, b: number) => void;
|
|
645
|
+
readonly wasmscene_set_field_interaction: (a: number, b: number) => [number, number];
|
|
627
646
|
readonly wasmscene_set_mode: (a: number, b: number, c: number, d: number) => [number, number];
|
|
628
647
|
readonly wasmscene_set_placement: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => [number, number];
|
|
629
648
|
readonly wasmscene_set_section_fill: (a: number, b: number, c: number) => [number, number];
|
|
@@ -641,6 +660,7 @@ export interface InitOutput {
|
|
|
641
660
|
readonly wasmscene_values_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
642
661
|
readonly wasmscene_vertex_count: (a: number, b: number, c: number) => [number, number, number];
|
|
643
662
|
readonly wasmscene_vertex_slots: (a: number, b: number, c: number) => [number, number, number];
|
|
663
|
+
readonly wasmscene_vertices_in_sphere: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
644
664
|
readonly wasmscene_withdraw_field: (a: number, b: number) => [number, number, number];
|
|
645
665
|
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
646
666
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|