From ebc0b3bfcfc347f47e833835644530389e19e34b Mon Sep 17 00:00:00 2001 From: Alan Rynne Date: Thu, 24 Jun 2021 10:40:00 +0200 Subject: [PATCH] feat(ifc): Added display mesh from productgeo to ifc object --- packages/ifc-parser/parser.js | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/packages/ifc-parser/parser.js b/packages/ifc-parser/parser.js index 9903b1879..b3d856efa 100644 --- a/packages/ifc-parser/parser.js +++ b/packages/ifc-parser/parser.js @@ -71,22 +71,31 @@ module.exports = class IFCParser { if ( !element ) return element.speckle_type = element.constructor.name + element.__closure = {} + + // Find spatial children and assign to element const spatialChildrenIds = this.getAllRelatedItemsOfType( element.expressID, WebIFC.IFCRELAGGREGATES, 'RelatingObject', 'RelatedObjects' ) + if( spatialChildrenIds.length > 0 ) element.spatialChildren = spatialChildrenIds.map( ( childId ) => this.api.GetLine( this.modelId, childId, false ) ) - element.spatialChildren = spatialChildrenIds.map( ( childId ) => this.api.GetLine( this.modelId, childId, false ) ) - + // Find children and populate element const childrenIds = this.getAllRelatedItemsOfType( element.expressID, WebIFC.IFCRELCONTAINEDINSPATIALSTRUCTURE, 'RelatingStructure', 'RelatedElements' ) - - element.children = childrenIds.map( ( childId ) => this.api.GetLine( this.modelId, childId, false ) ) + if( childrenIds.length > 0 ) element.children = childrenIds.map( ( childId ) => this.api.GetLine( this.modelId, childId, false ) ) // Lookup geometry in generated geometries object - console.log( `${element.constructor.name} (${element.expressID}) mesh:`, this.productGeo[element.expressID]?.length ) - - if ( recursive ) { - element.spatialChildren.forEach( ( child ) => this.traverse( child, recursive, depth ) ) - // NOTE: unsure if this is needed. - element.children.forEach( ( child ) => this.traverse( child, recursive, depth ) ) + if( this.productGeo[element.expressID] ) { + element['@displayMesh'] = this.productGeo[element.expressID] + // TODO: Add detached mesh to closure table. } + + // Recurse all children + if ( recursive ) { + if( element.spatialChildren ) element.spatialChildren.forEach( ( child ) => this.traverse( child, recursive, depth ) ) + // NOTE: unsure if this is needed. + if ( element.children ) element.children.forEach( ( child ) => this.traverse( child, recursive, depth ) ) + } + + // Detach and swap for ref! + } // (c) https://github.com/agviegas/web-ifc-three/blob/907e08b5673d5e1c18261a4fceade7189d6b2db7/src/IFC/PropertyManager.ts#L110