UNPKG

forge-svf-utils

Version:

Utilities for working with Autodesk Forge SVF file format.

159 lines 6.62 kB
/// <reference types="node" /> import { IAuthOptions } from 'forge-server-utils/dist/common'; import { PropDbReader } from './propdb-reader'; import * as schema from './schema'; /** * Entire content of SVF and its assets loaded in memory. */ export interface ISvfContent { metadata: schema.ISvfMetadata; fragments: schema.IFragment[]; geometries: schema.IGeometryMetadata[]; meshpacks: (schema.IMesh | schema.ILines | schema.IPoints | null)[][]; materials: (schema.IMaterial | null)[]; properties: PropDbReader; images: { [uri: string]: Buffer; }; } /** * Utility class for parsing & reading SVF content from Model Derivative service * or from local file system. * * The class can only be instantiated using one of the two async static methods: * {@link Reader.FromFileSystem}, or {@link Reader.FromDerivativeService}. * After that, you can parse the entire SVF into memory using {@link parse}, or parse * individual SVF objects using methods like {@link listFragments} or {@link enumerateGeometries}. * * @example * const auth = { client_id: 'forge client id', client_secret: 'forge client secreet' }; * const reader = await Reader.FromDerivativeService('model urn', 'viewable guid', auth); * const svf = await reader.read(); // Read entire SVF into memory * console.log(svf); * * @example * const reader = await Reader.FromFileSystem('path/to/svf'); * // Enumerate fragments (without building a list of all of them) * for await (const fragment of reader.enumerateFragments()) { * console.log(fragment); * } */ export declare class Reader { protected resolve: (uri: string) => Promise<Buffer>; /** * Instantiates new reader for an SVF on local file system. * @async * @param {string} filepath Path to the *.svf file. * @returns {Promise<Reader>} Reader for the provided SVF. */ static FromFileSystem(filepath: string): Promise<Reader>; /** * Instantiates new reader for an SVF in Forge Model Derivative service. * @async * @param {string} urn Forge model URN. * @param {string} guid Forge viewable GUID. The viewable(s) can be found in the manifest * with type: 'resource', role: 'graphics', and mime: 'application/autodesk-svf'. * @param {IAuthOptions} auth Credentials or access token for accessing the Model Derivative service. * @returns {Promise<Reader>} Reader for the provided SVF. */ static FromDerivativeService(urn: string, guid: string, auth: IAuthOptions): Promise<Reader>; protected svf: schema.ISvfRoot; protected constructor(svf: Buffer, resolve: (uri: string) => Promise<Buffer>); /** * Reads the entire SVF and all its referenced assets into memory. * In cases where a more granular control is needed (for example, when trying to control * memory consumption), consider parsing the different SVF elements individually, * using methods like {@link listFragments}, {@link enumerateGeometries}, etc. */ read(): Promise<ISvfContent>; protected findAsset(query: { type?: schema.AssetType; uri?: string; }): schema.ISvfManifestAsset | undefined; /** * Retrieves raw binary data of a specific SVF asset. * @async * @param {string} uri Asset URI. * @returns {Promise<Buffer>} Asset content. */ getAsset(uri: string): Promise<Buffer>; /** * Retrieves parsed SVF metadata. * @async * @returns {Promise<schema.ISvfMetadata>} SVF metadata. */ getMetadata(): Promise<schema.ISvfMetadata>; /** * Retrieves, parses, and iterates over all SVF fragments. * @async * @generator * @returns {AsyncIterable<schema.IFragment>} Async iterator over parsed fragments. */ enumerateFragments(): AsyncIterable<schema.IFragment>; /** * Retrieves, parses, and collects all SVF fragments. * @async * @returns {Promise<IFragment[]>} List of parsed fragments. */ readFragments(): Promise<schema.IFragment[]>; /** * Retrieves, parses, and iterates over all SVF geometry metadata. * @async * @generator * @returns {AsyncIterable<schema.IGeometryMetadata>} Async iterator over parsed geometry metadata. */ enumerateGeometries(): AsyncIterable<schema.IGeometryMetadata>; /** * Retrieves, parses, and collects all SVF geometry metadata. * @async * @returns {Promise<schema.IGeometryMetadata[]>} List of parsed geometry metadata. */ readGeometries(): Promise<schema.IGeometryMetadata[]>; /** * Gets the number of available mesh packs. */ getMeshPackCount(): number; /** * Retrieves, parses, and iterates over all meshes, lines, or points in a specific SVF meshpack. * @async * @generator * @returns {AsyncIterable<schema.IMesh | schema.ILines | schema.IPoints | null>} Async iterator over parsed meshes, * lines, or points (or null values for unsupported mesh types). */ enumerateMeshPack(packNumber: number): AsyncIterable<schema.IMesh | schema.ILines | schema.IPoints | null>; /** * Retrieves, parses, and collects all meshes, lines, or points in a specific SVF meshpack. * @async * @param {number} packNumber Index of mesh pack file. * @returns {Promise<(schema.IMesh | schema.ILines | schema.IPoints | null)[]>} List of parsed meshes, * lines, or points (or null values for unsupported mesh types). */ readMeshPack(packNumber: number): Promise<(schema.IMesh | schema.ILines | schema.IPoints | null)[]>; /** * Retrieves, parses, and iterates over all SVF materials. * @async * @generator * @returns {AsyncIterable<schema.IMaterial | null>} Async iterator over parsed materials * (or null values for unsupported material types). */ enumerateMaterials(): AsyncIterable<schema.IMaterial | null>; /** * Retrieves, parses, and collects all SVF materials. * @async * @returns {Promise<(schema.IMaterial | null)[]>} List of parsed materials (or null values for unsupported material types). */ readMaterials(): Promise<(schema.IMaterial | null)[]>; /** * Finds URIs of all image assets referenced in the SVF. * These can then be retrieved using {@link getAsset}. * @returns {string[]} Image asset URIs. */ listImages(): string[]; /** * Retrieves and parses the property database. * @async * @returns {Promise<PropDbReader>} Property database reader. */ getPropertyDb(): Promise<PropDbReader>; } //# sourceMappingURL=reader.d.ts.map