From 31a158d3e63bb259e7a16a559d2a1234ddaf7136 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Tue, 22 Oct 2019 14:16:41 +0300 Subject: [PATCH] ArcCylinder with custom start angle gitlab #10 Change-Id: Ica933203d05073499f1ab46c3f4a92041b1106d6 --- .../org/simantics/g3d/shape/ArcCylinder.java | 50 +++++++++++++++++++ .../src/org/simantics/g3d/shape/Tube.java | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java b/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java index 6f82e33c..c48584bb 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java +++ b/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java @@ -147,6 +147,56 @@ public class ArcCylinder { return new Mesh(vertices, normals, indices); } +public Mesh create(Point3d c, Vector3d axis, Vector3d an, double R, double r, double starta, double a, int res, double res2) { + + + + int steps = 0; + double sa = 0.0; + + Vector3d rn = new Vector3d(axis); + rn.normalize(); + Vector3d r1 = new Vector3d(an); + r1.normalize(); + r1.scale(R); + + + if ((a +0.0001) > Math.PI) { + steps = 1; + } else { + steps = (int)(Math.ceil(a/res2)); + if (steps == 0) + steps = 1; + sa = a/steps; + } + + List vertices = new ArrayList(res * (steps+1)); + List normals = new ArrayList(res * (steps+1)); + List indices = new ArrayList(); + + for (int i = 0; i <= steps; i++) { + Vector3d p; + Vector3d t; + p = new Vector3d(); + double ca = sa * i + starta; + Quat4d q = MathTools.getQuat(new AxisAngle4d(rn, ca)); + MathTools.rotate(q, r1, p); + t = new Vector3d(); + t.cross(rn,p); + t.normalize(); + p.add(c); + + + createCircle(vertices, normals, p, t, rn, res, r); + } + int count = steps*res*6; + for (int i = 0; i < count; i++) { + indices.add(-1); + } + createIndices(steps, res, indices); + return new Mesh(vertices, normals, indices); + } + private static void createCircle(List points, List normals, Tuple3d p, Vector3d t, Vector3d n, int res, double radius) { n = new Vector3d(n); n.scale(radius); diff --git a/org.simantics.g3d/src/org/simantics/g3d/shape/Tube.java b/org.simantics.g3d/src/org/simantics/g3d/shape/Tube.java index dc7ff4e5..6b1bf618 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/shape/Tube.java +++ b/org.simantics.g3d/src/org/simantics/g3d/shape/Tube.java @@ -72,7 +72,7 @@ public class Tube { for (int i = 0; i < vertices.size() - 1; i++) { t.set(vertices.get(i+1)); t.sub(vertices.get(i)); - if (t.lengthSquared() < 0.000001) + if (t.lengthSquared() < 0.0000001) throw new IllegalArgumentException("vertices at index " + i + " are too close to each other"); } -- 2.47.1