Search in sources :

Example 16 with Node

use of com.ardor3d.scenegraph.Node in project energy3d by concord-consortium.

the class Roof method drawDashLines.

private void drawDashLines() {
    if (container == null) {
        return;
    }
    if (lockEdit) {
        for (final Spatial roofPart : roofPartsRoot.getChildren()) {
            if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                final Node roofPartNode = (Node) roofPart;
                final Mesh dashLinesMesh = (Mesh) roofPartNode.getChild(5);
                dashLinesMesh.setVisible(false);
            }
        }
    } else {
        for (final Spatial roofPart : roofPartsRoot.getChildren()) {
            if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                final Node roofPartNode = (Node) roofPart;
                final Mesh roofPartMesh = (Mesh) roofPartNode.getChild(0);
                final Mesh dashLinesMesh = (Mesh) roofPartNode.getChild(5);
                final List<ReadOnlyVector3> result = computeDashPoints(roofPartMesh);
                if (result.isEmpty()) {
                    dashLinesMesh.setVisible(false);
                } else {
                    dashLinesMesh.setVisible(true);
                    FloatBuffer vertexBuffer = dashLinesMesh.getMeshData().getVertexBuffer();
                    if (vertexBuffer == null || vertexBuffer.capacity() < result.size() * 3) {
                        vertexBuffer = BufferUtils.createVector3Buffer(result.size());
                        dashLinesMesh.getMeshData().setVertexBuffer(vertexBuffer);
                    }
                    vertexBuffer.limit(result.size() * 3);
                    vertexBuffer.rewind();
                    for (final ReadOnlyVector3 p : result) {
                        vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
                    }
                    dashLinesMesh.getMeshData().updateVertexCount();
                    dashLinesMesh.updateModelBound();
                }
            }
        }
    }
    updateDashLinesColor();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer)

Example 17 with Node

use of com.ardor3d.scenegraph.Node in project energy3d by concord-consortium.

the class Roof method getArea.

// return the area WITH overhang
@Override
public double getArea() {
    if (areaByPartWithOverhang == null) {
        return 0;
    }
    double a = 0;
    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);
            final Double d = areaByPartWithOverhang.get(roofPartMesh);
            if (d != null) {
                a += d;
            }
        }
    }
    return a;
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh)

Example 18 with Node

use of com.ardor3d.scenegraph.Node 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;
                }
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 19 with Node

use of com.ardor3d.scenegraph.Node in project energy3d by concord-consortium.

the class ParabolicTrough method init.

@Override
protected void init() {
    super.init();
    if (Util.isZero(copyLayoutGap)) {
        // FIXME: Why is a transient member evaluated to zero?
        copyLayoutGap = 0.2;
    }
    if (Util.isZero(moduleLength)) {
        moduleLength = 3;
    }
    if (Util.isZero(troughLength)) {
        troughLength = 2 * moduleLength;
    }
    if (Util.isZero(apertureWidth)) {
        apertureWidth = 2;
    }
    if (Util.isZero(semilatusRectum)) {
        semilatusRectum = 2;
    }
    if (Util.isZero(reflectance)) {
        reflectance = 0.9;
    }
    if (Util.isZero(absorptance)) {
        absorptance = 0.95;
    }
    if (Util.isZero(opticalEfficiency)) {
        opticalEfficiency = 0.7;
    }
    if (Util.isZero(thermalEfficiency)) {
        thermalEfficiency = 0.3;
    }
    if (Util.isZero(nSectionParabola)) {
        nSectionParabola = 16;
    }
    if (Util.isZero(nSectionAxis)) {
        nSectionAxis = 32;
    }
    detailed = Scene.getInstance().countParts(this.getClass()) < 50;
    mesh = new ParabolicCylinder("Parabolic Cylinder", nSectionParabola, semilatusRectum, apertureWidth, troughLength);
    mesh.setDefaultColor(SKY_BLUE);
    mesh.setModelBound(new OrientedBoundingBox());
    mesh.setUserData(new UserData(this));
    CullState cullState = new CullState();
    cullState.setCullFace(Face.Back);
    mesh.setRenderState(cullState);
    root.attachChild(mesh);
    reflector = (ParabolicCylinder) mesh;
    reflectorBack = mesh.makeCopy(true);
    reflectorBack.clearRenderState(StateType.Texture);
    reflectorBack.setDefaultColor(ColorRGBA.WHITE);
    cullState = new CullState();
    cullState.setCullFace(Face.None);
    reflectorBack.setRenderState(cullState);
    root.attachChild(reflectorBack);
    final ColorRGBA tubeColor = new ColorRGBA(0.8f, 0.8f, 0.8f, 0.8f);
    absorber = new Cylinder("Absorber Tube", 2, detailed ? 10 : 4, 0.5, 0, true);
    final BlendState blend = new BlendState();
    blend.setBlendEnabled(true);
    absorber.setRenderState(blend);
    absorber.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    absorber.setDefaultColor(tubeColor);
    absorber.setModelBound(new OrientedBoundingBox());
    root.attachChild(absorber);
    absorberEnd1 = new Cylinder("Absorber End Tube 1", 2, detailed ? 10 : 4, 0.5, 0, true);
    absorberEnd1.setRenderState(blend);
    absorberEnd1.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    absorberEnd1.setDefaultColor(tubeColor);
    absorberEnd1.setModelBound(new OrientedBoundingBox());
    root.attachChild(absorberEnd1);
    absorberEnd2 = new Cylinder("Absorber End Tube 2", 2, detailed ? 10 : 4, 0.5, 0, true);
    absorberEnd2.setRenderState(blend);
    absorberEnd2.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    absorberEnd2.setDefaultColor(tubeColor);
    absorberEnd2.setModelBound(new OrientedBoundingBox());
    root.attachChild(absorberEnd2);
    if (detailed) {
        absorberCore = new Cylinder("Absorber Tube Core", 2, 4, 0.4, 0, true);
        absorberCore.setDefaultColor(ColorRGBA.BROWN);
        absorberCore.setModelBound(new OrientedBoundingBox());
        root.attachChild(absorberCore);
        absorberEnd1Core = new Cylinder("Absorber End Tube 1 Core", 2, 4, 0.4, 0, true);
        absorberEnd1Core.setDefaultColor(ColorRGBA.BROWN);
        absorberEnd1Core.setModelBound(new OrientedBoundingBox());
        root.attachChild(absorberEnd1Core);
        absorberEnd2Core = new Cylinder("Absorber End Tube 2 Core", 2, 4, 0.4, 0, true);
        absorberEnd2Core.setDefaultColor(ColorRGBA.BROWN);
        absorberEnd2Core.setModelBound(new OrientedBoundingBox());
        root.attachChild(absorberEnd2Core);
    }
    final int nModules = getNumberOfModules();
    outlines = new Line("Parabolic Trough (Outline)");
    outlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4 + 2 * (reflector.getNumberOfSamples() + 1) * (nModules + 1)));
    outlines.setDefaultColor(ColorRGBA.BLACK);
    outlines.setModelBound(new OrientedBoundingBox());
    outlines.setLineWidth(1f);
    outlines.setStipplePattern((short) 0xffff);
    Util.disablePickShadowLight(outlines);
    root.attachChild(outlines);
    steelFrame = new Line("Parabolic Trough Steel Frame");
    steelFrame.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    steelFrame.setDefaultColor(ColorRGBA.GRAY);
    steelFrame.setModelBound(new OrientedBoundingBox());
    steelFrame.setLineWidth(3);
    steelFrame.setStipplePattern((short) 0xffff);
    root.attachChild(steelFrame);
    lightBeams = new Line("Light Beams");
    lightBeams.setLineWidth(1f);
    lightBeams.setStipplePattern((short) 0xffff);
    lightBeams.setModelBound(null);
    Util.disablePickShadowLight(lightBeams);
    lightBeams.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    lightBeams.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
    root.attachChild(lightBeams);
    label = new BMText("Label", "#" + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
    Util.initHousePartLabel(label);
    label.setFontScale(0.5);
    label.setVisible(false);
    root.attachChild(label);
    modulesRoot = new Node("Modules Root");
    root.attachChild(modulesRoot);
    updateTextureAndColor();
    if (!points.isEmpty()) {
        oldTroughCenter = points.get(0).clone();
    }
    oldTroughLength = troughLength;
    oldApertureWidth = apertureWidth;
}
Also used : Line(com.ardor3d.scenegraph.Line) Cylinder(com.ardor3d.scenegraph.shape.Cylinder) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Node(com.ardor3d.scenegraph.Node) CullState(com.ardor3d.renderer.state.CullState) BMText(com.ardor3d.ui.text.BMText) BlendState(com.ardor3d.renderer.state.BlendState) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 20 with Node

use of com.ardor3d.scenegraph.Node in project energy3d by concord-consortium.

the class SolarPanel method init.

@Override
protected void init() {
    super.init();
    if (Util.isZero(panelWidth)) {
        panelWidth = 0.99;
    }
    if (Util.isZero(panelHeight)) {
        panelHeight = 1.65;
    }
    if (Util.isZero(efficiency)) {
        // make it the same as the default one in PvModuleSpecs
        efficiency = 0.1833;
    }
    if (Util.isZero(temperatureCoefficientPmax)) {
        temperatureCoefficientPmax = -0.005;
    }
    if (Util.isZero(nominalOperatingCellTemperature)) {
        nominalOperatingCellTemperature = 48;
    }
    if (Util.isZero(inverterEfficiency)) {
        inverterEfficiency = 0.95;
    }
    if (Util.isZero(baseHeight)) {
        baseHeight = 5;
    }
    if (Util.isZero(numberOfCellsInX)) {
        numberOfCellsInX = 6;
    }
    if (Util.isZero(numberOfCellsInY)) {
        numberOfCellsInY = 10;
    }
    if (pvModuleSpecs == null) {
        // backward compatibility
        pvModuleSpecs = new PvModuleSpecs("Custom");
        pvModuleSpecs.setCellEfficiency(efficiency);
        pvModuleSpecs.setWidth(panelWidth);
        pvModuleSpecs.setLength(panelHeight);
        pvModuleSpecs.setNoct(nominalOperatingCellTemperature);
        pvModuleSpecs.setPmaxTc(temperatureCoefficientPmax);
        pvModuleSpecs.setLayout(numberOfCellsInX, numberOfCellsInY);
        switch(cellType) {
            case POLYCRYSTALLINE:
                pvModuleSpecs.setCellType("Polycrystalline");
                colorOption = COLOR_OPTION_BLUE;
                break;
            case MONOCRYSTALLINE:
                pvModuleSpecs.setCellType("Monocrystalline");
                colorOption = COLOR_OPTION_BLACK;
                break;
            case THIN_FILM:
                pvModuleSpecs.setCellType("Thin Film");
                colorOption = COLOR_OPTION_BLACK;
                break;
        }
    } else {
        convertStringPropertiesToIntegerProperties();
    }
    mesh = new Mesh("SolarPanel");
    mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
    mesh.setModelBound(new OrientedBoundingBox());
    mesh.setUserData(new UserData(this));
    root.attachChild(mesh);
    surround = new Box("SolarPanel (Surround)");
    surround.setModelBound(new OrientedBoundingBox());
    final OffsetState offset = new OffsetState();
    offset.setFactor(1);
    offset.setUnits(1);
    surround.setRenderState(offset);
    root.attachChild(surround);
    outlineMesh = new Line("SolarPanel (Outline)");
    outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
    outlineMesh.setDefaultColor(ColorRGBA.BLACK);
    outlineMesh.setModelBound(new OrientedBoundingBox());
    root.attachChild(outlineMesh);
    supportFrame = new Mesh("Supporting Frame");
    supportFrame.getMeshData().setIndexMode(IndexMode.Quads);
    supportFrame.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(12));
    supportFrame.getMeshData().setNormalBuffer(BufferUtils.createVector3Buffer(12));
    supportFrame.setRenderState(offsetState);
    supportFrame.setModelBound(new BoundingBox());
    root.attachChild(supportFrame);
    sunBeam = new Line("Sun Beam");
    sunBeam.setLineWidth(1f);
    sunBeam.setStipplePattern((short) 0xffff);
    sunBeam.setModelBound(null);
    Util.disablePickShadowLight(sunBeam);
    sunBeam.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    sunBeam.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
    root.attachChild(sunBeam);
    normalVector = new Line("Normal Vector");
    normalVector.setLineWidth(1f);
    normalVector.setStipplePattern((short) 0xffff);
    normalVector.setModelBound(null);
    Util.disablePickShadowLight(normalVector);
    normalVector.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    normalVector.setDefaultColor(new ColorRGBA(1f, 1f, 0f, 1f));
    root.attachChild(normalVector);
    angles = new Node("Angles");
    angles.getSceneHints().setAllPickingHints(false);
    Util.disablePickShadowLight(angles);
    root.attachChild(angles);
    // the angle between the sun beam and the normal vector
    sunAngle = new AngleAnnotation();
    sunAngle.setColor(ColorRGBA.WHITE);
    sunAngle.setLineWidth(1);
    sunAngle.setFontSize(1);
    sunAngle.setCustomRadius(normalVectorLength * 0.8);
    angles.attachChild(sunAngle);
    label = new BMText("Label", "# " + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
    Util.initHousePartLabel(label);
    label.setFontScale(0.5);
    label.setVisible(false);
    root.attachChild(label);
    solarCellOutlines = new Line("Solar Cell Outlines");
    solarCellOutlines.setLineWidth(1f);
    solarCellOutlines.setStipplePattern((short) 0xffff);
    solarCellOutlines.setModelBound(null);
    Util.disablePickShadowLight(solarCellOutlines);
    solarCellOutlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(1));
    solarCellOutlines.setDefaultColor(new ColorRGBA(0f, 0f, 0f, 1f));
    root.attachChild(solarCellOutlines);
    updateTextureAndColor();
}
Also used : Line(com.ardor3d.scenegraph.Line) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ColorRGBA(com.ardor3d.math.ColorRGBA) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) AngleAnnotation(org.concord.energy3d.shapes.AngleAnnotation) BMText(com.ardor3d.ui.text.BMText) PvModuleSpecs(org.concord.energy3d.simulation.PvModuleSpecs) OffsetState(com.ardor3d.renderer.state.OffsetState)

Aggregations

Node (com.ardor3d.scenegraph.Node)50 Mesh (com.ardor3d.scenegraph.Mesh)31 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)27 Spatial (com.ardor3d.scenegraph.Spatial)26 Vector3 (com.ardor3d.math.Vector3)20 CullHint (com.ardor3d.scenegraph.hint.CullHint)20 Foundation (org.concord.energy3d.model.Foundation)12 FloatBuffer (java.nio.FloatBuffer)11 ArrayList (java.util.ArrayList)11 Line (com.ardor3d.scenegraph.Line)10 HousePart (org.concord.energy3d.model.HousePart)10 TPoint (org.poly2tri.triangulation.point.TPoint)10 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)9 ColorRGBA (com.ardor3d.math.ColorRGBA)7 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)7 BoundingBox (com.ardor3d.bounding.BoundingBox)6 BMText (com.ardor3d.ui.text.BMText)6 List (java.util.List)6 Rack (org.concord.energy3d.model.Rack)6 Roof (org.concord.energy3d.model.Roof)6