2

我在使用 JavaFX 和 FXyz 0.1.1 将纹理应用到网格时遇到问题。

我发现了这个问题,即使有详细的答案也无法弄清楚。我从头开始,完全复制答案中的代码,场景是黑色的,没有可见的二十面体。

我正在使用 Java 8。提供的图像是 gif,代码将其引用为 png。我已经尝试过使用文件的 png 和 gif 版本。据我所知,其他一切都与引用问题答案中的代码完全相同。

我能够毫无问题地运行这个球体并纹理该球体,但我希望能够使用二十面体而不是球体。

4

1 回答 1

1

如果您使用 FXyz,您可以很容易地将不同的纹理应用到二十面体或任何您可以在中找到的不同基元。

此片段显示了 5 种不同的纹理模式:

@Override
public void start(Stage primaryStage) {
    PerspectiveCamera camera = new PerspectiveCamera(true);   
    camera.setTranslateY(3);
    camera.setTranslateX(4);
    camera.setTranslateZ(-15);

    IcosahedronMesh icoLine = new IcosahedronMesh(100, 0);
    icoLine.setDrawMode(DrawMode.LINE);
    icoLine.getTransforms().addAll(new Rotate(10, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));

    IcosahedronMesh icoColor = new IcosahedronMesh(100, 0);
    icoColor.setTextureModeNone(Color.LIGHTGREEN);
    icoColor.getTransforms().addAll(new Rotate(20, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));

    IcosahedronMesh icoFunction = new IcosahedronMesh(100, 0);
    icoFunction.setTextureModeVertices3D(1530, p -> Math.cos(p.z));
    icoFunction.getTransforms().addAll(new Rotate(30, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));

    IcosahedronMesh icoFaces = new IcosahedronMesh(100, 0);
    icoFaces.setTextureModeFaces(5);
    icoFaces.getTransforms().addAll(new Rotate(20, Rotate.X_AXIS), new Rotate(-10, Rotate.Y_AXIS));

    IcosahedronMesh icoImage = new IcosahedronMesh(100, 0);
    icoImage.setTextureModeImage(getClass().getResource("icon.jpg").toExternalForm());
    icoImage.getTransforms().addAll(new Rotate(20, Rotate.X_AXIS), new Rotate(-20, Rotate.Y_AXIS));

    IcosahedronMesh icoPattern = new IcosahedronMesh(100, 0);
    icoPattern.setTextureModePattern(Patterns.CarbonPatterns.CARBON_KEVLAR, 100);
    icoPattern.getTransforms().addAll(new Rotate(20, Rotate.X_AXIS), new Rotate(-30, Rotate.Y_AXIS));


    GridPane grid = new GridPane();
    grid.add(new Group(icoLine), 0, 0);
    grid.add(new Group(icoColor), 1, 0);
    grid.add(new Group(icoFunction), 2, 0);

    grid.add(new Group(icoFaces), 0, 1);
    grid.add(new Group(icoImage), 1, 1);
    grid.add(new Group(icoPattern), 2, 1);
    Scene scene = new Scene(grid, 600, 400, true, SceneAntialiasing.BALANCED);
    scene.setCamera(camera);

    primaryStage.setScene(scene);
    primaryStage.setTitle(("Icosahedron - FXyz3D"));
    primaryStage.show(); 

}

二十面体纹理

于 2017-05-12T08:42:23.057 回答