Search in sources :

Example 81 with Vector3

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

the class Wall method reduceBackMeshWidth.

private void reduceBackMeshWidth(final List<Vector3> polygon, final ReadOnlyVector3 wallDir, final int neighbor) {
    final Snap snap = neighbors[neighbor];
    final int neighborPointIndex = snap.getSnapPointIndexOfNeighborOf(this);
    final Wall otherWall = snap.getNeighborOf(this);
    final Vector3 otherWallDir = otherWall.getAbsPoint(neighborPointIndex == 0 ? 2 : 0).subtract(otherWall.getAbsPoint(neighborPointIndex), null).normalizeLocal();
    final double angle = Math.max(0.1, otherWallDir.smallestAngleBetween(wallDir));
    final double angle360;
    if (wallDir.dot(otherWall.getThicknessNormal().normalize(null)) < 0) {
        angle360 = Math.PI + angle;
    } else {
        angle360 = angle;
    }
    final boolean reverse = angle360 >= Math.PI;
    final double length = wallThickness * Math.tan((Math.PI - angle) / 2) * (reverse ? -1 : 1);
    final Vector3 v = wallDir.normalize(null).multiplyLocal(length);
    final Vector3 p1 = polygon.get(neighbor == 0 ? 1 : 2);
    final Vector3 p2 = polygon.get(neighbor == 0 ? 0 : 3);
    // now reduce the actual wall points
    p1.set(p1.getX() + v.getX(), p1.getY() + v.getY(), p1.getZ());
    p2.set(p2.getX() + v.getX(), p2.getY() + v.getY(), p2.getZ());
}
Also used : 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)

Example 82 with Vector3

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

the class Wall method drawSteelFrame.

private void drawSteelFrame(final double size, final int n) {
    steelFrame.setDefaultColor(getColor());
    final FloatBuffer vertexBuffer = steelFrame.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = steelFrame.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final ReadOnlyVector3 p0 = getAbsPoint(0);
    final ReadOnlyVector3 p1 = getAbsPoint(1);
    final ReadOnlyVector3 p2 = getAbsPoint(2);
    final ReadOnlyVector3 p3 = getAbsPoint(3);
    final Vector3 d10 = p1.subtract(p0, null);
    final Vector3 d32 = p3.subtract(p2, null);
    d10.setZ(d10.getZ() / n);
    d32.setZ(d32.getZ() / n);
    final Vector3 dir = d10.normalize(null).multiplyLocal(size);
    for (int i = 0; i < n; i++) {
        final Vector3 a = p0.add(d10.multiply(1, 1, i, null), null);
        final Vector3 b = p2.add(d32.multiply(1, 1, i, null), null);
        Util.addPointToQuad(normal, a, b, dir, vertexBuffer, normalBuffer);
        final Vector3 c = p2.add(d32.multiply(1, 1, i + 1, null), null);
        Util.addPointToQuad(normal, a, c, dir, vertexBuffer, normalBuffer);
        final Vector3 d = p0.add(d10.multiply(1, 1, i + 1, null), null);
        Util.addPointToQuad(normal, b, d, dir, vertexBuffer, normalBuffer);
    }
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    steelFrame.getMeshData().updateVertexCount();
    steelFrame.updateModelBound();
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) FloatBuffer(java.nio.FloatBuffer) 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)

Example 83 with Vector3

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

the class Wall method drawBackMesh.

private void drawBackMesh(final List<List<Vector3>> polygon) {
    final Vector3 dir = getAbsPoint(2).subtract(getAbsPoint(0), null).normalizeLocal();
    if (neighbors[0] != null && neighbors[0].getNeighborOf(this).isFirstPointInserted() && !(Scene.getInstance().isDrawThickness() && isShortWall && isPerpendicularToNeighbor(0))) {
        reduceBackMeshWidth(polygon.get(0), dir, 0);
    }
    if (neighbors[1] != null && neighbors[1].getNeighborOf(this).isFirstPointInserted() && !(Scene.getInstance().isDrawThickness() && isShortWall && isPerpendicularToNeighbor(1))) {
        dir.normalizeLocal().negateLocal();
        reduceBackMeshWidth(polygon.get(0), dir, 1);
    }
    enforceGablePointsRangeAndRemoveDuplicatedGablePoints(polygon.get(0));
    stretchToRoof(polygon.get(0));
    /* lower the z of back wall to ensure it doesn't stick up through the roof */
    if (roof != null) {
        for (final Vector3 p : polygon.get(0)) {
            p.setZ(p.getZ() - 0.3);
        }
    }
    drawPolygon(polygon, backMesh, true, true, false);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 84 with Vector3

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

the class Wall method getThicknessNormal.

public Vector3 getThicknessNormal() {
    if (thicknessNormal != null) {
        return thicknessNormal;
    }
    computeNormalAndXYTransform();
    final Vector3 n = normal.clone();
    final Snap neighbor;
    final int whichNeighbor;
    if (editPointIndex == 0 || editPointIndex == 1) {
        /*
			 * if edit point has snapped to a new wall then use the angle with new wall to determine inside direction of this wall otherwise use the angle with the other wall attached to none moving corner of the this wall
			 */
        if (neighbors[0] == null) {
            whichNeighbor = 1;
        } else {
            whichNeighbor = 0;
        }
    } else {
        if (neighbors[1] == null) {
            whichNeighbor = 0;
        } else {
            whichNeighbor = 1;
        }
    }
    neighbor = neighbors[whichNeighbor];
    if (neighbor != null && neighbor.getNeighborOf(this).getPoints().size() >= 4) {
        final HousePart other = neighbor.getNeighborOf(this);
        final int otherPointIndex = neighbor.getSnapPointIndexOfNeighborOf(this);
        final Vector3 otherWallDir = other.getAbsPoint(otherPointIndex == 0 ? 2 : 0).subtract(other.getAbsPoint(otherPointIndex), null).normalizeLocal();
        if (n.dot(otherWallDir) < 0) {
            n.negateLocal();
        }
    } else {
        final ReadOnlyVector3 camera = SceneManager.getInstance().getCamera().getDirection();
        if (camera.dot(n) < 0) {
            n.negateLocal();
        }
    }
    n.multiplyLocal(wallThickness);
    thicknessNormal = n;
    return thicknessNormal;
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) 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)

Example 85 with Vector3

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

the class Wall method drawWindowsSurroundMesh.

private void drawWindowsSurroundMesh(final Vector3 thickness) {
    int numOfWindows = 0;
    for (final HousePart child : children) {
        if (child instanceof Window) {
            numOfWindows++;
        }
    }
    final int bufferSize = numOfWindows == 0 ? 1 : (numOfWindows * 4 * 4 * 3);
    FloatBuffer vertexBuffer = windowsSurroundMesh.getMeshData().getVertexBuffer();
    FloatBuffer normalBuffer = windowsSurroundMesh.getMeshData().getNormalBuffer();
    if (vertexBuffer.capacity() != bufferSize) {
        vertexBuffer = BufferUtils.createFloatBuffer(bufferSize);
        normalBuffer = BufferUtils.createFloatBuffer(bufferSize);
        windowsSurroundMesh.getMeshData().setVertexBuffer(vertexBuffer);
        windowsSurroundMesh.getMeshData().setNormalBuffer(normalBuffer);
    } else {
        vertexBuffer.rewind();
        normalBuffer.rewind();
        vertexBuffer.limit(vertexBuffer.capacity());
        normalBuffer.limit(vertexBuffer.capacity());
    }
    final int[] order1 = new int[] { 0, 1, 3, 2, 0 };
    final int[] order2 = new int[] { 2, 3, 1, 0, 2 };
    final Vector3 sideNormal = thickness.cross(0, 0, 1, null).normalizeLocal();
    final Vector3 n = new Vector3();
    final Vector3 p = new Vector3();
    final Vector3 wallDirection = getAbsPoint(2).subtract(getAbsPoint(0), null);
    for (final HousePart child : children) {
        if (child instanceof Window && includeWindow(child)) {
            int[] order = order1;
            final Vector3 windowDirection = child.getAbsPoint(2).subtract(child.getAbsPoint(0), null);
            if (windowDirection.dot(wallDirection) < 0) {
                order = order2;
            }
            for (int index = 0; index < order.length - 1; index++) {
                int i = order[index];
                p.set(child.getAbsPoint(i));
                vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
                p.set(child.getAbsPoint(i)).addLocal(thickness);
                vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
                i = order[index + 1];
                p.set(child.getAbsPoint(i)).addLocal(thickness);
                vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
                p.set(child.getAbsPoint(i));
                vertexBuffer.put(p.getXf()).put(p.getYf()).put(p.getZf());
                if (index == 1 || index == 3) {
                    int z = 1;
                    if (index == 1) {
                        z = -z;
                    }
                    final boolean reversedThickness = getAbsPoint(1).subtract(getAbsPoint(0), null).normalizeLocal().crossLocal(wallDirection.normalize(null)).dot(thicknessNormal.normalize(null)) >= 0;
                    if (!reversedThickness) {
                        z = -z;
                    }
                    for (int j = 0; j < 4; j++) {
                        normalBuffer.put(0).put(0).put(z);
                    }
                } else if (index == 0 || index == 2) {
                    n.set(sideNormal);
                    if (index == 2) {
                        n.negateLocal();
                    }
                    for (int j = 0; j < 4; j++) {
                        normalBuffer.put(n.getXf()).put(n.getYf()).put(n.getZf());
                    }
                }
            }
        }
    }
    windowsSurroundMesh.getMeshData().updateVertexCount();
    windowsSurroundMesh.updateModelBound();
}
Also used : FloatBuffer(java.nio.FloatBuffer) 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

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