How to delete a reflectionTexture from an imported material

Hi,

I made two materials for a ball in Blender (just two color materials). I want to delete a reflectionTexture. I have one mesh. It means that the zero element in meshes must be a ball. I tried to find material array but autocomplete says that the ball has only one material. I try to print this material but I see null.

Playground

Code:

        BABYLON.SceneLoader.Append("models/", "Ball.glb", scene,
            (loadedScene) =>
            {
                scene.createDefaultEnvironment();

                console.log(loadedScene);

                const material = loadedScene.meshes[0].material;
                console.log(material);
            });

scene.createDefaultEnvironment(); actually creates the environment reflection texture.

You should be able to do scene.environmentTexture = null to remove it.

I added it:

        BABYLON.SceneLoader.Append("models/", "Ball.glb", scene,
            (loadedScene) =>
            {
                scene.createDefaultEnvironment();

                scene.environmentTexture = null;
            });

And the ball is black:

image

This is expected as the PBR materials use the env texture as source of lightning :wink:

Just add static lights like hemispherical / point / directional or spot lights.

If you open my code example you will see that I use the DirectionalLight. But it does not work with the HemisphericLight light too.

How to export without PBR? I export one selected object. I just want to export a simple diffuse color material from Blender.

How to solve the problem? Full code of my example:

import * as BABYLON from "babylonjs";
import "babylonjs-loaders";

export default class Game
{
    public constructor(canvasName: string)
    {
        const canvas = document.getElementById(canvasName) as HTMLCanvasElement;
        const engine = new BABYLON.Engine(canvas, true);
        const scene = new BABYLON.Scene(engine);
        const camera = new BABYLON.ArcRotateCamera("camera", 0, 0, 3, BABYLON.Vector3.Zero(), scene);
        camera.attachControl(canvas, true);
        // const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
        const light = new BABYLON.DirectionalLight("dirLight", new BABYLON.Vector3(0, 1, 0), scene);

        BABYLON.SceneLoader.Append("models/", "Ball.glb", scene,
            (loadedScene) =>
            {
                scene.createDefaultEnvironment();
                console.log(loadedScene);
                const material = loadedScene.meshes[0].material;
                console.log(material);
                //scene.environmentTexture = null;
            });

        engine.runRenderLoop(() => scene.render());
        window.onresize = () => engine.resize();
    }
}

maybe you can simply keep the PBR material but set metallic property to 0 to remove shininess?

Your directional light does not work as expected because it has not a right direction: try -1 for the y axis instead of 1. You could also raise its intensity (light.intensity = 20 for eg).

I think the Blender exporter exports a PBR material because you use in Blender such a material (I think it is called “principled material” in Blender).

Yes, this code works now:

        const light = new BABYLON.DirectionalLight("dirLight", new BABYLON.Vector3(0, -1, 0), scene);

        BABYLON.SceneLoader.Append("models/", "Ball.glb", scene,
            (loadedScene) =>
            {
                scene.createDefaultEnvironment();

                scene.environmentTexture = null;
            });

But it looks strange with dark bar:

Hi,

Here is a little warning about your way of getting the material : you are loading a glb file, in this case, babylon wrap your ball in a “_root_” mesh. So, your materials are not available on loadedScene.meshes[0] but from loadedScene.meshes[1] and loadedScene.meshes[2].
By the way, you’d better use https://doc.babylonjs.com/api/classes/babylon.scene#getmeshbyname to pick your mesh instead of using the index.

more info about the _root_ wrapper : Blender to glTF - Babylon.js Documentation

here is a version that works:

No need to add additional ligths. Just metallic to 0 and roughness to 1

2 Likes

Do you mean to delete it in Blender? I use Blender 2.76 (because of performance of my laptop) in the “Blender Render” mode and I do not see “Metallic” and “Shininess” properties. Or do you mean to delete them in Babylon.js? But I cannot find where are materials as I described in the first message of my topic.

Good! Thank you! Now I see where materials are. But why do I see a gradient at the background color of the scene behind the ball when I rotate the camera?

It’s the default environment skybox:

2 Likes