Search in sources :

Example 6 with Cylinder

use of com.ardor3d.scenegraph.shape.Cylinder 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 7 with Cylinder

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

the class Tree method init.

@Override
protected void init() {
    super.init();
    switch(treeType) {
        case COTTONWOOD:
            treeWidth = 80;
            treeHeight = 100;
            break;
        case LINDEN:
            treeWidth = 90;
            treeHeight = 120;
            break;
        case OAK:
            treeWidth = 70;
            treeHeight = 80;
            break;
        case ELM:
            treeWidth = 60;
            treeHeight = 75;
            break;
        case MAPLE:
            treeWidth = 30;
            treeHeight = 60;
            break;
        case PINE:
            treeWidth = 30;
            treeHeight = 80;
            break;
        default:
            treeWidth = 30;
            treeHeight = 40;
    }
    mesh = new Quad("Tree Quad", treeWidth, treeHeight);
    mesh.setModelBound(new BoundingBox());
    mesh.updateModelBound();
    mesh.setRotation(new Matrix3().fromAngles(Math.PI / 2, 0, 0));
    mesh.setTranslation(0, 0, treeHeight / 2.0);
    mesh.getSceneHints().setPickingHint(PickingHint.Pickable, false);
    final BlendState bs = new BlendState();
    bs.setEnabled(true);
    bs.setBlendEnabled(false);
    bs.setTestEnabled(true);
    bs.setTestFunction(TestFunction.GreaterThan);
    bs.setReference(0.7f);
    mesh.setRenderState(bs);
    mesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    billboard = new BillboardNode("Billboard");
    billboard.setAlignment(BillboardAlignment.AxialZ);
    billboard.attachChild(mesh);
    root.attachChild(billboard);
    switch(treeType) {
        case PINE:
            // axis samples, radial samples, radius, height, closed
            crown = new Cone("Tree Crown", 2, 6, 18, 20, false);
            break;
        default:
            // z samples, radial samples, radius
            crown = new Sphere("Tree Crown", 4, 8, 14);
    }
    crown.setModelBound(new BoundingSphere());
    crown.updateModelBound();
    final Cylinder trunk = new Cylinder("Tree Trunk", 10, 10, 1, 20);
    trunk.setModelBound(new BoundingBox());
    trunk.updateModelBound();
    switch(treeType) {
        case COTTONWOOD:
            crown.setScale(3, 3, 3.5);
            crown.setTranslation(0, 0, 55);
            trunk.setScale(8, 8, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case LINDEN:
            crown.setScale(3.5, 3.5, 4);
            crown.setTranslation(0, 0, 65);
            trunk.setScale(5, 5, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case OAK:
            crown.setScale(2.5, 2.5, 3);
            crown.setTranslation(0, 0, 45);
            trunk.setScale(5, 5, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case ELM:
            crown.setScale(2, 2, 2.5);
            crown.setTranslation(0, 0, 40);
            trunk.setScale(2, 2, 2);
            trunk.setTranslation(0, 0, 20);
            break;
        case MAPLE:
            crown.setScale(1, 1, 2.1);
            crown.setTranslation(0, 0, 32);
            trunk.setTranslation(0, 0, 10);
            break;
        case PINE:
            crown.setScale(1, 1, -4.0);
            crown.setTranslation(0, 0, 45);
            trunk.setTranslation(0, 0, 10);
            break;
        default:
            crown.setScale(1, 1, 1.2);
            crown.setTranslation(0, 0, 24);
            trunk.setTranslation(0, 0, 10);
            break;
    }
    collisionRoot = new Node("Tree Collision Root");
    collisionRoot.attachChild(crown);
    collisionRoot.attachChild(trunk);
    if (points.size() > 0) {
        collisionRoot.setTranslation(getAbsPoint(0));
    }
    collisionRoot.updateWorldTransform(true);
    collisionRoot.updateWorldBound(true);
    collisionRoot.getSceneHints().setCullHint(showPolygons ? CullHint.Never : CullHint.Always);
    root.attachChild(collisionRoot);
    crown.setUserData(new UserData(this));
    trunk.setUserData(new UserData(this));
    updateTextureAndColor();
}
Also used : Sphere(com.ardor3d.scenegraph.shape.Sphere) BoundingSphere(com.ardor3d.bounding.BoundingSphere) Quad(com.ardor3d.scenegraph.shape.Quad) Cylinder(com.ardor3d.scenegraph.shape.Cylinder) Cone(com.ardor3d.scenegraph.shape.Cone) BoundingSphere(com.ardor3d.bounding.BoundingSphere) BoundingBox(com.ardor3d.bounding.BoundingBox) Node(com.ardor3d.scenegraph.Node) BillboardNode(com.ardor3d.scenegraph.extension.BillboardNode) BillboardNode(com.ardor3d.scenegraph.extension.BillboardNode) BlendState(com.ardor3d.renderer.state.BlendState) Matrix3(com.ardor3d.math.Matrix3)

Example 8 with Cylinder

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

the class Foundation method init.

@Override
protected void init() {
    super.init();
    resizeHouseMode = false;
    if (Util.isZero(uValue)) {
        uValue = 0.19;
    }
    if (Util.isZero(volumetricHeatCapacity)) {
        volumetricHeatCapacity = 0.5;
    }
    if (Util.isZero(solarReceiverEfficiency)) {
        solarReceiverEfficiency = 0.2;
    }
    if (Util.isZero(childGridSize)) {
        childGridSize = 2.5;
    }
    if (thermostat == null) {
        thermostat = new Thermostat();
    }
    mesh = new Mesh("Foundation");
    mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setNormalBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
    mesh.setRenderState(offsetState);
    mesh.setModelBound(new BoundingBox());
    root.attachChild(mesh);
    if (foundationPolygon == null) {
        foundationPolygon = new FoundationPolygon(this);
    } else {
        foundationPolygon.draw();
    }
    root.attachChild(foundationPolygon.getRoot());
    sideMesh = new Mesh[4];
    for (int i = 0; i < 4; i++) {
        final Mesh mesh_i = new Mesh("Foundation (Side " + i + ")");
        mesh_i.setUserData(new UserData(this));
        mesh_i.setRenderState(offsetState);
        mesh_i.setModelBound(new BoundingBox());
        final MeshData meshData = mesh_i.getMeshData();
        meshData.setVertexBuffer(BufferUtils.createVector3Buffer(6));
        meshData.setNormalBuffer(BufferUtils.createVector3Buffer(6));
        mesh_i.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
        root.attachChild(mesh_i);
        sideMesh[i] = mesh_i;
    }
    boundingMesh = new Line("Foundation (Bounding)");
    boundingMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(24));
    boundingMesh.setModelBound(new BoundingBox());
    Util.disablePickShadowLight(boundingMesh);
    boundingMesh.getSceneHints().setCullHint(CullHint.Always);
    root.attachChild(boundingMesh);
    outlineMesh = new Line("Foundation (Outline)");
    outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(24));
    outlineMesh.setDefaultColor(ColorRGBA.BLACK);
    outlineMesh.setModelBound(new BoundingBox());
    Util.disablePickShadowLight(outlineMesh);
    root.attachChild(outlineMesh);
    linePatternMesh = new Line("Line Pattern");
    linePatternMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(2));
    linePatternMesh.setDefaultColor(new ColorRGBA(0, 0, 0, 0.75f));
    linePatternMesh.setModelBound(null);
    final BlendState blendState = new BlendState();
    blendState.setBlendEnabled(true);
    linePatternMesh.setRenderState(blendState);
    linePatternMesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    Util.disablePickShadowLight(linePatternMesh);
    root.attachChild(linePatternMesh);
    setLinePatternVisible(false);
    final UserData userData = new UserData(this);
    mesh.setUserData(userData);
    boundingMesh.setUserData(userData);
    setLabelOffset(-0.11);
    label = new BMText("Floating Label", "Undefined", FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
    Util.initHousePartLabel(label);
    label.setFontScale(0.5);
    label.setVisible(false);
    root.attachChild(label);
    azimuthArrow = new Line("Azimuth Arrow");
    azimuthArrow.setLineWidth(2);
    azimuthArrow.setModelBound(null);
    Util.disablePickShadowLight(azimuthArrow);
    azimuthArrow.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    azimuthArrow.setDefaultColor(ColorRGBA.WHITE);
    root.attachChild(azimuthArrow);
    solarReceiver = new Cylinder("Solar Receiver", 10, 10, 10, 0, true);
    solarReceiver.setDefaultColor(ColorRGBA.WHITE);
    solarReceiver.setRenderState(offsetState);
    solarReceiver.setModelBound(new BoundingBox());
    solarReceiver.setVisible(false);
    root.attachChild(solarReceiver);
    selectedMeshOutline = new Line("Outline of Selected Mesh");
    selectedMeshOutline.setLineWidth(2f);
    selectedMeshOutline.setStipplePattern((short) 0xf0f0);
    selectedMeshOutline.setModelBound(null);
    Util.disablePickShadowLight(selectedMeshOutline);
    selectedMeshOutline.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(1));
    selectedMeshOutline.setDefaultColor(new ColorRGBA(0f, 0f, 0f, 1f));
    root.attachChild(selectedMeshOutline);
    selectedNodeBoundingBox = new Line("Bounding Box of Selected Mesh");
    selectedNodeBoundingBox.setLineWidth(0.01f);
    selectedNodeBoundingBox.setStipplePattern((short) 0xf0f0);
    selectedNodeBoundingBox.setModelBound(null);
    Util.disablePickShadowLight(selectedNodeBoundingBox);
    selectedNodeBoundingBox.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(24));
    selectedNodeBoundingBox.setDefaultColor(new ColorRGBA(1f, 1f, 0f, 1f));
    root.attachChild(selectedNodeBoundingBox);
    updateTextureAndColor();
    if (points.size() == 8) {
        for (int i = 0; i < 4; i++) {
            points.add(new Vector3());
        }
    }
    if (importedNodeStates != null) {
        try {
            for (final Iterator<NodeState> it = importedNodeStates.iterator(); it.hasNext(); ) {
                final NodeState ns = it.next();
                final Node n = importCollada(ns.getSourceURL(), null);
                if (n == null) {
                    it.remove();
                    EventQueue.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            try {
                                JOptionPane.showMessageDialog(MainFrame.getInstance(), Paths.get(ns.getSourceURL().toURI()).toFile() + " was not found!", "File problem", JOptionPane.ERROR_MESSAGE);
                            } catch (final HeadlessException e) {
                                e.printStackTrace();
                            } catch (final URISyntaxException e) {
                                e.printStackTrace();
                            }
                        }
                    });
                } else {
                    final ArrayList<Integer> reversedFaceMeshes = ns.getMeshesWithReversedNormal();
                    if (reversedFaceMeshes != null) {
                        for (final Integer i : reversedFaceMeshes) {
                            Util.reverseFace(Util.getMesh(n, i));
                        }
                    }
                    final ArrayList<Integer> deletedMeshes = ns.getDeletedMeshes();
                    if (deletedMeshes != null && !deletedMeshes.isEmpty()) {
                        final List<Mesh> toDelete = new ArrayList<Mesh>();
                        for (final Integer i : deletedMeshes) {
                            toDelete.add(Util.getMesh(n, i));
                        }
                        for (final Mesh m : toDelete) {
                            n.detachChild(m);
                        }
                    }
                    final HashMap<Integer, ReadOnlyColorRGBA> meshColors = ns.getMeshColors();
                    if (meshColors != null) {
                        for (final Integer i : meshColors.keySet()) {
                            Util.getMesh(n, i).setDefaultColor(meshColors.get(i));
                        }
                    }
                }
            }
        } catch (final Throwable t) {
            BugReporter.report(t);
        }
        setRotatedNormalsForImportedMeshes();
    }
}
Also used : ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) HeadlessException(java.awt.HeadlessException) Node(com.ardor3d.scenegraph.Node) ArrayList(java.util.ArrayList) URISyntaxException(java.net.URISyntaxException) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) BMText(com.ardor3d.ui.text.BMText) BlendState(com.ardor3d.renderer.state.BlendState) Thermostat(org.concord.energy3d.simulation.Thermostat) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) MeshData(com.ardor3d.scenegraph.MeshData) Line(com.ardor3d.scenegraph.Line) Cylinder(com.ardor3d.scenegraph.shape.Cylinder) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA)

Example 9 with Cylinder

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

the class ParabolicTrough method addPole.

private void addPole(final Vector3 position, final double poleHeight, final double baseZ) {
    final Cylinder pole = new Cylinder("Pole Cylinder", 2, detailed ? 10 : 2, 10, 0);
    pole.setRadius(0.6);
    pole.setRenderState(offsetState);
    // slightly shorter so that the pole won't penetrate the surface of the trough
    pole.setHeight(poleHeight - 0.5 * pole.getRadius());
    pole.setModelBound(new BoundingBox());
    pole.updateModelBound();
    position.setZ(baseZ + pole.getHeight() / 2);
    pole.setTranslation(position);
    modulesRoot.attachChild(pole);
}
Also used : Cylinder(com.ardor3d.scenegraph.shape.Cylinder) BoundingBox(com.ardor3d.bounding.BoundingBox) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox)

Aggregations

Cylinder (com.ardor3d.scenegraph.shape.Cylinder)9 BoundingBox (com.ardor3d.bounding.BoundingBox)7 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)7 ColorRGBA (com.ardor3d.math.ColorRGBA)4 Line (com.ardor3d.scenegraph.Line)4 BMText (com.ardor3d.ui.text.BMText)4 BlendState (com.ardor3d.renderer.state.BlendState)3 Node (com.ardor3d.scenegraph.Node)3 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)2 CullState (com.ardor3d.renderer.state.CullState)2 Mesh (com.ardor3d.scenegraph.Mesh)2 CullHint (com.ardor3d.scenegraph.hint.CullHint)2 BoundingSphere (com.ardor3d.bounding.BoundingSphere)1 Matrix3 (com.ardor3d.math.Matrix3)1 Vector3 (com.ardor3d.math.Vector3)1 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)1 OffsetState (com.ardor3d.renderer.state.OffsetState)1 MeshData (com.ardor3d.scenegraph.MeshData)1 BillboardNode (com.ardor3d.scenegraph.extension.BillboardNode)1 Box (com.ardor3d.scenegraph.shape.Box)1