对于我的项目,我需要 3D 场景中的 2D 文本(而不是叠加!)。所以我尝试在我的场景中添加一个BorderPane
with Label
/节点:Text
然而,问题是,当我用相机放大、缩小或飞来飞去时,面板的白色背景有时会与标签重叠(它们显然具有相同的深度)。
有没有办法从其面板“提升”标签?我试过设置setDepthTest(true);
没有效果。
这是一个显示问题的简单示例。该Xform
课程来自Oracle的分子样本(http://docs.oracle.com/javase/8/javafx/graphics-tutorial/sampleapp3d-code.htm#CJAGGIFG):
package mypackage;
import mypackage.Xform;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.Scene;
import javafx.scene.SceneAntialiasing;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class Example extends Application {
private Stage primaryStage;
private final Group root = new Group();
@Override
public void start(Stage primaryStage) throws Exception {
this.primaryStage = primaryStage;
primaryStage.setTitle("Example");
this.primaryStage.setWidth(500);
this.primaryStage.setHeight(500);
Scene scene = new Scene(this.root, 500, 500, true, SceneAntialiasing.BALANCED);
scene.setFill(Color.WHITESMOKE);
Text text = new Text();
text.setText("This is a text sample");
text.setStyle("-fx-font-size: 20;");
text.setCache(true);
BorderPane borderPane = new BorderPane();
borderPane.setStyle("-fx-border-color: black;-fx-background-color: #66CCFF;");
borderPane.setTop(text);
this.root.getChildren().add(borderPane);
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(10000.0);
camera.setTranslateX(100);
camera.setTranslateZ(-500);
Xform cameraXform = new Xform();
Xform cameraXform2 = new Xform();
Xform cameraXform3 = new Xform();
cameraXform.getChildren().add(cameraXform2);
cameraXform2.getChildren().add(cameraXform3);
cameraXform3.getChildren().add(camera);
//cameraXform3.setRotateZ(180.0);
cameraXform.ry.setAngle(400.0); // 320
cameraXform.rx.setAngle(20.0); // 40
scene.setCamera(camera);
this.primaryStage.setScene(scene);
this.primaryStage.show();
}
public static void main(String[] args) {
System.setProperty("prism.lcdtext", "false");
System.setProperty("prism.text", "t2k");
launch(args);
}
}