Search in sources :

Example 6 with DRectangle

use of org.twak.utils.geom.DRectangle in project chordatlas by twak.

the class GreebleCGA method cga.

protected double cga(Loop<Point2d> rect, Matrix4d to3d, WallTag wallTag, MeshBuilder normalWall, MeshBuilder ground, Cache<float[], MeshBuilder> mbs, List<DRectangle> occlusions) {
    double[] bounds = Loopz.minMax2d(rect);
    GreebleGrid gg = new GreebleGrid(tweed, new MMeshBuilderCache());
    DRectangle all = new DRectangle(bounds[0], bounds[2], bounds[1] - bounds[0], bounds[3] - bounds[2]);
    // for (DRectangle d : occlusions)
    // mbs.get( new float[] {1,1,0,1} ).add( d, to3d );
    float[] windowColor = new float[] { 0.8f, .8f, 0.8f, 1 }, glassColor = new float[] { 0.3f, 0.3f, 1, 1 }, mouldingColor = new float[] { 0.7f, .7f, 0.7f, 1 };
    double groundFloorHeight = 0;
    List<DRectangle> floors = all.splitY(r -> splitFloors(r, 3, 2.5, 2));
    for (int f = 0; f < floors.size(); f++) {
        boolean isGround = f == 0 && wallTag.isGroundFloor;
        DRectangle floor = floors.get(f);
        MeshBuilder wall = isGround ? ground : normalWall;
        List<DRectangle> edges = floor.splitX(r -> split3(r, 1, 1));
        if (isGround)
            groundFloorHeight = floor.height;
        if (edges.size() != 3) {
            wall.add(floor, to3d);
        } else {
            wall.add(edges.get(0), to3d);
            wall.add(edges.get(edges.size() - 1), to3d);
            DRectangle cen = edges.get(1);
            if (cen.height < 1.8)
                wall.add(cen, to3d);
            else {
                if (f == 0 && wallTag.isGroundFloor) {
                    List<DRectangle> groundPanel = cen.splitX(r -> split1(r, 0.9));
                    if (groundPanel.get(0).width < 0.7)
                        wall.add(groundPanel.get(0), to3d);
                    else if (wallTag.makeDoor) {
                        List<DRectangle> doorHeight = groundPanel.get(0).splitY(r -> split1(r, 2.2));
                        if (visible(doorHeight.get(0), occlusions))
                            greebleGrid.createDoor(doorHeight.get(0), to3d, wall, mbs.get(windowColor), wallTag.doorDepth);
                        else
                            wall.add(doorHeight.get(0), to3d);
                        if (doorHeight.size() > 1)
                            wall.add(doorHeight.get(1), to3d);
                        if (groundPanel.size() > 1) {
                            List<DRectangle> gWindowPanelH = groundPanel.get(1).splitX(r -> split3(r, 0.5, 0.0));
                            if (gWindowPanelH.size() > 2) {
                                wall.add(gWindowPanelH.get(0), to3d);
                                wall.add(gWindowPanelH.get(2), to3d);
                                List<DRectangle> gWindowPanelV = gWindowPanelH.get(1).splitY(r -> split3(r, 0.5, 0.5));
                                if (gWindowPanelV.size() > 2) {
                                    wall.add(gWindowPanelV.get(0), to3d);
                                    wall.add(gWindowPanelV.get(2), to3d);
                                    if (visible(gWindowPanelV.get(1), occlusions))
                                        greebleGrid.createWindow(gWindowPanelV.get(1), to3d, wall, mbs.get(windowColor), mbs.get(glassColor), wallTag.windowDepth, -1, -1, -1, 0.6, 0.9);
                                    else
                                        wall.add(gWindowPanelV.get(1), to3d);
                                } else
                                    for (DRectangle d : gWindowPanelV) wall.add(d, to3d);
                            } else
                                for (DRectangle d : gWindowPanelH) wall.add(d, to3d);
                        }
                    } else
                        windowStrip(to3d, wallTag, mbs.get(windowColor), mbs.get(glassColor), wall, cen, false, occlusions, greebleGrid);
                } else {
                    windowStrip(to3d, wallTag, mbs.get(windowColor), mbs.get(glassColor), wall, cen, f > 0 && f < floors.size() - 1 && wallTag.makeBalcony, occlusions, greebleGrid);
                    if (f == 1 && wallTag.isGroundFloor)
                        greebleGrid.moulding(to3d, new DRectangle(floor.x, floor.y, floor.width, 0.5), mbs.get(mouldingColor));
                }
            }
        }
    }
    return groundFloorHeight;
}
Also used : Loop(org.twak.utils.collections.Loop) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) List(java.util.List) Cache(org.twak.utils.Cache) Matrix4d(javax.vecmath.Matrix4d) DRectangle(org.twak.utils.geom.DRectangle) RectDir(org.twak.utils.geom.DRectangle.RectDir) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) DRectangle(org.twak.utils.geom.DRectangle) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) List(java.util.List) ArrayList(java.util.ArrayList)

Example 7 with DRectangle

use of org.twak.utils.geom.DRectangle in project chordatlas by twak.

the class GBias method getAngle.

/**
 * local bias
 */
public Double getAngle(Line line, Point2d cen) {
    final double PI8 = Math.PI / 8;
    DRectangle r = new DRectangle(line);
    r.grow(expand);
    Collection<Longer> res = tree.queryRange(r);
    double bestScore = -Double.MAX_VALUE;
    Double bestAngle = null;
    for (AxisAlignedBoundingBox aabb : res) {
        Line gis = ((Longer) aabb).line;
        double len = gis.length();
        // gis.distance( line );
        double dist = gis.fromPPram(0.5).distance(line.fromPPram(0.5));
        if (dist < len * expand) {
            double angle = line.absAngle(gis);
            if (angle < PI8) {
                double score = (PI8 - angle) / dist;
                if (score > bestScore) {
                    bestAngle = gis.aTan2();
                    bestScore = score;
                }
            } else if (Mathz.inRangeTol(angle, Mathz.PI2, PI8)) {
                double score = 0.2 * (PI8 - angle) / dist;
                if (score > bestScore) {
                    gis = new Line(new Point2d(gis.start.y, -gis.start.x), new Point2d(gis.end.y, -gis.end.x));
                    if (gis.absAngle(line) > PI8)
                        gis = gis.reverse();
                    bestAngle = gis.aTan2();
                    bestScore = score;
                }
            }
        }
    }
    if (bestAngle != null)
        return bestAngle;
    else
        return null;
}
Also used : Line(org.twak.utils.Line) QLine(org.twak.viewTrace.QuadTree.QLine) AxisAlignedBoundingBox(org.twak.viewTrace.QuadTree.AxisAlignedBoundingBox) DRectangle(org.twak.utils.geom.DRectangle) Point2d(javax.vecmath.Point2d)

Example 8 with DRectangle

use of org.twak.utils.geom.DRectangle in project chordatlas by twak.

the class WindowGen method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    FeatureCache fg = tweed.features;
    int i = 0;
    if (fg != null) {
        for (MegaFeatures mf : fg.getBlock(block.center).features) {
            Vector3f along, up, in;
            {
                Vector2d mfl = mf.megafacade.dir();
                mfl.normalize();
                along = new Vector3f((float) mfl.x, 0, (float) mfl.y);
                up = new Vector3f(0, 1, 0);
                in = along.cross(up);
            }
            Vector3f mfStart = Jme3z.to(Pointz.to3(mf.megafacade.start));
            for (ImageFeatures im : mf.features) {
                MeshBuilder mb = new MeshBuilder();
                float offset = (float) Math.random() * 5;
                for (MiniFacade mini : im.miniFacades) {
                    for (DRectangle r : mini.rects.get(Feature.WINDOW)) {
                        Vector3f loc = new Vector3f(mfStart);
                        loc.addLocal(along.mult((float) r.x));
                        loc.addLocal(up.mult((float) r.y));
                        createWindow(mb, mb, new Window(loc.add(in.mult(offset + 0.4f)), along, up, r.width, r.height, 0.3, 0.4, 0.6));
                    }
                    if (!mini.rects.get(Feature.WINDOW).isEmpty()) {
                        Vector3f loc = new Vector3f(mfStart);
                        loc.addLocal(along.mult((float) mini.left)).addLocal(in.mult(offset));
                        mb.addCube(loc, up, along, in, (float) mini.height, (float) mini.width, 0.1f);
                    }
                }
                Geometry g = new Geometry(this.getClass().getSimpleName());
                g.setMesh(mb.getMesh());
                Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
                mat.setColor("Diffuse", Jme3z.toJme(Rainbow.getColour(i)));
                mat.setColor("Ambient", Jme3z.toJme(Rainbow.getColour(i)));
                mat.setBoolean("UseMaterialColors", true);
                g.setMaterial(mat);
                i++;
                gNode.attachChild(g);
            }
        }
    }
    super.calculate();
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) DRectangle(org.twak.utils.geom.DRectangle) ImageFeatures(org.twak.tweed.gen.FeatureCache.ImageFeatures) MegaFeatures(org.twak.tweed.gen.FeatureCache.MegaFeatures) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) Vector2d(javax.vecmath.Vector2d) Spatial(com.jme3.scene.Spatial) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) Vector3f(com.jme3.math.Vector3f)

Example 9 with DRectangle

use of org.twak.utils.geom.DRectangle in project chordatlas by twak.

the class GreebleCGA method windowStrip.

private void windowStrip(Matrix4d to3d, WallTag wallTag, MeshBuilder windowColor, MeshBuilder glassColor, MeshBuilder wall, DRectangle cen, boolean makeBalcony, List<DRectangle> occlusions, GreebleGrid gg) {
    if (cen.width < 0.7) {
        wall.add(cen, to3d);
        return;
    }
    List<DRectangle> fPanels = cen.splitX(r -> stripe(r, 1.5, 0.8));
    for (int p = 0; p < fPanels.size(); p++) {
        if (p % 2 == 0) {
            List<DRectangle> winPanel = fPanels.get(p).splitY(r -> split3Y(r, 1, 0.2));
            if (winPanel.size() == 3) {
                wall.add(winPanel.get(0), to3d);
                wall.add(winPanel.get(2), to3d);
                if (visible(winPanel.get(1), occlusions)) {
                    gg.createWindow(winPanel.get(1), to3d, wall, windowColor, glassColor, wallTag.windowDepth, (float) wallTag.sillDepth, (float) wallTag.sillHeight, -1, 0.6, 0.9);
                    if (makeBalcony) {
                        DRectangle balcony = new DRectangle(winPanel.get(1));
                        balcony.height = wallTag.balconyHeight;
                        balcony.x -= 0.15;
                        balcony.width += 0.3;
                        gg.createBalcony(balcony, to3d, glassColor, wallTag.balconyDepth);
                    }
                } else
                    wall.add(winPanel.get(1), to3d);
            } else
                wall.add(fPanels.get(p), to3d);
        } else {
            wall.add(fPanels.get(p), to3d);
        }
    }
}
Also used : DRectangle(org.twak.utils.geom.DRectangle)

Example 10 with DRectangle

use of org.twak.utils.geom.DRectangle in project chordatlas by twak.

the class GreebleGrid method createDormerWindow.

protected void createDormerWindow(QuadF l, MeshBuilder window, MeshBuilder glass, float sillDepth, float sillHeight, float corniceHeight, double panelWidth, double panelHeight) {
    Vector3d along = new Vector3d(l.corners[3]);
    along.sub(l.corners[0]);
    along.normalize();
    Vector3d up = new Vector3d(0, 1, 0);
    Vector3d out = new Vector3d();
    out.cross(along, up);
    out.scale(1 / out.length());
    Line3d lout;
    {
        Point3d away = new Point3d(l.corners[0]);
        away.add(out);
        lout = new Line3d(new Point3d(l.corners[0]), away);
    }
    Vector3d loc = new Vector3d(l.found[0]);
    if (lout.findPPram(l.found[0]) < lout.findPPram(l.found[1])) {
        // outwards going wall...
        loc = new Vector3d(up);
        loc.scale(-l.original.height);
        loc.add(l.found[1]);
    }
    {
        Vector3d avoidRoof = new Vector3d(out);
        avoidRoof.scale(0.09);
        ;
        loc.add(avoidRoof);
    }
    Point3d deepest = Arrays.stream(l.found).map(p -> new Pair<Point3d, Double>(p, lout.findPPram(p))).max((a, b) -> b.second().compareTo(a.second())).get().first();
    double depth = lout.closestPointOn(deepest, false).distance(lout.closestPointOn(new Point3d(loc), false));
    // MUtils.max(
    // Math.abs (l.corners[0].distance( l.found[0] )),
    // Math.abs (l.corners[1].distance( l.found[1] )),
    // Math.abs (l.corners[2].distance( l.found[2] )),
    // Math.abs (l.corners[3].distance( l.found[3] ))
    // ) ;
    WindowGen.createWindow(window, glass, new Window(Jme3z.to(loc), Jme3z.to(along), Jme3z.to(up), l.original.width, l.original.height, depth, panelWidth, panelHeight));
// Vector3f u = Jme3z.to(up), o = Jme3z.to( out );
// if (sillDepth > 0)
// window.addCube( Jme3z.to ( ptt[0] ).add( u.mult( -sillHeight + 0.01f ) ).add( o.mult( -sillDepth) ),
// Jme3z.to(out), Jme3z.to(along), Jme3z.to(up),
// (float)depth + sillDepth, (float)winPanel.width,(float) sillHeight  );
// 
// if (corniceHeight > 0)
// moulding( to3d, new DRectangle(winPanel.x, winPanel.getMaxY(), winPanel.width, corniceHeight), wall );
}
Also used : Arrays(java.util.Arrays) Cach2(org.twak.utils.Cach2) Cache2(org.twak.utils.Cache2) Griddable(org.twak.viewTrace.facades.Grid.Griddable) WindowGen(org.twak.tweed.gen.WindowGen) LinearForm3D(org.twak.utils.geom.LinearForm3D) Matrix4d(javax.vecmath.Matrix4d) ClickMe(org.twak.tweed.ClickMe) Pair(org.twak.utils.Pair) Vector3d(javax.vecmath.Vector3d) QuadF(org.twak.viewTrace.facades.GreebleSkel.QuadF) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) Node(com.jme3.scene.Node) Pointz(org.twak.tweed.gen.Pointz) Material(com.jme3.material.Material) Point3d(javax.vecmath.Point3d) Output(org.twak.camp.Output) Vector3f(com.jme3.math.Vector3f) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) Vector2d(javax.vecmath.Vector2d) File(java.io.File) CrossGen(org.twak.viewTrace.facades.Tube.CrossGen) Point2d(javax.vecmath.Point2d) List(java.util.List) Jme3z(org.twak.siteplan.jme.Jme3z) DRectangle(org.twak.utils.geom.DRectangle) ColorRGBA(com.jme3.math.ColorRGBA) Face(org.twak.camp.Output.Face) Window(org.twak.tweed.gen.WindowGen.Window) Line3d(org.twak.utils.geom.Line3d) Collections(java.util.Collections) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) Geometry(com.jme3.scene.Geometry) Window(org.twak.tweed.gen.WindowGen.Window) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) Line3d(org.twak.utils.geom.Line3d) Pair(org.twak.utils.Pair)

Aggregations

DRectangle (org.twak.utils.geom.DRectangle)21 Point2d (javax.vecmath.Point2d)7 ArrayList (java.util.ArrayList)6 List (java.util.List)4 MeshBuilder (org.twak.siteplan.jme.MeshBuilder)4 Feature (org.twak.viewTrace.facades.MiniFacade.Feature)4 Vector3f (com.jme3.math.Vector3f)3 File (java.io.File)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3 Matrix4d (javax.vecmath.Matrix4d)3 Point3d (javax.vecmath.Point3d)3 Vector2d (javax.vecmath.Vector2d)3 Vector3d (javax.vecmath.Vector3d)3 Griddable (org.twak.viewTrace.facades.Grid.Griddable)3 Material (com.jme3.material.Material)2 Geometry (com.jme3.scene.Geometry)2 Map (java.util.Map)2 OptionalDouble (java.util.OptionalDouble)2 Window (org.twak.tweed.gen.WindowGen.Window)2