customizing javafx 3d box or rotating stackpane

前端 未结 1 1800
傲寒
傲寒 2021-01-06 20:02

My goal is a game played with dice. I am using javafx.

First question: Is there an easy way to customize the 3d box in javafx. It doesn\'t matter

相关标签:
1条回答
  • 2021-01-06 20:13

    The problem with Box, as you may have already noticed, is that if you apply an image as diffuse map, it will be applied equally to all its 6 faces.

    If you have a look at FXyz project, there's an implementation of a similar 3D shape, CuboidMesh.

    Having full access to its 'TriangleMesh` it's easy to customize the way the texture is mapped to a diffuse image. In this case, the way its implemented is by using the net of the cube:

    Cube net

    So now you just need to provide your own net. For instance, this one:

    Dice net

    from here

    Just rotate it 180º and crop it to its border, and with this short code you will have your dice:

    CuboidMesh cuboid = new CuboidMesh(10f,10f,10f);
    cuboid.setTextureModeImage(getClass().getResource("rotated_image014.jpg").toExternalForm());
    

    Dice

    0 讨论(0)
提交回复
热议问题