Skip to content
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

Merged
merged 30 commits into from
May 18, 2021
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
158a875
extract name and value properties from objects
fraguada Feb 11, 2021
ec3ff76
Extract object userStrings
fraguada Feb 15, 2021
89da0c7
Merge branch 'dev' of https://github.com/mrdoob/three.js into wip/3DM…
fraguada Feb 15, 2021
78afc99
Merge branch 'wip/3DMLoader' of https://github.com/mcneel/three.js in…
fraguada Apr 15, 2021
c810381
3dmLoader: refactor es6
fraguada Apr 15, 2021
4176142
Remove unnecessary imports.
fraguada Apr 15, 2021
1d97c81
Store conversion warnings in returned object
karimi Apr 13, 2021
e21f211
Pass worker erros to onError callback
karimi Apr 13, 2021
da176ab
Pass worker erros to onError callback
karimi Apr 13, 2021
6c02601
Merge branch 'dev' into 3dmloaderwarnings
karimi Apr 26, 2021
ea34dbf
adding some error catching related to PBR mats
fraguada Apr 30, 2021
103675f
Merge branch 'dev' of https://github.com/mrdoob/three.js into wip/3DM…
fraguada Apr 30, 2021
7731833
fix bug in texturetype checking
fraguada Apr 30, 2021
0652c61
Post warnings to worker
karimi May 3, 2021
b1ecb5e
Merge https://github.com/mrdoob/three.js into 3dmloaderwarnings
karimi May 3, 2021
27b8f45
Merge branch 'dev' of https://github.com/mrdoob/three.js into wip/3DM…
fraguada May 5, 2021
92a0c62
adding taskId in worker
fraguada May 7, 2021
6a35bd8
Merge branch 'wip/3DMLoader' of https://github.com/mcneel/three.js in…
fraguada May 7, 2021
0f2ac4a
Merge branch 'dev' of https://github.com/mrdoob/three.js into 3dmload…
fraguada May 7, 2021
cb633a0
cleanup taskID usage
fraguada May 7, 2021
e3a7f58
added class level warnings
fraguada May 7, 2021
3cdfabe
printing warnings
fraguada May 7, 2021
e9d7654
fixed bug in .catch
fraguada May 7, 2021
0c60f5f
Fix undefined this.warnings
karimi May 7, 2021
5d06888
Add onWarning callback
karimi May 7, 2021
3ca34c0
Rewriting onMessage as arrow function
karimi May 7, 2021
bd86376
rework warning messages, lightstyle switch
fraguada May 11, 2021
59dd4bd
Remove onWarning callback, add warnings to userData
karimi May 12, 2021
7f8bcc4
Cleanup comments, etc.
fraguada May 17, 2021
a7806e6
reverted change in example
fraguada May 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 113 additions & 44 deletions examples/jsm/loaders/3DMLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class Rhino3dmLoader extends Loader {
this.workerConfig = {};

this.materials = [];
this.warnings = [];

}

Expand Down Expand Up @@ -88,11 +89,15 @@ class Rhino3dmLoader extends Loader {
}

this.decodeObjects( buffer, url )
.then( onLoad )
.catch( onError );
.then( result => {

}, onProgress, onError );
result.userData.warnings = this.warnings;
onLoad( result );

} )
.catch( e => onError( e ) );

}, onProgress, onError );

}

Expand All @@ -113,20 +118,25 @@ class Rhino3dmLoader extends Loader {
.then( ( _worker ) => {

worker = _worker;
taskID = this.workerNextTaskID ++; //hmmm
taskID = this.workerNextTaskID ++;

return new Promise( ( resolve, reject ) => {

worker._callbacks[ taskID ] = { resolve, reject };

worker.postMessage( { type: 'decode', id: taskID, buffer }, [ buffer ] );

//this.debug();
// this.debug();

} );

} )
.then( ( message ) => this._createGeometry( message.data ) );
.then( ( message ) => this._createGeometry( message.data ) )
.catch( e => {

throw e;

} );

// Remove task from the task list.
// Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
Expand Down Expand Up @@ -159,8 +169,13 @@ class Rhino3dmLoader extends Loader {
parse( data, onLoad, onError ) {

this.decodeObjects( data, '' )
.then( onLoad )
.catch( onError );
.then( result => {

result.userData.warnings = this.warnings;
onLoad( result );

} )
.catch( e => onError( e ) );

}

Expand Down Expand Up @@ -332,7 +347,7 @@ class Rhino3dmLoader extends Loader {

} else {

const material = this._createMaterial( );
const material = this._createMaterial();
_object = this._createObject( obj, material );

}
Expand Down Expand Up @@ -575,49 +590,56 @@ class Rhino3dmLoader extends Loader {

let light;

if ( geometry.isDirectionalLight ) {
switch ( geometry.lightStyle.name ) {

light = new DirectionalLight();
light.castShadow = attributes.castsShadows;
light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
light.shadow.normalBias = 0.1;
case 'LightStyle_WorldPoint':

} else if ( geometry.isPointLight ) {
light = new PointLight();
light.castShadow = attributes.castsShadows;
light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
light.shadow.normalBias = 0.1;

light = new PointLight();
light.castShadow = attributes.castsShadows;
light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
light.shadow.normalBias = 0.1;
break;

} else if ( geometry.isRectangularLight ) {
case 'LightStyle_WorldSpot':

light = new RectAreaLight();
light = new SpotLight();
light.castShadow = attributes.castsShadows;
light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
light.angle = geometry.spotAngleRadians;
light.shadow.normalBias = 0.1;

const width = Math.abs( geometry.width[ 2 ] );
const height = Math.abs( geometry.length[ 0 ] );
break;

light.position.set( geometry.location[ 0 ] - ( height / 2 ), geometry.location[ 1 ], geometry.location[ 2 ] - ( width / 2 ) );
case 'LightStyle_WorldRectangular':

light.height = height;
light.width = width;
light = new RectAreaLight();
const width = Math.abs( geometry.width[ 2 ] );
const height = Math.abs( geometry.length[ 0 ] );
light.position.set( geometry.location[ 0 ] - ( height / 2 ), geometry.location[ 1 ], geometry.location[ 2 ] - ( width / 2 ) );
light.height = height;
light.width = width;
light.lookAt( new Vector3( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ) );

light.lookAt( new Vector3( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ) );
break;

} else if ( geometry.isSpotLight ) {
case 'LightStyle_WorldDirectional':

light = new SpotLight();
light.castShadow = attributes.castsShadows;
light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
light.angle = geometry.spotAngleRadians;
light.shadow.normalBias = 0.1;
light = new DirectionalLight();
light.castShadow = attributes.castsShadows;
light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
light.target.position.set( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] );
light.shadow.normalBias = 0.1;

} else if ( geometry.isLinearLight ) {
break;

console.warn( 'THREE.3DMLoader: No conversion exists for linear lights.' );
case 'LightStyle_WorldLinear':
// not conversion exists, warning has already been printed to the console
break;

return;
default:
break;

}

Expand Down Expand Up @@ -703,12 +725,17 @@ class Rhino3dmLoader extends Loader {
libraryConfig: this.libraryConfig
} );

worker.onmessage = function ( e ) {
worker.onmessage = e => {

const message = e.data;

switch ( message.type ) {

case 'warning':
this.warnings.push( message.data );
console.warn( message.data );
break;

case 'decode':
worker._callbacks[ message.id ].resolve( message );
break;
Expand Down Expand Up @@ -777,6 +804,7 @@ function Rhino3dmWorker() {
let libraryPending;
let libraryConfig;
let rhino;
let taskID;

onmessage = function ( e ) {

Expand All @@ -786,6 +814,7 @@ function Rhino3dmWorker() {

case 'init':

// console.log(message)
libraryConfig = message.libraryConfig;
const wasmBinary = libraryConfig.wasmBinary;
let RhinoModule;
Expand All @@ -806,12 +835,20 @@ function Rhino3dmWorker() {

case 'decode':

taskID = message.id;
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 } );

self.postMessage( { type: 'decode', id: message.id, data } );
} catch ( error ) {

self.postMessage( { type: 'error', id: message.id, error } );

}

} );

Expand Down Expand Up @@ -927,7 +964,13 @@ function Rhino3dmWorker() {

} else {

console.warn( `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` );
self.postMessage( { type: 'warning', id: taskID, data: {
message: `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.`,
type: 'missing resource'
}

} );

texture.image = null;

}
Expand Down Expand Up @@ -1192,6 +1235,18 @@ function Rhino3dmWorker() {

geometry = extractProperties( _geometry );

if ( geometry.lightStyle.name === 'LightStyle_WorldLinear' ) {

self.postMessage( { type: 'warning', id: taskID, data: {
message: `THREE.3DMLoader: No conversion exists for ${objectType.constructor.name} ${geometry.lightStyle.name}`,
type: 'no conversion',
guid: _attributes.id
}

} );

}

break;

case rhino.ObjectType.InstanceReference:
Expand Down Expand Up @@ -1223,7 +1278,15 @@ function Rhino3dmWorker() {
*/

default:
console.warn( `THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` );

self.postMessage( { type: 'warning', id: taskID, data: {
message: `THREE.3DMLoader: Conversion not implemented for ${objectType.constructor.name}`,
type: 'not implemented',
guid: _attributes.id
}

} );

break;

}
Expand Down Expand Up @@ -1260,7 +1323,13 @@ function Rhino3dmWorker() {

} else {

console.warn( `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` );
self.postMessage( { type: 'warning', id: taskID, data: {
message: `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.`,
type: 'missing mesh',
guid: _attributes.id
}

} );

}

Expand Down