UNPKG

playcanvas

Version:

Open-source WebGL/WebGPU 3D engine for the web

54 lines (53 loc) 1.99 kB
var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); import { http, Http } from "../../platform/net/http.js"; import { GSplatOctreeResource } from "../../scene/gsplat-unified/gsplat-octree.resource.js"; import { GSplatAssetLoader } from "../components/gsplat/gsplat-asset-loader.js"; class GSplatOctreeParser { /** * @param {AppBase} app - The app instance. * @param {number} maxRetries - Maximum amount of retries. */ constructor(app, maxRetries) { /** @type {AppBase} */ __publicField(this, "app"); /** @type {number} */ __publicField(this, "maxRetries"); this.app = app; this.maxRetries = maxRetries; } /** * @param {object} url - The URL of the resource to load. * @param {string} url.load - The URL to use for loading the resource. * @param {string} url.original - The original URL useful for identifying the resource type. * @param {ResourceHandlerCallback} callback - The callback used when * the resource is loaded or an error occurs. * @param {object} asset - Container asset. */ load(url, callback, asset) { if (typeof url === "string") { url = { load: url, original: url }; } const options = { retry: this.maxRetries > 0, maxRetries: this.maxRetries, responseType: Http.ResponseType.JSON }; http.get(url.load, options, (err, data) => { if (!err) { const assetLoader = new GSplatAssetLoader(this.app.assets); const resource = new GSplatOctreeResource(asset.file.url, data, assetLoader); callback(null, resource); } else { callback(`Error loading gsplat octree: ${url.original} [${err}]`); } }); } } export { GSplatOctreeParser };