private IEnumerator CreatePolygon(GameObject parent, string kind, string type, IList subject, List <object> clips, IDictionary properties, Layer layer, bool delayedLoad) { GameObject polygon = null; try { PolygonHandler poly = new PolygonHandler(subject, clips); RenderingOptions renderingOptions = null; foreach (RenderingOptions r in layer.renderingOptions) { if (r.kind == kind) { renderingOptions = r; break; } } float height = layer.defaultRendering.polygonHeight; float defaultZ = -layer.defaultRendering.distanceFromFloor; Material material = GetMaterial(layer.defaultRendering, poly.center); Material roofMat = layer.defaultRendering.roofMaterial == null ? layer.defaultRendering.material : layer.defaultRendering.roofMaterial; if (renderingOptions != null) { height = renderingOptions.polygonHeight; material = GetMaterial(renderingOptions, poly.center); defaultZ = renderingOptions.distanceFromFloor; roofMat = renderingOptions.roofMaterial; } //Group buildings by center coordinates if (layer.json == "buildings") { GameObject centerContainer = findNearestCenter(poly.center, parent, material); parent = centerContainer; material = centerContainer.GetComponent <MatHolder>().material; } Int64 sort; if (properties.Contains("sort_key")) { sort = (Int64)properties["sort_key"]; } else { sort = (Int64)properties["sort_rank"]; } if (material) { material.renderQueue = -(int)sort; } if (roofMat) { roofMat.renderQueue = -(int)sort; } if (defaultZ == 0f) { defaultZ = -sort / 1000.0f; } if (layer.useRealHeight && properties.Contains("height")) { double h = (double)properties["height"]; height = (float)h; } if (layer.useRealHeight && properties.Contains("min_height")) { double hm = (double)properties["min_height"]; defaultZ = (float)hm; height = (float)height - (float)hm; } polygon = poly.CreateModel(layer, height); if (polygon == null) { yield break; } polygon.name = layer.name; polygon.transform.parent = parent.transform; if (layer.useRealHeight) { // GameObject roof = poly.CreateModel(layer,0); GameObject roof = poly.CreateRoof(); roof.name = "roof"; roof.transform.parent = polygon.transform; roof.GetComponent <MeshRenderer>().material = roofMat; roof.transform.position = new Vector3(roof.transform.position.x, height + 0.1f, roof.transform.position.z); if (properties.Contains("roof_material")) { roof.name = "roofmat_" + (string)properties["roof_material"]; } if (properties.Contains("roof_color")) { Debug.LogError("Roof color: " + (string)properties["roof_color"]); polygon.name = "roofx"; } } Vector3 pos = polygon.transform.position; pos.z = defaultZ; polygon.transform.position = pos; polygon.transform.localPosition = pos; Attributes attributes = polygon.AddComponent <Attributes>(); attributes.type = type; attributes.loadWithDictionary((Dictionary <string, object>)properties); polygon.GetComponent <Renderer>().material = material; if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(poly.mesh2D, layer, kind, poly.center); } } catch (Exception ex) { GameObject.Destroy(polygon); Debug.Log(ex); } if (delayedLoad) { yield return(null); } }
public void Initialize(List <Vector3> verts, string kind, Layer layer, int sort) { _verts = verts; RenderingOptions renderingOptions = null; foreach (RenderingOptions r in layer.renderingOptions) { if (r.kind == kind) { renderingOptions = r; break; } } float width = layer.defaultRendering.lineWidth; float defaultZ = -layer.defaultRendering.distanceFromFloor; Material material = layer.defaultRendering.material; Material outlineMaterial = layer.defaultRendering.outlineMaterial; float outlineWidth = width + layer.defaultRendering.outlineWidth; if (renderingOptions != null) { width = renderingOptions.lineWidth; material = renderingOptions.material; defaultZ = renderingOptions.distanceFromFloor; outlineMaterial = renderingOptions.outlineMaterial; outlineWidth = width + renderingOptions.outlineWidth; } if (defaultZ == 0f) { defaultZ = -sort / 1000.0f; } if (material) { material.renderQueue = -sort; } if (outlineMaterial) { outlineMaterial.renderQueue = -sort; } SimpleRoad road = gameObject.AddComponent <SimpleRoad>(); Vector3[] vertices = _verts.Select(x => new Vector3(x.x, x.y, 0)).ToArray(); road.verts = vertices; road.width = width; road.load(); Vector3 position = transform.position; position.z = defaultZ; transform.position = position; gameObject.GetComponent <Renderer>().material = material; if (outlineMaterial != null) { CreateRoadOutline(verts, outlineMaterial, outlineWidth, sort, defaultZ); } }