Ejemplo n.º 1
0
        public myTerrain(HeightmapLoader _heightmap, BBox _bbox, string _OSMfileName, MapProvider _provider)
        {
            OSMfileName = _OSMfileName;
            heightmap = _heightmap;
            scenebbox = _bbox;
            textureType = _provider;

            terrainObject = new GameObject("Terrain");
            gridList = new List<GameObject>();

            int leftIndex = (int)Math.Floor((scenebbox.left - (float)Math.Floor(scenebbox.left)) * 1200.0f);
            int rightIndex = (int)Math.Ceiling((scenebbox.right - (float)Math.Floor(scenebbox.right)) * 1200.0f);

            if ((rightIndex - leftIndex) % 2 != 0)
                rightIndex++;

            int topIndex, bottomIndex;

            topIndex = (int)Math.Floor(((float)Math.Ceiling(scenebbox.top) - scenebbox.top) * 1200.0f);
            bottomIndex = (int)Math.Ceiling(((float)Math.Ceiling(scenebbox.bottom) - scenebbox.bottom) * 1200.0f);

            if ((bottomIndex - topIndex) % 2 != 0)
                topIndex -= 1;

            Debug.Log("<color=yellow>TERRAIN:</color>" + "left:" + leftIndex + " right:" + rightIndex
                       + " bottom:" + bottomIndex + " top:" + topIndex);

            float[,] myTerrainHeights = new float[1 + bottomIndex - topIndex, 1 + rightIndex - leftIndex ];
            Vector2[,] meterPositions = new Vector2[1 + bottomIndex - topIndex, 1 + rightIndex - leftIndex ];
            Geography geo = new Geography();

            float left = (float)Math.Floor(scenebbox.left) + (leftIndex / 1200.0f);
            float right = (float)Math.Floor(scenebbox.left) + (rightIndex / 1200.0f);
            float top = (float)Math.Ceiling(scenebbox.top) - (topIndex / 1200.0f);
            float bottom = (float)Math.Ceiling(scenebbox.top) - (bottomIndex / 1200.0f);

            for (int i = 0; i <= bottomIndex - topIndex; i++)
            {
                for (int j = 0; j <= rightIndex - leftIndex; j++)
                {
                    myTerrainHeights[i, j] = heightmap.heightmap[topIndex + i, leftIndex + j];
                    meterPositions[i , j] =  geo.LatLontoMeters(top - (i / 1200.0f), left + (j / 1200.0f));
                }
            }

            terrainInfo.leftIndex = leftIndex;
            terrainInfo.rightIndex = rightIndex;
            terrainInfo.bottomIndex = bottomIndex;
            terrainInfo.topIndex = topIndex;
            terrainInfo.terrainHeights = myTerrainHeights;
            terrainInfo.meterPositions = meterPositions;
            terrainInfo.ColumnCount = 1 + rightIndex - leftIndex;
            terrainInfo.RowCount = 1 + bottomIndex - topIndex;

            terrainInfo.terrainBBox = new BBox();
            terrainInfo.terrainBBox.left = left;
            terrainInfo.terrainBBox.top = top;
            terrainInfo.terrainBBox.bottom = bottom;
            terrainInfo.terrainBBox.right = right;
            Vector2 bottmleft = geo.LatLontoMeters(bottom, left);
            Vector2 topright = geo.LatLontoMeters(top, right);
            terrainInfo.terrainBBox.meterBottom = bottmleft.x;
            terrainInfo.terrainBBox.meterLeft = bottmleft.y;
            terrainInfo.terrainBBox.meterTop = topright.x;
            terrainInfo.terrainBBox.meterRight = topright.y;

            terrainInfo.shiftX = scenebbox.meterLeft;
            terrainInfo.shiftZ = scenebbox.meterBottom;

            Debug.Log("<color=yellow>TERRAIN:</color> ColumnCount:" + terrainInfo.ColumnCount + " RowCount:" + terrainInfo.RowCount);

               // drawBoundsforDebug();

            for (int i = 0; i < terrainInfo.RowCount-1; i += 2)
            {
                for (int j = 0; j < terrainInfo.ColumnCount-1; j += 2)
                    createGrid(i,j);
            }

            drawUnderPlates();
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public myTerrain(HeightmapLoader _heightmap, BBox _bbox, string _OSMfileName, MapProvider _provider)
        {
            OSMfileName = _OSMfileName;
            heightmap   = _heightmap;
            scenebbox   = _bbox;
            textureType = _provider;

            terrainObject = new GameObject("Terrain");
            gridList      = new List <GameObject>();

            int leftIndex  = (int)Math.Floor((scenebbox.left - (float)Math.Floor(scenebbox.left)) * 1200.0f);
            int rightIndex = (int)Math.Ceiling((scenebbox.right - (float)Math.Floor(scenebbox.right)) * 1200.0f);

            if ((rightIndex - leftIndex) % 2 != 0)
            {
                rightIndex++;
            }

            int topIndex, bottomIndex;


            topIndex    = (int)Math.Floor(((float)Math.Ceiling(scenebbox.top) - scenebbox.top) * 1200.0f);
            bottomIndex = (int)Math.Ceiling(((float)Math.Ceiling(scenebbox.bottom) - scenebbox.bottom) * 1200.0f);

            if ((bottomIndex - topIndex) % 2 != 0)
            {
                topIndex -= 1;
            }



            Debug.Log("<color=yellow>TERRAIN:</color>" + "left:" + leftIndex + " right:" + rightIndex
                      + " bottom:" + bottomIndex + " top:" + topIndex);


            float[,] myTerrainHeights = new float[1 + bottomIndex - topIndex, 1 + rightIndex - leftIndex];
            Vector2[,] meterPositions = new Vector2[1 + bottomIndex - topIndex, 1 + rightIndex - leftIndex];
            Geography geo = new Geography();

            float left   = (float)Math.Floor(scenebbox.left) + (leftIndex / 1200.0f);
            float right  = (float)Math.Floor(scenebbox.left) + (rightIndex / 1200.0f);
            float top    = (float)Math.Ceiling(scenebbox.top) - (topIndex / 1200.0f);
            float bottom = (float)Math.Ceiling(scenebbox.top) - (bottomIndex / 1200.0f);

            for (int i = 0; i <= bottomIndex - topIndex; i++)
            {
                for (int j = 0; j <= rightIndex - leftIndex; j++)
                {
                    myTerrainHeights[i, j] = heightmap.heightmap[topIndex + i, leftIndex + j];
                    meterPositions[i, j]   = geo.LatLontoMeters(top - (i / 1200.0f), left + (j / 1200.0f));
                }
            }


            terrainInfo.leftIndex      = leftIndex;
            terrainInfo.rightIndex     = rightIndex;
            terrainInfo.bottomIndex    = bottomIndex;
            terrainInfo.topIndex       = topIndex;
            terrainInfo.terrainHeights = myTerrainHeights;
            terrainInfo.meterPositions = meterPositions;
            terrainInfo.ColumnCount    = 1 + rightIndex - leftIndex;
            terrainInfo.RowCount       = 1 + bottomIndex - topIndex;

            terrainInfo.terrainBBox        = new BBox();
            terrainInfo.terrainBBox.left   = left;
            terrainInfo.terrainBBox.top    = top;
            terrainInfo.terrainBBox.bottom = bottom;
            terrainInfo.terrainBBox.right  = right;
            Vector2 bottmleft = geo.LatLontoMeters(bottom, left);
            Vector2 topright  = geo.LatLontoMeters(top, right);

            terrainInfo.terrainBBox.meterBottom = bottmleft.x;
            terrainInfo.terrainBBox.meterLeft   = bottmleft.y;
            terrainInfo.terrainBBox.meterTop    = topright.x;
            terrainInfo.terrainBBox.meterRight  = topright.y;

            terrainInfo.shiftX = scenebbox.meterLeft;
            terrainInfo.shiftZ = scenebbox.meterBottom;

            Debug.Log("<color=yellow>TERRAIN:</color> ColumnCount:" + terrainInfo.ColumnCount + " RowCount:" + terrainInfo.RowCount);

            // drawBoundsforDebug();

            for (int i = 0; i < terrainInfo.RowCount - 1; i += 2)
            {
                for (int j = 0; j < terrainInfo.ColumnCount - 1; j += 2)
                {
                    createGrid(i, j);
                }
            }

            drawUnderPlates();
        }
Ejemplo n.º 4
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);
        }