UNPKG

playcanvas

Version:

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

53 lines (52 loc) 1.91 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. */ constructor(app) { /** @type {AppBase} */ __publicField(this, "app"); this.app = app; } canParse(context) { return context.basename === "lod-meta.json"; } /** * @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.handler.maxRetries > 0, maxRetries: this.handler.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 };