/// <summary> /// Split faces so that none face is intercepted by a face of other object /// </summary> /// <param name="compareObject">the other object 3d used to make the split</param> public void SplitFaces(Object3D compareObject) { Line line; Face thisFace, compareFace; Segment segment1; Segment segment2; double v1DistToCompareFace, distFace1Vert2, distFace1Vert3, distFace2Vert1, distFace2Vert2, distFace2Vert3; int signFace1Vert1, signFace1Vert2, signFace1Vert3, signFace2Vert1, signFace2Vert2, signFace2Vert3; int numFacesBefore = this.GetNumFaces(); int numFacesStart = this.GetNumFaces(); //if the objects bounds overlap... if (this.GetBound().Overlap(compareObject.GetBound())) { //for each object1 face... for (int thisFaceIndex = 0; thisFaceIndex < this.GetNumFaces(); thisFaceIndex++) { //if object1 face bound and object2 bound overlap ... thisFace = GetFace(thisFaceIndex); if (thisFace.GetBound().Overlap(compareObject.GetBound())) { //for each object2 face... for (int compareFaceIndex = 0; compareFaceIndex < compareObject.GetNumFaces(); compareFaceIndex++) { //if object1 face bound and object2 face bound overlap... compareFace = compareObject.GetFace(compareFaceIndex); if (thisFace.GetBound().Overlap(compareFace.GetBound())) { //PART I - DO TWO POLIGONS INTERSECT? //POSSIBLE RESULTS: INTERSECT, NOT_INTERSECT, COPLANAR //distance from the face1 vertices to the face2 plane v1DistToCompareFace = ComputeDistance(thisFace.v1, compareFace); distFace1Vert2 = ComputeDistance(thisFace.v2, compareFace); distFace1Vert3 = ComputeDistance(thisFace.v3, compareFace); //distances signs from the face1 vertices to the face2 plane signFace1Vert1 = (v1DistToCompareFace > EqualityTolerance ? 1 : (v1DistToCompareFace < -EqualityTolerance ? -1 : 0)); signFace1Vert2 = (distFace1Vert2 > EqualityTolerance ? 1 : (distFace1Vert2 < -EqualityTolerance ? -1 : 0)); signFace1Vert3 = (distFace1Vert3 > EqualityTolerance ? 1 : (distFace1Vert3 < -EqualityTolerance ? -1 : 0)); //if all the signs are zero, the planes are coplanar //if all the signs are positive or negative, the planes do not intersect //if the signs are not equal... if (!(signFace1Vert1 == signFace1Vert2 && signFace1Vert2 == signFace1Vert3)) { //distance from the face2 vertices to the face1 plane distFace2Vert1 = ComputeDistance(compareFace.v1, thisFace); distFace2Vert2 = ComputeDistance(compareFace.v2, thisFace); distFace2Vert3 = ComputeDistance(compareFace.v3, thisFace); //distances signs from the face2 vertices to the face1 plane signFace2Vert1 = (distFace2Vert1 > EqualityTolerance ? 1 : (distFace2Vert1 < -EqualityTolerance ? -1 : 0)); signFace2Vert2 = (distFace2Vert2 > EqualityTolerance ? 1 : (distFace2Vert2 < -EqualityTolerance ? -1 : 0)); signFace2Vert3 = (distFace2Vert3 > EqualityTolerance ? 1 : (distFace2Vert3 < -EqualityTolerance ? -1 : 0)); //if the signs are not equal... if (!(signFace2Vert1 == signFace2Vert2 && signFace2Vert2 == signFace2Vert3)) { line = new Line(thisFace, compareFace); //intersection of the face1 and the plane of face2 segment1 = new Segment(line, thisFace, signFace1Vert1, signFace1Vert2, signFace1Vert3); //intersection of the face2 and the plane of face1 segment2 = new Segment(line, compareFace, signFace2Vert1, signFace2Vert2, signFace2Vert3); //if the two segments intersect... if (segment1.Intersect(segment2)) { //PART II - SUBDIVIDING NON-COPLANAR POLYGONS int lastNumFaces = GetNumFaces(); bool splitOccured = this.SplitFace(thisFaceIndex, segment1, segment2); //prevent from infinite loop (with a loss of faces...) if (GetNumFaces() > numFacesStart * 100) { //System.out.println("possible infinite loop situation: terminating faces split"); //return; int a = 0; } //if the face in the position isn't the same, there was a break if (splitOccured && thisFace != GetFace(thisFaceIndex)) { //if the generated solid is equal the origin... if (thisFace.Equals(GetFace(GetNumFaces() - 1))) { //return it to its position and jump it if (thisFaceIndex != (GetNumFaces() - 1)) { faces.RemoveAt(GetNumFaces() - 1); faces.Insert(thisFaceIndex, thisFace); } else { continue; } } //else: test next face else { thisFaceIndex--; break; } } } } } } } } } } }
/// <summary> /// Split faces so that none face is intercepted by a face of other object /// </summary> /// <param name="obj">the other object 3d used to make the split</param> public void SplitFaces(Object3D obj) { Line line; Face face1, face2; Segment segment1; Segment segment2; double distFace1Vert1, distFace1Vert2, distFace1Vert3, distFace2Vert1, distFace2Vert2, distFace2Vert3; int signFace1Vert1, signFace1Vert2, signFace1Vert3, signFace2Vert1, signFace2Vert2, signFace2Vert3; //int numFacesBefore = GetNumFaces(); //int numFacesStart = GetNumFaces(); //if the objects bounds overlap... if (GetBound().Overlap(obj.GetBound())) { //for each object1 face... for (int i = 0; i < GetNumFaces(); i++) { //if object1 face bound and object2 bound overlap ... face1 = GetFace(i); if (face1.GetBound().Overlap(obj.GetBound())) { //for each object2 face... for (int j = 0; j < obj.GetNumFaces(); j++) { //if object1 face bound and object2 face bound overlap... face2 = obj.GetFace(j); if (face1.GetBound().Overlap(face2.GetBound())) { //PART I - DO TWO POLIGONS INTERSECT? //POSSIBLE RESULTS: INTERSECT, NOT_INTERSECT, COPLANAR //distance from the face1 vertices to the face2 plane distFace1Vert1 = ComputeDistance(face1.v1, face2); distFace1Vert2 = ComputeDistance(face1.v2, face2); distFace1Vert3 = ComputeDistance(face1.v3, face2); //distances signs from the face1 vertices to the face2 plane signFace1Vert1 = (distFace1Vert1 > EqualityTolerance ? 1 : (distFace1Vert1 < -EqualityTolerance ? -1 : 0)); signFace1Vert2 = (distFace1Vert2 > EqualityTolerance ? 1 : (distFace1Vert2 < -EqualityTolerance ? -1 : 0)); signFace1Vert3 = (distFace1Vert3 > EqualityTolerance ? 1 : (distFace1Vert3 < -EqualityTolerance ? -1 : 0)); //if all the signs are zero, the planes are coplanar //if all the signs are positive or negative, the planes do not intersect //if the signs are not equal... if (!(signFace1Vert1 == signFace1Vert2 && signFace1Vert2 == signFace1Vert3)) { //distance from the face2 vertices to the face1 plane distFace2Vert1 = ComputeDistance(face2.v1, face1); distFace2Vert2 = ComputeDistance(face2.v2, face1); distFace2Vert3 = ComputeDistance(face2.v3, face1); //distances signs from the face2 vertices to the face1 plane signFace2Vert1 = (distFace2Vert1 > EqualityTolerance ? 1 : (distFace2Vert1 < -EqualityTolerance ? -1 : 0)); signFace2Vert2 = (distFace2Vert2 > EqualityTolerance ? 1 : (distFace2Vert2 < -EqualityTolerance ? -1 : 0)); signFace2Vert3 = (distFace2Vert3 > EqualityTolerance ? 1 : (distFace2Vert3 < -EqualityTolerance ? -1 : 0)); //if the signs are not equal... if (!(signFace2Vert1 == signFace2Vert2 && signFace2Vert2 == signFace2Vert3)) { line = new Line(face1, face2); //intersection of the face1 and the plane of face2 segment1 = new Segment(line, face1, signFace1Vert1, signFace1Vert2, signFace1Vert3); //intersection of the face2 and the plane of face1 segment2 = new Segment(line, face2, signFace2Vert1, signFace2Vert2, signFace2Vert3); //if the two segments intersect... if (segment1.Intersect(segment2)) { //PART II - SUBDIVIDING NON-COPLANAR POLYGONS //int lastNumFaces = GetNumFaces(); this.SplitFace(i, segment1, segment2); //prevent from infinite loop (with a loss of faces...) //if(numFacesStart*20<getNumFaces()) //{ // System.out.println("possible infinite loop situation: terminating faces split"); // return; //} //if the face in the position isn't the same, there was a break if (face1 != GetFace(i)) { //if the generated solid is equal the origin... if (face1.Equals(GetFace(GetNumFaces() - 1))) { //return it to its position and jump it if (i != (GetNumFaces() - 1)) { faces.RemoveAt(GetNumFaces() - 1); faces.Insert(i, face1); } else { continue; } } //else: test next face else { i--; break; } } } } } } } } } } }