Can not load custom material

I am trying to load an user defined material using Material m1 = new Material(assetManager, "SimpleColor.j3md");,when the SimpleColor.j3md is in the assets subdirectory, but it throws the following exception,

SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.asset.AssetNotFoundException: SimpleColor.j3md
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:385)
	at com.jme3.material.Material.<init>(Material.java:104)
	at HelloJME3.simpleInitApp(HelloJME3.java:31)
	at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:240)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:139)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:221)
	at java.base/java.lang.Thread.run(Thread.java:831)

Here is the folder structure of the project,

The j3md, vert and frag files are inside the assets folder. I was under the assumption it would work because the AssetManager documentation says jME3 searches for models in a directory named assets.

I was trying to set breakpoint to find what path is being searched at. When debugging I found the root gets the value empty string.

And the same method returns null because there member to loop over classLoaders.

And there is another thread here that seems to have some work-arounds:

I don’t use the SDK so I can’t comment personally. I just remembered the forum traffic.

Doesn’t look like the SDK. But yes, your problem is most likely in the Gradle configuration…

I get the following error if I add runtimeOnly project(':assets') to my gradle file: Project with path ':assets' could not be found in root project 'testJava2'.

But if I add runtimeOnly files('assets') then I get the following exception.

com.jme3.asset.AssetNotFoundException: SolidColor.frag
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:385)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:402)
	at com.jme3.material.TechniqueDef.loadShader(TechniqueDef.java:514)
	at com.jme3.material.TechniqueDef.getShader(TechniqueDef.java:529)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.makeCurrent(DefaultTechniqueDefLogic.java:59)
	at com.jme3.material.Technique.makeCurrent(Technique.java:152)
	at com.jme3.material.Material.render(Material.java:1018)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:634)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:273)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:312)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:897)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:799)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1128)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1180)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:273)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:160)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:201)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
	at java.base/java.lang.Thread.run(Thread.java:831)

To me it look like now the game can find the j3md file, but not the frag and vert file specified in the j3md file.

Here is the content of SimpleColor.j3md,

MaterialDef Simple Color{
    // user defined uniform
    MaterialParameters{
        Vector4 Color
    }

    // Each technique comes with a pair of shaders
    Technique{
        VertexShader GLSL100: SolidColor.vert
        FragmentShader GLSL100: SolidColor.frag

        // uniform
        WorldParameters{
            WorldViewProjectionMatrix
        }
    }
}

Another approach I’ve also tried by adding assetManager.registerLocator("C:/Projects/testJava2/assets", FileLocator.class); songangel suggested. Similarly, with this approach the game finds the j3md file but not the frag(and/or vert) file. Here is the exception,

et.AssetNotFoundException: SolidColor.frag
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:385)
	at com.jme3.asset.DesktopAssetManager.loadAsset(DesktopAssetManager.java:402)
	at com.jme3.material.TechniqueDef.loadShader(TechniqueDef.java:514)
	at com.jme3.material.TechniqueDef.getShader(TechniqueDef.java:529)
	at com.jme3.material.logic.DefaultTechniqueDefLogic.makeCurrent(DefaultTechniqueDefLogic.java:59)
	at com.jme3.material.Technique.makeCurrent(Technique.java:152)
	at com.jme3.material.Material.render(Material.java:1018)
	at com.jme3.renderer.RenderManager.renderGeometry(RenderManager.java:634)
	at com.jme3.renderer.queue.RenderQueue.renderGeometryList(RenderQueue.java:273)
	at com.jme3.renderer.queue.RenderQueue.renderQueue(RenderQueue.java:312)
	at com.jme3.renderer.RenderManager.renderViewPortQueues(RenderManager.java:897)
	at com.jme3.renderer.RenderManager.flushQueue(RenderManager.java:799)
	at com.jme3.renderer.RenderManager.renderViewPort(RenderManager.java:1128)
	at com.jme3.renderer.RenderManager.render(RenderManager.java:1180)
	at com.jme3.app.SimpleApplication.update(SimpleApplication.java:273)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:160)
	at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:201)
	at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:242)
	at java.base/java.lang.Thread.run(Thread.java:831)

Read that very carefully. Maybe one more time.

1 Like

doh! Sorry! Missed it when I was renaming things.

Thank you! I’ll add it to the documentation.

I get the following error if I add runtimeOnly project(':assets') to my gradle file: Project with path ':assets' could not be found in root project 'testJava2'.

Out of interest, if you remove the following from the build.gradle of the Basic Gradle Game created by the SDK:
sourceCompatibility = 1.8
will IntelliJ build the project with runtimeOnly project(':assets')?

What I think happens with that Basic Game Template is that the sourceCompatibility=1.8 line causes the root project to be built for Java8, but because the :assets project doesn’t have a build.gradle specifying the sourceCompatibility, it will get build for what JDK the IDE (SDK/Netbean & IntelliJ have this issue) is running on.

Likely Java 11 (especially now the SDK is based on NB12, which I think is JDK11 min?). The two projects want to be compiled for different versions of Java and thus are incompatible…

Removing that sourceCompatibility line work for me in both NB and IntelliJ…

1 Like

There is no min. Only max, which was 14 maybe? 8 is at least tested and ok. Java versions that is.