|
@@ -18,6 +18,7 @@
|
|
|
this.workerSourceURL = '';
|
|
|
this.workerConfig = {};
|
|
|
this.materials = [];
|
|
|
+ this.warnings = [];
|
|
|
|
|
|
}
|
|
|
|
|
@@ -54,7 +55,12 @@
|
|
|
|
|
|
}
|
|
|
|
|
|
- this.decodeObjects( buffer, url ).then( onLoad ).catch( onError );
|
|
|
+ this.decodeObjects( buffer, url ).then( result => {
|
|
|
+
|
|
|
+ result.userData.warnings = this.warnings;
|
|
|
+ onLoad( result );
|
|
|
+
|
|
|
+ } ).catch( e => onError( e ) );
|
|
|
|
|
|
}, onProgress, onError );
|
|
|
|
|
@@ -75,8 +81,7 @@
|
|
|
const objectPending = this._getWorker( taskCost ).then( _worker => {
|
|
|
|
|
|
worker = _worker;
|
|
|
- taskID = this.workerNextTaskID ++; //hmmm
|
|
|
-
|
|
|
+ taskID = this.workerNextTaskID ++;
|
|
|
return new Promise( ( resolve, reject ) => {
|
|
|
|
|
|
worker._callbacks[ taskID ] = {
|
|
@@ -87,11 +92,15 @@
|
|
|
type: 'decode',
|
|
|
id: taskID,
|
|
|
buffer
|
|
|
- }, [ buffer ] ); //this.debug();
|
|
|
+ }, [ buffer ] ); // this.debug();
|
|
|
|
|
|
} );
|
|
|
|
|
|
- } ).then( message => this._createGeometry( message.data ) ); // Remove task from the task list.
|
|
|
+ } ).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)
|
|
|
|
|
|
|
|
@@ -116,7 +125,12 @@
|
|
|
|
|
|
parse( data, onLoad, onError ) {
|
|
|
|
|
|
- this.decodeObjects( data, '' ).then( onLoad ).catch( onError );
|
|
|
+ this.decodeObjects( data, '' ).then( result => {
|
|
|
+
|
|
|
+ result.userData.warnings = this.warnings;
|
|
|
+ onLoad( result );
|
|
|
+
|
|
|
+ } ).catch( e => onError( e ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -503,44 +517,48 @@
|
|
|
geometry = obj.geometry;
|
|
|
let light;
|
|
|
|
|
|
- if ( geometry.isDirectionalLight ) {
|
|
|
-
|
|
|
- light = new THREE.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.isPointLight ) {
|
|
|
-
|
|
|
- light = new THREE.PointLight();
|
|
|
- light.castShadow = attributes.castsShadows;
|
|
|
- light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
|
|
|
- light.shadow.normalBias = 0.1;
|
|
|
+ switch ( geometry.lightStyle.name ) {
|
|
|
|
|
|
- } else if ( geometry.isRectangularLight ) {
|
|
|
+ case 'LightStyle_WorldPoint':
|
|
|
+ light = new THREE.PointLight();
|
|
|
+ light.castShadow = attributes.castsShadows;
|
|
|
+ light.position.set( geometry.location[ 0 ], geometry.location[ 1 ], geometry.location[ 2 ] );
|
|
|
+ light.shadow.normalBias = 0.1;
|
|
|
+ break;
|
|
|
|
|
|
- light = new THREE.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 THREE.Vector3( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ) );
|
|
|
+ case 'LightStyle_WorldSpot':
|
|
|
+ light = new THREE.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;
|
|
|
+ break;
|
|
|
|
|
|
- } else if ( geometry.isSpotLight ) {
|
|
|
+ case 'LightStyle_WorldRectangular':
|
|
|
+ light = new THREE.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 THREE.Vector3( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ) );
|
|
|
+ break;
|
|
|
|
|
|
- light = new THREE.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;
|
|
|
+ case 'LightStyle_WorldDirectional':
|
|
|
+ light = new THREE.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;
|
|
|
+ break;
|
|
|
|
|
|
- } else if ( geometry.isLinearLight ) {
|
|
|
+ case 'LightStyle_WorldLinear':
|
|
|
+ // not conversion exists, warning has already been printed to the console
|
|
|
+ break;
|
|
|
|
|
|
- console.warn( 'THREE.3DMLoader: No conversion exists for linear lights.' );
|
|
|
- return;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
|
|
|
}
|
|
|
|
|
@@ -613,12 +631,17 @@
|
|
|
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 );
|
|
|
|
|
@@ -686,6 +709,7 @@
|
|
|
let libraryPending;
|
|
|
let libraryConfig;
|
|
|
let rhino;
|
|
|
+ let taskID;
|
|
|
|
|
|
onmessage = function ( e ) {
|
|
|
|
|
@@ -694,6 +718,7 @@
|
|
|
switch ( message.type ) {
|
|
|
|
|
|
case 'init':
|
|
|
+ // console.log(message)
|
|
|
libraryConfig = message.libraryConfig;
|
|
|
const wasmBinary = libraryConfig.wasmBinary;
|
|
|
let RhinoModule;
|
|
@@ -714,15 +739,28 @@
|
|
|
break;
|
|
|
|
|
|
case 'decode':
|
|
|
+ taskID = message.id;
|
|
|
const buffer = message.buffer;
|
|
|
libraryPending.then( () => {
|
|
|
|
|
|
- const data = decodeObjects( rhino, buffer );
|
|
|
- self.postMessage( {
|
|
|
- type: 'decode',
|
|
|
- id: message.id,
|
|
|
- data
|
|
|
- } );
|
|
|
+ try {
|
|
|
+
|
|
|
+ const data = decodeObjects( rhino, buffer );
|
|
|
+ self.postMessage( {
|
|
|
+ type: 'decode',
|
|
|
+ id: message.id,
|
|
|
+ data
|
|
|
+ } );
|
|
|
+
|
|
|
+ } catch ( error ) {
|
|
|
+
|
|
|
+ self.postMessage( {
|
|
|
+ type: 'error',
|
|
|
+ id: message.id,
|
|
|
+ error
|
|
|
+ } );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} );
|
|
|
break;
|
|
@@ -809,7 +847,14 @@
|
|
|
|
|
|
} 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;
|
|
|
|
|
|
}
|
|
@@ -1057,6 +1102,21 @@
|
|
|
|
|
|
case rhino.ObjectType.Light:
|
|
|
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:
|
|
@@ -1087,7 +1147,15 @@
|
|
|
*/
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
@@ -1126,7 +1194,15 @@
|
|
|
|
|
|
} 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
|
|
|
+ }
|
|
|
+ } );
|
|
|
|
|
|
}
|
|
|
|