@buerli.io/headless 0.1.0 → 0.2.0-beta.1
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/build/history.js +71 -17
- package/package.json +2 -2
package/build/history.js
CHANGED
|
@@ -246,6 +246,16 @@ const createRecursiveBufferGeometry = async (object, drawingId, bufferGeomArray)
|
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* We traverse recursively over structure tree, starting with object and create three objects and meshes
|
|
251
|
+
* for the scene. Each part or assembly will be turned into groups and subgroups. Solids from parts will be turned
|
|
252
|
+
* into merged meshes, which are children of the group. Faces of a solid with different color
|
|
253
|
+
* or transparency will get its own mesh.
|
|
254
|
+
* @param object root object where we start building the three scene
|
|
255
|
+
* @param drawingId id of the drawing
|
|
256
|
+
* @param root the root of the scene
|
|
257
|
+
* @param options e.g. meshPerFace controls if each face gets a own mesh or if they will be combined/merged
|
|
258
|
+
*/
|
|
249
259
|
const createRecursiveScene = async (object, drawingId, root, options) => {
|
|
250
260
|
let cDrawing = getDrawing(drawingId);
|
|
251
261
|
const tree = cDrawing.structure.tree;
|
|
@@ -254,6 +264,7 @@ const createRecursiveScene = async (object, drawingId, root, options) => {
|
|
|
254
264
|
const solids = object.link ? tree[object.link].solids : object.solids;
|
|
255
265
|
if (solids != undefined) {
|
|
256
266
|
let meshes = [];
|
|
267
|
+
const cachedSolids = [];
|
|
257
268
|
for (const solid of solids) {
|
|
258
269
|
let cachedSolid = cDrawing.geometry.cache[solid];
|
|
259
270
|
if (!cachedSolid) {
|
|
@@ -262,30 +273,55 @@ const createRecursiveScene = async (object, drawingId, root, options) => {
|
|
|
262
273
|
cDrawing = getDrawing(drawingId); // get current drawing state after request
|
|
263
274
|
cachedSolid = cDrawing.geometry.cache[solid];
|
|
264
275
|
}
|
|
265
|
-
if (cachedSolid)
|
|
266
|
-
|
|
276
|
+
if (cachedSolid) {
|
|
277
|
+
if (options === null || options === void 0 ? void 0 : options.meshPerFace) {
|
|
278
|
+
meshes = [...meshes, ...cachedSolid.meshes.map(m => m)];
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
cachedSolids.push(cachedSolid);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
267
284
|
}
|
|
268
|
-
|
|
269
|
-
|
|
285
|
+
// If meshPerFace = true, we create for each face a separat mesh
|
|
286
|
+
if (options === null || options === void 0 ? void 0 : options.meshPerFace) {
|
|
287
|
+
if (meshes.length > 0) {
|
|
270
288
|
const part = new Group();
|
|
271
289
|
part.matrix = MathUtils.convertToMatrix4(object.coordinateSystem);
|
|
272
290
|
part.matrixAutoUpdate = false;
|
|
273
|
-
part.userData = { id: object.id };
|
|
274
|
-
part.name = object.name;
|
|
291
|
+
part.userData = { id: object.id }; // product reference id
|
|
292
|
+
part.name = object.name; // product reference name
|
|
275
293
|
for (const mesh of meshes) {
|
|
276
294
|
part.add(new Mesh(mesh.geometry, new MeshStandardMaterial({ color: mesh.color, transparent: mesh.opacity < 1, opacity: mesh.opacity })));
|
|
277
295
|
}
|
|
278
296
|
root.add(part);
|
|
279
297
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
if (cachedSolids.length > 0) {
|
|
301
|
+
const part = new Group();
|
|
302
|
+
part.matrix = MathUtils.convertToMatrix4(object.coordinateSystem);
|
|
303
|
+
part.matrixAutoUpdate = false;
|
|
304
|
+
part.userData = { id: object.id }; // product reference id
|
|
305
|
+
part.name = object.name; // product reference name
|
|
306
|
+
// A cached solid can have different colored faces, e.g. if a brep has been decorated.
|
|
307
|
+
// In that case, we group the meshes with the same color/tranparency
|
|
308
|
+
for (const cs of cachedSolids) {
|
|
309
|
+
const colorMeshesMap = getDifferentColoredMeshesFromSolid(cs);
|
|
310
|
+
Object.keys(colorMeshesMap).forEach(key => {
|
|
311
|
+
const coloredMeshes = colorMeshesMap[key];
|
|
312
|
+
const mesh = new Mesh();
|
|
313
|
+
mesh.userData = { id: cs.container.ownerId }; // solid id
|
|
314
|
+
mesh.name = tree[cs.container.ownerId].name; // solid name
|
|
315
|
+
mesh.geometry = BufferGeometryUtils.mergeBufferGeometries(coloredMeshes.map(m => m.geometry));
|
|
316
|
+
mesh.material = new MeshStandardMaterial({
|
|
317
|
+
color: coloredMeshes[0].color,
|
|
318
|
+
transparent: coloredMeshes[0].opacity < 1,
|
|
319
|
+
opacity: coloredMeshes[0].opacity,
|
|
320
|
+
});
|
|
321
|
+
part.add(mesh);
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
root.add(part);
|
|
289
325
|
}
|
|
290
326
|
}
|
|
291
327
|
}
|
|
@@ -295,8 +331,8 @@ const createRecursiveScene = async (object, drawingId, root, options) => {
|
|
|
295
331
|
const assembly = new Group();
|
|
296
332
|
assembly.matrix = MathUtils.convertToMatrix4(object.coordinateSystem);
|
|
297
333
|
assembly.matrixAutoUpdate = false;
|
|
298
|
-
assembly.userData = { id: object.id };
|
|
299
|
-
assembly.name = object.name;
|
|
334
|
+
assembly.userData = { id: object.id }; // assembly root or product reference id
|
|
335
|
+
assembly.name = object.name; // assembly root or product reference name
|
|
300
336
|
root.add(assembly);
|
|
301
337
|
for (const child of object.children) {
|
|
302
338
|
if (tree[child].class === CCClasses.CCProductReference || tree[child].class === CCClasses.CCProductReferenceET) {
|
|
@@ -305,6 +341,24 @@ const createRecursiveScene = async (object, drawingId, root, options) => {
|
|
|
305
341
|
}
|
|
306
342
|
}
|
|
307
343
|
};
|
|
344
|
+
/**
|
|
345
|
+
* Get all meshes in a map, sorted by their color / transparency
|
|
346
|
+
* @param solid solid to look for the meshes
|
|
347
|
+
* @returns map (key = color/transparency as string, value = meshes array)
|
|
348
|
+
*/
|
|
349
|
+
const getDifferentColoredMeshesFromSolid = (solid) => {
|
|
350
|
+
const colorMeshesMap = {};
|
|
351
|
+
solid.meshes.forEach(mesh => {
|
|
352
|
+
const key = mesh.color.getHexString() + mesh.opacity.toString();
|
|
353
|
+
if (colorMeshesMap[key]) {
|
|
354
|
+
colorMeshesMap[key].push(mesh);
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
colorMeshesMap[key] = [mesh];
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
return colorMeshesMap;
|
|
361
|
+
};
|
|
308
362
|
export default class CAD {
|
|
309
363
|
constructor() {
|
|
310
364
|
this.drawingId = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@buerli.io/headless",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
4
4
|
"description": "A non-manifold CAD workflow for the web",
|
|
5
5
|
"author": "AWV Informatik AG <info@awv-informatik.ch>",
|
|
6
6
|
"license": "ISC",
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"three": ">=0.138"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@buerli.io/classcad": "0.
|
|
32
|
+
"@buerli.io/classcad": "0.2.0-beta.1"
|
|
33
33
|
}
|
|
34
34
|
}
|