diff --git a/src/geometries/ExtrudeGeometry.js b/src/geometries/ExtrudeGeometry.js index 72cc5860658b03b55da683524e63adb168651527..513f18fdf5eefcc1c5c582d43f2eaea0d07b6da3 100644 --- a/src/geometries/ExtrudeGeometry.js +++ b/src/geometries/ExtrudeGeometry.js @@ -49,6 +49,17 @@ function ExtrudeGeometry( shapes, options ) { ExtrudeGeometry.prototype = Object.create( Geometry.prototype ); ExtrudeGeometry.prototype.constructor = ExtrudeGeometry; +ExtrudeGeometry.prototype.toJSON = function () { + + var data = Geometry.prototype.toJSON.call( this ); + + var shapes = this.parameters.shapes; + var options = this.parameters.options; + + return toJSON( shapes, options, data ); + +}; + // ExtrudeBufferGeometry function ExtrudeBufferGeometry( shapes, options ) { @@ -717,6 +728,19 @@ function ExtrudeBufferGeometry( shapes, options ) { ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry; +ExtrudeBufferGeometry.prototype.toJSON = function () { + + var data = BufferGeometry.prototype.toJSON.call( this ); + + var shapes = this.parameters.shapes; + var options = this.parameters.options; + + return toJSON( shapes, options, data ); + +}; + +// + var WorldUVGenerator = { generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) { @@ -774,5 +798,35 @@ var WorldUVGenerator = { } }; +function toJSON( shapes, options, data ) { + + // + + data.shapes = []; + + if ( Array.isArray( shapes ) ) { + + for ( var i = 0, l = shapes.length; i < l; i ++ ) { + + var shape = shapes[ i ]; + + data.shapes.push( shape.uuid ); + + } + + } else { + + data.shapes.push( shapes.uuid ); + + } + + // + + if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON(); + + return data; + +} + export { ExtrudeGeometry, ExtrudeBufferGeometry }; diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index 4921bb198f40de42cb3488bc3f76a04a17cff28e..f7adc4efe875e5cd60675cc518b47420ee6e0d25 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -51,6 +51,7 @@ import { BufferGeometryLoader } from './BufferGeometryLoader.js'; import { JSONLoader } from './JSONLoader.js'; import { FileLoader } from './FileLoader.js'; import * as Geometries from '../geometries/Geometries.js'; +import * as Curves from '../extras/curves/Curves.js'; /** * @author mrdoob / http://mrdoob.com/ @@ -377,6 +378,35 @@ Object.assign( ObjectLoader.prototype, { break; + + case 'ExtrudeGeometry': + case 'ExtrudeBufferGeometry': + + var geometryShapes = []; + + for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) { + + var shape = shapes[ data.shapes[ j ] ]; + + geometryShapes.push( shape ); + + } + + var extrudePath = data.options.extrudePath; + + if ( extrudePath !== undefined ) { + + data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath ); + + } + + geometry = new Geometries[ data.type ]( + geometryShapes, + data.options + ); + + break; + case 'BufferGeometry': geometry = bufferGeometryLoader.parse( data );