//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); }
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 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 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); }