private float mdc = 60; // Group buildings every 50meters public GOCenterContainer findNearestCenter(Vector3 center, GameObject parent) { foreach (GOCenterContainer c in map.containers) { float d = Vector3.Distance(center, c.center); if (d <= mdc) { return(c); } } if (map.containers.Count > 100) { map.containers.Clear(); } GOCenterContainer container = new GOCenterContainer(); container.center = center; map.containers.Add(container); return(container); }
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); } }