Forum

Change material on click in object?.

29 April 2016 15:23
Hello. How can change material on click in object?. Thanks.
29 April 2016 15:34
Change material on click in object?.
You can do this in two ways:
1. with the logic editor
example, blend file

2. via API
code snippet
The Founder | Twitter
03 May 2016 13:01

Reply to post of user Yuri Kovelenov
You can do this in two ways:
1. with the logic editor
example, blend file

2. via API
code snippet


Thanks.
14 September 2016 15:41
my object name: mamparaOb
my material name: mamparaLight

var lightObMampara = m_scenes.get_object_by_name('mamparaOb');

// console.log(m_material.get_materials_names(lightObMampara));
// console.log(lightObMampara);

m_material.set_emit_factor(lightObMampara, "mamparaLight", 1);
m_material.set_diffuse_intensity(lightObMampara, 'mamparaLight', 1);


this dont work for me in b4w 16.8.0, i get this error:

B4W ERROR: Couldn't set property "emit_factor"!error @ print.js:73exports.set_emit_factor @ material.js:343main_canvas_click @ casaGasNatural.js:135
print.js:73 B4W ERROR: Couldn't set property "diffuse_color"!


This:
console.log(m_material.get_materials_names(lightObMampara));
return an empty array [ ] but my object have assigned one material named mamparaLight.
15 September 2016 14:48
Hi,

Could you please export your project with the Project Manager and attach here the archive?
The Founder | Twitter
19 September 2016 12:27
Force Dynamic object checked?

Next time you can say hello, always a good way to start :)
19 September 2016 22:32
Reply to post of user martial
Next time you can say hello, always a good way to start :)

It's true, you're right, sorry, I had a bit rushed and passed me.


Reply to post of user martial
Force Dynamic object checked?

Tomorrow I will try to see that this, thank you.
13 March 2017 09:29
Hi,
I had the similar error for setting an alpha factor. But after checking on force dynamic object the error got cleared but the alpha / the transparency is not applied to the object.
Can anyone help?
13 March 2017 11:05
Hi! Are you using the set_alpha_factor method? It's for controlling those parameter that's located in the Texture->Influence panel in Blender. If you want to change the opacity of an object you should use the set_diffuse_color method and change the last component of the "color" parameter:
m_mat.set_diffuse_color(cube, "MyMaterial", [1, 1, 1, 0.3]);

[EDIT] forgot to mention that this is for non-node materials only, if you're using nodes you can do it as jeanpierre3d suggests below
Blend4Web Team
13 March 2017 11:07
hello just do an alpha control
i use node material with a value controling the alpha in extinded material
with a script
m_mat.set_nodemat_value(myObject, ["Texture.myObject.001", "Value.myObject.alpha"],1);

and i check transparenty in the material tab and choose alpha blending or alpha sort

it may help you
 
Please register or log in to leave a reply.