下面是一个简单的例子:
Java代码
1. import javafx.application.Application; 2. import javafx.scene.*; 3. import javafx.scene.paint.Color;4. import javafx.scene.paint.PhongMaterial; 5. import javafx.scene.shape.*; 6. import javafx.stage.Stage;7.8. public class Shapes3DViewer extends Application {9. @Override public void start(Stage stage) { 10. PhongMaterial material = new PhongMaterial();11. material.setDiffuseColor(Color.LIGHTGRAY);12. material.setSpecularColor(Color.rgb(30, 30, 30));13. 14. Shape3D[] meshView = new Shape3D[] { 15. new Box(200, 200, 200),16. new Sphere(100),17. new Cylinder(100, 200), 18. };19. 20. for (int i=0; i!=3; ++i) {21. meshView[i].setMaterial(material); 22. meshView[i].setTranslateX((i + 1) * 220);23. meshView[i].setTranslateY(500); 24. meshView[i].setTranslateZ(20); 25. meshView[i].setDrawMode(DrawMode.FILL); 26. meshView[i].setCullFace(CullFace.BACK); 27. }; 28. 29. PointLight pointLight = new PointLight(Color.ANTIQUEWHITE); 30. pointLight.setTranslateX(800); 31. pointLight.setTranslateY(-100);32. pointLight.setTranslateZ(-1000); 33.34. Group root = new Group(meshView); 35. root.getChildren().add(pointLight); 36. 37. Scene scene = new Scene(root, 800, 800, true);38. scene.setFill(Color.rgb(10, 10, 40)); 39. scene.setCamera(new PerspectiveCamera(false));40. stage.setScene(scene); 41. stage.show(); 42. } 43. 44. public static void main(String[] args) { 45. launch(args); 46. } 47. }