Expand description
§l3d_rs - L3D (Luminaire 3D) File Parser for Rust
A Rust library for parsing and working with L3D files, the 3D geometry format used in the lighting industry alongside GLDF (Global Lighting Data Format).
§What is L3D?
L3D (Luminaire 3D) is a ZIP-based file format that contains:
structure.xml- XML file describing the luminaire geometry hierarchy- OBJ files - 3D geometry files for each part of the luminaire
- Optional texture and material files
The format supports hierarchical assemblies with joints, allowing for adjustable luminaire components (e.g., rotatable lamp heads).
§Features
- XML Parsing: Parse
structure.xmlinto strongly-typed Rust structs - JSON Serialization: Convert between L3D XML and JSON formats
- 3D Model Building: Build transformation matrices for rendering
- No 3D Engine Dependency: Matrix operations are self-contained
- WASM Compatible: Designed for use in WebAssembly targets
§Quick Start
§Parse an L3D file from bytes (recommended for WASM)
use l3d_rs::{from_buffer, L3d};
// Load L3D file as bytes (e.g., from file upload or fetch)
let l3d_bytes = std::fs::read("luminaire.l3d").unwrap();
// Parse the L3D file
let l3d: L3d = from_buffer(&l3d_bytes);
// Access the parsed model
println!("Parts: {}", l3d.model.parts.len());
for part in &l3d.model.parts {
println!(" {} with transform matrix", part.path);
}
// Access raw assets for 3D rendering
for asset in &l3d.file.assets {
println!("Asset: {} ({} bytes)", asset.name, asset.size);
}§Load from file path (native only)
use l3d_rs::Luminaire;
// Load and parse the luminaire structure
let luminaire = Luminaire::load_l3d("luminaire.l3d").unwrap();
// Convert to JSON for web transmission
let json = luminaire.to_json().unwrap();§Integration with 3D Renderers
The Mat4 type is a [f32; 16] array in column-major order, compatible
with OpenGL, WebGL, and most 3D libraries. To use with three-d:
ⓘ
use three_d::Mat4 as ThreeDMat4;
use l3d_rs::L3dPart;
fn convert_matrix(part: &L3dPart) -> ThreeDMat4 {
ThreeDMat4::from_cols_array(&part.mat)
}§Module Structure
l3d- Core types for L3D structure (Luminaire, Geometry, etc.)from_buffer- Main entry point for parsing L3D files- Matrix utilities -
mat4_mul,mat4_translation,mat4_scale, etc.
Re-exports§
pub use l3d::build_transform;pub use l3d::get_scale;pub use l3d::mat4_mul;pub use l3d::mat4_rotate_x;pub use l3d::mat4_rotate_y;pub use l3d::mat4_rotate_z;pub use l3d::mat4_scale;pub use l3d::mat4_translation;pub use l3d::BufFile;pub use l3d::Circle;pub use l3d::Geometries;pub use l3d::Geometry;pub use l3d::GeometryDefinitions;pub use l3d::GeometryFileDefinition;pub use l3d::Header;pub use l3d::Joint;pub use l3d::Joints;pub use l3d::L3d;pub use l3d::L3dFile;pub use l3d::L3dModel;pub use l3d::L3dPart;pub use l3d::LightEmittingObject;pub use l3d::LightEmittingObjects;pub use l3d::Luminaire;pub use l3d::Mat4;pub use l3d::Rectangle;pub use l3d::Structure;pub use l3d::Vec3f;pub use l3d::MAT4_IDENTITY;
Modules§
- l3d
- L3D Core Types
Traits§
- Async
Logger - Trait for asynchronous logging (useful for WASM environments)
- Logger
- Trait for synchronous logging (useful for debugging in native environments)
Functions§
- from_
buffer - Parse an L3D file from a byte buffer
- normalize_
whitespace - Normalize XML by removing or collapsing excess whitespace and trimming newlines
- remove_
xml_ declaration - Remove the XML declaration