@@ -5,6 +5,8 @@ import { randomUUID } from 'crypto';
55import { TREE_MAKER_FILE_PROTOCOL } from '../constants' ;
66import { pathToFileURL } from 'url' ;
77import { exportTreePackage } from '../lib/workers/index' ;
8+ import { PLANT_CACHE } from '../lib/cache/plants' ;
9+ import { cachePlant } from '../lib/app' ;
810
911let treeMakerScope = new Map ( ) ;
1012export let treeWindow ;
@@ -57,26 +59,34 @@ export function createTreeMakerWindow() {
5759 treeWindow . show ( ) ;
5860}
5961
60- ipcMain . handle ( 'treeMaker.export' , async ( event , thumbnailUri ) => {
62+ ipcMain . handle ( 'treeMaker.export' , async ( event , thumbnailUri , plantOptions = { } ) => {
6163 const thumbnailRaw = thumbnailUri . split ( 'base64,' ) ?. [ 1 ] ;
6264 if ( ! thumbnailRaw ?. length ) {
6365 throw new Error ( 'Missing thumbnail data' ) ;
6466 }
6567
66- const result = await dialog . showSaveDialog ( {
67- defaultPath : 'TreePack'
68- // filters: [{ extensions: ['.glb'] }]
69- } ) ;
70- if ( result . canceled || ! result . filePath ?. length ) {
71- return ;
72- }
73- const outputFile = result . filePath ;
68+ // const result = await dialog.showSaveDialog({
69+ // defaultPath: 'TreePack'
70+ // // filters: [{ extensions: ['.glb'] }]
71+ // });
72+ // if (result.canceled || !result.filePath?.length) {
73+ // return;
74+ // }
75+
76+ const treeId = randomUUID ( ) ;
77+ const filename = `custom-${ treeId } .glb` ;
78+ const filenamePNG = `custom-${ treeId } .png` ;
79+ const outputFileGLB = path . join ( PLANT_CACHE , filename ) ;
80+ const outputFilePNG = path . join ( PLANT_CACHE , filenamePNG ) ;
81+
82+
7483 const inputFiles = [ ...treeMakerScope . values ( ) ]
7584 . sort ( ( a , b ) => a . lod < b . lod ? - 1 : 1 )
7685 . map ( tree => tree . path ) ;
7786
78- const outputFileGLB = `${ outputFile } .glb` ;
79- const outputFilePNG = `${ outputFile } .png` ;
87+ // const outputFile = filePath;
88+ // const outputFileGLB = `${outputFile}.glb`;
89+ // const outputFilePNG = `${outputFile}.png`;
8090 console . log ( 'inputFiles' , inputFiles ) ;
8191 console . log ( 'outputFileGLB' , outputFileGLB ) ;
8292 console . log ( 'outputFilePNG' , outputFilePNG ) ;
@@ -86,7 +96,17 @@ ipcMain.handle('treeMaker.export', async (event, thumbnailUri) => {
8696 // can take a while for compressing textures...
8797 await exportTreePackage ( inputFiles , outputFileGLB ) ;
8898
89- shell . showItemInFolder ( outputFileGLB ) ;
99+ cachePlant ( {
100+ id : treeId ,
101+ key : treeId ,
102+ type : 'custom' ,
103+ title : plantOptions . title ?? 'Custom Plant' ,
104+ addedAt : new Date ( ) ,
105+ thumbnail : outputFilePNG ,
106+ filePath : outputFileGLB ,
107+ } ) ;
108+
109+ // shell.showItemInFolder(outputFileGLB);
90110
91111} ) ;
92112
0 commit comments