Пример #1
0
    void loadXML()
    {
        // DestroyObject(go);
        //if (done || !GetComponent<MapChunkManager>().isReady)
        //   return;
        PolyLine pl = new PolyLine("TESTINGTRACER");
        pl.heigth = 1;
        pl.width = 3;
        pl.material = Resources.Load("Materials/blinker") as Material;
        float offsetPositionX = GetComponent<MapChunkManager>().offsetX;
        float offsetPositionZ = GetComponent<MapChunkManager>().offsetZ;
        pl.SetOffset(offsetPositionX, offsetPositionZ);

        XmlDocument XMLFile = new XmlDocument();
        XMLFile.LoadXml(gpsLog.text);
        XmlNodeList coords = XMLFile.GetElementsByTagName("trkpt");
        List<Node> nodes = new List<Node>();
        GeoUTMConverter convertor;
        foreach (XmlNode coord in coords) {
            // coord.Attributes["lat"].Value
            // coord.Attributes["lon"].Value
            Node n = new Node();
            n.lat = double.Parse(coord.Attributes["lat"].Value);
            n.lon = double.Parse(coord.Attributes["lon"].Value);
            convertor = new GeoUTMConverter();
            convertor.ToUTM(n.lat,n.lon);
            n.northing = convertor.Y;
            n.easthing = convertor.X;
            nodes.Add(n);
        }

        for (int a = 0; a < nodes.Count -1; a++) {
            Node n = nodes[a];

            Vector3 position = new Vector3((float)(n.easthing - offsetPositionX), 99999, (float)(n.northing - offsetPositionZ));
            float baseHeight = 0;
            RaycastHit hit;

            if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity)) {
                baseHeight = hit.point.y;
            }
            n.height = baseHeight + 1f;
            pl.Add(n);

        //            Debug.Log("Node is " + (float)(n.easthing - offsetPositionX) + "|" + (float)(n.northing - offsetPositionZ) + "|" + n.height);
        //            Color random = new Color(((float)n.easthing % 255) / 255f, ((float)n.northing % 255) / 255f, ((float)n.easthing % 255) / 255f);
        //            Debug.DrawLine(new Vector3((float)nodes[a].easthing - offsetPositionX, 200, (float)nodes[a].northing - offsetPositionZ), new Vector3((float)nodes[a + 1].easthing - offsetPositionX, 200, (float)nodes[a + 1].northing - offsetPositionZ), random,300);
        }

        //		foreach (Node node in nodes) {
        //			pl.Add (node);
        //		}
        GameObject go = new GameObject();
        go.transform.position = transform.position;
        pl.Close(go);
        done = true;
    }
Пример #2
0
    private void CreateRoad(Way w)
    {
        //GameObject go = new GameObject();
        //go.name = "Road";
        PolyLine pl = new PolyLine(w.id.ToString());
        pl.SetOffset(offsetPositionX, offsetPositionZ);
        pl.heigth = w.height;

        if (w.type == WayType.Footway)
        {
            pl.material = Resources.Load("Materials/Footway Material") as Material;
            pl.width = 1;
        }
        if (w.type == WayType.Motorway)
        {
            pl.material = Resources.Load("Materials/Road Material") as Material;
            pl.width = 4;
            pl.lanes = 2;
        }
        if (w.type == WayType.Residential)
        {
            pl.material = Resources.Load("Materials/Road Material") as Material;
            pl.width = 2;
        }
        if (w.type == WayType.River)
        {
            pl.material = Resources.Load("Materials/River Material") as Material;
            pl.width = 8;
        }
        //Road road = go.AddComponent<Road>();
        //road.groundOffset = 0.01f;
        //road.points.Clear();
        //road.roadWidth = 0.1f;// (float)(road.roadWidth/precision);
        //road.mat = (Material)Resources.LoadAssetAtPath("Assets/RoadTool/Example/Texture/Materials/Road.mat", typeof(Material));
        for (int a = 0; a < w.nodes.Count; a++)
        {
            Node n = w.nodes[a];

            Vector3 position = new Vector3((float)(n.easthing - offsetPositionX), 5000, (float)(n.northing - offsetPositionZ));
            float baseHeight = 0;
            RaycastHit hit;

            if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity, layerMask))
            {
                baseHeight = hit.point.y;
            }
            n.height = baseHeight;
            //Vector3 v = newn. Vector3((float)(((float)n.easthing-offsetPositionX)/precision),(float)0.0,(float)(((float)n.northing-offsetPositionZ)/precision));
            //road.points.Insert(0, v);
            pl.Add(n);

        }
        pl.Close(transform);
        //go.isStatic = true;
        //road.Refresh();
        //go.transform.parent = transform;
    }
Пример #3
0
    public override IEnumerator Build(Way w, MapChunkLoader mcl)
    {
        //GameObject go = new GameObject();
        //go.name = "Road";

        GameObject road = new GameObject();
        road.name = "Road - " + w.id.ToString();
        road.isStatic = true;
        road.transform.parent = mcl.transform;
        string roadPath = Application.persistentDataPath + "Assets/Resources/Objs/" + road.name + ".obj";

        if (!File.Exists(roadPath)) // If the file isn't cached we calculate everything and then we cache it
        {
            Debug.Log("STARTED CREATING ROAD");
            PolyLine pl = new PolyLine(w.id.ToString());
            pl.SetOffset(mcl.offsetPositionX, mcl.offsetPositionZ);
            pl.heigth = w.height;

            if (w.type == WayType.Footway)
            {
                pl.material = Resources.Load("Materials/Footway Material") as Material;
                pl.width = 1;
            }
            if (w.type == WayType.Motorway)
            {
                pl.material = Resources.Load("Materials/Road Material") as Material;
                pl.width = 4;
                pl.lanes = 2;
            }
            if (w.type == WayType.Residential)
            {
                pl.material = Resources.Load("Materials/Road Material") as Material;
                pl.width = 2;
            }
            if (w.type == WayType.River)
            {
                pl.material = Resources.Load("Materials/River Material") as Material;
                pl.width = 8;
            }

            for (int a = 0; a < w.nodes.Count; a++)
            {
                Node n = w.nodes[a];

                Vector3 position = new Vector3((float)(n.easthing - mcl.offsetPositionX), 5000, (float)(n.northing - mcl.offsetPositionZ));
                float baseHeight = 0;
                RaycastHit hit;

                if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity, mcl.layerMask))
                {
                    baseHeight = hit.point.y;
                }
                n.height = baseHeight;
                pl.Add(n);

            }
            //Closed road;
            mcl.StartCoroutine(pl.Close(road));

            if (mcl.exportObjs)
            {
                while (road.GetComponent<MeshFilter>() == null)
                {
                    yield return null;
                }
                MeshFilter mf = road.GetComponent<MeshFilter>();
                ObjExporter oe = new ObjExporter();
                oe.MeshToFile(mf, roadPath);

            }
        }
        else
        {
            ObjImporter oi = new ObjImporter();
            mcl.StartCoroutine(oi.FileToMesh("file://" + roadPath));
            while (oi._myMesh == null)
            {
                yield return null;

            }
            MeshFilter mf = road.AddComponent<MeshFilter>();
            MeshRenderer mr = road.AddComponent<MeshRenderer>();
            mf.sharedMesh = oi._myMesh;
            Debug.LogWarning("Loaded Road from cache " + roadPath);
            if (w.type == WayType.Footway)
            {
                mr.material = Resources.Load("Materials/Footway Material") as Material;

            }
            if (w.type == WayType.Motorway)
            {
                mr.material = Resources.Load("Materials/Road Material") as Material;

            }
            if (w.type == WayType.Residential)
            {
                mr.material = Resources.Load("Materials/Road Material") as Material;

            }
            if (w.type == WayType.River)
            {
                mr.material = Resources.Load("Materials/River Material") as Material;

            }
        }
    }