JavaFX - маскировка панели уменьшает видимость трехмерного объекта - PullRequest
0 голосов
/ 20 февраля 2019

Я пытаюсь создать визуальный компонент, который показывает диск со строками измерений для отображения текущего значения из источника.

disc meter

Все работаетхорошо, но когда я маскирую контейнер (панель), чтобы уменьшить видимую область, изображение отображается затемненным.

до маски: before masking it

после маски: after masking it

Маска не работает, SubScene работает: it works

Это код:

Main.java

package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        FXMLLoader loader = new FXMLLoader(
            getClass().getResource("sample.fxml"));
        Parent root = loader.load();
        primaryStage.setTitle("Clock Test");
        primaryStage.setScene(new Scene(root, 800, 200));
        primaryStage.show();

        Controller controller = loader.getController();
        controller.initClock();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Controller.java [ОБНОВЛЕНО]

package sample;

import javafx.fxml.FXML;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.SubScene;
import javafx.scene.image.Image;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Cylinder;
import javafx.scene.shape.Rectangle;

public class Controller {

    @FXML private Pane clock;

    public void initClock() {

        PerspectiveCamera camera = new PerspectiveCamera();
        camera.setTranslateX(-150);
        camera.setTranslateY(-32.5);
        camera.setTranslateZ(-600);

        Group group = new Group();

        SubScene subScene = new SubScene(group, 300, 65);
        subScene.setCamera(camera);

        Rectangle rectangle = new Rectangle();
        rectangle.setArcWidth(1);
        rectangle.setArcHeight(1);
        rectangle.setX(0);
        rectangle.setY(0);
        rectangle.setWidth(300);
        rectangle.setHeight(65);

        Cylinder cylinder = new Cylinder(600, 65);
        PhongMaterial material = new PhongMaterial();

        Image diffuseMap
                = new Image(getClass()
                .getResource("/images/clock.png")
                .toExternalForm());

        material.setDiffuseColor(new Color(1, 1, 1, 1));
        material.setDiffuseMap(diffuseMap);
        cylinder.setMaterial(material);

        PointLight light = new PointLight();
        light.setColor(Color.WHITE);
        light.setTranslateX(0);
        light.setTranslateY(50);
        light.setTranslateZ(-800);

        group.getChildren().addAll(cylinder, light);

        clock.getChildren().add(subScene);
    }
}

sample.fxml

<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.layout.RowConstraints?>
<GridPane alignment="center" hgap="10" vgap="10" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.172-ea" fx:controller="sample.Controller">
  <children>
     <Pane fx:id="clock" prefHeight="65.0" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
  </children>
  <columnConstraints>
     <ColumnConstraints minWidth="10.0" prefWidth="100.0" />
     <ColumnConstraints minWidth="300.0" maxWidth="300.0" prefWidth="300.0" />
     <ColumnConstraints minWidth="10.0" prefWidth="100.0" />
  </columnConstraints>
  <rowConstraints>
     <RowConstraints minHeight="10.0" prefHeight="30.0" />
     <RowConstraints />
     <RowConstraints minHeight="10.0" prefHeight="30.0" />
  </rowConstraints>
</GridPane>

Используемое изображение: meter image with lines

Клонируйте его здесь:

git clone https://your_username@bitbucket.org/diegoluisr/meter3d.git
...