JavaFX embedded in jme3

one example is:

 var imageView = new ImageView();
        
    var settings = JmeToJfxIntegrator.prepareSettings(new AppSettings(true), 60);
    var application = new MySomeApplication();
    
    JmeToJfxIntegrator.startAndBindMainViewPort(application, imageView, Thread::new);

I already put that in my code, but maybe not in the right location ?

	ImageView imageView = new ImageView();
        
	AppSettings settings = JmeToJfxIntegrator.prepareSettings(new AppSettings(true), 60);
   	settings.setRenderer(AppSettings.LWJGL_OPENGL2);
   	settings.put("Width", 800);
   	settings.put("Height", 600);
   	settings.put("Title", "Vue 3D");
   	settings.put("VSync", true);
   	settings.put("Samples", 4);//Anti-Aliasing

    VersperaApplication application = new VersperaApplication();
    application.setSettings(settings);
    application.setShowSettings(false);
    	  
    	 
	
				    
	Interface3DPanel interf=new Interface3DPanel(_view.baseImagePath) ;
	interf.vaImageView = imageView;
	interf.getChildren().add(interf.vaImageView);
	application.panel=interf;
		    	  
	JmeToJfxIntegrator.startAndBindMainViewPort(application, imageView, Thread::new);

		    	  try {
					Thread.sleep(1000, 0);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		    	  _model.camchase=new VersperaChaseCamera(application.getCamera(),application.getInputManager());
		    	  
		    	  _model.camchase.setMaxVerticalRotation((float)Math.PI*2.0f);
		    	  _model.camchase.setMinVerticalRotation(-(float)Math.PI*2.0f);
		    	  _model.camchase.setDownRotateOnCloseViewOnly(false);
		    	  
		    	  
		    	  application.enqueue(new Callable<Spatial>() {
				        public Spatial call() throws Exception {
				        	application.getAssetManager().registerLocator(_model.baseShaderResourcePath, FileLocator.class);
				        	application.getAssetManager().registerLocator(_model.baseImagePath, FileLocator.class);
				        	DirectionalLight l1=new DirectionalLight();
				        	l1.setDirection(new Vector3f(1.0f,0.0f,0.0f));
				        	DirectionalLight l2=new DirectionalLight();
				        	l2.setDirection(new Vector3f(-1.0f,0.0f,0.0f));
				        	DirectionalLight l3=new DirectionalLight();
				        	l3.setDirection(new Vector3f(0.0f,1.0f,0.0f));
				        	DirectionalLight l4=new DirectionalLight();
				        	l4.setDirection(new Vector3f(0.0f,-1.0f,0.0f));
				        	AmbientLight al = new AmbientLight();
				        	DirectionalLight pl=new DirectionalLight();
				        	pl.setColor(new ColorRGBA(1f,1f,1f,1.0f));
				        	pl.setDirection(application.getCamera().getDirection());
				        	application.getRootNode().addLight(pl);
				           
							Sphere sp=new Sphere(30,30,1.0f);
						    Geometry sphere=new Geometry("sphere",sp);
							Material mat=new Material(application.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); 
							mat.setColor("Color", ColorRGBA.Green);
							mat.getAdditionalRenderState().setFaceCullMode(FaceCullMode.FrontAndBack);
							sphere.setMaterial(mat);
							_model.nodetarget=new Node();
							_model.nodetarget.setName("target");
							_model.nodetarget.attachChild(sphere);
							_model.nodetarget.addControl(_model.camchase);
							application.getRootNode().attachChild(_model.nodetarget);
						
				        	return null;
				        }
				    });
		    	  application.startCanvas();
		    	  
		    	  
		    	  
					Scene scene3D = new Scene(interf, 1440, 720);
			    	  
					Stage stage3D = new Stage();
					stage3D.setScene(scene3D);
					stage3D.setTitle("Verspera - Fenêtre 3D");
					stage3D.show();

I mean could you execute in separated project only my example?

Here is what I tried:

package jmejfxtest;

import com.jme3.jfx.injfx.JmeToJfxApplication;
import com.jme3.jfx.injfx.JmeToJfxIntegrator;
import com.jme3.system.AppSettings;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;

public class JmeJfxTest extends Application{

@Override
public void start(Stage primaryStage) {
	try {
		BorderPane root = new BorderPane();
		
		ImageView imageView = new ImageView();
		AppSettings settings = JmeToJfxIntegrator.prepareSettings(new AppSettings(true), 60);
		JmeToJfxApplication application = new JmeToJfxApplication();   
		JmeToJfxIntegrator.startAndBindMainViewPort(application, imageView, Thread::new);
		root.setCenter(imageView);

		Scene scene = new Scene(root,1440,720);

		primaryStage.setTitle("Test Jme Jfx");
		primaryStage.setScene(scene);
		primaryStage.show();
	

	} catch(Exception e) {
		e.printStackTrace();
	}
}

public static void main(String[] args) {
	launch(args);
}

}

But I’m getting this error now:

Exception in Application start method
java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:941)
Caused by: java.lang.RuntimeException: Exception in Application start method
at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NoClassDefFoundError: com/jme3/system/AppSettings
at jmejfxtest.JmeJfxTest.start(JmeJfxTest.java:25)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
… 1 more
Caused by: java.lang.ClassNotFoundException: com.jme3.system.AppSettings
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
… 10 more
Exception running application jmejfxtest.JmeJfxTest

And when trying to build pom.xml, here is what I get (with clean test maven goal):

[INFO] Scanning for projects…
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jmejfxtest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-clean-plugin:2.5:clean (default-clean) @ jmejfxtest —
[INFO] Deleting /users/lucaparl/Documents/PFE 2018 ETIS/jmejfxtest/target
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ jmejfxtest —
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ jmejfxtest —
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /users/lucaparl/Documents/PFE 2018 ETIS/jmejfxtest/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error reading /users/lucaparl/.m2/repository/org/jmonkeyengine/jme3-core/3.2.0-stable/jme3-core-3.2.0-stable.jar; ZipFile invalid LOC header (bad signature)
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.308 s
[INFO] Finished at: 2018-07-06T14:50:19+02:00
[INFO] Final Memory: 9M/40M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jmejfxtest: Compilation failure: Compilation failure:
[ERROR] error reading /users/lucaparl/.m2/repository/org/jmonkeyengine/jme3-core/3.2.0-stable/jme3-core-3.2.0-stable.jar; ZipFile invalid LOC header (bad signature)
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] → [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

it looks like you have a wrong maven’s POM file, could you show this file here, please?

Unfortunately I haven’t been able to display xml code here, neither to upload xml files, so here is a screenshot:

I think your POM misses the jME’s repository:

<repositories>
                <repository>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                    <id>bintray-jmonkeyengine-org.jmonkeyengine</id>
                    <name>bintray</name>
                    <url>https://dl.bintray.com/jmonkeyengine/org.jmonkeyengine</url>
                </repository>
            </repositories>

because I see your “test-project” can’t resolve jME dependencies.

Thanks, but I tried adding it and it didn’t solve the problem

which errors do you have now?

pom.xml:

[INFO] Scanning for projects…
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building jmejfxtest 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] — maven-clean-plugin:2.5:clean (default-clean) @ jmejfxtest —
[INFO] Deleting /users/lucaparl/Documents/PFE 2018 ETIS/jmejfxtest/target
[INFO]
[INFO] — maven-resources-plugin:2.6:resources (default-resources) @ jmejfxtest —
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] — maven-compiler-plugin:3.1:compile (default-compile) @ jmejfxtest —
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 1 source file to /users/lucaparl/Documents/PFE 2018 ETIS/jmejfxtest/target/classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] error reading /users/lucaparl/.m2/repository/org/jmonkeyengine/jme3-core/3.2.0-stable/jme3-core-3.2.0-stable.jar; ZipFile invalid LOC header (bad signature)
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[INFO] 3 errors
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.276 s
[INFO] Finished at: 2018-07-06T16:22:50+02:00
[INFO] Final Memory: 9M/40M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project jmejfxtest: Compilation failure: Compilation failure:
[ERROR] error reading /users/lucaparl/.m2/repository/org/jmonkeyengine/jme3-core/3.2.0-stable/jme3-core-3.2.0-stable.jar; ZipFile invalid LOC header (bad signature)
[ERROR] Source option 5 is no longer supported. Use 6 or later.
[ERROR] Target option 1.5 is no longer supported. Use 1.6 or later.
[ERROR] → [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

and java code:

Erreur : impossible de trouver ou de charger la classe principale jmejfxtest.JmeJfxTest
Causé par : java.lang.ClassNotFoundException: jmejfxtest.JmeJfxTest

I think you have wrong cached jME libraries, could you clear maven local cache?
Also, you need to add source/target compilation properties to compile your project as java 8.

I’ll let you know when I try that one of these days. Thanks!

I tried what you suggested, (I removed the .m2/repository folder, and then I added this piece of code to pom.xml:

pom_prop

) and the program is now running, however the JME window is still not embedded in the JFX one, and I’m getting these errors:

juil. 09, 2018 11:21:10 AM com.jme3.system.JmeDesktopSystem initialize
INFOS: Running on jMonkeyEngine 3.2-stable

  • Branch: HEAD
  • Git Hash: 95d33e6
  • Build Date: 2018-01-05
    juil. 09, 2018 11:21:10 AM com.jme3.system.lwjgl.LwjglContext printContextInitInfo
    INFOS: LWJGL 3.1.2 build 29 context running on thread Thread-2
  • Graphics Adapter: GLFW 3.3.0 X11 GLX EGL clock_gettime /dev/js shared
    juil. 09, 2018 11:21:10 AM com.jme3.renderer.opengl.GLRenderer loadCapabilitiesCommon
    INFOS: OpenGL Renderer Information
  • Vendor: Intel Open Source Technology Center
  • Renderer: Mesa DRI Intel® Haswell Desktop
  • OpenGL Version: 3.0 Mesa 11.2.2
  • GLSL Version: 1.30
  • Profile: Compatibility
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MeshLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SkeletonLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.MaterialLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.ogre.SceneLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.blender.BlenderModelLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.fbx.FbxLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GltfLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.BinLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.scene.plugins.gltf.GlbLoader
    juil. 09, 2018 11:21:10 AM com.jme3.asset.AssetConfig loadText
    AVERTISSEMENT: Cannot find loader com.jme3.audio.plugins.OGGLoader
    juil. 09, 2018 11:21:10 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio Renderer Information
  • Device: OpenAL Soft
  • Vendor: OpenAL Community
  • Renderer: OpenAL Soft
  • Version: 1.1 ALSOFT 1.17.2
  • Supported channels: 64
  • ALC extensions: ALC_ENUMERATE_ALL_EXT ALC_ENUMERATION_EXT ALC_EXT_CAPTURE ALC_EXT_DEDICATED ALC_EXT_disconnect ALC_EXT_EFX ALC_EXT_thread_local_context ALC_SOFTX_device_clock ALC_SOFT_HRTF ALC_SOFT_loopback ALC_SOFTX_output_limiter ALC_SOFT_pause_device
  • AL extensions: AL_EXT_ALAW AL_EXT_BFORMAT AL_EXT_DOUBLE AL_EXT_EXPONENT_DISTANCE AL_EXT_FLOAT32 AL_EXT_IMA4 AL_EXT_LINEAR_DISTANCE AL_EXT_MCFORMATS AL_EXT_MULAW AL_EXT_MULAW_BFORMAT AL_EXT_MULAW_MCFORMATS AL_EXT_OFFSET AL_EXT_source_distance_model AL_EXT_SOURCE_RADIUS AL_EXT_STEREO_ANGLES AL_LOKI_quadriphonic AL_SOFT_block_alignment AL_SOFT_deferred_updates AL_SOFT_direct_channels AL_SOFT_gain_clamp_ex AL_SOFT_loop_points AL_SOFT_MSADPCM AL_SOFT_source_latency AL_SOFT_source_length AL_SOFT_source_resampler AL_SOFT_source_spatialize
    juil. 09, 2018 11:21:10 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio effect extension version: 1.0
    juil. 09, 2018 11:21:10 AM com.jme3.audio.openal.ALAudioRenderer initOpenAL
    INFOS: Audio max auxiliary sends: 2
    Exception in thread “JavaFX Application Thread” java.lang.ClassCastException: com.jme3.system.lwjgl.LwjglDisplay cannot be cast to com.jme3.jfx.injfx.JmeOffscreenSurfaceContext
    at com.jme3.jfx.injfx.processor.AbstractFrameTransferSceneProcessor.bindDestination(AbstractFrameTransferSceneProcessor.java:381)
    at com.jme3.jfx.injfx.processor.ImageViewFrameTransferSceneProcessor.bindDestination(ImageViewFrameTransferSceneProcessor.java:38)
    at com.jme3.jfx.injfx.processor.ImageViewFrameTransferSceneProcessor.bindDestination(ImageViewFrameTransferSceneProcessor.java:15)
    at com.jme3.jfx.injfx.processor.AbstractFrameTransferSceneProcessor.lambda$bind$4(AbstractFrameTransferSceneProcessor.java:360)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    at java.base/java.lang.Thread.run(Thread.java:844)

I don’t understand why your application creates incorrect conext :frowning:

I’ve been trying to do the other way around by embedding JavaFX buttons into JME using the other example provided, but I’m wondering what I should write in my Main class code. I tried this:

public class JmeJfxTest extends Application{

@Override
public void start(Stage primaryStage) {
	try {
		
		
		MyApplication myapp = new MyApplication();
		myapp.setShowSettings(false);
		myapp.simpleInitApp();
		myapp.start();


	} catch(Exception e) {
		e.printStackTrace();
	}
}

public static void main(String[] args) {
	launch(args);
}

}

But I get a null pointer exception:

java.lang.NullPointerException
at com.jme3.jfx.injme.cursor.proton.ProtonCursorProvider.(ProtonCursorProvider.java:48)
at com.jme3.jfx.injme.JmeFxContainerImpl.install(JmeFxContainerImpl.java:71)
at com.jme3.jfx.injme.JmeFxContainer.install(JmeFxContainer.java:26)
at jmejfxtest.MyApplication.simpleInitApp(MyApplication.java:17)
at jmejfxtest.JmeJfxTest.start(JmeJfxTest.java:50)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
at java.base/java.lang.Thread.run(Thread.java:844)

What should I do ?

could you share your “sample” on github or bitbucket? I absolutely don’t understand what happens on your machine.

Here it is: GitHub - ltp7/jmejfxtest

could you give me write access to this repository, please? @javasabr

I have fixed your test in my fork:

Thanks a lot, it works for me too! I’ll let you know if I have other issues in the future.