public Winding translate(Vector3f offset) { if (verts.isEmpty()) { return this; } ArrayList<Vector3f> vertsNew = new ArrayList<>(); for (Vector3f vert : verts) { vertsNew.add(vert.add(offset)); } return new Winding(vertsNew); }
/** * Rotates all vertices in this winding by the given euler angles. * * @param angles rotation angles */ public Winding rotate(Vector3f angles) { if (verts.isEmpty()) { return this; } ArrayList<Vector3f> vertsNew = new ArrayList<>(); for (Vector3f vert : verts) { vertsNew.add(vert.rotate(angles)); } return new Winding(vertsNew); }
public Winding addBackface() { if (verts.isEmpty()) { return this; } List<Vector3f> vertsNew = new ArrayList<>(); final int size = verts.size(); for (int i = 0; i < size; i++) { if (i != 0) { vertsNew.add(verts.get(i)); } if (i != size) { vertsNew.add(verts.get(i)); } } return new Winding(vertsNew); }
/** * Removes degenerated vertices from this winding. A vertex is degenerated when its distance to * the previous vertex is smaller than {@link EPS_DEGEN}. * * @return number of removed vertices */ public Winding removeDegenerated() { if (verts.isEmpty()) { return this; } ArrayList<Vector3f> vertsNew = new ArrayList<>(); final int size = verts.size(); for (int i = 0; i < size; i++) { int j = (i + 1) % size; Vector3f v1 = verts.get(i); Vector3f v2 = verts.get(j); if (v1.sub(v2).length() > EPS_DEGEN) { vertsNew.add(v1); } } return new Winding(vertsNew); }
/** * Removes collinear vertices from this winding. * * @return number of removed vertices */ public Winding removeCollinear() { if (verts.isEmpty()) { return this; } ArrayList<Vector3f> vertsNew = new ArrayList<>(); final int size = verts.size(); for (int i = 0; i < size; i++) { int j = (i + 1) % size; int k = (i + size - 1) % size; Vector3f v1 = verts.get(j).sub(verts.get(i)).normalize(); Vector3f v2 = verts.get(i).sub(verts.get(k)).normalize(); if (v1.dot(v2) < 0.999) { vertsNew.add(verts.get(i)); } } return new Winding(vertsNew); }
@Override public boolean isEmpty() { return verts.isEmpty(); }