Search in sources :

Example 16 with PickedHousePart

use of org.concord.energy3d.model.PickedHousePart in project energy3d by concord-consortium.

the class SelectUtil method selectHousePart.

public static PickedHousePart selectHousePart(final int x, final int y, final boolean edit) {
    final PickedHousePart pickedHousePart = pickPart(x, y);
    UserData data = null;
    if (pickedHousePart != null) {
        data = pickedHousePart.getUserData();
    }
    // set the color of edit point that the mouse currently hovers on to red
    if (data == null || !data.isEditPoint() || currentEditPointMesh != data.getHousePart().getEditPointShape(data.getEditPointIndex())) {
        if (currentEditPointMesh != null) {
            currentEditPointMesh.setDefaultColor(currentEditPointOriginalColor);
            currentEditPointMesh = null;
        }
    }
    if (data != null && data.isEditPoint() && currentEditPointMesh != data.getHousePart().getEditPointShape(data.getEditPointIndex())) {
        final Foundation foundation = data.getHousePart() instanceof Foundation ? (Foundation) data.getHousePart() : data.getHousePart().getTopContainer();
        if (foundation != null && !foundation.getLockEdit()) {
            currentEditPointMesh = data.getHousePart().getEditPointShape(data.getEditPointIndex());
            currentEditPointOriginalColor.set(currentEditPointMesh.getDefaultColor());
            currentEditPointMesh.setDefaultColor(ColorRGBA.RED);
        }
    }
    if (data == null) {
        Blinker.getInstance().setTarget(null);
    } else if (edit && data.isEditPoint()) {
        int pointIndex = data.getEditPointIndex();
        if (SceneManager.getInstance().isTopView() && data.getHousePart() instanceof Wall) {
            pointIndex -= 1;
        }
        data.getHousePart().setEditPoint(pointIndex);
    } else {
        if (data.getHousePart().getOriginal() == null) {
            Blinker.getInstance().setTarget(null);
        } else if (data.getHousePart() instanceof Roof) {
            Blinker.getInstance().setTarget(((Roof) data.getHousePart().getOriginal()).getRoofPartsRoot().getChild(data.getEditPointIndex() - 0));
        } else {
            Blinker.getInstance().setTarget(data.getHousePart().getOriginal().getRoot());
        }
    }
    return pickedHousePart;
}
Also used : Roof(org.concord.energy3d.model.Roof) Wall(org.concord.energy3d.model.Wall) UserData(org.concord.energy3d.model.UserData) Foundation(org.concord.energy3d.model.Foundation) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Example 17 with PickedHousePart

use of org.concord.energy3d.model.PickedHousePart in project energy3d by concord-consortium.

the class SelectUtil method pickPart.

public static PickedHousePart pickPart(final int x, final int y) {
    pickResults.clear();
    final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
    for (final HousePart housePart : Scene.getInstance().getParts()) {
        PickingUtil.findPick(housePart.getCollisionSpatial(), pickRay, pickResults, false);
        PickingUtil.findPick(housePart.getEditPointsRoot(), pickRay, pickResults, false);
        if (housePart instanceof Foundation) {
            final Foundation foundation = (Foundation) housePart;
            if (foundation.getPolygon().isVisible()) {
                PickingUtil.findPick(foundation.getPolygon().getEditPointsRoot(), pickRay, pickResults, false);
            }
        }
    }
    return getPickResult(pickRay);
}
Also used : Vector2(com.ardor3d.math.Vector2) Foundation(org.concord.energy3d.model.Foundation) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) Ray3(com.ardor3d.math.Ray3)

Example 18 with PickedHousePart

use of org.concord.energy3d.model.PickedHousePart in project energy3d by concord-consortium.

the class SelectUtil method getPickResult.

private static PickedHousePart getPickResult(final Ray3 pickRay) {
    PickedHousePart pickedHousePart = null;
    double polyDist = Double.MAX_VALUE;
    double pointDist = Double.MAX_VALUE;
    int objCounter = 0;
    HousePart prevHousePart = null;
    final long pickLayer = SelectUtil.pickLayer == -1 ? -1 : SelectUtil.pickLayer % Math.max(1, pickResults.getNumber());
    for (int i = 0; i < pickResults.getNumber(); i++) {
        final PickData pick = pickResults.getPickData(i);
        if (pick.getIntersectionRecord().getNumberOfIntersections() == 0) {
            continue;
        }
        final Object obj = ((Mesh) pick.getTarget()).getUserData();
        UserData userData = null;
        if (obj instanceof UserData) {
            // FIXME: Note that userData can be null if the pick is the land
            userData = (UserData) obj;
            if (userData.getHousePart() != prevHousePart) {
                objCounter++;
                prevHousePart = userData.getHousePart();
            }
        } else if (pickLayer != -1) {
            continue;
        }
        if (pickLayer != -1 && objCounter - 1 != pickLayer) {
            continue;
        }
        final Vector3 intersectionPoint = pick.getIntersectionRecord().getIntersectionPoint(0);
        final PickedHousePart picked_i = new PickedHousePart(userData, intersectionPoint, pick.getIntersectionRecord().getIntersectionNormal(0));
        double polyDist_i = pick.getIntersectionRecord().getClosestDistance();
        if (userData != null && userData.getHousePart() instanceof Window) {
            // give more priority to window (especially skylight)
            polyDist_i -= 0.2;
        }
        double pointDist_i = Double.MAX_VALUE;
        if (userData != null && polyDist_i - polyDist < 0.1) {
            for (int j = 0; j < userData.getHousePart().getPoints().size(); j++) {
                final Vector3 p = userData.getHousePart().getAbsPoint(j);
                pointDist_i = p.distance(intersectionPoint);
                double adjust = 0;
                if (userData.getHousePart().isFirstPointInserted()) {
                    // to avoid IndexOutOfBoundsException: Index: 2, Size: 2
                    if (userData.getHousePart().getNormal() != null) {
                        adjust -= Math.abs(userData.getHousePart().getNormal().negate(null).dot(pickRay.getDirection()) / 10.0);
                    }
                }
                if (userData.getHousePart() == SceneManager.getInstance().getSelectedPart()) {
                    // give more priority because the object is selected
                    adjust -= 0.1;
                }
                if (userData.isEditPoint()) {
                    // give more priority because this is an edit point
                    adjust -= 0.1;
                }
                if (userData.isEditPoint() && userData.getHousePart() instanceof Foundation && ((Foundation) userData.getHousePart()).isResizeHouseMode()) {
                    adjust -= 0.1;
                }
                pointDist_i += adjust;
                if (pointDist_i < pointDist && (userData.getEditPointIndex() != -1 || pickedHousePart == null || pickedHousePart.getUserData() == null || pickedHousePart.getUserData().getEditPointIndex() == -1)) {
                    pickedHousePart = picked_i;
                    polyDist = polyDist_i;
                    pointDist = pointDist_i;
                }
            }
        }
        if (pickedHousePart == null || polyDist_i < polyDist) {
            pickedHousePart = picked_i;
            polyDist = polyDist_i;
            pointDist = pointDist_i;
        }
    }
    return pickedHousePart;
}
Also used : Window(org.concord.energy3d.model.Window) UserData(org.concord.energy3d.model.UserData) Mesh(com.ardor3d.scenegraph.Mesh) Vector3(com.ardor3d.math.Vector3) Foundation(org.concord.energy3d.model.Foundation) PickData(com.ardor3d.intersection.PickData) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Aggregations

PickedHousePart (org.concord.energy3d.model.PickedHousePart)18 HousePart (org.concord.energy3d.model.HousePart)12 Foundation (org.concord.energy3d.model.Foundation)8 Ray3 (com.ardor3d.math.Ray3)5 Vector2 (com.ardor3d.math.Vector2)5 UserData (org.concord.energy3d.model.UserData)5 Vector3 (com.ardor3d.math.Vector3)4 Window (org.concord.energy3d.model.Window)4 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)3 Roof (org.concord.energy3d.model.Roof)3 MouseState (com.ardor3d.input.MouseState)2 PickData (com.ardor3d.intersection.PickData)2 Mesh (com.ardor3d.scenegraph.Mesh)2 CullHint (com.ardor3d.scenegraph.hint.CullHint)2 Component (java.awt.Component)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 CustomRoof (org.concord.energy3d.model.CustomRoof)2 GambrelRoof (org.concord.energy3d.model.GambrelRoof)2 HipRoof (org.concord.energy3d.model.HipRoof)2