Skip to content

Commit 98313f9

Browse files
committed
Fixing the extrude process
1 parent fd4663c commit 98313f9

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/main/java/eu/mihosoft/vrl/v3d/Extrude.java

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,47 @@ public CSG points(Vector3d dir, List<Vector3d> points) {
7979
*/
8080
public CSG extrude(Vector3d dir, Polygon polygon1) {
8181

82-
return Extrude.monotoneExtrude(dir, polygon1);
83-
}
82+
return monotoneExtrude(dir, polygon1);
83+
}
84+
private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
85+
List<Polygon> newPolygons = new ArrayList<>();
86+
CSG extrude;
87+
//polygon1=polygon1.flipped();
88+
newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped()));
89+
Polygon polygon2 = polygon1.translated(dir);
90+
91+
int numvertices = polygon1.vertices.size();
92+
//com.neuronrobotics.sdk.common.Log.error("Building Polygon "+polygon1.getPoints().size());
93+
for (int i = 0; i < numvertices; i++) {
94+
95+
int nexti = (i + 1) % numvertices;
96+
97+
Vector3d bottomV1 = polygon1.vertices.get(i).pos;
98+
Vector3d topV1 = polygon2.vertices.get(i).pos;
99+
Vector3d bottomV2 = polygon1.vertices.get(nexti).pos;
100+
Vector3d topV2 = polygon2.vertices.get(nexti).pos;
101+
double distance = bottomV1.minus(bottomV2).magnitude();
102+
if(Math.abs(distance)<Plane.getEPSILON()) {
103+
//com.neuronrobotics.sdk.common.Log.error("Skipping invalid polygon "+i+" to "+nexti);
104+
continue;
105+
}
106+
try {
107+
newPolygons.add(Polygon.fromPoints(Arrays.asList(bottomV2, topV2, topV1), polygon1.getStorage()));
108+
newPolygons.add(Polygon.fromPoints(Arrays.asList(bottomV2, topV1, bottomV1), polygon1.getStorage()));
109+
}catch(Exception ex) {
110+
//com.neuronrobotics.sdk.common.Log.error("Polygon has problems: ");
111+
ex.printStackTrace();
112+
}
113+
}
114+
115+
polygon2 = polygon2.flipped();
116+
List<Polygon> topPolygons = PolygonUtil.concaveToConvex(polygon2.flipped());
84117

118+
newPolygons.addAll(topPolygons);
119+
extrude = CSG.fromPolygons(newPolygons);
120+
121+
return extrude;
122+
}
85123

86124
@Override
87125
public CSG extrude(Vector3d dir, List<Vector3d> points) {
@@ -564,22 +602,6 @@ public static CSG sweep(Polygon p, Transform increment, Transform offset, int st
564602
public static CSG sweep(Polygon p, double angle, double z, double radius, int steps) {
565603
return sweep(p, new Transform().rotX(angle).movex(z), new Transform().movey(radius), steps);
566604
}
567-
private static CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
568-
List<Polygon> newPolygons = new ArrayList<>();
569-
CSG extrude;
570-
//polygon1=polygon1.flipped();
571-
newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped()));
572-
Polygon polygon2 = polygon1.translated(dir);
573-
newPolygons.addAll(monotoneExtrude(polygon1, polygon1));
574-
polygon2 = polygon2.flipped();
575-
List<Polygon> topPolygons = PolygonUtil.concaveToConvex(polygon2.flipped());
576-
577-
newPolygons.addAll(topPolygons);
578-
extrude = CSG.fromPolygons(newPolygons);
579-
580-
return extrude;
581-
}
582-
583605
public static List<Polygon> monotoneExtrude(Polygon polygon2, Polygon polygon1) {
584606
List<Polygon> newPolygons = new ArrayList<>();
585607

0 commit comments

Comments
 (0)