Beispiel #1
0
        private void Connect(ushort node1, ushort node2, Vector3 startDir, Vector3 endDir, NetInfo Info, bool invert = false)
        {
            //Debug.Log("Connectiong nodes " + node1 + " and " + node2);

            NetNode netNode1 = NetUtil.Node(node1);
            NetNode netNode2 = NetUtil.Node(node2);

            if ((netNode1.m_position - netNode2.m_position).magnitude < MIN_SEGMENT_LENGTH)
            {
                RepairShortSegment(ref endDir, ref node2);
            }

            //NetAccess.CreateSegment(node1,node2,(netNode2.m_position-netNode1.m_position).normalized, (netNode1.m_position - netNode2.m_position).normalized, info, invert);
            try
            {
                WrappedSegment segmentW = new WrappedSegment();
                segmentW.StartNode      = _networkDictionary.RegisterNode(node1);
                segmentW.EndNode        = _networkDictionary.RegisterNode(node2);
                segmentW.StartDirection = startDir;
                segmentW.EndDirection   = endDir;
                segmentW.NetInfo        = Info;
                segmentW.Invert         = invert;
                _actionGroup.Actions.Add(segmentW);

                segmentW.Create();
                //NetUtil.CreateSegment(node1, node2, startDir, endDir, Info, invert);
            }
            catch (Exception e)
            {
                Debug.LogWarning(e);
            }
        }
        // Called after intersection is built
        internal static void AfterIntersectionBuilt(BuildingInfo info)
        {
            if (!SmartIntersections.instance.Active)
            {
                return;
            }
            var m_tempNodeBuffer    = NetManager.instance.m_tempNodeBuffer;
            var m_tempSegmentBuffer = NetManager.instance.m_tempSegmentBuffer;

            if (info.m_paths.Length > 0)
            {
                foreach (ushort node in m_tempNodeBuffer)
                {
                    var nodeW = _networkDictionary.RegisterNode(node);
                    _actionGroup.Actions.Add(nodeW);
                }
                foreach (ushort segment in m_tempSegmentBuffer)
                {
                    var segmentW = _networkDictionary.RegisterSegment(segment);
                    _actionGroup.Actions.Add(segmentW);
                }
                ReleaseQuestionableSegments(m_tempNodeBuffer, m_tempSegmentBuffer);
                new MakeConnections(borderNodes, m_tempNodeBuffer, _networkDictionary, _actionGroup);
                _actionGroup.IsDone = true;

                SmartIntersections.instance.PushGameAction(_actionGroup);
            }
        }
        private void SnappingAlgorithmNew()
        {
            //Debug
            //EllipseTool.Instance.debugDraw = segmentBeziers;

            List <Bezier2> segmentBeziers    = makeBeziers(traveller.OuterSegments);
            List <Bezier2> ellipseBeziers    = traveller.Ellipse.Beziers;
            List <ushort>  processedSegments = new List <ushort>();

            /* We find all intersections between roads and ellipse beziers */
            for (int i = 0; i < segmentBeziers.Count; i++)
            {
                for (int j = 0; j < ellipseBeziers.Count; j++)
                {
                    if (ellipseBeziers[j].Intersect(segmentBeziers[i], out float t1, out float t2, ITERATIONS))
                    {
                        if (processedSegments.Contains(traveller.OuterSegments[i]))
                        {
                            continue;
                        }
                        else
                        {
                            processedSegments.Add(traveller.OuterSegments[i]);
                        }

                        //Debug.Log("Segment " + i.ToString() + " intersects ellipse bezier " + j.ToString());
                        Vector3 intersection = new Vector3(ellipseBeziers[j].Position(t1).x, CenterNode.m_position.y, ellipseBeziers[j].Position(t1).y);
                        segmentBeziers[i].Divide(out Bezier2 segementBezier1, out Bezier2 segementBezier2, t2);
                        Bezier2 outerBezier;
                        Vector2 outerNodePos = new Vector2(NetUtil.Node(traveller.OuterNodes[i]).m_position.x, NetUtil.Node(traveller.OuterNodes[i]).m_position.z);
                        bool    invert       = false;
                        // outerBezier - the bezier outside the ellipse (not the one inside)
                        if (segementBezier1.Position(0f) == outerNodePos || segementBezier1.Position(1f) == outerNodePos)
                        {
                            //Debug.Log("first is outer");
                            outerBezier = segementBezier1.Invert();
                            invert      = true;
                        }
                        else if (segementBezier2.Position(0f) == outerNodePos || segementBezier2.Position(1f) == outerNodePos)
                        {
                            //Debug.Log("second is probably outer");
                            outerBezier = segementBezier2;
                            invert      = false;
                        }
                        else
                        {
                            throw new Exception("Error - Failed to determine segment geometry.");
                        }

                        //debug:
                        //EllipseTool.Instance.debugDraw.Add(outerBezier);

                        /* We create a node at the intersection. */
                        WrappedNode newNode = new WrappedNode();
                        newNode.Position = intersection;
                        newNode.NetInfo  = CenterNode.Info;
                        RoundaboutNode raNode = new RoundaboutNode(newNode);
                        raNode.Create(ActionGroupRoads);
                        Intersections.Add(raNode);

                        WrappedNode    outerNode    = networkDictionary.RegisterNode(traveller.OuterNodes[i]);
                        WrappedSegment outerSegment = networkDictionary.RegisterSegment(traveller.OuterSegments[i]);

                        BezierToSegment(outerBezier, outerSegment, newNode, outerNode, invert);
                    }
                }
            }
        }