use of org.twak.viewTrace.facades.GreebleHelper.LPoint3d in project chordatlas by twak.
the class GreebleSkel method mapTo2d.
protected void mapTo2d(Face f, Loop<LPoint3d> ll, MiniFacade mf, WallTag wallTag, Set<QuadF> features, MatMeshBuilder faceMaterial) {
Matrix4d to2dXY = new Matrix4d();
Vector3d up = f.edge.uphill, along = f.edge.direction(), out = f.edge.getPlaneNormal();
along.normalize();
to2dXY.setRow(2, up.x, up.y, up.z, 0);
to2dXY.setRow(1, out.x, out.y, out.z, 0);
to2dXY.setRow(0, -along.x, -along.y, -along.z, 0);
Point3d bottomS = f.definingSE.iterator().next().getStart(f), bottomE = f.definingSE.iterator().next().getEnd(f);
Point3d start = new Point3d(bottomS);
Point3d end = new Point3d(bottomE);
to2dXY.m33 = 1;
to2dXY.transform(start);
to2dXY.m03 = -start.x;
to2dXY.m13 = -start.y;
to2dXY.m23 = -start.z;
start = new Point3d(bottomS);
to2dXY.transform(start);
to2dXY.transform(end);
Loop<LPoint2d> flat = GreebleHelper.to2dLoop(GreebleHelper.transform(ll, to2dXY), 1);
Matrix4d to3d = new Matrix4d(to2dXY);
to3d.invert();
{
// face in z-up, we're in y-up
double[] one = new double[4], two = new double[4];
to3d.getRow(1, one);
to3d.getRow(2, two);
to3d.setRow(1, two);
to3d.setRow(2, one);
}
// now in jme space
Matrix4d to2d = new Matrix4d(to3d);
to2d.invert();
MiniFacade forFace = null;
if (mf != null) {
forFace = new MiniFacade(mf);
forFace.rects.clear();
}
LinearForm3D facePlane = new LinearForm3D(new Vector3d(out.x, out.z, out.y), new Point3d(bottomS.x, bottomS.z, bottomS.y));
LoopL<Point2d> sides = null;
DRectangle facadeRect = null;
if (wallTag != null) {
sides = findRectagle(flat, Pointz.to2(start), Pointz.to2(end));
if (sides != null)
facadeRect = findRect(sides.remove(0));
}
List<DRectangle> floors = new ArrayList();
List<MeshBuilder> materials = new ArrayList();
if (wallTag != null && facadeRect != null && mf != null && wallTag.isGroundFloor && mf.groundFloorHeight > 0 && wallTag.groundFloorColor != null && facadeRect.x < mf.groundFloorHeight && facadeRect.getMaxX() > mf.groundFloorHeight) {
floors.addAll(facadeRect.splitY(mf.groundFloorHeight));
MatMeshBuilder gfm = greebleGrid.mbs.get("brick", wallTag.groundFloorColor);
for (Loop<Point2d> loop : sides) {
Loop<Point2d>[] cut = Loopz.cutConvex(loop, new LinearForm(0, 1, mf.groundFloorHeight));
faceMaterial.add(cut[1].singleton(), to3d);
gfm.add(cut[0].singleton(), to3d);
}
materials.add(gfm);
materials.add(faceMaterial);
} else {
floors.add(facadeRect);
materials.add(faceMaterial);
if (sides != null)
faceMaterial.add(sides, to3d);
}
for (int j = 0; j < floors.size(); j++) {
DRectangle floorRect = floors.get(j);
MeshBuilder m = materials.get(j);
Iterator<QuadF> quit = features.iterator();
while (quit.hasNext()) {
QuadF n = quit.next();
if (n.project(to2d, to3d, flat, facePlane, new Vector3d(along.y, 0, -along.x)) && wallTag != null && floorRect != null && forFace != null) {
// set the vertical bounds, so we can just render in 2d
FRect bounds = new FRect(n.original);
n.setBounds(to2d, bounds);
if (floorRect.contains(bounds)) {
forFace.rects.put(n.original.f, bounds);
quit.remove();
}
}
}
if (wallTag == null || forFace == null || floorRect == null) {
m.add(flat.singleton(), to3d);
return;
}
List<DRectangle> occlusions = new ArrayList<>();
for (LineHeight lh : wallTag.occlusions) {
Point3d s = new Point3d(lh.start.x, lh.start.y, lh.min), e = new Point3d(lh.end.x, lh.end.y, lh.max);
to2dXY.transform(s);
to2dXY.transform(e);
occlusions.add(new DRectangle(Math.min(s.x, e.x), s.z, Math.abs(e.x - s.x), Math.abs(e.z - s.z)));
}
if (mf.texture == null)
greebleGrid.buildGrid(floorRect, to3d, forFace, m, wallTag);
else
greebleGrid.textureGrid(floorRect, to3d, mf);
}
}
use of org.twak.viewTrace.facades.GreebleHelper.LPoint3d in project chordatlas by twak.
the class GreebleSkel method face.
private void face(Face f, MiniFacade mf, Set<QuadF> features, float[] roofColor, float[] wallColor) {
MatMeshBuilder faceColor = mbs.ERROR;
WallTag wallTag = null;
for (Tag t : f.profile) {
if (t instanceof WallTag) {
wallTag = ((WallTag) t);
faceColor = greebleGrid.mbs.get("brick", wallTag.color != null ? wallTag.color : wallColor);
} else if (t instanceof RoofTag) {
RoofTag rt = (RoofTag) t;
faceColor = greebleGrid.mbs.get("tile", rt.color != null ? rt.color : roofColor);
}
}
if (f.edge.getPlaneNormal().angle(new Vector3d(0, 0, 1)) < 0.1)
wallTag = null;
for (Loop<Point3d> ll : f.getLoopL()) {
for (Loopable<Point3d> lll : ll.loopableIterator()) if (lll.get().distance(lll.getNext().get()) > 200)
return;
}
for (Loop<LPoint3d> ll : GreebleHelper.findPerimeter(f)) {
if (wallTag != null)
wallTag.isGroundFloor = f.definingCorners.iterator().next().z < 1;
mapTo2d(f, ll, mf, wallTag, features, faceColor);
}
}
Aggregations