@classcad/client 0.0.0-stage → 3.0.0-beta.20261119100608
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 +20 -2
- package/bin/buerli-classcad.cjs +23 -0
- package/build/cjs/BuerliCadFacade.js +718 -0
- package/build/cjs/cclass/utils/assembly.js +687 -0
- package/build/cjs/cclass/utils/base.js +136 -0
- package/build/cjs/cclass/utils/index.js +99 -0
- package/build/cjs/cclass/utils/part.js +153 -0
- package/build/cjs/classcadEngine.js +33 -0
- package/build/cjs/createApi.js +71 -0
- package/build/cjs/createUnwrappedApi.js +43 -0
- package/build/cjs/facade.js +103 -0
- package/build/cjs/globals.js +157 -0
- package/build/cjs/index.js +102 -0
- package/build/cjs/io/AwvNodeClient.js +290 -0
- package/build/cjs/io/SocketIOClient.js +339 -0
- package/build/cjs/io/Transaction.js +134 -0
- package/build/cjs/io/WASMClient.js +433 -0
- package/build/cjs/io/WSClient.js +646 -0
- package/build/cjs/io/engineKey.js +202 -0
- package/build/cjs/re-export.js +35 -0
- package/build/cjs/session/host.js +479 -0
- package/build/cjs/session/identity.js +38 -0
- package/build/cjs/session/selection.js +283 -0
- package/build/cjs/session/share.js +229 -0
- package/build/cjs/session/types.js +23 -0
- package/build/cjs/test/SocketIOClient.spec.js +178 -0
- package/build/cjs/types/ComClient.js +10 -0
- package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
- package/build/cjs/utils/createRecursiveScene.js +140 -0
- package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
- package/build/cjs/utils/index.js +20 -0
- package/build/cjs/utils/polyline.js +65 -0
- package/build/cjs/utils/waitForSelect.js +29 -0
- package/build/esm/BuerliCadFacade.js +714 -0
- package/build/esm/cclass/utils/assembly.js +665 -0
- package/build/esm/cclass/utils/base.js +127 -0
- package/build/esm/cclass/utils/index.js +62 -0
- package/build/esm/cclass/utils/part.js +144 -0
- package/build/esm/classcadEngine.js +30 -0
- package/build/esm/createApi.js +66 -0
- package/build/esm/createUnwrappedApi.js +39 -0
- package/build/esm/facade.js +98 -0
- package/build/esm/globals.js +150 -0
- package/build/esm/index.js +80 -0
- package/build/esm/io/AwvNodeClient.js +286 -0
- package/build/esm/io/SocketIOClient.js +332 -0
- package/build/esm/io/Transaction.js +130 -0
- package/build/esm/io/WASMClient.js +429 -0
- package/build/esm/io/WSClient.js +642 -0
- package/build/esm/io/engineKey.js +196 -0
- package/build/esm/re-export.js +3 -0
- package/build/esm/session/host.js +474 -0
- package/build/esm/session/identity.js +34 -0
- package/build/esm/session/selection.js +277 -0
- package/build/esm/session/share.js +221 -0
- package/build/esm/session/types.js +20 -0
- package/build/esm/test/SocketIOClient.spec.js +178 -0
- package/build/esm/types/ComClient.js +7 -0
- package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
- package/build/esm/utils/createRecursiveScene.js +136 -0
- package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
- package/build/esm/utils/index.js +4 -0
- package/build/esm/utils/polyline.js +60 -0
- package/build/esm/utils/waitForSelect.js +23 -0
- package/build/types/BuerliCadFacade.d.ts +410 -0
- package/build/types/cclass/utils/assembly.d.ts +180 -0
- package/build/types/cclass/utils/base.d.ts +55 -0
- package/build/types/cclass/utils/index.d.ts +46 -0
- package/build/types/cclass/utils/part.d.ts +46 -0
- package/build/types/classcadEngine.d.ts +40 -0
- package/build/types/createApi.d.ts +65 -0
- package/build/types/createUnwrappedApi.d.ts +36 -0
- package/build/types/facade.d.ts +9 -0
- package/build/types/globals.d.ts +79 -0
- package/build/types/index.d.ts +82 -0
- package/build/types/io/AwvNodeClient.d.ts +182 -0
- package/build/types/io/SocketIOClient.d.ts +84 -0
- package/build/types/io/Transaction.d.ts +56 -0
- package/build/types/io/WASMClient.d.ts +239 -0
- package/build/types/io/WSClient.d.ts +242 -0
- package/build/types/io/engineKey.d.ts +137 -0
- package/build/types/re-export.d.ts +6 -0
- package/build/types/session/host.d.ts +108 -0
- package/build/types/session/identity.d.ts +46 -0
- package/build/types/session/selection.d.ts +164 -0
- package/build/types/session/share.d.ts +131 -0
- package/build/types/session/types.d.ts +113 -0
- package/build/types/test/SocketIOClient.spec.d.ts +0 -0
- package/build/types/types/ComClient.d.ts +307 -0
- package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
- package/build/types/utils/createRecursiveScene.d.ts +24 -0
- package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
- package/build/types/utils/index.d.ts +4 -0
- package/build/types/utils/polyline.d.ts +43 -0
- package/build/types/utils/waitForSelect.d.ts +4 -0
- package/doc/api/advanced/connection.md +488 -0
- package/doc/api/clients.md +2045 -0
- package/doc/api/engine-keys.md +230 -0
- package/doc/api/index.md +58 -0
- package/doc/api/modeling.md +682 -0
- package/doc/api/other.md +33 -0
- package/doc/api/session-sharing.md +706 -0
- package/package.json +60 -4
- package/test/classcadEngine.test.cjs +44 -0
- package/test/connect.test.cjs +81 -0
- package/test/engineKey.test.cjs +80 -0
- package/test/onClient.test.cjs +82 -0
- package/typedoc.json +8 -0
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
# Modeling
|
|
2
|
+
|
|
3
|
+
`BuerliCadFacade` connects a drawing, runs the ClassCAD API on it (`api.v1.*`) and turns the model into three.js
|
|
4
|
+
geometry.
|
|
5
|
+
|
|
6
|
+
## Classes
|
|
7
|
+
|
|
8
|
+
### BuerliCadFacade {#buerlicadfacade}
|
|
9
|
+
|
|
10
|
+
A drawing connected to ClassCAD: its API, and helpers that turn the model into three.js objects.
|
|
11
|
+
|
|
12
|
+
`connect()` creates a drawing in the SDK's store and connects it with a client from the factory given to
|
|
13
|
+
[init](clients.md#init). Then `api` is the drawing's ClassCAD API, unwrapped: `await api.v1.part.create(…)` resolves to the
|
|
14
|
+
new part's id and rejects when the engine reports an error; warnings are logged. `createBufferGeometry` and
|
|
15
|
+
`createScene` make three.js geometry of what was built, `tree` and `graphic` read the drawing as the store holds
|
|
16
|
+
it. The static `utils` do the facade's work for any drawing, by its id.
|
|
17
|
+
|
|
18
|
+
#### Example
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
import * as THREE from 'three'
|
|
22
|
+
import { init, BuerliCadFacade, WASMClient } from '@classcad/client'
|
|
23
|
+
|
|
24
|
+
init(drawingId => new WASMClient(drawingId, { token: 'ccpk_…' }))
|
|
25
|
+
|
|
26
|
+
// A parametric flange: one facade per drawing
|
|
27
|
+
export async function flange(diameter: number, thickness: number) {
|
|
28
|
+
const facade = new BuerliCadFacade()
|
|
29
|
+
await facade.connect('Flange')
|
|
30
|
+
const { part } = facade.api.v1
|
|
31
|
+
const flange = (await part.create({ name: 'Flange' }))!
|
|
32
|
+
await part.cylinder({ id: flange, diameter, height: thickness })
|
|
33
|
+
const geometries = (await facade.createBufferGeometry(flange)) ?? []
|
|
34
|
+
const meshes = geometries.map(geometry => new THREE.Mesh(geometry, new THREE.MeshStandardMaterial()))
|
|
35
|
+
// Done with it: the drawing leaves the store
|
|
36
|
+
await facade.destroy()
|
|
37
|
+
return meshes
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
#### Accessors
|
|
42
|
+
|
|
43
|
+
##### api {#api}
|
|
44
|
+
|
|
45
|
+
###### Get Signature
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
get api(): UnwrappedApiType;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The drawing's ClassCAD API ([ClassCADApi](#classcadapi)): calls resolve to their result and reject on an error.
|
|
52
|
+
Throws before `connect()` and after `disconnect()`.
|
|
53
|
+
|
|
54
|
+
###### Returns
|
|
55
|
+
|
|
56
|
+
`UnwrappedApiType`
|
|
57
|
+
|
|
58
|
+
##### drawingId {#drawingid}
|
|
59
|
+
|
|
60
|
+
###### Get Signature
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
get drawingId(): DrawingID;
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
The id of the drawing the facade connected. Throws before `connect()`.
|
|
67
|
+
|
|
68
|
+
###### Returns
|
|
69
|
+
|
|
70
|
+
`DrawingID`
|
|
71
|
+
|
|
72
|
+
#### Constructors
|
|
73
|
+
|
|
74
|
+
##### Constructor
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
new BuerliCadFacade(): BuerliCadFacade;
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
###### Returns
|
|
81
|
+
|
|
82
|
+
[`BuerliCadFacade`](#buerlicadfacade)
|
|
83
|
+
|
|
84
|
+
#### Methods
|
|
85
|
+
|
|
86
|
+
##### connect() {#connect}
|
|
87
|
+
|
|
88
|
+
```ts
|
|
89
|
+
connect(drawingName?): Promise<DrawingID>;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Creates a drawing, connects it to ClassCAD with a client from the factory given to [init](clients.md#init), and makes its
|
|
93
|
+
`api` available.
|
|
94
|
+
|
|
95
|
+
Rejects when the facade is connected already, when `init` has not been called, and when connecting fails: then
|
|
96
|
+
with the error that kept the client from connecting (a token the key service refuses, an engine that cannot be
|
|
97
|
+
reached), and the drawing it made is removed again.
|
|
98
|
+
|
|
99
|
+
###### Parameters
|
|
100
|
+
|
|
101
|
+
| Parameter | Type | Description |
|
|
102
|
+
| :------ | :------ | :------ |
|
|
103
|
+
| `drawingName?` | `string` | The drawing's name in the store; by default `Drawing #<n>`. |
|
|
104
|
+
|
|
105
|
+
###### Returns
|
|
106
|
+
|
|
107
|
+
`Promise`<`DrawingID`>
|
|
108
|
+
|
|
109
|
+
The id of the new drawing.
|
|
110
|
+
|
|
111
|
+
##### createBufferGeometry() {#createbuffergeometry}
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
createBufferGeometry(objectId?): Promise<
|
|
115
|
+
| BufferGeometry<NormalBufferAttributes, BufferGeometryEventMap>[]
|
|
116
|
+
| undefined>;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Creates the buffer geometry of any product (part or assembly).
|
|
120
|
+
|
|
121
|
+
Each part, and each instance of a part in an assembly, becomes one geometry: its bodies merged, placed where it
|
|
122
|
+
is in the model. Bodies the store has no graphic for yet are requested from ClassCAD first. Rejects when an id is
|
|
123
|
+
not in the drawing's tree.
|
|
124
|
+
|
|
125
|
+
###### Parameters
|
|
126
|
+
|
|
127
|
+
| Parameter | Type | Description |
|
|
128
|
+
| :------ | :------ | :------ |
|
|
129
|
+
| `objectId?` | `number` \| `number`[] | The product, its instance or a solid; or several of them. |
|
|
130
|
+
|
|
131
|
+
###### Returns
|
|
132
|
+
|
|
133
|
+
`Promise`<
|
|
134
|
+
\| `BufferGeometry`<`NormalBufferAttributes`, `BufferGeometryEventMap`>[]
|
|
135
|
+
\| `undefined`>
|
|
136
|
+
|
|
137
|
+
The geometries, or undefined when there is no id or nothing to show.
|
|
138
|
+
|
|
139
|
+
###### Example
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import * as THREE from 'three'
|
|
143
|
+
|
|
144
|
+
// A cylinder with diameter 20 and height 30, as a mesh of one's own
|
|
145
|
+
const part = (await facade.api.v1.part.create({ name: 'Pin' }))!
|
|
146
|
+
await facade.api.v1.part.cylinder({ id: part, diameter: 20, height: 30 })
|
|
147
|
+
const [geometry] = (await facade.createBufferGeometry(part)) ?? []
|
|
148
|
+
if (geometry) scene.add(new THREE.Mesh(geometry, new THREE.MeshStandardMaterial({ color: 'orange' })))
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
##### createPolyline() {#createpolyline}
|
|
152
|
+
|
|
153
|
+
```ts
|
|
154
|
+
createPolyline(
|
|
155
|
+
owner,
|
|
156
|
+
fPts,
|
|
157
|
+
close?
|
|
158
|
+
): Promise<void>;
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Adds a polyline through the given points to a shape curve of the model, its corners rounded where a radius is
|
|
162
|
+
given (`v1.curve.polyline2d`).
|
|
163
|
+
|
|
164
|
+
A corner with a radius above 0 becomes an arc of that radius. A corner whose arc does not fit between its
|
|
165
|
+
neighbours is left out.
|
|
166
|
+
|
|
167
|
+
###### Parameters
|
|
168
|
+
|
|
169
|
+
| Parameter | Type | Default value | Description |
|
|
170
|
+
| :------ | :------ | :------ | :------ |
|
|
171
|
+
| `owner` | `number` | `undefined` | The shape curve, from `v1.curve.shape`. |
|
|
172
|
+
| `fPts` | \{ `point`: `Vector3`; `radius`: `number`; \}[] | `undefined` | The corners, each with the radius to round it with (0 for a sharp corner). |
|
|
173
|
+
| `close?` | `boolean` | `true` | Closes the polyline. Default `true`. |
|
|
174
|
+
|
|
175
|
+
###### Returns
|
|
176
|
+
|
|
177
|
+
`Promise`<`void`>
|
|
178
|
+
|
|
179
|
+
###### Example
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
import * as THREE from 'three'
|
|
183
|
+
|
|
184
|
+
// A plate with two rounded corners, extruded from a polyline
|
|
185
|
+
const part = (await facade.api.v1.part.create({ name: 'Plate' }))!
|
|
186
|
+
const ei = (await facade.api.v1.part.entityInjection({ id: part }))!
|
|
187
|
+
const curve = (await facade.api.v1.curve.shape({ id: ei }))!
|
|
188
|
+
await facade.createPolyline(curve, [
|
|
189
|
+
{ point: new THREE.Vector3(0, 0, 0), radius: 0 },
|
|
190
|
+
{ point: new THREE.Vector3(100, 0, 0), radius: 10 },
|
|
191
|
+
{ point: new THREE.Vector3(100, 50, 0), radius: 10 },
|
|
192
|
+
{ point: new THREE.Vector3(0, 50, 0), radius: 0 },
|
|
193
|
+
])
|
|
194
|
+
await facade.api.v1.solid.extrusion({ id: ei, curves: [curve], direction: [0, 0, 8] })
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
##### createScene() {#createscene}
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
createScene(objectId?, options?): Promise<{
|
|
201
|
+
materials: {
|
|
202
|
+
[key: string]: Material<MaterialEventMap>;
|
|
203
|
+
};
|
|
204
|
+
nodes: {
|
|
205
|
+
[key: string]: Object3D<Object3DEventMap>;
|
|
206
|
+
};
|
|
207
|
+
scene: Scene;
|
|
208
|
+
}>;
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Creates the threeJS scene of any product (part or assembly).
|
|
212
|
+
|
|
213
|
+
Assemblies and instances become groups placed as in the model, parts become groups of their bodies. A body is
|
|
214
|
+
one mesh per color (`meshPerGeometry: false`, default) or one mesh per face. Bodies the store has no graphic
|
|
215
|
+
for yet are requested from ClassCAD first. Rejects when an id is not in the drawing's tree.
|
|
216
|
+
|
|
217
|
+
###### Parameters
|
|
218
|
+
|
|
219
|
+
| Parameter | Type | Description |
|
|
220
|
+
| :------ | :------ | :------ |
|
|
221
|
+
| `objectId?` | `number` \| `number`[] | The product, its instance or a solid, or several of them; by default the drawing's root. |
|
|
222
|
+
| `options?` | \{ `meshPerGeometry?`: `boolean`; `structureOnly?`: `boolean`; \} | Options. |
|
|
223
|
+
| `options.meshPerGeometry?` | `boolean` | Makes a mesh for each face (its `userData.id` is the face's graphic id) instead of merging a body's faces of one color into one mesh. |
|
|
224
|
+
| `options.structureOnly?` | `boolean` | Makes the nodes without geometry and materials. |
|
|
225
|
+
|
|
226
|
+
###### Returns
|
|
227
|
+
|
|
228
|
+
`Promise`<\{
|
|
229
|
+
`materials`: \{
|
|
230
|
+
\[`key`: `string`\]: `Material`<`MaterialEventMap`>;
|
|
231
|
+
\};
|
|
232
|
+
`nodes`: \{
|
|
233
|
+
\[`key`: `string`\]: `Object3D`<`Object3DEventMap`>;
|
|
234
|
+
\};
|
|
235
|
+
`scene`: `Scene`;
|
|
236
|
+
\}>
|
|
237
|
+
|
|
238
|
+
The scene, its nodes and their materials.
|
|
239
|
+
|
|
240
|
+
###### Example
|
|
241
|
+
|
|
242
|
+
```ts
|
|
243
|
+
import * as THREE from 'three'
|
|
244
|
+
|
|
245
|
+
// The whole assembly in a three.js scene, a node per instance
|
|
246
|
+
const { scene: model, nodes } = await facade.createScene(assembly)
|
|
247
|
+
scene.add(model)
|
|
248
|
+
// The nodes by the id of the object they show, and by name
|
|
249
|
+
nodes[`${wheel}`].rotation.z = Math.PI / 4
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
##### createThreeShape() {#createthreeshape}
|
|
253
|
+
|
|
254
|
+
```ts
|
|
255
|
+
createThreeShape(owner, shape): Promise<void>;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
Adds the curves of a three.js `Shape` to a shape curve of the model, in one batch of API calls.
|
|
259
|
+
|
|
260
|
+
Lines, arcs and ellipses, quadratic and cubic Bézier curves and splines (as interpolation curves) are added, in
|
|
261
|
+
the XY plane; other curves and the shape's holes are not.
|
|
262
|
+
|
|
263
|
+
###### Parameters
|
|
264
|
+
|
|
265
|
+
| Parameter | Type | Description |
|
|
266
|
+
| :------ | :------ | :------ |
|
|
267
|
+
| `owner` | `number` | The shape curve, from `v1.curve.shape`. |
|
|
268
|
+
| `shape` | `Shape` | The outline. |
|
|
269
|
+
|
|
270
|
+
###### Returns
|
|
271
|
+
|
|
272
|
+
`Promise`<`void`>
|
|
273
|
+
|
|
274
|
+
###### Example
|
|
275
|
+
|
|
276
|
+
```ts
|
|
277
|
+
import * as THREE from 'three'
|
|
278
|
+
|
|
279
|
+
// A disc, extruded from a three.js outline
|
|
280
|
+
const part = (await facade.api.v1.part.create({ name: 'Disc' }))!
|
|
281
|
+
const ei = (await facade.api.v1.part.entityInjection({ id: part }))!
|
|
282
|
+
const outline = new THREE.Shape()
|
|
283
|
+
outline.absarc(0, 0, 40, 0, Math.PI * 2, false)
|
|
284
|
+
const curve = (await facade.api.v1.curve.shape({ id: ei }))!
|
|
285
|
+
await facade.createThreeShape(curve, outline)
|
|
286
|
+
await facade.api.v1.solid.extrusion({ id: ei, curves: [curve], direction: [0, 0, 5] })
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
##### destroy() {#destroy}
|
|
290
|
+
|
|
291
|
+
```ts
|
|
292
|
+
destroy(): Promise<void>;
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
Disconnects from ClassCAD and removes the drawing from the SDK's store. The facade can `connect()` again.
|
|
296
|
+
|
|
297
|
+
A failing disconnect does not keep the drawing from being removed.
|
|
298
|
+
|
|
299
|
+
###### Returns
|
|
300
|
+
|
|
301
|
+
`Promise`<`void`>
|
|
302
|
+
|
|
303
|
+
##### disconnect() {#disconnect}
|
|
304
|
+
|
|
305
|
+
```ts
|
|
306
|
+
disconnect(): Promise<void>;
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
Disconnects from ClassCAD. The drawing stays in the SDK's store, reset (without its model), and keeps its
|
|
310
|
+
client; `api` is not available until [BuerliCadFacade.reconnect](#reconnect).
|
|
311
|
+
|
|
312
|
+
###### Returns
|
|
313
|
+
|
|
314
|
+
`Promise`<`void`>
|
|
315
|
+
|
|
316
|
+
##### graphic() {#graphic}
|
|
317
|
+
|
|
318
|
+
```ts
|
|
319
|
+
graphic(opts?): Promise<
|
|
320
|
+
| {
|
|
321
|
+
containers: ScgGraphicContainer[];
|
|
322
|
+
}
|
|
323
|
+
| null>;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
The current graphic (tessellation) of the drawing as `{ containers }`, as
|
|
327
|
+
held by the SDK's store. Pass `recalc: true` to recalculate first.
|
|
328
|
+
|
|
329
|
+
Note that graphic element ids are payload-local - they rotate on every
|
|
330
|
+
re-tessellation. The stable join between graphic and structure tree is
|
|
331
|
+
`container.owner === <CC_Solid id>`.
|
|
332
|
+
|
|
333
|
+
###### Parameters
|
|
334
|
+
|
|
335
|
+
| Parameter | Type | Description |
|
|
336
|
+
| :------ | :------ | :------ |
|
|
337
|
+
| `opts?` | \{ `recalc?`: `boolean`; \} | Options. |
|
|
338
|
+
| `opts.recalc?` | `boolean` | Recalculates the model before reading the graphic. |
|
|
339
|
+
|
|
340
|
+
###### Returns
|
|
341
|
+
|
|
342
|
+
`Promise`<
|
|
343
|
+
\| \{
|
|
344
|
+
`containers`: `ScgGraphicContainer`[];
|
|
345
|
+
\}
|
|
346
|
+
\| `null`>
|
|
347
|
+
|
|
348
|
+
The graphic containers, or `null` if the drawing is not available.
|
|
349
|
+
|
|
350
|
+
###### Example
|
|
351
|
+
|
|
352
|
+
```ts
|
|
353
|
+
import * as THREE from 'three'
|
|
354
|
+
|
|
355
|
+
// Frames the camera on the model: the bounds of every body
|
|
356
|
+
const graphic = await facade.graphic()
|
|
357
|
+
const bounds = new THREE.Box3()
|
|
358
|
+
for (const container of graphic?.containers ?? []) {
|
|
359
|
+
if (!container.meshes?.length) continue
|
|
360
|
+
bounds.expandByPoint(new THREE.Vector3().fromArray(container.properties.min))
|
|
361
|
+
bounds.expandByPoint(new THREE.Vector3().fromArray(container.properties.max))
|
|
362
|
+
}
|
|
363
|
+
const center = bounds.getCenter(new THREE.Vector3())
|
|
364
|
+
const size = bounds.getSize(new THREE.Vector3()).length()
|
|
365
|
+
camera.position.copy(center).add(new THREE.Vector3(0, -size, size))
|
|
366
|
+
camera.lookAt(center)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
##### reconnect() {#reconnect}
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
reconnect(): Promise<void>;
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Disconnects, connects the drawing's client again and recalculates the model (`v1.common.recalc`); then `api` is
|
|
376
|
+
available again.
|
|
377
|
+
|
|
378
|
+
###### Returns
|
|
379
|
+
|
|
380
|
+
`Promise`<`void`>
|
|
381
|
+
|
|
382
|
+
##### selectGeometry() {#selectgeometry}
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
selectGeometry(types, countOrResolver?): Promise<InteractionInfo[]>;
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
Lets the user pick geometry of the given types in the 3D view, and resolves with what was picked.
|
|
389
|
+
|
|
390
|
+
The drawing's geometry must be shown for selection, for example by `BuerliGeometry` of `@classcad/react` with
|
|
391
|
+
`selection`. With a count it resolves once that many items are picked; with a function, that function is
|
|
392
|
+
called at the first pick with one that ends the selection. Each item carries the picked element's ids, and in
|
|
393
|
+
`userData` its geometry in world coordinates and its positions (`matchingPoints`).
|
|
394
|
+
|
|
395
|
+
###### Parameters
|
|
396
|
+
|
|
397
|
+
| Parameter | Type | Description |
|
|
398
|
+
| :------ | :------ | :------ |
|
|
399
|
+
| `types` | ( \| `POINT` \| `LINE` \| `ARC` \| `CIRCLE` \| `PLANE` \| `CYLINDER` \| `CONE` \| `SPHERE` \| `NURBSCURVE` \| `NURBSSURFACE`)[] | The kinds of geometry that can be picked. |
|
|
400
|
+
| `countOrResolver?` | `number` \| ((`resolve`) => `void`) | How many items to pick (default 1), or a function that gets the function that ends the selection. |
|
|
401
|
+
|
|
402
|
+
###### Returns
|
|
403
|
+
|
|
404
|
+
`Promise`<`InteractionInfo`[]>
|
|
405
|
+
|
|
406
|
+
The picked items.
|
|
407
|
+
|
|
408
|
+
###### Examples
|
|
409
|
+
|
|
410
|
+
```ts
|
|
411
|
+
import { ScgGraphicType } from '@classcad/client'
|
|
412
|
+
|
|
413
|
+
// A box whose edges the user picks to round them; the drawing is shown with <BuerliGeometry selection />
|
|
414
|
+
const part = (await facade.api.v1.part.create({ name: 'Block' }))!
|
|
415
|
+
await facade.api.v1.part.box({ id: part, length: 60, width: 40, height: 20 })
|
|
416
|
+
const edges = await facade.selectGeometry([ScgGraphicType.LINE, ScgGraphicType.ARC], 2)
|
|
417
|
+
await facade.api.v1.part.fillet({ id: part, references: edges.map(edge => edge.graphicId!), radius: 4 })
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
```ts
|
|
421
|
+
import { ScgGraphicType } from '@classcad/client'
|
|
422
|
+
|
|
423
|
+
// As many faces as the user likes, until "Done"
|
|
424
|
+
const faces = await facade.selectGeometry([ScgGraphicType.PLANE, ScgGraphicType.CYLINDER], finish => {
|
|
425
|
+
doneButton.onclick = () => finish()
|
|
426
|
+
})
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
##### tree() {#tree}
|
|
430
|
+
|
|
431
|
+
```ts
|
|
432
|
+
tree(opts?): Promise<ScgTree>;
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
The structure tree (id -\> node) of the drawing, as held by the SDK's store.
|
|
436
|
+
The tree is kept up to date by the regular structure broadcast; pass
|
|
437
|
+
`refresh: true` to explicitly request it from ClassCAD first.
|
|
438
|
+
|
|
439
|
+
###### Parameters
|
|
440
|
+
|
|
441
|
+
| Parameter | Type | Description |
|
|
442
|
+
| :------ | :------ | :------ |
|
|
443
|
+
| `opts?` | \{ `refresh?`: `boolean`; \} | Options. |
|
|
444
|
+
| `opts.refresh?` | `boolean` | Loads the tree from ClassCAD before reading it. |
|
|
445
|
+
|
|
446
|
+
###### Returns
|
|
447
|
+
|
|
448
|
+
`Promise`<`ScgTree`>
|
|
449
|
+
|
|
450
|
+
The structure tree, keyed by object id.
|
|
451
|
+
|
|
452
|
+
###### Example
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
import { ccUtils, ScgClassType } from '@classcad/client'
|
|
456
|
+
|
|
457
|
+
// The parts of a loaded model, by name
|
|
458
|
+
const tree = await facade.tree({ refresh: true })
|
|
459
|
+
const parts = Object.values(tree).filter(node => ccUtils.base.isA(node.class, ScgClassType.CCPart))
|
|
460
|
+
const wheel = parts.find(node => node.name === 'Wheel')
|
|
461
|
+
console.log(parts.map(node => node.name), wheel?.id)
|
|
462
|
+
```
|
|
463
|
+
|
|
464
|
+
#### Properties
|
|
465
|
+
|
|
466
|
+
| Property | Modifier | Type | Description |
|
|
467
|
+
| :------ | :------ | :------ | :------ |
|
|
468
|
+
| <a id="property-utils"></a> `utils` | `public static` | \{ `callMiddleware`: (`drawingId`, `middlewareCommand`, `data`) => `Promise`<[`ServerResponse`](advanced/connection.md#serverresponse) \| `undefined`>; `connect`: (`drawingName?`) => `Promise`<`DrawingID` \| `null`>; `disconnect`: (`drawingId`) => `Promise`<`void`>; `fetchTree`: (`drawingId`) => `Promise`<`void`>; `getEmissionConfig`: (`drawingId`) => `Promise`<[`EmissionConfig`](advanced/connection.md#emissionconfig)>; `reconnect`: (`drawingId`) => `Promise`<`void`>; `redo`: (`drawingId`, `state?`) => `Promise`<`void`>; `setEmissionConfig`: (`drawingId`, `partial`) => `Promise`<[`EmissionConfig`](advanced/connection.md#emissionconfig)>; `undo`: (`drawingId`, `state?`) => `Promise`<`void`>; `withEmissionConfig`: <`T`>(`drawingId`, `partial`, `fn`) => `Promise`<`T`>; \} | The facade's work for any drawing, by its id: connect, disconnect, undo, emission config, middleware commands. For drawings an app connects without a facade, and for the drawings of react-cad and Buerligons. |
|
|
469
|
+
| `utils.callMiddleware` | `public` | (`drawingId`, `middlewareCommand`, `data`) => `Promise`<[`ServerResponse`](advanced/connection.md#serverresponse) \| `undefined`> | Sends a command of the server's own ([AwvNodeClient.executeMiddleware](clients.md#executemiddleware-3)) and resolves to the reply. Messages of the reply are logged as warnings; on an error it is logged and the call resolves to undefined. |
|
|
470
|
+
| `utils.connect` | `public` | (`drawingName?`) => `Promise`<`DrawingID` \| `null`> | Creates a drawing and connects it: makes its client with the factory given to [init](clients.md#init), calls the [onClient](clients.md#onclient) callbacks, connects the client. Rejects when `init` has not been called. When connecting fails, the error is logged and shown as a message, and it resolves to null. |
|
|
471
|
+
| `utils.disconnect` | `public` | (`drawingId`) => `Promise`<`void`> | Disconnects the drawing's client and resets the drawing: it stays in the store, without its model. Rejects when the drawing has no client. |
|
|
472
|
+
| `utils.fetchTree` | `public` | (`drawingId`) => `Promise`<`void`> | Loads the drawing's structure tree from the engine into the store. |
|
|
473
|
+
| `utils.getEmissionConfig` | `public` | (`drawingId`) => `Promise`<[`EmissionConfig`](advanced/connection.md#emissionconfig)> | Effective per-connection emission config of the drawing's client (see [IComClient.getEmissionConfig](advanced/connection.md#getemissionconfig)). |
|
|
474
|
+
| `utils.reconnect` | `public` | (`drawingId`) => `Promise`<`void`> | Disconnects the drawing, connects its client again and recalculates the model (`v1.common.recalc`). |
|
|
475
|
+
| `utils.redo` | `public` | (`drawingId`, `state?`) => `Promise`<`void`> | Steps forward in the drawing's undo history, to `state` when given ([AwvNodeClient.redo](clients.md#redo-3)). Messages of the engine are logged as warnings; an error is logged, not thrown. |
|
|
476
|
+
| `utils.setEmissionConfig` | `public` | (`drawingId`, `partial`) => `Promise`<[`EmissionConfig`](advanced/connection.md#emissionconfig)> | Merges `partial` into the per-connection emission config and returns the effective flags. |
|
|
477
|
+
| `utils.undo` | `public` | (`drawingId`, `state?`) => `Promise`<`void`> | Steps back in the drawing's undo history, to `state` when given ([AwvNodeClient.undo](clients.md#undo-3)). Messages of the engine are logged as warnings; an error is logged, not thrown. |
|
|
478
|
+
| `utils.withEmissionConfig` | `public` | <`T`>(`drawingId`, `partial`, `fn`) => `Promise`<`T`> | Runs `fn` with a temporary emission config and restores the previous one afterwards (also when `fn` throws). This is the "own config for a script" pattern: e.g. switch every graphic category off while a script issues hundreds of commands, then restore the app's config and fetch tree + graphic once. On engines without GetEmissionConfig/SetEmissionConfig ([EMISSION\_CONFIG\_UNSUPPORTED](advanced/connection.md#emission_config_unsupported)) `fn` simply runs with the fixed config. Only the flags in `partial` are restored. Resolves to what `fn` resolves to. [EmissionConfig](advanced/connection.md#emissionconfig) has an example. |
|
|
479
|
+
|
|
480
|
+
## Types
|
|
481
|
+
|
|
482
|
+
### ClassCADApi {#classcadapi}
|
|
483
|
+
|
|
484
|
+
```ts
|
|
485
|
+
type ClassCADApi = UnwrappedApiType;
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
The ClassCAD API of a [BuerliCadFacade](#buerlicadfacade), unwrapped: calls resolve to their result and reject on an error.
|
|
489
|
+
|
|
490
|
+
`api.v1` holds the namespaces (`part`, `sketch`, `assembly`, `solid`, `curve`, `common`, `drawing2d`), which are
|
|
491
|
+
also on the object itself. See [createUnwrappedApi](#createunwrappedapi).
|
|
492
|
+
|
|
493
|
+
#### Example
|
|
494
|
+
|
|
495
|
+
```ts
|
|
496
|
+
import { BuerliCadFacade } from '@classcad/client'
|
|
497
|
+
import type { ClassCADApi } from '@classcad/client'
|
|
498
|
+
|
|
499
|
+
// A model function that works with any facade's API
|
|
500
|
+
async function plateWithHole(api: ClassCADApi, size: number) {
|
|
501
|
+
const part = (await api.v1.part.create({ name: 'Plate' }))!
|
|
502
|
+
const plate = (await api.v1.part.box({ id: part, length: size, width: size, height: 10 }))!
|
|
503
|
+
const hole = (await api.v1.part.cylinder({ id: part, diameter: size / 2, height: 10 }))!
|
|
504
|
+
await api.v1.part.boolean({ id: part, type: 'SUBTRACTION', target: plate, tools: [hole] })
|
|
505
|
+
return part
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const facade = new BuerliCadFacade()
|
|
509
|
+
await facade.connect()
|
|
510
|
+
const part = await plateWithHole(facade.api, 100)
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
## Advanced
|
|
514
|
+
|
|
515
|
+
Most apps do not need these directly: types they meet through the exports above, and what is there for special cases or for building on the SDK itself.
|
|
516
|
+
|
|
517
|
+
### ccUtils {#ccutils}
|
|
518
|
+
|
|
519
|
+
```ts
|
|
520
|
+
const ccUtils: {
|
|
521
|
+
assembly: __module;
|
|
522
|
+
base: __module;
|
|
523
|
+
part: __module;
|
|
524
|
+
};
|
|
525
|
+
```
|
|
526
|
+
|
|
527
|
+
Helpers that look things up in a drawing's structure tree: classes, ancestors, work geometry, sketches, constraints.
|
|
528
|
+
|
|
529
|
+
They read the tree in the SDK's store; none of them calls the engine.
|
|
530
|
+
|
|
531
|
+
#### Type Declaration
|
|
532
|
+
|
|
533
|
+
| Name | Type | Description |
|
|
534
|
+
| :------ | :------ | :------ |
|
|
535
|
+
| <a id="property-assembly"></a> `assembly` | `__module` | Assemblies: `findProduct` (of an instance), `getInstance`, `getPartTemplate`, `getAssemblyTemplate`, `getTransformation`, `getMatePath`, `getWorkGeometry`, and the constraints (`getConstraint`, `getFastenedConstraint`, `getRevoluteConstraint`, …). |
|
|
536
|
+
| <a id="property-base"></a> `base` | `__module` | Class checks and tree walks: `isA` (a class or one derived from it), `getChildren`, `getAncestors`, `getAncestorIdByClass`, `getDescendants`, `findObject` (by identifier or name). |
|
|
537
|
+
| <a id="property-part"></a> `part` | `__module` | Parts: `getWorkGeometry`, `getSketch`, `getSketchRegion`, `getSketchlines`. |
|
|
538
|
+
|
|
539
|
+
#### Example
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
import { ccUtils, ScgClassType } from '@classcad/client'
|
|
543
|
+
|
|
544
|
+
// The part a picked solid belongs to, and that part's sketches
|
|
545
|
+
const partId = ccUtils.base.getAncestorIdByClass(facade.drawingId, solidId, ScgClassType.CCPart)
|
|
546
|
+
if (partId !== null) {
|
|
547
|
+
const sketches = ccUtils.part.getSketch(facade.drawingId, partId)
|
|
548
|
+
const tree = await facade.tree()
|
|
549
|
+
console.log(tree[partId].name, sketches.map(id => tree[id].name))
|
|
550
|
+
}
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
***
|
|
554
|
+
|
|
555
|
+
### createApi() {#createapi}
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
function createApi(drawingId, cached?): ApiType;
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
The ClassCAD API of a drawing; every call resolves to the engine's reply, `{ result, messages, maxLevel }`.
|
|
562
|
+
|
|
563
|
+
`v1` holds the namespaces (`part`, `sketch`, `assembly`, `solid`, `curve`, `common`, `drawing2d`); they are also
|
|
564
|
+
on the object itself, so `createApi(id).part` is `createApi(id).v1.part`. A call rejects when the reply carries an
|
|
565
|
+
error, with that reply, and when the drawing has no client. Warnings and errors are logged and shown as messages
|
|
566
|
+
of the drawing. `v0`, the old API, is deprecated. [createUnwrappedApi](#createunwrappedapi) gives the results without the reply
|
|
567
|
+
around them.
|
|
568
|
+
|
|
569
|
+
#### Parameters
|
|
570
|
+
|
|
571
|
+
| Parameter | Type | Default value | Description |
|
|
572
|
+
| :------ | :------ | :------ | :------ |
|
|
573
|
+
| `drawingId` | `DrawingID` | `undefined` | A drawing that is connected, for example by [BuerliCadFacade.connect](#connect). |
|
|
574
|
+
| `cached?` | `boolean` | `true` | `true` (default) returns the same object for the drawing on every call, `false` makes a new one. |
|
|
575
|
+
|
|
576
|
+
#### Returns
|
|
577
|
+
|
|
578
|
+
`ApiType`
|
|
579
|
+
|
|
580
|
+
#### Example
|
|
581
|
+
|
|
582
|
+
```ts
|
|
583
|
+
import { BuerliCadFacade, createApi, MessageLevel } from '@classcad/client'
|
|
584
|
+
|
|
585
|
+
const drawingId = await BuerliCadFacade.utils.connect('Bracket')
|
|
586
|
+
if (drawingId) {
|
|
587
|
+
const api = createApi(drawingId)
|
|
588
|
+
const part = (await api.v1.part.create({ name: 'Bracket' })).result!
|
|
589
|
+
// The reply carries the engine's messages; a warning does not reject
|
|
590
|
+
const { messages } = await api.v1.part.box({ id: part, length: 80, width: 40, height: 5 })
|
|
591
|
+
const warnings = messages?.filter(m => m.level === MessageLevel.warning) ?? []
|
|
592
|
+
if (warnings.length) console.warn(warnings.map(m => m.message))
|
|
593
|
+
}
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
***
|
|
597
|
+
|
|
598
|
+
### createUnwrappedApi() {#createunwrappedapi}
|
|
599
|
+
|
|
600
|
+
```ts
|
|
601
|
+
function createUnwrappedApi(drawingId, cached?): UnwrappedApiType;
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
The ClassCAD API of a drawing, unwrapped: calls resolve to their result and reject on an engine error.
|
|
605
|
+
|
|
606
|
+
The same namespaces as [createApi](#createapi) (`v1.part`, `v1.sketch`, …, also on the object itself); this is what
|
|
607
|
+
[BuerliCadFacade.api](#api) is. A rejection carries the engine's reply (`{ result, messages, maxLevel }`).
|
|
608
|
+
Warnings are logged and shown as messages of the drawing.
|
|
609
|
+
|
|
610
|
+
#### Parameters
|
|
611
|
+
|
|
612
|
+
| Parameter | Type | Default value | Description |
|
|
613
|
+
| :------ | :------ | :------ | :------ |
|
|
614
|
+
| `drawingId` | `DrawingID` | `undefined` | A drawing that is connected, for example by [BuerliCadFacade.connect](#connect). |
|
|
615
|
+
| `cached?` | `boolean` | `true` | `true` (default) returns the same object for the drawing on every call, `false` makes a new one. |
|
|
616
|
+
|
|
617
|
+
#### Returns
|
|
618
|
+
|
|
619
|
+
`UnwrappedApiType`
|
|
620
|
+
|
|
621
|
+
#### Example
|
|
622
|
+
|
|
623
|
+
```ts
|
|
624
|
+
import { BuerliCadFacade, createUnwrappedApi } from '@classcad/client'
|
|
625
|
+
|
|
626
|
+
const drawingId = await BuerliCadFacade.utils.connect('Plate')
|
|
627
|
+
if (drawingId) {
|
|
628
|
+
const api = createUnwrappedApi(drawingId)
|
|
629
|
+
try {
|
|
630
|
+
const part = (await api.v1.part.create({ name: 'Plate' }))!
|
|
631
|
+
await api.v1.part.box({ id: part, length: 200, width: 100, height: 8 })
|
|
632
|
+
} catch (reply) {
|
|
633
|
+
// The engine's reply, with the error in its messages
|
|
634
|
+
console.error(reply)
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
```
|
|
638
|
+
|
|
639
|
+
***
|
|
640
|
+
|
|
641
|
+
### getApiFacade() {#getapifacade}
|
|
642
|
+
|
|
643
|
+
```ts
|
|
644
|
+
function getApiFacade(drawingId): IFacade & {
|
|
645
|
+
callUnsafeApi: (command) => Promise<FacadeReturn>;
|
|
646
|
+
};
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
The low-level facade a drawing's API calls go through: one ClassCAD function, called by its name.
|
|
650
|
+
|
|
651
|
+
`callSafeApiV(version, namespace, func, args, options)` runs `<version>.<namespace>.<func>` and resolves to the
|
|
652
|
+
engine's reply, `{ result, messages, maxLevel }`; `callSafeApi` takes the namespace with its version
|
|
653
|
+
(`'v1.part'`). `fetchTree` loads the structure tree anew, `callUnsafeApi` sends a command as it is. Replies are
|
|
654
|
+
handled as in [createApi](#createapi). Use it for a function the typed API does not have, or one picked at runtime.
|
|
655
|
+
|
|
656
|
+
#### Parameters
|
|
657
|
+
|
|
658
|
+
| Parameter | Type | Description |
|
|
659
|
+
| :------ | :------ | :------ |
|
|
660
|
+
| `drawingId` | `DrawingID` | The drawing whose client the calls go to. |
|
|
661
|
+
|
|
662
|
+
#### Returns
|
|
663
|
+
|
|
664
|
+
`IFacade` & \{
|
|
665
|
+
`callUnsafeApi`: (`command`) => `Promise`<`FacadeReturn`>;
|
|
666
|
+
\}
|
|
667
|
+
|
|
668
|
+
#### Example
|
|
669
|
+
|
|
670
|
+
```ts
|
|
671
|
+
import { getApiFacade } from '@classcad/client'
|
|
672
|
+
|
|
673
|
+
// A call named at runtime, e.g. by a script or a tool an AI agent calls
|
|
674
|
+
async function call(name: string, args: Record<string, unknown>) {
|
|
675
|
+
const [namespace, func] = name.split('.') // 'part.box'
|
|
676
|
+
const { result, messages } = await getApiFacade(drawingId).callSafeApiV('v1', namespace, func, args)
|
|
677
|
+
return { result, messages }
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const { result: part } = await call('part.create', { name: 'Part' })
|
|
681
|
+
await call('part.box', { id: part, length: 50 })
|
|
682
|
+
```
|