From 158a87559bb5d81cabacbe53be7243b2f5fe4fb3 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Thu, 11 Feb 2021 15:30:50 +0100 Subject: [PATCH 01/22] extract name and value properties from objects --- examples/jsm/loaders/3DMLoader.js | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index c1ec669f7e8da7..239f875fa58767 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -1251,7 +1251,6 @@ Rhino3dmLoader.Rhino3dmWorker = function () { objectType = objectType.constructor.name; objectType = objectType.substring( 11, objectType.length ); - attributes.geometry.objectType = objectType; return { geometry, attributes, objectType }; @@ -1269,13 +1268,24 @@ Rhino3dmLoader.Rhino3dmWorker = function () { for ( var property in object ) { - if ( typeof object[ property ] !== 'function' ) { + var value = object[ property ]; - result[ property ] = object[ property ]; + if ( typeof value !== 'function' ) { + + if ( typeof value === 'object' && value !== null && value.hasOwnProperty( 'constructor' ) ) { + + result[ property ] = { name: value.constructor.name, value: value.value }; + + } else { + + result[ property ] = value; + + } } else { - // console.log( `${property}: ${object[ property ]}` ); + // these are functions that could be called to extract more data. + //console.log( `${property}: ${object[ property ].constructor.name}` ); } @@ -1368,7 +1378,7 @@ Rhino3dmLoader.Rhino3dmWorker = function () { var tan = curve.tangentAt( t ); var prevTan = curve.tangentAt( ts.slice( - 1 )[ 0 ] ); - // Duplicaated from THREE.Vector3 + // Duplicated from THREE.Vector3 // How to pass imports to worker? var tS = tan[ 0 ] * tan[ 0 ] + tan[ 1 ] * tan[ 1 ] + tan[ 2 ] * tan[ 2 ]; From ec3ff76b8e389086c9bde793e8360ba69491fd50 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Mon, 15 Feb 2021 07:03:48 +0100 Subject: [PATCH 02/22] Extract object userStrings --- examples/jsm/loaders/3DMLoader.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 239f875fa58767..2f9842127021b5 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -1247,6 +1247,12 @@ Rhino3dmLoader.Rhino3dmWorker = function () { } + if ( _geometry.userStringCount > 0 ) { + + attributes.geometry.userStrings = _geometry.getUserStrings(); + + } + attributes.drawColor = _attributes.drawColor( doc ); objectType = objectType.constructor.name; From c810381bbaf1cd733c9d57abef05cac5258e1fc4 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Thu, 15 Apr 2021 18:11:14 +0200 Subject: [PATCH 03/22] 3dmLoader: refactor es6 --- examples/jsm/loaders/3DMLoader.js | 370 +++++++++++++++--------------- 1 file changed, 187 insertions(+), 183 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 8dba9cd7b01705..36bbe06937782d 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -21,7 +21,9 @@ import { CanvasTexture, LinearFilter, ClampToEdgeWrapping, - TextureLoader + TextureLoader, + LatheGeometry, + LinearToneMapping } from '../../../build/three.module.js'; const _taskCache = new WeakMap(); @@ -104,12 +106,12 @@ class Rhino3dmLoader extends Loader { decodeObjects( buffer, url ) { - var worker; - var taskID; + let worker; + let taskID; - var taskCost = buffer.byteLength; + const taskCost = buffer.byteLength; - var objectPending = this._getWorker( taskCost ) + const objectPending = this._getWorker( taskCost ) .then( ( _worker ) => { worker = _worker; @@ -166,7 +168,7 @@ class Rhino3dmLoader extends Loader { _compareMaterials( material ) { - var mat = {}; + const mat = {}; mat.name = material.name; mat.color = {}; mat.color.r = material.color.r; @@ -174,10 +176,10 @@ class Rhino3dmLoader extends Loader { mat.color.b = material.color.b; mat.type = material.type; - for ( var i = 0; i < this.materials.length; i ++ ) { + for ( let i = 0; i < this.materials.length; i ++ ) { - var m = this.materials[ i ]; - var _mat = {}; + const m = this.materials[ i ]; + const _mat = {}; _mat.name = m.name; _mat.color = {}; _mat.color.r = m.color.r; @@ -212,9 +214,9 @@ class Rhino3dmLoader extends Loader { } - var _diffuseColor = material.diffuseColor; + const _diffuseColor = material.diffuseColor; - var diffusecolor = new Color( _diffuseColor.r / 255.0, _diffuseColor.g / 255.0, _diffuseColor.b / 255.0 ); + const diffusecolor = new Color( _diffuseColor.r / 255.0, _diffuseColor.g / 255.0, _diffuseColor.b / 255.0 ); if ( _diffuseColor.r === 0 && _diffuseColor.g === 0 && _diffuseColor.b === 0 ) { @@ -226,7 +228,7 @@ class Rhino3dmLoader extends Loader { // console.log( material ); - var mat = new MeshStandardMaterial( { + const mat = new MeshStandardMaterial( { color: diffusecolor, name: material.name, side: 2, @@ -234,15 +236,15 @@ class Rhino3dmLoader extends Loader { opacity: 1.0 - material.transparency } ); - var textureLoader = new TextureLoader(); + const textureLoader = new TextureLoader(); - for ( var i = 0; i < material.textures.length; i ++ ) { + for ( let i = 0; i < material.textures.length; i ++ ) { - var texture = material.textures[ i ]; + const texture = material.textures[ i ]; if ( texture.image !== null ) { - var map = textureLoader.load( texture.image ); + const map = textureLoader.load( texture.image ); switch ( texture.type ) { @@ -285,10 +287,10 @@ class Rhino3dmLoader extends Loader { // console.log(data); - var object = new Object3D(); - var instanceDefinitionObjects = []; - var instanceDefinitions = []; - var instanceReferences = []; + const object = new Object3D(); + const instanceDefinitionObjects = []; + const instanceDefinitions = []; + const instanceReferences = []; object.userData[ 'layers' ] = data.layers; object.userData[ 'groups' ] = data.groups; @@ -297,13 +299,13 @@ class Rhino3dmLoader extends Loader { object.userData[ 'materials' ] = null; object.name = this.url; - var objects = data.objects; - var materials = data.materials; + let objects = data.objects; + const materials = data.materials; - for ( var i = 0; i < objects.length; i ++ ) { + for ( let i = 0; i < objects.length; i ++ ) { - var obj = objects[ i ]; - var attributes = obj.attributes; + const obj = objects[ i ]; + const attributes = obj.attributes; switch ( obj.objectType ) { @@ -321,17 +323,19 @@ class Rhino3dmLoader extends Loader { default: + let _object; + if ( attributes.materialIndex >= 0 ) { - var rMaterial = materials[ attributes.materialIndex ]; - var material = this._createMaterial( rMaterial ); + const rMaterial = materials[ attributes.materialIndex ]; + let material = this._createMaterial( rMaterial ); material = this._compareMaterials( material ); - var _object = this._createObject( obj, material ); + _object = this._createObject( obj, material ); } else { - var material = this._createMaterial( ); - var _object = this._createObject( obj, material ); + const material = this._createMaterial( ); + _object = this._createObject( obj, material ); } @@ -341,7 +345,7 @@ class Rhino3dmLoader extends Loader { } - var layer = data.layers[ attributes.layerIndex ]; + const layer = data.layers[ attributes.layerIndex ]; _object.visible = layer ? data.layers[ attributes.layerIndex ].visible : true; @@ -361,19 +365,19 @@ class Rhino3dmLoader extends Loader { } - for ( var i = 0; i < instanceDefinitions.length; i ++ ) { + for ( let i = 0; i < instanceDefinitions.length; i ++ ) { - var iDef = instanceDefinitions[ i ]; + const iDef = instanceDefinitions[ i ]; - var objects = []; + objects = []; - for ( var j = 0; j < iDef.attributes.objectIds.length; j ++ ) { + for ( let j = 0; j < iDef.attributes.objectIds.length; j ++ ) { - var objId = iDef.attributes.objectIds[ j ]; + const objId = iDef.attributes.objectIds[ j ]; - for ( var p = 0; p < instanceDefinitionObjects.length; p ++ ) { + for ( let p = 0; p < instanceDefinitionObjects.length; p ++ ) { - var idoId = instanceDefinitionObjects[ p ].userData.attributes.id; + const idoId = instanceDefinitionObjects[ p ].userData.attributes.id; if ( objId === idoId ) { @@ -387,21 +391,21 @@ class Rhino3dmLoader extends Loader { // Currently clones geometry and does not take advantage of instancing - for ( var j = 0; j < instanceReferences.length; j ++ ) { + for ( let j = 0; j < instanceReferences.length; j ++ ) { - var iRef = instanceReferences[ j ]; + const iRef = instanceReferences[ j ]; if ( iRef.geometry.parentIdefId === iDef.attributes.id ) { - var iRefObject = new Object3D(); - var xf = iRef.geometry.xform.array; + const iRefObject = new Object3D(); + const xf = iRef.geometry.xform.array; - var matrix = new Matrix4(); + const matrix = new Matrix4(); matrix.set( xf[ 0 ], xf[ 1 ], xf[ 2 ], xf[ 3 ], xf[ 4 ], xf[ 5 ], xf[ 6 ], xf[ 7 ], xf[ 8 ], xf[ 9 ], xf[ 10 ], xf[ 11 ], xf[ 12 ], xf[ 13 ], xf[ 14 ], xf[ 15 ] ); iRefObject.applyMatrix4( matrix ); - for ( var p = 0; p < objects.length; p ++ ) { + for ( let p = 0; p < objects.length; p ++ ) { iRefObject.add( objects[ p ].clone( true ) ); @@ -422,33 +426,34 @@ class Rhino3dmLoader extends Loader { _createObject( obj, mat ) { - var loader = new BufferGeometryLoader(); + const loader = new BufferGeometryLoader(); + + const attributes = obj.attributes; - var attributes = obj.attributes; + let geometry, material, _color, color; switch ( obj.objectType ) { case 'Point': case 'PointSet': - var geometry = loader.parse( obj.geometry ); + geometry = loader.parse( obj.geometry ); - var material = null; if ( geometry.attributes.hasOwnProperty( 'color' ) ) { material = new PointsMaterial( { vertexColors: true, sizeAttenuation: false, size: 2 } ); } else { - var _color = attributes.drawColor; - var color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ); + _color = attributes.drawColor; + color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ); material = new PointsMaterial( { color: color, sizeAttenuation: false, size: 2 } ); } material = this._compareMaterials( material ); - var points = new Points( geometry, material ); + const points = new Points( geometry, material ); points.userData[ 'attributes' ] = attributes; points.userData[ 'objectType' ] = obj.objectType; @@ -467,7 +472,7 @@ class Rhino3dmLoader extends Loader { if ( obj.geometry === null ) return; - var geometry = loader.parse( obj.geometry ); + geometry = loader.parse( obj.geometry ); if ( geometry.attributes.hasOwnProperty( 'color' ) ) { @@ -482,7 +487,7 @@ class Rhino3dmLoader extends Loader { } - var mesh = new Mesh( geometry, mat ); + const mesh = new Mesh( geometry, mat ); mesh.castShadow = attributes.castsShadows; mesh.receiveShadow = attributes.receivesShadows; mesh.userData[ 'attributes' ] = attributes; @@ -500,13 +505,13 @@ class Rhino3dmLoader extends Loader { geometry = loader.parse( obj.geometry ); - var _color = attributes.drawColor; - var color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ); + _color = attributes.drawColor; + color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ); - var material = new LineBasicMaterial( { color: color } ); + material = new LineBasicMaterial( { color: color } ); material = this._compareMaterials( material ); - var lines = new Line( geometry, material ); + const lines = new Line( geometry, material ); lines.userData[ 'attributes' ] = attributes; lines.userData[ 'objectType' ] = obj.objectType; @@ -522,13 +527,13 @@ class Rhino3dmLoader extends Loader { geometry = obj.geometry; - var ctx = document.createElement( 'canvas' ).getContext( '2d' ); - var font = `${geometry.fontHeight}px ${geometry.fontFace}`; + const ctx = document.createElement( 'canvas' ).getContext( '2d' ); + const font = `${geometry.fontHeight}px ${geometry.fontFace}`; ctx.font = font; - var width = ctx.measureText( geometry.text ).width + 10; - var height = geometry.fontHeight + 10; + const width = ctx.measureText( geometry.text ).width + 10; + const height = geometry.fontHeight + 10; - var r = window.devicePixelRatio; + const r = window.devicePixelRatio; ctx.canvas.width = width * r; ctx.canvas.height = height * r; @@ -539,19 +544,19 @@ class Rhino3dmLoader extends Loader { ctx.font = font; ctx.textBaseline = 'middle'; ctx.textAlign = 'center'; - var color = attributes.drawColor; + color = attributes.drawColor; ctx.fillStyle = `rgba(${color.r},${color.g},${color.b},${color.a})`; ctx.fillRect( 0, 0, width, height ); ctx.fillStyle = 'white'; ctx.fillText( geometry.text, width / 2, height / 2 ); - var texture = new CanvasTexture( ctx.canvas ); + const texture = new CanvasTexture( ctx.canvas ); texture.minFilter = LinearFilter; texture.wrapS = ClampToEdgeWrapping; texture.wrapT = ClampToEdgeWrapping; - var material = new SpriteMaterial( { map: texture, depthTest: false } ); - var sprite = new Sprite( material ); + material = new SpriteMaterial( { map: texture, depthTest: false } ); + const sprite = new Sprite( material ); sprite.position.set( geometry.point[ 0 ], geometry.point[ 1 ], geometry.point[ 2 ] ); sprite.scale.set( width / 10, height / 10, 1.0 ); @@ -570,7 +575,7 @@ class Rhino3dmLoader extends Loader { geometry = obj.geometry; - var light; + let light; if ( geometry.isDirectionalLight ) { @@ -591,8 +596,8 @@ class Rhino3dmLoader extends Loader { light = new RectAreaLight(); - var width = Math.abs( geometry.width[ 2 ] ); - var height = Math.abs( geometry.length[ 0 ] ); + 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 ) ); @@ -621,8 +626,8 @@ class Rhino3dmLoader extends Loader { if ( light ) { light.intensity = geometry.intensity; - var _color = geometry.diffuse; - var color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ); + _color = geometry.diffuse; + color = new Color( _color.r / 255.0, _color.g / 255.0, _color.b / 255.0 ); light.color = color; light.userData[ 'attributes' ] = attributes; light.userData[ 'objectType' ] = obj.objectType; @@ -640,19 +645,19 @@ class Rhino3dmLoader extends Loader { if ( ! this.libraryPending ) { // Load rhino3dm wrapper. - var jsLoader = new FileLoader( this.manager ); + const jsLoader = new FileLoader( this.manager ); jsLoader.setPath( this.libraryPath ); - var jsContent = new Promise( ( resolve, reject ) => { + const jsContent = new Promise( ( resolve, reject ) => { jsLoader.load( 'rhino3dm.js', resolve, undefined, reject ); } ); // Load rhino3dm WASM binary. - var binaryLoader = new FileLoader( this.manager ); + const binaryLoader = new FileLoader( this.manager ); binaryLoader.setPath( this.libraryPath ); binaryLoader.setResponseType( 'arraybuffer' ); - var binaryContent = new Promise( ( resolve, reject ) => { + const binaryContent = new Promise( ( resolve, reject ) => { binaryLoader.load( 'rhino3dm.wasm', resolve, undefined, reject ); @@ -664,9 +669,9 @@ class Rhino3dmLoader extends Loader { //this.libraryBinary = binaryContent; this.libraryConfig.wasmBinary = binaryContent; - var fn = Rhino3dmWorker.toString(); + const fn = Rhino3dmWorker.toString(); - var body = [ + const body = [ '/* rhino3dm.js */', jsContent, '/* worker */', @@ -689,7 +694,7 @@ class Rhino3dmLoader extends Loader { if ( this.workerPool.length < this.workerLimit ) { - var worker = new Worker( this.workerSourceURL ); + const worker = new Worker( this.workerSourceURL ); worker._callbacks = {}; worker._taskCosts = {}; @@ -702,7 +707,7 @@ class Rhino3dmLoader extends Loader { worker.onmessage = function ( e ) { - var message = e.data; + const message = e.data; switch ( message.type ) { @@ -733,7 +738,7 @@ class Rhino3dmLoader extends Loader { } - var worker = this.workerPool[ this.workerPool.length - 1 ]; + const worker = this.workerPool[ this.workerPool.length - 1 ]; worker._taskLoad += taskCost; @@ -753,7 +758,7 @@ class Rhino3dmLoader extends Loader { dispose() { - for ( var i = 0; i < this.workerPool.length; ++ i ) { + for ( let i = 0; i < this.workerPool.length; ++ i ) { this.workerPool[ i ].terminate(); @@ -771,21 +776,21 @@ class Rhino3dmLoader extends Loader { function Rhino3dmWorker() { - var libraryPending; - var libraryConfig; - var rhino; + let libraryPending; + let libraryConfig; + let rhino; onmessage = function ( e ) { - var message = e.data; + const message = e.data; switch ( message.type ) { case 'init': libraryConfig = message.libraryConfig; - var wasmBinary = libraryConfig.wasmBinary; - var RhinoModule; + const wasmBinary = libraryConfig.wasmBinary; + let RhinoModule; libraryPending = new Promise( function ( resolve ) { /* Like Basis Loader */ @@ -803,10 +808,10 @@ function Rhino3dmWorker() { case 'decode': - var buffer = message.buffer; + const buffer = message.buffer; libraryPending.then( () => { - var data = decodeObjects( rhino, buffer ); + const data = decodeObjects( rhino, buffer ); self.postMessage( { type: 'decode', id: message.id, data } ); @@ -820,26 +825,26 @@ function Rhino3dmWorker() { function decodeObjects( rhino, buffer ) { - var arr = new Uint8Array( buffer ); - var doc = rhino.File3dm.fromByteArray( arr ); + const arr = new Uint8Array( buffer ); + const doc = rhino.File3dm.fromByteArray( arr ); - var objects = []; - var materials = []; - var layers = []; - var views = []; - var namedViews = []; - var groups = []; + const objects = []; + const materials = []; + const layers = []; + const views = []; + const namedViews = []; + const groups = []; //Handle objects - var objs = doc.objects(); - var cnt = objs.count; + const objs = doc.objects(); + const cnt = objs.count; - for ( var i = 0; i < cnt; i ++ ) { + for ( let i = 0; i < cnt; i ++ ) { - var _object = objs.get( i ); + const _object = objs.get( i ); - var object = extractObjectData( _object, doc ); + const object = extractObjectData( _object, doc ); _object.delete(); @@ -854,10 +859,10 @@ function Rhino3dmWorker() { // Handle instance definitions // console.log( `Instance Definitions Count: ${doc.instanceDefinitions().count()}` ); - for ( var i = 0; i < doc.instanceDefinitions().count(); i ++ ) { + for ( let i = 0; i < doc.instanceDefinitions().count(); i ++ ) { - var idef = doc.instanceDefinitions().get( i ); - var idefAttributes = extractProperties( idef ); + const idef = doc.instanceDefinitions().get( i ); + const idefAttributes = extractProperties( idef ); idefAttributes.objectIds = idef.getObjectIds(); objects.push( { geometry: null, attributes: idefAttributes, objectType: 'InstanceDefinition' } ); @@ -866,7 +871,7 @@ function Rhino3dmWorker() { // Handle materials - var textureTypes = [ + const textureTypes = [ // rhino.TextureType.Bitmap, rhino.TextureType.Diffuse, rhino.TextureType.Bump, @@ -875,7 +880,7 @@ function Rhino3dmWorker() { rhino.TextureType.Emap ]; - var pbrTextureTypes = [ + const pbrTextureTypes = [ rhino.TextureType.PBR_BaseColor, rhino.TextureType.PBR_Subsurface, rhino.TextureType.PBR_SubsurfaceScattering, @@ -898,25 +903,25 @@ function Rhino3dmWorker() { rhino.TextureType.PBR_Displacement ]; - for ( var i = 0; i < doc.materials().count(); i ++ ) { + for ( let i = 0; i < doc.materials().count(); i ++ ) { - var _material = doc.materials().get( i ); - var _pbrMaterial = _material.physicallyBased(); + const _material = doc.materials().get( i ); + const _pbrMaterial = _material.physicallyBased(); - var material = extractProperties( _material ); + const material = extractProperties( _material ); - var textures = []; + const textures = []; - for ( var j = 0; j < textureTypes.length; j ++ ) { + for ( let j = 0; j < textureTypes.length; j ++ ) { - var _texture = _material.getTexture( textureTypes[ j ] ); + const _texture = _material.getTexture( textureTypes[ j ] ); if ( _texture ) { - var textureType = textureTypes[ j ].constructor.name; + const textureType = textureTypes[ j ].constructor.name; textureType = textureType.substring( 12, textureType.length ); - var texture = { type: textureType }; + const texture = { type: textureType }; - var image = doc.getEmbeddedFileAsBase64( _texture.fileName ); + const image = doc.getEmbeddedFileAsBase64( _texture.fileName ); if ( image ) { @@ -943,15 +948,15 @@ function Rhino3dmWorker() { console.log( 'pbr true' ); - for ( var j = 0; j < pbrTextureTypes.length; j ++ ) { + for ( let j = 0; j < pbrTextureTypes.length; j ++ ) { - var _texture = _material.getTexture( textureTypes[ j ] ); + const _texture = _material.getTexture( textureTypes[ j ] ); if ( _texture ) { - var image = doc.getEmbeddedFileAsBase64( _texture.fileName ); - var textureType = textureTypes[ j ].constructor.name; + const image = doc.getEmbeddedFileAsBase64( _texture.fileName ); + const textureType = textureTypes[ j ].constructor.name; textureType = textureType.substring( 12, textureType.length ); - var texture = { type: textureType, image: 'data:image/png;base64,' + image }; + const texture = { type: textureType, image: 'data:image/png;base64,' + image }; textures.push( texture ); _texture.delete(); @@ -960,7 +965,7 @@ function Rhino3dmWorker() { } - var pbMaterialProperties = extractProperties( _material.physicallyBased() ); + const pbMaterialProperties = extractProperties( _material.physicallyBased() ); material = Object.assign( pbMaterialProperties, material ); @@ -975,10 +980,10 @@ function Rhino3dmWorker() { // Handle layers - for ( var i = 0; i < doc.layers().count(); i ++ ) { + for ( let i = 0; i < doc.layers().count(); i ++ ) { - var _layer = doc.layers().get( i ); - var layer = extractProperties( _layer ); + const _layer = doc.layers().get( i ); + const layer = extractProperties( _layer ); layers.push( layer ); @@ -988,10 +993,10 @@ function Rhino3dmWorker() { // Handle views - for ( var i = 0; i < doc.views().count(); i ++ ) { + for ( let i = 0; i < doc.views().count(); i ++ ) { - var _view = doc.views().get( i ); - var view = extractProperties( _view ); + const _view = doc.views().get( i ); + const view = extractProperties( _view ); views.push( view ); @@ -1001,10 +1006,10 @@ function Rhino3dmWorker() { // Handle named views - for ( var i = 0; i < doc.namedViews().count(); i ++ ) { + for ( let i = 0; i < doc.namedViews().count(); i ++ ) { - var _namedView = doc.namedViews().get( i ); - var namedView = extractProperties( _namedView ); + const _namedView = doc.namedViews().get( i ); + const namedView = extractProperties( _namedView ); namedViews.push( namedView ); @@ -1014,10 +1019,10 @@ function Rhino3dmWorker() { // Handle groups - for ( var i = 0; i < doc.groups().count(); i ++ ) { + for ( let i = 0; i < doc.groups().count(); i ++ ) { - var _group = doc.groups().get( i ); - var group = extractProperties( _group ); + const _group = doc.groups().get( i ); + const group = extractProperties( _group ); groups.push( group ); @@ -1027,7 +1032,7 @@ function Rhino3dmWorker() { // Handle settings - var settings = extractProperties( doc.settings() ); + const settings = extractProperties( doc.settings() ); //TODO: Handle other document stuff like dimstyles, instance definitions, bitmaps etc. @@ -1063,11 +1068,10 @@ function Rhino3dmWorker() { function extractObjectData( object, doc ) { - var _geometry = object.geometry(); - var _attributes = object.attributes(); - var objectType = _geometry.objectType; - var geometry = null; - var attributes = null; + const _geometry = object.geometry(); + const _attributes = object.attributes(); + let objectType = _geometry.objectType; + let geometry, attributes, position, data, mesh; // skip instance definition objects //if( _attributes.isInstanceDefinitionObject ) { continue; } @@ -1077,17 +1081,17 @@ function Rhino3dmWorker() { case rhino.ObjectType.Curve: - var pts = curveToPoints( _geometry, 100 ); + const pts = curveToPoints( _geometry, 100 ); - var position = {}; - var attributes = {}; - var data = {}; + position = {}; + attributes = {}; + data = {}; position.itemSize = 3; position.type = 'Float32Array'; position.array = []; - for ( var j = 0; j < pts.length; j ++ ) { + for ( let j = 0; j < pts.length; j ++ ) { position.array.push( pts[ j ][ 0 ] ); position.array.push( pts[ j ][ 1 ] ); @@ -1104,18 +1108,18 @@ function Rhino3dmWorker() { case rhino.ObjectType.Point: - var pt = _geometry.location; + const pt = _geometry.location; - var position = {}; - var color = {}; - var attributes = {}; - var data = {}; + position = {}; + const color = {}; + attributes = {}; + data = {}; position.itemSize = 3; position.type = 'Float32Array'; position.array = [ pt[ 0 ], pt[ 1 ], pt[ 2 ] ]; - var _color = _attributes.drawColor( doc ); + const _color = _attributes.drawColor( doc ); color.itemSize = 3; color.type = 'Float32Array'; @@ -1138,13 +1142,13 @@ function Rhino3dmWorker() { case rhino.ObjectType.Brep: - var faces = _geometry.faces(); - var mesh = new rhino.Mesh(); + const faces = _geometry.faces(); + mesh = new rhino.Mesh(); - for ( var faceIndex = 0; faceIndex < faces.count; faceIndex ++ ) { + for ( let faceIndex = 0; faceIndex < faces.count; faceIndex ++ ) { - var face = faces.get( faceIndex ); - var _mesh = face.getMesh( rhino.MeshType.Any ); + const face = faces.get( faceIndex ); + const _mesh = face.getMesh( rhino.MeshType.Any ); if ( _mesh ) { @@ -1171,7 +1175,7 @@ function Rhino3dmWorker() { case rhino.ObjectType.Extrusion: - var mesh = _geometry.getMesh( rhino.MeshType.Any ); + mesh = _geometry.getMesh( rhino.MeshType.Any ); if ( mesh ) { @@ -1206,7 +1210,7 @@ function Rhino3dmWorker() { // TODO: precalculate resulting vertices and faces and warn on excessive results _geometry.subdivide( 3 ); - var mesh = rhino.Mesh.createFromSubDControlNet( _geometry ); + mesh = rhino.Mesh.createFromSubDControlNet( _geometry ); if ( mesh ) { geometry = mesh.toThreejsJSON(); @@ -1230,7 +1234,7 @@ function Rhino3dmWorker() { if ( geometry ) { - var attributes = extractProperties( _attributes ); + attributes = extractProperties( _attributes ); attributes.geometry = extractProperties( _geometry ); if ( _attributes.groupCount > 0 ) { @@ -1268,11 +1272,11 @@ function Rhino3dmWorker() { function extractProperties( object ) { - var result = {}; + const result = {}; - for ( var property in object ) { + for ( const property in object ) { - var value = object[ property ]; + const value = object[ property ]; if ( typeof value !== 'function' ) { @@ -1301,9 +1305,9 @@ function Rhino3dmWorker() { function curveToPoints( curve, pointLimit ) { - var pointCount = pointLimit; - var rc = []; - var ts = []; + let pointCount = pointLimit; + let rc = []; + const ts = []; if ( curve instanceof rhino.LineCurve ) { @@ -1314,7 +1318,7 @@ function Rhino3dmWorker() { if ( curve instanceof rhino.PolylineCurve ) { pointCount = curve.pointCount; - for ( var i = 0; i < pointCount; i ++ ) { + for ( let i = 0; i < pointCount; i ++ ) { rc.push( curve.point( i ) ); @@ -1326,12 +1330,12 @@ function Rhino3dmWorker() { if ( curve instanceof rhino.PolyCurve ) { - var segmentCount = curve.segmentCount; + const segmentCount = curve.segmentCount; - for ( var i = 0; i < segmentCount; i ++ ) { + for ( let i = 0; i < segmentCount; i ++ ) { - var segment = curve.segmentCurve( i ); - var segmentArray = curveToPoints( segment, pointCount ); + const segment = curve.segmentCurve( i ); + const segmentArray = curveToPoints( segment, pointCount ); rc = rc.concat( segmentArray ); segment.delete(); @@ -1353,7 +1357,7 @@ function Rhino3dmWorker() { const pLine = curve.tryGetPolyline(); - for ( var i = 0; i < pLine.count; i ++ ) { + for ( let i = 0; i < pLine.count; i ++ ) { rc.push( pLine.get( i ) ); @@ -1365,12 +1369,12 @@ function Rhino3dmWorker() { } - var domain = curve.domain; - var divisions = pointCount - 1.0; + const domain = curve.domain; + const divisions = pointCount - 1.0; - for ( var j = 0; j < pointCount; j ++ ) { + for ( let j = 0; j < pointCount; j ++ ) { - var t = domain[ 0 ] + ( j / divisions ) * ( domain[ 1 ] - domain[ 0 ] ); + const t = domain[ 0 ] + ( j / divisions ) * ( domain[ 1 ] - domain[ 0 ] ); if ( t === domain[ 0 ] || t === domain[ 1 ] ) { @@ -1379,18 +1383,18 @@ function Rhino3dmWorker() { } - var tan = curve.tangentAt( t ); - var prevTan = curve.tangentAt( ts.slice( - 1 )[ 0 ] ); + const tan = curve.tangentAt( t ); + const prevTan = curve.tangentAt( ts.slice( - 1 )[ 0 ] ); // Duplicated from THREE.Vector3 // How to pass imports to worker? - var tS = tan[ 0 ] * tan[ 0 ] + tan[ 1 ] * tan[ 1 ] + tan[ 2 ] * tan[ 2 ]; - var ptS = prevTan[ 0 ] * prevTan[ 0 ] + prevTan[ 1 ] * prevTan[ 1 ] + prevTan[ 2 ] * prevTan[ 2 ]; + const tS = tan[ 0 ] * tan[ 0 ] + tan[ 1 ] * tan[ 1 ] + tan[ 2 ] * tan[ 2 ]; + const ptS = prevTan[ 0 ] * prevTan[ 0 ] + prevTan[ 1 ] * prevTan[ 1 ] + prevTan[ 2 ] * prevTan[ 2 ]; - var denominator = Math.sqrt( tS * ptS ); + const denominator = Math.sqrt( tS * ptS ); - var angle; + let angle; if ( denominator === 0 ) { @@ -1398,7 +1402,7 @@ function Rhino3dmWorker() { } else { - var theta = ( tan.x * prevTan.x + tan.y * prevTan.y + tan.z * prevTan.z ) / denominator; + const theta = ( tan.x * prevTan.x + tan.y * prevTan.y + tan.z * prevTan.z ) / denominator; angle = Math.acos( Math.max( - 1, Math.min( 1, theta ) ) ); } From 4176142ec51ba7a78570304f541f048f9f2f2bd4 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Thu, 15 Apr 2021 21:03:29 +0200 Subject: [PATCH 04/22] Remove unnecessary imports. --- examples/jsm/loaders/3DMLoader.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 36bbe06937782d..769f853e7cd45c 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -21,9 +21,7 @@ import { CanvasTexture, LinearFilter, ClampToEdgeWrapping, - TextureLoader, - LatheGeometry, - LinearToneMapping + TextureLoader } from '../../../build/three.module.js'; const _taskCache = new WeakMap(); From 1d97c81918bffa92d5c9418bfb3929875d041b61 Mon Sep 17 00:00:00 2001 From: karimi Date: Tue, 13 Apr 2021 09:31:15 -0400 Subject: [PATCH 05/22] Store conversion warnings in returned object --- examples/jsm/loaders/3DMLoader.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 7d555c149690ac..ce1e5595ab46db 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -295,6 +295,7 @@ class Rhino3dmLoader extends Loader { object.userData[ 'settings' ] = data.settings; object.userData[ 'objectType' ] = 'File3dm'; object.userData[ 'materials' ] = null; + object.warnings = data.warnings; object.name = this.url; let objects = data.objects; @@ -328,12 +329,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, warning =>object.warnings.push( warning ) ); } else { const material = this._createMaterial( ); - _object = this._createObject( obj, material ); + _object = this._createObject( obj, material, warning =>object.warnings.push( warning ) ); } @@ -422,7 +423,7 @@ class Rhino3dmLoader extends Loader { } - _createObject( obj, mat ) { + _createObject( obj, mat, onWarning ) { const loader = new BufferGeometryLoader(); @@ -616,6 +617,7 @@ class Rhino3dmLoader extends Loader { } else if ( geometry.isLinearLight ) { console.warn( 'THREE.3DMLoader: No conversion exists for linear lights.' ); + onWarning( 'THREE.3DMLoader: No conversion exists for linear lights.' ); return; @@ -832,6 +834,7 @@ function Rhino3dmWorker() { const views = []; const namedViews = []; const groups = []; + const warnings = []; //Handle objects @@ -842,7 +845,7 @@ function Rhino3dmWorker() { const _object = objs.get( i ); - const object = extractObjectData( _object, doc ); + const object = extractObjectData( _object, doc, ( warning )=>warnings.push( warning ) ); _object.delete(); @@ -928,6 +931,7 @@ function Rhino3dmWorker() { } else { console.warn( `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` ); + warnings.push( `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` ); texture.image = null; } @@ -1060,11 +1064,11 @@ function Rhino3dmWorker() { doc.delete(); - return { objects, materials, layers, views, namedViews, groups, settings }; + return { objects, materials, layers, views, namedViews, groups, settings, warnings }; } - function extractObjectData( object, doc ) { + function extractObjectData( object, doc, onWarning ) { const _geometry = object.geometry(); const _attributes = object.attributes(); @@ -1226,6 +1230,7 @@ function Rhino3dmWorker() { default: console.warn( `THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` ); + onWarning( `THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` ); break; } @@ -1263,6 +1268,7 @@ function Rhino3dmWorker() { } else { console.warn( `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` ); + onWarning( `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` ); } From e21f2113e3a4cee040098505c1a3c6526af5b64b Mon Sep 17 00:00:00 2001 From: karimi Date: Tue, 13 Apr 2021 11:43:57 -0400 Subject: [PATCH 06/22] Pass worker erros to onError callback --- examples/jsm/loaders/3DMLoader.js | 23 ++++++++++++++++++++--- examples/webgl_loader_3dm.html | 4 ++-- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index ce1e5595ab46db..61f93a8e001e41 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -89,7 +89,7 @@ class Rhino3dmLoader extends Loader { this.decodeObjects( buffer, url ) .then( onLoad ) - .catch( onError ); + .catch( e => onError( e ) ); }, onProgress, onError ); @@ -126,7 +126,11 @@ class Rhino3dmLoader extends Loader { } ); } ) - .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) @@ -160,7 +164,7 @@ class Rhino3dmLoader extends Loader { this.decodeObjects( data, '' ) .then( onLoad ) - .catch( onError ); + .catch( e => onError( e ) ); } @@ -811,9 +815,22 @@ function Rhino3dmWorker() { const buffer = message.buffer; libraryPending.then( () => { +<<<<<<< HEAD const data = decodeObjects( rhino, buffer ); self.postMessage( { type: 'decode', id: message.id, data } ); +======= + try { + + var data = decodeObjects( rhino, buffer ); + self.postMessage( { type: 'decode', id: message.id, data } ); + + } catch ( error ) { + + self.postMessage( { type: 'error', id: message.id, error } ); + + } +>>>>>>> Pass worker erros to onError callback } ); diff --git a/examples/webgl_loader_3dm.html b/examples/webgl_loader_3dm.html index 3a7e8893de39b8..b8764be0b629c6 100644 --- a/examples/webgl_loader_3dm.html +++ b/examples/webgl_loader_3dm.html @@ -68,7 +68,7 @@ const loader = new Rhino3dmLoader(); loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.15.0-beta/' ); - loader.load( 'models/3dm/Rhino_Logo.3dm', function ( object ) { + loader.load( 'models/3dm/Rhino_logo.3dm', function ( object ) { scene.add( object ); initGUI( object.userData.layers ); @@ -76,7 +76,7 @@ // hide spinner document.getElementById( 'loader' ).style.display = 'none'; - } ); + }, progress =>progress, error => ( console.log( error ) ) ); const width = window.innerWidth; const height = window.innerHeight; From da176ab74c09704ac7c9e95d3d2442040349b732 Mon Sep 17 00:00:00 2001 From: karimi Date: Tue, 13 Apr 2021 11:43:57 -0400 Subject: [PATCH 07/22] Pass worker erros to onError callback --- examples/jsm/loaders/3DMLoader.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 61f93a8e001e41..ceba98451d4656 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -121,7 +121,7 @@ class Rhino3dmLoader extends Loader { worker.postMessage( { type: 'decode', id: taskID, buffer }, [ buffer ] ); - //this.debug(); + // //this.debug(); } ); @@ -815,14 +815,9 @@ function Rhino3dmWorker() { const buffer = message.buffer; libraryPending.then( () => { -<<<<<<< HEAD - const data = decodeObjects( rhino, buffer ); - - self.postMessage( { type: 'decode', id: message.id, data } ); -======= try { - var data = decodeObjects( rhino, buffer ); + const data = decodeObjects( rhino, buffer ); self.postMessage( { type: 'decode', id: message.id, data } ); } catch ( error ) { @@ -830,7 +825,6 @@ function Rhino3dmWorker() { self.postMessage( { type: 'error', id: message.id, error } ); } ->>>>>>> Pass worker erros to onError callback } ); From ea34dbf70d5f200dad9ef95c51e8466670ae8f96 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 30 Apr 2021 11:23:54 +0200 Subject: [PATCH 08/22] adding some error catching related to PBR mats --- examples/jsm/loaders/3DMLoader.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 769f853e7cd45c..4dbc30b06b0d76 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -906,7 +906,7 @@ function Rhino3dmWorker() { const _material = doc.materials().get( i ); const _pbrMaterial = _material.physicallyBased(); - const material = extractProperties( _material ); + let material = extractProperties( _material ); const textures = []; @@ -948,7 +948,17 @@ function Rhino3dmWorker() { for ( let j = 0; j < pbrTextureTypes.length; j ++ ) { - const _texture = _material.getTexture( textureTypes[ j ] ); + let _texture = null; + try { + + _texture = _material.getTexture( textureTypes[ j ] ); + + } catch ( err ) { + + console.error( `THREE.3DMLoader: Error ${err}`); + + } + if ( _texture ) { const image = doc.getEmbeddedFileAsBase64( _texture.fileName ); From 773183304133798dee9785d79a58ebb9c0962de1 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 30 Apr 2021 12:06:05 +0200 Subject: [PATCH 09/22] fix bug in texturetype checking --- examples/jsm/loaders/3DMLoader.js | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 24c3f713828bd0..510548a53c5b39 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -944,25 +944,13 @@ function Rhino3dmWorker() { if ( _pbrMaterial.supported ) { - console.log( 'pbr true' ); - for ( let j = 0; j < pbrTextureTypes.length; j ++ ) { - let _texture = null; - try { - - _texture = _material.getTexture( textureTypes[ j ] ); - - } catch ( err ) { - - console.error( `THREE.3DMLoader: Error ${err}`); - - } - + const _texture = _material.getTexture( pbrTextureTypes[ j ] ); if ( _texture ) { const image = doc.getEmbeddedFileAsBase64( _texture.fileName ); - let textureType = textureTypes[ j ].constructor.name; + let textureType = pbrTextureTypes[ j ].constructor.name; textureType = textureType.substring( 12, textureType.length ); const texture = { type: textureType, image: 'data:image/png;base64,' + image }; textures.push( texture ); From 0652c61b1c683ce43f7a59fbba519a6a34f1dbc9 Mon Sep 17 00:00:00 2001 From: karimi Date: Mon, 3 May 2021 14:37:35 -0400 Subject: [PATCH 10/22] Post warnings to worker --- examples/jsm/loaders/3DMLoader.js | 48 +++++++++++++++---------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index ceba98451d4656..34ea13cb3d0c9a 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -106,6 +106,7 @@ class Rhino3dmLoader extends Loader { let worker; let taskID; + let warnings =[]; const taskCost = buffer.byteLength; @@ -117,7 +118,7 @@ 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 ] ); @@ -126,7 +127,11 @@ class Rhino3dmLoader extends Loader { } ); } ) - .then( ( message ) => this._createGeometry( message.data ) ).catch( e => { + .then( ( message ) => { + const geometry = this._createGeometry( message.data, taskID ); + geometry.warnings = warnings; + return geometry; + }).catch( e => { throw e; @@ -285,7 +290,7 @@ class Rhino3dmLoader extends Loader { } - _createGeometry( data ) { + _createGeometry( data, taskID ) { // console.log(data); @@ -299,7 +304,6 @@ class Rhino3dmLoader extends Loader { object.userData[ 'settings' ] = data.settings; object.userData[ 'objectType' ] = 'File3dm'; object.userData[ 'materials' ] = null; - object.warnings = data.warnings; object.name = this.url; let objects = data.objects; @@ -333,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, warning =>object.warnings.push( warning ) ); + _object = this._createObject( obj, material, taskID ); } else { const material = this._createMaterial( ); - _object = this._createObject( obj, material, warning =>object.warnings.push( warning ) ); + _object = this._createObject( obj, material, taskID ); } @@ -427,7 +431,7 @@ class Rhino3dmLoader extends Loader { } - _createObject( obj, mat, onWarning ) { + _createObject( obj, mat, taskID ) { const loader = new BufferGeometryLoader(); @@ -620,8 +624,7 @@ class Rhino3dmLoader extends Loader { } else if ( geometry.isLinearLight ) { - console.warn( 'THREE.3DMLoader: No conversion exists for linear lights.' ); - onWarning( 'THREE.3DMLoader: No conversion exists for linear lights.' ); + self.postMessage( { type: 'warning', id: taskID, message: 'THREE.3DMLoader: No conversion exists for linear lights.' } ); return; @@ -714,6 +717,9 @@ class Rhino3dmLoader extends Loader { const message = e.data; switch ( message.type ) { + case 'warning': + worker._callbacks[ message.id ].warn( message ); + break; case 'decode': worker._callbacks[ message.id ].resolve( message ); @@ -817,7 +823,7 @@ function Rhino3dmWorker() { try { - const data = decodeObjects( rhino, buffer ); + const data = decodeObjects( rhino, buffer, message.id ); self.postMessage( { type: 'decode', id: message.id, data } ); } catch ( error ) { @@ -834,7 +840,7 @@ function Rhino3dmWorker() { }; - function decodeObjects( rhino, buffer ) { + function decodeObjects( rhino, buffer, taskID ) { const arr = new Uint8Array( buffer ); const doc = rhino.File3dm.fromByteArray( arr ); @@ -845,7 +851,6 @@ function Rhino3dmWorker() { const views = []; const namedViews = []; const groups = []; - const warnings = []; //Handle objects @@ -856,7 +861,7 @@ function Rhino3dmWorker() { const _object = objs.get( i ); - const object = extractObjectData( _object, doc, ( warning )=>warnings.push( warning ) ); + const object = extractObjectData( _object, doc, taskID ); _object.delete(); @@ -940,11 +945,8 @@ function Rhino3dmWorker() { texture.image = 'data:image/png;base64,' + image; } else { - - console.warn( `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` ); - warnings.push( `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 ); @@ -1075,11 +1077,11 @@ function Rhino3dmWorker() { doc.delete(); - return { objects, materials, layers, views, namedViews, groups, settings, warnings }; + return { objects, materials, layers, views, namedViews, groups, settings }; } - function extractObjectData( object, doc, onWarning ) { + function extractObjectData( object, doc, taskID ) { const _geometry = object.geometry(); const _attributes = object.attributes(); @@ -1240,8 +1242,7 @@ function Rhino3dmWorker() { */ default: - console.warn( `THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` ); - onWarning( `THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` ); + self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` } ); break; } @@ -1277,10 +1278,7 @@ function Rhino3dmWorker() { return { geometry, attributes, objectType }; } else { - - console.warn( `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` ); - onWarning( `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.` } ); } } From 92a0c62c78e8e83d7faafe8b188bbc6f62e0a3af Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 7 May 2021 10:43:50 +0200 Subject: [PATCH 11/22] adding taskId in worker --- examples/jsm/loaders/3DMLoader.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 510548a53c5b39..df04ed90608cc9 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -777,6 +777,7 @@ function Rhino3dmWorker() { let libraryPending; let libraryConfig; let rhino; + let taskId; onmessage = function ( e ) { @@ -786,6 +787,7 @@ function Rhino3dmWorker() { case 'init': + console.log(message) libraryConfig = message.libraryConfig; const wasmBinary = libraryConfig.wasmBinary; let RhinoModule; @@ -806,6 +808,7 @@ function Rhino3dmWorker() { case 'decode': + taskId = message.id; const buffer = message.buffer; libraryPending.then( () => { From cb633a06f4e8ae5c887e393d6dd36b3d23fafdb1 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 7 May 2021 10:54:59 +0200 Subject: [PATCH 12/22] cleanup taskID usage --- examples/jsm/loaders/3DMLoader.js | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 8adde17af389af..4eaed8afd178ac 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -128,7 +128,7 @@ class Rhino3dmLoader extends Loader { } ) .then( ( message ) => { - const geometry = this._createGeometry( message.data, taskID ); + const geometry = this._createGeometry( message.data ); geometry.warnings = warnings; return geometry; }).catch( e => { @@ -290,7 +290,7 @@ class Rhino3dmLoader extends Loader { } - _createGeometry( data, taskID ) { + _createGeometry( data ) { // console.log(data); @@ -337,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, taskID ); + _object = this._createObject( obj, material ); } else { - const material = this._createMaterial( ); - _object = this._createObject( obj, material, taskID ); + const material = this._createMaterial(); + _object = this._createObject( obj, material ); } @@ -431,7 +431,7 @@ class Rhino3dmLoader extends Loader { } - _createObject( obj, mat, taskID ) { + _createObject( obj, mat ) { const loader = new BufferGeometryLoader(); @@ -789,7 +789,7 @@ function Rhino3dmWorker() { let libraryPending; let libraryConfig; let rhino; - let taskId; + let taskID; onmessage = function ( e ) { @@ -820,7 +820,7 @@ function Rhino3dmWorker() { case 'decode': - taskId = message.id; + taskID = message.id; const buffer = message.buffer; libraryPending.then( () => { @@ -843,7 +843,7 @@ function Rhino3dmWorker() { }; - function decodeObjects( rhino, buffer, taskID ) { + function decodeObjects( rhino, buffer ) { const arr = new Uint8Array( buffer ); const doc = rhino.File3dm.fromByteArray( arr ); @@ -864,7 +864,7 @@ function Rhino3dmWorker() { const _object = objs.get( i ); - const object = extractObjectData( _object, doc, taskID ); + const object = extractObjectData( _object, doc ); _object.delete(); @@ -948,8 +948,10 @@ function Rhino3dmWorker() { texture.image = 'data:image/png;base64,' + image; } else { + self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: Image for ${textureType} texture not embedded in file.` } ); texture.image = null; + } textures.push( texture ); @@ -1082,7 +1084,7 @@ function Rhino3dmWorker() { } - function extractObjectData( object, doc, taskID ) { + function extractObjectData( object, doc ) { const _geometry = object.geometry(); const _attributes = object.attributes(); @@ -1243,7 +1245,9 @@ function Rhino3dmWorker() { */ default: + self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: TODO: Implement ${objectType.constructor.name}` } ); + break; } @@ -1279,7 +1283,9 @@ function Rhino3dmWorker() { return { geometry, attributes, objectType }; } else { + self.postMessage( { type: 'warning', id: taskID, message:`THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.` } ); + } } From e3a7f58dfae5d672967e8634832f40e693c802d9 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 7 May 2021 11:18:12 +0200 Subject: [PATCH 13/22] added class level warnings --- examples/jsm/loaders/3DMLoader.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 4eaed8afd178ac..37a6f245b14a16 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -46,6 +46,7 @@ class Rhino3dmLoader extends Loader { this.workerConfig = {}; this.materials = []; + this.warnings = []; } @@ -106,7 +107,6 @@ class Rhino3dmLoader extends Loader { let worker; let taskID; - let warnings =[]; const taskCost = buffer.byteLength; @@ -118,20 +118,22 @@ class Rhino3dmLoader extends Loader { return new Promise( ( resolve, reject ) => { - worker._callbacks[ taskID ] = { resolve, reject, warn: warning =>warnings.push(warning) }; + worker._callbacks[ taskID ] = { resolve, reject }; worker.postMessage( { type: 'decode', id: taskID, buffer }, [ buffer ] ); - // //this.debug(); + // this.debug(); } ); } ) .then( ( message ) => { + const geometry = this._createGeometry( message.data ); geometry.warnings = warnings; return geometry; - }).catch( e => { + + } ).catch( e => { throw e; @@ -717,8 +719,9 @@ class Rhino3dmLoader extends Loader { const message = e.data; switch ( message.type ) { + case 'warning': - worker._callbacks[ message.id ].warn( message ); + this.warnings.push( message ) break; case 'decode': From 3cdfabefd903789a834dfb699ecfa93353c131cb Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 7 May 2021 11:27:38 +0200 Subject: [PATCH 14/22] printing warnings --- examples/jsm/loaders/3DMLoader.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 37a6f245b14a16..e8d8e03aeaa3f2 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -127,13 +127,7 @@ class Rhino3dmLoader extends Loader { } ); } ) - .then( ( message ) => { - - const geometry = this._createGeometry( message.data ); - geometry.warnings = warnings; - return geometry; - - } ).catch( e => { + .then( ( message ) => { this._createGeometry( message.data ); } ).catch( e => { throw e; @@ -722,6 +716,7 @@ class Rhino3dmLoader extends Loader { case 'warning': this.warnings.push( message ) + console.warn( message ) break; case 'decode': @@ -802,7 +797,7 @@ function Rhino3dmWorker() { case 'init': - console.log(message) + // console.log(message) libraryConfig = message.libraryConfig; const wasmBinary = libraryConfig.wasmBinary; let RhinoModule; From e9d7654736f9bee58875343073cd9b250db44b84 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Fri, 7 May 2021 11:42:23 +0200 Subject: [PATCH 15/22] fixed bug in .catch --- examples/jsm/loaders/3DMLoader.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index e8d8e03aeaa3f2..e732304a33e68b 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -127,7 +127,8 @@ class Rhino3dmLoader extends Loader { } ); } ) - .then( ( message ) => { this._createGeometry( message.data ); } ).catch( e => { + .then( ( message ) => this._createGeometry( message.data ) ) + .catch( e => { throw e; From 0c60f5f05d1b5cac75d7c29246b2bddf4efbe119 Mon Sep 17 00:00:00 2001 From: karimi Date: Fri, 7 May 2021 17:19:01 -0400 Subject: [PATCH 16/22] Fix undefined this.warnings --- examples/jsm/loaders/3DMLoader.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index e732304a33e68b..6858d1609db9b3 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -621,7 +621,7 @@ class Rhino3dmLoader extends Loader { } else if ( geometry.isLinearLight ) { - self.postMessage( { type: 'warning', id: taskID, message: 'THREE.3DMLoader: No conversion exists for linear lights.' } ); + // self.postMessage( { type: 'warning', id: taskID, message: 'THREE.3DMLoader: No conversion exists for linear lights.' } ); return; @@ -709,6 +709,8 @@ class Rhino3dmLoader extends Loader { libraryConfig: this.libraryConfig } ); + const pushWarning = warning =>{this.warnings.push(warning)} + worker.onmessage = function ( e ) { const message = e.data; @@ -716,7 +718,7 @@ class Rhino3dmLoader extends Loader { switch ( message.type ) { case 'warning': - this.warnings.push( message ) + pushWarning( message ) console.warn( message ) break; From 5d06888c428912e659a8854bacd79e27ee6db558 Mon Sep 17 00:00:00 2001 From: karimi Date: Fri, 7 May 2021 17:48:04 -0400 Subject: [PATCH 17/22] Add onWarning callback --- examples/jsm/loaders/3DMLoader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 6858d1609db9b3..ec1bdc1d1ef9de 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -66,7 +66,7 @@ class Rhino3dmLoader extends Loader { } - load( url, onLoad, onProgress, onError ) { + load( url, onLoad, onProgress, onError, onWarning ) { const loader = new FileLoader( this.manager ); @@ -89,7 +89,7 @@ class Rhino3dmLoader extends Loader { } this.decodeObjects( buffer, url ) - .then( onLoad ) + .then( result =>{onLoad(result); this.warnings.length>0 && onWarning(this.warnings)} ) .catch( e => onError( e ) ); }, onProgress, onError ); @@ -162,10 +162,10 @@ class Rhino3dmLoader extends Loader { } - parse( data, onLoad, onError ) { + parse( data, onLoad, onError, onWarning ) { this.decodeObjects( data, '' ) - .then( onLoad ) + .then( result =>{onLoad(result); this.warnings.length>0 && onWarning(this.warnings)} ) .catch( e => onError( e ) ); } From 3ca34c07627c98cb77455378aa7eba82636b413f Mon Sep 17 00:00:00 2001 From: karimi Date: Fri, 7 May 2021 18:27:35 -0400 Subject: [PATCH 18/22] Rewriting onMessage as arrow function --- examples/jsm/loaders/3DMLoader.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index ec1bdc1d1ef9de..861111519afd5d 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -709,16 +709,13 @@ class Rhino3dmLoader extends Loader { libraryConfig: this.libraryConfig } ); - const pushWarning = warning =>{this.warnings.push(warning)} - - worker.onmessage = function ( e ) { - + worker.onmessage = e =>{ const message = e.data; switch ( message.type ) { case 'warning': - pushWarning( message ) + this.warnings.push( message ) console.warn( message ) break; @@ -734,8 +731,7 @@ class Rhino3dmLoader extends Loader { console.error( 'THREE.Rhino3dmLoader: Unexpected message, "' + message.type + '"' ); } - - }; + } this.workerPool.push( worker ); From bd86376b241732a4599369b6043379b4f62631a8 Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Tue, 11 May 2021 12:33:01 +0200 Subject: [PATCH 19/22] rework warning messages, lightstyle switch --- examples/jsm/loaders/3DMLoader.js | 102 +++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 8 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 861111519afd5d..b955f948563e12 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -89,7 +89,9 @@ class Rhino3dmLoader extends Loader { } this.decodeObjects( buffer, url ) - .then( result =>{onLoad(result); this.warnings.length>0 && onWarning(this.warnings)} ) + .then( result => { + onLoad( result ); + this.warnings.length > 0 && onWarning ( this.warnings ) } ) .catch( e => onError( e ) ); }, onProgress, onError ); @@ -165,7 +167,7 @@ class Rhino3dmLoader extends Loader { parse( data, onLoad, onError, onWarning ) { this.decodeObjects( data, '' ) - .then( result =>{onLoad(result); this.warnings.length>0 && onWarning(this.warnings)} ) + .then( result => { onLoad( result ); this.warnings.length > 0 && onWarning( this.warnings ) } ) .catch( e => onError( e ) ); } @@ -581,6 +583,58 @@ class Rhino3dmLoader extends Loader { let light; + switch ( geometry.lightStyle.name ) { + + case 'LightStyle_WorldPoint': + + 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; + + case 'LightStyle_WorldSpot': + + 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; + + break; + + case 'LightStyle_WorldRectangular': + + 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 ] ) ); + + break; + + case 'LightStyle_WorldDirectional': + + 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; + + break; + + case 'LightStyle_WorldLinear': + // not conversion exists, warning has already been printed to the console + break; + + default: + break; + } +/* if ( geometry.isDirectionalLight ) { light = new DirectionalLight(); @@ -626,6 +680,7 @@ class Rhino3dmLoader extends Loader { return; } + */ if ( light ) { @@ -709,14 +764,15 @@ class Rhino3dmLoader extends Loader { libraryConfig: this.libraryConfig } ); - worker.onmessage = e =>{ + worker.onmessage = e => { + const message = e.data; switch ( message.type ) { case 'warning': - this.warnings.push( message ) - console.warn( message ) + this.warnings.push( message.data ) + console.warn( message.data ) break; case 'decode': @@ -731,6 +787,7 @@ class Rhino3dmLoader extends Loader { console.error( 'THREE.Rhino3dmLoader: Unexpected message, "' + message.type + '"' ); } + } this.workerPool.push( worker ); @@ -946,7 +1003,12 @@ function Rhino3dmWorker() { } else { - self.postMessage( { type: 'warning', id: taskID, message:`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; } @@ -1211,6 +1273,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: @@ -1243,7 +1317,13 @@ function Rhino3dmWorker() { default: - self.postMessage( { type: 'warning', id: taskID, message:`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; @@ -1281,7 +1361,13 @@ function Rhino3dmWorker() { } else { - self.postMessage( { type: 'warning', id: taskID, message:`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 + } + + } ); } From 59dd4bd98d3bd6ca13ccb352496c092f747cf1eb Mon Sep 17 00:00:00 2001 From: karimi Date: Wed, 12 May 2021 17:04:50 -0400 Subject: [PATCH 20/22] Remove onWarning callback, add warnings to userData --- examples/jsm/loaders/3DMLoader.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index b955f948563e12..2a61b333066f35 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -66,7 +66,7 @@ class Rhino3dmLoader extends Loader { } - load( url, onLoad, onProgress, onError, onWarning ) { + load( url, onLoad, onProgress, onError ) { const loader = new FileLoader( this.manager ); @@ -90,8 +90,9 @@ class Rhino3dmLoader extends Loader { this.decodeObjects( buffer, url ) .then( result => { + result.userData.warnings = this.warnings; onLoad( result ); - this.warnings.length > 0 && onWarning ( this.warnings ) } ) + } ) .catch( e => onError( e ) ); }, onProgress, onError ); @@ -164,10 +165,13 @@ class Rhino3dmLoader extends Loader { } - parse( data, onLoad, onError, onWarning ) { + parse( data, onLoad, onError ) { this.decodeObjects( data, '' ) - .then( result => { onLoad( result ); this.warnings.length > 0 && onWarning( this.warnings ) } ) + .then( result => { + result.userData.warnings = this.warnings; + onLoad( result ); + } ) .catch( e => onError( e ) ); } From 7f8bcc4f939d1a746b4247ad1ac12627c82032bd Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Mon, 17 May 2021 10:59:21 +0200 Subject: [PATCH 21/22] Cleanup comments, etc. --- examples/jsm/loaders/3DMLoader.js | 80 ++++++++----------------------- 1 file changed, 19 insertions(+), 61 deletions(-) diff --git a/examples/jsm/loaders/3DMLoader.js b/examples/jsm/loaders/3DMLoader.js index 2a61b333066f35..453577c11a8c11 100644 --- a/examples/jsm/loaders/3DMLoader.js +++ b/examples/jsm/loaders/3DMLoader.js @@ -89,15 +89,16 @@ class Rhino3dmLoader extends Loader { } this.decodeObjects( buffer, url ) - .then( result => { + .then( result => { + result.userData.warnings = this.warnings; - onLoad( result ); + onLoad( result ); + } ) .catch( e => onError( e ) ); }, onProgress, onError ); - } debug() { @@ -117,7 +118,7 @@ class Rhino3dmLoader extends Loader { .then( ( _worker ) => { worker = _worker; - taskID = this.workerNextTaskID ++; //hmmm + taskID = this.workerNextTaskID ++; return new Promise( ( resolve, reject ) => { @@ -168,9 +169,11 @@ class Rhino3dmLoader extends Loader { parse( data, onLoad, onError ) { this.decodeObjects( data, '' ) - .then( result => { + .then( result => { + result.userData.warnings = this.warnings; - onLoad( result ); + onLoad( result ); + } ) .catch( e => onError( e ) ); @@ -618,7 +621,7 @@ class Rhino3dmLoader extends Loader { light.height = height; light.width = width; light.lookAt( new Vector3( geometry.direction[ 0 ], geometry.direction[ 1 ], geometry.direction[ 2 ] ) ); - + break; case 'LightStyle_WorldDirectional': @@ -637,54 +640,8 @@ class Rhino3dmLoader extends Loader { default: break; - } -/* - if ( geometry.isDirectionalLight ) { - - 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.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; - - } else if ( geometry.isRectangularLight ) { - - 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 ] ) ); - - } else if ( geometry.isSpotLight ) { - - 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; - - } else if ( geometry.isLinearLight ) { - - // self.postMessage( { type: 'warning', id: taskID, message: 'THREE.3DMLoader: No conversion exists for linear lights.' } ); - - return; } - */ if ( light ) { @@ -775,8 +732,8 @@ class Rhino3dmLoader extends Loader { switch ( message.type ) { case 'warning': - this.warnings.push( message.data ) - console.warn( message.data ) + this.warnings.push( message.data ); + console.warn( message.data ); break; case 'decode': @@ -792,7 +749,7 @@ class Rhino3dmLoader extends Loader { } - } + }; this.workerPool.push( worker ); @@ -1007,10 +964,11 @@ function Rhino3dmWorker() { } else { - self.postMessage( { type: 'warning', id: taskID, data: { + self.postMessage( { type: 'warning', id: taskID, data: { message: `THREE.3DMLoader: Image for ${textureType} texture not embedded in file.`, type: 'missing resource' - } + } + } ); texture.image = null; @@ -1283,7 +1241,7 @@ function Rhino3dmWorker() { message: `THREE.3DMLoader: No conversion exists for ${objectType.constructor.name} ${geometry.lightStyle.name}`, type: 'no conversion', guid: _attributes.id - } + } } ); @@ -1325,7 +1283,7 @@ function Rhino3dmWorker() { message: `THREE.3DMLoader: Conversion not implemented for ${objectType.constructor.name}`, type: 'not implemented', guid: _attributes.id - } + } } ); @@ -1369,7 +1327,7 @@ function Rhino3dmWorker() { message: `THREE.3DMLoader: ${objectType.constructor.name} has no associated mesh geometry.`, type: 'missing mesh', guid: _attributes.id - } + } } ); From a7806e6c2011322ba3cc6ee6458860ae7005d06e Mon Sep 17 00:00:00 2001 From: Luis Fraguada Date: Mon, 17 May 2021 20:13:03 +0200 Subject: [PATCH 22/22] reverted change in example --- examples/webgl_loader_3dm.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/webgl_loader_3dm.html b/examples/webgl_loader_3dm.html index 39d34a5beec5a7..c069973e8c228b 100644 --- a/examples/webgl_loader_3dm.html +++ b/examples/webgl_loader_3dm.html @@ -76,7 +76,7 @@ // hide spinner document.getElementById( 'loader' ).style.display = 'none'; - }, progress =>progress, error => ( console.log( error ) ) ); + } ); controls = new OrbitControls( camera, renderer.domElement );