Search in sources :

Example 1 with ClickMe

use of org.twak.tweed.ClickMe in project chordatlas by twak.

the class PanoGen method calculate.

@Override
public void calculate() {
    File absFolder = Tweed.toWorkspace(PanoGen.this.folder);
    if (!absFolder.exists())
        throw new Error("File not found " + this.folder);
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    panos.clear();
    createPanoGens();
    Iterator<Pano> pit = panos.iterator();
    while (pit.hasNext()) {
        Pano p = pit.next();
        if (p.rx == 0 && Math.abs(p.rz - Mathz.TwoPI) < 1e-6)
            pit.remove();
    }
    Random randy = new Random(0xdeadbeef);
    for (Pano p : panos) {
        if (p.geom == null) {
            Box box1 = new Box(1f, 1f, 1f);
            p.geom = new Geometry("Box", box1);
            // p.geom.setUserData(Gen.class.getSimpleName(), new Object[]{this});
            p.geom.setUserData(EventMoveHandle.class.getSimpleName(), new Object[] { new EventMoveHandle() {

                @Override
                public void posChanged() {
                    p.location = new Vector3d(Jme3z.from(p.geom.getLocalTranslation()));
                    calculate();
                }
            } });
            // Material mat1 = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            ColorRGBA col = new ColorRGBA(color.getRed() * (0.2f + randy.nextFloat() * 0.8f) / 255f, color.getGreen() * (0.2f + randy.nextFloat() * 0.8f) / 255f, color.getBlue() * (0.2f + randy.nextFloat() * 0.8f) / 255f, 1f);
            Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
            mat.setColor("Diffuse", col);
            mat.setColor("Ambient", col);
            mat.setBoolean("UseMaterialColors", true);
            p.geom.setMaterial(mat);
        }
        p.geom.setLocalTranslation((float) p.location.x, (float) p.location.y, (float) p.location.z);
        p.geom.setLocalRotation(p.geomRot);
        p.geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {

            @Override
            public void clicked(Object data) {
                tweed.frame.setSelected(PanoGen.this);
                selected(p);
            }
        } });
        gNode.attachChild(p.geom);
    }
    super.calculate();
}
Also used : EventMoveHandle(org.twak.tweed.EventMoveHandle) ClickMe(org.twak.tweed.ClickMe) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) Random(java.util.Random) ColorRGBA(com.jme3.math.ColorRGBA) Spatial(com.jme3.scene.Spatial) Vector3d(javax.vecmath.Vector3d) File(java.io.File)

Example 2 with ClickMe

use of org.twak.tweed.ClickMe in project chordatlas by twak.

the class GreebleGrid method mb2Tex.

private Geometry mb2Tex(Output output, List<Face> chain, String name, String texture, Node node, ClickMe clickMe) {
    Geometry geom;
    {
        MatMeshBuilder builder = mbs.get(name, texture);
        geom = new Geometry("material_" + texture, builder.getMesh());
        geom.setUserData(Jme3z.MAT_KEY, name);
        Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
        if (new File(tweed.DATA + "/" + texture).exists())
            mat.setTexture("DiffuseMap", tweed.getAssetManager().loadTexture(texture));
        else {
            System.out.println(this.getClass().getSimpleName() + " can't find " + tweed.SCRATCH + texture);
            mat.setColor("Diffuse", ColorRGBA.Red);
        }
        mat.setColor("Ambient", ColorRGBA.White);
        if (builder.normal != null)
            mat.setTexture("NormalMap", tweed.getAssetManager().loadTexture(builder.normal));
        // mat.setColor( "Ambient", ColorRGBA.Gray );
        mat.setColor("Diffuse", ColorRGBA.White);
        if (builder.spec != null)
            mat.setTexture("SpecularMap", tweed.getAssetManager().loadTexture(builder.spec));
        else
            mat.setColor("Specular", ColorRGBA.White);
        // mat.setFloat("Shininess", 6f);
        mat.setBoolean("UseMaterialColors", true);
        geom.setMaterial(mat);
        geom.updateGeometricState();
        geom.updateModelBound();
        if (chain != null)
            geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { clickMe });
    }
    return geom;
}
Also used : Geometry(com.jme3.scene.Geometry) ClickMe(org.twak.tweed.ClickMe) Material(com.jme3.material.Material) File(java.io.File)

Example 3 with ClickMe

use of org.twak.tweed.ClickMe in project chordatlas by twak.

the class PlanesGen method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    for (Plane p : planes) {
        p.color = color;
        Spatial s = p.render(tweed);
        if (s == null)
            continue;
        s.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {

            @Override
            public void clicked(Object data) {
                selected(p);
            }
        } });
        gNode.attachChild(s);
    }
    super.calculate();
}
Also used : ClickMe(org.twak.tweed.ClickMe) Spatial(com.jme3.scene.Spatial)

Example 4 with ClickMe

use of org.twak.tweed.ClickMe 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 5 with ClickMe

use of org.twak.tweed.ClickMe in project chordatlas by twak.

the class LineGen3d method calculate.

@Override
public void calculate() {
    for (Spatial s : gNode.getChildren()) s.removeFromParent();
    {
        Geometry geom;
        Mesh m = new Mesh();
        m.setMode(Mesh.Mode.Lines);
        List<Float> coords = new ArrayList();
        List<Integer> inds = new ArrayList();
        for (Line3d l : getLines()) {
            inds.add(inds.size());
            inds.add(inds.size());
            coords.add((float) l.start.x);
            coords.add((float) l.start.y);
            coords.add((float) l.start.z);
            coords.add((float) l.end.x);
            coords.add((float) l.end.y);
            coords.add((float) l.end.z);
        }
        m.setBuffer(VertexBuffer.Type.Position, 3, Arrayz.toFloatArray(coords));
        m.setBuffer(VertexBuffer.Type.Index, 2, Arrayz.toIntArray(inds));
        geom = new Geometry(filename, m);
        geom.setCullHint(CullHint.Never);
        Material lineMaterial = new Material(tweed.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
        lineMaterial.setColor("Color", new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1f));
        geom.setMaterial(lineMaterial);
        geom.setLocalTranslation(0, 0, 0);
        gNode.attachChild(geom);
    }
    // int c = 0;
    VertexBuffer emptyVB = new VertexBuffer(Type.Index);
    emptyVB.setupData(Usage.Static, 3, Format.UnsignedShort, BufferUtils.createShortBuffer(0));
    {
        Geometry geom;
        Random randy = new Random();
        for (Map.Entry<Loop<Point3d>, Integer> e : getFaces().entrySet()) {
            Loop<Point3d> p = e.getKey();
            final int callbackI = e.getValue();
            Mesh m = Jme3z.fromLoop(p);
            // m.setMode( Mesh.Mode.Triangles );
            // 
            // List<Integer> inds = new ArrayList<>();
            // List<Float> pos = new ArrayList<>();
            // List<Float> norms = new ArrayList<>();
            // 
            // Loopz.triangulate( p, true, inds, pos, norms );
            // 
            // m.set setVe( Type.Index, Arrayz.toIntArray(inds));
            geom = new Geometry(filename, m);
            geom.setCullHint(CullHint.Never);
            // ColorRGBA col = Jme3z.toJme( Rainbow.getColour( c++ ) );
            ColorRGBA col = new ColorRGBA(color.getRed() * randy.nextFloat() / 500f + 0.1f, color.getGreen() * randy.nextFloat() / 500f + 0.1f, color.getBlue() * randy.nextFloat() / 500f + 0.1f, 1f);
            Material mat = new Material(tweed.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
            mat.setColor("Diffuse", col);
            mat.setColor("Ambient", col);
            mat.setBoolean("UseMaterialColors", true);
            geom.setUserData(ClickMe.class.getSimpleName(), new Object[] { new ClickMe() {

                @Override
                public void clicked(Object data) {
                    polyClicked(callbackI);
                }
            } });
            geom.setUserData(Gen.class.getSimpleName(), new Object[] { this });
            geom.setMaterial(mat);
            geom.setLocalTranslation(0, 0, 0);
            if (TweedSettings.settings.LOD) {
                LodGenerator lod = new LodGenerator(geom);
                lod.bakeLods(LodGenerator.TriangleReductionMethod.COLLAPSE_COST, 10, 100);
                GISLodControl lc = new GISLodControl();
                lc.setTrisPerPixel(0.000001f);
                geom.addControl(lc);
            }
            gNode.attachChild(geom);
        }
    }
    gNode.updateModelBound();
    super.calculate();
}
Also used : Loop(org.twak.utils.collections.Loop) ClickMe(org.twak.tweed.ClickMe) VertexBuffer(com.jme3.scene.VertexBuffer) ArrayList(java.util.ArrayList) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) Line3d(org.twak.utils.geom.Line3d) Geometry(com.jme3.scene.Geometry) LodGenerator(jme3tools.optimize.LodGenerator) ColorRGBA(com.jme3.math.ColorRGBA) Random(java.util.Random) Spatial(com.jme3.scene.Spatial) Point3d(javax.vecmath.Point3d) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ClickMe (org.twak.tweed.ClickMe)5 Material (com.jme3.material.Material)3 Geometry (com.jme3.scene.Geometry)3 Spatial (com.jme3.scene.Spatial)3 ColorRGBA (com.jme3.math.ColorRGBA)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Random (java.util.Random)2 Point3d (javax.vecmath.Point3d)2 Vector3d (javax.vecmath.Vector3d)2 Loop (org.twak.utils.collections.Loop)2 Mesh (com.jme3.scene.Mesh)1 Node (com.jme3.scene.Node)1 VertexBuffer (com.jme3.scene.VertexBuffer)1 Box (com.jme3.scene.shape.Box)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Optional (java.util.Optional)1 Set (java.util.Set)1