Search in sources :

Example 21 with Mesh

use of com.ardor3d.scenegraph.Mesh 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 22 with Mesh

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

the class Sensor method init.

@Override
protected void init() {
    super.init();
    mesh = new Mesh("Sensor");
    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("Sensor (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("Sensor (Outline)");
    outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
    outlineMesh.setDefaultColor(ColorRGBA.BLACK);
    outlineMesh.setModelBound(new OrientedBoundingBox());
    root.attachChild(outlineMesh);
    label = new BMText("" + getId(), "0", FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
    Util.initHousePartLabel(label);
    label.setFontScale(0.6);
    label.setVisible(true);
    root.attachChild(label);
    updateTextureAndColor();
}
Also used : Line(com.ardor3d.scenegraph.Line) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) Mesh(com.ardor3d.scenegraph.Mesh) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) Box(com.ardor3d.scenegraph.shape.Box) BMText(com.ardor3d.ui.text.BMText) OffsetState(com.ardor3d.renderer.state.OffsetState)

Example 23 with Mesh

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

the class Mirror method init.

@Override
protected void init() {
    super.init();
    if (Util.isZero(mirrorWidth)) {
        mirrorWidth = 5;
    }
    if (Util.isZero(mirrorHeight)) {
        mirrorHeight = 3;
    }
    if (Util.isZero(reflectance)) {
        reflectance = 0.9;
    }
    if (Util.isZero(opticalEfficiency)) {
        opticalEfficiency = 1;
    }
    if (Util.isZero(baseHeight)) {
        baseHeight = 10;
    }
    if (heliostatTarget != null) {
        // FIXME: Somehow the target, when copied, doesn't point to the right object. This is not a prefect solution, but it fixes the problem.
        final HousePart hp = Scene.getInstance().getPart(heliostatTarget.getId());
        if (hp instanceof Foundation) {
            heliostatTarget = (Foundation) hp;
        } else {
            heliostatTarget = null;
        }
    }
    mesh = new Mesh("Reflecting Mirror");
    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("Mirror (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("Mirror (Outline)");
    outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
    outlineMesh.setDefaultColor(ColorRGBA.BLACK);
    outlineMesh.setModelBound(new OrientedBoundingBox());
    root.attachChild(outlineMesh);
    // if there are many mirrors, reduce the solution of post
    post = new Cylinder("Post Cylinder", 2, Scene.getInstance().getAllHeliostats().size() < 200 ? 10 : 2, 10, 0);
    post.setRadius(0.6);
    post.setDefaultColor(ColorRGBA.WHITE);
    post.setRenderState(offsetState);
    post.setModelBound(new BoundingBox());
    post.updateModelBound();
    root.attachChild(post);
    lightBeams = new Line("Light Beams");
    lightBeams.setLineWidth(1f);
    lightBeams.setStipplePattern((short) 0xffff);
    lightBeams.setModelBound(null);
    // final BlendState blendState = new BlendState();
    // blendState.setBlendEnabled(true);
    // lightBeams.setRenderState(blendState);
    // lightBeams.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    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);
    updateTextureAndColor();
}
Also used : Line(com.ardor3d.scenegraph.Line) Cylinder(com.ardor3d.scenegraph.shape.Cylinder) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ColorRGBA(com.ardor3d.math.ColorRGBA) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) Mesh(com.ardor3d.scenegraph.Mesh) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) BMText(com.ardor3d.ui.text.BMText) OffsetState(com.ardor3d.renderer.state.OffsetState)

Example 24 with Mesh

use of com.ardor3d.scenegraph.Mesh 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)

Example 25 with Mesh

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

the class Wall method setOriginal.

@Override
public void setOriginal(final HousePart original) {
    final Wall originalWall = (Wall) original;
    this.thicknessNormal = originalWall.getThicknessNormal();
    root.detachChild(invisibleMesh);
    root.detachChild(backMesh);
    root.detachChild(surroundMesh);
    root.detachChild(windowsSurroundMesh);
    root.detachChild(outlineMesh);
    backMesh = originalWall.backMesh.makeCopy(true);
    surroundMesh = originalWall.surroundMesh.makeCopy(true);
    windowsSurroundMesh = originalWall.windowsSurroundMesh.makeCopy(true);
    outlineMesh = originalWall.outlineMesh.makeCopy(true);
    ((Line) outlineMesh).setLineWidth(printOutlineThickness);
    root.attachChild(backMesh);
    root.attachChild(surroundMesh);
    root.attachChild(windowsSurroundMesh);
    root.attachChild(outlineMesh);
    final Mesh orgInvisibleMesh = originalWall.invisibleMesh;
    invisibleMesh = orgInvisibleMesh.makeCopy(true);
    invisibleMesh.setUserData(new UserData(this, ((UserData) orgInvisibleMesh.getUserData()).getEditPointIndex(), false));
    root.attachChild(invisibleMesh);
    wallAndWindowsPoints = originalWall.wallAndWindowsPoints;
    super.setOriginal(original);
}
Also used : Line(com.ardor3d.scenegraph.Line) Mesh(com.ardor3d.scenegraph.Mesh)

Aggregations

Mesh (com.ardor3d.scenegraph.Mesh)69 Spatial (com.ardor3d.scenegraph.Spatial)36 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)33 Node (com.ardor3d.scenegraph.Node)31 CullHint (com.ardor3d.scenegraph.hint.CullHint)28 Vector3 (com.ardor3d.math.Vector3)25 FloatBuffer (java.nio.FloatBuffer)18 TPoint (org.poly2tri.triangulation.point.TPoint)16 Line (com.ardor3d.scenegraph.Line)15 ArrayList (java.util.ArrayList)15 BoundingBox (com.ardor3d.bounding.BoundingBox)12 Point (org.poly2tri.geometry.primitives.Point)12 HousePart (org.concord.energy3d.model.HousePart)11 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)10 PickResults (com.ardor3d.intersection.PickResults)10 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)10 Ray3 (com.ardor3d.math.Ray3)10 Foundation (org.concord.energy3d.model.Foundation)10 ColorRGBA (com.ardor3d.math.ColorRGBA)8 Calendar (java.util.Calendar)8