UNPKG

threepipe

Version:

A 3D viewer framework built on top of three.js in TypeScript with a focus on quality rendering, modularity and extensibility.

38 lines 1.63 kB
import { SimpleJSONLoader } from './SimpleJSONLoader'; import { getEmptyMeta, ThreeSerialization } from '../../utils/serialization'; export class JSONMaterialLoader extends SimpleJSONLoader { async loadAsync(url, onProgress) { if (!this.viewer) throw 'Viewer not set in JSONMaterialLoader.'; const json = await super.loadAsync(url, onProgress); return await JSONMaterialLoader.DeserializeMaterialJSON(json, this.viewer); } static async DeserializeMaterialJSON(json, viewer, meta, obj) { meta = meta || getEmptyMeta(); const json2 = { ...json }; if (json.images) { if (Array.isArray(json.images)) meta.images = Object.fromEntries(json.images.map((i) => [i.uuid, i])); else meta.images = json.images; delete json2.images; } if (json.textures) { if (Array.isArray(json.textures)) meta.textures = Object.fromEntries(json.textures.map((t) => [t.uuid, t])); else meta.textures = json.textures; delete json2.textures; } if (json.materials) { if (Array.isArray(json.materials)) meta.materials = Object.fromEntries(json.materials.map((m) => [m.uuid, m])); else meta.materials = json.materials; delete json2.materials; } const resources = await viewer.loadConfigResources(meta); return ThreeSerialization.Deserialize(json2, obj || undefined, resources); } } //# sourceMappingURL=JSONMaterialLoader.js.map