Skip to content

Commit 109c87f

Browse files
committed
Editor: Moved Export Geometry/Object/Scene to Sidebar.
1 parent f933950 commit 109c87f

File tree

5 files changed

+102
-115
lines changed

5 files changed

+102
-115
lines changed

editor/js/Menubar.File.js

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -72,112 +72,6 @@ function MenubarFile( editor ) {
7272

7373
options.add( new UIHorizontalRule() );
7474

75-
// Export Geometry
76-
77-
option = new UIRow();
78-
option.setClass( 'option' );
79-
option.setTextContent( strings.getKey( 'menubar/file/export/geometry' ) );
80-
option.onClick( function () {
81-
82-
const object = editor.selected;
83-
84-
if ( object === null ) {
85-
86-
alert( 'No object selected.' );
87-
return;
88-
89-
}
90-
91-
const geometry = object.geometry;
92-
93-
if ( geometry === undefined ) {
94-
95-
alert( 'The selected object doesn\'t have geometry.' );
96-
return;
97-
98-
}
99-
100-
let output = geometry.toJSON();
101-
102-
try {
103-
104-
output = JSON.stringify( output, null, '\t' );
105-
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
106-
107-
} catch ( e ) {
108-
109-
output = JSON.stringify( output );
110-
111-
}
112-
113-
saveString( output, 'geometry.json' );
114-
115-
} );
116-
options.add( option );
117-
118-
// Export Object
119-
120-
option = new UIRow();
121-
option.setClass( 'option' );
122-
option.setTextContent( strings.getKey( 'menubar/file/export/object' ) );
123-
option.onClick( function () {
124-
125-
const object = editor.selected;
126-
127-
if ( object === null ) {
128-
129-
alert( 'No object selected' );
130-
return;
131-
132-
}
133-
134-
let output = object.toJSON();
135-
136-
try {
137-
138-
output = JSON.stringify( output, null, '\t' );
139-
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
140-
141-
} catch ( e ) {
142-
143-
output = JSON.stringify( output );
144-
145-
}
146-
147-
saveString( output, 'model.json' );
148-
149-
} );
150-
options.add( option );
151-
152-
// Export Scene
153-
154-
option = new UIRow();
155-
option.setClass( 'option' );
156-
option.setTextContent( strings.getKey( 'menubar/file/export/scene' ) );
157-
option.onClick( function () {
158-
159-
let output = editor.scene.toJSON();
160-
161-
try {
162-
163-
output = JSON.stringify( output, null, '\t' );
164-
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
165-
166-
} catch ( e ) {
167-
168-
output = JSON.stringify( output );
169-
170-
}
171-
172-
saveString( output, 'scene.json' );
173-
174-
} );
175-
options.add( option );
176-
177-
//
178-
179-
options.add( new UIHorizontalRule() );
180-
18175
// Export DRC
18276

18377
option = new UIRow();

editor/js/Sidebar.Geometry.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,39 @@ function SidebarGeometry( editor ) {
170170
} );
171171
helpersRow.add( vertexNormalsButton );
172172

173+
// Export JSON
174+
175+
const exportJson = new UIButton( strings.getKey( 'sidebar/geometry/export' ) );
176+
exportJson.setMarginLeft( '90px' );
177+
exportJson.onClick( function () {
178+
179+
const object = editor.selected;
180+
const geometry = object.geometry;
181+
182+
let output = geometry.toJSON();
183+
184+
try {
185+
186+
output = JSON.stringify( output, null, '\t' );
187+
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
188+
189+
} catch ( e ) {
190+
191+
output = JSON.stringify( output );
192+
193+
}
194+
195+
const left = ( screen.width / 2 ) - ( 250 );
196+
const top = ( screen.height / 2 ) - ( 250 );
197+
198+
const url = URL.createObjectURL( new Blob( [ output ], { type: 'text/plain' } ) );
199+
window.open( url, null, `location=no,left=${left},top=${top},width=500,height=500` );
200+
201+
} );
202+
container.add( exportJson );
203+
204+
//
205+
173206
async function build() {
174207

175208
const object = editor.selected;

editor/js/Sidebar.Material.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,37 @@ function SidebarMaterial( editor ) {
413413

414414
container.add( materialUserDataRow );
415415

416+
// Export JSON
417+
418+
const exportJson = new UIButton( strings.getKey( 'sidebar/material/export' ) );
419+
exportJson.setMarginLeft( '90px' );
420+
exportJson.onClick( function () {
421+
422+
const object = editor.selected;
423+
const material = object.material;
424+
425+
let output = material.toJSON();
426+
427+
try {
428+
429+
output = JSON.stringify( output, null, '\t' );
430+
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
431+
432+
} catch ( e ) {
433+
434+
output = JSON.stringify( output );
435+
436+
}
437+
438+
const left = ( screen.width / 2 ) - ( 250 );
439+
const top = ( screen.height / 2 ) - ( 250 );
440+
441+
const url = URL.createObjectURL( new Blob( [ output ], { type: 'text/plain' } ) );
442+
window.open( url, null, `location=no,left=${left},top=${top},width=500,height=500` );
443+
444+
} );
445+
container.add( exportJson );
446+
416447
//
417448

418449
function update() {

editor/js/Sidebar.Object.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,35 @@ function SidebarObject( editor ) {
386386

387387
container.add( objectUserDataRow );
388388

389+
// Export JSON
390+
391+
const exportJson = new UIButton( strings.getKey( 'sidebar/object/export' ) );
392+
exportJson.setMarginLeft( '90px' );
393+
exportJson.onClick( function () {
394+
395+
const object = editor.selected;
396+
397+
let output = object.toJSON();
398+
399+
try {
400+
401+
output = JSON.stringify( output, null, '\t' );
402+
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
403+
404+
} catch ( e ) {
405+
406+
output = JSON.stringify( output );
407+
408+
}
409+
410+
const left = ( screen.width / 2 ) - ( 250 );
411+
const top = ( screen.height / 2 ) - ( 250 );
412+
413+
const url = URL.createObjectURL( new Blob( [ output ], { type: 'text/plain' } ) );
414+
window.open( url, null, `location=no,left=${left},top=${top},width=500,height=500` );
415+
416+
} );
417+
container.add( exportJson );
389418

390419
//
391420

editor/js/Strings.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ function Strings( config ) {
99
'menubar/file': 'File',
1010
'menubar/file/new': 'New',
1111
'menubar/file/import': 'Import',
12-
'menubar/file/export/geometry': 'Export Geometry',
13-
'menubar/file/export/object': 'Export Object',
14-
'menubar/file/export/scene': 'Export Scene',
1512
'menubar/file/export/drc': 'Export DRC',
1613
'menubar/file/export/glb': 'Export GLB',
1714
'menubar/file/export/gltf': 'Export GLTF',
@@ -124,6 +121,7 @@ function Strings( config ) {
124121
'sidebar/object/frustumcull': 'Frustum Cull',
125122
'sidebar/object/renderorder': 'Render Order',
126123
'sidebar/object/userdata': 'User data',
124+
'sidebar/object/export': 'Export JSON',
127125

128126
'sidebar/geometry/type': 'Type',
129127
'sidebar/geometry/new': 'New',
@@ -134,6 +132,7 @@ function Strings( config ) {
134132
'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
135133
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
136134
'sidebar/geometry/center': 'Center',
135+
'sidebar/geometry/export': 'Export JSON',
137136

138137
'sidebar/geometry/box_geometry/width': 'Width',
139138
'sidebar/geometry/box_geometry/height': 'Height',
@@ -304,6 +303,7 @@ function Strings( config ) {
304303
'sidebar/material/depthwrite': 'Depth Write',
305304
'sidebar/material/wireframe': 'Wireframe',
306305
'sidebar/material/userdata': 'User data',
306+
'sidebar/material/export': 'Export JSON',
307307

308308
'sidebar/script': 'Script',
309309
'sidebar/script/new': 'New',
@@ -360,9 +360,6 @@ function Strings( config ) {
360360
'menubar/file': 'Fichier',
361361
'menubar/file/new': 'Nouveau',
362362
'menubar/file/import': 'Importer',
363-
'menubar/file/export/geometry': 'Exporter Geometrie',
364-
'menubar/file/export/object': 'Exporter Objet',
365-
'menubar/file/export/scene': 'Exporter Scene',
366363
'menubar/file/export/drc': 'Exporter DRC',
367364
'menubar/file/export/glb': 'Exporter GLB',
368365
'menubar/file/export/gltf': 'Exporter GLTF',
@@ -475,6 +472,7 @@ function Strings( config ) {
475472
'sidebar/object/frustumcull': 'Culling',
476473
'sidebar/object/renderorder': 'Ordre de rendus',
477474
'sidebar/object/userdata': 'Données utilisateur',
475+
'sidebar/object/export': 'Exporter JSON',
478476

479477
'sidebar/geometry/type': 'Type',
480478
'sidebar/geometry/new': 'Nouveau',
@@ -485,6 +483,7 @@ function Strings( config ) {
485483
'sidebar/geometry/compute_vertex_normals': 'Compute Vertex Normals',
486484
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
487485
'sidebar/geometry/center': 'Center',
486+
'sidebar/geometry/export': 'Exporter JSON',
488487

489488
'sidebar/geometry/box_geometry/width': 'Largeur',
490489
'sidebar/geometry/box_geometry/height': 'Hauteur',
@@ -653,6 +652,7 @@ function Strings( config ) {
653652
'sidebar/material/depthwrite': 'Depth Write',
654653
'sidebar/material/wireframe': 'Fil de fer',
655654
'sidebar/material/userdata': 'Données utilisateur',
655+
'sidebar/material/export': 'Exporter JSON',
656656

657657
'sidebar/script': 'Script',
658658
'sidebar/script/new': 'Nouveau',
@@ -709,9 +709,6 @@ function Strings( config ) {
709709
'menubar/file': '文件',
710710
'menubar/file/new': '新建',
711711
'menubar/file/import': '导入',
712-
'menubar/file/export/geometry': '导出几何体',
713-
'menubar/file/export/object': '导出物体',
714-
'menubar/file/export/scene': '导出场景',
715712
'menubar/file/export/drc': '导出DRC',
716713
'menubar/file/export/glb': '导出GLB',
717714
'menubar/file/export/gltf': '导出GLTF',
@@ -824,6 +821,7 @@ function Strings( config ) {
824821
'sidebar/object/frustumcull': '视锥体裁剪',
825822
'sidebar/object/renderorder': '渲染次序',
826823
'sidebar/object/userdata': '自定义数据',
824+
'sidebar/object/export': '导出JSON',
827825

828826
'sidebar/geometry/type': '类型',
829827
'sidebar/geometry/new': '更新',
@@ -834,6 +832,7 @@ function Strings( config ) {
834832
'sidebar/geometry/compute_vertex_normals': '计算顶点法线',
835833
'sidebar/geometry/compute_vertex_tangents': 'Compute Tangents',
836834
'sidebar/geometry/center': '居中',
835+
'sidebar/geometry/export': '导出JSON',
837836

838837
'sidebar/geometry/box_geometry/width': '宽度',
839838
'sidebar/geometry/box_geometry/height': '高度',
@@ -1002,6 +1001,7 @@ function Strings( config ) {
10021001
'sidebar/material/depthwrite': '深度缓冲',
10031002
'sidebar/material/wireframe': '线框',
10041003
'sidebar/material/userdata': '自定义数据',
1004+
'sidebar/material/export': '导出JSON',
10051005

10061006
'sidebar/script': '脚本',
10071007
'sidebar/script/new': '新建',

0 commit comments

Comments
 (0)