Material List Empty (get_materials_names)

02 June 2017 23:48
Hi guys,

I'm new with blend4web and I'm not 100% sure if it is a bug or not, but the command get_materials_names returns always an empty array, I have tried in different ways but I don't get the expected result.

I'm using Linux (Arch Linux)
I have tested it with:
Firefox 53.0.3 (64-bit) and Chromium 58.0.3029.110 (64-bit).

I have tried with blend4web 17.02.1 and 17.04.1
I have exported a cube (in json/bin) with 2 materials. I have made a simple script to load it inside the page and to read the materials, but it returns an empty array.

An example to replicate the problem:

HTML File:
<!DOCTYPE html>
    <script type="text/javascript" src="b4w.min.js"></script>
    <script type="text/javascript" src="main.js"></script>
        body {
            margin: 0;
            overflow: hidden;

        #container_id {
            position: absolute;
            width: 100%;
            height: 100%;


    <div id="container_id"></div>


Js file (main.js):
var app = b4w.require("app");
var data = b4w.require("data");
var scenes = b4w.require("scenes");
var material = b4w.require("material");

	canvas_container_id: "container_id",
	physics_enabled: false,
	autoresize: true,
	callback: load_cb

function load_cb() {
    data.load("test.json", loaded_cb);

function loaded_cb() {
    var cube = scenes.get_object_by_name("Cube");
    var material_list = material.get_materials_names(cube);

material_list is an empty array in Firefox

and Chromium

Attached you can find the entire example, with the blend, json and bin files.

03 June 2017 05:50
So I went to the Materials Code snippets and hit the lower left button to clone the project. That way all the right code is there to start with. I added in your console.log and it works. So that is someplace to start anyway. In your code, I could not get the object data to log either. Maybe if you had used:
var APP_ASSETS_PATH = m_cfg.get_assets_path("mat-test");
m_data.load(APP_ASSETS_PATH + "material_api.json", load_cb);

03 June 2017 14:21
Hi Will,

thanks for the reply.

I have added a console.log for the object

and I can see the cube inside the console:

I don't know why you can't

I have also tried my code and the file that you have suggested (material_api.json)

and it works

So it is not the API call get_materials_names, but probably it is something inside the exporter or Blender.

Any Ideas?

04 June 2017 05:34
I am still in the process of learning the code API for Blend4Web so I am not sure. But if you really want to know, start with the code snippet version and start stripping it down to make it like your project. Keep checking your console.log results along the way until you find out what part you were missing that caused this.
I have had good results by starting with a stock project, then remove what I don't need rather than trying to build from scratch. That way you end up with pieces and parts that you did not even know you needed. Then, when you remove something essential, you will know what broke the code.

I am working to understand what registering the application module does.
b4w.register("terrain-1_main", function(exports, require) {
	//all the code contained here

Is that just for registering the code within the development environment or is it needed for later execution when deployed?
04 June 2017 20:00
Hi Will,

thanks for the suggestion, but the code that I'm using is very minimal and it works with the stock files:

I have also tried the same piece of code with others stock files and it works flawlessly.

I don't see the material list when I load a model made by me.

I have tested it with the standard Blender cube with a very simple material but blend4web doesn't return the material list.

04 June 2017 20:47
I tried it on the Materials Code Snippet project. In order to get my own material to log, I had to assign one face of the object to the new material.
var material_list = m_mat.get_materials_names(sphere_2);
    console.log("materials List = " + material_list);

Console result:
materials List = Sphere_mat_2,New_Material
05 June 2017 22:05
I have created another test file from scratch.

The file test contains a plane.

I have assigned a material to the object and to the data

I have loaded it inside the script

I can see the object but I can't see the materials

I have created it with Blender 2.78c on Linux and I have exported it with the add-on 17.04.1

I'm really stuck there, I don't know what else to try.

You can find the files attached.

06 June 2017 10:49
Hello guys,
This API requires a dynamic object. Just enable this for the plane:

It should do the trick
06 June 2017 11:30
Thank you Roman!

It works

I have just realized that is written inside the documentation

It was in front of me and I didn't see it.

Thanks again.

Please register or log in to leave a reply.