Search in sources :

Example 71 with Vector3

use of com.ardor3d.math.Vector3 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 72 with Vector3

use of com.ardor3d.math.Vector3 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 73 with Vector3

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

the class Roof method stretchToRoof.

private void stretchToRoof(final ArrayList<ReadOnlyVector3> result, final Mesh roof, final ReadOnlyVector3 p1, final ReadOnlyVector3 p2, final double z) {
    final Vector3 dir = p2.subtract(p1, null).multiplyLocal(1, 1, 0);
    final double length = dir.length();
    dir.normalizeLocal();
    Vector3 direction = null;
    ReadOnlyVector3 previousStretchPoint = null;
    boolean firstInsert = false;
    final boolean isSingleMesh = isSingleFlatMesh();
    final double minDistance = STRETCH_ROOF_STEP * 3;
    final Vector3 p = new Vector3();
    for (double d = STRETCH_ROOF_STEP; d < length; d += STRETCH_ROOF_STEP) {
        dir.multiply(d, p).addLocal(p1);
        final ReadOnlyVector3 currentStretchPoint;
        if (isSingleMesh) {
            p.setZ(z);
            currentStretchPoint = p.clone();
        } else {
            currentStretchPoint = findRoofIntersection(roof, p);
        }
        if (currentStretchPoint != null && !firstInsert) {
            result.add(currentStretchPoint);
            firstInsert = true;
        } else if (currentStretchPoint == null) {
            if (previousStretchPoint != null) {
                result.add(previousStretchPoint);
            }
            direction = null;
            firstInsert = false;
        } else {
            final Vector3 currentDirection = currentStretchPoint.subtract(previousStretchPoint, null).normalizeLocal();
            if (direction == null) {
                direction = currentDirection;
            } else if (direction.dot(currentDirection) < 1.0 - MathUtils.ZERO_TOLERANCE) {
                result.add(currentStretchPoint);
                result.add(currentStretchPoint);
                direction = null;
            }
        }
        previousStretchPoint = currentStretchPoint;
    }
    if (previousStretchPoint != null) {
        if (previousStretchPoint.distance(result.get(result.size() - 1)) > minDistance) {
            result.add(previousStretchPoint);
        } else {
            result.remove(result.size() - 1);
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 74 with Vector3

use of com.ardor3d.math.Vector3 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 75 with Vector3

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

the class Roof method ensureEditPointsInside.

private void ensureEditPointsInside() {
    for (int i = 1; i < points.size(); i++) {
        final Vector3 editPoint = getAbsPoint(i);
        final Vector2 p = new Vector2(editPoint.getX(), editPoint.getY());
        if (!insideWallsPolygon(editPoint)) {
            double closestDistance = Double.MAX_VALUE;
            int closestIndex = 0;
            for (int j = 0; j < wallUpperPoints.size(); j++) {
                final Vector2 l1 = new Vector2(wallUpperPoints.get(j).getX(), wallUpperPoints.get(j).getY());
                final Vector2 l2 = new Vector2(wallUpperPoints.get((j + 1) % wallUpperPoints.size()).getX(), wallUpperPoints.get((j + 1) % wallUpperPoints.size()).getY());
                final double distance = p.distance(l1) + p.distance(l2);
                if (distance < closestDistance) {
                    closestDistance = distance;
                    closestIndex = j;
                }
            }
            final List<ReadOnlyVector3> wallPoints = new ArrayList<ReadOnlyVector3>(2);
            wallPoints.add(wallUpperPoints.get(closestIndex));
            wallPoints.add(wallUpperPoints.get((closestIndex + 1) % wallUpperPoints.size()));
            final ReadOnlyVector2 p2D = Util.snapToPolygon(editPoint, wallPoints, null);
            editPoint.setX(p2D.getX());
            editPoint.setY(p2D.getY());
            if (closestIndex < walls.size()) {
                editPoint.subtractLocal(walls.get(closestIndex).getNormal().multiply(0.01, null));
            }
            points.get(i).set(toRelative(editPoint));
        }
    }
}
Also used : ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) 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)

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