@buerli.io/headless 0.0.35-beta.1 → 0.0.35

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.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,22 +1,20 @@
1
1
  {
2
2
  "name": "@buerli.io/headless",
3
- "version": "0.0.35-beta.1",
3
+ "version": "0.0.35",
4
4
  "description": "A non-manifold CAD workflow for the web",
5
5
  "author": "AWV Informatik AG <info@awv-informatik.ch>",
6
6
  "repository": {},
7
- "main": "build/cjs/index.js",
8
- "module": "build/esm/index.js",
9
- "types": "build/types/index.d.ts",
7
+ "main": "build/index.js",
8
+ "module": "build/index.js",
9
+ "types": "build/index.d.ts",
10
10
  "sideEffects": false,
11
11
  "scripts": {
12
12
  "ver": "npm version",
13
13
  "prepack": "npm run build:dist",
14
14
  "clean": "rimraf ./build",
15
- "build": "npm run build:esm -- --sourceMap true --declaration true --declarationDir ./build/types",
16
- "build:dist": "npm run clean && npm run build:esm && npm run build:cjs && npm run build:types && echo DONE",
17
- "build:esm": "tsc --target es2017 --module esNext --declaration false --declarationDir null --sourceMap false --outDir ./build/esm",
18
- "build:cjs": "tsc --target es2017 --module commonjs --declaration false --declarationDir null --sourceMap false --outDir ./build/cjs",
19
- "build:types": "tsc --declaration --emitDeclarationOnly --outDir ./build/types",
15
+ "build": "echo Typescript: && tsc --version && tsc && npm run build:copy && echo DONE",
16
+ "build:dist": "npm run clean && echo Typescript: && tsc --version && tsc --sourceMap false && npm run build:copy && echo DONE",
17
+ "build:copy": "copyfiles -a -u 1 \"./src/**/*.png\" \"./build\"",
20
18
  "test": "echo no tests yet",
21
19
  "lint": "eslint \"./src/**/*.ts?(x)\"",
22
20
  "prettier": "prettier --write \"./{src,tests}/**/*.{js,jsx,ts,tsx,json}\""
@@ -53,6 +51,6 @@
53
51
  "three": ">=0.128"
54
52
  },
55
53
  "dependencies": {
56
- "@buerli.io/classcad": "0.0.35-beta.1"
54
+ "@buerli.io/classcad": "0.0.35"
57
55
  }
58
56
  }
@@ -1,814 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- /* eslint-disable max-lines */
23
- const classcad_1 = require("@buerli.io/classcad");
24
- const core_1 = require("@buerli.io/core");
25
- const three_1 = require("three");
26
- const BufferGeometryUtils_ = __importStar(require("three/examples/jsm/utils/BufferGeometryUtils"));
27
- const featureAPI = classcad_1.ccAPI.feature;
28
- let BufferGeometryUtils = BufferGeometryUtils_;
29
- if (BufferGeometryUtils.BufferGeometryUtils) {
30
- BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
31
- }
32
- // Qeued execute, returns the first result and expects it to be an ObjectID
33
- const exec = (instance, drawing, namespace, fn, stream, ...args) => {
34
- return (instance.queue = instance.queue.then(() => Promise.all(args).then(resolvedArgs => {
35
- return classcad_1.ccAPI.base.callSafeAPI(drawing, namespace, fn, resolvedArgs, stream).then(res => {
36
- return (res && res.results[0].result);
37
- });
38
- })));
39
- };
40
- const toCCVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
41
- const toArray = (v) => (Array.isArray(v) ? v : v.toArray());
42
- const toEuler = (v) => toArray(v);
43
- const makeVec = (v) => toCCVec(toArray(v));
44
- const getBoxMember = (drawingId, featureId, member) => {
45
- const cDrawing = core_1.getDrawing(drawingId);
46
- const members = cDrawing.structure.tree[featureId].members;
47
- if (members) {
48
- switch (member) {
49
- case 'width':
50
- return members.width.value === undefined ? 10 : Number(members.width.value);
51
- case 'length':
52
- return members.length.value === undefined ? 10 : Number(members.length.value);
53
- case 'height':
54
- return members.height.value === undefined ? 10 : Number(members.height.value);
55
- }
56
- }
57
- };
58
- const getDataType = (value) => {
59
- switch (typeof value) {
60
- case 'number':
61
- return classcad_1.DataType.REAL;
62
- case 'object':
63
- return classcad_1.DataType.POINT;
64
- case 'string':
65
- return classcad_1.DataType.STRING;
66
- }
67
- };
68
- const getBoolType = (type) => {
69
- switch (type) {
70
- case 'Union':
71
- return classcad_1.BooleanOperationType.UNION;
72
- case 'Subtraction':
73
- return classcad_1.BooleanOperationType.SUBTRACTION;
74
- case 'Intersection':
75
- return classcad_1.BooleanOperationType.INTERSECTION;
76
- case undefined:
77
- break;
78
- }
79
- };
80
- const getChamferType = (type) => {
81
- switch (type) {
82
- case 'Equal_Distance':
83
- return classcad_1.ChamferType.EQUAL_DISTANCE;
84
- case 'Two_Distances':
85
- return classcad_1.ChamferType.TWO_DISTANCES;
86
- case 'Distance_And_Angle':
87
- return classcad_1.ChamferType.DISTANCE_AND_ANGLE;
88
- case undefined:
89
- break;
90
- }
91
- };
92
- const getWCSType = (type) => {
93
- switch (type) {
94
- case 'XYAxisOrigin':
95
- return classcad_1.WorkCoordSystemType.WCS_XYAXISORIGIN;
96
- case 'Custom':
97
- return classcad_1.WorkCoordSystemType.WCS_CUSTOM;
98
- case undefined:
99
- break;
100
- }
101
- };
102
- const getWAType = (type) => {
103
- switch (type) {
104
- case 'Custom':
105
- return classcad_1.WorkAxisType.WA_USERDEFINED;
106
- case 'WorkPoints':
107
- return classcad_1.WorkAxisType.WA_WORKPOINTS;
108
- case 'PointAndDirection':
109
- return classcad_1.WorkAxisType.WA_POINTDIRECTION;
110
- case 'SketchLine':
111
- return classcad_1.WorkAxisType.WA_SKETCHLINE;
112
- case 'Curve':
113
- return classcad_1.WorkAxisType.WA_CURVE;
114
- case '2Points':
115
- return classcad_1.WorkAxisType.WA_2POINTS;
116
- case '2Planes':
117
- return classcad_1.WorkAxisType.WA_2PLANES;
118
- case undefined:
119
- break;
120
- }
121
- };
122
- const getWPType = (type) => {
123
- switch (type) {
124
- case 'Custom':
125
- return classcad_1.WorkPlaneType.WP_USERDEFINED;
126
- case 'Plane':
127
- return classcad_1.WorkPlaneType.WP_PLANE;
128
- case 'EdgeAndPoint':
129
- return classcad_1.WorkPlaneType.WP_EDGEPOINT;
130
- case '3Points':
131
- return classcad_1.WorkPlaneType.WP_3POINTS;
132
- case 'PointAndNormal':
133
- return classcad_1.WorkPlaneType.WP_POINTNORMAL;
134
- case 'PointAndFace':
135
- return classcad_1.WorkPlaneType.WP_POINTFACE;
136
- case 'LinePlaneAndAngle':
137
- return classcad_1.WorkPlaneType.WP_LINEPLANEANGLE;
138
- case undefined:
139
- break;
140
- }
141
- };
142
- const getWPTType = (type) => {
143
- switch (type) {
144
- case 'Custom':
145
- return classcad_1.WorkPointType.WPT_USERDEFINED;
146
- case 'Point':
147
- return classcad_1.WorkPointType.WPT_BREPVERTEX;
148
- case 'MidPointLine':
149
- return classcad_1.WorkPointType.WPT_EDGEMIDPOINT;
150
- case 'Center':
151
- return classcad_1.WorkPointType.WPT_CENTER;
152
- case 'BaryCenter':
153
- return classcad_1.WorkPointType.WPT_BARYCENTER;
154
- case 'Intersection':
155
- return classcad_1.WorkPointType.WPT_INTERSECTION;
156
- case 'InnerCircle':
157
- return classcad_1.WorkPointType.WPT_INNERCIRCLE;
158
- case 'MidPointOf2Points':
159
- return classcad_1.WorkPointType.WPT_2POINTS;
160
- case undefined:
161
- break;
162
- }
163
- };
164
- const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
165
- let cDrawing = core_1.getDrawing(drawingId);
166
- const tree = cDrawing.structure.tree;
167
- if (object.link || object.solids) {
168
- // Part
169
- const solids = object.link ? tree[object.link].solids : object.solids;
170
- if (solids != undefined) {
171
- let geometries = [];
172
- for (const solid of solids) {
173
- let cachedSolid = cDrawing.geometry.cache[solid];
174
- if (cachedSolid) {
175
- // if solid already cached, take it from cache
176
- geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
177
- }
178
- else {
179
- // else get visualisation from classcad
180
- await classcad_1.ccAPI.baseModeler.requestVisualisationOfEntities(drawingId, [solid]);
181
- cDrawing = core_1.getDrawing(drawingId); // get current drawing state after request
182
- cachedSolid = cDrawing.geometry.cache[solid];
183
- if (cachedSolid) {
184
- geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
185
- }
186
- else {
187
- console.warn(`There is no cached entry for ${solid}!`, cDrawing.geometry.cache);
188
- }
189
- }
190
- }
191
- if (geometries.length > 0) {
192
- const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
193
- const bufferGeom = BufferGeometryUtils.mergeBufferGeometries(geometries);
194
- bufferGeom.applyMatrix4(transformation);
195
- bufferGeomArray.push(bufferGeom);
196
- }
197
- }
198
- }
199
- else if (object.children) {
200
- // Assembly
201
- for (const child of object.children) {
202
- if (tree[child].class === classcad_1.CCClasses.CCProductReference || tree[child].class === classcad_1.CCClasses.CCProductReferenceET) {
203
- await createRecursiveBufferGeometry(tree[child], drawingId, bufferGeomArray);
204
- }
205
- }
206
- }
207
- };
208
- const createRecursiveScene = async (object, drawingId, root, options) => {
209
- let cDrawing = core_1.getDrawing(drawingId);
210
- const tree = cDrawing.structure.tree;
211
- if (object.link || object.solids) {
212
- // Part
213
- const solids = object.link ? tree[object.link].solids : object.solids;
214
- if (solids != undefined) {
215
- let meshes = [];
216
- for (const solid of solids) {
217
- let cachedSolid = cDrawing.geometry.cache[solid];
218
- if (!cachedSolid) {
219
- // else get visualisation from classcad
220
- await classcad_1.ccAPI.baseModeler.requestVisualisationOfEntities(drawingId, [solid]);
221
- cDrawing = core_1.getDrawing(drawingId); // get current drawing state after request
222
- cachedSolid = cDrawing.geometry.cache[solid];
223
- }
224
- if (cachedSolid)
225
- meshes = [...meshes, ...cachedSolid.meshes.map(m => m)];
226
- }
227
- if (meshes.length > 0) {
228
- if (options === null || options === void 0 ? void 0 : options.meshPerFace) {
229
- const part = new three_1.Group();
230
- part.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
231
- part.matrixAutoUpdate = false;
232
- part.userData = { id: object.id };
233
- part.name = object.name;
234
- for (const mesh of meshes) {
235
- part.add(new three_1.Mesh(mesh.geometry, new three_1.MeshStandardMaterial({ color: mesh.color, transparent: mesh.opacity < 1, opacity: mesh.opacity })));
236
- }
237
- root.add(part);
238
- }
239
- else {
240
- const mesh = new three_1.Mesh();
241
- mesh.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
242
- mesh.matrixAutoUpdate = false;
243
- mesh.userData = { id: object.id };
244
- mesh.name = object.name;
245
- mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(meshes.map(m => m.geometry));
246
- mesh.material = new three_1.MeshStandardMaterial();
247
- root.add(mesh);
248
- }
249
- }
250
- }
251
- }
252
- else if (object.children) {
253
- // Assembly
254
- const assembly = new three_1.Group();
255
- assembly.matrix = core_1.MathUtils.convertToMatrix4(object.coordinateSystem);
256
- assembly.matrixAutoUpdate = false;
257
- assembly.userData = { id: object.id };
258
- assembly.name = object.name;
259
- root.add(assembly);
260
- for (const child of object.children) {
261
- if (tree[child].class === classcad_1.CCClasses.CCProductReference || tree[child].class === classcad_1.CCClasses.CCProductReferenceET) {
262
- await createRecursiveScene(tree[child], drawingId, assembly, options);
263
- }
264
- }
265
- }
266
- };
267
- class CAD {
268
- constructor(url) {
269
- this.drawingId = null;
270
- this.queue = Promise.resolve(0);
271
- this.queue = Promise.resolve(0);
272
- core_1.init({ url });
273
- }
274
- resolve(callback, ...args) {
275
- // eslint-disable-next-line promise/no-callback-in-promise
276
- return (this.queue = this.queue.then(() => Promise.all(args).then(callback)));
277
- }
278
- init(callback) {
279
- const promise = new Promise(async (resolve, reject) => {
280
- const drawingId = await classcad_1.ccAPI.base.createCCDrawing();
281
- if (!drawingId)
282
- throw new Error('Drawing could not be created');
283
- this.drawingId = drawingId;
284
- const publicApi = {
285
- addNode: (productId, ownerId, transformation, name) => {
286
- return this.resolve(async ([rProductId, rOwnerId]) => {
287
- return classcad_1.ccAPI.assemblyBuilder.addNode(drawingId, rProductId, rOwnerId, transformation, name);
288
- }, productId, ownerId);
289
- },
290
- addNodes: (...nodes) => {
291
- return this.resolve(async ([]) => {
292
- const nodesToAdd = [];
293
- nodes.forEach(node => {
294
- nodesToAdd.push([node.productId, node.ownerId, node.transformation, node.name]);
295
- });
296
- return classcad_1.ccAPI.assemblyBuilder.addNodes(drawingId, nodesToAdd);
297
- });
298
- },
299
- boolean: (partId, type, entities) => {
300
- return this.resolve(async ([rPartId, ...rEntities]) => {
301
- const cDrawing = await core_1.getDrawing(drawingId);
302
- const entArray = [];
303
- for (const rEntity of rEntities) {
304
- const entity = cDrawing.structure.tree[rEntity].children;
305
- if (entity != undefined) {
306
- entArray.push(entity[0]);
307
- }
308
- }
309
- const boolType = getBoolType(type);
310
- if (boolType != undefined) {
311
- const boolId = await featureAPI.createBooleanOperation(drawingId, rPartId, {
312
- type: boolType,
313
- entities: entArray,
314
- });
315
- if (boolId != null) {
316
- await featureAPI.updateBooleanOperation(drawingId, boolId, boolType, entArray);
317
- return boolId;
318
- }
319
- }
320
- return null; // Todo: Exceptions?
321
- }, partId, ...entities);
322
- },
323
- box: (partId, references, width, length, height) => {
324
- return this.resolve(async ([rPartId]) => {
325
- const boxId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCBox, 'Box');
326
- if (boxId != null) {
327
- const widthParam = { value: width, isExpr: typeof width === 'string' };
328
- const lengthParam = { value: length, isExpr: typeof length === 'string' };
329
- const heightParam = { value: height, isExpr: typeof height === 'string' };
330
- await featureAPI.updateBox(drawingId, boxId, references, widthParam, lengthParam, heightParam);
331
- return boxId;
332
- }
333
- return null;
334
- }, partId);
335
- },
336
- cylinder: (partId, references, diameter, height) => {
337
- return this.resolve(async ([rPartId]) => {
338
- const cylId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCylinder, 'Cylinder');
339
- if (cylId != null) {
340
- const diameterParam = { value: diameter, isExpr: typeof length === 'string' };
341
- const heightParam = { value: height, isExpr: typeof height === 'string' };
342
- await featureAPI.updateCylinder(drawingId, cylId, references, diameterParam, heightParam);
343
- return cylId;
344
- }
345
- return null;
346
- }, partId);
347
- },
348
- chamfer: (partId, type, references, dist1, dist2, angle) => {
349
- return this.resolve(async ([rPartId, ...rReferences]) => {
350
- const dist1Param = { value: dist1, isExpr: typeof dist1 === 'string' };
351
- const dist2Param = { value: dist2, isExpr: typeof dist2 === 'string' };
352
- const angleParam = { value: angle, isExpr: typeof angle === 'string' };
353
- const chamferId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCChamfer, 'Chamfer');
354
- const chamferType = getChamferType(type);
355
- if (chamferType != undefined && chamferId != null) {
356
- await featureAPI.updateChamfer(drawingId, chamferId, chamferType, rReferences, dist1Param, dist2Param, angleParam);
357
- return chamferId;
358
- }
359
- return null;
360
- }, partId, ...references);
361
- },
362
- cone: (partId, references, bDiameter, tDiameter, height) => {
363
- return this.resolve(async ([rPartId]) => {
364
- const coneId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCCone, 'Cone');
365
- if (coneId != null) {
366
- const bDiamParam = { value: bDiameter, isExpr: typeof bDiameter === 'string' };
367
- const tDiamParam = { value: tDiameter, isExpr: typeof tDiameter === 'string' };
368
- const heightParam = { value: height, isExpr: typeof height === 'string' };
369
- await featureAPI.updateCone(drawingId, coneId, references, bDiamParam, tDiamParam, heightParam);
370
- return coneId;
371
- }
372
- return null;
373
- }, partId);
374
- },
375
- createFastenedConstraint: (asmId, mate1, mate2, xOffset, yOffset, zOffset, name) => {
376
- return this.resolve(async ([rAsmId]) => {
377
- const constraintId = await classcad_1.ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCFastenedConstraint, name);
378
- if (constraintId != null) {
379
- const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
380
- const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
381
- const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
382
- await classcad_1.ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, constraintId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], [mate2.matePath, mate2.wcsId, mate2.flip, mate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
383
- return constraintId;
384
- }
385
- return null;
386
- }, asmId);
387
- },
388
- updateFastenedConstraint: (constrId, mate1, mate2, xOffset, yOffset, zOffset) => {
389
- return this.resolve(async ([rConstrId]) => {
390
- const xOffsetParam = { value: xOffset, isExpr: false };
391
- const yOffsetParam = { value: yOffset, isExpr: false };
392
- const zOffsetParam = { value: zOffset, isExpr: false };
393
- await classcad_1.ccAPI.assemblyBuilder.updateFastenedConstraint(drawingId, rConstrId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], [mate2.matePath, mate2.wcsId, mate2.flip, mate2.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
394
- }, constrId);
395
- },
396
- updateFastenedConstraints: (...constraints) => {
397
- return this.resolve(async ([]) => {
398
- const constrToAdd = [];
399
- constraints.forEach(constr => {
400
- const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
401
- const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
402
- const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
403
- constrToAdd.push([constr.constrId,
404
- [constr.mate1.matePath, constr.mate1.wcsId, constr.mate1.flip, constr.mate1.reoriented],
405
- [constr.mate2.matePath, constr.mate2.wcsId, constr.mate2.flip, constr.mate2.reoriented],
406
- xOffsetParam, yOffsetParam, zOffsetParam]);
407
- });
408
- await classcad_1.ccAPI.assemblyBuilder.updateFastenedConstraints(drawingId, constrToAdd);
409
- });
410
- },
411
- createFastenedOriginConstraint: (asmId, mate1, xOffset, yOffset, zOffset, name) => {
412
- return this.resolve(async ([rAsmId]) => {
413
- const constraintId = await classcad_1.ccAPI.assemblyBuilder.create3DConstraint(drawingId, rAsmId, classcad_1.CCClasses.CCFastenedOriginConstraint, name);
414
- if (constraintId != null) {
415
- const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
416
- const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
417
- const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
418
- await classcad_1.ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, constraintId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
419
- return constraintId;
420
- }
421
- return null;
422
- }, asmId);
423
- },
424
- updateFastenedOriginConstraint: (constrId, mate1, xOffset, yOffset, zOffset) => {
425
- return this.resolve(async ([rConstrId]) => {
426
- const xOffsetParam = { value: xOffset, isExpr: typeof xOffset === 'string' };
427
- const yOffsetParam = { value: yOffset, isExpr: typeof yOffset === 'string' };
428
- const zOffsetParam = { value: zOffset, isExpr: typeof zOffset === 'string' };
429
- await classcad_1.ccAPI.assemblyBuilder.updateFastenedOriginConstraint(drawingId, rConstrId, [mate1.matePath, mate1.wcsId, mate1.flip, mate1.reoriented], xOffsetParam, yOffsetParam, zOffsetParam);
430
- }, constrId);
431
- },
432
- updateFastenedOriginConstraints: (...constraints) => {
433
- return this.resolve(async ([]) => {
434
- const constrToAdd = [];
435
- constraints.forEach(constr => {
436
- const xOffsetParam = [constr.xOffset, typeof constr.xOffset === 'string'];
437
- const yOffsetParam = [constr.yOffset, typeof constr.yOffset === 'string'];
438
- const zOffsetParam = [constr.zOffset, typeof constr.zOffset === 'string'];
439
- constrToAdd.push([constr.constrId,
440
- [constr.mate1.matePath, constr.mate1.wcsId, constr.mate1.flip, constr.mate1.reoriented],
441
- xOffsetParam, yOffsetParam, zOffsetParam]);
442
- });
443
- await classcad_1.ccAPI.assemblyBuilder.updateFastenedOriginConstraints(drawingId, constrToAdd);
444
- });
445
- },
446
- createBufferGeometry: async (objectId) => {
447
- await this.queue;
448
- this.queue = Promise.resolve(0);
449
- const rObjectId = await objectId;
450
- const cDrawing = core_1.getDrawing(drawingId);
451
- const structureTree = cDrawing.structure.tree;
452
- const bufferGeomArray = [];
453
- if (rObjectId != null) {
454
- const rootObj = structureTree[rObjectId];
455
- await createRecursiveBufferGeometry(rootObj, drawingId, bufferGeomArray);
456
- if (bufferGeomArray.length > 0) {
457
- return bufferGeomArray;
458
- }
459
- }
460
- return undefined;
461
- },
462
- createScene: async (objectId, options) => {
463
- await this.queue;
464
- this.queue = Promise.resolve(0);
465
- const rObjectId = await objectId;
466
- const cDrawing = core_1.getDrawing(drawingId);
467
- const structureTree = cDrawing.structure.tree;
468
- const scene = new three_1.Scene();
469
- if (rObjectId != null) {
470
- const rootObj = structureTree[rObjectId];
471
- await createRecursiveScene(rootObj, drawingId, scene, options);
472
- }
473
- return scene;
474
- },
475
- createExpressions: (partId, ...members) => {
476
- return this.resolve(async (resolvedArgs) => {
477
- const membersToAdd = [];
478
- members.forEach(mem => {
479
- const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
480
- const dataType = getDataType(mem.value);
481
- const featureAPIParam = {
482
- value: mem.value,
483
- isExpr: isExpr,
484
- };
485
- membersToAdd.push([mem.name, featureAPIParam, dataType]);
486
- });
487
- const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], membersToAdd, [], []);
488
- return success;
489
- }, partId);
490
- },
491
- createAssemblyAsTemplate: (name) => {
492
- return this.resolve(async ([]) => {
493
- return await classcad_1.ccAPI.assemblyBuilder.createAssemblyAsTemplate(drawingId, name);
494
- });
495
- },
496
- createRootAssembly: (name) => {
497
- return this.resolve(async ([]) => {
498
- return await classcad_1.ccAPI.assemblyBuilder.createRootAssembly(drawingId, name);
499
- });
500
- },
501
- createPart: (name) => {
502
- return this.resolve(async ([]) => {
503
- const partName = name ? name : 'Part';
504
- return await featureAPI.newPart(drawingId, partName);
505
- });
506
- },
507
- createPartAsTemplate: (name) => {
508
- return this.resolve(async ([]) => {
509
- const partName = name ? name : 'Part';
510
- return await classcad_1.ccAPI.assemblyBuilder.createPartAsTemplate(drawingId, partName);
511
- });
512
- },
513
- createWorkAxis: (partId, type, references, position, direction, local, name) => {
514
- return this.resolve(async ([rPartId, rReferences]) => {
515
- const wAType = getWAType(type);
516
- const wAName = name ? name : 'WorkAxis';
517
- const wARefs = rReferences;
518
- if (wAType != undefined) {
519
- const wAId = await featureAPI.createWorkAxis(drawingId, rPartId, {
520
- axisType: wAType,
521
- references: wARefs,
522
- name: wAName,
523
- position: position,
524
- direction: direction,
525
- local: local,
526
- });
527
- if (wAId != null) {
528
- const positionParam = {
529
- value: position,
530
- isExpr: typeof position === 'string',
531
- };
532
- const directionParam = {
533
- value: direction,
534
- isExpr: typeof direction === 'string',
535
- };
536
- await featureAPI.updateWorkAxis(drawingId, wAId, wAType, wARefs, positionParam, directionParam, local);
537
- return wAId;
538
- }
539
- }
540
- return null;
541
- }, partId, references);
542
- },
543
- createWorkCoordSystem: (partId, type, references, coordinateSystem, offset, rotation, inverted, local, name) => {
544
- return this.resolve(async ([rPartId, rReferences]) => {
545
- const wCSType = getWCSType(type);
546
- const wCSName = name ? name : 'WorkCoordSystem';
547
- const wCSRefs = rReferences;
548
- if (wCSType != undefined) {
549
- const wCSId = await featureAPI.createWorkCoordSystem(drawingId, rPartId, {
550
- coordSystemType: wCSType,
551
- name: wCSName,
552
- references: wCSRefs,
553
- coordinateSystem,
554
- offset,
555
- rotation,
556
- inverted,
557
- local,
558
- });
559
- if (wCSId != null) {
560
- const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
561
- const rotationParam = {
562
- value: rotation,
563
- isExpr: typeof rotation === 'string',
564
- };
565
- await featureAPI.updateWorkCoordSystem(drawingId, wCSId, wCSType, wCSRefs, coordinateSystem, offsetParam, rotationParam, inverted, local);
566
- return wCSId;
567
- }
568
- }
569
- return null;
570
- }, partId, references);
571
- },
572
- createWorkPlane: (partId, type, references, offset, angle, position, normal, local, name) => {
573
- return this.resolve(async ([rPartId, rReferences]) => {
574
- const wPType = getWPType(type);
575
- const wPName = name ? name : 'WorkPlane';
576
- const wPRefs = rReferences;
577
- if (wPType != undefined) {
578
- const wPId = await featureAPI.createWorkPlane(drawingId, rPartId, {
579
- planeType: wPType,
580
- references: wPRefs,
581
- offsetOrAngle: offset,
582
- name: wPName,
583
- position: position,
584
- normal: normal,
585
- local: local,
586
- });
587
- if (wPId != undefined) {
588
- const offsetParam = { value: offset, isExpr: typeof offset === 'string' };
589
- const angleParam = { value: angle, isExpr: typeof angle === 'string' };
590
- const positionParam = {
591
- value: position,
592
- isExpr: typeof position === 'string',
593
- };
594
- const normalParam = { value: normal, isExpr: typeof normal === 'string' };
595
- await featureAPI.updateWorkPlane(drawingId, wPId, wPType, wPRefs, offsetParam, angleParam, positionParam, normalParam, local);
596
- return wPId;
597
- }
598
- }
599
- return null;
600
- }, partId, references);
601
- },
602
- createWorkPoint: (partId, type, references, position, local, name) => {
603
- return this.resolve(async ([rPartId, rReferences]) => {
604
- const wPTType = getWPTType(type);
605
- const wPTName = name ? name : 'WorkPoint';
606
- const wPTRefs = rReferences;
607
- if (wPTType != undefined) {
608
- const wPTId = await featureAPI.createWorkPoint(drawingId, rPartId, {
609
- pointType: wPTType,
610
- references: wPTRefs,
611
- name: wPTName,
612
- position: position,
613
- local: local,
614
- });
615
- if (wPTId != undefined) {
616
- const positionParam = {
617
- value: position,
618
- isExpr: typeof position === 'string',
619
- };
620
- await featureAPI.updateWorkPoint(drawingId, wPTId, wPTType, wPTRefs, positionParam, local);
621
- return wPTId;
622
- }
623
- }
624
- return null;
625
- }, partId, references);
626
- },
627
- fillet: (partId, references, radius) => {
628
- return this.resolve(async ([rPartId, ...rReferences]) => {
629
- const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
630
- const filletId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCConstantRadiusFillet, 'Fillet');
631
- if (filletId != null) {
632
- await featureAPI.updateFillet(drawingId, filletId, rReferences, radiusParam);
633
- return filletId;
634
- }
635
- return null;
636
- }, partId, ...references);
637
- },
638
- getAssemblyFromContainer: (asmName) => {
639
- return this.resolve(async ([]) => {
640
- const asmIds = classcad_1.ccUtils.assembly.getAssemblyFromContainer(drawingId, asmName);
641
- if (asmIds != undefined) {
642
- return Array.isArray(asmIds) ? asmIds : [asmIds];
643
- }
644
- return null;
645
- });
646
- },
647
- getAssemblyNode: (refId, nodeName) => {
648
- return this.resolve(async ([rRefId]) => {
649
- const nodeIds = classcad_1.ccUtils.assembly.getAssemblyNode(drawingId, rRefId, nodeName);
650
- if (nodeIds != undefined) {
651
- return Array.isArray(nodeIds) ? nodeIds : [nodeIds];
652
- }
653
- return null;
654
- }, refId);
655
- },
656
- getPartFromContainer: (partName) => {
657
- return this.resolve(async ([]) => {
658
- const partIds = classcad_1.ccUtils.assembly.getPartFromContainer(drawingId, partName);
659
- if (partIds != undefined) {
660
- return Array.isArray(partIds) ? partIds : [partIds];
661
- }
662
- return null;
663
- });
664
- },
665
- getWorkCoordSystem: (refId, wcsName) => {
666
- return this.resolve(async ([rRefId]) => {
667
- const wcsIds = classcad_1.ccUtils.assembly.getWorkCoordSystem(drawingId, rRefId, wcsName);
668
- if (wcsIds != undefined) {
669
- return Array.isArray(wcsIds) ? wcsIds : [wcsIds];
670
- }
671
- return null;
672
- }, refId);
673
- },
674
- getConstraint: (refId, constrName) => {
675
- return this.resolve(async ([rRefId]) => {
676
- const constrIds = classcad_1.ccUtils.assembly.getConstraint(drawingId, rRefId, constrName);
677
- if (constrIds != undefined) {
678
- return Array.isArray(constrIds) ? constrIds : [constrIds];
679
- }
680
- return null;
681
- }, refId);
682
- },
683
- getFeatureByName: (partId, featureName) => {
684
- return this.resolve(async ([rProductId]) => {
685
- const solid = await featureAPI.getFeatureByName(drawingId, rProductId, featureName);
686
- if (solid !== null) {
687
- return solid;
688
- }
689
- return null;
690
- }, partId);
691
- },
692
- removeNode: (referenceId, ownerId) => {
693
- return this.resolve(async ([rReferenceId, rOwnerId]) => {
694
- await classcad_1.ccAPI.assemblyBuilder.removeNode(drawingId, rReferenceId, rOwnerId);
695
- }, referenceId, ownerId);
696
- },
697
- removeNodes: (...nodes) => {
698
- return this.resolve(async ([]) => {
699
- const nodesToRemove = [];
700
- nodes.forEach(node => {
701
- nodesToRemove.push([node.referenceId, node.ownerId]);
702
- });
703
- return classcad_1.ccAPI.assemblyBuilder.removeNodes(drawingId, nodesToRemove);
704
- });
705
- },
706
- importFeature: (partId, content, format, name) => {
707
- return this.resolve(async ([rPartId]) => {
708
- const featureName = name ? name : 'Import';
709
- const importFeatureId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCImport, featureName);
710
- if (importFeatureId !== null) {
711
- const solids = await featureAPI.loadGeometryStreamToImportFeature(drawingId, importFeatureId, content, format);
712
- if (solids !== null) {
713
- return importFeatureId;
714
- }
715
- }
716
- return null;
717
- }, partId);
718
- },
719
- translate: (partId, featureIds, references, inverted, distance) => {
720
- return this.resolve(async ([rPartId, rFeatureIds, rReferences]) => {
721
- const translationId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCTranslation, 'Translate');
722
- if (translationId !== null) {
723
- const cDrawing = await core_1.getDrawing(drawingId);
724
- const entArray = [];
725
- for (const rFeatureId of rFeatureIds) {
726
- const entity = cDrawing.structure.tree[rFeatureId].children;
727
- if (entity != undefined) {
728
- entArray.push(entity[0]);
729
- }
730
- }
731
- const dist = { value: distance, isExpr: typeof distance === 'string' };
732
- await featureAPI.updateTransformation(drawingId, translationId, entArray, rReferences, inverted, dist);
733
- return translationId;
734
- }
735
- return null;
736
- }, partId, featureIds, references);
737
- },
738
- updateTranslate: (translationId, distance) => {
739
- return this.resolve(async ([rTranslationId]) => {
740
- const cDrawing = await core_1.getDrawing(drawingId);
741
- const members = cDrawing.structure.tree[rTranslationId].members;
742
- if (members !== null && members !== undefined) {
743
- const entArray = members['bodiesToTransform'].members.map(m => m.value);
744
- const references = members['references'].members.map(m => m.value);
745
- const inverted = members['inverted'].value;
746
- const dist = distance !== null ? distance : members['translationDistance'].value;
747
- const distParam = { value: dist, isExpr: typeof distance === 'string' };
748
- await featureAPI.openFeature(drawingId, rTranslationId);
749
- await featureAPI.updateTransformation(drawingId, rTranslationId, entArray, references, inverted, distParam);
750
- await featureAPI.closeFeature(drawingId, rTranslationId);
751
- }
752
- }, translationId);
753
- },
754
- save: (type) => {
755
- return classcad_1.ccAPI.baseModeler.save(drawingId, type);
756
- },
757
- load: (content, type) => {
758
- return classcad_1.ccAPI.baseModeler.load(drawingId, content, type);
759
- },
760
- loadProduct: (content, type) => {
761
- return classcad_1.ccAPI.assemblyBuilder.loadProduct(drawingId, content, type);
762
- },
763
- pick: (partId, type, points) => {
764
- return this.resolve(async ([rPartId]) => {
765
- const refs = await featureAPI.pick(drawingId, rPartId, type, points);
766
- if (refs != undefined) {
767
- return Array.isArray(refs) ? refs : [refs];
768
- }
769
- return null;
770
- }, partId);
771
- },
772
- setExpressions: (partId, ...members) => {
773
- return this.resolve(async (resolvedArgs) => {
774
- const membersToModify = [];
775
- members.forEach(mem => {
776
- const isExpr = typeof mem.value === 'string'; // TODO Expression unterscheiden von normalen STrings
777
- const featureAPIParam = {
778
- value: mem.value,
779
- isExpr: isExpr,
780
- };
781
- membersToModify.push([mem.name, featureAPIParam]);
782
- });
783
- const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], [], membersToModify, []);
784
- return success;
785
- }, partId);
786
- },
787
- deleteExpressions: (partId, members) => {
788
- return this.resolve(async (resolvedArgs) => {
789
- const success = featureAPI.updateExpressionSet(drawingId, resolvedArgs[0], [], [], members);
790
- return success;
791
- }, partId);
792
- },
793
- sphere: (partId, references, radius) => {
794
- return this.resolve(async ([rPartId]) => {
795
- const sphereId = await featureAPI.createFeature(drawingId, rPartId, classcad_1.CCClasses.CCSphere, 'Sphere');
796
- if (sphereId != null) {
797
- const radiusParam = { value: radius, isExpr: typeof radius === 'string' };
798
- await featureAPI.updateSphere(drawingId, sphereId, references, radiusParam);
799
- return sphereId;
800
- }
801
- return null;
802
- }, partId);
803
- },
804
- };
805
- callback(publicApi);
806
- resolve(drawingId);
807
- });
808
- return () => promise.then(drawingId => core_1.api.getState().api.removeDrawing(drawingId));
809
- }
810
- destroy() {
811
- this.drawingId && core_1.api.getState().api.removeDrawing(this.drawingId);
812
- }
813
- }
814
- exports.default = CAD;
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __importDefault = (this && this.__importDefault) || function (mod) {
22
- return (mod && mod.__esModule) ? mod : { "default": mod };
23
- };
24
- Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.createPolyline = exports.history = exports.solid = void 0;
26
- const history_1 = __importDefault(require("./history"));
27
- exports.history = history_1.default;
28
- const solid_1 = __importStar(require("./solid"));
29
- exports.solid = solid_1.default;
30
- Object.defineProperty(exports, "createPolyline", { enumerable: true, get: function () { return solid_1.createPolyline; } });
31
- //#endregion Re-export type definitions
@@ -1,352 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.createPolyline = void 0;
23
- /* eslint-disable max-lines */
24
- const classcad_1 = require("@buerli.io/classcad");
25
- const core_1 = require("@buerli.io/core");
26
- const three_1 = require("three");
27
- const BufferGeometryUtils_ = __importStar(require("three/examples/jsm/utils/BufferGeometryUtils"));
28
- let BufferGeometryUtils = BufferGeometryUtils_;
29
- if (BufferGeometryUtils.BufferGeometryUtils) {
30
- BufferGeometryUtils = BufferGeometryUtils.BufferGeometryUtils;
31
- }
32
- // Qeued execute, returns the first result and expects it to be an ObjectID or
33
- // a stream, in case of save() or export() is called
34
- const exec = (instance, drawing, namespace, fn, stream, returnStream, ...args) => {
35
- return (instance.queue = instance.queue.then(() => Promise.all(args).then(resolvedArgs => {
36
- return classcad_1.ccAPI.base.callSafeAPI(drawing, namespace, fn, resolvedArgs, stream).then(res => {
37
- if (returnStream) {
38
- return (res && res.results);
39
- }
40
- else {
41
- return (res && res.results[0].result);
42
- }
43
- });
44
- })));
45
- };
46
- const toCCVec = (args) => ({ x: args[0], y: args[1], z: args[2] });
47
- const toArray = (v) => (Array.isArray(v) ? v : v.toArray());
48
- const toEuler = (v) => toArray(v);
49
- const makeVec = (v) => toCCVec(toArray(v));
50
- const makeEuler = (v) => toCCVec(toEuler(v));
51
- const makeBoolean = (instance, drawingId, type) => (target, keepSolid, ...bodies) => {
52
- for (const body of bodies)
53
- exec(instance, drawingId, 'Solid', type, undefined, false, target, keepSolid, body);
54
- return target;
55
- };
56
- /**
57
- * Returns the entity of solid from structure tree
58
- * @param drawingId Id of current drawing
59
- * @param solid Solid to get entity from
60
- */
61
- const getEntity = async (drawingId, solid) => {
62
- const rSolid = await solid;
63
- const cDrawing = core_1.getDrawing(drawingId);
64
- const object = cDrawing.structure.tree[rSolid];
65
- if (object != undefined) {
66
- const entities = object.geometryIdList;
67
- if (entities != undefined && entities.length > 0) {
68
- return cDrawing.geometry.cache[entities[0]];
69
- }
70
- else {
71
- console.warn(`There is no cached entry for ${rSolid}!`, cDrawing.geometry.cache);
72
- return null;
73
- }
74
- }
75
- else {
76
- console.warn(`There is no cached entry for ${rSolid}!`, cDrawing.geometry.cache);
77
- return null;
78
- }
79
- };
80
- /**
81
- * Returns the adjacent points of the fillet arc. These are the points where fillet arc tangentially touches the lines.
82
- * @param info contains all information for the fillet, like start- and endpoints of adjacent lines and control point
83
- * @param radius radius of the fillet arc
84
- */
85
- const getTouchPoints = (info, radius) => {
86
- const controlPos = info.control;
87
- const linearTolerance = 1e-3;
88
- const dirs = [];
89
- const maxDists = [];
90
- for (let i = 0; i < 2; i++) {
91
- const startPos = info.lineStarts[i];
92
- const endPos = info.lineEnds[i];
93
- const dir = endPos
94
- .clone()
95
- .sub(startPos)
96
- .normalize();
97
- const maxDist = endPos.distanceTo(controlPos);
98
- dirs.push(dir);
99
- maxDists.push(maxDist);
100
- }
101
- if (radius + linearTolerance >= Math.min(maxDists[0], maxDists[1])) {
102
- return null; // too large fillet
103
- }
104
- // Calculate distance from controlpt to touchpoint
105
- const scalar = Math.abs(radius / Math.tan(getIncludingAngle(info) / 2));
106
- return dirs.map(dir => dir
107
- .clone()
108
- .multiplyScalar(scalar)
109
- .add(controlPos));
110
- };
111
- /**
112
- * Calculates the including angle between two lines. The angle is measured from first to second line counterclockwise. If angle exceeds 180°, measuring is clockwise but negative angle
113
- * @param info Info contains information about lines
114
- */
115
- const getIncludingAngle = (info) => {
116
- // First line (line to point)
117
- const line1 = info.lineEnds[0]
118
- .clone()
119
- .sub(info.lineStarts[0])
120
- .normalize();
121
- // Second line (line from point)
122
- const line2 = info.lineEnds[1]
123
- .clone()
124
- .sub(info.lineStarts[1])
125
- .normalize();
126
- // Angle, measured from first line to second line counterclockwise.
127
- // If angle exceeds 180°, measuring is clockwise but negative angle
128
- const angle = Math.atan2(line1.x * line2.y - line1.y * line2.x, line1.x * line2.x + line1.y * line2.y);
129
- return angle;
130
- };
131
- /**
132
- * Calculates and returns the including angle between the touchpoints of the fillet. Attention: It is the angle of touchpoints and center of fillet arc and not the one between touchpoints and control point.
133
- * @param info
134
- */
135
- const getIncludingBulgeAngle = (info) => {
136
- // angle of first line, control point and second line
137
- const angle = getIncludingAngle(info);
138
- // Opposite angle of the angle which was calculated from control point and its adjacent lines
139
- const oppositeAngle = Math.PI - Math.abs(angle);
140
- const sign = angle / Math.abs(angle);
141
- return oppositeAngle * sign * -1; // -1 because of bulges definition
142
- };
143
- /**
144
- * Creates a polyline from the given fillet points
145
- * @param fPts points of the polyline with its associated fillet radius
146
- * @example
147
- * // Creates a polyline with three points
148
- * const fp0 = { point: new THREE.Vector3(20, 20, 0), radius: 4 }
149
- * const fp1 = { point: new THREE.Vector3(40, 0, 0), radius: 2 }
150
- * const fp2 = { point: new THREE.Vector3(0, 0, 0), radius: 2 }
151
- * const polyline = createPolyline([fp0, fp1, fp2])
152
- */
153
- function createPolyline(fPts) {
154
- const newVertices = [];
155
- const newBulges = [];
156
- for (let i = 0; i < fPts.length; i++) {
157
- // if fillet point has radius, calculate fillet info, touchpoints and bulge
158
- if (fPts[i].radius > 0) {
159
- const j = i - 1 < 0 ? fPts.length - 1 : i - 1;
160
- const k = i + 1 > fPts.length - 1 ? 0 : i + 1;
161
- const filletInfo = {
162
- control: fPts[i].point,
163
- lineStarts: [fPts[i].point, fPts[i].point],
164
- lineEnds: [fPts[j].point, fPts[k].point],
165
- };
166
- const touchPts = getTouchPoints(filletInfo, fPts[i].radius); // returns two points
167
- if (touchPts != undefined && (touchPts === null || touchPts === void 0 ? void 0 : touchPts.length) > 0) {
168
- const angle = getIncludingBulgeAngle(filletInfo);
169
- const bulge = Math.tan(angle / 4);
170
- newVertices.push(...touchPts);
171
- newBulges.push(bulge); // bulge for first point
172
- newBulges.push(0); // bulge for second point
173
- }
174
- }
175
- else {
176
- newVertices.push(fPts[i].point);
177
- newBulges.push(0);
178
- }
179
- }
180
- return { points: newVertices, bulges: newBulges };
181
- }
182
- exports.createPolyline = createPolyline;
183
- /**
184
- * Creates the specific curve array from THREE.Shape.curves to draw the region in ClassCAD. It contains the type and all necessary points and control points in a multidimensional array.
185
- * @param curves THREE.Shape.curves
186
- */
187
- const makeCCData = (curves) => {
188
- return curves.map((curve) => {
189
- switch (curve.type) {
190
- // [pStart, p1, p2, p3]
191
- case 'CubicBezierCurve':
192
- return [curve.type, curve.v0.toArray(), curve.v1.toArray(), curve.v2.toArray(), curve.v3.toArray()];
193
- // [pStart, p1, p2]
194
- case 'QuadraticBezierCurve':
195
- return [curve.type, curve.v0.toArray(), curve.v1.toArray(), curve.v2.toArray()];
196
- // [p1, p2]
197
- case 'LineCurve':
198
- return [curve.type, curve.v1.toArray(), curve.v2.toArray()];
199
- // [...points]
200
- case 'SplineCurve':
201
- return [curve.type, curve.points.map((point) => point.toArray())];
202
- // [pA, radii, angles, clockwise, rotation]
203
- case 'EllipseCurve':
204
- case 'ArcCurve':
205
- const { aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation } = curve;
206
- return [
207
- curve.type,
208
- [aX, aY],
209
- [xRadius, yRadius],
210
- [(aStartAngle / Math.PI) * 180, (aEndAngle / Math.PI) * 180],
211
- aClockwise,
212
- aRotation,
213
- ];
214
- default:
215
- return undefined;
216
- }
217
- });
218
- };
219
- class CAD {
220
- constructor(target) {
221
- this.drawingId = null;
222
- this.queue = Promise.resolve(0);
223
- this.queue = Promise.resolve(0);
224
- if (typeof target !== 'string')
225
- this.target = target;
226
- core_1.init({ url: typeof target === 'string' ? target : '' });
227
- }
228
- init(callback) {
229
- const promise = new Promise(async (resolve, reject) => {
230
- const drawingId = await classcad_1.ccAPI.base.createCCDrawing('solid', this.target);
231
- if (!drawingId)
232
- throw new Error('Drawing could not be created');
233
- this.drawingId = drawingId;
234
- await exec(this, drawingId, 'Solid', 'Init', undefined, false);
235
- const publicApi = {
236
- box: (length, width, height) => exec(this, drawingId, 'Solid', 'CreateBox', undefined, false, length, width, height),
237
- clearSolids: () => exec(this, drawingId, 'Solid', 'ClearSolids', undefined, false),
238
- clearSolid: (target) => exec(this, drawingId, 'Solid', 'ClearSolid', undefined, false, target),
239
- cone: (length, diameter1, diameter2) => exec(this, drawingId, 'Solid', 'CreateCone', undefined, false, length, diameter1, diameter2),
240
- copy: (target) => exec(this, drawingId, 'Solid', 'Copy', undefined, false, target),
241
- createBufferGeometry: async (solid) => {
242
- await this.queue;
243
- this.queue = Promise.resolve(0);
244
- const rSolid = await solid;
245
- await classcad_1.ccAPI.baseModeler.requestVisualisationOfObject(drawingId, rSolid);
246
- const entity = await getEntity(drawingId, rSolid);
247
- if (entity != null) {
248
- return BufferGeometryUtils.mergeBufferGeometries(entity.meshes.map(m => m.geometry));
249
- }
250
- },
251
- createScene: async (solid) => {
252
- await this.queue;
253
- this.queue = Promise.resolve(0);
254
- const rSolid = await solid;
255
- await classcad_1.ccAPI.baseModeler.requestVisualisationOfObject(drawingId, rSolid);
256
- const entity = await getEntity(drawingId, rSolid);
257
- const group = new three_1.Scene();
258
- group.userData = { id: rSolid };
259
- if (entity != null) {
260
- for (const mesh of entity.meshes) {
261
- group.add(new three_1.Mesh(mesh.geometry, new three_1.MeshStandardMaterial({
262
- color: mesh.color,
263
- transparent: mesh.opacity < 1,
264
- opacity: mesh.opacity,
265
- })));
266
- }
267
- }
268
- return group;
269
- },
270
- cylinder: (length, diameter) => exec(this, drawingId, 'Solid', 'CreateCylinder', undefined, false, length, diameter),
271
- edgeLoops: (target) => exec(this, drawingId, 'Solid', 'EdgeLoops', undefined, false, target).then(async (id) => {
272
- return Array.isArray(id) ? id : [id];
273
- }),
274
- export: (solidIds) => exec(this, drawingId, 'Solid', 'Export', undefined, true, null, 'stp', solidIds).then(async (resp) => {
275
- if (resp && resp[0].result) {
276
- const res = resp[0];
277
- const key = res.result;
278
- if (key && res.streamData) {
279
- return res.streamData[key] || null;
280
- }
281
- }
282
- }),
283
- extendSolidAtPlane: (target, point, normal, distance) => exec(this, drawingId, 'Solid', 'SolidExtendAtPlane', undefined, false, target, makeVec(point), makeVec(normal), distance),
284
- extrude: (height, region) => {
285
- if (region instanceof three_1.Shape) {
286
- const curveArray = makeCCData(region.curves);
287
- return exec(this, drawingId, 'Solid', 'CreateExtrudeRegion', undefined, false, makeVec(height), curveArray);
288
- }
289
- else {
290
- return exec(this, drawingId, 'Solid', 'CreateExtrude', undefined, false, makeVec(height), region.points, region.bulges);
291
- }
292
- },
293
- fillet: (radius, edges) => exec(this, drawingId, 'Solid', 'CreateFillet', undefined, false, radius, edges),
294
- import: (data) => exec(this, drawingId, 'Solid', 'Import', { data }, false, 'data', 'stp').then(async (id) => {
295
- return Array.isArray(id) ? id : [id];
296
- }),
297
- intersect: makeBoolean(this, drawingId, 'Intersect'),
298
- load: (data) => exec(this, drawingId, 'Solid', 'Load', { data }, false, 'data', 'of1', true).then(async (id) => {
299
- if (id !== null) {
300
- const drawing = core_1.getDrawing(drawingId);
301
- const solids = drawing.structure.tree[id].solids;
302
- if (solids !== undefined) {
303
- return solids.map(innerId => drawing.graphic.containers[innerId].owner);
304
- }
305
- }
306
- return [];
307
- }),
308
- mirror: (target, point, normal) => exec(this, drawingId, 'Solid', 'Mirror', undefined, false, target, makeVec(point), makeVec(normal)),
309
- moveTo: (target, position) => exec(this, drawingId, 'Solid', 'MoveTo', undefined, false, target, makeVec(position)),
310
- offset: (target, offsetDistance) => exec(this, drawingId, 'Solid', 'Offset', undefined, false, target, offsetDistance),
311
- pick: (target, type, ...points) => exec(this, drawingId, 'Solid', 'Pick', undefined, false, target, type, points.map(makeVec)).then(async (id) => {
312
- return Array.isArray(id) ? id : [id];
313
- }),
314
- revolve: (position, direction, angle, region) => {
315
- if (region instanceof three_1.Shape) {
316
- const curveArray = makeCCData(region.curves);
317
- return exec(this, drawingId, 'Solid', 'CreateRevolveRegion', undefined, false, makeVec(position), makeVec(direction), angle, curveArray);
318
- }
319
- else {
320
- return exec(this, drawingId, 'Solid', 'CreateRevolve', undefined, false, makeVec(position), makeVec(direction), (angle / Math.PI) * 180, region.points, region.bulges);
321
- }
322
- },
323
- rotateTo: (target, point) => exec(this, drawingId, 'Solid', 'RotateTo', undefined, false, target, makeEuler(point)),
324
- save: () => exec(this, drawingId, 'Solid', 'Save', undefined, true, null, 'of1').then(async (resp) => {
325
- if (resp && resp[0].result) {
326
- const res = resp[0];
327
- const key = res.result;
328
- if (key && res.streamData) {
329
- return res.streamData[key] || null;
330
- }
331
- }
332
- }),
333
- scale: (target, pointOrFactor) => {
334
- const lPointOrFactor = typeof pointOrFactor === 'number' ? pointOrFactor : makeVec(pointOrFactor);
335
- return exec(this, drawingId, 'Solid', 'Scale', undefined, false, target, lPointOrFactor);
336
- },
337
- setFacetingParams: (distanceTol, angleTol) => exec(this, drawingId, 'BaseModeler', 'SetFacetingParams', undefined, false, distanceTol, angleTol),
338
- slice: (target, point, normal) => exec(this, drawingId, 'Solid', 'Slice', undefined, false, target, makeVec(point), makeVec(normal)),
339
- sphere: (radius) => exec(this, drawingId, 'Solid', 'CreateSphere', undefined, false, radius),
340
- subtract: makeBoolean(this, drawingId, 'Subtract'),
341
- union: makeBoolean(this, drawingId, 'Union'),
342
- };
343
- callback(publicApi);
344
- resolve(drawingId);
345
- });
346
- return () => promise.then(drawingId => core_1.api.getState().api.removeDrawing(drawingId));
347
- }
348
- destroy() {
349
- this.drawingId && core_1.api.getState().api.removeDrawing(this.drawingId);
350
- }
351
- }
352
- exports.default = CAD;