Esempio n. 1
0
        public static void CreateGlbForSimpleBuilding()
        {
            // arrange
            var buildingDelawareWkt = "POLYHEDRALSURFACE Z (((1237196.52254261 -4794569.11324542 4006730.36853675,1237205.09930114 -4794565.00723136 4006732.61840877,1237198.22281801 -4794557.02527831 4006744.21497578,1237196.52254261 -4794569.11324542 4006730.36853675)),((1237198.22281801 -4794557.02527831 4006744.21497578,1237189.64607418 -4794561.13128501 4006741.96510802,1237196.52254261 -4794569.11324542 4006730.36853675,1237198.22281801 -4794557.02527831 4006744.21497578)),((1237199.14544946 -4794579.27792655 4006738.92021596,1237207.72222617 -4794575.17190377 4006741.17009276,1237200.84572844 -4794567.18993371 4006752.76668446,1237199.14544946 -4794579.27792655 4006738.92021596)),((1237200.84572844 -4794567.18993371 4006752.76668446,1237192.26896643 -4794571.29594914 4006750.51681191,1237199.14544946 -4794579.27792655 4006738.92021596,1237200.84572844 -4794567.18993371 4006752.76668446)),((1237205.09930114 -4794565.00723136 4006732.61840877,1237196.52254261 -4794569.11324542 4006730.36853675,1237207.72222617 -4794575.17190377 4006741.17009276,1237205.09930114 -4794565.00723136 4006732.61840877)),((1237207.72222617 -4794575.17190377 4006741.17009276,1237199.14544946 -4794579.27792655 4006738.92021596,1237196.52254261 -4794569.11324542 4006730.36853675,1237207.72222617 -4794575.17190377 4006741.17009276)),((1237196.52254261 -4794569.11324542 4006730.36853675,1237189.64607418 -4794561.13128501 4006741.96510802,1237199.14544946 -4794579.27792655 4006738.92021596,1237196.52254261 -4794569.11324542 4006730.36853675)),((1237199.14544946 -4794579.27792655 4006738.92021596,1237192.26896643 -4794571.29594914 4006750.51681191,1237189.64607418 -4794561.13128501 4006741.96510802,1237199.14544946 -4794579.27792655 4006738.92021596)),((1237189.64607418 -4794561.13128501 4006741.96510802,1237198.22281801 -4794557.02527831 4006744.21497578,1237192.26896643 -4794571.29594914 4006750.51681191,1237189.64607418 -4794561.13128501 4006741.96510802)),((1237192.26896643 -4794571.29594914 4006750.51681191,1237200.84572844 -4794567.18993371 4006752.76668446,1237198.22281801 -4794557.02527831 4006744.21497578,1237192.26896643 -4794571.29594914 4006750.51681191)),((1237198.22281801 -4794557.02527831 4006744.21497578,1237205.09930114 -4794565.00723136 4006732.61840877,1237200.84572844 -4794567.18993371 4006752.76668446,1237198.22281801 -4794557.02527831 4006744.21497578)),((1237200.84572844 -4794567.18993371 4006752.76668446,1237207.72222617 -4794575.17190377 4006741.17009276,1237205.09930114 -4794565.00723136 4006732.61840877,1237200.84572844 -4794567.18993371 4006752.76668446)))";
            var colors = new List <string>()
            {
                "#385E0F", "#385E0F", "#FF0000", "#FF0000", "#EEC900", "#EEC900", "#EEC900", "#EEC900", "#EEC900", "#EEC900", "#EEC900", "#EEC900"
            };
            var g = Geometry.Deserialize <WktSerializer>(buildingDelawareWkt);
            var polyhedralsurface = ((PolyhedralSurface)g);
            var center            = polyhedralsurface.GetCenter();

            var shaderColors      = new ShaderColors();
            var metallicRoughness = new PbrMetallicRoughnessColors();

            metallicRoughness.BaseColors = colors;

            var triangles = Triangulator.GetTriangles(polyhedralsurface, 100, shaderColors);

            CheckNormal(triangles[2], center);
            Assert.IsTrue(triangles.Count == 12);

            // act
            var bytes    = GlbCreator.GetGlb(triangles);
            var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "simle_building.glb");

            File.WriteAllBytes(fileName, bytes);

            // assert
        }
Esempio n. 2
0
        public void CreateGlbWithShader()
        {
            // arrange
            var buildingWkb       = File.OpenRead(@"testfixtures/ams_building.wkb");
            var g                 = Geometry.Deserialize <WkbSerializer>(buildingWkb);
            var polyhedralsurface = ((PolyhedralSurface)g);
            var shaderColors      = new ShaderColors();
            var metallicRoughness = new PbrMetallicRoughnessColors();

            metallicRoughness.BaseColors = (from geo in polyhedralsurface.Geometries
                                            let random = new Random()
                                                         let color = string.Format("#{0:X6}", random.Next(0x1000000))
                                                                     select color).ToList();

            shaderColors.PbrMetallicRoughnessColors = metallicRoughness;

            // act
            var triangles = Triangulator.GetTriangles(polyhedralsurface, 100, shaderColors);
            var bytes     = GlbCreator.GetGlb(triangles);
            var fileName  = Path.Combine(TestContext.CurrentContext.WorkDirectory, "ams_building_multiple_colors.glb");

            File.WriteAllBytes(fileName, bytes);

            // assert (each triangle becomes a primitive because colors
            var model = ModelRoot.Load(fileName);

            Assert.AreEqual(triangles.Count, model.LogicalMeshes[0].Primitives.Count);
        }
Esempio n. 3
0
        public void CreateGlbWithDefaultColor()
        {
            // arrange
            var buildingWkb       = File.OpenRead(@"testfixtures/ams_building.wkb");
            var g                 = Geometry.Deserialize <WkbSerializer>(buildingWkb);
            var polyhedralsurface = ((PolyhedralSurface)g);
            var triangles         = Triangulator.GetTriangles(polyhedralsurface, new string[0], 100);
            var bytes             = GlbCreator.GetGlb(triangles);

            File.WriteAllBytes(@"d:\aaa\ams_building_default_color.glb", bytes);
        }
Esempio n. 4
0
        private static void WriteTiles(NpgsqlConnection conn, string geometryTable, string geometryColumn, string idcolumn, double[] translation, Node node, string outputPath, string colorColumn = "", string attributesColumn = "")
        {
            if (node.Features.Count > 0)
            {
                counter++;
                var subset     = (from f in node.Features select(f.Id)).ToArray();
                var geometries = BoundingBoxRepository.GetGeometrySubset(conn, geometryTable, geometryColumn, idcolumn, translation, subset, colorColumn, attributesColumn);

                var triangleCollection = GetTriangles(geometries);

                var bytes        = GlbCreator.GetGlb(triangleCollection);
                var b3dm         = new B3dm.Tile.B3dm(bytes);
                var featureTable = new FeatureTable();
                featureTable.BATCH_LENGTH = geometries.Count;
                b3dm.FeatureTableJson     = JsonConvert.SerializeObject(featureTable);

                if (attributesColumn != string.Empty)
                {
                    var batchtable    = new BatchTable();
                    var allattributes = new List <object>();
                    foreach (var geom in geometries)
                    {
                        // only take the first now....
                        allattributes.Add(geom.Attributes[0]);
                    }

                    var item = new BatchTableItem();
                    item.Name   = attributesColumn;
                    item.Values = allattributes.ToArray();
                    batchtable.BatchTableItems.Add(item);
                    var json = JsonConvert.SerializeObject(batchtable, new BatchTableJsonConverter(typeof(BatchTable)));
                    b3dm.BatchTableJson = json;
                }

                B3dmWriter.WriteB3dm($"{outputPath}/tiles/{node.Id}.b3dm", b3dm);
            }
            // and write children too
            foreach (var subnode in node.Children)
            {
                var perc = Math.Round(((double)counter / Counter.Instance.Count) * 100, 2);
                Console.Write($"\rProgress: tile {counter} - {perc.ToString("F")}%");
                WriteTiles(conn, geometryTable, geometryColumn, idcolumn, translation, subnode, outputPath, colorColumn, attributesColumn);
            }
        }
Esempio n. 5
0
        public void CreateGlbWithSingleColor()
        {
            // arrange
            var buildingWkb       = File.OpenRead(@"testfixtures/ams_building.wkb");
            var g                 = Geometry.Deserialize <WkbSerializer>(buildingWkb);
            var polyhedralsurface = ((PolyhedralSurface)g);
            var triangles         = Triangulator.GetTriangles(polyhedralsurface, 100, null);

            // act
            var bytes    = GlbCreator.GetGlb(triangles);
            var fileName = Path.Combine(TestContext.CurrentContext.WorkDirectory, "ams_building_single_color.glb");

            File.WriteAllBytes(fileName, bytes);

            // assert
            var model = ModelRoot.Load(fileName);

            Assert.AreEqual(1, model.LogicalMeshes[0].Primitives.Count);
        }
Esempio n. 6
0
        public void CreateGlbWithMultipleColors()
        {
            // arrange
            var buildingWkb       = File.OpenRead(@"testfixtures/ams_building.wkb");
            var g                 = Geometry.Deserialize <WkbSerializer>(buildingWkb);
            var polyhedralsurface = ((PolyhedralSurface)g);

            var colors = new List <string>();

            foreach (var geo in polyhedralsurface.Geometries)
            {
                var random = new Random();
                var color  = String.Format("#{0:X6}", random.Next(0x1000000));
                colors.Add(color);
            }

            var triangles = Triangulator.GetTriangles(polyhedralsurface, colors.ToArray(), 100);
            var bytes     = GlbCreator.GetGlb(triangles);

            File.WriteAllBytes(@"d:\aaa\ams_building_multiple_colors.glb", bytes);
        }
Esempio n. 7
0
        private static void WriteTiles(NpgsqlConnection conn, string geometryTable, string geometryColumn, double[] translation, Node node, string outputPath, string colorColumn = "")
        {
            if (node.Features.Count > 0)
            {
                counter++;
                var subset     = (from f in node.Features select(f.Id)).ToArray();
                var geometries = BoundingBoxRepository.GetGeometrySubset(conn, geometryTable, geometryColumn, translation, subset, colorColumn);

                var triangleCollection = Triangulator.GetTriangles(geometries);

                var bytes        = GlbCreator.GetGlb(triangleCollection);
                var b3dm         = new B3dm.Tile.B3dm(bytes);
                var featureTable = new FeatureTable();
                featureTable.BATCH_LENGTH = geometries.Count;
                b3dm.FeatureTableJson     = JsonConvert.SerializeObject(featureTable);

                var batchTable = new BatchTable();

                var r       = new Random();
                var heights = new List <float>();
                for (var i = 0; i < geometries.Count; i++)
                {
                    heights.Add(r.Next(100));
                }
                batchTable.Height   = heights.ToArray();
                b3dm.BatchTableJson = JsonConvert.SerializeObject(batchTable);
                B3dmWriter.WriteB3dm($"{outputPath}/tiles/{node.Id}.b3dm", b3dm);
            }
            // and write children too
            foreach (var subnode in node.Children)
            {
                var perc = Math.Round(((double)counter / Counter.Instance.Count) * 100, 2);
                Console.Write($"\rProgress: tile {counter} - {perc.ToString("F")}%");
                WriteTiles(conn, geometryTable, geometryColumn, translation, subnode, outputPath, colorColumn);
            }
        }