예제 #1
0
        public Pavement(Highway highway, myTerrain terrain, pavementSide _side)
        {
            Pavementid = highway.id;
            side = _side;

            if(side == pavementSide.left)
            {
                rightSideVertexes = new List<Vector3>(highway.leftSideVertexes);
                leftSideVertexes = new List<Vector3>();
                generateOtherSide(highway.leftSidewalkSize, terrain);

                PavementObj = new GameObject("LeftPavement" + Pavementid);
                PavementObj.transform.parent = highway.highwayGameObject.transform;

            }
            if(side == pavementSide.right)
            {
                leftSideVertexes = new List<Vector3>(highway.rightSideVertexes);
                rightSideVertexes = new List<Vector3>();
                generateOtherSide(highway.rightSidewalkSize, terrain);

                PavementObj = new GameObject("RightPavement" + Pavementid);
                PavementObj.transform.parent = highway.highwayGameObject.transform;
            }
        }
예제 #2
0
        //Highway Constructor (Uses Save File)
        public Highway(Way w, List <HighwayConfigurations> config, myTerrain _terrain, HighwaySave save)
        {
            id   = w.id;
            way  = w;
            type = getHighwayType(w.tags);
            name = getHighwayName(w.tags);

            if (type == highwayType.HighwayFootway)
            {
                return;
            }


            getConfiguration(config);
            waySize           = save.waySize;
            hasLeftSidewalk   = save.hasLeftSidewalk;
            hasRightSideWalk  = save.hasRightSidewalk;
            leftSidewalkSize  = save.leftSidewalkSize;
            rightSidewalkSize = save.rightSidewalkSize;

            bbox = _terrain.scenebbox;

            streetLampList = new List <Object3D>();
            generateInitial3Dway(_terrain);
            //colliderMesh = generateColliderMesh();

            highwayGameObject = new GameObject("Highway" + way.id, typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider));
            highwayGameObject.transform.localScale = new Vector3(1, 1, 1);


            if (type != highwayType.River)
            {
                highwayGameObject.tag = "Highway";
            }
        }
예제 #3
0
 //Drape highway to the Terrain
 public void DrapeRoad(myTerrain _terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
 {
     //------ DO Not Change Order------
     HorizontalDrape(_terrain,leftSideVertexes,rightSideVertexes);
     VerticalDrape(_terrain, leftSideVertexes,rightSideVertexes);
     DiagonalDrape(_terrain, leftSideVertexes,rightSideVertexes);
     //--------------------------------
 }
 //Drape highway to the Terrain
 public void DrapeRoad(myTerrain _terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
 {
     //------ DO Not Change Order------
     HorizontalDrape(_terrain,leftSideVertexes,rightSideVertexes);
     VerticalDrape(_terrain, leftSideVertexes,rightSideVertexes);
     DiagonalDrape(_terrain, leftSideVertexes,rightSideVertexes);
     //--------------------------------
 }
 public HighwayModeller(List<Way> _wayList, myTerrain _terrain, List<HighwayConfigurations> _configurations, List<HighwaySave> highwaySaveList)
 {
     wayList = _wayList;
     highwayList = new List<Highway>();
     pavementList = new List<Pavement>();
     terrain = _terrain;
     configurations = _configurations;
     generateHighwayList(highwaySaveList);
     generatePavementList();
 }
예제 #6
0
        //Highway Constructor
        public Highway(Way w, List<HighwayConfigurations> config, myTerrain _terrain)
        {
            id = w.id;
            way = w;
            type = getHighwayType(w.tags);
            name = getHighwayName(w.tags);

            if (type == highwayType.HighwayFootway)
                return;

            getConfiguration(config);
            bbox = _terrain.scenebbox;

            streetLampList = new List<Object3D>();
            generateInitial3Dway(_terrain);
            //colliderMesh = generateColliderMesh();

            highwayGameObject = new GameObject("Highway" + way.id, typeof(MeshRenderer), typeof(MeshFilter), typeof(MeshCollider));
            highwayGameObject.transform.localScale = new Vector3(1, 1, 1);

            if(type != highwayType.River)
                highwayGameObject.tag = "Highway";
        }
예제 #7
0
        public Pavement(Highway highway, myTerrain terrain, pavementSide _side)
        {
            Pavementid = highway.id;
            side       = _side;

            if (side == pavementSide.left)
            {
                rightSideVertexes = new List <Vector3>(highway.leftSideVertexes);
                leftSideVertexes  = new List <Vector3>();
                generateOtherSide(highway.leftSidewalkSize, terrain);

                PavementObj = new GameObject("LeftPavement" + Pavementid);
                PavementObj.transform.parent = highway.highwayGameObject.transform;
            }
            if (side == pavementSide.right)
            {
                leftSideVertexes  = new List <Vector3>(highway.rightSideVertexes);
                rightSideVertexes = new List <Vector3>();
                generateOtherSide(highway.rightSidewalkSize, terrain);

                PavementObj = new GameObject("RightPavement" + Pavementid);
                PavementObj.transform.parent = highway.highwayGameObject.transform;
            }
        }
예제 #8
0
        //This will be used for generating initial vertexes
        public void generateInitial3Dway(myTerrain terrain)
        {
            leftSideVertexes = new List<Vector3>();
            rightSideVertexes = new List<Vector3>();

            if (way.nodes.Count == 2)
            {
                Vector3 up = new Vector3(0, 1, 0);
                Vector3 forward = way.nodes[1].meterPosition - way.nodes[0].meterPosition;
                        forward.y = 0.0f;
                //Vector3 right = Vector3.Cross(forward ,up);**********************************************
                Vector3 right = Vector3.Cross(up ,forward);
                right = right.normalized;
                Vector3 left = -1 * right;

                //LEFT SIDE
                Vector2 pointLeft1 = new Vector2(way.nodes[0].meterPosition.x,way.nodes[0].meterPosition.z) + new Vector2(left.x,left.z) * (waySize /2.0f);
                Vector2 pointLeft2 = new Vector2(way.nodes[1].meterPosition.x,way.nodes[1].meterPosition.z) + new Vector2(left.x,left.z) * (waySize /2.0f);
                Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y);
                Vector3 pointLeft2Pos = new Vector3(pointLeft2.x, terrain.getTerrainHeight2(pointLeft2.y + bbox.meterBottom, pointLeft2.x + bbox.meterLeft), pointLeft2.y);
                leftSideVertexes.Add(pointLeft1Pos);
                leftSideVertexes.Add(pointLeft2Pos);
                if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp)
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft1Pos,way.nodes[0].id));
                if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp)
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft2Pos, way.nodes[1].id));

                //RIGHT SIDE
                Vector2 pointRight1 = new Vector2(way.nodes[0].meterPosition.x,way.nodes[0].meterPosition.z) + new Vector2(right.x,right.z) * (waySize /2.0f);
                Vector2 pointRight2 = new Vector2(way.nodes[1].meterPosition.x,way.nodes[1].meterPosition.z) + new Vector2(right.x,right.z) * (waySize /2.0f);
                Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y);
                Vector3 pointRight2Pos = new Vector3(pointRight2.x, terrain.getTerrainHeight2(pointRight2.y + bbox.meterBottom, pointRight2.x + bbox.meterLeft), pointRight2.y);
                rightSideVertexes.Add(pointRight1Pos);
                rightSideVertexes.Add(pointRight2Pos);
                if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp)
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight1Pos, way.nodes[0].id));
                if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp)
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight2Pos, way.nodes[1].id));
            }
            else
            {
                for (int i = 0; i < way.nodes.Count - 2; i++)
                {

                    Vector3 up = new Vector3(0, 1, 0);
                    Vector3 forward1 = way.nodes[i+1].meterPosition - way.nodes[i].meterPosition;
                            forward1.y = 0.0f;
                    Vector3 right1 = Vector3.Cross(up, forward1);
                    right1 = right1.normalized;
                    Vector3 left1 = -1 * right1;

                    Vector3 forward2 = way.nodes[i+2].meterPosition - way.nodes[i+1].meterPosition;
                            forward2.y = 0.0f;
                    Vector3 right2 = Vector3.Cross(up, forward2);
                    right2 = right2.normalized;
                    Vector3 left2 = -1 * right2;

                    //INITIAL POINTS ARE ADDED TO NODES3D
                    if(i == 0)
                    {
                        Vector2 pointLeft1 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f);
                        Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y);
                        leftSideVertexes.Add(pointLeft1Pos);

                        Vector2 pointRight1 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f);
                        Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y);
                        rightSideVertexes.Add(pointRight1Pos);

                    }

                    //1ST LINE LEFT
                    Vector2 p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f);
                    Vector2 p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f);

                    //2ND LINE LEFT
                    Vector2 p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f);
                    Vector2 p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f);

                    //INTERSECTION LEFT
                    Vector2 iL = new Vector2();
                    Vector3 iLPos;
                    if(!Geometry.getInfiniteLineIntersection(ref iL,p0,p1,p2,p3))
                        iLPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom,p1.x + bbox.meterLeft) ,p1.y);
                    else
                       iLPos = new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + bbox.meterBottom, iL.x + bbox.meterLeft), iL.y);

                    leftSideVertexes.Add(iLPos);
                    if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp)
                        streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iLPos, way.nodes[i + 1].id));

                    //1ST LINE RIGHT
                     p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f);
                     p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f);

                    //2ND LINE RIGHT
                     p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f);
                     p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f);

                    //INTERSECTION RIGHT
                     Vector2 iR = new Vector2();
                     Vector3 iRPos;
                    if (!Geometry.getInfiniteLineIntersection(ref iR, p0, p1, p2, p3))
                        iRPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom, p1.x + bbox.meterLeft), p1.y);
                    else
                        iRPos = new Vector3(iR.x, terrain.getTerrainHeight2(iR.y + bbox.meterBottom, iR.x + bbox.meterLeft), iR.y);

                    rightSideVertexes.Add(iRPos);
                    if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp)
                        streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iRPos, way.nodes[i + 1].id));

                    //ENDING POINTS ARE ADDEDD TO NODES3D
                    if (i == way.nodes.Count - 3)
                    {
                        Vector2 pointLeft1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f);
                        leftSideVertexes.Add(new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y));

                        Vector2 pointRight1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f);
                        rightSideVertexes.Add(new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y));
                        return;
                    }

                }
            }
        }
예제 #9
0
        private void generateOtherSide(float size, myTerrain terrain)
        {
            List<Vector3> otherside;
            List<Vector3> generatedside;

            TerrainInfo ti = terrain.terrainInfo;

            if (side == pavementSide.left)
            {
                otherside = rightSideVertexes;
                generatedside = leftSideVertexes;
            }
            else
            {
                otherside = leftSideVertexes;
                generatedside = rightSideVertexes;
            }

            if (otherside.Count == 2)
            {
                Vector3 up = Vector3.up;
                Vector3 forward = otherside[1] - otherside[0];
                forward.y = 0.0f;
                Vector3 sideVec;
                //if (side == pavementSide.left)*******************************************************
                //    sideVec =  Vector3.Cross(up, forward).normalized;
                //else
                //    sideVec =  Vector3.Cross(forward, up).normalized;
                if (side == pavementSide.left)
                    sideVec = Vector3.Cross(forward, up).normalized;
                else
                    sideVec = Vector3.Cross(up, forward).normalized;

                Vector2 point1 = new Vector2(otherside[0].x, otherside[0].z) + new Vector2(sideVec.x, sideVec.z) * size;
                Vector2 point2 = new Vector2(otherside[1].x, otherside[1].z) + new Vector2(sideVec.x, sideVec.z) * size;

                if ((point1 - point2).magnitude < 6.0f)
                    return;

                generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y));
                generatedside.Add(new Vector3(point2.x, terrain.getTerrainHeight2(point2.y + ti.shiftZ, point2.x + ti.shiftX), point2.y));

             }

            else
            {
                //Checking if side has enough length to draw a pavement
                float totalsize = 0.0f;
                for (int k = 0; k < otherside.Count - 1; k++)
                {
                    totalsize += (otherside[k + 1] - otherside[k]).magnitude;
                }
                if (totalsize <= 6.0f)
                    return;

                for (int i = 0; i < otherside.Count; i++)
                {
                    Vector3 up = Vector3.up;
                    Vector3 forward1 = otherside[i + 1] - otherside[i];
                    forward1.y = 0.0f;
                    Vector3 sideVec1;
                    //if (side == pavementSide.left)***************************************************************
                    //    sideVec1 = Vector3.Cross(up, forward1).normalized;
                    //else
                    //    sideVec1 = Vector3.Cross(forward1, up).normalized;
                    if (side == pavementSide.left)
                        sideVec1 = Vector3.Cross(forward1, up).normalized;
                    else
                        sideVec1 = Vector3.Cross(up, forward1).normalized;

                    Vector3 forward2 = otherside[i + 2] - otherside[i + 1];
                    forward2.y = 0.0f;
                    Vector3 sideVec2;
                    if (side == pavementSide.left)
                        sideVec2 = Vector3.Cross(forward2, up).normalized;
                    else
                        sideVec2 = Vector3.Cross(up, forward2).normalized;

                    //START POINT WAS ADDED TO GENERATED SIDE
                    if (i == 0)
                    {
                        Vector2 point1 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size;
                        generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y));
                    }

                    //MID POINTS WERE ADDED TO GENERATED SIDE

                    //1ST LINE
                    Vector2 p0 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size;
                    Vector2 p1 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec1.x, sideVec1.z) * size;

                    //2ND LINE
                    Vector2 p2 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec2.x, sideVec2.z) * size;
                    Vector2 p3 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size;

                    Vector2 iL = new Vector2();
                    //INTERSECTION
                    if (!Geometry.getInfiniteLineIntersection(ref iL, p0, p1, p2, p3))
                        generatedside.Add(new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + ti.shiftZ, p1.x + ti.shiftX), p1.y));
                    else
                        generatedside.Add(new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + ti.shiftZ, iL.x + ti.shiftX), iL.y));

                    //ENDING POINT WAS ADDEDD TO GENERATED SIDE
                    if (i == otherside.Count - 3)
                    {
                        Vector2 point1 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size;
                        generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y));
                        return;
                    }

                }

            }
        }
예제 #10
0
        private void generateOtherSide(float size, myTerrain terrain)
        {
            List <Vector3> otherside;
            List <Vector3> generatedside;

            TerrainInfo ti = terrain.terrainInfo;

            if (side == pavementSide.left)
            {
                otherside     = rightSideVertexes;
                generatedside = leftSideVertexes;
            }
            else
            {
                otherside     = leftSideVertexes;
                generatedside = rightSideVertexes;
            }

            if (otherside.Count == 2)
            {
                Vector3 up      = Vector3.up;
                Vector3 forward = otherside[1] - otherside[0];
                forward.y = 0.0f;
                Vector3 sideVec;
                //if (side == pavementSide.left)*******************************************************
                //    sideVec =  Vector3.Cross(up, forward).normalized;
                //else
                //    sideVec =  Vector3.Cross(forward, up).normalized;
                if (side == pavementSide.left)
                {
                    sideVec = Vector3.Cross(forward, up).normalized;
                }
                else
                {
                    sideVec = Vector3.Cross(up, forward).normalized;
                }



                Vector2 point1 = new Vector2(otherside[0].x, otherside[0].z) + new Vector2(sideVec.x, sideVec.z) * size;
                Vector2 point2 = new Vector2(otherside[1].x, otherside[1].z) + new Vector2(sideVec.x, sideVec.z) * size;

                if ((point1 - point2).magnitude < 6.0f)
                {
                    return;
                }

                generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y));
                generatedside.Add(new Vector3(point2.x, terrain.getTerrainHeight2(point2.y + ti.shiftZ, point2.x + ti.shiftX), point2.y));
            }

            else
            {
                //Checking if side has enough length to draw a pavement
                float totalsize = 0.0f;
                for (int k = 0; k < otherside.Count - 1; k++)
                {
                    totalsize += (otherside[k + 1] - otherside[k]).magnitude;
                }
                if (totalsize <= 6.0f)
                {
                    return;
                }


                for (int i = 0; i < otherside.Count; i++)
                {
                    Vector3 up       = Vector3.up;
                    Vector3 forward1 = otherside[i + 1] - otherside[i];
                    forward1.y = 0.0f;
                    Vector3 sideVec1;
                    //if (side == pavementSide.left)***************************************************************
                    //    sideVec1 = Vector3.Cross(up, forward1).normalized;
                    //else
                    //    sideVec1 = Vector3.Cross(forward1, up).normalized;
                    if (side == pavementSide.left)
                    {
                        sideVec1 = Vector3.Cross(forward1, up).normalized;
                    }
                    else
                    {
                        sideVec1 = Vector3.Cross(up, forward1).normalized;
                    }

                    Vector3 forward2 = otherside[i + 2] - otherside[i + 1];
                    forward2.y = 0.0f;
                    Vector3 sideVec2;
                    if (side == pavementSide.left)
                    {
                        sideVec2 = Vector3.Cross(forward2, up).normalized;
                    }
                    else
                    {
                        sideVec2 = Vector3.Cross(up, forward2).normalized;
                    }

                    //START POINT WAS ADDED TO GENERATED SIDE
                    if (i == 0)
                    {
                        Vector2 point1 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size;
                        generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y));
                    }

                    //MID POINTS WERE ADDED TO GENERATED SIDE

                    //1ST LINE
                    Vector2 p0 = new Vector2(otherside[i].x, otherside[i].z) + new Vector2(sideVec1.x, sideVec1.z) * size;
                    Vector2 p1 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec1.x, sideVec1.z) * size;

                    //2ND LINE
                    Vector2 p2 = new Vector2(otherside[i + 1].x, otherside[i + 1].z) + new Vector2(sideVec2.x, sideVec2.z) * size;
                    Vector2 p3 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size;

                    Vector2 iL = new Vector2();
                    //INTERSECTION
                    if (!Geometry.getInfiniteLineIntersection(ref iL, p0, p1, p2, p3))
                    {
                        generatedside.Add(new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + ti.shiftZ, p1.x + ti.shiftX), p1.y));
                    }
                    else
                    {
                        generatedside.Add(new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + ti.shiftZ, iL.x + ti.shiftX), iL.y));
                    }


                    //ENDING POINT WAS ADDEDD TO GENERATED SIDE
                    if (i == otherside.Count - 3)
                    {
                        Vector2 point1 = new Vector2(otherside[i + 2].x, otherside[i + 2].z) + new Vector2(sideVec2.x, sideVec2.z) * size;
                        generatedside.Add(new Vector3(point1.x, terrain.getTerrainHeight2(point1.y + ti.shiftZ, point1.x + ti.shiftX), point1.y));
                        return;
                    }
                }
            }
        }
예제 #11
0
        //This will be used to drape Highway to Terrain Tiles Horizontally
        private void HorizontalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
        {
            TerrainInfo ti = terrain.terrainInfo;

            for (int i = 0; i < leftSideVertexes.Count - 1; i++)
            {

                //LEFT SIDE
                Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z);
                Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z);
                //RIGHT SIDE
                Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z);
                Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z);

                Vector2 previousIntersectLeft = pointLeft1;
                Vector2 previousIntersectRight = pointRight1;

                int leftit = i + 1;
                int rightit = i + 1;
                int count = 0;

                for (int k = ti.bottomIndex, t = 0; k >= ti.topIndex; k--, t++)
                {
                    //Horizontal Line
                    Vector2 pLeft = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ);
                    Vector2 pRight = new Vector2(ti.meterPositions[t, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[t, ti.ColumnCount - 1].x - ti.shiftZ);

                    Vector2 intersectleft = new Vector2();
                    Vector2 intersectright = new Vector2();
                    bool isleft = Geometry.getLineIntersection(ref intersectleft, pLeft, pRight, pointLeft1, pointLeft2);
                    bool isright = Geometry.getLineIntersection(ref intersectright, pLeft, pRight, pointRight1, pointRight2);

                    if (isleft && isright)
                    {
                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftit++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightit++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = intersectright;
                        count++;
                    }

                    else if (isleft)
                    {
                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftit++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude;
                        Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio;
                        rightSideVertexes.Insert(rightit, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y));

                        count++;
                        rightit++;
                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = rightPointnew;

                    }
                    else if (isright)
                    {

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightit++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude;
                        Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio;
                        leftSideVertexes.Insert(leftit, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y));

                        previousIntersectLeft = leftPointnew;
                        previousIntersectRight = intersectright;
                        count++;
                        leftit++;
                    }
                    else
                        continue;

                }

                i += count;

            }
        }
예제 #12
0
        //This will be used to drape Highway to Terrain Tiles Diagonally
        private void DiagonalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
        {
            TerrainInfo ti = terrain.terrainInfo;

            for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++)
            {

                //LEFT SIDE
                Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z);
                Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z);

                //RIGHT SIDE
                Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z);
                Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z);

                int cnt = 0;

                for (int k = 0, t = 1; k < ti.ColumnCount + ti.RowCount - 3; k++, t++)
                {
                    //Diagonal Line
                    Vector2 pBottom;
                    Vector2 pTop;
                    if (t < ti.ColumnCount)
                        pTop = new Vector2(ti.meterPositions[0, t].y - ti.shiftX, ti.meterPositions[0, t].x - ti.shiftZ);
                    else
                        pTop = new Vector2(ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].x - ti.shiftZ);

                    if (t < ti.RowCount)
                        pBottom = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ);
                    else
                        pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, 1 + t - ti.RowCount].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, t + 1 - ti.RowCount].x - ti.shiftZ);

                    //LEFT SIDE INTERSECTION
                    Vector2 intersectleft = new Vector2();
                    //RIGHT SIDE INTERSECTION
                    Vector2 intersectright = new Vector2();

                    bool isLeft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2);
                    bool isRight = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2);

                    if (isLeft && isRight)
                    {
                        leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));

                        rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        cnt++;
                    }
                    else if (isLeft)
                    {
                        leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));

                        float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude;
                        Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio;
                        rightSideVertexes.Insert(i + 1, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y));
                        cnt++;
                    }

                    else if (isRight)
                    {
                        rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));

                        float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude;
                        Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio;
                        leftSideVertexes.Insert(i + 1, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y));
                        cnt++;
                    }
                }
                i += cnt;
            }
        }
예제 #13
0
        /// <summary>
        ///  Constructs the scene from given parameters
        /// </summary>
        /// <param name="OSMfilename">Full path of OSM file</param>
        /// <param name="continent">Specify Continent to download correct Heightmap from Nasa Srtm Data</param>
        /// <param name="provider">Choose mapProvider to select Texture of Terrain</param>
        public void initializeScene(string OSMfilename, HeightmapContinent _continent, MapProvider _provider)
        {
            string[] subStr = OSMfilename.Split(new char[] { '/', '\\' });
            sceneName = subStr[subStr.Length - 1];
            OSMPath   = OSMfilename;

            continent = _continent;
            provider  = _provider;

            List <Way> WayListforHighway  = new List <Way>();
            List <Way> WayListforBuilding = new List <Way>();

            InitialConfigLoader configloader = new InitialConfigLoader();

            var stopwatch = new System.Diagnostics.Stopwatch();

            stopwatch.Start();

            OSMparser parser = new OSMparser();

            scenebbox = parser.readBBox(OSMfilename);
            scenebbox = editbbox(scenebbox);
            config    = configloader.loadInitialConfig();


            HeightmapLoader heightMap = new HeightmapLoader(scenebbox, continent);

            terrain = new myTerrain(heightMap, scenebbox, OSMfilename, provider);

            stopwatch.Stop();
            Debug.Log("<color=blue>TERRAIN RENDER TIME:</color>" + stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();

            osmxml = parser.parseOSM(OSMfilename);
            assignNodePositions();

            stopwatch.Stop();
            Debug.Log("<color=blue>OSM PARSING TIME:</color>" + stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();


            defaultObject3DList = DefaultObject3DHandler.drawDefaultObjects(osmxml.defaultobject3DList);

            stopwatch.Stop();
            Debug.Log("<color=blue>3D OBJECT RENDER TIME:</color>" + stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();


            for (int k = 0; k < osmxml.wayList.Count; k++)
            {
                Way w = osmxml.wayList[k];

                switch (w.type)
                {
                case ItemEnumerator.wayType.building:
                    WayListforBuilding.Add(w);
                    break;

                case ItemEnumerator.wayType.highway:
                    WayListforHighway.Add(w);
                    break;

                case ItemEnumerator.wayType.area:
                    break;

                case ItemEnumerator.wayType.barrier:
                    barrierList.Add(new Barrier(w, config.barrierConfig));
                    break;

                case ItemEnumerator.wayType.river:
                    highwayList.Add(new Highway(w, config.highwayConfig, terrain));
                    break;

                case ItemEnumerator.wayType.none:
                    break;
                }
            }

            stopwatch.Stop();
            Debug.Log("<color=blue>ITEM ENUMERATING TIME:</color>" + stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();

            highwayModeller = new HighwayModeller(WayListforHighway, terrain, config.highwayConfig);
            highwayModeller.renderHighwayList();
            highwayModeller.renderPavementList();
            highwayList  = highwayModeller.highwayList;
            pavementList = highwayModeller.pavementList;

            stopwatch.Stop();
            Debug.Log("<color=blue>HIGHWAY RENDERING TIME:</color>" + stopwatch.ElapsedMilliseconds);
            stopwatch.Reset();
            stopwatch.Start();

            BuildingListModeller buildingListModeller = new BuildingListModeller(WayListforBuilding, osmxml.buildingRelations, config.buildingConfig);

            buildingListModeller.renderBuildingList();
            buildingList = buildingListModeller.buildingList;

            stopwatch.Stop();
            Debug.Log("<color=blue>BUILDING RENDERING TIME:</color>" + stopwatch.ElapsedMilliseconds);

            Debug.Log("<color=red>Scene Info:</color> BuildingCount:" + buildingList.Count.ToString() + " HighwayCount:" + highwayList.Count);
        }
예제 #14
0
        //This will be used for generating initial vertexes
        public void generateInitial3Dway(myTerrain terrain)
        {
            leftSideVertexes  = new List <Vector3>();
            rightSideVertexes = new List <Vector3>();

            if (way.nodes.Count == 2)
            {
                Vector3 up      = new Vector3(0, 1, 0);
                Vector3 forward = way.nodes[1].meterPosition - way.nodes[0].meterPosition;
                forward.y = 0.0f;
                //Vector3 right = Vector3.Cross(forward ,up);**********************************************
                Vector3 right = Vector3.Cross(up, forward);
                right = right.normalized;
                Vector3 left = -1 * right;


                //LEFT SIDE
                Vector2 pointLeft1    = new Vector2(way.nodes[0].meterPosition.x, way.nodes[0].meterPosition.z) + new Vector2(left.x, left.z) * (waySize / 2.0f);
                Vector2 pointLeft2    = new Vector2(way.nodes[1].meterPosition.x, way.nodes[1].meterPosition.z) + new Vector2(left.x, left.z) * (waySize / 2.0f);
                Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y);
                Vector3 pointLeft2Pos = new Vector3(pointLeft2.x, terrain.getTerrainHeight2(pointLeft2.y + bbox.meterBottom, pointLeft2.x + bbox.meterLeft), pointLeft2.y);
                leftSideVertexes.Add(pointLeft1Pos);
                leftSideVertexes.Add(pointLeft2Pos);
                if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp)
                {
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft1Pos, way.nodes[0].id));
                }
                if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp)
                {
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointLeft2Pos, way.nodes[1].id));
                }

                //RIGHT SIDE
                Vector2 pointRight1    = new Vector2(way.nodes[0].meterPosition.x, way.nodes[0].meterPosition.z) + new Vector2(right.x, right.z) * (waySize / 2.0f);
                Vector2 pointRight2    = new Vector2(way.nodes[1].meterPosition.x, way.nodes[1].meterPosition.z) + new Vector2(right.x, right.z) * (waySize / 2.0f);
                Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y);
                Vector3 pointRight2Pos = new Vector3(pointRight2.x, terrain.getTerrainHeight2(pointRight2.y + bbox.meterBottom, pointRight2.x + bbox.meterLeft), pointRight2.y);
                rightSideVertexes.Add(pointRight1Pos);
                rightSideVertexes.Add(pointRight2Pos);
                if (way.nodes[0].type == ItemEnumerator.nodeType.StreetLamp)
                {
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight1Pos, way.nodes[0].id));
                }
                if (way.nodes[1].type == ItemEnumerator.nodeType.StreetLamp)
                {
                    streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(pointRight2Pos, way.nodes[1].id));
                }
            }
            else
            {
                for (int i = 0; i < way.nodes.Count - 2; i++)
                {
                    Vector3 up       = new Vector3(0, 1, 0);
                    Vector3 forward1 = way.nodes[i + 1].meterPosition - way.nodes[i].meterPosition;
                    forward1.y = 0.0f;
                    Vector3 right1 = Vector3.Cross(up, forward1);
                    right1 = right1.normalized;
                    Vector3 left1 = -1 * right1;

                    Vector3 forward2 = way.nodes[i + 2].meterPosition - way.nodes[i + 1].meterPosition;
                    forward2.y = 0.0f;
                    Vector3 right2 = Vector3.Cross(up, forward2);
                    right2 = right2.normalized;
                    Vector3 left2 = -1 * right2;

                    //INITIAL POINTS ARE ADDED TO NODES3D
                    if (i == 0)
                    {
                        Vector2 pointLeft1    = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f);
                        Vector3 pointLeft1Pos = new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y);
                        leftSideVertexes.Add(pointLeft1Pos);

                        Vector2 pointRight1    = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f);
                        Vector3 pointRight1Pos = new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y);
                        rightSideVertexes.Add(pointRight1Pos);
                    }

                    //1ST LINE LEFT
                    Vector2 p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f);
                    Vector2 p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left1.x, left1.z) * (waySize / 2.0f);

                    //2ND LINE LEFT
                    Vector2 p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f);
                    Vector2 p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f);

                    //INTERSECTION LEFT
                    Vector2 iL = new Vector2();
                    Vector3 iLPos;
                    if (!Geometry.getInfiniteLineIntersection(ref iL, p0, p1, p2, p3))
                    {
                        iLPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom, p1.x + bbox.meterLeft), p1.y);
                    }
                    else
                    {
                        iLPos = new Vector3(iL.x, terrain.getTerrainHeight2(iL.y + bbox.meterBottom, iL.x + bbox.meterLeft), iL.y);
                    }

                    leftSideVertexes.Add(iLPos);
                    if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp)
                    {
                        streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iLPos, way.nodes[i + 1].id));
                    }

                    //1ST LINE RIGHT
                    p0 = new Vector2(way.nodes[i].meterPosition.x, way.nodes[i].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f);
                    p1 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right1.x, right1.z) * (waySize / 2.0f);

                    //2ND LINE RIGHT
                    p2 = new Vector2(way.nodes[i + 1].meterPosition.x, way.nodes[i + 1].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f);
                    p3 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f);


                    //INTERSECTION RIGHT
                    Vector2 iR = new Vector2();
                    Vector3 iRPos;
                    if (!Geometry.getInfiniteLineIntersection(ref iR, p0, p1, p2, p3))
                    {
                        iRPos = new Vector3(p1.x, terrain.getTerrainHeight2(p1.y + bbox.meterBottom, p1.x + bbox.meterLeft), p1.y);
                    }
                    else
                    {
                        iRPos = new Vector3(iR.x, terrain.getTerrainHeight2(iR.y + bbox.meterBottom, iR.x + bbox.meterLeft), iR.y);
                    }

                    rightSideVertexes.Add(iRPos);
                    if (way.nodes[i + 1].type == ItemEnumerator.nodeType.StreetLamp)
                    {
                        streetLampList.Add(DefaultObject3DHandler.drawStreetLamp(iRPos, way.nodes[i + 1].id));
                    }

                    //ENDING POINTS ARE ADDEDD TO NODES3D
                    if (i == way.nodes.Count - 3)
                    {
                        Vector2 pointLeft1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(left2.x, left2.z) * (waySize / 2.0f);
                        leftSideVertexes.Add(new Vector3(pointLeft1.x, terrain.getTerrainHeight2(pointLeft1.y + bbox.meterBottom, pointLeft1.x + bbox.meterLeft), pointLeft1.y));

                        Vector2 pointRight1 = new Vector2(way.nodes[i + 2].meterPosition.x, way.nodes[i + 2].meterPosition.z) + new Vector2(right2.x, right2.z) * (waySize / 2.0f);
                        rightSideVertexes.Add(new Vector3(pointRight1.x, terrain.getTerrainHeight2(pointRight1.y + bbox.meterBottom, pointRight1.x + bbox.meterLeft), pointRight1.y));
                        return;
                    }
                }
            }
        }
        //This will be used to drape Highway to Terrain Tiles Horizontally
        private void HorizontalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
        {
            TerrainInfo ti = terrain.terrainInfo;

            for (int i = 0; i < leftSideVertexes.Count - 1; i++)
            {

                //LEFT SIDE
                Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z);
                Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z);
                //RIGHT SIDE
                Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z);
                Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z);

                Vector2 previousIntersectLeft = pointLeft1;
                Vector2 previousIntersectRight = pointRight1;

                int leftit = i + 1;
                int rightit = i + 1;
                int count = 0;

                for (int k = ti.bottomIndex, t = 0; k >= ti.topIndex; k--, t++)
                {
                    //Horizontal Line
                    Vector2 pLeft = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ);
                    Vector2 pRight = new Vector2(ti.meterPositions[t, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[t, ti.ColumnCount - 1].x - ti.shiftZ);

                    Vector2 intersectleft = new Vector2();
                    Vector2 intersectright = new Vector2();
                    bool isleft = Geometry.getLineIntersection(ref intersectleft, pLeft, pRight, pointLeft1, pointLeft2);
                    bool isright = Geometry.getLineIntersection(ref intersectright, pLeft, pRight, pointRight1, pointRight2);

                    if (isleft && isright)
                    {
                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftit++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightit++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = intersectright;
                        count++;
                    }

                    else if (isleft)
                    {
                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftit, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftit++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude;
                        Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio;
                        rightSideVertexes.Insert(rightit, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y));

                        count++;
                        rightit++;
                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = rightPointnew;

                    }
                    else if (isright)
                    {

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightit, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightit++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude;
                        Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio;
                        leftSideVertexes.Insert(leftit, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y));

                        previousIntersectLeft = leftPointnew;
                        previousIntersectRight = intersectright;
                        count++;
                        leftit++;
                    }
                    else
                        continue;

                }

                i += count;

            }
        }
        //This will be used to drape Highway to Terrain Tiles Diagonally
        private void DiagonalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
        {
            TerrainInfo ti = terrain.terrainInfo;

            for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++)
            {

                //LEFT SIDE
                Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z);
                Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z);

                //RIGHT SIDE
                Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z);
                Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z);

                int cnt = 0;

                for (int k = 0, t = 1; k < ti.ColumnCount + ti.RowCount - 3; k++, t++)
                {
                    //Diagonal Line
                    Vector2 pBottom;
                    Vector2 pTop;
                    if (t < ti.ColumnCount)
                        pTop = new Vector2(ti.meterPositions[0, t].y - ti.shiftX, ti.meterPositions[0, t].x - ti.shiftZ);
                    else
                        pTop = new Vector2(ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].y - ti.shiftX, ti.meterPositions[1 + t - ti.ColumnCount, ti.ColumnCount - 1].x - ti.shiftZ);

                    if (t < ti.RowCount)
                        pBottom = new Vector2(ti.meterPositions[t, 0].y - ti.shiftX, ti.meterPositions[t, 0].x - ti.shiftZ);
                    else
                        pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, 1 + t - ti.RowCount].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, t + 1 - ti.RowCount].x - ti.shiftZ);

                    //LEFT SIDE INTERSECTION
                    Vector2 intersectleft = new Vector2();
                    //RIGHT SIDE INTERSECTION
                    Vector2 intersectright = new Vector2();

                    bool isLeft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2);
                    bool isRight = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2);

                    if (isLeft && isRight)
                    {
                        leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));

                        rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        cnt++;
                    }
                    else if (isLeft)
                    {
                        leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));

                        float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude;
                        Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio;
                        rightSideVertexes.Insert(i + 1, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y));
                        cnt++;
                    }

                    else if (isRight)
                    {
                        rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));

                        float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude;
                        Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio;
                        leftSideVertexes.Insert(i + 1, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y));
                        cnt++;
                    }
                }
                i += cnt;
            }
        }
        //This will be used to drape Highway to Terrain Tiles Vertically
        private void VerticalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
        {
            TerrainInfo ti = terrain.terrainInfo;

            for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++)
            {
                Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z);
                Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z);

                Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z);
                Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z);

                int cnt = 0;
                int leftiterator = i + 1;
                int rightiterator = i + 1;

                Vector2 previousIntersectLeft = pointLeft1;
                Vector2 previousIntersectRight = pointRight1;

                for (int k = ti.leftIndex, z = 0; k <= ti.rightIndex; k++, z++)
                {
                    //Vertical Terrain Line
                    Vector2 pTop = new Vector2(ti.meterPositions[0, z].y - ti.shiftX, ti.meterPositions[0, z].x - ti.shiftZ);
                    Vector2 pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, z].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, z].x - ti.shiftZ);

                    Vector2 intersectleft = new Vector2();
                    Vector2 intersectright = new Vector2();
                    bool isleft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2);
                    bool isright = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2);

                    if (isleft && isright)
                    {

                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftiterator++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightiterator++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = intersectright;
                        cnt++;
                    }
                    else if (isleft)
                    {

                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftiterator++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude;
                        Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio;

                        rightSideVertexes.Insert(rightiterator, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y));
                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = rightPointnew;
                        rightiterator++;
                        cnt++;

                    }
                    else if (isright)
                    {

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightiterator++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude;
                        Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio;

                        leftSideVertexes.Insert(leftiterator, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y));
                        previousIntersectRight = intersectright;
                        previousIntersectLeft = leftPointnew;
                        leftiterator++;
                        cnt++;
                    }

                }

                i += cnt;

            }
        }
예제 #18
0
        //This will be used to drape Highway to Terrain Tiles Vertically
        private void VerticalDrape(myTerrain terrain, List<Vector3> leftSideVertexes, List<Vector3> rightSideVertexes)
        {
            TerrainInfo ti = terrain.terrainInfo;

            for (int i = 0; i < (int)leftSideVertexes.Count - 1; i++)
            {
                Vector2 pointLeft1 = new Vector2(leftSideVertexes[i].x, leftSideVertexes[i].z);
                Vector2 pointLeft2 = new Vector2(leftSideVertexes[i + 1].x, leftSideVertexes[i + 1].z);

                Vector2 pointRight1 = new Vector2(rightSideVertexes[i].x, rightSideVertexes[i].z);
                Vector2 pointRight2 = new Vector2(rightSideVertexes[i + 1].x, rightSideVertexes[i + 1].z);

                int cnt = 0;
                int leftiterator = i + 1;
                int rightiterator = i + 1;

                Vector2 previousIntersectLeft = pointLeft1;
                Vector2 previousIntersectRight = pointRight1;

                for (int k = ti.leftIndex, z = 0; k <= ti.rightIndex; k++, z++)
                {
                    //Vertical Terrain Line
                    Vector2 pTop = new Vector2(ti.meterPositions[0, z].y - ti.shiftX, ti.meterPositions[0, z].x - ti.shiftZ);
                    Vector2 pBottom = new Vector2(ti.meterPositions[ti.RowCount - 1, z].y - ti.shiftX, ti.meterPositions[ti.RowCount - 1, z].x - ti.shiftZ);

                    Vector2 intersectleft = new Vector2();
                    Vector2 intersectright = new Vector2();
                    bool isleft = Geometry.getLineIntersection(ref intersectleft, pTop, pBottom, pointLeft1, pointLeft2);
                    bool isright = Geometry.getLineIntersection(ref intersectright, pTop, pBottom, pointRight1, pointRight2);

                    if (isleft && isright)
                    {

                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftiterator++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightiterator++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = intersectright;
                        cnt++;
                    }
                    else if (isleft)
                    {

                        if ((intersectleft - pointLeft1).magnitude > (previousIntersectLeft - pointLeft1).magnitude)
                        {
                            leftSideVertexes.Insert(leftiterator, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                            leftiterator++;
                        }
                        else
                        {
                            leftSideVertexes.Insert(i + 1, new Vector3(intersectleft.x, terrain.getTerrainHeight2(intersectleft.y + ti.shiftZ, intersectleft.x + ti.shiftX), intersectleft.y));
                        }

                        float ratio = (pointLeft1 - intersectleft).magnitude / (pointLeft1 - pointLeft2).magnitude;
                        Vector2 rightPointnew = pointRight1 + (pointRight2 - pointRight1) * ratio;

                        rightSideVertexes.Insert(rightiterator, new Vector3(rightPointnew.x, terrain.getTerrainHeight2(rightPointnew.y + ti.shiftZ, rightPointnew.x + ti.shiftX), rightPointnew.y));
                        previousIntersectLeft = intersectleft;
                        previousIntersectRight = rightPointnew;
                        rightiterator++;
                        cnt++;

                    }
                    else if (isright)
                    {

                        if ((intersectright - pointRight1).magnitude > (previousIntersectRight - pointRight1).magnitude)
                        {
                            rightSideVertexes.Insert(rightiterator, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                            rightiterator++;
                        }
                        else
                        {
                            rightSideVertexes.Insert(i + 1, new Vector3(intersectright.x, terrain.getTerrainHeight2(intersectright.y + ti.shiftZ, intersectright.x + ti.shiftX), intersectright.y));
                        }

                        float ratio = (pointRight1 - intersectright).magnitude / (pointRight1 - pointRight2).magnitude;
                        Vector2 leftPointnew = pointLeft1 + (pointLeft2 - pointLeft1) * ratio;

                        leftSideVertexes.Insert(leftiterator, new Vector3(leftPointnew.x, terrain.getTerrainHeight2(leftPointnew.y + ti.shiftZ, leftPointnew.x + ti.shiftX), leftPointnew.y));
                        previousIntersectRight = intersectright;
                        previousIntersectLeft = leftPointnew;
                        leftiterator++;
                        cnt++;
                    }

                }

                i += cnt;

            }
        }
예제 #19
0
        /// <summary>
        /// Load urban scene using a save file
        /// </summary>
        /// <param name="save"> Save file object </param>
        public void loadProject(SceneSave save)
        {
            List <Way> WayListforHighway  = new List <Way>();
            List <Way> WayListforBuilding = new List <Way>();

            InitialConfigLoader configloader = new InitialConfigLoader();

            OSMPath = save.osmPath;
            OSMparser parser = new OSMparser();

            scenebbox = parser.readBBox(save.osmPath);
            scenebbox = editbbox(scenebbox);
            config    = configloader.loadInitialConfig(); //--> Maybe it is better to include config to SaveProject file

            HeightmapLoader heightMap = new HeightmapLoader(scenebbox, save.continent);

            terrain = new myTerrain(heightMap, scenebbox, save.osmPath, save.provider);
            osmxml  = parser.parseOSM(save.osmPath);
            assignNodePositions();

            defaultObject3DList = DefaultObject3DHandler.drawDefaultObjects(osmxml.defaultobject3DList);

            LoadExternalOBJ objloader = new LoadExternalOBJ();

            //3D OBJECT LOAD
            for (int i = 0; i < save.objectSaveList.Count; i++)
            {
                Object3D obj = new Object3D();
                obj.name = save.objectSaveList[i].name;

                if (save.objectSaveList[i].type == ObjectType.External)
                {
                    obj.object3D = objloader.loadOBJ(save.objectSaveList[i].resourcePath);
                }
                else
                {
                    obj.object3D = (GameObject)MonoBehaviour.Instantiate(Resources.Load(save.objectSaveList[i].resourcePath));
                }
                obj.object3D.AddComponent <Object3dMouseHandler>();
                obj.resourcePath = save.objectSaveList[i].resourcePath;
                obj.object3D.transform.position   = save.objectSaveList[i].translate;
                obj.object3D.transform.localScale = save.objectSaveList[i].scale;
                Quaternion quat = new Quaternion();
                quat.eulerAngles = save.objectSaveList[i].rotate;
                obj.object3D.transform.rotation = quat;
                obj.object3D.name = obj.name;
                obj.object3D.tag  = "3DObject";
                object3DList.Add(obj);
            }

            for (int k = 0; k < osmxml.wayList.Count; k++)
            {
                Way w = osmxml.wayList[k];

                switch (w.type)
                {
                case ItemEnumerator.wayType.building:
                    WayListforBuilding.Add(w);
                    break;

                case ItemEnumerator.wayType.highway:
                    WayListforHighway.Add(w);
                    break;

                case ItemEnumerator.wayType.area:
                    break;

                case ItemEnumerator.wayType.barrier:
                    barrierList.Add(new Barrier(w, config.barrierConfig));
                    break;

                case ItemEnumerator.wayType.river:
                    highwayList.Add(new Highway(w, config.highwayConfig, terrain));
                    break;

                case ItemEnumerator.wayType.none:
                    break;
                }
            }

            highwayModeller = new HighwayModeller(WayListforHighway, terrain, config.highwayConfig, save.highwaySaveList);
            highwayModeller.renderHighwayList();
            highwayModeller.renderPavementList();
            highwayList  = highwayModeller.highwayList;
            pavementList = highwayModeller.pavementList;

            BuildingListModeller buildingListModeller = new BuildingListModeller(WayListforBuilding, osmxml.buildingRelations, config.buildingConfig, save.buildingSaveList);

            buildingListModeller.renderBuildingList();
            buildingList = buildingListModeller.buildingList;

            if (save.controller == null)
            {
                return;
            }

            if (save.controller.controllerType == ControllerSave.ControllerType.CameraVan)
            {
                Transform        mainCamera    = GameObject.Find("Main Camera").transform;
                CameraController camController = mainCamera.GetComponent <CameraController>();

                controller = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Car/PolimiCameraCar/CameraVan"));
                controller.AddComponent <CameraVanMouseHandler>();
                controller.tag  = "CameraVan";
                controller.name = "Camera Van";
                controller.transform.position = mainCamera.position + mainCamera.forward * 10.0f;
                controller.GetComponent <Rigidbody>().useGravity = false;
                camController.target = controller.transform;
            }

            else
            {
                Transform        mainCamera    = GameObject.Find("Main Camera").transform;
                CameraController camController = mainCamera.GetComponent <CameraController>();

                controller = (GameObject)GameObject.Instantiate(Resources.Load("Prefabs/Ethan/ThirdPersonController"));
                controller.AddComponent <CameraVanMouseHandler>();
                controller.tag  = "CameraVan";
                controller.name = "Third Person (Ethan)";
                controller.transform.position = mainCamera.position + mainCamera.forward * 10.0f;
                camController.target          = controller.transform;
            }

            controller.transform.position = save.controller.controllerPosition;
            Quaternion controllerQuat = new Quaternion();

            controllerQuat.eulerAngles    = save.controller.controllerRotation;
            controller.transform.rotation = controllerQuat;

            CameraVanEdit cve = GameObject.Find("Canvas").transform.Find("CameraVanEdit").GetComponent <CameraVanEdit>();

            cve.cameraList   = save.controller.convertBackToCamList(save.controller.cameraSettings);
            cve.laserScanner = save.controller.convertBackToLaser(save.controller.laserSetting);
        }