@buerli.io/headless 0.5.0-beta.1 → 0.5.0-beta.3

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
@@ -1,7 +1,14 @@
1
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
2
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
3
+ var m = o[Symbol.asyncIterator], i;
4
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
5
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
6
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
7
+ };
1
8
  /* eslint-disable max-lines */
2
9
  import { ccAPI } from '@buerli.io/classcad';
3
10
  import { api, getDrawing } from '@buerli.io/core';
4
- import { Mesh, MeshStandardMaterial, Scene, Shape } from 'three';
11
+ import { Group, Mesh, MeshStandardMaterial, Scene, Shape } from 'three';
5
12
  import * as BufferGeometryUtils_ from 'three/examples/jsm/utils/BufferGeometryUtils';
6
13
  const solidAPI = ccAPI.solid;
7
14
  let BufferGeometryUtils = BufferGeometryUtils_;
@@ -231,25 +238,73 @@ export default class CAD {
231
238
  return BufferGeometryUtils.mergeBufferGeometries(entity.meshes.map(m => m.geometry));
232
239
  }
233
240
  },
234
- createScene: async (solid) => {
241
+ createScene: async (solids, options) => {
242
+ var e_1, _a;
235
243
  await this.queue;
236
244
  this.queue = Promise.resolve(0);
237
- const rSolid = await solid;
238
- await ccAPI.baseModeler.requestVisualisationOfObject(drawingId, rSolid);
239
- const entity = await getEntity(drawingId, rSolid);
240
- const group = new Scene();
241
- group.userData = { id: rSolid };
242
- group.name = 'Solid';
243
- if (entity != null) {
244
- for (const mesh of entity.meshes) {
245
- group.add(new Mesh(mesh.geometry, new MeshStandardMaterial({
246
- color: mesh.color,
247
- transparent: mesh.opacity < 1,
248
- opacity: mesh.opacity,
249
- })));
245
+ const scene = new Scene();
246
+ scene.name = 'Scene'; // Default name for the scene
247
+ const part = new Group();
248
+ part.name = 'Part'; // Default name for the part
249
+ const _solids = [];
250
+ const meshes = [];
251
+ try {
252
+ for (var solids_1 = __asyncValues(solids), solids_1_1; solids_1_1 = await solids_1.next(), !solids_1_1.done;) {
253
+ const solid = solids_1_1.value;
254
+ await ccAPI.baseModeler.requestVisualisationOfObject(drawingId, solid);
255
+ const cDrawing = getDrawing(drawingId);
256
+ const solidObject = cDrawing.structure.tree[solid];
257
+ if (solidObject) {
258
+ const _solid = new Group();
259
+ _solid.name = solidObject.name;
260
+ _solid.userData = { id: solidObject.id }; // add solid id to the userData
261
+ const entities = solidObject.geometryIdList;
262
+ if (entities && entities.length > 0) {
263
+ const entity = cDrawing.geometry.cache[entities[0]];
264
+ if (entity && entity.meshes.length > 0) {
265
+ if (options === null || options === void 0 ? void 0 : options.meshPerGeometry) {
266
+ // Create a mesh for each geometry element
267
+ entity.meshes.forEach(m => {
268
+ const mesh = new Mesh();
269
+ mesh.userData = { id: m.graphicId }; // add graphic id to the userData
270
+ mesh.geometry = m.geometry;
271
+ mesh.material = new MeshStandardMaterial({
272
+ color: m.color,
273
+ transparent: m.opacity < 1,
274
+ opacity: m.opacity,
275
+ });
276
+ _solid.add(mesh);
277
+ meshes.push(mesh);
278
+ });
279
+ }
280
+ else {
281
+ // Merge all geometries into one mesh
282
+ const mesh = new Mesh();
283
+ mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(entity.meshes.map(m => m.geometry));
284
+ mesh.material = new MeshStandardMaterial({
285
+ color: entity.meshes[0].color,
286
+ transparent: entity.meshes[0].opacity < 1,
287
+ opacity: entity.meshes[0].opacity,
288
+ });
289
+ _solid.add(mesh); // Add mesh to solid of the scene
290
+ meshes.push(mesh); // Collect mesh to return later
291
+ }
292
+ part.add(_solid); // Add solid to part of the scene
293
+ _solids.push(_solid); // Collect solid to return later
294
+ }
295
+ }
296
+ }
297
+ }
298
+ }
299
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
300
+ finally {
301
+ try {
302
+ if (solids_1_1 && !solids_1_1.done && (_a = solids_1.return)) await _a.call(solids_1);
250
303
  }
304
+ finally { if (e_1) throw e_1.error; }
251
305
  }
252
- return group;
306
+ scene.add(part); // Add part to the scene
307
+ return { scene, part, solids: _solids, meshes };
253
308
  },
254
309
  cylinder: (length, diameter) => {
255
310
  return this.resolve(async () => {
File without changes