Using loadscene with vars

  • I need to load a scene with its initial position set to something other than the value declared in the view section of the scene.

    If I say -
    loadscene(get(startscene), view.hlookat=45, MERGE);
    - this works fine.

    but I would like to say -
    loadscene(get(startscene), view.hlookat=nnn, MERGE); where nnn is a variable derived as the result of a previous calculation, but I cannot get that to work. I have tried accessing the variable directly and via a get() instruction, but to no avail.

    What is the correct syntax for this, please?

    Regards

    Andrew

  • Thanks Alexey. I have tried that this afternoon and I can see that I can control the view parameters when opening a scene from a hotspot, but I am trying to change the opening view of a single scene at startup.

    What I would like to do is use the hlookat value as defined in the view section of the scene element only if the user is holding their device in a landscape, horizontal orientation. If they open the panorama while holding their tablet or phone in a portrait, vertical orientation I would like the scene to open using a different hlookat value. The scene is a very simple one, with no gyro, no VR.

    Here is my startup action -

    <action name="startup">
    if(startscene === null, copy(startscene,scene[0].name));
    div(stageratio,stagewidth,stageheight);
    if(stageratio lt 1,
    loadscene(get(startscene), view.hlookat=15, MERGE);
    ,
    loadscene(get(startscene), null, MERGE);
    )
    </action>

    As you can see, if the stage is in portrait orientation, i.e. stagewidth is less than stageheight, the scene opens with an initial hlookat value of 15, if in landscape orientation it opens with whatever hlookat value is declared in the scene element.

    This works fine, with no problem.

    But what I would like to do is replace the value of 15 in the above example with a value held in a variable which has been declared elsewhere in the xml by saying something like -

    loadscene(get(startscene), view.hlookat=get(nnn), MERGE);

    When I try this the scene does not open and I just see a black screen.

    Obviously I have my syntax wrong here, and at the moment I cannot see the way forward. I am a photographer and while I muddle along with my programming I will never be an expert at it, so any help would be very much appreciated, please.

    Regards

    Andrew

  • Hi,

    about the syntax itself - here the 'calc' action could be used to build the 'vars' parameter string:
    https://krpano.com/docu/actions/#calc

    e.g.

    Code
    loadscene(get(startscene), calc('view.hlookat=' + nnn), MERGE);


    where 'nnn' should be a value or the name of a variable.

    Or here an example for more variables:

    Code
    loadscene(get(startscene), calc('view.hlookat=' + n1 + '&amp;view.vlookat=' + n2), MERGE);


    This would work, but I would recommend a solution like this:

    Code
    loadscene(get(startscene), null, MERGE);
    set(view.hlookat, get(nnn));


    (or just the lookat action)

    That means setting the new view directly after loading the scene.
    The result itself would be the same.

    Best regards,
    Klaus

  • Oh wow, Klaus - that's absolutely perfect! Thank you very much indeed.

    I have gone for your third and recommended option, which does exactly what I wanted.

    Thanks again

    Kind regards
    Andrew

  • hi klaus
    is it corret like this:

    loadscene(get(startscene), null,MERGE);
    set(view.hlookat, get(view.hlookat));
    set(view.vlookat, get(view.vlookat));

    but it doesn't work

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!