Forum

name of loaded object

19 August 2017 20:04
I am trying to get a loaded objects name in the scene but the name of the Json file doesn't seem to work.
20 August 2017 05:04
Here is the code for that.
var m_scenes = require("scenes");

// get objects of all types
var scene_object_list = m_scenes.get_all_objects();

// get all MESH objects
var scene_object_list = m_scenes.get_all_objects("MESH");

// get all SPEAKER objects from the first dynamically loaded scene
var scene_object_list = m_scenes.get_all_objects("SPEAKER", 1);

The Cartoon Interior example project uses this.
20 August 2017 17:40
Thanks! I will give that a try.
21 August 2017 02:36
Other fuctions in the Scenes module may help also. Like get_object_name().
21 August 2017 10:57
Ok so it works only never the first time. I need to click twice my loader link to get someting in
var scene_object_list = m_scenes.get_all_objects("MESH",1);



Is there a way of forcing a update of that list. Or should i set it in a callback??


document.getElementById("rightHandedSwordMan").addEventListener("click", function(e) {
e.preventDefault();
console.log('sword_ACbtDLE');
m_data.load( "../media/artefacts/sword_ACbtDLE.json");

var positionObjectsword_ACbtDLE = m_scenes.get_object_by_name("handRightPos");
var scene_object_list = m_scenes.get_all_objects("MESH",1);
console.log(scene_object_list);

21 August 2017 11:41
OK so i'm solving this nice and gently.
In fact i'm pushing all the logic after the object is loaded in the loaded_cb. The question now is how do i keep trace of the object location variable????
Got to find a way…

There you go !
some python magic (positionObject is a empty object )
positionObject.{{artefact}} = m_scenes.get_object_by_name("{{artefact.position}}");
to build a object with all my position objects names after the element that going to that position
AND :
function loaded_cb(data_id) {
var scene_object_list = m_scenes.get_all_objects("MESH",data_id);
var positionName = scene_object_list[0].name
m_const.append_copy_trans(scene_object_list[0], positionObject[positionName])

templating JS loops with python and keeping track of the scope isn't the easiest trick i've seen today
21 August 2017 21:51
Have you looked at the Transform Module?
Specifically the get_tsr() function to get the transformation, scale and rotation. It returns a TSR array.
22 August 2017 11:07
I cant seem to make my unloader work…
Could someone take a look. They must be somethng pretty obvious.
function unloadPrev(){
data_id_counter += 1
console.log('unload');
console.log(data_id_counter);
console.log( m_scenes.get_all_objects("MESH",data_id_counter).length);
console.log( m_scenes.get_all_objects("MESH",data_id_counter))
console.log('#############');
if (data_id_counter > 1){
for (i=1; i < data_id_counter; i ++){
console.log( m_scenes.get_all_objects("MESH",i));
if ( m_scenes.get_all_objects("MESH",i).length > 0 ) {

m_data.unload(i);
}
}
return

}
else {
return
}

}



Here a my logs in the browser. You'll notice a long a the for loop doesn't start i get the callback. That's what loads the scene. But as soon a it starts looping it fails and the callback functins are not called…
unload  character:241:10
1 character:242:10
0 character:243:10
Array [ ] character:244:10
############# character:245:10
callback character:266:10
callbackDone character:273:10
callback character:266:10
callbackDone character:273:10
unload character:241:10
2 character:242:10
1 character:243:10
Array [ Object ] character:244:10
############# character:245:10
unload character:241:10
3 character:242:10
0 character:243:10
Array [ ] character:244:10
############# character:245:10
unload character:241:10
4 character:242:10
0 character:243:10
Array [ ] character:244:10
#############


EDIT : i have moved the incrementer for data_id_counter to get the right number. It wasn't called often enough here.
22 August 2017 12:09
I am starting to wonder if B4W supports for loops
so it works as follow

function unloadPrev(){

console.log('unload');
console.log(data_id_counter);
var i = 1
while ( i <= data_id_counter ){
console.log(i)
m_data.unload(i);
i++
}
 
Please register or log in to leave a reply.