Expand description
§weldr
weldr is a Rust library to manipulate LDraw files (format specification), which are files describing 3D models of LEGO®* pieces.
weldr allows building command-line tools and applications leveraging the fantastic database of pieces contributed by the LDraw community.
§Example
Parse a single LDraw file containing 2 commands:
- A comment : “this is a comment”
- A segment command to draw a segment between 2 vertices
extern crate weldr;
use weldr::{parse_raw, Command, CommentCmd, LineCmd, Vec3};
fn main() {}
#[test]
fn parse_ldr() {
let ldr = b"0 this is a comment\n2 16 0 0 0 1 1 1";
let cmds = parse_raw(ldr);
let cmd0 = Command::Comment(CommentCmd::new("this is a comment"));
let cmd1 = Command::Line(LineCmd{
color: 16,
vertices: [
Vec3{ x: 0.0, y: 0.0, z: 0.0 },
Vec3{ x: 1.0, y: 1.0, z: 1.0 }
]
});
assert_eq!(cmds, vec![cmd0, cmd1]);
}
A slightly more involved but more powerful approach is to load and resolve a file and all its
sub-file references recursively using the parse()
function. This requires implementing the
FileRefResolver
trait to load file content by reference filename.
The code is available on GitHub.
§Technical features
weldr leverages the nom parser combinator library to efficiently
and reliably parse LDraw files, and transform them into in-memory data structures for consumption.
All parsing is done on &[u8]
input expected to contain specification-compliant
LDraw content. In particular, this means:
- UTF-8 encoded input
- Both DOS/Windows
<CR><LF>
and Unix<LF>
line termination accepted
§Copyrights
The current code repository is licensed under the MIT license.
LDraw™ is a trademark owned and licensed by the Estate of James Jessiman, which does not sponsor, endorse, or authorize this project.
*LEGO® is a registered trademark of the LEGO Group, which does not sponsor, endorse, or authorize this project.
Re-exports§
pub use error::Error;
pub use error::ParseError;
pub use error::ResolveError;
Modules§
- error
- Error management
Structs§
- Category
Cmd - Line Type 0 META command: !CATEGORY language extension.
- Color
- RGB color in sRGB color space.
- Colour
Cmd - Line Type 0 META command: !COLOUR language extension.
- Command
Iterator - Iterator over all drawing commands of a
SourceFile
and all its referenced sub-files. - Comment
Cmd - Line Type 0 comment.
- Draw
Context - Drawing context used when iterating over all drawing commands of a file via
SourceFile::iter()
. - Glitter
Material - Glitter material definition of a color definition (!COLOUR language extension).
- Keywords
Cmd - Line Type 0 META command: !KEYWORDS language extension.
- LineCmd
- Line Type 2 LDraw command: Draw a segment between 2 vertices.
- Local
Command Iterator - Iterator over all local commands of a
SourceFile
. - OptLine
Cmd - Line Type 5 LDraw command: Draw an optional segment between two vertices, aided by 2 control points.
- QuadCmd
- Line Type 4 LDraw command: Draw a quad between 4 vertices.
- Source
File - Single LDraw source file loaded and optionally parsed.
- Source
File Ref - Reference to a single
SourceFile
instance in a givenSourceMap
. - Source
Map - Collection of
SourceFile
accessible from their reference filename. - Speckle
Material - Speckle material definition of a color definition (!COLOUR language extension).
- SubFile
RefCmd - Line Type 1 LDraw command: Reference a sub-file from the current file.
- Triangle
Cmd - Line Type 3 LDraw command: Draw a triangle between 3 vertices.
Enums§
- Color
Finish - Finish for color definitions (!COLOUR language extension).
- Command
- Types of commands contained in a LDraw file.
- Grain
Size - Grain size variants for the optional MATERIAL part of color definition (!COLOUR language extension).
- Material
Finish - Finish for optional MATERIAL part of color definition (!COLOUR language extension).
- SubFile
Ref - Reference to a sub-file from inside another file.
Traits§
- File
RefResolver - Resolver trait for sub-file references (Line Type 1 LDraw command).
Functions§
- parse
- Parse a single file and its sub-file references recursively.
- parse_
raw - Parse raw LDR content without sub-file resolution.