Browse Source

Object3D, Camera: world* methods to getWorld* (and some refactoring). See #5420.

Mr.doob 10 years ago
parent
commit
a3b468bc46
2 changed files with 90 additions and 90 deletions
  1. 14 14
      src/cameras/Camera.js
  2. 76 76
      src/core/Object3D.js

+ 14 - 14
src/cameras/Camera.js

@@ -17,35 +17,35 @@ THREE.Camera = function () {
 
 
 THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
 
 
-THREE.Camera.prototype.lookAt = function () {
+THREE.Camera.prototype.getWorldDirection = function () {
 
 
-	// This routine does not support cameras with rotated and/or translated parent(s)
+	var quaternion = new THREE.Quaternion();
 
 
-	var m1 = new THREE.Matrix4();
+	return function ( optionalTarget ) {
 
 
-	return function ( vector ) {
+		var result = optionalTarget || new THREE.Vector3();
 
 
-		m1.lookAt( this.position, vector, this.up );
+		this.worldQuaternion( quaternion );
 
 
-		this.quaternion.setFromRotationMatrix( m1 );
+		return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
 
 
-	};
+	}
 
 
 }();
 }();
 
 
-THREE.Camera.prototype.worldDirection = function () {
+THREE.Camera.prototype.lookAt = function () {
 
 
-	var quaternion = new THREE.Quaternion();
+	// This routine does not support cameras with rotated and/or translated parent(s)
 
 
-	return function ( optionalTarget ) {
+	var m1 = new THREE.Matrix4();
 
 
-		var result = optionalTarget || new THREE.Vector3();
+	return function ( vector ) {
 
 
-		this.worldQuaternion( quaternion );
+		m1.lookAt( this.position, vector, this.up );
 
 
-		return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
+		this.quaternion.setFromRotationMatrix( m1 );
 
 
-	}
+	};
 
 
 }();
 }();
 
 

+ 76 - 76
src/core/Object3D.js

@@ -370,31 +370,10 @@ THREE.Object3D.prototype = {
 
 
 	},
 	},
 
 
-	raycast: function () {},
-
-	traverse: function ( callback ) {
-
-		callback( this );
-
-		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
-
-			this.children[ i ].traverse( callback );
-
-		}
-
-	},
-
-	traverseVisible: function ( callback ) {
-
-		if ( this.visible === false ) return;
-
-		callback( this );
-
-		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
-
-			this.children[ i ].traverseVisible( callback );
+	getChildByName: function ( name, recursive ) {
 
 
-		}
+		console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
+		return this.getObjectByName( name, recursive );
 
 
 	},
 	},
 
 
@@ -440,54 +419,7 @@ THREE.Object3D.prototype = {
 
 
 	},
 	},
 
 
-	getChildByName: function ( name, recursive ) {
-
-		console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
-		return this.getObjectByName( name, recursive );
-
-	},
-
-	updateMatrix: function () {
-
-		this.matrix.compose( this.position, this.quaternion, this.scale );
-
-		this.matrixWorldNeedsUpdate = true;
-
-	},
-
-	updateMatrixWorld: function ( force ) {
-
-		if ( this.matrixAutoUpdate === true ) this.updateMatrix();
-
-		if ( this.matrixWorldNeedsUpdate === true || force === true ) {
-
-			if ( this.parent === undefined ) {
-
-				this.matrixWorld.copy( this.matrix );
-
-			} else {
-
-				this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
-
-			}
-
-			this.matrixWorldNeedsUpdate = false;
-
-			force = true;
-
-		}
-
-		// update children
-
-		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
-
-			this.children[ i ].updateMatrixWorld( force );
-
-		}
-
-	},
-
-	worldPosition: function ( optionalTarget ) {
+	getWorldPosition: function ( optionalTarget ) {
 
 
 		var result = optionalTarget || new THREE.Vector3();
 		var result = optionalTarget || new THREE.Vector3();
 
 
@@ -497,7 +429,7 @@ THREE.Object3D.prototype = {
 
 
 	},
 	},
 
 
-	worldQuaternion: function () {
+	getWorldQuaternion: function () {
 
 
 		var position = new THREE.Vector3();
 		var position = new THREE.Vector3();
 		var scale = new THREE.Vector3();
 		var scale = new THREE.Vector3();
@@ -516,7 +448,7 @@ THREE.Object3D.prototype = {
 
 
 	}(),
 	}(),
 
 
-	worldRotation: function () {
+	getWorldRotation: function () {
 
 
 		var quaternion = new THREE.Quaternion();
 		var quaternion = new THREE.Quaternion();
 
 
@@ -532,7 +464,7 @@ THREE.Object3D.prototype = {
 
 
 	}(),
 	}(),
 
 
-	worldScale: function () {
+	getWorldScale: function () {
 
 
 		var position = new THREE.Vector3();
 		var position = new THREE.Vector3();
 		var quaternion = new THREE.Quaternion();
 		var quaternion = new THREE.Quaternion();
@@ -551,7 +483,7 @@ THREE.Object3D.prototype = {
 
 
 	}(),
 	}(),
 
 
-	worldDirection: function () {
+	getWorldDirection: function () {
 
 
 		var quaternion = new THREE.Quaternion();
 		var quaternion = new THREE.Quaternion();
 
 
@@ -567,6 +499,74 @@ THREE.Object3D.prototype = {
 
 
 	}(),
 	}(),
 
 
+	raycast: function () {},
+
+	traverse: function ( callback ) {
+
+		callback( this );
+
+		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+
+			this.children[ i ].traverse( callback );
+
+		}
+
+	},
+
+	traverseVisible: function ( callback ) {
+
+		if ( this.visible === false ) return;
+
+		callback( this );
+
+		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+
+			this.children[ i ].traverseVisible( callback );
+
+		}
+
+	},
+
+	updateMatrix: function () {
+
+		this.matrix.compose( this.position, this.quaternion, this.scale );
+
+		this.matrixWorldNeedsUpdate = true;
+
+	},
+
+	updateMatrixWorld: function ( force ) {
+
+		if ( this.matrixAutoUpdate === true ) this.updateMatrix();
+
+		if ( this.matrixWorldNeedsUpdate === true || force === true ) {
+
+			if ( this.parent === undefined ) {
+
+				this.matrixWorld.copy( this.matrix );
+
+			} else {
+
+				this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
+
+			}
+
+			this.matrixWorldNeedsUpdate = false;
+
+			force = true;
+
+		}
+
+		// update children
+
+		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+
+			this.children[ i ].updateMatrixWorld( force );
+
+		}
+
+	},
+
 	toJSON: function () {
 	toJSON: function () {
 
 
 		var output = {
 		var output = {