Search in sources :

Example 11 with Matrix4d

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

the class Prof method buildProfile.

public static Prof buildProfile(Line3d oLine, Point3d cen) {
    Matrix4d to2D = new Matrix4d();
    Vector3d c2 = oLine.dir(), c3 = new Vector3d();
    c2.normalize();
    c3.cross(c2, UP);
    to2D.setIdentity();
    to2D.setRow(0, c3.x, c3.y, c3.z, 0);
    to2D.setRow(1, UP.x, UP.y, UP.z, 0);
    to2D.setRow(2, c2.x, c2.y, c2.z, 0);
    {
        Point3d start = new Point3d(cen.x, 0, cen.z);
        to2D.transform(start);
        to2D.m03 = -start.x;
        to2D.m13 = -start.y;
        to2D.m23 = -start.z;
        to2D.m33 = 1;
    }
    Prof monotonic = new Prof(to2D, c2);
    return monotonic;
}
Also used : Matrix4d(javax.vecmath.Matrix4d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d)

Example 12 with Matrix4d

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

the class VizSkelGen method toHalf.

private SuperFace toHalf(Loop<Point3d> loop) {
    Cache<Point3d, Point2d> look = new Cach<>(x -> Pointz.to2(x));
    HalfEdge last = null, first = null;
    SuperFace out = new SuperFace();
    for (Loopable<Point3d> edge : loop.loopableIterator()) {
        SuperEdge e = new SuperEdge(look.get(edge.get()), look.get(edge.getNext().get()), null);
        if (first == null)
            first = e;
        if (last != null)
            last.next = e;
        e.face = out;
        // !
        e.prof = null;
        e.mini = Collections.EMPTY_LIST;
        if (mode == Mode.Profiles)
            for (Line l : footprint) {
                if (l.absAngle(e.line()) < 0.1 && l.distance(e.start, true) < 1.5 && l.distance(e.end, true) < 1.5) {
                    SuperLine sl = (SuperLine) l;
                    MegaFacade mf = sl.getMega();
                    e.prof = findProf(e.start, e.end, sl, mf);
                }
            }
        last = e;
    }
    last.next = first;
    out.e = first;
    SkelFootprint.meanModeHeightColor(Loopz.toXZLoop(loop), out, blockGen);
    if (mode == Mode.CE) {
        for (HalfEdge ee : out) {
            SuperEdge e = (SuperEdge) ee;
            Matrix4d m = new Matrix4d();
            m.setIdentity();
            e.prof = new Prof(m, new Vector3d());
            e.prof.add(new Point2d(0, 0));
            e.prof.add(new Point2d(0, out.height));
            e.prof.add(new Point2d(-1, out.height + 1));
        }
    }
    return out;
}
Also used : MegaFacade(org.twak.tweed.gen.ProfileGen.MegaFacade) HalfEdge(org.twak.utils.geom.HalfMesh2.HalfEdge) Line(org.twak.utils.Line) SuperLine(org.twak.viewTrace.SuperLine) Matrix4d(javax.vecmath.Matrix4d) Point2d(javax.vecmath.Point2d) Vector3d(javax.vecmath.Vector3d) Point3d(javax.vecmath.Point3d) SuperLine(org.twak.viewTrace.SuperLine) Cach(org.twak.utils.Cach)

Example 13 with Matrix4d

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

the class AlignTool method buildFrame.

private Matrix4d buildFrame(Vector3f[] locs) {
    Vector3f dir0 = new Vector3f(locs[1]);
    dir0 = dir0.subtract(locs[0]);
    dir0.y = 0;
    // dir.normalize();
    Vector3f dir1 = new Vector3f(0, dir0.length(), 0);
    Vector3f dir2 = new Vector3f(-dir0.z, 0, dir0.x);
    Matrix4d out = new Matrix4d();
    out.setRow(0, toArray(dir2));
    out.setRow(1, toArray(dir1));
    out.setRow(2, toArray(dir0));
    out.m03 = locs[0].x;
    out.m13 = 0;
    out.m23 = locs[0].z;
    out.m33 = 1;
    if (false) {
        Point3d a = new Point3d(0, 0, 0);
        Point3d b = new Point3d(0, 0, 1);
        out.transform(a);
        out.transform(b);
        System.out.println(a + " >>><<< " + b);
        System.out.println(locs[0] + " <<<>>> " + locs[1]);
    }
    return out;
}
Also used : Matrix4d(javax.vecmath.Matrix4d) Point3d(javax.vecmath.Point3d) Vector3f(com.jme3.math.Vector3f)

Example 14 with Matrix4d

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

the class GreebleSkel method mapTo2d.

protected void mapTo2d(Face f, Loop<LPoint3d> ll, MiniFacade mf, WallTag wallTag, Set<QuadF> features, MatMeshBuilder faceMaterial) {
    Matrix4d to2dXY = new Matrix4d();
    Vector3d up = f.edge.uphill, along = f.edge.direction(), out = f.edge.getPlaneNormal();
    along.normalize();
    to2dXY.setRow(2, up.x, up.y, up.z, 0);
    to2dXY.setRow(1, out.x, out.y, out.z, 0);
    to2dXY.setRow(0, -along.x, -along.y, -along.z, 0);
    Point3d bottomS = f.definingSE.iterator().next().getStart(f), bottomE = f.definingSE.iterator().next().getEnd(f);
    Point3d start = new Point3d(bottomS);
    Point3d end = new Point3d(bottomE);
    to2dXY.m33 = 1;
    to2dXY.transform(start);
    to2dXY.m03 = -start.x;
    to2dXY.m13 = -start.y;
    to2dXY.m23 = -start.z;
    start = new Point3d(bottomS);
    to2dXY.transform(start);
    to2dXY.transform(end);
    Loop<LPoint2d> flat = GreebleHelper.to2dLoop(GreebleHelper.transform(ll, to2dXY), 1);
    Matrix4d to3d = new Matrix4d(to2dXY);
    to3d.invert();
    {
        // face in z-up, we're in y-up
        double[] one = new double[4], two = new double[4];
        to3d.getRow(1, one);
        to3d.getRow(2, two);
        to3d.setRow(1, two);
        to3d.setRow(2, one);
    }
    // now in jme space
    Matrix4d to2d = new Matrix4d(to3d);
    to2d.invert();
    MiniFacade forFace = null;
    if (mf != null) {
        forFace = new MiniFacade(mf);
        forFace.rects.clear();
    }
    LinearForm3D facePlane = new LinearForm3D(new Vector3d(out.x, out.z, out.y), new Point3d(bottomS.x, bottomS.z, bottomS.y));
    LoopL<Point2d> sides = null;
    DRectangle facadeRect = null;
    if (wallTag != null) {
        sides = findRectagle(flat, Pointz.to2(start), Pointz.to2(end));
        if (sides != null)
            facadeRect = findRect(sides.remove(0));
    }
    List<DRectangle> floors = new ArrayList();
    List<MeshBuilder> materials = new ArrayList();
    if (wallTag != null && facadeRect != null && mf != null && wallTag.isGroundFloor && mf.groundFloorHeight > 0 && wallTag.groundFloorColor != null && facadeRect.x < mf.groundFloorHeight && facadeRect.getMaxX() > mf.groundFloorHeight) {
        floors.addAll(facadeRect.splitY(mf.groundFloorHeight));
        MatMeshBuilder gfm = greebleGrid.mbs.get("brick", wallTag.groundFloorColor);
        for (Loop<Point2d> loop : sides) {
            Loop<Point2d>[] cut = Loopz.cutConvex(loop, new LinearForm(0, 1, mf.groundFloorHeight));
            faceMaterial.add(cut[1].singleton(), to3d);
            gfm.add(cut[0].singleton(), to3d);
        }
        materials.add(gfm);
        materials.add(faceMaterial);
    } else {
        floors.add(facadeRect);
        materials.add(faceMaterial);
        if (sides != null)
            faceMaterial.add(sides, to3d);
    }
    for (int j = 0; j < floors.size(); j++) {
        DRectangle floorRect = floors.get(j);
        MeshBuilder m = materials.get(j);
        Iterator<QuadF> quit = features.iterator();
        while (quit.hasNext()) {
            QuadF n = quit.next();
            if (n.project(to2d, to3d, flat, facePlane, new Vector3d(along.y, 0, -along.x)) && wallTag != null && floorRect != null && forFace != null) {
                // set the vertical bounds, so we can just render in 2d
                FRect bounds = new FRect(n.original);
                n.setBounds(to2d, bounds);
                if (floorRect.contains(bounds)) {
                    forFace.rects.put(n.original.f, bounds);
                    quit.remove();
                }
            }
        }
        if (wallTag == null || forFace == null || floorRect == null) {
            m.add(flat.singleton(), to3d);
            return;
        }
        List<DRectangle> occlusions = new ArrayList<>();
        for (LineHeight lh : wallTag.occlusions) {
            Point3d s = new Point3d(lh.start.x, lh.start.y, lh.min), e = new Point3d(lh.end.x, lh.end.y, lh.max);
            to2dXY.transform(s);
            to2dXY.transform(e);
            occlusions.add(new DRectangle(Math.min(s.x, e.x), s.z, Math.abs(e.x - s.x), Math.abs(e.z - s.z)));
        }
        if (mf.texture == null)
            greebleGrid.buildGrid(floorRect, to3d, forFace, m, wallTag);
        else
            greebleGrid.textureGrid(floorRect, to3d, mf);
    }
}
Also used : Loop(org.twak.utils.collections.Loop) DRectangle(org.twak.utils.geom.DRectangle) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) ArrayList(java.util.ArrayList) LinearForm(org.twak.utils.geom.LinearForm) LinearForm3D(org.twak.utils.geom.LinearForm3D) Matrix4d(javax.vecmath.Matrix4d) Vector3d(javax.vecmath.Vector3d) LPoint2d(org.twak.viewTrace.facades.GreebleHelper.LPoint2d) Point2d(javax.vecmath.Point2d) Point3d(javax.vecmath.Point3d) LPoint3d(org.twak.viewTrace.facades.GreebleHelper.LPoint3d) MeshBuilder(org.twak.siteplan.jme.MeshBuilder)

Example 15 with Matrix4d

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

the class Tweed method buildOrigin.

/**
 * Transform toCartesian (around x,y) to a renderable coordinate system with y-up.
 */
private Matrix4d buildOrigin(double x, double y, MathTransform toCartesian) throws TransformException {
    double delta = 1e-6;
    double[] frame = new double[] { x, y, x + delta, y, x, y + delta, 0, 0, 0 };
    toCartesian.transform(frame, 0, frame, 0, 3);
    Vector3d o = new Vector3d(frame[0], frame[1], frame[2]), a = new Vector3d(frame[3], frame[4], frame[5]), b = new Vector3d(frame[6], frame[7], frame[8]), c = new Vector3d();
    a.sub(o);
    b.sub(o);
    a.normalize();
    b.normalize();
    c.cross(a, b);
    Matrix4d out = new Matrix4d();
    out.setRow(0, -a.x, -a.y, -a.z, 0);
    out.setRow(1, c.x, c.y, c.z, 0);
    out.setRow(2, b.x, b.y, b.z, 0);
    out.setRow(3, 0, 0, 0, 1);
    out.transform(o);
    out.m03 = -o.x;
    out.m13 = -o.y;
    out.m23 = -o.z;
    return out;
}
Also used : Matrix4d(javax.vecmath.Matrix4d) Vector3d(javax.vecmath.Vector3d)

Aggregations

Matrix4d (javax.vecmath.Matrix4d)18 Vector3d (javax.vecmath.Vector3d)8 File (java.io.File)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Point3d (javax.vecmath.Point3d)6 Map (java.util.Map)5 Point2d (javax.vecmath.Point2d)5 IOException (java.io.IOException)4 ObjDump (org.twak.utils.geom.ObjDump)4 Transform (com.jme3.math.Transform)3 XStream (com.thoughtworks.xstream.XStream)3 FileOutputStream (java.io.FileOutputStream)3 List (java.util.List)3 Tuple3d (javax.vecmath.Tuple3d)3 Loop (org.twak.utils.collections.Loop)3 LinearForm3D (org.twak.utils.geom.LinearForm3D)3 Face (org.twak.utils.geom.ObjDump.Face)3 ModelKey (com.jme3.asset.ModelKey)2 Material (com.jme3.material.Material)2