JavaFX embedded in jme3

Oh for the normal stuff, you can basically use everything on the web.
http://docs.oracle.com/javase/8/javase-clienttechnologies.htm

There are two classes provided, AbstractHud and Abstractwindow (and the fxml version of them) wich are the most common entry points.
Basically the either provide a window kinda like swing innerframe or work on a fullscreen scene.

Also take a look at the examples in test, basically they already do everything that is necessary.
One noteable difference is probably, that you only have one Scene internally, wich has a group, where all custom stuff is attached to.

JavaFX + jME 3 my project :slight_smile:

javaFX the best UI engine :smiley:

4 Likes

Nice, the full Ui is done with jfx?

Also for your third module the active effect, how did you do it, is there a progressbar involved?

Nice, the full Ui is done with jfx?
Yes, full UI is implemented on JavaFX.
Also for your third module the active effect, how did you do it, is there a progressbar involved?
activeIndicator = new ProgressBar(INDETERMINATE_PROGRESS);
		activeIndicator.setId(FAST_PANEL_CELL_ACTIVE_INDICATOR);
		activeIndicator.prefWidthProperty().bind(activePane.widthProperty());
		activeIndicator.prefHeightProperty().bind(activePane.heightProperty());
		activeIndicator.setRotate(-90);

Hi, I haven’t been paying attention here for a while and was wondering if someone could sum up progress and point me in the right direction. I want to create an application that is not a game, but uses jme3 for visualization and using JavaFX for the windows and the rest of the GUI. The user should be able to interact with the JME3 view via the mouse (for example moving the camera).

So far I have had working the examples by David Bernard with JME3 inside an ImageView in a JavaFX window.

JME3 in JavaFX window

But then I got distracted and left it for a while hoping that things would advance a little. That was about 3 months ago. Now I have just setup a test project and have the JME3-JFX as a dependency.

With the exception of TestDisplayInImageView all the tests use SimpleApplication as a start point. Are there any examples of how to start out using AbstractWindow and would it better fit my use case of jme3 as a visual tool? I realise I could use the JavaFX 3d stuff as per some examples on the web but I want it to look modern, and all the JavaFX 3d stuff looks it was done back in 1987 on an Amiga 500. No disrespect to the Amiga, but that was 25 years ago.

Cheers,

It really depends on what you do, if jme is just a small part of a desktop appliation, jme in jfx makes sense.
But much more than rendering it is currently not added i think. (I never used that direction, so i cannot comment on details)

For the other direction, the other tests use both AbstractWindow and Abstracthud. (However in the fxml flavour)

Hi rob_bb,

I’ve a waiting project to edit shader (I create jme in jfx for it). I just push the code to github so you can play with it : GitHub - davidB/shader_editor: [wip] a shader editor (glsl vert + frag)

In it I drive ChaseCam via jfx event. I didn’t reroute jfx event to an inputManager. My strategie is to use jfx event to do the final action or call onAnalog if the final action is not public (like ChaseCamere.rotate(…)

[java]
fcam.subscribe((cam) -> {
try {
final Vector3f lastPosition = new Vector3f();
cam.setEnabled(true);
cam.setRotationSpeed(0.1f);
cam.setMaxVerticalRotation(FastMath.TWO_PI);
//cam.setDragToRotate(true); // <– NPE because inputMnager is null
javafx.scene.Node evtReceiver = (javafx.scene.Node) controller.image;
evtReceiver.getParent().setMouseTransparent(false);
evtReceiver.setFocusTraversable(false);
evtReceiver.addEventHandler(MouseEvent.ANY, (e) -> {
//System.err.println("mouseEvent " + e);
if (MouseEvent.MOUSE_ENTERED.equals(e.getEventType())) {
controller.image.requestFocus(); // ?
e.consume();
} else if (MouseEvent.MOUSE_PRESSED.equals(e.getEventType()) /&& dragModeActiveProperty.get()/) {
lastPosition.x = (float)e.getX();
lastPosition.y = (float)e.getY();
e.consume();
} else if (MouseEvent.MOUSE_DRAGGED.equals(e.getEventType())) {
float deltaX = (float) e.getX() - lastPosition.x;
float deltaY = (float) e.getY() - lastPosition.y;
cam.onAnalog(ChaseCamera.ChaseCamMoveRight, deltaX, 0);
cam.onAnalog(ChaseCamera.ChaseCamUp, deltaY, 0);
lastPosition.x = (float)e.getX();
lastPosition.y = (float)e.getY();
e.consume();
}
});
evtReceiver.addEventHandler(KeyEvent.KEY_PRESSED, (e) -> {
System.err.println("keyEvent " + e);
if (KeyCode.A == e.getCode()) {
cam.onAnalog(ChaseCamera.ChaseCamZoomIn, 0.2f, 0);
e.consume();
} else if (KeyCode.Q == e.getCode()) {
cam.onAnalog(ChaseCamera.ChaseCamZoomOut, 0.2f, 0);
e.consume();
}
});
} catch(Exception exc) {
exc.printStackTrace();
}
});
[/java]

1 Like

Hi Oskar,

if you’re interested by a more complexe sample (multi-pages), you can take a look,… at jme3_skel : GitHub - davidB/jme3_skel: my project skeleton for jme 3.0 projects (gradle based)

1 Like

Nice project! Will you add GLSL Highlighting? Like JME SDK has?
Or can i use external text editor like Kate(which has GLSL support)?

Thanks,
It’s a sleeping side project (low priority), I just share as a sample about how to use jme into javafx app.
If I continue to work on it, it was planned to provide highlighting and/or node editor. I’m not sur of the approach to use lib,… (recently I use freemarker as macro to experiment port of some G3D shader lib to jme).

EDIT: last year I wrote a webgl glsl editor for my webgl wrapper lib, you can try it at viewer for test - glf

1 Like

I just came back to check out the forum after a few months, and I can’t believe I never saw this thread for the past year… I asked about something like this previously, I didn’t think we could combine them both… Awesome work!!!

@javasabr said: JavaFX + jME 3 my project :) https://www.youtube.com/watch?v=efIWglcKND8 javaFX the best UI engine :D

классно! :slight_smile:

I noticed a bug in isCovered(): The image is stored ABGR, ABGR, etc. not RGBA, RGBA. So final int alpha = data.get(3 + 4 * (y * this.pWidth + x)); checks the red component not the alpha. I don’t know if the error is here, or if the data is stored the wrong way. :stuck_out_tongue:

@tuffe said: I noticed a bug in isCovered(): The image is stored ABGR, ABGR, etc. not RGBA, RGBA. So final int alpha = data.get(3 + 4 * (y * this.pWidth + x)); checks the red component not the alpha. I don't know if the error is here, or if the data is stored the wrong way. :p

On windows it is BGRA_PRE rather than ABGR. But yes, you are right, this check should take pixel format into account, as I think that on linux it is ABGR format.

@abies said: On windows it is BGRA_PRE rather than ABGR. But yes, you are right, this check should take pixel format into account, as I think that on linux it is ABGR format.

I’m on Windows, and for me it’s ABGR.

Ok, it might be related to JME3 3.0 compatibility layer. I’m using 3.1 git version - if you are using 3.0, then all jfx-jme goes through some emulation layer which I don’t really know much about.

In any case, we need to parameterize this method to follow selected pixel format, rather than to work only on windows-jme3.1

with jme 3.0.10, the compatibility layer convert to Format.ABGR8.
I can work and push a “fix” for isCovered, later today.

EDIT: fix isCovered to work with ABGR8, ARGB8, BGRA8 + add a TestIsCovered by davidB · Pull Request #26 · empirephoenix/JME3-JFX · GitHub

Hi!

I have a few questions after working with JavaFX a few days.

  1. I noticed something a bit weird. I remake my scene graph every frame, because it’s simpler than modifying an old one. So far it’s fast enough, and I do it a couple of hundred times per second. But I noticed that mouse click events often disappear when I do that. Say I have a Label, and it listens to MOUSE_PRESSED events. Only about every 20th time I press it does it trigger the handler. Is it an issue with JavaFX, or can it be fixed in JME3-JFX, do you think?

  2. How does drag-and-drop work? I think I heard someone say you had to do something special to get it to work.

  3. I was thinking about how one could change isCovered to somehow allow mouse click through some JavaFX thing that is not invisible. Has anyone done this already? I can think of a few ways with varying degree of difficulty and robustness:

Method 1: Use some specific alpha, like 126/127, to mean that mouse clicks on that should not count, but it will look like a solid color anyway, probably. Can it go wrong if something behind a 126/127 alpha thing is more transparent? Does the final image end up with some other alpha then?
Method 2: Pass all events to JavaFX. In JavaFX, use an invisible Pane as a parent, behind your whole scene. For any event that is not consumed earlier, that Pane gets the event, and then you know that it went through, and then JME gets it. Will that round trip cause noticable delay?
Method 3: Keep track of the shapes that you are using for things that should block the mouse clicks, and in isCovered check if the mouse is in any of the shapes. Should work, but is kind of tedious to implement, unless there is a smart way to get all the shapes.

Thoughts?

1.)
i think events are invalidated if the object is removed,
why not hash your data, and compare if recreation is necessary instead, before doing it?

2.)
Take a look at the example for drag and drop.

3.)
-> 1 might make problems with multiple transparent objects behind each other, yes
-> 2 converting the events needs processing time, and i fell it is not the best approach here
-> 3 yeah not that nice to implement

I would suggest to make it an interface, and allow users to push via guimanager their own custom logic.
-> special thinking here is required as for usefull checks they would need access to jfx, but events are in jme thread.

Oskar, with the “fix” of isCovered I also include a sample test. You can try it and you can modify it to include other case (alpha 127/126, …).