fast-mesh-wasm 0.5.0 → 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 +91 -3
- package/dist/{api-BUy7FRx7.js → api-4kz45-Mq.js} +2 -3
- package/dist/{client-CE6RvmvB.js → client-BIPPznBZ.js} +108 -24
- package/dist/{client-pv0Fwvl4.d.ts → client-Uo7hHvD8.d.ts} +25 -11
- package/dist/{colormap-DxGMYVfs.js → colormap-Dr5V3bvs.js} +1 -2
- package/dist/{core-Cke_kZ2e.js → core-4OcWKu3r.js} +2 -2
- package/dist/{core-D2X9GPfK.d.ts → core-CJ9D6U5A.d.ts} +1 -3
- package/dist/{engine-DLQAL9GT.js → engine-BS8i5U8J.js} +41 -11
- package/dist/io.d.ts +306 -0
- package/dist/io.js +1479 -0
- package/dist/{mesh-RtPVmPQy.d.ts → mesh-CqAIuOxU.d.ts} +15 -6
- package/dist/{mesh-zj7-wJBw.js → mesh-hPWBQPaN.js} +31 -8
- package/dist/node.d.ts +3 -5
- package/dist/node.js +4 -5
- package/dist/{protocol-z-jeCUGO.d.ts → protocol-BHAI0xiA.d.ts} +25 -7
- package/dist/{protocol-DkhGNP0h.js → protocol-Ci9LLiwO.js} +1 -2
- package/dist/r3f.d.ts +22 -6
- package/dist/r3f.js +28 -19
- package/dist/{react-CTADh3NN.js → react-DzrtrzZy.js} +4 -6
- package/dist/react.d.ts +4 -6
- package/dist/react.js +1 -1
- package/dist/{scene-like-YcY08oii.d.ts → scene-like-CavrKbpQ.d.ts} +590 -47
- package/dist/{scene-DyYdEQdy.js → scene-rsfM06St.js} +711 -21
- package/dist/{snapshot-Cf6NgDl7.js → snapshot-BkbGPspK.js} +1 -2
- package/dist/{store-C5nzCpxy.d.ts → store-CZwml1K3.d.ts} +5 -10
- package/dist/{store-Z6A2HPih.js → store-m9l0Al-m.js} +9 -12
- package/dist/store.d.ts +2 -4
- package/dist/store.js +4 -5
- package/dist/three.d.ts +2 -6
- package/dist/three.js +4 -6
- package/dist/{views-Dh3aWc2q.js → views-CdOArjcB.js} +6 -8
- package/dist/wasm/fast_mesh_wasm.d.ts +113 -8
- package/dist/wasm/fast_mesh_wasm.js +267 -8
- package/dist/wasm/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm/fast_mesh_wasm_bg.wasm.d.ts +13 -1
- package/dist/wasm-threads/fast_mesh_wasm.d.ts +113 -8
- package/dist/wasm-threads/fast_mesh_wasm.js +268 -9
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm +0 -0
- package/dist/wasm-threads/fast_mesh_wasm_bg.wasm.d.ts +13 -1
- package/dist/web.d.ts +3 -5
- package/dist/web.js +4 -5
- package/dist/worker-engine.d.ts +1 -7
- package/dist/worker-engine.js +1 -1
- package/dist/worker-entry.js +2 -3
- package/dist/worker.d.ts +2 -2
- package/dist/worker.js +1 -1
- package/package.json +16 -4
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ct as MeshHandle, t as SceneLike } from "./scene-like-CavrKbpQ.js";
|
|
2
2
|
import * as THREE from "three";
|
|
3
|
-
//#region src/three/mesh.d.ts
|
|
4
3
|
/** Options of {@link bindMesh}. */
|
|
5
4
|
interface BindMeshOptions {
|
|
6
5
|
/**
|
|
@@ -17,6 +16,16 @@ interface BindMeshOptions {
|
|
|
17
16
|
* it is rebuilt with, then without, the shading); the material stays usable.
|
|
18
17
|
*/
|
|
19
18
|
material?: THREE.MeshStandardMaterial | THREE.MeshPhongMaterial | THREE.MeshLambertMaterial | THREE.MeshBasicMaterial;
|
|
19
|
+
/**
|
|
20
|
+
* The texture to draw the mesh's UVs with: sets the material's `map`, and
|
|
21
|
+
* makes the default material's colour white. A `material` that already has
|
|
22
|
+
* a `map` needs no more. Either way the map is on while the mesh has UVs: an
|
|
23
|
+
* operation that drops them (see `docs/uv-channel.md`) takes it off rather
|
|
24
|
+
* than stretch one texel over the surface, and undo puts it back. The
|
|
25
|
+
* texture stays the caller's to dispose. glTF UVs want `texture.flipY = false`,
|
|
26
|
+
* as three's `GLTFLoader` sets.
|
|
27
|
+
*/
|
|
28
|
+
map?: THREE.Texture;
|
|
20
29
|
/**
|
|
21
30
|
* The colour shown while the mesh has no colouring. Defaults to the given
|
|
22
31
|
* material's colour (left untouched), or light grey for the default material.
|
|
@@ -68,8 +77,8 @@ interface BindMeshOptions {
|
|
|
68
77
|
interface BoundMesh {
|
|
69
78
|
/**
|
|
70
79
|
* The mesh to add to a THREE.Scene. Its geometry has `position`, `normal`
|
|
71
|
-
* (when the scene mesh keeps normals), `
|
|
72
|
-
* an index; its `matrix` is the scene mesh's world matrix
|
|
80
|
+
* (when the scene mesh keeps normals), `uv` (while it has UVs), `color`
|
|
81
|
+
* (while colouring is on) and an index; its `matrix` is the scene mesh's world matrix
|
|
73
82
|
* (`matrixAutoUpdate` is off). The colour attribute is normalized `Uint16`
|
|
74
83
|
* RGBA: the engine's sRGB colours converted to three's linear working space.
|
|
75
84
|
*/
|
|
@@ -107,7 +116,8 @@ type MeshBinding = Pick<BoundMesh, "mesh" | "object">;
|
|
|
107
116
|
* {@link SceneLike.commitFrame}: dirty ranges are copied into the attributes'
|
|
108
117
|
* mirrors and marked with `addUpdateRange`, attributes are recreated when the
|
|
109
118
|
* mesh's slot counts change, the colour attribute comes and goes with the
|
|
110
|
-
* mesh's colouring,
|
|
119
|
+
* mesh's colouring, the `uv` attribute with its UVs, and `object.matrix`
|
|
120
|
+
* follows its placement.
|
|
111
121
|
*
|
|
112
122
|
* Dead vertex slots keep stale positions, so the geometry's bounding box and
|
|
113
123
|
* sphere are computed from the vertices of live triangles only (a removed
|
|
@@ -133,5 +143,4 @@ type MeshBinding = Pick<BoundMesh, "mesh" | "object">;
|
|
|
133
143
|
* `scene.commitFrame()` once per animation frame, before rendering.
|
|
134
144
|
*/
|
|
135
145
|
declare function bindMesh(scene: SceneLike, mesh: MeshHandle, options?: BindMeshOptions): BoundMesh;
|
|
136
|
-
//#endregion
|
|
137
146
|
export { bindMesh as i, BoundMesh as n, MeshBinding as r, BindMeshOptions as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as SRGB_TO_LINEAR16, i as SHADING_VERTEX, o as encodeValues, r as SHADING_FRAGMENT, s as shadingOf } from "./colormap-Dr5V3bvs.js";
|
|
2
|
+
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
3
3
|
import * as THREE from "three";
|
|
4
|
-
|
|
4
|
+
// src/three/mesh.ts
|
|
5
5
|
const DEFAULT_COLOR = 13421772;
|
|
6
6
|
const WHITE = new THREE.Color(16777215);
|
|
7
7
|
/**
|
|
@@ -41,6 +41,12 @@ const BUFFERS = {
|
|
|
41
41
|
normalized: true,
|
|
42
42
|
make: (n) => new Uint16Array(n)
|
|
43
43
|
},
|
|
44
|
+
uvs: {
|
|
45
|
+
name: "uv",
|
|
46
|
+
itemSize: 2,
|
|
47
|
+
normalized: false,
|
|
48
|
+
make: (n) => new Float32Array(n)
|
|
49
|
+
},
|
|
44
50
|
values: {
|
|
45
51
|
name: "fmValue",
|
|
46
52
|
itemSize: 4,
|
|
@@ -59,7 +65,8 @@ const BUFFERS = {
|
|
|
59
65
|
* {@link SceneLike.commitFrame}: dirty ranges are copied into the attributes'
|
|
60
66
|
* mirrors and marked with `addUpdateRange`, attributes are recreated when the
|
|
61
67
|
* mesh's slot counts change, the colour attribute comes and goes with the
|
|
62
|
-
* mesh's colouring,
|
|
68
|
+
* mesh's colouring, the `uv` attribute with its UVs, and `object.matrix`
|
|
69
|
+
* follows its placement.
|
|
63
70
|
*
|
|
64
71
|
* Dead vertex slots keep stale positions, so the geometry's bounding box and
|
|
65
72
|
* sphere are computed from the vertices of live triangles only (a removed
|
|
@@ -88,18 +95,23 @@ function bindMesh(scene, mesh, options = {}) {
|
|
|
88
95
|
if (options.shading !== void 0 && options.shading !== "vertex" && options.shading !== "fragment") throw new FastMeshError("INVALID_ARGUMENT", "shading must be \"vertex\" or \"fragment\"");
|
|
89
96
|
checkSoftness(options.edgeSoftness ?? 0);
|
|
90
97
|
const ownsMaterial = options.material === void 0;
|
|
91
|
-
const material = options.material ?? new THREE.MeshStandardMaterial({ color: DEFAULT_COLOR });
|
|
98
|
+
const material = options.material ?? new THREE.MeshStandardMaterial({ color: options.map === void 0 ? DEFAULT_COLOR : WHITE });
|
|
99
|
+
const givenMap = material.map;
|
|
100
|
+
const map = options.map ?? givenMap;
|
|
101
|
+
material.map = map;
|
|
92
102
|
const fragment = options.shading === "fragment" && typeof scene.coloring === "function" && typeof scene.views(mesh).values === "function" && patchable(material);
|
|
93
103
|
if (fragment && patched.has(material)) throw new FastMeshError("INVALID_ARGUMENT", "the material is already drawn by another fragment-shaded binding: give each binding its own (material.clone())");
|
|
94
104
|
const keys = fragment ? [
|
|
95
105
|
"positions",
|
|
96
106
|
"normals",
|
|
97
107
|
"values",
|
|
108
|
+
"uvs",
|
|
98
109
|
"indices"
|
|
99
110
|
] : [
|
|
100
111
|
"positions",
|
|
101
112
|
"normals",
|
|
102
113
|
"colors",
|
|
114
|
+
"uvs",
|
|
103
115
|
"indices"
|
|
104
116
|
];
|
|
105
117
|
if (options.color !== void 0) material.color.set(options.color);
|
|
@@ -124,6 +136,7 @@ function bindMesh(scene, mesh, options = {}) {
|
|
|
124
136
|
case "normals": return v.normals();
|
|
125
137
|
case "colors": return v.colors();
|
|
126
138
|
case "values": return shading === void 0 ? null : v.values?.() ?? null;
|
|
139
|
+
case "uvs": return v.uvs?.() ?? null;
|
|
127
140
|
case "indices": return v.indices();
|
|
128
141
|
}
|
|
129
142
|
};
|
|
@@ -245,7 +258,7 @@ function bindMesh(scene, mesh, options = {}) {
|
|
|
245
258
|
const pending = [];
|
|
246
259
|
const ruleChanged = followRule();
|
|
247
260
|
for (const key of keys) {
|
|
248
|
-
const dirty = change === void 0 || key === "values" && ruleChanged ? "all" : change[key === "values" ? "colors" : key];
|
|
261
|
+
const dirty = change === void 0 || key === "values" && ruleChanged ? "all" : change[key === "values" ? "colors" : key] ?? [];
|
|
249
262
|
if (dirty !== "all" && dirty.length === 0 && !resized) continue;
|
|
250
263
|
const view = viewOf(key);
|
|
251
264
|
const attribute = attributeOf(key);
|
|
@@ -283,6 +296,11 @@ function bindMesh(scene, mesh, options = {}) {
|
|
|
283
296
|
for (const key of keys) attributeOf(key)?.clearUpdateRanges();
|
|
284
297
|
}
|
|
285
298
|
setColored(attributeOf(fragment ? "values" : "colors") !== void 0);
|
|
299
|
+
const shown = attributeOf("uvs") === void 0 ? null : map;
|
|
300
|
+
if (material.map !== shown) {
|
|
301
|
+
material.map = shown;
|
|
302
|
+
material.needsUpdate = true;
|
|
303
|
+
}
|
|
286
304
|
return geometryChanged;
|
|
287
305
|
};
|
|
288
306
|
apply(void 0);
|
|
@@ -330,7 +348,13 @@ function bindMesh(scene, mesh, options = {}) {
|
|
|
330
348
|
geometry.dispose();
|
|
331
349
|
uniforms?.fmLut.value?.dispose();
|
|
332
350
|
if (ownsMaterial) material.dispose();
|
|
333
|
-
else
|
|
351
|
+
else {
|
|
352
|
+
if (material.map !== givenMap) {
|
|
353
|
+
material.map = givenMap;
|
|
354
|
+
material.needsUpdate = true;
|
|
355
|
+
}
|
|
356
|
+
restoreMaterial?.();
|
|
357
|
+
}
|
|
334
358
|
}
|
|
335
359
|
};
|
|
336
360
|
if (options.opacity !== void 0) bound.setOpacity(options.opacity);
|
|
@@ -471,5 +495,4 @@ function patchMaterial(material, uniforms) {
|
|
|
471
495
|
material.needsUpdate = true;
|
|
472
496
|
};
|
|
473
497
|
}
|
|
474
|
-
//#endregion
|
|
475
498
|
export { checkUntransformedParent as n, bindMesh as t };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { $ as
|
|
2
|
-
import { n as FastMeshErrorCode, t as FastMeshError } from "./core-
|
|
3
|
-
//#region src/node.d.ts
|
|
1
|
+
import { $ as Scene, A as InflateReport, At as PlacementInput, B as OutOfRange, C as EditRef, Ct as MeshHandle, D as FilledLoop, Dt as InitInput, E as FillReport, Et as Indices, F as MeshChange, Ft as Vec3, G as RegisterStatus, H as RaycastOptions, I as MeshComponent, It as computeBounds, J as RemoveReport, K as RelaxReport, L as MeshDistance, Lt as computeVertexNormals, M as JoinReport, Mt as Positions64, N as LoopId, Nt as Quat, O as FindContactsOptions, Ot as Mat3, P as MeasureResult, Pt as UpdateMode, Q as Rgba, R as OffsetReport, S as EditOp, St as FieldHandle, T as FieldStatus, Tt as Bounds, U as RegisterOptions, V as RayHit, W as RegisterResult, X as RepairReport, Y as RepairOp, Z as RepairReportOf, _ as CutReport, _t as SelectSpec, a as AutoRepairReport, at as SectionResult, b as DragOptions, bt as MeshViews, c as BoundaryLoop, ct as SimplifyReport, d as ClosestPointOptions, dt as ThicknessFieldDesc, et as SceneOptions, f as ColorRule, ft as WeldReport, g as CutOptions, gt as LassoSelect, h as CurvatureFieldDesc, ht as IsolateReport, i as AnalyzeOptions, it as SectionPlane, j as JoinOptions, jt as Positions, k as GrabReport, kt as Placement, l as BridgeReport, lt as SmoothReport, m as Contact, mt as ComponentSelect, n as AddMeshOptions, nt as SectionDesc, o as AutoRepairRequest, ot as ShellReport, p as Colormap, pt as BrushSelect, q as RemeshReport, r as Analysis, rt as SectionGap, s as BooleanOp, st as SignMode, t as SceneLike, tt as SectionContour, u as ClosestHit, ut as SubdivideReport, v as DegenerateReport, vt as VertexSelection, w as EditResult, wt as SectionHandle, x as DragSession, xt as SceneMeshViews, y as DistanceFieldDesc, yt as Range, z as OrientReport } from "./scene-like-CavrKbpQ.js";
|
|
2
|
+
import { n as FastMeshErrorCode, t as FastMeshError } from "./core-CJ9D6U5A.js";
|
|
4
3
|
/**
|
|
5
4
|
* Resolves immediately: in Node.js and Bun the module is ready as soon as it is imported.
|
|
6
5
|
* Accepts the same argument as the browser `init()` so the same code runs everywhere;
|
|
7
6
|
* the argument is ignored.
|
|
8
7
|
*/
|
|
9
8
|
export declare function init(_input?: InitInput | Promise<InitInput>): Promise<void>;
|
|
10
|
-
|
|
11
|
-
export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type BoundaryLoop, type Bounds, type BridgeReport, type ClosestHit, type ClosestPointOptions, type ColorRule, type Colormap, type Contact, 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 Indices, type InflateReport, type InitInput, type JoinOptions, type JoinReport, type LoopId, type Mat3, type MeshChange, type MeshComponent, type MeshDistance, type MeshHandle, type MeshViews, type OrientReport, type OutOfRange, type Placement, type PlacementInput, type Positions, type Positions64, type Quat, type Range, type RayHit, type RaycastOptions, type RemeshReport, type RemoveReport, type RepairOp, type RepairReport, type RepairReportOf, type Rgba, Scene, type SceneLike, type SceneOptions, type SectionContour, type SectionDesc, type SectionGap, type SectionHandle, type SectionPlane, type SectionResult, type SignMode, type SmoothReport, type UpdateMode, type Vec3, type WeldReport, computeBounds, computeVertexNormals };
|
|
9
|
+
export { type AddMeshOptions, type Analysis, type AnalyzeOptions, type AutoRepairReport, type AutoRepairRequest, type BooleanOp, type BoundaryLoop, type Bounds, type BridgeReport, type BrushSelect, 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 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 SubdivideReport, type ThicknessFieldDesc, type UpdateMode, type Vec3, type VertexSelection, type WeldReport, computeBounds, computeVertexNormals };
|
package/dist/node.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
import {
|
|
3
|
-
import { t as Scene } from "./scene-
|
|
1
|
+
import { n as computeVertexNormals, r as markInitialized, t as computeBounds } from "./api-4kz45-Mq.js";
|
|
2
|
+
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
3
|
+
import { t as Scene } from "./scene-rsfM06St.js";
|
|
4
4
|
import { initSync } from "./wasm/fast_mesh_wasm.js";
|
|
5
5
|
import { readFileSync } from "node:fs";
|
|
6
|
-
|
|
6
|
+
// src/node.ts
|
|
7
7
|
markInitialized(initSync({ module: readFileSync(new URL("./wasm/fast_mesh_wasm_bg.wasm", import.meta.url)) }));
|
|
8
8
|
/**
|
|
9
9
|
* Resolves immediately: in Node.js and Bun the module is ready as soon as it is imported.
|
|
@@ -13,5 +13,4 @@ markInitialized(initSync({ module: readFileSync(new URL("./wasm/fast_mesh_wasm_b
|
|
|
13
13
|
function init(_input) {
|
|
14
14
|
return Promise.resolve();
|
|
15
15
|
}
|
|
16
|
-
//#endregion
|
|
17
16
|
export { FastMeshError, Scene, computeBounds, computeVertexNormals, init };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
//#region src/worker/protocol.d.ts
|
|
1
|
+
import { at as SectionResult, f as ColorRule, it as SectionPlane, n as AddMeshOptions, y as DistanceFieldDesc, yt as Range } from "./scene-like-CavrKbpQ.js";
|
|
3
2
|
/** A mesh, field or section id allocated on the main side. Unique per kind. */
|
|
4
3
|
type ClientId = number;
|
|
5
4
|
/** A {@link ColorRule} naming its field by client id. */
|
|
@@ -38,7 +37,9 @@ type Request = {
|
|
|
38
37
|
f64: boolean;
|
|
39
38
|
/** `Uint32Array` bytes. */
|
|
40
39
|
indices: ArrayBuffer;
|
|
41
|
-
/** `
|
|
40
|
+
/** `Float32Array` bytes of the UVs, for a mesh with them. */
|
|
41
|
+
uvs?: ArrayBuffer;
|
|
42
|
+
/** `mode` and `uvs` are ignored: the Worker scene is always `"eager"`, and `uvs` above is what crosses. */
|
|
42
43
|
options: AddMeshOptions;
|
|
43
44
|
/**
|
|
44
45
|
* Add in place, in the batch's own result (a restart's replay), never
|
|
@@ -58,6 +59,8 @@ type Request = {
|
|
|
58
59
|
id: ClientId;
|
|
59
60
|
rotation: number[];
|
|
60
61
|
translation: number[];
|
|
62
|
+
/** Per-axis scale, 3 numbers; `[1, 1, 1]` when omitted. */
|
|
63
|
+
scale?: number[];
|
|
61
64
|
key: string;
|
|
62
65
|
} | {
|
|
63
66
|
kind: "drag";
|
|
@@ -67,12 +70,14 @@ type Request = {
|
|
|
67
70
|
/** For `move`, and optionally `end` (a last move before ending). */
|
|
68
71
|
rotation?: number[];
|
|
69
72
|
translation?: number[];
|
|
73
|
+
/** The move's per-axis scale, 3 numbers; `[1, 1, 1]` when omitted. */
|
|
74
|
+
scale?: number[];
|
|
70
75
|
key: string;
|
|
71
76
|
} | {
|
|
72
77
|
kind: "edit" | "repair";
|
|
73
78
|
rev: number;
|
|
74
79
|
id: ClientId;
|
|
75
|
-
/** `EditOp[]` for `edit`; `RepairOp
|
|
80
|
+
/** `EditOp[]` for `edit`; `RepairOp`, `RepairOp[]` or `AutoRepairRequest` for `repair`. */
|
|
76
81
|
payload: unknown;
|
|
77
82
|
/** When set, the result (an `EditResult` or the repair report(s)) is replied under it. */
|
|
78
83
|
qid?: number;
|
|
@@ -87,6 +92,16 @@ type Request = {
|
|
|
87
92
|
/** When set, the `JoinReport` is replied under it. */
|
|
88
93
|
qid?: number;
|
|
89
94
|
key?: string;
|
|
95
|
+
} | {
|
|
96
|
+
kind: "register";
|
|
97
|
+
rev: number;
|
|
98
|
+
moving: ClientId;
|
|
99
|
+
fixed: ClientId;
|
|
100
|
+
/** `RegisterOptions`. */
|
|
101
|
+
payload: unknown;
|
|
102
|
+
/** The `RegisterResult` is replied under it. */
|
|
103
|
+
qid: number;
|
|
104
|
+
key?: string;
|
|
90
105
|
} | {
|
|
91
106
|
kind: "undo" | "redo";
|
|
92
107
|
rev: number;
|
|
@@ -153,9 +168,10 @@ type Request = {
|
|
|
153
168
|
* `bytes` holds, per buffer, every dirty range's elements concatenated in
|
|
154
169
|
* range order (positions and normals: 3 `f32` per vertex slot; colours: 4
|
|
155
170
|
* bytes per vertex slot; values: 1 `f32` per vertex slot, over the colours'
|
|
156
|
-
* ranges, once a `values` request turned them on; indices: 3 `u32` per triangle slot), or the whole buffer when the
|
|
171
|
+
* ranges, once a `values` request turned them on; UVs: 2 `f32` per vertex slot; indices: 3 `u32` per triangle slot), or the whole buffer when the
|
|
157
172
|
* ranges are `"all"`. `null` for a buffer that is off (normals, colours and
|
|
158
|
-
* values), and for every buffer of a removed mesh.
|
|
173
|
+
* values), and for every buffer of a removed mesh; UVs are absent when off.
|
|
174
|
+
* `uvs` is present only for a mesh that has UVs or just lost them.
|
|
159
175
|
*/
|
|
160
176
|
interface MeshChangeWire {
|
|
161
177
|
id: ClientId;
|
|
@@ -167,6 +183,7 @@ interface MeshChangeWire {
|
|
|
167
183
|
normals: Range[] | "all";
|
|
168
184
|
colors: Range[] | "all";
|
|
169
185
|
indices: Range[] | "all";
|
|
186
|
+
uvs?: Range[] | "all";
|
|
170
187
|
fields: ClientId[];
|
|
171
188
|
sections: ClientId[];
|
|
172
189
|
/** Slot counts after the change; 0 for a removed mesh. */
|
|
@@ -178,6 +195,7 @@ interface MeshChangeWire {
|
|
|
178
195
|
colors: ArrayBuffer | null;
|
|
179
196
|
values: ArrayBuffer | null;
|
|
180
197
|
indices: ArrayBuffer | null;
|
|
198
|
+
uvs?: ArrayBuffer;
|
|
181
199
|
};
|
|
182
200
|
}
|
|
183
201
|
/** An error crossing the boundary: a `FastMeshError` code and message. */
|
|
@@ -199,6 +217,7 @@ interface Result {
|
|
|
199
217
|
id: ClientId;
|
|
200
218
|
rotation: number[];
|
|
201
219
|
translation: number[];
|
|
220
|
+
scale: number[];
|
|
202
221
|
matrix4: number[];
|
|
203
222
|
}[];
|
|
204
223
|
/**
|
|
@@ -299,5 +318,4 @@ type WorkerMessage = Result | {
|
|
|
299
318
|
kind: "fatal";
|
|
300
319
|
error: ErrorWire;
|
|
301
320
|
};
|
|
302
|
-
//#endregion
|
|
303
321
|
export { WorkerMessage as a, Result as i, InitMessage as n, Request as r, ClientId as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/worker/protocol.ts
|
|
2
2
|
/** Whether a message to a Worker is its {@link InitMessage} (else a batch). */
|
|
3
3
|
function isInit(data) {
|
|
4
4
|
return !Array.isArray(data) && data?.kind === "init";
|
|
@@ -66,5 +66,4 @@ function supersedes(later, earlier) {
|
|
|
66
66
|
default: return false;
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
//#endregion
|
|
70
69
|
export { supersedes as a, sectionAspects as i, isLastWins as n, keyOf as r, isInit as t };
|
package/dist/r3f.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as SceneStore } from "./store-
|
|
3
|
-
import { n as BoundMesh, t as BindMeshOptions } from "./mesh-
|
|
1
|
+
import { Ct as MeshHandle } from "./scene-like-CavrKbpQ.js";
|
|
2
|
+
import { t as SceneStore } from "./store-CZwml1K3.js";
|
|
3
|
+
import { n as BoundMesh, t as BindMeshOptions } from "./mesh-CqAIuOxU.js";
|
|
4
4
|
import * as THREE from "three";
|
|
5
5
|
import { JSX } from "react";
|
|
6
6
|
import { EventHandlers } from "@react-three/fiber";
|
|
7
|
-
//#region src/r3f/index.d.ts
|
|
8
7
|
/**
|
|
9
8
|
* Calls `store.commitFrame()` once per rendered R3F frame, however many
|
|
10
9
|
* components call this hook for the same store, and invalidates the canvas
|
|
@@ -34,6 +33,12 @@ export interface FastMeshProps extends EventHandlers {
|
|
|
34
33
|
material?: BindMeshOptions["material"];
|
|
35
34
|
/** The colour while the mesh has no colouring (see `BindMeshOptions.color`). */
|
|
36
35
|
color?: THREE.ColorRepresentation;
|
|
36
|
+
/**
|
|
37
|
+
* A visibility override, ANDed with the store display's `visible` (unset
|
|
38
|
+
* shows). The store still hides the mesh while set; changing it never
|
|
39
|
+
* rebinds.
|
|
40
|
+
*/
|
|
41
|
+
visible?: boolean;
|
|
37
42
|
/**
|
|
38
43
|
* How a colouring is drawn (see `BindMeshOptions.shading`): `"vertex"` (the
|
|
39
44
|
* default) or `"fragment"`. Changing it rebinds the mesh.
|
|
@@ -55,5 +60,16 @@ export interface FastMeshProps extends EventHandlers {
|
|
|
55
60
|
*/
|
|
56
61
|
onBind?: (bound: BoundMesh | null) => void;
|
|
57
62
|
}
|
|
58
|
-
|
|
59
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Draws a scene mesh: binds it with `bindMesh` on mount and disposes the
|
|
65
|
+
* binding on unmount (or when the mesh is removed, after which it renders
|
|
66
|
+
* nothing). The mesh's applied `opacity` and `visible` follow the store in
|
|
67
|
+
* the frame that applies them; colouring follows the scene. Drives the
|
|
68
|
+
* store's frames with {@link useFrameDriver}. Use it inside a `<Canvas>`.
|
|
69
|
+
*
|
|
70
|
+
* The mesh must be added through the store (`store.addMesh`): a mesh added
|
|
71
|
+
* straight to `store.scene` is not in the store, and renders nothing.
|
|
72
|
+
*
|
|
73
|
+
* @throws `INVALID_ARGUMENT` without a `store` outside a `SceneProvider`.
|
|
74
|
+
*/
|
|
75
|
+
export declare function FastMesh(props: FastMeshProps): JSX.Element;
|
package/dist/r3f.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { t as FastMeshError } from "./core-
|
|
2
|
-
import { t as
|
|
3
|
-
import { s as meshState } from "./snapshot-
|
|
4
|
-
import { r as setFrameLoop } from "./store-
|
|
5
|
-
import {
|
|
1
|
+
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
+
import { c as useStoreSelector, i as useScene, l as StoreContext, t as SceneProvider } from "./react-DzrtrzZy.js";
|
|
3
|
+
import { s as meshState } from "./snapshot-BkbGPspK.js";
|
|
4
|
+
import { r as setFrameLoop } from "./store-m9l0Al-m.js";
|
|
5
|
+
import { t as bindMesh } from "./mesh-hPWBQPaN.js";
|
|
6
6
|
import * as THREE from "three";
|
|
7
7
|
import { createElement, useCallback, useContext, useLayoutEffect, useRef, useState } from "react";
|
|
8
8
|
import { useFrame, useThree } from "@react-three/fiber";
|
|
9
|
-
|
|
9
|
+
// src/r3f/index.ts
|
|
10
10
|
const drivers = /* @__PURE__ */ new WeakMap();
|
|
11
11
|
/**
|
|
12
12
|
* Calls `store.commitFrame()` once per rendered R3F frame, however many
|
|
@@ -76,6 +76,16 @@ function useFrameDriver(store) {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
+
* `width` when it is a finite number `>= 0` (what `setEdgeSoftness` takes),
|
|
80
|
+
* else 0 with a warning: a bad prop (a slider's NaN, say) draws hard edges
|
|
81
|
+
* rather than throwing inside the canvas.
|
|
82
|
+
*/
|
|
83
|
+
function usableSoftness(width) {
|
|
84
|
+
if (typeof width === "number" && Number.isFinite(width) && width >= 0) return width;
|
|
85
|
+
console.warn(`fast-mesh-wasm: <FastMesh edgeSoftness={${String(width)}}> is not a finite number >= 0; using 0.`);
|
|
86
|
+
return 0;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
79
89
|
* Draws a scene mesh: binds it with `bindMesh` on mount and disposes the
|
|
80
90
|
* binding on unmount (or when the mesh is removed, after which it renders
|
|
81
91
|
* nothing). The mesh's applied `opacity` and `visible` follow the store in
|
|
@@ -87,22 +97,12 @@ function useFrameDriver(store) {
|
|
|
87
97
|
*
|
|
88
98
|
* @throws `INVALID_ARGUMENT` without a `store` outside a `SceneProvider`.
|
|
89
99
|
*/
|
|
90
|
-
/**
|
|
91
|
-
* `width` when it is a finite number `>= 0` (what `setEdgeSoftness` takes),
|
|
92
|
-
* else 0 with a warning: a bad prop (a slider's NaN, say) draws hard edges
|
|
93
|
-
* rather than throwing inside the canvas.
|
|
94
|
-
*/
|
|
95
|
-
function usableSoftness(width) {
|
|
96
|
-
if (typeof width === "number" && Number.isFinite(width) && width >= 0) return width;
|
|
97
|
-
console.warn(`fast-mesh-wasm: <FastMesh edgeSoftness={${String(width)}}> is not a finite number >= 0; using 0.`);
|
|
98
|
-
return 0;
|
|
99
|
-
}
|
|
100
100
|
function FastMesh(props) {
|
|
101
101
|
const body = createElement(FastMeshBody, props);
|
|
102
102
|
return props.store === void 0 ? body : createElement(SceneProvider, { store: props.store }, body);
|
|
103
103
|
}
|
|
104
104
|
function FastMeshBody(props) {
|
|
105
|
-
const { mesh, store: _store, material, color, shading, edgeSoftness = 0, onBind, ...events } = props;
|
|
105
|
+
const { mesh, store: _store, material, color, shading, edgeSoftness = 0, onBind, visible, ...events } = props;
|
|
106
106
|
const store = useScene();
|
|
107
107
|
useFrameDriver(store);
|
|
108
108
|
const present = useStoreSelector(useCallback((s) => s.meshes.has(mesh), [mesh]));
|
|
@@ -110,6 +110,8 @@ function FastMeshBody(props) {
|
|
|
110
110
|
const [bound, setBound] = useState(null);
|
|
111
111
|
const onBindRef = useRef(onBind);
|
|
112
112
|
onBindRef.current = onBind;
|
|
113
|
+
const visibleRef = useRef(visible);
|
|
114
|
+
visibleRef.current = visible;
|
|
113
115
|
const softness = usableSoftness(edgeSoftness);
|
|
114
116
|
const softnessRef = useRef(softness);
|
|
115
117
|
softnessRef.current = softness;
|
|
@@ -130,7 +132,7 @@ function FastMeshBody(props) {
|
|
|
130
132
|
if (d !== last) {
|
|
131
133
|
last = d;
|
|
132
134
|
b.setOpacity(d.opacity);
|
|
133
|
-
b.object.visible = d.visible;
|
|
135
|
+
b.object.visible = d.visible && (visibleRef.current ?? true);
|
|
134
136
|
}
|
|
135
137
|
};
|
|
136
138
|
apply();
|
|
@@ -154,6 +156,14 @@ function FastMeshBody(props) {
|
|
|
154
156
|
useLayoutEffect(() => {
|
|
155
157
|
bound?.setEdgeSoftness(softness);
|
|
156
158
|
}, [bound, softness]);
|
|
159
|
+
useLayoutEffect(() => {
|
|
160
|
+
if (bound !== null) bound.object.visible = meshState(store.getSnapshot(), mesh).display.visible && (visible ?? true);
|
|
161
|
+
}, [
|
|
162
|
+
store,
|
|
163
|
+
mesh,
|
|
164
|
+
bound,
|
|
165
|
+
visible
|
|
166
|
+
]);
|
|
157
167
|
if (bound === null) return null;
|
|
158
168
|
return createElement("primitive", {
|
|
159
169
|
object: bound.object,
|
|
@@ -161,5 +171,4 @@ function FastMeshBody(props) {
|
|
|
161
171
|
...events
|
|
162
172
|
});
|
|
163
173
|
}
|
|
164
|
-
//#endregion
|
|
165
174
|
export { FastMesh, useFrameDriver };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { t as FastMeshError } from "./core-
|
|
2
|
-
import { l as sectionState, n as EMPTY_SNAPSHOT, s as meshState } from "./snapshot-
|
|
1
|
+
import { t as FastMeshError } from "./core-4OcWKu3r.js";
|
|
2
|
+
import { l as sectionState, n as EMPTY_SNAPSHOT, s as meshState } from "./snapshot-BkbGPspK.js";
|
|
3
3
|
import { createContext, createElement, useCallback, useContext, useMemo, useRef, useSyncExternalStore } from "react";
|
|
4
|
-
|
|
4
|
+
// src/react/context.ts
|
|
5
5
|
/** The store a `SceneProvider` provides, or `null` outside one. */
|
|
6
6
|
const StoreContext = createContext(null);
|
|
7
|
-
|
|
8
|
-
//#region src/react/index.ts
|
|
7
|
+
// src/react/index.ts
|
|
9
8
|
/** Provides `store` to the hooks below it. */
|
|
10
9
|
function SceneProvider(props) {
|
|
11
10
|
return createElement(StoreContext.Provider, { value: props.store }, props.children);
|
|
@@ -120,5 +119,4 @@ function useSelection() {
|
|
|
120
119
|
const store = useScene();
|
|
121
120
|
return [useStoreSelector(selectSelection), useCallback((mesh) => store.select(mesh), [store])];
|
|
122
121
|
}
|
|
123
|
-
//#endregion
|
|
124
122
|
export { useSceneStatus as a, useStoreSelector as c, useScene as i, StoreContext as l, useHistory as n, useSection as o, useMeshDisplay as r, useSelection as s, SceneProvider as t };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { a as DisplayState, c as MeshState, d as SceneSnapshot, n as SectionPatch, p as SectionState, t as SceneStore } from "./store-
|
|
1
|
+
import { t as FastMeshError } from "./core-CJ9D6U5A.js";
|
|
2
|
+
import { Ct as MeshHandle, wt as SectionHandle } from "./scene-like-CavrKbpQ.js";
|
|
3
|
+
import { a as DisplayState, c as MeshState, d as SceneSnapshot, n as SectionPatch, p as SectionState, t as SceneStore } from "./store-CZwml1K3.js";
|
|
4
4
|
import { ReactElement, ReactNode } from "react";
|
|
5
|
-
//#region src/react/index.d.ts
|
|
6
5
|
/** Provides `store` to the hooks below it. */
|
|
7
6
|
export declare function SceneProvider(props: {
|
|
8
7
|
store: SceneStore;
|
|
@@ -61,5 +60,4 @@ export interface SceneStatus {
|
|
|
61
60
|
/** The overall status: `"error"` (with the first error) when anything failed, else `"computing"` while anything is pending. */
|
|
62
61
|
export declare function useSceneStatus(): SceneStatus;
|
|
63
62
|
/** The selected mesh (or `null`) and the function that selects one (`store.select`). */
|
|
64
|
-
export declare function useSelection(): [MeshHandle | null, (mesh: MeshHandle | null) => void];
|
|
65
|
-
//#endregion
|
|
63
|
+
export declare function useSelection(): [MeshHandle | null, (mesh: MeshHandle | null) => void];
|
package/dist/react.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as SceneProvider, n as useHistory, r as useMeshDisplay, i as useScene, a as useSceneStatus, o as useSection, s as useSelection, c as useStoreSelector } from "./react-
|
|
1
|
+
export { t as SceneProvider, n as useHistory, r as useMeshDisplay, i as useScene, a as useSceneStatus, o as useSection, s as useSelection, c as useStoreSelector } from "./react-DzrtrzZy.js";
|