Search in sources :

Example 11 with Node

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

the class Roof method drawOutline.

protected void drawOutline() {
    if (container == null) {
        return;
    }
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final Node roofPartNode = (Node) roofPart;
            final Mesh outlineMesh = (Mesh) roofPartNode.getChild(4);
            final Mesh mesh = (Mesh) roofPartNode.getChild(0);
            final ArrayList<ReadOnlyVector3> outlinePoints = MeshLib.computeOutline(mesh.getMeshData().getVertexBuffer());
            int totalVertices = outlinePoints.size();
            for (final HousePart part : children) {
                if (part instanceof Window) {
                    totalVertices += 8;
                }
            }
            final FloatBuffer buf;
            if (outlineMesh.getMeshData().getVertexBuffer().capacity() >= totalVertices * 2 * 3) {
                buf = outlineMesh.getMeshData().getVertexBuffer();
                buf.limit(buf.capacity());
                buf.rewind();
            } else {
                buf = BufferUtils.createVector3Buffer(totalVertices * 2);
                outlineMesh.getMeshData().setVertexBuffer(buf);
            }
            // draw roof outline
            for (int i = 0; i < outlinePoints.size(); i++) {
                final ReadOnlyVector3 p1 = outlinePoints.get(i);
                final ReadOnlyVector3 p2 = outlinePoints.get((i + 1) % outlinePoints.size());
                buf.put(p1.getXf()).put(p1.getYf()).put(p1.getZf());
                buf.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
            }
            // draw skylights outline
            final int[] windowIndices = new int[] { 0, 2, 3, 1 };
            for (final HousePart part : children) {
                if (part instanceof Window && part.isDrawable() && ((Window) part).getRoofIndex() == ((UserData) mesh.getUserData()).getEditPointIndex()) {
                    for (int i = 0; i < part.getPoints().size(); i++) {
                        final ReadOnlyVector3 p1 = part.getAbsPoint(windowIndices[i]);
                        final ReadOnlyVector3 p2 = part.getAbsPoint(windowIndices[(i + 1) % part.getPoints().size()]);
                        buf.put(p1.getXf()).put(p1.getYf()).put(p1.getZf());
                        buf.put(p2.getXf()).put(p2.getYf()).put(p2.getZf());
                    }
                }
            }
            buf.limit(buf.position());
            outlineMesh.getMeshData().updateVertexCount();
            outlineMesh.updateModelBound();
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 12 with Node

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

the class Roof method drawMesh.

@Override
protected void drawMesh() {
    // undo the effect of wall stretch on all walls if roof is moved to new walls
    if (previousContainer != container) {
        previousContainer = container;
        for (final Wall wall : walls) {
            wall.setRoof(null);
            wall.draw();
        }
    }
    dashPointsCache.clear();
    if (wallUpperPoints == null) {
        wallUpperPoints = new ArrayList<ReadOnlyVector3>();
    } else {
        wallUpperPoints.clear();
    }
    if (container != null) {
        initWallUpperPoints((Wall) container, walls, wallUpperPoints, wallNormals);
    }
    if (!isDrawable()) {
        roofPartsRoot.getSceneHints().setCullHint(CullHint.Always);
        setEditPointsVisible(false);
        return;
    }
    roofPartsRoot.getSceneHints().setCullHint(CullHint.Inherit);
    final ArrayList<Vector3> orgPoints = new ArrayList<Vector3>(points.size());
    for (final ReadOnlyVector3 p : points) {
        orgPoints.add(p.clone());
    }
    wallUpperPointsWithoutOverhang = new ArrayList<ReadOnlyVector3>(wallUpperPoints);
    drawRoof();
    switch(type) {
        case TRANSPARENT:
            for (final Spatial child : roofPartsRoot.getChildren()) {
                ((Mesh) ((Node) child).getChild(0)).getSceneHints().setCullHint(CullHint.Always);
                ((Mesh) ((Node) child).getChild(REAL_MESH_INDEX)).getSceneHints().setCullHint(CullHint.Always);
            }
            break;
        default:
            for (final Spatial child : roofPartsRoot.getChildren()) {
                ((Mesh) ((Node) child).getChild(0)).getSceneHints().setCullHint(CullHint.Inherit);
                ((Mesh) ((Node) child).getChild(REAL_MESH_INDEX)).getSceneHints().setCullHint(CullHint.Inherit);
            }
    }
    roofPartsRoot.updateWorldBound(true);
    drawOutline();
    if (Scene.getInstance().areDashedLinesOnRoofShown()) {
        drawDashLines();
    } else {
        for (final Spatial roofPart : roofPartsRoot.getChildren()) {
            if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                final Mesh dashLinesMesh = (Mesh) ((Node) roofPart).getChild(5);
                dashLinesMesh.setVisible(false);
            }
        }
    }
}
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) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 13 with Node

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

the class Roof method drawHeatFlux.

@Override
public void drawHeatFlux() {
    FloatBuffer arrowsVertices = heatFlux.getMeshData().getVertexBuffer();
    final Foundation foundation = getTopContainer();
    final int cols = (int) Math.max(2, foundation.getAbsPoint(0).distance(foundation.getAbsPoint(2)) / Scene.getInstance().getHeatVectorGridSize());
    final int rows = (int) Math.max(2, foundation.getAbsPoint(0).distance(foundation.getAbsPoint(1)) / Scene.getInstance().getHeatVectorGridSize());
    arrowsVertices = BufferUtils.createVector3Buffer(rows * cols * 6);
    heatFlux.getMeshData().setVertexBuffer(arrowsVertices);
    final ReadOnlyVector3 o = foundation.getAbsPoint(0);
    final ReadOnlyVector3 u = foundation.getAbsPoint(2).subtract(o, null);
    final ReadOnlyVector3 v = foundation.getAbsPoint(1).subtract(o, null);
    final Vector3 a = new Vector3();
    double g, h;
    boolean init = true;
    for (int j = 0; j < cols; j++) {
        h = j + 0.5;
        for (int i = 0; i < rows; i++) {
            g = i + 0.5;
            a.setX(o.getX() + g * v.getX() / rows + h * u.getX() / cols);
            a.setY(o.getY() + g * v.getY() / rows + h * u.getY() / cols);
            a.setZ(o.getZ());
            if (insideWalls(a.getX(), a.getY(), init)) {
                ReadOnlyVector3 b = null;
                Node node = null;
                Mesh mesh = null;
                for (final Spatial child : roofPartsRoot.getChildren()) {
                    if (child.getSceneHints().getCullHint() != CullHint.Always) {
                        node = (Node) child;
                        mesh = (Mesh) node.getChild(REAL_MESH_INDEX);
                        b = findRoofIntersection(mesh, a);
                        if (b != null) {
                            break;
                        }
                    }
                }
                if (b != null) {
                    final ReadOnlyVector3 normal = (ReadOnlyVector3) node.getUserData();
                    final double heat = calculateHeatVector(mesh);
                    drawArrow(b, normal, arrowsVertices, heat);
                }
            }
            if (init) {
                init = false;
            }
        }
        heatFlux.getMeshData().updateVertexCount();
        heatFlux.updateModelBound();
    }
    updateHeatFluxVisibility();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 14 with Node

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

the class Roof method hideGableRoofParts.

private void hideGableRoofParts() {
    if (gableEditPointToWallMap == null) {
        return;
    }
    // Two Options: hide using estimating direction with wall. Or, hide using roof part number (it be wrong))
    for (final List<Wall> walls : gableEditPointToWallMap.values()) {
        for (final HousePart wall : walls) {
            final Vector3[] base_i = { wall.getAbsPoint(0), wall.getAbsPoint(2) };
            for (final Spatial roofPart : getRoofPartsRoot().getChildren()) {
                final ReadOnlyVector3[] base = findBasePoints((Mesh) ((Node) roofPart).getChild(0), null);
                if (base != null && isSameBasePoints(base_i[0], base_i[1], base[0], base[1])) {
                    roofPart.getSceneHints().setCullHint(CullHint.Always);
                    roofPart.getSceneHints().setAllPickingHints(false);
                    break;
                }
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 15 with Node

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

the class Roof method setAnnotationsVisible.

@Override
public void setAnnotationsVisible(final boolean visible) {
    super.setAnnotationsVisible(visible);
    final CullHint cull = visible ? CullHint.Inherit : CullHint.Always;
    if (roofPartsRoot != null) {
        for (final Spatial roofPart : roofPartsRoot.getChildren()) {
            if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                ((Node) roofPart).getChild(1).getSceneHints().setCullHint(cull);
                ((Node) roofPart).getChild(2).getSceneHints().setCullHint(cull);
            }
        }
    }
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Aggregations

Node (com.ardor3d.scenegraph.Node)50 Mesh (com.ardor3d.scenegraph.Mesh)31 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)27 Spatial (com.ardor3d.scenegraph.Spatial)26 Vector3 (com.ardor3d.math.Vector3)20 CullHint (com.ardor3d.scenegraph.hint.CullHint)20 Foundation (org.concord.energy3d.model.Foundation)12 FloatBuffer (java.nio.FloatBuffer)11 ArrayList (java.util.ArrayList)11 Line (com.ardor3d.scenegraph.Line)10 HousePart (org.concord.energy3d.model.HousePart)10 TPoint (org.poly2tri.triangulation.point.TPoint)10 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)9 ColorRGBA (com.ardor3d.math.ColorRGBA)7 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)7 BoundingBox (com.ardor3d.bounding.BoundingBox)6 BMText (com.ardor3d.ui.text.BMText)6 List (java.util.List)6 Rack (org.concord.energy3d.model.Rack)6 Roof (org.concord.energy3d.model.Roof)6