Search in sources :

Example 1 with Spatial

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

the class Foundation method pickMesh.

public void pickMesh(final int x, final int y) {
    selectedMesh = null;
    if (importedNodes != null) {
        final PickResults pickResults = new PrimitivePickResults();
        pickResults.setCheckDistance(true);
        final Ray3 pickRay = SceneManager.getInstance().getCamera().getPickRay(new Vector2(x, y), false, null);
        for (final Node node : importedNodes) {
            for (final Spatial s : node.getChildren()) {
                if (s instanceof Mesh) {
                    PickingUtil.findPick(s, pickRay, pickResults, false);
                }
            }
        }
        if (pickResults.getNumber() > 0) {
            final Pickable pickable = pickResults.getPickData(0).getTarget();
            if (pickable instanceof Mesh) {
                selectedMesh = (Mesh) pickable;
                drawMeshSelection(selectedMesh);
            }
        } else {
            setMeshSelectionVisible(false);
        }
    }
}
Also used : PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) ReadOnlyVector2(com.ardor3d.math.type.ReadOnlyVector2) Vector2(com.ardor3d.math.Vector2) Spatial(com.ardor3d.scenegraph.Spatial) Pickable(com.ardor3d.intersection.Pickable) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) PrimitivePickResults(com.ardor3d.intersection.PrimitivePickResults) PickResults(com.ardor3d.intersection.PickResults) Ray3(com.ardor3d.math.Ray3)

Example 2 with Spatial

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

the class Foundation method setMovePointsVisible.

public void setMovePointsVisible(final boolean visible) {
    final int n = points.size();
    for (int i = n - 4; i < n; i++) {
        final Spatial editPoint = pointsRoot.getChild(i);
        ((Mesh) editPoint).setVisible(visible);
        final SceneHints sceneHints = editPoint.getSceneHints();
        sceneHints.setAllPickingHints(visible);
    }
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Mesh(com.ardor3d.scenegraph.Mesh) SceneHints(com.ardor3d.scenegraph.hint.SceneHints) CullHint(com.ardor3d.scenegraph.hint.CullHint)

Example 3 with Spatial

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

the class Foundation method drawImportedNodes.

public void drawImportedNodes() {
    if (importedNodes != null) {
        final int n = importedNodes.size();
        if (n > 0) {
            Node ni;
            final Vector3 c = getAbsCenter();
            // the absolute center is lifted to the center of the bounding box that includes walls when there are
            c.setZ(height);
            // FIXME: Why negate?
            final Matrix3 matrix = new Matrix3().fromAngles(0, 0, -Math.toRadians(getAzimuth()));
            for (int i = 0; i < n; i++) {
                ni = importedNodes.get(i);
                if (root.getChildren().contains(ni)) {
                    final Vector3 relativePosition = importedNodeStates.get(i).getRelativePosition();
                    if (relativePosition != null) {
                        final Vector3 vi = matrix.applyPost(relativePosition, null);
                        ni.setTranslation(c.add(vi, null));
                        ni.setRotation(matrix);
                        for (final Spatial s : ni.getChildren()) {
                            if (s instanceof Mesh) {
                                final Mesh m = (Mesh) s;
                                m.updateModelBound();
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) Node(com.ardor3d.scenegraph.Node) Mesh(com.ardor3d.scenegraph.Mesh) ReadOnlyVector3(com.ardor3d.math.type.ReadOnlyVector3) Vector3(com.ardor3d.math.Vector3) CullHint(com.ardor3d.scenegraph.hint.CullHint) Matrix3(com.ardor3d.math.Matrix3)

Example 4 with Spatial

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

the class SceneManager method initCamera.

public void initCamera() {
    System.out.println("initCamera()");
    final Camera camera = getCamera();
    cameraNode = new CameraNode("Camera Node", camera);
    root.attachChild(cameraNode);
    cameraNode.updateFromCamera();
    Scene.getInstance().updateEditShapes();
    setCameraControl(CameraMode.ORBIT);
    resetCamera(ViewMode.NORMAL);
    SceneManager.getInstance().getCameraControl().reset();
    taskManager.update(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            final Spatial compass = createCompass();
            compass.setScale(0.1);
            compass.setTranslation(-1, -0.7, 2);
            cameraNode.attachChild(compass);
            final Spatial earth = createEarth();
            earth.setScale(0.00012);
            earth.setTranslation(-1, -0.67, 2);
            cameraNode.attachChild(earth);
            Scene.getInstance().updateEditShapes();
            return null;
        }
    });
}
Also used : Spatial(com.ardor3d.scenegraph.Spatial) CameraNode(com.ardor3d.scenegraph.extension.CameraNode) Camera(com.ardor3d.renderer.Camera) IOException(java.io.IOException)

Example 5 with Spatial

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

Aggregations

Spatial (com.ardor3d.scenegraph.Spatial)57 Mesh (com.ardor3d.scenegraph.Mesh)36 ReadOnlyVector3 (com.ardor3d.math.type.ReadOnlyVector3)33 Node (com.ardor3d.scenegraph.Node)26 CullHint (com.ardor3d.scenegraph.hint.CullHint)26 Vector3 (com.ardor3d.math.Vector3)24 TPoint (org.poly2tri.triangulation.point.TPoint)18 PickResults (com.ardor3d.intersection.PickResults)15 PrimitivePickResults (com.ardor3d.intersection.PrimitivePickResults)15 Ray3 (com.ardor3d.math.Ray3)15 Point (org.poly2tri.geometry.primitives.Point)14 FloatBuffer (java.nio.FloatBuffer)13 ArrayList (java.util.ArrayList)12 HousePart (org.concord.energy3d.model.HousePart)12 CancellationException (java.util.concurrent.CancellationException)10 Foundation (org.concord.energy3d.model.Foundation)10 Roof (org.concord.energy3d.model.Roof)9 Calendar (java.util.Calendar)7 UserData (org.concord.energy3d.model.UserData)6 Window (org.concord.energy3d.model.Window)6