viewer.loadObject now returns after loading (#187)

This commit is contained in:
Cristian Balas
2021-04-22 13:47:03 +03:00
committed by GitHub
parent df05f61f2d
commit 09de8184a7
2 changed files with 19 additions and 9 deletions
+10 -3
View File
@@ -31,12 +31,17 @@ export default class Coverter {
if ( obj.referencedId ) obj = await this.resolveReference( obj )
let childrenConversionPromisses = []
// Traverse arrays, and exit early (we don't want to iterate through many numbers)
if ( Array.isArray( obj ) ) {
for ( let element of obj ) {
if ( typeof element !== 'object' ) return // exit early for non-object based arrays
( async() => await this.traverseAndConvert( element, callback ) )() //iife so we don't block
if ( typeof element !== 'object' ) break // exit early for non-object based arrays
let childPromise = this.traverseAndConvert( element, callback )
childrenConversionPromisses.push( childPromise )
}
await Promise.all( childrenConversionPromisses )
return
}
// If we can convert it, we should invoke the respective conversion routine.
@@ -72,8 +77,10 @@ export default class Coverter {
// traverses the object in case there's any sub-objects we can convert.
for ( let prop in target ) {
if ( typeof target[prop] !== 'object' ) continue
( async() => await this.traverseAndConvert( target[prop], callback ) )() //iife so we don't block
let childPromise = this.traverseAndConvert( target[prop], callback )
childrenConversionPromisses.push( childPromise )
}
await Promise.all( childrenConversionPromisses )
}
/**
@@ -44,14 +44,13 @@ export default class ViewerObjectLoader {
let current = 0
let total = 0
let viewerLoads = 0
let firstObjectPromise = null
for await ( let obj of this.loader.getObjectIterator() ) {
if ( first ) {
( async() => {
await this.converter.traverseAndConvert( obj, ( o ) => {
this.viewer.sceneManager.addObject( o )
viewerLoads++
} )
} )()
firstObjectPromise = this.converter.traverseAndConvert( obj, ( o ) => {
this.viewer.sceneManager.addObject( o )
viewerLoads++
} )
first = false
total = obj.totalChildrenCount
}
@@ -59,6 +58,10 @@ export default class ViewerObjectLoader {
this.viewer.emit( 'load-progress', { progress: current/( total+1 ), id: this.objectId } )
}
if ( firstObjectPromise ) {
await firstObjectPromise
}
if ( viewerLoads === 0 ) {
console.warn( `Viewer: no 3d objects found in object ${this.objectId}` )
this.viewer.emit( 'load-warning', { message: `No displayable objects found in object ${this.objectId}.` } )