Search in sources :

Example 86 with Vector3

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

the class Wall method drawMesh.

@Override
protected void drawMesh() {
    final boolean drawable = isDrawable();
    final CullHint drawableSolidWall = drawable && type == SOLID_WALL ? CullHint.Inherit : CullHint.Always;
    mesh.getSceneHints().setCullHint(drawableSolidWall);
    outlineMesh.getSceneHints().setCullHint(drawableSolidWall);
    final CullHint drawableSolidNoneFrozenWall = drawable && type == SOLID_WALL ? CullHint.Inherit : CullHint.Always;
    backMesh.getSceneHints().setCullHint(drawableSolidNoneFrozenWall);
    surroundMesh.getSceneHints().setCullHint(drawableSolidNoneFrozenWall);
    windowsSurroundMesh.getSceneHints().setCullHint(drawableSolidNoneFrozenWall);
    if (!drawable) {
        return;
    }
    computeNormalAndXYTransform();
    wallAndWindowsPoints = computeWallAndWindowPolygon(false);
    stretchToRoof(wallAndWindowsPoints.get(0));
    switch(type) {
        case EMPTY:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Always);
            rails.getSceneHints().setCullHint(CullHint.Always);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            break;
        case VERTICAL_EDGES_ONLY:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Inherit);
            rails.getSceneHints().setCullHint(CullHint.Always);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            drawVerticalEdges(columnRadius);
            break;
        case COLUMNS_ONLY:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Inherit);
            rails.getSceneHints().setCullHint(CullHint.Always);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            drawColumns(10);
            break;
        case RAILS_ONLY:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Always);
            rails.getSceneHints().setCullHint(CullHint.Inherit);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            drawRails(1, false);
            break;
        case COLUMNS_RAILS:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Inherit);
            rails.getSceneHints().setCullHint(CullHint.Inherit);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            drawColumns(10);
            drawRails(1, false);
            break;
        case FENCE:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Always);
            rails.getSceneHints().setCullHint(CullHint.Inherit);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            drawRails(1, true);
            break;
        case STEEL_FRAME:
            outlineMesh.getSceneHints().setCullHint(CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Inherit);
            rails.getSceneHints().setCullHint(CullHint.Always);
            steelFrame.getSceneHints().setCullHint(CullHint.Inherit);
            drawVerticalEdges(1);
            drawSteelFrame(0.25, 10);
            break;
        default:
            outlineMesh.getSceneHints().setCullHint(drawable && !hideOutline ? CullHint.Inherit : CullHint.Always);
            columns.getSceneHints().setCullHint(CullHint.Always);
            rails.getSceneHints().setCullHint(CullHint.Always);
            steelFrame.getSceneHints().setCullHint(CullHint.Always);
            if (Scene.getInstance().isDrawThickness() && isShortWall) {
                final Vector3 dir = getAbsPoint(2).subtract(getAbsPoint(0), null).normalizeLocal();
                if (neighbors[0] != null && neighbors[0].getNeighborOf(this).isFirstPointInserted()) {
                    if (isPerpendicularToNeighbor(0)) {
                        reduceBackMeshWidth(wallAndWindowsPoints.get(0), dir, 0);
                    }
                }
                if (neighbors[1] != null && neighbors[1].getNeighborOf(this).isFirstPointInserted()) {
                    dir.normalizeLocal().negateLocal();
                    if (isPerpendicularToNeighbor(1)) {
                        reduceBackMeshWidth(wallAndWindowsPoints.get(0), dir, 1);
                    }
                }
            }
            drawOutline(wallAndWindowsPoints);
            if (isDrawBackMesh()) {
                drawBackMesh(computeWallAndWindowPolygon(true));
            } else {
                backMesh.getSceneHints().setCullHint(CullHint.Always);
            }
            drawSurroundMesh(thicknessNormal);
            drawWindowsSurroundMesh(thicknessNormal);
    }
    drawPolygon(wallAndWindowsPoints, mesh, true, true, true);
    drawPolygon(wallAndWindowsPoints, invisibleMesh, false, false, false);
    CollisionTreeManager.INSTANCE.removeCollisionTree(mesh);
    CollisionTreeManager.INSTANCE.removeCollisionTree(invisibleMesh);
    root.updateWorldBound(true);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 87 with Vector3

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

the class Wall method fits.

@Override
public boolean fits(final HousePart window) {
    if (wallAndWindowsPoints != null) {
        final List<Vector3> hole = computeWindowHole(window, Vector3.ZERO);
        applyXYTransform(hole);
        final double minDistanceToRoof = 0.1 * getGridSize();
        final ArrayList<Vector3> polygon = new ArrayList<Vector3>(wallAndWindowsPoints.get(0).size());
        for (int i = 0; i < wallAndWindowsPoints.get(0).size(); i++) {
            final Vector3 p = wallAndWindowsPoints.get(0).get(i).clone();
            if (i == 0 || i > 2) {
                p.subtractLocal(0, 0, minDistanceToRoof);
            }
            polygon.add(p);
        }
        applyXYTransform(polygon);
        for (final Vector3 p : hole) {
            if (!Util.insidePolygon(p, polygon)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) 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)

Example 88 with Vector3

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

the class Wall method stretchToRoof.

private void stretchToRoof(final List<Vector3> polygon) {
    if (!extendToRoofEnabled || roof == null || roof.isSingleFlatMesh()) {
        return;
    }
    final ReadOnlyVector3 o = polygon.get(0).clone();
    final Vector3 dir = polygon.get(3).subtract(o, null);
    dir.setZ(0);
    final double length = dir.length();
    dir.normalizeLocal();
    final int[] upper = { 0, 3 };
    for (final int i : upper) {
        final Vector3 tp = polygon.get(i);
        final double z = findRoofIntersection(tp);
        tp.set(tp.getX(), tp.getY(), z);
    }
    Vector3 direction = null;
    Vector3 previousStretchPoint = polygon.get(3);
    for (double d = length - STRETCH_ROOF_STEP; d > STRETCH_ROOF_STEP; d -= STRETCH_ROOF_STEP) {
        final Vector3 p = dir.multiply(d, null).addLocal(o);
        final double findRoofIntersection = findRoofIntersection(p);
        final Vector3 currentStretchPoint = new Vector3(p.getX(), p.getY(), findRoofIntersection);
        final Vector3 currentDirection = currentStretchPoint.subtract(previousStretchPoint, null).normalizeLocal();
        if (direction == null) {
            direction = currentDirection;
        } else if (direction.dot(currentDirection) < 1.0 - MathUtils.ZERO_TOLERANCE) {
            direction = null;
            polygon.add(previousStretchPoint);
            polygon.add(currentStretchPoint);
        }
        previousStretchPoint = currentStretchPoint;
    }
    if (!polygon.get(polygon.size() - 1).equals(previousStretchPoint)) {
        polygon.add(previousStretchPoint);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) 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)

Example 89 with Vector3

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

the class Wall method drawHeatFlux.

@Override
public void drawHeatFlux() {
    if (type != SOLID_WALL) {
        return;
    }
    double zmax = -Double.MAX_VALUE;
    final List<Vector3> wallPolygonPoints = getWallPolygonPoints();
    for (final Vector3 a : wallPolygonPoints) {
        if (a.getZ() > zmax) {
            zmax = a.getZ();
        }
    }
    final Path2D.Double path = new Path2D.Double();
    path.moveTo(0, 0);
    final Vector3 v1 = new Vector3();
    final Vector3 v2 = new Vector3();
    wallPolygonPoints.get(1).subtract(wallPolygonPoints.get(0), v1);
    wallPolygonPoints.get(2).subtract(wallPolygonPoints.get(0), v2);
    if (Util.isZero(v1.getX()) && Util.isZero(v2.getX())) {
        path.moveTo(v1.getY(), v1.getZ());
        path.lineTo(v2.getY(), v2.getZ());
        for (int i = 3; i < wallPolygonPoints.size(); i++) {
            wallPolygonPoints.get(i).subtract(wallPolygonPoints.get(0), v2);
            path.lineTo(v2.getY(), v2.getZ());
        }
    } else {
        // always use the Y plane unless it is a X plane as above
        path.moveTo(v1.getX(), v1.getZ());
        path.lineTo(v2.getX(), v2.getZ());
        for (int i = 3; i < wallPolygonPoints.size(); i++) {
            wallPolygonPoints.get(i).subtract(wallPolygonPoints.get(0), v2);
            path.lineTo(v2.getX(), v2.getZ());
        }
    }
    path.lineTo(0, 0);
    path.closePath();
    heatFlux.getSceneHints().setCullHint(CullHint.Inherit);
    FloatBuffer arrowsVertices = heatFlux.getMeshData().getVertexBuffer();
    final int cols = (int) Math.max(2, getAbsPoint(0).distance(getAbsPoint(2)) / Scene.getInstance().getHeatVectorGridSize());
    final int rows = (int) Math.max(2, zmax / Scene.getInstance().getHeatVectorGridSize());
    arrowsVertices = BufferUtils.createVector3Buffer(rows * cols * 6);
    heatFlux.getMeshData().setVertexBuffer(arrowsVertices);
    final double heat = calculateHeatVector();
    if (heat != 0) {
        final ReadOnlyVector3 o = getAbsPoint(0);
        final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
        final ReadOnlyVector3 v = getAbsPoint(1).subtract(o, null);
        final ReadOnlyVector3 normal = getNormal();
        final Vector3 a = new Vector3();
        double g, h;
        for (int j = 0; j < cols; j++) {
            h = j + 0.5;
            for (int i = 0; i < rows - 1; 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() + g * zmax / rows);
                a.subtract(wallPolygonPoints.get(0), v1);
                if (Util.isZero(v1.getX())) {
                    if (!path.contains(v1.getY(), v1.getZ())) {
                        break;
                    }
                } else {
                    if (!path.contains(v1.getX(), v1.getZ())) {
                        break;
                    }
                }
                drawArrow(a, normal, arrowsVertices, heat);
            }
        }
        heatFlux.getMeshData().updateVertexCount();
        heatFlux.updateModelBound();
    }
    updateHeatFluxVisibility();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Path2D(java.awt.geom.Path2D) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) FloatBuffer(java.nio.FloatBuffer) 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)

Example 90 with Vector3

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

the class Wall method drawVerticalEdges.

private void drawVerticalEdges(final double size) {
    columns.setDefaultColor(getColor());
    final FloatBuffer vertexBuffer = columns.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = columns.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final ReadOnlyVector3 o = getAbsPoint(0);
    final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
    final Vector3 dir = new Vector3(u).normalizeLocal().multiplyLocal(size);
    Util.addPointToQuad(normal, o, getAbsPoint(1), dir, vertexBuffer, normalBuffer);
    Util.addPointToQuad(normal, getAbsPoint(2), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    columns.getMeshData().updateVertexCount();
    columns.updateModelBound();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Aggregations

Vector3 (com.ardor3d.math.Vector3)284 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)258 CullHint (com.ardor3d.scenegraph.hint.CullHint)106 FloatBuffer (java.nio.FloatBuffer)69 TPoint (org.poly2tri.triangulation.point.TPoint)41 Point (org.poly2tri.geometry.primitives.Point)35 ArrayList (java.util.ArrayList)34 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)32 Matrix3 (com.ardor3d.math.Matrix3)30 Mesh (com.ardor3d.scenegraph.Mesh)25 Spatial (com.ardor3d.scenegraph.Spatial)24 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)22 Foundation (org.concord.energy3d.model.Foundation)22 Node (com.ardor3d.scenegraph.Node)20 HousePart (org.concord.energy3d.model.HousePart)20 ArdorVector3Point (org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)20 Ray3 (com.ardor3d.math.Ray3)15 PickResults (com.ardor3d.intersection.PickResults)13 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)13 Vector2 (com.ardor3d.math.Vector2)12