feat(ifcparser): moved things to src, minor tests mostly for remembering the process
This commit is contained in:
@@ -17,7 +17,7 @@ module.exports = {
|
||||
'space-before-blocks': 'error',
|
||||
'space-infix-ops': 'error',
|
||||
'comma-dangle': [ 'error', 'never' ],
|
||||
'no-console': [ 'error', { allow: [ 'warn', 'error' ] } ],
|
||||
'no-console': [ 'warn', { allow: [ 'warn', 'error' ] } ],
|
||||
'space-unary-ops': 'error',
|
||||
'no-var': 'error',
|
||||
'no-alert': 'error',
|
||||
|
||||
Generated
+2
-1146
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
||||
const crypto = require( 'crypto' )
|
||||
|
||||
module.exports = class ObjectSaver {
|
||||
|
||||
constructor( { serverUrl = 'http://localhost:3000' } ) {
|
||||
this.serverUrl = serverUrl
|
||||
this.isSending = false
|
||||
this.buffer = []
|
||||
}
|
||||
|
||||
async saveObject( obj ) {
|
||||
if( !obj ) throw new Error( 'Null object' )
|
||||
|
||||
if( !obj.id ) {
|
||||
obj.id = crypto.createHash( 'md5' ).update( JSON.stringify( obj ) ).digest( 'hex' )
|
||||
}
|
||||
|
||||
// TODO
|
||||
|
||||
return obj.id
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
const fs = require( 'fs' )
|
||||
const Parser = require( './parser' )
|
||||
const ObjectSaver = require( './api.js' )
|
||||
|
||||
|
||||
const myParser = new Parser( { objectSaver: new ObjectSaver() } )
|
||||
|
||||
const myParser = new Parser()
|
||||
// const data = fs.readFileSync( './ifcs/20160414office_model_CV2_fordesign.ifc' )
|
||||
// const data = fs.readFileSync( './ifcs/231110AC11-Institute-Var-2-IFC.ifc' )
|
||||
// const data = fs.readFileSync( './ifcs/231110ADT-FZK-Haus-2005-2006.ifc' )
|
||||
@@ -10,6 +13,8 @@ const data = fs.readFileSync( './ifcs/example.ifc' )
|
||||
|
||||
async function load() {
|
||||
const parsed = await myParser.parse( data )
|
||||
fs.writeFileSync( 'foo.txt', JSON.stringify( parsed ) )
|
||||
|
||||
console.log( parsed )
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
const WebIFC = require( 'web-ifc/web-ifc-api-node' )
|
||||
const ObjectSaver = require( './api.js' )
|
||||
|
||||
module.exports = class IFCParser {
|
||||
constructor() {
|
||||
|
||||
constructor( { objectSaver } ) {
|
||||
this.api = new WebIFC.IfcAPI()
|
||||
this.objectSaver = objectSaver || new ObjectSaver()
|
||||
}
|
||||
|
||||
async parse( data ) {
|
||||
@@ -14,17 +17,22 @@ module.exports = class IFCParser {
|
||||
|
||||
this.project = this.api.GetLine( this.modelId, this.projectId, true )
|
||||
|
||||
this.createGeometries()
|
||||
// Steps: create and store in speckle all the geometries (meshes) from this project and store them
|
||||
// as reference objects in this.productGeo
|
||||
this.productGeo = {}
|
||||
await this.createGeometries()
|
||||
|
||||
// Lastly, traverse the ifc project object and parse it into something friendly; as well as
|
||||
// replace all its geometries with actual references to speckle meshes from the productGeo map
|
||||
let map = {}
|
||||
this.traverse( this.project, true, 0, map )
|
||||
|
||||
return this.project
|
||||
}
|
||||
|
||||
createGeometries() {
|
||||
async createGeometries() {
|
||||
// NOTE: this is where we can alreadt create speckle meshes and plop them in the db.
|
||||
this.rawGeo = this.api.LoadAllGeometry( this.modelId )
|
||||
this.productGeo = {}
|
||||
let materialMap = {}
|
||||
for( let i = 0; i < this.rawGeo.size(); i++ ) {
|
||||
const mesh = this.rawGeo.get( i )
|
||||
@@ -61,8 +69,9 @@ module.exports = class IFCParser {
|
||||
}
|
||||
|
||||
//TODO: Send the mesh and swap for speckle ref
|
||||
let id = await this.objectSaver.saveObject( spcklMesh )
|
||||
let ref = spcklMesh
|
||||
|
||||
|
||||
this.productGeo[prodId].push( ref )
|
||||
}
|
||||
}
|
||||
@@ -91,7 +100,7 @@ module.exports = class IFCParser {
|
||||
}
|
||||
|
||||
// If you got here -> It's an IFC Element: create base object, upload and return ref.
|
||||
console.log( `Traversing element ${element.expressID}; Recurse: ${recursive}; Stack ${depth}` )
|
||||
// console.log( `Traversing element ${element.expressID}; Recurse: ${recursive}; Stack ${depth}` )
|
||||
|
||||
// Traverse all key/value pairs first.
|
||||
Object.keys( element ).forEach( key => {
|
||||
Reference in New Issue
Block a user