Texture of glb does not load

Hello, I was using this code to load a model:

Spatial scene = assetManager.loadModel("Models/scene.glb");
scene.scale(2f, 2f, 2f);
scene.setLocalTranslation(0f, -10f, 0f);
rootNode.attachChild(scene);

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.

This happened because you have created a new blank material, it overrides the existing one.

When you got a black screen at the first code, have you tried to add an ambient light to your scene ?

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.

this is correct result, problem is on your side.

like others said: you have no light / light probe. GLTF/GLB is loading PBR material that require them.

Just add some Directional Light and some Light Probe.

Thanks everyone, and sorry for the late reply!
I had added a directional light before. (Sorry for not mentioning :frowning: )
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.

“Code looks fine from here.”

The thing is, the problem you describe “I don’t see anything and I switch to unshaded and I see stuff.”

…can only be two things: 1) you don’t really have a light, 2) all of your materials are black.

Yup, like Paul said post above.

you might add light into wrong Node

or

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.

This is the entire function:

    public void initScene() {
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(0,0,0).normalizeLocal());
        sun.setColor(ColorRGBA.White);
        rootNode.addLight(sun);

        AmbientLight al = new AmbientLight();
        al.setColor(ColorRGBA.White.mult(1.3f));
        rootNode.addLight(al);

        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);
        CollisionShape sceneShape = CollisionShapeFactory.createMeshShape(scene);
        RigidBodyControl scenePhyControl = new RigidBodyControl(sceneShape, 0f);
        this.physics.getPhysicsSpace().add(scenePhyControl);

        this.app.getCamera().lookAt(new Vector3f(0f, 0f, 0f), new Vector3f(0f, 0f, 0f));
    }

in no other place am i doing anything with the rootNode. the scene is here : SpatialLearningVWM/scene.glb at f1579d65daa4e8a000cfec845c4eb3ba206c83c6 · BharSat/SpatialLearningVWM · GitHub
It opens fine in windows 3d viewer.

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 i tried that earlier, thats why this thread.
Thanks btw

Do you need both A lightProbe and Directional light?
because ive only used a directional light

What direction do you believe 0,0,0 is?

1 Like

Looking towards +x +y +z
oh wait
never mind i got it
However Why didnt the ambient light work?

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.

1 Like

You can find a bunch of other prebuilt LightProbes here:

Thumbnails here:

And this is the code I’d use to load one of those probes:

Spatial probeHolder = getApplication().getAssetManager().loadModel(probeName);
LightProbe probe = (LightProbe)probeHolder.getLocalLightList().get(0);
probe.setPosition(Vector3f.ZERO);
probeHolder.removeLight(probe);   
rootNode.addLight(probe);
2 Likes

Thanks!

1 Like