X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fg3d%2Fshape%2FArcCylinder.java;h=6f82e33cab924b4de7c082550970f02597ca7ee2;hb=53d55c24c779745f188bdb18d32f71d20acb61b2;hp=ab6178440ab04a8772dd25902eb59cdfcc0d0dd9;hpb=58ebeb2baac48f9066c1395a9071f99745574ef9;p=simantics%2F3d.git 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 ab617844..6f82e33c 100644 --- a/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java +++ b/org.simantics.g3d/src/org/simantics/g3d/shape/ArcCylinder.java @@ -12,8 +12,12 @@ import javax.vecmath.Vector3d; import org.simantics.g3d.math.MathTools; public class ArcCylinder { + + public Mesh create(Point3d s, Point3d v, Point3d e, double r, int res) { + return create(s, v, e, r, res, 0.15); + } - public Mesh create(Point3d s, Point3d v, Point3d e, double rad, int res) { + public Mesh create(Point3d s, Point3d v, Point3d e, double r, int res, double res2) { Vector3d v1 = new Vector3d(s); v1.sub(v); @@ -49,7 +53,7 @@ public class ArcCylinder { rn.cross(v2, v1); rn.normalize(); - steps = (int)(Math.ceil(a/0.1)); + steps = (int)(Math.ceil(a/res2)); if (steps == 0) steps = 1; sa = a/steps; @@ -83,7 +87,57 @@ public class ArcCylinder { p.add(c); } - createCircle(vertices, normals, p, t, rn, res, rad); + 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); + } + + public Mesh create(Point3d c, Vector3d axis, Vector3d an, double R, double r, 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; + 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++) { @@ -124,9 +178,9 @@ public class ArcCylinder { int iv = c*resolution + s; /* - iv+1 ---- iv + resolution + 1 - | /| - |/ | + iv+1 ---- iv + resolution + 1 + | /| + |/ | iv ---- iv + resolution */ if (s < resolution - 1) {