public void clickSave()
        {
            InitialConfigLoader   loader = new InitialConfigLoader();
            InitialConfigurations config = loader.loadInitialConfig();

            //Create new Building Config Part
            BuildingConfigurations newbuildingconfig = new BuildingConfigurations();

            InputField min = buildingMenu.transform.Find("Panel").Find("HeightComponent").Find("InputField_Min").GetComponent <InputField>();

            newbuildingconfig.minheight = float.Parse(min.text);
            InputField max = buildingMenu.transform.Find("Panel").Find("HeightComponent").Find("InputField_Max").GetComponent <InputField>();

            newbuildingconfig.maxheight    = float.Parse(max.text);
            newbuildingconfig.defaultSkins = materialList;

            Transform contentPanel = buildingMenu.transform.Find("Panel").Find("ScrollRect").Find("Content Panel");
            int       index        = 0;

            foreach (Transform child in contentPanel)
            {
                Toggle t = child.Find("Panel").Find("Toggle").GetComponent <Toggle>();
                newbuildingconfig.defaultSkins[index].isActive = t.isOn;
                index++;
            }


            config.buildingConfig = newbuildingconfig;

            loader.saveInitialConfig(Path.Combine(Application.persistentDataPath, "ConfigFiles/initialConfig.xml"), config);

            buildingMenu.SetActive(false);
        }
        private void loadConfig()
        {
            InitialConfigLoader   loader = new InitialConfigLoader();
            InitialConfigurations config = loader.loadInitialConfig();

            configLoadHelper(config);
        }
        public void ClickSave()
        {
            InitialConfigLoader   loader = new InitialConfigLoader();
            InitialConfigurations config = loader.loadInitialConfig();

            List <BarrierConfigurations> newBarrierConfig = new List <BarrierConfigurations>();

            for (int i = 0; i < config.barrierConfig.Count; i++)
            {
                string GOname   = "BarrierSkin " + i;
                var    skinitem = barrierMenu.transform.Find("Panel").Find("Scroll Rect").Find("Content Panel").Find(GOname).Find("Panel");

                BarrierConfigurations barrieritem = new BarrierConfigurations();

                barrieritem.name   = skinitem.Find("TextName").GetComponent <Text>().text;
                barrieritem.width  = float.Parse(skinitem.Find("InputField_Thickness").GetComponent <InputField>().text);
                barrieritem.height = float.Parse(skinitem.Find("InputField_Height").GetComponent <InputField>().text);
                barrieritem.Path   = materialPaths[i];
                if (isTextureChanged[i])
                {
                    Material  mat      = (Material)Resources.Load(barrieritem.Path);
                    byte[]    fileData = File.ReadAllBytes(texturePaths[i]);
                    Texture2D tex      = new Texture2D(2, 2);
                    tex.LoadImage(fileData);
                    mat.mainTexture      = tex;
                    mat.mainTextureScale = new Vector2(5, 1);
                }
            }

            config.barrierConfig = newBarrierConfig;
            loader.saveInitialConfig(Path.Combine(Application.persistentDataPath, "ConfigFiles/initialConfig.xml"), config);


            barrierMenu.SetActive(false);
        }
        public void ClickReset()
        {
            InitialConfigLoader   loader    = new InitialConfigLoader();
            InitialConfigurations config    = loader.loadInitialConfig();
            InitialConfigurations tmpConfig = loader.fillConfig();

            config.highwayConfig = tmpConfig.highwayConfig;
            configLoadHelper(config);
        }
        public void clickReset()
        {
            InitialConfigLoader   loader    = new InitialConfigLoader();
            InitialConfigurations config    = loader.loadInitialConfig();
            InitialConfigurations tmpconfig = loader.fillConfig();

            config.buildingConfig = tmpconfig.buildingConfig;
            configLoadHelper(config);
        }
        public void ClickSave()
        {
            InitialConfigLoader   loader = new InitialConfigLoader();
            InitialConfigurations config = loader.loadInitialConfig();

            List <HighwayConfigurations> newHighwayConfig = new List <HighwayConfigurations>();

            for (int i = 0; i < config.highwayConfig.Count; i++)
            {
                string GOname   = "HighwaySkin " + i;
                var    skinitem = highwayMenu.transform.Find("Panel").Find("Scroll Rect").Find("Content Panel").Find(GOname).Find("Panel");

                HighwayConfigurations highwayitem = new HighwayConfigurations();

                highwayitem.type              = skinitem.Find("Text_Type").GetComponent <Text>().text;
                highwayitem.size              = float.Parse(skinitem.Find("InputField_Width").GetComponent <InputField>().text);
                highwayitem.leftSidewalk      = skinitem.Find("ToggleLeftSideWalk").GetComponent <Toggle>().isOn;
                highwayitem.rightSidewalk     = skinitem.Find("ToggleRightSideWalk").GetComponent <Toggle>().isOn;
                highwayitem.leftSidewalkSize  = float.Parse(skinitem.Find("InputField LeftSize").GetComponent <InputField>().text);
                highwayitem.rightSidewalkSize = float.Parse(skinitem.Find("InputField RightSize").GetComponent <InputField>().text);
                highwayitem.materialPath      = materialPaths[i];

                if (isTextureChanged[i])
                {
                    Material  mat      = (Material)Resources.Load(highwayitem.materialPath);
                    byte[]    fileData = File.ReadAllBytes(texturePaths[i]);
                    Texture2D tex      = new Texture2D(2, 2);
                    tex.LoadImage(fileData);
                    mat.mainTexture      = tex;
                    mat.mainTextureScale = new Vector2(5, 1);
                }

                newHighwayConfig.Add(highwayitem);
            }

            config.highwayConfig = newHighwayConfig;
            loader.saveInitialConfig(Path.Combine(Application.persistentDataPath, "ConfigFiles/initialConfig.xml"), config);


            highwayMenu.SetActive(false);
        }
Beispiel #7
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);
        }
Beispiel #8
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);
        }