Search in sources :

Example 16 with Vector2

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

the class SelectUtil method pickPart.

public static PickedHousePart pickPart(final int x, final int y) {
    pickResults.clear();
    final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
    for (final HousePart housePart : Scene.getInstance().getParts()) {
        PickingUtil.findPick(housePart.getCollisionSpatial(), pickRay, pickResults, false);
        PickingUtil.findPick(housePart.getEditPointsRoot(), pickRay, pickResults, false);
        if (housePart instanceof Foundation) {
            final Foundation foundation = (Foundation) housePart;
            if (foundation.getPolygon().isVisible()) {
                PickingUtil.findPick(foundation.getPolygon().getEditPointsRoot(), pickRay, pickResults, false);
            }
        }
    }
    return getPickResult(pickRay);
}
Also used : Vector2(com.ardor3d.math.Vector2) Foundation(org.concord.energy3d.model.Foundation) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) Ray3(com.ardor3d.math.Ray3)

Example 17 with Vector2

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

the class TriangleMeshLib method findGroups.

private static ArrayList<GroupData> findGroups(final Mesh mesh, final boolean redoNormal) {
    final FloatBuffer vertexBuffer = mesh.getMeshData().getVertexBuffer();
    vertexBuffer.rewind();
    FloatBuffer normalBuffer = mesh.getMeshData().getNormalBuffer();
    if (normalBuffer == null) {
        normalBuffer = BufferUtils.createFloatBuffer(vertexBuffer.limit());
    } else {
        normalBuffer.rewind();
    }
    final TextureState textureState = (TextureState) mesh.getLocalRenderState(StateType.Texture);
    FloatBuffer textureBuffer = mesh.getMeshData().getTextureBuffer(0);
    if (textureBuffer != null) {
        textureBuffer.rewind();
    } else {
        textureBuffer = BufferUtils.createFloatBuffer(vertexBuffer.limit() / 3 * 2);
    }
    final Vector3 v1 = new Vector3();
    final Vector3 v2 = new Vector3();
    final Vector3 normal = new Vector3();
    final ArrayList<GroupData> groups = new ArrayList<GroupData>();
    for (int i = 0; i < vertexBuffer.limit() / 9; i++) {
        final Vector3 p1 = new Vector3(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
        final Vector3 p2 = new Vector3(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
        final Vector3 p3 = new Vector3(vertexBuffer.get(), vertexBuffer.get(), vertexBuffer.get());
        p2.subtract(p1, v1);
        p3.subtract(p1, v2);
        v1.cross(v2, normal);
        // as the vertex buffer can be relative to the node, apply the world transform to get the absolute normal
        mesh.getWorldTransform().applyForwardVector(normal);
        normal.normalizeLocal();
        Vector3 firstNormal = null;
        if (!redoNormal) {
            firstNormal = new Vector3(normalBuffer.get(), normalBuffer.get(), normalBuffer.get());
            if (Double.isNaN(firstNormal.length())) {
                continue;
            }
        }
        final GroupData group = new GroupData();
        group.key.set(normal);
        groups.add(group);
        if (textureState != null && textureState.getTexture() != null) {
            group.textureImage = textureState.getTexture().getImage();
        }
        group.vertices.add(p1);
        group.vertices.add(p2);
        group.vertices.add(p3);
        if (redoNormal) {
            group.normals.add(group.key.clone());
            group.normals.add(group.key.clone());
            group.normals.add(group.key.clone());
        } else {
            group.normals.add(firstNormal);
            group.normals.add(new Vector3(normalBuffer.get(), normalBuffer.get(), normalBuffer.get()));
            group.normals.add(new Vector3(normalBuffer.get(), normalBuffer.get(), normalBuffer.get()));
        }
        // texture is 2D, vertex is 3D
        group.textures.add(new Vector2(textureBuffer.get(), textureBuffer.get()));
        group.textures.add(new Vector2(textureBuffer.get(), textureBuffer.get()));
        group.textures.add(new Vector2(textureBuffer.get(), textureBuffer.get()));
    }
    MeshLib.combineGroups(groups);
    return groups;
}
Also used : TextureState(com.ardor3d.renderer.state.TextureState) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) ArrayList(java.util.ArrayList) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) GroupData(org.concord.energy3d.util.MeshLib.GroupData)

Example 18 with Vector2

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

the class PopupMenuForMesh method getPopupMenu.

static JPopupMenu getPopupMenu() {
    if (popupMenuForMesh == null) {
        final JMenuItem miInfo = new JMenuItem("Mesh");
        miInfo.setEnabled(false);
        miInfo.setOpaque(true);
        miInfo.setBackground(Config.isMac() ? Color.BLACK : Color.GRAY);
        miInfo.setForeground(Color.WHITE);
        final JMenuItem miMessThickness = new JMenuItem("Thickness...");
        miMessThickness.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        final Node n = m.getParent();
                        final String title = "<html>Adjust the distance between two mesh faces to create some thickness<br>A larger thickness also mitigates the z-fighting effect.</html>";
                        while (true) {
                            final String newValue = JOptionPane.showInputDialog(MainFrame.getInstance(), title, f.getMeshThickness(n) * Scene.getInstance().getAnnotationScale());
                            if (newValue == null) {
                                break;
                            } else {
                                try {
                                    final double val = Double.parseDouble(newValue);
                                    if (val < 0 || val > 1) {
                                        JOptionPane.showMessageDialog(MainFrame.getInstance(), "Thickness must be between 0 and 1 meter.", "Range Error", JOptionPane.ERROR_MESSAGE);
                                    } else {
                                        SceneManager.getTaskManager().update(new Callable<Object>() {

                                            @Override
                                            public Object call() throws Exception {
                                                f.setMeshThickness(n, val / Scene.getInstance().getAnnotationScale());
                                                f.draw();
                                                return null;
                                            }
                                        });
                                        break;
                                    }
                                } catch (final NumberFormatException exception) {
                                    JOptionPane.showMessageDialog(MainFrame.getInstance(), newValue + " is an invalid value!", "Error", JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        }
                    }
                }
            }
        });
        final JMenuItem miReverseNormalVector = new JMenuItem("Reverse Mesh Normal Vector");
        miReverseNormalVector.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    SceneManager.getTaskManager().update(new Callable<Object>() {

                        @Override
                        public Object call() throws Exception {
                            final Mesh m = f.getSelectedMesh();
                            if (m != null) {
                                Util.reverseFace(m);
                                f.getNodeState(m.getParent()).reverseNormalOfMesh(((UserData) m.getUserData()).getMeshIndex());
                                f.draw();
                                updateAfterEdit();
                            }
                            return null;
                        }
                    });
                }
            }
        });
        final JMenuItem miAlignBottom = new JMenuItem("Align Node Bottom with Ground Level");
        miAlignBottom.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                final Node n = m.getParent();
                                if (n != null) {
                                    final OrientedBoundingBox boundingBox = Util.getOrientedBoundingBox(n);
                                    final double zBottom = boundingBox.getCenter().getZ() - boundingBox.getZAxis().getZ() * boundingBox.getExtent().getZ() - f.getHeight();
                                    f.translateImportedNode(n, 0, 0, -zBottom);
                                    f.draw();
                                    updateAfterEdit();
                                }
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miAlignCenter = new JMenuItem("Align Node Center with Foundation Center");
        miAlignCenter.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                final Node n = m.getParent();
                                if (n != null) {
                                    final OrientedBoundingBox boundingBox = Util.getOrientedBoundingBox(n);
                                    final ReadOnlyVector3 shift = boundingBox.getCenter().subtract(f.getAbsCenter(), null);
                                    f.translateImportedNode(n, shift.getX(), shift.getY(), 0);
                                    f.setMeshSelectionVisible(false);
                                    f.draw();
                                    updateAfterEdit();
                                }
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miCopyNode = new JMenuItem("Copy Node");
        miCopyNode.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miCopyNode.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                        if (selectedPart instanceof Foundation) {
                            final Foundation f = (Foundation) selectedPart;
                            final Mesh m = f.getSelectedMesh();
                            if (m != null) {
                                final Node n = m.getParent();
                                Scene.getInstance().setCopyNode(n, f.getNodeState(n));
                            }
                        }
                        return null;
                    }
                });
            }
        });
        final JMenuItem miPaste = new JMenuItem("Paste");
        miPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miPaste.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                SceneManager.getTaskManager().update(new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                        if (selectedPart instanceof Foundation) {
                            final Foundation f = (Foundation) selectedPart;
                            final Mesh m = f.getSelectedMesh();
                            if (m != null) {
                                Scene.getInstance().pasteToPickedLocationOnMesh(m);
                                Scene.getInstance().setEdited(true);
                                updateAfterEdit();
                            }
                        }
                        return null;
                    }
                });
            }
        });
        popupMenuForMesh = new JPopupMenu();
        popupMenuForMesh.setInvoker(MainPanel.getInstance().getCanvasPanel());
        popupMenuForMesh.addPopupMenuListener(new PopupMenuListener() {

            @Override
            public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        String name = f.getNodeState(m.getParent()).getName();
                        if (name == null) {
                            name = "Undefined";
                        }
                        miInfo.setText(m.getName() + " (" + name + ")");
                        final OrientedBoundingBox boundingBox = Util.getOrientedBoundingBox(m.getParent());
                        final ReadOnlyVector3 center = boundingBox.getCenter();
                        final double zBottom = center.getZ() - boundingBox.getZAxis().getZ() * boundingBox.getExtent().getZ();
                        miAlignBottom.setEnabled(!Util.isZero(zBottom - f.getHeight()));
                        final Vector3 foundationCenter = f.getAbsCenter();
                        miAlignCenter.setEnabled(!Util.isEqual(new Vector2(foundationCenter.getX(), foundationCenter.getY()), new Vector2(center.getX(), center.getY())));
                        final HousePart copyBuffer = Scene.getInstance().getCopyBuffer();
                        miPaste.setEnabled(copyBuffer instanceof SolarPanel || copyBuffer instanceof Rack);
                    }
                }
            }

            @Override
            public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
                miAlignBottom.setEnabled(true);
                miAlignCenter.setEnabled(true);
            }

            @Override
            public void popupMenuCanceled(final PopupMenuEvent e) {
                miAlignBottom.setEnabled(true);
                miAlignCenter.setEnabled(true);
            }
        });
        final JMenuItem miDeleteMesh = new JMenuItem("Delete Mesh");
        miDeleteMesh.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                f.deleteMesh(m);
                                updateAfterEdit();
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miRestoreDeletedMeshes = new JMenuItem("Restore Deleted Meshes (Reload Required)");
        miRestoreDeletedMeshes.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                f.restoreDeletedMeshes(m.getParent());
                                updateAfterEdit();
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miCutNode = new JMenuItem("Cut Node");
        miCutNode.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Config.isMac() ? KeyEvent.META_MASK : InputEvent.CTRL_MASK));
        miCutNode.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        SceneManager.getTaskManager().update(new Callable<Object>() {

                            @Override
                            public Object call() throws Exception {
                                final Node n = m.getParent();
                                Scene.getInstance().setCopyNode(n, f.getNodeState(n));
                                f.deleteNode(n);
                                updateAfterEdit();
                                return null;
                            }
                        });
                    }
                }
            }
        });
        final JMenuItem miMeshProperties = new JMenuItem("Mesh Properties...");
        miMeshProperties.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        final UserData ud = (UserData) m.getUserData();
                        final JPanel gui = new JPanel(new BorderLayout());
                        final String title = "<html>A mesh is a basic unit (e.g., a triangle or a line) of geometry of a structure.</html>";
                        gui.add(new JLabel(title), BorderLayout.NORTH);
                        final JPanel propertiesPanel = new JPanel(new SpringLayout());
                        propertiesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                        gui.add(propertiesPanel, BorderLayout.CENTER);
                        // index mode
                        JLabel label = new JLabel("Index Mode: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        JTextField textField = new JTextField(m.getMeshData().getIndexMode(0) + "", 5);
                        textField.setEditable(false);
                        label.setLabelFor(textField);
                        propertiesPanel.add(textField);
                        // vertex count
                        label = new JLabel("Vertex Count: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        textField = new JTextField(m.getMeshData().getVertexCount() + "", 5);
                        textField.setEditable(false);
                        label.setLabelFor(textField);
                        propertiesPanel.add(textField);
                        // normal
                        label = new JLabel("Normal Vector: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        final ReadOnlyVector3 normal = ((UserData) m.getUserData()).getNormal();
                        textField = new JTextField("(" + threeDecimalsFormat.format(normal.getX()) + ", " + threeDecimalsFormat.format(normal.getY()) + ", " + threeDecimalsFormat.format(normal.getZ()) + "), relative", 5);
                        textField.setEditable(false);
                        label.setLabelFor(textField);
                        propertiesPanel.add(textField);
                        // color
                        label = new JLabel("Color: ", JLabel.TRAILING);
                        propertiesPanel.add(label);
                        final ReadOnlyColorRGBA rgb = m.getDefaultColor();
                        colorChooser.setColor(new Color(Math.round(rgb.getRed() * 255), Math.round(rgb.getGreen() * 255), Math.round(rgb.getBlue() * 255)));
                        label.setLabelFor(colorChooser);
                        propertiesPanel.add(colorChooser);
                        SpringUtilities.makeCompactGrid(propertiesPanel, 4, 2, 6, 6, 6, 6);
                        if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Mesh Properties: " + miInfo.getText(), JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                            final Color color = colorChooser.getColor();
                            m.clearRenderState(StateType.Texture);
                            m.setDefaultColor(new ColorRGBA(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1));
                            final NodeState ns = f.getNodeState(m.getParent());
                            ns.setMeshColor(ud.getMeshIndex(), m.getDefaultColor());
                            f.draw();
                        }
                    }
                }
            }
        });
        final JMenuItem miNodeProperties = new JMenuItem("Node Properties...");
        miNodeProperties.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
                if (selectedPart instanceof Foundation) {
                    final Foundation f = (Foundation) selectedPart;
                    final Mesh m = f.getSelectedMesh();
                    if (m != null) {
                        final Node n = m.getParent();
                        if (n != null) {
                            final NodeState ns = f.getNodeState(n);
                            final JPanel gui = new JPanel(new BorderLayout());
                            final String title = "<html>A node contains a set of meshes that represent<br>the geometry of the structure.</html>";
                            gui.add(new JLabel(title), BorderLayout.NORTH);
                            final JPanel propertiesPanel = new JPanel(new SpringLayout());
                            propertiesPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
                            gui.add(propertiesPanel, BorderLayout.CENTER);
                            // name
                            JLabel label = new JLabel("Name: ", JLabel.TRAILING);
                            propertiesPanel.add(label);
                            final JTextField nameField = new JTextField(ns.getName(), 5);
                            label.setLabelFor(nameField);
                            propertiesPanel.add(nameField);
                            // name
                            label = new JLabel("File: ", JLabel.TRAILING);
                            propertiesPanel.add(label);
                            final JTextField fileField = new JTextField(Util.getFileName(ns.getSourceURL().getPath()), 5);
                            label.setLabelFor(fileField);
                            propertiesPanel.add(fileField);
                            // children count
                            label = new JLabel("Children: ", JLabel.TRAILING);
                            propertiesPanel.add(label);
                            final JTextField textField = new JTextField(n.getNumberOfChildren() + "", 5);
                            textField.setEditable(false);
                            label.setLabelFor(textField);
                            propertiesPanel.add(textField);
                            SpringUtilities.makeCompactGrid(propertiesPanel, 3, 2, 6, 6, 6, 6);
                            if (JOptionPane.showConfirmDialog(MainFrame.getInstance(), gui, "Node Properties", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) {
                                final String nodeName = nameField.getText();
                                if (nodeName != null && !nodeName.trim().equals("")) {
                                    n.setName(nodeName);
                                    f.getNodeState(n).setName(nodeName);
                                } else {
                                    JOptionPane.showMessageDialog(MainFrame.getInstance(), "Node must have a name!", "Name Error", JOptionPane.ERROR_MESSAGE);
                                }
                            }
                        }
                    }
                }
            }
        });
        popupMenuForMesh.add(miInfo);
        popupMenuForMesh.add(miCutNode);
        popupMenuForMesh.add(miPaste);
        popupMenuForMesh.add(miCopyNode);
        popupMenuForMesh.addSeparator();
        popupMenuForMesh.add(miAlignBottom);
        popupMenuForMesh.add(miAlignCenter);
        popupMenuForMesh.add(miMessThickness);
        popupMenuForMesh.add(miNodeProperties);
        popupMenuForMesh.addSeparator();
        popupMenuForMesh.add(miDeleteMesh);
        popupMenuForMesh.add(miReverseNormalVector);
        popupMenuForMesh.add(miRestoreDeletedMeshes);
        popupMenuForMesh.add(miMeshProperties);
    }
    return popupMenuForMesh;
}
Also used : JPanel(javax.swing.JPanel) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) NodeState(org.concord.energy3d.model.NodeState) UserData(org.concord.energy3d.model.UserData) ActionEvent(java.awt.event.ActionEvent) Node(com.ardor3d.scenegraph.Node) PopupMenuListener(javax.swing.event.PopupMenuListener) JTextField(javax.swing.JTextField) PopupMenuEvent(javax.swing.event.PopupMenuEvent) Callable(java.util.concurrent.Callable) Rack(org.concord.energy3d.model.Rack) BorderLayout(java.awt.BorderLayout) Foundation(org.concord.energy3d.model.Foundation) JMenuItem(javax.swing.JMenuItem) HousePart(org.concord.energy3d.model.HousePart) Color(java.awt.Color) Mesh(com.ardor3d.scenegraph.Mesh) JLabel(javax.swing.JLabel) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) JPopupMenu(javax.swing.JPopupMenu) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ActionListener(java.awt.event.ActionListener) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Vector2(com.ardor3d.math.Vector2) SolarPanel(org.concord.energy3d.model.SolarPanel) SpringLayout(javax.swing.SpringLayout)

Example 19 with Vector2

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

the class Foundation method ensureIncludesChildren.

private void ensureIncludesChildren(final Vector3 p, final int index) {
    if (children.isEmpty()) {
        return;
    }
    useOrgPoints = true;
    final List<Vector2> insidePoints = new ArrayList<Vector2>(children.size() * 2);
    for (final HousePart part : children) {
        if (part.children.size() > 2 && part.getPoints().size() > 1) {
            final Vector3 p0 = part.getAbsPoint(0);
            final Vector3 p2 = part.getAbsPoint(2);
            insidePoints.add(new Vector2(p0.getX(), p0.getY()));
            insidePoints.add(new Vector2(p2.getX(), p2.getY()));
        } else {
            // if the child is a solar panel, a rack, or a mirror
            final Vector3 p0 = part.getAbsPoint(0);
            insidePoints.add(new Vector2(p0.getX(), p0.getY()));
        }
    }
    final Vector3 p0 = getAbsPoint(0);
    final Vector3 p1 = getAbsPoint(1);
    final Vector3 p2 = getAbsPoint(2);
    final ReadOnlyVector2 p0_2d = new Vector2(p0.getX(), p0.getY());
    final ReadOnlyVector2 p1_2d = new Vector2(p1.getX(), p1.getY());
    final ReadOnlyVector2 p2_2d = new Vector2(p2.getX(), p2.getY());
    useOrgPoints = false;
    double uScaleMin = Double.MAX_VALUE;
    double uScaleMax = -Double.MAX_VALUE;
    double vScaleMin = Double.MAX_VALUE;
    double vScaleMax = -Double.MAX_VALUE;
    for (final Vector2 insidePoint : insidePoints) {
        final double uScale = Util.projectPointOnLineScale(insidePoint, p0_2d, p2_2d);
        if (uScaleMin > uScale) {
            uScaleMin = uScale;
        }
        if (uScaleMax < uScale) {
            uScaleMax = uScale;
        }
        final double vScale = Util.projectPointOnLineScale(insidePoint, p0_2d, p1_2d);
        if (vScaleMin > vScale) {
            vScaleMin = vScale;
        }
        if (vScaleMax < vScale) {
            vScaleMax = vScale;
        }
    }
    final double uScaleP = Util.projectPointOnLineScale(new Vector2(p.getX(), p.getY()), p0_2d, p2_2d);
    final double vScaleP = Util.projectPointOnLineScale(new Vector2(p.getX(), p.getY()), p0_2d, p1_2d);
    final double uScaleP0 = Util.projectPointOnLineScale(new Vector2(points.get(0).getX(), points.get(0).getY()), p0_2d, p2_2d);
    final double uScaleP2 = Util.projectPointOnLineScale(new Vector2(points.get(2).getX(), points.get(2).getY()), p0_2d, p2_2d);
    final double vScaleP0 = Util.projectPointOnLineScale(new Vector2(points.get(0).getX(), points.get(0).getY()), p0_2d, p1_2d);
    final double vScaleP1 = Util.projectPointOnLineScale(new Vector2(points.get(1).getX(), points.get(1).getY()), p0_2d, p1_2d);
    final boolean isOnRight = uScaleP2 >= uScaleP0 && (index == 2 || index == 3);
    final boolean isOnTop = vScaleP1 >= vScaleP0 && (index == 1 || index == 3);
    final double uScale;
    if (isOnRight && uScaleP < uScaleMax) {
        uScale = uScaleMax;
    } else if (!isOnRight && uScaleP > uScaleMin) {
        uScale = uScaleMin;
    } else {
        uScale = uScaleP;
    }
    final double vScale;
    if (isOnTop && vScaleP < vScaleMax) {
        vScale = vScaleMax;
    } else if (!isOnTop && vScaleP > vScaleMin) {
        vScale = vScaleMin;
    } else {
        vScale = vScaleP;
    }
    final Vector3 u = p2.subtract(p0, null);
    final Vector3 v = p1.subtract(p0, null);
    p.set(p0).addLocal(u.multiplyLocal(uScale)).addLocal(v.multiplyLocal(vScale));
}
Also used : ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 20 with Vector2

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

the class Wall method enforceGablePointsRangeAndRemoveDuplicatedGablePoints.

private void enforceGablePointsRangeAndRemoveDuplicatedGablePoints(final List<Vector3> polygonPoints) {
    final Vector2 min = new Vector2(Math.min(polygonPoints.get(1).getX(), polygonPoints.get(2).getX()), Math.min(polygonPoints.get(1).getY(), polygonPoints.get(2).getY()));
    final Vector2 max = new Vector2(Math.max(polygonPoints.get(1).getX(), polygonPoints.get(2).getX()), Math.max(polygonPoints.get(1).getY(), polygonPoints.get(2).getY()));
    for (int i = 4; i < polygonPoints.size(); i++) {
        final Vector3 tp = polygonPoints.get(i);
        tp.set(Math.max(tp.getX(), min.getX()), Math.max(tp.getY(), min.getY()), tp.getZ());
        tp.set(Math.min(tp.getX(), max.getX()), Math.min(tp.getY(), max.getY()), tp.getZ());
        for (int j = 0; j < i; j++) {
            final Vector3 tpj = polygonPoints.get(j);
            if (Util.isEqual(tpj.getX(), tp.getX()) && Util.isEqual(tpj.getY(), tp.getY())) {
                polygonPoints.remove(i);
                i--;
                break;
            }
        }
    }
}
Also used : Vector2(com.ardor3d.math.Vector2) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArdorVector3Point(org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point) PickingHint(com.ardor3d.scenegraph.hint.PickingHint) TPoint(org.poly2tri.triangulation.point.TPoint) Point(org.poly2tri.geometry.primitives.Point)

Aggregations

Vector2 (com.ardor3d.math.Vector2)23 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)15 Vector3 (com.ardor3d.math.Vector3)12 ReadOnlyVector2 (com.ardor3d.math.type.ReadOnlyVector2)10 Ray3 (com.ardor3d.math.Ray3)9 CullHint (com.ardor3d.scenegraph.hint.CullHint)8 TPoint (org.poly2tri.triangulation.point.TPoint)7 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)6 Point (org.poly2tri.geometry.primitives.Point)6 ArrayList (java.util.ArrayList)5 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)4 HousePart (org.concord.energy3d.model.HousePart)4 PickedHousePart (org.concord.energy3d.model.PickedHousePart)4 PickResults (com.ardor3d.intersection.PickResults)3 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)3 Mesh (com.ardor3d.scenegraph.Mesh)3 Node (com.ardor3d.scenegraph.Node)3 Spatial (com.ardor3d.scenegraph.Spatial)3 FloatBuffer (java.nio.FloatBuffer)3 Canvas (com.ardor3d.framework.Canvas)2