/// <summary> /// Moves child buildings whose centerpoint is within the bounds into the tile. /// </summary> /// <param name="rd">The tile RD coordinates (bottomleft)</param> /// <param name="targetParentTile">Tile gameobject to move buildings into</param> /// <param name="removeOutside">Clear up the buildings that are outside</param> /// <returns></returns> private int MoveChildrenIntoTile(Vector2Int rd, GameObject targetParentTile, bool removeOutside = false) { //Lets use meshrenderer bounds to get the buildings centre for now, and put them in the right tile Vector3RD childRDCenter; Vector2Int childGroupedTile; int buildingsAdded = 0; MeshRenderer[] renderers = GetComponentsInChildren <MeshRenderer>(true); for (int i = renderers.Length - 1; i >= 0; i--) { var building = renderers[i]; childRDCenter = CoordConvert.UnitytoRD(building.bounds.center); childGroupedTile = new Vector2Int( Mathf.FloorToInt((float)childRDCenter.x / tileSize) * tileSize, Mathf.FloorToInt((float)childRDCenter.y / tileSize) * tileSize ); //If we have a tile for this object, put it in. if (childGroupedTile == rd) { buildingsAdded++; building.transform.SetParent(targetParentTile.transform, true); } else if (removeOutside && !overrideChildObjects.Contains(building.gameObject)) { //This child is not in our tile. destroy it. Leave it there if it is an override object Destroy(building.GetComponent <MeshFilter>().sharedMesh); Destroy(building.gameObject); } } return(buildingsAdded); }
private void ReadVertices() { Vector3[] verts = mesh.vertices; rdVertices = new Vector3RD[verts.Length]; for (int i = 0; i < verts.Length; i++) { rdVertices[i] = CoordConvert.UnitytoRD((verts[i] + tileOrigin)); } }
private Vector3Int GetCameraPosition(ICameraExtents cameraExtents) { var cameraPositionRD = CoordConvert.UnitytoRD(cameraExtents.GetPosition()); Vector3Int cameraPosition = new Vector3Int(); cameraPosition.x = (int)cameraPositionRD.x; cameraPosition.y = (int)cameraPositionRD.y; cameraPosition.z = (int)cameraPositionRD.z; return(cameraPosition); }
private List <Vector3RD> GetVertsRD(CityModel cityModel) { List <Vector3RD> vertsRD = new List <Vector3RD>(); Vector3 vertexCoordinate = new Vector3(); foreach (Vector3Double vertex in cityModel.vertices) { vertexCoordinate.x = (float)vertex.x; vertexCoordinate.y = (float)vertex.z; vertexCoordinate.z = (float)vertex.y; vertsRD.Add(CoordConvert.UnitytoRD(vertexCoordinate)); } return(vertsRD); }
private IEnumerator createFile(Bounds UnityBounds, List <Layer> layerList) { freezeLayers(layerList, true); Debug.Log(layerList.Count); Vector3RD bottomLeftRD = CoordConvert.UnitytoRD(UnityBounds.min); Vector3RD topRightRD = CoordConvert.UnitytoRD(UnityBounds.max); boundingbox = new MeshClipper.RDBoundingBox(bottomLeftRD.x, bottomLeftRD.y, topRightRD.x, topRightRD.y); DxfFile file = new DxfFile(); file.SetupDXF(); yield return(null); MeshClipper meshClipper = new MeshClipper(); loadingScreen.ShowMessage("dxf-bestand genereren..."); loadingScreen.ProgressBar.Percentage(0f); int layercounter = 0; foreach (var layer in layerList) { List <GameObject> gameObjectsToClip = getTilesInLayer(layer, bottomLeftRD, topRightRD); if (gameObjectsToClip.Count == 0) { continue; } foreach (var gameObject in gameObjectsToClip) { meshClipper.SetGameObject(gameObject); for (int submeshID = 0; submeshID < gameObject.GetComponent <MeshFilter>().sharedMesh.subMeshCount; submeshID++) { meshClipper.clipSubMesh(boundingbox, submeshID); string layerName = gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID].name.Replace(" (Instance)", ""); file.AddLayer(meshClipper.clippedVerticesRD, layerName, getColor(gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID])); yield return(null); } } loadingScreen.ProgressBar.Percentage(50 * layercounter / layerList.Count); layercounter++; } freezeLayers(layerList, false); file.Save(); loadingScreen.Hide(); Debug.Log("file saved"); }
private Vector2[] RDuv2(Vector3[] verts, Vector3 UnityOrigin, float tileSize) { Vector3 UnityCoordinate; Vector3RD rdCoordinate; Vector3RD rdOrigin = CoordConvert.UnitytoRD(UnityOrigin); float offset = -tileSize / 2; Vector2[] uv2 = new Vector2[verts.Length]; for (int i = 0; i < verts.Length; i++) { UnityCoordinate = verts[i] + UnityOrigin; rdCoordinate = CoordConvert.UnitytoRD(UnityCoordinate); uv2[i].x = ((float)(rdCoordinate.x - rdOrigin.x) + offset) / tileSize; uv2[i].y = ((float)(rdCoordinate.y - rdOrigin.y) + offset) / tileSize; } return(uv2); }
private void GetBoundingBoxCameraIsIn() { var cameraRD = CoordConvert.UnitytoRD(CameraModeChanger.Instance.ActiveCamera.transform.position); cameraRD.x = Mathf.Round((float)cameraRD.x); cameraRD.y = Mathf.Round((float)cameraRD.y); //Outside our bounds? Load a new area (always load a bigger area) if (cameraRD.x < boundingBoxMinimum.x || cameraRD.y > boundingBoxMinimum.y || cameraRD.x > boundingBoxMaximum.x || cameraRD.y < boundingBoxMaximum.y) { //Make sure to stop all ongoing requests StopAllCoroutines(); //Set new area based on rounded camera position with a margin boundingBoxMinimum.x = cameraRD.x - boundingBoxMargin; boundingBoxMinimum.y = cameraRD.y + boundingBoxMargin; boundingBoxMaximum.x = cameraRD.x + boundingBoxMargin; boundingBoxMaximum.y = cameraRD.y - boundingBoxMargin; Generate(boundingBoxMinimum, boundingBoxMaximum); } }
private IEnumerator CreateFile(Bounds UnityBounds, List <Layer> layerList) { FreezeLayers(layerList, true); Debug.Log(layerList.Count); Vector3RD bottomLeftRD = CoordConvert.UnitytoRD(UnityBounds.min); Vector3RD topRightRD = CoordConvert.UnitytoRD(UnityBounds.max); boundingbox = new MeshClipper.RDBoundingBox(bottomLeftRD.x, bottomLeftRD.y, topRightRD.x, topRightRD.y); DxfFile dxfFile = new DxfFile(); dxfFile.SetupDXF(); yield return(null); MeshClipper meshClipper = new MeshClipper(); loadingScreen.ShowMessage("DXF-bestand genereren..."); loadingScreen.ProgressBar.SetMessage(""); loadingScreen.ProgressBar.Percentage(0.1f); yield return(new WaitForEndOfFrame()); int layercounter = 0; foreach (var layer in layerList) { layercounter++; loadingScreen.ProgressBar.Percentage((float)layercounter / ((float)layerList.Count + 1)); loadingScreen.ProgressBar.SetMessage("Laag '" + layer.name + "' wordt omgezet..."); yield return(new WaitForEndOfFrame()); List <GameObject> gameObjectsToClip = GetTilesInLayer(layer, bottomLeftRD, topRightRD); if (gameObjectsToClip.Count == 0) { continue; } foreach (var gameObject in gameObjectsToClip) { meshClipper.SetGameObject(gameObject); for (int submeshID = 0; submeshID < gameObject.GetComponent <MeshFilter>().sharedMesh.subMeshCount; submeshID++) { string layerName = gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID].name.Replace(" (Instance)", ""); loadingScreen.ProgressBar.SetMessage("Laag '" + layer.name + "' object " + layerName + " wordt uitgesneden..."); yield return(new WaitForEndOfFrame()); meshClipper.ClipSubMesh(boundingbox, submeshID); dxfFile.AddLayer(meshClipper.clippedVerticesRD, layerName, GetColor(gameObject.GetComponent <MeshRenderer>().sharedMaterials[submeshID])); yield return(new WaitForEndOfFrame()); } yield return(new WaitForEndOfFrame()); } yield return(new WaitForEndOfFrame()); } loadingScreen.ProgressBar.Percentage((float)layerList.Count / ((float)layerList.Count + 1)); loadingScreen.ProgressBar.SetMessage("Het AutoCAD DXF (.dxf) bestand wordt afgerond..."); yield return(new WaitForEndOfFrame()); dxfFile.Save(); loadingScreen.Hide(); FreezeLayers(layerList, false); Debug.Log("file saved"); }