Forum

Change material at runtime

26 May 2017 20:17
In my blend file I did tried to change the material with

var group_5 = m_scenes.get_object_by_name('group_10.002', m_scenes.DATA_ID_ALL);
m_mat.set_nodemat_rgb(group_5, ["mat_node_rgb", "RGB"], 0, 1, 0);

but I get

The type of the object "group_10.002" is not "MESH" or it is not dynamic.

Any idea please ?
27 May 2017 09:29
Obvious questions maybe but…
In the Objects tab under Render Properties, have you checked the "Dynamic Geometry and Materials" option?
Is this method working on any other objects in your scene?
05 June 2017 18:59
Yes, thank you. I did not set the dynamic geomety and materials.
Now js continue but

print.js:73 B4W ERROR: Material "mat_node_rgb" was not found in the object "Cube.001".
How should I create the required material? I was trying to follow this example

https://www.blend4web.com/apps/code_snippets/code_snippets.html?scene=material_api

B4W ERROR: RGB node "RGB" was not found in the object "Cube.001".
05 June 2017 19:05
So the material API lets you change properties of a material that you applied to your object in Blender. The 'Change Texture' API allows you to completely change the texture image. We were talking about this in another thread:
https://www.blend4web.com/en/forums/topic/3361/
And…
https://www.blend4web.com/en/forums/topic/3357/
06 June 2017 12:55
Hi,

print.js:73 B4W ERROR: Material "mat_node_rgb" was not found in the object "Cube.001".
How should I create the required material?

When you call the set_nodemat_rgb() function in your JS code it expects that the object has a node-based material (with a certain name) with an RGB node inside it (also with a certain name which you use to refer to it from your JS code). You might want to look at the corresponding .blend file of this example to find out how it works.
The Founder | Twitter | Facebook | Linkedin
 
Please register or log in to leave a reply.