فهرست منبع

Split SceneUtils.cloneObject into *.clone()

Mr.doob 13 سال پیش
والد
کامیت
6a0b0eb1fd

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 264 - 262
build/three.min.js


+ 37 - 2
src/core/Object3D.js

@@ -302,9 +302,44 @@ THREE.Object3D.prototype = {
 
 	},
 
-	clone: function () {
+	clone: function ( object ) {
 
-		// TODO
+		if ( object === undefined ) object = new THREE.Object3D();
+
+		object.name = this.name;
+
+		object.up.copy( this.up );
+
+		object.position.copy( this.position );
+		if ( object.rotation instanceof THREE.Vector3 ) object.rotation.copy( this.rotation ); // because of Sprite madness
+		object.eulerOrder = this.eulerOrder;
+		object.scale.copy( this.scale );
+
+		object.renderDepth = this.renderDepth;
+
+		object.rotationAutoUpdate = this.rotationAutoUpdate;
+
+		object.matrix.copy( this.matrix );
+		object.matrixWorld.copy( this.matrixWorld );
+		object.matrixRotationWorld.copy( this.matrixRotationWorld );
+
+		object.matrixAutoUpdate = this.matrixAutoUpdate;
+		object.matrixWorldNeedsUpdate = this.matrixWorldNeedsUpdate;
+
+		object.quaternion.copy( this.quaternion );
+		object.useQuaternion = this.useQuaternion;
+
+		object.boundRadius = this.boundRadius;
+		object.boundRadiusScale = this.boundRadiusScale;
+
+		object.visible = this.visible;
+
+		object.castShadow = this.castShadow;
+		object.receiveShadow = this.receiveShadow;
+
+		object.frustumCulled = this.frustumCulled;
+
+		return object;
 
 	}
 

+ 0 - 158
src/extras/SceneUtils.js

@@ -18,164 +18,6 @@ THREE.SceneUtils = {
 
 	},
 
-	cloneObject: function ( source ) {
-
-		var object;
-
-		// subclass specific properties
-		// (must process in order from more specific subclasses to more abstract classes)
-
-		if ( source instanceof THREE.MorphAnimMesh ) {
-
-			object = new THREE.MorphAnimMesh( source.geometry, source.material );
-
-			object.duration = source.duration;
-			object.mirroredLoop = source.mirroredLoop;
-			object.time = source.time;
-
-			object.lastKeyframe = source.lastKeyframe;
-			object.currentKeyframe = source.currentKeyframe;
-
-			object.direction = source.direction;
-			object.directionBackwards = source.directionBackwards;
-
-		} else if ( source instanceof THREE.SkinnedMesh ) {
-
-			object = new THREE.SkinnedMesh( source.geometry, source.material, source.useVertexTexture );
-
-		} else if ( source instanceof THREE.Mesh ) {
-
-			object = new THREE.Mesh( source.geometry, source.material );
-
-		} else if ( source instanceof THREE.Line ) {
-
-			object = new THREE.Line( source.geometry, source.material, source.type );
-
-		} else if ( source instanceof THREE.Ribbon ) {
-
-			object = new THREE.Ribbon( source.geometry, source.material );
-
-		} else if ( source instanceof THREE.ParticleSystem ) {
-
-			object = new THREE.ParticleSystem( source.geometry, source.material );
-			object.sortParticles = source.sortParticles;
-
-		} else if ( source instanceof THREE.Particle ) {
-
-			object = new THREE.Particle( source.material );
-
-		} else if ( source instanceof THREE.Sprite ) {
-
-			object = new THREE.Sprite( {} );
-
-			object.color.copy( source.color );
-			object.map = source.map;
-			object.blending = source.blending;
-
-			object.useScreenCoordinates = source.useScreenCoordinates;
-			object.mergeWith3D = source.mergeWith3D;
-			object.affectedByDistance = source.affectedByDistance;
-			object.scaleByViewport = source.scaleByViewport;
-			object.alignment = source.alignment;
-
-			object.rotation3d.copy( source.rotation3d );
-			object.rotation = source.rotation;
-			object.opacity = source.opacity;
-
-			object.uvOffset.copy( source.uvOffset );
-			object.uvScale.copy( source.uvScale);
-
-		} else if ( source instanceof THREE.LOD ) {
-
-			object = new THREE.LOD();
-
-		/*
-		} else if ( source instanceof THREE.MarchingCubes ) {
-
-			object = new THREE.MarchingCubes( source.resolution, source.material );
-			object.field.set( source.field );
-			object.isolation = source.isolation;
-		*/
-
-		} else if ( source instanceof THREE.Object3D ) {
-
-			object = new THREE.Object3D();
-
-		}
-
-		// base class properties
-
-		object.name = source.name;
-
-		object.parent = source.parent;
-
-		object.up.copy( source.up );
-
-		object.position.copy( source.position );
-
-		// because of Sprite madness
-
-		if ( object.rotation instanceof THREE.Vector3 )
-			object.rotation.copy( source.rotation );
-
-		object.eulerOrder = source.eulerOrder;
-
-		object.scale.copy( source.scale );
-
-		object.dynamic = source.dynamic;
-
-		object.renderDepth = source.renderDepth;
-
-		object.rotationAutoUpdate = source.rotationAutoUpdate;
-
-		object.matrix.copy( source.matrix );
-		object.matrixWorld.copy( source.matrixWorld );
-		object.matrixRotationWorld.copy( source.matrixRotationWorld );
-
-		object.matrixAutoUpdate = source.matrixAutoUpdate;
-		object.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
-
-		object.quaternion.copy( source.quaternion );
-		object.useQuaternion = source.useQuaternion;
-
-		object.boundRadius = source.boundRadius;
-		object.boundRadiusScale = source.boundRadiusScale;
-
-		object.visible = source.visible;
-
-		object.castShadow = source.castShadow;
-		object.receiveShadow = source.receiveShadow;
-
-		object.frustumCulled = source.frustumCulled;
-
-		// children
-
-		for ( var i = 0; i < source.children.length; i ++ ) {
-
-			var child = THREE.SceneUtils.cloneObject( source.children[ i ] );
-			object.children[ i ] = child;
-
-			child.parent = object;
-
-		}
-
-		// LODs need to be patched separately to use cloned children
-
-		if ( source instanceof THREE.LOD ) {
-
-			for ( var i = 0; i < source.LODs.length; i ++ ) {
-
-				var lod = source.LODs[ i ];
-				object.LODs[ i ] = { visibleAtDistance: lod.visibleAtDistance, object3D: object.children[ i ] };
-
-			}
-
-		}
-
-		return object;
-
-	},
-
 	detach : function ( child, parent, scene ) {
 
 		child.applyMatrix( parent.matrixWorld );

+ 6 - 0
src/objects/LOD.js

@@ -75,3 +75,9 @@ THREE.LOD.prototype.update = function ( camera ) {
 	}
 
 };
+
+THREE.LOD.prototype.clone = function () {
+
+	// TODO
+
+};

+ 10 - 0
src/objects/Line.js

@@ -26,3 +26,13 @@ THREE.LineStrip = 0;
 THREE.LinePieces = 1;
 
 THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
+
+THREE.Line.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.Line( this.geometry, this.material, this.type );
+
+	THREE.Object3D.prototype.clone.call( this, object );
+
+	return object;
+
+};

+ 16 - 9
src/objects/Mesh.js

@@ -15,7 +15,7 @@ THREE.Mesh = function ( geometry, material ) {
 
 		// calc bound radius
 
-		if ( ! this.geometry.boundingSphere ) {
+		if ( this.geometry.boundingSphere === null ) {
 
 			this.geometry.computeBoundingSphere();
 
@@ -26,7 +26,7 @@ THREE.Mesh = function ( geometry, material ) {
 
 		// setup morph targets
 
-		if( this.geometry.morphTargets.length ) {
+		if ( this.geometry.morphTargets.length ) {
 
 			this.morphTargetBase = -1;
 			this.morphTargetForcedOrder = [];
@@ -48,19 +48,26 @@ THREE.Mesh = function ( geometry, material ) {
 
 THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
 
-
-/*
- * Get Morph Target Index by Name
- */
-
-THREE.Mesh.prototype.getMorphTargetIndexByName = function( name ) {
+THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
 
 	if ( this.morphTargetDictionary[ name ] !== undefined ) {
 
 		return this.morphTargetDictionary[ name ];
+
 	}
 
 	console.log( "THREE.Mesh.getMorphTargetIndexByName: morph target " + name + " does not exist. Returning 0." );
+
 	return 0;
 
-}
+};
+
+THREE.Mesh.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.Mesh( this.geometry, this.material );
+
+	THREE.Object3D.prototype.clone.call( this, object );
+
+	return object;
+
+};

+ 20 - 0
src/objects/MorphAnimMesh.js

@@ -174,3 +174,23 @@ THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
 	this.morphTargetInfluences[ this.lastKeyframe ] = 1 - mix;
 
 };
+
+THREE.MorphAnimMesh.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.MorphAnimMesh( this.geometry, this.material );
+
+	object.duration = this.duration;
+	object.mirroredLoop = this.mirroredLoop;
+	object.time = this.time;
+
+	object.lastKeyframe = this.lastKeyframe;
+	object.currentKeyframe = this.currentKeyframe;
+
+	object.direction = this.direction;
+	object.directionBackwards = this.directionBackwards;
+
+	THREE.Mesh.prototype.clone.call( this, object );
+
+	return object;
+
+};

+ 10 - 0
src/objects/Particle.js

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

+ 12 - 1
src/objects/ParticleSystem.js

@@ -15,7 +15,7 @@ THREE.ParticleSystem = function ( geometry, material ) {
 
 		// calc bound radius
 
-		if( !this.geometry.boundingSphere ) {
+		if( this.geometry.boundingSphere === null ) {
 
 			this.geometry.computeBoundingSphere();
 
@@ -30,3 +30,14 @@ THREE.ParticleSystem = function ( geometry, material ) {
 };
 
 THREE.ParticleSystem.prototype = Object.create( THREE.Object3D.prototype );
+
+THREE.ParticleSystem.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.ParticleSystem( this.geometry, this.material );
+	object.sortParticles = this.sortParticles;
+
+	THREE.Object3D.prototype.clone.call( this, object );
+
+	return object;
+
+};

+ 10 - 0
src/objects/Ribbon.js

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

+ 10 - 5
src/objects/SkinnedMesh.js

@@ -212,10 +212,6 @@ THREE.SkinnedMesh.prototype.updateMatrixWorld = function ( force ) {
 
 };
 
-/*
- * Pose
- */
-
 THREE.SkinnedMesh.prototype.pose = function() {
 
 	this.updateMatrixWorld( true );
@@ -242,5 +238,14 @@ THREE.SkinnedMesh.prototype.pose = function() {
 
 };
 
-THREE.SkinnedMesh.offsetMatrix = new THREE.Matrix4();
+THREE.SkinnedMesh.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
+
+	THREE.Mesh.prototype.clone.call( this, object );
 
+	return object;
+
+};
+
+THREE.SkinnedMesh.offsetMatrix = new THREE.Matrix4();

+ 27 - 0
src/objects/Sprite.js

@@ -54,6 +54,33 @@ THREE.Sprite.prototype.updateMatrix = function () {
 
 };
 
+THREE.Sprite.prototype.clone = function ( object ) {
+
+	if ( object === undefined ) object = new THREE.Sprite( {} );
+
+	object.color.copy( this.color );
+	object.map = this.map;
+	object.blending = this.blending;
+
+	object.useScreenCoordinates = this.useScreenCoordinates;
+	object.mergeWith3D = this.mergeWith3D;
+	object.affectedByDistance = this.affectedByDistance;
+	object.scaleByViewport = this.scaleByViewport;
+	object.alignment = this.alignment;
+
+	object.rotation3d.copy( this.rotation3d );
+	object.rotation = this.rotation;
+	object.opacity = this.opacity;
+
+	object.uvOffset.copy( this.uvOffset );
+	object.uvScale.copy( this.uvScale);
+
+	THREE.Object3D.prototype.clone.call( this, object );
+
+	return object;
+
+};
+
 /*
  * Alignment
  */

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است