2

我正在尝试使用 Javafx(使用 TornadoFX 库)进行一些 3D 工作,但无法将 my 设置PerspectiveCameraScene正在Scene返回的null.

我像这样启动我的程序:

class ThreeDTest : App(HomeView::class, ThreeDStyles::class) {
    override fun start(stage: Stage) {
        super.start(stage)
        stage.show()
        stage.scene.fill = Color.BLACK

        val primaryScreenBounds = Screen.getPrimary().visualBounds

        stage.maxWidth = 1920.0
        stage.maxHeight = 1080.0
        stage.minWidth = 1920.0
        stage.minHeight = 1080.0
    }
}

然后在HomeView课堂上我有这个:

class HomeView : View() {
    override val root = stackpane {
        val axisGroup = Xform()
        val world = Xform()
        val camera = PerspectiveCamera(true)
        val cameraXform = Xform()
        val cameraXform2 = Xform()
        val cameraXform3 = Xform()
        val cameraInitialDistance = -450.0
        val cameraInitialXAngle = 70.0
        val cameraInitialYAngle = 320.0
        val cameraNearClip = 0.1
        val cameraFarClip = 10000.0

        //just a builder class to add properties to the camera
        buildCamera(this, cameraXform, cameraXform2, cameraXform3, camera, cameraNearClip, cameraFarClip, cameraInitialDistance,
            cameraInitialYAngle, cameraInitialXAngle)
        buildAxes(axisGroup, world)

        println(scene)
        //returns null
        scene.camera = camera
        //this does not work as scene is null
}

有什么我做错了吗?我不知道为什么我Scene的为空,因为我认为 TornadoFX在初始化时View应该创建一个新Scene的?我需要在 App 类中手动创建它吗?我尝试覆盖该createPrimaryScene函数,并将我的代码移动到视图中的一个init函数HomeView——两者都没有成功。

有任何想法吗?在这里拔毛。

(哦,在一个不相关的说明中,我可以说在 TornadoFX 中拥有 3D 支持,坦率地说,会影响我的一生吗?)

4

1 回答 1

4

视图是在附加场景之前创建的,因此要操作场景,只需覆盖onDock并在那里执行您的操作。当onDock被调用时,场景被附加。

于 2017-11-01T11:34:58.913 回答