Forum

Programmatically outlining an object

20 August 2016 13:26 #11315
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
20 August 2016 16:35 #11316
Hi,

Since you are loading objects dynamically, you need to set Object Outlining in your first scene's Render settings to ON (it is AUTO by default).
Development Lead | Twitter
20 August 2016 18:55 #11317
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
21 August 2016 09:04 #11319
Hi Brett,

Could you please attach here a minimum file set which reproduces this problem? You can do it by exporting your project with the Project Manager. We'll try to help!
Development Lead | Twitter
21 August 2016 17:33 #11320
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
21 August 2016 17:38 #11321
Here, are the actual Blend-files in question:
- main.blend
- crates.blend

Regards,

Brett
21 August 2016 18:29 #11322
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 20:55 #11325
Brett, I'm glad you found the solution!
Development Lead | Twitter
23 October 2016 08:41 #12955
Cam i do deselection as well ?
I want to select objects and deselect selected objects, as reset the objects as deselect
Software Engineer
24 October 2016 12:18 #12994
Hi, you can clear outlining by calling

m_scenes.clear_outline_anim(obj);

See also the source code of the Scene Viewer inside your SDK.
Development Lead | Twitter
 
Please register or log in to leave a reply.