Files
gromandClaude Opus 5 e6e8cfdca1 weather: rain lands on what is DRAWN, not on the city's invisible lids
grom, 2026-11-09: *"in lots of the city rain doesn't fall all the way to the
ground, almost like it hits an invisible roof"*. There is one, it is literal,
and this is it.

**The defect, measured.** Two capture shots of one fixed pose three clock steps
apart isolate the rain exactly -- the scene cancels, only drops move. Over a
Stormwind street, by sixths of the frame from sky to foreground:

    2.46%  1.18%  0.08%  0.000%  0.000%  0.000%

Nothing below the horizon. No streaks, no splashes. The ground oracle said why:
75% of its cells reported ground at or OVER the eye, median +11.5 yd, the
camera's own cell among them, and the ray stopped on a collider whose layer was
`Walk` and whose box is a kilometre square -- Stormwind's own walking trimesh --
while the terrain leg reported real ground 43.5 yd BELOW. Looking straight up
from that stand draws open sky. The face is not rendered.

**Why there is such a face.** `examples/wmo_faces` (added here) reads the MOPY
census off the model: `stormwind.wmo` carries **63,583 faces flagged `COLLISION`
with no `RENDER`, 16,000 of them horizontal** -- invisible walls, and the lids
over its streets. A body must stop on those. A raindrop must not, and the
reference says so in its own structure: its BSP ray walk rejects `0x08` where its
walking box query keeps it, which this tree had already written down for the
footprint ray (`FOOTPRINT_REJECT`).

**The fix.** A WMO's camera/line-of-sight faces split at load into the half that
is drawn and the collision-only sheets, no triangle duplicated, each spawned on
its own layer. `camera_filter` takes both, so the camera is what it was. A new
`weather_filter` takes the drawn half plus the default layer, and both weather
oracles use it: the drop's ground probe and the wetness grid, which was being
shaded dry by the same lids.

**The CAMERA set, and the first attempt proves why it matters.** I split the
walking set first. It was wrong: a vanilla WMO draws its world with `DETAIL`
faces (`DETAIL|RENDER` is Stormwind's largest class at 327,700) and the walking
gather drops `DETAIL`, so the floor you stand on is in that set only as its
collision sheet. Stripping the sheets took the street with them and the oracle
moved to -43.5 -- the canal floor under the city, with the rain falling through
the pavement. The camera gather keeps `DETAIL`, so its drawn half is the surface
the eye actually sees.

**After**, same pose, same bands:

    3.05%  2.44%  2.47%  1.04%  0.26%  0.16%

and the oracle now stops at -1.4 yd on the drawn camera layer: the street. Rain
reaches the ground, splash rings land on the pavement, and the pavement is wet.

Gates: `benilla-world --lib` is 686 passed / 6 failed, byte for byte what clean
HEAD gives (checked by stashing); `benilla-formats`'s `blob_shadow_box` red is
pre-existing the same way. fmt and clippy clean on the three crates.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SgstFWtn1RxEJ5kVrpgYwn
2026-11-09 17:44:01 -07:00

154 lines
5.7 KiB
Rust

//! `cargo run -p benilla-formats --example wmo_faces -- [wmo path]` — a WMO's MOPY face census:
//! how many faces carry each flag combination, how many of those are horizontal, and the heights
//! the horizontal ones cluster at.
//!
//! Written to answer one question (2026-11-09). Rain over a Stormwind street dies 11.5 yd above
//! the eye on the city's **walking** collider while open sky is drawn overhead, so the face it
//! dies on collides and is not rendered. MOPY `0x08` is the reference's own name for exactly that
//! — `models/wmo/group.rs`'s `FOOTPRINT_REJECT` records that the reference's BSP ray walk
//! (`0x6b92b0`/`0x6bc370`) rejects it, "so of a floor's coplanar render and collision sheets only
//! the render one is sampled" — and this turns the guess into a reading.
//!
//! Reads the three chunks it needs out of the group files itself (MOPY, MOVI, MOVT) rather than
//! widening the crate's API for a diagnostic.
#![allow(clippy::cast_possible_truncation)]
use std::collections::BTreeMap;
use anyhow::Result;
/// A WMO chunk's payload, by its on-disk reversed magic.
fn chunk<'a>(bytes: &'a [u8], magic: &[u8; 4]) -> Option<&'a [u8]> {
let mut at = 0usize;
while at + 8 <= bytes.len() {
let id = &bytes[at..at + 4];
let size = u32::from_le_bytes([bytes[at + 4], bytes[at + 5], bytes[at + 6], bytes[at + 7]])
as usize;
let body = at + 8;
if body + size > bytes.len() {
return None;
}
if id == magic {
return Some(&bytes[body..body + size]);
}
// MOGP wraps the group's own chunks: step INTO it, past its 68-byte header.
at = if id == b"PGOM" {
body + 68
} else {
body + size
};
}
None
}
/// MOPY bits, by the names `models/collision.rs` and `models/wmo/group.rs` use for them.
fn flag_names(f: u8) -> String {
const BITS: [(u8, &str); 8] = [
(0x01, "UNK01"),
(0x02, "NOCAMCOLLIDE"),
(0x04, "DETAIL"),
(0x08, "COLLISION"),
(0x10, "HINT"),
(0x20, "RENDER"),
(0x40, "UNK40"),
(0x80, "COLLIDE_HIT"),
];
let set: Vec<&str> = BITS
.iter()
.filter(|(b, _)| f & b != 0)
.map(|(_, n)| *n)
.collect();
if set.is_empty() {
"none".into()
} else {
set.join("|")
}
}
fn main() -> Result<()> {
let data = benilla_formats::wow_data().expect("set WOW_DATA");
let mut chain = benilla_formats::Chain::open(&data)?;
let raw: String = std::env::args()
.nth(1)
.unwrap_or_else(|| "world\\wmo\\azeroth\\buildings\\stormwind\\stormwind.wmo".into());
let root_path = raw.to_ascii_lowercase();
let stem = root_path.strip_suffix(".wmo").unwrap_or(&root_path);
// flags -> (faces, horizontal faces, 1-yd bins of the horizontal ones by model z)
let mut by_flags: BTreeMap<u8, (usize, usize, BTreeMap<i32, usize>)> = BTreeMap::new();
let mut groups = 0usize;
for gi in 0..512u32 {
let group_path = format!("{stem}_{gi:03}.wmo");
let Ok(gbytes) = chain.read_file(&group_path) else {
continue;
};
groups += 1;
let (Some(mopy), Some(movi), Some(movt)) = (
chunk(&gbytes, b"YPOM"),
chunk(&gbytes, b"IVOM"),
chunk(&gbytes, b"TVOM"),
) else {
continue;
};
let verts: Vec<[f32; 3]> = movt
.as_chunks::<12>()
.0
.iter()
.map(|c| {
let f = |i: usize| f32::from_le_bytes([c[i], c[i + 1], c[i + 2], c[i + 3]]);
[f(0), f(4), f(8)]
})
.collect();
let idx: Vec<usize> = movi
.as_chunks::<2>()
.0
.iter()
.map(|c| usize::from(u16::from_le_bytes([c[0], c[1]])))
.collect();
for (ti, tri) in idx.as_chunks::<3>().0.iter().enumerate() {
let Some(m) = mopy.as_chunks::<2>().0.get(ti) else {
continue;
};
let flags = m[0];
let Some(v): Option<Vec<[f32; 3]>> =
tri.iter().map(|&i| verts.get(i).copied()).collect()
else {
continue;
};
let e1 = [v[1][0] - v[0][0], v[1][1] - v[0][1], v[1][2] - v[0][2]];
let e2 = [v[2][0] - v[0][0], v[2][1] - v[0][1], v[2][2] - v[0][2]];
// WMO model space is Z-up, like the ADT's.
let n = [
e1[1] * e2[2] - e1[2] * e2[1],
e1[2] * e2[0] - e1[0] * e2[2],
e1[0] * e2[1] - e1[1] * e2[0],
];
let len = (n[0] * n[0] + n[1] * n[1] + n[2] * n[2]).sqrt();
let entry = by_flags.entry(flags).or_default();
entry.0 += 1;
if len > 1e-6 && (n[2] / len).abs() > 0.95 {
entry.1 += 1;
let z = (v[0][2] + v[1][2] + v[2][2]) / 3.0;
let band = z.floor() as i32;
*entry.2.entry(band).or_default() += 1;
}
}
}
println!("{root_path}: {groups} group files read");
println!("\n MOPY name faces horizontal tallest flat bands (model z: faces)");
for (flags, (n, h, bins)) in &by_flags {
let mut top: Vec<(i32, usize)> = bins.iter().map(|(z, c)| (*z, *c)).collect();
top.sort_by_key(|&(_, c)| std::cmp::Reverse(c));
let bands = top
.iter()
.take(4)
.map(|(z, c)| format!("{z}: {c}"))
.collect::<Vec<_>>()
.join(", ");
println!(
" 0x{flags:02x} {:<24} {n:>7} {h:>12} {bands}",
flag_names(*flags)
);
}
Ok(())
}