Forum

Programmatically toggle mist

11 October 2016 20:50 #12617
Hi,

Is it possible to "switch" mist (i.e., fog) on or off, programmatically? The m_scenes.set_fog_color_density(val) method (https://www.blend4web.com/api_doc/module-scenes.html#.set_fog_color_density) seems to only influence the actual color of the mist. The 4th value in the color-density vector [C,C,C,D] supposedly alters the density of the mist. But, passing in either 0 or 1.0 for the density doesn't seem to have any effect.

I expected the following to switch mist on:
var mistToggle = 1.0;
var mistColorDensity = m_vec4.fromValues(0.5, 0.5, 0.5, mistToggle);
m_scenes.set_fog_color_density(mistColorDensity);


And the following code to switch mist off:
var mistToggle = 0.0;
var mistColorDensity = m_vec4.fromValues(0.5, 0.5, 0.5, mistToggle);
m_scenes.set_fog_color_density(mistColorDensity);


Basically, what I'm trying to achieve is to be able to toggle mist in a scene. I'm not interested in changing the scene's mist color. Just switching mist either on or off, in a scene, using the API. Is that even possible? If yes, how?

One other thing, which I am not sure if it is relevant or not: a "child" scene is loaded dynamically into a "parent" scene and I am calling the m_scenes.set_fog_color_density function on the main/parent scene. Like I said, I'm not sure if this is of relevance.

Thanks in advance,

Brett
12 October 2016 11:08 #12640
Hi,

Just to be clear: I can change the color of the mist with the API (i.e., programmatically). What I cannot seemingly do, is switch the mist either "on" or "off".

I suspect that it is not possible to toggle mist with the API and that it can only be enabled or disabled in Blender.

Can anyone help?

Brett
12 October 2016 12:12 #12652
I suspect that it is not possible to toggle mist with the API and that it can only be enabled or disabled in Blender.
Hi, Brett!

Unfortunately, for now the fourth component of the fog_color_density makes sense only for procedural fog.

Blender's fog density depends on its depth and height, but we haven't yet finished refactoring of the fog API, so these parameters can't be changed directly. We will add necessary API in the nearest release.

Also there is workaround: fog parameters can be animated and animation can be toggled via API (16.02 Release Feautures)
Blend4Web Team - developer
12 October 2016 18:38 #12670
Hi Konstantin,

Thanks for your reply.

Are you aware of any tutorial covering the animating of parameters. I don't see any on the Blend4Web website. Also, just to confirm: are you saying that the necessary functions to programmatically interact with mist will be added to the API in the Blend4Web 16.10 release? If yes, that would be fantastic :)

Regards,

Brett
12 October 2016 18:46 #12671
Are you aware of any tutorial covering the animating of parameters. I don't see any on the Blend4Web website.
World object can be obtained via get_world_by_name method and then manipulated as any other object from the scene.
I've also attached an example blend file with environment animation.

Also, just to confirm: are you saying that the necessary functions to programmatically interact with mist will be added to the API in the Blend4Web 16.10 release?
Yep
Blend4Web Team - developer
12 October 2016 19:00 #12672
Hi Konstantin,

Thanks for your very swift reply (including the Blend file with environment animation). Great news to hear that the mist functions will be added to the API.

Also, I would just like to say that the Blend4Web customer support is superb. Thanks for a great product and the accompanying support! It's a pleasure using your product.

Brett
28 October 2016 11:07 #13150
Thanks for your very swift reply (including the Blend file with environment animation). Great news to hear that the mist functions will be added to the API.
Hi, Brett!
You can try out API in the fresh release
Blend4Web Team - developer
31 October 2016 11:50 #13203
Thanks Konstantin! I'm already using the new mist-related API in my application and it's working perfectly :)

Thanks for your help in this matter.

Regards,

Brett
 
Please register or log in to leave a reply.