예제 #1
0
 private static void GetHeightData(VectorFeatureUnity feature, ref float minHeight, ref float hf)
 {
     if (feature.Properties.ContainsKey("height"))
     {
         if (float.TryParse(feature.Properties["height"].ToString(), out hf))
         {
             if (feature.Properties.ContainsKey("min_height"))
             {
                 minHeight = float.Parse(feature.Properties["min_height"].ToString());
                 hf       -= minHeight;
             }
         }
     }
     if (feature.Properties.ContainsKey("ele"))
     {
         if (float.TryParse(feature.Properties["ele"].ToString(), out hf))
         {
         }
     }
 }
        public override void Run(VectorFeatureUnity feature, MeshData md)
        {
            if (md.Vertices.Distinct().Count() < 3)
            {
                return;
            }

            var data  = new List <int>();
            var _mesh = new TriangleNet.Mesh();
            var inp   = new InputGeometry(md.Vertices.Count);

            for (int i = 0; i < md.Vertices.Count; i++)
            {
                var v = md.Vertices[i];
                inp.AddPoint(v.x, v.z);
                inp.AddSegment(i, (i + 1) % md.Vertices.Count);
            }
            _mesh.Behavior.Algorithm = TriangulationAlgorithm.SweepLine;
            _mesh.Behavior.Quality   = true;
            _mesh.Triangulate(inp);

            foreach (var tri in _mesh.Triangles)
            {
                data.Add(tri.P1);
                data.Add(tri.P0);
                data.Add(tri.P2);
            }

            if (_mesh.Vertices.Count != md.Vertices.Count)
            {
                md.Vertices.Clear();
                using (var sequenceEnum = _mesh.Vertices.GetEnumerator())
                {
                    while (sequenceEnum.MoveNext())
                    {
                        md.Vertices.Add(new Vector3((float)sequenceEnum.Current.x, 0, (float)sequenceEnum.Current.y));
                    }
                }
            }
            md.Triangles.Add(data);
        }
예제 #3
0
        private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            //go.layer = LayerMask.NameToLayer(_key);
            if (!feature.Points.Any())
            {
                return;
            }

            int selpos = feature.Points[0].Count / 2;
            var met    = Conversions.LatLonToMeters(feature.Points[0][selpos].Lat, feature.Points[0][selpos].Lng);

            if (!tile.Rect.Contains(met, true))
            {
                return;
            }
            if (!feature.Properties.ContainsKey("name"))
            {
                return;
            }

            var go = Instantiate(PoiPrefab);

            go.name = _key + " " + feature.Data.Id.ToString();
            var pos = met.ToVector3xz() - tile.Rect.center.ToVector3xz();

            var rx = (pos.x - tile.Rect.min.x) / tile.Rect.width;
            var ry = 1 - (pos.z - tile.Rect.min.y) / tile.Rect.height;
            var h  = tile.QueryHeightData(rx, ry);

            pos.y += h;
            go.transform.position = pos;
            go.transform.SetParent(parent.transform, false);

            var bd = go.AddComponent <FeatureBehaviour>();

            bd.Init(feature);

            var tm = go.GetComponent <ILabelVisualizationHelper>();

            tm.Initialize(feature.Properties);
        }
예제 #4
0
        public override GameObject Execute(UnityTile tile, VectorFeatureUnity feature, MeshData meshData, GameObject parent = null, string type = "")
        {
            foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
            {
                mod.Run(feature, meshData, tile);
            }

            var go = CreateGameObject(meshData, parent);

            go.name = type + " - " + feature.Data.Id;
            var bd = go.AddComponent <FeatureBehaviour>();

            bd.Init(feature);

            foreach (GameObjectModifier mod in GoModifiers.Where(x => x.Active))
            {
                mod.Run(bd);
            }

            return(go);
        }
예제 #5
0
        private void QueryHeight(VectorFeatureUnity feature, MeshData md, UnityTile tile, out float maxHeight, out float minHeight)
        {
            minHeight = 0.0f;
            maxHeight = 0.0f;

            switch (_options.extrusionType)
            {
            case ExtrusionType.None:
                break;

            case ExtrusionType.PropertyHeight:
            case ExtrusionType.MinHeight:
            case ExtrusionType.MaxHeight:
                if (feature.Properties.ContainsKey(_options.propertyName))
                {
                    maxHeight = Convert.ToSingle(feature.Properties[_options.propertyName]);
                    if (feature.Properties.ContainsKey("min_height"))
                    {
                        minHeight = Convert.ToSingle(feature.Properties["min_height"]);
                        //maxHeight -= minHeight;
                    }
                }
                break;

            case ExtrusionType.RangeHeight:
                if (feature.Properties.ContainsKey(_options.propertyName))
                {
                    var featureHeight = Convert.ToSingle(feature.Properties[_options.propertyName]);
                    maxHeight = Math.Min(Math.Max(_options.minimumHeight, featureHeight), _options.maximumHeight);
                }
                break;

            case ExtrusionType.AbsoluteHeight:
                maxHeight = _options.maximumHeight;
                break;

            default:
                break;
            }
        }
예제 #6
0
        public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
        {
            _uv.Clear();
            _mdVertexCount = md.Vertices.Count;
            _size          = md.TileRect.Size;

            for (int i = 0; i < _mdVertexCount; i++)
            {
                _vert = md.Vertices[i];
                if (UseSatelliteRoof)
                {
                    var fromBottomLeft = new Vector2((float)(((_vert.x + md.PositionInTile.x) / tile.TileScale + _size.x / 2) / _size.x),
                                                     (float)(((_vert.z + md.PositionInTile.z) / tile.TileScale + _size.x / 2) / _size.x));
                    _uv.Add(fromBottomLeft);
                }
                else
                {
                    _uv.Add(new Vector2(_vert.x, _vert.z));
                }
            }
            md.UV[0].AddRange(_uv);
        }
    void DrawRespondingLine(ReadFileSpawnOnMap.Geometry response)
    {
        var meshData = new MeshData();
        var dat      = new List <Vector3>();

        foreach (List <double> point in response.coordinates)
        {
            Debug.Log("Adding ponts ");
            dat.Add(Conversions.GeoToWorldPosition(point[1], point[0], _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
        }

        var feat = new VectorFeatureUnity();

        feat.Points.Add(dat);

        foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
        {
            mod.Run(feat, meshData, _map.WorldRelativeScale);
        }

        CreateGameObject(meshData);
    }
예제 #8
0
 public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
 {
     if (md.Vertices.Count > 0)
     {
         for (int i = 0; i < md.Vertices.Count; i++)
         {
             var h = tile.QueryHeightData((float)((md.Vertices[i].x + tile.Rect.Size.x / 2) / tile.Rect.Size.x), (float)((md.Vertices[i].z + tile.Rect.Size.y / 2) / tile.Rect.Size.y));
             md.Vertices[i] += new Vector3(0, h, 0);
         }
     }
     else
     {
         foreach (var sub in feature.Points)
         {
             for (int i = 0; i < sub.Count; i++)
             {
                 var h = tile.QueryHeightData((float)((sub[i].x + tile.Rect.Size.x / 2) / tile.Rect.Size.x), (float)((sub[i].z + tile.Rect.Size.y / 2) / tile.Rect.Size.y));
                 sub[i] += new Vector3(0, h, 0);
             }
         }
     }
 }
        private void Build(VectorFeatureUnity feature, UnityTile tile, GameObject parent)
        {
            if (!feature.Points.Any())
            {
                return;
            }

            int selpos = feature.Points[0].Count / 2;
            var met    = feature.Points[0][selpos];

            if (Math.Abs(met.x) > Math.Abs(tile.Rect.Size.x) / 2 || Math.Abs(met.y) > Math.Abs(tile.Rect.Size.y) / 2)
            {
                return;
            }
            if (!feature.Properties.ContainsKey("name"))
            {
                return;
            }

            var go = Instantiate(PoiPrefab);

            go.name = _key + " " + feature.Data.Id.ToString();

            var rx = (met.x - tile.Rect.Min.x) / tile.Rect.Size.x;
            var ry = 1 - (met.z - tile.Rect.Min.y) / tile.Rect.Size.y;
            var h  = tile.QueryHeightData((float)rx, (float)ry);

            met.y += h;
            go.transform.position = met;
            go.transform.SetParent(parent.transform, false);

            var bd = go.AddComponent <FeatureBehaviour>();

            bd.Init(feature);

            var tm = go.GetComponent <ILabelVisualizationHelper>();

            tm.Initialize(feature.Properties);
        }
        /// <summary>
        /// Creates a vector feature from lat lon and builds that feature using the modifier stack.
        /// </summary>
        /// <param name="layer">Layer.</param>
        /// <param name="tile">Tile.</param>
        private void BuildFeatureFromLatLon(VectorTileLayer layer, UnityTile tile)
        {
            var coordinates = (SubLayerProperties as PrefabItemOptions).coordinates;

            for (int i = 0; i < coordinates.Length; i++)
            {
                if (String.IsNullOrEmpty(coordinates[i]))
                {
                    return;
                }

                //check if the coordinate is in the tile
                var coordinate       = Conversions.StringToLatLon(coordinates[i]);
                var coordinateTileId = Conversions.LatitudeLongitudeToTileId(
                    coordinate.x, coordinate.y, tile.InitialZoom);

                if (coordinateTileId.Canonical.Equals(tile.CanonicalTileId))
                {
                    //create new vector feature
                    var feature = new VectorFeatureUnity();
                    feature.Properties = new Dictionary <string, object>();
                    feature.Points     = new List <List <Vector3> >();

                    //create submesh for feature
                    var latLonPoint = new List <Vector3>();

                    //add point to submesh, and submesh to feature
                    latLonPoint.Add(Conversions.LatitudeLongitudeToUnityTilePosition(coordinate, tile.InitialZoom, tile.TileScale, layer.Extent).ToVector3xz());
                    feature.Points.Add(latLonPoint);

                    //pass valid feature.Data to modifiers
                    //this data has no relation to the features being drawn
                    feature.Data = layer.GetFeature(0);

                    //pass the feature to the mod stack
                    base.Build(feature, tile, tile.gameObject);
                }
            }
        }
        public override void FeaturePreProcess(VectorFeatureUnity feature)
        {
            int index = -1;

            foreach (var point in _prefabLocations)
            {
                try
                {
                    index++;
                    var coord = Conversions.StringToLatLon(point);
                    if (feature.ContainsLatLon(coord) && (feature.Data.Id != 0))
                    {
                        _featureId[index] = (_featureId[index] == null) ? new List <string>() : _featureId[index];
                        _tempFeatureId    = feature.Data.Id.ToString();
                        _featureId[index].Add(_tempFeatureId.Substring(0, _tempFeatureId.Length - 3));
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }
        }
예제 #12
0
        private string FindSelectorKey(VectorFeatureUnity feature)
        {
            if (string.IsNullOrEmpty(_classificationKey))
            {
                if (feature.Properties.ContainsKey("type"))
                {
                    return(feature.Properties["type"].ToString().ToLowerInvariant());
                }
                else if (feature.Properties.ContainsKey("class"))
                {
                    return(feature.Properties["class"].ToString().ToLowerInvariant());
                }
            }
            else if (feature.Properties.ContainsKey(_classificationKey))
            {
                if (feature.Properties.ContainsKey(_classificationKey))
                {
                    return(feature.Properties[_classificationKey].ToString().ToLowerInvariant());
                }
            }

            return("");
        }
예제 #13
0
    void HandleDirectionsResponse(DirectionsResponse response)
    {
        if (null == response.Routes || response.Routes.Count < 1)
        {
            return;
        }
        //Debug.Log("Run here out");

        var meshData = new MeshData();
        var dat      = new List <Vector3>();

        foreach (var point in response.Routes[0].Geometry)
        {
            dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
        }

        //Debug.Log("Current Bot's Position = " + bots[indexHandle].transform.position.x + ", " + bots[indexHandle].transform.position.y);
        bots[indexHandle].transform.position = dat[0];
        //Debug.Log("After update Bot's Position = " + bots[indexHandle].transform.position.x + ", " + bots[indexHandle].transform.position.y);


        var feat = new VectorFeatureUnity();

        feat.Points.Add(dat);

        bots[indexHandle].GetComponent <BotBehavior>().VectorFeatureUnity = feat;
        bots[indexHandle].GetComponent <BotBehavior>().ReadyToMove        = true;
        bots[indexHandle].GetComponent <BotBehavior>().MovePoints         = dat;

        foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
        {
            mod.Run(feat, meshData, _map.WorldRelativeScale);
        }

        CreateGameObject(meshData);
        indexHandle++;
    }
예제 #14
0
        public override GameObject Execute(UnityTile tile, VectorFeatureUnity feature, MeshData meshData, GameObject parent = null, string type = "")
        {
            base.Execute(tile, feature, meshData, parent, type);

            if (!_cacheVertexCount.ContainsKey(tile))
            {
                _cacheVertexCount.Add(tile, 0);
                _cached.Add(tile, _meshDataPool.GetObject());
                _buildingCount.Add(tile, 0);
            }

            _buildingCount[tile]++;
            _counter = MeshModifiers.Count;
            for (var i = 0; i < _counter; i++)
            {
                if (MeshModifiers[i] != null && MeshModifiers[i].Active)
                {
                    MeshModifiers[i].Run(feature, meshData, tile);
                }
            }

            GameObject go = null;

            //65000 is the vertex limit for meshes, keep stashing it until that
            _counter = meshData.Vertices.Count;
            if (_cacheVertexCount[tile] + _counter < 65000)
            {
                _cacheVertexCount[tile] += _counter;
                _cached[tile].Add(meshData);
            }
            else
            {
                go = End(tile, parent, type);
            }

            return(go);
        }
        /// <summary>
        /// Checks if the feature should be used to spawn a prefab, once per lat/lon
        /// </summary>
        /// <returns><c>true</c>, if the feature should be spawned <c>false</c> otherwise.</returns>
        /// <param name="feature">Feature.</param>
        private bool ShouldSpawnFeature(VectorFeatureUnity feature)
        {
            if (feature == null)
            {
                return(false);
            }

            if (_objects.ContainsKey(feature.Data.Id))
            {
                return(true);
            }

            foreach (var point in _latLonToSpawn)
            {
                var coord = Conversions.StringToLatLon(point);
                if (feature.ContainsLatLon(coord))
                {
                    _latLonToSpawn.Remove(point);
                    return(true);
                }
            }

            return(false);
        }
예제 #16
0
        public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
        {
            if (md.Vertices.Count == 0 || feature == null || feature.Points.Count < 1)
            {
                return;
            }

            var   minHeight = 0f;
            float hf        = _height;

            if (!_forceHeight)
            {
                GetHeightData(feature, tile.TileScale, ref minHeight, ref hf);
            }

            var max = md.Vertices[0].y;
            var min = md.Vertices[0].y;

            if (_flatTops)
            {
                FlattenTops(md, minHeight, ref hf, ref max, ref min);
            }
            else
            {
                for (int i = 0; i < md.Vertices.Count; i++)
                {
                    md.Vertices[i] = new Vector3(md.Vertices[i].x, md.Vertices[i].y + minHeight + hf, md.Vertices[i].z);
                }
            }

            var originalVertexCount = md.Vertices.Count;

            Chamfer(feature, md, tile);

            Sides(feature, md, hf, originalVertexCount);
        }
        /// <summary>
        /// Check the feature against the list of lat/lons in the modifier
        /// </summary>
        /// <returns><c>true</c>, if the feature overlaps with a lat/lon in the modifier <c>false</c> otherwise.</returns>
        /// <param name="feature">Feature.</param>
        public bool ShouldReplaceFeature(VectorFeatureUnity feature)
        {
            int index = -1;

            foreach (var point in _prefabLocations)
            {
                try
                {
                    index++;
                    if (_featureId[index] != null)
                    {
                        foreach (var featureId in _featureId[index])
                        {
                            //preventing spawning of explicitly blocked features
                            foreach (var blockedId in _explicitlyBlockedFeatureIds)
                            {
                                if (feature.Data.Id.ToString() == blockedId)
                                {
                                    return(true);
                                }
                            }

                            if (feature.Data.Id.ToString().StartsWith(featureId, StringComparison.CurrentCulture))
                            {
                                return(true);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }
            return(false);
        }
예제 #18
0
 public virtual GameObject Execute(UnityTile tile, VectorFeatureUnity feature, MeshData meshData, GameObject parent = null, string type = "")
 {
     return(null);
 }
예제 #19
0
        public void Chamfer(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
        {
            if (md.Vertices.Count == 0 || feature.Points.Count < 1)
            {
                return;
            }

            List <Vector3> newVertices = new List <Vector3>();
            List <Vector2> newUV       = new List <Vector2>();

            md.Normals.Clear();
            md.Edges.Clear();
            md.Tangents.Clear();

            for (int t = 0; t < md.Triangles[0].Count; t++)
            {
                md.Triangles[0][t] *= 3;
            }

            var     next = 0; var current = 0; var prev = 0;
            Vector3 v1, v2, n1, n2, pij1, pij2, pjk1, pjk2;
            Vector3 poi, close1, close2;

            var start = 0;

            for (int i = 0; i < feature.Points.Count; i++)
            {
                var count = feature.Points[i].Count;
                var cst   = newVertices.Count;
                for (int j = 0; j < count; j++)
                {
                    if (j == count - 1)
                    {
                        newVertices.Add(newVertices[cst]);
                        newVertices.Add(newVertices[cst + 1]);
                        newVertices.Add(newVertices[cst + 2]);
                        newUV.Add(newUV[cst]);
                        newUV.Add(newUV[cst + 1]);
                        newUV.Add(newUV[cst + 2]);
                        md.Normals.Add(md.Normals[cst]);
                        md.Normals.Add(md.Normals[cst + 1]);
                        md.Normals.Add(md.Normals[cst + 2]);

                        md.Tangents.Add(md.Tangents[cst]);
                        md.Tangents.Add(md.Tangents[cst + 1]);
                        md.Tangents.Add(md.Tangents[cst + 2]);

                        continue;
                    }

                    current = start + j;
                    if (j > 0)
                    {
                        next = start + j - 1;
                    }
                    else
                    {
                        next = start + j - 1 + count - 1;                         //another -1  as last item equals first
                    }
                    prev = start + j + 1;


                    v1 = new Vector3(
                        md.Vertices[current].x - md.Vertices[next].x, 0,
                        md.Vertices[current].z - md.Vertices[next].z);
                    v1.Normalize();
                    v1 *= -_offset;
                    n1  = new Vector3(-v1.z, 0, v1.x);

                    pij1 = new Vector3(
                        (float)(md.Vertices[next].x + n1.x), 0,
                        (float)(md.Vertices[next].z + n1.z));
                    pij2 = new Vector3(
                        (float)(md.Vertices[current].x + n1.x), 0,
                        (float)(md.Vertices[current].z + n1.z));

                    v2 = new Vector3(
                        md.Vertices[prev].x - md.Vertices[current].x, 0,
                        md.Vertices[prev].z - md.Vertices[current].z);

                    v2.Normalize();
                    v2  *= -_offset;
                    n2   = new Vector3(-v2.z, 0, v2.x);
                    pjk1 = new Vector3(
                        (float)(md.Vertices[current].x + n2.x), 0,
                        (float)(md.Vertices[current].z + n2.z));
                    pjk2 = new Vector3(
                        (float)(md.Vertices[prev].x + n2.x), 0,
                        (float)(md.Vertices[prev].z + n2.z));

                    // See where the shifted lines ij and jk intersect.
                    bool lines_intersect, segments_intersect;

                    FindIntersection(pij1, pij2, pjk1, pjk2,
                                     out lines_intersect, out segments_intersect,
                                     out poi, out close1, out close2);

                    var d = Vector3.Distance(poi, pij2);
                    if (d > 10 * _offset)
                    {
                        poi = new Vector3((md.Vertices[current].x + (poi - (-v1 - v2)).normalized.x), 0,
                                          (md.Vertices[current].z + (poi - (-v1 - v2)).normalized.z));
                    }

                    newVertices.Add(new Vector3(poi.x, poi.y + _offset + md.Vertices[current].y, poi.z));
                    newVertices.Add(md.Vertices[current] + v1);
                    newVertices.Add(md.Vertices[current] - v2);

                    md.Normals.Add(Constants.Math.Vector3Up);
                    md.Normals.Add(-n1);
                    md.Normals.Add(-n2);

                    md.Tangents.Add(v1 - v2);
                    md.Tangents.Add(v1 - v2);
                    md.Tangents.Add(v1 - v2);

                    newUV.Add(md.UV[0][current]);
                    newUV.Add(md.UV[0][current]);
                    newUV.Add(md.UV[0][current]);

                    md.Triangles[0].Add(3 * current);
                    md.Triangles[0].Add(3 * current + 1);
                    md.Triangles[0].Add(3 * current + 2);

                    md.Edges.Add(3 * current + 2);
                    md.Edges.Add(3 * current + 1);

                    md.Triangles[0].Add(3 * prev);
                    md.Triangles[0].Add(3 * current + 2);
                    md.Triangles[0].Add(3 * prev + 1);

                    md.Triangles[0].Add(3 * current);
                    md.Triangles[0].Add(3 * current + 2);
                    md.Triangles[0].Add(3 * prev);
                    //Debug.Log(i + " - " + j + " - " + k);
                    md.Edges.Add(3 * prev + 1);
                    md.Edges.Add(3 * current + 2);
                }
                start += count;
            }

            md.Vertices = newVertices;
            md.UV[0]    = newUV;
        }
예제 #20
0
 public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
 {
     _scaledWidth = tile != null ? Width * tile.TileScale : Width;
     ExtureLine(feature, md);
 }
예제 #21
0
        private void ExtureLine(VectorFeatureUnity feature, MeshData md)
        {
            if (feature.Points.Count < 1)
            {
                return;
            }

            foreach (var roadSegment in feature.Points)
            {
                var mdVertexCount    = md.Vertices.Count;
                var roadSegmentCount = roadSegment.Count;
                for (int i = 1; i < roadSegmentCount * 2; i++)
                {
                    md.Edges.Add(mdVertexCount + i);
                    md.Edges.Add(mdVertexCount + i - 1);
                }
                md.Edges.Add(mdVertexCount);
                md.Edges.Add(mdVertexCount + (roadSegmentCount * 2) - 1);

                var     newVerticeList = new Vector3[roadSegmentCount * 2];
                var     newNorms       = new Vector3[roadSegmentCount * 2];
                var     uvList         = new Vector2[roadSegmentCount * 2];
                Vector3 norm;
                var     lastUv = 0f;
                var     p1     = Constants.Math.Vector3Zero;
                var     p2     = Constants.Math.Vector3Zero;
                var     p3     = Constants.Math.Vector3Zero;
                for (int i = 1; i < roadSegmentCount; i++)
                {
                    p1 = roadSegment[i - 1];
                    p2 = roadSegment[i];
                    p3 = p2;
                    if (i + 1 < roadSegmentCount)
                    {
                        p3 = roadSegment[i + 1];
                    }

                    if (i == 1)
                    {
                        norm = GetNormal(p1, p1, p2) * _scaledWidth;                         //road width
                        newVerticeList[0] = (p1 + norm);
                        newVerticeList[roadSegmentCount * 2 - 1] = (p1 - norm);
                        newNorms[0] = Constants.Math.Vector3Up;
                        newNorms[roadSegmentCount * 2 - 1] = Constants.Math.Vector3Up;
                        uvList[0] = new Vector2(0, 0);
                        uvList[roadSegmentCount * 2 - 1] = new Vector2(1, 0);
                    }
                    var dist = Vector3.Distance(p1, p2);
                    lastUv           += dist;
                    norm              = GetNormal(p1, p2, p3) * _scaledWidth;
                    newVerticeList[i] = (p2 + norm);
                    newVerticeList[2 * roadSegmentCount - 1 - i] = (p2 - norm);
                    newNorms[i] = Constants.Math.Vector3Up;
                    newNorms[2 * roadSegmentCount - 1 - i] = Constants.Math.Vector3Up;

                    uvList[i] = new Vector2(0, lastUv);
                    uvList[2 * roadSegmentCount - 1 - i] = new Vector2(1, lastUv);
                }

                md.Vertices.AddRange(newVerticeList);
                md.Normals.AddRange(newNorms);
                md.UV[0].AddRange(uvList);
                var lineTri = new List <int>();
                var n       = roadSegmentCount;

                for (int i = 0; i < n - 1; i++)
                {
                    lineTri.Add(mdVertexCount + i);
                    lineTri.Add(mdVertexCount + i + 1);
                    lineTri.Add(mdVertexCount + 2 * n - 1 - i);

                    lineTri.Add(mdVertexCount + i + 1);
                    lineTri.Add(mdVertexCount + 2 * n - i - 2);
                    lineTri.Add(mdVertexCount + 2 * n - i - 1);
                }

                if (md.Triangles.Count < 1)
                {
                    md.Triangles.Add(new List <int>());
                }
                md.Triangles[0].AddRange(lineTri);
            }
        }
예제 #22
0
        public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
        {
            _secondCounter = feature.Points.Count;
            var            subset = new List <List <Vector3> >(_secondCounter);
            Data           flatData = null;
            List <int>     result = null;
            var            currentIndex = 0;
            int            vertCount = 0, c2 = 0;
            List <int>     triList = null;
            List <Vector3> sub     = null;

            for (int i = 0; i < _secondCounter; i++)
            {
                sub = feature.Points[i];
                //earcut is built to handle one polygon with multiple holes
                //point data can contain multiple polygons though, so we're handling them separately here

                vertCount = md.Vertices.Count;
                if (IsClockwise(sub) && vertCount > 0)
                {
                    flatData = EarcutLibrary.Flatten(subset);
                    result   = EarcutLibrary.Earcut(flatData.Vertices, flatData.Holes, flatData.Dim);
                    c2       = result.Count;
                    if (triList == null)
                    {
                        triList = new List <int>(c2);
                    }
                    else
                    {
                        triList.Capacity = triList.Count + c2;
                    }

                    for (int j = 0; j < c2; j++)
                    {
                        triList.Add(result[j] + currentIndex);
                    }
                    currentIndex = vertCount;
                    subset.Clear();
                }

                subset.Add(sub);

                c2 = sub.Count;
                md.Vertices.Capacity = md.Vertices.Count + c2;
                md.Normals.Capacity  = md.Normals.Count + c2;
                md.Edges.Capacity    = md.Edges.Count + c2 * 2;
                for (int j = 0; j < c2; j++)
                {
                    md.Edges.Add(vertCount + ((j + 1) % c2));
                    md.Edges.Add(vertCount + j);
                    md.Vertices.Add(sub[j]);
                    md.Tangents.Add(Constants.Math.Vector3Forward);
                    md.Normals.Add(Constants.Math.Vector3Up);
                }
            }

            flatData = EarcutLibrary.Flatten(subset);
            result   = EarcutLibrary.Earcut(flatData.Vertices, flatData.Holes, flatData.Dim);
            c2       = result.Count;
            if (triList == null)
            {
                triList = new List <int>(c2);
            }
            else
            {
                triList.Capacity = triList.Count + c2;
            }
            for (int i = 0; i < c2; i++)
            {
                triList.Add(result[i] + currentIndex);
            }

            md.Triangles.Add(triList);
        }
예제 #23
0
 public override void Run(VectorFeatureUnity feature, MeshData md, float scale)
 {
     _scaledWidth = Width * scale;
     ExtureLine(feature, md);
 }
예제 #24
0
        void HandleDirectionsResponse(DirectionsResponse response)
        {
            button2 = GameObject.Find("Route2").GetComponent <Button>();
            if (response.Routes.Count() == 1)
            {
                button2.interactable = false;
            }
            else
            {
                button2.interactable = true;
            }


            if (response == null || null == response.Routes || response.Routes.Count < 1)
            {
                return;
            }

            var meshData = new MeshData();
            var dat      = new List <Vector3>();

            _waypointsOnMap = new List <Vector3>();
            _arMark.Clear();
            if (routeNum == 1)
            {
                if (response.Routes.Count == 1)
                {
                    foreach (var point in response.Routes[0].Geometry)
                    {
                        _arMark.Add(new Vector2d(point.x, point.y));
                        dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
                    }
                    int    timet = (int)response.Routes[0].Duration / 60;
                    double times = (int)response.Routes[0].Duration % 60;
                    duration.text = "time: " + timet.ToString() + " min " + times.ToString() + " sec ";
                }
                else
                {
                    foreach (var point in response.Routes[1].Geometry)
                    {
                        _arMark.Add(new Vector2d(point.x, point.y));
                        dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
                    }
                    int    timet = (int)response.Routes[1].Duration / 60;
                    double times = (int)response.Routes[1].Duration % 60;
                    duration.text = "time: " + timet.ToString() + " min " + times.ToString() + " sec ";
                }
            }
            else
            {
                foreach (var point in response.Routes[0].Geometry)
                {
                    _arMark.Add(new Vector2d(point.x, point.y));
                    dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
                }
                int    timet = (int)response.Routes[0].Duration / 60;
                double times = (int)response.Routes[0].Duration % 60;
                duration.text = "Duration time: " + timet.ToString() + " min " + times.ToString() + " sec ";
            }

            var feat = new VectorFeatureUnity();

            feat.Points.Add(dat);
            _waypointsOnMap = dat;

            foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
            {
                mod.Run(feat, meshData, _map.WorldRelativeScale);
            }

            CreateGameObject(meshData);
        }
예제 #25
0
 public void Initialize(VectorEntity ve)
 {
     VectorEntity = ve;
     Transform    = transform;
     Data         = ve.Feature;
 }
예제 #26
0
        void HandleDirectionsResponse(DirectionsResponse response)
        {
            if (response == null || null == response.Routes || response.Routes.Count < 1)
            {
                return;
            }

            var meshData = new MeshData();
            var dat      = new List <Vector3>();

            foreach (var point in response.Routes[0].Geometry)
            {
                dat.Add(Conversions.GeoToWorldPosition(point.x, point.y, _map.CenterMercator, _map.WorldRelativeScale).ToVector3xz());
            }

            var feat = new VectorFeatureUnity();

            feat.Points.Add(dat);

            foreach (MeshModifier mod in MeshModifiers.Where(x => x.Active))
            {
                mod.Run(feat, meshData, _map.WorldRelativeScale);
            }

            CreateGameObject(meshData);

            //set the duration of the travel;
            duration.data = 0f;
            foreach (var i in response.Routes)
            {
                duration.data += (float)i.Duration;
            }

            duration.data /= 60;
            duration.data -= duration.data % 1;
            duration.data++;

            //set the Arrival time
            arrivalMinute.data = (DateTime.Now.Minute + duration.data) % 60f;

            float tempTime = (DateTime.Now.Minute + duration.data) / 60f;

            if (tempTime > 1)
            {
                tempTime        -= tempTime % 1;
                arrivalHour.data = DateTime.Now.Hour + tempTime;
            }
            else
            {
                arrivalHour.data = DateTime.Now.Hour;
            }


            //set the distance to travel
            foreach (var j in response.Routes)
            {
                distance.data += (float)j.Distance;
            }

            distance.data = distance.data / 1609;
            distance.data = (float)Math.Round(distance.data, 2);
        }
예제 #27
0
        public override void Run(VectorFeatureUnity feature, MeshData md, UnityTile tile = null)
        {
            if (md.Vertices.Count == 0 || feature == null || feature.Points.Count < 1)
            {
                return;
            }

            if (tile != null)
            {
                _scale = tile.TileScale;
            }

            _currentFacade = _options.atlasInfo.Textures[UnityEngine.Random.Range(0, _options.atlasInfo.Textures.Count)];
            //rect is a struct so we're caching this
            _currentTextureRect = _currentFacade.TextureRect;

            //this can be moved to initialize or in an if clause if you're sure all your tiles will be same level/scale
            _scaledFloorHeight      = tile.TileScale * _currentFacade.FloorHeight;
            _scaledFirstFloorHeight = tile.TileScale * _currentFacade.FirstFloorHeight;
            _scaledTopFloorHeight   = tile.TileScale * _currentFacade.TopFloorHeight;

            //read or force height
            float maxHeight = 1, minHeight = 0;

            QueryHeight(feature, md, tile, out maxHeight, out minHeight);
            maxHeight = maxHeight * _options.extrusionScaleFactor * _scale;
            minHeight = minHeight * _options.extrusionScaleFactor * _scale;
            height    = (maxHeight - minHeight);

            GenerateRoofMesh(md, minHeight, maxHeight);

            if (_options.extrusionGeometryType != ExtrusionGeometryType.RoofOnly)
            {
                edgeList.Clear();
                //cuts long edges into smaller ones using PreferredEdgeSectionLength
                CalculateEdgeList(md, tile, _currentFacade.PreferredEdgeSectionLength);

                //limiting section heights, first floor gets priority, then we draw top floor, then mid if we still have space
                firstHeight = Mathf.Min(height, _scaledFirstFloorHeight);
                topHeight   = Mathf.Min(height - firstHeight, _scaledTopFloorHeight);
                midHeight   = Mathf.Max(0, height - (firstHeight + topHeight));

                //we're merging small mid sections to top and small top sections to first floor to avoid really short/compressed floors
                //I think we need this but I'm not sure about implementation. I feel like mid height should be shared by top&bottom for example.
                if (midHeight < _scaledFloorHeight / (_currentFacade.MidFloorCount * 2))
                {
                    topHeight             += midHeight;
                    _scaledTopFloorHeight += midHeight;
                    midHeight              = 0;
                }
                if (topHeight < _scaledTopFloorHeight * 0.66f)                 //0.66 here is just a random number for acceptable stretching
                {
                    firstHeight += topHeight;
                    topHeight    = 0;
                }

                floorCount        = (int)(midHeight / _scaledFloorHeight) + 1;
                scaledFloorHeight = midHeight / floorCount;
                wallTriangles     = new List <int>();

                //this first loop is for columns
                for (int i = 0; i < edgeList.Count - 1; i += 2)
                {
                    v1            = edgeList[i];
                    v2            = edgeList[i + 1];
                    ind           = md.Vertices.Count;
                    wallDirection = (v2 - v1);
                    d             = wallDirection.magnitude;

                    //this part minimizes stretching for narrow columns
                    //if texture has 3 columns, 33% (of preferred edge length) wide walls will get 1 window.
                    //0-33% gets 1 window, 33-66 gets 2, 66-100 gets all three
                    //we're not wrapping/repeating texture as it won't work with atlases
                    columnScaleRatio = Math.Min(1, d / (_currentFacade.PreferredEdgeSectionLength * tile.TileScale));
                    rightOfEdgeUv    = _currentTextureRect.xMin + _currentTextureRect.size.x * Math.Min(1, ((float)(Math.Floor(columnScaleRatio * _currentFacade.ColumnCount) + 1) / _currentFacade.ColumnCount));
                    bottomOfTopUv    = _currentTextureRect.yMax - (_currentTextureRect.size.y * _currentFacade.TopSectionRatio);                  //not doing that scaling thing for y axis and floors yet
                    topOfBottomUv    = _currentTextureRect.yMin + (_currentTextureRect.size.y * _currentFacade.BottomSectionRatio);               // * (Mathf.Max(1, (float)Math.Floor(tby * textureSection.TopSectionFloorCount)) / textureSection.TopSectionFloorCount);

                    wallNormal = new Vector3(-(v1.z - v2.z), 0, (v1.x - v2.x)).normalized;
                    currentY1  = v1.y;
                    currentY2  = v2.y;

                    floorScaleRatio = Math.Min(1, midHeight / _scaledFloorHeight);
                    var midSecHeight    = (_currentTextureRect.height * (1 - _currentFacade.TopSectionRatio - _currentFacade.BottomSectionRatio));
                    var midFittedHeight = midSecHeight * Math.Min(1, ((float)(Math.Floor(floorScaleRatio * _currentFacade.MidFloorCount) + 1) / _currentFacade.MidFloorCount));                     // midHeight < _scaledFloorHeight * 0.66 ? 0.5f : 0.125f;
                    bottomOfMidUv = (_currentTextureRect.yMax - (_currentTextureRect.height * _currentFacade.TopSectionRatio)) - midFittedHeight;
                    topOfMidUv    = _currentTextureRect.yMax - (_currentTextureRect.height * _currentFacade.TopSectionRatio);

                    TopFloor(md);
                    MidFloors(md);
                    FirstFloor(md, height);
                }

                if (_separateSubmesh)
                {
                    md.Triangles.Add(wallTriangles);
                }
                else
                {
                    md.Triangles.Capacity = md.Triangles.Count + wallTriangles.Count;
                    md.Triangles[0].AddRange(wallTriangles);
                }
            }
        }
예제 #28
0
 public virtual bool Try(VectorFeatureUnity feature)
 {
     return(true);
 }
예제 #29
0
 public void Initialize(VectorFeatureUnity feature)
 {
     Transform = transform;
     Data      = feature;
 }
예제 #30
0
 public virtual void FeaturePreProcess(VectorFeatureUnity feature)
 {
 }