Przeglądaj źródła

Editor: Notify user that no object has been selected when exporting geometry. Fixes #4295.

Mr.doob 11 lat temu
rodzic
commit
4d6c6790d3
3 zmienionych plików z 38 dodań i 29 usunięć
  1. 11 1
      editor/js/Editor.js
  2. 26 27
      editor/js/Menubar.File.js
  3. 1 1
      editor/js/Viewport.js

+ 11 - 1
editor/js/Editor.js

@@ -292,7 +292,17 @@ Editor.prototype = {
 	select: function ( object ) {
 	select: function ( object ) {
 
 
 		this.selected = object;
 		this.selected = object;
-		this.config.setKey( 'selected', object.uuid );
+
+		if ( object !== null ) {
+
+			this.config.setKey( 'selected', object.uuid );
+
+		} else {
+
+			this.config.setKey( 'selected', null );
+
+		}
+
 		this.signals.objectSelected.dispatch( object );
 		this.signals.objectSelected.dispatch( object );
 
 
 	},
 	},

+ 26 - 27
editor/js/Menubar.File.js

@@ -69,37 +69,37 @@ Menubar.File = function ( editor ) {
 	option.setTextContent( 'Export Geometry' );
 	option.setTextContent( 'Export Geometry' );
 	option.onClick( function () {
 	option.onClick( function () {
 
 
-		var geometry = editor.selected.geometry;
+		var object = editor.selected;
 
 
-		if ( geometry instanceof THREE.BufferGeometry ) {
+		if ( object === null ) {
 
 
-			exportGeometry( THREE.BufferGeometryExporter );
+			alert( 'No object selected.' );
+			return;
 
 
-		} else if ( geometry instanceof THREE.Geometry ) {
+		}
 
 
-			exportGeometry( THREE.GeometryExporter );
+		var geometry = object.geometry;
+
+		if ( geometry === undefined ) {
+
+			alert( 'The selected object doesn\'t have geometry.' );
+			return;
 
 
 		}
 		}
 
 
-	} );
-	options.add( option );
+		if ( geometry instanceof THREE.BufferGeometry ) {
 
 
-	/*
+			exportGeometry( THREE.BufferGeometryExporter );
 
 
-	// export scene
+		} else if ( geometry instanceof THREE.Geometry ) {
 
 
-	var option = new UI.Panel();
-	option.setClass( 'option' );
-	option.setTextContent( 'Export Scene' );
-	option.onClick( function () {
+			exportGeometry( THREE.GeometryExporter );
 
 
-		exportScene( THREE.SceneExporter );
+		}
 
 
 	} );
 	} );
 	options.add( option );
 	options.add( option );
 
 
-	*/
-
 	// export object
 	// export object
 
 
 	var option = new UI.Panel();
 	var option = new UI.Panel();
@@ -107,6 +107,13 @@ Menubar.File = function ( editor ) {
 	option.setTextContent( 'Export Object' );
 	option.setTextContent( 'Export Object' );
 	option.onClick( function () {
 	option.onClick( function () {
 
 
+		if ( editor.selected === null ) {
+
+			alert( 'No object selected' );
+			return;
+
+		}
+
 		exportObject( THREE.ObjectExporter );
 		exportObject( THREE.ObjectExporter );
 
 
 	} );
 	} );
@@ -139,19 +146,12 @@ Menubar.File = function ( editor ) {
 	var exportGeometry = function ( exporterClass ) {
 	var exportGeometry = function ( exporterClass ) {
 
 
 		var object = editor.selected;
 		var object = editor.selected;
-
-		if ( object.geometry === undefined ) {
-
-			alert( "Selected object doesn't have any geometry" );
-			return;
-
-		}
-
 		var exporter = new exporterClass();
 		var exporter = new exporterClass();
 
 
 		var output;
 		var output;
 
 
-		if ( exporter instanceof THREE.BufferGeometryExporter || exporter instanceof THREE.GeometryExporter ) {
+		if ( exporter instanceof THREE.BufferGeometryExporter ||
+		     exporter instanceof THREE.GeometryExporter ) {
 
 
 			output = JSON.stringify( exporter.parse( object.geometry ), null, '\t' );
 			output = JSON.stringify( exporter.parse( object.geometry ), null, '\t' );
 			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
@@ -172,9 +172,8 @@ Menubar.File = function ( editor ) {
 
 
 	var exportObject = function ( exporterClass ) {
 	var exportObject = function ( exporterClass ) {
 
 
-		var exporter = new exporterClass();
-
 		var object = editor.selected;
 		var object = editor.selected;
+		var exporter = new exporterClass();
 
 
 		var output = JSON.stringify( exporter.parse( object ), null, '\t' );
 		var output = JSON.stringify( exporter.parse( object ), null, '\t' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
 		output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );

+ 1 - 1
editor/js/Viewport.js

@@ -139,7 +139,7 @@ var Viewport = function ( editor ) {
 
 
 			} else {
 			} else {
 
 
-				editor.select( camera );
+				editor.select( null );
 
 
 			}
 			}