UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

28 lines (27 loc) 959 B
"use strict"; import { Poly } from "../../../engine/Poly"; import { CoreBaseLoader } from "../_Base"; import { JSONDataParser } from "./JSONDataParser"; export class JsonDataLoader extends CoreBaseLoader { constructor(url, options = {}, _node) { super(url, _node); this._node = _node; this._parser = new JSONDataParser(options); } async load(success_callback, progress_callback, error_callback) { const url = this._urlToLoad(); fetch(url).then(async (response) => { let json = await response.json(); const dataKeysPrefix = this._parser.dataKeysPrefix(); if (dataKeysPrefix != null && dataKeysPrefix != "") { json = this._parser.get_prefixed_json(json, dataKeysPrefix.split(".")); } this._parser.setJSON(json); const object = this._parser.createObject(); success_callback(object); }).catch((error) => { Poly.error("error", error); error_callback(error); }); } }