Search in sources :

Example 1 with PolygonPoint

use of org.poly2tri.geometry.polygon.PolygonPoint in project energy3d by concord-consortium.

the class Floor method drawAnnotations.

@Override
public void drawAnnotations() {
    if (container == null) {
        return;
    }
    int annotCounter = 0;
    for (int i = 0; i < wallUpperPoints.size(); i++) {
        PolygonPoint p = wallUpperPoints.get(i);
        final Vector3 a = new Vector3(p.getX(), p.getY(), p.getZ());
        p = wallUpperPoints.get((i + 1) % wallUpperPoints.size());
        final Vector3 b = new Vector3(p.getX(), p.getY(), p.getZ());
        final SizeAnnotation sizeAnnot = fetchSizeAnnot(annotCounter++);
        sizeAnnot.setRange(a, b, getCenter(), getNormal(), original == null, Align.Center, true, false, Scene.isDrawAnnotationsInside());
        sizeAnnot.setLineWidth(original == null ? 1f : 2f);
    }
}
Also used : PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) SizeAnnotation(org.concord.energy3d.shapes.SizeAnnotation) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) TPoint(org.poly2tri.triangulation.point.TPoint)

Example 2 with PolygonPoint

use of org.poly2tri.geometry.polygon.PolygonPoint in project energy3d by concord-consortium.

the class MeshLib method applyHoles.

public static void applyHoles(final Node root, final List<Window> windows) {
    final Map<Window, List<ReadOnlyVector3>> holes = new HashMap<Window, List<ReadOnlyVector3>>();
    for (final Window window : windows) {
        final ArrayList<ReadOnlyVector3> hole = new ArrayList<ReadOnlyVector3>();
        hole.add(window.getAbsPoint(0).multiplyLocal(1, 1, 0));
        hole.add(window.getAbsPoint(2).multiplyLocal(1, 1, 0));
        hole.add(window.getAbsPoint(3).multiplyLocal(1, 1, 0));
        hole.add(window.getAbsPoint(1).multiplyLocal(1, 1, 0));
        holes.put(window, hole);
    }
    for (int roofIndex = 0; roofIndex < root.getChildren().size(); roofIndex++) {
        final Spatial roofPart = root.getChildren().get(roofIndex);
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final ReadOnlyVector3 normal = (ReadOnlyVector3) roofPart.getUserData();
            final AnyToXYTransform toXY = new AnyToXYTransform(normal.getX(), normal.getY(), normal.getZ());
            final XYToAnyTransform fromXY = new XYToAnyTransform(normal.getX(), normal.getY(), normal.getZ());
            final Mesh mesh = (Mesh) ((Node) roofPart).getChild(0);
            final ArrayList<ReadOnlyVector3> points3D = computeOutline(mesh.getMeshData().getVertexBuffer());
            final List<PolygonPoint> points2D = new ArrayList<PolygonPoint>();
            final ReadOnlyVector3 firstPoint = points3D.get(0);
            final double scale = Scene.getInstance().getTextureMode() == TextureMode.Simple ? 0.5 : 0.1;
            final TPoint o;
            final TPoint u;
            final TPoint v;
            if (normal.dot(Vector3.UNIT_Z) == 1) {
                o = new TPoint(firstPoint.getX(), firstPoint.getY(), firstPoint.getZ());
                u = new TPoint(1 / scale, 0, 0);
                v = new TPoint(0, 1 / scale, 0);
            } else {
                final ReadOnlyVector3 u3 = Vector3.UNIT_Z.cross(normal, null).normalizeLocal();
                final ReadOnlyVector3 ou3 = u3.divide(scale, null).add(firstPoint, null);
                final ReadOnlyVector3 ov3 = normal.cross(u3, null).divideLocal(scale).addLocal(firstPoint);
                o = new TPoint(firstPoint.getX(), firstPoint.getY(), firstPoint.getZ());
                u = new TPoint(ou3.getX(), ou3.getY(), ou3.getZ());
                v = new TPoint(ov3.getX(), ov3.getY(), ov3.getZ());
                toXY.transform(o);
                toXY.transform(u);
                toXY.transform(v);
                u.set(u.getX() - o.getX(), u.getY() - o.getY(), 0);
                v.set(v.getX() - o.getX(), v.getY() - o.getY(), 0);
            }
            final Vector2 o2 = new Vector2(firstPoint.getX(), firstPoint.getY());
            final Vector2 ou2 = o2.add(new Vector2(u.getX(), u.getY()), null);
            final Vector2 ov2 = o2.add(new Vector2(v.getX(), v.getY()), null);
            double minLineScaleU = Double.MAX_VALUE;
            double minLineScaleV = Double.MAX_VALUE;
            for (final ReadOnlyVector3 p : points3D) {
                final PolygonPoint polygonPoint = new PolygonPoint(p.getX(), p.getY(), p.getZ());
                toXY.transform(polygonPoint);
                points2D.add(polygonPoint);
                final Vector2 p2 = new Vector2(polygonPoint.getX(), polygonPoint.getY());
                final double lineScaleU = Util.projectPointOnLineScale(p2, o2, ou2);
                final double lineScaleV = Util.projectPointOnLineScale(p2, o2, ov2);
                if (lineScaleU < minLineScaleU) {
                    minLineScaleU = lineScaleU;
                }
                if (lineScaleV < minLineScaleV) {
                    minLineScaleV = lineScaleV;
                }
            }
            o2.addLocal(new Vector2(u.getX(), u.getY()).multiplyLocal(minLineScaleU));
            o2.addLocal(new Vector2(v.getX(), v.getY()).multiplyLocal(minLineScaleV));
            final PolygonWithHoles polygon = new PolygonWithHoles(points2D);
            o.set(o2.getX(), o2.getY(), 0);
            roofPart.updateWorldBound(true);
            for (final Window window : windows) {
                if (holes.get(window) == null) {
                    continue;
                }
                final List<PolygonPoint> holePolygon = new ArrayList<PolygonPoint>();
                boolean outside = false;
                for (final ReadOnlyVector3 holePoint : holes.get(window)) {
                    final PickResults pickResults = new PrimitivePickResults();
                    PickingUtil.findPick(((Node) roofPart).getChild(0), new Ray3(holePoint, Vector3.UNIT_Z), pickResults, false);
                    if (pickResults.getNumber() > 0) {
                        final ReadOnlyVector3 intersectionPoint = pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0);
                        final PolygonPoint polygonPoint = new PolygonPoint(intersectionPoint.getX(), intersectionPoint.getY(), intersectionPoint.getZ());
                        toXY.transform(polygonPoint);
                        holePolygon.add(polygonPoint);
                    } else {
                        outside = true;
                        break;
                    }
                }
                if (!outside) {
                    polygon.addHole(new PolygonWithHoles(holePolygon));
                    holes.remove(window);
                    window.setRoofIndex(roofIndex);
                }
            }
            final Mesh meshWithHoles = (Mesh) ((Node) roofPart).getChild(6);
            try {
                fillMeshWithPolygon(meshWithHoles, polygon, fromXY, true, o, v, u, false);
            } catch (final RuntimeException e) {
                e.printStackTrace();
                final Mesh meshWithoutHoles = (Mesh) ((Node) roofPart).getChild(0);
                meshWithHoles.setMeshData(meshWithoutHoles.getMeshData());
            }
        }
    }
}
Also used : Window(org.concord.energy3d.model.Window) AnyToXYTransform(org.poly2tri.transform.coordinate.AnyToXYTransform) HashMap(java.util.HashMap) Node(com.ardor3d.scenegraph.Node) ArrayList(java.util.ArrayList) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) Mesh(com.ardor3d.scenegraph.Mesh) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point) TPoint(org.poly2tri.triangulation.point.TPoint) Ray3(com.ardor3d.math.Ray3) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) XYToAnyTransform(org.poly2tri.transform.coordinate.XYToAnyTransform) Spatial(com.ardor3d.scenegraph.Spatial) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) ArrayList(java.util.ArrayList) List(java.util.List) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) PickResults(com.ardor3d.intersection.PickResults)

Example 3 with PolygonPoint

use of org.poly2tri.geometry.polygon.PolygonPoint in project energy3d by concord-consortium.

the class Wall method drawPolygon.

private void drawPolygon(final List<List<Vector3>> wallAndWindowsPoints, final Mesh mesh, final boolean drawHoles, final boolean normal, final boolean texture) {
    final List<PolygonPoint> polygonPoints = new ArrayList<PolygonPoint>(wallAndWindowsPoints.get(0).size());
    for (final Vector3 p : wallAndWindowsPoints.get(0)) {
        final PolygonPoint tp = new PolygonPoint(p.getX(), p.getY(), p.getZ());
        toXY.transform(tp);
        polygonPoints.add(tp);
    }
    final PolygonWithHoles polygon = new PolygonWithHoles(polygonPoints);
    if (drawHoles) {
        for (int i = 1; i < wallAndWindowsPoints.size(); i++) {
            final List<PolygonPoint> holePoints = new ArrayList<PolygonPoint>(wallAndWindowsPoints.get(i).size());
            for (final Vector3 p : wallAndWindowsPoints.get(i)) {
                final PolygonPoint tp = new PolygonPoint(p.getX(), p.getY(), p.getZ());
                toXY.transform(tp);
                holePoints.add(tp);
            }
            polygon.addHole(new Polygon(holePoints));
        }
    }
    if (texture) {
        final double scale = Scene.getInstance().getTextureMode() == TextureMode.Simple ? 1.0 : 8.0;
        final boolean fullTexture = Scene.getInstance().getTextureMode() == TextureMode.Full;
        final ReadOnlyVector3 p0 = getAbsPoint(0);
        final ReadOnlyVector3 p01 = getAbsPoint(1).subtractLocal(p0).normalizeLocal().multiplyLocal(scale * (fullTexture ? 1.5 : 1.0));
        final ReadOnlyVector3 p02 = getAbsPoint(2).subtractLocal(p0).normalizeLocal().multiplyLocal(scale * (fullTexture ? 2.0 : 1.0));
        final TPoint o = new TPoint(p0.getX(), p0.getY(), p0.getZ());
        final TPoint u = new TPoint(p01.getX(), p01.getY(), p01.getZ());
        final TPoint v = new TPoint(p02.getX(), p02.getY(), p02.getZ());
        toXY.transform(o);
        toXY.transform(u);
        MeshLib.fillMeshWithPolygon(mesh, polygon, fromXY, normal, o, u, v, true);
    } else {
        MeshLib.fillMeshWithPolygon(mesh, polygon, fromXY, normal, null, null, null, true);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArrayList(java.util.ArrayList) PolygonWithHoles(org.concord.energy3d.util.PolygonWithHoles) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Polygon(org.poly2tri.geometry.polygon.Polygon) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point) PickingHint(com.ardor3d.scenegraph.hint.PickingHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point) TPoint(org.poly2tri.triangulation.point.TPoint)

Example 4 with PolygonPoint

use of org.poly2tri.geometry.polygon.PolygonPoint in project energy3d by concord-consortium.

the class Floor method exploreWallNeighbors.

protected ArrayList<PolygonPoint> exploreWallNeighbors(final Wall startWall) {
    final ArrayList<PolygonPoint> poly = new ArrayList<PolygonPoint>();
    startWall.visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall currentWall, final Snap prev, final Snap next) {
            int pointIndex = 0;
            if (next != null) {
                pointIndex = next.getSnapPointIndexOf(currentWall);
            }
            pointIndex = pointIndex + 1;
            final ReadOnlyVector3 p1 = currentWall.getAbsPoint(pointIndex == 1 ? 3 : 1);
            final ReadOnlyVector3 p2 = currentWall.getAbsPoint(pointIndex);
            addPointToPolygon(poly, p1);
            addPointToPolygon(poly, p2);
            wallUpperVectors.add(p1);
            wallUpperVectors.add(p2);
        }
    });
    return poly;
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArrayList(java.util.ArrayList)

Aggregations

ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)4 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)4 CullHint (com.ardor3d.scenegraph.hint.CullHint)3 ArrayList (java.util.ArrayList)3 TPoint (org.poly2tri.triangulation.point.TPoint)3 Vector3 (com.ardor3d.math.Vector3)2 Point (org.poly2tri.geometry.primitives.Point)2 PickResults (com.ardor3d.intersection.PickResults)1 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)1 Ray3 (com.ardor3d.math.Ray3)1 Vector2 (com.ardor3d.math.Vector2)1 ReadOnlyVector2 (com.ardor3d.math.type.ReadOnlyVector2)1 Mesh (com.ardor3d.scenegraph.Mesh)1 Node (com.ardor3d.scenegraph.Node)1 Spatial (com.ardor3d.scenegraph.Spatial)1 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Window (org.concord.energy3d.model.Window)1 SizeAnnotation (org.concord.energy3d.shapes.SizeAnnotation)1