Hi, today i tried to set initial position focused on a model.
That model is loaded from json file external, so after loading i call the focus function.
orbitCamera .focus should work. Do you have a public project to share?
Does app.root.findByName(*entity-id*) return a valid entity? Are you getting any error messages in the console?
Edit: Thinking about it, it also might be possible that the model or the model’s AABB isn’t generated in the same frame as the entity is created when you loaded the JSON. Try waiting a waiting or 2 before calling focus.
I solved the problem with a custom workaround.
I post it for someone that have the same problem.
Yes, the model load after 1 second or something similar, so the focus call have a entity without meshInstance and return error. There is no way to call focus when meshes are ok so i write this:
// my workaround
var active=false;
function f(){
active=true;
try{
app.root.findByName("Camera").script.orbitCamera.focus(app.root.findByName("*entity_id*"));
}catch(ex){
setTimeout(f,200);
}
}
function k(){
if(active==false)f();
}