Esempio n. 1
0
        /// <summary>
        /// Build the array
        /// </summary>
        /// <param name="buildMesh">Weather to build the mesh or not</param>
        /// <param name="tm">The terrain modifier</param>
        /// <returns>The array details of the cross road</returns>
        private CrossRoadsArray BuildArray(bool buildMesh, TerrainModifier tm)
        {
            RoadCrossRoadOrder order;
            MeshBuilderSection mbs;
            RoadCrossSection   leftIntersectionInner, leftIntersectionOutter, rightIntersectionInner, rightIntersectionOutter, middleIntersectionInner, oppositeIntersectionInner;

            UpdateRoadNodesEndPoints(out order, out mbs, out leftIntersectionInner, out leftIntersectionOutter, out rightIntersectionInner, out rightIntersectionOutter, out middleIntersectionInner, out oppositeIntersectionInner);

            if (buildMesh)
            {
                mbs.DirectBuild(leftIntersectionInner, order.LeftRoad);
                mbs.DirectBuild(rightIntersectionInner, order.RightRoad);

                mbs.DirectBuild(middleIntersectionInner, order.MiddleRoad);
                mbs.DirectBuild(oppositeIntersectionInner, order.OppositeRoad);
            }
            else
            {
                tm.ApplyToTerrain(leftIntersectionInner, order.LeftRoad);
                tm.ApplyToTerrain(rightIntersectionInner, order.RightRoad);

                tm.ApplyToTerrain(middleIntersectionInner, order.MiddleRoad);
                tm.ApplyToTerrain(oppositeIntersectionInner, order.OppositeRoad);
            }

            CrossRoadsArray ja = new CrossRoadsArray();

            ja.LeftSide[7] = middleIntersectionInner.Left;
            ja.LeftSide[4] = middleIntersectionInner.CurbLeftLip;
            ja.LeftSide[1] = middleIntersectionInner.CurbLeftEnd;
            ja.LeftSide[5] = leftIntersectionInner.Right;
            ja.LeftSide[2] = leftIntersectionInner.CurbRightLip;
            ja.LeftSide[6] = leftIntersectionOutter.Right;
            ja.LeftSide[3] = AddSlope(leftIntersectionOutter.CurbRightLip, middleIntersectionInner.Angle);

            ja.RightSide[7] = middleIntersectionInner.Right;
            ja.RightSide[4] = middleIntersectionInner.CurbRightLip;
            ja.RightSide[1] = middleIntersectionInner.CurbRightEnd;
            ja.RightSide[5] = rightIntersectionInner.Left;
            ja.RightSide[2] = rightIntersectionInner.CurbLeftLip;
            ja.RightSide[6] = rightIntersectionOutter.Left;
            ja.RightSide[3] = AddSlope(rightIntersectionOutter.CurbLeftLip, middleIntersectionInner.Angle - (float)(Mathf.PI));

            ja.LeftFarSide[7] = oppositeIntersectionInner.Left;
            ja.LeftFarSide[4] = oppositeIntersectionInner.CurbLeftLip;
            ja.LeftFarSide[1] = oppositeIntersectionInner.CurbLeftEnd;
            ja.LeftFarSide[5] = rightIntersectionInner.Right;
            ja.LeftFarSide[2] = rightIntersectionInner.CurbRightLip;
            ja.LeftFarSide[6] = rightIntersectionOutter.Right;
            ja.LeftFarSide[3] = AddSlope(rightIntersectionOutter.CurbRightLip, oppositeIntersectionInner.Angle);

            ja.RightFarSide[7] = oppositeIntersectionInner.Right;
            ja.RightFarSide[4] = oppositeIntersectionInner.CurbRightLip;
            ja.RightFarSide[1] = oppositeIntersectionInner.CurbRightEnd;
            ja.RightFarSide[5] = leftIntersectionInner.Left;
            ja.RightFarSide[2] = leftIntersectionInner.CurbLeftLip;
            ja.RightFarSide[6] = leftIntersectionOutter.Left;
            ja.RightFarSide[3] = AddSlope(leftIntersectionOutter.CurbLeftLip, oppositeIntersectionInner.Angle - (float)(Mathf.PI));
            return(ja);
        }
Esempio n. 2
0
        /// <summary>
        /// Apply the terrain height
        /// </summary>
        /// <param name="tm">The terrain modifier</param>
        public void ApplyTerrain(TerrainModifier tm)
        {
            OutterInner outterInner = BuildArray(false, tm);

            for (int i = 0; i < _totalRoads; i++)
            {
                int rightRoad = i + 1;
                if (rightRoad > _totalRoads - 1)
                {
                    rightRoad -= _totalRoads;
                }

                int leftRoad = i - 1;
                if (leftRoad < 0)
                {
                    leftRoad += _totalRoads;
                }

                RectVector3 r;
                r = new RectVector3(outterInner.Inner[i].Left, outterInner.Outter[i].Left, outterInner.Inner[i].Right, outterInner.Outter[i].Right);
                tm.ApplyToTerrain(r, true);

                r = new RectVector3(outterInner.Outter[i].CurbRightEnd, outterInner.Outter[i].Right, outterInner.Outter[rightRoad].CurbLeftEnd, outterInner.Inner[i].Right);
                tm.ApplyToTerrain(r, true);

                r = new RectVector3(outterInner.Outter[i].CurbLeftEnd, outterInner.Outter[i].Left, outterInner.Outter[leftRoad].CurbRightEnd, outterInner.Inner[i].Left);
                tm.ApplyToTerrain(r, true);

                r = new RectVector3(_roadNetworkNode.transform.position, _roadNetworkNode.transform.position, outterInner.Inner[i].Left, outterInner.Inner[i].Right);
                tm.ApplyToTerrain(r, true);
            }
        }
        /// <summary>
        /// Modify the terrain for the Junction
        /// </summary>
        public void ApplyTerrain(TerrainModifier terrainModifier)
        {
            JunctionArray ja = BuildArray(false, terrainModifier);

            RectVector3 rect;

            rect = new RectVector3(ja.LeftSide[6], ja.LeftSide[7], ja.RightSide[6], ja.RightSide[7]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.LeftFarSide[5], ja.LeftFarSide[4], ja.LeftSide[6], ja.LeftSide[5]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.RightSide[6], ja.RightSide[5], ja.RightFarSide[5], ja.RightFarSide[4]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.RightSide[6], ja.RightFarSide[5], ja.LeftSide[6], ja.LeftFarSide[5]);
            terrainModifier.ApplyToTerrain(rect, true);

            // pavements
            rect = new RectVector3(ja.LeftSide[1], ja.LeftSide[4], ja.LeftSide[2], ja.LeftSide[3]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.RightSide[1], ja.RightSide[4], ja.RightSide[2], ja.RightSide[3]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.LeftFarSide[1], ja.LeftFarSide[2], ja.LeftFarSide[6], ja.LeftFarSide[3]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.RightFarSide[3], ja.RightFarSide[2], ja.RightFarSide[6], ja.RightFarSide[1]);
            terrainModifier.ApplyToTerrain(rect, true);
            rect = new RectVector3(ja.LeftFarSide[6], ja.LeftFarSide[3], ja.RightFarSide[6], ja.RightFarSide[3]);
            terrainModifier.ApplyToTerrain(rect, true);
        }
        /// <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);
            }
        }
Esempio n. 5
0
    /// <summary>
    /// Apply the strights to the terrain
    /// </summary>
    /// <param name="_roadNetworkNode">The main road network node</param>
    /// <param name="tm">The Terrain modifier</param>
    /// <param name="index">The index of the road to use</param>
    public static void ApplyLeadingStrights(RoadNetworkNode _roadNetworkNode, TerrainModifier tm, int index)
    {
        string[] stringArray = new string[2] {
            _roadNetworkNode.name, _roadNetworkNode.Details.Roads[index].name
        };
        Array.Sort(stringArray);

        string streetFullName = string.Join("-", stringArray);

        StreetData       street = StreetManager.Instance[streetFullName];
        RoadCrossSection rsc    = street.GetFirst;

        if (rsc == null)
        {
            return;
        }

        RoadCrossSection rsca = street.GetSecond;

        if (rsca == null)
        {
            return;
        }

        tm.ApplyToTerrain(rsc, rsca);
    }
Esempio n. 6
0
        /// <summary>
        /// Build the array
        /// </summary>
        /// <param name="buildMesh">Weather to build the mesh or not</param>
        /// <param name="tm">The terrain modifier</param>
        /// <returns>The array of outter and inner cross sections</returns>
        private OutterInner BuildArray(bool buildMesh, TerrainModifier tm)
        {
            RoadFiveRoadOrder  order;
            MeshBuilderSection mbs;
            OutterInner        outterInner;

            UpdateRoadNodesEndPoints(out order, out mbs, out outterInner);

            if (buildMesh)
            {
                for (int i = 0; i < _totalRoads; i++)
                {
                    mbs.DirectBuildDynamicTextureLength(outterInner.Outter[i], order.Road(i));
                }
            }
            else
            {
                for (int i = 0; i < _totalRoads; i++)
                {
                    tm.ApplyToTerrain(outterInner.Outter[i], order.Road(i));
                }
            }
            return(outterInner);
        }
Esempio n. 7
0
        /// <summary>
        /// Apply the terrain height
        /// </summary>
        /// <param name="tm">The terrain modifier</param>
        public void ApplyTerrain(TerrainModifier tm)
        {
            CrossRoadsArray ja = BuildArray(false, tm);

            RectVector3 r;

            r = new RectVector3(ja.LeftSide[6], ja.LeftSide[7], ja.RightSide[6], ja.RightSide[7]);
            tm.ApplyToTerrain(r, true);

            if (UVDATA.JunctionAcrossUV)
            {
                // Main road section Left
                Vector3 posAMid = (ja.RightFarSide[5] + ja.LeftSide[5]) / 2;
                Vector3 posBMid = (ja.RightFarSide[6] + ja.LeftSide[6]) / 2;

                r = new RectVector3(posBMid, posAMid, ja.LeftSide[6], ja.LeftSide[5]);
                tm.ApplyToTerrain(r, true);

                r = new RectVector3(ja.RightFarSide[6], ja.RightFarSide[5], posBMid, posAMid);
                tm.ApplyToTerrain(r, true);
            }
            else
            {
                r = new RectVector3(ja.RightFarSide[6], ja.RightFarSide[5], ja.LeftSide[6], ja.LeftSide[5]);
                tm.ApplyToTerrain(r, true);
            }

            if (UVDATA.JunctionAcrossUV)
            {
                // Road section Right
                Vector3 posAMid = (ja.RightSide[5] + ja.LeftFarSide[5]) / 2;
                Vector3 posBMid = (ja.RightSide[6] + ja.LeftFarSide[6]) / 2;

                r = new RectVector3(ja.RightSide[6], ja.RightSide[5], posBMid, posAMid);
                tm.ApplyToTerrain(r, true);

                r = new RectVector3(posBMid, posAMid, ja.LeftFarSide[6], ja.LeftFarSide[5]);
                tm.ApplyToTerrain(r, true);
            }
            else
            {
                r = new RectVector3(ja.RightSide[6], ja.RightSide[5], ja.LeftFarSide[6], ja.LeftFarSide[5]);
                tm.ApplyToTerrain(r, true);
            }

            // Road section Middle
            r = new RectVector3(ja.LeftFarSide[6], ja.LeftFarSide[7], ja.RightFarSide[6], ja.RightFarSide[7]);
            tm.ApplyToTerrain(r, true);

            Vector3 posC = (ja.LeftFarSide[6] + ja.RightSide[6]) / 2;
            Vector3 posD = (ja.RightFarSide[6] + ja.LeftSide[6]) / 2;

            r = new RectVector3(posC, posD, ja.RightSide[6], ja.LeftSide[6]);
            tm.ApplyToTerrain(r, true);

            r = new RectVector3(ja.LeftFarSide[6], ja.RightFarSide[6], posC, posD);
            tm.ApplyToTerrain(r, true);

            // pavements
            r = new RectVector3(ja.LeftSide[1], ja.LeftSide[4], ja.LeftSide[2], ja.LeftSide[3]);
            tm.ApplyToTerrain(r, true);

            r = new RectVector3(ja.RightSide[1], ja.RightSide[4], ja.RightSide[2], ja.RightSide[3]);
            tm.ApplyToTerrain(r, true);

            r = new RectVector3(ja.LeftFarSide[1], ja.LeftFarSide[4], ja.LeftFarSide[2], ja.LeftFarSide[3]);
            tm.ApplyToTerrain(r, true);

            r = new RectVector3(ja.RightFarSide[1], ja.RightFarSide[4], ja.RightFarSide[2], ja.RightFarSide[3]);
            tm.ApplyToTerrain(r, true);
        }
        /// <summary>
        /// Modify the terrain for the corner
        /// </summary>
        /// <param name="sections">The number of sections</param>
        /// <param name="tm">The terrain modifier</param>
        private void CreateCornerTerrain(int sections, TerrainModifier tm)
        {
            // this is not the best way - but it's a start
            // maybe have a function that returns a list of cross sections

            // find the point where the two roads meet
            Vector3 pos = _roadNetworkNode.gameObject.transform.position;

            // create a corne at this postion
            Vector3 newpos = pos;

            float roadAngleA = RoadUnionHelper.AngleClamp(RoadUnionHelper.GetAngleOfRoadClampped(_roadNetworkNode, 0) - Mathf.PI / 2);
            float roadAngleB = RoadUnionHelper.AngleClamp(RoadUnionHelper.GetAngleOfRoadClampped(_roadNetworkNode, 1) + Mathf.PI / 2);
            float roadAngleDifference = roadAngleB - roadAngleA;
            float couveSize = 1.85f;
            float x, z;

            float road_A_length = GetLengthOfRoad(0);
            float road_B_length = GetLengthOfRoad(1);

            float minLength = Mathf.Min(road_A_length, road_B_length);

            float offSetDownRoad = RoadConstructorHelper.CrossSectionDetails.RoadWidthValue * couveSize;

            if (offSetDownRoad > minLength / 2)
            {
                offSetDownRoad = minLength / 2;
            }

            RoadNetworkNode oppositeEnd = _roadNetworkNode.Details.Roads[1].GetComponent <RoadNetworkNode>();
            Vector3         roadPointA  = oppositeEnd.GetOffSetDownRoad(pos, (offSetDownRoad));
            Vector3         outA;
            bool            offSetPos   = _roadNetworkNode.GetInnerCorner(0, 1, (offSetDownRoad), out outA);
            Vector3         CornerPoint = outA;

            newpos = CornerPoint;

            // get the gap form point to point
            Vector3 gap = CornerPoint - roadPointA;

            couveSize = offSetPos ? gap.magnitude : 0;
            couveSize = offSetPos ? gap.magnitude : 0;

            Radian currentAngle = new Radian(roadAngleA - (float)(Math.PI / 2));

            roadAngleDifference = MathsHelper.ClampAngle(roadAngleDifference);
            if (roadAngleDifference > Mathf.PI)
            {
                roadAngleDifference = (Mathf.PI * 2) - roadAngleDifference;
                currentAngle        = new Radian(roadAngleB + (float)(Math.PI / 2));
            }

            float diff = roadAngleDifference;

            x = Mathf.Sin(currentAngle.Value) * (couveSize);
            z = Mathf.Cos(currentAngle.Value) * (couveSize);

            newpos.x -= x;
            newpos.z += z;

            ICrossSection      crossSectionMiddle = RoadConstructorHelper.CrossSection(_roadNetworkNode);
            IMaterialFrequency materialFrequency  = _roadNetworkNode.gameObject.GetComponent <IMaterialFrequency>();

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

            RoadCrossSection rA = new RoadCrossSection(newpos, currentAngle.Value, crossSectionMiddle, materialFrequency);

            float angleStep = Mathf.Abs(diff / sections);

            for (int i = 0; i < sections; i++)
            {
                newpos              = CornerPoint;
                currentAngle.Value += angleStep;

                x         = Mathf.Sin(currentAngle.Value) * (couveSize);
                z         = Mathf.Cos(currentAngle.Value) * (couveSize);
                newpos.x -= x;
                newpos.z += z;

                RoadCrossSection rB = new RoadCrossSection(newpos, currentAngle.Value, crossSectionMiddle, materialFrequency);
                tm.ApplyToTerrain(rA, rB);
                rA = rB;
            }

            RoadConstructorHelper.ApplyLeadingStrights(_roadNetworkNode, tm, 0);
            RoadConstructorHelper.ApplyLeadingStrights(_roadNetworkNode, tm, 1);
        }