From 9a6387930899a8674e4262aab6a07b21befb396b Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Tue, 15 Oct 2019 12:59:53 +0200 Subject: [PATCH] ParametricGeometry: Added serialization/deserialization support. --- src/geometries/ParametricGeometry.js | 19 +++++++++++++++++++ src/loaders/ObjectLoader.js | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/geometries/ParametricGeometry.js b/src/geometries/ParametricGeometry.js index 329230c4fa40f9..a55eb2a1603a82 100644 --- a/src/geometries/ParametricGeometry.js +++ b/src/geometries/ParametricGeometry.js @@ -33,6 +33,16 @@ function ParametricGeometry( func, slices, stacks ) { ParametricGeometry.prototype = Object.create( Geometry.prototype ); ParametricGeometry.prototype.constructor = ParametricGeometry; +ParametricGeometry.prototype.toJSON = function () { + + var data = Geometry.prototype.toJSON.call( this ); + + data.func = this.parameters.func.toString(); + + return data; + +}; + // ParametricBufferGeometry function ParametricBufferGeometry( func, slices, stacks ) { @@ -159,5 +169,14 @@ function ParametricBufferGeometry( func, slices, stacks ) { ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype ); ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry; +ParametricBufferGeometry.prototype.toJSON = function () { + + var data = BufferGeometry.prototype.toJSON.call( this ); + + data.func = this.parameters.func.toString(); + + return data; + +}; export { ParametricGeometry, ParametricBufferGeometry }; diff --git a/src/loaders/ObjectLoader.js b/src/loaders/ObjectLoader.js index d2b2afeea56f06..9d8cb1e588d9db 100644 --- a/src/loaders/ObjectLoader.js +++ b/src/loaders/ObjectLoader.js @@ -408,6 +408,19 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), { break; + case 'ParametricGeometry': + case 'ParametricBufferGeometry': + + var func = new Function( 'return ' + data.func )(); + + geometry = new Geometries[ data.type ]( + func, + data.slices, + data.stacks + ); + + break; + case 'BufferGeometry': case 'InstancedBufferGeometry':