Search in sources :

Example 21 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 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 22 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 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 23 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.

the class Roof method initWallUpperPoints.

private void initWallUpperPoints(final Wall startWall, final List<Wall> walls, final List<ReadOnlyVector3> wallUpperPoints, final List<ReadOnlyVector3> wallNormals) {
    walls.clear();
    wallUpperPoints.clear();
    wallNormals.clear();
    startWall.visitNeighbors(new WallVisitor() {

        @Override
        public void visit(final Wall currentWall, final Snap prevSnap, final Snap nextSnap) {
            if (currentWall.isFirstPointInserted()) {
                walls.add(currentWall);
                currentWall.setRoof(Roof.this);
                final int pointIndex2 = nextSnap != null ? nextSnap.getSnapPointIndexOf(currentWall) + 1 : 1;
                final int pointIndex1 = pointIndex2 == 1 ? 3 : 1;
                final Vector3 p1 = currentWall.getAbsPoint(pointIndex1);
                final Vector3 p2 = currentWall.getAbsPoint(pointIndex2);
                final ReadOnlyVector3 normal = currentWall.getNormal();
                addPointToPolygon(p1, normal, wallUpperPoints, wallNormals);
                addPointToPolygon(p2, normal, wallUpperPoints, wallNormals);
            }
        }
    });
}
Also used : WallVisitor(org.concord.energy3d.util.WallVisitor) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 24 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 in project energy3d by concord-consortium.

the class Roof method computeGableEditPoints.

private void computeGableEditPoints() {
    if (gableEditPointToWallMap == null) {
        return;
    }
    for (final int editPointIndex : gableEditPointToWallMap.keySet()) {
        // if (editPointIndex >= points.size()) {
        // gableEditPointToWallMap.clear();
        // break;
        // }
        final Vector3 editPoint = getAbsPoint(editPointIndex);
        final List<Wall> gableWalls = gableEditPointToWallMap.get(editPointIndex);
        final List<ReadOnlyVector3> wallPoints = new ArrayList<ReadOnlyVector3>(gableWalls.size() * 2);
        final List<ReadOnlyVector3> wallNormals = new ArrayList<ReadOnlyVector3>(gableWalls.size() * 2);
        for (final Wall wall : gableWalls) {
            addPointToPolygon(wall.getAbsPoint(0), wall.getNormal(), wallPoints, wallNormals);
            addPointToPolygon(wall.getAbsPoint(2), wall.getNormal(), wallPoints, wallNormals);
        }
        applyOverhang(wallPoints, wallNormals);
        if (gableWalls.size() == 1) {
            final ReadOnlyVector2 p2D = Util.snapToPolygon(editPoint, wallPoints, wallNormals);
            editPoint.setX(p2D.getX());
            editPoint.setY(p2D.getY());
        } else if (gableWalls.size() > 1) {
            final Vector3 p0 = gableWalls.get(0).getAbsPoint(0);
            final Wall secondWall = gableWalls.get(1);
            final ReadOnlyVector3 cornerPoint;
            final int cornerIndex;
            if (Util.isEqual(p0, secondWall.getAbsPoint(0)) || Util.isEqual(p0, secondWall.getAbsPoint(2))) {
                cornerIndex = 0;
            } else {
                cornerIndex = 1;
            }
            cornerPoint = wallPoints.get(cornerIndex).subtract(wallNormals.get(cornerIndex).multiply(0.01, null), null);
            editPoint.setX(cornerPoint.getX());
            editPoint.setY(cornerPoint.getY());
        }
        points.get(editPointIndex).set(toRelative(editPoint));
    }
}
Also used : ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ArrayList(java.util.ArrayList) 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 25 with ReadOnlyVector3

use of com.ardor3d.math.type.ReadOnlyVector3 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)

Aggregations

ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)125 Vector3 (com.ardor3d.math.Vector3)88 CullHint (com.ardor3d.scenegraph.hint.CullHint)60 FloatBuffer (java.nio.FloatBuffer)45 TPoint (org.poly2tri.triangulation.point.TPoint)44 Point (org.poly2tri.geometry.primitives.Point)34 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)32 Mesh (com.ardor3d.scenegraph.Mesh)25 Spatial (com.ardor3d.scenegraph.Spatial)25 ArrayList (java.util.ArrayList)23 Node (com.ardor3d.scenegraph.Node)18 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)18 Ray3 (com.ardor3d.math.Ray3)16 PickResults (com.ardor3d.intersection.PickResults)15 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)15 ArdorVector3Point (org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)15 TriangulationPoint (org.poly2tri.triangulation.TriangulationPoint)13 Matrix3 (com.ardor3d.math.Matrix3)10 CancellationException (java.util.concurrent.CancellationException)10 Vector2 (com.ardor3d.math.Vector2)9