Search in sources :

Example 51 with Mesh

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

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

the class Foundation method updateTextureAndColor.

@Override
public void updateTextureAndColor() {
    for (final Mesh mesh : sideMesh) {
        mesh.setDefaultColor(Scene.getInstance().getTextureMode() == TextureMode.Full ? ColorRGBA.GRAY : (getColor() == null ? Scene.getInstance().getFoundationColor() : getColor()));
        updateTextureAndColor(mesh, getColor() == null ? Scene.getInstance().getFoundationColor() : getColor());
    }
    updateTextureAndColor(mesh, getColor() == null ? Scene.getInstance().getFoundationColor() : getColor());
    if (!SceneManager.getInstance().getSolarHeatMap() && importedNodes != null) {
        final int n = importedNodes.size();
        if (n > 0) {
            Node ni;
            for (int i = 0; i < n; i++) {
                ni = importedNodes.get(i);
                if (root.getChildren().contains(ni)) {
                    for (final Spatial s : ni.getChildren()) {
                        if (s instanceof Mesh) {
                            if (s instanceof Line) {
                                continue;
                            }
                            final Mesh m = (Mesh) s;
                            final UserData ud = (UserData) m.getUserData();
                            final TextureState ts = (TextureState) m.getLocalRenderState(StateType.Texture);
                            if (ts == null || ts.getTexture() == null) {
                                m.clearRenderState(StateType.Texture);
                            // m.setDefaultColor(nis.getDefaultColor());
                            } else {
                                if (ud.getTextureBuffer() == null || Util.isZero(ud.getTextureBuffer())) {
                                    m.clearRenderState(StateType.Texture);
                                // m.setDefaultColor(nis.getDefaultColor());
                                } else {
                                    m.getMeshData().setTextureBuffer(ud.getTextureBuffer(), 0);
                                    m.setRenderState(ud.getRenderState());
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Line(com.ardor3d.scenegraph.Line) TextureState(com.ardor3d.renderer.state.TextureState) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 53 with Mesh

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

the class Foundation method deleteNode.

public void deleteNode(final Node n) {
    final List<HousePart> toDelete = new ArrayList<HousePart>();
    for (final HousePart p : children) {
        if (p instanceof Meshable) {
            final MeshLocator l = ((Meshable) p).getMeshLocator();
            if (l != null) {
                final Mesh m = l.find();
                if (m != null && n.hasChild(m)) {
                    toDelete.add(p);
                }
            }
        }
    }
    if (!toDelete.isEmpty()) {
        for (final HousePart p : toDelete) {
            Scene.getInstance().remove(p, false);
        }
    }
    final DeleteNodeCommand c = new DeleteNodeCommand(n, this, toDelete);
    n.getParent().detachChild(n);
    final int i = importedNodes.indexOf(n);
    importedNodes.remove(n);
    importedNodeStates.remove(i);
    clearSelectedMesh();
    draw();
    SceneManager.getInstance().getUndoManager().addEdit(c);
}
Also used : DeleteNodeCommand(org.concord.energy3d.undo.DeleteNodeCommand) ArrayList(java.util.ArrayList) Mesh(com.ardor3d.scenegraph.Mesh) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 54 with Mesh

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

the class Foundation method importCollada.

public Node importCollada(final URL file, final Vector3 position) throws Exception {
    if (importedNodes == null) {
        importedNodes = new ArrayList<Node>();
    }
    if (importedNodeStates == null) {
        importedNodeStates = new ArrayList<NodeState>();
    }
    if (position != null) {
        // when position is null, the cursor is already set to be wait by the loading method
        SceneManager.getInstance().cursorWait(true);
    }
    File sourceFile = new File(file.toURI());
    if (!sourceFile.exists() && Scene.getURL() != null) {
        sourceFile = new File(new File(Scene.getURL().toURI()).getParentFile(), Util.getFileName(file.getPath()).replaceAll("%20", " "));
    }
    if (sourceFile.exists()) {
        final double az = Math.toRadians(getAzimuth());
        final boolean zeroAz = Util.isZero(az);
        // 0.633 is determined by fitting the length in Energy3D to the length in SketchUp
        final double scale = Scene.getInstance().getAnnotationScale() * 0.633;
        final ColladaStorage storage = new ColladaImporter().load(new URLResourceSource(sourceFile.toURI().toURL()));
        final Node originalNode = storage.getScene();
        originalNode.setScale(scale);
        if (position != null) {
            // when position is null, the node uses the position saved in the associated NodeState object
            final NodeState ns = new NodeState();
            ns.setSourceURL(file);
            ns.setAbsolutePosition(position.clone());
            importedNodeStates.add(ns);
            originalNode.setTranslation(position);
            final Vector3 relativePosition = position.subtract(getAbsCenter().multiplyLocal(1, 1, 0), null).addLocal(0, 0, height);
            // why not -getAzimuth()?
            ns.setRelativePosition(zeroAz ? relativePosition : new Matrix3().fromAngles(0, 0, az).applyPost(relativePosition, null));
        }
        // now construct a new node that is a parent of all planar meshes
        final Node newNode = new Node(originalNode.getName());
        final String nodeString = "Node #" + importedNodes.size() + ", Foundation #" + id;
        final List<Mesh> meshes = new ArrayList<Mesh>();
        Util.getMeshes(originalNode, meshes);
        String warnInfo = null;
        final int nodeIndex = importedNodes.size();
        int meshIndex = 0;
        for (final Mesh m : meshes) {
            final ReadOnlyTransform t = m.getWorldTransform();
            final MeshData md = m.getMeshData();
            switch(md.getIndexMode(0)) {
                case Triangles:
                    final List<Mesh> children = TriangleMeshLib.getPlanarMeshes(m);
                    if (!children.isEmpty()) {
                        for (final Mesh s : children) {
                            s.setTransform(t);
                            final UserData ud = new UserData(this, nodeIndex, meshIndex);
                            ud.setNormal((Vector3) s.getUserData());
                            ud.setRenderState(s.getLocalRenderState(StateType.Texture));
                            ud.setTextureBuffer(s.getMeshData().getTextureBuffer(0));
                            s.setUserData(ud);
                            s.setName("Mesh #" + meshIndex + ", " + nodeString);
                            newNode.attachChild(s);
                            meshIndex++;
                        }
                    }
                    break;
                case Lines:
                    break;
                default:
                    warnInfo = md.getIndexMode(0).name();
                    break;
            }
        }
        if (warnInfo != null) {
            JOptionPane.showMessageDialog(MainFrame.getInstance(), "Non-triangular mesh " + warnInfo + " is found.", "Warning", JOptionPane.WARNING_MESSAGE);
        }
        if (newNode.getNumberOfChildren() > 0) {
            importedNodes.add(newNode);
            newNode.setScale(scale);
            newNode.updateWorldTransform(true);
            root.attachChild(newNode);
            createMeshThickness(newNode);
            if (!zeroAz) {
                setRotatedNormalsForImportedMeshes();
            }
            return newNode;
        }
        if (position != null) {
            SceneManager.getInstance().cursorWait(false);
        }
    } else {
        if (position != null) {
            // get rid of the dead nodes no longer linked to files
            for (final Iterator<NodeState> it = importedNodeStates.iterator(); it.hasNext(); ) {
                if (file.equals(it.next().getSourceURL())) {
                    it.remove();
                }
            }
        }
    }
    return null;
}
Also used : Node(com.ardor3d.scenegraph.Node) ColladaImporter(com.ardor3d.extension.model.collada.jdom.ColladaImporter) URLResourceSource(com.ardor3d.util.resource.URLResourceSource) ArrayList(java.util.ArrayList) ReadOnlyTransform(com.ardor3d.math.type.ReadOnlyTransform) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Matrix3(com.ardor3d.math.Matrix3) MeshData(com.ardor3d.scenegraph.MeshData) ColladaStorage(com.ardor3d.extension.model.collada.jdom.data.ColladaStorage) File(java.io.File)

Example 55 with Mesh

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

Aggregations

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