public static bool SetColor(string colorString, Material material) { try { if (OsmToUnityConverter.OnlyHexInString(colorString)) { var color = OsmToUnityConverter.HexToColor(colorString); material.color = color; return(true); } else { System.Drawing.Color systemColor = System.Drawing.Color.FromName(colorString); if (systemColor.IsKnownColor) { var color = new Color(systemColor.R, systemColor.G, systemColor.B, systemColor.A); material.color = color; return(true); } } } catch (Exception) { } return(false); }
public static GameObject CreateHighway(OsmWay highwayData, OsmBounds bounds, Transform parent) { Vector3[] linePoints = new Vector3[highwayData.Nodes.Count]; for (int i = 0; i < highwayData.Nodes.Count; i++) { linePoints[i] = OsmToUnityConverter.GetPointFromUnityPointVec3(highwayData.Nodes[i].Point, bounds); } HighwayTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions. GetTagKeyEnum <HighwayTypeEnum> (highwayData.Tags[TagKeyEnum.Highway]); float width = GetHighwayWidth(type); Color color = GetHighwayColor(type); GameObject result = LineFactory.CreateLine(linePoints, width, color, new Material(Shader.Find("Sprites/Default"))); if (highwayData.Tags.ContainsKey(TagKeyEnum.Name)) { result.name = highwayData.Tags[TagKeyEnum.Name]; CreateRoadNameLabel(linePoints, result.name, result.transform); } else { result.name = "<highway>"; } result.transform.parent = parent; return(result); }
public static void CreatePower(OsmNode towerData, OsmBounds bounds, Transform parent) { Vector3[] linePoints = new Vector3[2]; linePoints[0] = OsmToUnityConverter.GetPointFromUnityPointVec3(towerData.Point, bounds); linePoints[1] = linePoints[0]; linePoints[1].y = GetPowerTowerHeight(); float width = GetPowerTowerWidth(); Color color = GetPowerTowerColor(); GameObject result = LineFactory.CreateLine(linePoints, width, color, new Material(Shader.Find("Sprites/Default"))); result.name = "<powertower>"; result.transform.parent = parent; }
public static void CreateRailway(OsmWay railway, OsmBounds bounds, Transform parent) { RailwayTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions. GetTagKeyEnum <RailwayTypeEnum> (railway.Tags[TagKeyEnum.Railway]); Vector3[] linePoints = new Vector3[railway.Nodes.Count]; for (int i = 0; i < railway.Nodes.Count; i++) { linePoints[i] = OsmToUnityConverter.GetPointFromUnityPointVec3(railway.Nodes[i].Point, bounds); } float width = GetHighwayWidth(type); Color color = GetHighwayColor(type); GameObject result = LineFactory.CreateLine(linePoints, width, color, new Material(Shader.Find("Sprites/Default"))); result.name = "<railway>"; result.transform.parent = parent; }
public static GameObject CreateMesh(OsmWay areaData, OsmBounds bounds) { var buildingCorners = new List <Vector3>(); for (int i = 0; i < areaData.Nodes.Count - 1; i++) { buildingCorners.Add(OsmToUnityConverter.GetPointFromUnityPointVec3(areaData.Nodes[i].Point, bounds)); } GameObject result = new GameObject(); result.AddComponent <MeshRenderer>(); MeshFilter mf = result.AddComponent <MeshFilter>(); if (buildingCorners.Count > 2) { Mesh mesh = Assets.Scripts.Factories.Unity.UnityMeshFactory.CreateMesh(buildingCorners); mf.mesh = mesh; } return(result); }
public static void CreatePower(OsmWay lineData, OsmBounds bounds, Transform parent) { GameObject result = new GameObject(); result.name = "<powerline>"; PowerTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions. GetTagKeyEnum <PowerTypeEnum> (lineData.Tags[TagKeyEnum.Power]); Vector3[] linePoints = new Vector3[lineData.Nodes.Count]; for (int i = 0; i < lineData.Nodes.Count; i++) { linePoints[i] = OsmToUnityConverter.GetPointFromUnityPointVec3(lineData.Nodes[i].Point, bounds); linePoints[i].y = GetPowerLineHeight(type); } LineRenderer lineRender = result.AddComponent <LineRenderer>(); lineRender.positionCount = lineData.Nodes.Count; lineRender.material = new Material(Shader.Find("Sprites/Default")); float width = GetPowerLineWidth(type); Color color = GetPowerLineColor(type); lineRender.startWidth = width; lineRender.endWidth = width; lineRender.startColor = color; lineRender.endColor = color; lineRender.SetPositions(linePoints); result.transform.parent = parent; }
public static void CreateWalls(OsmWay buildingData, OsmBounds bounds, float width, float levels, float height, float minHeight, Transform parent) { BuildingsTypeEnum type = OSMtoSharp.Enums.Helpers.EnumExtensions. GetTagKeyEnum <BuildingsTypeEnum> (buildingData.Tags[TagKeyEnum.Building]); string materiaName; Material material = null; if (ConfigManager.Instance.Textures) { if (!buildingData.Tags.ContainsKey(TagKeyEnum.BuildingColor)) { if (buildingData.Tags.ContainsKey(TagKeyEnum.Shop) || buildingData.Tags.ContainsKey(TagKeyEnum.Shop1) || buildingData.Tags.ContainsKey(TagKeyEnum.Shop2)) { materiaName = string.Format("{0}/{1}_{2}", Constants.Constants.MaterialsFolderName, "shop", new System.Random().Next(BuildingsConstants.firstIndexRandomShop, BuildingsConstants.endIndexRandomShop)); } else if (type == BuildingsTypeEnum.House || type == BuildingsTypeEnum.Apartments || type == BuildingsTypeEnum.Bungalow || type == BuildingsTypeEnum.Detached || type == BuildingsTypeEnum.Greenhouse || type == BuildingsTypeEnum.Residential ) { materiaName = string.Format("{0}/{1}_{2}", Constants.Constants.MaterialsFolderName, OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(TagKeyEnum.Building), OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(BuildingsTypeEnum.House)); } else if (type == BuildingsTypeEnum.Hotel || type == BuildingsTypeEnum.Commercial ) { materiaName = string.Format("{0}/{1}_{2}", Constants.Constants.MaterialsFolderName, OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(TagKeyEnum.Building), OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(BuildingsTypeEnum.Hotel)); } else { materiaName = string.Format("{0}/{1}_{2}", Constants.Constants.MaterialsFolderName, OSMtoSharp.Enums.Helpers.EnumExtensions.GetEnumAttributeValue(TagKeyEnum.Building), new System.Random().Next(BuildingsConstants.firstIndexRandomBuilding, BuildingsConstants.endIndexRandomBuilding)); } material = Resources.Load(materiaName, typeof(Material)) as Material; } } for (int i = 1; i < buildingData.Nodes.Count; i++) { Vector2 pointA = OsmToUnityConverter.GetPointFromUnityPointVec2(buildingData.Nodes[i].Point, bounds); Vector2 pointB = OsmToUnityConverter.GetPointFromUnityPointVec2(buildingData.Nodes[i - 1].Point, bounds); GameObject wall = CreateWall(new Vector3(pointA.x, minHeight, pointA.y), new Vector3(pointB.x, minHeight, pointB.y), width, height, minHeight); if (buildingData.Tags.ContainsKey(TagKeyEnum.BuildingColor)) { var color = buildingData.Tags[TagKeyEnum.BuildingColor].Replace("#", ""); SetColor(color, wall.GetComponent <Renderer>().material); } else { if (material != null) { Material mat = new Material(material); int tilingX = (int)wall.transform.localScale.z; if (tilingX == 0) { tilingX = 1; } mat.mainTextureScale = new Vector2(tilingX, levels); wall.GetComponent <Renderer>().material = mat; } } wall.transform.SetParent(parent); } }