void GenerateGeometry(List <List <Vector3> > segments, GameObject container, IDictionary properties, string type) { string pname = OSMTools.GetProperty(properties, "name"); // Debug.Log( "Processing:" + pname); //List<Vector2> points = new List<Vector2>(); GameObject go = new GameObject("building"); go.transform.parent = container.transform; go.layer = LayerMask.NameToLayer("Buildings"); go.name = pname; //go.transform.position = segments[0][0]; go.transform.localPosition = Vector3.zero; //go.name = properties["kind"].ToString(); MassiveFeature f = go.AddComponent <MassiveFeature>(); f.SetProperties(properties); f.SetSegments(segments); f.SetType(type); //if height it not present assume 1 floor height = f.height == 0 ? 5 : f.height; CreateRoof(segments, go); CreateWalls(segments, go); MeshTools.MoveGameObjectToTerrain(TileBoundsMeters, this.transform.position, mc, go, Walls.GetComponent <MeshFilter>().sharedMesh); //create roof //MeshTools.FitMeshToTerrain(TileBoundsMeters, this.transform.position, mc, msh); //MeshTools.MoveMeshToTerrain(TileBoundsMeters, this.transform.position, mc, msh, f.height, go); }
void GenerateGeometry(List <List <Vector3> > segments, GameObject container, IDictionary properties, string type) { List <Vector2> points = new List <Vector2>(); foreach (List <Vector3> list in segments) { GameObject go = new GameObject("piece"); go.transform.parent = container.transform; go.layer = LayerMask.NameToLayer("Water"); go.name = properties["kind"].ToString(); MassiveFeature mf = go.AddComponent <MassiveFeature>(); mf.SetProperties(properties); mf.SetSegments(segments); mf.SetType(type); for (int i = 0; i < list.Count - 1; i++) { Vector3 v1 = list[i]; points.Add(new Vector2((float)v1.x, (float)v1.z)); //float heightv1 = GetMeshHeight(v1); //GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube); //go.transform.parent = container.transform; //go.transform.position = v1.ToVector3(); //go.transform.localScale = new Vector3(20, 20, 20); } Triangulator tr = new Triangulator(points.ToArray()); int[] indices = tr.Triangulate(); // Create the Vector3 vertices Vector3[] vertices = new Vector3[points.Count]; for (int i = 0; i < vertices.Length; i++) { vertices[i] = new Vector3(points[i].x, 0, points[i].y); float h = GetMeshHeight(vertices[i]); vertices[i].y = h; } // Create the mesh Mesh msh = new Mesh(); msh.vertices = vertices; msh.triangles = indices; msh.RecalculateNormals(); msh.RecalculateBounds(); // Set up game object with mesh; MeshRenderer r = go.AddComponent <MeshRenderer>(); r.material = OceanMaterial; r.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; MeshFilter filter = go.AddComponent(typeof(MeshFilter)) as MeshFilter; filter.mesh = msh; go.AddComponent <MeshCollider>(); } }
public void Generate(string sData, DVector3 PositionMeters, string AssetPath) { mc = transform.parent.Find("terrain").GetComponent <MeshCollider>(); TileBoundsMeters = this.transform.parent.GetComponent <MassiveTile>().TileBoundsMeters; Data = (Dictionary <string, object>)MiniJSON.Json.Deserialize(sData); IList features = (IList)Data["features"]; foreach (IDictionary feature in features) { IDictionary geometry = (IDictionary)feature["geometry"]; string geotype = (string)geometry["type"]; IDictionary properties = (IDictionary)feature["properties"]; string kind = ""; string kinddetail = ""; string name = "_"; string id = ""; name = OSMTools.GetProperty(properties, "name"); kind = OSMTools.GetProperty(properties, "kind"); kinddetail = OSMTools.GetProperty(properties, "kind_detail"); id = OSMTools.GetProperty(properties, "id"); //if (name == "_") continue; if (!CanWeInclude(AllowKinds, kind)) { continue; } List <List <Vector3> > segments = new List <List <Vector3> >(); if (geotype == "LineString" && CanWeInclude(AllowShapes, "LineString")) { List <Vector3> list = new List <Vector3>(); foreach (IList piece in (IList)geometry["coordinates"]) { double dx = (double)piece[0]; double dz = (double)piece[1]; Vector3 v = MapTools.LatLonToMeters((float)dz, (float)dx).ToVector3(); v -= PositionMeters.ToVector3(); list.Add(v); } list = OSMTools.InsertPoints(list, InterpolateRoadMeters); segments.Add(list); } if (geotype == "MultiLineString" && CanWeInclude(AllowShapes, "MultiLineString")) { foreach (IList piecelist in (IList)geometry["coordinates"]) { List <Vector3> list = new List <Vector3>(); foreach (IList piece in (IList)piecelist) { double dx = (double)piece[0]; double dz = (double)piece[1]; Vector3 v = MapTools.LatLonToMeters((float)dz, (float)dx).ToVector3(); v -= PositionMeters.ToVector3(); list.Add(v); } list = OSMTools.InsertPoints(list, InterpolateRoadMeters); segments.Add(list); } } if (segments.Count > 0) { MeshData md = new MeshData(); Run(segments, md, GetWidthForKind(kind)); GameObject go = new GameObject(name); go.layer = LayerMask.NameToLayer("Roads"); MassiveFeature f = go.AddComponent <MassiveFeature>(); f.SetSegments(segments); f.SetProperties(properties); f.SetType(geotype); f.SetID(id); go.transform.parent = this.transform; go.transform.localPosition = Vector3.zero; // Create the mesh CreateGameObject(md, go, kind); //WriteAsset(go, AssetPath); } } #if UNITY_EDITOR AssetDatabase.SaveAssets(); #endif }