UNPKG

threepipe

Version:

A modern 3D viewer framework built on top of three.js, written in TypeScript, designed to make creating high-quality, modular, and extensible 3D experiences on the web simple and enjoyable.

43 lines 1.92 kB
import { Importer } from '../../assetmanager'; import { USDZLoader } from 'three/examples/jsm/loaders/USDZLoader.js'; import { zipSync } from 'three/examples/jsm/libs/fflate.module.js'; import { BaseImporterPlugin } from '../base/BaseImporterPlugin'; /** * Adds support for loading `.usdz`, `model/vnd.usd+zip` and `.usda`, `model/vnd.usda` files and data uris * @category Plugins */ export class USDZLoadPlugin extends BaseImporterPlugin { constructor() { super(...arguments); this._importer = new Importer(class extends USDZLoader { constructor() { super(...arguments); this.currentUrl = ''; } async loadAsync(url, onProgress) { this.currentUrl = url; const res = await super.loadAsync(url, onProgress); // console.log(res) this.currentUrl = ''; if (!res.children.length) throw new Error('No mesh found in USDZ file, note that usdc files are not supported.'); // todo see three-usdz-loader return res; } parse(buffer) { // todo make changes in three.js to allow passing unzipped buffer directly for usda if (this.currentUrl.endsWith('.usda') && typeof buffer !== 'string') { const filename = this.currentUrl.split('/').pop(); if (filename) { const zip = {}; zip[filename] = new Uint8Array(buffer); buffer = zipSync(zip).buffer; } } return super.parse(buffer); } }, ['usdz', 'usda'], ['model/vnd.usd+zip', 'model/vnd.usdz+zip', 'model/vnd.usda'], false); } } USDZLoadPlugin.PluginType = 'USDZLoadPlugin'; //# sourceMappingURL=USDZLoadPlugin.js.map