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