| Crates.io | l3d_rs |
| lib.rs | l3d_rs |
| version | 0.2.3 |
| created_at | 2024-10-09 16:24:33.39585+00 |
| updated_at | 2025-12-16 14:26:21.08583+00 |
| description | L3D (Luminaire 3D) file parser for Rust - parse 3D luminaire geometry with transformation matrices, designed for WASM/WebGL rendering |
| homepage | https://github.com/holg/l3d-rs |
| repository | https://github.com/holg/l3d-rs |
| max_upload_size | |
| id | 1402558 |
| size | 54,182 |
A Rust library for parsing L3D (Luminaire 3D) files, the 3D geometry format used in the lighting industry alongside GLDF (Global Lighting Data Format).
L3D is a ZIP-based file format containing:
structure.xml - XML file describing the luminaire geometry hierarchyThe format supports hierarchical assemblies with joints, allowing for adjustable luminaire components (e.g., rotatable lamp heads).
structure.xml into strongly-typed Rust structs[f32; 16])Add to your Cargo.toml:
[dependencies]
l3d_rs = "0.2"
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", part.path);
}
// Access raw assets for 3D rendering
for asset in &l3d.file.assets {
println!("Asset: {} ({} bytes)", asset.name, asset.size);
}
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();
println!("{}", json);
use l3d_rs::Luminaire;
// Load L3D file
let luminaire = Luminaire::load_l3d("luminaire.l3d").unwrap();
// Convert to JSON
let json = luminaire.to_json().unwrap();
// Parse back from JSON
let restored = Luminaire::from_json(&json).unwrap();
The Mat4 type is a [f32; 16] array in column-major order, compatible with OpenGL, WebGL, and most 3D libraries.
use three_d::Mat4 as ThreeDMat4;
use l3d_rs::{from_buffer, L3dPart};
let l3d = from_buffer(&bytes);
for part in &l3d.model.parts {
// Convert l3d_rs matrix to three-d matrix
let transform = ThreeDMat4::from_cols_array(&part.mat);
// Load the OBJ file from assets
let obj_data = l3d.file.assets.iter()
.find(|a| a.name == part.path)
.map(|a| &a.content);
// Apply transform to model...
}
use three_d_asset::io::RawAssets;
use l3d_rs::L3d;
fn load_assets(l3d: &L3d) -> RawAssets {
let mut raw = RawAssets::new();
for asset in &l3d.file.assets {
raw.insert(&asset.name, asset.content.clone());
}
raw
}
| Type | Description |
|---|---|
L3d |
Complete parsed L3D data (file + model) |
L3dFile |
Raw file contents (structure.xml + assets) |
L3dModel |
Collection of geometry parts with transforms |
L3dPart |
Single geometry part with transformation matrix |
Luminaire |
Parsed XML structure (for serialization) |
Mat4 |
4x4 transformation matrix ([f32; 16]) |
BufFile |
Asset file from ZIP archive |
| Function | Description |
|---|---|
from_buffer(&[u8]) |
Parse L3D from bytes (main entry point) |
Luminaire::load_l3d(path) |
Load L3D from file path |
Luminaire::from_json(str) |
Parse from JSON string |
Luminaire::to_json() |
Serialize to JSON string |
mat4_mul(a, b) |
Multiply two matrices |
mat4_translation(x, y, z) |
Create translation matrix |
mat4_rotate_x/y/z(deg) |
Create rotation matrix |
The Mat4 type uses column-major order (OpenGL convention):
[ m0 m4 m8 m12 ] [ Xx Yx Zx Tx ]
[ m1 m5 m9 m13 ] = [ Xy Yy Zy Ty ]
[ m2 m6 m10 m14 ] [ Xz Yz Zz Tz ]
[ m3 m7 m11 m15 ] [ 0 0 0 1 ]
This project is licensed under the GPL-3.0-or-later license. See the LICENSE file for details.