From e3af646a3c497ee47b59617f20021d248228f474 Mon Sep 17 00:00:00 2001 From: hena-3 Date: Tue, 23 Jun 2015 13:16:22 +0530 Subject: [PATCH] Added clone functionality --- src/objects/Bone.js | 11 +++++++++++ src/objects/Group.js | 10 ++++++++++ src/objects/LensFlare.js | 19 +++++++++++++++++++ src/objects/LineSegments.js | 10 ++++++++++ src/objects/Skeleton.js | 7 +++++++ 5 files changed, 57 insertions(+) diff --git a/src/objects/Bone.js b/src/objects/Bone.js index daa4c7a515..88e2951ca8 100644 --- a/src/objects/Bone.js +++ b/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; + +}; \ No newline at end of file diff --git a/src/objects/Group.js b/src/objects/Group.js index 8a930fe4a5..a7c8838f6a 100644 --- a/src/objects/Group.js +++ b/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; + +}; \ No newline at end of file diff --git a/src/objects/LensFlare.js b/src/objects/LensFlare.js index 0f83750cdd..76905dea46 100644 --- a/src/objects/LensFlare.js +++ b/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; + +}; \ No newline at end of file diff --git a/src/objects/LineSegments.js b/src/objects/LineSegments.js index e81c3614f6..65b47fba0a 100644 --- a/src/objects/LineSegments.js +++ b/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; + +}; \ No newline at end of file diff --git a/src/objects/Skeleton.js b/src/objects/Skeleton.js index 38e6061d32..a63b30a802 100644 --- a/src/objects/Skeleton.js +++ b/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; + +}; \ No newline at end of file -- GitLab