Bläddra i källkod

Editor: Moved Export Geometry/Object/Scene to Sidebar.

Mr.doob 1 år sedan
förälder
incheckning
109c87fbef

+ 0 - 106
editor/js/Menubar.File.js

@@ -72,112 +72,6 @@ function MenubarFile( editor ) {
 
 	options.add( new UIHorizontalRule() );
 
-	// Export Geometry
-
-	option = new UIRow();
-	option.setClass( 'option' );
-	option.setTextContent( strings.getKey( 'menubar/file/export/geometry' ) );
-	option.onClick( function () {
-
-		const object = editor.selected;
-
-		if ( object === null ) {
-
-			alert( 'No object selected.' );
-			return;
-
-		}
-
-		const geometry = object.geometry;
-
-		if ( geometry === undefined ) {
-
-			alert( 'The selected object doesn\'t have geometry.' );
-			return;
-
-		}
-
-		let output = geometry.toJSON();
-
-		try {
-
-			output = JSON.stringify( output, null, '\t' );
-			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
-
-		} catch ( e ) {
-
-			output = JSON.stringify( output );
-
-		}
-
-		saveString( output, 'geometry.json' );
-
-	} );
-	options.add( option );
-
-	// Export Object
-
-	option = new UIRow();
-	option.setClass( 'option' );
-	option.setTextContent( strings.getKey( 'menubar/file/export/object' ) );
-	option.onClick( function () {
-
-		const object = editor.selected;
-
-		if ( object === null ) {
-
-			alert( 'No object selected' );
-			return;
-
-		}
-
-		let output = object.toJSON();
-
-		try {
-
-			output = JSON.stringify( output, null, '\t' );
-			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
-
-		} catch ( e ) {
-
-			output = JSON.stringify( output );
-
-		}
-
-		saveString( output, 'model.json' );
-
-	} );
-	options.add( option );
-
-	// Export Scene
-
-	option = new UIRow();
-	option.setClass( 'option' );
-	option.setTextContent( strings.getKey( 'menubar/file/export/scene' ) );
-	option.onClick( function () {
-
-		let output = editor.scene.toJSON();
-
-		try {
-
-			output = JSON.stringify( output, null, '\t' );
-			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
-
-		} catch ( e ) {
-
-			output = JSON.stringify( output );
-
-		}
-
-		saveString( output, 'scene.json' );
-
-	} );
-	options.add( option );
-
-	//
-
-	options.add( new UIHorizontalRule() );
-
 	// Export DRC
 
 	option = new UIRow();

+ 33 - 0
editor/js/Sidebar.Geometry.js

@@ -170,6 +170,39 @@ function SidebarGeometry( editor ) {
 	} );
 	helpersRow.add( vertexNormalsButton );
 
+	// Export JSON
+
+	const exportJson = new UIButton( strings.getKey( 'sidebar/geometry/export' ) );
+	exportJson.setMarginLeft( '90px' );
+	exportJson.onClick( function () {
+
+		const object = editor.selected;
+		const geometry = object.geometry;
+
+		let output = geometry.toJSON();
+
+		try {
+
+			output = JSON.stringify( output, null, '\t' );
+			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
+
+		} catch ( e ) {
+
+			output = JSON.stringify( output );
+
+		}
+
+		const left = ( screen.width / 2 ) - ( 250 );
+		const top = ( screen.height / 2 ) - ( 250 );
+
+		const url = URL.createObjectURL( new Blob( [ output ], { type: 'text/plain' } ) );
+		window.open( url, null, `location=no,left=${left},top=${top},width=500,height=500` );
+
+	} );
+	container.add( exportJson );
+
+	//
+
 	async function build() {
 
 		const object = editor.selected;

+ 31 - 0
editor/js/Sidebar.Material.js

@@ -413,6 +413,37 @@ function SidebarMaterial( editor ) {
 
 	container.add( materialUserDataRow );
 
+	// Export JSON
+
+	const exportJson = new UIButton( strings.getKey( 'sidebar/material/export' ) );
+	exportJson.setMarginLeft( '90px' );
+	exportJson.onClick( function () {
+
+		const object = editor.selected;
+		const material = object.material;
+
+		let output = material.toJSON();
+
+		try {
+
+			output = JSON.stringify( output, null, '\t' );
+			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
+
+		} catch ( e ) {
+
+			output = JSON.stringify( output );
+
+		}
+
+		const left = ( screen.width / 2 ) - ( 250 );
+		const top = ( screen.height / 2 ) - ( 250 );
+
+		const url = URL.createObjectURL( new Blob( [ output ], { type: 'text/plain' } ) );
+		window.open( url, null, `location=no,left=${left},top=${top},width=500,height=500` );
+
+	} );
+	container.add( exportJson );
+
 	//
 
 	function update() {

+ 29 - 0
editor/js/Sidebar.Object.js

@@ -386,6 +386,35 @@ function SidebarObject( editor ) {
 
 	container.add( objectUserDataRow );
 
+	// Export JSON
+
+	const exportJson = new UIButton( strings.getKey( 'sidebar/object/export' ) );
+	exportJson.setMarginLeft( '90px' );
+	exportJson.onClick( function () {
+
+		const object = editor.selected;
+
+		let output = object.toJSON();
+
+		try {
+
+			output = JSON.stringify( output, null, '\t' );
+			output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
+
+		} catch ( e ) {
+
+			output = JSON.stringify( output );
+
+		}
+
+		const left = ( screen.width / 2 ) - ( 250 );
+		const top = ( screen.height / 2 ) - ( 250 );
+
+		const url = URL.createObjectURL( new Blob( [ output ], { type: 'text/plain' } ) );
+		window.open( url, null, `location=no,left=${left},top=${top},width=500,height=500` );
+
+	} );
+	container.add( exportJson );
 
 	//
 

+ 9 - 9
editor/js/Strings.js

@@ -9,9 +9,6 @@ function Strings( config ) {
 			'menubar/file': 'File',
 			'menubar/file/new': 'New',
 			'menubar/file/import': 'Import',
-			'menubar/file/export/geometry': 'Export Geometry',
-			'menubar/file/export/object': 'Export Object',
-			'menubar/file/export/scene': 'Export Scene',
 			'menubar/file/export/drc': 'Export DRC',
 			'menubar/file/export/glb': 'Export GLB',
 			'menubar/file/export/gltf': 'Export GLTF',
@@ -124,6 +121,7 @@ function Strings( config ) {
 			'sidebar/object/frustumcull': 'Frustum Cull',
 			'sidebar/object/renderorder': 'Render Order',
 			'sidebar/object/userdata': 'User data',
+			'sidebar/object/export': 'Export JSON',
 
 			'sidebar/geometry/type': 'Type',
 			'sidebar/geometry/new': 'New',
@@ -134,6 +132,7 @@ function Strings( config ) {
 			'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
 			'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
 			'sidebar/geometry/center': 'Center',
+			'sidebar/geometry/export': 'Export JSON',
 
 			'sidebar/geometry/box_geometry/width': 'Width',
 			'sidebar/geometry/box_geometry/height': 'Height',
@@ -304,6 +303,7 @@ function Strings( config ) {
 			'sidebar/material/depthwrite': 'Depth Write',
 			'sidebar/material/wireframe': 'Wireframe',
 			'sidebar/material/userdata': 'User data',
+			'sidebar/material/export': 'Export JSON',
 
 			'sidebar/script': 'Script',
 			'sidebar/script/new': 'New',
@@ -360,9 +360,6 @@ function Strings( config ) {
 			'menubar/file': 'Fichier',
 			'menubar/file/new': 'Nouveau',
 			'menubar/file/import': 'Importer',
-			'menubar/file/export/geometry': 'Exporter Geometrie',
-			'menubar/file/export/object': 'Exporter Objet',
-			'menubar/file/export/scene': 'Exporter Scene',
 			'menubar/file/export/drc': 'Exporter DRC',
 			'menubar/file/export/glb': 'Exporter GLB',
 			'menubar/file/export/gltf': 'Exporter GLTF',
@@ -475,6 +472,7 @@ function Strings( config ) {
 			'sidebar/object/frustumcull': 'Culling',
 			'sidebar/object/renderorder': 'Ordre de rendus',
 			'sidebar/object/userdata': 'Données utilisateur',
+			'sidebar/object/export': 'Exporter JSON',
 
 			'sidebar/geometry/type': 'Type',
 			'sidebar/geometry/new': 'Nouveau',
@@ -485,6 +483,7 @@ function Strings( config ) {
 			'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
 			'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
 			'sidebar/geometry/center': 'Center',
+			'sidebar/geometry/export': 'Exporter JSON',
 
 			'sidebar/geometry/box_geometry/width': 'Largeur',
 			'sidebar/geometry/box_geometry/height': 'Hauteur',
@@ -653,6 +652,7 @@ function Strings( config ) {
 			'sidebar/material/depthwrite': 'Depth Write',
 			'sidebar/material/wireframe': 'Fil de fer',
 			'sidebar/material/userdata': 'Données utilisateur',
+			'sidebar/material/export': 'Exporter JSON',
 
 			'sidebar/script': 'Script',
 			'sidebar/script/new': 'Nouveau',
@@ -709,9 +709,6 @@ function Strings( config ) {
 			'menubar/file': '文件',
 			'menubar/file/new': '新建',
 			'menubar/file/import': '导入',
-			'menubar/file/export/geometry': '导出几何体',
-			'menubar/file/export/object': '导出物体',
-			'menubar/file/export/scene': '导出场景',
 			'menubar/file/export/drc': '导出DRC',
 			'menubar/file/export/glb': '导出GLB',
 			'menubar/file/export/gltf': '导出GLTF',
@@ -824,6 +821,7 @@ function Strings( config ) {
 			'sidebar/object/frustumcull': '视锥体裁剪',
 			'sidebar/object/renderorder': '渲染次序',
 			'sidebar/object/userdata': '自定义数据',
+			'sidebar/object/export': '导出JSON',
 
 			'sidebar/geometry/type': '类型',
 			'sidebar/geometry/new': '更新',
@@ -834,6 +832,7 @@ function Strings( config ) {
 			'sidebar/geometry/compute_vertex_normals': '计算顶点法线',
 			'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
 			'sidebar/geometry/center': '居中',
+			'sidebar/geometry/export': '导出JSON',
 
 			'sidebar/geometry/box_geometry/width': '宽度',
 			'sidebar/geometry/box_geometry/height': '高度',
@@ -1002,6 +1001,7 @@ function Strings( config ) {
 			'sidebar/material/depthwrite': '深度缓冲',
 			'sidebar/material/wireframe': '线框',
 			'sidebar/material/userdata': '自定义数据',
+			'sidebar/material/export': '导出JSON',
 
 			'sidebar/script': '脚本',
 			'sidebar/script/new': '新建',