<commit_before>﻿using UnityEngine;
using MapzenGo.Models;
using MapzenGo.Models.Plugins;

public class Initialize : MonoBehaviour
{
    private GameObject world;
    private GameObject terrain;
    // Use this for initialization
    private GameObject spatialMapping;
    public GameObject _cursorFab;
    private GameObject cursor;
    private AppState appState;
    private GameObject table;
    float[] mapScales = new float[] { 0.004f, 0.002f, 0.00143f, 0.00111f, 0.00091f, 0.00077f, 0.000666f };

    public float _latitude = 53.298482F;
    public float _longitude = 5.070756F;
    public int _range = 4;
    public int _zoom = 17;
    public int _TitleSize = 100;
    public string json = "{   \"type\": \"FeatureCollection\",   \"features\": [     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.070362091064453,           53.295336751980656         ]       },       \"type\": \"Feature\",       \"properties\": {         \"kind\": \"forest\",         \"area\": 35879,         \"source\": \"openstreetmap.org\",         \"min_zoom\": 14,         \"tier\": 2,         \"id\": 119757239, 		 \"symbol\": \"liaise.png\"       }     },     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.072250366210937,           53.29523415150025         ]       },       \"type\": \"Feature\",       \"properties\": {         \"kind\": \"forest\",         \"area\": 1651,         \"source\": \"openstreetmap.org\",         \"min_zoom\": 14,         \"tier\": 2,         \"id\": 119757777, 		 \"symbol\": \"counterattack_fire.png\"       }     },     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.066671371459961,           53.29469549493482         ]       },       \"type\": \"Feature\",       \"properties\": {         \"marker-color\": \"#7e7e7e\",         \"marker-size\": \"medium\",         \"marker-symbol\": \"circle-stroked\",         \"kind\": \"app-622\",         \"area\": 18729,         \"source\": \"openstreetmap.org\",         \"min_zoom\": 14,         \"tier\": 2,         \"id\": 119758146,         \"symbol\": \"warrant_served.png\"       }     },     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.068731307983398,           53.29497764922103         ]       },       \"type\": \"Feature\",       \"properties\": {         \"kind\": \"bus_stop\",         \"name\": \"Eureka\",         \"source\": \"openstreetmap.org\",         \"min_zoom\": 17,         \"operator\": \"TCR\",         \"id\": 2833355779, 		 \"symbol\": \"activity.png\"       }     }   ] }";
    void includeAnchorMovingScript()
    {

        var gazeGesture = terrain.AddComponent<GazeGestureManager>();
        var AnchorPlacemant = terrain.AddComponent<TapToPlaceParent>();
        spatialMapping = new GameObject("Spatial Mapping");
        spatialMapping.AddComponent<UnityEngine.VR.WSA.SpatialMappingCollider>();
        spatialMapping.AddComponent<UnityEngine.VR.WSA.SpatialMappingRenderer>();

        var _spatial = spatialMapping.AddComponent<SpatialMapping>();
        _spatial.DrawMaterial = Resources.Load("Wireframe", typeof(Material)) as Material;

        if (_cursorFab)
        {
            cursor = (GameObject)Instantiate(_cursorFab, new Vector3(0, 0, -1), transform.rotation);
            cursor.name = "Cursor";
            var t = cursor.GetComponentInChildren<Transform>().Find("CursorMesh");

            var r = t.GetComponent<MeshRenderer>();
            r.enabled = true;
        }


    }
    void Start()
    {
        appState = AppState.Instance;



        //foreach (GameObject go in Cars)
        //{
        //    go.GetComponent<MeshFilter>().mesh = carMesh;
        //}


        // get config
        appState.LoadConfig();
        
        AddTerrain();



    }

    protected void AddTerrain()
    {
        var iv = appState.Config.InitalView;

        terrain = new GameObject("terrain");
        terrain.transform.position = new Vector3(0f, 0f, 0f);
        

        // terrain.transform.localScale = new Vector3(0.001f, 0.001f, 0.001f);
        Vector3 pos = new Vector3(0f, 0f, 0f);

        table = GameObject.CreatePrimitive(PrimitiveType.Cube);
        table.transform.position = new Vector3(0f, 0f, 3f);
        table.transform.localScale = new Vector3(iv.TableSize, iv.TableHeight, iv.TableSize);
        table.transform.parent = terrain.transform;


        var map = new GameObject("Map");
        map.transform.parent = table.transform;
        map.transform.localPosition = new Vector3(0f, 0.5f, 0f);


        //  _terrain.transform.localPosition = new Vector3(0.001875073f, 16.34f, 0.153019f);
        var mapScale = mapScales[iv.Range-1];
        map.transform.localScale = new Vector3(mapScale, mapScale, mapScale);
        //terrain.transform.position = new Vector3(0f, 0.3f, 2f);


        world = new GameObject("World");
        // world.transform.localScale= new Vector3(0.0005f, 0.0005f, 0.0005f);


        world.transform.parent = map.transform;

       // includeAnchorMovingScript();





        // init map
        var tm = world.AddComponent<TileManager>();
        tm.Latitude = iv.Lat;
        tm.Longitude = iv.Lon;
        tm.Range = iv.Range;
        tm.Zoom = iv.Zoom;
        tm.TileSize = iv.TileSize;
        tm._key = "vector-tiles-dB21RAF";



        #region UI

        var ui = new GameObject("UI"); // Placeholder (root element in UI tree)
        ui.transform.parent = world.transform;
        var place = new GameObject("PlaceContainer");
        AddRectTransformToGameObject(place);
        place.transform.parent = ui.transform;
<commit_msg>Clean initialize script<commit_after>﻿using UnityEngine;
using MapzenGo.Models;
using MapzenGo.Models.Plugins;

public class Initialize : MonoBehaviour
{
    private GameObject world;
    private GameObject terrain;
    // Use this for initialization
    private GameObject spatialMapping;
    public GameObject _cursorFab;
    private GameObject cursor;
    private AppState appState;
    private GameObject table;
    float[] mapScales = new float[] { 0.004f, 0.002f, 0.00143f, 0.00111f, 0.00091f, 0.00077f, 0.000666f };

    public float _latitude = 53.298482F;
    public float _longitude = 5.070756F;
    public int _range = 4;
    public int _zoom = 17;
    public int _TitleSize = 100;
    public string json = "{   \"type\": \"FeatureCollection\",   \"features\": [     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.070362091064453,           53.295336751980656         ]       },       \"type\": \"Feature\",       \"properties\": {         \"kind\": \"forest\",         \"area\": 35879,         \"source\": \"openstreetmap.org\",         \"min_zoom\": 14,         \"tier\": 2,         \"id\": 119757239, 		 \"symbol\": \"liaise.png\"       }     },     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.072250366210937,           53.29523415150025         ]       },       \"type\": \"Feature\",       \"properties\": {         \"kind\": \"forest\",         \"area\": 1651,         \"source\": \"openstreetmap.org\",         \"min_zoom\": 14,         \"tier\": 2,         \"id\": 119757777, 		 \"symbol\": \"counterattack_fire.png\"       }     },     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.066671371459961,           53.29469549493482         ]       },       \"type\": \"Feature\",       \"properties\": {         \"marker-color\": \"#7e7e7e\",         \"marker-size\": \"medium\",         \"marker-symbol\": \"circle-stroked\",         \"kind\": \"app-622\",         \"area\": 18729,         \"source\": \"openstreetmap.org\",         \"min_zoom\": 14,         \"tier\": 2,         \"id\": 119758146,         \"symbol\": \"warrant_served.png\"       }     },     {       \"geometry\": {         \"type\": \"Point\",         \"coordinates\": [           5.068731307983398,           53.29497764922103         ]       },       \"type\": \"Feature\",       \"properties\": {         \"kind\": \"bus_stop\",         \"name\": \"Eureka\",         \"source\": \"openstreetmap.org\",         \"min_zoom\": 17,         \"operator\": \"TCR\",         \"id\": 2833355779, 		 \"symbol\": \"activity.png\"       }     }   ] }";
    void includeAnchorMovingScript()
    {

        var gazeGesture = terrain.AddComponent<GazeGestureManager>();
        var AnchorPlacemant = terrain.AddComponent<TapToPlaceParent>();
        spatialMapping = new GameObject("Spatial Mapping");
        spatialMapping.AddComponent<UnityEngine.VR.WSA.SpatialMappingCollider>();
        spatialMapping.AddComponent<UnityEngine.VR.WSA.SpatialMappingRenderer>();

        var _spatial = spatialMapping.AddComponent<SpatialMapping>();
        _spatial.DrawMaterial = Resources.Load("Wireframe", typeof(Material)) as Material;

        if (_cursorFab)
        {
            cursor = (GameObject)Instantiate(_cursorFab, new Vector3(0, 0, -1), transform.rotation);
            cursor.name = "Cursor";
            var t = cursor.GetComponentInChildren<Transform>().Find("CursorMesh");

            var r = t.GetComponent<MeshRenderer>();
            r.enabled = true;
        }


    }
    void Start()
    {
        appState = AppState.Instance;

        // get config
        appState.LoadConfig();
        
        AddTerrain();


        // includeAnchorMovingScript();

    }

    protected void AddTerrain()
    {
        var iv = appState.Config.InitalView;

        #region create map & terrain

        terrain = new GameObject("terrain");
        terrain.transform.position = new Vector3(0f, 0f, 0f);        

        table = GameObject.CreatePrimitive(PrimitiveType.Cube);
        table.transform.position = new Vector3(0f, 0f, 3f);
        table.transform.localScale = new Vector3(iv.TableSize, iv.TableHeight, iv.TableSize);
        table.transform.parent = terrain.transform;


        var map = new GameObject("Map");
        map.transform.parent = table.transform;
        map.transform.localPosition = new Vector3(0f, 0.5f, 0f);
        
        var mapScale = mapScales[iv.Range-1];
        map.transform.localScale = new Vector3(mapScale, mapScale, mapScale);

        #endregion       

        #region init map

        world = new GameObject("World");
        world.transform.parent = map.transform;

        // init map
        var tm = world.AddComponent<TileManager>();
        tm.Latitude = iv.Lat;
        tm.Longitude = iv.Lon;
        tm.Range = iv.Range;
        tm.Zoom = iv.Zoom;
        tm.TileSize = iv.TileSize;
        tm._key = "vector-tiles-dB21RAF";

        #endregion

        #region UI

        var ui = new GameObject("UI"); // Placeholder (root element in UI tree)
        ui.transform.parent = world.transform;
        var place = new GameObject("PlaceContainer");
        AddRectTransformToGameObject(place);
        place.transform.parent = ui.transform;

{'fraction_non_alphanumeric': 0.15635504678840736, 'fraction_numerical': 0.05623694012900881, 'mean_word_length': 1.901423299947285, 'pattern_counts': {'":': 106, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '896884', 'n_tokens_mistral': 3619, 'n_tokens_neox': 3126, 'n_words': 664}