在此代码中,我有一个启用了 3d 功能的
Subscene
。我在运行时添加相机和网格视图,但我想将相机放入 FXML 中,因为我不需要在运行时更改它。我怎样才能做到这一点
?
<SubScene fx:id="viewer3d" depthBuffer="true" fill="#3389de" height="600.0" width="600.0">
<root>
<Region />
</root>
<antiAliasing>
<SceneAntialiasing fx:constant="BALANCED" />
如果您同意
fixedEyAtCameraZero
属性为 false
那么您需要的是:
<camera>
<!-- make sure to import the class (or use fully qualified name) -->
<PerspectiveCamera/>
</camera>
嵌套在
SubScene
元素中。但是,如果您希望上述属性为true
,那么不幸的是您必须在代码中设置相机。该属性只能在构造期间设置,但从 JavaFX 21 开始,PerspectiveCamera(boolean)
构造函数不会使用 @NamedArg
注释其参数。
尝试加载以下内容:
<camera>
<PerspectiveCamera fixedEyeAtCameraZero="true"/>
</camera>
尝试加载 FXML 文件时会出现以下异常:
Caused by: com.sun.javafx.fxml.PropertyNotFoundException: Property "fixedEyeAtCameraZero" does not exist or is read-only.
at [email protected]/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:254)
at [email protected]/com.sun.javafx.fxml.BeanAdapter.put(BeanAdapter.java:54)
at [email protected]/javafx.fxml.FXMLLoader$Element.applyProperty(FXMLLoader.java:525)
at [email protected]/javafx.fxml.FXMLLoader$Element.processValue(FXMLLoader.java:375)
at [email protected]/javafx.fxml.FXMLLoader$Element.processPropertyAttribute(FXMLLoader.java:337)
at [email protected]/javafx.fxml.FXMLLoader$Element.processInstancePropertyAttributes(FXMLLoader.java:248)
at [email protected]/javafx.fxml.FXMLLoader$ValueElement.processEndElement(FXMLLoader.java:780)
at [email protected]/javafx.fxml.FXMLLoader.processEndElement(FXMLLoader.java:2969)
at [email protected]/javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2654)
... 17 more