Search in sources :

Example 1 with CanvasRenderer

use of com.ardor3d.framework.CanvasRenderer 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);
        }
    }
}
Also used : Wall(org.concord.energy3d.model.Wall) Spatial(com.ardor3d.scenegraph.Spatial) CanvasRenderer(com.ardor3d.framework.CanvasRenderer) ArrayList(java.util.ArrayList) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) CullHint(com.ardor3d.scenegraph.hint.CullHint) Matrix3(com.ardor3d.math.Matrix3)

Aggregations

CanvasRenderer (com.ardor3d.framework.CanvasRenderer)1 Matrix3 (com.ardor3d.math.Matrix3)1 Spatial (com.ardor3d.scenegraph.Spatial)1 CullHint (com.ardor3d.scenegraph.hint.CullHint)1 ArrayList (java.util.ArrayList)1 Foundation (org.concord.energy3d.model.Foundation)1 HousePart (org.concord.energy3d.model.HousePart)1 Wall (org.concord.energy3d.model.Wall)1