Browse Source

Geometry/BufferGeometry: Handle primitives in clone()

Mr.doob 9 years ago
parent
commit
b1884c623a

+ 20 - 0
src/core/BufferGeometry.js

@@ -975,6 +975,26 @@ THREE.BufferGeometry.prototype = {
 
 
 	clone: function () {
 	clone: function () {
 
 
+		// Handle primitives
+
+		var parameters = this.parameters;
+
+		if ( parameters !== undefined ) {
+
+			var values = [];
+
+			for ( var key in parameters ) {
+
+				values.push( parameters[ key ] );
+
+			}
+
+			var geometry = Object.create( this.constructor.prototype );
+			this.constructor.apply( geometry, values );
+			return geometry;
+
+		}
+
 		return new this.constructor().copy( this );
 		return new this.constructor().copy( this );
 
 
 	},
 	},

+ 20 - 0
src/core/Geometry.js

@@ -1103,6 +1103,26 @@ THREE.Geometry.prototype = {
 
 
 	clone: function () {
 	clone: function () {
 
 
+		// Handle primitives
+
+		var parameters = this.parameters;
+
+		if ( parameters !== undefined ) {
+
+			var values = [];
+
+			for ( var key in parameters ) {
+
+				values.push( parameters[ key ] );
+
+			}
+
+			var geometry = Object.create( this.constructor.prototype );
+			this.constructor.apply( geometry, values );
+			return geometry;
+
+		}
+
 		return new this.constructor().copy( this );
 		return new this.constructor().copy( this );
 
 
 	},
 	},

+ 0 - 15
src/extras/geometries/BoxGeometry.js

@@ -126,19 +126,4 @@ THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegmen
 THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
 THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
 
 
-THREE.BoxGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.BoxGeometry(
-		parameters.width,
-		parameters.height,
-		parameters.depth,
-		parameters.widthSegments,
-		parameters.heightSegments,
-		parameters.depthSegments
-	);
-
-};
-
 THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
 THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility

+ 0 - 13
src/extras/geometries/CircleBufferGeometry.js

@@ -65,16 +65,3 @@ THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLengt
 
 
 THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
 THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
-
-THREE.CircleBufferGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.CircleBufferGeometry(
-		parameters.radius,
-		parameters.segments,
-		parameters.thetaStart,
-		parameters.thetaLength
-	);
-
-};

+ 0 - 13
src/extras/geometries/CircleGeometry.js

@@ -21,16 +21,3 @@ THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
 
 
 THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
 THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
-
-THREE.CircleGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.CircleGeometry(
-		parameters.radius,
-		parameters.segments,
-		parameters.thetaStart,
-		parameters.thetaLength
-	);
-
-};

+ 0 - 17
src/extras/geometries/CylinderGeometry.js

@@ -170,20 +170,3 @@ THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegme
 
 
 THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
 THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
-
-THREE.CylinderGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.CylinderGeometry(
-		parameters.radiusTop,
-		parameters.radiusBottom,
-		parameters.height,
-		parameters.radialSegments,
-		parameters.heightSegments,
-		parameters.openEnded,
-		parameters.thetaStart,
-		parameters.thetaLength
-	);
-
-};

+ 0 - 11
src/extras/geometries/DodecahedronGeometry.js

@@ -56,14 +56,3 @@ THREE.DodecahedronGeometry = function ( radius, detail ) {
 
 
 THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
 THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
-
-THREE.DodecahedronGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.DodecahedronGeometry(
-		parameters.radius,
-		parameters.detail
-	);
-
-};

+ 0 - 11
src/extras/geometries/IcosahedronGeometry.js

@@ -32,14 +32,3 @@ THREE.IcosahedronGeometry = function ( radius, detail ) {
 
 
 THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
 THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
-
-THREE.IcosahedronGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.IcosahedronGeometry(
-		parameters.radius,
-		parameters.detail
-	);
-
-};

+ 0 - 11
src/extras/geometries/OctahedronGeometry.js

@@ -25,14 +25,3 @@ THREE.OctahedronGeometry = function ( radius, detail ) {
 
 
 THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
 THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
-
-THREE.OctahedronGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.OctahedronGeometry(
-		parameters.radius,
-		parameters.detail
-	);
-
-};

+ 0 - 13
src/extras/geometries/PlaneBufferGeometry.js

@@ -94,16 +94,3 @@ THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegme
 
 
 THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
 THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
-
-THREE.PlaneBufferGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.PlaneBufferGeometry(
-		parameters.width,
-		parameters.height,
-		parameters.widthSegments,
-		parameters.heightSegments
-	);
-
-};

+ 0 - 13
src/extras/geometries/PlaneGeometry.js

@@ -22,16 +22,3 @@ THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments )
 
 
 THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
 THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
-
-THREE.PlaneGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.PlaneGeometry(
-		parameters.width,
-		parameters.height,
-		parameters.widthSegments,
-		parameters.heightSegments
-	);
-
-};

+ 0 - 13
src/extras/geometries/PolyhedronGeometry.js

@@ -239,16 +239,3 @@ THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
 
 
 THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
 THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
-
-THREE.PolyhedronGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.PolyhedronGeometry(
-		parameters.vertices,
-		parameters.indices,
-		parameters.radius,
-		parameters.detail
-	);
-
-};

+ 0 - 15
src/extras/geometries/RingGeometry.js

@@ -90,18 +90,3 @@ THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegm
 
 
 THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
 THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
-
-THREE.RingGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.RingGeometry(
-		parameters.innerRadius,
-		parameters.outerRadius,
-		parameters.thetaSegments,
-		parameters.phiSegments,
-		parameters.thetaStart,
-		parameters.thetaLength
-	);
-
-};

+ 0 - 16
src/extras/geometries/SphereBufferGeometry.js

@@ -99,19 +99,3 @@ THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, p
 
 
 THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
 THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
 THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
-
-THREE.SphereBufferGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.SphereBufferGeometry(
-		parameters.radius,
-		parameters.widthSegments,
-		parameters.heightSegments,
-		parameters.phiStart,
-		parameters.phiLength,
-		parameters.thetaStart,
-		parameters.thetaLength
-	);
-
-};

+ 0 - 16
src/extras/geometries/SphereGeometry.js

@@ -24,19 +24,3 @@ THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStar
 
 
 THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
 THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
-
-THREE.SphereGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.SphereGeometry(
-		parameters.radius,
-		parameters.widthSegments,
-		parameters.heightSegments,
-		parameters.phiStart,
-		parameters.phiLength,
-		parameters.thetaStart,
-		parameters.thetaLength
-	);
-
-};

+ 0 - 11
src/extras/geometries/TetrahedronGeometry.js

@@ -25,14 +25,3 @@ THREE.TetrahedronGeometry = function ( radius, detail ) {
 
 
 THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
 THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
 THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
-
-THREE.TetrahedronGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.TetrahedronGeometry(
-		parameters.radius,
-		parameters.detail
-	);
-
-};

+ 0 - 14
src/extras/geometries/TorusGeometry.js

@@ -77,17 +77,3 @@ THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments,
 
 
 THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
 THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
-
-THREE.TorusGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.TorusGeometry(
-		parameters.radius,
-		parameters.tube,
-		parameters.radialSegments,
-		parameters.tubularSegments,
-		parameters.arc
-	);
-
-};

+ 0 - 16
src/extras/geometries/TorusKnotGeometry.js

@@ -112,19 +112,3 @@ THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegmen
 
 
 THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
 THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
-
-THREE.TorusKnotGeometry.prototype.clone = function () {
-
-	var parameters = this.parameters;
-
-	return new THREE.TorusKnotGeometry(
-		parameters.radius,
-		parameters.tube,
-		parameters.radialSegments,
-		parameters.tubularSegments,
-		parameters.p,
-		parameters.q,
-		parameters.heightScale
-	);
-
-};

+ 0 - 8
src/extras/geometries/TubeGeometry.js

@@ -139,14 +139,6 @@ THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed,
 
 
 THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
 THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
 THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
-THREE.TubeGeometry.prototype.clone = function() {
-
-	return new this.constructor( this.parameters.path,
-		this.parameters.segments, this.parameters.radius, this.parameters.radialSegments,
-		this.parameters.closed, this.parameters.taper
-	);
-
-};
 
 
 THREE.TubeGeometry.NoTaper = function ( u ) {
 THREE.TubeGeometry.NoTaper = function ( u ) {