import { ThreeMfModelBuilder } from "./3mf.builder.js"; import { type I3mfDocument } from "./3mf.opc.interfaces.js"; import { type I3mfModel, ST_Unit } from "./3mf.interfaces.js"; /** * Options controlling how meshes are exported into the 3MF model. * * Notes: * - These flags are kept generic here and are expected to be interpreted by the concrete serializer/model builder. * - Defaults are set in AbstractThreeMfSerializer.DEFAULT_3MF_EXPORTER_OPTIONS. */ export interface IThreeMfSerializerBaseOptions { /** * define the unit. Default is millimeter */ unit?: ST_Unit; /** * */ metadata?: Record; } /** * Minimal contract for a 3MF serializer that can stream its output through a sink callback. * * The sink callback receives: * - err: any error produced by the serialization pipeline (if any) * - chunk: a chunk of bytes to append to the destination * - final: true when this is the last chunk * * Important: * - Implementations should call sink with final=true exactly once, or rely on the underlying zip lib to do so. * - Consumers may ignore final if they just buffer everything. */ export interface I3mfSerializer { serializeAsync(sink: (err: any, chunk: Uint8Array, final: boolean) => void, ...meshes: Array): Promise; } /** * Base class for 3MF serialization. * * Responsibilities: * - Convert user meshes to a 3MF model (toModel). * - Wrap the 3MF document parts into an OPC container (zip) and stream bytes through the sink. * * Non-responsibilities: * - Providing/initializing the zip implementation (ensureZipLibReadyAsync is abstract). * - Defining how meshes map to 3MF objects (toModel is abstract). */ export declare abstract class AbstractThreeMfSerializer implements I3mfSerializer { private _o; /** * @param opts user-provided options overriding defaults. */ constructor(opts: O); /** * Expose the resolved options (defaults + overrides) as readonly. */ get options(): Readonly; /** * Generic 3MF binary serializer. * Pipeline overview: * 1. ensureZipLibReadyAsync provides a zip implementation (host-dependent). * 2. Convert meshes into an I3mfDocument (OPC parts + model). * 3. Create a zip target that streams through the provided sink. * 4. Serialize XML parts into zip entries. * 5. End the zip stream. * @param sink a callback receiving byte chunks; enables streaming without buffering the full archive in memory. * @param meshes the meshes to serialize. * @returns */ serializeAsync(sink: (err: any, chunk: Uint8Array, final: boolean) => void, ...meshes: Array): Promise; /** * Build a full 3MF OPC document from meshes. * * The default behavior uses ThreeMfDocumentBuilder with the model produced by toModel(). * Override if you need custom parts (textures, thumbnails, print ticket, etc.). * @param meshes * @returns */ toDocument(...meshes: Array): I3mfDocument | undefined; /** * Convert input meshes into a 3MF model. * * Implementations typically: * - Create resources and objects. * - Define build items (instances) when exportInstances is enabled. * - Encode geometry and properties required by your pipeline. */ abstract toModel(builder: ThreeMfModelBuilder, ...meshes: Array): I3mfModel; /** * Provide a zip implementation for the current host/runtime. * * This might be provided by the framework implementation, but it could differ depending on the host * (native, Node.js, browser, etc.). * * Expected shape (fflate-like): * - return [ Zip, ZipDeflate ] at minimum. * * Notes: * - In a browser, this might require bundler configuration or dynamic import. * - In Node.js, this might be a direct import of "fflate" or another compatible implementation. */ abstract ensureZipLibReadyAsync(): Promise; } /** * Convenience helpers around serializers. */ export declare class ThreeMf { /** * Serialize to a single in-memory buffer. * * This is a helper that buffers all chunks produced by serializeAsync, then concatenates them. * Use serializeAsync directly if you want true streaming to a file/response. * @param s * @param meshes * @returns */ static SerializeToMemoryAsync(s: I3mfSerializer, ...meshes: Array): Promise; }