winder / Universal-G-Code-Sender

A cross-platform G-Code sender for GRBL, Smoothieware, TinyG and G2core.
http://winder.github.io/ugs_website/
GNU General Public License v3.0
1.86k stars 757 forks source link

jMonkeyEngine3-based visualizer proof-of-concept #2408

Closed tangmi closed 6 months ago

tangmi commented 6 months ago

Hi @breiler et al.! Thank you for maintaining a lovely program that continues to surprise me with useful features (I just recently learned of the visualizer's "jog to here" action).

I was looking into filing an unrelated issue and stumbled on your comment here https://github.com/winder/Universal-G-Code-Sender/issues/737#issuecomment-486951520 suggesting changing the rendering backend for the visualizer. Despite not being a Java dev (or familiar with UGS, jMonkeyEngine, etc), curiosity got the better of me and after some hacking I've come up with a (highly incomplete) visualizer plugin that uses jMonkeyEngine3 with LWJGL2.

First, some screenshots: image image image

Benefits

Why jMonkeyEngine3?

I evaluated some other options and here are my notes:

jMonkeyEngine3 is much better documented and for sure has more community support and active development. However, it feels like a heavier and more opinionated engine when compared to Ardor3D. Ardor3D, from my cursory look, feels less like a game engine and more geared towards things like visualizations, etc. It allows the application to control the main loop and [drive frame updates](https://jogamp.org/deployment/ardor3d/javadoc/com/ardor3d/framework/FrameHandler.html#updateFrame()). Overall, the Awt integration seems more robust in Ardor3D.

What next?

If this change seems useful, I think some possible next steps could be:

I'm happy to discuss and help where I can, but I'll definitely need help with Maven and UGS integration.

I am currently on holiday and will soon not have much free time to work on this (sorry!).

Thank you again for UGS and thank you for time!

breiler commented 6 months ago

Thanks for looking into this!

I did some similar experiments trying to port from JOGL to LWJGL some time ago, but stumbled on the poor AWT integration. I could make it work decently in a standalone program but as soon as it was integrated with the NetBeans platform I got into problems when for instance resizing the window.

Unfortunately I get the same problem when trying your sample. My conclusion is that LWJGL is not suited to run in a desktop application. If these problems can't be fixed to make LWJGL run smoothly I think that we are stuck with JOGL. I looked at the old jme3-jogl library and it was using the older JOGL 2.3.2 which has problems running on both ARM32, ARM64 and MacOSX.

The Renanse/Ardor3D fork seems to also have dropped the support for JOGL.

So if we want a scene graph we will probably have to roll our own... 😞

tangmi commented 6 months ago

Thank you for taking a look! Bummer that it seems every option here is not without its own issues.

Unfortunately I get the same problem when trying your sample.

Out of curiosity, what are the resize issues you're seeing? I'll admit I was only able to figure out how to run the Visualizer3TestMain and not UGS itself (again, a "me" problem), but I did not see any issues at least on Windows (at least no more than normal for OpenGL πŸ˜„).

The Renanse/Ardor3D fork seems to also have dropped the support for JOGL.

It looks like the JogAmp fork has been keeping the JOGL backend support up to date. IIUC it was forked originally because the Renanse/Ardor3D repo was abandoned, but that doesn't seem to be the case anymore. gouessej seems aware of this and has ported some of the changes over, I wonder if renanse and gouessej can be convinced to re-merge the forks..?

So if we want a scene graph we will probably have to roll our own... 😞

I wonder if we can identify what's going wrong with LWJGL and get some help fixing it upstream. I'm not very familiar with LWJGL and JOGL, but my understanding is that they're pretty straightforward bindings to OpenGL with extra implementation to deal with input, windowing, etc. I imagine issues with resizing may be somewhere in that windowing code. It looks like LWJGL3 might use GLFW for windowing so perhaps better AWT support may be possible?

breiler commented 6 months ago

Out of curiosity, what are the resize issues you're seeing? I'll admit I was only able to figure out how to run the Visualizer3TestMain and not UGS itself (again, a "me" problem), but I did not see any issues at least on Windows (at least no more than normal for OpenGL πŸ˜„).

If you start UGS Platform and open your Visualizer3 panel and try to resize it. For me I can only make the panel larger - it will prevent me from making it smaller. When doing resizing or moving the panel to a different pane it is extremly sluggish.

It looks like the JogAmp fork has been keeping the JOGL backend support up to date. IIUC it was forked originally because the Renanse/Ardor3D repo was abandoned, but that doesn't seem to be the case anymore. gouessej seems aware of this and has ported some of the changes over, I wonder if renanse and gouessej can be convinced to re-merge the forks..?

Gouessejs version is distributed here as a snapshot: https://jogamp.org/deployment/maven-ardor3d/org/jogamp/ardor3d/ I tried adding the repository and allow snapshot builds, but I got stuck with the Java version as he is using Java 20. But that could may be a way forward...

I wonder if we can identify what's going wrong with LWJGL and get some help fixing it upstream.

If we managed to get it working properly on all (macosx x64/arm64, Linux x64/arm/arm64, Windows x64) platforms I'd prefer this over JOGL as it seems to have more developers. I am currently working on some other stuff, I might take this up later.

tangmi commented 6 months ago

Happy new years! Thanks for your replies!

If you start UGS Platform and open your Visualizer3 panel and try to resize it. For me I can only make the panel larger - it will prevent me from making it smaller. When doing resizing or moving the panel to a different pane it is extremly sluggish.

Strange, I'm not seeing that on Windows 10. I am, however, seeing a much lower frame rate and no multisampling, along with other general weirdness.

If we managed to get it working properly on all (macosx x64/arm64, Linux x64/arm/arm64, Windows x64) platforms I'd prefer this over JOGL as it seems to have more developers. I am currently working on some other stuff, I might take this up later.

I found lwjglx/lwjgl3-awt, which seems like a good implementation of AWT integration-- I assume you're already familiar.

I tried to hackily port UGS to lwjgl to investigate what AWT issues there were (https://github.com/winder/Universal-G-Code-Sender/compare/master...tangmi:Universal-G-Code-Sender:try-switch-to-lwjgl) but I think I'm making some mistakes in building-- I was not able to get the maven files or build commands to consistently build successfully... I don't think I know enough about Maven or NetBeans to be touching the build files productively πŸ˜„.

In my change linked above, I think I'm just running into an issue where the visualizer needs to depend on lwjgl and friends but doesn't have dependencies in the class path (?). If there's a smoking gun here, please let me know. Otherwise, I may need help with the dependencies or may need to wait until UGS switches over to jME3/Ardor3D before being able to contribute graphics changes.

Thanks again for your time!

breiler commented 6 months ago

I resurrected my ancient branch when I was looking at this: https://github.com/breiler/Universal-G-Code-Sender/tree/bugfix/lwjgl

It works okish on Linux.

On MacOSX the stand alone application works, but when integrating in NetBeans it didn't refresh the window properly.

tangmi commented 6 months ago

Thanks for the link, I've updated my branch and got it building and running on Windows. I'll see what I can do with the macOS issues.

~edit: FYI looks like lwjgl3-awt doesn't support arm64 mac. I'm working around this by using the x64 JDK (and running into other java issues). I'm not sure what it takes to package java libs but it may just be asking nicely to build for arm?~

tangmi commented 6 months ago

I did a little more digging and will write up some notes here. I'm going to close this for now to keep your PR queue clean.