JavaFXZ缓冲区问题
我用很多小盒子装满一个容器,问题是你可以从一些角度看到它们。我已经启用了深度缓冲区,但这不起作用 处理此部分的代码分为3部分。setupUIPreElements设置所有内容,setupUIElements添加框,setupUIPostElements添加容器和一些相机内容JavaFXZ缓冲区问题,java,javafx,depth-buffer,Java,Javafx,Depth Buffer,我用很多小盒子装满一个容器,问题是你可以从一些角度看到它们。我已经启用了深度缓冲区,但这不起作用 处理此部分的代码分为3部分。setupUIPreElements设置所有内容,setupUIElements添加框,setupUIPostElements添加容器和一些相机内容 public static void setupUIPreElements(Stage stage){ //Setup grids, groups, scenes, camera and such so that t
public static void setupUIPreElements(Stage stage){
//Setup grids, groups, scenes, camera and such so that the scene is made from scratch
topGrid = new GridPane();
twoDGroup = new Group();
threeDGroup = new SmartGroup();
root = new HBox();
mainScene = new Scene(root, SCREEN_WIDTH, SCREEN_HEIGHT, true, SceneAntialiasing.BALANCED);
twoD = new SubScene(twoDGroup, SCREEN_WIDTH*.2, SCREEN_HEIGHT);
threeD = new SubScene(threeDGroup, SCREEN_WIDTH*.8, SCREEN_HEIGHT);
anchorAngleX = 0;
anchorAngleY = 0;
angleX = new SimpleDoubleProperty(0);
angleY = new SimpleDoubleProperty(0);
camera = new PerspectiveCamera();
pins = new ProgressIndicator[1];
pin = pins[0] = new ProgressIndicator();
parcels = new ArrayList<UIParcel>();
//add subscenes to scene
root.getChildren().addAll(twoD, threeD);
root.setSpacing(10);
root.setPadding(new Insets(20, 20, 20, 20));
/*START Setup top menu*/
//Setup grid
topGrid.setHgap(10);
topGrid.setVgap(10);
//Setup items
//Add scoring label
scoringLabel = new Label("Score: " + Wrapper.score);
startButton = new Button("Start");
modeSelection = new ChoiceBox(FXCollections.observableArrayList(
"Parcels", "Pentominoes"
));
modeSelection.setValue("");
//Parcel selection UI
ParcelAAmountLabel = new Label("Amount of parcel A: ");
ParcelBAmountLabel = new Label("Amount of parcel B: ");
ParcelCAmountLabel = new Label("Amount of parcel C: ");
ParcelAAmountTextField = new TextField();
ParcelBAmountTextField = new TextField();
ParcelCAmountTextField = new TextField();
ParcelAValueLabel = new Label("Value of parcel A: ");
ParcelBValueLabel = new Label("Value of parcel B: ");
ParcelCValueLabel = new Label("Value of parcel C: ");
ParcelAValueTextField = new TextField();
ParcelBValueTextField = new TextField();
ParcelCValueTextField = new TextField();
//Pentominoe selection UI
LPentominoAmountLabel = new Label("Amount of L pentominoes: ");
PPentominoAmountLabel = new Label("Amount of P pentominoes: ");
TPentominoAmountLabel = new Label("Amount of T pentominoes: ");
LPentominoAmountTextField = new TextField();
PPentominoAmountTextField = new TextField();
TPentominoAmountTextField = new TextField();
LPentominoValueLabel = new Label("Value of L pentominoes: ");
PPentominoValueLabel = new Label("Value of P pentominoes: ");
TPentominoValueLabel = new Label("Value of T pentominoes: ");
LPentominoValueTextField = new TextField();
PPentominoValueTextField = new TextField();
TPentominoValueTextField = new TextField();
//-1 will make it display an animated disk, set to 1 to show that it's done
//pin is the progress indicator
pin.setProgress(-1);
topGrid.add(scoringLabel, 0, 0);
topGrid.add(modeSelection, 0, 1);
topGrid.add(startButton, 0, 8);
twoDGroup.getChildren().add(topGrid);
/*END*/
//Set materials
container_material.setDiffuseColor(CONTAINER_COLOR);
edge_material.setDiffuseColor(EDGE_COLOR);
}
public static void setupUIElements(Stage stage, int[][][] resultBoxesArray){
//TODO check if I can assume the IDs to be either 1, 2 or 3 if filled in or 0 if not
int colorStart = 0;
int colorEnd = 0;
//give every filled in field a box representation and keep color in mind
//create all the boxes
for(int x=0; x<resultBoxesArray.length; x++){
for(int y=0; y<resultBoxesArray[x].length; y++){
for(int z=0; z<resultBoxesArray[x][y].length; z++){
int currentValue = resultBoxesArray[x][y][z];
//if this field is filled
if(currentValue!=0){
//update color range
if(currentValue==1){
colorStart = 0;
colorEnd = 70;
} else if (currentValue==2){
colorStart = 85;
colorEnd = 155;
} else {
colorStart = 170;
colorEnd = 255;
}
//50 is used because that is the size that is given for each cell in the array
UIParcel cellBox = new UIParcel(x*50, y*50, z*50, 50, 50, 50, colorStart, colorEnd);
parcels.add(cellBox);
}
}
}
}
//show them
threeDGroup.getChildren().addAll(parcels);
}
public static void setupUIPostElements(Stage stage){
//Create container (note: Has to be created after adding all the other objects in order to use transparency (I know, javaFX can be crappy))
Box container = new Box(Wrapper.CONTAINER_WIDTH, Wrapper.CONTAINER_HEIGHT, Wrapper.CONTAINER_DEPTH);
container.setTranslateX(Wrapper.CONTAINER_WIDTH/2);
container.setTranslateY(Wrapper.CONTAINER_HEIGHT/2);
container.setTranslateZ(Wrapper.CONTAINER_DEPTH/2);
container.setMaterial(container_material);
threeDGroup.getChildren().add(container);
//Setup camera (so that you can have the container at the origin and can still see it well
//The +threeDOffsetLeft comes from the compensation for the 2D subscene on the left
camera.setTranslateX(-SCREEN_WIDTH/2+Wrapper.CONTAINER_WIDTH/2+threeDOffsetLeft);
camera.setTranslateY(-SCREEN_HEIGHT/2+Wrapper.CONTAINER_HEIGHT/2);
camera.setTranslateZ(-Wrapper.CONTAINER_DEPTH/0.5);
//Setup mouse rotation
initMouseControl(threeDGroup, mainScene, stage);
//Set eventListener for mode selection
modeSelection.getSelectionModel().selectedItemProperty().addListener((v, oldValue, newValue) -> {
//check what mode was selected and show the corresponding options
if(newValue.equals("Parcels")){
//remove other option
if(oldValue.equals("Pentominoes")){
topGrid.getChildren().removeAll(LPentominoAmountLabel, PPentominoAmountLabel, TPentominoAmountLabel, LPentominoAmountTextField, PPentominoAmountTextField, TPentominoAmountTextField, LPentominoValueLabel, PPentominoValueLabel, TPentominoValueLabel, LPentominoValueTextField, PPentominoValueTextField, TPentominoValueTextField);
}
//add labels
topGrid.add(ParcelAAmountLabel, 0, 2);
topGrid.add(ParcelBAmountLabel, 0, 4);
topGrid.add(ParcelCAmountLabel, 0, 6);
topGrid.add(ParcelAValueLabel, 0, 3);
topGrid.add(ParcelBValueLabel, 0, 5);
topGrid.add(ParcelCValueLabel, 0, 7);
//add text fields
topGrid.add(ParcelAAmountTextField, 1, 2);
topGrid.add(ParcelBAmountTextField, 1, 4);
topGrid.add(ParcelCAmountTextField, 1, 6);
topGrid.add(ParcelAValueTextField, 1, 3);
topGrid.add(ParcelBValueTextField, 1, 5);
topGrid.add(ParcelCValueTextField, 1, 7);
} else if (newValue.equals("Pentominoes")){
//remove other option
if(oldValue.equals("Parcels")){
topGrid.getChildren().removeAll(ParcelAAmountLabel, ParcelBAmountLabel, ParcelCAmountLabel, ParcelAAmountTextField, ParcelBAmountTextField, ParcelCAmountTextField, ParcelAValueLabel, ParcelBValueLabel, ParcelCValueLabel, ParcelAValueTextField, ParcelBValueTextField, ParcelCValueTextField);
}
//add labels
topGrid.add(LPentominoAmountLabel, 0, 2);
topGrid.add(PPentominoAmountLabel, 0, 4);
topGrid.add(TPentominoAmountLabel, 0, 6);
topGrid.add(LPentominoValueLabel, 0, 3);
topGrid.add(PPentominoValueLabel, 0, 5);
topGrid.add(TPentominoValueLabel, 0, 7);
//add text fields
topGrid.add(LPentominoAmountTextField, 1, 2);
topGrid.add(PPentominoAmountTextField, 1, 4);
topGrid.add(TPentominoAmountTextField, 1, 6);
topGrid.add(LPentominoValueTextField, 1, 3);
topGrid.add(PPentominoValueTextField, 1, 5);
topGrid.add(TPentominoValueTextField, 1, 7);
}
});
//Set evenListener for start button
startButton.addEventHandler(MouseEvent.MOUSE_CLICKED, event-> {
//Show loading circle (that was created at the start)
topGrid.add(pin, 0, 9);
//TODO use values from the textFields as input
//TODO start calculations
//TODO remove after testing
test.giveInput();
});
threeD.setCamera(camera);
stage.setTitle("Filling 3D objects");
threeD.setFill(BACKGROUND_COLOR);
stage.setScene(mainScene);
stage.show();
}
公共静态无效设置预元件(阶段){
//设置网格、组、场景、摄影机等,以便从头开始创建场景
topGrid=新的GridPane();
twoDGroup=新组();
threeDGroup=新智能组();
根=新的HBox();
主场景=新场景(根、屏幕宽度、屏幕高度、真、场景初始化.平衡);
twoD=新的亚场景(twoDGroup,屏幕宽度*.2,屏幕高度);
threeD=新的亚场景(threeDGroup,屏幕宽度*.8,屏幕高度);
Anchoranlex=0;
Anchoranley=0;
angleX=新的SimpleDupleProperty(0);
angleY=新的SimpleDoubleProperty(0);
摄像头=新透视摄像头();
引脚=新的进度指示器[1];
引脚=引脚[0]=新ProgressIndicator();
地块=新阵列列表();
//将子场景添加到场景中
root.getChildren().addAll(twoD,threeD);
根起搏(10);
根.坐垫(新的插图(20,20,20,20));
/*开始设置顶部菜单*/
//设置网格
topGrid.setHgap(10);
topGrid.setVgap(10);
//设置项
//添加评分标签
scoringLabel=新标签(“分数:+Wrapper.Score”);
开始按钮=新按钮(“开始”);
modeSelection=新建选项框(FXCollections.observableArrayList(
“包裹”、“五分音符”
));
modeSelection.setValue(“”);
//地块选择界面
ParcelAAmountLabel=新标签(“地块A的数量:”);
ParcelBAmountLabel=新标签(“地块B的数量:”);
ParcelCAmountLabel=新标签(“地块C数量:”);
ParcelaaMontTextField=新的TextField();
ParcelBAmountTextField=新的TextField();
ParcelCAmountTextField=新的TextField();
ParcelAValueLabel=新标签(“地块A的值:”);
ParcelBValueLabel=新标签(“地块B的值:”);
ParcelCValueLabel=新标签(“地块C的值:”);
ParcelAValueTextField=新文本字段();
ParcelBValueTextField=新的TextField();
ParcelCValueTextField=新的TextField();
//五线谱选择界面
LPENTOMINOMONAMOUNTLABEL=新标签(“L戊胺的量:”);
PPentominoAmountLabel=新标签(“P-戊胺的量:”);
TPentominoAmountLabel=新标签(“T五胺的数量:”);
lpentominamountextfield=新的TextField();
pPenToMinomountTextField=新的TextField();
tpentominamountextfield=新的TextField();
LPentominoValueLabel=新标签(“L Pentomines的值:”);
PPentominoValueLabel=新标签(“P五聚体的值:”);
TPentominoValueLabel=新标签(“T五联体的值:”);
LPentominoValueTextField=新的TextField();
PPentominoValueTextField=新的TextField();
TPentominoValueTextField=新的TextField();
//-1将使其显示动画磁盘,设置为1表示已完成
//pin是进度指示器
引脚设置进度(-1);
添加(scoringLabel,0,0);
添加(模式选择,0,1);
添加(开始按钮,0,8);
twoDGroup.getChildren().add(topGrid);
/*结束*/
//定做材料
容器颜色。设置漫射颜色(容器颜色);
edge_material.setDiffuseColor(edge_COLOR);
}
公共静态void setupUIElements(Stage Stage,int[][]resultBoxesArray){
//TODO检查我是否可以假设ID为1、2或3(如果已填写),或者0(如果未填写)
int colorStart=0;
int colorEnd=0;
//给每个填写的字段一个方框表示,并记住颜色
//创建所有框
对于(int x=0;x来说,解决方案是为包含3D元素的子场景启用深度缓冲,而不仅仅是遵循主场景的设置
threeD = new SubScene(threeDGroup, SCREEN_WIDTH*.8, SCREEN_HEIGHT);
变成
threeD = new SubScene(threeDGroup, SCREEN_WIDTH*.8, SCREEN_HEIGHT, true, SceneAntialiasing.BALANCED);
SubScene构造函数也需要设置场景初始化。您可能需要了解如何使用一个网格处理多个长方体。