Search in sources :

Example 1 with Meshable

use of org.concord.energy3d.model.Meshable in project energy3d by concord-consortium.

the class SceneManager method mouseMoved.

private void mouseMoved() {
    if (!mouseControlEnabled) {
        return;
    }
    final int x = mouseState.getX();
    final int y = mouseState.getY();
    if (Scene.getInstance().getDisableShadowInAction()) {
        if (mouseState.getButtonState(MouseButton.LEFT) == ButtonState.DOWN || mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.DOWN) {
            if (MainPanel.getInstance().getShadowButton().isSelected()) {
                shadowPass.setEnabled(false);
            }
        } else {
            if (MainPanel.getInstance().getShadowButton().isSelected()) {
                shadowPass.setEnabled(true);
            }
        }
    }
    try {
        if (selectedPart != null) {
            if (!selectedPart.isDrawCompleted()) {
                selectedPart.setPreviewPoint(x, y);
                if (selectedPart instanceof Meshable) {
                    // don't draw grid if it sits on an imported mesh
                    selectedPart.setGridsVisible(((Meshable) selectedPart).getMeshLocator() == null);
                }
            } else if (objectMoveStartPoint != null) {
                if ((operation == Operation.RESIZE || selectedPart instanceof Foundation)) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
                    if (pick != null) {
                        if (selectedPart instanceof Foundation) {
                            final Foundation foundation = (Foundation) selectedPart;
                            final Vector3 pickPoint = pick.getPoint().clone();
                            // if (!foundation.insideBuilding(pickPoint.getX(), pickPoint.getY(), true)) { // only move the building when clicking outside
                            final Vector3 d = pickPoint.multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
                            if (foundation.isGroupMaster()) {
                                final List<Foundation> g = Scene.getInstance().getFoundationGroup(foundation);
                                for (final Foundation f : g) {
                                    final ArrayList<Vector3> movePoints = objectGroupMovePoints.get(f);
                                    if (movePoints != null) {
                                        // just in case this foundation's move point hasn't been included yet
                                        f.move(d, movePoints);
                                    }
                                }
                            } else {
                                foundation.move(d, objectMovePoints);
                            }
                        }
                    }
                } else if (selectedPart instanceof Tree) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, collisionLand);
                    if (pick != null) {
                        final Vector3 d = pick.getPoint().multiply(1, 1, 0, null).subtractLocal(objectMoveStartPoint.multiply(1, 1, 0, null));
                        ((Tree) selectedPart).move(d, objectMovePoints);
                    }
                } else if (selectedPart instanceof Window) {
                    final PickedHousePart pick = SelectUtil.pickPart(x, y, selectedPart.getContainer());
                    if (pick != null) {
                        final Vector3 d = pick.getPoint().subtract(objectMoveStartPoint, null);
                        ((Window) selectedPart).move(d, objectMovePoints);
                    }
                }
            }
        }
        hoveredPart = null;
        if ((operation == Operation.SELECT || operation == Operation.RESIZE) && mouseState.getButtonState(MouseButton.LEFT) == ButtonState.UP && mouseState.getButtonState(MouseButton.MIDDLE) == ButtonState.UP && mouseState.getButtonState(MouseButton.RIGHT) == ButtonState.UP) {
            final PickedHousePart pickedPart = SelectUtil.selectHousePart(x, y, false);
            pick = pickedPart == null ? null : pickedPart.getUserData();
            final HousePart housePart = pick == null ? null : pick.getHousePart();
            if (pick != null) {
                hoveredPart = housePart;
                if (pick.getEditPointIndex() != -1) {
                    lastSelectedEditPointMouseState = mouseState;
                }
            }
        }
        mouseState = null;
    } catch (final Throwable t) {
        t.printStackTrace();
        BugReporter.report(t);
    }
    EventQueue.invokeLater(new // this method is run by the main Energy3D thread, so invoke the Swing code later
    Runnable() {

        @Override
        public void run() {
            final Component canvasComponent = (Component) canvas;
            canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
            if (!zoomLock && (operation == Operation.SELECT || operation == Operation.RESIZE) && hoveredPart != null) {
                if (hoveredPart instanceof Tree || hoveredPart instanceof Human) {
                    canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                } else if (hoveredPart instanceof SolarCollector) {
                    if (pick.getEditPointIndex() >= 0) {
                        canvasComponent.setCursor(Cursor.getPredefinedCursor(pick.getEditPointIndex() == 0 ? Cursor.MOVE_CURSOR : Cursor.HAND_CURSOR));
                    }
                } else {
                    if (pick.getEditPointIndex() == -1) {
                        if (hoveredPart instanceof Window) {
                            // for windows, there is no apparent move point
                            canvasComponent.setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
                        }
                    }
                }
            }
        }
    });
}
Also used : Window(org.concord.energy3d.model.Window) Human(org.concord.energy3d.model.Human) ArrayList(java.util.ArrayList) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Meshable(org.concord.energy3d.model.Meshable) SolarCollector(org.concord.energy3d.model.SolarCollector) Tree(org.concord.energy3d.model.Tree) Foundation(org.concord.energy3d.model.Foundation) ArrayList(java.util.ArrayList) List(java.util.List) Component(java.awt.Component) PickedHousePart(org.concord.energy3d.model.PickedHousePart) HousePart(org.concord.energy3d.model.HousePart) PickedHousePart(org.concord.energy3d.model.PickedHousePart)

Aggregations

Vector3 (com.ardor3d.math.Vector3)1 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)1 CullHint (com.ardor3d.scenegraph.hint.CullHint)1 Component (java.awt.Component)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Foundation (org.concord.energy3d.model.Foundation)1 HousePart (org.concord.energy3d.model.HousePart)1 Human (org.concord.energy3d.model.Human)1 Meshable (org.concord.energy3d.model.Meshable)1 PickedHousePart (org.concord.energy3d.model.PickedHousePart)1 SolarCollector (org.concord.energy3d.model.SolarCollector)1 Tree (org.concord.energy3d.model.Tree)1 Window (org.concord.energy3d.model.Window)1