IEnumerator CreatePoi(GOTile tile, bool delayedLoad) { if (poiRendering == null) { yield break; } GameObject poi = GameObject.Instantiate (poiRendering.prefab); #if GOLINK poiGeometry.y = GoTerrain.GOTerrain.RaycastAltitudeForVector(poiGeometry); #endif poi.transform.localPosition = poiGeometry; poi.transform.parent = parent.transform; poi.name = name; //Layer mask if (poiLayer.useLayerMask == true) { tile.AddObjectToLayerMask (layer, poi); } GOFeatureBehaviour fb = poi.AddComponent<GOFeatureBehaviour> (); fb.goFeature = this; if (poiRendering.OnPoiLoad != null) { poiRendering.OnPoiLoad.Invoke(this); } if (delayedLoad) yield return null; }
public virtual IEnumerator CreateLine(GOTile tile, bool delayedLoad) { GORenderingOptions renderingOptions = GetRenderingOptions(); if (renderingOptions.lineWidth == 0) { yield break; } GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); featureCenter = builder.center; GameObject line = null; if (preloadedMeshData != null) { line = builder.BuildLineFromPreloaded(this, tile.map, parent); } if (line == null) { yield break; } line.name = name != null? name:kind.ToString(); //Layer mask if (layer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, line); } if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = line.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } //Mapzen Streetnames if (goTile.mapType == GOMap.GOMapType.Mapzen_Legacy && layer.layerType == GOLayer.GOLayerType.Roads && name != null && name.Length > 0 && goTile.useStreetnames && !isLoop && !goTile.useElevation) { GOStreetName streetName = GameObject.Instantiate(goTile.streetnamePrototype, line.transform).GetComponent <GOStreetName>(); streetName.gameObject.name = name + "_streetname"; yield return(tile.StartCoroutine(streetName.Build(name, this))); } if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(this, line); } if (delayedLoad) { yield return(null); } }
public virtual IEnumerator CreateLine(GOTile tile, bool delayedLoad) { GORenderingOptions renderingOptions = GetRenderingOptions(); if (renderingOptions.lineWidth == 0) { yield break; } GameObject line = new GameObject(name != null? name:kind.ToString()); line.transform.parent = parent.transform; //Layer mask if (layer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, line); } GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); if (preloadedMeshData != null) { builder.BuildLineFromPreloaded(line, this, tile.map); } else if (tile.map.mapType == GOMap.GOMapType.MapzenJson) { builder.BuildLine(line, layer, renderingOptions, tile.map); } GOFeatureBehaviour fb = line.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; if (layer.layerType == GOLayer.GOLayerType.Roads && name != null && name.Length > 0 && renderingOptions.useStreetNames) { GOStreetName streetName = new GameObject().AddComponent <GOStreetName> (); streetName.gameObject.name = ""; streetName.transform.SetParent(line.transform); yield return(tile.StartCoroutine(streetName.Build(name, tile.map.textShader, tile.map.streetnameColor))); } if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(builder.mesh, layer, kind, builder.center); } if (delayedLoad) { yield return(null); } }
IEnumerator CreateLabel(GOTile tile, bool delayedLoad) { GameObject label = GameObject.Instantiate(goTile.streetnamePrototype); //Mapzen Streetnames if (name != null && name.Length > 0 && !goTile.useElevation) { GOStreetName streetName = label.GetComponent <GOStreetName>(); streetName.gameObject.name = name + "_streetname"; yield return(tile.StartCoroutine(streetName.Build(name, this))); } if (label == null) { yield break; } Vector3 pos = label.transform.position; pos.y = y; label.transform.position = pos; label.transform.SetParent(parent.transform); //Layer mask if (labelsLayer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, label); } if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = label.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } if (labelsLayer.OnLabelLoad != null) { labelsLayer.OnLabelLoad.Invoke(this, label); } if (delayedLoad) { yield return(null); } }
IEnumerator CreatePoi(GOTile tile, bool delayedLoad) { if (poiRendering == null) { yield break; } GameObject poi = GameObject.Instantiate(poiRendering.prefab); #if GOLINK poiGeometry.y = GoTerrain.GOTerrain.RaycastAltitudeForVector(poiGeometry); #endif poiGeometry.y += poi.transform.position.y; poiGeometry.y *= goTile.worldScale; poi.transform.position = poiGeometry; poi.transform.SetParent(parent.transform); poi.name = name; // Debug.Log ("Load POI: "+ name); //Layer mask if (poiLayer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, poi); } if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = poi.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } if (poiRendering.OnPoiLoad != null) { poiRendering.OnPoiLoad.Invoke(this, poi); } if (delayedLoad) { yield return(null); } }
public virtual IEnumerator CreatePolygon (GOTile tile, bool delayedLoad) { Profiler.BeginSample ("[GOFeature] CreatePolygon ALLOC"); GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); Profiler.EndSample (); Profiler.BeginSample ("[GOFeature] CreatePolygon Material"); //Materials Material material = tile.GetMaterial(renderingOptions,builder.center); Material roofMat = renderingOptions.roofMaterial; if (sort != 0) { if (material) material.renderQueue = -(int)sort; if (roofMat) roofMat.renderQueue = -(int)sort; } Profiler.EndSample (); Profiler.BeginSample ("[GOFeature] CreatePolygon Center"); //Group buildings by center coordinates if (layer.layerType == GOLayer.GOLayerType.Buildings && defaultRendering) { GameObject centerContainer = tile.findNearestCenter(builder.center,parent,material); parent = centerContainer; material = centerContainer.GetComponent<GOMatHolder> ().material; } Profiler.EndSample(); if (!layer.useRealHeight) { height = renderingOptions.polygonHeight; } int offset = 0; float trueHeight = height; #if GOLINK if (GOMap.GOLink) { trueHeight += BuildingElevationOffset; //[GOLINK] GOTerrain link (This requires GOTerrain! https://www.assetstore.unity3d.com/#!/content/84198) if (tile.map.goTerrain != null) { offset = BuildingElevationOffset; if (y < offset) y = tile.map.goTerrain.FindAltitudeForVector(builder.center)-offset; } } #endif Profiler.BeginSample ("[GOFeature] CreatePolygon MESH"); GameObject polygon = null; if (preloadedMeshData != null) polygon = builder.BuildPolygonFromPreloaded(this); else if (tile.map.mapType == GOMap.GOMapType.MapzenJson) //ONLY FOR JSON polygon = builder.BuildPolygon(layer,trueHeight+offset); Profiler.EndSample (); if (polygon == null) yield break; polygon.name = name; polygon.transform.parent = parent.transform; //Layer mask if (layer.useLayerMask == true) { tile.AddObjectToLayerMask (layer, polygon); } if (renderingOptions.tag.Length > 0) { polygon.tag = renderingOptions.tag; } if (layer.useRealHeight && roofMat != null) { Profiler.BeginSample ("[GOFeature] CreatePolygon ROOF"); GameObject roof; if (preloadedMeshData != null && preloadedMeshData.secondaryMesh != null) roof = builder.CreateRoofFromPreloaded (preloadedMeshData.secondaryMesh); else roof = builder.CreateRoof(); roof.name = "roof"; roof.transform.parent = polygon.transform; roof.GetComponent<MeshRenderer> ().material = roofMat; roof.transform.position = new Vector3 (roof.transform.position.x,trueHeight+0.11f,roof.transform.position.z); roof.tag = polygon.tag; roof.layer = polygon.layer; Profiler.EndSample (); } Profiler.BeginSample ("[GOFeature] TRANSFORM"); Vector3 pos = polygon.transform.position; pos.y = y; if (layer.layerType == GOLayer.GOLayerType.Buildings) y += GOFeatureMeshBuilder.Noise (); polygon.transform.position = pos; polygon.transform.localPosition = pos; GOFeatureBehaviour fb = polygon.AddComponent<GOFeatureBehaviour> (); fb.goFeature = this; builder.meshRenderer.material = material; if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(builder.mesh,layer,kind, builder.center); } Profiler.EndSample (); preloadedMeshData = null; if (delayedLoad) yield return null; }
public virtual IEnumerator CreatePolygon(GOTile tile, bool delayedLoad) { // // if (layer.layerType == GOLayer.GOLayerType.Buildings && name != "Whitehall Building Annex") // yield break; Profiler.BeginSample("[GOFeature] CreatePolygon ALLOC"); GOFeatureMeshBuilder builder = new GOFeatureMeshBuilder(this); this.featureCenter = new Vector3(2, builder.center.y, 8); //new Vector3 (builder.center.x, builder.center.y, builder.center.z); Profiler.EndSample(); Material material = null; Material roofMat = null; if (layer.layerType == GOLayer.GOLayerType.Buildings && defaultRendering && renderingOptions.materials.Length != 0) { Profiler.BeginSample("[GOFeature] CreatePolygon Center"); GOCenterContainer centerContainer = tile.findNearestCenter(builder.center, parent); Profiler.EndSample(); if (centerContainer.material == null) { Profiler.BeginSample("[GOFeature] CreatePolygon Material"); centerContainer.material = tile.GetMaterial(renderingOptions, builder.center); centerContainer.secondaryMaterial = renderingOptions.roofMaterial; Profiler.EndSample(); } material = centerContainer.material; roofMat = centerContainer.secondaryMaterial; } else { Profiler.BeginSample("[GOFeature] CreatePolygon Material"); //Materials material = tile.GetMaterial(renderingOptions, builder.center); roofMat = renderingOptions.roofMaterial; Profiler.EndSample(); } if (sort != 0) { if (material) { material.renderQueue = -(int)sort; } if (roofMat) { roofMat.renderQueue = -(int)sort; } } if (!layer.useRealHeight) { height = renderingOptions.polygonHeight; } float offset = 0; float trueHeight = height; if (goTile.useElevation && layer.layerType == GOLayer.GOLayerType.Buildings) { trueHeight += BuildingElevationOffset; offset = BuildingElevationOffset; if (y < offset) { y = highestAltitudeVertex - offset + 0.5f; } // y = goTile.altitudeForPoint(builder.center)-offset+0.5f; } Profiler.BeginSample("[GOFeature] CreatePolygon MESH"); GameObject polygon = null; if (preloadedMeshData != null) { polygon = builder.BuildPolygonFromPreloaded(this, parent); } Profiler.EndSample(); if (polygon == null) { yield break; } polygon.name = name; //Layer mask if (layer.useLayerMask == true) { tile.AddObjectToLayerMask(layer, polygon); } if (renderingOptions.tag.Length > 0) { polygon.tag = renderingOptions.tag; } if (renderingOptions.hasRoof) { Material[] mats = new Material[2]; mats [0] = material; mats [1] = roofMat; MeshRenderer mr = polygon.GetComponent <MeshRenderer> (); mr.shadowCastingMode = layer.castShadows; mr.materials = mats; } else { builder.meshRenderer.material = material; builder.meshRenderer.shadowCastingMode = layer.castShadows; } Profiler.BeginSample("[GOFeature] TRANSFORM"); Vector3 pos = polygon.transform.position; pos.y = y; if (layer.layerType == GOLayer.GOLayerType.Buildings) { y += GOFeatureMeshBuilder.Noise(); } polygon.transform.position = pos; polygon.transform.localPosition = pos; if (goTile.addGoFeatureComponents) { GOFeatureBehaviour fb = polygon.AddComponent <GOFeatureBehaviour> (); fb.goFeature = this; } if (layer.OnFeatureLoad != null) { layer.OnFeatureLoad.Invoke(this, polygon); } Profiler.EndSample(); preloadedMeshData = null; if (delayedLoad) { yield return(null); } }