dem-net / DEM.Net

Digital Elevation model library in C#. 3D terrain models, line/point Elevations, intervisibility reports
https://elevationapi.com
Other
300 stars 56 forks source link

transform hgt to glb #58

Closed sui0312feng closed 3 years ago

sui0312feng commented 5 years ago

Describe the bug i use this code ,transform hgt to glb ,the glb file can be loaded by cesium-1.58 ,but it can not display normally,it seem to have no height.

**string str2 = "zsq4";
        string str3 = @"C:\Users\sui03\Desktop\DEM.Net\DEM.Net.xUnit.Test\TestData\N43E005.hgt.zip\N43E005.hgt";
        HGTFile hgtFile = new HGTFile(str3);
        FileMetadata fileMetadata2= hgtFile.ParseMetaData();
        HeightMap heightMap2 = hgtFile.GetHeightMap(fileMetadata2);
        // ILogger <MeshService> loger=LoggerFactor
        MeshService meshService = new MeshService();
        glTFService gltfService = new glTFService(meshService);
        MeshPrimitive meshPrimitive = gltfService.GenerateTriangleMesh(heightMap2);
        Model model = gltfService.GenerateModel(meshPrimitive, str2);
        gltfService.Export(model, @"c:\geotiff_gltf\", str2, false, true);**
xfischer commented 5 years ago

Hi @sui0312feng thanks for reporting this issue. I'll get a look at it and let you know.

xfischer commented 5 years ago

@sui0312feng Your code was ok. You need to reproject the height map to cartesian coordinates :

Native coords units (lon, lat, elevation) are (degrees, degrees, meters) After a call like this : heightMap = heightMap.ReprojectGeodeticToCartesian();

Heightmap coordinates units will be (meters, meters, meters). You can then call ZScale for Z exageration factor.

I have made a test called _Test_GLBExport for you to check. There's also a Sample project

Let me know how you go.

sui0312feng commented 5 years ago

@xfischer I test code that you give to me, it is right ,but the model have flew in the cesium-1.58, is it problem that transform the coords?

image image

sui0312feng commented 5 years ago

@xfischer the test data is WGS84 in your unit.test , is it ?

xfischer commented 5 years ago

Wow this is interesting... ok I understand your problem. Can you share the sample code you used ? When you call ‘ReprojectGeodeticToCartesian’ the model coordinates are in meters, centered to the model box center.

sui0312feng commented 5 years ago

I add code you say : "ReprojectGeodeticToCartesian().ZScale(2.5f)",

string str2 = "zsq4"; string str3 = @"C:\Users\sui03\Desktop\DEM.Net\DEM.Net.xUnit.Test\TestData\N43E005.hgt.zip\N43E005.hgt"; HGTFile hgtFile = new HGTFile(str3); FileMetadata fileMetadata2= hgtFile.ParseMetaData(); HeightMap heightMap2 = hgtFile.GetHeightMap(fileMetadata2).ReprojectGeodeticToCartesian().ZScale(2.5f); // ILogger loger=LoggerFactor MeshService meshService = new MeshService(); glTFService gltfService = new glTFService(meshService); MeshPrimitive meshPrimitive = gltfService.GenerateTriangleMesh(heightMap2); Model model = gltfService.GenerateModel(meshPrimitive, str2); gltfService.Export(model, @"c:\geotiff_gltf\", str2, false, true);

this is code in cesuim-1.58: I use "Cartesian3.fromRadians" to reproject coords to cartesian coordinates. longitude : FileMetadata.StartLon latitude : FileMetadata.StartLat

/*

xfischer commented 5 years ago

@sui0312feng Thanks for taking the time to report this. Cesium can load WGS84 model out of the box (you may not need to reproject at all, the first code you sent was OK). I have tried with Cesium sandbox and I think the orientation XYZ is bad in DEM.net. I'll try to change it. I'm on vacation now, but I'll get back to you next week.

sui0312feng commented 5 years ago

@xfischer I hava updated your latest code ,the result is same!

xfischer commented 5 years ago

Hi @sui0312feng ! Yes it is normal I’m on holidays with poor internet connection. I’ll get back to you as soon as I can.

sui0312feng commented 5 years ago

@xfischer OK , Have a nice vacation!

xfischer commented 4 years ago

Hi @sui0312feng do you finally could get it right ? Sorry for no answering this.