Beispiel #1
0
 public glTFTests(DemNetFixture fixture)
 {
     _rasterService    = fixture.ServiceProvider.GetService <IRasterService>();
     _elevationService = fixture.ServiceProvider.GetService <IElevationService>();
     _gltfService      = fixture.ServiceProvider.GetService <IglTFService>();
     _meshService      = fixture.ServiceProvider.GetService <IMeshService>();
 }
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);
        }