Forum

b4w.js:202 B4W ERROR: set_alpha_factor(): Object "cube1" is not a dynamic MESH.

24 February 2019 21:21
Hi all, I'm new to blender and b4w. I have one cube in blender and all I want to do is make the cube disappear with Javascript.

I use this code:
var cube1 = m_scenes.get_object_by_name("cube1");
m_mat.set_alpha_factor(cube1, "cube1Mat", 0);

cube1 is the name of the cube in blender.
cube1Mat is cube1's material name.

When I run this, I get:
b4w.js:202 B4W ERROR: set_alpha_factor(): Object "cube1" is not a dynamic MESH.

I've googled for hours but can not find a solution, any help would be greatly appreciated.
25 February 2019 09:47
Did you check the object's "Dynamic Geometry & Materials" checkbox under the Object Tab in Blender? This is required.

Also, if you want to switch on/off objects, show_object/hide_object is a better option than setting the alpha factor. But if you want to fade in and out objects, alpha is the way to go.

P.S.: If you use alpha, you must also set the material to a transparency type. The default setting is "Opaque", under which the material will not show any transparency at all, so you must change that, for example to "Alpha Blend".
26 February 2019 16:22
Thanks Blend4Life…. checking "Dynamic Geometry & Materials" got rid of the error but the cube alpha doesn't change.

I prefer not to "show_object/hide_object" due to needing to fade objects in and out.

I have the material transparency set to "Alpha Blend".
"Dynamic Geometry & Materials" is checked.
Code to change transparency is here:
m_mat.set_alpha_factor(cube1, "cube1Mat", 0);

Object alpha doesn't change and there are no JavaScript errors in console.
26 February 2019 20:32
Hello again,

I'm sorry, do I take it that you have a very simple, very basic non-node material without textures? For this material, the transparency is not changed with set_alpha_factor, but with

m_mat.set_diffuse_color (your_object_reference, "your_material_name",
[your_red_value, your_green_value, your_blue_value, your_alpha_value]);

So there it is, the last value of the passed RGBA array. All RGBA values are from 0 to 1.

The method you've tried to use is for non-node materials with TEXTURES.

P.S.: You might also consider using NODE MATERIALS to do your fading, because then you can simply plug a value node into the final alpha socket and it always works regardless of what material setup you have, and you can even put keyframes on the value node.

And now for some shameless self promotion , run my coffin demo and click on the Checkout sign on the floor. A scroll will fade in. Click on STAY and it will fade out again. These fades were done with node material fading.
 
Please register or log in to leave a reply.