but all I get is a black screen.
however, when i add:
Spatial scene = assetManager.loadModel("Models/scene.glb");
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
scene.setMaterial(mat);
scene.scale(2f, 2f, 2f);
scene.setLocalTranslation(0f, -10f, 0f);
rootNode.attachChild(scene);
I get the shape of the scene, but with a white texture.
I have added the texture(Image) through blender Uv Editing.
Could someone please help.
Your scene has no light… so lit things will be black and the environment will be black, etc…
The next problem will be that you don’t have any ambient light… and with GLTF (glb) you will need a light probe. But at least with a DirectLight you will see your stuff.
Thanks everyone, and sorry for the late reply!
I had added a directional light before. (Sorry for not mentioning )
I now added an ambient light, but am getting the same results.
I got that part, I was trying to see if the model was not loading or the texture was having a problem.
you might have black materials (full metalness can be same result)
or
for some reason model is not there at all(for example you detach it moment after attach)
Best solution for you, is to load one of JME Examples with PBR model (tank it was for example) and verify difference between your code and example one, to know what code line cause issue.
If you remove these liens of code it should work. Your model will already be using an embedded material when you load it with the assetManager, so this code you had is replacing the embedded material with a blank unshaded material (as Pavl mentioned earlier:)
An unshaded material will render without any lights in the scene, so that is why you got something to appear when you apply that.
But the material embedded in your GLB file by default will use the PBRLighting.j3md material definition, which requires a Directional light and LightProbe to render properly.
Yeah if you’re using the embedded PBR shader and don’t actually want to replace it with the unshaded one, then you do need both of those lights for the PBR shader to work as intended.
Directional Light will simulate the global sun light for an entire scene, and a LightProbe is used to simulate indirect light and has a radius, so you can generate unique light probes to match certain areas of your scene. But there’s also this one in the engine’s jme3-testdata library that you can use for testing
The AmbientLight can also be used to scale a LightProbe’s color/brightness for all Spatials/Materials affected by that AmbientLight, but it is not necessary for PBR like the other two.