コード例 #1
0
ファイル: CmptWriterTests.cs プロジェクト: bertt/cmpt-tile-cs
        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);
        }
コード例 #2
0
ファイル: TileHandler.cs プロジェクト: fnicollet/i3dm.export
        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);
        }
コード例 #3
0
ファイル: CmptWriterTests.cs プロジェクト: bertt/cmpt-tile-cs
        public void TestArgumentExceptionWhenNoInnertiles()
        {
            // arrange
            var tiles = new List <byte[]>();

            // assert, should throw argumentexception
            Assert.Throws <ArgumentException>(() => CmptWriter.Write(tiles));
        }
コード例 #4
0
ファイル: CmptWriterTests.cs プロジェクト: bertt/cmpt-tile-cs
        public void WriteFromInnerTiles()
        {
            // arrange
            var tile0 = File.ReadAllBytes(@"./testfixtures/inner/tile0.i3dm");
            var tile1 = File.ReadAllBytes(@"./testfixtures/inner/tile1.i3dm");

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

            tiles.Add(tile0);
            tiles.Add(tile1);

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

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

            Assert.IsTrue(cmpt.Tiles.Count() == 2);
        }
コード例 #5
0
ファイル: CmptWriterTests.cs プロジェクト: bertt/cmpt-tile-cs
        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);
        }
コード例 #6
0
ファイル: CmptWriterTests.cs プロジェクト: bertt/cmpt-tile-cs
        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));
        }