Search in sources :

Example 11 with ColorRGBA

use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.

the class SolarRadiation method applyTexture.

private void applyTexture(final Mesh mesh) {
    if (onMesh.get(mesh) == null) {
        mesh.setDefaultColor(ColorRGBA.BLACK);
        mesh.clearRenderState(StateType.Texture);
        return;
    }
    final double[][] solarData = onMesh.get(mesh).dailySolarIntensity;
    final int rows = solarData.length;
    if (rows == 0) {
        return;
    }
    final int cols = solarData[0].length;
    if (cols == 0) {
        return;
    }
    fillBlanksWithNeighboringValues(solarData);
    final ByteBuffer data = BufferUtils.createByteBuffer(cols * rows * 3);
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            final ColorRGBA color = computeColor(solarData[row][col], maxValue);
            data.put((byte) (color.getRed() * 255)).put((byte) (color.getGreen() * 255)).put((byte) (color.getBlue() * 255));
        }
    }
    final Image image = new Image(ImageDataFormat.RGB, PixelDataType.UnsignedByte, cols, rows, data, null);
    final Texture2D texture = new Texture2D();
    texture.setTextureKey(TextureKey.getRTTKey(MinificationFilter.NearestNeighborNoMipMaps));
    texture.setImage(image);
    // texture.setWrap(WrapMode.Clamp);
    final TextureState textureState = new TextureState();
    textureState.setTexture(texture);
    mesh.setDefaultColor(ColorRGBA.WHITE);
    mesh.setRenderState(textureState);
}
Also used : Texture2D(com.ardor3d.image.Texture2D) TextureState(com.ardor3d.renderer.state.TextureState) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Image(com.ardor3d.image.Image) ByteBuffer(java.nio.ByteBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Example 12 with ColorRGBA

use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.

the class MainFrame method showColorDialogForParts.

void showColorDialogForParts() {
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    ActionListener colorActionListener;
    if (selectedPart == null) {
        final ReadOnlyColorRGBA color = Scene.getInstance().getLandColor();
        if (color != null) {
            colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
        }
        colorActionListener = new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final float[] newColor = colorChooser.getColor().getComponents(null);
                final ColorRGBA rgba = new ColorRGBA(newColor[0], newColor[1], newColor[2], 0.5f);
                if (!Scene.getInstance().getLandColor().equals(rgba)) {
                    final ChangeLandColorCommand cmd = new ChangeLandColorCommand();
                    Scene.getInstance().setLandColor(rgba);
                    Scene.getInstance().setEdited(true);
                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                }
            }
        };
    } else {
        if (Scene.getInstance().getTextureMode() != TextureMode.None) {
            // when the user wants to set the color, automatically switch to no texture
            if (JOptionPane.showConfirmDialog(this, "To set color for an individual part, we have to remove the texture. Is that OK?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE) == JOptionPane.NO_OPTION) {
                return;
            }
            Scene.getInstance().setTextureMode(TextureMode.None);
        }
        final ReadOnlyColorRGBA color = selectedPart.getColor();
        if (color != null) {
            colorChooser.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue()));
        }
        colorActionListener = new ActionListener() {

            private boolean changed;

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart == null) {
                    return;
                }
                final Color c = colorChooser.getColor();
                final float[] newColor = c.getComponents(null);
                final boolean restartPrintPreview = Scene.getInstance().getRoofColor().equals(ColorRGBA.WHITE) || c.equals(Color.WHITE);
                final ColorRGBA color = new ColorRGBA(newColor[0], newColor[1], newColor[2], newColor[3]);
                final JPanel panel = new JPanel();
                panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
                panel.setBorder(BorderFactory.createTitledBorder("Apply to:"));
                if (selectedPart instanceof Wall) {
                    final JRadioButton rb1 = new JRadioButton("Only this Wall", true);
                    final JRadioButton rb2 = new JRadioButton("All Walls Connected to This One (Direct and Indirect)");
                    final JRadioButton rb3 = new JRadioButton("All Walls of this Building");
                    final JRadioButton rb4 = new JRadioButton("All Walls");
                    panel.add(rb1);
                    panel.add(rb2);
                    panel.add(rb3);
                    panel.add(rb4);
                    final ButtonGroup bg = new ButtonGroup();
                    bg.add(rb1);
                    bg.add(rb2);
                    bg.add(rb3);
                    bg.add(rb4);
                    final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                    final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Wall Color");
                    while (true) {
                        changed = false;
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            break;
                        } else {
                            changed = !color.equals(selectedPart.getColor());
                            if (rb1.isSelected()) {
                                // apply to only this part
                                if (changed) {
                                    final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                                    selectedPart.setColor(color);
                                    selectedPart.draw();
                                    SceneManager.getInstance().refresh();
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else if (rb2.isSelected()) {
                                final Wall w = (Wall) selectedPart;
                                if (!changed) {
                                    w.visitNeighbors(new WallVisitor() {

                                        @Override
                                        public void visit(final Wall currentWall, final Snap prev, final Snap next) {
                                            if (!color.equals(currentWall.getColor())) {
                                                changed = true;
                                            }
                                        }
                                    });
                                }
                                if (changed) {
                                    final ChangeColorOfConnectedWallsCommand cmd = new ChangeColorOfConnectedWallsCommand(w);
                                    Scene.getInstance().setColorOfConnectedWalls(w, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else if (rb3.isSelected()) {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getPartsOfSameTypeInBuilding(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeBuildingColorCommand cmd = new ChangeBuildingColorCommand(selectedPart);
                                    Scene.getInstance().setPartColorOfBuilding(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else if (rb4.isSelected()) {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
                                    Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            }
                            // remember the color decision for the next wall to be added
                            Scene.getInstance().setWallColor(color);
                            if (choice == options[0]) {
                                break;
                            }
                        }
                    }
                } else if (selectedPart instanceof Roof) {
                    final JRadioButton rb1 = new JRadioButton("Only this Roof", true);
                    final JRadioButton rb2 = new JRadioButton("All Roofs");
                    panel.add(rb1);
                    panel.add(rb2);
                    final ButtonGroup bg = new ButtonGroup();
                    bg.add(rb1);
                    bg.add(rb2);
                    final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                    final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Roof Color");
                    while (true) {
                        changed = false;
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            break;
                        } else {
                            changed = !color.equals(selectedPart.getColor());
                            if (rb1.isSelected()) {
                                // apply to only this part
                                if (changed) {
                                    final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                                    selectedPart.setColor(color);
                                    selectedPart.draw();
                                    SceneManager.getInstance().refresh();
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
                                    Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            }
                            // remember the color decision for the next roof to be added
                            Scene.getInstance().setRoofColor(color);
                            if (choice == options[0]) {
                                break;
                            }
                        }
                    }
                } else if (selectedPart instanceof Foundation) {
                    final JRadioButton rb1 = new JRadioButton("Only this Foundation", true);
                    final JRadioButton rb2 = new JRadioButton("All Foundations");
                    panel.add(rb1);
                    panel.add(rb2);
                    final ButtonGroup bg = new ButtonGroup();
                    bg.add(rb1);
                    bg.add(rb2);
                    final Object[] options = new Object[] { "OK", "Cancel", "Apply" };
                    final JOptionPane optionPane = new JOptionPane(panel, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION, null, options, options[2]);
                    final JDialog dialog = optionPane.createDialog(MainFrame.getInstance(), "Foundation Color");
                    while (true) {
                        changed = false;
                        dialog.setVisible(true);
                        final Object choice = optionPane.getValue();
                        if (choice == options[1]) {
                            break;
                        } else {
                            changed = !color.equals(selectedPart.getColor());
                            if (rb1.isSelected()) {
                                // apply to only this part
                                if (changed) {
                                    final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                                    selectedPart.setColor(color);
                                    selectedPart.draw();
                                    SceneManager.getInstance().refresh();
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            } else {
                                if (!changed) {
                                    for (final HousePart x : Scene.getInstance().getAllPartsOfSameType(selectedPart)) {
                                        if (!color.equals(x.getColor())) {
                                            changed = true;
                                            break;
                                        }
                                    }
                                }
                                if (changed) {
                                    final ChangeColorOfAllPartsOfSameTypeCommand cmd = new ChangeColorOfAllPartsOfSameTypeCommand(selectedPart);
                                    Scene.getInstance().setColorOfAllPartsOfSameType(selectedPart, color);
                                    SceneManager.getInstance().getUndoManager().addEdit(cmd);
                                }
                            }
                            // remember the color decision for the next foundation to be added
                            Scene.getInstance().setFoundationColor(color);
                            if (choice == options[0]) {
                                break;
                            }
                        }
                    }
                } else {
                    changed = !color.equals(selectedPart.getColor());
                    if (changed) {
                        final ChangePartColorCommand cmd = new ChangePartColorCommand(selectedPart);
                        selectedPart.setColor(color);
                        selectedPart.draw();
                        SceneManager.getInstance().refresh();
                        SceneManager.getInstance().getUndoManager().addEdit(cmd);
                        if (selectedPart instanceof Door) {
                            // remember the color decision for the next part
                            Scene.getInstance().setDoorColor(color);
                        } else if (selectedPart instanceof Floor) {
                            Scene.getInstance().setFloorColor(color);
                        }
                    }
                }
                Scene.getInstance().setTextureMode(Scene.getInstance().getTextureMode());
                if (restartPrintPreview && PrintController.getInstance().isPrintPreview()) {
                    PrintController.getInstance().restartAnimation();
                }
                MainPanel.getInstance().getEnergyButton().setSelected(false);
                Scene.getInstance().setEdited(changed);
            }
        };
    }
    JColorChooser.createDialog(this, "Select Color", true, colorChooser, colorActionListener, null).setVisible(true);
}
Also used : ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) JPanel(javax.swing.JPanel) Wall(org.concord.energy3d.model.Wall) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) Snap(org.concord.energy3d.model.Snap) ChangeColorOfConnectedWallsCommand(org.concord.energy3d.undo.ChangeColorOfConnectedWallsCommand) WallVisitor(org.concord.energy3d.util.WallVisitor) Roof(org.concord.energy3d.model.Roof) ChangePartColorCommand(org.concord.energy3d.undo.ChangePartColorCommand) Foundation(org.concord.energy3d.model.Foundation) HousePart(org.concord.energy3d.model.HousePart) ChangeLandColorCommand(org.concord.energy3d.undo.ChangeLandColorCommand) Floor(org.concord.energy3d.model.Floor) ChangeColorOfAllPartsOfSameTypeCommand(org.concord.energy3d.undo.ChangeColorOfAllPartsOfSameTypeCommand) Color(java.awt.Color) JOptionPane(javax.swing.JOptionPane) Door(org.concord.energy3d.model.Door) ActionListener(java.awt.event.ActionListener) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) ButtonGroup(javax.swing.ButtonGroup) ChangeBuildingColorCommand(org.concord.energy3d.undo.ChangeBuildingColorCommand) JDialog(javax.swing.JDialog)

Example 13 with ColorRGBA

use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.

the class SceneManager method drawGrids.

public Mesh drawGrids(final double gridSize) {
    final Mesh gridsMesh = new Line("Ground Grids");
    gridsMesh.getSceneHints().setCullHint(CullHint.Always);
    gridsMesh.setDefaultColor(new ColorRGBA(0, 0, 1, 1));
    final BlendState blendState = new BlendState();
    blendState.setBlendEnabled(true);
    gridsMesh.setRenderState(blendState);
    gridsMesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    final ReadOnlyVector3 width = Vector3.UNIT_X.multiply(2000, null);
    final ReadOnlyVector3 height = Vector3.UNIT_Y.multiply(2000, null);
    final ArrayList<ReadOnlyVector3> points = new ArrayList<ReadOnlyVector3>();
    final ReadOnlyVector3 pMiddle = Vector3.ZERO;
    final int cols = (int) (width.length() / gridSize);
    for (int col = 1; col < cols / 2 + 1; col++) {
        for (int neg = -1; neg <= 1; neg += 2) {
            final ReadOnlyVector3 lineP1 = width.normalize(null).multiplyLocal(neg * col * gridSize).addLocal(pMiddle).subtractLocal(height.multiply(0.5, null));
            points.add(lineP1);
            final ReadOnlyVector3 lineP2 = lineP1.add(height, null);
            points.add(lineP2);
            if (col == 0) {
                break;
            }
        }
    }
    final int rows = (int) (height.length() / gridSize);
    for (int row = 1; row < rows / 2 + 1; row++) {
        for (int neg = -1; neg <= 1; neg += 2) {
            final ReadOnlyVector3 lineP1 = height.normalize(null).multiplyLocal(neg * row * gridSize).addLocal(pMiddle).subtractLocal(width.multiply(0.5, null));
            points.add(lineP1);
            final ReadOnlyVector3 lineP2 = lineP1.add(width, null);
            points.add(lineP2);
            if (row == 0) {
                break;
            }
        }
    }
    final FloatBuffer buf = BufferUtils.createVector3Buffer(points.size());
    for (final ReadOnlyVector3 p : points) {
        buf.put(p.getXf()).put(p.getYf()).put(0.01f);
    }
    gridsMesh.getMeshData().setVertexBuffer(buf);
    gridsMesh.getMeshData().updateVertexCount();
    Util.disablePickShadowLight(gridsMesh);
    gridsMesh.setModelBound(new BoundingBox());
    gridsMesh.updateModelBound();
    gridsMesh.updateWorldBound(true);
    return gridsMesh;
}
Also used : Line(com.ardor3d.scenegraph.Line) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ColorRGBA(com.ardor3d.math.ColorRGBA) BoundingBox(com.ardor3d.bounding.BoundingBox) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) FloatBuffer(java.nio.FloatBuffer) BlendState(com.ardor3d.renderer.state.BlendState) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 14 with ColorRGBA

use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.

the class SceneManager method createLand.

private Mesh createLand() {
    final Quad land = new Quad("Land", SKY_RADIUS * 2, SKY_RADIUS * 2);
    land.setDefaultColor(new ColorRGBA(0, 1.0f, 0.75f, 0.5f));
    final OffsetState offsetState = new OffsetState();
    offsetState.setTypeEnabled(OffsetType.Fill, true);
    offsetState.setFactor(10);
    offsetState.setUnits(10);
    land.setRenderState(offsetState);
    final BlendState blendState = new BlendState();
    blendState.setBlendEnabled(true);
    land.setRenderState(blendState);
    land.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    final MaterialState ms = new MaterialState();
    ms.setColorMaterial(ColorMaterial.Diffuse);
    land.setRenderState(ms);
    land.updateModelBound();
    land.updateWorldBound(true);
    return land;
}
Also used : Quad(com.ardor3d.scenegraph.shape.Quad) ColorRGBA(com.ardor3d.math.ColorRGBA) MaterialState(com.ardor3d.renderer.state.MaterialState) OffsetState(com.ardor3d.renderer.state.OffsetState) BlendState(com.ardor3d.renderer.state.BlendState)

Example 15 with ColorRGBA

use of com.ardor3d.math.ColorRGBA in project energy3d by concord-consortium.

the class SolarRadiation method computeColor.

public static ColorRGBA computeColor(final double value, final long maxValue) {
    final ReadOnlyColorRGBA[] colors = EnergyPanel.solarColors;
    long valuePerColorRange = maxValue / (colors.length - 1);
    int colorIndex;
    if (valuePerColorRange == 0) {
        valuePerColorRange = 1;
        colorIndex = 0;
    } else {
        colorIndex = (int) Math.min(value / valuePerColorRange, colors.length - 2);
        if (colorIndex < 0) {
            colorIndex = 0;
        }
    }
    final float scalar = Math.min(1.0f, (float) (value - valuePerColorRange * colorIndex) / valuePerColorRange);
    return new ColorRGBA().lerpLocal(colors[colorIndex], colors[colorIndex + 1], scalar);
}
Also used : ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Aggregations

ColorRGBA (com.ardor3d.math.ColorRGBA)20 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)14 Line (com.ardor3d.scenegraph.Line)10 BoundingBox (com.ardor3d.bounding.BoundingBox)8 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)8 Mesh (com.ardor3d.scenegraph.Mesh)8 Node (com.ardor3d.scenegraph.Node)7 CullHint (com.ardor3d.scenegraph.hint.CullHint)7 BMText (com.ardor3d.ui.text.BMText)7 BlendState (com.ardor3d.renderer.state.BlendState)6 OffsetState (com.ardor3d.renderer.state.OffsetState)5 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)4 Box (com.ardor3d.scenegraph.shape.Box)4 Cylinder (com.ardor3d.scenegraph.shape.Cylinder)4 Color (java.awt.Color)4 HousePart (org.concord.energy3d.model.HousePart)4 Vector3 (com.ardor3d.math.Vector3)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JPanel (javax.swing.JPanel)3