In this code I have a Subscene with 3d features enabled. I add camera and meshviews at runtime, but I want to put the camera in FXML because I don´t need to change it at runtime. How can I do that
?
<SubScene fx:id="viewer3d" depthBuffer="true" fill="#3389de" height="600.0" width="600.0">
<root>
<Region />
</root>
<antiAliasing>
<SceneAntialiasing fx:constant="BALANCED" />
If you're okay with the
fixedEyeAtCameraZeroproperty being false then all you need is:Nested in the
SubSceneelement.However, if you want the aforementioned property to be true then unfortunately you have to write some code. Said property can only be set during construction, but the constructor does not annotate its parameter with
@NamedArg. Meaning the following:Will fail because the
FXMLLoaderwill not know what to do with the attribute. In this case, there are two options:Instead of defining the camera in the FXML file, create the camera and set it on the sub-scene in code (e.g., in the controllers
initializemethod).I find this option preferable, but that is just my opinion.
Continue defining the camera in the FXML file and implement a
BuilderandBuilderFactory.Here is an example implementation. Note the example
Builderis extremely simple. It is only implemented to allow setting thefixedEyeAtCameraZeroproperty. Trying to set any other property, which would have otherwise worked without registering this builder, will now fail. You can add other getters and setters as needed. Or, perhaps easier, you could have the builder implementMap<String, Object>and appropriately implement theputmethod.Builder
Builder Factory
Usage