public GameObject BuildPolygonFromPreloaded(GOFeature feature)
        {
            if (feature.preloadedMeshData == null)
            {
                return(null);
            }

            GameObject polygon = new GameObject();

            MeshFilter filter = polygon.AddComponent <MeshFilter>();

            meshRenderer = polygon.AddComponent <MeshRenderer>();

            Mesh mesh = feature.preloadedMeshData.ToMesh();

            if (feature.height > 0 && feature.layer.layerType == GOLayer.GOLayerType.Buildings)
            {
                SimpleExtruder.FixUV(mesh, feature.preloadedMeshData.sliceHeight);
            }

            filter.sharedMesh = mesh;

            if (feature.layer.useColliders && mesh != null && feature.convertedGeometry.Count() > 2)
            {
                polygon.AddComponent <MeshCollider> ();
            }

            return(polygon);
        }
        public static GOMesh PreloadLine(GOFeature feature)
        {
            if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1]))
            {
                return(null);
            }

            GOMesh preMesh = new GOMesh();

            GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry);

            lineMesh.width = feature.renderingOptions.lineWidth;
            preMesh        = lineMesh.CreatePremesh();

            if (feature.height > 0)
            {
                float h = feature.height;

                if (GOMap.GOLink)
                {
                    h += GOFeature.BuildingElevationOffset;
                }

                preMesh = SimpleExtruder.SliceExtrudePremesh(preMesh, h + Noise(), 4f, 4f, 10f);
            }

            if (feature.renderingOptions.outlineWidth > 0)
            {
                lineMesh.width        = feature.renderingOptions.lineWidth + feature.layer.defaultRendering.outlineWidth;
                preMesh.secondaryMesh = lineMesh.CreatePremesh();
            }

            return(preMesh);
        }
Beispiel #3
0
        public static GOMesh PreloadFeatureData(GOFeature feature)
        {
            try {
                switch (feature.goFeatureType)
                {
                case GOFeatureType.Polygon:
                case GOFeatureType.MultiPolygon:
                    if (!feature.layer.isPolygon)
                    {
                        return(PreloadLine(feature));
                    }
                    else if (feature.goTile.useElevation && feature.layer.layerType != GOLayer.GOLayerType.Buildings)
                    {
                        return(Preload3DPolygon(feature));
                    }
                    else
                    {
                        return(PreloadPolygon(feature));
                    }

                case GOFeatureType.Line:
                case GOFeatureType.MultiLine:
                    return(PreloadLine(feature));

                default:
                    return(null);
                }
            } catch (Exception ex) {
                Debug.LogWarning("[GOMAP] error catched in feature: " + feature.name + ", " + feature.kind + ", " + feature.convertedGeometry + ", " + ex);
                return(null);
            }
        }
Beispiel #4
0
        public override GOFeature EditFeatureData(GOFeature goFeature)
        {
            IDictionary properties = goFeature.properties;

            if (goFeature.goFeatureType == GOFeatureType.Point)
            {
                goFeature.name = (string)goFeature.properties ["name"];
                return(goFeature);
            }
            else
            {
                goFeature.name = goFeature.layer.name;
            }

            goFeature.kind = GOEnumUtils.MapboxToKind(goFeature.layer.name);
            goFeature.setRenderingOptions();

            goFeature.y = goFeature.layer.defaultLayerY();
            if (properties.Contains("_symbol"))
            {
                goFeature.y = Convert.ToInt64(properties ["_symbol"]) / 15.0f;
            }

//			float fraction = 20f;
//			goFeature.y = (1 + goFeature.layerIndex + goFeature.featureIndex/goFeature.featureCount)/fraction;

            goFeature.height = goFeature.layer.defaultRendering.polygonHeight;

            return(goFeature);
        }
Beispiel #5
0
        private void ComputeFeatureRanges(GOFeature feature)
        {
            xRange.x = xRange.y = feature.convertedGeometry [0].x;
            zRange.x = zRange.y = feature.convertedGeometry [0].z;

            foreach (Vector3 v in feature.convertedGeometry)
            {
                if (v.x > xRange.y)
                {
                    xRange.y = v.x;
                }
                if (v.x < xRange.x)
                {
                    xRange.x = v.x;
                }

                if (v.z > zRange.y)
                {
                    zRange.y = v.z;
                }
                if (v.z < zRange.x)
                {
                    zRange.x = v.z;
                }
            }
        }
Beispiel #6
0
        public override GOFeature EditLabelData(GOFeature goFeature)
        {
            goFeature.name = (string)goFeature.properties ["name"];
            goFeature.kind = GOEnumUtils.MapzenToKind((string)goFeature.properties ["kind"]);
            if (goFeature.properties.Contains("kind_detail"))               //Mapzen
            {
                goFeature.kind = GOEnumUtils.MapzenToKind((string)goFeature.properties ["kind_detail"]);
            }


            Int64 sort = 0;

            if (goFeature.properties.Contains("sort_rank"))
            {
                sort = Convert.ToInt64(goFeature.properties ["sort_rank"]);
            }
            else if (goFeature.properties.Contains("sort_key"))
            {
                sort = Convert.ToInt64(goFeature.properties ["sort_key"]);
            }
            goFeature.y    = sort / 1000.0f;
            goFeature.sort = sort;

            return(goFeature);
        }
        public static GOMesh PreloadFeatureData(GOFeature feature)
        {
            try {
                switch (feature.goFeatureType)
                {
                case GOFeatureType.Polygon:
                    return(PreloadPolygon(feature));

                case GOFeatureType.MultiPolygon:
                    return(PreloadPolygon(feature));

                case GOFeatureType.Line:
                    return(PreloadLine(feature));

                case GOFeatureType.MultiLine:
                    return(PreloadLine(feature));

                default:
                    return(null);
                }
            } catch (Exception ex) {
                Debug.LogWarning("[GOMAP] error catched in feature: " + feature.name + ", " + feature.kind + ", " + feature.convertedGeometry + ", " + ex);
                return(null);
            }
        }
        public override GOFeature EditFeatureData(GOFeature goFeature)
        {
            IDictionary properties = goFeature.properties;

            if (goFeature.goFeatureType == GOFeatureType.Point)
            {
                goFeature.name = (string)goFeature.properties ["name"];
                return(goFeature);
            }

            if (goFeature.layer != null && goFeature.layer.layerType == GOLayer.GOLayerType.Roads)
            {
                ((GORoadFeature)goFeature).isBridge = properties.Contains("brunnel") && (string)properties ["brunnel"] == "bridge";
                ((GORoadFeature)goFeature).isTunnel = properties.Contains("brunnel") && (string)properties ["brunnel"] == "tunnel";
                ((GORoadFeature)goFeature).isLink   = properties.Contains("brunnel") && (string)properties ["brunnel"] == "link";
            }

            goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["class"]);

//			goFeature.y = goFeature.featureIndex/1000 + goFeature.layer.defaultLayerY();
//			if (goFeature.kind == GOFeatureKind.lake) //terrible fix for vector maps without a sort value.
//				goFeature.y = GOLayer.defaultLayerY (GOLayer.GOLayerType.Landuse)+0.1f;

            float fraction = 20f;

            goFeature.y = (1 + goFeature.layerIndex + goFeature.featureIndex / goFeature.featureCount) / fraction;
            if (goFeature.kind == GOFeatureKind.lake)             //terrible fix for vector maps without a sort value.
            {
                goFeature.y += 0.5f;
            }

            goFeature.setRenderingOptions();
            goFeature.height = goFeature.renderingOptions.polygonHeight;

            if (goFeature.layer.useRealHeight && properties.Contains("render_height"))
            {
                double h = Convert.ToDouble(properties["render_height"]);
                goFeature.height = (float)h;
            }

            if (goFeature.layer.useRealHeight && properties.Contains("render_min_height"))
            {
                double hm = Convert.ToDouble(properties["render_min_height"]);
                goFeature.y = (float)hm;
                if (goFeature.height >= hm)
                {
                    goFeature.y      = (float)hm;
                    goFeature.height = (float)goFeature.height - (float)hm;
                }
            }


            if (goFeature.layer.forceMinHeight && goFeature.height < goFeature.renderingOptions.polygonHeight && goFeature.y < 0.5f)
            {
                goFeature.height = goFeature.renderingOptions.polygonHeight;
            }

            return(goFeature);
        }
Beispiel #9
0
 public GOFeatureMeshBuilder(GOFeature f)
 {
     feature = f;
     if (feature.goFeatureType == GOFeatureType.Polygon || feature.goFeatureType == GOFeatureType.MultiPolygon)
     {
         center = feature.convertedGeometry.Aggregate((acc, cur) => acc + cur) / feature.convertedGeometry.Count;
     }
 }
Beispiel #10
0
        public GameObject CreateRoofFromPreloaded(GOFeature feature, GOMesh premesh, GameObject parent)
        {
            GameObject roof   = GameObject.Instantiate(feature.goTile.featurePrototype, parent.transform);
            MeshFilter filter = roof.GetComponent <MeshFilter>();

            filter.mesh = premesh.ToMesh();
            return(roof);
        }
Beispiel #11
0
 private void AddFatureToList(GOFeature f, IList list)
 {
     f.preloadedMeshData = GOFeatureMeshBuilder.PreloadFeatureData(f);
     if (f.goFeatureType == GOFeatureType.Point || f.goFeatureType == GOFeatureType.Label || f.preloadedMeshData != null)
     {
         list.Add(f);
     }
 }
Beispiel #12
0
        public GameObject BuildPolygonFromPreloaded(GOFeature feature, GameObject parent)
        {
            if (feature.preloadedMeshData == null)
            {
                return(null);
            }

            GameObject polygon = GameObject.Instantiate(feature.goTile.featurePrototype, parent.transform);

            meshRenderer = polygon.GetComponent <MeshRenderer>();

            Mesh mesh = null;

            Profiler.BeginSample("Load preloaded mesh data");
            if (feature.renderingOptions.hasRoof)  //&& feature.roofMat != null) {
            {
                if (feature.layer.outlinedPolygon)
                {
                    mesh = feature.preloadedMeshData.ToOutlinedPolygonMesh();
                }
                else
                {
                    mesh = feature.preloadedMeshData.ToSubmeshes();
                }
            }
            else
            {
                mesh = feature.preloadedMeshData.ToMesh();
            }
            Profiler.EndSample();

//			if (feature.layer.layerType == GOLayer.GOLayerType.Buildings && feature.height > 0 && feature.layer.useRealHeight)
//				SimpleExtruder.FixUV (mesh, feature.preloadedMeshData.sliceHeight,10f);

            polygon.GetComponent <MeshFilter>().sharedMesh = mesh;

            if (feature.layer.useColliders && mesh != null && feature.convertedGeometry.Count() > 2)
            {
                MeshCollider collider = polygon.GetComponent <MeshCollider> ();
                collider.enabled    = true;
                collider.sharedMesh = mesh;

                if (feature.height < feature.layer.colliderHeight)
                {
                    //GameObject colliderGameObject = new GameObject("Collider");
                    //colliderGameObject.transform.parent = polygon.transform;
                    //MeshCollider collider2 = colliderGameObject.AddComponent<MeshCollider>();
                    //collider2.enabled = true;
                    //collider2.sharedMesh = feature.preloadedMeshData.secondaryMesh.ToMesh();
                    //MeshCollider.Destroy(collider);

                    collider.sharedMesh = feature.preloadedMeshData.secondaryMesh.ToMesh();
                }
            }


            return(polygon);
        }
 private void breakLine(GOFeature f)
 {
                 #if GOLINK
     if (GOMap.GOLink)
     {
         f.convertedGeometry = GOFeatureMeshBuilder.BreakLine(f.convertedGeometry, tile.map.goTerrain);
     }
                 #endif
 }
        public void OnFeatureLoad(GOFeature feature, GameObject featureObject)
        {
            if (feature.layer.layerType == GOLayer.GOLayerType.Buildings)
            {
                foreach (GOEnvironmentKind kind in buildings)
                {
                    bool kindCondition = kind.kind == feature.kind;

//					if (kindCondition) {
//						if (Application.isPlaying)
//							StartCoroutine (SpawnBuildings (feature, featureObject, kind));
//						else
//							GORoutine.start (SpawnBuildings (feature, featureObject, kind), this);
//					}
                }
            }
            else if (goMap.useElevation == true)
            {
                foreach (GOEnvironmentKind kind in featureEnvironment)
                {
                    bool kindCondition  = kind.kind == feature.kind;
                    bool layerCondition = kind.layer == feature.layer.layerType && kind.kind == GOFeatureKind.baseKind;

                    if (kindCondition || layerCondition)
                    {
                        if (Application.isPlaying)
                        {
                            StartCoroutine(SpawnPrefabsIn3DMesh(feature, featureObject, kind));
                        }
                        else
                        {
                            GORoutine.start(SpawnPrefabsIn3DMesh(feature, featureObject, kind), this);
                        }
                    }
                }
            }
            else
            {
                foreach (GOEnvironmentKind kind in featureEnvironment)
                {
                    bool kindCondition  = kind.kind == feature.kind;
                    bool layerCondition = kind.layer == feature.layer.layerType && kind.kind == GOFeatureKind.baseKind;

                    if (kindCondition || layerCondition)
                    {
                        if (Application.isPlaying)
                        {
                            StartCoroutine(SpawnPrefabsInMesh(feature, featureObject, kind));
                        }
                        else
                        {
                            GORoutine.start(SpawnPrefabsInMesh(feature, featureObject, kind), this);
                        }
                    }
                }
            }
        }
Beispiel #15
0
        private void ParseLabelLayerToList(List <GOParsedLayer> list, VectorTile vt, GOLabelsLayer layer)
        {
            string[] lyrs = tile.GetLabelsStrings().Split(',');
//			string kindKey = tile.GetPoisKindKey();

            foreach (string l in lyrs)
            {
                VectorTileLayer lyr = vt.GetLayer(l);
                if (lyr != null)
                {
                    int featureCount = lyr.FeatureCount();

                    if (featureCount == 0)
                    {
                        continue;
                    }

                    GOParsedLayer pl = new GOParsedLayer();
                    pl.name        = lyr.Name;
                    pl.labelsLayer = layer;
                    pl.goFeatures  = new List <GOFeature> ();

                    for (int i = 0; i < featureCount; i++)
                    {
                        VectorTileFeature vtf        = lyr.GetFeature(i);
                        IDictionary       properties = vtf.GetProperties();

                        List <List <LatLng> > geomWgs = vtf.GeometryAsWgs84((ulong)goTile.zoomLevel, (ulong)goTile.tileCoordinates.x, (ulong)goTile.tileCoordinates.y, 0);

                        if (geomWgs.Count == 0 || geomWgs[0].Count <= 1)
                        {
                            continue;
                        }

                        GOFeature gf = new GOFeature();
                        gf.properties    = properties;
                        gf.goFeatureType = vtf.GOFeatureType(geomWgs);
                        gf.labelsLayer   = layer;
                        gf.featureIndex  = (Int64)i + vt.LayerNames().IndexOf(lyr.Name);
                        gf.goTile        = goTile;
                        gf = tile.EditLabelData(gf);
                        gf.goFeatureType = GOFeatureType.Label;

                        gf.ConvertAttributes();
                        if (geomWgs.Count > 0)
                        {
                            gf.geometry = geomWgs[0];
                            gf.ConvertGeometries();
                            gf.preloadedLabelData = GOSegment.FindTheLongestStreightSegment(gf.convertedGeometry, 0);
                            AddFatureToList(gf, pl.goFeatures);
                        }
                    }
                    list.Add(pl);
                }
            }
        }
Beispiel #16
0
        public override GOFeature EditLabelData(GOFeature goFeature)
        {
            IDictionary properties = goFeature.properties;

            goFeature.name = (string)goFeature.properties ["name"];
            goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["class"]);

            goFeature.y = goFeature.getLayerDefaultY();

            return(goFeature);
        }
        public override GOFeature EditFeatureData(GOFeature goFeature)
        {
            if (goFeature.goFeatureType == GOFeatureType.Point)
            {
                goFeature.name = (string)goFeature.properties ["name"];
                return(goFeature);
            }

            IDictionary properties = goFeature.properties;

            if (goFeature.layer != null && goFeature.layer.layerType == GOLayer.GOLayerType.Roads)
            {
                ((GORoadFeature)goFeature).isBridge = properties.Contains("structure") && (string)properties ["structure"] == "bridge";
                ((GORoadFeature)goFeature).isTunnel = properties.Contains("structure") && (string)properties ["structure"] == "tunnel";
                ((GORoadFeature)goFeature).isLink   = properties.Contains("structure") && (string)properties ["structure"] == "link";
            }

            goFeature.kind = GOEnumUtils.MapboxToKind((string)properties["class"]);

            goFeature.name = (string)properties ["class"];

//			goFeature.y = (goFeature.index / 50.0f) + goFeature.getLayerDefaultY() /150.0f;
//			float fraction = goFeature.layer.layerType == GOLayer.GOLayerType.Buildings? 100f:10f;
            float fraction = 20f;

            goFeature.y = (1 + goFeature.layerIndex + goFeature.featureIndex / goFeature.featureCount) / fraction;

            goFeature.setRenderingOptions();
            goFeature.height = goFeature.renderingOptions.polygonHeight;

            bool extrude = properties.Contains("extrude") && (string)properties["extrude"] == "true";

            if (goFeature.layer.useRealHeight && properties.Contains("height") && extrude)
            {
                double h = Convert.ToDouble(properties["height"]);
                goFeature.height = (float)h;
            }

            if (goFeature.layer.useRealHeight && properties.Contains("min_height") && extrude)
            {
                double minHeight = Convert.ToDouble(properties["min_height"]);
                goFeature.y      = (float)minHeight;
                goFeature.height = (float)goFeature.height - (float)minHeight;
            }

            if (goFeature.height < goFeature.layer.defaultRendering.polygonHeight && goFeature.y == 0)
            {
                goFeature.height = goFeature.layer.defaultRendering.polygonHeight;
            }

            return(goFeature);
        }
Beispiel #18
0
        public override GOFeature EditLabelData(GOFeature goFeature)
        {
            goFeature.name = (string)goFeature.properties ["_name_global"];
            goFeature.kind = GOEnumUtils.MapboxToKind(goFeature.labelsLayer.name);
            goFeature.y    = goFeature.getLayerDefaultY() + 1;

//			if (properties.Contains ("_symbol"))
//				goFeature.y = Convert.ToInt64 (properties ["_symbol"]) / 10.0f;



            return(goFeature);
        }
Beispiel #19
0
        public static GOMesh PreloadLine(GOFeature feature)
        {
            if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1]))
            {
                return(null);
            }

            GOMesh preMesh = new GOMesh();

            GOLineMesh lineMesh = new GOLineMesh(feature, true);

            lineMesh.width = feature.renderingOptions.lineWidth * feature.goTile.worldScale;
            preMesh        = lineMesh.CreatePremesh();
            feature.isLoop = lineMesh.isLoop;
//			GORoad road = new GORoad (feature, 25, 1, 0);
//			road.computeRoad ();
//			preMesh = road.goMesh;

            if (feature.goTile.useElevation && feature.height == 0)
            {
                feature.height += GOFeature.RoadsHeightForElevation;
            }

            if (feature.height > 0)
            {
                float h = feature.height * feature.goTile.worldScale;
                if (feature.goTile.useElevation)
                {
                    h += GOFeature.BuildingElevationOffset;
                }
                preMesh = SimpleExtruder.ExtrudePremesh(preMesh, h + Noise(), false);
            }

            if (feature.renderingOptions.outlineWidth > 0 && !feature.goTile.useElevation)
            {
                lineMesh.width        = (feature.renderingOptions.lineWidth + feature.layer.defaultRendering.outlineWidth) * feature.goTile.worldScale;
                preMesh.secondaryMesh = lineMesh.CreatePremesh();

                if (feature.height > 0)
                {
                    float h = feature.height * feature.goTile.worldScale;
                    if (feature.goTile.useElevation)
                    {
                        h += GOFeature.BuildingElevationOffset;
                    }
                    preMesh.secondaryMesh = SimpleExtruder.ExtrudePremesh(preMesh.secondaryMesh, h + Noise(), false);
                }
            }

            return(preMesh);
        }
Beispiel #20
0
        public void GrowTrees(Mesh mesh, GOFeature feature, Vector3 center)
        {
            if (feature.kind == GOFeatureKind.park || feature.kind == GOFeatureKind.garden)
            {
                var randomRotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                int n = Random.Range(0, treePrefab.Length);
                center.y  = treePrefab [n].transform.position.y + feature.goTile.altitudeForPoint(center);
                center.y *= feature.goTile.worldScale;
                GameObject obj = (GameObject)Instantiate(treePrefab[n], center, randomRotation);

                obj.transform.parent = feature.parent.transform;

                obj.transform.localScale *= feature.goTile.worldScale;
            }
        }
Beispiel #21
0
        public GOLineMesh(GOFeature goFeature_, bool curved = false)
        {
            goFeature = goFeature_;

            this.isLoop = goFeature.convertedGeometry [0].Equals(goFeature.convertedGeometry[goFeature.convertedGeometry.Count - 1]);

            if ((goFeature.goTile.useElevation || curved) && goFeature.layer.layerType == GOLayer.GOLayerType.Roads)
            {
                geometry = GOCurver.MakeBetterCurve(goFeature.convertedGeometry, 15, isLoop);
            }
            else
            {
                geometry = goFeature.convertedGeometry;
            }
        }
Beispiel #22
0
        public void AddBoats(Mesh mesh, GOFeature feature, Vector3 center)
        {
            bool spawn = Random.value > 0.5f;

            if (feature.kind != GOFeatureKind.riverbank && feature.kind != GOFeatureKind.water && spawn)
            {
                var randomRotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                center.y  = 2 + feature.goTile.altitudeForPoint(center);
                center.y *= feature.goTile.worldScale;

                GameObject obj = (GameObject)Instantiate(boatPrefab, center, randomRotation);
                obj.transform.parent = feature.parent.transform;

                obj.transform.localScale *= feature.goTile.worldScale;
            }
        }
        public IEnumerator SpawnPrefabsInMesh(GOFeature feature, GameObject parent, GOEnvironmentKind kind)
        {
            if (feature.preloadedMeshData == null)
            {
                yield break;
            }

            float area = Area(feature.convertedGeometry);
            float rate = kind.density / 1000.0f;
            int   k    = Mathf.FloorToInt(area * rate / 100);

            //Debug.Log (area + " " + rate + " " + k);

            for (int i = 0; i < k; i++)
            {
                try {
//					int spawn = UnityEngine.Random.Range (0, rate);
//					if (spawn != 0)
//						continue;

                    int     n   = UnityEngine.Random.Range(0, kind.prefabs.Length);
                    Vector3 pos = randomPointInShape(feature.convertedGeometry);

                    if (GOMap.IsPointAboveWater(pos))
                    {
                        continue;
                    }

                    pos.y += kind.prefabs [n].transform.position.y;


                    var rotation       = kind.prefabs [n].transform.eulerAngles;
                    var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

                    GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));
                    obj.transform.parent = parent.transform;
                } catch {
                }

                if (Application.isPlaying)
                {
                    yield return(null);
                }
            }

            yield return(null);
        }
        public IEnumerator SpawnPrefabsIn3DMesh(GOFeature feature, GameObject parent, GOEnvironmentKind kind)
        {
            if (feature.preloadedMeshData == null)
            {
                yield break;
            }

            int rate = 100 / kind.density;

            foreach (Vector3 vertex in feature.preloadedMeshData.vertices)
            {
                try {
                    int spawn = UnityEngine.Random.Range(0, rate);
                    if (spawn != 0)
                    {
                        continue;
                    }

                    int     n   = UnityEngine.Random.Range(0, kind.prefabs.Length);
                    Vector3 pos = vertex;

                    if (GOMap.IsPointAboveWater(pos))
                    {
                        continue;
                    }

                    pos.y += kind.prefabs [n].transform.position.y;


                    var rotation       = kind.prefabs [n].transform.eulerAngles;
                    var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

                    GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));
                    obj.transform.parent = parent.transform;
                } catch {
                }

                if (Application.isPlaying)
                {
                    yield return(null);
                }
            }

            yield return(null);
        }
        public void OnFeatureLoad(GOFeature feature, GameObject featureObject)
        {
            if (goMap.useElevation == true)
            {
                foreach (GOEnvironmentKind kind in featureEnvironment)
                {
                    bool kindCondition  = kind.kind == feature.kind;
                    bool layerCondition = kind.layer == feature.layer.layerType && kind.kind == GOFeatureKind.baseKind;

                    if (kindCondition || layerCondition)
                    {
                        if (Application.isPlaying)
                        {
                            StartCoroutine(SpawnPrefabsIn3DMesh(feature, featureObject, kind));
                        }
                        else
                        {
                            GORoutine.start(SpawnPrefabsIn3DMesh(feature, featureObject, kind), this);
                        }
                    }
                }
            }
            else
            {
                foreach (GOEnvironmentKind kind in featureEnvironment)
                {
                    bool kindCondition  = kind.kind == feature.kind || kind.kind == GOFeatureKind.baseKind;
                    bool layerCondition = kind.layer == feature.layer.layerType;

                    if (kindCondition && layerCondition)
                    {
                        //Debug.Log(kind.layer + " " + feature.layer.layerType);

                        if (Application.isPlaying)
                        {
                            StartCoroutine(SpawnPrefabsInMesh(feature, featureObject, kind));
                        }
                        else
                        {
                            GORoutine.start(SpawnPrefabsInMesh(feature, featureObject, kind), this);
                        }
                    }
                }
            }
        }
        public override GOFeature EditLabelData(GOFeature goFeature)
        {
            string labelKey = goFeature.labelsLayer.LanguageKey(goFeature.goTile.mapType);

            if (goFeature.properties.Contains(labelKey) && !string.IsNullOrEmpty((string)goFeature.properties [labelKey]))
            {
                goFeature.name = (string)goFeature.properties [labelKey];
            }
            else
            {
                goFeature.name = (string)goFeature.properties ["name"];
            }

            goFeature.kind = GOEnumUtils.MapboxToKind(goFeature.labelsLayer.name);
            goFeature.y    = goFeature.getLayerDefaultY() + 1;

            return(goFeature);
        }
 public void OnFeatureLoad(GOFeature feature, GameObject featureObject)
 {
     foreach (GOEnvironmentKind kind in featureEnvironment)
     {
         int spawn = 0;
         if (spawn == 0 && kind.kind == feature.kind)
         {
             if (Application.isPlaying)
             {
                 StartCoroutine(SpawnPrefabsInMesh(feature, featureObject, kind));
             }
             else
             {
                 GORoutine.start(SpawnPrefabsInMesh(feature, featureObject, kind), this);
             }
         }
     }
 }
        private void AddFatureToList(GOFeature f, IList list)
        {
            //			if (f.GetType () == typeof(GORoadFeature)) {
            //
            //				GORoadFeature rf = (GORoadFeature)f;
            //				GORoadFeature.MergeRoad (list, rf);
            //
            //			} else {


            f.preloadedMeshData = GOFeatureMeshBuilder.PreloadFeatureData(f);
            if (f.goFeatureType == GOFeatureType.Point || f.preloadedMeshData != null)
            {
                list.Add(f);
            }

            //			}
        }
        public IEnumerator SpawnBuildings(GOFeature feature, GameObject parent, GOEnvironmentKind kind)
        {
            if (feature.preloadedMeshData == null)
            {
                yield break;
            }


            int rate = 100 / (kind.density + 1);

//			foreach (Vector3 vertex in feature.preloadedMeshData.vertices) {
//
//				try {
            int spawn = UnityEngine.Random.Range(0, rate);

            if (spawn != 0)
            {
                yield break;
            }

            int n = UnityEngine.Random.Range(0, kind.prefabs.Length);

            Vector3 pos = feature.featureCenter;

            pos.y += kind.prefabs [n].transform.position.y;

            var rotation       = kind.prefabs [n].transform.eulerAngles;
            var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

            GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));

            obj.transform.parent = parent.transform;

//				} catch {
//				}

            if (Application.isPlaying)
            {
                yield return(null);
            }
//			}

            yield return(null);
        }
Beispiel #30
0
        public GOMesh ProjectFeature(GOFeature feature, GOMesh terrainMesh, float distance)
        {
            Vector3[] vertices  = terrainMesh.vertices;
            int[]     triangles = terrainMesh.triangles;

            GOTempPolyNew poly;

            ComputeFeatureRanges(feature);

            for (int i = 0; i < triangles.Length; i += 3)
            {
                int i1 = triangles[i];
                int i2 = triangles[i + 1];
                int i3 = triangles[i + 2];

                Vector3 v1 = feature.goTile.position + vertices [i1];
                Vector3 v2 = feature.goTile.position + vertices [i2];
                Vector3 v3 = feature.goTile.position + vertices [i3];

                Vector3 side1  = v2 - v1;
                Vector3 side2  = v3 - v1;
                Vector3 normal = Vector3.Cross(side1, side2).normalized;

                poly        = new GOTempPolyNew(v1, v2, v3);
                poly.normal = normal;
                poly.indices.AddRange(new int[] { i1, i2, i3 });
                poly.xRange = xRange;
                poly.zRange = zRange;

//				Profiler.BeginSample ("Wrap Polygon");
                poly = poly.WrapPolygon(feature.convertedGeometry.ToArray(), terrainMesh);
//				Profiler.EndSample ();

                if (poly == null)
                {
                    continue;
                }

                polys.Add(poly);
            }

            return(MergeTempPolys(distance));
        }