Search in sources :

Example 1 with JmeToJFXApplication

use of com.jme3x.jfx.injfx.JmeToJFXApplication in project TeachingInSimulation by ScOrPiOzzy.

the class TestJmeToJFXCanvas method makeJmeApplication.

@NotNull
private static JmeToJFXApplication makeJmeApplication() {
    final AppSettings settings = JmeToJFXIntegrator.prepareSettings(new AppSettings(true), 60);
    final JmeToJFXApplication application = new JmeToJFXApplication() {

        protected Geometry player;

        Boolean isRunning = true;

        @Override
        public void simpleInitApp() {
            super.simpleInitApp();
            flyCam.setDragToRotate(true);
            Box b = new Box(1, 1, 1);
            player = new Geometry("Player", b);
            Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
            mat.setColor("Color", ColorRGBA.Blue);
            player.setMaterial(mat);
            rootNode.attachChild(player);
            // 添加鼠标监听
            inputManager.addMapping("pick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
            inputManager.addListener((ActionListener) (name, isPressed, tpf) -> {
                if (isPressed) {
                    System.out.println(inputManager.getCursorPosition());
                    System.out.println(settings.getWidth());
                    System.out.println(settings.getHeight());
                    // @Nullable
                    // Geometry picked = JmeUtil.getGeometryFromCursor(root, cam, inputManager);
                    // if (picked != null) {
                    // System.err.println(picked);
                    // }
                    @Nullable Vector3f point = JmeUtil.getContactPointFromCursor(rootNode, cam, inputManager);
                    if (point != null) {
                        Geometry ball = JmeUtil.getSphere(assetManager, 32, 0.1f, ColorRGBA.Red);
                        rootNode.attachChild(ball);
                        ball.setLocalTranslation(point);
                    }
                }
            }, "pick");
        // initKeys(); // load my custom keybinding
        }
    };
    application.setSettings(settings);
    application.setShowSettings(false);
    return application;
}
Also used : Geometry(com.jme3.scene.Geometry) Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) JmeToJFXApplication(com.jme3x.jfx.injfx.JmeToJFXApplication) AppSettings(com.jme3.system.AppSettings) JmeUtil(com.cas.sim.tis.util.JmeUtil) Vector3f(com.jme3.math.Vector3f) ActionListener(com.jme3.input.controls.ActionListener) Canvas(javafx.scene.canvas.Canvas) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) StackPane(javafx.scene.layout.StackPane) MouseInput(com.jme3.input.MouseInput) Application(javafx.application.Application) Nullable(org.jetbrains.annotations.Nullable) JFXMouseInput(com.jme3x.jfx.injfx.input.JFXMouseInput) Stage(javafx.stage.Stage) Material(com.jme3.material.Material) JmeToJFXIntegrator(com.jme3x.jfx.injfx.JmeToJFXIntegrator) ColorRGBA(com.jme3.math.ColorRGBA) NotNull(org.jetbrains.annotations.NotNull) Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) JmeToJFXApplication(com.jme3x.jfx.injfx.JmeToJFXApplication) AppSettings(com.jme3.system.AppSettings) Vector3f(com.jme3.math.Vector3f) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JmeToJFXApplication

use of com.jme3x.jfx.injfx.JmeToJFXApplication in project TeachingInSimulation by ScOrPiOzzy.

the class TestJmeToJFXImageView method makeJmeApplication.

@NotNull
private static JmeToJFXApplication makeJmeApplication() {
    final AppSettings settings = JmeToJFXIntegrator.prepareSettings(new AppSettings(true), 60);
    final JmeToJFXApplication application = new JmeToJFXApplication() {

        protected Spatial player;

        @Override
        public void simpleInitApp() {
            super.simpleInitApp();
            // stateManager.attach(new SceneCameraState());
            float aspect = (float) cam.getWidth() / cam.getHeight();
            // flyCam.setDragToRotate(true);
            cam.setFrustumPerspective(45f, aspect, 0.01f, 1000);
            assetManager.registerLocator("E:\\JME_SDKPROJ_HOME\\robot_assets\\assets\\", FileLocator.class);
            assetManager.registerLocator("http://192.168.1.19:8082/assets/", UrlLocator.class);
            player = assetManager.loadModel("Models\\elecComp\\DZ47LEC32.j3o");
            // player = assetManager.loadModel("Model/RT28N-32X/RT28N-32X.j3o");
            // Box b = new Box(1, 1, 1);
            // player = new Geometry("Player", b);
            // Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
            // mat.setColor("Color", ColorRGBA.Blue);
            // player.setMaterial(mat);
            rootNode.attachChild(player);
        }
    };
    application.setSettings(settings);
    application.setShowSettings(false);
    return application;
}
Also used : JmeToJFXApplication(com.jme3x.jfx.injfx.JmeToJFXApplication) AppSettings(com.jme3.system.AppSettings) Spatial(com.jme3.scene.Spatial) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with JmeToJFXApplication

use of com.jme3x.jfx.injfx.JmeToJFXApplication in project TeachingInSimulation by ScOrPiOzzy.

the class TestJmeToJFXImageView method start.

@Override
public void start(@NotNull final Stage stage) {
    final ImageView imageView = new ImageView();
    imageView.setFocusTraversable(true);
    imageView.setOnMouseClicked(event -> imageView.requestFocus());
    final StackPane stackPane = new StackPane(imageView);
    final Scene scene = new Scene(stackPane, 600, 600);
    imageView.fitWidthProperty().bind(stackPane.widthProperty());
    imageView.fitHeightProperty().bind(stackPane.heightProperty());
    stage.setTitle("Test");
    stage.setScene(scene);
    stage.show();
    stage.setOnCloseRequest(event -> System.exit(0));
    // creates jME application
    final JmeToJFXApplication application = makeJmeApplication();
    // integrate jME application with ImageView
    JmeToJFXIntegrator.startAndBindMainViewPort(application, imageView, Thread::new);
}
Also used : JmeToJFXApplication(com.jme3x.jfx.injfx.JmeToJFXApplication) ImageView(javafx.scene.image.ImageView) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 4 with JmeToJFXApplication

use of com.jme3x.jfx.injfx.JmeToJFXApplication in project TeachingInSimulation by ScOrPiOzzy.

the class TestJmeToJFXCanvas method start.

@Override
public void start(@NotNull final Stage stage) {
    final Canvas canvas = new Canvas();
    canvas.getProperties().put(JFXMouseInput.PROP_USE_LOCAL_COORDS, true);
    canvas.setFocusTraversable(true);
    canvas.setOnMouseClicked(event -> canvas.requestFocus());
    final Button button = new Button("BUTTON");
    final StackPane stackPane = new StackPane(canvas, button);
    final Scene scene = new Scene(stackPane, 600, 600);
    canvas.widthProperty().bind(stackPane.widthProperty());
    canvas.heightProperty().bind(stackPane.heightProperty());
    stage.setTitle("Test");
    stage.setScene(scene);
    stage.show();
    stage.setOnCloseRequest(event -> System.exit(0));
    // creates jME application
    final JmeToJFXApplication application = makeJmeApplication();
    // integrate jME application with Canvas
    JmeToJFXIntegrator.startAndBindMainViewPort(application, canvas, Thread::new);
}
Also used : JmeToJFXApplication(com.jme3x.jfx.injfx.JmeToJFXApplication) Button(javafx.scene.control.Button) Canvas(javafx.scene.canvas.Canvas) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Aggregations

JmeToJFXApplication (com.jme3x.jfx.injfx.JmeToJFXApplication)4 Scene (javafx.scene.Scene)3 StackPane (javafx.scene.layout.StackPane)3 AppSettings (com.jme3.system.AppSettings)2 Canvas (javafx.scene.canvas.Canvas)2 Button (javafx.scene.control.Button)2 NotNull (org.jetbrains.annotations.NotNull)2 JmeUtil (com.cas.sim.tis.util.JmeUtil)1 MouseInput (com.jme3.input.MouseInput)1 ActionListener (com.jme3.input.controls.ActionListener)1 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)1 Material (com.jme3.material.Material)1 ColorRGBA (com.jme3.math.ColorRGBA)1 Vector3f (com.jme3.math.Vector3f)1 Geometry (com.jme3.scene.Geometry)1 Spatial (com.jme3.scene.Spatial)1 Box (com.jme3.scene.shape.Box)1 JmeToJFXIntegrator (com.jme3x.jfx.injfx.JmeToJFXIntegrator)1 JFXMouseInput (com.jme3x.jfx.injfx.input.JFXMouseInput)1 Application (javafx.application.Application)1