convert JavaFX Node To 3D - Java javafx.scene.shape

Java examples for javafx.scene.shape:Box

Description

convert JavaFX Node To 3D

Demo Code


//package com.java2s;

import javafx.scene.*;

import javafx.scene.image.WritableImage;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;

public class Main {
    public static Group convertTo3D(Node node) {
        return convertTo3D(node, 0);
    }/*w  w w. ja  v  a 2s .  c o m*/

    public static Group convertTo3D(Node node, int depth) {
        Group root = new Group();
        root.setTranslateX(node.getLayoutX());
        root.setTranslateY(node.getLayoutY());
        root.setTranslateZ(-20);

        System.out.println("Layer " + depth + " - Node Type: "
                + node.getClass());

        Box box = new Box(node.getBoundsInParent().getWidth(), node
                .getBoundsInParent().getHeight(), 0.1);
        box.setTranslateX(node.getLayoutX());
        box.setTranslateY(node.getLayoutY());

        SnapshotParameters snapshotParameters = new SnapshotParameters();
        snapshotParameters.setFill(Color.TRANSPARENT);
        box.setMaterial(new PhongMaterial(Color.WHITE, node.snapshot(
                snapshotParameters, new WritableImage((int) node
                        .getBoundsInParent().getWidth(), (int) node
                        .getBoundsInParent().getHeight())), null, null,
                null));
        root.getChildren().add(box);

        if (node instanceof Parent) {
            for (Node child : ((Parent) node).getChildrenUnmodifiable()) {
                root.getChildren().add(convertTo3D(child, depth + 1));
            }
        }
        return root;
    }
}

Related Tutorials