//Draws a line given a list of vector 3 public GameObject dropLine(List <Vector3> polyline, float witdh, float height, Material material, bool curved = false) { GameObject line = new GameObject("Polyline"); MeshFilter filter = line.AddComponent <MeshFilter>(); MeshRenderer renderer = line.AddComponent <MeshRenderer>(); GOLineMesh lineMesh = new GOLineMesh(polyline, curved); lineMesh.width = witdh; lineMesh.load(line); Mesh mesh = lineMesh.mesh; if (height > 0) { mesh = SimpleExtruder.SliceExtrude(mesh, line, height, 4f, 4f, 10f); } filter.sharedMesh = mesh; renderer.material = material; line.AddComponent <MeshCollider> (); return(line); }
//Draws a polygon given a list of Vector3 that is a closed shape public GameObject dropPolygon(List <Vector3> shape, float height, Material material, GOUVMappingStyle uvMappingStyle) { GameObject polygon = new GameObject("Polygon"); MeshFilter filter = polygon.AddComponent <MeshFilter>(); MeshRenderer renderer = polygon.AddComponent <MeshRenderer>(); Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = shape; GOMesh goMesh = Poly2Mesh.CreateMeshInBackground(poly); goMesh.uvMappingStyle = uvMappingStyle; goMesh.ApplyUV(shape); if (height > 0) { goMesh = SimpleExtruder.SliceExtrudePremesh(goMesh, height, 4f, 4f, 10f); } Mesh mesh = goMesh.ToSubmeshes(); filter.sharedMesh = mesh; renderer.material = material; polygon.AddComponent <MeshCollider> (); return(polygon); }
//Draws a line given a list of vector 3 public GameObject dropLine(List <Vector3> polyline, float witdh, float height, Material material, GOUVMappingStyle uvMappingStyle, bool curved = false) { GameObject line = new GameObject("Polyline"); MeshFilter filter = line.AddComponent <MeshFilter>(); MeshRenderer renderer = line.AddComponent <MeshRenderer>(); GOLineMesh lineMesh = new GOLineMesh(polyline, curved); lineMesh.width = witdh; lineMesh.load(line); GOMesh goMesh = lineMesh.CreatePremesh(); goMesh.uvMappingStyle = uvMappingStyle; if (height > 0) { goMesh = SimpleExtruder.SliceExtrudePremesh(goMesh, height, 4f, 4f, 10f); } filter.sharedMesh = goMesh.ToMesh(); renderer.material = material; line.AddComponent <MeshCollider> (); return(line); }
//Draws a polygon given a list of Vector3 that is a closed shape public GameObject dropPolygon(List <Vector3> shape, float height, Material material) { GameObject polygon = new GameObject("Polygon"); MeshFilter filter = polygon.AddComponent <MeshFilter>(); MeshRenderer renderer = polygon.AddComponent <MeshRenderer>(); Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = shape; Mesh mesh = Poly2Mesh.CreateMesh(poly); Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z) * 100; } mesh.uv = uvs; if (height > 0) { mesh = SimpleExtruder.SliceExtrude(mesh, polygon, height, 4f, 4f, 10f); } filter.sharedMesh = mesh; renderer.material = material; polygon.AddComponent <MeshCollider> (); return(polygon); }
GameObject CreateRoadOutline(GameObject line, Material material, float width) { GameObject outline = new GameObject(line.name + "outline"); outline.transform.parent = line.transform; material.renderQueue = -((int)feature.sort - 1); GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry); lineMesh.width = width; lineMesh.load(outline); mesh = lineMesh.mesh; mesh = SimpleExtruder.Extrude(mesh, outline, 0.05f); Vector2[] uvs2 = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs2.Length; i++) { uvs2[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } mesh.uv = uvs2; mesh.RecalculateBounds(); outline.GetComponent <MeshFilter>().sharedMesh = mesh; Vector3 position = outline.transform.position; position.y = -0.01f; outline.transform.localPosition = position; outline.GetComponent <Renderer>().material = material; return(outline); }
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); }
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 void BuildLine(GameObject line, GOLayer layer, GORenderingOptions renderingOptions, GOMap map) { if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return; } if (renderingOptions.tag.Length > 0) { line.tag = renderingOptions.tag; } if (renderingOptions.material) { renderingOptions.material.renderQueue = -(int)feature.sort; } if (renderingOptions.outlineMaterial) { renderingOptions.outlineMaterial.renderQueue = -(int)feature.sort; } GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry); lineMesh.width = renderingOptions.lineWidth * Global.tilesizeRank; lineMesh.load(line); mesh = lineMesh.mesh; mesh = SimpleExtruder.Extrude(mesh, line, 0.05f); line.GetComponent <MeshFilter>().sharedMesh = mesh; line.GetComponent <Renderer>().material = renderingOptions.material; Vector3 position = line.transform.position; position.y = feature.y * Global.tilesizeRank; line.transform.position = position; if (renderingOptions.outlineMaterial != null) { GameObject outline = CreateRoadOutline(line, renderingOptions.outlineMaterial, Global.tilesizeRank * (renderingOptions.lineWidth + layer.defaultRendering.outlineWidth)); if (layer.useColliders) { outline.AddComponent <MeshCollider>().sharedMesh = outline.GetComponent <MeshFilter>().sharedMesh; } outline.layer = line.layer; outline.tag = line.tag; } else if (layer.useColliders) { // Mesh m = gameObject.GetComponent<MeshFilter> ().sharedMesh; line.AddComponent <MeshCollider>(); } }
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); }
public GameObject CreateModel(Layer layer, float height) { GameObject polygon = new GameObject(); try { Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = convertedSubject; if (clips != null) { foreach (IList clipVerts in clips) { poly.holes.Add(CoordsToVerts(clipVerts)); } } MeshFilter filter = polygon.AddComponent <MeshFilter>(); polygon.AddComponent(typeof(MeshRenderer)); Mesh mesh = Poly2Mesh.CreateMesh(poly); if (mesh) { Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } mesh.uv = uvs; mesh2D = Mesh.Instantiate(mesh); if (height > 0) { mesh = SimpleExtruder.Extrude(mesh, polygon, height); } } filter.sharedMesh = mesh; if (layer.useColliders) { polygon.AddComponent <MeshCollider>().sharedMesh = mesh; } } catch (Exception ex) { Debug.Log("[PolygonHandler] Catched exeption: " + ex); } return(polygon); }
public Mesh loadExtruded(List <Vector3> _verts, float height) { verts = _verts; filter = gameObject.GetComponent <MeshFilter>(); if (filter == null) { filter = (MeshFilter)gameObject.AddComponent(typeof(MeshFilter)); } List <Vector3> vertices = verts.ToList(); Mesh mesh = CreateMesh(vertices); filter.sharedMesh = SimpleExtruder.Extrude(mesh, gameObject, height); return(mesh); }
public static GOMesh PreloadPolygon(GOFeature feature) { if (feature.convertedGeometry == null) { return(null); } if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return(null); } List <Vector3> clean = feature.convertedGeometry.Distinct().ToList(); if (clean == null || clean.Count <= 2) { return(null); } Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = feature.convertedGeometry; if (feature.clips != null) { foreach (List <Vector3> clipVerts in feature.clips) { poly.holes.Add(clipVerts); } } GOMesh preMesh = null; // try { preMesh = Poly2Mesh.CreateMeshInBackground(poly); // } catch { // Debug.LogWarning ("Catched polygon"); // } if (preMesh != null) { Vector2[] uvs = new Vector2[preMesh.vertices.Length]; Vector3[] vertices = preMesh.vertices; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(vertices[i].x, vertices[i].z); } preMesh.uv = uvs; if (feature.height > 0) { preMesh.secondaryMesh = new GOMesh(preMesh); float h = feature.height; if (GOMap.GOLink) { h += GOFeature.BuildingElevationOffset; } h += Noise(); preMesh = SimpleExtruder.SliceExtrudePremesh(preMesh, h, 4f, 4f, 10f); } } return(preMesh); }
public GameObject BuildPolygon(GOLayer layer, float height) { if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return(null); } List <Vector3> clean = feature.convertedGeometry.Distinct().ToList(); if (clean == null || clean.Count <= 2) { return(null); } GameObject polygon = new GameObject(); Profiler.BeginSample("[GoMap] Start poly2mesh"); Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = feature.convertedGeometry; if (feature.clips != null) { foreach (IList clipVerts in feature.clips) { poly.holes.Add(GOFeature.CoordsToVerts(clipVerts, true)); } } Profiler.EndSample(); MeshFilter filter = polygon.AddComponent <MeshFilter>(); meshRenderer = polygon.AddComponent <MeshRenderer>(); Profiler.BeginSample("[GoMap] Create polygon mesh"); try { mesh = Poly2Mesh.CreateMesh(poly); } catch { } Profiler.EndSample(); if (mesh) { Profiler.BeginSample("[GoMap] Set polygon UV"); Vector2[] uvs = new Vector2[mesh.vertices.Length]; Vector3[] vertices = mesh.vertices; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(vertices[i].x, vertices[i].z); } mesh.uv = uvs; Profiler.EndSample(); Profiler.BeginSample("[GoMap] instantiate mesh 2D"); mesh2D = Mesh.Instantiate(mesh); Profiler.EndSample(); Profiler.BeginSample("[GoMap] polygon extrusion"); if (height > 0) { mesh = SimpleExtruder.SliceExtrude(mesh, polygon, height, 4f, 4f, 10f); // mesh = SimpleExtruder.Extrude (mesh, polygon, height); } Profiler.EndSample(); } filter.sharedMesh = mesh; if (layer.useColliders && mesh != null && feature.convertedGeometry.Count() > 2) { polygon.AddComponent <MeshCollider>().sharedMesh = mesh; } return(polygon); }
public static GOMesh PreloadPolygon(GOFeature feature) { if (feature.convertedGeometry == null) { return(null); } if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return(null); } List <Vector3> clean = feature.convertedGeometry.Distinct().ToList(); if (clean == null || clean.Count <= 2) { return(null); } Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = feature.convertedGeometry; if (feature.clips != null) { foreach (List <Vector3> clipVerts in feature.clips) { poly.holes.Add(clipVerts); } } GOMesh preMesh = null; preMesh = Poly2Mesh.CreateMeshInBackground(poly); if (preMesh != null) { // if (feature.layer.layerType != GOLayer.GOLayerType.Buildings) { Vector2[] uvs = new Vector2[preMesh.vertices.Length]; Vector3[] vertices = preMesh.vertices; for (int i = 0; i < uvs.Length; i++) { uvs [i] = new Vector2(vertices [i].x, vertices [i].z) * 0.01f; } preMesh.uv = uvs; // } if (feature.goTile.useElevation) { feature.ComputeHighestAltitude(); } // feature.height += GOFeature.BuildingElevationOffset; if (feature.height > 0) { feature.height *= feature.goTile.worldScale; preMesh.secondaryMesh = new GOMesh(preMesh); float h = feature.height; if (feature.goTile.useElevation) { h += GOFeature.BuildingElevationOffset; } h += Noise(); preMesh.separateTop = feature.renderingOptions.hasRoof; preMesh = SimpleExtruder.SliceExtrudePremesh(preMesh, h, 4f, 4f, 10f * feature.goTile.worldScale); } } return(preMesh); }
public static GOMesh PreloadPolygon(GOFeature feature) { if (feature.convertedGeometry == null) { return(null); } if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return(null); } List <Vector3> clean = feature.convertedGeometry.Distinct().ToList(); if (clean == null || clean.Count <= 2) { return(null); } Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = feature.convertedGeometry; if (feature.clips != null) { foreach (List <Vector3> clipVerts in feature.clips) { poly.holes.Add(clipVerts); } } GOMesh goMesh = null; goMesh = Poly2Mesh.CreateMeshInBackground(poly); if (goMesh != null) { goMesh.uvMappingStyle = feature.layer.uvMappingStyle; goMesh.ApplyUV(feature.convertedGeometry); goMesh.Y = feature.y; if (feature.goTile.useElevation) { feature.ComputeHighestAltitude(); } if (feature.height > 0) { feature.height *= feature.goTile.worldScale; goMesh.secondaryMesh = new GOMesh(goMesh); float h = feature.height; if (feature.goTile.useElevation) { h += GOFeature.BuildingElevationOffset; } h += Noise(); goMesh.separateTop = feature.renderingOptions.hasRoof; if (feature.layer.slicedExtrusion) { goMesh = SimpleExtruder.SliceExtrudePremesh(goMesh, h, 4f, 4f, 10f * feature.goTile.worldScale); } else { goMesh = SimpleExtruder.ExtrudePremesh(goMesh, h); } } if (feature.height < feature.layer.colliderHeight) { float h = feature.layer.colliderHeight; h *= feature.goTile.worldScale; if (feature.goTile.useElevation) { h += GOFeature.BuildingElevationOffset; } goMesh.secondaryMesh = new GOMesh(goMesh); goMesh.secondaryMesh = SimpleExtruder.SliceExtrudePremesh(goMesh.secondaryMesh, h, 4f, 4f, 10f * feature.goTile.worldScale); } } return(goMesh); }
public GameObject BuildPolygon(string name, GOLayer layer, float height) { //GameObject polygon = GameObject.Instantiate((GameObject)Resources.Load("Prefabs/CityBuildings/" + "Building_CornerHouse_A")); GameObject polygon = new GameObject(); Poly2Mesh.Polygon poly = new Poly2Mesh.Polygon(); poly.outside = feature.convertedGeometry; if (feature.clips != null) { foreach (IList clipVerts in feature.clips) { poly.holes.Add(GOFeature.CoordsToVerts(clipVerts)); } } MeshFilter filter = polygon.AddComponent <MeshFilter>(); polygon.AddComponent(typeof(MeshRenderer)); try { mesh = Poly2Mesh.CreateMesh(poly); } catch { } if (height > 1) { if (mesh) { Vector2[] uv2d = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uv2d.Length; i++) { uv2d[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } var meshlemp = Mesh.Instantiate(mesh); meshlemp.uv = uv2d; mesh2D = Mesh.Instantiate(meshlemp); mesh.uv = uv2d; if (height > 0) { mesh = SimpleExtruder.Extrude(mesh, polygon, height); Vector2[] uvs3D = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs3D.Length - 1; i++) { uvs3D[i] = new Vector2(Vector2.Distance(new Vector2(mesh.vertices[i + 1].x, mesh.vertices[i + 1].z), new Vector2(mesh.vertices[i].x, mesh.vertices[i].z)), mesh.vertices[i].y); } // uvs2[uvs2.Length - 1] = new Vector2(Mathf.Sqrt((float)(Math.Pow(mesh.vertices[0].x - mesh.vertices[uvs2.Length - 1].x, 2) + Math.Pow(mesh.vertices[0].z - mesh.vertices[uvs2.Length - 1].z, 2))), mesh.vertices[uvs2.Length - 1].y); uvs3D[uvs3D.Length - 1] = new Vector2(10, mesh.vertices[uvs3D.Length - 1].y); mesh.uv = uvs3D; } } } else { if (mesh) { Vector2[] uvs = new Vector2[mesh.vertices.Length]; for (int i = 0; i < uvs.Length; i++) { uvs[i] = new Vector2(mesh.vertices[i].x, mesh.vertices[i].z); } mesh.uv = uvs; if (height > 0) { mesh = SimpleExtruder.Extrude(mesh, polygon, height); } } } filter.sharedMesh = mesh; if (layer.useColliders) { polygon.AddComponent <MeshCollider>().sharedMesh = mesh; } return(polygon); }
public void BuildLine(GameObject line, GOLayer layer, GORenderingOptions renderingOptions, GOMap map) { if (feature.convertedGeometry.Count == 2 && feature.convertedGeometry[0].Equals(feature.convertedGeometry[1])) { return; } #if GOLINK feature.convertedGeometry = GOFeatureMeshBuilder.BreakLine(feature.convertedGeometry, map.goTerrain); #endif if (renderingOptions.tag.Length > 0) { line.tag = renderingOptions.tag; } if (renderingOptions.material) { renderingOptions.material.renderQueue = -(int)feature.sort; } if (renderingOptions.outlineMaterial) { renderingOptions.outlineMaterial.renderQueue = -(int)feature.sort; } GOLineMesh lineMesh = new GOLineMesh(feature.convertedGeometry); lineMesh.width = renderingOptions.lineWidth; lineMesh.load(line); mesh = lineMesh.mesh; line.GetComponent <Renderer>().material = renderingOptions.material; Vector3 position = line.transform.position; position.y = feature.y; #if GOLINK if (renderingOptions.polygonHeight > 0) { int offset = GOFeature.BuildingElevationOffset; line.GetComponent <MeshFilter> ().sharedMesh = SimpleExtruder.Extrude(line.GetComponent <MeshFilter> ().sharedMesh, line, renderingOptions.polygonHeight + offset); position.y -= offset; } #else #endif line.transform.position = position; if (renderingOptions.outlineMaterial != null) { GameObject outline = CreateRoadOutline(line, renderingOptions.outlineMaterial, renderingOptions.lineWidth + layer.defaultRendering.outlineWidth); if (layer.useColliders) { outline.AddComponent <MeshCollider> ().sharedMesh = outline.GetComponent <MeshFilter> ().sharedMesh; } outline.layer = line.layer; outline.tag = line.tag; } else if (layer.useColliders) { // Mesh m = gameObject.GetComponent<MeshFilter> ().sharedMesh; line.AddComponent <MeshCollider> (); } }