Search in sources :

Example 1 with Tag

use of org.twak.camp.Tag in project chordatlas by twak.

the class SkelGen method tagWalls.

public static Profile tagWalls(Profile profile, float[] roofColor, SuperEdge se, Point2d s, Point2d e) {
    MiniFacade mini;
    if (se.toEdit == null) {
        if (se.mini == null || (se.mini.isEmpty() && se.proceduralFacade == null))
            mini = null;
        else {
            double[] range = findRange(se, s, e, se.proceduralFacade == null ? null : se.proceduralFacade.megafacade);
            if (range == null)
                mini = null;
            else
                mini = new Regularizer().go(se.mini, range[0], range[1], se.proceduralFacade);
        }
    } else
        // second time through, use the edited results
        mini = se.toEdit;
    Tag wall = new WallTag(se.profLine, se.occlusions, mini), roof = new RoofTag(roofColor);
    boolean first = true;
    for (Loop<Bar> lb : profile.points) {
        for (Loopable<Bar> ll : lb.loopableIterator()) {
            Bar b = ll.get();
            if (// || ll != lb.start && isRoof ( ll.getPrev().get() ) && b.start.distanceSquared( b.end ) < 16 )
            isRoof(b))
                b.tags.add(roof);
            else {
                if (first)
                    b.tags.add(new WallTag(se.profLine, se.occlusions, mini, true));
                else
                    b.tags.add(wall);
            }
        }
        first = false;
    }
    return profile;
}
Also used : MiniFacade(org.twak.viewTrace.facades.MiniFacade) RoofTag(org.twak.viewTrace.facades.RoofTag) Bar(org.twak.camp.ui.Bar) Regularizer(org.twak.viewTrace.facades.Regularizer) WallTag(org.twak.viewTrace.facades.WallTag) Tag(org.twak.camp.Tag) WallTag(org.twak.viewTrace.facades.WallTag) RoofTag(org.twak.viewTrace.facades.RoofTag)

Example 2 with Tag

use of org.twak.camp.Tag in project chordatlas by twak.

the class GreebleSkel method createMesh.

public void createMesh(Output output) {
    float[] roofColor = new float[] { 0.3f, 0.3f, 0.3f, 1 }, wallColor = new float[] { 228 / 255f, 223 / 255f, 206 / 255f, 1.0f };
    if (output.faces == null)
        return;
    double bestWallArea = 0, bestRoofArea = 0;
    for (Face f : output.faces.values()) {
        double area = Loopz.area3(f.getLoopL());
        Tag t = getTag(f.profile, RoofTag.class);
        if (t != null && area > bestRoofArea && ((RoofTag) t).color != null) {
            roofColor = ((RoofTag) t).color;
            bestRoofArea = area;
        }
        t = getTag(f.profile, WallTag.class);
        if (t != null && area > bestWallArea && ((WallTag) t).color != null) {
            wallColor = ((WallTag) t).color;
            bestWallArea = area;
        }
    }
    greebleGrid = new GreebleGrid(tweed, mbs = new MMeshBuilderCache());
    output.addNonSkeletonSharedEdges(new RoofTag(roofColor));
    edges(output, roofColor);
    for (List<Face> chain : Campz.findChains(output)) {
        // for ( Face f : output.faces.values() )
        // mbs.get(roofColor).add3d( Loopz.insertInnerEdges( f.getLoopL() ), zToYup );
        Optional<Tag> opt = chain.stream().flatMap(f -> f.profile.stream()).filter(tag -> tag instanceof WallTag).findAny();
        WallTag wt = null;
        Set<QuadF> features = new HashSet<>();
        MiniFacade mf = null;
        if (opt.isPresent() && (wt = (WallTag) opt.get()).miniFacade != null) {
            MiniFacade mf2 = new MiniFacade(wt.miniFacade);
            Line facadeLine;
            {
                Edge e = chain.get(0).edge;
                // we might rotate the facade to apply a set of features to a different side of the building.
                facadeLine = new Line(e.end.x, e.end.y, e.start.x, e.start.y);
            }
            if (TweedSettings.settings.snapFacadeWidth) {
                // move/scale mf horizontally from mean-image-location to mesh-facade-location
                double[] meshSE = findSE(wt.miniFacade, facadeLine, chain);
                mf2.scaleX(meshSE[0], meshSE[1]);
            }
            // find window locations in 3 space
            mf2.rects.values().stream().flatMap(f -> f.stream()).map(r -> new QuadF(r, facadeLine)).forEach(q -> features.add(q));
            mf = mf2;
        }
        for (Face f : chain) {
            face(f, mf, features, roofColor, wallColor);
        }
        for (QuadF w : features) if ((w.original.f == Feature.WINDOW || w.original.f == Feature.SHOP) && w.foundAll()) {
            greebleGrid.createDormerWindow(w, mbs.WOOD, mbs.GLASS, (float) wt.sillDepth, (float) wt.sillHeight, (float) wt.corniceHeight, 0.6, 0.9);
        }
        // for ( String mName : mbs.cache.keySet() )
        // for (float[] mCol : mbs.cache.get( mName ).keySet() )
        // node.attachChild( mb2Geom( output, chain, mName, mCol ) );
        greebleGrid.attachAll(node, chain, output, new ClickMe() {

            @Override
            public void clicked(Object data) {
                try {
                    SwingUtilities.invokeAndWait(new Runnable() {

                        @Override
                        public void run() {
                            selected(output, node, findSuperEdge(output, chain));
                        }
                    });
                } catch (Throwable th) {
                    th.printStackTrace();
                }
            }
        });
    }
}
Also used : LinearForm3D(org.twak.utils.geom.LinearForm3D) PlanSkeleton(org.twak.siteplan.campskeleton.PlanSkeleton) Matrix4d(javax.vecmath.Matrix4d) ClickMe(org.twak.tweed.ClickMe) Tag(org.twak.camp.Tag) Vector3d(javax.vecmath.Vector3d) Bar(org.twak.camp.ui.Bar) Tweed(org.twak.tweed.Tweed) ArrayList(java.util.ArrayList) TweedSettings(org.twak.tweed.TweedSettings) HashSet(java.util.HashSet) SETag(org.twak.tweed.gen.skel.SETag) Loop(org.twak.utils.collections.Loop) Node(com.jme3.scene.Node) SwingUtilities(javax.swing.SwingUtilities) Pointz(org.twak.tweed.gen.Pointz) Mathz(org.twak.utils.Mathz) SuperEdge(org.twak.tweed.gen.SuperEdge) Point3d(javax.vecmath.Point3d) ColumnProperties(org.twak.siteplan.campskeleton.PlanSkeleton.ColumnProperties) LoopL(org.twak.utils.collections.LoopL) Iterator(java.util.Iterator) Output(org.twak.camp.Output) Edge(org.twak.camp.Edge) Line(org.twak.utils.Line) Set(java.util.Set) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) LinearForm(org.twak.utils.geom.LinearForm) Collectors(java.util.stream.Collectors) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Loopz(org.twak.utils.collections.Loopz) Point2d(javax.vecmath.Point2d) LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) List(java.util.List) Loopable(org.twak.utils.collections.Loopable) DRectangle(org.twak.utils.geom.DRectangle) Optional(java.util.Optional) Face(org.twak.camp.Output.Face) Feature(org.twak.viewTrace.facades.MiniFacade.Feature) ClickMe(org.twak.tweed.ClickMe) Line(org.twak.utils.Line) Tag(org.twak.camp.Tag) SETag(org.twak.tweed.gen.skel.SETag) Face(org.twak.camp.Output.Face) SuperEdge(org.twak.tweed.gen.SuperEdge) Edge(org.twak.camp.Edge) HashSet(java.util.HashSet)

Example 3 with Tag

use of org.twak.camp.Tag 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);
    }
}
Also used : LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) Tag(org.twak.camp.Tag) SETag(org.twak.tweed.gen.skel.SETag)

Aggregations

Tag (org.twak.camp.Tag)3 Point3d (javax.vecmath.Point3d)2 Vector3d (javax.vecmath.Vector3d)2 Bar (org.twak.camp.ui.Bar)2 SETag (org.twak.tweed.gen.skel.SETag)2 LPoint3d (org.twak.viewTrace.facades.GreebleHelper.LPoint3d)2 Node (com.jme3.scene.Node)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 SwingUtilities (javax.swing.SwingUtilities)1 Matrix4d (javax.vecmath.Matrix4d)1 Point2d (javax.vecmath.Point2d)1 Edge (org.twak.camp.Edge)1 Output (org.twak.camp.Output)1 Face (org.twak.camp.Output.Face)1