Skip to content

Instantly share code, notes, and snippets.

@skrb
Created December 25, 2016 03:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skrb/926f3078455cfbc92d7e299a9272516d to your computer and use it in GitHub Desktop.
Save skrb/926f3078455cfbc92d7e299a9272516d to your computer and use it in GitHub Desktop.
JavaFX Bump Mapping Demo
import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.RotateTransition;
import javafx.application.Application;
import javafx.geometry.Point3D;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Sphere;
import javafx.stage.Stage;
import javafx.util.Duration;
public class MarsBumpMappingDemo extends Application {
@Override
public void start(Stage stage) throws Exception {
Group root = new Group();
Sphere mars = new Sphere(200);
mars.setTranslateX(400);
mars.setTranslateY(400);
root.getChildren().add(mars);
PhongMaterial material = new PhongMaterial();
// テクスチャの設定
material.setDiffuseMap(new Image(getClass().getResource("720px-Mars_Géolocalisation.jpg").toString()));
// バンプマッピングの設定
material.setBumpMap(new Image(getClass().getResource("MarsGéolocalisation.jpg").toString()));
// オブジェクトにマテリアルを設定
mars.setMaterial(material);
// 回転
RotateTransition rotate = new RotateTransition(Duration.millis(10_000), mars);
rotate.setFromAngle(360.0);
rotate.setToAngle(0.0);
rotate.setInterpolator(Interpolator.LINEAR);
rotate.setCycleCount(Animation.INDEFINITE);
rotate.setAxis(new Point3D(0.0, 1.0, 0.0));
rotate.play();
Scene scene = new Scene(root, 800, 800 , Color.BLACK);
scene.setCamera(new PerspectiveCamera());
stage.setScene(scene);
stage.show();
}
public static void main(String... args) {
launch(args);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment