现场演示
->
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.scene.shape.Box;
import javafx.scene.shape.CullFace;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
public class CullFaceProperty extends Application {
public void start(Stage stage) {
//画一个盒子
Box cube1 = new Box(100, 120, 100);
cube1.setTranslateX(30);
cube1.setTranslateY(180);
cube1.setTranslateZ(150);
//Setting the property "cull face"
cube1.setCullFace(CullFace.FRONT);
Box cube2 = new Box(100, 120, 100);
cube2.setTranslateX(250);
cube2.setTranslateY(180);
cube2.setTranslateZ(150);
//Setting the property "cull face"
cube2.setCullFace(CullFace.BACK);
Box cube3 = new Box(100, 120, 100);
cube3.setTranslateX(480);
cube3.setTranslateY(180);
cube3.setTranslateZ(150);
//Setting the property "cull face"
cube3.setCullFace(CullFace.NONE);
//设置透视相机
PerspectiveCamera cam = new PerspectiveCamera();
cam.setTranslateX(-50);
cam.setTranslateY(50);
cam.setTranslateZ(0);
Font font = Font.font("verdana", FontWeight.BOLD, FontPosture.REGULAR, 15);
Text label1 = new Text("CullFace: front");
label1.setFont(font);
label1.setX(10);
label1.setY(270);
Text label2 = new Text("CullFace: back");
label2.setFont(font);
label2.setX(180);
label2.setY(270);
Text label3 = new Text("CullFace: none");
label3.setFont(font);
label3.setX(370);
label3.setY(270);
//设置场景
Group root = new Group(cube1, cube2, cube3, label1, label2, label3);
Scene scene = new Scene(root, 595, 300, Color.BEIGE);
scene.setCamera(cam);
stage.setTitle("3D Shape Property: Cull Face");
stage.setScene(scene);
stage.show();
}
public static void main(String args[]){
launch(args);
}
}输出结果