jMonkeyEngine / sdk

The jMonkeyEngine3 Software Development Kit based on Netbeans
BSD 3-Clause "New" or "Revised" License
314 stars 100 forks source link

ProjectAssetManager doesn't load resources from dependency Jar files in Gradle projects #373

Closed peedeeboy closed 1 year ago

peedeeboy commented 2 years ago

As mentioned by @yaRnMcDonuts in #305 :

Yes I notice that as well. The drop down menu contains all my own shaders located in my projects assets folder, but none of the MatDefs from dependencies such as JME core or Terrain.

I am also noticing that the material editor begins to work again with my GradleTemplate based project when I open up a material using a MatDef from my assets folder, so I believe if this issue is resolved then it will also resolve the other issue with Gradle projects in the SDK where the visual Material Editor doesn't work for the stock Lighting.j3md and PBRLighting.3md MatDefs

This happens because the Materials Editor does two things:

1) Scans for files in the project directory tree with a .j3m extension 2) Defers to the ProjectAssetsManager to load dependencies from .jar files in the project

Part 1) still works, and will find .j3m files in the /assets folder/sub-project, but the ProjectAssetManager class is using NB's Java Project API to the files on the classpath, and its not returning the files for Gradle projects. ProjectAssetManager needs to be extended to be "Gradle-aware" and probably use NB's Gradle Java Projects API to locate the dependency .jars (after a priming build) in Gradle projects and load the materials from them.

This would probably fix a bunch of other things that are squiffy in Gradle projects, like the textures browser etc.

tonihele commented 1 year ago

And then there is this, not maybe 100% related but: WARNING [com.jme3.gde.core.assets.ExternalChangeScanner]: File is not part of a jME project but tries to find original model...

If I create a scene file to the Gradle template... It doesn't seem to understand it is a jME project or something....

peedeeboy commented 1 year ago

If I create a scene file to the Gradle template... It doesn't seem to understand it is a jME project or something....

Yes - I noticed that. Similar, in that I think it is to do with the ProjectAssetManager, but I don't think directly related.

With SDK3.4, if I create a new Gradle project, the Asset node gets created in the Project view. This appears to be when the ProjectAssetManager then gets initialised. Opening Scenes etc. works in this new project.

But when Opening an existing project (or restarting SDK), the Asset node doesn't get created, and assets can't be viewed in the SDK.

My hunch was that if it were possible to fix the detection of the assets folder and creation of the Assets node, then opening Scenes / Models would start working again. I only had chance to have a cursory look through the code, and it seemed like it is simply looking for a folder called assets, so I'm not sure why it would be failing. Needs a proper look at some point...

peedeeboy commented 1 year ago

I also did some experimentation at trying to get the classpaths out of NB's Gradle API, so that compiled jars could be classloaded to load assets from dependencies. No joy so far, every when trying to mimic NB's Gradle classpath tests 🤷

neph1 commented 1 year ago

I'm acquiring some knowledge around this when figuring out how and which icons are loaded. I'll keep a look out, too, and report back.

tonihele commented 1 year ago

It would be super cool to get the kinks ironed out from the Gradle template to the SDK 3.5 release (slated for next month).

peedeeboy commented 1 year ago

Progress!

Gradle_Texture_Browser

Very hacky progress though - and the Material editor, whilst listing out all the .j3md files, doesn't then load their parameters correctly 😢 Still a ways to go to fix this properly 👎

neph1 commented 1 year ago

Hmm, is this issue totally unrelated? https://github.com/jMonkeyEngine/sdk/issues/266 Because the fix works both on ant and gradle projects. Could we somehow do a similar fix for this issue?

peedeeboy commented 1 year ago

Got the MatDef properties loading in the Materials Editor 👍 : image

neph1 commented 1 year ago

Close?