diff --git a/web/app/brep/io/brepIO.js b/web/app/brep/io/brepIO.js index cdcb91c4..5c568fed 100644 --- a/web/app/brep/io/brepIO.js +++ b/web/app/brep/io/brepIO.js @@ -21,7 +21,12 @@ export function readBrep(data) { format: 'verbose', data: normalizeTesselationData(faceData.tess, inverted, faceData.surface.normal) }; - + if (faceData.ref !== undefined) { + bb._face.data.externals = { + ref: faceData.ref + } + } + for (let loop of faceData.loops) { bb.loop(); for (let edgeData of loop) { diff --git a/web/app/cad/model/mshell.js b/web/app/cad/model/mshell.js index 879697c3..7a29ceff 100644 --- a/web/app/cad/model/mshell.js +++ b/web/app/cad/model/mshell.js @@ -27,7 +27,7 @@ export class MBrepShell extends MShell { let vertexCounter = 0; for (let brepFace of this.brepShell.faces) { - const mFace = new MBrepFace(this.id + '/F:' + faceCounter++, this, brepFace); + const mFace = new MBrepFace(brepFace.data.id || (this.id + '/F:' + faceCounter++), this, brepFace); this.faces.push(mFace); } diff --git a/web/app/cad/scene/wrappers/entityIO.js b/web/app/cad/scene/wrappers/entityIO.js index 1ad7ca06..a6e4c2d7 100644 --- a/web/app/cad/scene/wrappers/entityIO.js +++ b/web/app/cad/scene/wrappers/entityIO.js @@ -1,6 +1,36 @@ import {readBrep} from '../../../brep/io/brepIO'; import {MBrepShell} from '../../model/mshell'; -export function readShellEntityFromJson(data) { - return new MBrepShell(readBrep(data)); -} \ No newline at end of file +export function readShellEntityFromJson(data, consumed) { + + let refIndex = indexFacesByRef(consumed); + + let shell = readBrep(data); + for (let face of shell.faces) { + let ref = getRef(face); + if (ref !== undefined) { + let consumedFace = refIndex.get(ref); + if (consumedFace) { + face.data.id = consumedFace.id; + } + } + } + return new MBrepShell(shell); +} + +function indexFacesByRef(shells) { + let index = new Map(); + if (shells) { + for (let shell of shells) { + for (let face of shell.faces) { + let ref = getRef(face.brepFace); + if (ref !== undefined) { + index.set(ref, face); + } + } + } + } + return index; +} + +const getRef = brepFace => brepFace && brepFace.data.externals && brepFace.data.externals.ref; \ No newline at end of file