how to get a value computed in a Javascript renderloop function?

  • I have a Javascript action that runs a renderloop function to decode some input device events. For some events, it terminates the renderloop, and at that point it should return or post some variables accessible to the calling action, or alternatively call some other action with those values. I have tried several ways that don't work, and would appreciate some definitive guidance.

    Klaus, are you listening?

  • Hello,

    You can use https://krpano.com/docu/actions/#inlinefunctions

    I learned about it from klaus in this post:

    klaus.krpano
    March 14, 2023 at 10:40 AM


    gr,

    Kristof

  • thanks, Kris, I will try that.

    I have had some luck using krpano global variables, but there are problems with multiple instances of the renderloop function getting started. I think a subroutine call will be more reliable.

    The basic problem is that I need to stop the renderloop function in order to load a new scene, then start it again after the scene loads. I am having a hard time getting my head around the fact that krpano code is all synchronous -- I keep thinking in terms of cooperating threads.

  • SOLVED. The correct solution, as suggested by indexofrefraction, is to keep the renderloop running as long as webvr is enabled. It posts its findings to global variables, and the consuming code is triggered by onchanged(var, action). The loop posts a variable only when it is zero (and other conditions are right), and the consuming code ignores the value zero.

    This way gives the effect of cooperating threads, even though krpano runs on a single thread.

    This has enabled me to create a new skin for stereoscopic tours, that works to my liking on all devices including VR headsets. Example here.

Participate now!

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