### Installing Project Dependencies with Bun Source: https://github.com/watzon/three-mf/blob/main/README.md This command installs project dependencies using the Bun package manager. It should be run once after cloning the repository or when new dependencies are added, both for initial setup and development. ```bash bun install ``` -------------------------------- ### Converting STL Files to 3MF - TypeScript/Bash Source: https://github.com/watzon/three-mf/blob/main/examples/README.md This example reads an ASCII or binary STL file and wraps it into a minimal 3MF package. This conversion is useful for preparing existing STL models for printing or further processing within the 3MF ecosystem. ```Bash bun run examples/stl-to-3mf.ts path/to/input.stl path/to/output.3mf ``` -------------------------------- ### Inspecting Meshes and Reporting Metrics - TypeScript/Bash Source: https://github.com/watzon/three-mf/blob/main/examples/README.md This example inspects all meshes in the root model, including flattened component hierarchies and referenced OPC part relationships. It reports key metrics such as vertex and triangle counts, and bounding boxes, useful for model analysis. ```Bash bun run examples/mesh-inspector.ts path/to/model.3mf ``` -------------------------------- ### Parsing 3MF Files with Basic Usage - TypeScript/Bash Source: https://github.com/watzon/three-mf/blob/main/examples/README.md This example demonstrates how to parse a standard 3MF file using `three-mf` and output its JSON structure. It's a fundamental use case for understanding the library's parsing capabilities. ```Bash bun run examples/basic-usage.ts path/to/model.3mf ``` -------------------------------- ### Flattening 3MF Component Hierarchy - TypeScript/Bash Source: https://github.com/watzon/three-mf/blob/main/examples/README.md This example reads a 3MF file and flattens the component hierarchy for a specified object ID. It outputs the merged mesh as JSON, which is useful for simplifying complex models or preparing them for specific processing. ```Bash bun run examples/component-flatten.ts path/to/model.3mf ``` -------------------------------- ### Example 3MF Model with Metadata and Mesh Data in XML Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md This comprehensive XML example illustrates a 3MF model, showcasing various metadata properties at both the model and item levels, including custom vendor-specific metadata. It defines resources such as base materials and an object with detailed mesh vertices and triangles, and demonstrates how components and build items are structured within a 3MF document. ```XML © Microsoft Corporation 2013 Microsoft 3D Builder All rights reserved Cube Microsoft Corporation 2013-10-07 2014-03-27 Cube CE8A91FB-C44E-4F00-B634-BAA411465F6A 03DAE6E4-24FF-4B20-97A1-7487AB9C1CB0 1 ``` -------------------------------- ### Parsing and Serializing 3MF Production Extension - TypeScript/Bash Source: https://github.com/watzon/three-mf/blob/main/examples/README.md This example showcases parsing and serializing 3MF Production Extension attributes, generating OPC `.rels` relationships, and creating new ST_UUID strings. It's crucial for handling advanced 3MF features related to production data. ```Bash bun run examples/production-usage.ts path/to/production-model.3mf ``` -------------------------------- ### Validating 3MF Model Integrity - TypeScript/Bash Source: https://github.com/watzon/three-mf/blob/main/examples/README.md This example validates various aspects of a 3MF model, including mesh integrity, component references, and build items. It reports any detected issues or confirms successful validation, ensuring model correctness. ```Bash bun run examples/validate-report.ts path/to/model.3mf ``` -------------------------------- ### Running Tests in Watch Mode with Bun Source: https://github.com/watzon/three-mf/blob/main/README.md Executes the project's test suite using Bun, with the `--watch` flag enabling continuous re-running of tests upon file changes. This is useful for development to get immediate feedback on code modifications. ```bash bun test --watch ``` -------------------------------- ### Deploying Package to npm Source: https://github.com/watzon/three-mf/blob/main/README.md This sequence of commands first builds the project using Bun, then publishes the compiled package to the npm registry. Ensure you are authenticated with npm and have the necessary permissions before attempting to publish. ```bash bun run build npm publish ``` -------------------------------- ### Building Project with Bun Source: https://github.com/watzon/three-mf/blob/main/README.md Runs the build script defined in the project's `package.json` using Bun. This command compiles the source code and prepares the project for distribution or deployment, generating production-ready assets. ```bash bun run build ``` -------------------------------- ### Simple Production Sample - XML Source: https://github.com/watzon/three-mf/blob/main/3MF Production Extension.md This XML snippet defines a basic 3D model in the 3MF format, including metadata, a simple box mesh with vertices and triangles, and a build section with production UUIDs for the object and the build itself. It demonstrates the structure for a single object production file, adhering to the 3MF Core and Production specifications. ```xml Copyright (c) 2018 3MF Consortium. All rights reserved. ``` -------------------------------- ### Building Project in Watch Mode with Bun Source: https://github.com/watzon/three-mf/blob/main/README.md Executes the project's build script using Bun, with the `--watch` flag enabling continuous re-building upon file changes. This is useful for development to see changes reflected immediately without manual re-compilation. ```bash bun run build --watch ``` -------------------------------- ### Building and Packaging 3MF XML Structures Source: https://github.com/watzon/three-mf/blob/main/README.md This TypeScript snippet illustrates how to programmatically construct 3MF XML elements for objects and build items, assemble them into a `ThreeMFXml` structure, and then package them into a `.3mf` archive using `create3MFArchive`. It demonstrates a high-level approach to generating 3MF files without direct XML or ZIP manipulation, simplifying the creation process. ```typescript import type { ThreeMFXml } from './src/builder'; import { objectWithMesh, buildItemXml } from './src/builder'; import { create3MFArchive } => from './src/packager'; import type { Mesh } from './src/mesh'; // Given a Mesh object (from parseMesh or custom geometry) const mesh: Mesh = /* ... */; // 1. Build object and build-item XML elements const objElement = objectWithMesh(1, mesh); const itemElement = buildItemXml(1 /* object ID */, { '@_partnumber': 'baseplate' }); // 2. Assemble the top-level ThreeMFXml structure const xmlObj: ThreeMFXml = { model: { '@_unit': 'millimeter', '@_xmlns': 'http://schemas.microsoft.com/3dmanufacturing/core/2015/02', resources: { object: objElement }, build: { item: itemElement } } }; // 3. Create the .3mf package and write it out const zip = create3MFArchive(xmlObj); const buffer = await zip.generateAsync({ type: 'nodebuffer' }); await Deno.writeFile('output.3mf', buffer); ``` -------------------------------- ### Parsing 3MF File with three-mf Library Source: https://github.com/watzon/three-mf/blob/main/README.md This asynchronous function demonstrates the core workflow for opening, parsing, and inspecting a 3MF file. It uses `three-mf` utilities to open the archive, extract the primary model, parse resources and build items from its XML content, and then construct an in-memory `ThreeMFDocument` for further manipulation or JSON serialization. ```typescript import { openArchive, getPrimaryModelPath, getModel, parseResourcesFromXml, parseBuildFromXml, ThreeMFDocument } from 'three-mf'; async function example(filePath: string) { // 1. Open 3MF archive const zip = await openArchive(filePath); const modelPath = await getPrimaryModelPath(zip); // 2. Parse the element const model = await getModel(zip, modelPath); const xmlText = await zip.file(modelPath)!.async('text'); // 3. Extract resources and build items const resources = parseResourcesFromXml(xmlText); const buildItems = parseBuildFromXml(xmlText, resources); // 4. Work with in-memory document const document = new ThreeMFDocument(model, resources, buildItems); console.log(JSON.stringify(document.toJSON(), null, 2)); } ``` -------------------------------- ### Specifying Build Instructions in 3MF Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md The element contains one or more elements, specifying the objects to be manufactured. Consumers must only output 3D objects referenced by an element within this section. ```XML ``` -------------------------------- ### Defining Root Model Relationships (OPC .rels) Source: https://github.com/watzon/three-mf/blob/main/3MF Production Extension.md This XML snippet demonstrates a root .rels file, which is essential for OPC standard conformance in 3MF packages. It defines relationships to the main 3D model file (build.model) and a thumbnail image (thumbnail.png), ensuring the root model is properly referenced within the package. ```XML ``` -------------------------------- ### Defining Resources in 3MF Models Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md The element serves as a library for constituent pieces of the 3D object definition, such as objects, properties, and materials. Resource IDs must be unique within the model, and objects defined here can be reused. ```XML ``` -------------------------------- ### Defining Non-Root Model Relationships (OPC .rels) Source: https://github.com/watzon/three-mf/blob/main/3MF Production Extension.md This XML snippet illustrates how non-root model files are referenced within a 3MF package. It shows a .rels file (e.g., model.model.rels) that defines relationships to other 3D model files (object1.model, object2.model, object3.model), adhering to OPC part relationship standards for multi-file 3MF constructions. ```XML ``` -------------------------------- ### Defining Reusable Object Resources in 3MF Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md The element describes reusable 3D objects that can be output directly or composed into more complex objects. These objects are defined as resources to aid in modular design and component reuse. ```XML ``` -------------------------------- ### 3MF Production Extension XML Schema Definition Source: https://github.com/watzon/three-mf/blob/main/3MF Production Extension.md This XML Schema defines the structure and elements of the 3MF Production Extension. It specifies complex types for CT_Item, CT_Component, and CT_Object, including required UUID attributes for unique identification, and simple types for ST_Path and ST_UUID, ensuring valid 3MF production package construction. ```XML ``` -------------------------------- ### Referencing Objects for Manufacturing with 3MF Item Element Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md The element identifies an object resource to be output by the 3D manufacturing device. It requires an objectid reference and can include a transform matrix, partnumber, and optional . ```XML Batch-2023-Q4 ``` -------------------------------- ### Defining Triangle Set Extension Schema in XML Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md This XML Schema defines the `Triangle Set` extension for 3MF, introducing complex types like `CT_Mesh`, `CT_TriangleSets`, `CT_TriangleSet`, `CT_Ref`, and `CT_RefRange`, along with the `ST_ResourceIndex` simple type. It specifies how triangle sets can be referenced and organized within a 3D model, enabling efficient handling of large mesh data. ```XML ``` -------------------------------- ### Declaring Core 3MF Elements in XML Schema Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md This snippet declares fundamental elements like `triangle`, `components`, `component`, `metadata`, and `item` within an XML Schema, which are common building blocks for 3MF models. These elements define the basic structure for geometric data, object composition, and descriptive information. ```XML ``` -------------------------------- ### Defining the 3MF Core Specification Schema in XML Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md This XML Schema Definition (XSD) specifies the structure and elements for the core components of a 3MF document. It defines complex types for model structure, resources (like materials and objects), and build instructions, along with simple types for data validation such as units, colors, and matrix transformations. This schema is essential for validating 3MF files against the core specification. ```XML ``` -------------------------------- ### Adding a MustPreserve Relationship in 3MF XML Source: https://github.com/watzon/three-mf/blob/main/3MF Core Specification.md This XML snippet demonstrates how to define relationships within a 3MF package, specifically highlighting the inclusion of a MustPreserve relationship. This relationship type ensures that a consumer application saves the associated part (e.g., /Metadata/MustPreservePart.txt) even if it doesn't understand its content, preventing data loss during file modification. It also shows standard relationships for the 3D model and a thumbnail. ```XML ```