Browse Source

*BufferAttribute/*InterleavedBuffer: Updated copy/clone.

Mr.doob 10 years ago
parent
commit
69c1daff54

+ 12 - 1
src/core/BufferAttribute.js

@@ -47,6 +47,17 @@ THREE.BufferAttribute.prototype = {
 
 
 	},
 	},
 
 
+	copy: function ( source ) {
+
+		this.array = new source.array.constructor( source.array );
+		this.itemSize = source.itemSize;
+
+		this.dynamic = source.dynamic;
+
+		return this;
+
+	},
+
 	copyAt: function ( index1, attribute, index2 ) {
 	copyAt: function ( index1, attribute, index2 ) {
 
 
 		index1 *= this.itemSize;
 		index1 *= this.itemSize;
@@ -292,7 +303,7 @@ THREE.BufferAttribute.prototype = {
 
 
 	clone: function () {
 	clone: function () {
 
 
-		return new this.constructor( new this.array.constructor( this.array ), this.itemSize );
+		return new this.constructor().copy( this );
 
 
 	}
 	}
 
 

+ 6 - 2
src/core/InstancedBufferAttribute.js

@@ -13,8 +13,12 @@ THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute )
 THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
 THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
 THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
 THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
 
 
-THREE.InstancedBufferAttribute.prototype.clone = function () {
+THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
 
 
-	return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute );
+	THREE.BufferAttribute.prototype.copy.call( this, source );
+
+	this.meshPerAttribute = source.meshPerAttribute;
+
+	return this;
 
 
 };
 };

+ 6 - 2
src/core/InstancedInterleavedBuffer.js

@@ -13,8 +13,12 @@ THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute )
 THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
 THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
 THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
 THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
 
 
-THREE.InstancedInterleavedBuffer.prototype.clone = function () {
+THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
 
 
-	return new this.constructor( new this.array.constructor( this.array ), this.stride, this.meshPerAttribute );
+	THREE.InterleavedBuffer.prototype.copy.call( this, source );
+
+	this.meshPerAttribute = source.meshPerAttribute;
+
+	return this;
 
 
 };
 };

+ 11 - 3
src/core/InterleavedBuffer.js

@@ -9,11 +9,11 @@ THREE.InterleavedBuffer = function ( array, stride ) {
 	this.array = array;
 	this.array = array;
 	this.stride = stride;
 	this.stride = stride;
 
 
-	this.version = 0;
-
 	this.dynamic = false;
 	this.dynamic = false;
 	this.updateRange = { offset: 0, count: - 1 };
 	this.updateRange = { offset: 0, count: - 1 };
 
 
+	this.version = 0;
+
 };
 };
 
 
 THREE.InterleavedBuffer.prototype = {
 THREE.InterleavedBuffer.prototype = {
@@ -46,6 +46,14 @@ THREE.InterleavedBuffer.prototype = {
 
 
 	},
 	},
 
 
+	copy: function ( source ) {
+
+		this.array = new source.array.constructor( source.array );
+		this.stride = source.stride;
+		this.dynamic = source.dynamic;
+
+	},
+
 	copyAt: function ( index1, attribute, index2 ) {
 	copyAt: function ( index1, attribute, index2 ) {
 
 
 		index1 *= this.stride;
 		index1 *= this.stride;
@@ -73,7 +81,7 @@ THREE.InterleavedBuffer.prototype = {
 
 
 	clone: function () {
 	clone: function () {
 
 
-		return new this.constructor( new this.array.constructor( this.array ), this.stride, this.dynamic );
+		return new this.constructor().copy( this );
 
 
 	}
 	}