| 32 | } |
| 33 | |
| 34 | public async transform(...transforms: Transform[]): Promise<void> { |
| 35 | const logger = this._logger; |
| 36 | const document = this._input |
| 37 | ? (await this._io.read(this._input)).setLogger(this._logger) |
| 38 | : new Document().setLogger(this._logger); |
| 39 | |
| 40 | // Warn and remove lossy compression, to avoid increasing loss on round trip. |
| 41 | for (const extensionName of ['KHR_draco_mesh_compression', 'EXT_meshopt_compression']) { |
| 42 | if (document.hasExtension(extensionName)) { |
| 43 | document.disposeExtension(extensionName); |
| 44 | this._logger.warn(`Decoded ${extensionName}. Further compression will be lossy.`); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | if (this._display) { |
| 49 | const tasks = [] as ListrTask[]; |
| 50 | for (const transform of transforms) { |
| 51 | tasks.push({ |
| 52 | title: transform.name, |
| 53 | task: async (_ctx, task) => { |
| 54 | let time = performance.now(); |
| 55 | await document.transform(transform); |
| 56 | time = Math.round(performance.now() - time); |
| 57 | task.title = task.title.padEnd(20) + styleText('dim', ` ${formatLong(time)}ms`); |
| 58 | }, |
| 59 | }); |
| 60 | } |
| 61 | |
| 62 | const prevLevel = logger.getVerbosity(); |
| 63 | if (prevLevel === Verbosity.INFO) logger.setVerbosity(Verbosity.WARN); |
| 64 | |
| 65 | // Disable signal listeners so Ctrl+C works. Note that 'simple' and 'default' |
| 66 | // renderers have different capability to display errors and warnings. |
| 67 | await new Listr(tasks, { |
| 68 | renderer: 'default', |
| 69 | registerSignalListeners: false, |
| 70 | silentRendererCondition: process.env.NODE_ENV === 'test', |
| 71 | }).run(); |
| 72 | console.log(''); |
| 73 | |
| 74 | logger.setVerbosity(prevLevel); |
| 75 | } else { |
| 76 | await document.transform(...transforms); |
| 77 | } |
| 78 | |
| 79 | await document.transform(updateMetadata); |
| 80 | |
| 81 | if (this._outputFormat === Format.GLB) { |
| 82 | await document.transform(unpartition()); |
| 83 | } |
| 84 | |
| 85 | await this._io.write(this._output, document); |
| 86 | |
| 87 | const { lastReadBytes, lastWriteBytes } = this._io; |
| 88 | if (!this._input) { |
| 89 | const output = FileUtils.basename(this._output) + '.' + FileUtils.extension(this._output); |
| 90 | this._logger.info(`${output} (${formatBytes(lastWriteBytes)})`); |
| 91 | } else { |