Skip to content

Commit f5cbb41

Browse files
authored
Merge pull request #13811 from Mugen87/dev1
ExtrudeGeometry: Added serialization/ deserialization 3rd attempt
2 parents f9b0be4 + db94b0b commit f5cbb41

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

src/geometries/ExtrudeGeometry.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ function ExtrudeGeometry( shapes, options ) {
4949
ExtrudeGeometry.prototype = Object.create( Geometry.prototype );
5050
ExtrudeGeometry.prototype.constructor = ExtrudeGeometry;
5151

52+
ExtrudeGeometry.prototype.toJSON = function () {
53+
54+
var data = Geometry.prototype.toJSON.call( this );
55+
56+
var shapes = this.parameters.shapes;
57+
var options = this.parameters.options;
58+
59+
return toJSON( shapes, options, data );
60+
61+
};
62+
5263
// ExtrudeBufferGeometry
5364

5465
function ExtrudeBufferGeometry( shapes, options ) {
@@ -717,6 +728,19 @@ function ExtrudeBufferGeometry( shapes, options ) {
717728
ExtrudeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
718729
ExtrudeBufferGeometry.prototype.constructor = ExtrudeBufferGeometry;
719730

731+
ExtrudeBufferGeometry.prototype.toJSON = function () {
732+
733+
var data = BufferGeometry.prototype.toJSON.call( this );
734+
735+
var shapes = this.parameters.shapes;
736+
var options = this.parameters.options;
737+
738+
return toJSON( shapes, options, data );
739+
740+
};
741+
742+
//
743+
720744
var WorldUVGenerator = {
721745

722746
generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
@@ -774,5 +798,35 @@ var WorldUVGenerator = {
774798
}
775799
};
776800

801+
function toJSON( shapes, options, data ) {
802+
803+
//
804+
805+
data.shapes = [];
806+
807+
if ( Array.isArray( shapes ) ) {
808+
809+
for ( var i = 0, l = shapes.length; i < l; i ++ ) {
810+
811+
var shape = shapes[ i ];
812+
813+
data.shapes.push( shape.uuid );
814+
815+
}
816+
817+
} else {
818+
819+
data.shapes.push( shapes.uuid );
820+
821+
}
822+
823+
//
824+
825+
if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
826+
827+
return data;
828+
829+
}
830+
777831

778832
export { ExtrudeGeometry, ExtrudeBufferGeometry };

src/loaders/ObjectLoader.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import { BufferGeometryLoader } from './BufferGeometryLoader.js';
5151
import { JSONLoader } from './JSONLoader.js';
5252
import { FileLoader } from './FileLoader.js';
5353
import * as Geometries from '../geometries/Geometries.js';
54+
import * as Curves from '../extras/curves/Curves.js';
5455

5556
/**
5657
* @author mrdoob / http://mrdoob.com/
@@ -377,6 +378,35 @@ Object.assign( ObjectLoader.prototype, {
377378

378379
break;
379380

381+
382+
case 'ExtrudeGeometry':
383+
case 'ExtrudeBufferGeometry':
384+
385+
var geometryShapes = [];
386+
387+
for ( var j = 0, jl = data.shapes.length; j < jl; j ++ ) {
388+
389+
var shape = shapes[ data.shapes[ j ] ];
390+
391+
geometryShapes.push( shape );
392+
393+
}
394+
395+
var extrudePath = data.options.extrudePath;
396+
397+
if ( extrudePath !== undefined ) {
398+
399+
data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
400+
401+
}
402+
403+
geometry = new Geometries[ data.type ](
404+
geometryShapes,
405+
data.options
406+
);
407+
408+
break;
409+
380410
case 'BufferGeometry':
381411

382412
geometry = bufferGeometryLoader.parse( data );

0 commit comments

Comments
 (0)