From 98313f976e93ae75ff175ccaf78ea9f383ca26d9 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Thu, 16 Jan 2025 12:44:29 -0500 Subject: [PATCH] Fixing the extrude process --- .../java/eu/mihosoft/vrl/v3d/Extrude.java | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/src/main/java/eu/mihosoft/vrl/v3d/Extrude.java b/src/main/java/eu/mihosoft/vrl/v3d/Extrude.java index 56d32331..a3b49ea0 100644 --- a/src/main/java/eu/mihosoft/vrl/v3d/Extrude.java +++ b/src/main/java/eu/mihosoft/vrl/v3d/Extrude.java @@ -79,9 +79,47 @@ public CSG points(Vector3d dir, List points) { */ public CSG extrude(Vector3d dir, Polygon polygon1) { - return Extrude.monotoneExtrude(dir, polygon1); - } + return monotoneExtrude(dir, polygon1); + } + private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) { + List newPolygons = new ArrayList<>(); + CSG extrude; + //polygon1=polygon1.flipped(); + newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped())); + Polygon polygon2 = polygon1.translated(dir); + + int numvertices = polygon1.vertices.size(); + //com.neuronrobotics.sdk.common.Log.error("Building Polygon "+polygon1.getPoints().size()); + for (int i = 0; i < numvertices; i++) { + + int nexti = (i + 1) % numvertices; + + Vector3d bottomV1 = polygon1.vertices.get(i).pos; + Vector3d topV1 = polygon2.vertices.get(i).pos; + Vector3d bottomV2 = polygon1.vertices.get(nexti).pos; + Vector3d topV2 = polygon2.vertices.get(nexti).pos; + double distance = bottomV1.minus(bottomV2).magnitude(); + if(Math.abs(distance) topPolygons = PolygonUtil.concaveToConvex(polygon2.flipped()); + newPolygons.addAll(topPolygons); + extrude = CSG.fromPolygons(newPolygons); + + return extrude; + } @Override public CSG extrude(Vector3d dir, List points) { @@ -564,22 +602,6 @@ public static CSG sweep(Polygon p, Transform increment, Transform offset, int st public static CSG sweep(Polygon p, double angle, double z, double radius, int steps) { return sweep(p, new Transform().rotX(angle).movex(z), new Transform().movey(radius), steps); } - private static CSG monotoneExtrude(Vector3d dir, Polygon polygon1) { - List newPolygons = new ArrayList<>(); - CSG extrude; - //polygon1=polygon1.flipped(); - newPolygons.addAll(PolygonUtil.concaveToConvex(polygon1.flipped())); - Polygon polygon2 = polygon1.translated(dir); - newPolygons.addAll(monotoneExtrude(polygon1, polygon1)); - polygon2 = polygon2.flipped(); - List topPolygons = PolygonUtil.concaveToConvex(polygon2.flipped()); - - newPolygons.addAll(topPolygons); - extrude = CSG.fromPolygons(newPolygons); - - return extrude; - } - public static List monotoneExtrude(Polygon polygon2, Polygon polygon1) { List newPolygons = new ArrayList<>();