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,227 +1,279 @@
|
|
|
1
|
-
export interface WorkerMesh {
|
|
2
|
-
name: string;
|
|
3
|
-
positions: Float32Array;
|
|
4
|
-
normals: Float32Array;
|
|
5
|
-
indices: Uint32Array;
|
|
6
|
-
vertexCount: number;
|
|
7
|
-
triangleCount: number;
|
|
8
|
-
}
|
|
9
|
-
/** One placed reference of a body inside the assembly. */
|
|
10
|
-
export interface AssemblyInstance {
|
|
11
|
-
instanceId: string;
|
|
12
|
-
bodyId: string;
|
|
13
|
-
name: string;
|
|
14
|
-
translate: [number, number, number];
|
|
15
|
-
rotate: [number, number, number];
|
|
16
|
-
}
|
|
17
|
-
/** One projected hidden-line drawing view (flat [x,y, x,y, …] polylines, mm). */
|
|
18
|
-
export interface DrawingView {
|
|
19
|
-
name: string;
|
|
20
|
-
visible: number[][];
|
|
21
|
-
hidden: number[][];
|
|
22
|
-
}
|
|
23
|
-
export interface OpResult {
|
|
24
|
-
bodyId?: string;
|
|
25
|
-
name?: string;
|
|
26
|
-
removed?: string[];
|
|
27
|
-
edges?: number;
|
|
28
|
-
mesh?: WorkerMesh;
|
|
29
|
-
meshes?: Array<WorkerMesh & {
|
|
30
|
-
bodyId: string;
|
|
31
|
-
}>;
|
|
32
|
-
bytes?: ArrayBuffer;
|
|
33
|
-
volume?: number;
|
|
34
|
-
/** Center of mass [x,y,z] (occt.ts backend). */
|
|
35
|
-
centroid?: number[];
|
|
36
|
-
deleted?: string;
|
|
37
|
-
cleared?: boolean;
|
|
38
|
-
views?: DrawingView[];
|
|
39
|
-
instanceId?: string;
|
|
40
|
-
instances?: AssemblyInstance[];
|
|
41
|
-
/** Pattern op: the newly created copy bodies with their meshes. */
|
|
42
|
-
created?: Array<{
|
|
43
|
-
bodyId: string;
|
|
44
|
-
name?: string;
|
|
45
|
-
mesh?: WorkerMesh;
|
|
46
|
-
}>;
|
|
47
|
-
/** Name of the sketch touched by a sketch op. */
|
|
48
|
-
sketch?: string;
|
|
49
|
-
/** Flat [x,y,z,…] display polyline of the sketch (sketch_set; occt.ts backend). */
|
|
50
|
-
wire?: number[];
|
|
51
|
-
/** Flat [x,y,z,…] TRUE vertex points of the sketch (corners/ends; circles carry none). */
|
|
52
|
-
points?: number[];
|
|
53
|
-
/** Triangulated enclosed region { positions, indices } (the translucent fill). */
|
|
54
|
-
fill?: {
|
|
55
|
-
positions: number[];
|
|
56
|
-
indices: number[];
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
smooth
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
} | {
|
|
118
|
-
kind: '
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
} | {
|
|
212
|
-
kind: '
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
/**
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
1
|
+
export interface WorkerMesh {
|
|
2
|
+
name: string;
|
|
3
|
+
positions: Float32Array;
|
|
4
|
+
normals: Float32Array;
|
|
5
|
+
indices: Uint32Array;
|
|
6
|
+
vertexCount: number;
|
|
7
|
+
triangleCount: number;
|
|
8
|
+
}
|
|
9
|
+
/** One placed reference of a body inside the assembly. */
|
|
10
|
+
export interface AssemblyInstance {
|
|
11
|
+
instanceId: string;
|
|
12
|
+
bodyId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
translate: [number, number, number];
|
|
15
|
+
rotate: [number, number, number];
|
|
16
|
+
}
|
|
17
|
+
/** One projected hidden-line drawing view (flat [x,y, x,y, …] polylines, mm). */
|
|
18
|
+
export interface DrawingView {
|
|
19
|
+
name: string;
|
|
20
|
+
visible: number[][];
|
|
21
|
+
hidden: number[][];
|
|
22
|
+
}
|
|
23
|
+
export interface OpResult {
|
|
24
|
+
bodyId?: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
removed?: string[];
|
|
27
|
+
edges?: number;
|
|
28
|
+
mesh?: WorkerMesh;
|
|
29
|
+
meshes?: Array<WorkerMesh & {
|
|
30
|
+
bodyId: string;
|
|
31
|
+
}>;
|
|
32
|
+
bytes?: ArrayBuffer;
|
|
33
|
+
volume?: number;
|
|
34
|
+
/** Center of mass [x,y,z] (occt.ts backend). */
|
|
35
|
+
centroid?: number[];
|
|
36
|
+
deleted?: string;
|
|
37
|
+
cleared?: boolean;
|
|
38
|
+
views?: DrawingView[];
|
|
39
|
+
instanceId?: string;
|
|
40
|
+
instances?: AssemblyInstance[];
|
|
41
|
+
/** Pattern op: the newly created copy bodies with their meshes. */
|
|
42
|
+
created?: Array<{
|
|
43
|
+
bodyId: string;
|
|
44
|
+
name?: string;
|
|
45
|
+
mesh?: WorkerMesh;
|
|
46
|
+
}>;
|
|
47
|
+
/** Name of the sketch touched by a sketch op. */
|
|
48
|
+
sketch?: string;
|
|
49
|
+
/** Flat [x,y,z,…] display polyline of the sketch (sketch_set; occt.ts backend). */
|
|
50
|
+
wire?: number[];
|
|
51
|
+
/** Flat [x,y,z,…] TRUE vertex points of the sketch (corners/ends; circles carry none). */
|
|
52
|
+
points?: number[];
|
|
53
|
+
/** Triangulated enclosed region { positions, indices } (the translucent fill). */
|
|
54
|
+
fill?: {
|
|
55
|
+
positions: number[];
|
|
56
|
+
indices: number[];
|
|
57
|
+
};
|
|
58
|
+
/** import_step structure probe: unique parts + placed leaves (no geometry). */
|
|
59
|
+
stepStructure?: {
|
|
60
|
+
parts: Array<{
|
|
61
|
+
name: string;
|
|
62
|
+
key: string;
|
|
63
|
+
}>;
|
|
64
|
+
leaves: Array<{
|
|
65
|
+
part: number;
|
|
66
|
+
name: string;
|
|
67
|
+
translate: [number, number, number];
|
|
68
|
+
rotate: [number, number, number];
|
|
69
|
+
}>;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export interface DrawingViewSpec {
|
|
73
|
+
name: string;
|
|
74
|
+
dir: [number, number, number];
|
|
75
|
+
xDir: [number, number, number];
|
|
76
|
+
}
|
|
77
|
+
/** One loft section: a flat world-space loop, or a curve/profile section. */
|
|
78
|
+
export type LoftSection = number[] | {
|
|
79
|
+
/** Flat [x,y,z, …] loop (polygon, or a smooth B-spline when `smooth`). */
|
|
80
|
+
points?: number[];
|
|
81
|
+
/** Flat [x,y,z, …] points interpolated by a closed B-spline. */
|
|
82
|
+
through?: number[];
|
|
83
|
+
/** 2D profile (flat [x,y,…], {start,segments}, or {circle}) in the section plane. */
|
|
84
|
+
profile?: unknown;
|
|
85
|
+
/** Plane origin for `profile` (default world origin). */
|
|
86
|
+
at?: [number, number, number];
|
|
87
|
+
/** Plane normal for `profile` (default +Z). */
|
|
88
|
+
normal?: [number, number, number];
|
|
89
|
+
/** In-plane X axis for `profile` (default world +X projected). */
|
|
90
|
+
xAxis?: [number, number, number];
|
|
91
|
+
/** Override the loft-level `smooth` flag for this section. */
|
|
92
|
+
smooth?: boolean;
|
|
93
|
+
};
|
|
94
|
+
export type ModelOp = {
|
|
95
|
+
kind: 'create_prim';
|
|
96
|
+
bodyId: string;
|
|
97
|
+
prim: string;
|
|
98
|
+
params?: Record<string, unknown>;
|
|
99
|
+
name?: string;
|
|
100
|
+
} | {
|
|
101
|
+
kind: 'extrude_profile';
|
|
102
|
+
bodyId: string;
|
|
103
|
+
points?: number[];
|
|
104
|
+
profile?: unknown;
|
|
105
|
+
sketch?: string;
|
|
106
|
+
height?: number;
|
|
107
|
+
base?: number;
|
|
108
|
+
name?: string;
|
|
109
|
+
} | {
|
|
110
|
+
kind: 'loft';
|
|
111
|
+
bodyId: string;
|
|
112
|
+
sections: LoftSection[];
|
|
113
|
+
solid?: boolean;
|
|
114
|
+
ruled?: boolean;
|
|
115
|
+
smooth?: boolean;
|
|
116
|
+
name?: string;
|
|
117
|
+
} | {
|
|
118
|
+
kind: 'revolve';
|
|
119
|
+
bodyId: string;
|
|
120
|
+
profile?: unknown;
|
|
121
|
+
sketch?: string;
|
|
122
|
+
angle?: number;
|
|
123
|
+
axis?: [number, number, number];
|
|
124
|
+
at?: [number, number, number];
|
|
125
|
+
name?: string;
|
|
126
|
+
} | {
|
|
127
|
+
kind: 'chamfer';
|
|
128
|
+
target: string;
|
|
129
|
+
distance: number;
|
|
130
|
+
} | {
|
|
131
|
+
kind: 'shell';
|
|
132
|
+
target: string;
|
|
133
|
+
thickness: number;
|
|
134
|
+
openNormals?: Array<[number, number, number]>;
|
|
135
|
+
faces?: number[];
|
|
136
|
+
} | {
|
|
137
|
+
kind: 'draft';
|
|
138
|
+
target: string;
|
|
139
|
+
angle: number;
|
|
140
|
+
direction?: [number, number, number];
|
|
141
|
+
faces?: number[];
|
|
142
|
+
} | {
|
|
143
|
+
kind: 'pattern';
|
|
144
|
+
target: string;
|
|
145
|
+
mode: 'linear' | 'circular';
|
|
146
|
+
count: number;
|
|
147
|
+
delta?: [number, number, number];
|
|
148
|
+
axis?: [number, number, number];
|
|
149
|
+
at?: [number, number, number];
|
|
150
|
+
angle?: number;
|
|
151
|
+
} | {
|
|
152
|
+
kind: 'sweep';
|
|
153
|
+
bodyId: string;
|
|
154
|
+
profile?: unknown;
|
|
155
|
+
sketch?: string;
|
|
156
|
+
path: number[];
|
|
157
|
+
name?: string;
|
|
158
|
+
} | {
|
|
159
|
+
kind: 'boolean';
|
|
160
|
+
op: 'fuse' | 'cut' | 'common';
|
|
161
|
+
target: string;
|
|
162
|
+
tools: string[];
|
|
163
|
+
} | {
|
|
164
|
+
kind: 'fillet';
|
|
165
|
+
target: string;
|
|
166
|
+
radius: number;
|
|
167
|
+
} | {
|
|
168
|
+
kind: 'transform';
|
|
169
|
+
target: string;
|
|
170
|
+
translate?: [number, number, number];
|
|
171
|
+
rotate?: [number, number, number];
|
|
172
|
+
mirror?: [number, number, number];
|
|
173
|
+
} | {
|
|
174
|
+
kind: 'tessellate_all';
|
|
175
|
+
} | {
|
|
176
|
+
kind: 'export';
|
|
177
|
+
target: string;
|
|
178
|
+
format: 'step' | 'stl';
|
|
179
|
+
} | {
|
|
180
|
+
kind: 'volume';
|
|
181
|
+
target: string;
|
|
182
|
+
} | {
|
|
183
|
+
kind: 'delete';
|
|
184
|
+
target: string;
|
|
185
|
+
} | {
|
|
186
|
+
kind: 'reset';
|
|
187
|
+
} | {
|
|
188
|
+
kind: 'drawing';
|
|
189
|
+
target: string;
|
|
190
|
+
views: DrawingViewSpec[];
|
|
191
|
+
sceneViewId?: string;
|
|
192
|
+
name?: string;
|
|
193
|
+
paper?: 'A4' | 'A3';
|
|
194
|
+
} | {
|
|
195
|
+
kind: 'assembly_insert';
|
|
196
|
+
instanceId: string;
|
|
197
|
+
bodyId: string;
|
|
198
|
+
name?: string;
|
|
199
|
+
translate?: [number, number, number];
|
|
200
|
+
rotate?: [number, number, number];
|
|
201
|
+
} | {
|
|
202
|
+
kind: 'assembly_transform';
|
|
203
|
+
instanceId: string;
|
|
204
|
+
translate?: [number, number, number];
|
|
205
|
+
rotate?: [number, number, number];
|
|
206
|
+
} | {
|
|
207
|
+
kind: 'assembly_remove';
|
|
208
|
+
instanceId: string;
|
|
209
|
+
} | {
|
|
210
|
+
kind: 'assembly_list';
|
|
211
|
+
} | {
|
|
212
|
+
kind: 'assembly_joint';
|
|
213
|
+
instanceId: string;
|
|
214
|
+
label: string;
|
|
215
|
+
/** Normalized JointSpec (validated on the main thread before posting). */
|
|
216
|
+
joint: unknown;
|
|
217
|
+
} | {
|
|
218
|
+
kind: 'assembly_connect';
|
|
219
|
+
/** The child instance being placed. */
|
|
220
|
+
instanceId: string;
|
|
221
|
+
parent: string;
|
|
222
|
+
parentLabel: string;
|
|
223
|
+
childLabel: string;
|
|
224
|
+
/** Merged into the parent joint's value at connect time (optional). */
|
|
225
|
+
value?: unknown;
|
|
226
|
+
} | {
|
|
227
|
+
kind: 'assembly_joint_value';
|
|
228
|
+
instanceId: string;
|
|
229
|
+
label: string;
|
|
230
|
+
value: unknown;
|
|
231
|
+
} | {
|
|
232
|
+
kind: 'assembly_explode';
|
|
233
|
+
factor: number;
|
|
234
|
+
} | {
|
|
235
|
+
kind: 'import_step';
|
|
236
|
+
/** Sidecar asset path (workspace .dsh-cad/docs/assets/<hash>.step). */
|
|
237
|
+
path: string;
|
|
238
|
+
/** Assignments for the materialize phase (absent = structure probe). */
|
|
239
|
+
bodies?: Array<{
|
|
240
|
+
bodyId: string;
|
|
241
|
+
name: string;
|
|
242
|
+
}>;
|
|
243
|
+
instances?: Array<{
|
|
244
|
+
instanceId: string;
|
|
245
|
+
bodyId: string;
|
|
246
|
+
name: string;
|
|
247
|
+
translate: [number, number, number];
|
|
248
|
+
rotate: [number, number, number];
|
|
249
|
+
}>;
|
|
250
|
+
} | {
|
|
251
|
+
kind: 'constraints';
|
|
252
|
+
model: {
|
|
253
|
+
entities: unknown[];
|
|
254
|
+
constraints: unknown[];
|
|
255
|
+
};
|
|
256
|
+
} | {
|
|
257
|
+
kind: 'export_assembly';
|
|
258
|
+
format: 'step' | 'stl';
|
|
259
|
+
} | {
|
|
260
|
+
kind: 'sketch_set';
|
|
261
|
+
name: string;
|
|
262
|
+
profile: unknown;
|
|
263
|
+
} | {
|
|
264
|
+
kind: 'sketch_delete';
|
|
265
|
+
name: string;
|
|
266
|
+
};
|
|
267
|
+
export interface ModelClient {
|
|
268
|
+
/** Run one modeling operation on this client's worker. */
|
|
269
|
+
run(op: ModelOp, timeoutMs?: number): Promise<OpResult>;
|
|
270
|
+
/** Terminate the worker and fail any in-flight jobs. */
|
|
271
|
+
dispose(): void;
|
|
272
|
+
}
|
|
273
|
+
export declare function createModelClient(): ModelClient;
|
|
274
|
+
/** Run one modeling operation on the shared session worker. */
|
|
275
|
+
export declare function runModelOp(op: ModelOp, timeoutMs?: number): Promise<OpResult>;
|
|
276
|
+
/** Current reset epoch of the shared worker (see above). */
|
|
277
|
+
export declare function workerResetEpoch(): number;
|
|
278
|
+
/** Test/Dev helper: hard worker file path (used by the vitest suite). */
|
|
279
|
+
export declare function workerEntryPath(): string;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Joint algebra for the assembly (main thread, pure math — kernel-independent).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors cadorange 0.10.0's runtime assembly model (build123d joint family)
|
|
5
|
+
* in dsh-cad's placement convention: flat world-placed instances with
|
|
6
|
+
* translate + XYZ-Euler rotate (degrees, p' = T + Rx·(Ry·(Rz·p))). Joints are
|
|
7
|
+
* placement data — a frame in the owner's LOCAL coordinates plus a motion
|
|
8
|
+
* value; connecting pairs solves the child's world placement:
|
|
9
|
+
*
|
|
10
|
+
* ```text
|
|
11
|
+
* childWorld = parentWorld ∘ Fp ∘ Mp(valueP) ∘ Mc(valueC) ∘ Fc⁻¹
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* `connect` is a one-time solve (the tool layer writes the result back through
|
|
15
|
+
* an `assembly_transform` op, so the op log replays without this module);
|
|
16
|
+
* driving a joint value or re-solving replays every recorded connection at
|
|
17
|
+
* current values — the motion-study path. The worker never computes any of
|
|
18
|
+
* this: joint specs and connections are persisted as ops and folded here.
|
|
19
|
+
*/
|
|
20
|
+
import type { AssemblyInstance } from './client.js';
|
|
21
|
+
import type { BinMeshData } from './bin-format.js';
|
|
22
|
+
export type JointType = 'rigid' | 'revolute' | 'linear' | 'cylindrical' | 'ball' | 'planar' | 'polar';
|
|
23
|
+
export declare const JOINT_TYPES: readonly JointType[];
|
|
24
|
+
/**
|
|
25
|
+
* A joint definition persisted in the op log. The frame (`at` + `axis`/`xDir`)
|
|
26
|
+
* lives in the OWNER instance's local coordinates; `value` is the joint's
|
|
27
|
+
* current motion (a bare number drives single-DOF joints).
|
|
28
|
+
*/
|
|
29
|
+
export interface JointSpec {
|
|
30
|
+
type: JointType;
|
|
31
|
+
/** Frame origin in the owner's local coordinates (mm). */
|
|
32
|
+
at?: [number, number, number];
|
|
33
|
+
/** Joint axis / frame Z (default +Z). */
|
|
34
|
+
axis?: [number, number, number];
|
|
35
|
+
/** Pins the zero-position orientation (the frame's local X). */
|
|
36
|
+
xDir?: [number, number, number];
|
|
37
|
+
value?: JointValue;
|
|
38
|
+
angularRange?: [number, number];
|
|
39
|
+
linearRange?: [number, number];
|
|
40
|
+
}
|
|
41
|
+
export type JointValue = number | {
|
|
42
|
+
angle?: number;
|
|
43
|
+
linear?: number;
|
|
44
|
+
radial?: number;
|
|
45
|
+
position?: [number, number];
|
|
46
|
+
angles?: [number, number, number];
|
|
47
|
+
};
|
|
48
|
+
/** One recorded joint pairing (child placed against parent). */
|
|
49
|
+
export interface AssemblyConnection {
|
|
50
|
+
/** The child instance that was placed. */
|
|
51
|
+
child: string;
|
|
52
|
+
/** The parent (fixed side) instance. */
|
|
53
|
+
parent: string;
|
|
54
|
+
parentLabel: string;
|
|
55
|
+
childLabel: string;
|
|
56
|
+
}
|
|
57
|
+
type Vec3 = [number, number, number];
|
|
58
|
+
/** Rigid transform as a row-major 3×3 rotation + translation. */
|
|
59
|
+
export interface RigidMat {
|
|
60
|
+
/** Row-major [r00,r01,r02, r10,r11,r12, r20,r21,r22]. */
|
|
61
|
+
r: readonly number[];
|
|
62
|
+
t: Vec3;
|
|
63
|
+
}
|
|
64
|
+
/** Row-major rotation of XYZ Euler degrees — Rx·Ry·Rz (cad_transform). */
|
|
65
|
+
export declare function eulerMatrix(rotate: Vec3): number[];
|
|
66
|
+
/** Euler degrees back out of a row-major Rx·Ry·Rz rotation (gimbal at ±90° ry). */
|
|
67
|
+
export declare function matrixEuler(r: readonly number[]): Vec3;
|
|
68
|
+
/** a ∘ b — apply b first, then a. */
|
|
69
|
+
export declare function composeMat(a: RigidMat, b: RigidMat): RigidMat;
|
|
70
|
+
export declare function invertMat(a: RigidMat): RigidMat;
|
|
71
|
+
export interface Placement {
|
|
72
|
+
translate: Vec3;
|
|
73
|
+
rotate: Vec3;
|
|
74
|
+
}
|
|
75
|
+
export declare function placementMat(p: Placement): RigidMat;
|
|
76
|
+
export declare function matPlacement(m: RigidMat): Placement;
|
|
77
|
+
/**
|
|
78
|
+
* The joint's frame in the owner's local coordinates: local X → xDir (or the
|
|
79
|
+
* deterministic fallback), local Z → axis, origin → at. Columns are the frame
|
|
80
|
+
* axes, so frameMat maps joint-local coordinates onto owner-local ones.
|
|
81
|
+
*/
|
|
82
|
+
export declare function jointFrameMat(spec: JointSpec): RigidMat;
|
|
83
|
+
/** The joint's motion at its current value, in joint-local coordinates. */
|
|
84
|
+
export declare function jointMotionMat(spec: JointSpec): RigidMat;
|
|
85
|
+
/** The spec's value as an object (a bare number routed per type). */
|
|
86
|
+
export declare function valueOf(spec: JointSpec): Exclude<JointValue, number>;
|
|
87
|
+
/** Validate + normalize a raw cad_assembly_joint payload into a JointSpec. */
|
|
88
|
+
export declare function normalizeJointSpec(raw: unknown, where: string): JointSpec;
|
|
89
|
+
/**
|
|
90
|
+
* Merge a motion value into a spec (driving a joint): object values overlay
|
|
91
|
+
* their keys onto the current value, a bare number replaces the single DOF.
|
|
92
|
+
*/
|
|
93
|
+
export declare function mergeJointValue(spec: JointSpec, value: JointValue, where: string): JointSpec;
|
|
94
|
+
/** Check a parent↔child pairing (build123d's table). */
|
|
95
|
+
export declare function checkPairing(parentType: JointType, childType: JointType, where: string): void;
|
|
96
|
+
/**
|
|
97
|
+
* Merge a connect-time value into the pairing (build123d semantics): the
|
|
98
|
+
* value drives the PARENT joint — except a linear→revolute pair, where
|
|
99
|
+
* `angle` routes to the child revolute and the rest goes to the parent.
|
|
100
|
+
*/
|
|
101
|
+
export declare function applyConnectValue(parentSpec: JointSpec, childSpec: JointSpec, value: JointValue, where: string): {
|
|
102
|
+
parent: JointSpec;
|
|
103
|
+
child: JointSpec;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Solve the child's world placement so the two joint frames coincide (with
|
|
107
|
+
* both motions applied) — cadorange's `connectTo` in the flat world-placed
|
|
108
|
+
* model. The parent stays fixed; the child is repositioned.
|
|
109
|
+
*/
|
|
110
|
+
export declare function solveConnection(parent: Placement, parentSpec: JointSpec, childSpec: JointSpec): Placement;
|
|
111
|
+
/**
|
|
112
|
+
* Replay every connection at the joints' CURRENT values (recorded order — a
|
|
113
|
+
* connection whose parent was itself placed by an earlier connection chains
|
|
114
|
+
* through its fresh placement). Returns the solved placement per child.
|
|
115
|
+
*/
|
|
116
|
+
export declare function solveConnections(instances: AssemblyInstance[], joints: ReadonlyMap<string, Readonly<Record<string, JointSpec>>>, connections: readonly AssemblyConnection[]): Map<string, Placement>;
|
|
117
|
+
/**
|
|
118
|
+
* Exploded-view offsets per instance (cadorange's `explode` in the flat
|
|
119
|
+
* model): every instance is pushed radially away from the assembly's world
|
|
120
|
+
* bbox center — direction = instance world center − assembly center,
|
|
121
|
+
* magnitude = factor × that distance. Returns instanceId → world offset
|
|
122
|
+
* (empty when factor is 0 or no two centers differ).
|
|
123
|
+
*/
|
|
124
|
+
export declare function explodeOffsets(bodies: ReadonlyMap<string, BinMeshData>, instances: readonly AssemblyInstance[], factor: number): Map<string, Vec3>;
|
|
125
|
+
/** Human value text ("30°", "12mm", "30° · 5mm") — for tool renders and the panel. */
|
|
126
|
+
export declare function jointValueText(spec: JointSpec): string;
|
|
127
|
+
/** Chinese labels for the joint kinds (panel display). */
|
|
128
|
+
export declare const JOINT_TYPE_ZH: Record<JointType, string>;
|
|
129
|
+
export {};
|