首页 > 解决方案 > 想将 FXML 导入为场景,然后使用 FXML 中的相机

问题描述

我想制作 3d 对象(使用搅拌器)并使用交互式网格:模型浏览器将它们放入 javaFx 中。这会生成一个包含我需要的所有信息的 FXML。我在那个 FXMl 中有一个摄像头(基本上来自搅拌机),我希望它使用那个摄像头作为主摄像头。

我尝试使用查找和 getNamespace 从 fxml 加载对象。

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Group;
import javafx.scene.*;
import javafx.stage.Stage;

import java.io.IOException;


public class main extends Application {
    public static void main(String[] args) {
        launch(args);
    }
    public void start(Stage stage){
        FXMLLoader loader = new FXMLLoader(getClass().getResource("ground.fxml"));
        Group base = new Group();
        PerspectiveCamera camera;
        Parent root=new Parent(){};
        try {
            root = loader.load();
        }catch (IOException e){
            e.printStackTrace();
        }
        base=(Group)root.lookup("#Full3DScene");
        camera= (PerspectiveCamera) base.lookup("#camera");
        Scene scene = new Scene(base,1920,1080);
        stage.setScene(scene);
        scene.setCamera(camera);
        stage.show();
        camera.getId();
    }
}

提前致谢! 这是使用 InteractiveMesh:ModelBrowserJFX 0.4.1 从相机拍摄的视图

FXML 看起来像:

<Group fx:id="Full3DScene" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8.0.121" fx:controller="Controller">
  <transforms>
    <Rotate angle="-90.0" pivotX="0.0" pivotY="0.0" pivotZ="0.0">
      <axis>
        <Point3D x="1.0" y="0.0" z="0.0" />
      </axis>
    </Rotate>
  </transforms>
  <children>
    //...all objects for the scene...
    //+
    <PerspectiveCamera fx:id="camera">
    </PerspectiveCamera>
  </children>
</Group>

我做了什么 Blender->.dae(Collada)->InteractiveMesh:Model Browser->FXML->javaFx

标签: javajavafxfxml

解决方案


推荐阅读