playcanvas
Version:
PlayCanvas WebGL game engine
40 lines (37 loc) • 1.19 kB
JavaScript
import { http } from '../../platform/net/http.js';
class SceneUtils {
/**
* Loads the scene JSON file from a URL.
*
* @param {string} url - URL to scene JSON.
* @param {number} maxRetries - Number of http load retry attempts.
* @param {Function} callback - The callback to the JSON file is loaded.
*/ static load(url, maxRetries, callback) {
if (typeof url === 'string') {
url = {
load: url,
original: url
};
}
http.get(url.load, {
retry: maxRetries > 0,
maxRetries: maxRetries
}, (err, response)=>{
if (!err) {
callback(err, response);
} else {
var errMsg = "Error while loading scene JSON " + url.original;
if (err.message) {
errMsg += ": " + err.message;
if (err.stack) {
errMsg += "\n" + err.stack;
}
} else {
errMsg += ": " + err;
}
callback(errMsg);
}
});
}
}
export { SceneUtils };