Search in sources :

Example 1 with Edge

use of org.twak.camp.Edge 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)

Aggregations

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 Point3d (javax.vecmath.Point3d)1 Vector3d (javax.vecmath.Vector3d)1 Edge (org.twak.camp.Edge)1 Output (org.twak.camp.Output)1 Face (org.twak.camp.Output.Face)1 Tag (org.twak.camp.Tag)1 Bar (org.twak.camp.ui.Bar)1 PlanSkeleton (org.twak.siteplan.campskeleton.PlanSkeleton)1 ColumnProperties (org.twak.siteplan.campskeleton.PlanSkeleton.ColumnProperties)1