コード例 #1
0
        public void Export()
        {
            Debug.Log("Starting OSM Export.");

            osmNodes.Clear();
            osmWays.Clear();

            haveRoadNamerMod = RoadNamerManager.Instance().HaveMod();

            //Debug.Log("Exporting nodes");
            ExportNodes();

            //Debug.Log("Exporting ways");
            ExportWays();

            //Debug.Log("Exporting buildings");
            ExportBuildings();

            //Debug.Log("Exporting ground and water");
            ExportGroundAndWater();

            //Debug.Log("Exporting routes");
            ExportRoutes();

            //Debug.Log("Exporting districts");
            ExportDistricts();

            UniqueLogger.PrintLog("Road name matches");
            UniqueLogger.PrintLog("Road names missing from search");
            UniqueLogger.PrintLog("Building names missing from search");

            osm.node = osmNodes.ToArray();
            osm.way  = osmWays.ToArray();

            XmlSerializer xmlSerialiser = new XmlSerializer(typeof(OSM));
            StreamWriter  writer        = new StreamWriter(Singleton <SimulationManager> .instance.m_metaData.m_CityName + ".osm");

            xmlSerialiser.Serialize(writer, osm);
            writer.Close();

            Debug.Log("Finished OSM Export");
        }
コード例 #2
0
        private OSMWay CreateWay(int index, NetSegment segment, ushort segmentId)
        {
            OSMWay returnWay = null;

            NetSegment.Flags segmentFlags = segment.m_flags;
            NetManager       netManager   = Singleton <NetManager> .instance;
            List <OSMWayND>  wayPaths     = new List <OSMWayND>();
            List <OSMWayTag> wayTags;
            ushort           startNodeId = segment.m_startNode, endNodeId = segment.m_endNode;

            if (startNodeId != 0 && endNodeId != 0)
            {
                Vector3 startNodeDirection = segment.m_startDirection;
                Vector3 endNodeDirection   = segment.m_endDirection;

                if (segmentFlags.IsFlagSet(NetSegment.Flags.Invert))
                {
                    startNodeId        = segment.m_endNode;
                    endNodeId          = segment.m_startNode;
                    startNodeDirection = segment.m_endDirection;
                    endNodeDirection   = segment.m_startDirection;
                }

                NetNode startNode         = netManager.m_nodes.m_buffer[startNodeId];
                NetNode endNode           = netManager.m_nodes.m_buffer[endNodeId];
                Vector3 startNodePosition = startNode.m_position;
                Vector3 endNodePosition   = endNode.m_position;

                wayPaths.Add(new OSMWayND {
                    @ref = startNodeId
                });

                if (Vector3.Angle(startNodeDirection, -endNodeDirection) > 3f)
                {
                    Vector3 midPointA = Vector3.zero, midPointB = Vector3.zero;
                    NetSegment.CalculateMiddlePoints(startNodePosition, startNodeDirection, endNodePosition, endNodeDirection, false, false, out midPointA, out midPointB);
                    Bezier3 bezier = new Bezier3(startNodePosition, midPointA, midPointB, endNodePosition);

                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.25f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.5f)));
                    osmNodes.Add(CreateNode(unindexedNodeOffset++, bezier.Position(0.75f)));

                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 3
                    });
                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 2
                    });
                    wayPaths.Add(new OSMWayND {
                        @ref = (uint)unindexedNodeOffset - 1
                    });
                }

                wayPaths.Add(new OSMWayND {
                    @ref = endNodeId
                });

                if (Tagger.CreateWayTags(segment, out wayTags))
                {
                    if (haveRoadNamerMod)
                    {
                        // If road namer mod is available, then attempt to get the name asscociated with the segment, if any
                        string roadName = RoadNamerManager.Instance().getSegmentName((ushort)(segmentId));
                        if (roadName != null)
                        {
                            //If a name is available, add a name tag
                            wayTags.Add(new OSMWayTag {
                                k = "name", v = StringUtilities.RemoveTags(roadName)
                            });
                        }
                    }
                    returnWay = new OSMWay {
                        changeset = 50000000, id = (uint)index, timestamp = DateTime.Now, user = "******", nd = wayPaths.ToArray(), tag = wayTags.ToArray(), version = 1
                    };
                }
                else
                {
                    UniqueLogger.AddLog("Road names missing from search", segment.Info.name, "");
                }
            }

            return(returnWay);
        }