Browse Source

SceneExporter2: Added some basic type checking and hierarchy.

Mr.doob 12 years ago
parent
commit
e7d260cb37
1 changed files with 67 additions and 1 deletions
  1. 67 1
      examples/js/exporters/SceneExporter2.js

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

@@ -20,7 +20,73 @@ THREE.SceneExporter2.prototype = {
 
 		console.log( scene );
 
-		return JSON.stringify( output );
+		var parseObject = function ( object ) {
+
+			var data = {
+
+				name: object.name
+
+			};
+
+			if ( object instanceof THREE.PerspectiveCamera ) {
+
+				data.type = 'PerspectiveCamera';
+
+			} else if ( object instanceof THREE.OrthographicCamera ) {
+
+				data.type = 'OrthographicCamera';
+
+			} else if ( object instanceof THREE.AmbientLight ) {
+
+				data.type = 'AmbientLight';
+
+			} else if ( object instanceof THREE.DirectionalLight ) {
+
+				data.type = 'DirectionalLight';
+
+			} else if ( object instanceof THREE.PointLight ) {
+
+				data.type = 'PointLight';
+
+			} else if ( object instanceof THREE.SpotLight ) {
+
+				data.type = 'SpotLight';
+
+			} else if ( object instanceof THREE.HemisphereLight ) {
+
+				data.type = 'HemisphereLight';
+
+			} else if ( object instanceof THREE.Mesh ) {
+
+				data.type = 'Mesh';
+
+			} else {
+
+				data.type = 'Object3D';
+
+			}
+
+			// parse children
+
+			if ( object.children.length > 0 ) {
+
+				data.children = [];
+
+				for ( var i = 0; i < object.children.length; i ++ ) {
+
+					data.children.push( parseObject( object.children[ i ] ) );
+
+				}
+
+			}
+
+			return data;
+
+		}
+
+		output.graph = parseObject( scene ).children;
+
+		return JSON.stringify( output, null, '\t' );
 
 	}