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;
}
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);
}
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;
}
Aggregations