Forum

Single preloader for multi-file load

07 May 2017 19:43
Hi, I am designing a configurator where I load multiple component json files with m_data.load(). Now my question is how to create a preloader that shows loading until all these components are loaded?
08 May 2017 11:11
Hello

Have you saw this article?
If you need to create a preloader, you should call the m_preloader.create_preloader(); fucntion before you call m_data.load()
08 May 2017 15:10
As I have mentioned, I need a single preloader for multi-file loading. For example, if I am loading a table design in 4 blend files as table-top, legs, table cloth and table lamp, I want a single preloader that will show that the file is loading until those 4 files are loaded. Using m_data.load("filename.json", load_cb, preloader_cb);, the preloader will start loading for every file separately which is not what is required.
12 May 2017 19:17
Any suggestions anyone?
15 May 2017 15:41
Hi, you can still use the standard preloader but it needs a proper percentage value when calling the m_preloader.update_preloader() method.

An ordinary way is to pass it from the preloader_cb method:
function preloader_cb(percentage) {
    m_preloader.update_preloader(percentage);
}


But for multiple json files you need to store their own percentage values somewhere (especially if the json files are loaded simultaneously) and calculate the overall value divided by the count of json files. Then, this value should be passed into the "update_preloader" function.
For now the problem is that if you'll use the same "preloader_cb" callback it will be hard to distinguish the percentage values and to do the proper calculation.

We've added a little fix in the code, which will be available in the next June release. It'll allow to use the special "data_id" parameter in the "preloader_cb" callback. So, the following snippet will work, you just need to specify the number of json files to be loaded (JSON_COUNT variable):

var _preload_data = {};
var JSON_COUNT = 4; 
function upd_preloader_data(percentage, data_id) {
    if (!(data_id in _preload_data))
        _preload_data[data_id] = 0;

    _preload_data[data_id] = percentage;
}

function get_preloader_value() {
    var value = 0;
    for (var id in _preload_data)
        value += _preload_data[id];

    return m_util.trunc(value/JSON_COUNT);
}

/**
 * update the app's preloader
 */
function preloader_cb(percentage, load_time, data_id) {
    upd_preloader_data(percentage, data_id);
    m_preloader.update_preloader(get_preloader_value());
}


As for now, something similar can be achieved by using multiple different preloader_cb functions, each specified in the separated m_data.load call, but it's not very convenient.
 
Please register or log in to leave a reply.