Search in sources :

Example 16 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class Window method init.

@Override
protected void init() {
    label1 = Annotation.makeNewLabel(1);
    super.init();
    if (Util.isZero(uValue)) {
        uValue = 2;
    }
    if (Util.isZero(solarHeatGainCoefficient)) {
        solarHeatGainCoefficient = 0.5;
    } else if (solarHeatGainCoefficient > 1) {
        solarHeatGainCoefficient *= 0.01;
    }
    if (Util.isZero(volumetricHeatCapacity)) {
        volumetricHeatCapacity = 0.5;
    }
    if (Util.isZero(shutterLength)) {
        shutterLength = 0.5;
    }
    if (glassColor == null) {
        setColor(new ColorRGBA(0.3f, 0.3f, 0.5f, 0.5f));
    }
    if (shutterColor == null) {
        shutterColor = ColorRGBA.DARK_GRAY;
    }
    mesh = new Mesh("Window");
    mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setNormalBuffer(BufferUtils.createVector3Buffer(6));
    mesh.setModelBound(new BoundingBox());
    mesh.getSceneHints().setAllPickingHints(false);
    if (glassColor == null) {
        glassColor = new ColorRGBA(0.3f, 0.3f, 0.5f, 0.5f);
    }
    mesh.setDefaultColor(glassColor);
    final BlendState blend = new BlendState();
    blend.setBlendEnabled(true);
    // blend.setTestEnabled(true);
    mesh.setRenderState(blend);
    mesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    final MaterialState ms = new MaterialState();
    ms.setColorMaterial(ColorMaterial.Diffuse);
    mesh.setRenderState(ms);
    root.attachChild(mesh);
    collisionMesh = new Mesh("Window Collision");
    collisionMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    collisionMesh.setVisible(false);
    collisionMesh.setUserData(new UserData(this));
    collisionMesh.setModelBound(new BoundingBox());
    root.attachChild(collisionMesh);
    label1.setAlign(Align.SouthWest);
    root.attachChild(label1);
    bars = new Line("Window (bars)");
    bars.setLineWidth(3);
    bars.setModelBound(new BoundingBox());
    Util.disablePickShadowLight(bars);
    bars.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
    root.attachChild(bars);
    leftShutter = new Mesh("Left Shutter");
    leftShutter.getMeshData().setIndexMode(IndexMode.Quads);
    leftShutter.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    leftShutter.getMeshData().setNormalBuffer(BufferUtils.createVector3Buffer(4));
    leftShutter.setRenderState(ms);
    leftShutter.setModelBound(new BoundingBox());
    root.attachChild(leftShutter);
    rightShutter = new Mesh("Right Shutter");
    rightShutter.getMeshData().setIndexMode(IndexMode.Quads);
    rightShutter.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    rightShutter.getMeshData().setNormalBuffer(BufferUtils.createVector3Buffer(4));
    rightShutter.setRenderState(ms);
    rightShutter.setModelBound(new BoundingBox());
    root.attachChild(rightShutter);
    leftShutterOutline = new Line("Left Shutter (Outline)");
    leftShutterOutline.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(12));
    leftShutterOutline.setDefaultColor(ColorRGBA.BLACK);
    leftShutterOutline.setModelBound(new BoundingBox());
    root.attachChild(leftShutterOutline);
    rightShutterOutline = new Line("Right Shutter (Outline)");
    rightShutterOutline.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(12));
    rightShutterOutline.setDefaultColor(ColorRGBA.BLACK);
    rightShutterOutline.setModelBound(new BoundingBox());
    root.attachChild(rightShutterOutline);
}
Also used : Line(com.ardor3d.scenegraph.Line) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) BoundingBox(com.ardor3d.bounding.BoundingBox) Mesh(com.ardor3d.scenegraph.Mesh) MaterialState(com.ardor3d.renderer.state.MaterialState) BlendState(com.ardor3d.renderer.state.BlendState)

Example 17 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class TriangleMeshLib method createMeshes.

private static List<Mesh> createMeshes(final ArrayList<GroupData> groups) {
    final List<Mesh> results = new ArrayList<Mesh>();
    for (final GroupData group : groups) {
        final Mesh mesh = new Mesh();
        mesh.setUserData(group.key);
        mesh.setModelBound(new BoundingBox());
        results.add(mesh);
        final FloatBuffer vertexBuffer = BufferUtils.createVector3Buffer(group.vertices.size());
        mesh.getMeshData().setVertexBuffer(vertexBuffer);
        for (final ReadOnlyVector3 v : group.vertices) {
            vertexBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
        }
        final FloatBuffer normalBuffer = BufferUtils.createFloatBuffer(vertexBuffer.limit());
        mesh.getMeshData().setNormalBuffer(normalBuffer);
        for (final ReadOnlyVector3 v : group.normals) {
            normalBuffer.put(v.getXf()).put(v.getYf()).put(v.getZf());
        }
        if (!group.textures.isEmpty()) {
            final FloatBuffer textureBuffer = BufferUtils.createVector2Buffer(group.textures.size());
            mesh.getMeshData().setTextureBuffer(textureBuffer, 0);
            for (final ReadOnlyVector2 v : group.textures) {
                textureBuffer.put(v.getXf()).put(v.getYf());
            }
            if (group.textureImage != null) {
                final Texture texture = TextureManager.loadFromImage(group.textureImage, Texture.MinificationFilter.Trilinear, TextureStoreFormat.GuessNoCompressedFormat);
                final TextureState ts = new TextureState();
                ts.setTexture(texture);
                mesh.setRenderState(ts);
            }
        }
        mesh.updateModelBound();
    }
    return results;
}
Also used : ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) TextureState(com.ardor3d.renderer.state.TextureState) BoundingBox(com.ardor3d.bounding.BoundingBox) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) Texture(com.ardor3d.image.Texture) GroupData(org.concord.energy3d.util.MeshLib.GroupData)

Example 18 with BoundingBox

use of com.ardor3d.bounding.BoundingBox 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 19 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class FoundationPolygon method init.

@Override
protected void init() {
    super.init();
    root.getSceneHints().setAllPickingHints(false);
    final Line line = new Line("Foundation Polygon");
    line.setLineWidth(3);
    line.getMeshData().setIndexMode(IndexMode.LineLoop);
    line.setModelBound(new BoundingBox());
    // line.setStipplePattern((short) 0xf);
    Util.disablePickShadowLight(line);
    root.attachChild(line);
    mesh = line;
    setVisible(visible);
}
Also used : Line(com.ardor3d.scenegraph.Line) BoundingBox(com.ardor3d.bounding.BoundingBox)

Example 20 with BoundingBox

use of com.ardor3d.bounding.BoundingBox in project energy3d by concord-consortium.

the class Wall method drawSurroundMesh.

private void drawSurroundMesh(final ReadOnlyVector3 thickness) {
    final boolean drawThicknessAndIsLongWall = Scene.getInstance().isDrawThickness() && !isShortWall;
    final boolean noNeighbor0 = neighbors[0] == null || (drawThicknessAndIsLongWall && isPerpendicularToNeighbor(0));
    final boolean noNeighbor1 = neighbors[1] == null || (drawThicknessAndIsLongWall && isPerpendicularToNeighbor(1));
    final boolean visible = roof == null || noNeighbor0 || noNeighbor1;
    surroundMesh.getSceneHints().setCullHint(visible ? CullHint.Inherit : CullHint.Always);
    if (!visible) {
        if (surroundMesh.getModelBound() != null) {
            surroundMesh.setModelBound(null);
        }
    } else {
        if (surroundMesh.getModelBound() == null) {
            surroundMesh.setModelBound(new BoundingBox());
        }
    }
    if (!visible) {
        return;
    }
    final FloatBuffer vertexBuffer = surroundMesh.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = surroundMesh.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final Vector3 sideNormal = thickness.cross(0, 0, 1, null).normalizeLocal();
    if (noNeighbor0) {
        addSurroundQuad(0, 1, sideNormal.negate(null), thickness, vertexBuffer, normalBuffer);
    }
    if (noNeighbor1) {
        addSurroundQuad(3, 2, sideNormal, thickness, vertexBuffer, normalBuffer);
    }
    if (roof == null) {
        addSurroundQuad(1, 3, Vector3.UNIT_Z, thickness, vertexBuffer, normalBuffer);
    }
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    surroundMesh.getMeshData().updateVertexCount();
    surroundMesh.updateModelBound();
    CollisionTreeManager.INSTANCE.removeCollisionTree(surroundMesh);
}
Also used : BoundingBox(com.ardor3d.bounding.BoundingBox) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Aggregations

BoundingBox (com.ardor3d.bounding.BoundingBox)23 Line (com.ardor3d.scenegraph.Line)12 Mesh (com.ardor3d.scenegraph.Mesh)10 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)8 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)8 Cylinder (com.ardor3d.scenegraph.shape.Cylinder)7 ColorRGBA (com.ardor3d.math.ColorRGBA)6 Vector3 (com.ardor3d.math.Vector3)6 CullHint (com.ardor3d.scenegraph.hint.CullHint)6 BMText (com.ardor3d.ui.text.BMText)6 FloatBuffer (java.nio.FloatBuffer)6 BlendState (com.ardor3d.renderer.state.BlendState)5 Node (com.ardor3d.scenegraph.Node)5 ArrayList (java.util.ArrayList)4 Matrix3 (com.ardor3d.math.Matrix3)3 Box (com.ardor3d.scenegraph.shape.Box)3 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)2 OffsetState (com.ardor3d.renderer.state.OffsetState)2 BillboardNode (com.ardor3d.scenegraph.extension.BillboardNode)2 Quad (com.ardor3d.scenegraph.shape.Quad)2