Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ldraw/src/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ pub enum CustomizedMaterial {
}

#[derive(Clone, Debug, PartialEq)]
#[non_exhaustive]
pub enum Material {
Plastic,
Chrome,
Pearlescent,
Rubber,
MatteMetallic,
Metal,
Fabric,
Custom(CustomizedMaterial),
}

Expand Down
14 changes: 13 additions & 1 deletion ldraw/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,9 @@ pub async fn parse_color_definitions<T: AsyncBufRead + Unpin>(
"MATTE_METALLIC" => {
material = Material::MatteMetallic;
}
"FABRIC" => {
material = Material::Fabric;
}
"MATERIAL" => {
material = Material::Custom(parse_customized_material(&mut it)?);
}
Comment thread
bkfunk marked this conversation as resolved.
Expand Down Expand Up @@ -1045,7 +1048,8 @@ mod tests {
0 !COLOUR Glitter CODE 6 VALUE #FFFF00 EDGE #00FFFF MATERIAL GLITTER VALUE #FF00FF FRACTION 0.17 VFRACTION 0.2 SIZE 1
0 !COLOUR Glitter_Transparent CODE 7 VALUE #00FFFF EDGE #FFFF00 ALPHA 128 MATERIAL GLITTER VALUE #FF00FF FRACTION 0.17 VFRACTION 0.2 SIZE 1
0 !COLOUR Speckle CODE 8 VALUE #123456 EDGE #654321 MATERIAL SPECKLE VALUE #898788 FRACTION 0.4 MINSIZE 1 MAXSIZE 3
0 !COLOUR Rubber CODE 9 VALUE #ABCDEF EDGE #FEDCBA RUBBER";
0 !COLOUR Rubber CODE 9 VALUE #ABCDEF EDGE #FEDCBA RUBBER
0 !COLOUR Fabric CODE 10 VALUE #112233 EDGE #445566 FABRIC";

#[tokio::test]
async fn test_parse_color_definition() {
Expand Down Expand Up @@ -1156,6 +1160,14 @@ mod tests {
luminance: 0,
material: Material::Rubber,
},
Color {
code: 10,
name: "Fabric".into(),
color: Rgba::new(0x11, 0x22, 0x33, 255),
edge: Rgba::new(0x44, 0x55, 0x66, 255),
luminance: 0,
material: Material::Fabric,
},
];
for material in colors {
assert_eq!(parsed[&material.code], material);
Expand Down