public void SplitVolume(int volumeIndexA, int pointIndexA, int pointIndexB) { //add second volume int volumeIndexB = AddVolume(); BuildrVolume volumeA = volumes[volumeIndexA]; BuildrVolume volumeB = volumes[volumeIndexB]; int volumeASize = volumeA.Count; int volumePointIndexA = volumeA.IndexOf(pointIndexA); int volumePointIndexB = volumeA.IndexOf(pointIndexB); //switchy if (volumePointIndexB < volumePointIndexA) { volumePointIndexA = volumeA.IndexOf(pointIndexB); volumePointIndexB = volumeA.IndexOf(pointIndexA); pointIndexA = volumeA.points[volumePointIndexA]; pointIndexB = volumeA.points[volumePointIndexB]; } List <int> pointIndices = new List <int>(); for (int i = 0; i < volumeASize; i++) { pointIndices.Add(volumeA.points[i]); if (i == volumePointIndexA) { i = volumePointIndexB; pointIndices.Add(volumeA.points[i]); } } //Add the points from the first volume to the new volume for (int i = 0; i < volumeASize; i++) { int facadeIndex = volumeA.points[i]; if (!pointIndices.Contains(facadeIndex) || facadeIndex == pointIndexA || facadeIndex == pointIndexB) { BuildrVolumeStylesUnit[] styleUnits = volumeA.styles.GetContentsByFacade(facadeIndex); volumeB.Add(facadeIndex, styleUnits); } } //Remove point from the first volume for (int i = 0; i < volumeASize; i++) { int pointIndex = volumeA.points[i]; if (!pointIndices.Contains(pointIndex)) { volumeA.Remove(pointIndex); volumeASize--; i--; } } }
public void MergeVolumes(int volumeIndexA, int volumeIndexB) { BuildrVolume volumeA = volumes[volumeIndexA]; BuildrVolume volumeB = volumes[volumeIndexB]; int volumeASize = volumeA.Count; int volumeBSize = volumeB.Count; List <int> keepPoints = new List <int>(); string outpt = ""; foreach (int p in volumeA.points) { outpt += "," + p; } //Debug.Log(outpt); outpt = ""; foreach (int p in volumeB.points) { outpt += "," + p; } //Debug.Log(outpt); //find the start of volume A - where the connection to volume B ends. bool insideConnections = false; int volumeAStart = 0; for (int pa = 0; pa < volumeASize; pa++) { int paa = volumeA.points[pa]; int pab = volumeA.points[(pa + 1) % volumeASize]; int linkedVA = GetConnectingVolumeIndex(volumeIndexA, paa, pab); if (insideConnections) { if (linkedVA != volumeIndexB) //if we leave the connection - mark the start of the non connected points { volumeAStart = pa; break; } } else { if (linkedVA == volumeIndexB) //we have entered connected points { insideConnections = true; } } } for (int pa = 0; pa < volumeASize; pa++) { int pas = (pa + volumeAStart) % volumeASize; int paa = volumeA.points[pas]; int pab = volumeA.points[(pas + 1) % volumeASize]; int linkedVA = GetConnectingVolumeIndex(volumeIndexA, paa, pab); if (linkedVA != volumeIndexB) //if we leave the connection - mark the start of the non connected points { keepPoints.Add(paa); } else { keepPoints.Add(paa); //add last point break; } } outpt = ""; foreach (int p in keepPoints) { outpt += "," + p; } //Debug.Log(outpt); int volumeBStartIndex = volumeB.IndexOf(keepPoints[keepPoints.Count - 1]); //Debug.Log("volumeBStartIndex "+volumeBStartIndex); for (int pb = 1; pb < volumeBSize; pb++) //start at one as we already have the first point logged from volume a { int pbs = (pb + volumeBStartIndex) % volumeBSize; int pba = volumeB.points[pbs]; int pbb = volumeB.points[(pbs + 1) % volumeBSize]; int linkedVB = GetConnectingVolumeIndex(volumeIndexB, pba, pbb); //Debug.Log(pbs+" "+pba+" "+pbb+" "+linkedVB); if (linkedVB != volumeIndexA) //if we leave the connection - mark the start of the non connected points { keepPoints.Add(pba); } else { break; } } //keepPoints.RemoveAt(keepPoints.Count-1);//remove last one - it is the start of volume a outpt = ""; foreach (int p in keepPoints) { outpt += "," + p; } //Debug.Log(outpt); //remove all the linked points for (int rp = 0; rp < volumeASize; rp++) { int point = volumeA.points[rp]; if (!keepPoints.Contains(point)) { int keepPointLength = keepPoints.Count; for (int ap = 0; ap < keepPointLength; ap++) { int keepPoint = keepPoints[ap]; if (keepPoint > point) { keepPoints[ap]--; } } Debug.Log(point); RemovePoint(point); volumeASize--; rp--; } } //transfer all the styles across to the one volume foreach (int kp in keepPoints) { BuildrVolumeStylesUnit[] VBStyles = volumeB.styles.GetContents(); if (!volumeA.Contains(kp)) { foreach (BuildrVolumeStylesUnit style in VBStyles) { if (style.facadeID == kp) { volumeA.styles.AddStyle(style.styleID, style.facadeID, style.floors); } } } } //reassign the list of points volumeA.points = new List <int>(keepPoints); //remove old volume RemoveVolume(volumeB); outpt = ""; foreach (int p in volumeA.points) { outpt += "," + p; } //Debug.Log(outpt); }