From 232692421298cee10e4d0be7cfe51978b265a1d2 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Tue, 30 Jul 2019 14:45:29 +0200 Subject: [PATCH] JSM: Update modules. --- examples/jsm/loaders/GLTFLoader.js | 74 +++++++++++++++++++++--------- examples/jsm/loaders/TTFLoader.js | 4 +- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/examples/jsm/loaders/GLTFLoader.js b/examples/jsm/loaders/GLTFLoader.js index ff6901df61..ed722001dd 100644 --- a/examples/jsm/loaders/GLTFLoader.js +++ b/examples/jsm/loaders/GLTFLoader.js @@ -1940,13 +1940,15 @@ var GLTFLoader = ( function () { // The buffer is not interleaved if the stride is the item size in bytes. if ( byteStride && byteStride !== itemBytes ) { - var ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType; + // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer + // This makes sure that IBA.count reflects accessor.count properly + var ibSlice = Math.floor( byteOffset / byteStride ); + var ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count; var ib = parser.cache.get( ibCacheKey ); if ( ! ib ) { - // Use the full buffer if it's interleaved. - array = new TypedArray( bufferView ); + array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes ); // Integer parameters to IB/IBA are in array elements, not bytes. ib = new InterleavedBuffer( array, byteStride / elementBytes ); @@ -1955,7 +1957,7 @@ var GLTFLoader = ( function () { } - bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, byteOffset / elementBytes, normalized ); + bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, (byteOffset % byteStride) / elementBytes, normalized ); } else { @@ -2977,14 +2979,11 @@ var GLTFLoader = ( function () { return ( function () { - // .isBone isn't in glTF spec. See .markDefs - if ( nodeDef.isBone === true ) { - - return Promise.resolve( new Bone() ); + var pending = []; - } else if ( nodeDef.mesh !== undefined ) { + if ( nodeDef.mesh !== undefined ) { - return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) { + pending.push( parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) { var node; @@ -3030,25 +3029,58 @@ var GLTFLoader = ( function () { return node; - } ); + } ) ); + + } - } else if ( nodeDef.camera !== undefined ) { + if ( nodeDef.camera !== undefined ) { - return parser.getDependency( 'camera', nodeDef.camera ); + pending.push( parser.getDependency( 'camera', nodeDef.camera ) ); - } else if ( nodeDef.extensions + } + + if ( nodeDef.extensions && nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ] && nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ].light !== undefined ) { - return parser.getDependency( 'light', nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ].light ); + pending.push( parser.getDependency( 'light', nodeDef.extensions[ EXTENSIONS.KHR_LIGHTS_PUNCTUAL ].light ) ); + + } + + return Promise.all( pending ); + + }() ).then( function ( objects ) { + + var node; + + // .isBone isn't in glTF spec. See .markDefs + if ( nodeDef.isBone === true ) { + + node = new Bone(); + + } else if ( objects.length > 1 ) { + + node = new Group(); + + } else if ( objects.length === 1 ) { + + node = objects[ 0 ]; } else { - return Promise.resolve( new Object3D() ); + node = new Object3D(); } - }() ).then( function ( node ) { + if ( node !== objects[ 0 ] ) { + + for ( var i = 0, il = objects.length; i < il; i ++ ) { + + node.add( objects[ i ] ); + + } + + } if ( nodeDef.name !== undefined ) { @@ -3132,11 +3164,9 @@ var GLTFLoader = ( function () { } ).then( function ( jointNodes ) { - var meshes = node.isGroup === true ? node.children : [ node ]; - - for ( var i = 0, il = meshes.length; i < il; i ++ ) { + node.traverse( function ( mesh ) { - var mesh = meshes[ i ]; + if ( ! mesh.isMesh ) return; var bones = []; var boneInverses = []; @@ -3169,7 +3199,7 @@ var GLTFLoader = ( function () { mesh.bind( new Skeleton( bones, boneInverses ), mesh.matrixWorld ); - } + } ); return node; diff --git a/examples/jsm/loaders/TTFLoader.js b/examples/jsm/loaders/TTFLoader.js index 247e4231df..b4dc1dc6cd 100644 --- a/examples/jsm/loaders/TTFLoader.js +++ b/examples/jsm/loaders/TTFLoader.js @@ -54,7 +54,7 @@ TTFLoader.prototype = { var glyphs = {}; var scale = ( 100000 ) / ( ( font.unitsPerEm || 2048 ) * 72 ); - + var glyphIndexMap = font.encoding.cmap.glyphIndexMap; var unicodes = Object.keys( glyphIndexMap ); @@ -108,7 +108,7 @@ TTFLoader.prototype = { } ); - glyphs[ String.fromCodePoint( unicode ) ] = token; + glyphs[ String.fromCodePoint( glyph.unicode ) ] = token; } -- GitLab