瀏覽代碼

Merge pull request #15789 from Temdog007/feature/TubeGeometrySerialization

Allow Tube Geometry to be serialized and loaded
Mr.doob 6 年之前
父節點
當前提交
fb6133c6c8
共有 2 個文件被更改,包括 24 次插入0 次删除
  1. 9 0
      src/geometries/TubeGeometry.js
  2. 15 0
      src/loaders/ObjectLoader.js

+ 9 - 0
src/geometries/TubeGeometry.js

@@ -219,5 +219,14 @@ function TubeBufferGeometry( path, tubularSegments, radius, radialSegments, clos
 TubeBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
 TubeBufferGeometry.prototype.constructor = TubeBufferGeometry;
 
+TubeBufferGeometry.prototype.toJSON = function () {
+
+	var data = BufferGeometry.prototype.toJSON.call( this );
+
+	data.path = this.parameters.path.toJSON();
+
+	return data;
+
+};
 
 export { TubeGeometry, TubeBufferGeometry };

+ 15 - 0
src/loaders/ObjectLoader.js

@@ -341,6 +341,21 @@ Object.assign( ObjectLoader.prototype, {
 
 						break;
 
+					case 'TubeGeometry':
+					case 'TubeBufferGeometry':
+
+						// This only works for built-in curves (e.g. CatmullRomCurve3).
+						// User defined curves or instances of CurvePath will not be deserialized.
+						geometry = new Geometries[ data.type ](
+							new Curves[ data.path.type ]().fromJSON( data.path ),
+							data.tubularSegments,
+							data.radius,
+							data.radialSegments,
+							data.closed
+						);
+
+						break;
+
 					case 'LatheGeometry':
 					case 'LatheBufferGeometry':