Forum

Cant access loaded obj

21 December 2015 23:37
Hi!
So I load one json containing Cube1,
then I load another json containing Cube2.
Both cubes are visible and it works nice except I can access Cube1 but not Cube2.
B4W ERROR: get object Cube2: not found
What am I missing here?


//load scene one
function load_sc1() {m_data.load("scene1.json",sc1_loaded_cb);} //has Cube1

//load scene two
function load_sc2() {m_data.load("scene2.json");} //has Cube2

//////——–
function sc1_loaded_cb(data_id) {
m_app.enable_controls();
m_app.enable_camera_controls();
}

//test functions
function test_one(){ var obj_one = m_scenes.get_object_by_name("Cube1");} //works
function test_two(){ var obj_two = m_scenes.get_object_by_name("Cube2");} //fails..

22 December 2015 08:26
Hi Kristian,

The get_object_by_name() method accepts an optional second argument data_id which you should use to obtain objects from the second dynamically loaded scene. For example:
var obj_two = m_scenes.get_object_by_name("Cube2", 1); // scenes are indexed starting from 0

Hope this helps!
The Founder | Twitter | Facebook | Linkedin
22 December 2015 09:49
Hello.

Also we discussed it on this page.
22 December 2015 11:55
Thanks alot! I can access it now.
I read the other post and trying out some things with external loading.
So how would the proper use of get_meta_tags(obj) be used? documentation confusing me bit, all I get returned is undefined or just object Object..

Kristian
22 December 2015 12:15
Do you mean get_meta_tags from the "objects" module?

If yes, it returns the object metatags, that were set in Blender.



If you use the "get_meta_tags" function from the "scenes" module, it returns the metatags of the active scene.
23 December 2015 18:20
Thanx alot! figured it out and updated my fish viewer!
link


23 December 2015 18:24
Glad we could help! Nice start with Blend4Web API
The Founder | Twitter | Facebook | Linkedin
 
Please register or log in to leave a reply.