Exemple #1
0
 public static void GUI(this MapMetaDataMsg message)
 {
     GUILayout.Label($"Load time: {message.map_load_time.ToTimestampString()}");
     GUILayout.Label($"Resolution: {message.resolution}");
     GUILayout.Label($"Size: {message.width}x{message.height}");
     message.origin.GUI();
 }
 public OccupancyGridMsg(JSONNode msg)
 {
     _header = new HeaderMsg(msg["header"]);
     _info   = new MapMetaDataMsg(msg["info"]);
     _data   = new sbyte[msg["data"].Count];
     for (int i = 0; i < _data.Length; i++)
     {
         _data[i] = sbyte.Parse(msg["data"][i]);
     }
 }
        public void NewOcupanceGridMsg(OccupancyGridMsg msg)
        {
            MapMetaDataMsg metaData = msg.GetInfo();

            sbyte[] AlturasRecibidas = msg.GetData();


            float _resolutionMap = msg.GetInfo().GetResolution();
            int   _width         = (int)(metaData.Getwidth());
            int   _height        = (int)(metaData.Getheight());

            _originPosition = msg.GetInfo().GetOrigin().GetPositionUnity();

            td = new TerrainData();
            if (_width > _height)
            {
                td.heightmapResolution = _width;
            }
            else
            {
                td.heightmapResolution = _height;
            }

            td.size = new Vector3(_width * _resolutionMap, _elevation, _height * _resolutionMap);

            xRes    = td.heightmapResolution;
            yRes    = td.heightmapResolution;
            heights = td.GetHeights(0, 0, xRes, yRes);

            for (int filas = 0; filas < yRes; filas++)
            {
                for (int columna = 0; columna < xRes; columna++)
                {
                    heights[filas, columna] = AlturasRecibidas[(int)(columna * _width / xRes) + (int)(filas * _height / yRes) * _width] / 100;
                }
            }

            td.SetHeights(0, 0, heights);

            td.terrainLayers = new TerrainLayer[1] {
                new TerrainLayer {
                    diffuseTexture = texture, tileSize = new Vector2(2, 2)
                }
            };

            t = Terrain.CreateTerrainGameObject(td).GetComponent <Terrain>();
            t.transform.position = _originPosition;
            t.gameObject.layer   = 18;

            gameObject.SendMessage("MapLoaded", t, SendMessageOptions.DontRequireReceiver);
        }
 public OccupancyGridMsg(HeaderMsg header, TextAsset pgmFile, float resolution, Vector3 origin)
 {
     _header = header;
     _data   = LoadImage(pgmFile, out uint width, out uint height);
     _info   = new MapMetaDataMsg(new TimeMsg(0, 0), resolution, width, height, new PoseMsg(origin, Quaternion.identity, false));
 }
 public OccupancyGridMsg(HeaderMsg header, MapMetaDataMsg info, sbyte[] data)
 {
     _header = header;
     _info   = info;
     _data   = data;
 }