Exemplo n.º 1
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);
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
0
        public void CreateGlbWithWrongNumberOfColorsGivesArgumentOfRangeException()
        {
            // 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();

            // accidentally remove 1:
            metallicRoughness.BaseColors.RemoveAt(metallicRoughness.BaseColors.Count - 1);

            var specularGlosiness = new PbrSpecularGlossinessColors();

            specularGlosiness.DiffuseColors = metallicRoughness.BaseColors;

            shaderColors.PbrMetallicRoughnessColors  = metallicRoughness;
            shaderColors.PbrSpecularGlossinessColors = specularGlosiness;

            // act
            try {
                var triangles = Triangulator.GetTriangles(polyhedralsurface, 100, shaderColors);
            }
            catch (Exception ex) {
                // assert
                Assert.IsTrue(ex != null);
                Assert.IsTrue(ex is ArgumentOutOfRangeException);
                Assert.IsTrue(ex.Message.Contains("Diffuse, BaseColor"));
            }
        }