Skip to content

feat(ldraw): add Fabric material variant#66

Open
bkfunk wants to merge 2 commits into
segfault87:mainfrom
bkfunk:feat/fabric-material
Open

feat(ldraw): add Fabric material variant#66
bkfunk wants to merge 2 commits into
segfault87:mainfrom
bkfunk:feat/fabric-material

Conversation

@bkfunk
Copy link
Copy Markdown

@bkfunk bkfunk commented May 13, 2026

Summary

Adds Material::Fabric and parses the FABRIC material keyword in LDConfig.ldr. LDraw's color spec supports a FABRIC material (used for capes, flags, and other soft-goods items); without this variant, color definitions that declare FABRIC fall back to default-material handling and lose their material classification.

Change

  • ldraw/src/color.rs: add Fabric variant to Material
  • ldraw/src/parser.rs: recognize the FABRIC keyword in parse_color_definitions and assign Material::Fabric

Test plan

  • cargo check -p ldraw passes
  • Manual: parse an LDConfig.ldr that contains a FABRIC-material color and confirm the resulting Material::Fabric

Copilot AI review requested due to automatic review settings May 13, 2026 16:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class support for LDraw’s FABRIC color material by introducing a new Material::Fabric variant and recognizing the FABRIC keyword during LDConfig.ldr color-definition parsing.

Changes:

  • Added Fabric to the Material enum.
  • Updated parse_color_definitions to map the FABRIC keyword to Material::Fabric.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
ldraw/src/color.rs Extends the public Material enum with a Fabric variant to represent the LDraw FABRIC material.
ldraw/src/parser.rs Recognizes FABRIC in !COLOUR definitions and assigns Material::Fabric during parsing.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ldraw/src/parser.rs
Comment on lines +726 to 731
"FABRIC" => {
material = Material::Fabric;
}
"MATERIAL" => {
material = Material::Custom(parse_customized_material(&mut it)?);
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call — addressed in 637e821. Added a Fabric (code 10) row to COLOR_DEFINITIONS and a matching expected Color with material: Material::Fabric. Note: the top-level FABRIC keyword handled in parse_color_definitions is a separate code path from the MATERIAL FABRIC CANVAS handling in parse_customized_material (introduced by the rust-2024 commit), so this test guards only the new branch.

Comment thread ldraw/src/color.rs
Comment on lines 105 to 114
pub enum Material {
Plastic,
Chrome,
Pearlescent,
Rubber,
MatteMetallic,
Metal,
Fabric,
Custom(CustomizedMaterial),
}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point — addressed in 637e821 by marking Material as #[non_exhaustive]. The enum has been accumulating variants (Glow, Metal, MatteMetallic, now Fabric) and will likely keep doing so as more LDraw materials get covered; #[non_exhaustive] lets future additions avoid the same downstream breakage this PR causes today.

Two follow-ups from review on segfault87#66:

- Mark `Material` as `#[non_exhaustive]`. The enum has accumulated
  variants over time (Glow, Metal, MatteMetallic, now Fabric); flagging
  it `non_exhaustive` lets future additions avoid the same downstream
  breakage this PR causes for exhaustive `match`-ers.

- Extend `test_parse_color_definition` with a FABRIC color (code 10) so
  the new top-level `FABRIC` parse branch in `parse_color_definitions`
  is exercised. (The existing `parse_customized_material` FABRIC arm,
  introduced by the rust-2024 commit, handles `MATERIAL FABRIC CANVAS`
  and is on a separate code path.)

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants