/// <summary>
        /// Create the section of the road
        /// </summary>
        public void Build()
        {
            RoadCrossSection rA = IntersectionManager.Instance[_list[0]];
            RoadCrossSection rB = IntersectionManager.Instance[_list[1]];

            Build(rA, rB, 1);
        }
        /// <summary>
        /// Apply to terrain
        /// </summary>
        /// <param name="TerrainModifier">The Terrain Modifier helper</param>
        public void ModifiyTerrain(TerrainModifier tm)
        {
            foreach (RoadNetworkNode rnn in _roadNetworkNode.Details.Roads)
            {
                string[] stringArray = new string[2] {
                    _roadNetworkNode.name, rnn.name
                };
                Array.Sort(stringArray);

                string     streetFullName = string.Join("-", stringArray);
                StreetData sd             = StreetManager.Instance[streetFullName];

                RoadCrossSection rsc = sd.GetFirst;
                if (rsc == null)
                {
                    continue;
                }

                RoadCrossSection rsca = sd.GetSecond;
                if (rsca == null)
                {
                    continue;
                }

                tm.ApplyToTerrain(rsc, rsca);
            }
        }
        /// <summary>
        /// Create the section of the road
        /// </summary>
        /// <param name="rA">The start of the road section</param>
        /// <param name="rB">The end of the road section</param>
        /// <param name="texturePercent">The percentage of the texture to use</param>
        public void Build(RoadCrossSection rA, RoadCrossSection rB, float texturePercent)
        {
            bool flip = false;

            List <int> triangles = _roadObject.GetTriangles(_materialName);

            if (rA.IsRoadTwisted(rB))
            {
                rB = RoadCrossSection.CreateMirror(rB);
            }

            flip = AddMainRoadSection(rA, rB, triangles, texturePercent);

            if (!RoadConstructorHelper.CrossSectionDetails.WithCurbValue)
            {
                return;
            }

            AddCurbTopLeft(rA, rB, flip, triangles, texturePercent);
            AddCurbTopRight(rA, rB, flip, triangles, texturePercent);

            if (RoadConstructorHelper.CrossSectionDetails.HasCurbDataValue)
            {
                AddCurbUpLeft(rA, rB, flip, triangles);
                AddCurbUpRight(rA, rB, flip, triangles);
            }

            // Add the Curb Down polys.
            AddCurbLeftDrop(rA, rB, flip, triangles);
            AddCurbRightDrop(rA, rB, flip, triangles);
        }
示例#4
0
        /// <summary>
        /// Define the road and cross section
        /// </summary>
        /// <param name="couveSize">The size off set</param>
        /// <param name="index">The road index</param>
        /// <param name="roadNetworkNode">The main road node</param>
        /// <param name="road">The rode node to populate</param>
        /// <param name="crossSection">The cross section to populate</param>
        public static void DefineCrossSectionOffSet(float couveSize, int index, RoadNetworkNode roadNetworkNode, out RoadNetworkNode road, out RoadCrossSection crossSection)
        {
            road = roadNetworkNode.Details.Roads[index];
            Vector3 pos        = roadNetworkNode.gameObject.transform.position;
            float   angleA     = RoadUnionHelper.AngleClamp(RoadUnionHelper.GetAngleOfRoad(roadNetworkNode, index) + (Mathf.PI / 2));
            Vector3 roadPointA = road.GetOffSetDownRoad(pos, (RoadConstructorHelper.CrossSectionDetails.RoadWidthValue * couveSize));

            crossSection = new RoadCrossSection(roadPointA, angleA - (float)(Math.PI / 2), RoadConstructorHelper.CrossSection(road), RoadConstructorHelper.Materials(road));
        }
示例#5
0
        /// <summary>
        /// Set the intersecion for this road
        /// </summary>
        /// <param name="index">The road section index</param>
        /// <param name="section">The road crosss section to use</param>
        public void SetRoadCrossSection(int index, RoadCrossSection section)
        {
            if (_roadCrossSections == null || _roadCrossSections.Length != Details.Roads.Count)
            {
                _roadCrossSections = new RoadCrossSection[Details.Roads.Count];
            }

            _roadCrossSections[index] = section;
        }
        /// <summary>
        /// Add one intersection
        /// </summary>
        /// <param name="a">Road intersection</param>
        /// <returns>The index of the connection set</returns>
        public int AddLinkedIntersecions(RoadCrossSection a)
        {
            a = AddIntersection(a);

            _connections.Add(new List <Guid>()
            {
                a.ID
            });
            return(_connections.Count - 1);
        }
        /// <summary>
        /// Create the road object
        /// </summary>
        /// <param name="roadObject">The base object to add the road to</param>
        /// <param name="sections">The number of sections to use for this road</param>
        private void CreateFiveRoads(RoadBuilder roadObject, int sections)
        {
            float couveSize = 2.5f;

            _roadNetworkNode.OrderRoads();

            IMaterialFrequency materialFrequency = _roadNetworkNode.GetComponent <OverridableMaterialFrequency>();

            if (materialFrequency == null)
            {
                materialFrequency = RoadConstructorHelper.MaterialFrequencySet;
            }

            RoadNetworkNode  roadA, roadB, roadC, roadD, roadE;
            RoadCrossSection rA, rB, rC, rD, rE;

            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 0, _roadNetworkNode, out roadA, out rA);
            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 1, _roadNetworkNode, out roadB, out rB);
            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 2, _roadNetworkNode, out roadC, out rC);
            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 3, _roadNetworkNode, out roadD, out rD);
            RoadUnionHelper.DefineCrossSectionOffSet(couveSize, 4, _roadNetworkNode, out roadE, out rE);

            int connectionSet = IntersectionManager.Instance.AddLinkedIntersecions(rA, rB, rC, rD, rE);

            _meshSection.AddFiveRoad(connectionSet, _roadNetworkNode, RoadConstructorHelper.GetMainMaterial(materialFrequency));
            _meshSection.UpdateEndPoints(roadObject);

            StreetManager.Instance.AddStreetEnd(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[0].name, RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[0]), RoadConstructorHelper.Materials(roadA), rA);
            StreetManager.Instance.AddStreetEnd(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[1].name, RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[1]), RoadConstructorHelper.Materials(roadB), rB);
            StreetManager.Instance.AddStreetEnd(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[2].name, RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[2]), RoadConstructorHelper.Materials(roadC), rC);
            StreetManager.Instance.AddStreetEnd(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[3].name, RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[3]), RoadConstructorHelper.Materials(roadD), rD);
            StreetManager.Instance.AddStreetEnd(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[4].name, RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[4]), RoadConstructorHelper.Materials(roadE), rE);

            List <Guid>      list = IntersectionManager.Instance[connectionSet];
            RoadCrossSection rscA = IntersectionManager.Instance[list[0]];
            RoadCrossSection rscB = IntersectionManager.Instance[list[1]];
            RoadCrossSection rscC = IntersectionManager.Instance[list[2]];
            RoadCrossSection rscD = IntersectionManager.Instance[list[3]];
            RoadCrossSection rscE = IntersectionManager.Instance[list[4]];

            StreetManager.Instance.ReplaceRoadWithId(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[0].name,
                                                     RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[0]), rscA);

            StreetManager.Instance.ReplaceRoadWithId(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[1].name,
                                                     RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[1]), rscB);

            StreetManager.Instance.ReplaceRoadWithId(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[2].name,
                                                     RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[2]), rscC);

            StreetManager.Instance.ReplaceRoadWithId(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[3].name,
                                                     RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[3]), rscD);

            StreetManager.Instance.ReplaceRoadWithId(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[4].name,
                                                     RoadConstructorHelper.CrossSection(_roadNetworkNode.Details.Roads[4]), rscE);
        }
        /// <summary>
        /// Add a few linked intersections
        /// </summary>
        /// <param name="a">Road intersection a</param>
        /// <param name="b">Road intersection b</param>
        /// <param name="c">Road intersection c</param>
        public int AddLinkedIntersecions(RoadCrossSection a, RoadCrossSection b, RoadCrossSection c)
        {
            a = AddIntersection(a);
            b = AddIntersection(b);
            c = AddIntersection(c);

            _connections.Add(new List <Guid>()
            {
                a.ID, b.ID, c.ID
            });
            return(_connections.Count - 1);
        }
        /// <summary>
        /// Add a curb top section to the left hand side of the road
        /// </summary>
        /// <param name="rA">The start of the road section</param>
        /// <param name="rB">The end of the road section</param>
        /// <param name="flip">Do we need to flip the triangles</param>
        /// <param name="triangles">The list of triangle to add to</param>
        /// <param name="texturePercent">The percage of the texture to use</param>
        private void AddCurbTopLeft(RoadCrossSection rA, RoadCrossSection rB, bool flip, List <int> triangles, float texturePercent)
        {
            _roadObject.MeshVertices.Add(rA.CurbLeftLip);
            _roadObject.MeshVertices.Add(rB.CurbLeftLip);
            _roadObject.MeshVertices.Add(rA.CurbLeftEnd);
            _roadObject.MeshVertices.Add(rB.CurbLeftEnd);

            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightStart, UVDATA.CurbRightInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightLength * texturePercent, UVDATA.CurbRightInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightStart, UVDATA.CurbRightOutter));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightLength * texturePercent, UVDATA.CurbRightOutter));

            AddTriangles(flip, triangles);
        }
        /// <summary>
        /// Add a few linked intersections
        /// </summary>
        /// <param name="a">Road intersection a</param>
        /// <param name="b">Road intersection b</param>
        /// <param name="c">Road intersection c</param>
        /// <param name="d">Road intersection d</param>
        /// <param name="e">Road intersection d</param>
        /// <param name="f">Road intersection d</param>
        public int AddLinkedIntersecions(RoadCrossSection a, RoadCrossSection b, RoadCrossSection c, RoadCrossSection d, RoadCrossSection e, RoadCrossSection f)
        {
            a = AddIntersection(a);
            b = AddIntersection(b);
            c = AddIntersection(c);
            d = AddIntersection(d);
            e = AddIntersection(e);
            f = AddIntersection(f);

            _connections.Add(new List <Guid>()
            {
                a.ID, b.ID, c.ID, d.ID, e.ID, f.ID
            });
            return(_connections.Count - 1);
        }
        /// <summary>
        /// Add a curb drop off section to the left hand side of the road
        /// </summary>
        /// <param name="rA">The start of the road section</param>
        /// <param name="rB">The end of the road section</param>
        /// <param name="flip">Do we need to flip the triangles</param>
        /// <param name="triangles">The list of triangle to add to</param>
        private void AddCurbLeftDrop(RoadCrossSection rA, RoadCrossSection rB, bool flip, List <int> triangles)
        {
            _roadObject.MeshVertices.Add(rA.CurbLeftEnd);
            _roadObject.MeshVertices.Add(rB.CurbLeftEnd);

            _roadObject.MeshVertices.Add(rA.CurbLeftEndDrop);
            _roadObject.MeshVertices.Add(rB.CurbLeftEndDrop);

            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightStart, UVDATA.CurbRightLipInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightLength, UVDATA.CurbRightLipInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightStart, UVDATA.CurbRightInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightLength, UVDATA.CurbRightInner));

            AddTriangles(flip, triangles);
        }
        private void AddAngle(Guid id, RoadNetworkNode node)
        {
            RoadCrossSection road  = IntersectionManager.Instance[id];
            float            angle = MathsHelper.ClampAngle(road.Angle);

            while (_angles.ContainsKey(angle))
            {
                angle = angle + 0.001f;
                Debug.Log("Overlap node " + node.name);
            }

            _angles.Add(angle, road);
            _nodes.Add(angle, node);
            _orderedAngles.Add(angle);
        }
        /// <summary>
        /// Standared constructor
        /// </summary>
        /// <param name="roadIds">The list of ids</param>
        /// <param name="roadNodes">The list of roads</param>
        public RoadFiveRoadOrder(List <Guid> roadIds, List <RoadNetworkNode> roadNodes)
        {
            _orderedAngles = new List <float>();
            _angles        = new Dictionary <float, RoadCrossSection>();
            _nodes         = new Dictionary <float, RoadNetworkNode>();

            for (int i = 0; i < roadIds.Count; i++)
            {
                RoadCrossSection road  = IntersectionManager.Instance[roadIds[i]];
                float            angle = MathsHelper.ClampAngle(road.Angle);
                _angles.Add(angle, road);
                _nodes.Add(angle, roadNodes[i]);
                _orderedAngles.Add(angle);
            }
            _orderedAngles.Sort();
        }
 /// <summary>
 /// replace an existing node
 /// </summary>
 /// <param name="roadSection">The road section</param>
 /// <param name="crossSection">The cross section details</param>
 public void ReplaceRoadWith(RoadCrossSection roadSection, ICrossSection crossSection)
 {
     if (_startRoadId.ID == roadSection.ID)
     {
         _startRoadId       = roadSection;
         _startCrossSection = crossSection;
     }
     else if (_endRoadId.ID == roadSection.ID)
     {
         _endRoadId       = roadSection;
         _endCrossSection = crossSection;
     }
     else
     {
         Debug.LogError("StreetData.ReplaceRoadWith: Can't find node to replace");
     }
 }
        /// <summary>
        /// Adjust the texture size based of the distance of the two road cross sections
        /// </summary>
        /// <param name="roadCrossSection1"></param>
        /// <param name="roadCrossSection2"></param>
        public void DirectBuildDynamicTextureLength(RoadCrossSection roadCrossSection1, RoadCrossSection roadCrossSection2)
        {
            RoadCrossSection rcsA = (RoadCrossSection)roadCrossSection1.Clone();
            RoadCrossSection rcsB = (RoadCrossSection)roadCrossSection2.Clone();

            Vector3 diff = rcsA.Middle - rcsB.Middle;

            if (diff.magnitude > 5f)
            {
                Build(roadCrossSection1, roadCrossSection2, 1);
                return;
            }

            float a = (100 / 5) * diff.magnitude;

            Build(roadCrossSection1, roadCrossSection2, a / 100);
        }
        /// <summary>
        /// Create the main section of the road. EG the road
        /// </summary>
        /// <param name="rA">Start of road</param>
        /// <param name="rB">End of the road</param>
        /// <param name="texturePercent">The percentage of texture to use</param>
        /// <returns>The flip flag</returns>
        private bool AddMainRoadSection(RoadCrossSection rA, RoadCrossSection rB, List <int> triangles, float texturePercent)
        {
            bool flip = false;

            // TODO: ADD subdivde here: Debug.Log("_subDivide = "+ _subDivide);
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightStart, UVDATA.CurbRightLipInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightStart, UVDATA.CurbLeftLipInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightLength * texturePercent, UVDATA.CurbRightLipInner));
            _roadObject.MeshUVs.Add(new Vector2(UVDATA.StraightLength * texturePercent, UVDATA.CurbLeftLipInner));

            _roadObject.MeshVertices.Add(rA.Left);
            _roadObject.MeshVertices.Add(rA.Right);

            _roadObject.MeshVertices.Add(rB.Left);
            _roadObject.MeshVertices.Add(rB.Right);

            int v = _roadObject.MeshVertices.Count - 4;

            // now we can work out if we need to flip the normals
            Vector3 nA = MathsHelper.NormalTri(
                _roadObject.MeshVertices[v],
                _roadObject.MeshVertices[v + 1],
                _roadObject.MeshVertices[v + 2]);

            nA.Normalize();

            Vector3 nB = MathsHelper.NormalTri(
                _roadObject.MeshVertices[v + 3],
                _roadObject.MeshVertices[v + 2],
                _roadObject.MeshVertices[v + 1]);

            nB.Normalize();

            if (nA.y < 0 && nB.y < 0)
            {
                flip = true;
            }

            AddTriangles(flip, triangles);

            return(flip);
        }
示例#17
0
        /// <summary>
        /// Find the smallest road needed for this junction
        /// </summary>
        /// <param name="currentroadNode">The road node</param>
        /// <param name="crossSections">The cross section of the road</param>
        /// <param name="middlePoint">The middle point in the cross section</param>
        /// <returns>The cross seciton of the road that is nearest to the junction</returns>
        private RoadCrossSection FindSmallestRoadForJunction(RoadNetworkNode currentroadNode, RoadCrossSection crossSections, Vector3 middlePoint)
        {
            Vector3 a        = crossSections.Middle;
            Vector3 diffline = a - middlePoint;
            float   angleA   = MathsHelper.GetAngleFrom(diffline.x, diffline.z);

            angleA = RoadUnionHelper.AngleClamp(crossSections.Angle - angleA) - Mathf.PI / 2;
            Vector3 diff = a - crossSections.CurbLeftEndDrop;
            float   mag2 = diff.magnitude * Mathf.Cos(angleA);

            if (mag2 < 0)
            {
                mag2 = -mag2;
            }
            Vector3          roadPointA = currentroadNode.GetOffSetDownRoad(crossSections.Middle, mag2);
            float            angleB     = RoadUnionHelper.AngleClamp(GetAngleOfRoad(currentroadNode) + Mathf.PI / 2);
            RoadCrossSection rA         = new RoadCrossSection(roadPointA, angleB - (float)(Math.PI / 2), RoadConstructorHelper.CrossSection(currentroadNode), RoadConstructorHelper.Materials(currentroadNode));

            return(rA);
        }
        /// <summary>
        /// The the intersection
        /// </summary>
        /// <param name="id">The id of the intersection</param>
        /// <param name="rcs">The intersection of the road</param>
        public void SetIntersection(Guid id, RoadCrossSection rcs)
        {
            rcs.ID = id;
            RoadCrossSection current;

            if (!_intersection.TryGetValue(id, out current))
            {
                current = null;
            }

            if (current != rcs)
            {
                if (current != null)
                {
                    RemoveFromIndex(id, current.Middle);
                }
                AddToIndex(id, rcs);
            }

            _intersection[id] = rcs;
        }
示例#19
0
        /// <summary>
        /// Create a clone of this intersection
        /// </summary>
        /// <returns>A new object as a clone of this one</returns>
        public object Clone()
        {
            RoadCrossSection rcs = new RoadCrossSection();

            rcs._id     = _id;
            rcs._angle  = _angle;
            rcs._left   = _left;
            rcs._right  = _right;
            rcs._middle = _middle;

            rcs._curbUpLeft   = _curbUpLeft;
            rcs._curbEndLeft  = _curbEndLeft;
            rcs._right        = _right;
            rcs._curbUpRight  = _curbUpRight;
            rcs._curbEndRight = _curbEndRight;

            rcs._curbEndLeftDrop  = _curbEndLeftDrop;
            rcs._curbEndRightDrop = _curbEndRightDrop;
            rcs._curbLipHeight    = _curbLipHeight;
            return(rcs);
        }
示例#20
0
        /// <summary>
        /// Is the road twisted compared with the other
        /// </summary>
        /// <param name="rsc">The over road to compear to</param>
        /// <returns>True if the road is twisted</returns>
        internal bool IsRoadTwisted(RoadCrossSection rsc)
        {
            Radian r1 = new Radian(_angle);
            Radian r2 = new Radian(rsc.Angle);

            if (r1.Value == r2.Value)
            {
                return(false);
            }

            Radian r3 = new Radian(r2.Value - r1.Value);

            r3.Value += Mathf.PI / 2;
            if (r3.Value < Mathf.PI)
            {
                return(false);
            }

            Gizmos.color = Color.white;
            return(true);
        }
        /// <summary>
        /// Update all of the end points of the jucntions
        /// </summary>
        /// <param name="order">The orderd list of roads</param>
        /// <param name="mbs">The created mesg builder</param>
        /// <param name="leftIntersectionInner">The inner left cross section</param>
        /// <param name="leftIntersectionOutter">The outter left cross section</param>
        /// <param name="rightIntersectionInner">The inner right cross section</param>
        /// <param name="rightIntersectionOutter">The outter right cross section</param>
        /// <param name="middleIntersectionInner">The middle road cross sections</param>
        private void UpdateRoadNodesEndPoint(out RoadJunctionOrder order, out MeshBuilderSection mbs, out RoadCrossSection leftIntersectionInner,
                                             out RoadCrossSection leftIntersectionOutter, out RoadCrossSection rightIntersectionInner, out RoadCrossSection rightIntersectionOutter,
                                             out RoadCrossSection middleIntersectionInner)
        {
            RoadNetworkNode roadA = _roadNetworkNode.Details.Roads[0];
            RoadNetworkNode roadB = _roadNetworkNode.Details.Roads[1];
            RoadNetworkNode roadC = _roadNetworkNode.Details.Roads[2];

            order = new RoadJunctionOrder(
                _list[0], roadA,
                _list[1], roadB,
                _list[2], roadC);
            mbs = new MeshBuilderSection(_roadObject, null, _materialName, 0);

            // left road
            leftIntersectionInner        = order.LeftRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.CurbLeftEnd);
            leftIntersectionOutter       = order.LeftRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.Left);
            leftIntersectionInner.Angle += (float)(Math.PI);

            rightIntersectionInner  = order.RightRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.CurbRightEnd);
            rightIntersectionOutter = order.RightRoad.GetIntersection(order.MiddleRoad.Angle, order.MiddleRoad.Right);
            Vector3 curbToCurb   = rightIntersectionInner.CurbLeftEnd - leftIntersectionInner.CurbRightEnd;
            float   newRoadAngle = -MathsHelper.GetAngleFrom(curbToCurb.z, curbToCurb.x) + (Mathf.PI / 2);

            middleIntersectionInner = order.MiddleRoad.GetIntersection(newRoadAngle, leftIntersectionInner.CurbRightEnd);

            // Store the ids so we know where to update them later
            Guid leftRoadNodeId   = order.LeftRoad.ID;
            Guid rightRoadNodeId  = order.RightRoad.ID;
            Guid middleRoadNodeId = order.MiddleRoad.ID;

            // reduce the run off roads
            order.ReSetLeft(FindSmallestRoadForJunction(order.LeftRoadNode, leftIntersectionInner, order.LeftRoad.Middle));
            order.ReSetRight(FindSmallestRoadForJunction(order.RightRoadNode, rightIntersectionInner, order.RightRoad.Middle));
            order.ReSetMiddle(FindSmallestRoadForJunction(order.MiddleRoadNode, middleIntersectionInner, order.MiddleRoad.Middle));

            IntersectionManager.Instance.SetIntersection(leftRoadNodeId, order.LeftRoad);
            IntersectionManager.Instance.SetIntersection(middleRoadNodeId, order.MiddleRoad);
            IntersectionManager.Instance.SetIntersection(rightRoadNodeId, order.RightRoad);
        }
示例#22
0
        /// <summary>
        /// Copy mirror constructor
        /// </summary>
        /// <param name="oldSection">The road cross section to copy</param>
        private RoadCrossSection(RoadCrossSection oldSection)
        {
            _angle = oldSection.Angle + (Mathf.PI * 2);

            _left  = oldSection.Right;
            _right = oldSection.Left;

            _curbUpLeft  = oldSection._curbUpRight;
            _curbUpRight = oldSection._curbUpLeft;

            _curbEndLeft  = oldSection._curbEndRight;
            _curbEndRight = oldSection._curbEndLeft;

            _curbEndLeftDrop  = oldSection._curbEndRightDrop;
            _curbEndRightDrop = oldSection._curbEndLeftDrop;

            _middle    = oldSection._middle;
            _withCurbs = oldSection._withCurbs;

            _curbLipHeight = oldSection._curbLipHeight;
            _curbEdgeDrop  = oldSection._curbEdgeDrop;
        }
示例#23
0
        /// <summary>
        /// Create the cross section at the point the roads roads intersect
        /// </summary>
        /// <param name="angle">The angel of the intersecting road</param>
        /// <param name="point">The point on the road to use</param>
        /// <returns>Creates a new intersecion of the road at the angle given</returns>
        internal RoadCrossSection GetIntersection(float angle, Vector3 point)
        {
            RoadCrossSection intersection = (RoadCrossSection)this.Clone();

            Vector3 pos;

            GetPointFrom(intersection.Angle, angle, intersection._curbEndRight, point, out pos);
            intersection._curbEndRight = pos;

            GetPointFrom(intersection.Angle, angle, intersection._curbUpLeft, point, out pos);
            intersection._curbUpLeft = pos;

            GetPointFrom(intersection.Angle, angle, intersection.CurbLeftEnd, point, out pos);
            intersection._curbEndLeft = pos;

            GetPointFrom(intersection.Angle, angle, intersection._curbUpRight, point, out pos);
            intersection._curbUpRight = pos;

            GetPointFrom(intersection.Angle, angle, intersection.Left, point, out pos);
            intersection._left = pos;

            GetPointFrom(intersection.Angle, angle, intersection.Right, point, out pos);
            intersection._right = pos;

            GetPointFrom(intersection.Angle, angle, intersection._curbEndLeftDrop, point, out pos);
            intersection._curbEndLeftDrop = pos;

            GetPointFrom(intersection.Angle, angle, intersection._curbEndRightDrop, point, out pos);
            intersection._curbEndRightDrop = pos;

            intersection._angle = angle + (float)(Mathf.PI / 2);

            intersection._curbLipHeight = _curbLipHeight;
            intersection._curbEdgeDrop  = _curbEdgeDrop;

            intersection._middle = (intersection._left + intersection._right) / 2;

            return(intersection);
        }
        /// <summary>
        /// Created the intersections of the roads
        /// </summary>
        /// <param name="roadBuilderObject">The road builder object</param>
        public void CreateLayout(RoadBuilder roadBuilderObject)
        {
            float   angleRoadStart = RoadUnionHelper.AngleClamp(RoadUnionHelper.GetAngleOfRoad(_roadNetworkNode, 0));
            Vector3 pos            = _roadNetworkNode.transform.position;

            ICrossSection sc = _roadNetworkNode.gameObject.GetComponent <ICrossSection>();

            if (sc == null)
            {
                sc = RoadConstructorHelper.CrossSectionDetails;
            }

            IMaterialFrequency mf = _roadNetworkNode.gameObject.GetComponent <IMaterialFrequency>();

            if (mf == null)
            {
                mf = RoadConstructorHelper.MaterialFrequencySet;
            }

            RoadCrossSection rA = new RoadCrossSection(pos, angleRoadStart, sc, mf);

            StreetManager.Instance.AddStreetEnd(_roadNetworkNode.name, _roadNetworkNode.Details.Roads[0].name, sc, mf, rA);
        }
        /// <summary>
        /// Add to index
        /// </summary>
        /// <param name="id">The id to add</param>
        /// <param name="rcs">The new road cross sections</param>
        private void AddToIndex(Guid id, RoadCrossSection rcs)
        {
            Vector3 mid = rcs.Middle;
            int     x   = (int)Math.Round(mid.x);
            int     z   = (int)Math.Round(mid.z);

            Dictionary <int, List <Guid> > outer;

            if (!_intersectionIndex.TryGetValue(x, out outer))
            {
                outer = new Dictionary <int, List <Guid> >();
                _intersectionIndex.Add(x, outer);
            }

            List <Guid> inner;

            if (!outer.TryGetValue(z, out inner))
            {
                inner = new List <Guid>();
                outer.Add(z, inner);
            }
            inner.Add(id);
        }
        /// <summary>
        /// Add a road intersection
        /// </summary>
        /// <param name="section">The Guid to use as the key</param>
        private RoadCrossSection AddIntersection(RoadCrossSection section)
        {
            Vector3 mid = section.Middle;
            int     x   = (int)Math.Round(mid.x);
            int     z   = (int)Math.Round(mid.z);

            List <Guid> intersections = GetClosebyNodes(x, z);

            foreach (var a in intersections)
            {
                RoadCrossSection rsc = _intersection[a];
                Vector3          v   = rsc.Middle - section.Middle;
                float            m   = Mathf.Abs(v.magnitude);
                if (m < 0.5f)
                {
                    return(rsc);
                }
            }

            AddToIndex(section.ID, section);
            _intersection.Add(section.ID, section);
            return(section);
        }
        /// <summary>
        /// Create the steet layout
        /// </summary>
        public void CreateStreetLayout(int subDivide)
        {
            if (_startRoadId == null)
            {
                return;
            }

            if (_endRoadId == null)
            {
                return;
            }

            RoadCrossSection rA = _startRoadId;
            ICrossSection    crossSectionStart = _startCrossSection;

            if (crossSectionStart == null)
            {
                crossSectionStart = RoadConstructorHelper.CrossSectionDetails;
            }

            RoadCrossSection rB = _endRoadId;
            ICrossSection    crossSectionEnd = _endCrossSection;

            if (crossSectionEnd == null)
            {
                crossSectionEnd = RoadConstructorHelper.CrossSectionDetails;
            }

            IMaterialFrequency materialFrequency = _materialFrequency;

            if (materialFrequency == null)
            {
                materialFrequency = RoadConstructorHelper.MaterialFrequencySet;
            }

            Vector3 len      = rA.Middle - rB.Middle;
            float   mag      = len.magnitude;
            int     sections = (int)(mag / crossSectionStart.RoadWidthValue);

            RoadCrossSection[] array         = new RoadCrossSection[sections + 1];
            string[]           materialNames = new string[sections + 1];

            float   an    = rB.Angle;
            Vector3 start = rB.Middle;

            if (sections < 2)
            {
                Vector3 another = rB.Middle;
                another = rA.Middle;
                RoadCrossSection rn = new RoadCrossSection(another, an, crossSectionStart, materialFrequency);
                _meshSection.AddBasicRoad(IntersectionManager.Instance.AddLinkedIntersecions(rB, rn), RoadConstructorHelper.GetMainMaterial(materialFrequency), 0); // TODO SubDivide
                return;
            }

            Vector3 gap  = len / sections;
            float   mag2 = gap.magnitude;

            for (int i = 0; i < sections + 1; i++)
            {
                ICrossSection    crossSection = CrossSection.Lerp(crossSectionEnd, crossSectionStart, (mag2 * i) / mag);
                RoadCrossSection rn           = new RoadCrossSection(start, an, crossSection, materialFrequency);
                array[i] = rn;
                start   += gap;
            }

            RoadConstructorHelper.SetMaterialsArray(materialNames, materialFrequency);
            for (int i = 0; i < sections; i++)
            {
                _meshSection.AddBasicRoad(IntersectionManager.Instance.AddLinkedIntersecions(array[i], array[i + 1]), materialNames[i], subDivide);
            }
        }
 /// <summary>
 /// Add a second road
 /// </summary>
 /// <param name="roadSection">The road section</param>
 /// <param name="crossSection">The cross section details</param>
 public void AddSecondRoad(RoadCrossSection roadSection, ICrossSection crossSection)
 {
     _endRoadId       = roadSection;
     _endCrossSection = crossSection;
 }
 /// <summary>
 /// Standard Constructor
 /// </summary>
 /// <param name="id">The id of the first road</param>
 /// <param name="crossSection">The cross section details</param>
 /// <param name="mf">The materials frequency</param>
 public StreetData(RoadCrossSection id, ICrossSection crossSection, IMaterialFrequency mf)
 {
     _startRoadId       = id;
     _startCrossSection = crossSection;
     _materialFrequency = mf;
 }
 /// <summary>
 /// Create the section of the road
 /// </summary>
 /// <param name="rA">The start road cross section</param>
 /// <param name="rB">The end road cross section</param>
 public void DirectBuild(RoadCrossSection rA, RoadCrossSection rB)
 {
     Build(rA, rB, 1);
 }