Search in sources :

Example 66 with Mesh

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

the class Roof method updateDashLinesColor.

public void updateDashLinesColor() {
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            final Node roofPartNode = (Node) roofPart;
            final Mesh dashLinesMesh = (Mesh) roofPartNode.getChild(5);
            dashLinesMesh.setDefaultColor(ColorRGBA.RED);
        }
    }
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh)

Example 67 with Mesh

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

the class Roof method setPrintVertical.

public void setPrintVertical(final Spatial roofPartNode, final boolean isVertical) {
    roofPartPrintVerticalMap.put(roofPartNode, isVertical);
    flattenQuadTriangle((Node) roofPartNode, 1.0);
    roofPartNode.updateGeometricState(0);
    final Mesh roofPartMesh = (Mesh) ((Node) roofPartNode).getChild(0);
    final ReadOnlyVector3 center = computeOrientedBoundingBox(roofPartMesh);
    orgCenters.put((Node) roofPartNode, center);
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Mesh(com.ardor3d.scenegraph.Mesh)

Example 68 with Mesh

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

the class HousePart method computeNormalAndKeepOnSurface.

protected ReadOnlyVector3 computeNormalAndKeepOnSurface() {
    if (container == null) {
        return null;
    }
    if (container instanceof Rack) {
        final Rack rack = (Rack) container;
        final PickResults pickResults = new PrimitivePickResults();
        final Ray3 ray = new Ray3(getAbsPoint(0).multiplyLocal(1, 1, 0), Vector3.UNIT_Z);
        PickingUtil.findPick(container.getCollisionSpatial(), ray, pickResults, false);
        if (pickResults.getNumber() != 0) {
            final PickData pickData = pickResults.getPickData(0);
            final Vector3 p = pickData.getIntersectionRecord().getIntersectionPoint(0);
            points.get(0).setZ(p.getZ());
        } else {
            if (rack.getBaseHeight() < Math.abs(0.5 * rack.getRackHeight() / Scene.getInstance().getAnnotationScale() * Math.sin(Math.toRadians(rack.getTiltAngle())))) {
                final Ray3 ray2 = new Ray3(getAbsPoint(0).multiplyLocal(1, 1, 0), Vector3.NEG_UNIT_Z);
                PickingUtil.findPick(container.getCollisionSpatial(), ray2, pickResults, false);
                if (pickResults.getNumber() != 0) {
                    final PickData pickData = pickResults.getPickData(0);
                    final Vector3 p = pickData.getIntersectionRecord().getIntersectionPoint(0);
                    points.get(0).setZ(p.getZ());
                }
            }
        }
        return rack.getNormal();
    } else if (container instanceof Roof) {
        final Roof roof = (Roof) container;
        final int[] editPointToRoofIndex = new int[points.size()];
        final PickResults pickResults = new PrimitivePickResults();
        for (int i = 0; i < points.size(); i++) {
            pickResults.clear();
            final Ray3 ray = new Ray3(getAbsPoint(i).multiplyLocal(1, 1, 0), Vector3.UNIT_Z);
            for (final Spatial roofPart : roof.getRoofPartsRoot().getChildren()) {
                if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
                    PickingUtil.findPick(((Node) roofPart).getChild(0), ray, pickResults, false);
                    if (pickResults.getNumber() != 0) {
                        break;
                    }
                }
            }
            if (pickResults.getNumber() != 0) {
                final PickData pickData = pickResults.getPickData(0);
                final Vector3 p = pickData.getIntersectionRecord().getIntersectionPoint(0);
                points.get(i).setZ(p.getZ());
                final UserData userData = (UserData) ((Spatial) pickData.getTarget()).getUserData();
                final int roofPartIndex = userData.getEditPointIndex();
                editPointToRoofIndex[i] = roofPartIndex;
            }
            // find roofPart with most edit points on it
            containerRoofIndex = editPointToRoofIndex[0];
            if (points.size() > 1) {
                containerRoofIndex = 0;
                final Map<Integer, Integer> counts = new HashMap<Integer, Integer>(points.size());
                for (final int roofIndex : editPointToRoofIndex) {
                    counts.put(roofIndex, counts.get(roofIndex) == null ? 1 : counts.get(roofIndex) + 1);
                }
                int highestCount = 0;
                for (final int roofIndex : editPointToRoofIndex) {
                    if (counts.get(roofIndex) > highestCount) {
                        highestCount = counts.get(roofIndex);
                        containerRoofIndex = roofIndex;
                    }
                }
            }
        }
        return (ReadOnlyVector3) roof.getRoofPartsRoot().getChild(containerRoofIndex).getUserData();
    } else if (container instanceof Foundation) {
        final Foundation foundation = (Foundation) container;
        final List<Node> nodes = foundation.getImportedNodes();
        if (nodes != null) {
            final Map<Vector3, ReadOnlyVector3> intersections = new HashMap<Vector3, ReadOnlyVector3>();
            final PickResults pickResults = new PrimitivePickResults();
            for (final Node n : nodes) {
                for (final Spatial s : n.getChildren()) {
                    if (s instanceof Mesh) {
                        final Mesh m = (Mesh) s;
                        pickResults.clear();
                        PickingUtil.findPick(m, new Ray3(getAbsPoint(0).multiplyLocal(1, 1, 0), Vector3.UNIT_Z), pickResults, false);
                        if (pickResults.getNumber() > 0) {
                            intersections.put(pickResults.getPickData(0).getIntersectionRecord().getIntersectionPoint(0), ((UserData) m.getUserData()).getNormal());
                        }
                    }
                }
            }
            if (!intersections.isEmpty()) {
                double zmax = -Double.MAX_VALUE;
                ReadOnlyVector3 normal = null;
                for (final Vector3 v : intersections.keySet()) {
                    if (v.getZ() > zmax) {
                        zmax = v.getZ();
                        normal = intersections.get(v);
                    }
                }
                if (normal != null) {
                    pickedNormal = normal;
                    return normal;
                }
            }
        }
    }
    return container.getNormal();
}
Also used : HashMap(java.util.HashMap) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) PickData(com.ardor3d.intersection.PickData) Ray3(com.ardor3d.math.Ray3) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) PickResults(com.ardor3d.intersection.PickResults) Map(java.util.Map) HashMap(java.util.HashMap)

Example 69 with Mesh

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

the class MeshLocator method find.

public Mesh find() {
    if (foundation.getImportedNodes() == null || foundation.getImportedNodes().isEmpty()) {
        return null;
    }
    Node node = null;
    for (final Node n : foundation.getImportedNodes()) {
        if (n.getNumberOfChildren() > 0) {
            final Spatial s = n.getChild(0);
            final Mesh m = (Mesh) s;
            final UserData u = (UserData) m.getUserData();
            if (u.getNodeIndex() == nodeIndex) {
                node = n;
                break;
            }
        }
    }
    if (node != null) {
        for (final Spatial s : node.getChildren()) {
            final Mesh m = (Mesh) s;
            final UserData u = (UserData) m.getUserData();
            if (u.getMeshIndex() == meshIndex) {
                return m;
            }
        }
    }
    return null;
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh)

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