fast-mesh-wasm 0.6.0 → 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/dist/{client-BrTp2eMp.js → client-DFgvktkT.js} +164 -10
- package/dist/{client-Ds09vLkN.d.ts → client-nvmbhtn-.d.ts} +76 -14
- package/dist/{engine-DjdY3GxK.js → engine-BL5_sWAf.js} +15 -4
- package/dist/io.d.ts +200 -2
- package/dist/io.js +3057 -3
- package/dist/{mesh-BsqIofgT.d.ts → mesh-BHTFxsXc.d.ts} +1 -1
- package/dist/node.d.ts +2 -2
- package/dist/node.js +3 -2
- package/dist/{protocol-Cb23HelE.d.ts → protocol-DFR0JDAS.d.ts} +3 -1
- package/dist/r3f.d.ts +3 -3
- package/dist/r3f.js +1 -1
- package/dist/react.d.ts +2 -2
- package/dist/{scene-D0HNTwoo.js → scene-DUsj6uJD.js} +346 -30
- package/dist/{scene-like-CADk1vfb.d.ts → scene-like-CR_Dpohm.d.ts} +902 -146
- package/dist/{store-BfC6kkf5.d.ts → store-8HWG90Jg.d.ts} +14 -3
- package/dist/{store-DIQmxF_s.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/views-BSy-Qeg8.js +584 -0
- package/dist/wasm/fast_mesh_wasm.d.ts +7 -0
- package/dist/wasm/fast_mesh_wasm.js +21 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +1 -0
- package/dist/wasm-threads/fast_mesh_wasm.d.ts +7 -0
- package/dist/wasm-threads/fast_mesh_wasm.js +21 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +1 -0
- package/dist/web.d.ts +2 -2
- package/dist/web.js +3 -2
- 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
- package/dist/views-B00kdV0R.js +0 -214
|
Binary file
|
|
@@ -97,6 +97,7 @@ export const wasmscene_values_len: (a: number, b: number, c: number) => [number,
|
|
|
97
97
|
export const wasmscene_values_ptr: (a: number, b: number, c: number) => [number, number, number];
|
|
98
98
|
export const wasmscene_vertex_count: (a: number, b: number, c: number) => [number, number, number];
|
|
99
99
|
export const wasmscene_vertex_slots: (a: number, b: number, c: number) => [number, number, number];
|
|
100
|
+
export const wasmscene_vertices_in_sphere: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
100
101
|
export const wasmscene_withdraw_field: (a: number, b: number) => [number, number, number];
|
|
101
102
|
export const watchPoolCrashes: (a: number, b: number) => void;
|
|
102
103
|
export const wbg_rayon_poolbuilder_build: (a: number) => void;
|
package/dist/web.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as SculptDomain, $n as StretchReport, $t as FindContactsOptions, A as InspectDomain, An as RepairReport, Ar as Vec3, At as CaptureRestReport, B as WorkerDeformDomain, Bn as SectionGap, Bt as CurvatureFieldDesc, C as SimplifyOptions, Cn as RegisterOptions, Cr as Mat3, Ct as AnalyzeOptions, D as WorkerRemeshDomain, Dn as RemeshReport, Dr as Positions64, Dt as BooleanOp, E as VoxelRemeshOptions, En as RelaxReport, Er as Positions, Et as AutoRepairRequest, F as DeformBackend, Fn as SculptOp, Ft as ClosestPointOptions, G as ClayOp, Gn as SelfIntersectionMode, Gt as DragOptions, H as BeginStrokeOptions, Hn as SectionResult, Ht as CutReport, I as DeformDomain, In as SculptReport, It as ColorRule, J as FlattenOp, Jn as SimplifyReport, Jt as EditRef, K as CreaseOp, Kn as ShellReport, Kt as DragSession, L as DeformReturn, Ln as SculptReportOf, Lt as Colormap, M as SyncInspectDomain, Mn as Rgba, Mr as computeVertexNormals, Mt as ClayProfile, N as WorkerInspectDomain, Nn as Scene, Nt as ClayReport, O as createRemeshDomain, On as RemoveReport, Or as Quat, Ot as BoundaryLoop, P as createInspectDomain, Pn as SceneOptions, Pt as ClosestHit, Q as SculptBackend, Qn as SmoothReport, Qt as FilledLoop, R as ProtectedSculptOp, Rn as SectionContour, Rt as Contact, S as RemeshReturn, Sn as RegisterNotApplied, Sr as InitInput, St as Analysis, T as SyncRemeshDomain, Tn as RegisterStatus, Tr as PlacementInput, Tt as AutoRepairReport, U as CaptureRestOptions, Un as SelfIntersectOptions, Ut as DegenerateReport, V as createDeformDomain, Vn as SectionPlane, Vt as CutOptions, W as CaptureStrokeOptions, Wn as SelfIntersectReport, Wt as DistanceFieldDesc, X as InflateOp, Xn as SliverReport, Xt as FieldStatus, Y as GrabOp, Yn as SliverOptions, Yt as EditResult, Z as RelaxOp, Zn as SmoothMethod, Zt as FillReport, _ as WorkerRepairDomain, _n as OrientReport, _r as FieldHandle, _t as AlignReturn, a as WorkerSceneDomains, an as InflateReport, ar as TwistReport, at as WorkerSculptDomain, b as RemeshBackend, bn as RaycastOptions, br as Bounds, bt as createAlignDomain, c as CleanOptions, cn as LoopId, cr as MeshViews, ct as BooleanDomain, d as FillHolesOptions, dn as MeasureResult, dr as ComponentSelect, dt as ShellOptions, en as FlattenMode, er as SubdivideReport, et as SculptReturn, f as RepairBackend, fn as MeshChange, fr as IsolateReport, ft as SyncBooleanDomain, g as SyncRepairDomain, gn as OffsetReport, gr as Range, gt as AlignDomain, h as SmallComponentOptions, hn as OffsetAlgorithm, hr as VertexSelection, ht as AlignBackend, i as SyncSceneDomains, in as InflateMethod, ir as TwistMethod, it as TwistOp, j as InspectReturn, jn as RepairReportOf, jr as computeBounds, jt as CaptureStrokeReport, k as InspectBackend, kn as RepairOp, kr as UpdateMode, kt as BridgeReport, l as CleanReport, ln as ManifoldOptions, lr as SceneMeshViews, lt as BooleanReturn, m as RepairReturn, mn as MeshDistance, mr as SelectSpec, mt as createBooleanDomain, n as SceneLike, nn as GrabMethod, nr as Symmetry, nt as SplitStretchedOptions, o as AutoRepairOptions, on as JoinOptions, or as VertexProtection, ot as createSculptDomain, p as RepairDomain, pn as MeshComponent, pr as LassoSelect, pt as WorkerBooleanDomain, q as FilteredSculptOp, qn as SignMode, qt as EditOp, r as SceneDomains, rn as GrabReport, rr as ThicknessFieldDesc, rt as SyncSculptDomain, s as BridgeLoopsOptions, sn as JoinReport, sr as WeldReport, st as BooleanBackend, t as SceneDomainsLike, tn as FlattenReport, tr as SurfaceFilter, tt as SmoothOp, u as DegenerateOptions, un as ManifoldReport, ur as BrushSelect, ut as OffsetOptions, v as createRepairDomain, vn as OutOfRange, vr as MeshHandle, vt as SyncAlignDomain, w as SubdivideOptions, wn as RegisterResult, wr as Placement, wt as AutoRepairPreset, x as RemeshDomain, xn as RegisterMotion, xr as Indices, xt as AddMeshOptions, y as RegionRemeshOptions, yn as RayHit, yr as SectionHandle, yt as WorkerAlignDomain, z as SyncDeformDomain, zn as SectionDesc, zt as CreaseReport } from "./scene-like-CR_Dpohm.js";
|
|
2
2
|
import { n as FastMeshErrorCode, t as FastMeshError } from "./core-CJ9D6U5A.js";
|
|
3
3
|
/**
|
|
4
4
|
* Loads the WebAssembly module. Await this once before calling any other function.
|
|
@@ -8,4 +8,4 @@ import { n as FastMeshErrorCode, t as FastMeshError } from "./core-CJ9D6U5A.js";
|
|
|
8
8
|
* Leave empty to load the file shipped with this package.
|
|
9
9
|
*/
|
|
10
10
|
export declare function init(input?: InitInput | Promise<InitInput>): Promise<void>;
|
|
11
|
-
export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type AutoRepairReport, type AutoRepairRequest, type BooleanOp, type BoundaryLoop, type Bounds, type BridgeReport, type BrushSelect, type CaptureRestReport, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type ComponentSelect, type Contact, type CurvatureFieldDesc, type CutOptions, type CutReport, type DegenerateReport, type DistanceFieldDesc, type DragOptions, type DragSession, type EditOp, type EditRef, type EditResult, FastMeshError, type FastMeshErrorCode, type FieldHandle, type FieldStatus, type FillReport, type FilledLoop, type FindContactsOptions, type GrabReport, type Indices, type InflateReport, type InitInput, type IsolateReport, type JoinOptions, type JoinReport, type LassoSelect, type LoopId, type Mat3, type MeasureResult, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OffsetReport, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type Quat, type Range, type RayHit, type RaycastOptions, type RegisterMotion, type RegisterNotApplied, type RegisterOptions, type RegisterResult, type RegisterStatus, type RelaxReport, type RemeshReport, type RemoveReport, type RepairOp, type RepairReport, type RepairReportOf, type Rgba, Scene, type SceneLike, type SceneMeshViews, type SceneOptions, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SelectSpec, type ShellReport, type SignMode, type SimplifyReport, type SmoothReport, type StretchReport, type SubdivideReport, type ThicknessFieldDesc, type UpdateMode, type Vec3, type VertexProtection, type VertexSelection, type WeldReport, computeBounds, computeVertexNormals };
|
|
11
|
+
export { type AddMeshOptions, type AlignBackend, type AlignDomain, type AlignReturn, type Analysis, type AnalyzeOptions, type AutoRepairOptions, type AutoRepairPreset, type AutoRepairReport, type AutoRepairRequest, type BeginStrokeOptions, type BooleanBackend, type BooleanDomain, type BooleanOp, type BooleanReturn, type BoundaryLoop, type Bounds, type BridgeLoopsOptions, type BridgeReport, type BrushSelect, type CaptureRestOptions, type CaptureRestReport, type CaptureStrokeOptions, type CaptureStrokeReport, type ClayOp, type ClayProfile, type ClayReport, type CleanOptions, type CleanReport, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type ComponentSelect, type Contact, type CreaseOp, type CreaseReport, type CurvatureFieldDesc, type CutOptions, type CutReport, type DeformBackend, type DeformDomain, type DeformReturn, type DegenerateOptions, type DegenerateReport, type DistanceFieldDesc, type DragOptions, type DragSession, type EditOp, type EditRef, type EditResult, FastMeshError, type FastMeshErrorCode, type FieldHandle, type FieldStatus, type FillHolesOptions, type FillReport, type FilledLoop, type FilteredSculptOp, type FindContactsOptions, type FlattenMode, type FlattenOp, type FlattenReport, type GrabMethod, type GrabOp, type GrabReport, type Indices, type InflateMethod, type InflateOp, type InflateReport, type InitInput, type InspectBackend, type InspectDomain, type InspectReturn, type IsolateReport, type JoinOptions, type JoinReport, type LassoSelect, type LoopId, type ManifoldOptions, type ManifoldReport, type Mat3, type MeasureResult, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OffsetAlgorithm, type OffsetOptions, type OffsetReport, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type ProtectedSculptOp, type Quat, type Range, type RayHit, type RaycastOptions, type RegionRemeshOptions, type RegisterMotion, type RegisterNotApplied, type RegisterOptions, type RegisterResult, type RegisterStatus, type RelaxOp, type RelaxReport, type RemeshBackend, type RemeshDomain, type RemeshReport, type RemeshReturn, type RemoveReport, type RepairBackend, type RepairDomain, type RepairOp, type RepairReport, type RepairReportOf, type RepairReturn, type Rgba, Scene, type SceneDomains, type SceneDomainsLike, type SceneLike, type SceneMeshViews, type SceneOptions, type SculptBackend, type SculptDomain, type SculptOp, type SculptReport, type SculptReportOf, type SculptReturn, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SelectSpec, type SelfIntersectOptions, type SelfIntersectReport, type SelfIntersectionMode, type ShellOptions, type ShellReport, type SignMode, type SimplifyOptions, type SimplifyReport, type SliverOptions, type SliverReport, type SmallComponentOptions, type SmoothMethod, type SmoothOp, type SmoothReport, type SplitStretchedOptions, type StretchReport, type SubdivideOptions, type SubdivideReport, type SurfaceFilter, type Symmetry, type SyncAlignDomain, type SyncBooleanDomain, type SyncDeformDomain, type SyncInspectDomain, type SyncRemeshDomain, type SyncRepairDomain, type SyncSceneDomains, type SyncSculptDomain, type ThicknessFieldDesc, type TwistMethod, type TwistOp, type TwistReport, type UpdateMode, type Vec3, type VertexProtection, type VertexSelection, type VoxelRemeshOptions, type WeldReport, type WorkerAlignDomain, type WorkerBooleanDomain, type WorkerDeformDomain, type WorkerInspectDomain, type WorkerRemeshDomain, type WorkerRepairDomain, type WorkerSceneDomains, type WorkerSculptDomain, computeBounds, computeVertexNormals, createAlignDomain, createBooleanDomain, createDeformDomain, createInspectDomain, createRemeshDomain, createRepairDomain, createSculptDomain };
|
package/dist/web.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { n as computeVertexNormals, r as markInitialized, t as computeBounds } from "./api-4kz45-Mq.js";
|
|
2
2
|
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
3
|
-
import {
|
|
3
|
+
import { _ as createBooleanDomain, f as createSculptDomain, g as createDeformDomain, h as createInspectDomain, m as createRemeshDomain, p as createRepairDomain, v as createAlignDomain } from "./views-BSy-Qeg8.js";
|
|
4
|
+
import { t as Scene } from "./scene-DUsj6uJD.js";
|
|
4
5
|
import wasmInit from "./wasm/fast_mesh_wasm.js";
|
|
5
6
|
// src/web.ts
|
|
6
7
|
let ready;
|
|
@@ -15,4 +16,4 @@ function init(input) {
|
|
|
15
16
|
ready ??= wasmInit(input === void 0 ? void 0 : { module_or_path: input }).then(markInitialized);
|
|
16
17
|
return ready;
|
|
17
18
|
}
|
|
18
|
-
export { FastMeshError, Scene, computeBounds, computeVertexNormals, init };
|
|
19
|
+
export { FastMeshError, Scene, computeBounds, computeVertexNormals, createAlignDomain, createBooleanDomain, createDeformDomain, createInspectDomain, createRemeshDomain, createRepairDomain, createSculptDomain, init };
|
package/dist/worker-engine.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as WorkerMessage, i as Result, n as InitMessage, r as Request, t as ClientId } from "./protocol-
|
|
1
|
+
import { a as WorkerMessage, i as Result, n as InitMessage, r as Request, t as ClientId } from "./protocol-DFR0JDAS.js";
|
|
2
2
|
import { WasmScene } from "./wasm/fast_mesh_wasm.js";
|
|
3
3
|
/** What the engine needs of a wasm-bindgen glue module. */
|
|
4
4
|
interface Glue {
|
package/dist/worker-engine.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as ADD_STEP_WORK, n as BACKGROUND_ADD_TRIANGLES, r as STALE_GUARD_MS, i as STEP_POINTS, a as YIELD_MS, c as loadEngine, u as probeSharedGrowth, o as runEngine, s as serveEngine, l as startEngine } from "./engine-
|
|
1
|
+
export { t as ADD_STEP_WORK, n as BACKGROUND_ADD_TRIANGLES, r as STALE_GUARD_MS, i as STEP_POINTS, a as YIELD_MS, c as loadEngine, u as probeSharedGrowth, o as runEngine, s as serveEngine, l as startEngine } from "./engine-BL5_sWAf.js";
|
package/dist/worker-entry.js
CHANGED
package/dist/worker.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as WorkerSceneOptions, i as WorkerScene, n as MAX_THREADS, o as createWorkerScene, r as WorkerLike, t as KeyStatus } from "./client-
|
|
1
|
+
import { a as WorkerSceneOptions, i as WorkerScene, n as MAX_THREADS, o as createWorkerScene, r as WorkerLike, t as KeyStatus } from "./client-nvmbhtn-.js";
|
|
2
2
|
export { type KeyStatus, MAX_THREADS, type WorkerLike, WorkerScene, type WorkerSceneOptions, createWorkerScene };
|
package/dist/worker.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as MAX_THREADS, n as WorkerScene, i as createWorkerScene } from "./client-
|
|
1
|
+
export { t as MAX_THREADS, n as WorkerScene, i as createWorkerScene } from "./client-DFgvktkT.js";
|
package/package.json
CHANGED
package/dist/views-B00kdV0R.js
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
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/register.ts
|
|
4
|
-
function invalid$1(message) {
|
|
5
|
-
return new FastMeshError("INVALID_ARGUMENT", message);
|
|
6
|
-
}
|
|
7
|
-
function isNumber(v) {
|
|
8
|
-
return typeof v === "number" && !Number.isNaN(v);
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Throws `INVALID_ARGUMENT` for an option out of range or for one mesh twice.
|
|
12
|
-
* Unset options are valid: they take their defaults.
|
|
13
|
-
*/
|
|
14
|
-
function checkRegisterOptions(sameMesh, o) {
|
|
15
|
-
if (sameMesh) throw invalid$1("cannot register a mesh to itself");
|
|
16
|
-
const { maxIterations: it, tolerance: tol, overlap, maxDistance: far, maxSamples: cap, maxRmse: rmse } = o;
|
|
17
|
-
if (it !== void 0 && !(Number.isInteger(it) && it >= 0)) throw invalid$1("maxIterations must be a non-negative integer");
|
|
18
|
-
if (tol !== void 0 && !(isNumber(tol) && Number.isFinite(tol) && tol >= 0)) throw invalid$1("tolerance must be finite and zero or greater");
|
|
19
|
-
if (overlap !== void 0 && !(isNumber(overlap) && overlap > 0 && overlap <= 1)) throw invalid$1("overlap must be in (0, 1]");
|
|
20
|
-
if (far !== void 0 && !(isNumber(far) && far > 0)) throw invalid$1("maxDistance must be positive");
|
|
21
|
-
if (cap !== void 0 && !(Number.isInteger(cap) && cap >= 1)) throw invalid$1("maxSamples must be a positive integer");
|
|
22
|
-
if (rmse !== void 0 && !(isNumber(rmse) && rmse >= 0)) throw invalid$1("maxRmse must be zero or greater");
|
|
23
|
-
if (o.apply !== void 0 && typeof o.apply !== "boolean") throw invalid$1("apply must be a boolean");
|
|
24
|
-
}
|
|
25
|
-
// src/handles.ts
|
|
26
|
-
/**
|
|
27
|
-
* A mesh in a {@link Scene}. Opaque: pass it to the scene's methods. The same
|
|
28
|
-
* mesh always gives the same handle object, so handles compare with `===`.
|
|
29
|
-
*/
|
|
30
|
-
var MeshHandle = class {};
|
|
31
|
-
/**
|
|
32
|
-
* A field in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle}.
|
|
33
|
-
* The scene keeps every field handle it gave out for its own lifetime, even
|
|
34
|
-
* after the field is removed, so a removal in a change record names the same
|
|
35
|
-
* object you hold.
|
|
36
|
-
*/
|
|
37
|
-
var FieldHandle = class {};
|
|
38
|
-
/**
|
|
39
|
-
* A section in a {@link Scene}. Opaque and deduplicated like {@link MeshHandle},
|
|
40
|
-
* and kept for the scene's lifetime like {@link FieldHandle}.
|
|
41
|
-
*/
|
|
42
|
-
var SectionHandle = class {};
|
|
43
|
-
/** A quaternion as a row-major rotation matrix, normalised first, in f64. */
|
|
44
|
-
function quatToMat3(q) {
|
|
45
|
-
const n = Math.hypot(q[0], q[1], q[2], q[3]);
|
|
46
|
-
if (!(n > 0) || !Number.isFinite(n)) throw new FastMeshError("INVALID_ARGUMENT", "quaternion must be non-zero and finite");
|
|
47
|
-
const x = q[0] / n;
|
|
48
|
-
const y = q[1] / n;
|
|
49
|
-
const z = q[2] / n;
|
|
50
|
-
const w = q[3] / n;
|
|
51
|
-
return [
|
|
52
|
-
1 - 2 * (y * y + z * z),
|
|
53
|
-
2 * (x * y - z * w),
|
|
54
|
-
2 * (x * z + y * w),
|
|
55
|
-
2 * (x * y + z * w),
|
|
56
|
-
1 - 2 * (x * x + z * z),
|
|
57
|
-
2 * (y * z - x * w),
|
|
58
|
-
2 * (x * z - y * w),
|
|
59
|
-
2 * (y * z + x * w),
|
|
60
|
-
1 - 2 * (x * x + y * y)
|
|
61
|
-
];
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* A placement rotation as 9 numbers, row-major (a quaternion converted in
|
|
65
|
-
* f64). Internal: shared with the Worker client, not part of the public API.
|
|
66
|
-
*/
|
|
67
|
-
function rotationMatrix(rotation) {
|
|
68
|
-
if (rotation.length === 4) return quatToMat3(rotation);
|
|
69
|
-
if (rotation.length === 9) return Array.from(rotation);
|
|
70
|
-
throw new FastMeshError("INVALID_ARGUMENT", "rotation must be a 3×3 matrix (9 numbers) or a quaternion (4 numbers)");
|
|
71
|
-
}
|
|
72
|
-
/** A distance field's target or targets (`DistanceFieldDesc.to`), as a list. Internal. */
|
|
73
|
-
function targetsOf(to) {
|
|
74
|
-
return Array.isArray(to) ? to : [to];
|
|
75
|
-
}
|
|
76
|
-
// src/rule.ts
|
|
77
|
-
const MAPS = {
|
|
78
|
-
turbo: 0,
|
|
79
|
-
viridis: 1,
|
|
80
|
-
coolwarm: 2,
|
|
81
|
-
grayscale: 3
|
|
82
|
-
};
|
|
83
|
-
const OUT_OF_RANGE = {
|
|
84
|
-
clamp: 0,
|
|
85
|
-
base: 1
|
|
86
|
-
};
|
|
87
|
-
function invalid(message) {
|
|
88
|
-
return new FastMeshError("INVALID_ARGUMENT", message);
|
|
89
|
-
}
|
|
90
|
-
/** The code of a string option in `table`, or `INVALID_ARGUMENT` naming `what`. */
|
|
91
|
-
function codeIn(table, value, what) {
|
|
92
|
-
if (!Object.hasOwn(table, value)) throw invalid(`${what} must be one of ${Object.keys(table).join(", ")}`);
|
|
93
|
-
return table[value];
|
|
94
|
-
}
|
|
95
|
-
/** A colour rule as the binding's `(map, rule)`: see `parse_rule` in the Rust crate. */
|
|
96
|
-
function encodeRule(rule) {
|
|
97
|
-
if (rule.range?.length !== 2) throw invalid("range must be [lo, hi]");
|
|
98
|
-
if (rule.center !== void 0 && Number.isNaN(rule.center)) throw invalid("color center must lie within the range");
|
|
99
|
-
const base = rule.base ?? DEFAULT_BASE;
|
|
100
|
-
const nan = rule.nan ?? DEFAULT_NAN;
|
|
101
|
-
if (base.length !== 4) throw invalid("base must have 4 channels");
|
|
102
|
-
if (nan.length !== 4) throw invalid("nan must have 4 channels");
|
|
103
|
-
const values = [
|
|
104
|
-
rule.range[0],
|
|
105
|
-
rule.range[1],
|
|
106
|
-
rule.center ?? NaN,
|
|
107
|
-
codeIn(OUT_OF_RANGE, rule.below ?? "clamp", "below"),
|
|
108
|
-
codeIn(OUT_OF_RANGE, rule.above ?? "base", "above"),
|
|
109
|
-
...base,
|
|
110
|
-
...nan
|
|
111
|
-
];
|
|
112
|
-
let map;
|
|
113
|
-
if (typeof rule.map === "string") map = codeIn(MAPS, rule.map, "map");
|
|
114
|
-
else if (typeof rule.map === "object" && rule.map !== null && Array.isArray(rule.map.stops)) {
|
|
115
|
-
map = 4;
|
|
116
|
-
for (const stop of rule.map.stops) {
|
|
117
|
-
if (!Array.isArray(stop) || stop.length !== 2) throw invalid("each stop must be [t, rgba]");
|
|
118
|
-
const [t, color] = stop;
|
|
119
|
-
if (typeof color !== "object" || color === null || color.length !== 4) throw invalid("stop colours must have 4 channels");
|
|
120
|
-
values.push(t, ...Array.from(color));
|
|
121
|
-
}
|
|
122
|
-
} else throw invalid("map must be \"turbo\", \"viridis\", \"coolwarm\", \"grayscale\" or { stops }");
|
|
123
|
-
return {
|
|
124
|
-
map,
|
|
125
|
-
values: Float32Array.from(values)
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* A deep, frozen copy of a colour rule (the field handle kept, not frozen):
|
|
130
|
-
* its range and colours, and a custom map's stops with their colours, so
|
|
131
|
-
* later changes to the caller's object do not leak in and callers of
|
|
132
|
-
* `coloring()` cannot change it. Colours given as typed arrays become plain
|
|
133
|
-
* arrays (a typed array cannot be frozen). Copies what it is given; the
|
|
134
|
-
* engine checks it.
|
|
135
|
-
*/
|
|
136
|
-
function copyRule(rule) {
|
|
137
|
-
const frozen = (x) => Array.isArray(x) || ArrayBuffer.isView(x) ? Object.freeze(Array.from(x)) : x;
|
|
138
|
-
const copy = { ...rule };
|
|
139
|
-
for (const [k, v] of Object.entries(copy)) if (k !== "field") copy[k] = frozen(v);
|
|
140
|
-
const stops = rule.map?.stops;
|
|
141
|
-
if (Array.isArray(stops)) copy.map = Object.freeze({ stops: Object.freeze(stops.map((stop) => Array.isArray(stop) ? Object.freeze(stop.map(frozen)) : stop)) });
|
|
142
|
-
return Object.freeze(copy);
|
|
143
|
-
}
|
|
144
|
-
/** @internal The argument of `setFieldInteraction`, checked. */
|
|
145
|
-
function checkInteractionPoints(points) {
|
|
146
|
-
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)");
|
|
147
|
-
return points;
|
|
148
|
-
}
|
|
149
|
-
// src/views.ts
|
|
150
|
-
/**
|
|
151
|
-
* Debug-mode check of kept views. The scene bumps the epoch on every call
|
|
152
|
-
* that may allocate or move buffers; a guarded view is a `Proxy` over the
|
|
153
|
-
* typed array that, on every access, warns (once per guard) when the epoch
|
|
154
|
-
* moved since the view was made, or the memory growth detached it.
|
|
155
|
-
*/
|
|
156
|
-
var ViewGuard = class {
|
|
157
|
-
#epoch = 0;
|
|
158
|
-
#warned = false;
|
|
159
|
-
/** A scene call that may allocate or move buffers is about to run. */
|
|
160
|
-
bump() {
|
|
161
|
-
this.#epoch++;
|
|
162
|
-
}
|
|
163
|
-
/** `view`, checked on every access. */
|
|
164
|
-
wrap(view) {
|
|
165
|
-
const born = this.#epoch;
|
|
166
|
-
const attached = view.byteLength > 0;
|
|
167
|
-
const check = () => {
|
|
168
|
-
if (!this.#warned && (this.#epoch !== born || attached && view.byteLength === 0)) {
|
|
169
|
-
this.#warned = true;
|
|
170
|
-
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.");
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
return new Proxy(view, {
|
|
174
|
-
get(target, key) {
|
|
175
|
-
check();
|
|
176
|
-
const value = Reflect.get(target, key, target);
|
|
177
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
178
|
-
},
|
|
179
|
-
set(target, key, value) {
|
|
180
|
-
check();
|
|
181
|
-
return Reflect.set(target, key, value, target);
|
|
182
|
-
},
|
|
183
|
-
has(target, key) {
|
|
184
|
-
check();
|
|
185
|
-
return Reflect.has(target, key);
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* The views of mesh `(index, generation)`. `scene` returns the live raw scene
|
|
192
|
-
* (it throws once the scene is freed); every getter goes through it.
|
|
193
|
-
*/
|
|
194
|
-
function meshViews(scene, index, generation, guard) {
|
|
195
|
-
const build = (make, ptr, len) => {
|
|
196
|
-
const s = scene();
|
|
197
|
-
const p = call(() => ptr(s));
|
|
198
|
-
if (p === 0) return null;
|
|
199
|
-
const view = make(wasmMemory().buffer, p, call(() => len(s)));
|
|
200
|
-
return guard === void 0 ? view : guard.wrap(view);
|
|
201
|
-
};
|
|
202
|
-
const f32 = (b, p, n) => new Float32Array(b, p, n);
|
|
203
|
-
const u8 = (b, p, n) => new Uint8Array(b, p, n);
|
|
204
|
-
const u32 = (b, p, n) => new Uint32Array(b, p, n);
|
|
205
|
-
return {
|
|
206
|
-
positions: () => build(f32, (s) => s.positions_ptr(index, generation), (s) => s.positions_len(index, generation)),
|
|
207
|
-
normals: () => build(f32, (s) => s.normals_ptr(index, generation), (s) => s.normals_len(index, generation)),
|
|
208
|
-
colors: () => build(u8, (s) => s.colors_ptr(index, generation), (s) => s.colors_len(index, generation)),
|
|
209
|
-
values: () => build(f32, (s) => s.values_ptr(index, generation), (s) => s.values_len(index, generation)),
|
|
210
|
-
uvs: () => build(f32, (s) => s.uvs_ptr(index, generation), (s) => s.uvs_len(index, generation)),
|
|
211
|
-
indices: () => build(u32, (s) => s.indices_ptr(index, generation), (s) => s.indices_len(index, generation))
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
export { encodeRule as a, SectionHandle as c, checkRegisterOptions as d, copyRule as i, rotationMatrix as l, meshViews as n, FieldHandle as o, checkInteractionPoints as r, MeshHandle as s, ViewGuard as t, targetsOf as u };
|