private Vector2[] GetUV(Element element)
        {
            Rect rect = GetUvRect(element);

            var p0 = new Vector2(rect.xMin, rect.yMin);
            var p1 = new Vector2(rect.xMax, rect.yMin);
            var p2 = new Vector2(rect.xMin, rect.yMax);
            var p3 = new Vector2(rect.xMax, rect.yMax);

            // Imagine looking at the front of the cube, the first 4 vertices are arranged like so
            //   2 --- 3
            //   |     |
            //   |     |
            //   0 --- 1
            // then the UV's are mapped as follows
            //    2    3    0    1   Front
            //    6    7   10   11   Back
            //   19   17   16   18   Left
            //   23   21   20   22   Right
            //    4    5    8    9   Top
            //   15   13   12   14   Bottom
            return new[]
            {
                p0, p1, p2, p3,
                p2, p3, p2, p3,
                p0, p1, p0, p1,
                p0, p3, p1, p2,
                p0, p3, p1, p2,
                p0, p3, p1, p2
            };
        }
Esempio n. 2
0
 /// <inheritdoc />
 public void Add(MapStorageType storageType, Element element, Range<int> levelOfDetails)
 {
     CoreLibrary.AddElementToStore(storageType,
         _resolver.Resolve(_stylesheet.Path),
         element, levelOfDetails, message =>
         {
             if (!String.IsNullOrEmpty(message))
                 throw new MapDataException(message);
         });
 }
Esempio n. 3
0
        /// <summary> Adapts element data received from utymap. </summary>
        public void AdaptElement(long id, string[] tags, int tagCount, double[] vertices, int vertexCount, 
            string[] styles, int styleCount)
        {
            var geometry = new GeoCoordinate[vertexCount / 2];
            for (int i = 0; i < vertexCount / 2; i += 2)
                geometry[i / 2] = new GeoCoordinate(vertices[i + 1], vertices[i]);

            Element element = new Element(id, geometry, ReadDict(tags), ReadDict(styles));
            _observer.OnNext(new Union<Element, Mesh>(element));
        }
 private void CompareElements(Element expected, Element actual)
 {
     Assert.AreEqual(expected.Id, actual.Id);
     // geometry
     Assert.AreEqual(expected.Geometry.Length, actual.Geometry.Length);
     for(int i = 0; i < expected.Geometry.Length; ++i)
         Assert.AreEqual(expected.Geometry[i], actual.Geometry[i]);
     // tags
     Assert.AreEqual(expected.Tags.Count, actual.Tags.Count);
     var keys = expected.Tags.Keys.ToArray();
     for (int i = 0; i < keys.Length; ++i)
         Assert.AreEqual(expected.Tags[keys[i]], actual.Tags[keys[i]]);
 }
        public GameObject Build(Tile tile, Element element)
        {
            GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            gameObject.name = GetName(element);

            var transform = gameObject.transform;
            transform.position = tile.Projection.Project(element.Geometry[0], GetMinHeight(element));
            transform.localScale = new Vector3(2, 2, 2);

            gameObject.GetComponent<MeshFilter>().mesh.uv = GetUV(element);
            gameObject.GetComponent<MeshRenderer>().sharedMaterial = GetMaterial(element);

            return gameObject;
        }
Esempio n. 6
0
        public static void AddElementToStore(MapStorageType storageType, string stylePath, Element element, Range<int> levelOfDetails, OnError onError)
        {
            double[] coordinates = new double[element.Geometry.Length*2];
            for (int i = 0; i < element.Geometry.Length; ++i)
            {
                coordinates[i*2] = element.Geometry[i].Latitude;
                coordinates[i*2 + 1] = element.Geometry[i].Longitude;
            }

            string[] tags = new string[element.Tags.Count * 2];
            var tagKeys = element.Tags.Keys.ToArray();
            for (int i = 0; i < tagKeys.Length; ++i)
            {
                tags[i*2] = tagKeys[i];
                tags[i*2 + 1] = element.Tags[tagKeys[i]];
            }

            addToStoreElement(GetStoreKey(storageType), stylePath, element.Id,
                coordinates, coordinates.Length,
                tags, tags.Length,
                levelOfDetails.Minimum, levelOfDetails.Maximum, onError);
        }
        public void CanAddNode()
        {
            var levelOfDetails = new Range<int>(1, 1);
            var node = new Element(7,
                new GeoCoordinate[] { new GeoCoordinate(5, 5) },
                new Dictionary<string, string>() { { "featurecla", "Populated place" } },
                new Dictionary<string, string>());

            _elementEditor.Add(MapStorageType.InMemory, node, levelOfDetails);

            Union<Element, Mesh> result = default(Union<Element, Mesh>);
            _dataLoader
                .Load(new Tile(new QuadKey(1, 0, 1), _stylesheet, _projection))
                .Do(u => result = u)
                .Wait();
            result.Match(
                e => CompareElements(node, e),
                mesh =>
                {
                    throw new ArgumentException();
                });
        }
Esempio n. 8
0
 /// <inheritdoc />
 public void Edit(MapStorageType storageType, Element element, Range<int> levelOfDetails)
 {
     throw new NotImplementedException();
 }
        private Rect GetUvRect(Element element)
        {
            var values = element.Styles["rect"].Split('_');
            if (values.Length != 4)
                throw new InvalidOperationException("Cannot read uv mapping.");

            var textureHeight = float.Parse(element.Styles["height"]);
            var textureWidth = float.Parse(element.Styles["width"]);

            var width = (float)int.Parse(values[2]);
            var height = (float)int.Parse(values[3]);

            var offset = int.Parse(values[1]);
            var x = (float)int.Parse(values[0]);
            var y = Math.Abs((offset + height) - textureHeight);

            var leftBottom = new Vector2(x / textureWidth, y / textureHeight);
            var rightUpper = new Vector2((x + width) / textureWidth, (y + height) / textureHeight);

            return new Rect(leftBottom.x, leftBottom.y, rightUpper.x - leftBottom.x, rightUpper.y - leftBottom.y);
        }
 private string GetName(Element element)
 {
     return String.Format("place:{0}[{1}]", element.Id,
         element.Tags.Aggregate("", (s, t) => s+=String.Format("{0}={1},", t.Key, t.Value)));
 }
 private float GetMinHeight(Element element)
 {
     return element.Styles.ContainsKey("min-height")
         ? float.Parse(element.Styles["min-height"])
         : 0;
 }
 private Material GetMaterial(Element element)
 {
     return _customizationService.GetSharedMaterial("Materials/" + element.Styles["material"]);
 }
Esempio n. 13
0
 /// <inheritdoc />
 public void BuildElement(Tile tile, Element element)
 {
 }
Esempio n. 14
0
 /// <inheritdoc />
 public void BuildElement(Tile tile, Element element)
 {
     if (element.Styles["builders"].Contains("info"))
         _placeElementBuilder.Build(tile, element).transform.parent = tile.GameObject.transform;
 }