我正在尝试使用 Javafx(使用 TornadoFX 库)进行一些 3D 工作,但无法将 my 设置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 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 支持,坦率地说,会影响我的一生吗?)