Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //create a Pane et graph scene root for the 3D cont
- Group root3D = new Group();
- Pane pane3D = new Pane( root3D);
- //Create cube shape
- Box cube = new Box(1, 1, 1);
- //Create Material
- final PhongMaterial blueMaterial = new PhongMaterial();
- blueMaterial.setDiffuseColor(Color.BLUE);
- blueMaterial.setSpecularColor(Color.BLUE);
- //Set it to the cube
- cube.setMaterial(blueMaterial);
- //Add the cube to this node
- root3D.getChildren().add(cube);
- //a camera group
- PerspectiveCamera camera = new PerspectiveCamera(true);
- Group cameraGroup = new Group(camera);
- root3D.getChildren().add(cameraGroup);
- //ate then move the camera
- Rotate ry = new Rotate();
- ry.setAxis(Rotate.Y_AXIS);
- ry.setAngle(-15);
- Translate tz = new Translate();
- tz.setZ(-10);
- tz.setY(-1);
- cameraGroup.getTransforms().addAll(ry,tz);
- // Add point light
- PointLight light = new PointLight(Color.WHITE);
- light.setTranslateX(-180);
- light.setTranslateY(-90);
- light.setTranslateZ(-120);
- light.getScope().addAll(root3D);
- root3D.getChildren().add(light);
- // Create scene
- Scene scene = new Scene(pane3D, 600, 600, true);
- scene.setCamera(camera);
- scene.setFill(Color.GREY);
- //Add the scene to the stage and show it
- primaryStage.setTitle("Cubes Test");
- primaryStage.setScene(scene);
- primaryStage.show();
- primaryStage.show();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement