Browse Source

GLTF2Exporter: Allow list of scenes and objects and single object and scene

Fernando Serrano 8 years ago
parent
commit
501ac6447e
1 changed files with 44 additions and 3 deletions
  1. 44 3
      examples/js/exporters/GLTFExporter.js

+ 44 - 3
examples/js/exporters/GLTFExporter.js

@@ -798,18 +798,59 @@ THREE.GLTFExporter.prototype = {
 
 
 		}
 		}
 
 
-		// Process the scene/s
+		/**
+		 * Creates a THREE.Scene to hold a list of objects and parse it
+		 * @param  {Array} objects List of objects to process
+		 */
+		function processObjects ( objects ) {
+
+			var scene = new THREE.Scene();
+
+			for ( var i = 0; i < objects.length; i++ ) {
+
+				scene.add( objects[ i ] );
+
+			}
+
+			processScene( scene );
+
+		}
+
+
 		if ( input instanceof Array ) {
 		if ( input instanceof Array ) {
 
 
+			var allScenes = false;
 			for ( i = 0; i < input.length; i++ ) {
 			for ( i = 0; i < input.length; i++ ) {
 
 
-				processScene( input[ i ] );
+				allScenes &= input instanceof THREE.Scene;
+
+			}
+
+			if ( allScenes ) {
+
+				for ( i = 0; i < input.length; i++ ) {
+
+					processScene( input[ i ] );
+
+				}
+
+			} else {
+
+				processObjects( input );
 
 
 			}
 			}
 
 
 		} else {
 		} else {
 
 
-			processScene( input );
+			if ( input instanceof THREE.Scene ) {
+
+				processScene( input );
+
+			} else {
+
+				processObjects( [ input ] );
+
+			}
 
 
 		}
 		}