| Crates.io | asset-importer-rs-obj |
| lib.rs | asset-importer-rs-obj |
| version | 0.3.0 |
| created_at | 2025-07-28 23:53:01.926652+00 |
| updated_at | 2025-07-28 23:53:01.926652+00 |
| description | OBJ importer for asset-importer-rs |
| homepage | |
| repository | https://github.com/crazyjackel/asset-importer-rs |
| max_upload_size | |
| id | 1771730 |
| size | 427,103 |

asset-importer-rs-obj provides Wavefront OBJ file import functionality for the asset-importer-rs project. This implementation supports the OBJ format with material library (MTL) handling, making it a complete solution for importing OBJ assets into the asset-importer-rs ecosystem.
This crate provides the essential functionality for:



Add the following to your Cargo.toml:
[dependencies]
asset-importer-rs-obj = "0.3.0"
# Or for development from source:
asset-importer-rs-obj = { path = "../path/to/asset-importer-rs-obj" }

Basic OBJ import example:
use asset_importer_rs_obj::{
ObjImporter,
ObjImportError,
};
use std::path::Path;
// Create an importer
let importer = ObjImporter::new();
// Import an OBJ file
let scene = importer.import_file(Path::new("model.obj"))?;
// Access scene data
println!("Scene has {} meshes", scene.meshes.len());
println!("Scene has {} materials", scene.materials.len());
// Access mesh data
for mesh in &scene.meshes {
println!("Mesh has {} vertices", mesh.vertices.len());
println!("Mesh has {} faces", mesh.faces.len());
}
Importing with material support:
use asset_importer_rs_obj::ObjImporter;
// Create an importer
let importer = ObjImporter::new();
// Import OBJ with MTL file
let scene = importer.import_file("model_with_materials.obj")?;
// Access material data
for material in &scene.materials {
println!("Material: {:?}", material.name);
// Access material properties like diffuse, specular, etc.
}
Error handling example:
use asset_importer_rs_obj::{ObjImporter, ObjImportError};
let importer = ObjImporter::new();
match importer.import_file("model.obj") {
Ok(scene) => {
println!("Successfully imported OBJ file");
// Process scene data
}
Err(ObjImportError::FileNotFound) => {
eprintln!("OBJ file not found");
}
Err(ObjImportError::ParseError(msg)) => {
eprintln!("Parse error: {}", msg);
}
Err(e) => {
eprintln!("Other error: {:?}", e);
}
}

The OBJ crate provides a complete implementation of the Wavefront OBJ format with a focus on efficient parsing and material handling. The importer handles file parsing, geometry processing, material loading, and scene construction, integrating seamlessly with the asset-importer-rs ecosystem.
The crate uses the tObj library for initial parsing but provides optimized handling for the asset-importer-rs pipeline, ensuring efficient memory usage and proper integration with the broader 3D asset ecosystem.


Why tObj over obj-rs? tObj provides better separation of models and materials for easy parsing, whereas obj-rs keeps them together. This separation aligns better with the asset-importer-rs architecture.
Future Improvements: While tObj serves as a good foundation, there are several optimizations that could be implemented with a custom parser:
In general, writing a custom parser would be more efficient for our use case, but getting things to work comes first. The current implementation provides a solid foundation for OBJ import functionality.

This project is part of the asset-importer-rs workspace and follows its licensing terms. See the main project LICENSE file for details.
Copyright (c) 2024 Jackson Levitt