use of com.ardor3d.scenegraph.Spatial 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.scenegraph.Spatial in project energy3d by concord-consortium.
the class Roof method computeArea.
@Override
protected void computeArea() {
this.area = 0;
if (container == null) {
return;
}
if (areaByPartWithOverhang == null) {
areaByPartWithOverhang = new HashMap<Mesh, Double>();
} else {
areaByPartWithOverhang.clear();
}
if (areaByPartWithoutOverhang == null) {
areaByPartWithoutOverhang = new HashMap<Mesh, Double>();
} else {
areaByPartWithoutOverhang.clear();
}
for (final Spatial roofPart : roofPartsRoot.getChildren()) {
if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
final Node roofPartNode = (Node) roofPart;
final Mesh roofPartMesh = (Mesh) roofPartNode.getChild(REAL_MESH_INDEX);
areaByPartWithOverhang.put(roofPartMesh, Util.computeArea(roofPartMesh));
final FloatBuffer vertexBuffer = roofPartMesh.getMeshData().getVertexBuffer();
final Vector3 p = new Vector3();
if (overhangLength <= OVERHANG_MIN) {
final double a = Util.computeArea(roofPartMesh);
areaByPartWithoutOverhang.put(roofPartMesh, a);
area += a;
} else {
final List<ReadOnlyVector3> result = computeDashPoints(roofPartMesh);
if (result.isEmpty()) {
vertexBuffer.rewind();
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
final double a;
if (Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
a = Util.computeArea(roofPartMesh);
} else {
a = 0;
}
areaByPartWithoutOverhang.put(roofPartMesh, a);
area += a;
} else {
// if (roofPartsRoot.getNumberOfChildren() > 1) {
double highPointZ = Double.NEGATIVE_INFINITY;
vertexBuffer.rewind();
while (vertexBuffer.hasRemaining()) {
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
if (p.getZ() > highPointZ) {
highPointZ = p.getZ();
}
}
final List<ReadOnlyVector3> highPoints = new ArrayList<ReadOnlyVector3>();
vertexBuffer.rewind();
while (vertexBuffer.hasRemaining()) {
p.set(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
if (p.getZ() >= highPointZ - MathUtils.ZERO_TOLERANCE && Util.insidePolygon(p, wallUpperPointsWithoutOverhang)) {
highPoints.add(new Vector3(p));
}
}
if (highPoints.size() == 1) {
result.add(highPoints.get(0));
} else {
final ReadOnlyVector3 lastPoint = result.get(result.size() - 1);
while (!highPoints.isEmpty()) {
double shortestDistance = Double.MAX_VALUE;
ReadOnlyVector3 nearestPoint = null;
for (final ReadOnlyVector3 hp : highPoints) {
final double distance = hp.distance(lastPoint);
if (distance < shortestDistance) {
shortestDistance = distance;
nearestPoint = hp;
}
}
result.add(nearestPoint);
highPoints.remove(nearestPoint);
}
}
result.add(result.get(0));
final double annotationScale = Scene.getInstance().getAnnotationScale();
final double a = Util.area3D_Polygon(result, (ReadOnlyVector3) roofPart.getUserData()) * annotationScale * annotationScale;
areaByPartWithoutOverhang.put(roofPartMesh, a);
this.area += a;
}
}
}
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class PrintController method arrangePrintPages.
private void arrangePrintPages(final ArrayList<ArrayList<Spatial>> pages) {
final double ratio = (double) Camera.getCurrentCamera().getWidth() / Camera.getCurrentCamera().getHeight();
cols = (int) Math.round(Math.sqrt(pages.size() + 4) * ratio);
if (cols % 2 == 0) {
cols++;
}
rows = (int) Math.ceil((pages.size() + 4) / cols);
int pageNum = 0;
printCenters.clear();
for (final ArrayList<Spatial> page : pages) {
final Vector3 upperLeftCorner = new Vector3();
double x, z;
final BoundingBox originalHouseBoundingBox = (BoundingBox) Scene.getOriginalHouseRoot().getWorldBound().asType(Type.AABB);
final ReadOnlyVector3 originalHouseCenter = Scene.getOriginalHouseRoot().getWorldBound().getCenter();
final double minXDistance = originalHouseBoundingBox.getXExtent() + pageWidth / 2.0;
final double minYDistance = originalHouseBoundingBox.getZExtent();
do {
x = (pageNum % cols - cols / 2) * (pageWidth + SPACE_BETWEEN_PAGES) + originalHouseCenter.getX();
z = (pageNum / cols) * (pageHeight + SPACE_BETWEEN_PAGES);
upperLeftCorner.setX(x - pageWidth / 2.0);
upperLeftCorner.setZ(z + pageHeight);
pageNum++;
} while (Math.abs(x - originalHouseCenter.getX()) < minXDistance && Math.abs(z - originalHouseCenter.getZ()) < minYDistance);
printCenters.add(upperLeftCorner);
for (final Spatial printSpatial : page) {
((UserData) printSpatial.getUserData()).getPrintCenter().addLocal(upperLeftCorner.multiply(1, 0, 1, null));
}
final Box box = new Box("Page Boundary");
final double y = Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY();
box.setData(upperLeftCorner.add(0, y + 1, 0, null), upperLeftCorner.add(pageWidth, y + 1.2, -pageHeight, null));
box.setModelBound(new BoundingBox());
box.updateModelBound();
pagesRoot.attachChild(box);
final BMText footNote = Annotation.makeNewLabel(1);
final String url = Scene.getURL() != null ? Scene.getURL().getFile().substring(Scene.getURL().getFile().lastIndexOf('/') + 1, Scene.getURL().getFile().length()) + " -" : "";
footNote.setText(url.replaceAll("%20", " ") + " Page " + printCenters.size() + " / " + pages.size() + " - http://energy.concord.org/");
footNote.setFontScale(0.5);
footNote.setAlign(Align.North);
footNote.setTranslation(upperLeftCorner.add(pageWidth / 2.0, 0.0, -pageBottom - spaceBetweenParts / 2.0, null));
pagesRoot.attachChild(footNote);
}
pagesRoot.updateGeometricState(0);
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class PrintController method computePrintCenterOf.
private void computePrintCenterOf(final Spatial printPart, final ArrayList<ArrayList<Spatial>> pages) {
boolean isFitted = false;
for (int pageNum = 0; pageNum < pages.size() && !isFitted; pageNum++) {
isFitted = fitInPage(printPart, pages.get(pageNum));
}
if (!isFitted) {
printPart.updateWorldBound(true);
final OrientedBoundingBox bounds = (OrientedBoundingBox) printPart.getWorldBound().asType(Type.OBB);
((UserData) printPart.getUserData()).setPrintCenter(new Vector3(bounds.getExtent().getX() + pageLeft, Scene.getOriginalHouseRoot().getWorldBound().getCenter().getY(), -bounds.getExtent().getZ() - pageTop));
final ArrayList<Spatial> page = new ArrayList<Spatial>();
page.add(printPart);
pages.add(page);
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class NodeWorker method reach.
static void reach(final Node node) {
final List<Spatial> collidables = new ArrayList<Spatial>();
collidables.addAll(node.getChildren());
collidables.add(SceneManager.getInstance().getLand());
int count = 0;
for (final Spatial s : node.getChildren()) {
reach((Mesh) s, collidables);
if (count % 20 == 0) {
EnergyPanel.getInstance().progress((int) Math.round(100.0 * count / node.getNumberOfChildren()));
}
count++;
}
EnergyPanel.getInstance().progress(0);
}
Aggregations