Module obj

Module obj 

Source
Expand description

Wavefront OBJ format import and export.

This module provides conversion between OBJ files and 3MF Model structures.

§OBJ Format

The Wavefront OBJ format is a text-based 3D geometry format. This implementation supports:

Supported features:

  • v - Vertex positions (x, y, z)
  • f - Faces (vertex indices, with automatic fan triangulation for polygons)
  • g / o - Group/object directives (each creates a separate 3MF Object)
  • usemtl - Material assignment (maps to per-triangle pid/p1/p2/p3)
  • mtllib - Material library file reference (parsed via mtl module)

Ignored features:

  • vt - Texture coordinates
  • vn - Vertex normals

§Material Import

When using ObjImporter::read_from_path, the importer resolves mtllib directives relative to the OBJ file’s directory. MTL Kd (diffuse color) maps to 3MF BaseMaterial display colors. Materials are collected into a single BaseMaterialsGroup resource.

When using ObjImporter::read, no MTL resolution is possible and materials are not imported (geometry-only mode for backward compatibility).

§Examples

§Importing OBJ with materials

use lib3mf_converters::obj::ObjImporter;
use std::path::Path;

let model = ObjImporter::read_from_path(Path::new("model.obj"))?;
println!("Imported model with {} build items", model.build.items.len());

§Importing OBJ (geometry only)

use lib3mf_converters::obj::ObjImporter;
use std::fs::File;

let file = File::open("model.obj")?;
let model = ObjImporter::read(file)?;
println!("Imported model with {} build items", model.build.items.len());

§Exporting OBJ

use lib3mf_converters::obj::ObjExporter;
use lib3mf_core::model::Model;
use std::fs::File;

let file = File::create("output.obj")?;
ObjExporter::write(&model, file)?;

Structs§

ObjExporter
Exports 3MF Model structures to Wavefront OBJ files.
ObjImporter
Imports Wavefront OBJ files into 3MF Model structures.