简体   繁体   中英

Why is my Scene null?

I'm trying to do some 3D work with Javafx (using the TornadoFX library) and am unable to set my PerspectiveCamera to the Scene as the Scene is returning null .

I launch my program like so:

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
    }
}

and then in HomeView class I have this:

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
}

Is there something I'm doing wrong? I have no idea why my Scene is null as I thought TornadoFX View was supposed to create a new Scene when it's initialized? Do I need to manually create it in the App class? I tried overriding the createPrimaryScene function, and also moving my code to an init function within the HomeView view– both with no success.

Any ideas? Pulling out hairs over here.

(Oh, and on an unrelated note, could I just say that having 3D support in TornadoFX would, quite frankly, make my entire life ?)

The View is created before the scene is attached, so to manipulate scene, simply override onDock and perform your operations there. When onDock is called, the scene is attached.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM