Beispiel #1
0
        public void Test_GLB_Export()
        {
            string fileName   = "N43E005.hgt";
            string sourceFile = Path.Combine("TestData", fileName + ".zip");
            bool   fileOk     = File.Exists(sourceFile);

            Assert.True(fileOk, "TestData is missing");

            if (!File.Exists(fileName))
            {
                ZipFile.ExtractToDirectory(sourceFile, ".", true);
            }


            Assert.True(File.Exists(fileName), "Unzip failed.");

            // Pass the full file name
            fileName = Path.GetFullPath(fileName);
            using (IRasterFile raster = _rasterService.OpenFile(fileName, DEMFileFormat.SRTM_HGT))
            {
                FileMetadata metaData = raster.ParseMetaData();
                Assert.NotNull(metaData);

                string    str2      = "zsq4";
                HeightMap heightMap = _elevationService.GetHeightMap(metaData)
                                      .ReprojectGeodeticToCartesian()
                                      .ZScale(2.5f);

                MeshPrimitive meshPrimitive = _gltfService.GenerateTriangleMesh(heightMap);
                Model         model         = _gltfService.GenerateModel(meshPrimitive, str2);
                _gltfService.Export(model, ".", str2, false, true);
            }
        }
Beispiel #2
0
        internal void Run(ServiceProvider serviceProvider)
        {
            bool              useTIN           = false; // still buggy with SRID 3857
            int               v_outSrid        = Reprojection.SRID_PROJECTED_MERCATOR;
            IglTFService      glTF             = serviceProvider.GetService <IglTFService>();
            IElevationService elevationService = serviceProvider.GetService <IElevationService>();

            string outputDir = Path.GetFullPath(Path.Combine(_outputDirectory, "glTF"));

            Logger.Info("============================");
            Logger.Info($"= {nameof(TextureSamples)}");
            Logger.Info("============================");
            Logger.Info($"= {nameof(TextureSamples)} : Datadirectory report");


            // Get GPX points
            var bbox = GeometryService.GetBoundingBox(_bboxWkt);

            //=======================
            // Textures
            //
            TextureInfo texInfo = null;


            ImageryService imageryService = new ImageryService();

            Console.WriteLine("Download image tiles...");
            TileRange tiles = imageryService.DownloadTiles(bbox, ImageryProvider.StamenToner, 1);

            Console.WriteLine("Construct texture...");
            string fileName = Path.Combine(outputDir, "Texture.jpg");

            texInfo = imageryService.ConstructTexture(tiles, bbox, fileName, TextureImageFormat.image_jpeg);

            //
            //=======================

            //=======================
            // Normal map
            Console.WriteLine("Height map...");
            float     Z_FACTOR   = 2f;
            HeightMap hMapNormal = elevationService.GetHeightMap(bbox, _normalsDataSet);

            //HeightMap hMapNormal = _elevationService.GetHeightMap(bbox, Path.Combine(_localdatadir, "ETOPO1", "ETOPO1_Bed_g_geotiff.tif"), DEMFileFormat.GEOTIFF);

            hMapNormal = hMapNormal.ReprojectTo(4326, v_outSrid);
            //hMapNormal = hMapNormal.ReprojectGeodeticToCartesian();

            Console.WriteLine("Generate normal map...");
            TextureInfo normal = imageryService.GenerateNormalMap(hMapNormal, outputDir);
            //
            //=======================

            //=======================
            // Get height map
            HeightMap hMap = elevationService.GetHeightMap(bbox, _meshDataSet);
            //HeightMap hMap = _elevationService.GetHeightMap(bbox, Path.Combine(_localdatadir, "ETOPO1","ETOPO1_Bed_g_geotiff.tif"), DEMFileFormat.GEOTIFF);

            //=======================
            // UV mapping (before projection)
            PBRTexture pBRTexture = PBRTexture.Create(texInfo, normal, imageryService.ComputeUVMap(hMap, texInfo));

            hMap = hMap.ReprojectTo(4326, v_outSrid);
            hMap = hMap.CenterOnOrigin().ZScale(Z_FACTOR);


            //=======================


            //=======================
            // MESH 3D terrain

            List <MeshPrimitive> meshes = new List <MeshPrimitive>();
            // generate mesh with texture
            MeshPrimitive triangleMesh;

            if (useTIN)
            {
                Console.WriteLine("Create TIN...");
                //triangleMesh = GenerateTIN(hMapTIN, glTF, pBRTexture);
                triangleMesh = TINGeneration.GenerateTIN(hMap, 10d, glTF, pBRTexture, v_outSrid);
            }
            else
            {
                Console.WriteLine("GenerateTriangleMesh...");
                triangleMesh = glTF.GenerateTriangleMesh_Boxed(hMap);
            }
            meshes.Add(triangleMesh);

            // model export
            Console.WriteLine("GenerateModel...");
            Model model = glTF.GenerateModel(meshes, this.GetType().Name);

            glTF.Export(model, outputDir, $"{GetType().Name} NONormal", false, true);
        }