/// <summary> /// Create a footprint roof. /// </summary> /// <param name="footPrint">The footprint is a curve loop, or a wall loop, or loops combined of walls and curves</param> /// <param name="level">The base level of the roof to be created.</param> /// <param name="roofType">The type of the newly created roof.</param> /// <returns>Return a new created footprint roof.</returns> public FootPrintRoof CreateFootPrintRoof(CurveArray footPrint, Level level, RoofType roofType) { FootPrintRoof footprintRoof = null; Transaction createRoofTransaction = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "FootPrintRoof"); createRoofTransaction.Start(); try { ModelCurveArray footPrintToModelCurveMapping = new ModelCurveArray(); footprintRoof = m_creationDoc.NewFootPrintRoof(footPrint, level, roofType, out footPrintToModelCurveMapping); createRoofTransaction.Commit(); } catch (System.Exception e) { createRoofTransaction.RollBack(); throw e; } return footprintRoof; }
/// <summary> /// Create a extrusion roof. /// </summary> /// <param name="profile">The profile combined of straight lines and arcs.</param> /// <param name="refPlane">The reference plane for the extrusion roof.</param> /// <param name="level">The reference level of the roof to be created.</param> /// <param name="roofType">The type of the newly created roof.</param> /// <param name="extrusionStart">The extrusion start point.</param> /// <param name="extrusionEnd">The extrusion end point.</param> /// <returns>Return a new created extrusion roof.</returns> public ExtrusionRoof CreateExtrusionRoof(CurveArray profile, ReferencePlane refPlane, Level level, RoofType roofType, double extrusionStart, double extrusionEnd) { ExtrusionRoof extrusionRoof = null; Transaction createRoofTransaction = new Transaction(m_commandData.Application.ActiveUIDocument.Document, "ExtrusionRoof"); createRoofTransaction.Start(); try { extrusionRoof = m_creationDoc.NewExtrusionRoof(profile, refPlane, level, roofType, extrusionStart, extrusionEnd); createRoofTransaction.Commit(); } catch (System.Exception e) { createRoofTransaction.RollBack(); throw e; } return extrusionRoof; }
private void Stream(ArrayList data, RoofType roofType) { data.Add(new Snoop.Data.ClassSeparator(typeof(RoofType))); // No data at this level yet! }
/// <summary> /// Create a footprint roof. /// </summary> /// <param name="level">The base level of the roof to be created.</param> /// <param name="roofType">The type of the newly created roof.</param> /// <returns>Return a new created footprint roof.</returns> public FootPrintRoof CreateFootPrintRoof(Level level, RoofType roofType) { FootPrintRoof roof = null; roof = m_footPrintRoofManager.CreateFootPrintRoof(m_footPrint, level, roofType); if (roof != null) { this.m_footPrintRoofs.Insert(roof); } return roof; }
/// <summary> /// Create a extrusion roof. /// </summary> /// <param name="refPlane">The reference plane for the extrusion roof.</param> /// <param name="level">The reference level of the roof to be created.</param> /// <param name="roofType">The type of the newly created roof.</param> /// <param name="extrusionStart">The extrusion start point.</param> /// <param name="extrusionEnd">The extrusion end point.</param> /// <returns>Return a new created extrusion roof.</returns> public ExtrusionRoof CreateExtrusionRoof(ReferencePlane refPlane, Level level, RoofType roofType, double extrusionStart, double extrusionEnd) { ExtrusionRoof roof = null; roof = m_extrusionRoofManager.CreateExtrusionRoof(m_profile, refPlane, level, roofType, extrusionStart, extrusionEnd); if (roof != null) { m_extrusionRoofs.Insert(roof); } return roof; }
private static void CreateHouseRoofTriangles(int countVertices, List <Vector3> vertices, RoofType roofType, float[] roofPoints, float baseHeight, float roofHeight, ref List <int> triangles) { if (roofType == RoofType.flat) { if (roofIndices == null) { roofIndices = new List <int>(60); } triangles.AddRange(OnlineMapsUtils.Triangulate(roofPoints, countVertices, roofIndices)); } else if (roofType == RoofType.dome) { CreateHouseRoofDome(baseHeight + roofHeight, vertices, triangles); } }
Stream(ArrayList data, RoofType roofType) { data.Add(new Snoop.Data.ClassSeparator(typeof(RoofType))); // No data at this level yet! }
private void CreateHouseRoof(List <Vector3> baseVertices, float baseHeight, float roofHeight, RoofType roofType) { float[] roofPoints = new float[baseVertices.Count * 2]; if (roofVertices == null) { roofVertices = new List <Vector3>(baseVertices.Count); } else { roofVertices.Clear(); } try { int countVertices = CreateHouseRoofVerticles(baseVertices, roofVertices, roofPoints, baseHeight); CreateHouseRoofTriangles(countVertices, roofVertices, roofType, roofPoints, baseHeight, roofHeight, ref roofTriangles); if (roofTriangles.Count == 0) { hasErrors = true; return; } Vector3 side1 = roofVertices[roofTriangles[1]] - roofVertices[roofTriangles[0]]; Vector3 side2 = roofVertices[roofTriangles[2]] - roofVertices[roofTriangles[0]]; Vector3 perp = Vector3.Cross(side1, side2); bool reversed = perp.y < 0; if (reversed) { roofTriangles.Reverse(); } float minX = float.MaxValue; float minZ = float.MaxValue; float maxX = float.MinValue; float maxZ = float.MinValue; for (int i = 0; i < roofVertices.Count; i++) { Vector3 v = roofVertices[i]; if (v.x < minX) { minX = v.x; } if (v.z < minZ) { minZ = v.z; } if (v.x > maxX) { maxX = v.x; } if (v.z > maxZ) { maxZ = v.z; } } float offX = maxX - minX; float offZ = maxZ - minZ; for (int i = 0; i < roofVertices.Count; i++) { Vector3 v = roofVertices[i]; uvs.Add(new Vector2((v.x - minX) / offX, (v.z - minZ) / offZ)); } int triangleOffset = vertices.Count; for (int i = 0; i < roofTriangles.Count; i++) { roofTriangles[i] += triangleOffset; } vertices.AddRange(roofVertices); } catch (Exception) { Debug.Log(roofTriangles.Count + " " + roofVertices.Count); hasErrors = true; throw; } }
private static void AnalizeHouseRoofType(OnlineMapsOSMWay way, ref float baseHeight, ref RoofType roofType, ref float roofHeight) { string roofShape = way.GetTagValue("roof:shape"); string roofHeightStr = way.GetTagValue("roof:height"); string minHeightStr = way.GetTagValue("min_height"); if (!String.IsNullOrEmpty(roofShape)) { if ((roofShape == "dome" || roofShape == "pyramidal") && !String.IsNullOrEmpty(roofHeightStr)) { GetHeightFromString(roofHeightStr, ref roofHeight); baseHeight -= roofHeight; roofType = RoofType.dome; } } else if (!String.IsNullOrEmpty(roofHeightStr)) { GetHeightFromString(roofHeightStr, ref roofHeight); baseHeight -= roofHeight; roofType = RoofType.dome; } else if (!String.IsNullOrEmpty(minHeightStr)) { float totalHeight = baseHeight; GetHeightFromString(minHeightStr, ref baseHeight); roofHeight = totalHeight - baseHeight; roofType = RoofType.dome; } }
/// <summary> /// Creates a new building, based on Open Street Map. /// </summary> /// <param name="container">Reference to OnlineMapsBuildings.</param> /// <param name="way">Way of building.</param> /// <param name="nodes">Nodes obtained from Open Street Maps.</param> /// <returns>Building instance.</returns> public static OnlineMapsBuildingBase Create(OnlineMapsBuildings container, OnlineMapsOSMWay way, Dictionary <string, OnlineMapsOSMNode> nodes) { if (CheckIgnoredBuildings(way)) { return(null); } if (usedNodes == null) { usedNodes = new List <OnlineMapsOSMNode>(32); } else { usedNodes.Clear(); } way.GetNodes(nodes, usedNodes); List <Vector3> points = GetLocalPoints(usedNodes); if (points.Count < 3) { return(null); } if (points[0] == points[points.Count - 1]) { points.RemoveAt(points.Count - 1); } if (points.Count < 3) { return(null); } for (int i = 0; i < points.Count; i++) { int prev = i - 1; if (prev < 0) { prev = points.Count - 1; } int next = i + 1; if (next >= points.Count) { next = 0; } float a1 = OnlineMapsUtils.Angle2D(points[prev], points[i]); float a2 = OnlineMapsUtils.Angle2D(points[i], points[next]); if (Mathf.Abs(a1 - a2) < 5) { points.RemoveAt(i); i--; } } if (points.Count < 3) { return(null); } Vector4 cp = new Vector4(float.MaxValue, float.MaxValue, float.MinValue, float.MinValue); for (int i = 0; i < points.Count; i++) { Vector3 point = points[i]; if (point.x < cp.x) { cp.x = point.x; } if (point.z < cp.y) { cp.y = point.z; } if (point.x > cp.z) { cp.z = point.x; } if (point.z > cp.w) { cp.w = point.z; } } Vector3 centerPoint = new Vector3((cp.z + cp.x) / 2, 0, (cp.y + cp.w) / 2); for (int i = 0; i < points.Count; i++) { points[i] -= centerPoint; } bool generateWall = true; if (way.HasTagKey("building")) { string buildingType = way.GetTagValue("building"); if (buildingType == "roof") { generateWall = false; } } float baseHeight = 15; float roofHeight = 0; OnlineMapsBuildingMaterial material = GetRandomMaterial(container); Vector2 scale = Vector2.one; if (defaultShader == null) { defaultShader = Shader.Find("Diffuse"); } GameObject houseGO = CreateGameObject(way.id); MeshRenderer renderer = houseGO.AddComponent <MeshRenderer>(); MeshFilter meshFilter = houseGO.AddComponent <MeshFilter>(); OnlineMapsBuildingBuiltIn building = houseGO.AddComponent <OnlineMapsBuildingBuiltIn>(); building.way = way; building.nodes = new List <OnlineMapsOSMNode>(usedNodes); houseGO.transform.localPosition = centerPoint; houseGO.transform.localRotation = Quaternion.Euler(Vector3.zero); houseGO.transform.localScale = Vector3.one; if (material != null) { if (material.wall != null) { building.wallMaterial = Instantiate(material.wall) as Material; } else { building.wallMaterial = new Material(defaultShader); } if (material.roof != null) { building.roofMaterial = Instantiate(material.roof) as Material; } else { building.roofMaterial = new Material(defaultShader); } scale = material.scale; } else { if (defaultWallMaterial == null) { defaultWallMaterial = new Material(defaultShader); } if (defaultRoofMaterial == null) { defaultRoofMaterial = new Material(defaultShader); } building.wallMaterial = Instantiate(defaultWallMaterial) as Material; building.roofMaterial = Instantiate(defaultRoofMaterial) as Material; } RoofType roofType = RoofType.flat; AnalizeHouseTags(way, ref building.wallMaterial, ref building.roofMaterial, ref baseHeight); AnalizeHouseRoofType(way, ref baseHeight, ref roofType, ref roofHeight); building.mesh = new Mesh { name = way.id }; meshFilter.sharedMesh = building.mesh; renderer.sharedMaterials = new [] { building.wallMaterial, building.roofMaterial }; Vector2 centerCoords = Vector2.zero; float minCX = float.MaxValue, minCY = float.MaxValue, maxCX = float.MinValue, maxCY = float.MinValue; foreach (OnlineMapsOSMNode node in usedNodes) { Vector2 nodeCoords = node; centerCoords += nodeCoords; if (nodeCoords.x < minCX) { minCX = nodeCoords.x; } if (nodeCoords.y < minCY) { minCY = nodeCoords.y; } if (nodeCoords.x > maxCX) { maxCX = nodeCoords.x; } if (nodeCoords.y > maxCY) { maxCY = nodeCoords.y; } } building.id = way.id; building.initialZoom = OnlineMaps.instance.buffer.apiZoom; building.centerCoordinates = new Vector2((maxCX + minCX) / 2, (maxCY + minCY) / 2); building.boundsCoords = new Bounds(building.centerCoordinates, new Vector3(maxCX - minCX, maxCY - minCY)); int wallVerticesCount = (points.Count + 1) * 2; int roofVerticesCount = points.Count; int verticesCount = wallVerticesCount + roofVerticesCount; int countTriangles = wallVerticesCount * 3; if (vertices == null) { vertices = new List <Vector3>(verticesCount); } else { vertices.Clear(); } if (uvs == null) { uvs = new List <Vector2>(verticesCount); } else { uvs.Clear(); } if (wallTriangles == null) { wallTriangles = new List <int>(countTriangles); } else { wallTriangles.Clear(); } if (roofTriangles == null) { roofTriangles = new List <int>(); } else { roofTriangles.Clear(); } double tlx, tly, brx, bry; OnlineMaps.instance.buffer.GetCorners(out tlx, out tly, out brx, out bry); baseHeight *= OnlineMapsTileSetControl.instance.GetBestElevationYScale(tlx, tly, brx, bry) * OnlineMapsBuildings.instance.heightScale; if (generateWall) { building.CreateHouseWall(points, baseHeight, building.wallMaterial, scale); } building.CreateHouseRoof(points, baseHeight, roofHeight, roofType); if (building.hasErrors) { OnlineMapsUtils.DestroyImmediate(building.gameObject); return(null); } building.mesh.vertices = vertices.ToArray(); building.mesh.uv = uvs.ToArray(); building.mesh.subMeshCount = 2; building.mesh.SetTriangles(wallTriangles.ToArray(), 0); building.mesh.SetTriangles(roofTriangles.ToArray(), 1); building.mesh.RecalculateBounds(); building.mesh.RecalculateNormals(); building.buildingCollider = houseGO.AddComponent <MeshCollider>(); (building.buildingCollider as MeshCollider).sharedMesh = building.mesh; return(building); }
/// <summary> /// Adds the new foot print roof. /// </summary> /// <param name="doc"></param> /// <param name="profile"></param> /// <param name="lvl"></param> /// <param name="type"></param> /// <param name="model"></param> /// <returns></returns> public static FootPrintRoof AddFootPrintRoof(this Document doc, CurveArray profile, Level lvl, RoofType type, out ModelCurveArray model) { return(doc.Create.NewFootPrintRoof(profile, lvl, type, out model)); }
/// <summary> /// Adds the new extrusion roof. /// </summary> /// <param name="doc"></param> /// <param name="profile"></param> /// <param name="plane"></param> /// <param name="lvl"></param> /// <param name="type"></param> /// <param name="start"></param> /// <param name="end"></param> /// <returns></returns> public static ExtrusionRoof AddExtrusionRoof(this Document doc, CurveArray profile, ReferencePlane plane, Level lvl, RoofType type, double start, double end) { return(doc.Create.NewExtrusionRoof(profile, plane, lvl, type, start, end)); }