mirror of
https://github.com/bherbruck/solidcraft.git
synced 2026-11-06 20:02:16 +00:00
9559ad398a
* claim: #4783 * Physical material: one rule for a body's material and its density (#4783) inspect.measure, component.properties, occurrence.properties and the Properties window took a body's material name from the raw assignment, but its density from Document::density, which falls back to the default material when the assigned one is unknown or has an unusable density. So a damaged or hand-edited design read one material and weighed another: a design material "Broken" at -3 g/cm³ read "Broken" at 1.29 g/cm³. One rule, in one place: - DEFAULT_MATERIAL (new, beside DEFAULT_DENSITY in the material library) is the default material's name. The library's first row uses it. - Document::body_material (new, beside Document::density) is the material a body's mass is computed with, as the library or the design spells it: the assigned one when it is known and has a usable density, else DEFAULT_MATERIAL. Document::density is that material's density, with the same value as before for every input. inspect.measure and the physical properties name body_material. inspect.measure now names every body's material, measured or not, since naming it takes no measuring; the density stays with the mass, on the bodies measured. So the Properties window shows the engine's name without a fallback of its own. The places that keep the assignment as stored (configuration cells, material.assign, material.edit, material.delete and the dialogs) only use the constant, so a configuration still keeps a damaged assignment as it is. The visible change: a body whose material is unknown, or has an unusable density, reads "Default", the material it weighs, and a miscased name reads as the library or the design spells it. A body inspect.measure can't measure now has its material too. Masses and densities don't change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
//! Built-in physical materials: densities in g/cm³ and sRGB colours.
|
|
|
|
/// The default material's name: what a body without a usable material of its own is made of.
|
|
/// Assigning it clears a body's assignment.
|
|
pub const DEFAULT_MATERIAL: &str = "Default";
|
|
/// Density of the default material (g/cm³).
|
|
pub const DEFAULT_DENSITY: f64 = 1.29;
|
|
|
|
/// Physical materials: name and density (g/cm³).
|
|
pub const MATERIALS: [(&str, f64); 14] = [
|
|
(DEFAULT_MATERIAL, DEFAULT_DENSITY),
|
|
("Steel", 7.85),
|
|
("Stainless Steel", 8.0),
|
|
("Aluminum", 2.70),
|
|
("Brass", 8.50),
|
|
("Copper", 8.96),
|
|
("Titanium", 4.43),
|
|
("Cast Iron", 7.20),
|
|
("ABS Plastic", 1.06),
|
|
("PLA", 1.24),
|
|
("Nylon", 1.14),
|
|
("Polycarbonate", 1.20),
|
|
("Oak", 0.75),
|
|
("Glass", 2.50),
|
|
];
|
|
|
|
/// How a physical material looks (sRGB); the default material has no colour of its own.
|
|
pub fn material_color(name: &str) -> Option<[u8; 3]> {
|
|
Some(match name {
|
|
"Steel" => [158, 164, 172],
|
|
"Stainless Steel" => [186, 191, 198],
|
|
"Aluminum" => [204, 208, 214],
|
|
"Brass" => [208, 172, 88],
|
|
"Copper" => [204, 122, 80],
|
|
"Titanium" => [150, 148, 158],
|
|
"Cast Iron" => [104, 104, 110],
|
|
"ABS Plastic" => [222, 222, 216],
|
|
"PLA" => [110, 160, 222],
|
|
"Nylon" => [236, 230, 214],
|
|
"Polycarbonate" => [196, 216, 232],
|
|
"Oak" => [190, 146, 92],
|
|
"Glass" => [170, 208, 218],
|
|
_ => return None,
|
|
})
|
|
}
|