Forum

User posts Brett Kromkamp
12 October 2016 11:08
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
11 October 2016 20:50
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
21 August 2016 18:29
Hi Yuri,

Don't spend time on this. I've figured out the issue… a combination of confusion and mis-configured setting in the Render ("Object Outlining"), Scene ("Objects Selection"), and Object ("Selection and Outlining") tabs for both the main scene and the dynamically loaded scene.

Thanks for helping and regards,

Brett
21 August 2016 17:38
Here, are the actual Blend-files in question:
- main.blend
- crates.blend

Regards,

Brett
21 August 2016 17:33
Hi Yuri,

That would be fantastic. Don't spend too much time on trying to determine the problem. Eventually, I will figure it out :)

I've attached the project. The problem is that it won't actually work because the application extensively talks to back-end web services. Nonetheless, maybe you will be able see what is the issue. With regards to the project, the following points are relevant:
1 - the main.json is the initial (empty) scene in which other scenes are loaded. It only contains a camera and a lamp. Nothing else.
2 - the crates-001.json is the scene in question which I am trying to apply the outline to. It gets loaded into the main scene (together with other dynamically loaded scenes).
3 - the "onReceiveMessage" (provided below) is where I am trying to actually run the outline animation for the crates-001 object: else if (event.data.hasOwnProperty("selectedIdentifier")) …

function onReceiveMessage(event) {
    if (event.data.hasOwnProperty("sceneIdentifier")) {
        clearScene();
        loadScene(event.data.sceneIdentifier);
    } else if (event.data.hasOwnProperty("selectedIdentifier")) {
        var name = "topic_" + event.data.selectedIdentifier;
        var selectedObject = m_scenes.get_object_by_name(name, m_scenes.DATA_ID_ALL);
        console.log(selectedObject);
        console.log(m_scenes.can_select_objects());
        console.log(m_scenes.check_object(selectedObject));
        m_scenes.apply_outline_anim_def(selectedObject);
    } else if (event.data.hasOwnProperty("screenshot")) {
        m_screen_shooter.shot();
    }
}

Let me know if you need any more information. Thanks in advance,

Regards,

Brett
20 August 2016 18:55
Thanks for you reply, Yuri. However, it's still not working. I do not get the (B4W ERROR: apply_outline_anim(): wrong object) error anymore after doing what you explained above… but, even so, the object's outline (https://www.blend4web.com/doc/en/postprocessing_effects.html#outline) is not displayed. In the main/first scene "Objects Selection" is set to "On", and in the dynamically loaded scene "Selection and Outlining > Selectable" and "Selection and Outlining > Enable Outlining" are both set.

The code that I am executing to trigger the outlining is as follows:
var selectedObject = m_scenes.get_object_by_name(name_of_object, m_scenes.DATA_ID_ALL);
console.log(selectedObject); 
m_scenes.apply_outline_anim(selectedObject, 1, 1, 0);

Obviously, the "console.log" statement is to verify that the object has been found by the "get_object_by_name" function.

Furthermore, the following "console.log" statements return true:
console.log(m_scenes.can_select_objects());
console.log(m_scenes.check_object(selectedObject));

I've reviewed the code in the "Furnishing a Room" tutorial and in many respects I am doing the same. Is there anything else I should be looking for (specifically, on the Blender side-of-things)?

Is the "pick_object(x, y)" function the only way to *select* an object? It just seems that I am fundamentally not understanding something. This should be a simple thing to accomplish: 1] get an object (using the "get_object_by_name" function) and 2] display the object's outline.

In my case I haven't added a selection sensor (and accompanying manifold). Is it necessary to have a selection sensor and manifold to "trigger" the selection?

Thanks in advance,

Brett
20 August 2016 13:26
Hi,

I'm trying to programmatically get an object so that I can outline it in the scene viewer. The object in question has been dynamically loaded making it necessary to get it like this:
var selectedObject = m_scenes.get_object_by_name(name_of_object, m_scenes.DATA_ID_ALL);


Once, I have the object, I try to apply its outline animation:
m_scenes.apply_outline_anim(selectedObject, 1, 1, 0);


Nonetheless, this doesn't work… the error I get given back is: B4W ERROR: apply_outline_anim(): wrong object

The select object's type is 'MESH'. Is that the reason? Either way, how can I programmatically get a dynamically loaded object/scene and display its outline (animation). That is, I am not interested in using something like the "pick_object" function (https://www.blend4web.com/api_doc/module-scenes.html#.pick_object) to get the object based on user interaction within the scene viewer.

Do I need to implement sensors (and the accompanying manifolds), not unlike what was done in the "Furnishing a Room" tutorial (https://www.blend4web.com/en/community/article/66/) to programmatically get an object and run its outline animation?

The whole point of what I am trying to do is to have a list of (dynamically loaded) objects in a host web application and to outline the object of the corresponding list item that is currently being hovered over (in the before-mentioned list).

Hope this makes sense. Thanks in advance,

Brett
25 July 2016 12:16
For what it's worth, this is how I fixed this issue:

function entity_loaded_cb(data_id) {
    var objs = m_scenes.get_all_objects("ALL", data_id);
    for (var i = 0; i < objs.length; i++) {
        var obj = objs[i];
            
        // Enable physics on the object.
        if (m_phy.has_physics(obj)) {
            m_phy.enable_simulation(obj);
        }

        // Set the object's location.
        if (spawn_position != null) {
            var obj_translation_rel = m_trans.get_translation_rel(obj);
            var x_pos = spawn_position[X_INDEX] + obj_translation_rel[X_INDEX];
            var y_pos = spawn_position[Y_INDEX] + obj_translation_rel[Y_INDEX];
            var z_pos = spawn_position[Z_INDEX] + obj_translation_rel[Z_INDEX];
            m_trans.set_translation(obj, x_pos, y_pos, z_pos); // x, y, z
        }

        // Show appended object.
        if (m_obj.is_mesh(obj)) {
            m_scenes.show_object(obj);
        }
    }
}
25 July 2016 10:30
Hi,

I'm dynamically loading a scene with several objects which i want to subsequently position in an arbitrary location in the main scene. Nonetheless, I want the relative position of the individual objects (from the dynamically loaded scene) to be maintained.

The API call I am using to position the objects from the dynamically loaded scene is:

m_trans.set_translation(obj, spawn_position[0], spawn_position[1], spawn_position[2]);

I've tried with "m_trans.set_translation_rel" as well.

(The full function to position the objects from the dynamically loaded scene in the main scene is provided below).

What obviously happens (in hindsight) is that all of the individual objects in the dynamically loaded scene are placed in the exact same position (in the main scene) causing the objects to "overlap".

So, how can I load a scene and position the objects in the main scene ***while maintaining their relative position to one another***?

By the way, it's not possible to "join" all of the objects in the dynamically loaded scene… I need them to be individual objects in the main scene.

Hope this all makes sense. Hope somebody can help me :)

Brett

function entity_loaded_cb(data_id) {
    var objs = m_scenes.get_all_objects("ALL", data_id);
    for (var i = 0; i < objs.length; i++) {
        var obj = objs[i];
            
        // Enable physics on the object.
        if (m_phy.has_physics(obj)) {
            m_phy.enable_simulation(obj);
        }

        // Set the object's location.
        console.log(spawn_position);
        if (spawn_position != null) {
            // TODO: Fix!
            //trans.set_translation(obj, spawn_position[0], spawn_position[1], spawn_position[2]); // x, y, z
            m_trans.set_translation_rel(obj, obj, spawn_position[0], spawn_position[1], spawn_position[2]); // x, y, z
        }
        // Show appended object.
        if (m_obj.is_mesh(obj)) {
            m_scenes.show_object(obj);
        }
    }
}
12 July 2016 19:09
Good to hear. Looking forward to seeing a regularly updated blog :-)