-
-
Notifications
You must be signed in to change notification settings - Fork 35.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Returning conversion warnings in 3DMLoader #21639
Changes from 6 commits
158a875
ec3ff76
89da0c7
78afc99
c810381
4176142
1d97c81
e21f211
da176ab
6c02601
ea34dbf
103675f
7731833
0652c61
b1ecb5e
27b8f45
92a0c62
6a35bd8
0f2ac4a
cb633a0
e3a7f58
3cdfabe
e9d7654
0c60f5f
5d06888
3ca34c0
bd86376
59dd4bd
7f8bcc4
a7806e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ class Rhino3dmLoader extends Loader { | |
|
||
this.decodeObjects( buffer, url ) | ||
.then( onLoad ) | ||
.catch( onError ); | ||
.catch( e => onError( e ) ); | ||
|
||
}, onProgress, onError ); | ||
|
||
|
@@ -106,6 +106,7 @@ class Rhino3dmLoader extends Loader { | |
|
||
let worker; | ||
let taskID; | ||
let warnings =[]; | ||
|
||
const taskCost = buffer.byteLength; | ||
|
||
|
@@ -117,16 +118,24 @@ class Rhino3dmLoader extends Loader { | |
|
||
return new Promise( ( resolve, reject ) => { | ||
|
||
worker._callbacks[ taskID ] = { resolve, reject }; | ||
worker._callbacks[ taskID ] = { resolve, reject, warn: warning =>warnings.push(warning) }; | ||
|
||
worker.postMessage( { type: 'decode', id: taskID, buffer }, [ buffer ] ); | ||
|
||
//this.debug(); | ||
// //this.debug(); | ||
|
||
} ); | ||
|
||
} ) | ||
.then( ( message ) => this._createGeometry( message.data ) ); | ||
.then( ( message ) => { | ||
const geometry = this._createGeometry( message.data, taskID ); | ||
geometry.warnings = warnings; | ||
return geometry; | ||
}).catch( e => { | ||
|
||
throw e; | ||
|
||
} ); | ||
|
||
// Remove task from the task list. | ||
// Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416) | ||
|
@@ -160,7 +169,7 @@ class Rhino3dmLoader extends Loader { | |
|
||
this.decodeObjects( data, '' ) | ||
.then( onLoad ) | ||
.catch( onError ); | ||
.catch( e => onError( e ) ); | ||
|
||
} | ||
|
||
|
@@ -281,7 +290,7 @@ class Rhino3dmLoader extends Loader { | |
|
||
} | ||
|
||
_createGeometry( data ) { | ||
_createGeometry( data, taskID ) { | ||
|
||
// console.log(data); | ||
|
||
|
@@ -328,12 +337,12 @@ class Rhino3dmLoader extends Loader { | |
const rMaterial = materials[ attributes.materialIndex ]; | ||
let material = this._createMaterial( rMaterial ); | ||
material = this._compareMaterials( material ); | ||
_object = this._createObject( obj, material ); | ||
_object = this._createObject( obj, material, taskID ); | ||
|
||
} else { | ||
|
||
const material = this._createMaterial( ); | ||
_object = this._createObject( obj, material ); | ||
_object = this._createObject( obj, material, taskID ); | ||
|
||
} | ||
|
||
|
@@ -422,7 +431,7 @@ class Rhino3dmLoader extends Loader { | |
|
||
} | ||
|
||
_createObject( obj, mat ) { | ||
_createObject( obj, mat, taskID ) { | ||
|
||
const loader = new BufferGeometryLoader(); | ||
|
||
|
@@ -615,7 +624,7 @@ class Rhino3dmLoader extends Loader { | |
|
||
} else if ( geometry.isLinearLight ) { | ||
|
||
console.warn( 'THREE.3DMLoader: No conversion exists for linear lights.' ); | ||
self.postMessage( { type: 'warning', id: taskID, message: 'THREE.3DMLoader: No conversion exists for linear lights.' } ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @karimi here we are no longer in the worker. What do you want to do with these warnings? I'm don't think posting messages is the way to go here. |
||
|
||
return; | ||
|
||
|
@@ -708,6 +717,9 @@ class Rhino3dmLoader extends Loader { | |
const message = e.data; | ||
|
||
switch ( message.type ) { | ||
case 'warning': | ||
worker._callbacks[ message.id ].warn( message ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fraguada We need a id to figure out which task this warning belongs to. I'm using the taskID corresponding to the file to collate the warnings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure we should add a .warn to this callback, since the promises api only defines |
||
break; | ||
|
||
case 'decode': | ||
worker._callbacks[ message.id ].resolve( message ); | ||
|
@@ -809,9 +821,16 @@ function Rhino3dmWorker() { | |
const buffer = message.buffer; | ||
libraryPending.then( () => { | ||
|
||
const data = decodeObjects( rhino, buffer ); | ||
try { | ||
|
||
const data = decodeObjects( rhino, buffer, message.id ); | ||
karimi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.postMessage( { type: 'decode', id: message.id, data } ); | ||
|
||
} catch ( error ) { | ||
|
||
self.postMessage( { type: 'decode', id: message.id, data } ); | ||
self.postMessage( { type: 'error', id: message.id, error } ); | ||
|
||
} | ||
|
||
} ); | ||
|
||
|
@@ -821,7 +840,7 @@ function Rhino3dmWorker() { | |
|
||
}; | ||
|
||
function decodeObjects( rhino, buffer ) { | ||
function decodeObjects( rhino, buffer, taskID ) { | ||
karimi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const arr = new Uint8Array( buffer ); | ||
const doc = rhino.File3dm.fromByteArray( arr ); | ||
|
@@ -842,7 +861,7 @@ function Rhino3dmWorker() { | |
|
||
const _object = objs.get( i ); | ||
|
||
const object = extractObjectData( _object, doc ); | ||
const object = extractObjectData( _object, doc, taskID ); | ||
karimi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
_object.delete(); | ||
|
||
|
@@ -926,10 +945,8 @@ function Rhino3dmWorker() { | |
texture.image = 'data:image/png;base64,' + image; | ||
|
||
} else { | ||
|
||
console.warn( `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` ); | ||
self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` } ); | ||
texture.image = null; | ||
|
||
} | ||
|
||
textures.push( texture ); | ||
|
@@ -1064,7 +1081,7 @@ function Rhino3dmWorker() { | |
|
||
} | ||
|
||
function extractObjectData( object, doc ) { | ||
function extractObjectData( object, doc, taskID ) { | ||
karimi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const _geometry = object.geometry(); | ||
const _attributes = object.attributes(); | ||
|
@@ -1225,7 +1242,7 @@ function Rhino3dmWorker() { | |
*/ | ||
|
||
default: | ||
console.warn( `THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` ); | ||
self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` } ); | ||
break; | ||
|
||
} | ||
|
@@ -1261,9 +1278,7 @@ function Rhino3dmWorker() { | |
return { geometry, attributes, objectType }; | ||
|
||
} else { | ||
|
||
console.warn( `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` ); | ||
|
||
self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` } ); | ||
} | ||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,7 +76,7 @@ | |
// hide spinner | ||
document.getElementById( 'loader' ).style.display = 'none'; | ||
|
||
} ); | ||
}, progress =>progress, error => ( console.log( error ) ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cleaned that up. |
||
|
||
controls = new OrbitControls( camera, renderer.domElement ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a function to collate warnings thrown by workers.