Browse Source

Added Vector*.toArray(). Implemented in SceneExporter2.

Mr.doob 12 years ago
parent
commit
9eaf84a50f
4 changed files with 32 additions and 1 deletions
  1. 14 1
      examples/js/exporters/SceneExporter2.js
  2. 6 0
      src/math/Vector2.js
  3. 6 0
      src/math/Vector3.js
  4. 6 0
      src/math/Vector4.js

+ 14 - 1
examples/js/exporters/SceneExporter2.js

@@ -31,10 +31,14 @@ THREE.SceneExporter2.prototype = {
 			if ( object instanceof THREE.PerspectiveCamera ) {
 
 				data.type = 'PerspectiveCamera';
+				data.position = object.position.toArray();
+				data.rotation = object.rotation.toArray();
 
 			} else if ( object instanceof THREE.OrthographicCamera ) {
 
 				data.type = 'OrthographicCamera';
+				data.position = object.position.toArray();
+				data.rotation = object.rotation.toArray();
 
 			} else if ( object instanceof THREE.AmbientLight ) {
 
@@ -43,14 +47,17 @@ THREE.SceneExporter2.prototype = {
 			} else if ( object instanceof THREE.DirectionalLight ) {
 
 				data.type = 'DirectionalLight';
+				data.position = object.position.toArray();
 
 			} else if ( object instanceof THREE.PointLight ) {
 
 				data.type = 'PointLight';
+				data.position = object.position.toArray();
 
 			} else if ( object instanceof THREE.SpotLight ) {
 
 				data.type = 'SpotLight';
+				data.position = object.position.toArray();
 
 			} else if ( object instanceof THREE.HemisphereLight ) {
 
@@ -59,10 +66,16 @@ THREE.SceneExporter2.prototype = {
 			} else if ( object instanceof THREE.Mesh ) {
 
 				data.type = 'Mesh';
+				data.position = object.position.toArray();
+				data.rotation = object.rotation.toArray();
+				data.scale = object.scale.toArray();
 
 			} else {
 
 				data.type = 'Object3D';
+				data.position = object.position.toArray();
+				data.rotation = object.rotation.toArray();
+				data.scale = object.scale.toArray();
 
 			}
 
@@ -84,7 +97,7 @@ THREE.SceneExporter2.prototype = {
 
 		}
 
-		output.graph = parseObject( scene ).children;
+		output.scene = parseObject( scene ).children;
 
 		return JSON.stringify( output, null, '\t' );
 

+ 6 - 0
src/math/Vector2.js

@@ -293,6 +293,12 @@ THREE.extend( THREE.Vector2.prototype, {
 
 	},
 
+	toArray: function () {
+
+		return [ this.x, this.y ];
+		
+	},
+
 	clone: function () {
 
 		return new THREE.Vector2( this.x, this.y );

+ 6 - 0
src/math/Vector3.js

@@ -751,6 +751,12 @@ THREE.extend( THREE.Vector3.prototype, {
 
 	},
 
+	toArray: function () {
+
+		return [ this.x, this.y, this.z ];
+		
+	},
+
 	clone: function () {
 
 		return new THREE.Vector3( this.x, this.y, this.z );

+ 6 - 0
src/math/Vector4.js

@@ -393,6 +393,12 @@ THREE.extend( THREE.Vector4.prototype, {
 
 	},
 
+	toArray: function () {
+
+		return [ this.x, this.y, this.z, this.w ];
+		
+	},
+
 	clone: function () {
 
 		return new THREE.Vector4( this.x, this.y, this.z, this.w );