Search in sources :

Example 91 with ReadOnlyVector3

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

the class Wall method drawPolygon.

private void drawPolygon(final List<List<Vector3>> wallAndWindowsPoints, final Mesh mesh, final boolean drawHoles, final boolean normal, final boolean texture) {
    final List<PolygonPoint> polygonPoints = new ArrayList<PolygonPoint>(wallAndWindowsPoints.get(0).size());
    for (final Vector3 p : wallAndWindowsPoints.get(0)) {
        final PolygonPoint tp = new PolygonPoint(p.getX(), p.getY(), p.getZ());
        toXY.transform(tp);
        polygonPoints.add(tp);
    }
    final PolygonWithHoles polygon = new PolygonWithHoles(polygonPoints);
    if (drawHoles) {
        for (int i = 1; i < wallAndWindowsPoints.size(); i++) {
            final List<PolygonPoint> holePoints = new ArrayList<PolygonPoint>(wallAndWindowsPoints.get(i).size());
            for (final Vector3 p : wallAndWindowsPoints.get(i)) {
                final PolygonPoint tp = new PolygonPoint(p.getX(), p.getY(), p.getZ());
                toXY.transform(tp);
                holePoints.add(tp);
            }
            polygon.addHole(new Polygon(holePoints));
        }
    }
    if (texture) {
        final double scale = Scene.getInstance().getTextureMode() == TextureMode.Simple ? 1.0 : 8.0;
        final boolean fullTexture = Scene.getInstance().getTextureMode() == TextureMode.Full;
        final ReadOnlyVector3 p0 = getAbsPoint(0);
        final ReadOnlyVector3 p01 = getAbsPoint(1).subtractLocal(p0).normalizeLocal().multiplyLocal(scale * (fullTexture ? 1.5 : 1.0));
        final ReadOnlyVector3 p02 = getAbsPoint(2).subtractLocal(p0).normalizeLocal().multiplyLocal(scale * (fullTexture ? 2.0 : 1.0));
        final TPoint o = new TPoint(p0.getX(), p0.getY(), p0.getZ());
        final TPoint u = new TPoint(p01.getX(), p01.getY(), p01.getZ());
        final TPoint v = new TPoint(p02.getX(), p02.getY(), p02.getZ());
        toXY.transform(o);
        toXY.transform(u);
        MeshLib.fillMeshWithPolygon(mesh, polygon, fromXY, normal, o, u, v, true);
    } else {
        MeshLib.fillMeshWithPolygon(mesh, polygon, fromXY, normal, null, null, null, true);
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint) ArrayList(java.util.ArrayList) PolygonWithHoles(org.concord.energy3d.util.PolygonWithHoles) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Polygon(org.poly2tri.geometry.polygon.Polygon) 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) TPoint(org.poly2tri.triangulation.point.TPoint)

Example 92 with ReadOnlyVector3

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

the class Wall method snapToWall.

protected boolean snapToWall(final Vector3 p, final int index) {
    ReadOnlyVector3 closestPoint = null;
    double closestDistance = Double.MAX_VALUE;
    for (final HousePart housePart : container.getChildren()) {
        if (housePart instanceof Wall && housePart != this) {
            final Wall wall = (Wall) housePart;
            for (int i = 0; i < wall.points.size(); i += 2) {
                final ReadOnlyVector3 p2 = wall.getAbsPoint(i);
                final double distance = p.distance(p2);
                if (distance < closestDistance) {
                    closestPoint = p2;
                    closestDistance = distance;
                }
            }
        }
    }
    final double snapDistance = isSnapToObjects() ? getGridSize() : SNAP_DISTANCE;
    final boolean snap;
    if (isFirstPointInserted() && p.subtract(getAbsPoint(index == 0 ? 2 : 0), null).length() < getGridSize() * 2) {
        snap = false;
    } else if (closestDistance < snapDistance) {
        snap = true;
    } else if (neighbors[index / 2] != null && closestDistance < snapDistance + getGridSize()) {
        snap = true;
    } else {
        snap = false;
    }
    if (snap) {
        p.set(closestPoint);
        return true;
    } else {
        return false;
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) 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 93 with ReadOnlyVector3

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

the class Wall method drawSurroundMesh.

private void drawSurroundMesh(final ReadOnlyVector3 thickness) {
    final boolean drawThicknessAndIsLongWall = Scene.getInstance().isDrawThickness() && !isShortWall;
    final boolean noNeighbor0 = neighbors[0] == null || (drawThicknessAndIsLongWall && isPerpendicularToNeighbor(0));
    final boolean noNeighbor1 = neighbors[1] == null || (drawThicknessAndIsLongWall && isPerpendicularToNeighbor(1));
    final boolean visible = roof == null || noNeighbor0 || noNeighbor1;
    surroundMesh.getSceneHints().setCullHint(visible ? CullHint.Inherit : CullHint.Always);
    if (!visible) {
        if (surroundMesh.getModelBound() != null) {
            surroundMesh.setModelBound(null);
        }
    } else {
        if (surroundMesh.getModelBound() == null) {
            surroundMesh.setModelBound(new BoundingBox());
        }
    }
    if (!visible) {
        return;
    }
    final FloatBuffer vertexBuffer = surroundMesh.getMeshData().getVertexBuffer();
    final FloatBuffer normalBuffer = surroundMesh.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final Vector3 sideNormal = thickness.cross(0, 0, 1, null).normalizeLocal();
    if (noNeighbor0) {
        addSurroundQuad(0, 1, sideNormal.negate(null), thickness, vertexBuffer, normalBuffer);
    }
    if (noNeighbor1) {
        addSurroundQuad(3, 2, sideNormal, thickness, vertexBuffer, normalBuffer);
    }
    if (roof == null) {
        addSurroundQuad(1, 3, Vector3.UNIT_Z, thickness, vertexBuffer, normalBuffer);
    }
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    surroundMesh.getMeshData().updateVertexCount();
    surroundMesh.updateModelBound();
    CollisionTreeManager.INSTANCE.removeCollisionTree(surroundMesh);
}
Also used : BoundingBox(com.ardor3d.bounding.BoundingBox) FloatBuffer(java.nio.FloatBuffer) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3)

Example 94 with ReadOnlyVector3

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

the class Wall method drawAnnotations.

@Override
public void drawAnnotations() {
    if (points.size() < 4) {
        return;
    }
    final ReadOnlyVector3 faceDirection = getNormal();
    int annotCounter = 0;
    int angleAnnotCounter = 0;
    if (wallAndWindowsPoints != null) {
        final List<Vector3> wallPolygonPoints = wallAndWindowsPoints.get(0);
        final Vector3 actualNormal = wallPolygonPoints.get(0).subtract(wallPolygonPoints.get(1), null).normalizeLocal().crossLocal(wallPolygonPoints.get(2).subtract(wallPolygonPoints.get(1), null).normalizeLocal()).negateLocal();
        final boolean reverse = actualNormal.dot(getNormal()) < 0;
        final double lowestWallZ = Math.min(wallPolygonPoints.get(0).getZ(), wallPolygonPoints.get(3).getZ());
        double low = lowestWallZ;
        double hi = Math.max(wallPolygonPoints.get(0).getZ(), wallPolygonPoints.get(3).getZ());
        for (int i = 4; i < wallPolygonPoints.size(); i++) {
            if (wallPolygonPoints.get(i).getZ() < low) {
                low = wallPolygonPoints.get(i).getZ();
            }
            if (wallPolygonPoints.get(i).getZ() > hi) {
                hi = wallPolygonPoints.get(i).getZ();
            }
        }
        final float lineWidth = original == null ? 1f : 2f;
        final boolean isRectangular = hi - low < 0.1;
        ;
        if (isRectangular) {
            final ReadOnlyVector3 p1 = wallPolygonPoints.get(0).multiply(new Vector3(1, 1, 0), null).addLocal(0, 0, lowestWallZ);
            final ReadOnlyVector3 p2 = wallPolygonPoints.get(1);
            final ReadOnlyVector3 p3 = wallPolygonPoints.get(2);
            final ReadOnlyVector3 p4 = wallPolygonPoints.get(3).multiply(new Vector3(1, 1, 0), null).addLocal(0, 0, lowestWallZ);
            final boolean front = false;
            fetchSizeAnnot(annotCounter++).setRange(p1, p2, getCenter(), faceDirection, front, front ? Align.South : Align.Center, true, reverse, Scene.isDrawAnnotationsInside());
            fetchSizeAnnot(annotCounter++).setRange(p2, p3, getCenter(), faceDirection, original == null, original == null ? Align.South : Align.Center, true, reverse, Scene.isDrawAnnotationsInside());
            fetchSizeAnnot(annotCounter++).setRange(p3, p4, getCenter(), faceDirection, front, front ? Align.South : Align.Center, true, reverse, Scene.isDrawAnnotationsInside());
            fetchSizeAnnot(annotCounter++).setRange(p4, p1, getCenter(), faceDirection, front, front ? Align.South : Align.Center, true, reverse, Scene.isDrawAnnotationsInside());
            for (int i = 0; i < annotCounter; i++) {
                fetchSizeAnnot(i).setLineWidth(lineWidth);
            }
            fetchAngleAnnot(angleAnnotCounter++).setRange(p2, p1, p3, getNormal());
            fetchAngleAnnot(angleAnnotCounter++).setRange(p3, p2, p4, getNormal());
            fetchAngleAnnot(angleAnnotCounter++).setRange(p4, p3, p1, getNormal());
            fetchAngleAnnot(angleAnnotCounter++).setRange(p1, p4, p2, getNormal());
            for (int i = 0; i < annotCounter; i++) {
                fetchAngleAnnot(i).setLineWidth(lineWidth);
            }
        } else {
            for (int i = 0; i < wallPolygonPoints.size(); i++) {
                final boolean front = i == 1 && original == null;
                final ReadOnlyVector3 p1 = wallPolygonPoints.get(i);
                final ReadOnlyVector3 p2 = wallPolygonPoints.get((i + 1) % wallPolygonPoints.size());
                final ReadOnlyVector3 p3 = wallPolygonPoints.get((i + 2) % wallPolygonPoints.size());
                final double minLength = 4.0;
                if (p1.distance(p2) > minLength) {
                    final ReadOnlyVector3 min = new Vector3(Math.min(p1.getX(), Math.min(p2.getX(), p3.getX())), Math.min(p1.getY(), Math.min(p2.getY(), p3.getY())), 0);
                    final ReadOnlyVector3 max = new Vector3(Math.max(p1.getX(), Math.max(p2.getX(), p3.getX())), Math.max(p1.getY(), Math.max(p2.getY(), p3.getY())), 0);
                    final ReadOnlyVector3 center = min.add(max, null).divideLocal(2.0).addLocal(0, 0, getCenter().getZ());
                    final SizeAnnotation sizeAnnot = fetchSizeAnnot(annotCounter++);
                    sizeAnnot.setRange(p1, p2, center, faceDirection, front, front ? Align.South : Align.Center, true, reverse, Scene.isDrawAnnotationsInside());
                    sizeAnnot.setLineWidth(lineWidth);
                }
                if (p1.distance(p2) > minLength && p2.distance(p3) > minLength) {
                    final AngleAnnotation angleAnnot = fetchAngleAnnot(angleAnnotCounter++);
                    angleAnnot.setRange(p2, p1, p3, getNormal());
                    angleAnnot.setLineWidth(lineWidth);
                }
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) AngleAnnotation(org.concord.energy3d.shapes.AngleAnnotation) SizeAnnotation(org.concord.energy3d.shapes.SizeAnnotation) 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 95 with ReadOnlyVector3

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

the class Wall method drawColumns.

private void drawColumns(final double distance) {
    columns.setDefaultColor(getColor());
    FloatBuffer vertexBuffer = columns.getMeshData().getVertexBuffer();
    FloatBuffer normalBuffer = columns.getMeshData().getNormalBuffer();
    vertexBuffer.rewind();
    normalBuffer.rewind();
    vertexBuffer.limit(vertexBuffer.capacity());
    normalBuffer.limit(normalBuffer.capacity());
    final ReadOnlyVector3 o = getAbsPoint(0);
    final ReadOnlyVector3 u = getAbsPoint(2).subtract(o, null);
    final ReadOnlyVector3 v = getAbsPoint(1).subtract(o, null);
    final int cols = (int) Math.max(2, u.length() / distance);
    final int bufferSize = 12 * (cols + 1);
    if (bufferSize > vertexBuffer.capacity()) {
        vertexBuffer = BufferUtils.createFloatBuffer(bufferSize);
        columns.getMeshData().setVertexBuffer(vertexBuffer);
        normalBuffer = BufferUtils.createFloatBuffer(bufferSize);
        columns.getMeshData().setNormalBuffer(normalBuffer);
    } else {
        vertexBuffer.rewind();
        normalBuffer.rewind();
    }
    // Vector3 dir = new Vector3(v).normalizeLocal().multiplyLocal(columnRadius);
    // addPointToQuad(getAbsPoint(1), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
    final Vector3 dir = new Vector3(u).normalizeLocal().multiplyLocal(columnRadius);
    Util.addPointToQuad(normal, o, getAbsPoint(1), dir, vertexBuffer, normalBuffer);
    Util.addPointToQuad(normal, getAbsPoint(2), getAbsPoint(3), dir, vertexBuffer, normalBuffer);
    final Vector3 p = new Vector3();
    for (int col = 1; col < cols; col++) {
        u.multiply((double) col / cols, p).addLocal(o);
        Util.addPointToQuad(normal, p, p.add(v, null), dir, vertexBuffer, normalBuffer);
    }
    vertexBuffer.limit(vertexBuffer.position());
    normalBuffer.limit(normalBuffer.position());
    columns.getMeshData().updateVertexCount();
    columns.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)

Aggregations

ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)125 Vector3 (com.ardor3d.math.Vector3)88 CullHint (com.ardor3d.scenegraph.hint.CullHint)60 FloatBuffer (java.nio.FloatBuffer)45 TPoint (org.poly2tri.triangulation.point.TPoint)44 Point (org.poly2tri.geometry.primitives.Point)34 PolygonPoint (org.poly2tri.geometry.polygon.PolygonPoint)32 Mesh (com.ardor3d.scenegraph.Mesh)25 Spatial (com.ardor3d.scenegraph.Spatial)25 ArrayList (java.util.ArrayList)23 Node (com.ardor3d.scenegraph.Node)18 PickingHint (com.ardor3d.scenegraph.hint.PickingHint)18 Ray3 (com.ardor3d.math.Ray3)16 PickResults (com.ardor3d.intersection.PickResults)15 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)15 ArdorVector3Point (org.poly2tri.triangulation.point.ardor3d.ArdorVector3Point)15 TriangulationPoint (org.poly2tri.triangulation.TriangulationPoint)13 Matrix3 (com.ardor3d.math.Matrix3)10 CancellationException (java.util.concurrent.CancellationException)10 Vector2 (com.ardor3d.math.Vector2)9