dsh-cad 0.16.2 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/README.zh-CN.md +9 -0
- package/lib/client.js +31 -31
- package/lib/client.js.map +3 -3
- package/lib/modeling/assembly.js +318 -215
- package/lib/modeling/cadorange-adapter.cjs +75 -0
- package/lib/modeling/cadorange-bridge.cjs +10 -0
- package/lib/modeling/joints.js +442 -0
- package/lib/modeling/modeling-worker.cjs +88 -0
- package/lib/tools/cad-model.js +2282 -1797
- package/lib/types/modeling/assembly.d.ts +106 -78
- package/lib/types/modeling/client.d.ts +279 -227
- package/lib/types/modeling/joints.d.ts +129 -0
- package/lib/types/tools/cad-model.d.ts +16 -16
- package/package.json +2 -2
|
@@ -1,78 +1,106 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Assembly composition (main thread): instances reference body meshes by id
|
|
3
|
-
* and place them with translate + XYZ-Euler rotate (degrees, the same
|
|
4
|
-
* "translate → rotate" convention as cad_transform / the worker's
|
|
5
|
-
* BRepBuilderAPI_Transform path: p' = T + Rx·(Ry·(Rz·p))). Composition is
|
|
6
|
-
* pure typed-array math on the already-tessellated body meshes — no worker
|
|
7
|
-
* round-trip, no re-tessellation.
|
|
8
|
-
*/
|
|
9
|
-
import type { BinMeshData } from './bin-format.js';
|
|
10
|
-
import type { AssemblyInstance, ModelOp } from './client.js';
|
|
11
|
-
import type { ConstraintEntity, ConstraintEntry } from './constraints.js';
|
|
12
|
-
import type { ModelDoc } from './document.js';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Assembly composition (main thread): instances reference body meshes by id
|
|
3
|
+
* and place them with translate + XYZ-Euler rotate (degrees, the same
|
|
4
|
+
* "translate → rotate" convention as cad_transform / the worker's
|
|
5
|
+
* BRepBuilderAPI_Transform path: p' = T + Rx·(Ry·(Rz·p))). Composition is
|
|
6
|
+
* pure typed-array math on the already-tessellated body meshes — no worker
|
|
7
|
+
* round-trip, no re-tessellation.
|
|
8
|
+
*/
|
|
9
|
+
import type { BinMeshData } from './bin-format.js';
|
|
10
|
+
import type { AssemblyInstance, ModelOp } from './client.js';
|
|
11
|
+
import type { ConstraintEntity, ConstraintEntry } from './constraints.js';
|
|
12
|
+
import type { ModelDoc } from './document.js';
|
|
13
|
+
import type { AssemblyConnection, JointSpec } from './joints.js';
|
|
14
|
+
/**
|
|
15
|
+
* The per-instance pastel palette: instance i takes palette[i % n] both in the
|
|
16
|
+
* composed 3D scene and in the assembly-tree swatches, so a part's color chip
|
|
17
|
+
* always matches its solid. Stable per list position (the worker's insertion
|
|
18
|
+
* order), like the reference CAD assembly panels.
|
|
19
|
+
*/
|
|
20
|
+
export declare const INSTANCE_PALETTE: readonly number[];
|
|
21
|
+
/** The palette color of the instance at `index` in the assembly list. */
|
|
22
|
+
export declare function instanceColor(index: number): number;
|
|
23
|
+
/**
|
|
24
|
+
* Instance display names with the ·N dedup suffix — the single source for
|
|
25
|
+
* mesh names in the composed scene AND part names in the assembly tree, so a
|
|
26
|
+
* tree row always names its mesh (highlight linking relies on it).
|
|
27
|
+
*/
|
|
28
|
+
export declare function assemblyDisplayNames(instances: AssemblyInstance[]): string[];
|
|
29
|
+
/**
|
|
30
|
+
* Compose the assembly scene: one transformed mesh copy per instance, colored
|
|
31
|
+
* by list position (see INSTANCE_PALETTE). Instances referencing bodies
|
|
32
|
+
* missing from `bodies` (consumed by a later boolean) are skipped — the
|
|
33
|
+
* worker's live list already filters them, this is the replay-side double
|
|
34
|
+
* guard. Duplicate names get a ·N suffix (assemblyDisplayNames). `explode`
|
|
35
|
+
* (from explodeOffsets) shifts each instance radially before composing —
|
|
36
|
+
* the exploded view, view-only math over the same placement data.
|
|
37
|
+
*/
|
|
38
|
+
export declare function composeAssemblyMeshes(bodies: Map<string, BinMeshData>, instances: AssemblyInstance[], explode?: ReadonlyMap<string, [number, number, number]>): BinMeshData[];
|
|
39
|
+
/** The assembly state folded from a document's op log (worker-equivalent). */
|
|
40
|
+
export interface FoldedAssembly {
|
|
41
|
+
instances: AssemblyInstance[];
|
|
42
|
+
entities: ConstraintEntity[];
|
|
43
|
+
constraints: ConstraintEntry[];
|
|
44
|
+
/** Body ids alive at the end of the log — the ground truth for "missing".
|
|
45
|
+
* Folded from ops rather than read off bodyNames because documents written
|
|
46
|
+
* before pattern copies were recorded have incomplete name maps. */
|
|
47
|
+
liveBodyIds: Set<string>;
|
|
48
|
+
/** Joints per instance (label → spec), folded from the joint ops. */
|
|
49
|
+
joints: Map<string, Record<string, JointSpec>>;
|
|
50
|
+
/** Recorded joint pairings (connect order preserved — solve replays them). */
|
|
51
|
+
connections: AssemblyConnection[];
|
|
52
|
+
/** Latest exploded-view factor (0 = assembled). */
|
|
53
|
+
explode: number;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Rebuild the assembly state purely from the persisted op log — the worker
|
|
57
|
+
* keeps the same data live (Map insertion order = push order here), so the
|
|
58
|
+
* tree endpoint serves restart-safe data without a worker round-trip.
|
|
59
|
+
*
|
|
60
|
+
* Joint ops are metadata: the placements they solve are written back through
|
|
61
|
+
* `assembly_transform` ops by the tool layer, so this fold carries specs and
|
|
62
|
+
* connections but computes no algebra — replay restores identical placements.
|
|
63
|
+
*/
|
|
64
|
+
export declare function foldAssemblyState(ops: ModelOp[], bodyNames: Record<string, string>): FoldedAssembly;
|
|
65
|
+
/** One PARTS row of the assembly tree. */
|
|
66
|
+
export interface AssemblyTreePart {
|
|
67
|
+
instanceId: string;
|
|
68
|
+
bodyId: string;
|
|
69
|
+
/** Display name — identical to the composed scene's mesh name. */
|
|
70
|
+
name: string;
|
|
71
|
+
color: number;
|
|
72
|
+
/** True when the referenced body was consumed (no mesh in the scene). */
|
|
73
|
+
missing: boolean;
|
|
74
|
+
}
|
|
75
|
+
/** One CONSTRAINTS row; a/b are resolved display names where possible. */
|
|
76
|
+
export interface AssemblyTreeConstraint {
|
|
77
|
+
id: number;
|
|
78
|
+
type: string;
|
|
79
|
+
label?: string;
|
|
80
|
+
a?: string;
|
|
81
|
+
b?: string;
|
|
82
|
+
}
|
|
83
|
+
/** One JOINTS row of the assembly tree (a joint, plus its pairing if connected). */
|
|
84
|
+
export interface AssemblyTreeJoint {
|
|
85
|
+
instanceId: string;
|
|
86
|
+
label: string;
|
|
87
|
+
type: string;
|
|
88
|
+
/** Display text of the current motion value ("30°", "12mm · 5°"). */
|
|
89
|
+
value?: string;
|
|
90
|
+
/** The owner instance's display name. */
|
|
91
|
+
owner: string;
|
|
92
|
+
/** "owner.label ↔ peer.name" when this joint is one side of a pairing. */
|
|
93
|
+
link?: string;
|
|
94
|
+
}
|
|
95
|
+
/** GET /dsh-cad/asm/<docId> response body. */
|
|
96
|
+
export interface AssemblyTreePayload {
|
|
97
|
+
docId: string;
|
|
98
|
+
version: number;
|
|
99
|
+
parts: AssemblyTreePart[];
|
|
100
|
+
constraints: AssemblyTreeConstraint[];
|
|
101
|
+
joints: AssemblyTreeJoint[];
|
|
102
|
+
/** Exploded-view factor (absent when assembled). */
|
|
103
|
+
explode?: number;
|
|
104
|
+
}
|
|
105
|
+
/** Build the assembly-tree payload from a restored document. */
|
|
106
|
+
export declare function assemblyTreePayload(doc: ModelDoc): AssemblyTreePayload;
|