Esempio n. 1
0
        public void WriteBarrelI3dmTest()
        {
            // arrange
            var i3dmExpectedfile = File.OpenRead(@"testfixtures/barrel.i3dm");
            var i3dmExpected     = I3dmReader.Read(i3dmExpectedfile);
            var positions        = i3dmExpected.Positions;

            Assert.IsTrue(positions.Count == 10);
            Assert.IsTrue(i3dmExpected.FeatureTableJson == "{\"INSTANCES_LENGTH\":10,\"POSITION\":{\"byteOffset\":0},\"BATCH_ID\":{\"byteOffset\":120,\"componentType\":\"UNSIGNED_BYTE\"},\"NORMAL_UP\":{\"byteOffset\":132},\"NORMAL_RIGHT\":{\"byteOffset\":252},\"SCALE_NON_UNIFORM\":{\"byteOffset\":372}}       ");

            var result = @"testfixtures/barrel_actual.i3dm";

            I3dmWriter.Write(result, i3dmExpected);

            var i3dmActualStream = File.OpenRead(@"testfixtures/barrel_actual.i3dm");
            var i3dmActual       = I3dmReader.Read(i3dmActualStream);

            // Assert.IsTrue(i3dmExpected.Equals(i3dmActual));
            Assert.IsTrue(i3dmActual.Positions.Count == 10);
            Assert.IsTrue(i3dmActual.FeatureTable.IsEastNorthUp == false);
            Assert.IsTrue(i3dmActual.Positions[0].Equals(i3dmExpected.Positions[0]));
            var stream = new MemoryStream(i3dmActual.GlbData);
            var glb    = SharpGLTF.Schema2.ModelRoot.ReadGLB(stream);

            Assert.IsTrue(glb.Asset.Version.Major == 2.0);
            Assert.IsTrue(glb.Asset.Generator == "obj2gltf");
        }
Esempio n. 2
0
        public void WriteI3dmWithRtcCenterTest()
        {
            var treeGlb   = File.ReadAllBytes(@"testfixtures/tree.glb");
            var pos1      = new Vector3(100, 101, 102);
            var pos2      = new Vector3(200, 201, 202);
            var positions = new List <Vector3>()
            {
                pos1, pos2
            };

            var i3dm = new I3dm.Tile.I3dm(positions, treeGlb);

            i3dm.RtcCenter = new Vector3(100, 100, 100);

            var i3dmBytes = I3dmWriter.Write(i3dm);
            var ms        = new MemoryStream(i3dmBytes);

            var headerValidateErrors = i3dm.I3dmHeader.Validate();

            Assert.IsTrue(headerValidateErrors.Count == 0);

            var i3dmActual = I3dmReader.Read(ms);

            Assert.IsTrue(i3dmActual.RtcCenter.Equals(i3dm.RtcCenter));
        }
Esempio n. 3
0
        public void WriteBarrelI3dmWithBatchIdShortTest()
        {
            // arrange
            var originalFile     = @"testfixtures/barrel.i3dm";
            var i3dmOriginalfile = File.OpenRead(originalFile);

            var i3dmOriginal = I3dmReader.Read(i3dmOriginalfile);

            Assert.IsTrue(i3dmOriginal.I3dmHeader.FeatureTableBinaryByteLength == 496);
            Assert.IsTrue(i3dmOriginal.FeatureTable.BatchIdOffset.componentType == "UNSIGNED_BYTE");
            i3dmOriginal.FeatureTable.BatchIdOffset.componentType = "UNSIGNED_SHORT";
            var result = @"barrel_actual_short.i3dm";

            I3dmWriter.Write(result, i3dmOriginal);

            var headerValidateErrors = i3dmOriginal.I3dmHeader.Validate();

            Assert.IsTrue(headerValidateErrors.Count == 0);

            // assert
            var i3dmActualfile  = File.OpenRead(result);
            var i3dmActualShort = I3dmReader.Read(i3dmActualfile);

            i3dmActualShort.FeatureTable.BatchIdOffset.componentType = "UNSIGNED_SHORT";
        }
Esempio n. 4
0
        public void FirstCmptWriterTest()
        {
            // arrange
            var treeUrlGlb = "https://bertt.github.io/mapbox_3dtiles_samples/samples/instanced/trees_external_gltf/tree.glb";
            var pos1       = new Vector3(100, 101, 102);
            var pos2       = new Vector3(200, 201, 202);
            var positions  = new List <Vector3>()
            {
                pos1, pos2
            };

            var i3dm = new I3dm.Tile.I3dm(positions, treeUrlGlb);

            i3dm.RtcCenter = new Vector3(100, 100, 100);

            var tileBytes = I3dmWriter.Write(i3dm);
            var tiles     = new List <byte[]>();

            tiles.Add(tileBytes);

            // act
            var cmptBytes = CmptWriter.Write(tiles);

            // assert
            Assert.IsTrue(cmptBytes.Length > 0);
        }
Esempio n. 5
0
        public void TestRotations()
        {
            var seatGlb   = File.ReadAllBytes(@"testfixtures/stoel000.glb");
            var positions = new List <Vector3>();

            positions.Add(new Vector3(1214947.2f, -4736379f, 4081540.8f));

            var i3dm = new I3dm.Tile.I3dm(positions, seatGlb);

            i3dm.FeatureTable.IsEastNorthUp = true;

            var rotationsUp    = new List <Vector3>();
            var rotationsRight = new List <Vector3>();

            rotationsUp.Add(new Vector3(0.9686397001928082f, 0.24846957803801f, 0));
            rotationsRight.Add(new Vector3(0.1598520208967612f, -0.6231709121869502f, -0.765575173068789f));
            i3dm.NormalUps    = rotationsUp;
            i3dm.NormalRights = rotationsRight;

            // act
            var bytes = I3dmWriter.Write(i3dm);

            // assert
            Assert.IsTrue(bytes.Length > 0);
        }
Esempio n. 6
0
        public static (byte[] tile, bool isI3dm) GetTile(List <Instance> instances, bool UseExternalModel = false, bool UseRtcCenter = false, bool UseScaleNonUniform = false)
        {
            var firstPosition = (Point)instances[0].Position;

            var uniqueModels = instances.Select(s => s.Model).Distinct();

            var tiles = new List <byte[]>();

            foreach (var model in uniqueModels)
            {
                var positions        = new List <Vector3>();
                var scales           = new List <float>();
                var scalesNonUniform = new List <Vector3>();
                var normalUps        = new List <Vector3>();
                var normalRights     = new List <Vector3>();
                var tags             = new List <JArray>();

                var modelInstances = instances.Where(s => s.Model == model).ToList();
                CalculateArrays(modelInstances, UseRtcCenter, UseScaleNonUniform, positions, scales, scalesNonUniform, normalUps, normalRights, tags, firstPosition);
                var i3dm      = GetI3dm(model, positions, scales, scalesNonUniform, normalUps, normalRights, tags, firstPosition, UseExternalModel, UseRtcCenter, UseScaleNonUniform);
                var bytesI3dm = I3dmWriter.Write(i3dm);
                tiles.Add(bytesI3dm);
            }

            var bytes  = tiles.Count == 1 ? tiles[0] : CmptWriter.Write(tiles);
            var isI3dm = tiles.Count == 1;

            return(bytes, isI3dm);
        }
Esempio n. 7
0
        public void WriteI3dmHelloWorld()
        {
            var treeGlb   = File.ReadAllBytes(@"testfixtures/tree.glb");
            var pos1      = new Vector3(100, 101, 102);
            var pos2      = new Vector3(200, 201, 202);
            var positions = new List <Vector3>()
            {
                pos1, pos2
            };
            var batchIds = new List <int>()
            {
                9, 11
            };

            var i3dm   = new I3dm.Tile.I3dm(positions, treeGlb);
            var result = @"tree_basic.i3dm";

            i3dm.BatchIds = batchIds;
            I3dmWriter.Write(result, i3dm);

            var headerValidateErrors = i3dm.I3dmHeader.Validate();

            Assert.IsTrue(headerValidateErrors.Count == 0);

            var i3dmActualfile = File.OpenRead(result);
            var i3dmActual     = I3dmReader.Read(i3dmActualfile);

            Assert.IsTrue(i3dmActual.Positions.Count == 2);
            Assert.IsTrue(i3dmActual.Positions[0].Equals(pos1));
            Assert.IsTrue(i3dmActual.Positions[1].Equals(pos2));
            Assert.IsTrue(i3dmActual.BatchIds.Count == 2);
            Assert.IsTrue(i3dmActual.BatchIds[0] == 9);
            Assert.IsTrue(i3dmActual.BatchIds[1] == 11);
            Assert.IsTrue(i3dmActual.FeatureTable.BatchIdOffset.componentType == "UNSIGNED_SHORT");
        }
Esempio n. 8
0
        public void WriteI3dmWithRtcCenterTest()
        {
            var treeGlb   = File.ReadAllBytes(@"testfixtures/tree.glb");
            var pos1      = new Vector3(100, 101, 102);
            var pos2      = new Vector3(200, 201, 202);
            var positions = new List <Vector3>()
            {
                pos1, pos2
            };

            var i3dm = new I3dm.Tile.I3dm(positions, treeGlb);

            i3dm.RtcCenter = new Vector3(100, 100, 100);
            var result = @"tree_invalid.i3dm";

            I3dmWriter.Write(result, i3dm);

            var headerValidateErrors = i3dm.I3dmHeader.Validate();

            Assert.IsTrue(headerValidateErrors.Count == 0);

            var i3dmActualfile = File.OpenRead(result);
            var i3dmActual     = I3dmReader.Read(i3dmActualfile);

            Assert.IsTrue(i3dmActual.RtcCenter.Equals(i3dm.RtcCenter));
        }
Esempio n. 9
0
        public void WriteI3dmHelloWorldWithBatchIdType()
        {
            var treeGlb   = File.ReadAllBytes(@"testfixtures/tree.glb");
            var pos1      = new Vector3(100, 101, 102);
            var pos2      = new Vector3(200, 201, 202);
            var positions = new List <Vector3>()
            {
                pos1, pos2
            };
            var batchIds = new List <int>()
            {
                9, 11
            };

            var i3dm = new I3dm.Tile.I3dm(positions, treeGlb);

            var types = new List <string> {
                "UNSIGNED_BYTE", "UNSIGNED_SHORT", "UNSIGNED_INT"
            };

            // write i3dm with every type for batch_id
            foreach (var type in types)
            {
                var result = $"tree_batchid_{type}.i3dm";
                i3dm.BatchIds = batchIds;
                I3dmWriter.Write(result, i3dm, type);

                var headerValidateErrors = i3dm.I3dmHeader.Validate();
                Assert.IsTrue(headerValidateErrors.Count == 0);

                var i3dmActualfile = File.OpenRead(result);
                var i3dmActual     = I3dmReader.Read(i3dmActualfile);
                Assert.IsTrue(i3dmActual.Positions.Count == 2);
                Assert.IsTrue(i3dmActual.Positions[0].Equals(pos1));
                Assert.IsTrue(i3dmActual.Positions[1].Equals(pos2));
                Assert.IsTrue(i3dmActual.BatchIds.Count == 2);
                Assert.IsTrue(i3dmActual.BatchIds[0] == 9);
                Assert.IsTrue(i3dmActual.BatchIds[1] == 11);
                Assert.IsTrue(i3dmActual.FeatureTable.BatchIdOffset.componentType == type);

                var stream = new MemoryStream(i3dmActual.GlbData);
                var glb    = SharpGLTF.Schema2.ModelRoot.ReadGLB(stream);
                Assert.IsTrue(glb.Asset.Version.Major == 2.0);
            }
        }
Esempio n. 10
0
        private void exportTiles(List <I3dmTileInfo> tiles)
        {
            foreach (var tile in tiles)
            {
                var i3dm = new I3dm.Tile.I3dm(tile.Positions, tile.File);

                if (!string.IsNullOrEmpty(tile.BatchTableJson))
                {
                    i3dm.BatchTableJson = tile.BatchTableJson;
                }

                if (!string.IsNullOrEmpty(tile.FeatureTableJson))
                {
                    i3dm.FeatureTableJson = tile.FeatureTableJson;
                }
                if (tile.NormalsUp != null)
                {
                    i3dm.NormalUps = tile.NormalsUp;
                }
                if (tile.NormalsRight != null)
                {
                    i3dm.NormalRights = tile.NormalsRight;
                }
                if (tile.ScaleNonUniforms != null)
                {
                    i3dm.ScaleNonUniforms = tile.ScaleNonUniforms;
                }
                if (tile.Scales != null)
                {
                    i3dm.Scales = tile.Scales;
                }

                var file = (Output == string.Empty ? tile.TileName : Path.Combine(Path.GetDirectoryName(Output), tile.TileName));

                if (File.Exists(file) && !Force)
                {
                    Console.WriteLine($"File {file} already exists. Specify -f or --force to overwrite existing files.");
                }
                else
                {
                    I3dmWriter.Write(file, i3dm);
                    Console.WriteLine("I3dm created " + file);
                }
            }
        }
Esempio n. 11
0
        public void WriteTreeBasicI3dmTest()
        {
            // arrange
            var treeGlb          = File.ReadAllBytes(@"testfixtures/tree.glb");
            var mapbox_positions = new List <Vector3>();

            mapbox_positions.Add(new Vector3(-8407346.9596f, 4743739.3031f, 38.29f));
            mapbox_positions.Add(new Vector3(-8406181.2949f, 4744924.0771f, 38.29f));

            var i3dm = new I3dm.Tile.I3dm(mapbox_positions, treeGlb);

            i3dm.BatchTableJson             = "{\"Height\":[100,101]}";
            i3dm.FeatureTable.IsEastNorthUp = true;
            var result = @"tree.i3dm";

            // act
            I3dmWriter.Write(result, i3dm);
        }
Esempio n. 12
0
        public void WriteI3dmHelloWorldWithScales()
        {
            // arrange
            var treeGlb   = File.ReadAllBytes(@"testfixtures/tree.glb");
            var pos1      = new Vector3(100, 101, 102);
            var pos2      = new Vector3(200, 201, 202);
            var positions = new List <Vector3>()
            {
                pos1, pos2
            };
            var scales = new List <float> {
                2, 3
            };
            var batchIds = new List <int>()
            {
                9, 11
            };

            var i3dm = new I3dm.Tile.I3dm(positions, treeGlb);

            i3dm.BatchIds = batchIds;
            i3dm.Scales   = scales;

            // act
            var bytes = I3dmWriter.Write(i3dm);

            // assert
            var headerValidateErrors = i3dm.I3dmHeader.Validate();

            Assert.IsTrue(headerValidateErrors.Count == 0);

            var i3dmActual = I3dmReader.Read(new MemoryStream(bytes));

            Assert.IsTrue(i3dmActual.Positions.Count == 2);
            Assert.IsTrue(i3dmActual.Positions[0].Equals(pos1));
            Assert.IsTrue(i3dmActual.Positions[1].Equals(pos2));
            Assert.IsTrue(i3dmActual.BatchIds.Count == 2);
            Assert.IsTrue(i3dmActual.BatchIds[0] == 9);
            Assert.IsTrue(i3dmActual.BatchIds[1] == 11);
            Assert.IsTrue(i3dmActual.FeatureTable.BatchIdOffset.componentType == "UNSIGNED_SHORT");
            Assert.IsTrue(i3dmActual.Scales[0] == 2);
            Assert.IsTrue(i3dmActual.Scales[1] == 3);
        }
Esempio n. 13
0
        public void WriteToBytesTest()
        {
            // arrange
            var i3dm = GetTestI3dm(treeUrlGlb);

            // act
            var bytes = I3dmWriter.Write(i3dm);

            // assert
            Assert.IsTrue(bytes.Length > 0);

            // and try to recreate i3dm
            var stream    = new MemoryStream(bytes);
            var i3dmRound = I3dmReader.Read(stream);

            // assert again
            Assert.IsTrue(i3dmRound.Positions.Count == 2);
            Assert.IsTrue(i3dmRound.GlbUrl == treeUrlGlb);
        }
Esempio n. 14
0
        public void WriteTreeI3dmTest()
        {
            // arrange
            var i3dmExpectedfile = File.OpenRead(@"testfixtures/tree.i3dm");
            var i3dmExpected     = I3dmReader.Read(i3dmExpectedfile);
            var positions        = i3dmExpected.Positions;

            Assert.IsTrue(positions.Count == 25);

            var treeGlb = File.ReadAllBytes(@"testfixtures/tree.glb");
            var i3dm    = new I3dm.Tile.I3dm(positions, treeGlb);

            i3dm.FeatureTable.IsEastNorthUp = true;
            i3dm.BatchTableJson             = @"{""Height"":[20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20]} ";

            // act
            var result = @"testfixtures/tree_actual.i3dm";

            I3dmWriter.Write(result, i3dm);

            var i3dmActualStream = File.OpenRead(@"testfixtures/tree_actual.i3dm");
            var i3dmActual       = I3dmReader.Read(i3dmActualStream);

            // Assert

            Assert.IsTrue(i3dmActual.I3dmHeader.Version == 1);
            Assert.IsTrue(i3dmActual.I3dmHeader.Magic == "i3dm");
            Assert.IsTrue(i3dmActual.I3dmHeader.GltfFormat == 1);
            Assert.IsTrue(i3dmActual.I3dmHeader.BatchTableJsonByteLength == 88);
            Assert.IsTrue(i3dmActual.I3dmHeader.FeatureTableJsonByteLength == 72);           //
            Assert.IsTrue(i3dmActual.I3dmHeader.FeatureTableBinaryByteLength == 25 * 4 * 3); // note: is 304 in original file?
            Assert.IsTrue(i3dmActual.I3dmHeader.ByteLength == 282064);                       // Note  is: 282072 originally)
            Assert.IsTrue(i3dmActual.I3dmHeader.BatchTableBinaryByteLength == 0);
            Assert.IsTrue(i3dmActual.Positions.Count == 25);
            Assert.IsTrue(i3dmActual.FeatureTable.IsEastNorthUp == true);
            Assert.IsTrue(i3dmActual.Positions[0].Equals(new Vector3(1214947.2f, -4736379f, 4081540.8f)));
            var stream = new MemoryStream(i3dmActual.GlbData);
            var glb    = SharpGLTF.Schema2.ModelRoot.ReadGLB(stream);

            Assert.IsTrue(glb.Asset.Version.Major == 2.0);
            Assert.IsTrue(glb.Asset.Generator == "COLLADA2GLTF");
        }
Esempio n. 15
0
        public void WriteI3dmWithExternalGltfTest()
        {
            // arrange
            var i3dm = GetTestI3dm(treeUrlGlb);

            i3dm.RtcCenter = new Vector3(100, 100, 100);

            // act
            var bytes = I3dmWriter.Write(i3dm);

            // assert
            var headerValidateErrors = i3dm.I3dmHeader.Validate();

            Assert.IsTrue(headerValidateErrors.Count == 0);

            var i3dmActual = I3dmReader.Read(new MemoryStream(bytes));

            Assert.IsTrue(i3dmActual.GlbUrl == treeUrlGlb);
            Assert.IsTrue(i3dmActual.RtcCenter.Equals(i3dm.RtcCenter));
        }
Esempio n. 16
0
        public void WriteBarrelI3dmTest()
        {
            // arrange
            var i3dmExpectedfile = File.OpenRead(@"testfixtures/barrel.i3dm");
            var i3dmExpected     = I3dmReader.Read(i3dmExpectedfile);
            var positions        = i3dmExpected.Positions;

            Assert.IsTrue(positions.Count == 10);
            Assert.IsTrue(i3dmExpected.FeatureTableJson == "{\"INSTANCES_LENGTH\":10,\"POSITION\":{\"byteOffset\":0},\"BATCH_ID\":{\"byteOffset\":120,\"componentType\":\"UNSIGNED_BYTE\"},\"NORMAL_UP\":{\"byteOffset\":132},\"NORMAL_RIGHT\":{\"byteOffset\":252},\"SCALE_NON_UNIFORM\":{\"byteOffset\":372}}       ");

            var barrelGlb = File.ReadAllBytes(@"testfixtures/barrel.glb");
            var i3dm      = new I3dm.Tile.I3dm(positions, barrelGlb);

            i3dm.NormalUps        = i3dmExpected.NormalUps;
            i3dm.NormalRights     = i3dmExpected.NormalRights;
            i3dm.ScaleNonUniforms = i3dmExpected.ScaleNonUniforms;
            i3dm.BatchIdsBytes    = i3dmExpected.BatchIdsBytes;

            i3dm.BatchTableJson = @"{""Height"":[20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20]} ";
            var result = @"testfixtures/barrel_actual.i3dm";

            I3dmWriter.Write(result, i3dm);

            var i3dmActualStream = File.OpenRead(@"testfixtures/barrel_actual.i3dm");
            var i3dmActual       = I3dmReader.Read(i3dmActualStream);

            Assert.IsTrue(i3dmActual.I3dmHeader.Version == 1);
            Assert.IsTrue(i3dmActual.I3dmHeader.Magic == "i3dm");
            Assert.IsTrue(i3dmActual.I3dmHeader.GltfFormat == 1);
            Assert.IsTrue(i3dmActual.I3dmHeader.BatchTableJsonByteLength == 88);
            Assert.IsTrue(i3dmActual.I3dmHeader.FeatureTableBinaryByteLength == 10 * 4 * 3 * 4 + 10); // note: is 304 in original file?
            Assert.IsTrue(i3dmActual.I3dmHeader.BatchTableBinaryByteLength == 0);
            Assert.IsTrue(i3dmActual.Positions.Count == 10);
            Assert.IsTrue(i3dmActual.FeatureTable.IsEastNorthUp == false);
            Assert.IsTrue(i3dmActual.Positions[0].Equals(i3dmExpected.Positions[0]));
            var stream = new MemoryStream(i3dmActual.GlbData);
            var glb    = SharpGLTF.Schema2.ModelRoot.ReadGLB(stream);

            Assert.IsTrue(glb.Asset.Version.Major == 2.0);
            Assert.IsTrue(glb.Asset.Generator == "obj2gltf");
        }
Esempio n. 17
0
        public void MultipleInnertilesCmptWriterTest()
        {
            // arrange
            var treeUrlGlb = "https://bertt.github.io/mapbox_3dtiles_samples/samples/instanced/trees_external_gltf/tree.glb";
            var pos1       = new Vector3(100, 101, 102);
            var pos2       = new Vector3(200, 201, 202);
            var positions  = new List <Vector3>()
            {
                pos1, pos2
            };

            var i3dm = new I3dm.Tile.I3dm(positions, treeUrlGlb);

            i3dm.RtcCenter = new Vector3(100, 100, 100);

            var i3dm1 = new I3dm.Tile.I3dm(positions, treeUrlGlb);

            i3dm1.RtcCenter = new Vector3(200, 200, 200);

            var i3dmBytes = I3dmWriter.Write(i3dm);

            File.WriteAllBytes(@"d:\aaa\i3dmvalid.i3dm", i3dmBytes);

            var i3dm1Bytes = I3dmWriter.Write(i3dm1);

            var tiles = new List <byte[]>();

            tiles.Add(i3dmBytes);
            tiles.Add(i3dm1Bytes);

            // act
            var cmptBytes = CmptWriter.Write(tiles);

            // assert
            Assert.IsTrue(cmptBytes.Length > 0);

            var ms   = new MemoryStream(cmptBytes);
            var cmpt = CmptReader.Read(ms);

            Assert.IsTrue(cmpt.Tiles.Count() == 2);
        }
Esempio n. 18
0
        public void TestArgumentExceptionWhenNot8byteAligned()
        {
            // arrange
            var treeUrlGlb = "https://mymodels/tree.glb";
            var pos1       = new Vector3(100, 101, 102);
            var positions  = new List <Vector3>()
            {
                pos1
            };
            var i3dm      = new I3dm.Tile.I3dm(positions, treeUrlGlb);
            var tiles     = new List <byte[]>();
            var tileBytes = I3dmWriter.Write(i3dm);

            // act
            // make i3dm tile not 8 byte aligned
            var wrongTile = tileBytes.SkipLast(1).ToArray();

            tiles.Add(wrongTile);

            // assert, should throw argumentexception
            Assert.Throws <ArgumentException>(() => CmptWriter.Write(tiles));
        }
Esempio n. 19
0
        private static void Pack(PackOptions options)
        {
            Console.WriteLine($"Action: Pack");
            Console.WriteLine($"Input: {options.Input}");
            var batchTableJsonFile     = Path.GetFileNameWithoutExtension(options.Input) + ".batch.csv";
            var featureTableJsonFile   = Path.GetFileNameWithoutExtension(options.Input) + ".feature.csv";
            var positionsFile          = Path.GetFileNameWithoutExtension(options.Input) + ".positions.csv";
            var normal_upsfile         = (options.Output == string.Empty ? Path.GetFileNameWithoutExtension(options.Input) + ".normal_ups.csv" : options.Output);
            var normal_rightsfile      = (options.Output == string.Empty ? Path.GetFileNameWithoutExtension(options.Input) + ".normal_rights.csv" : options.Output);
            var scale_non_uniformsfile = (options.Output == string.Empty ? Path.GetFileNameWithoutExtension(options.Input) + ".scale_non_uniforms.csv" : options.Output);
            var scalesfile             = (options.Output == string.Empty ? Path.GetFileNameWithoutExtension(options.Input) + ".scales.csv" : options.Output);

            var positions = ReadVectors(positionsFile);

            var i3dm = Uri.IsWellFormedUriString(options.Input, UriKind.Absolute)?
                       new I3dm.Tile.I3dm(positions, options.Input):
                       new I3dm.Tile.I3dm(positions, File.ReadAllBytes(options.Input));

            if (File.Exists(batchTableJsonFile))
            {
                Console.WriteLine($"Input batchtable json file: {batchTableJsonFile}");
                var batchTableJson = File.ReadAllText(batchTableJsonFile);
                i3dm.BatchTableJson = batchTableJson;
            }
            if (File.Exists(featureTableJsonFile))
            {
                Console.WriteLine($"Input featureTable json file: {featureTableJsonFile}");
                var featureTableJson = File.ReadAllText(featureTableJsonFile);
                i3dm.FeatureTableJson = featureTableJson;
            }
            if (File.Exists(normal_upsfile))
            {
                Console.WriteLine($"Input normal_upsfile file: {normal_upsfile}");
                var normal_ups = ReadVectors(normal_upsfile);
                i3dm.NormalUps = normal_ups;
            }
            if (File.Exists(normal_rightsfile))
            {
                Console.WriteLine($"Input normal_rightsfile file: {normal_rightsfile}");
                var normal_rights = ReadVectors(normal_rightsfile);
                i3dm.NormalRights = normal_rights;
            }
            if (File.Exists(scale_non_uniformsfile))
            {
                Console.WriteLine($"Input scale_non_uniforms file: {scale_non_uniformsfile}");
                var scale_non_uniforms = ReadVectors(scale_non_uniformsfile);
                i3dm.ScaleNonUniforms = scale_non_uniforms;
            }
            if (File.Exists(scalesfile))
            {
                Console.WriteLine($"Input scales file: {scalesfile}");
                var scales = ReadFloats(scalesfile);
                i3dm.Scales = scales;
            }

            var i3dmfile = (options.Output == string.Empty ? Path.GetFileNameWithoutExtension(options.Input) + "_new.i3dm" : options.Output);

            if (File.Exists(i3dmfile) && !options.Force)
            {
                Console.WriteLine($"File {i3dmfile} already exists. Specify -f or --force to overwrite existing files.");
            }
            else
            {
                I3dmWriter.Write(i3dmfile, i3dm);
                Console.WriteLine("I3dm created " + i3dmfile);
            }
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
            {
                string tileFolder  = "tiles";
                string geom_column = "geom";
                Console.WriteLine($"Exporting i3dm's from {o.Table}...");
                SqlMapper.AddTypeHandler(new GeometryTypeHandler());
                var glbBytes   = File.ReadAllBytes(o.Model);
                var tilefolder = $"{o.Output}{Path.DirectorySeparatorChar}{tileFolder}";

                if (!Directory.Exists(tilefolder))
                {
                    Directory.CreateDirectory(tilefolder);
                }

                var conn = new NpgsqlConnection(o.ConnectionString);

                var rootBounds = BoundingBoxRepository.GetBoundingBox3DForTable(conn, o.Table, geom_column);
                var tiles      = new List <TileInfo>();

                var xrange = (int)Math.Ceiling(rootBounds.ExtentX() / o.ExtentTile);
                var yrange = (int)Math.Ceiling(rootBounds.ExtentY() / o.ExtentTile);

                var totalTicks = xrange * yrange;
                var options    = new ProgressBarOptions
                {
                    ProgressCharacter   = '-',
                    ProgressBarOnBottom = true
                };
                var pbar = new ProgressBar(totalTicks, "Exporting i3dm tiles...", options);

                for (var x = 0; x < xrange; x++)
                {
                    for (var y = 0; y < yrange; y++)
                    {
                        var from      = new Point(rootBounds.XMin + o.ExtentTile * x, rootBounds.YMin + o.ExtentTile * y);
                        var to        = new Point(rootBounds.XMin + o.ExtentTile * (x + 1), rootBounds.YMin + o.ExtentTile * (y + 1));
                        var instances = BoundingBoxRepository.GetTileInstances(conn, o.Table, from, to);

                        if (instances.Count > 0)
                        {
                            // todo: handle rotations + scale + other instance properties
                            var positions = new List <Vector3>();
                            foreach (var instance in instances)
                            {
                                var p = (Point)instance.Position;
                                positions.Add(new Vector3((float)p.X, (float)p.Y, (float)p.Z));
                            }

                            var i3dm     = new I3dm.Tile.I3dm(positions, glbBytes);
                            var i3dmFile = $"{o.Output}{Path.DirectorySeparatorChar}{tileFolder}{Path.DirectorySeparatorChar}tile_{x}_{y}.i3dm";
                            I3dmWriter.Write(i3dmFile, i3dm);

                            tiles.Add(new TileInfo
                            {
                                Filename = $"{tileFolder}/tile_{x}_{y}.i3dm",
                                Bounds   = new BoundingBox3D((float)from.X, (float)from.Y, 0, (float)to.X, (float)to.Y, 0)
                            });
                        }

                        pbar.Tick();
                    }
                }
                Console.WriteLine();
                Console.WriteLine("Writing tileset.json...");
                WriteJson(o.Output, rootBounds, tiles, o.GeometricErrors);
                Console.WriteLine("\nExport finished!");
            });
        }
Esempio n. 21
0
 public void WriteI3dm()
 {
     var bytes = I3dmWriter.Write(i3dm);
 }