Buildings textured by material (stone, iron, wood, cloth); the heart in crystal facets
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d951c16902
commit
d87f862199
10 files changed
+119
-64
No files matched your search
+42
-2
@@ -49,17 +49,57 @@ pub enum Mat {
|
||||
Fur,
|
||||
Book,
|
||||
Paper,
|
||||
Crystal,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
// the material textures of the current graphics style (set every frame, see set_materials)
|
||||
static MATS: std::cell::RefCell<Option<[Texture2D; 8]>> = std::cell::RefCell::new(None);
|
||||
static MATS: std::cell::RefCell<Option<[Texture2D; 9]>> = std::cell::RefCell::new(None);
|
||||
}
|
||||
|
||||
pub fn set_materials(m: &[Texture2D; 8]) {
|
||||
pub fn set_materials(m: &[Texture2D; 9]) {
|
||||
MATS.with(|t| *t.borrow_mut() = Some(m.clone()));
|
||||
}
|
||||
|
||||
// the texture of a material in the current style
|
||||
pub fn material(m: Mat) -> Option<Texture2D> {
|
||||
MATS.with(|t| t.borrow().as_ref().map(|a| a[m as usize].clone()))
|
||||
}
|
||||
|
||||
// the material of a box of the buildings (render3d: towers, the soul core's throne, gates,
|
||||
// portals, traps) by its colour and shape: dark and grey blocks are stone (thin ones iron),
|
||||
// brown is wood, gold and brass are metal, strong colours are cloth; translucent and bright
|
||||
// glowing parts stay plain
|
||||
fn auto_mat(s: Vec3, c: Color) -> Option<Mat> {
|
||||
if c.a < 0.99 {
|
||||
return None;
|
||||
}
|
||||
let (mx, mn) = (c.r.max(c.g).max(c.b), c.r.min(c.g).min(c.b));
|
||||
let sat = if mx > 0.0 { (mx - mn) / mx } else { 0.0 };
|
||||
let thin = s.x.min(s.y).min(s.z) < 0.07;
|
||||
if mx > 0.85 && sat > 0.45 {
|
||||
return None;
|
||||
}
|
||||
if mx < 0.22 || sat < 0.2 {
|
||||
return Some(if thin { Mat::Iron } else { Mat::Stone });
|
||||
}
|
||||
if c.r > 0.6 && c.g > 0.45 && c.b < c.g * 0.6 {
|
||||
return Some(Mat::Iron);
|
||||
}
|
||||
if c.r >= c.g && c.g >= c.b && mx < 0.8 {
|
||||
return Some(Mat::Wood);
|
||||
}
|
||||
Some(Mat::Cloth)
|
||||
}
|
||||
|
||||
// a box of a building, textured by its material (see auto_mat)
|
||||
pub fn auto_cube(p: Vec3, s: Vec3, c: Color) {
|
||||
match auto_mat(s, c) {
|
||||
Some(m) => mc(m, p, s, c),
|
||||
None => draw_cube(p, s, None, c),
|
||||
}
|
||||
}
|
||||
|
||||
// a box of a material; the detail is a little darker than white, the colour makes up for it
|
||||
fn mc(m: Mat, p: Vec3, s: Vec3, c: Color) {
|
||||
let k = GROW.with(|g| g.get()).map_or(1.0, |g| g.1);
|
||||
|
||||
Reference in new issue
Block a user