Search in sources :

Example 6 with Node

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

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

the class SceneManager method createAxes.

private Spatial createAxes() {
    final int axisLen = SKY_RADIUS;
    final Node axisRoot = new Node();
    FloatBuffer buf;
    Line line;
    // X-Axis
    buf = BufferUtils.createVector3Buffer(2);
    buf.put(-axisLen).put(0).put(0);
    buf.put(axisLen).put(0).put(0);
    line = new Line("X-Axis", buf, null, null, null);
    line.setDefaultColor(ColorRGBA.RED);
    Util.disablePickShadowLight(line);
    line.setModelBound(new BoundingBox());
    line.updateModelBound();
    axisRoot.attachChild(line);
    // Y-Axis
    buf = BufferUtils.createVector3Buffer(2);
    buf.put(0).put(-axisLen).put(0);
    buf.put(0).put(axisLen).put(0);
    line = new Line("Y-Axis", buf, null, null, null);
    line.setDefaultColor(ColorRGBA.GREEN);
    Util.disablePickShadowLight(line);
    line.setModelBound(new BoundingBox());
    line.updateModelBound();
    axisRoot.attachChild(line);
    // Z-Axis
    buf = BufferUtils.createVector3Buffer(2);
    buf.put(0).put(0).put(-axisLen);
    buf.put(0).put(0).put(axisLen);
    line = new Line("Z-Axis", buf, null, null, null);
    Util.disablePickShadowLight(line);
    line.setDefaultColor(ColorRGBA.BLUE);
    line.setModelBound(new BoundingBox());
    line.updateModelBound();
    axisRoot.attachChild(line);
    axisRoot.updateWorldBound(true);
    return axisRoot;
}
Also used : Line(com.ardor3d.scenegraph.Line) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) BoundingBox(com.ardor3d.bounding.BoundingBox) FloatBuffer(java.nio.FloatBuffer) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 8 with Node

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

the class SceneManager method createCompass.

private Node createCompass() throws IOException {
    final ResourceSource source = ResourceLocatorTool.locateResource(ResourceLocatorTool.TYPE_MODEL, "compass.dae");
    final ColladaImporter colladaImporter = new ColladaImporter();
    // Load the collada scene
    Logger.getLogger(ColladaAnimUtils.class.getName()).setLevel(Level.SEVERE);
    Logger.getLogger(ColladaMaterialUtils.class.getName()).setLevel(Level.SEVERE);
    final ColladaStorage storage = colladaImporter.load(source);
    final Node compass = storage.getScene();
    BMText txt;
    final double Z = 0.1;
    txt = new BMText("N", "N", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setTextColor(ColorRGBA.BLACK);
    txt.setAutoRotate(false);
    txt.setTranslation(2, 0.0, Z);
    txt.setRotation(new Matrix3().fromAngles(0.0, MathUtils.HALF_PI, -MathUtils.HALF_PI));
    compass.attachChild(txt);
    txt = new BMText("S", "S", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setTextColor(ColorRGBA.BLACK);
    txt.setAutoRotate(false);
    txt.setTranslation(-2, -0.0, Z);
    txt.setRotation(new Matrix3().fromAngles(0.0, -MathUtils.HALF_PI, MathUtils.HALF_PI));
    compass.attachChild(txt);
    txt = new BMText("W", "W", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setAutoRotate(false);
    txt.setTranslation(-0.0, 2, Z);
    txt.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
    compass.attachChild(txt);
    txt = new BMText("E", "E", FontManager.getInstance().getAnnotationFont(), Align.South);
    txt.setAutoRotate(false);
    txt.setTranslation(-0.0, -2, Z);
    txt.setRotation(new Matrix3().fromAngles(MathUtils.HALF_PI, MathUtils.PI, 0.0));
    compass.attachChild(txt);
    final DirectionalLight light = new DirectionalLight();
    light.setDirection(new Vector3(0, 0, -1));
    light.setEnabled(true);
    final LightState lightState = new LightState();
    lightState.attach(light);
    compass.setRenderState(lightState);
    compass.getSceneHints().setLightCombineMode(LightCombineMode.Replace);
    compass.updateWorldRenderStates(true);
    final Node compassNode = new Node();
    compassNode.setRotation(new Matrix3().fromAngles(-MathUtils.HALF_PI, 0.0, 0.0));
    compassNode.attachChild(compass);
    System.out.println("done");
    compass.addController(new SpatialController<Spatial>() {

        @Override
        public void update(final double time, final Spatial caller) {
            final Vector3 direction = getCamera().getDirection().normalize(null);
            direction.setZ(0);
            direction.normalizeLocal();
            double angle = -direction.smallestAngleBetween(Vector3.UNIT_Y);
            if (direction.dot(Vector3.UNIT_X) > 0) {
                angle = -angle;
            }
            angle -= MathUtils.HALF_PI;
            compass.setRotation(new Matrix3().fromAngles(0.0, 0.0, angle - 0.3));
        }
    });
    return compassNode;
}
Also used : LightState(com.ardor3d.renderer.state.LightState) ColladaImporter(com.ardor3d.extension.model.collada.jdom.ColladaImporter) Node(com.ardor3d.scenegraph.Node) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) Matrix3(com.ardor3d.math.Matrix3) ResourceSource(com.ardor3d.util.resource.ResourceSource) Spatial(com.ardor3d.scenegraph.Spatial) DirectionalLight(com.ardor3d.light.DirectionalLight) ColladaStorage(com.ardor3d.extension.model.collada.jdom.data.ColladaStorage) BMText(com.ardor3d.ui.text.BMText)

Example 9 with Node

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

the class SizeAnnotation method makeCopy.

@Override
public Node makeCopy(final boolean shareGeometricData) {
    // get copy of basic spatial info
    final Node node = super.makeCopy(shareGeometricData);
    // because the above code calls the constructor of this object (which adds 3 children) and then clones the node.children (which then adds extra 3 children) we need to undo the effect of last step
    node.detachChildAt(5);
    node.detachChildAt(4);
    node.detachChildAt(3);
    return node;
}
Also used : Node(com.ardor3d.scenegraph.Node)

Example 10 with Node

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

the class Rack method init.

@Override
protected void init() {
    super.init();
    if (Util.isZero(copyLayoutGap)) {
        // FIXME: Why is a transient member evaluated to zero?
        copyLayoutGap = 1;
    }
    if (Util.isZero(rackWidth)) {
        rackWidth = 4.95;
    }
    if (Util.isZero(rackHeight)) {
        rackHeight = 1.65;
    }
    if (monthlyTiltAngles == null) {
        monthlyTiltAngles = new double[12];
        Arrays.fill(monthlyTiltAngles, tiltAngle);
    }
    mesh = new Mesh("Rack");
    mesh.setDefaultColor(ColorRGBA.LIGHT_GRAY);
    mesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    mesh.getMeshData().setTextureBuffer(BufferUtils.createVector2Buffer(6), 0);
    mesh.setModelBound(new OrientedBoundingBox());
    mesh.setUserData(new UserData(this));
    root.attachChild(mesh);
    surround = new Box("Rack (Surround)");
    surround.setDefaultColor(ColorRGBA.LIGHT_GRAY);
    surround.setModelBound(new OrientedBoundingBox());
    final OffsetState offset = new OffsetState();
    // set a smaller value than solar panel so that the texture doesn't show up on the underside
    offset.setFactor(0.2f);
    offset.setUnits(1);
    surround.setRenderState(offset);
    root.attachChild(surround);
    outlineMesh = new Line("Rack (Outline)");
    outlineMesh.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(8));
    outlineMesh.setDefaultColor(ColorRGBA.BLACK);
    outlineMesh.setModelBound(new OrientedBoundingBox());
    root.attachChild(outlineMesh);
    sunBeam = new Line("Sun Beam");
    sunBeam.setLineWidth(1f);
    sunBeam.setStipplePattern((short) 0xffff);
    sunBeam.setModelBound(null);
    Util.disablePickShadowLight(sunBeam);
    sunBeam.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(4));
    sunBeam.setDefaultColor(new ColorRGBA(1f, 1f, 1f, 1f));
    root.attachChild(sunBeam);
    normalVector = new Line("Normal Vector");
    normalVector.setLineWidth(1f);
    normalVector.setStipplePattern((short) 0xffff);
    normalVector.setModelBound(null);
    Util.disablePickShadowLight(normalVector);
    normalVector.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(6));
    normalVector.setDefaultColor(new ColorRGBA(1f, 1f, 0f, 1f));
    root.attachChild(normalVector);
    angles = new Node("Angles");
    angles.getSceneHints().setAllPickingHints(false);
    Util.disablePickShadowLight(angles);
    root.attachChild(angles);
    // the angle between the sun beam and the normal vector
    sunAngle = new AngleAnnotation();
    sunAngle.setColor(ColorRGBA.WHITE);
    sunAngle.setLineWidth(1);
    sunAngle.setFontSize(1);
    sunAngle.setCustomRadius(normalVectorLength * 0.8);
    angles.attachChild(sunAngle);
    solarPanelOutlines = new Line("Solar Panel Outlines");
    solarPanelOutlines.setLineWidth(1f);
    solarPanelOutlines.setStipplePattern((short) 0xffff);
    solarPanelOutlines.setModelBound(null);
    Util.disablePickShadowLight(solarPanelOutlines);
    solarPanelOutlines.getMeshData().setVertexBuffer(BufferUtils.createVector3Buffer(1));
    solarPanelOutlines.setDefaultColor(new ColorRGBA(0f, 0f, 0f, 1f));
    root.attachChild(solarPanelOutlines);
    label = new BMText("Label", "#" + id, FontManager.getInstance().getPartNumberFont(), Align.Center, Justify.Center);
    Util.initHousePartLabel(label);
    label.setFontScale(0.5);
    label.setVisible(false);
    root.attachChild(label);
    polesRoot = new Node("Poles Root");
    root.attachChild(polesRoot);
    updateTextureAndColor();
    if (sampleSolarPanel == null) {
        sampleSolarPanel = new SolarPanel();
    }
    // ugly fixes for zero initial values when sampleSolarPanel is previously serialized without new variables
    if (sampleSolarPanel.getPvModuleSpecs() == null) {
        sampleSolarPanel.setPvModuleSpecs(new PvModuleSpecs());
    }
    if (Util.isZero(sampleSolarPanel.getNominalOperatingCellTemperature())) {
        sampleSolarPanel.setNominalOperatingCellTemperature(48);
    }
    if (!points.isEmpty()) {
        oldRackCenter = points.get(0).clone();
    }
    oldRackWidth = rackWidth;
    oldRackHeight = rackHeight;
}
Also used : Line(com.ardor3d.scenegraph.Line) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) ReadOnlyColorRGBA(com.ardor3d.math.type.ReadOnlyColorRGBA) ColorRGBA(com.ardor3d.math.ColorRGBA) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) BoundingBox(com.ardor3d.bounding.BoundingBox) Box(com.ardor3d.scenegraph.shape.Box) OrientedBoundingBox(com.ardor3d.bounding.OrientedBoundingBox) AngleAnnotation(org.concord.energy3d.shapes.AngleAnnotation) BMText(com.ardor3d.ui.text.BMText) PvModuleSpecs(org.concord.energy3d.simulation.PvModuleSpecs) OffsetState(com.ardor3d.renderer.state.OffsetState)

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