diff --git a/src/core/BufferGeometry.js b/src/core/BufferGeometry.js index 5a1ec264505aa93b091bdaf5d0fe52bdbf988812..feff7118e61a9a195af62e10548beb23efea20c1 100644 --- a/src/core/BufferGeometry.js +++ b/src/core/BufferGeometry.js @@ -980,7 +980,7 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy } - data.data = { attributes: {} }; + data.data = { attributes: {}, morphAttributes: {} }; var index = this.index; @@ -1012,6 +1012,32 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy } + var morphAttributes = this.morphAttributes; + + for ( var key in morphAttributes ) { + + var attributeArray = this.morphAttributes[ key ]; + + var array = []; + + for ( var i = 0, il = attributeArray.length; i < il; i ++ ) { + + var attribute = attributeArray[ i ]; + + array.push( { + name: attribute.name, + itemSize: attribute.itemSize, + type: attribute.array.constructor.name, + array: Array.prototype.slice.call( attribute.array ), + normalized: attribute.normalized + } ); + + } + + data.data.morphAttributes[ key ] = array; + + } + var groups = this.groups; if ( groups.length > 0 ) { diff --git a/src/loaders/BufferGeometryLoader.js b/src/loaders/BufferGeometryLoader.js index 9582a8d874f6a79ad723dcff912d72f74f1e51d6..df4c3128b2bf95c3f03c5d9c827b922c8ff8ec15 100644 --- a/src/loaders/BufferGeometryLoader.js +++ b/src/loaders/BufferGeometryLoader.js @@ -55,6 +55,29 @@ Object.assign( BufferGeometryLoader.prototype, { } + var morphAttributes = json.data.morphAttributes; + + for ( var key in morphAttributes ) { + + var attributeArray = morphAttributes[ key ]; + + var array = []; + + for ( var i = 0, il = attributeArray.length; i < il; i ++ ) { + + var attribute = attributeArray[ i ]; + var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array ); + + var bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized ); + if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name; + array.push( bufferAttribute ); + + } + + geometry.morphAttributes[ key ] = array; + + } + var groups = json.data.groups || json.data.drawcalls || json.data.offsets; if ( groups !== undefined ) {