@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.
Files changed (108) hide show
  1. package/README.md +20 -2
  2. package/bin/buerli-classcad.cjs +23 -0
  3. package/build/cjs/BuerliCadFacade.js +718 -0
  4. package/build/cjs/cclass/utils/assembly.js +687 -0
  5. package/build/cjs/cclass/utils/base.js +136 -0
  6. package/build/cjs/cclass/utils/index.js +99 -0
  7. package/build/cjs/cclass/utils/part.js +153 -0
  8. package/build/cjs/classcadEngine.js +33 -0
  9. package/build/cjs/createApi.js +71 -0
  10. package/build/cjs/createUnwrappedApi.js +43 -0
  11. package/build/cjs/facade.js +103 -0
  12. package/build/cjs/globals.js +157 -0
  13. package/build/cjs/index.js +102 -0
  14. package/build/cjs/io/AwvNodeClient.js +290 -0
  15. package/build/cjs/io/SocketIOClient.js +339 -0
  16. package/build/cjs/io/Transaction.js +134 -0
  17. package/build/cjs/io/WASMClient.js +433 -0
  18. package/build/cjs/io/WSClient.js +646 -0
  19. package/build/cjs/io/engineKey.js +202 -0
  20. package/build/cjs/re-export.js +35 -0
  21. package/build/cjs/session/host.js +479 -0
  22. package/build/cjs/session/identity.js +38 -0
  23. package/build/cjs/session/selection.js +283 -0
  24. package/build/cjs/session/share.js +229 -0
  25. package/build/cjs/session/types.js +23 -0
  26. package/build/cjs/test/SocketIOClient.spec.js +178 -0
  27. package/build/cjs/types/ComClient.js +10 -0
  28. package/build/cjs/utils/createRecursiveBufferGeometry.js +55 -0
  29. package/build/cjs/utils/createRecursiveScene.js +140 -0
  30. package/build/cjs/utils/getDifferentColoredMeshesFromEntity.js +24 -0
  31. package/build/cjs/utils/index.js +20 -0
  32. package/build/cjs/utils/polyline.js +65 -0
  33. package/build/cjs/utils/waitForSelect.js +29 -0
  34. package/build/esm/BuerliCadFacade.js +714 -0
  35. package/build/esm/cclass/utils/assembly.js +665 -0
  36. package/build/esm/cclass/utils/base.js +127 -0
  37. package/build/esm/cclass/utils/index.js +62 -0
  38. package/build/esm/cclass/utils/part.js +144 -0
  39. package/build/esm/classcadEngine.js +30 -0
  40. package/build/esm/createApi.js +66 -0
  41. package/build/esm/createUnwrappedApi.js +39 -0
  42. package/build/esm/facade.js +98 -0
  43. package/build/esm/globals.js +150 -0
  44. package/build/esm/index.js +80 -0
  45. package/build/esm/io/AwvNodeClient.js +286 -0
  46. package/build/esm/io/SocketIOClient.js +332 -0
  47. package/build/esm/io/Transaction.js +130 -0
  48. package/build/esm/io/WASMClient.js +429 -0
  49. package/build/esm/io/WSClient.js +642 -0
  50. package/build/esm/io/engineKey.js +196 -0
  51. package/build/esm/re-export.js +3 -0
  52. package/build/esm/session/host.js +474 -0
  53. package/build/esm/session/identity.js +34 -0
  54. package/build/esm/session/selection.js +277 -0
  55. package/build/esm/session/share.js +221 -0
  56. package/build/esm/session/types.js +20 -0
  57. package/build/esm/test/SocketIOClient.spec.js +178 -0
  58. package/build/esm/types/ComClient.js +7 -0
  59. package/build/esm/utils/createRecursiveBufferGeometry.js +51 -0
  60. package/build/esm/utils/createRecursiveScene.js +136 -0
  61. package/build/esm/utils/getDifferentColoredMeshesFromEntity.js +20 -0
  62. package/build/esm/utils/index.js +4 -0
  63. package/build/esm/utils/polyline.js +60 -0
  64. package/build/esm/utils/waitForSelect.js +23 -0
  65. package/build/types/BuerliCadFacade.d.ts +410 -0
  66. package/build/types/cclass/utils/assembly.d.ts +180 -0
  67. package/build/types/cclass/utils/base.d.ts +55 -0
  68. package/build/types/cclass/utils/index.d.ts +46 -0
  69. package/build/types/cclass/utils/part.d.ts +46 -0
  70. package/build/types/classcadEngine.d.ts +40 -0
  71. package/build/types/createApi.d.ts +65 -0
  72. package/build/types/createUnwrappedApi.d.ts +36 -0
  73. package/build/types/facade.d.ts +9 -0
  74. package/build/types/globals.d.ts +79 -0
  75. package/build/types/index.d.ts +82 -0
  76. package/build/types/io/AwvNodeClient.d.ts +182 -0
  77. package/build/types/io/SocketIOClient.d.ts +84 -0
  78. package/build/types/io/Transaction.d.ts +56 -0
  79. package/build/types/io/WASMClient.d.ts +239 -0
  80. package/build/types/io/WSClient.d.ts +242 -0
  81. package/build/types/io/engineKey.d.ts +137 -0
  82. package/build/types/re-export.d.ts +6 -0
  83. package/build/types/session/host.d.ts +108 -0
  84. package/build/types/session/identity.d.ts +46 -0
  85. package/build/types/session/selection.d.ts +164 -0
  86. package/build/types/session/share.d.ts +131 -0
  87. package/build/types/session/types.d.ts +113 -0
  88. package/build/types/test/SocketIOClient.spec.d.ts +0 -0
  89. package/build/types/types/ComClient.d.ts +307 -0
  90. package/build/types/utils/createRecursiveBufferGeometry.d.ts +8 -0
  91. package/build/types/utils/createRecursiveScene.d.ts +24 -0
  92. package/build/types/utils/getDifferentColoredMeshesFromEntity.d.ts +14 -0
  93. package/build/types/utils/index.d.ts +4 -0
  94. package/build/types/utils/polyline.d.ts +43 -0
  95. package/build/types/utils/waitForSelect.d.ts +4 -0
  96. package/doc/api/advanced/connection.md +488 -0
  97. package/doc/api/clients.md +2045 -0
  98. package/doc/api/engine-keys.md +230 -0
  99. package/doc/api/index.md +58 -0
  100. package/doc/api/modeling.md +682 -0
  101. package/doc/api/other.md +33 -0
  102. package/doc/api/session-sharing.md +706 -0
  103. package/package.json +60 -4
  104. package/test/classcadEngine.test.cjs +44 -0
  105. package/test/connect.test.cjs +81 -0
  106. package/test/engineKey.test.cjs +80 -0
  107. package/test/onClient.test.cjs +82 -0
  108. package/typedoc.json +8 -0
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ // import {
3
+ // DEFAULT_STRUCTURE_TREE,
4
+ // DrawingAPI,
5
+ // IGraphicPackage,
6
+ // IStructureProtocol,
7
+ // IStructurePatch,
8
+ // } from '@classcad/sdkjs'
9
+ // import * as assert from 'assert'
10
+ // import { readFileSync } from 'fs'
11
+ // import { join, resolve } from 'path'
12
+ // import io from 'socket.io'
13
+ // import { SocketIOClient, SocketIOEvent } from './../SocketIOClient'
14
+ // const resDir = resolve(join(__dirname, '..', '..', 'res', 'test'))
15
+ // const readResFile = (file: string) => readFileSync(join(resDir, file), 'utf-8')
16
+ // class TestDrawing implements DrawingAPI {
17
+ // private _structureTree: IStructureProtocol = DEFAULT_STRUCTURE_TREE()
18
+ // private _graphicPackages: IGraphicPackage[] = []
19
+ // private _errors: ServerError[] = []
20
+ // public getStructure(): IStructureProtocol {
21
+ // return this._structureTree
22
+ // }
23
+ // public setStructure(tree: IStructureProtocol): void {
24
+ // this._structureTree = tree
25
+ // }
26
+ // public applyPatches(patches: IStructurePatch[]): void {
27
+ // //
28
+ // }
29
+ // public addPackages(graphic: IGraphicPackage[]): void {
30
+ // this._graphicPackages.push(...graphic)
31
+ // }
32
+ // public addError(error: ServerError): void {
33
+ // this._errors.push(error)
34
+ // }
35
+ // }
36
+ // describe('SocketIOClient', () => {
37
+ // let _client: SocketIOClient
38
+ // let _mockServer: io.Server
39
+ // before(() => {
40
+ // _client = new SocketIOClient()
41
+ // _mockServer = io().listen(62135)
42
+ // _mockServer.on('connection', (socket: io.Socket) => {
43
+ // socket.emit(SocketIOEvent.CONNECT)
44
+ // socket.on('disconnect', () => {
45
+ // console.info('user disconnected')
46
+ // })
47
+ // socket.on(SocketIOEvent.INIT, () => {
48
+ // socket.emit(SocketIOEvent.PERMISSION, { id: 1, version: '8.x.x' })
49
+ // })
50
+ // socket.on(SocketIOEvent.SEND, (transactionID, command, factory) => {
51
+ // socket.emit(SocketIOEvent.JSON, { from: 'BeginFrame', transactionID })
52
+ // switch (command.command) {
53
+ // case 'GetTree': {
54
+ // const result = JSON.parse(readResFile('getTreeResult.json'))
55
+ // socket.emit(SocketIOEvent.JSON, {
56
+ // command: 'Result',
57
+ // from: command.command,
58
+ // result,
59
+ // })
60
+ // break
61
+ // }
62
+ // default:
63
+ // break
64
+ // }
65
+ // socket.emit(SocketIOEvent.JSON, { from: 'EndFrame', transactionID })
66
+ // })
67
+ // })
68
+ // })
69
+ // after(() => {
70
+ // _mockServer.close()
71
+ // })
72
+ // afterEach(() => {
73
+ // _client.removeAllListeners()
74
+ // })
75
+ // it(`should connect/disconnect to/from the server`, function(this: any, done) {
76
+ // let alreadyDone = false
77
+ // const safeDone = (err?: any) => {
78
+ // !alreadyDone ? done(err) : null
79
+ // alreadyDone = true
80
+ // }
81
+ // _client.on('connected', (client, connected) => {
82
+ // try {
83
+ // assert.strictEqual(connected, true)
84
+ // assert.strictEqual(client['_id'], 1)
85
+ // assert.strictEqual(client['_version'], '8.x.x')
86
+ // } catch (error) {
87
+ // _client.disconnect().catch()
88
+ // safeDone(error)
89
+ // }
90
+ // console.info('connected')
91
+ // })
92
+ // _client
93
+ // .connect(getUrl())
94
+ // .then(client => {
95
+ // assert.strictEqual(client['_id'], 1)
96
+ // assert.strictEqual(client['_version'], '8.x.x')
97
+ // _client.disconnect().catch()
98
+ // })
99
+ // .then(() => {
100
+ // safeDone()
101
+ // })
102
+ // .catch(error => {
103
+ // _client.disconnect().catch()
104
+ // safeDone(error)
105
+ // })
106
+ // })
107
+ // it(`should fail to connect/disconnect to/from the server`, function(this: any, done) {
108
+ // this.skip()
109
+ // // done();
110
+ // })
111
+ // it(`should get the classcad tree by promise`, function(this: any, done) {
112
+ // const drawing = new TestDrawing()
113
+ // _client
114
+ // .connect(getUrl())
115
+ // .then(client => {
116
+ // return client.requestTree(drawing)
117
+ // })
118
+ // .then(response => {
119
+ // const tree = response.result[0] as IStructureProtocol
120
+ // assert.strictEqual(tree.root, 49)
121
+ // assert.strictEqual(tree.testRoot, 0)
122
+ // assert.strictEqual(Object.getOwnPropertyNames(tree).length, 53)
123
+ // // TODO: more tree testing
124
+ // done()
125
+ // _client.disconnect().catch()
126
+ // })
127
+ // .catch(error => {
128
+ // done(error)
129
+ // _client.disconnect().catch()
130
+ // })
131
+ // })
132
+ // it(`should get the classcad tree by observing`, function(this: any, done) {
133
+ // // /////////////
134
+ // // testing code
135
+ // // /////////////
136
+ // let alreadyDone = false
137
+ // const safeDone = (err?: any) => {
138
+ // !alreadyDone ? done(err) : null
139
+ // alreadyDone = true
140
+ // }
141
+ // const testTree = (tree: IStructureProtocol) => {
142
+ // try {
143
+ // assert.strictEqual(tree.root, 49)
144
+ // assert.strictEqual(tree.testRoot, 0)
145
+ // assert.strictEqual(Object.getOwnPropertyNames(tree).length, 53)
146
+ // // TODO: more tree testing
147
+ // } catch (error) {
148
+ // safeDone(error)
149
+ // }
150
+ // }
151
+ // // /////////////
152
+ // // execute the request
153
+ // // /////////////
154
+ // const drawing = new TestDrawing()
155
+ // _client
156
+ // .connect(getUrl())
157
+ // .then(client => {
158
+ // return client.requestTree(drawing, {
159
+ // onTreeChanged: (tree: IStructureProtocol) => {
160
+ // testTree(tree)
161
+ // testTree(drawing.getStructure())
162
+ // },
163
+ // })
164
+ // })
165
+ // .then(response => {
166
+ // testTree(drawing.getStructure())
167
+ // safeDone()
168
+ // _client.disconnect().catch()
169
+ // })
170
+ // .catch(error => {
171
+ // safeDone(error)
172
+ // _client.disconnect().catch()
173
+ // })
174
+ // })
175
+ // })
176
+ // function getUrl(): string {
177
+ // return 'http://localhost:62135'
178
+ // }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * `Error.name` of the rejection when the engine does not support GetEmissionConfig/SetEmissionConfig.
3
+ *
4
+ * @advanced
5
+ * @category Connection
6
+ */
7
+ export const EMISSION_CONFIG_UNSUPPORTED = 'EmissionConfigUnsupported';
@@ -0,0 +1,51 @@
1
+ import { getDrawing } from '@classcad/sdkjs';
2
+ import { mergeBufferGeometries } from 'three-stdlib';
3
+ import { createApi } from '../createApi';
4
+ /**
5
+ * Helps to create the buffer geometry of the given object recursively.
6
+ * @param object object to create the buffergeometry from
7
+ * @param bufferGeomArray array to fill up with buffert geometries
8
+ */
9
+ export const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray) => {
10
+ let cDrawing = getDrawing(drawingId);
11
+ const tree = cDrawing.structure.tree;
12
+ if (object.link || object.solids || object.geometryIdList) {
13
+ // Part or Solid
14
+ const baseModeler = createApi(drawingId).v0.baseModeler;
15
+ const solids = object.link ? tree[object.link].solids : object.solids ? object.solids : object.geometryIdList;
16
+ if (solids != undefined) {
17
+ let geometries = [];
18
+ for (const solid of solids) {
19
+ let cachedSolid = cDrawing.geometry.cache[solid];
20
+ if (cachedSolid) {
21
+ // if solid already cached, take it from cache
22
+ geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
23
+ }
24
+ else {
25
+ // else get visualisation from classcad
26
+ await baseModeler.requestVisualisationOfEntities([solid]);
27
+ cDrawing = getDrawing(drawingId); // get current drawing state after request
28
+ cachedSolid = cDrawing.geometry.cache[solid];
29
+ if (cachedSolid) {
30
+ geometries = [...geometries, ...cachedSolid.meshes.map(m => m.geometry)];
31
+ }
32
+ else {
33
+ console.warn(`There is no cached entry for ${solid}!`, cDrawing.geometry.cache);
34
+ }
35
+ }
36
+ }
37
+ if (geometries.length > 0) {
38
+ const transformation = cDrawing.api.structure.calculateGlobalTransformation(object.id);
39
+ const bufferGeom = mergeBufferGeometries(geometries);
40
+ bufferGeom.applyMatrix4(transformation);
41
+ bufferGeomArray.push(bufferGeom);
42
+ }
43
+ }
44
+ }
45
+ else if (object.children) {
46
+ // Assembly or Entity
47
+ for (const child of object.children) {
48
+ await createRecursiveBufferGeometry(tree[child], drawingId, bufferGeomArray);
49
+ }
50
+ }
51
+ };
@@ -0,0 +1,136 @@
1
+ import { getDrawing, MathUtils } from '@classcad/sdkjs';
2
+ import { Group, Matrix4, Mesh, MeshStandardMaterial } from 'three';
3
+ import { mergeBufferGeometries } from 'three-stdlib';
4
+ import { createApi } from '../createApi';
5
+ import { getDifferentColoredMeshesFromEntity } from './getDifferentColoredMeshesFromEntity';
6
+ /**
7
+ * We traverse recursively over structure tree, starting with object and create THREE objects
8
+ * for the scene. Each part or assembly will be turned into groups and subgroups. Solids which are children of the
9
+ * parts will be turned into groups as well. Children of solids will be merged to meshes. Faces of a solid with different color
10
+ * or transparency will get its own mesh.
11
+ * @param object root object where we start building the three scene
12
+ * @param drawingId id of the drawing
13
+ * @param root the root of the scene
14
+ * @param result object containing all the current collected nodes, solids, meshes
15
+ * @param options e.g. meshPerGeometry controls if each geometry element gets a own mesh or if they will be combined/merged
16
+ */
17
+ export const createRecursiveScene = async (object, drawingId, root, result, options) => {
18
+ let cDrawing = getDrawing(drawingId);
19
+ const tree = cDrawing.structure.tree;
20
+ if (object.link || object.solids || object.geometryIdList) {
21
+ // Part or Solid
22
+ const baseModeler = createApi(drawingId).v0.baseModeler;
23
+ const entities = object.link ? tree[object.link].solids : object.solids ? object.solids : object.geometryIdList;
24
+ if (entities != undefined) {
25
+ const part = new Group();
26
+ const matrix = object.coordinateSystem ? MathUtils.convertToMatrix4(object.coordinateSystem) : new Matrix4();
27
+ matrix.decompose(part.position, part.quaternion, part.scale);
28
+ part.updateMatrix();
29
+ part.userData = { id: object.id }; // instance id
30
+ part.name = object.name; // instance name
31
+ for (const entity of entities) {
32
+ let cachedEntity = cDrawing.geometry.cache[entity];
33
+ if (!cachedEntity) {
34
+ // else get visualisation from classcad
35
+ await baseModeler.requestVisualisationOfEntities([entity]);
36
+ cDrawing = getDrawing(drawingId); // get current drawing state after request
37
+ cachedEntity = cDrawing.geometry.cache[entity];
38
+ }
39
+ if (cachedEntity && cachedEntity.meshes.length > 0) {
40
+ const solidObject = cDrawing.structure.tree[cachedEntity.container.ownerId];
41
+ if (solidObject) {
42
+ const _solid = new Group();
43
+ _solid.name = solidObject.name + '_solid';
44
+ _solid.userData = { id: solidObject.id }; // add solid id to the userData
45
+ result.nodes[_solid.name] = _solid;
46
+ result.nodes[`${solidObject.id}`] = _solid;
47
+ if (options === null || options === void 0 ? void 0 : options.meshPerGeometry) {
48
+ // Create a mesh for each geometry element
49
+ cachedEntity.meshes.forEach((m, i) => {
50
+ const mesh = new Mesh();
51
+ mesh.name = solidObject.name + '_' + i;
52
+ mesh.userData = { id: m.graphicId }; // add graphic id to the userData
53
+ if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
54
+ mesh.geometry = m.geometry;
55
+ mesh.material = new MeshStandardMaterial({
56
+ color: m.color ? m.color : cachedEntity.color,
57
+ transparent: m.color ? m.opacity < 1 : cachedEntity.opacity < 1,
58
+ opacity: m.color ? m.opacity : cachedEntity.opacity,
59
+ });
60
+ mesh.material.name = mesh.name + '_material';
61
+ result.materials[mesh.material.name] = mesh.material;
62
+ }
63
+ result.nodes[mesh.name] = mesh;
64
+ _solid.add(mesh);
65
+ });
66
+ part.add(_solid);
67
+ }
68
+ else {
69
+ // Merge all geometries into one mesh, sort them by color
70
+ const colorMeshesMap = getDifferentColoredMeshesFromEntity(cachedEntity);
71
+ const colorMeshes = Object.keys(colorMeshesMap);
72
+ if (colorMeshes.length > 1) {
73
+ // If the solid consists of multiple meshes we must keep the group
74
+ colorMeshes.forEach((key, i) => {
75
+ const mesh = new Mesh();
76
+ mesh.name = solidObject.name + '_' + i;
77
+ mesh.userData = { id: solidObject.id }; // add solid id to the userData
78
+ if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
79
+ mesh.geometry = mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
80
+ mesh.material = new MeshStandardMaterial({
81
+ color: colorMeshesMap[key].color,
82
+ transparent: colorMeshesMap[key].opacity < 1,
83
+ opacity: colorMeshesMap[key].opacity,
84
+ });
85
+ mesh.material.name = mesh.name + '_material';
86
+ result.materials[mesh.material.name] = mesh.material;
87
+ }
88
+ result.nodes[mesh.name] = mesh; // Collect mesh to return result later
89
+ _solid.add(mesh); // Add mesh to solid of the scene
90
+ });
91
+ part.add(_solid);
92
+ }
93
+ else {
94
+ // Otherwise we can use the mesh itself
95
+ const key = colorMeshes[0];
96
+ const mesh = new Mesh();
97
+ mesh.name = solidObject.name;
98
+ mesh.userData = { id: solidObject.id }; // add solid id to the userData
99
+ if (!(options === null || options === void 0 ? void 0 : options.structureOnly)) {
100
+ mesh.geometry = mergeBufferGeometries(colorMeshesMap[key].meshes.map(m => m.geometry));
101
+ mesh.material = new MeshStandardMaterial({
102
+ color: colorMeshesMap[key].color,
103
+ transparent: colorMeshesMap[key].opacity < 1,
104
+ opacity: colorMeshesMap[key].opacity,
105
+ });
106
+ mesh.material.name = mesh.name + '_material';
107
+ result.materials[mesh.material.name] = mesh.material;
108
+ }
109
+ result.nodes[mesh.name] = mesh;
110
+ part.add(mesh);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ }
116
+ root.add(part);
117
+ result.nodes[part.name] = part;
118
+ result.nodes[`${object.id}`] = part;
119
+ }
120
+ }
121
+ else if (object.children) {
122
+ // Assembly or Entity
123
+ const group = new Group();
124
+ const matrix = object.coordinateSystem ? MathUtils.convertToMatrix4(object.coordinateSystem) : new Matrix4();
125
+ matrix.decompose(group.position, group.quaternion, group.scale);
126
+ group.updateMatrix();
127
+ group.userData = { id: object.id }; // assembly root or instance id
128
+ group.name = object.name; // assembly root or instance name
129
+ result.nodes[group.name] = group;
130
+ result.nodes[`${object.id}`] = group;
131
+ root.add(group);
132
+ for (const child of object.children) {
133
+ await createRecursiveScene(tree[child], drawingId, group, result, options);
134
+ }
135
+ }
136
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Get all meshes in a map, sorted by their color / opacity
3
+ * @param entity entity to look for the meshes
4
+ * @returns map (key = color/opacity as string, value = object containing the meshes, color and opacity)
5
+ */
6
+ export const getDifferentColoredMeshesFromEntity = (entity) => {
7
+ const colorMeshesMap = {};
8
+ entity.meshes.forEach(mesh => {
9
+ const color = mesh.color ? mesh.color : entity.color;
10
+ const opacity = mesh.opacity ? mesh.opacity : entity.opacity;
11
+ const key = (color === null || color === void 0 ? void 0 : color.getHexString()) + (opacity === null || opacity === void 0 ? void 0 : opacity.toString());
12
+ if (colorMeshesMap[key]) {
13
+ colorMeshesMap[key].meshes.push(mesh);
14
+ }
15
+ else {
16
+ colorMeshesMap[key] = { meshes: [mesh], color, opacity };
17
+ }
18
+ });
19
+ return colorMeshesMap;
20
+ };
@@ -0,0 +1,4 @@
1
+ export * from './createRecursiveBufferGeometry';
2
+ export * from './createRecursiveScene';
3
+ export * from './polyline';
4
+ export * from './waitForSelect';
@@ -0,0 +1,60 @@
1
+ /**
2
+ * 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
3
+ * @param info Info contains information about lines
4
+ */
5
+ const getIncludingAngle = (info) => {
6
+ // First line (line to point)
7
+ const line1 = info.lineEnds[0]
8
+ .clone()
9
+ .sub(info.lineStarts[0])
10
+ .normalize();
11
+ // Second line (line from point)
12
+ const line2 = info.lineEnds[1]
13
+ .clone()
14
+ .sub(info.lineStarts[1])
15
+ .normalize();
16
+ // Angle, measured from first line to second line counterclockwise.
17
+ // If angle exceeds 180°, measuring is clockwise but negative angle
18
+ const angle = Math.atan2(line1.x * line2.y - line1.y * line2.x, line1.x * line2.x + line1.y * line2.y);
19
+ return angle;
20
+ };
21
+ /**
22
+ * Returns the adjacent points of the fillet arc. These are the points where fillet arc tangentially touches the lines.
23
+ * @param info contains all information for the fillet, like start- and endpoints of adjacent lines and control point
24
+ * @param radius radius of the fillet arc
25
+ */
26
+ export const getTouchPoints = (info, radius) => {
27
+ const controlPos = info.control;
28
+ const linearTolerance = 1e-3;
29
+ const dirs = [];
30
+ const maxDists = [];
31
+ for (let i = 0; i < 2; i++) {
32
+ const startPos = info.lineStarts[i];
33
+ const endPos = info.lineEnds[i];
34
+ const dir = endPos.clone().sub(startPos).normalize();
35
+ const maxDist = endPos.distanceTo(controlPos);
36
+ dirs.push(dir);
37
+ maxDists.push(maxDist);
38
+ }
39
+ if (radius + linearTolerance >= Math.min(maxDists[0], maxDists[1])) {
40
+ return null; // too large fillet
41
+ }
42
+ // Calculate distance from controlpt to touchpoint
43
+ const scalar = Math.abs(radius / Math.tan(getIncludingAngle(info) / 2));
44
+ return dirs.map(dir => dir
45
+ .clone()
46
+ .multiplyScalar(scalar)
47
+ .add(controlPos));
48
+ };
49
+ /**
50
+ * 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.
51
+ * @param info
52
+ */
53
+ export const getIncludingBulgeAngle = (info) => {
54
+ // angle of first line, control point and second line
55
+ const angle = getIncludingAngle(info);
56
+ // Opposite angle of the angle which was calculated from control point and its adjacent lines
57
+ const oppositeAngle = Math.PI - Math.abs(angle);
58
+ const sign = angle / Math.abs(angle);
59
+ return oppositeAngle * sign * -1; // -1 because of bulges definition
60
+ };
@@ -0,0 +1,23 @@
1
+ import { getDrawing } from '@classcad/sdkjs';
2
+ import { v4 } from 'uuid';
3
+ // @ts-ignore
4
+ import createPromise from 'flat-promise';
5
+ export async function waitForSelect(drawingId, length, filter, onChange) {
6
+ const id = v4();
7
+ const selApi = drawingId && getDrawing(drawingId).api.selection;
8
+ // Set up selection API
9
+ const { promise, resolve } = createPromise();
10
+ const change = (selId, items, diff) => {
11
+ selApi && selApi.setItems(selId, items);
12
+ if (onChange)
13
+ onChange(resolve, items, diff);
14
+ };
15
+ const unsub = selApi && selApi.createSelector(id, filter, false, [], length, change, change);
16
+ // Wait for user interaction
17
+ selApi && selApi.activateSelector(id);
18
+ const result = await promise;
19
+ // Unsubscribe from all selections
20
+ unsub && unsub();
21
+ selApi && selApi.activateSelector(null);
22
+ return result;
23
+ }