Browse Source

Object3D: Using Object.defineProperties to avoid object.rotation = new THREE.Euler() pattern. See fffeeb636ee9fa38f2e3a51358c361116d827d8b.

Mr.doob 11 years ago
parent
commit
5549e242e0
2 changed files with 24 additions and 8 deletions
  1. 24 7
      src/core/Object3D.js
  2. 0 1
      src/math/Vector2.js

+ 24 - 7
src/core/Object3D.js

@@ -7,8 +7,6 @@
 
 
 THREE.Object3D = function () {
 THREE.Object3D = function () {
 
 
-	var scope = this;
-
 	this.id = THREE.Object3DIdCount ++;
 	this.id = THREE.Object3DIdCount ++;
 	this.uuid = THREE.Math.generateUUID();
 	this.uuid = THREE.Math.generateUUID();
 
 
@@ -19,11 +17,30 @@ THREE.Object3D = function () {
 
 
 	this.up = new THREE.Vector3( 0, 1, 0 );
 	this.up = new THREE.Vector3( 0, 1, 0 );
 
 
-	this.position = new THREE.Vector3();
-	this.rotation = new THREE.Euler().onChange( function () { scope.quaternion.setFromEuler( scope.rotation, false ); } );
-	this.quaternion = new THREE.Quaternion().onChange( function () { scope.rotation.setFromQuaternion( scope.quaternion, undefined, false );
- } );
-	this.scale = new THREE.Vector3( 1, 1, 1 );
+	var scope = this;
+
+	Object.defineProperties( this, {
+		position: { 
+			enumerable: true, 
+			value: new THREE.Vector3()
+		},
+		rotation: {
+			enumerable: true,	
+			value: new THREE.Euler().onChange( function () {
+				scope.quaternion.setFromEuler( scope.rotation, false );
+			} )
+		},
+		quaternion: {
+			enumerable: true,	
+			value: new THREE.Quaternion().onChange( function () {
+				scope.rotation.setFromQuaternion( scope.quaternion, undefined, false );
+			} )
+		},
+		scale: {
+			enumerable: true,	
+			value: new THREE.Vector3( 1, 1, 1 )
+		}
+	} );
 
 
 	this.renderDepth = null;
 	this.renderDepth = null;
 
 

+ 0 - 1
src/math/Vector2.js

@@ -41,7 +41,6 @@ THREE.Vector2.prototype = {
 
 
 	},
 	},
 
 
-
 	setComponent: function ( index, value ) {
 	setComponent: function ( index, value ) {
 
 
 		switch ( index ) {
 		switch ( index ) {