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.

49 lines 1.89 kB
import { AViewerPluginSync } from '../../viewer'; import { downloadBlob } from 'ts-browser-helpers'; /** * File Transfer Plugin * * Provides a way to extend the viewer.export functionality with custom actions. Used in `AWSClientPlugin` to upload files directly to S3. * * @category Plugins */ export class FileTransferPlugin extends AViewerPluginSync { async exportFile(file, name) { name = name || file.name || 'file_export'; this.dispatchEvent({ type: 'transferFile', path: name, state: 'exporting', progress: 0 }); await this.actions.exportFile(file, name, ({ state, progress }) => { this.dispatchEvent({ type: 'transferFile', path: name, state: state ?? 'exporting', progress }); }); this.dispatchEvent({ type: 'transferFile', path: name, state: 'done' }); } constructor() { super(); this.enabled = true; this.toJSON = undefined; this.defaultActions = { exportFile: async (blob, name, _onProgress) => { downloadBlob(blob, name); }, }; this.actions = { ...this.defaultActions }; this._updateProcessState = this._updateProcessState.bind(this); } onAdded(viewer) { super.onAdded(viewer); this.addEventListener('transferFile', this._updateProcessState); } onRemove(viewer) { this.removeEventListener('transferFile', this._updateProcessState); super.onRemove(viewer); } _updateProcessState(data) { if (!this._viewer) return; this._viewer.assetManager.setProcessState(data.path, data.state !== 'done' ? { state: data.state, progress: data.progress ? data.progress * 100 : undefined, } : undefined); } } FileTransferPlugin.PluginType = 'FileTransferPlugin'; //# sourceMappingURL=FileTransferPlugin.js.map