122 lines
3.4 KiB
Java
122 lines
3.4 KiB
Java
package main.java.com.ThreeDtest.application;
|
|
|
|
import javafx.animation.Interpolator;
|
|
import javafx.animation.RotateTransition;
|
|
import javafx.application.Application;
|
|
import javafx.event.ActionEvent;
|
|
import javafx.fxml.FXML;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.geometry.Pos;
|
|
import javafx.stage.Stage;
|
|
import javafx.util.Duration;
|
|
import javafx.scene.Node;
|
|
import javafx.scene.PointLight;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.SceneAntialiasing;
|
|
import javafx.scene.control.Alert;
|
|
import javafx.scene.control.Alert.AlertType;
|
|
import javafx.scene.control.Button;
|
|
import javafx.scene.control.MenuItem;
|
|
import javafx.scene.image.Image;
|
|
import javafx.scene.layout.AnchorPane;
|
|
import javafx.scene.layout.Background;
|
|
import javafx.scene.layout.BackgroundFill;
|
|
import javafx.scene.layout.StackPane;
|
|
import javafx.scene.paint.Color;
|
|
import javafx.scene.paint.PhongMaterial;
|
|
import javafx.scene.shape.Box;
|
|
import javafx.scene.transform.Rotate;
|
|
|
|
public class Main extends Application
|
|
{
|
|
|
|
@Override
|
|
public void start(Stage primaryStage)
|
|
{
|
|
try {
|
|
|
|
StackPane pane = new StackPane();
|
|
|
|
primaryStage.setTitle("jFx3Dtest");
|
|
Scene scene = new Scene(pane, 600, 600, true,
|
|
SceneAntialiasing.BALANCED);
|
|
|
|
Box myBox = new Box(300, 300, 300);
|
|
|
|
final String DIFFUSE_MAP = "https://upload.wikimedia.org/wikipedia/commons/thumb/a/ac/D%C3%BClmen%2C_Kreuzkapelle_--_2014_--_2731.jpg/640px-D%C3%BClmen%2C_Kreuzkapelle_--_2014_--_2731.jpg";
|
|
|
|
Image texture = new Image(DIFFUSE_MAP);
|
|
|
|
PhongMaterial textureMaterial = new PhongMaterial();
|
|
|
|
textureMaterial.setDiffuseMap(texture);
|
|
|
|
myBox.setMaterial(textureMaterial);
|
|
|
|
PointLight pointLightFront = new PointLight(Color.WHITE);
|
|
pointLightFront.setTranslateX(100);
|
|
pointLightFront.setTranslateY(100);
|
|
pointLightFront.setTranslateZ(-300);
|
|
pointLightFront.setRotate(90);
|
|
|
|
PointLight pointLightSky = new PointLight(Color.WHITE);
|
|
pointLightSky.setTranslateX(0);
|
|
pointLightSky.setTranslateY(-600);
|
|
pointLightSky.setTranslateZ(0);
|
|
pointLightSky.setRotate(90);
|
|
|
|
PointLight pointLightGround = new PointLight(Color.WHITE);
|
|
pointLightSky.setTranslateX(0);
|
|
pointLightSky.setTranslateY(600);
|
|
pointLightSky.setTranslateZ(0);
|
|
pointLightSky.setRotate(90);
|
|
|
|
pane.getChildren().add(pointLightFront);
|
|
pane.getChildren().add(pointLightSky);
|
|
pane.getChildren().add(pointLightGround);
|
|
|
|
StackPane.setAlignment(pointLightFront, Pos.CENTER);
|
|
StackPane.setAlignment(pointLightSky, Pos.CENTER);
|
|
StackPane.setAlignment(pointLightGround, Pos.CENTER);
|
|
|
|
Rotate rxBox = new Rotate(0, 0, 0, 0, Rotate.X_AXIS);
|
|
Rotate ryBox = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
|
|
Rotate rzBox = new Rotate(0, 0, 0, 0, Rotate.Z_AXIS);
|
|
rxBox.setAngle(30);
|
|
ryBox.setAngle(50);
|
|
rzBox.setAngle(30);
|
|
myBox.getTransforms().addAll(rxBox, ryBox, rzBox);
|
|
|
|
StackPane.setAlignment(myBox, Pos.CENTER);
|
|
|
|
rotateAroundYAxis(myBox).play();
|
|
|
|
pane.getChildren().add(myBox);
|
|
|
|
primaryStage.setScene(scene);
|
|
primaryStage.show();
|
|
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
|
|
private RotateTransition rotateAroundYAxis(Node node)
|
|
{
|
|
RotateTransition rotate = new RotateTransition(Duration.seconds(36),
|
|
node);
|
|
rotate.setAxis(Rotate.Y_AXIS);
|
|
rotate.setFromAngle(360);
|
|
rotate.setToAngle(0);
|
|
rotate.setInterpolator(Interpolator.LINEAR);
|
|
rotate.setCycleCount(RotateTransition.INDEFINITE);
|
|
|
|
return rotate;
|
|
}
|
|
|
|
public static void main(String[] args)
|
|
{
|
|
launch(args);
|
|
}
|
|
|
|
} |