Search in sources :

Example 16 with DRectangle

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

the class CGAMini method cga.

public void cga() {
    DRectangle all = mf.getAsRect();
    List<DRectangle> occlusions = Collections.EMPTY_LIST;
    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;
        DRectangle floor = floors.get(f);
        List<DRectangle> edges = floor.splitX(r -> split3(r, 1, 1));
        if (isGround)
            groundFloorHeight = floor.height;
        if (edges.size() != 3) {
        } else {
            DRectangle cen = edges.get(1);
            if (cen.height > 1.8) {
                if (f == 0) {
                    List<DRectangle> groundPanel = cen.splitX(r -> split1(r, 0.9));
                    if (groundPanel.get(0).width < 0.7) {
                    } else if (true) /* door */
                    {
                        List<DRectangle> doorHeight = groundPanel.get(0).splitY(r -> split1(r, 2.2));
                        if (visible(doorHeight.get(0), occlusions))
                            mf.add(Feature.DOOR, doorHeight.get(0));
                        if (groundPanel.size() > 1) {
                            List<DRectangle> gWindowPanelH = groundPanel.get(1).splitX(r -> split3(r, 0.5, 0.0));
                            if (gWindowPanelH.size() > 2) {
                                List<DRectangle> gWindowPanelV = gWindowPanelH.get(1).splitY(r -> split3(r, 0.5, 0.5));
                                if (gWindowPanelV.size() > 2) {
                                    if (visible(gWindowPanelV.get(1), occlusions))
                                        mf.add(Feature.SHOP, gWindowPanelV.get(1));
                                }
                            }
                        }
                    } else
                        windowStrip(cen, Math.random() < 0.5, occlusions);
                } else {
                    windowStrip(cen, f > 0 && f < floors.size() - 1 && Math.random() < 0.5, occlusions);
                    if (f == 1)
                        mf.add(Feature.MOULDING, new DRectangle(floor.x + 0.1, floor.y, floor.width - 0.2, 0.5));
                }
            }
        }
    }
}
Also used : Point2d(javax.vecmath.Point2d) List(java.util.List) DRectangle(org.twak.utils.geom.DRectangle) RectDir(org.twak.utils.geom.DRectangle.RectDir) Collections(java.util.Collections) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) ArrayList(java.util.ArrayList) DRectangle(org.twak.utils.geom.DRectangle) List(java.util.List) ArrayList(java.util.ArrayList)

Example 17 with DRectangle

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

the class CGAMini method windowStrip.

private void windowStrip(DRectangle cen, boolean makeBalcony, List<DRectangle> occlusions) {
    if (cen.width < 0.7)
        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) {
                if (visible(winPanel.get(1), occlusions)) {
                    DRectangle window = winPanel.get(1);
                    mf.add(Feature.WINDOW, window);
                    DRectangle sill = new DRectangle(window);
                    sill.height = 0.2;
                    sill.y -= sill.height;
                    mf.add(Feature.SILL, sill);
                    DRectangle lintel = new DRectangle(sill);
                    sill.y = window.getMaxY();
                    mf.add(Feature.CORNICE, sill);
                    if (makeBalcony) {
                        DRectangle balcony = new DRectangle(winPanel.get(1));
                        balcony.height = winPanel.get(1).height / 3;
                        balcony.x -= 0.15;
                        balcony.width += 0.3;
                        mf.add(Feature.BALCONY, balcony);
                    }
                }
            }
        }
    }
}
Also used : DRectangle(org.twak.utils.geom.DRectangle)

Example 18 with DRectangle

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

the class GreebleGrid method textureGrid.

protected void textureGrid(DRectangle all, Matrix4d to3d, MiniFacade mf) {
    if (mf != null && mf.texture != null) {
        Grid g = new Grid(.10, all.x, all.getMaxX(), all.y, all.getMaxY());
        MatMeshBuilder mmb = mbs.get("texture_" + mf.texture, mf.texture);
        mmb.spec = mf.spec;
        mmb.normal = mf.normal;
        for (FRect w : mf.rects.get(Feature.WINDOW)) {
            if (all.contains(w))
                g.insert(w, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createInnie(rect, all.normalize(rect), to3d, mmb, 0.2f);
                    }
                });
        }
        for (FRect w : mf.rects.get(Feature.DOOR)) {
            if (all.contains(w))
                g.insert(w, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createInnie(rect, all.normalize(rect), to3d, mmb, 0.5f);
                    }
                });
        }
        for (FRect w : mf.getRects(Feature.MOULDING, Feature.CORNICE, Feature.SILL)) {
            if (all.contains(w))
                g.insert(w, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createInnie(rect, all.normalize(rect), to3d, mmb, -0.2f);
                    }
                });
        }
        for (DRectangle b : mf.rects.get(Feature.BALCONY)) {
            if (all.contains(b))
                g.insert(b, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createBalcony(rect, to3d, mbs.BALCONY, 0.3);
                    }

                    @Override
                    public boolean noneBehind() {
                        return true;
                    }
                });
        }
        g.instance(new Griddable() {

            @Override
            public void instance(DRectangle rect) {
                mmb.add(rect, all.normalize(rect), to3d);
            }
        });
    }
}
Also used : DRectangle(org.twak.utils.geom.DRectangle) Griddable(org.twak.viewTrace.facades.Grid.Griddable)

Example 19 with DRectangle

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

the class GreebleGrid method createWindow.

protected void createWindow(DRectangle winPanel, Matrix4d to3d, MeshBuilder wall, MeshBuilder window, MeshBuilder glass, double depth, float sillDepth, float sillHeight, float corniceHeight, double panelWidth, double panelHeight) {
    Point2d[] pts = winPanel.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.scale(-1 / out.length());
    Vector3d loc = new Vector3d();
    loc.cross(along, up);
    loc.scale(-depth / loc.length());
    loc.add(ptt[0]);
    WindowGen.createWindow(window, glass, new Window(Jme3z.to(loc), Jme3z.to(along), Jme3z.to(up), winPanel.width, winPanel.height, 0.3, panelWidth, panelHeight));
    Vector3f u = Jme3z.to(up), o = Jme3z.to(out);
    wall.addInsideRect(Jme3z.to(ptt[0]), o, Jme3z.to(along), u, (float) depth, (float) winPanel.width, (float) winPanel.height, null);
    if (sillDepth > 0 && sillHeight > 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 : Window(org.twak.tweed.gen.WindowGen.Window) DRectangle(org.twak.utils.geom.DRectangle) Point2d(javax.vecmath.Point2d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) Vector3f(com.jme3.math.Vector3f)

Example 20 with DRectangle

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

the class GreebleGrid method buildGrid.

protected void buildGrid(DRectangle all, Matrix4d to3d, MiniFacade mf, MeshBuilder wallColorMat, WallTag wallTag) {
    Grid g = new Grid(.10, all.x, all.getMaxX(), all.y, all.getMaxY());
    if (mf != null) {
        for (FRect w : mf.rects.get(Feature.WINDOW)) {
            if (all.contains(w))
                g.insert(w, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createWindow(rect, to3d, wallColorMat, mbs.WOOD, mbs.GLASS, wallTag.windowDepth, (float) wallTag.sillDepth, (float) w.attachedHeight.get(Feature.SILL).d, (float) w.attachedHeight.get(Feature.CORNICE).d, 0.6, 0.9);
                    }
                });
            double bHeight = w.attachedHeight.get(Feature.BALCONY).d;
            if (bHeight > 0) {
                DRectangle balcon = new DRectangle();
                balcon.setFrom(w);
                balcon.grow(0.2);
                balcon.height = bHeight;
                createBalcony(balcon, to3d, mbs.BALCONY, wallTag.balconyDepth);
            }
        }
        for (FRect s_ : mf.rects.get(Feature.SHOP)) {
            FRect s = new FRect(s_);
            DRectangle rect = all.intersect(s);
            if (rect != null) {
                s.setFrom(rect);
                g.insert(s, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createWindow(rect, to3d, wallColorMat, mbs.WOOD, mbs.GLASS, wallTag.windowDepth, (float) wallTag.sillDepth, (float) s.attachedHeight.get(Feature.SILL).d, (float) s.attachedHeight.get(Feature.CORNICE).d, 1.5, 2);
                    }
                });
            }
        }
        for (DRectangle d : mf.rects.get(Feature.DOOR)) {
            if (all.contains(d))
                g.insert(d, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createDoor(rect, to3d, wallColorMat, mbs.get("wood", new float[] { 0, 0, 0.3f, 1 }), wallTag.doorDepth);
                    }
                });
        }
        for (DRectangle b : mf.rects.get(Feature.BALCONY)) {
            if (all.contains(b))
                g.insert(b, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        createBalcony(rect, to3d, mbs.BALCONY, wallTag.balconyDepth);
                    }

                    @Override
                    public boolean noneBehind() {
                        return true;
                    }
                });
        }
        for (DRectangle b : mf.rects.get(Feature.MOULDING)) {
            if (all.contains(b))
                g.insert(b, new Griddable() {

                    @Override
                    public void instance(DRectangle rect) {
                        moulding(to3d, rect, mbs.MOULDING);
                    }
                });
        }
    }
    g.instance(new Griddable() {

        @Override
        public void instance(DRectangle rect) {
            wallColorMat.add(rect, to3d);
        }
    });
}
Also used : DRectangle(org.twak.utils.geom.DRectangle) Griddable(org.twak.viewTrace.facades.Grid.Griddable)

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