未验证 提交 f5cbb415 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #13811 from Mugen87/dev1

ExtrudeGeometry: Added serialization/ deserialization 3rd attempt
......@@ -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 };
......@@ -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 );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册