Skip to content

Commit

Permalink
Editor: Moved Export Geometry/Object/Scene to Sidebar.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdoob committed Feb 16, 2024
1 parent f933950 commit 109c87f
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 115 deletions.
106 changes: 0 additions & 106 deletions editor/js/Menubar.File.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions editor/js/Sidebar.Geometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions editor/js/Sidebar.Material.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
29 changes: 29 additions & 0 deletions editor/js/Sidebar.Object.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

//

Expand Down
18 changes: 9 additions & 9 deletions editor/js/Strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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': '更新',
Expand All @@ -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': '高度',
Expand Down Expand Up @@ -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': '新建',
Expand Down

0 comments on commit 109c87f

Please sign in to comment.