use of javax.vecmath.Point2d in project chordatlas by twak.
the class MiniFacade method getMenu.
@Override
public void getMenu(MouseEvent e, PanMouseAdaptor ma, ChangeListener cl) {
mouseDown(e, ma);
SimplePopup2 pop = new SimplePopup2(e);
if (dragging != null)
pop.add("delete", new Runnable() {
@Override
public void run() {
if (dragging != null)
rects.remove(dragging.f, dragging);
cl.stateChanged(null);
}
});
if (dragging != null)
pop.add("duplicate", new Runnable() {
@Override
public void run() {
mouseDown(e, ma);
if (dragging != null) {
FRect rec = new FRect(dragging);
// rec.x += 0.5;
rec.x += rec.width + 0.3;
rects.put(rec.f, rec);
cl.stateChanged(null);
}
}
});
for (Feature f : Feature.values()) {
pop.add("add " + f.name().toLowerCase(), new Runnable() {
@Override
public void run() {
Point2d pt = flip(ma.from(e));
FRect rec = new FRect(pt.x, pt.y, pt.x + 0.5, pt.y + 0.5);
rec.f = f;
rects.put(f, rec);
cl.stateChanged(null);
}
});
}
pop.add("color", new Runnable() {
@Override
public void run() {
new ColourPicker(null, new Color((float) color[0], (float) color[1], (float) color[2])) {
@Override
public void picked(Color color) {
MiniFacade.this.color = new double[] { color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1 };
cl.stateChanged(null);
}
};
}
});
pop.show();
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class GreebleGrid method findWorldBox.
protected Vector3f[] findWorldBox(DRectangle door, Matrix4d to3d, double depth) {
Point2d[] pts = door.points();
Point3d[] ptt = new Point3d[4];
for (int i = 0; i < 4; i++) {
ptt[i] = Pointz.to3(pts[i]);
to3d.transform(ptt[i]);
}
Vector3d along = new Vector3d(ptt[3]);
along.sub(ptt[0]);
along.normalize();
Vector3d up = new Vector3d(ptt[1]);
up.sub(ptt[0]);
up.normalize();
Vector3d out = new Vector3d();
out.cross(along, up);
out.normalize();
Vector3d loc = new Vector3d();
loc.cross(along, up);
loc.scale(-depth / loc.length());
loc.add(ptt[0]);
Vector3f lo = Jme3z.to(loc), ou = Jme3z.to(out), al = Jme3z.to(along), u = Jme3z.to(up), p = Jme3z.to(ptt[0]);
return new Vector3f[] { lo, ou, al, u, p };
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class GreebleSkel method toPoly.
private static Loop<Point2d> toPoly(List<Point2d> left, PtInChain xyL) {
Loop<Point2d> lef = new Loop<>();
for (int i = 0; i <= xyL.prevPt; i++) lef.append(left.get(i));
if (xyL.frac > 0 && xyL.prevPt < left.size() - 1)
lef.append(new Line(left.get(xyL.prevPt), left.get(xyL.prevPt + 1)).fromPPram(xyL.frac));
lef.append(new Point2d(xyL.x, xyL.y));
lef.append(new Point2d(xyL.x, 0));
return lef;
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class GreebleSkel method findSE.
private static double[] findSE(MiniFacade mf, Line l, List<Face> chain) {
double mlen = l.length();
double lowest = Double.MAX_VALUE;
Face bestFace = null;
for (Face f : chain) {
double[] bounds = Loopz.minMax(f.getLoopL());
if (bounds[5] - bounds[4] > 1 && bounds[4] < lowest) {
bestFace = f;
lowest = bounds[4];
}
}
if (bestFace == null)
// !
return new double[] { mf.left, mf.left + mf.width };
List<Double> params = bestFace.getLoopL().streamE().map(p3 -> l.findPPram(new Point2d(p3.x, p3.y))).collect(Collectors.toList());
double[] out = new double[] { params.stream().mapToDouble(x -> x).min().getAsDouble() * mlen, params.stream().mapToDouble(x -> x).max().getAsDouble() * mlen };
// if good, stretch whole minifacade to mesh
if (Mathz.inRange((out[1] - out[0]) / (mf.width), 0.66, 1.4))
return out;
// else snap to the closest of start/end
if (l.fromPPram(out[0] / mlen).distance(l.fromPPram(mf.left / mlen)) > l.fromPPram(out[1] / mlen).distance(l.fromPPram((mf.left + mf.width) / mlen)))
return new double[] { out[1] - mf.width, out[1] };
else
return new double[] { out[0], out[0] + mf.width };
}
use of javax.vecmath.Point2d in project chordatlas by twak.
the class GreebleEdge method roofGreeble.
public static boolean roofGreeble(Face f, MeshBuilder roof) {
boolean isWall = isWall(f);
for (Loop<SharedEdge> sl : f.edges) {
for (Loopable<SharedEdge> sel : sl.loopableIterator()) {
SharedEdge se = sel.get();
boolean otherIsWall = isWall(se.getOther(f));
if (!isWall && !otherIsWall) {
Face oF = se.getOther(f);
if (oF == null || order(f, oF) || f.edge.getPlaneNormal().angle(oF.edge.getPlaneNormal()) < 0.4)
continue;
List<LinearForm3D> start = new ArrayList(), end = new ArrayList<>();
{
SharedEdge fPrev = se.getAdjEdge(f, false), fNext = se.getAdjEdge(f, true), ofPrev = se.getAdjEdge(oF, false), ofNext = se.getAdjEdge(oF, true);
if (fNext == null || fPrev == null || ofNext == null || ofPrev == null)
continue;
double overHang = -0.03;
if (isWall(fNext.getOther(f)))
end.add(toLF(fNext.getOther(f), overHang));
else
end.add(roofTween(fNext, se, f));
if (isWall(ofPrev.getOther(oF)))
end.add(toLF(ofPrev.getOther(oF), overHang));
else
end.add(roofTween(se, ofPrev, oF));
if (isWall(fPrev.getOther(f)))
start.add(toLF(fPrev.getOther(f), overHang));
else
start.add(roofTween(se, fPrev, f));
if (isWall(ofNext.getOther(oF)))
start.add(toLF(ofNext.getOther(oF), overHang));
else
start.add(roofTween(ofNext, se, oF));
}
Point3d s = se.getStart(f), e = se.getEnd(f);
if (end.contains(null) || start.contains(null))
continue;
Tube.tube(roof, end, start, new Line3d(new Point3d(s.x, s.z, s.y), new Point3d(e.x, e.z, e.y)), toLF(f, 0), toLF(oF, 0), new CrossGen() {
@Override
public List<Point2d> gen(Vector2d left, Vector2d right) {
Vector2d l = new Vector2d(left);
l.normalize();
Vector2d lP = new Vector2d(l.y, -l.x);
Vector2d r = new Vector2d(right);
r.normalize();
Vector2d rP = new Vector2d(-r.y, r.x);
List<Point2d> out = new ArrayList();
double width = 0.15, height = 0.03;
Vector2d rn = new Vector2d(r);
rn.negate();
// height / Math.sin ( ( Math.PI - l.angle( rn ) ) /2 );
double cenOffset = 0.02;
Vector2d cen = new Vector2d(lP);
cen.add(rP);
cen.normalize();
for (double[] coords : new double[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, -width }, { 0, 0, 0, height, -width }, { 0, 0, cenOffset, 0, 0 }, { -width, height, 0, 0, 0 }, { -width, 0, 0, 0, 0 } }) {
Point2d tmp = new Point2d(l), tmp2;
tmp.scale(coords[0]);
tmp2 = new Point2d(lP);
tmp2.scale(coords[1]);
tmp.add(tmp2);
tmp2 = new Point2d(cen);
tmp2.scale(coords[2]);
tmp.add(tmp2);
tmp2 = new Point2d(rP);
tmp2.scale(coords[3]);
tmp.add(tmp2);
tmp2 = new Point2d(r);
tmp2.scale(coords[4]);
tmp.add(tmp2);
out.add(tmp);
}
return out;
}
});
}
}
}
return true;
}
Aggregations