@@ -7,6 +7,7 @@ import { broadcast, mainWindow } from './window';
77import { ensureRecent } from './app' ;
88import { generateSVG , geoJSONToSvgPaths , parseSVG } from './svg' ;
99import { parseRaw } from './heightmap' ;
10+ import { getHeightMapStats } from './terrain' ;
1011import { layerToMesh , smoothTerrain , svgToCourseLayers } from './workers' ;
1112import { IMAGERY_DIR , PROJECT_FILE_PROTOCOL , TERRAIN_DIR , TREE_IMPORT_PREFIX } from '../constants' ;
1213import { getDateId } from './utils' ;
@@ -156,8 +157,8 @@ export async function saveHeightMap(heightMapData, heightScale) {
156157 // recalculate stats
157158 openProject . stats = { ...openProject . stats , ...getHeightMapStats ( heightMapData , heightScale ) } ;
158159 await saveProjectSettings ( ) ;
159-
160- _heightMapCache = { data : heightMapData , size : heightMapData . byteLength } ;
160+ await refreshRawData ( ) ;
161+ // _heightMapCache = { data: heightMapData, size: heightMapData.byteLength };
161162 return openProject ;
162163}
163164
@@ -308,6 +309,15 @@ export async function loadProjectFile(filePath) {
308309 ...stored ,
309310 holes
310311 } ) ;
312+
313+ // migrate tree configs to have filenames
314+ openProject . trees . forEach ( treeLayer => {
315+ treeLayer . treeConfigs . forEach ( config => {
316+ if ( ! config . name ) {
317+ config . name = path . basename ( config . filePath ) ;
318+ }
319+ } ) ;
320+ } ) ;
311321 // openProject = {
312322 // name: filePathInfo.name,
313323 // _dirty: false,
@@ -489,7 +499,7 @@ export async function generateMeshes(layerSettings, terrainSettings) {
489499 // meshMap.set(layer.id, mesh);
490500 // console.log(`Meshing ${index} of ${result.layers.length} (triangles:${mesh.triangles.length}, points:${mesh.points.length})`);
491501 meshData . meshes . set ( layer . id , { name : layer . name , mesh } ) ;
492- // console.log(`Conformed (${layer.id}) ${index} of ${result.layers .length} (triangles:${mesh.triangles.length}, points:${mesh.points.length})`);
502+ console . log ( `Conformed (${ layer . id } ) ${ index } of ${ openProject . _meshes . length } (triangles:${ mesh . triangles . length } , points:${ mesh . points . length } )` ) ;
493503
494504 progress = ( index / openProject . _meshes . length ) * 100 ;
495505 index ++ ;
@@ -604,32 +614,32 @@ export async function removeTreeConfig(treeLayerId, treeConfigId) {
604614 return openProject ;
605615}
606616
607- export async function postImportTree ( treeLayerId , treeConfigId , billboardData ) {
608- const foundLayer = openProject . trees . find ( tl => tl . id === treeLayerId ) ;
609- const foundConfig = foundLayer . treeConfigs . find ( cfg => cfg . id === treeConfigId ) ;
610- // write file data to disk
611- const imageryFolder = path . join ( openProject . _workingDir , IMAGERY_DIR ) ;
612- // if (!fs.existsSync(imageryFolder)) {
613- // fs.mkdirSync(imageryFolder);
614- // }
615- const billboardFilename = `tree-${ treeConfigId } .png` ;
616- const outputTexture = path . join ( imageryFolder , billboardFilename ) ;
617- let outputData ;
618- if ( typeof billboardData . buffer === 'string' ) {
619- outputData = Buffer . from ( billboardData . buffer . split ( 'base64,' ) [ 1 ] , 'base64' ) ;
620- }
621- if ( outputData ) {
622- console . log ( `Writing file: ${ outputTexture } ` , outputData ) ;
623- await fs . promises . writeFile ( outputTexture , outputData ) ;
624- foundConfig . billboard = {
625- size : billboardData . size ,
626- filePath : outputTexture ,
627- uri : `${ PROJECT_FILE_PROTOCOL } :///${ path . join ( IMAGERY_DIR , billboardFilename ) } `
628- } ;
629- }
630- await saveProjectSettings ( ) ;
631- return openProject . trees ;
632- }
617+ // export async function postImportTree(treeLayerId, treeConfigId, billboardData) {
618+ // const foundLayer = openProject.trees.find(tl => tl.id === treeLayerId);
619+ // const foundConfig = foundLayer.treeConfigs.find(cfg => cfg.id === treeConfigId);
620+ // // write file data to disk
621+ // const imageryFolder = path.join(openProject._workingDir, IMAGERY_DIR);
622+ // // if (!fs.existsSync(imageryFolder)) {
623+ // // fs.mkdirSync(imageryFolder);
624+ // // }
625+ // const billboardFilename = `tree-${treeConfigId}.png`;
626+ // const outputTexture = path.join(imageryFolder, billboardFilename);
627+ // let outputData;
628+ // if (typeof billboardData.buffer === 'string') {
629+ // outputData = Buffer.from(billboardData.buffer.split('base64,')[1], 'base64');
630+ // }
631+ // if (outputData) {
632+ // console.log(`Writing file: ${outputTexture}`, outputData);
633+ // await fs.promises.writeFile(outputTexture, outputData);
634+ // foundConfig.billboard = {
635+ // size: billboardData.size,
636+ // filePath: outputTexture,
637+ // uri: `${PROJECT_FILE_PROTOCOL}:///${path.join(IMAGERY_DIR, billboardFilename)}`
638+ // };
639+ // }
640+ // await saveProjectSettings();
641+ // return openProject.trees;
642+ // }
633643
634644export async function importTree ( treeLayerId ) {
635645 const { canceled, filePaths } = await dialog . showOpenDialog ( {
@@ -643,6 +653,7 @@ export async function importTree(treeLayerId) {
643653 const config = {
644654 url : `${ PROJECT_FILE_PROTOCOL } ://${ TREE_IMPORT_PREFIX } /${ treeConfigId } .glb` ,
645655 filePath : filePaths [ 0 ] ,
656+ name : path . basename ( filePaths [ 0 ] ) ,
646657 id : treeConfigId ,
647658 randomSeed : 12345 ,
648659 scaleRange : { min : 0.6 , max : 1.8 } ,
0 commit comments