Skip to content

Commit

Permalink
[cli] Automatically unpartition glb output (donmccurdy#576)
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy authored Apr 29, 2022
1 parent e9b3a8a commit 79b2f73
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/cli/src/session.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Document, NodeIO, Logger, FileUtils, Transform } from '@gltf-transform/core';
import { Document, NodeIO, Logger, FileUtils, Transform, Format } from '@gltf-transform/core';
import type { Packet, XMP } from '@gltf-transform/extensions';
import { unpartition } from '@gltf-transform/functions';
import { formatBytes, XMPContext } from './util';

/** Helper class for managing a CLI command session. */
export class Session {
private _outputFormat: Format;

constructor(private _io: NodeIO, private _logger: Logger, private _input: string, private _output: string) {
_io.setLogger(_logger);
this._outputFormat = FileUtils.extension(_output) === 'glb' ? Format.GLB : Format.GLTF;
}

public static create(io: NodeIO, logger: unknown, input: unknown, output: unknown): Session {
Expand All @@ -31,6 +35,10 @@ export class Session {

await doc.transform(...transforms, updateMetadata);

if (this._outputFormat === Format.GLB) {
await doc.transform(unpartition());
}

await this._io.write(this._output, doc);

const { lastReadBytes, lastWriteBytes } = this._io;
Expand Down

0 comments on commit 79b2f73

Please sign in to comment.