コード例 #1
0
        void GenerateGeometry(List <List <Vector3> > segments, GameObject container, IDictionary properties, string type)
        {
            string pname = OSMTools.GetProperty(properties, "name");
            // Debug.Log( "Processing:" + pname);
            //List<Vector2> points = new List<Vector2>();

            GameObject go = new GameObject("building");

            go.transform.parent = container.transform;
            go.layer            = LayerMask.NameToLayer("Buildings");
            go.name             = pname;
            //go.transform.position = segments[0][0];
            go.transform.localPosition = Vector3.zero;
            //go.name = properties["kind"].ToString();
            MassiveFeature f = go.AddComponent <MassiveFeature>();

            f.SetProperties(properties);
            f.SetSegments(segments);
            f.SetType(type);
            //if height it not present assume 1 floor
            height = f.height == 0 ? 5 : f.height;

            CreateRoof(segments, go);
            CreateWalls(segments, go);
            MeshTools.MoveGameObjectToTerrain(TileBoundsMeters, this.transform.position, mc, go, Walls.GetComponent <MeshFilter>().sharedMesh);

            //create roof

            //MeshTools.FitMeshToTerrain(TileBoundsMeters, this.transform.position, mc, msh);
            //MeshTools.MoveMeshToTerrain(TileBoundsMeters, this.transform.position, mc, msh, f.height, go);
        }
コード例 #2
0
        public void GenerateWaterJSON(string data, GameObject Container, DVector3 PositionMeters)
        {
            mc = transform.parent.Find("terrain").GetComponent <MeshCollider>();
            TileBoundsMeters = this.transform.parent.GetComponent <MassiveTile>().TileBoundsMeters;
            Container.layer  = LayerMask.NameToLayer("Water");
            sData            = data;
            Data             = (Dictionary <string, object>)MiniJSON.Json.Deserialize(sData);

            IList features = (IList)Data["features"];

            foreach (IDictionary feature in features)
            {
                IDictionary geometry   = (IDictionary)feature["geometry"];
                string      type       = (string)geometry["type"];
                IDictionary properties = (IDictionary)feature["properties"];
                string      kind       = OSMTools.GetProperty(properties, "kind");

                List <List <Vector3> > segments = new List <List <Vector3> >();

                /*
                 * if (type == "LineString")
                 * {
                 * List<DVector3> list = new List<DVector3>();
                 * foreach (IList piece in (IList)geometry["coordinates"])
                 * {
                 *  double dx = (double)piece[0];
                 *  double dz = (double)piece[1];
                 *  DVector3 v = MapFuncs.LatLonToMeters((float)dz, (float)dx);
                 *  v -= PositionMeters;
                 *  list.Add(v);
                 * }
                 * segments.Add(list);
                 * }
                 */

                if (type == "MultiPolygon")
                {
                    IList segs = (IList)geometry["coordinates"];
                    foreach (IList part in segs)
                    {
                        segments = OSMTools.CreateMultiPolygon(part, PositionMeters);
                        GenerateGeometry(segments, Container, properties, type);
                    }
                }
                if (type == "Polygon")
                {
                    IList segs = (IList)geometry["coordinates"];
                    foreach (IList part in segs)
                    {
                        segments = OSMTools.CreatePolygon(part, PositionMeters.ToVector3());
                        GenerateGeometry(segments, Container, properties, type);
                    }
                }

                //Debug.Log(segments);
            }
        }
コード例 #3
0
 public void SetProperties(IDictionary dproperties)
 {
     foreach (string s in dproperties.Keys)
     {
         if (dproperties[s] != null)
         {
             string val = dproperties[s].ToString();
             properties += s + "=" + val + "\n";
         }
     }
     featurename = OSMTools.GetProperty(dproperties, "name");
     kind        = OSMTools.GetProperty(dproperties, "kind");
     kind_detail = OSMTools.GetProperty(dproperties, "kind_detail");
     height      = OSMTools.GetFloatProperty(dproperties, "height");
     is_bridge   = OSMTools.GetBoolProperty(dproperties, "is_bridge");
 }
コード例 #4
0
        public void CreateRoads(string sData, DVector3 PositionMeters)
        {
            TileBoundsMeters = this.transform.parent.GetComponent <MassiveTile>().TileBoundsMeters;
            mc = transform.parent.Find("terrain").GetComponent <MeshCollider>();

            Dictionary <string, object> Data     = (Dictionary <string, object>)MiniJSON.Json.Deserialize(sData);
            List <List <Vector3> >      segments = new List <List <Vector3> >();
            IList features = (IList)Data["features"];

            Roads.Clear();
            foreach (IDictionary feature in features)
            {
                IDictionary geometry   = (IDictionary)feature["geometry"];
                IDictionary properties = (IDictionary)feature["properties"];

                string geotype     = (string)geometry["type"];
                string name        = OSMTools.GetProperty(properties, "name");
                string kind        = OSMTools.GetProperty(properties, "kind");
                string kind_detail = OSMTools.GetProperty(properties, "kind_detail");
                //Debug.Log("Processing:" + name);

                if (geotype == "LineString")
                {
                    Road           rs = new Road(name, this.gameObject, kind, kind_detail);
                    MassiveFeature mf = rs.go.AddComponent <MassiveFeature>();
                    mf.SetProperties(properties);
                    rs.is_bridge = mf.is_bridge;

                    for (int i = 0; i < ((IList)geometry["coordinates"]).Count; i++)
                    {
                        IList   piece = (IList)((IList)geometry["coordinates"])[i];
                        double  dx    = (double)piece[0];
                        double  dz    = (double)piece[1];
                        Vector3 v     = MapTools.LatLonToMeters((float)dz, (float)dx).ToVector3();
                        v -= PositionMeters.ToVector3();
                        Node n = new Node(v, name);
                        rs.nodes.Add(n);
                        if (i == 0)
                        {
                            //rs.go.transform.position = v;
                            rs.go.layer = LayerMask.NameToLayer("Roads");
                        }
                    }
                    Roads.Add(rs);
                }


                if (geotype == "MultiLineString")
                {
                    GameObject go = new GameObject();
                    go.transform.parent = this.transform;
                    MassiveFeature mf = go.AddComponent <MassiveFeature>();
                    mf.SetProperties(properties);

                    for (int i = 0; i < ((IList)geometry["coordinates"]).Count; i++)
                    {
                        Road rs = new Road(name, go, kind, kind_detail);
                        rs.is_bridge = mf.is_bridge;
                        go.name      = name;
                        IList segment = (IList)((IList)geometry["coordinates"])[i];
                        for (int j = 0; j < segment.Count; j++)
                        {
                            IList   piece = (IList)segment[j];
                            double  dx    = (double)piece[0];
                            double  dz    = (double)piece[1];
                            Vector3 v     = MapTools.LatLonToMeters((float)dz, (float)dx).ToVector3();
                            v -= PositionMeters.ToVector3();
                            Node n = new Node(v, name);
                            rs.nodes.Add(n);
                            if ((i == 0) && (j == 0))
                            {
                                //rs.go.transform.position = v;
                                rs.go.layer = LayerMask.NameToLayer("Roads");
                            }
                        }
                        Roads.Add(rs);
                    }
                }
            }
            //calculate intersections
            CalculateIntersections();
            CreateRoadGeometry();
            //VisualizeNodes();
        }
コード例 #5
0
        public void Generate(string sData, DVector3 PositionMeters, string AssetPath)
        {
            mc = transform.parent.Find("terrain").GetComponent <MeshCollider>();
            TileBoundsMeters = this.transform.parent.GetComponent <MassiveTile>().TileBoundsMeters;
            Data             = (Dictionary <string, object>)MiniJSON.Json.Deserialize(sData);

            IList features = (IList)Data["features"];

            foreach (IDictionary feature in features)
            {
                IDictionary geometry = (IDictionary)feature["geometry"];
                string      geotype  = (string)geometry["type"];

                IDictionary properties = (IDictionary)feature["properties"];
                string      kind       = "";
                string      kinddetail = "";
                string      name       = "_";
                string      id         = "";
                name       = OSMTools.GetProperty(properties, "name");
                kind       = OSMTools.GetProperty(properties, "kind");
                kinddetail = OSMTools.GetProperty(properties, "kind_detail");
                id         = OSMTools.GetProperty(properties, "id");

                //if (name == "_") continue;

                if (!CanWeInclude(AllowKinds, kind))
                {
                    continue;
                }


                List <List <Vector3> > segments = new List <List <Vector3> >();

                if (geotype == "LineString" &&
                    CanWeInclude(AllowShapes, "LineString"))
                {
                    List <Vector3> list = new List <Vector3>();
                    foreach (IList piece in (IList)geometry["coordinates"])
                    {
                        double  dx = (double)piece[0];
                        double  dz = (double)piece[1];
                        Vector3 v  = MapTools.LatLonToMeters((float)dz, (float)dx).ToVector3();
                        v -= PositionMeters.ToVector3();
                        list.Add(v);
                    }

                    list = OSMTools.InsertPoints(list, InterpolateRoadMeters);

                    segments.Add(list);
                }

                if (geotype == "MultiLineString" &&
                    CanWeInclude(AllowShapes, "MultiLineString"))
                {
                    foreach (IList piecelist in (IList)geometry["coordinates"])
                    {
                        List <Vector3> list = new List <Vector3>();
                        foreach (IList piece in (IList)piecelist)
                        {
                            double  dx = (double)piece[0];
                            double  dz = (double)piece[1];
                            Vector3 v  = MapTools.LatLonToMeters((float)dz, (float)dx).ToVector3();
                            v -= PositionMeters.ToVector3();
                            list.Add(v);
                        }
                        list = OSMTools.InsertPoints(list, InterpolateRoadMeters);
                        segments.Add(list);
                    }
                }

                if (segments.Count > 0)
                {
                    MeshData md = new MeshData();
                    Run(segments, md, GetWidthForKind(kind));

                    GameObject go = new GameObject(name);
                    go.layer = LayerMask.NameToLayer("Roads");
                    MassiveFeature f = go.AddComponent <MassiveFeature>();
                    f.SetSegments(segments);
                    f.SetProperties(properties);
                    f.SetType(geotype);
                    f.SetID(id);
                    go.transform.parent        = this.transform;
                    go.transform.localPosition = Vector3.zero;
                    // Create the mesh
                    CreateGameObject(md, go, kind);
                    //WriteAsset(go, AssetPath);
                }
            }

#if UNITY_EDITOR
            AssetDatabase.SaveAssets();
#endif
        }