解釋 JavaFX 中 3D 形狀的剔除面屬性
一般來說,剔除是指移除形狀中定向不當的部分(在檢視區域中不可見)。
你可以使用 setCullFace() 方法(形狀類)將值設定為 3d 物件的剔除面屬性。
JavaFX 支援三種類型的剔除面型別,它們由名為 CullFace 的列舉的這三個常量表示,分別是NONE、FRONT、BACK。
示例
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) {
//Drawing a Box
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);
//Setting the perspective camera
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);
//Setting the Scene
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);
}
}輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP