Skip to content

Commit f3fcec6

Browse files
fix: bug fixes and start custom data
1 parent 149d446 commit f3fcec6

16 files changed

Lines changed: 238 additions & 61 deletions

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,11 @@ npm run generate-tree -- \
6868
/path/to/tree/Oak_LOD2.obj \
6969
/path/to/tree/Oak_LOD3.obj \
7070
/path/to/tree/OakTree.glb
71+
```
72+
73+
74+
## Debug Logs
75+
76+
```powershell
77+
Get-Content "$env:USERPROFILE\AppData\Roaming\ogs-meshery\logs\main.log" -Wait -Tail 30
7178
```

src/contexts/Project.jsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const ProjectContext = createContext({
1111
// setProject: () => {},
1212
generateHillShade: () => {},
1313
generateSatellite: () => {},
14+
generateTerrainData: () => {},
1415
setProjectSettings: () => {},
1516
updateSceneSettings: () => {},
1617
addHole: () => {},
@@ -219,6 +220,12 @@ export const ProjectProvider = ({ children }) => {
219220
setProject((old) => ({ ...old, stats: res.stats, raw: res.raw }))
220221
}
221222
}
223+
const generateTerrainData = async (terrainType) => {
224+
const res = await window.meshery.terrain.generate(terrainType);
225+
if (res) {
226+
setProject((old) => ({ ...old, stats: res.stats, raw: res.raw }))
227+
}
228+
}
222229

223230
const updateLayerById = (layerId, update) => {
224231
return window.meshery.project.updateLayerById(layerId, update);
@@ -300,6 +307,7 @@ export const ProjectProvider = ({ children }) => {
300307
handleDownloadCourse,
301308
generateHillShade,
302309
generateSatellite,
310+
generateTerrainData,
303311
palette,
304312
updateLayerById,
305313
generateMeshes,

src/dialogs/EditTerrainDialog.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,9 @@ export default function EditTerrainDialog(props) {
720720
}}
721721
>
722722
<MenuItem value={''}>None</MenuItem>
723-
{project._svgBuffer ? (
723+
{/* {project._svgBuffer ? (
724724
<MenuItem value='svg'>Course SVG</MenuItem>
725-
) : null}
725+
) : null} */}
726726
{Object.values(project.satellite).map(sat => {
727727
return (<MenuItem key={sat.uri} value={sat.uri}>Satellite ({sat.source})</MenuItem>);
728728
})}

src/dialogs/GenerateSVGDialog.jsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,20 @@ export default function SearchShapesDialog(props) {
5656

5757
const handleSave = useCallback(async () => {
5858
console.log('save it', results);
59-
const file = await window.meshery.project.saveSVG({ paths: results.paths, included });
59+
const file = await window.meshery.project.saveSVG({ paths: results?.paths, included });
6060
if (props.onSave) {
6161
props.onSave();
6262
}
6363
}, [results, included]);
6464

65+
useEffect(() => {
66+
setIncluded(old => ({
67+
...old,
68+
hillShade: !!project?.hillShade,
69+
satellite: hasSatellite
70+
}));
71+
}, [hasSatellite, project?.hillShade])
72+
6573
useEffect(() => {
6674
if (!props.open || !project.settings.centerPoint || !project.settings.distance) {
6775
return;

src/dialogs/GenerateTerrainDialog.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
import React from 'react';
1+
import React, { useCallback, useState } from 'react';
22
import { Dialog, DialogTitle, DialogContent, Typography, DialogActions, Button, Alert, Stack, Box, TextField, MenuItem } from '@mui/material';
33
import MenuBookIcon from '@mui/icons-material/MenuBook';
44
import ClearIcon from '@mui/icons-material/Clear';
5+
import { useProject } from '../contexts/Project';
56

67
export default function GenerateTerrainDialog(props) {
78
const { onClose, open } = props;
9+
const { generateTerrainData } = useProject();
10+
const [terrainType, setTerrainType] = useState('flat');
811

912
const handleClose = () => {
1013
onClose();
1114
};
12-
const handleGenerate = async () => {
13-
await window.meshery.terrain.generate('flat');
15+
const handleGenerate = useCallback(async () => {
16+
// await window.meshery.terrain.generate(terrainType);
17+
await generateTerrainData(terrainType);
1418
onClose();
15-
};
19+
}, [terrainType]);
1620

1721
return (
1822
<Dialog
@@ -29,8 +33,9 @@ export default function GenerateTerrainDialog(props) {
2933
<TextField
3034
label="Generate"
3135
select={true}
36+
onChange={(event) => setTerrainType(event.target.value)}
3237
fullWidth={true}
33-
defaultValue={'flat'}
38+
value={terrainType}
3439
>
3540
<MenuItem value="flat">Flat</MenuItem>
3641
<MenuItem value="random">Random</MenuItem>

src/fuse/CourseScene.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ export default function CourseScene({
305305
const meshes = surfacesRef.current.map(s => s.mesh);
306306
const hits = raycasterRef.current.intersectObjects(meshes, false);
307307
if (hits.length > 0) {
308-
const layer = project._meshes.find(l => l.id === hits[0].object.name);
308+
const layer = project._meshes?.find(l => l.id === hits[0].object.name);
309309
if (onSelect) onSelect(layer);
310310

311311
const bbox = new THREE.Box3().setFromObject(hits[0].object);

src/hooks/useCompositeTexture.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,36 @@ export default function useCompositeTexture(baseUrl, overlayUrl, overlayOpacity
1515
const [texture, setTexture] = useState(null);
1616

1717
useEffect(() => {
18-
if (!baseUrl) {
19-
setTexture(null);
20-
return;
21-
}
18+
// if (!baseUrl) {
19+
// setTexture(null);
20+
// return;
21+
// }
2222

2323
let cancelled = false;
2424

2525
async function composite() {
26-
let resolvedBase = baseUrl;
27-
if (resolvedBase.includes('hillshade')) {
28-
resolvedBase = resolvedBase.replace('.tif', '.jpg');
29-
}
30-
31-
const baseImg = await loadImage(resolvedBase);
26+
let baseImg;
3227
const canvas = document.createElement('canvas');
33-
canvas.width = baseImg.naturalWidth;
34-
canvas.height = baseImg.naturalHeight;
28+
if (baseUrl) {
29+
let resolvedBase = baseUrl;
30+
if (resolvedBase.includes('hillshade')) {
31+
resolvedBase = resolvedBase.replace('.tif', '.jpg');
32+
}
33+
baseImg = await loadImage(resolvedBase);
34+
canvas.width = baseImg.naturalWidth;
35+
canvas.height = baseImg.naturalHeight;
36+
} else {
37+
canvas.width = 4096;
38+
canvas.height = 4096;
39+
}
3540
const ctx = canvas.getContext('2d');
3641

37-
ctx.drawImage(baseImg, 0, 0, canvas.width, canvas.height);
42+
if (baseImg) {
43+
ctx.drawImage(baseImg, 0, 0, canvas.width, canvas.height);
44+
} else {
45+
ctx.fillStyle = '#aaa';
46+
ctx.fillRect(0, 0, canvas.width, canvas.height);
47+
}
3848

3949
if (overlayUrl) {
4050
try {

src/lib/app.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ const APP_NAME = 'ogs-meshery';
88
const getDefaultInstallPath = () => {
99
switch (process.platform) {
1010
case 'win32':
11-
return path.join(app.getPath('home'), `.${APP_NAME}`, 'tools');
11+
return path.join(app.getPath('home'), `.${APP_NAME}-tools`);
1212
case 'darwin':
13-
return path.join(app.getPath('home'), APP_NAME, 'tools');
13+
return path.join(app.getPath('home'), `${APP_NAME}-tools`);
1414
case 'linux':
1515
const dataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), '.local', 'share');
16-
return path.join(dataHome, APP_NAME, 'tools');
16+
return path.join(dataHome, `${APP_NAME}-tools`);
1717
default:
1818
throw new Error('Unsupported platform');
1919
}

src/lib/imagery.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,32 @@ async function getElevationRange(tifPath) {
8383
};
8484
}
8585

86+
export async function getGeoTIFFSummary(tifPath) {
87+
const output = await runGDALCommand('gdalinfo', ['-json', tifPath]);
88+
89+
const info = JSON.parse(output.stdout);
90+
91+
const wkt = info.coordinateSystem?.wkt || '';
92+
if (!wkt.trim()) {
93+
throw new Error(`No CRS found in ${tifPath} — cannot build GeoJSON bbox`);
94+
}
95+
96+
if (!info.wgs84Extent) {
97+
throw new Error(`GDAL could not compute WGS84 extent for ${tifPath}`);
98+
}
99+
100+
const bboxGeoJSON = {
101+
type: 'Feature',
102+
properties: {},
103+
geometry: info.wgs84Extent
104+
};
105+
106+
return {
107+
...info,
108+
bboxGeoJSON
109+
};
110+
}
111+
86112
/**
87113
* Convert lat/lon to tile coordinates at a given zoom level
88114
*/

src/lib/ipc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import * as tools from './tools';
77
import * as colors from './colors';
88
import * as plants from './cache/plants';
99
import { exportMeshes } from './export';
10-
import { generateTerrain } from './terrain';
10+
import { generateTerrain, importTerrainData } from './terrain';
1111
import { changeToolsPath, getRecentProjects, getToolsPath } from './app';
1212

1313

@@ -82,6 +82,7 @@ ipcMain.handle('terrain.smoothRivers', (_event, data) => project.smoothRivers(da
8282
ipcMain.handle('terrain.smoothLakes', (_event, data) => project.smoothLakes(data));
8383
ipcMain.handle('terrain.saveHeightMap', (_event, data, heightScale) => project.saveHeightMap(data, heightScale));
8484
ipcMain.handle('terrain.generate', (_event, type) => generateTerrain(type));
85+
ipcMain.handle('terrain.importTerrainData', (_event) => importTerrainData());
8586

8687
ipcMain.handle('mesh.getCourseMesh', (_event) => project.getCourseMesh());
8788
ipcMain.handle('imagery.downloadDEM', (_event, courseBounds) => imagery.downloadCourseDEM(courseBounds));

0 commit comments

Comments
 (0)