Pārlūkot izejas kodu

Merge pull request #6727 from hena-3/devClone

Added clone functionality for objects
Ricardo Cabello 10 gadi atpakaļ
vecāks
revīzija
2e123b1eea

+ 11 - 0
src/objects/Bone.js

@@ -16,3 +16,14 @@ THREE.Bone = function ( skin ) {
 
 THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Bone.prototype.constructor = THREE.Bone;
+
+THREE.Bone.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.Bone( this.skin );
+
+	THREE.Object3D.prototype.clone.call( this, object );
+	object.skin = this.skin; 
+
+	return object;
+
+};

+ 10 - 0
src/objects/Group.js

@@ -12,3 +12,13 @@ THREE.Group = function () {
 
 THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Group.prototype.constructor = THREE.Group;
+
+THREE.Group.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.Group();
+
+	THREE.Object3D.prototype.clone.call( this, object );
+
+	return object;
+
+};

+ 19 - 0
src/objects/LensFlare.js

@@ -78,3 +78,22 @@ THREE.LensFlare.prototype.updateLensFlares = function () {
 
 };
 
+THREE.LensFlare.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.LensFlare();
+
+	THREE.Object3D.prototype.clone.call( this, object );
+	
+	object.positionScreen.copy(this.positionScreen);
+	object.customUpdateCallback = this.customUpdateCallback;
+	
+	object.lensFlares = [];
+	
+	for ( var i = 0, l = this.lensFlares.length; i < l; i ++ ) {
+		
+		object.lensFlares.push(this.lensFlares[i]);			
+	}
+
+	return object;
+
+};

+ 10 - 0
src/objects/LineSegments.js

@@ -12,3 +12,13 @@ THREE.LineSegments = function ( geometry, material ) {
 
 THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
 THREE.LineSegments.prototype.constructor = THREE.LineSegments;
+
+THREE.LineSegments.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.LineSegments( this.geometry, this.material );
+
+	THREE.Line.prototype.clone.call( this, object );
+
+	return object;
+
+};

+ 7 - 0
src/objects/Skeleton.js

@@ -170,3 +170,10 @@ THREE.Skeleton.prototype.update = ( function () {
 
 } )();
 
+THREE.Skeleton.prototype.clone = function ( ) {
+
+	var object = new THREE.Skeleton(this.bones, this.boneInverses, this.useVertexTexture);
+	
+	return object;
+
+};