为什么我的场景为空?
Why is my Scene null?
我正在尝试使用 Javafx(使用 TornadoFX 库)进行一些 3D 工作,但无法将我的 PerspectiveCamera
设置为 Scene
,因为 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 我有这个:
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中手动创建吗class?我尝试覆盖 createPrimaryScene
函数,并将我的代码移动到 HomeView
视图中的 init
函数——但都没有成功。
有什么想法吗?在这里拔毛
(哦,顺便提一句,坦率地说,TornadoFX 中的 3D 支持会让我 终生受益 ?)
视图是在附加场景之前创建的,因此要操作场景,只需覆盖 onDock
并在那里执行您的操作。 onDock
调用时,附上场景
我正在尝试使用 Javafx(使用 TornadoFX 库)进行一些 3D 工作,但无法将我的 PerspectiveCamera
设置为 Scene
,因为 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 我有这个:
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中手动创建吗class?我尝试覆盖 createPrimaryScene
函数,并将我的代码移动到 HomeView
视图中的 init
函数——但都没有成功。
有什么想法吗?在这里拔毛
(哦,顺便提一句,坦率地说,TornadoFX 中的 3D 支持会让我 终生受益 ?)
视图是在附加场景之前创建的,因此要操作场景,只需覆盖 onDock
并在那里执行您的操作。 onDock
调用时,附上场景