Search in sources :

Example 46 with Vector3

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

the class GambrelRoof method computeEditPoints.

private Vector3[] computeEditPoints(final Wall wall) {
    final Vector3 p1 = wall.getAbsPoint(1);
    final Vector3 p2 = wall.getAbsPoint(3);
    ReadOnlyVector3 p1_overhang = null;
    ReadOnlyVector3 p2_overhang = null;
    double minDistance = Double.MAX_VALUE;
    for (int i = 0; i < wallUpperPoints.size(); i++) {
        final ReadOnlyVector3 pi = wallUpperPoints.get(i);
        final ReadOnlyVector3 pi2 = wallUpperPoints.get((i + 1) % wallUpperPoints.size());
        final double distance1 = p1.distance(pi) + p2.distance(pi2);
        final double distance2 = p1.distance(pi2) + p2.distance(pi);
        if (distance1 < minDistance || distance2 < minDistance) {
            if (distance1 < distance2) {
                p1_overhang = pi;
                p2_overhang = pi2;
                minDistance = distance1;
            } else {
                p1_overhang = pi2;
                p2_overhang = pi;
                minDistance = distance2;
            }
        }
    }
    p1.set(p1_overhang);
    p2.set(p2_overhang);
    final Vector3 p1p2 = p2.subtractLocal(p1);
    final Vector3[] result = new Vector3[3];
    final Vector3 n = wall.getNormal().multiply(-0.1, null);
    result[0] = toRelative(p1p2.multiply(0.25, null).addLocal(p1).addLocal(n));
    result[1] = toRelative(p1p2.multiply(0.5, null).addLocal(p1).addLocal(n));
    result[2] = toRelative(p1p2.multiply(0.75, null).addLocal(p1).addLocal(n));
    return result;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 47 with Vector3

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

the class Scene method pasteToPickedLocationOnRoof.

public void pasteToPickedLocationOnRoof() {
    EnergyPanel.getInstance().updateRadiationHeatMap();
    if (copyBuffer == null) {
        return;
    }
    if (copyBuffer instanceof Foundation) {
        return;
    }
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (!(selectedPart instanceof Roof)) {
        return;
    }
    final HousePart c = copyBuffer.copy(false);
    if (c == null) {
        return;
    }
    Vector3 position = SceneManager.getInstance().getPickedLocationOnRoof();
    if (position == null) {
        return;
    }
    if (selectedPart != c.getContainer()) {
        // solar panels and racks can be pasted to a different parent
        if (c instanceof SolarPanel) {
            ((SolarPanel) c).moveTo(selectedPart);
        } else if (c instanceof Rack) {
            ((Rack) c).moveTo(selectedPart);
        }
    }
    position = c.toRelative(position.subtractLocal(c.getContainer().getAbsPoint(0)));
    final Vector3 center = c.toRelative(c.getAbsCenter().subtractLocal(c.getContainer().getAbsPoint(0)));
    position = position.subtractLocal(center);
    final int n = c.getPoints().size();
    for (int i = 0; i < n; i++) {
        final Vector3 v = c.getPoints().get(i);
        v.addLocal(position);
    }
    if (c instanceof Rack) {
        ((Rack) c).moveSolarPanels(position);
        setIdOfChildren(c);
    }
    add(c, true);
    copyBuffer = c;
    SceneManager.getInstance().setSelectedPart(c);
    SceneManager.getInstance().getUndoManager().addEdit(new PastePartCommand(c));
}
Also used : Rack(org.concord.energy3d.model.Rack) Roof(org.concord.energy3d.model.Roof) SolarPanel(org.concord.energy3d.model.SolarPanel) Foundation(org.concord.energy3d.model.Foundation) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) HousePart(org.concord.energy3d.model.HousePart) PastePartCommand(org.concord.energy3d.undo.PastePartCommand)

Example 48 with Vector3

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

the class Scene method pasteToPickedLocationOnFoundation.

public void pasteToPickedLocationOnFoundation() {
    if (SceneManager.getInstance().getSolarHeatMap()) {
        EnergyPanel.getInstance().updateRadiationHeatMap();
    }
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (!(selectedPart instanceof Foundation)) {
        return;
    }
    final Foundation foundation = (Foundation) selectedPart;
    if (copyNode != null) {
        final Vector3 position = SceneManager.getInstance().getPickedLocationOnFoundation();
        if (position == null) {
            return;
        }
        copyNodeState.setAbsolutePosition(position.clone());
        Node newNode = null;
        try {
            newNode = foundation.importCollada(copyNodeState.getSourceURL(), position);
        } catch (final Throwable t) {
            t.printStackTrace();
        }
        if (newNode != null) {
            // copy the attributes that aren't copied by import
            final NodeState s = foundation.getNodeState(newNode);
            s.setDefaultColor(copyNodeState.getDefaultColor());
            s.setName(copyNodeState.getName());
            if (copyNodeState.getMeshesWithReversedNormal() != null) {
                for (final Integer i : copyNodeState.getMeshesWithReversedNormal()) {
                    s.reverseNormalOfMesh(i);
                    Util.reverseFace(Util.getMesh(newNode, i));
                }
            }
            if (copyNodeState.getDeletedMeshes() != null) {
                for (final Integer i : copyNodeState.getDeletedMeshes()) {
                    foundation.deleteMesh(Util.getMesh(newNode, i));
                }
            }
            final HashMap<Integer, ReadOnlyColorRGBA> meshColors = copyNodeState.getMeshColors();
            if (meshColors != null) {
                for (final Integer i : meshColors.keySet()) {
                    s.setMeshColor(i, meshColors.get(i));
                    Util.getMesh(newNode, i).setDefaultColor(s.getMeshColor(i));
                }
            }
        }
    } else {
        if (copyBuffer != null) {
            final HousePart c = copyBuffer.copy(false);
            if (c == null) {
                return;
            }
            Vector3 position = SceneManager.getInstance().getPickedLocationOnFoundation();
            if (position == null) {
                return;
            }
            // move to this foundation
            c.setContainer(foundation);
            position = c.toRelative(position.subtractLocal(c.getContainer().getAbsPoint(0)));
            final Vector3 center = c.toRelative(c.getAbsCenter().subtractLocal(c.getContainer().getAbsPoint(0)));
            position = position.subtractLocal(center);
            final int n = c.getPoints().size();
            for (int i = 0; i < n; i++) {
                final Vector3 v = c.getPoints().get(i);
                v.addLocal(position);
            }
            if (c instanceof Rack) {
                ((Rack) c).moveSolarPanels(position);
                setIdOfChildren(c);
            }
            add(c, true);
            copyBuffer = c;
            SceneManager.getInstance().setSelectedPart(c);
            SceneManager.getInstance().getUndoManager().addEdit(new PastePartCommand(c));
        }
    }
}
Also used : ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) Rack(org.concord.energy3d.model.Rack) NodeState(org.concord.energy3d.model.NodeState) Node(com.ardor3d.scenegraph.Node) Foundation(org.concord.energy3d.model.Foundation) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) HousePart(org.concord.energy3d.model.HousePart) PastePartCommand(org.concord.energy3d.undo.PastePartCommand)

Example 49 with Vector3

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

the class Scene method pasteToPickedLocationOnLand.

public void pasteToPickedLocationOnLand() {
    if (SceneManager.getInstance().getSolarHeatMap()) {
        EnergyPanel.getInstance().updateRadiationHeatMap();
    }
    if (copyBuffer == null) {
        return;
    }
    final HousePart c = copyBuffer.copy(false);
    if (c == null) {
        return;
    }
    final Vector3 position = SceneManager.getInstance().getPickedLocationOnLand();
    if (position == null) {
        return;
    }
    if (c instanceof Tree || c instanceof Human) {
        c.getPoints().set(0, position);
        add(c, true);
        copyBuffer = c;
        SceneManager.getInstance().getUndoManager().addEdit(new PastePartCommand(c));
    } else if (c instanceof Foundation) {
        // pasting a foundation also clones the building above it
        final Vector3 shift = position.subtractLocal(c.getAbsCenter()).multiplyLocal(1, 1, 0);
        final int n = c.getPoints().size();
        for (int i = 0; i < n; i++) {
            c.getPoints().get(i).addLocal(shift);
        }
        add(c, true);
        // copy gable info, too
        final Foundation oldFoundation = (Foundation) copyBuffer;
        final Foundation newFoundation = (Foundation) c;
        final List<Roof> oldRoofs = oldFoundation.getRoofs();
        final List<Roof> newRoofs = newFoundation.getRoofs();
        if (!oldRoofs.isEmpty() && !newRoofs.isEmpty()) {
            for (int i = 0; i < newRoofs.size(); i++) {
                final Map<Integer, List<Wall>> oldMap = oldRoofs.get(i).getGableEditPointToWallMap();
                if (oldMap == null || oldMap.isEmpty()) {
                    continue;
                }
                final Map<Integer, List<Wall>> newMap = new HashMap<Integer, List<Wall>>();
                for (final Integer key : oldMap.keySet()) {
                    final List<Wall> oldWalls = oldMap.get(key);
                    final List<Wall> newWalls = new ArrayList<Wall>();
                    for (final Wall w : oldWalls) {
                        newWalls.add(getCopiedWall(w, oldFoundation, newFoundation));
                    }
                    newMap.put(key, newWalls);
                }
                newRoofs.get(i).setGableEditPointToWallMap(newMap);
            }
        }
        copyBuffer = c;
        setIdOfChildren(c);
        SceneManager.getInstance().getUndoManager().addEdit(new PastePartCommand(c));
    }
    SceneManager.getInstance().setSelectedPart(c);
}
Also used : Human(org.concord.energy3d.model.Human) Wall(org.concord.energy3d.model.Wall) Tree(org.concord.energy3d.model.Tree) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Foundation(org.concord.energy3d.model.Foundation) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) HousePart(org.concord.energy3d.model.HousePart) PastePartCommand(org.concord.energy3d.undo.PastePartCommand)

Example 50 with Vector3

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

the class Scene method pasteToPickedLocationOnWall.

public void pasteToPickedLocationOnWall() {
    EnergyPanel.getInstance().updateRadiationHeatMap();
    final HousePart selectedPart = SceneManager.getInstance().getSelectedPart();
    if (!(selectedPart instanceof Wall)) {
        return;
    }
    if (copyBuffer == null) {
        return;
    }
    if (copyBuffer instanceof Foundation) {
        return;
    }
    final HousePart c = copyBuffer.copy(false);
    if (c == null) {
        return;
    }
    Vector3 position = SceneManager.getInstance().getPickedLocationOnWall();
    if (position == null) {
        return;
    }
    final Wall wall = (Wall) selectedPart;
    if (wall != c.getContainer()) {
        // windows and solar panels can be pasted to a different wall
        if (c instanceof Window) {
            ((Window) c).moveTo(wall);
        } else if (c instanceof SolarPanel) {
            ((SolarPanel) c).moveTo(wall);
        }
    }
    position = c.toRelative(position.subtractLocal(c.getContainer().getAbsPoint(0)));
    final Vector3 center = c.toRelative(c.getAbsCenter().subtractLocal(c.getContainer().getAbsPoint(0)));
    position = position.subtractLocal(center);
    final int n = c.getPoints().size();
    for (int i = 0; i < n; i++) {
        final Vector3 v = c.getPoints().get(i);
        v.addLocal(position);
    }
    // out of boundary check
    final List<Vector3> polygon = wall.getWallPolygonPoints();
    final List<Vector3> relativePolygon = new ArrayList<Vector3>();
    for (final Vector3 p : polygon) {
        relativePolygon.add(c.toRelative(p));
    }
    for (final Vector3 p : relativePolygon) {
        final double y = p.getY();
        p.setY(p.getZ());
        p.setZ(y);
    }
    for (int i = 0; i < n; i++) {
        final Vector3 v = c.getPoints().get(i);
        if (!Util.insidePolygon(new Vector3(v.getX(), v.getZ(), v.getY()), relativePolygon)) {
            return;
        }
    }
    add(c, true);
    copyBuffer = c;
    SceneManager.getInstance().setSelectedPart(c);
    SceneManager.getInstance().getUndoManager().addEdit(new PastePartCommand(c));
}
Also used : Window(org.concord.energy3d.model.Window) Wall(org.concord.energy3d.model.Wall) SolarPanel(org.concord.energy3d.model.SolarPanel) ArrayList(java.util.ArrayList) Foundation(org.concord.energy3d.model.Foundation) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) HousePart(org.concord.energy3d.model.HousePart) PastePartCommand(org.concord.energy3d.undo.PastePartCommand)

Aggregations

Vector3 (com.ardor3d.math.Vector3)284 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)258 CullHint (com.ardor3d.scenegraph.hint.CullHint)106 FloatBuffer (java.nio.FloatBuffer)69 TPoint (org.poly2tri.triangulation.point.TPoint)41 Point (org.poly2tri.geometry.primitives.Point)35 ArrayList (java.util.ArrayList)34 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)32 Matrix3 (com.ardor3d.math.Matrix3)30 Mesh (com.ardor3d.scenegraph.Mesh)25 Spatial (com.ardor3d.scenegraph.Spatial)24 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)22 Foundation (org.concord.energy3d.model.Foundation)22 Node (com.ardor3d.scenegraph.Node)20 HousePart (org.concord.energy3d.model.HousePart)20 ArdorVector3Point (org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)20 Ray3 (com.ardor3d.math.Ray3)15 PickResults (com.ardor3d.intersection.PickResults)13 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)13 Vector2 (com.ardor3d.math.Vector2)12