Search in sources :

Example 6 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class Tube method tube.

public static void tube(MeshBuilder out, Collection<LinearForm3D> before, Collection<LinearForm3D> after, Line3d line, LinearForm3D left, LinearForm3D right, CrossGen gen) {
    if (angle(before, line) < 0.1 || angle(after, line) < 0.1)
        // too pointy to touch
        return;
    Point3d middle = line.fromPPram(0.5);
    Vector3d along = line.dir();
    along.normalize();
    Vector3d nAlong = new Vector3d(along);
    nAlong.negate();
    Vector3d o1 = left.normal(), u1 = new Vector3d();
    u1.cross(along, o1);
    Frame frame = Mathz.buildFrame(o1, u1, along, middle);
    Vector3d u2 = right.normal();
    u2.cross(u2, along);
    // u2.add( middle );
    Vector2d leftDir = Mathz.toXY(frame, u1);
    Vector2d rightDir = Mathz.toXY(frame, u2);
    List<Point3d> profilePts = gen.gen(leftDir, rightDir).stream().map(p -> Mathz.fromXY(frame, p)).collect(Collectors.toList());
    List<LinearForm3D> dummy = new ArrayList<>();
    for (Pair<Point3d, Point3d> pair : new ConsecutivePairs<Point3d>(profilePts, true)) {
        Point3d f1 = clip(pair.first(), along, after, dummy), f2 = clip(pair.second(), along, after, dummy), b1 = clip(pair.first(), nAlong, before, dummy), b2 = clip(pair.second(), nAlong, before, dummy);
        out.add(f2, f1, b1, b2);
    }
// cap( out, after ,  along, profilePts, true  );
// cap( out, before, nAlong, profilePts, false );
}
Also used : ConsecutivePairs(org.twak.utils.collections.ConsecutivePairs) LinearForm3D(org.twak.utils.geom.LinearForm3D) Collection(java.util.Collection) MultiMap(org.twak.utils.collections.MultiMap) MeshBuilder(org.twak.siteplan.jme.MeshBuilder) Vector2d(javax.vecmath.Vector2d) Pair(org.twak.utils.Pair) Collectors(java.util.stream.Collectors) Vector3d(javax.vecmath.Vector3d) ArrayList(java.util.ArrayList) Frame(org.twak.utils.Mathz.Frame) Loop(org.twak.utils.collections.Loop) Point2d(javax.vecmath.Point2d) List(java.util.List) Map(java.util.Map) Mathz(org.twak.utils.Mathz) Line3d(org.twak.utils.geom.Line3d) Point3d(javax.vecmath.Point3d) Frame(org.twak.utils.Mathz.Frame) ConsecutivePairs(org.twak.utils.collections.ConsecutivePairs) Vector2d(javax.vecmath.Vector2d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) ArrayList(java.util.ArrayList) LinearForm3D(org.twak.utils.geom.LinearForm3D)

Example 7 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class GreebleEdge method roofGreeble.

public static boolean roofGreeble(Face f, MeshBuilder roof) {
    boolean isWall = isWall(f);
    for (Loop<SharedEdge> sl : f.edges) {
        for (Loopable<SharedEdge> sel : sl.loopableIterator()) {
            SharedEdge se = sel.get();
            boolean otherIsWall = isWall(se.getOther(f));
            if (!isWall && !otherIsWall) {
                Face oF = se.getOther(f);
                if (oF == null || order(f, oF) || f.edge.getPlaneNormal().angle(oF.edge.getPlaneNormal()) < 0.4)
                    continue;
                List<LinearForm3D> start = new ArrayList(), end = new ArrayList<>();
                {
                    SharedEdge fPrev = se.getAdjEdge(f, false), fNext = se.getAdjEdge(f, true), ofPrev = se.getAdjEdge(oF, false), ofNext = se.getAdjEdge(oF, true);
                    if (fNext == null || fPrev == null || ofNext == null || ofPrev == null)
                        continue;
                    double overHang = -0.03;
                    if (isWall(fNext.getOther(f)))
                        end.add(toLF(fNext.getOther(f), overHang));
                    else
                        end.add(roofTween(fNext, se, f));
                    if (isWall(ofPrev.getOther(oF)))
                        end.add(toLF(ofPrev.getOther(oF), overHang));
                    else
                        end.add(roofTween(se, ofPrev, oF));
                    if (isWall(fPrev.getOther(f)))
                        start.add(toLF(fPrev.getOther(f), overHang));
                    else
                        start.add(roofTween(se, fPrev, f));
                    if (isWall(ofNext.getOther(oF)))
                        start.add(toLF(ofNext.getOther(oF), overHang));
                    else
                        start.add(roofTween(ofNext, se, oF));
                }
                Point3d s = se.getStart(f), e = se.getEnd(f);
                if (end.contains(null) || start.contains(null))
                    continue;
                Tube.tube(roof, end, start, new Line3d(new Point3d(s.x, s.z, s.y), new Point3d(e.x, e.z, e.y)), toLF(f, 0), toLF(oF, 0), new CrossGen() {

                    @Override
                    public List<Point2d> gen(Vector2d left, Vector2d right) {
                        Vector2d l = new Vector2d(left);
                        l.normalize();
                        Vector2d lP = new Vector2d(l.y, -l.x);
                        Vector2d r = new Vector2d(right);
                        r.normalize();
                        Vector2d rP = new Vector2d(-r.y, r.x);
                        List<Point2d> out = new ArrayList();
                        double width = 0.15, height = 0.03;
                        Vector2d rn = new Vector2d(r);
                        rn.negate();
                        // height / Math.sin ( ( Math.PI - l.angle( rn ) ) /2 );
                        double cenOffset = 0.02;
                        Vector2d cen = new Vector2d(lP);
                        cen.add(rP);
                        cen.normalize();
                        for (double[] coords : new double[][] { { 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, -width }, { 0, 0, 0, height, -width }, { 0, 0, cenOffset, 0, 0 }, { -width, height, 0, 0, 0 }, { -width, 0, 0, 0, 0 } }) {
                            Point2d tmp = new Point2d(l), tmp2;
                            tmp.scale(coords[0]);
                            tmp2 = new Point2d(lP);
                            tmp2.scale(coords[1]);
                            tmp.add(tmp2);
                            tmp2 = new Point2d(cen);
                            tmp2.scale(coords[2]);
                            tmp.add(tmp2);
                            tmp2 = new Point2d(rP);
                            tmp2.scale(coords[3]);
                            tmp.add(tmp2);
                            tmp2 = new Point2d(r);
                            tmp2.scale(coords[4]);
                            tmp.add(tmp2);
                            out.add(tmp);
                        }
                        return out;
                    }
                });
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) LinearForm3D(org.twak.utils.geom.LinearForm3D) Line3d(org.twak.utils.geom.Line3d) SharedEdge(org.twak.camp.Output.SharedEdge) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) CrossGen(org.twak.viewTrace.facades.Tube.CrossGen) ArrayList(java.util.ArrayList) List(java.util.List) Face(org.twak.camp.Output.Face)

Example 8 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class ImagePlaneGen method rotateByAngle.

public ImagePlaneGen rotateByAngle(double deltaAngle, double distance) {
    Line nLine = new Line(new Point2d(a.x, a.z), new Point2d(b.x, b.z));
    Point2d cen = nLine.fromPPram(0.5);
    double angle = nLine.aTan2() + deltaAngle;
    double len = nLine.length() / 2;
    Vector2d dir = new Vector2d(-Math.cos(angle) * len, -Math.sin(angle) * len);
    Point2d start = new Point2d(cen), end = new Point2d(cen);
    start.add(dir);
    end.sub(dir);
    ImagePlaneGen out = new ImagePlaneGen(this);
    out.a.set((float) start.x, a.y, (float) start.y);
    out.b.set((float) end.x, b.y, (float) end.y);
    out.calcUV();
    return out;
}
Also used : Line(org.twak.utils.Line) Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d)

Example 9 with Vector2d

use of javax.vecmath.Vector2d in project chordatlas by twak.

the class Concarnie method project.

public static Point2d project(Line l, Point2d pt) {
    Vector2d v1 = new Vector2d(l.end);
    v1.sub(l.start);
    Vector2d v2 = new Vector2d(pt);
    v2.sub(l.start);
    double param = v2.dot(v1) / v1.length();
    if (param < 0 || param > v1.length())
        return null;
    v1.normalize();
    v1.scale(param);
    v1.add(l.start);
    return new Point2d(v1);
}
Also used : Vector2d(javax.vecmath.Vector2d) Point2d(javax.vecmath.Point2d)

Example 10 with Vector2d

use of javax.vecmath.Vector2d 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)

Aggregations

Vector2d (javax.vecmath.Vector2d)29 Point2d (javax.vecmath.Point2d)15 Vector3d (javax.vecmath.Vector3d)12 ArrayList (java.util.ArrayList)9 Point3d (javax.vecmath.Point3d)8 List (java.util.List)7 Line (org.twak.utils.Line)7 SuperLine (org.twak.viewTrace.SuperLine)6 Line3d (org.twak.utils.geom.Line3d)5 LinearForm3D (org.twak.utils.geom.LinearForm3D)5 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Mesh (com.jme3.scene.Mesh)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 ColorRGBA (com.jme3.math.ColorRGBA)3 Node (com.jme3.scene.Node)3 VertexBuffer (com.jme3.scene.VertexBuffer)3 Graphics2D (java.awt.Graphics2D)3 Collection (java.util.Collection)3