Search in sources :

Example 46 with Node

use of com.ardor3d.scenegraph.Node 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 47 with Node

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

the class Roof method drawAnnotations.

@Override
public void drawAnnotations() {
    if (container == null) {
        return;
    }
    for (final Spatial roofPart : roofPartsRoot.getChildren()) {
        if (roofPart.getSceneHints().getCullHint() != CullHint.Always) {
            int annotCounter = 0, angleAnnotCounter = 0;
            final Node roofPartNode = (Node) roofPart;
            final FloatBuffer buf = ((Mesh) roofPartNode.getChild(0)).getMeshData().getVertexBuffer();
            final ArrayList<ReadOnlyVector3> convexHull = MeshLib.computeOutline(buf);
            final ReadOnlyVector3 normal = (ReadOnlyVector3) roofPart.getUserData();
            final int n = convexHull.size();
            for (int i = 0; i < n; i++) {
                final ReadOnlyVector3 p1 = convexHull.get(i);
                final ReadOnlyVector3 p2 = convexHull.get((i + 1) % n);
                final ReadOnlyVector3 p3 = convexHull.get((i + 2) % n);
                // Size annotation
                final ReadOnlyVector3 center = p1.add(p2, null).addLocal(p3).multiplyLocal(1.0 / 3.0);
                final SizeAnnotation sizeAnnot = fetchSizeAnnot(annotCounter++, (Node) roofPartNode.getChild(1));
                final boolean drawAnnotationsInside = Scene.isDrawAnnotationsInside();
                sizeAnnot.setRange(p2, p3, center, normal, false, Align.Center, true, true, drawAnnotationsInside);
                sizeAnnot.setLineWidth(original == null ? 1f : 2f);
                if (drawAnnotationsInside) {
                    sizeAnnot.setColor(ColorRGBA.WHITE);
                } else {
                    sizeAnnot.setColor(ColorRGBA.BLACK);
                }
                // Angle annotations
                final AngleAnnotation angleAnnot = fetchAngleAnnot(angleAnnotCounter++, (Node) roofPartNode.getChild(2));
                angleAnnot.setLineWidth(original == null ? 1f : 2f);
                angleAnnot.setRange(p2, p1, p3, normal);
            }
        }
    }
}
Also used : ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) FloatBuffer(java.nio.FloatBuffer) AngleAnnotation(org.concord.energy3d.shapes.AngleAnnotation) SizeAnnotation(org.concord.energy3d.shapes.SizeAnnotation) CullHint(com.ardor3d.scenegraph.hint.CullHint) TPoint(org.poly2tri.triangulation.point.TPoint) TriangulationPoint(org.poly2tri.triangulation.TriangulationPoint) PolygonPoint(org.poly2tri.geometry.polygon.PolygonPoint)

Example 48 with Node

use of com.ardor3d.scenegraph.Node 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 49 with Node

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

the class HousePart method init.

/* if an attribute is transient but is always needed then it should be set to default here */
protected void init() {
    orgHeight = height;
    flattenCenter = new Vector3();
    isPrintVertical = false;
    if (id == 0) {
        id = Scene.getInstance().nextID();
    }
    root = new Node(toString());
    pointsRoot = new Node("Edit Points");
    sizeAnnotRoot = new Node("Size Annotations");
    sizeAnnotRoot.getSceneHints().setAllPickingHints(false);
    angleAnnotRoot = new Node("Angle Annotations");
    angleAnnotRoot.getSceneHints().setAllPickingHints(false);
    labelsRoot = new Node("Labels");
    labelsRoot.getSceneHints().setAllPickingHints(false);
    setAnnotationsVisible(Scene.getInstance().areAnnotationsVisible());
    // Set up a reusable pick results
    for (int i = 0; i < points.size(); i++) {
        addNewEditPointShape(i);
    }
    root.attachChild(pointsRoot);
    root.attachChild(sizeAnnotRoot);
    root.attachChild(angleAnnotRoot);
    root.attachChild(labelsRoot);
    gridsMesh = new Line("Grids");
    gridsMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(2));
    gridsMesh.setDefaultColor(new ColorRGBA(0, 0, 1, 0.25f));
    gridsMesh.setModelBound(null);
    final BlendState blendState = new BlendState();
    blendState.setBlendEnabled(true);
    gridsMesh.setRenderState(blendState);
    gridsMesh.getSceneHints().setRenderBucketType(RenderBucketType.Transparent);
    Util.disablePickShadowLight(gridsMesh);
    root.attachChild(gridsMesh);
    setGridsVisible(false);
    heatFlux = new Line("Heat Flux");
    heatFlux.setLineWidth(1);
    heatFlux.setModelBound(null);
    Util.disablePickShadowLight(heatFlux);
    heatFlux.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    heatFlux.setDefaultColor(ColorRGBA.YELLOW);
    root.attachChild(heatFlux);
    if (color == null) {
        if (this instanceof Foundation) {
            color = Scene.getInstance().getFoundationColor();
        } else if (this instanceof Door) {
            color = Scene.getInstance().getDoorColor();
        } else if (this instanceof Roof) {
            color = Scene.getInstance().getRoofColor();
        } else if (this instanceof Wall) {
            color = Scene.getInstance().getWallColor();
        } else {
            color = ColorRGBA.LIGHT_GRAY;
        }
    }
}
Also used : Line(com.ardor3d.scenegraph.Line) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Node(com.ardor3d.scenegraph.Node) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) BlendState(com.ardor3d.renderer.state.BlendState)

Example 50 with Node

use of com.ardor3d.scenegraph.Node 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

Node (com.ardor3d.scenegraph.Node)50 Mesh (com.ardor3d.scenegraph.Mesh)31 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)27 Spatial (com.ardor3d.scenegraph.Spatial)26 Vector3 (com.ardor3d.math.Vector3)20 CullHint (com.ardor3d.scenegraph.hint.CullHint)20 Foundation (org.concord.energy3d.model.Foundation)12 FloatBuffer (java.nio.FloatBuffer)11 ArrayList (java.util.ArrayList)11 Line (com.ardor3d.scenegraph.Line)10 HousePart (org.concord.energy3d.model.HousePart)10 TPoint (org.poly2tri.triangulation.point.TPoint)10 OrientedBoundingBox (com.ardor3d.bounding.OrientedBoundingBox)9 ColorRGBA (com.ardor3d.math.ColorRGBA)7 ReadOnlyColorRGBA (com.ardor3d.math.type.ReadOnlyColorRGBA)7 BoundingBox (com.ardor3d.bounding.BoundingBox)6 BMText (com.ardor3d.ui.text.BMText)6 List (java.util.List)6 Rack (org.concord.energy3d.model.Rack)6 Roof (org.concord.energy3d.model.Roof)6