예제 #1
0
        public void CanGetMultiplyModelBuilders()
        {
            // ARRANGE
            var stylesheet = MapCssHelper.GetStylesheetFromContent("way[highway] { builders:test1,test2;}\n");
            var way        = MapCssHelper.GetWay(new Dictionary <string, string>()
            {
                { "highway", "yes" }
            }.ToTags());
            var testBulder1 = new Mock <IModelBuilder>();

            testBulder1.SetupGet(b => b.Name).Returns("test1");
            var testBulder2 = new Mock <IModelBuilder>();

            testBulder2.SetupGet(b => b.Name).Returns("test2");
            var testBulder3 = new Mock <IModelBuilder>();

            testBulder3.SetupGet(b => b.Name).Returns("test2");
            var provider = new CustomizationService(new Container())
                           .RegisterBuilder(testBulder1.Object)
                           .RegisterBuilder(testBulder2.Object);
            var rule = stylesheet.GetModelRule(way, ZoomHelper.GetZoomLevel(RenderMode.Scene));

            // ACT
            var builders = rule.GetModelBuilders(provider).ToArray();

            // ASSERT
            Assert.AreEqual(2, builders.Length);
            Assert.AreEqual("test1", builders[0].Name);
            Assert.AreEqual("test2", builders[1].Name);
        }
        public void CanBuildBarrier()
        {
            // ARRANGE
            var points = new List <Vector2d>()
            {
                new Vector2d(0, 0),
                new Vector2d(10, 0),
                new Vector2d(10, 10)
            };
            var way  = CreateWay(points);
            var rule = _stylesheet.GetModelRule(way, ZoomHelper.GetZoomLevel(_tile.RenderMode));

            // ACT
            _barrierModelBuilder.BuildWay(_tile, rule, CreateWay(points));

            // ASSERT
            var meshData = _barrierModelBuilder.MeshData;

            Assert.IsNotNull(meshData);
            Assert.IsNotNull(meshData.GameObject);
            Assert.IsNotNull(meshData.MaterialKey);
            Assert.IsNotNull(meshData.Index);

            Assert.AreEqual(144, meshData.Vertices.Length);
            Assert.AreEqual(144, meshData.Triangles.Length);
            Assert.AreEqual(144, meshData.Colors.Length);

            AssertPoints(points[0], meshData.Vertices[0]);
        }
예제 #3
0
        private void LoadModel(Tile tile, Model model, Func <Rule, IModelBuilder, IGameObject> func)
        {
            var zoomLevel = ZoomHelper.GetZoomLevel(tile.RenderMode);
            var rule      = _stylesheet.GetModelRule(model, zoomLevel);

            if (rule.IsApplicable && ShouldUseBuilder(tile, rule, model))
            {
                try
                {
                    foreach (var modelBuilder in rule.GetModelBuilders(_customizationService))
                    {
                        var gameObject = func(rule, modelBuilder);
                        AttachBehaviours(gameObject, rule, model);
                    }
                }
                catch (Exception ex)
                {
                    Trace.Error(LogCategory, ex, Strings.UnableToLoadModel, model.ToString());
                }
            }
        }
예제 #4
0
        /// <inheritdoc />
        public IObservable <Unit> Load(Tile tile)
        {
            var boundingBox = tile.BoundingBox;
            var zoomLevel   = ZoomHelper.GetZoomLevel(tile.RenderMode);

            var filterElementVisitor = new CompositeElementVisitor(
                new NodeVisitor(tile, _modelLoader, _objectPool),
                new WayVisitor(tile, _modelLoader, _objectPool),
                new RelationVisitor(tile, _modelLoader, _objectPool));

            _elevationProvider.SetNullPoint(tile.RelativeNullPoint);

            // download elevation data if necessary
            if (!_elevationProvider.HasElevation(tile.BoundingBox))
            {
                _elevationProvider.Download(tile.BoundingBox).Wait();
            }

            // prepare tile
            tile.Accept(tile, _modelLoader);

            var subject = new Subject <Unit>();

            _elementSourceProvider
            .Get(tile.BoundingBox)
            .SelectMany(e => e.Get(boundingBox, zoomLevel))
            .ObserveOn(Scheduler.ThreadPool)
            .SubscribeOn(Scheduler.ThreadPool)
            .Subscribe(element => element.Accept(filterElementVisitor),
                       () =>
            {
                tile.Canvas.Accept(tile, _modelLoader);
                subject.OnCompleted();
            });

            return(subject);
        }