use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class PrintController method update.
@Override
public void update(final ReadOnlyTimer globalTimer) {
if (isPrintPreview) {
rotate();
}
if (isFinished()) {
return;
}
final Spatial originalHouseRoot = Scene.getOriginalHouseRoot();
if (init) {
init = false;
finish = false;
if (!isPrintPreview) {
Scene.getRoot().detachChild(pagesRoot);
pagesRoot.detachAllChildren();
for (final HousePart part : printParts) {
if (part instanceof Wall) {
((Wall) part).setBackMeshesVisible(true);
}
}
for (final HousePart part : printParts) {
part.hideLabels();
part.getOriginal().hideLabels();
}
} else {
printParts = new ArrayList<HousePart>(Scene.getInstance().getParts().size());
final boolean orgSolarHeatMap = SceneManager.getInstance().getSolarHeatMap();
SceneManager.getInstance().setSolarHeatMapWithoutUpdate(false);
for (final HousePart part : Scene.getInstance().getParts()) {
if (part.isPrintable()) {
final HousePart printPart = (HousePart) ObjectCloner.deepCopy(part);
printParts.add(printPart);
Scene.getRoot().attachChild(printPart.getRoot());
printPart.setOriginal(part);
printPart.flatten(1.0);
}
}
SceneManager.getInstance().setSolarHeatMapWithoutUpdate(orgSolarHeatMap);
final ArrayList<ArrayList<Spatial>> pages = new ArrayList<ArrayList<Spatial>>();
computePageDimension();
computePrintCenters(pages);
arrangePrintPages(pages);
if (!restartFlag) {
SceneManager.getInstance().updatePrintPreviewScene(true);
}
drawPrintParts(0);
}
originalHouseRoot.getSceneHints().setCullHint(CullHint.Always);
timer.reset();
}
final double viewSwitchDelay = 0.5;
if (!finish && (!isPrintPreview || timer.getTimeInSeconds() > viewSwitchDelay)) {
final double t = timer.getTimeInSeconds() - (isPrintPreview ? viewSwitchDelay : 0);
drawPrintParts(isPrintPreview ? t : 1 - t);
finish = t > 1;
if (finish) {
timer.reset();
}
}
if (finish) {
if (isPrintPreview) {
Scene.getRoot().attachChild(pagesRoot);
}
if (isPrintPreview && restartFlag) {
restartFlag = false;
}
// (time - startTime) > 1.0;
final boolean doTheEndAnimation = timer.getTimeInSeconds() > viewSwitchDelay;
if (!isPrintPreview && doTheEndAnimation) {
originalHouseRoot.setRotation(new Matrix3().fromAngles(0, 0, 0));
angle = 0;
for (final HousePart housePart : printParts) {
Scene.getRoot().detachChild(housePart.getRoot());
}
printParts = null;
if (!isPrintPreview && restartFlag) {
/* to force redraw when animated back to normal scene */
// redraw does not stretch the walls of print parts the roof. there is also no need for redraw since nothing has changed
Scene.getInstance().redrawAllNow();
setPrintPreview(true);
return;
}
originalHouseRoot.setScale(1);
originalHouseRoot.setTranslation(0, 0, 0);
originalHouseRoot.updateGeometricState(timer.getTimePerFrame(), true);
final CanvasRenderer renderer = SceneManager.getInstance().getCanvas().getCanvasRenderer();
renderer.makeCurrentContext();
renderer.getRenderer().setBackgroundColor(ColorRGBA.BLACK);
renderer.releaseCurrentContext();
SceneManager.getInstance().setShading(shadingSelected);
SceneManager.getInstance().setShadow(shadowSelected);
Heliodon.getInstance().setVisible(heliodonSelected);
SceneManager.getInstance().updatePrintPreviewScene(false);
if (!doTheEndAnimation) {
// to avoid concurrency exception
setFinished(true);
}
}
if (printParts != null) {
for (final HousePart part : printParts) {
if (part instanceof Foundation) {
part.getRoot().getSceneHints().setCullHint(isPrintPreview ? CullHint.Always : CullHint.Inherit);
}
}
}
if (isPrintPreview && printParts != null) {
for (final HousePart part : printParts) {
if (part instanceof Wall) {
((Wall) part).setBackMeshesVisible(false);
}
}
}
if (isPrintPreview || doTheEndAnimation) {
originalHouseRoot.getSceneHints().setCullHint(CullHint.Inherit);
if (isPrintPreview && printParts != null) {
int printSequence = 0;
for (final HousePart part : printParts) {
part.getOriginal().drawLabels(printSequence);
printSequence = part.drawLabels(printSequence);
}
SceneManager.getInstance().refresh();
}
setFinished(true);
}
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class PrintController method computePrintCenters.
private void computePrintCenters(final ArrayList<ArrayList<Spatial>> pages) {
for (final HousePart printPart : printParts) {
if (printPart.isPrintable()) {
printPart.getRoot().updateWorldTransform(true);
printPart.getRoot().updateWorldBound(true);
if (printPart instanceof Roof) {
final Roof roof = (Roof) printPart;
for (final Spatial roofPart : roof.getRoofPartsRoot().getChildren()) {
if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
final Mesh mesh = (Mesh) ((Node) roofPart).getChild(0);
roof.setPrintVertical(roofPart, decideVertical(mesh));
computePrintCenterOf(mesh, pages);
}
}
} else {
final Mesh mesh = printPart.getMesh();
printPart.setPrintVertical(decideVertical(mesh));
computePrintCenterOf(mesh, pages);
}
}
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class HeatLoad method computeEnergyToday.
public void computeEnergyToday(final Calendar today) {
today.set(Calendar.SECOND, 0);
today.set(Calendar.MINUTE, 0);
today.set(Calendar.HOUR_OF_DAY, 0);
if (EnergyPanel.getInstance().getCityComboBox().getSelectedItem().equals("")) {
return;
}
final int timeStep = Scene.getInstance().getTimeStep();
final double[] outsideTemperatureRange = Weather.computeOutsideTemperature(today, (String) EnergyPanel.getInstance().getCityComboBox().getSelectedItem());
// System.out.println(today.get(Calendar.DAY_OF_YEAR) + ", " + outsideTemperatureRange[0] + ", " + outsideTemperatureRange[1]);
int iMinute = 0;
for (int minute = 0; minute < SolarRadiation.MINUTES_OF_DAY; minute += timeStep) {
iMinute = minute / timeStep;
final double outsideTemperature = Weather.getInstance().getOutsideTemperatureAtMinute(outsideTemperatureRange[1], outsideTemperatureRange[0], minute);
final double groundTemperature = Scene.getInstance().getGround().getTemperatureMinuteOfDay(today.get(Calendar.DAY_OF_YEAR), minute, 0.5 * (outsideTemperatureRange[1] - outsideTemperatureRange[0]));
for (final HousePart part : Scene.getInstance().getParts()) {
if (part instanceof Human || part instanceof Tree || part instanceof Floor || (part instanceof SolarCollector && !(part instanceof Sensor))) {
continue;
}
final double insideTemperature = (part instanceof Foundation ? (Foundation) part : part.getTopContainer()).getThermostat().getTemperature(today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY, minute / 60);
final float absorption = part instanceof Window ? 0 : 1 - part.getAlbedo();
if (part instanceof Roof) {
// need to compute piece by piece for a roof because sun affects outside temperature of roof part
final Roof roof = (Roof) part;
for (final Spatial child : roof.getRoofPartsRoot().getChildren()) {
if (child.getSceneHints().getCullHint() != CullHint.Always) {
final Mesh mesh = (Mesh) ((Node) child).getChild(6);
final double[] solarPotential = SolarRadiation.getInstance().getSolarPotential(mesh);
final double solarHeat = solarPotential != null ? solarPotential[iMinute] * absorption / roof.getVolumetricHeatCapacity() : 0;
final double deltaT = insideTemperature - (outsideTemperature + solarHeat);
if (part.isDrawCompleted()) {
final double uValue = getUValue(part);
if (Util.isZero(uValue)) {
continue;
}
double heatloss = roof.getAreaWithoutOverhang(mesh) * uValue * deltaT / 1000.0 / 60 * timeStep;
// if the lowest outside temperature is high enough, there is no need to turn on the heater hence no heat loss
if (heatloss > 0 && outsideTemperatureRange[0] >= LOWEST_TEMPERATURE_OF_WARM_DAY) {
heatloss = 0;
}
roof.getHeatLoss()[iMinute] += heatloss;
final double[] heatLossArray = SolarRadiation.getInstance().getHeatLoss(mesh);
if (heatLossArray != null) {
heatLossArray[iMinute] += heatloss;
}
}
}
}
} else if (part instanceof Foundation) {
final Foundation foundation = (Foundation) part;
final double deltaT = insideTemperature - groundTemperature;
if (foundation.isDrawCompleted()) {
final double uValue = getUValue(part);
if (Util.isZero(uValue)) {
continue;
}
final Building building = new Building(foundation);
double area;
if (building.isWallComplete()) {
building.calculate();
area = building.getArea();
} else {
area = foundation.getArea();
}
final double heatloss = area * uValue * deltaT / 1000.0 / 60 * timeStep;
// if (iMinute % 4 == 0) System.out.println((int) (iMinute / 4) + "=" + outsideTemperature + ", " + groundTemperature + ", " + deltaT + ", " + heatloss);
foundation.getHeatLoss()[iMinute] += heatloss;
}
} else {
double deltaT = insideTemperature - outsideTemperature;
if (part instanceof Thermal) {
// direct solar heating raises the outside temperature
deltaT -= part.getSolarPotential()[iMinute] * absorption / ((Thermal) part).getVolumetricHeatCapacity();
}
if (part.isDrawCompleted()) {
final double uValue = getUValue(part);
if (Util.isZero(uValue)) {
continue;
}
double heatloss = part.getArea() * uValue * deltaT / 1000.0 / 60 * timeStep;
// if outside is warm enough, there is no need to turn on the heater hence no heat loss
if (heatloss > 0 && outsideTemperatureRange[0] >= LOWEST_TEMPERATURE_OF_WARM_DAY) {
heatloss = 0;
}
part.getHeatLoss()[iMinute] += heatloss;
}
}
}
}
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class Util method getMesh.
/**
* return the mesh by its mesh index, which is NOT the index of the children array of the node, but the original index of the mesh when the node is created
*/
public static Mesh getMesh(final Node n, final int meshIndex) {
for (final Spatial s : n.getChildren()) {
final Mesh m = (Mesh) s;
final UserData u = (UserData) m.getUserData();
if (u.getMeshIndex() == meshIndex) {
return m;
}
}
return null;
}
use of com.ardor3d.scenegraph.Spatial in project energy3d by concord-consortium.
the class Util method getOrientedBoundingBox.
public static OrientedBoundingBox getOrientedBoundingBox(final Node node) {
int count = 0;
for (final Spatial s : node.getChildren()) {
if (s instanceof Mesh) {
final Mesh m = (Mesh) s;
count += m.getMeshData().getVertexBuffer().limit();
}
}
final FloatBuffer newbuf = BufferUtils.createFloatBuffer(count);
for (final Spatial s : node.getChildren()) {
if (s instanceof Mesh) {
final Mesh m = (Mesh) s;
final FloatBuffer buf = m.getMeshData().getVertexBuffer();
buf.rewind();
while (buf.hasRemaining()) {
final Vector3 v = new Vector3(buf.get(), buf.get(), buf.get());
m.getWorldTransform().applyForward(v);
newbuf.put(v.getXf()).put(v.getYf()).put(v.getZf());
}
}
}
final OrientedBoundingBox boundingBox = new OrientedBoundingBox();
boundingBox.computeFromPoints(newbuf);
boundingBox.transform(node.getWorldTransform().invert(null), node.getWorldBound());
// node.updateWorldBound(true);
return boundingBox;
}
Aggregations