fast-mesh-wasm 0.5.1 → 0.5.2
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 +43 -3
- package/dist/{client-C61Kku4i.js → client-BIPPznBZ.js} +47 -7
- package/dist/{client-tP6R9foI.d.ts → client-Uo7hHvD8.d.ts} +14 -5
- package/dist/{engine-X1Awlc5y.js → engine-BS8i5U8J.js} +29 -4
- package/dist/io.d.ts +21 -9
- package/dist/io.js +102 -18
- package/dist/{mesh-D3fv56nF.d.ts → mesh-CqAIuOxU.d.ts} +15 -4
- package/dist/{mesh-CWvrjO8S.js → mesh-hPWBQPaN.js} +28 -4
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/{protocol-BGQAB0op.d.ts → protocol-BHAI0xiA.d.ts} +20 -5
- package/dist/r3f.d.ts +3 -3
- package/dist/r3f.js +2 -2
- package/dist/react.d.ts +2 -2
- package/dist/{scene-like-BzkDNHCy.d.ts → scene-like-CavrKbpQ.d.ts} +181 -6
- package/dist/{scene-BnkCS0sv.js → scene-rsfM06St.js} +120 -6
- package/dist/{store-BKFzSykN.d.ts → store-CZwml1K3.d.ts} +4 -3
- package/dist/{store-CEd2y2KS.js → store-m9l0Al-m.js} +4 -5
- package/dist/store.d.ts +2 -2
- package/dist/store.js +1 -1
- package/dist/three.d.ts +2 -2
- package/dist/three.js +1 -1
- package/dist/{views-CUBMOK0U.js → views-CdOArjcB.js} +1 -0
- package/dist/wasm/fast_mesh_wasm.d.ts +36 -2
- package/dist/wasm/fast_mesh_wasm.js +100 -2
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +5 -0
- package/dist/wasm-threads/fast_mesh_wasm.d.ts +36 -2
- package/dist/wasm-threads/fast_mesh_wasm.js +101 -3
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +5 -0
- package/dist/web.d.ts +2 -2
- package/dist/web.js +1 -1
- package/dist/worker-engine.d.ts +1 -1
- 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
|
@@ -128,9 +128,20 @@ interface MeshViews {
|
|
|
128
128
|
* provide it.
|
|
129
129
|
*/
|
|
130
130
|
values?(): Float32Array | null;
|
|
131
|
+
/**
|
|
132
|
+
* Texture coordinates, 2 floats per vertex slot, or `null` for a mesh
|
|
133
|
+
* without them (never given, or dropped by an operation: see
|
|
134
|
+
* `docs/uv-channel.md`). Optional for other {@link SceneLike} hosts; `Scene`
|
|
135
|
+
* and `WorkerScene` provide it ({@link SceneMeshViews}).
|
|
136
|
+
*/
|
|
137
|
+
uvs?(): Float32Array | null;
|
|
131
138
|
/** 3 vertex indices per triangle slot; a removed triangle reads `0, 0, 0`. */
|
|
132
139
|
indices(): Uint32Array;
|
|
133
140
|
}
|
|
141
|
+
/** {@link MeshViews} of `Scene` and `WorkerScene`, which always provide `uvs`. */
|
|
142
|
+
interface SceneMeshViews extends MeshViews {
|
|
143
|
+
uvs(): Float32Array | null;
|
|
144
|
+
}
|
|
134
145
|
/** `[start, count]` in elements: vertex slots, or triangle slots for indices. */
|
|
135
146
|
type Range = readonly [start: number, count: number];
|
|
136
147
|
/** A snapshot of selected vertices of one mesh; see the module docs. */
|
|
@@ -208,6 +219,12 @@ interface MeshChange {
|
|
|
208
219
|
colors: Range[] | "all";
|
|
209
220
|
/** Triangle slots. */
|
|
210
221
|
indices: Range[] | "all";
|
|
222
|
+
/**
|
|
223
|
+
* Vertex slots. Only on a record of a mesh that has UVs or just lost them:
|
|
224
|
+
* `"all"` with `views(mesh).uvs()` reading `null` means an operation dropped
|
|
225
|
+
* them, and `"all"` after `undo` that they came back.
|
|
226
|
+
*/
|
|
227
|
+
uvs?: Range[] | "all";
|
|
211
228
|
fieldsChanged: FieldHandle[];
|
|
212
229
|
sectionsChanged: SectionHandle[];
|
|
213
230
|
}
|
|
@@ -276,6 +293,13 @@ interface AddMeshOptions {
|
|
|
276
293
|
mode?: UpdateMode;
|
|
277
294
|
/** Keep vertex normals up to date. Defaults to `true`. */
|
|
278
295
|
normals?: boolean;
|
|
296
|
+
/**
|
|
297
|
+
* Texture coordinates: 2 finite values per vertex, stored as `f32` and read
|
|
298
|
+
* back with `views(mesh).uvs()`. Without them the mesh has no UV channel and
|
|
299
|
+
* pays nothing. Every operation keeps them aligned or drops them, undoably;
|
|
300
|
+
* see `docs/uv-channel.md`. Weld keeps seams apart.
|
|
301
|
+
*/
|
|
302
|
+
uvs?: Float32Array | readonly number[];
|
|
279
303
|
}
|
|
280
304
|
/** Options of the {@link Scene} constructor. */
|
|
281
305
|
interface SceneOptions {
|
|
@@ -540,6 +564,18 @@ type EditOp = {
|
|
|
540
564
|
} | {
|
|
541
565
|
op: "removeVertices";
|
|
542
566
|
vertices: Uint32Array | readonly number[] | readonly EditRef[];
|
|
567
|
+
} |
|
|
568
|
+
/**
|
|
569
|
+
* Sets the UVs of vertices (2 values each; undoable like the rest of the
|
|
570
|
+
* edit), `addVertices` ones included. `addVertices` alone gives a mesh with
|
|
571
|
+
* UVs the UV `(0, 0)`, and `setPositions` leaves them as they were.
|
|
572
|
+
*
|
|
573
|
+
* @throws `INVALID_ARGUMENT` on a mesh without UVs.
|
|
574
|
+
*/
|
|
575
|
+
{
|
|
576
|
+
op: "setUvs";
|
|
577
|
+
vertices: Uint32Array | readonly (number | EditRef)[];
|
|
578
|
+
uvs: Float32Array | readonly number[];
|
|
543
579
|
};
|
|
544
580
|
/** What {@link Scene.edit} added. */
|
|
545
581
|
interface EditResult {
|
|
@@ -824,7 +860,7 @@ interface FillReport {
|
|
|
824
860
|
/** Loops left out: beyond a bound, or unclean (or open). */
|
|
825
861
|
skipped: {
|
|
826
862
|
id: LoopId;
|
|
827
|
-
reason: "bounds" | "unclean";
|
|
863
|
+
reason: "bounds" | "unclean" | "uvSeam";
|
|
828
864
|
}[];
|
|
829
865
|
/** Selected loops that could not be filled; they stay open. */
|
|
830
866
|
failed: {
|
|
@@ -919,6 +955,89 @@ interface JoinReport {
|
|
|
919
955
|
/** Bridge triangles between the two loops. */
|
|
920
956
|
bridgeTrianglesAdded: number;
|
|
921
957
|
}
|
|
958
|
+
/** Options of {@link Scene.register}. */
|
|
959
|
+
interface RegisterOptions {
|
|
960
|
+
/** The most solver steps. 0 only measures the current placement. Default 50. */
|
|
961
|
+
maxIterations?: number;
|
|
962
|
+
/**
|
|
963
|
+
* Stops when one step moves every point by at most this fraction of the
|
|
964
|
+
* moving mesh's extent (the largest distance of its points from their
|
|
965
|
+
* centroid). Default `1e-6`.
|
|
966
|
+
*/
|
|
967
|
+
tolerance?: number;
|
|
968
|
+
/**
|
|
969
|
+
* The fraction of the moving mesh expected to lie over the fixed one, in
|
|
970
|
+
* `(0, 1]`: each iteration uses that many of its points, closest first, so
|
|
971
|
+
* the rest (the part beyond the overlap, and outliers) do not pull the
|
|
972
|
+
* result. Set it a little below the true overlap for partial scans.
|
|
973
|
+
* Default 1: every point counts, and nothing is rejected.
|
|
974
|
+
*/
|
|
975
|
+
overlap?: number;
|
|
976
|
+
/** Points farther than this from the fixed mesh (world units) are not used. Default: no limit. */
|
|
977
|
+
maxDistance?: number;
|
|
978
|
+
/**
|
|
979
|
+
* The most points of the moving mesh to use, evenly spaced over its
|
|
980
|
+
* triangles' centroids and its vertices. `rmse` is measured on these.
|
|
981
|
+
* Default 100,000.
|
|
982
|
+
*/
|
|
983
|
+
maxSamples?: number;
|
|
984
|
+
/**
|
|
985
|
+
* Whether a converged result becomes the moving mesh's placement, as one
|
|
986
|
+
* undo step. A result that did not converge is never applied, whatever
|
|
987
|
+
* this says. Default `true`.
|
|
988
|
+
*/
|
|
989
|
+
apply?: boolean;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
* Why {@link Scene.register} stopped:
|
|
993
|
+
* - `"converged"`: a step fell below the tolerance with all six rigid motions
|
|
994
|
+
* constrained.
|
|
995
|
+
* - `"maxIterations"`: the steps ran out first.
|
|
996
|
+
* - `"underconstrained"`: a step fell below the tolerance, but the surface
|
|
997
|
+
* does not determine some motion (a plane sliding in its plane, a tube along
|
|
998
|
+
* its axis), which stayed where the current placement put it.
|
|
999
|
+
* - `"tooFewCorrespondences"`: fewer than six points have a usable closest
|
|
1000
|
+
* point.
|
|
1001
|
+
* - `"diverged"`: a step took points out of the range the query can represent.
|
|
1002
|
+
*/
|
|
1003
|
+
type RegisterStatus = "converged" | "maxIterations" | "underconstrained" | "tooFewCorrespondences" | "diverged";
|
|
1004
|
+
/** What {@link Scene.register} found. */
|
|
1005
|
+
interface RegisterResult {
|
|
1006
|
+
/**
|
|
1007
|
+
* The moving mesh's aligned placement, with its scale unchanged: the
|
|
1008
|
+
* converged result, or the best estimate when it did not converge.
|
|
1009
|
+
*/
|
|
1010
|
+
placement: Placement;
|
|
1011
|
+
/**
|
|
1012
|
+
* The root mean square distance (world units) from the used points to the
|
|
1013
|
+
* fixed mesh at `placement`; `Infinity` when no point has a closest point.
|
|
1014
|
+
*/
|
|
1015
|
+
rmse: number;
|
|
1016
|
+
/** Solver steps taken. */
|
|
1017
|
+
iterations: number;
|
|
1018
|
+
/**
|
|
1019
|
+
* `status === "converged"`. ICP is local, so this says the iteration settled
|
|
1020
|
+
* and the surface determined the result, not that it found the right
|
|
1021
|
+
* alignment: judge that from `rmse`.
|
|
1022
|
+
*/
|
|
1023
|
+
converged: boolean;
|
|
1024
|
+
/** Why iteration stopped. */
|
|
1025
|
+
status: RegisterStatus;
|
|
1026
|
+
/** Whether `placement` was set on the moving mesh. */
|
|
1027
|
+
applied: boolean;
|
|
1028
|
+
/** Points of the moving mesh sampled. */
|
|
1029
|
+
samples: number;
|
|
1030
|
+
/** Sampled points used at `placement`: the rest were trimmed or out of range. */
|
|
1031
|
+
inliers: number;
|
|
1032
|
+
/**
|
|
1033
|
+
* How well the worst-constrained motion is determined, in `[0, 1]`: the
|
|
1034
|
+
* smallest eigenvalue of the solver's normal equations over the largest at
|
|
1035
|
+
* the last step. Below `1e-6` it counts as undetermined. A sphere's spin is
|
|
1036
|
+
* determined only by its facets, so this falls as it is tessellated finer.
|
|
1037
|
+
* 0 when no step ran.
|
|
1038
|
+
*/
|
|
1039
|
+
conditioning: number;
|
|
1040
|
+
}
|
|
922
1041
|
/** Options of {@link Scene.cutByPlane}. */
|
|
923
1042
|
interface CutOptions {
|
|
924
1043
|
/**
|
|
@@ -942,6 +1061,33 @@ interface CutReport {
|
|
|
942
1061
|
}
|
|
943
1062
|
/** Which boolean for {@link Scene.boolean} to compute. */
|
|
944
1063
|
type BooleanOp = "union" | "subtract" | "intersect";
|
|
1064
|
+
/**
|
|
1065
|
+
* The standard cleanup pipeline for {@link Scene.repair}: weld, remove
|
|
1066
|
+
* degenerate, orient, remove small components, fill holes, as one transaction.
|
|
1067
|
+
* The library owns the order; an option left out takes the library's default.
|
|
1068
|
+
*/
|
|
1069
|
+
interface AutoRepairRequest {
|
|
1070
|
+
kind: "auto";
|
|
1071
|
+
/** Vertices at most this far apart are welded, in mesh units. Default `1e-5`. */
|
|
1072
|
+
weldTolerance?: number;
|
|
1073
|
+
/** Components with fewer triangles are removed; the largest always stays. Default `500`. */
|
|
1074
|
+
minTriangles?: number;
|
|
1075
|
+
/** Fill only holes with at most this many edges; `Infinity` fills any size. Default `64`. */
|
|
1076
|
+
maxEdges?: number;
|
|
1077
|
+
/** Refine and fair each fill so it follows the surrounding curvature. Default `true`. */
|
|
1078
|
+
fair?: boolean;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* What an {@link AutoRepairRequest} did, one report per stage, keyed by the
|
|
1082
|
+
* stage's {@link RepairOp} name. The keys iterate in the order the stages ran.
|
|
1083
|
+
*/
|
|
1084
|
+
interface AutoRepairReport {
|
|
1085
|
+
weld: WeldReport;
|
|
1086
|
+
removeDegenerate: DegenerateReport;
|
|
1087
|
+
orient: OrientReport;
|
|
1088
|
+
removeSmallComponents: RemoveReport;
|
|
1089
|
+
fillHoles: FillReport;
|
|
1090
|
+
}
|
|
945
1091
|
/** The report of a {@link RepairOp}. */
|
|
946
1092
|
type RepairReport = WeldReport | DegenerateReport | RemoveReport | OrientReport | FillReport | InflateReport | SmoothReport | RemeshReport | BridgeReport | GrabReport | RelaxReport | OffsetReport | ShellReport | SimplifyReport | SubdivideReport;
|
|
947
1093
|
/** The report type of a repair op. */
|
|
@@ -999,7 +1145,8 @@ declare class Scene implements SceneLike {
|
|
|
999
1145
|
* identity, so {@link Scene.matrix4} maps the local coordinates back to
|
|
1000
1146
|
* where they were given.
|
|
1001
1147
|
*
|
|
1002
|
-
* @throws `INVALID_ARGUMENT` for bad lengths or options
|
|
1148
|
+
* @throws `INVALID_ARGUMENT` for bad lengths or options (`uvs` not 2 finite
|
|
1149
|
+
* values per vertex included), `INVALID_INDEX` for an index out of range.
|
|
1003
1150
|
*/
|
|
1004
1151
|
addMesh(positions: Positions64, indices: Indices, options?: AddMeshOptions): MeshHandle;
|
|
1005
1152
|
/**
|
|
@@ -1049,6 +1196,31 @@ declare class Scene implements SceneLike {
|
|
|
1049
1196
|
* boolean changes nothing.
|
|
1050
1197
|
*/
|
|
1051
1198
|
boolean(target: MeshHandle, source: MeshHandle, op: BooleanOp): MeshHandle;
|
|
1199
|
+
/**
|
|
1200
|
+
* Rigidly aligns the mesh `moving` to the mesh `fixed` by point-to-plane ICP,
|
|
1201
|
+
* with the closest points found through `fixed`'s BVH and trimmed by
|
|
1202
|
+
* `options.overlap`. A drag of either mesh ends first, recording its moves
|
|
1203
|
+
* as one step.
|
|
1204
|
+
*
|
|
1205
|
+
* **The initial guess is the current placements.** ICP finds the nearest
|
|
1206
|
+
* fit, so put the meshes roughly in place first with `setPlacement`.
|
|
1207
|
+
*
|
|
1208
|
+
* **Applying.** By default a converged result becomes `moving`'s placement
|
|
1209
|
+
* as one undo step (`applied` in the result); `apply: false` only returns
|
|
1210
|
+
* it. A result that did not converge is never applied, so a failed alignment
|
|
1211
|
+
* does not move anything; `placement` still holds the best estimate, for
|
|
1212
|
+
* `setPlacement` if it will do.
|
|
1213
|
+
*
|
|
1214
|
+
* **Scales.** Only rotation and translation are solved. `moving`'s scale is
|
|
1215
|
+
* applied to its points and kept. `fixed`'s scale, uniform or not, is
|
|
1216
|
+
* followed exactly on a copy baked through it, so each such call costs a BVH
|
|
1217
|
+
* build. All distances are in world units.
|
|
1218
|
+
*
|
|
1219
|
+
* @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
|
|
1220
|
+
* mesh twice, a mesh without triangles or an invalid option; `STALE_BVH` for
|
|
1221
|
+
* a stale Manual `fixed`. Nothing changes on a throw.
|
|
1222
|
+
*/
|
|
1223
|
+
register(moving: MeshHandle, fixed: MeshHandle, options?: RegisterOptions): RegisterResult;
|
|
1052
1224
|
/**
|
|
1053
1225
|
* Sets a mesh's placement: world = rotation · (scale · local) + translation,
|
|
1054
1226
|
* where local is relative to the mesh origin. A quaternion is normalised
|
|
@@ -1096,7 +1268,7 @@ declare class Scene implements SceneLike {
|
|
|
1096
1268
|
* view; re-acquire views after every scene call that may allocate, since a
|
|
1097
1269
|
* kept one may read other data or be empty (see {@link MeshViews}).
|
|
1098
1270
|
*/
|
|
1099
|
-
views(mesh: MeshHandle):
|
|
1271
|
+
views(mesh: MeshHandle): SceneMeshViews;
|
|
1100
1272
|
/**
|
|
1101
1273
|
* Everything that changed since the previous call, one record per mesh.
|
|
1102
1274
|
* There is a single consumer: apps that use {@link Scene.onChanges} call
|
|
@@ -1189,9 +1361,12 @@ declare class Scene implements SceneLike {
|
|
|
1189
1361
|
* Runs one repair operation and returns its report, or a list of them in
|
|
1190
1362
|
* order and returns their reports. A list is one transaction: one undo step,
|
|
1191
1363
|
* and when any operation fails nothing changes and nothing is recorded.
|
|
1364
|
+
* `{ kind: "auto" }` runs the standard cleanup pipeline the same way and
|
|
1365
|
+
* returns a report per stage; see {@link AutoRepairRequest}.
|
|
1192
1366
|
*
|
|
1193
1367
|
* @throws `INVALID_ARGUMENT` for invalid options (`fillHoles` needs a bound or `loops`); `STALE_LOOPS` when a loop id of `fillHoles` no longer matches a loop of the mesh.
|
|
1194
1368
|
*/
|
|
1369
|
+
repair(mesh: MeshHandle, request: AutoRepairRequest): AutoRepairReport;
|
|
1195
1370
|
repair<const O extends RepairOp>(mesh: MeshHandle, op: O): RepairReportOf<O>;
|
|
1196
1371
|
repair<const O extends readonly RepairOp[]>(mesh: MeshHandle, ops: O): { -readonly [K in keyof O]: RepairReportOf<O[K]>; };
|
|
1197
1372
|
/**
|
|
@@ -1394,8 +1569,8 @@ interface SceneLike {
|
|
|
1394
1569
|
/**
|
|
1395
1570
|
* Views of the mesh's render buffers. Slot counts follow from them, so
|
|
1396
1571
|
* `positions()` must be exactly 3 × vertex slots long and `indices()`
|
|
1397
|
-
* exactly 3 × triangle slots long (normals 3
|
|
1398
|
-
* when present): `positions().length / 3` vertex slots and
|
|
1572
|
+
* exactly 3 × triangle slots long (normals 3, colours 4 and UVs 2 per vertex
|
|
1573
|
+
* slot, when present): `positions().length / 3` vertex slots and
|
|
1399
1574
|
* `indices().length / 3` triangle slots.
|
|
1400
1575
|
*/
|
|
1401
1576
|
views(mesh: MeshHandle): MeshViews;
|
|
@@ -1423,4 +1598,4 @@ interface SceneLike {
|
|
|
1423
1598
|
*/
|
|
1424
1599
|
bounds?(mesh: MeshHandle): Bounds | null;
|
|
1425
1600
|
}
|
|
1426
|
-
export {
|
|
1601
|
+
export { Scene as $, InflateReport as A, PlacementInput as At, OutOfRange as B, EditRef as C, MeshHandle as Ct, FilledLoop as D, InitInput as Dt, FillReport as E, Indices as Et, MeshChange as F, Vec3 as Ft, RegisterStatus as G, RaycastOptions as H, MeshComponent as I, computeBounds as It, RemoveReport as J, RelaxReport as K, MeshDistance as L, computeVertexNormals as Lt, JoinReport as M, Positions64 as Mt, LoopId as N, Quat as Nt, FindContactsOptions as O, Mat3 as Ot, MeasureResult as P, UpdateMode as Pt, Rgba as Q, OffsetReport as R, EditOp as S, FieldHandle as St, FieldStatus as T, Bounds as Tt, RegisterOptions as U, RayHit as V, RegisterResult as W, RepairReport as X, RepairOp as Y, RepairReportOf as Z, CutReport as _, SelectSpec as _t, AutoRepairReport as a, SectionResult as at, DragOptions as b, MeshViews as bt, BoundaryLoop as c, SimplifyReport as ct, ClosestPointOptions as d, ThicknessFieldDesc as dt, SceneOptions as et, ColorRule as f, WeldReport as ft, CutOptions as g, LassoSelect as gt, CurvatureFieldDesc as h, IsolateReport as ht, AnalyzeOptions as i, SectionPlane as it, JoinOptions as j, Positions as jt, GrabReport as k, Placement as kt, BridgeReport as l, SmoothReport as lt, Contact as m, ComponentSelect as mt, AddMeshOptions as n, SectionDesc as nt, AutoRepairRequest as o, ShellReport as ot, Colormap as p, BrushSelect as pt, RemeshReport as q, Analysis as r, SectionGap as rt, BooleanOp as s, SignMode as st, SceneLike as t, SectionContour as tt, ClosestHit as u, SubdivideReport as ut, DegenerateReport as v, VertexSelection as vt, EditResult as w, SectionHandle as wt, DragSession as x, SceneMeshViews as xt, DistanceFieldDesc as y, Range as yt, OrientReport as z };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as release, c as wasmMemory, i as finalizer, n as call, r as ensureInitialized, t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
-
import { a as FieldHandle, c as rotationMatrix, i as encodeRule, l as targetsOf, n as meshViews, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-
|
|
2
|
+
import { a as FieldHandle, c as rotationMatrix, i as encodeRule, l as targetsOf, n as meshViews, o as MeshHandle, r as copyRule, s as SectionHandle, t as ViewGuard } from "./views-CdOArjcB.js";
|
|
3
3
|
import { WasmScene } from "./wasm/fast_mesh_wasm.js";
|
|
4
4
|
// src/changes.ts
|
|
5
5
|
const ADDED = 1;
|
|
@@ -10,6 +10,8 @@ const POSITIONS_ALL = 16;
|
|
|
10
10
|
const NORMALS_ALL = 32;
|
|
11
11
|
const COLORS_ALL = 64;
|
|
12
12
|
const INDICES_ALL = 128;
|
|
13
|
+
const UVS = 256;
|
|
14
|
+
const UVS_ALL = 512;
|
|
13
15
|
/** Decodes `[record_count, record...]`. */
|
|
14
16
|
function decodeChanges(msg) {
|
|
15
17
|
let at = 0;
|
|
@@ -49,6 +51,7 @@ function decodeChanges(msg) {
|
|
|
49
51
|
normals: ranges((flags & NORMALS_ALL) !== 0),
|
|
50
52
|
colors: ranges((flags & COLORS_ALL) !== 0),
|
|
51
53
|
indices: ranges((flags & INDICES_ALL) !== 0),
|
|
54
|
+
...(flags & UVS) !== 0 ? { uvs: ranges((flags & UVS_ALL) !== 0) } : {},
|
|
52
55
|
fields: ids(),
|
|
53
56
|
sections: ids()
|
|
54
57
|
});
|
|
@@ -368,7 +371,8 @@ const EDIT_CODES = {
|
|
|
368
371
|
addVertices: 1,
|
|
369
372
|
addTriangles: 2,
|
|
370
373
|
removeTriangles: 3,
|
|
371
|
-
removeVertices: 4
|
|
374
|
+
removeVertices: 4,
|
|
375
|
+
setUvs: 5
|
|
372
376
|
};
|
|
373
377
|
/** An id list as the binding's `n, r, ids..., (slot, op, i)...`; see `crate::edit`. */
|
|
374
378
|
function encodeIds(list, what, words) {
|
|
@@ -426,7 +430,16 @@ function encodeEdit(ops) {
|
|
|
426
430
|
case "removeTriangles":
|
|
427
431
|
encodeIds(o.triangles, `${what}: triangles`, words);
|
|
428
432
|
break;
|
|
429
|
-
case "removeVertices":
|
|
433
|
+
case "removeVertices":
|
|
434
|
+
encodeIds(o.vertices, `${what}: vertices`, words);
|
|
435
|
+
break;
|
|
436
|
+
case "setUvs": {
|
|
437
|
+
encodeIds(o.vertices, `${what}: vertices`, words);
|
|
438
|
+
const uvs = Float64Array.from(o.uvs ?? []);
|
|
439
|
+
if (uvs.length !== 2 * o.vertices.length) throw invalid(`${what}: uvs need 2 values per vertex`);
|
|
440
|
+
values.push(uvs);
|
|
441
|
+
break;
|
|
442
|
+
}
|
|
430
443
|
}
|
|
431
444
|
});
|
|
432
445
|
const out = new Uint32Array(words.reduce((n, w) => n + w.length, 0));
|
|
@@ -463,12 +476,22 @@ const REPAIR_CODES = {
|
|
|
463
476
|
simplify: 13,
|
|
464
477
|
subdivide: 14
|
|
465
478
|
};
|
|
479
|
+
/** The op code of an {@link AutoRepairRequest}; see `crate::edit` in the Rust crate. */
|
|
480
|
+
const AUTO_REPAIR_CODE = 15;
|
|
466
481
|
const FALLOFF_CODES = {
|
|
467
482
|
linear: 0,
|
|
468
483
|
smooth: 1
|
|
469
484
|
};
|
|
470
485
|
const SUBDIVIDE_METHOD_CODES = { loop: 0 };
|
|
471
486
|
/** An optional number for the binding: NaN when unset; an explicit NaN is rejected. */
|
|
487
|
+
/** The `status` codes of `WasmScene.register`, in order. */
|
|
488
|
+
const REGISTER_STATUSES = [
|
|
489
|
+
"converged",
|
|
490
|
+
"maxIterations",
|
|
491
|
+
"underconstrained",
|
|
492
|
+
"tooFewCorrespondences",
|
|
493
|
+
"diverged"
|
|
494
|
+
];
|
|
472
495
|
function optional(v, what) {
|
|
473
496
|
if (v === void 0) return NaN;
|
|
474
497
|
if (typeof v !== "number" || Number.isNaN(v)) throw invalid(`${what} must be a number`);
|
|
@@ -494,6 +517,9 @@ function encodeLoopId(id, out) {
|
|
|
494
517
|
for (const v of [minVertex, len]) if (!Number.isInteger(v) || v < 0 || v >= U32_LIMIT) throw invalid("a loop id's minVertex and len must be u32 integers");
|
|
495
518
|
out.push(minVertex, len, Number(hash & 4294967295n), Number(hash >> 32n));
|
|
496
519
|
}
|
|
520
|
+
function isAutoRepair(op) {
|
|
521
|
+
return op?.kind === "auto";
|
|
522
|
+
}
|
|
497
523
|
/** A repair op list as the binding's `(ops, loops)`; see `crate::edit` in the Rust crate. */
|
|
498
524
|
function encodeRepair(ops) {
|
|
499
525
|
const values = [];
|
|
@@ -606,7 +632,11 @@ var Reader = class {
|
|
|
606
632
|
return out;
|
|
607
633
|
}
|
|
608
634
|
};
|
|
609
|
-
const SKIP_REASONS = [
|
|
635
|
+
const SKIP_REASONS = [
|
|
636
|
+
"bounds",
|
|
637
|
+
"unclean",
|
|
638
|
+
"uvSeam"
|
|
639
|
+
];
|
|
610
640
|
const FAIL_REASONS = [
|
|
611
641
|
"projectionFolds",
|
|
612
642
|
"noValidTriangulation",
|
|
@@ -701,6 +731,16 @@ function decodeReport(op, r) {
|
|
|
701
731
|
};
|
|
702
732
|
}
|
|
703
733
|
}
|
|
734
|
+
/** An auto repair's result, stage by stage in the order they ran; see `crate::edit` in the Rust crate. */
|
|
735
|
+
function decodeAutoReport(r) {
|
|
736
|
+
const ops = Object.keys(REPAIR_CODES);
|
|
737
|
+
const stages = {};
|
|
738
|
+
while (r.at < r.data.length) {
|
|
739
|
+
const op = ops[r.next()];
|
|
740
|
+
stages[op] = decodeReport(op, r);
|
|
741
|
+
}
|
|
742
|
+
return stages;
|
|
743
|
+
}
|
|
704
744
|
/** An analysis result; see `encode_analysis` in the Rust crate. */
|
|
705
745
|
function decodeAnalysis(r) {
|
|
706
746
|
const loops = r.many(() => ({
|
|
@@ -896,7 +936,8 @@ var Scene = class {
|
|
|
896
936
|
* identity, so {@link Scene.matrix4} maps the local coordinates back to
|
|
897
937
|
* where they were given.
|
|
898
938
|
*
|
|
899
|
-
* @throws `INVALID_ARGUMENT` for bad lengths or options
|
|
939
|
+
* @throws `INVALID_ARGUMENT` for bad lengths or options (`uvs` not 2 finite
|
|
940
|
+
* values per vertex included), `INVALID_INDEX` for an index out of range.
|
|
900
941
|
*/
|
|
901
942
|
addMesh(positions, indices, options = {}) {
|
|
902
943
|
const s = this.#scene();
|
|
@@ -904,7 +945,13 @@ var Scene = class {
|
|
|
904
945
|
const origin = options.origin === void 0 ? void 0 : Float64Array.from(options.origin);
|
|
905
946
|
const p = toFloat64(positions);
|
|
906
947
|
const i = toUint32(indices);
|
|
907
|
-
const
|
|
948
|
+
const normals = options.normals ?? true;
|
|
949
|
+
if (options.uvs === void 0) {
|
|
950
|
+
const id = call(() => s.add_mesh(p, i, origin, mode, normals));
|
|
951
|
+
return this.#meshHandle(id[0], id[1]);
|
|
952
|
+
}
|
|
953
|
+
const uvs = options.uvs instanceof Float32Array ? options.uvs : Float32Array.from(options.uvs);
|
|
954
|
+
const id = call(() => s.add_mesh_with_uvs(p, i, uvs, origin, mode, normals));
|
|
908
955
|
return this.#meshHandle(id[0], id[1]);
|
|
909
956
|
}
|
|
910
957
|
/**
|
|
@@ -1000,6 +1047,66 @@ var Scene = class {
|
|
|
1000
1047
|
return this.#meshHandle(r[0], r[1]);
|
|
1001
1048
|
}
|
|
1002
1049
|
/**
|
|
1050
|
+
* Rigidly aligns the mesh `moving` to the mesh `fixed` by point-to-plane ICP,
|
|
1051
|
+
* with the closest points found through `fixed`'s BVH and trimmed by
|
|
1052
|
+
* `options.overlap`. A drag of either mesh ends first, recording its moves
|
|
1053
|
+
* as one step.
|
|
1054
|
+
*
|
|
1055
|
+
* **The initial guess is the current placements.** ICP finds the nearest
|
|
1056
|
+
* fit, so put the meshes roughly in place first with `setPlacement`.
|
|
1057
|
+
*
|
|
1058
|
+
* **Applying.** By default a converged result becomes `moving`'s placement
|
|
1059
|
+
* as one undo step (`applied` in the result); `apply: false` only returns
|
|
1060
|
+
* it. A result that did not converge is never applied, so a failed alignment
|
|
1061
|
+
* does not move anything; `placement` still holds the best estimate, for
|
|
1062
|
+
* `setPlacement` if it will do.
|
|
1063
|
+
*
|
|
1064
|
+
* **Scales.** Only rotation and translation are solved. `moving`'s scale is
|
|
1065
|
+
* applied to its points and kept. `fixed`'s scale, uniform or not, is
|
|
1066
|
+
* followed exactly on a copy baked through it, so each such call costs a BVH
|
|
1067
|
+
* build. All distances are in world units.
|
|
1068
|
+
*
|
|
1069
|
+
* @throws `UNKNOWN_MESH` for a removed handle; `INVALID_ARGUMENT` for one
|
|
1070
|
+
* mesh twice, a mesh without triangles or an invalid option; `STALE_BVH` for
|
|
1071
|
+
* a stale Manual `fixed`. Nothing changes on a throw.
|
|
1072
|
+
*/
|
|
1073
|
+
register(moving, fixed, options = {}) {
|
|
1074
|
+
const m = this.#id(moving);
|
|
1075
|
+
const f = this.#id(fixed);
|
|
1076
|
+
const maxIterations = optional(options.maxIterations, "maxIterations");
|
|
1077
|
+
const tolerance = optional(options.tolerance, "tolerance");
|
|
1078
|
+
const overlap = optional(options.overlap, "overlap");
|
|
1079
|
+
const maxDistance = optional(options.maxDistance, "maxDistance");
|
|
1080
|
+
const maxSamples = optional(options.maxSamples, "maxSamples");
|
|
1081
|
+
const apply = options.apply ?? true;
|
|
1082
|
+
if (this.#drag?.mesh === moving || this.#drag?.mesh === fixed) this.#drag.end();
|
|
1083
|
+
const r = call(() => this.#scene().register(m.index, m.generation, f.index, f.generation, maxIterations, tolerance, overlap, maxDistance, maxSamples, apply));
|
|
1084
|
+
const status = REGISTER_STATUSES[r[17]];
|
|
1085
|
+
return {
|
|
1086
|
+
placement: {
|
|
1087
|
+
rotation: Array.from(r.subarray(0, 9)),
|
|
1088
|
+
translation: [
|
|
1089
|
+
r[9],
|
|
1090
|
+
r[10],
|
|
1091
|
+
r[11]
|
|
1092
|
+
],
|
|
1093
|
+
scale: [
|
|
1094
|
+
r[12],
|
|
1095
|
+
r[13],
|
|
1096
|
+
r[14]
|
|
1097
|
+
]
|
|
1098
|
+
},
|
|
1099
|
+
rmse: r[15],
|
|
1100
|
+
iterations: r[16],
|
|
1101
|
+
converged: status === "converged",
|
|
1102
|
+
status,
|
|
1103
|
+
applied: r[18] === 1,
|
|
1104
|
+
samples: r[19],
|
|
1105
|
+
inliers: r[20],
|
|
1106
|
+
conditioning: r[21]
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
/**
|
|
1003
1110
|
* Sets a mesh's placement: world = rotation · (scale · local) + translation,
|
|
1004
1111
|
* where local is relative to the mesh origin. A quaternion is normalised
|
|
1005
1112
|
* and converted in double precision. The scale defaults to `[1, 1, 1]`
|
|
@@ -1149,6 +1256,7 @@ var Scene = class {
|
|
|
1149
1256
|
normals: c.normals,
|
|
1150
1257
|
colors: c.colors,
|
|
1151
1258
|
indices: c.indices,
|
|
1259
|
+
...c.uvs === void 0 ? {} : { uvs: c.uvs },
|
|
1152
1260
|
fieldsChanged: c.fields.map((f) => this.#rawHandle(this.#fields, () => new FieldHandle(), f)),
|
|
1153
1261
|
sectionsChanged: c.sections.map((x) => this.#rawHandle(this.#sections, () => new SectionHandle(), x))
|
|
1154
1262
|
}));
|
|
@@ -1424,6 +1532,11 @@ var Scene = class {
|
|
|
1424
1532
|
}
|
|
1425
1533
|
repair(mesh, op) {
|
|
1426
1534
|
const { index, generation } = this.#id(mesh);
|
|
1535
|
+
if (isAutoRepair(op)) {
|
|
1536
|
+
const values = Float64Array.of(AUTO_REPAIR_CODE, optional(op.weldTolerance, "weldTolerance"), optional(op.minTriangles, "minTriangles"), optional(op.maxEdges, "maxEdges"), op.fair === void 0 ? NaN : flagOf(op.fair, true));
|
|
1537
|
+
const noLoops = /* @__PURE__ */ new Uint32Array();
|
|
1538
|
+
return decodeAutoReport(new Reader(call(() => this.#scene().repair(index, generation, values, noLoops))));
|
|
1539
|
+
}
|
|
1427
1540
|
const ops = Array.isArray(op) ? op : [op];
|
|
1428
1541
|
const { values, loops } = encodeRepair(ops);
|
|
1429
1542
|
const r = new Reader(call(() => this.#scene().repair(index, generation, values, loops)));
|
|
@@ -1837,6 +1950,7 @@ var Scene = class {
|
|
|
1837
1950
|
},
|
|
1838
1951
|
pushPositions: (token, chunk) => call(() => scene.#scene().add_mesh_push_positions(token, chunk)),
|
|
1839
1952
|
pushIndices: (token, chunk) => call(() => scene.#scene().add_mesh_push_indices(token, chunk)),
|
|
1953
|
+
pushUvs: (token, chunk) => call(() => scene.#scene().add_mesh_push_uvs(token, chunk)),
|
|
1840
1954
|
step: (token, budget) => call(() => scene.#scene().add_mesh_step(token, budget)),
|
|
1841
1955
|
buffers: (token) => {
|
|
1842
1956
|
const [pp, pl, np, nl, ip, il] = call(() => scene.#peek().add_mesh_buffers(token));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { i as WorkerScene } from "./client-
|
|
1
|
+
import { $ as Scene, At as PlacementInput, B as OutOfRange, Ct as MeshHandle, Et as Indices, F as MeshChange, Mt as Positions64, Q as Rgba, S as EditOp, X as RepairReport, Y as RepairOp, a as AutoRepairReport, it as SectionPlane, n as AddMeshOptions, nt as SectionDesc, o as AutoRepairRequest, p as Colormap, st as SignMode, t as SceneLike, w as EditResult, wt as SectionHandle, x as DragSession } from "./scene-like-CavrKbpQ.js";
|
|
2
|
+
import { i as WorkerScene } from "./client-Uo7hHvD8.js";
|
|
3
3
|
import { t as FastMeshError } from "./core-CJ9D6U5A.js";
|
|
4
4
|
/** Options of `SceneStore.addMesh`: those both scenes take (a store mesh is always eager). */
|
|
5
|
-
type StoreAddMeshOptions = Pick<AddMeshOptions, "origin" | "normals">;
|
|
5
|
+
type StoreAddMeshOptions = Pick<AddMeshOptions, "origin" | "normals" | "uvs">;
|
|
6
6
|
/**
|
|
7
7
|
* The state of a mesh's or section's work: `"computing"` while it, or a
|
|
8
8
|
* result it depends on, is pending; `"ready"` once applied; `"error"` when
|
|
@@ -170,6 +170,7 @@ declare class SceneStore {
|
|
|
170
170
|
edit(mesh: MeshHandle, ops: readonly EditOp[]): Promise<EditResult>;
|
|
171
171
|
/** Repairs a mesh (one undo step). */
|
|
172
172
|
repair(mesh: MeshHandle, op: RepairOp | readonly RepairOp[]): Promise<RepairReport | RepairReport[]>;
|
|
173
|
+
repair(mesh: MeshHandle, request: AutoRepairRequest): Promise<AutoRepairReport>;
|
|
173
174
|
/** Undoes the latest step. */
|
|
174
175
|
undo(): void;
|
|
175
176
|
/** Redoes the latest undone step. */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { o as reportListenerError, t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
-
import { l as targetsOf } from "./views-
|
|
2
|
+
import { l as targetsOf } from "./views-CdOArjcB.js";
|
|
3
3
|
import { i as sectionAspects } from "./protocol-Ci9LLiwO.js";
|
|
4
|
-
import { a as watchStatusKeys, r as addFieldKeyed } from "./client-
|
|
4
|
+
import { a as watchStatusKeys, r as addFieldKeyed } from "./client-BIPPznBZ.js";
|
|
5
5
|
import { a as combine, c as sameData, n as EMPTY_SNAPSHOT, o as frozenCopy, t as DEFAULT_DISPLAY } from "./snapshot-BkbGPspK.js";
|
|
6
6
|
// src/store/host.ts
|
|
7
7
|
/** Whether `scene` is a Worker scene (structurally: it reports key statuses). */
|
|
@@ -61,7 +61,7 @@ function localHost(scene) {
|
|
|
61
61
|
removeMesh: (mesh) => scene.removeMesh(mesh),
|
|
62
62
|
setPlacement: (mesh, placement) => scene.setPlacement(mesh, placement),
|
|
63
63
|
edit: (mesh, ops) => promised(() => scene.edit(mesh, ops)),
|
|
64
|
-
repair: (mesh, op) => promised(() => scene.repair(mesh, op)),
|
|
64
|
+
repair: ((mesh, op) => promised(() => scene.repair(mesh, op))),
|
|
65
65
|
undo: () => {
|
|
66
66
|
scene.undo();
|
|
67
67
|
},
|
|
@@ -124,7 +124,7 @@ function workerHost(scene) {
|
|
|
124
124
|
removeMesh: (mesh) => scene.removeMesh(mesh),
|
|
125
125
|
setPlacement: (mesh, placement) => scene.setPlacement(mesh, placement),
|
|
126
126
|
edit: (mesh, ops) => scene.edit(mesh, ops),
|
|
127
|
-
repair: (mesh, op) => scene.repair(mesh, op),
|
|
127
|
+
repair: ((mesh, op) => scene.repair(mesh, op)),
|
|
128
128
|
undo: () => scene.undo(),
|
|
129
129
|
redo: () => scene.redo(),
|
|
130
130
|
canUndo: () => scene.canUndo,
|
|
@@ -560,7 +560,6 @@ var SceneStore = class {
|
|
|
560
560
|
this.#alive();
|
|
561
561
|
return this.#settled(this.#host.edit(mesh, ops));
|
|
562
562
|
}
|
|
563
|
-
/** Repairs a mesh (one undo step). */
|
|
564
563
|
repair(mesh, op) {
|
|
565
564
|
this.#alive();
|
|
566
565
|
return this.#settled(this.#host.repair(mesh, op));
|
package/dist/store.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { _ as StoreAddMeshOptions, a as DisplayState, c as MeshState, d as SceneSnapshot, f as SectionParts, g as sectionState, h as meshState, i as ContactGroup, l as REMOVED_MESH_STATE, m as Status, n as SectionPatch, o as DistanceColoring, p as SectionState, r as createSceneStore, s as EMPTY_SNAPSHOT, t as SceneStore, u as REMOVED_SECTION_STATE } from "./store-
|
|
1
|
+
import { Q as Rgba, st as SignMode } from "./scene-like-CavrKbpQ.js";
|
|
2
|
+
import { _ as StoreAddMeshOptions, a as DisplayState, c as MeshState, d as SceneSnapshot, f as SectionParts, g as sectionState, h as meshState, i as ContactGroup, l as REMOVED_MESH_STATE, m as Status, n as SectionPatch, o as DistanceColoring, p as SectionState, r as createSceneStore, s as EMPTY_SNAPSHOT, t as SceneStore, u as REMOVED_SECTION_STATE } from "./store-CZwml1K3.js";
|
|
3
3
|
/** Options of {@link contactHeatmap}. Distances are in the meshes' units. */
|
|
4
4
|
interface ContactHeatmapOptions {
|
|
5
5
|
/** The penetration depth shown darkest (`deep`); deeper clamps to it. `> 0`. */
|
package/dist/store.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
2
|
import { i as REMOVED_SECTION_STATE, l as sectionState, n as EMPTY_SNAPSHOT, r as REMOVED_MESH_STATE, s as meshState } from "./snapshot-BkbGPspK.js";
|
|
3
|
-
import { n as createSceneStore, t as SceneStore } from "./store-
|
|
3
|
+
import { n as createSceneStore, t as SceneStore } from "./store-m9l0Al-m.js";
|
|
4
4
|
// src/store/heatmap.ts
|
|
5
5
|
/** The default colours: `#7f0000`, `#ff6b6b`, `#ffffff`, `#4caf50`, `#1e3a8a`. */
|
|
6
6
|
const DEFAULT_COLORS = {
|
package/dist/three.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as SceneLike,
|
|
2
|
-
import { i as bindMesh, n as BoundMesh, r as MeshBinding, t as BindMeshOptions } from "./mesh-
|
|
1
|
+
import { t as SceneLike, wt as SectionHandle } from "./scene-like-CavrKbpQ.js";
|
|
2
|
+
import { i as bindMesh, n as BoundMesh, r as MeshBinding, t as BindMeshOptions } from "./mesh-CqAIuOxU.js";
|
|
3
3
|
import * as THREE from "three";
|
|
4
4
|
/**
|
|
5
5
|
* What {@link attachTransformControls} needs of a TransformControls: its
|
package/dist/three.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
-
import { n as checkUntransformedParent, t as bindMesh } from "./mesh-
|
|
2
|
+
import { n as checkUntransformedParent, t as bindMesh } from "./mesh-hPWBQPaN.js";
|
|
3
3
|
import * as THREE from "three";
|
|
4
4
|
// src/three/controls.ts
|
|
5
5
|
const defaultSchedule = (callback) => {
|
|
@@ -180,6 +180,7 @@ function meshViews(scene, index, generation, guard) {
|
|
|
180
180
|
normals: () => build(f32, (s) => s.normals_ptr(index, generation), (s) => s.normals_len(index, generation)),
|
|
181
181
|
colors: () => build(u8, (s) => s.colors_ptr(index, generation), (s) => s.colors_len(index, generation)),
|
|
182
182
|
values: () => build(f32, (s) => s.values_ptr(index, generation), (s) => s.values_len(index, generation)),
|
|
183
|
+
uvs: () => build(f32, (s) => s.uvs_ptr(index, generation), (s) => s.uvs_len(index, generation)),
|
|
183
184
|
indices: () => build(u32, (s) => s.indices_ptr(index, generation), (s) => s.indices_len(index, generation))
|
|
184
185
|
};
|
|
185
186
|
}
|