Search in sources :

Example 16 with Spatial

use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.

the class Roof method computeOrientedBoundingBox.

@Override
public void computeOrientedBoundingBox() {
    orgCenters.clear();
    for (final Spatial roofPartNode : roofPartsRoot.getChildren()) {
        if (roofPartNode.getSceneHints().getCullHint() != CullHint.Always) {
            final Mesh roofPartMesh = (Mesh) ((Node) roofPartNode).getChild(0);
            computeOrientedBoundingBox(roofPartMesh);
            orgCenters.put((Node) roofPartNode, new Vector3(roofPartMesh.getWorldBound().getCenter()));
        }
    }
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 17 with Spatial

use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.

the class Roof method computeArea.

@Override
protected void computeArea() {
    this.area = 0;
    if (container == null) {
        return;
    }
    if (areaByPartWithOverhang == null) {
        areaByPartWithOverhang = new HashMap<Mesh, Double>();
    } else {
        areaByPartWithOverhang.clear();
    }
    if (areaByPartWithoutOverhang == null) {
        areaByPartWithoutOverhang = new HashMap<Mesh, Double>();
    } else {
        areaByPartWithoutOverhang.clear();
    }
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final Node roofPartNode = (Node) roofPart;
            final Mesh roofPartMesh = (Mesh) roofPartNode.getChild(REAL_MESH_INDEX);
            areaByPartWithOverhang.put(roofPartMesh, Util.computeArea(roofPartMesh));
            final FloatBuffer vertexBuffer = roofPartMesh.getMeshData().getVertexBuffer();
            final Vector3 p = new Vector3();
            if (overhangLength <= OVERHANG_MIN) {
                final double a = Util.computeArea(roofPartMesh);
                areaByPartWithoutOverhang.put(roofPartMesh, a);
                area += a;
            } else {
                final List<ReadOnlyVector3> result = computeDashPoints(roofPartMesh);
                if (result.isEmpty()) {
                    vertexBuffer.rewind();
                    p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
                    final double a;
                    if (Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
                        a = Util.computeArea(roofPartMesh);
                    } else {
                        a = 0;
                    }
                    areaByPartWithoutOverhang.put(roofPartMesh, a);
                    area += a;
                } else {
                    // if (roofPartsRoot.getNumberOfChildren() > 1) {
                    double highPointZ = Double.NEGATIVE_INFINITY;
                    vertexBuffer.rewind();
                    while (vertexBuffer.hasRemaining()) {
                        p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
                        if (p.getZ() > highPointZ) {
                            highPointZ = p.getZ();
                        }
                    }
                    final List<ReadOnlyVector3> highPoints = new ArrayList<ReadOnlyVector3>();
                    vertexBuffer.rewind();
                    while (vertexBuffer.hasRemaining()) {
                        p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
                        if (p.getZ() >= highPointZ - MathUtils.ZERO_TOLERANCE && Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
                            highPoints.add(new Vector3(p));
                        }
                    }
                    if (highPoints.size() == 1) {
                        result.add(highPoints.get(0));
                    } else {
                        final ReadOnlyVector3 lastPoint = result.get(result.size() - 1);
                        while (!highPoints.isEmpty()) {
                            double shortestDistance = Double.MAX_VALUE;
                            ReadOnlyVector3 nearestPoint = null;
                            for (final ReadOnlyVector3 hp : highPoints) {
                                final double distance = hp.distance(lastPoint);
                                if (distance < shortestDistance) {
                                    shortestDistance = distance;
                                    nearestPoint = hp;
                                }
                            }
                            result.add(nearestPoint);
                            highPoints.remove(nearestPoint);
                        }
                    }
                    result.add(result.get(0));
                    final double annotationScale = Scene.getInstance().getAnnotationScale();
                    final double a = Util.area3D_Polygon(result, (ReadOnlyVector3) roofPart.getUserData()) * annotationScale * annotationScale;
                    areaByPartWithoutOverhang.put(roofPartMesh, a);
                    this.area += a;
                }
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 18 with Spatial

use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.

the class PrintController method arrangePrintPages.

private void arrangePrintPages(final ArrayList<ArrayList<Spatial>> pages) {
    final double ratio = (double) Camera.getCurrentCamera().getWidth() / Camera.getCurrentCamera().getHeight();
    cols = (int) Math.round(Math.sqrt(pages.size() + 4) * ratio);
    if (cols % 2 == 0) {
        cols++;
    }
    rows = (int) Math.ceil((pages.size() + 4) / cols);
    int pageNum = 0;
    printCenters.clear();
    for (final ArrayList<Spatial> page : pages) {
        final Vector3 upperLeftCorner = new Vector3();
        double x, z;
        final BoundingBox originalHouseBoundingBox = (BoundingBox) Scene.getOriginalHouseRoot().getWorldBound().asType(Type.AABB);
        final ReadOnlyVector3 originalHouseCenter = Scene.getOriginalHouseRoot().getWorldBound().getCenter();
        final double minXDistance = originalHouseBoundingBox.getXExtent() + pageWidth / 2.0;
        final double minYDistance = originalHouseBoundingBox.getZExtent();
        do {
            x = (pageNum % cols - cols / 2) * (pageWidth + SPACE_BETWEEN_PAGES) + originalHouseCenter.getX();
            z = (pageNum / cols) * (pageHeight + SPACE_BETWEEN_PAGES);
            upperLeftCorner.setX(x - pageWidth / 2.0);
            upperLeftCorner.setZ(z + pageHeight);
            pageNum++;
        } while (Math.abs(x - originalHouseCenter.getX()) < minXDistance && Math.abs(z - originalHouseCenter.getZ()) < minYDistance);
        printCenters.add(upperLeftCorner);
        for (final Spatial printSpatial : page) {
            ((UserData) printSpatial.getUserData()).getPrintCenter().addLocal(upperLeftCorner.multiply(1, 0, 1, null));
        }
        final Box box = new Box("Page Boundary");
        final double y = Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY();
        box.setData(upperLeftCorner.add(0, y + 1, 0, null), upperLeftCorner.add(pageWidth, y + 1.2, -pageHeight, null));
        box.setModelBound(new BoundingBox());
        box.updateModelBound();
        pagesRoot.attachChild(box);
        final BMText footNote = Annotation.makeNewLabel(1);
        final String url = Scene.getURL() != null ? Scene.getURL().getFile().substring(Scene.getURL().getFile().lastIndexOf('/') + 1, Scene.getURL().getFile().length()) + " -" : "";
        footNote.setText(url.replaceAll("%20", " ") + " Page " + printCenters.size() + " / " + pages.size() + " - http://energy.concord.org/");
        footNote.setFontScale(0.5);
        footNote.setAlign(Align.North);
        footNote.setTranslation(upperLeftCorner.add(pageWidth / 2.0, 0.0, -pageBottom - spaceBetweenParts / 2.0, null));
        pagesRoot.attachChild(footNote);
    }
    pagesRoot.updateGeometricState(0);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) BMText(com.ardor3d.ui.text.BMText) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 19 with Spatial

use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.

the class PrintController method computePrintCenterOf.

private void computePrintCenterOf(final Spatial printPart, final ArrayList<ArrayList<Spatial>> pages) {
    boolean isFitted = false;
    for (int pageNum = 0; pageNum < pages.size() && !isFitted; pageNum++) {
        isFitted = fitInPage(printPart, pages.get(pageNum));
    }
    if (!isFitted) {
        printPart.updateWorldBound(true);
        final OrientedBoundingBox bounds = (OrientedBoundingBox) printPart.getWorldBound().asType(Type.OBB);
        ((UserData) printPart.getUserData()).setPrintCenter(new Vector3(bounds.getExtent().getX() + pageLeft, Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY(), -bounds.getExtent().getZ() - pageTop));
        final ArrayList<Spatial> page = new ArrayList<Spatial>();
        page.add(printPart);
        pages.add(page);
    }
}
Also used : OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) UserData(org.concord.energy3d.model.UserData) Spatial(com.ardor3d.scenegraph.Spatial) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 20 with Spatial

use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.

the class NodeWorker method reach.

static void reach(final Node node) {
    final List<Spatial> collidables = new ArrayList<Spatial>();
    collidables.addAll(node.getChildren());
    collidables.add(SceneManager.getInstance().getLand());
    int count = 0;
    for (final Spatial s : node.getChildren()) {
        reach((Mesh) s, collidables);
        if (count % 20 == 0) {
            EnergyPanel.getInstance().progress((int) Math.round(100.0 * count / node.getNumberOfChildren()));
        }
        count++;
    }
    EnergyPanel.getInstance().progress(0);
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) ArrayList(java.util.ArrayList)

Aggregations

Spatial (com.ardor3d.scenegraph.Spatial)57 Mesh (com.ardor3d.scenegraph.Mesh)36 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)33 Node (com.ardor3d.scenegraph.Node)26 CullHint (com.ardor3d.scenegraph.hint.CullHint)26 Vector3 (com.ardor3d.math.Vector3)24 TPoint (org.poly2tri.triangulation.point.TPoint)18 PickResults (com.ardor3d.intersection.PickResults)15 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)15 Ray3 (com.ardor3d.math.Ray3)15 Point (org.poly2tri.geometry.primitives.Point)14 FloatBuffer (java.nio.FloatBuffer)13 ArrayList (java.util.ArrayList)12 HousePart (org.concord.energy3d.model.HousePart)12 CancellationException (java.util.concurrent.CancellationException)10 Foundation (org.concord.energy3d.model.Foundation)10 Roof (org.concord.energy3d.model.Roof)9 Calendar (java.util.Calendar)7 UserData (org.concord.energy3d.model.UserData)6 Window (org.concord.energy3d.model.Window)6