Files
benilla-octo/crates/benilla-formats/tests/m2_lights.rs
T
Sam SungandClaude Opus 5.5 8da634afa9 Comments in benilla-formats: one line of fact each, no history, no record numbers (#130)
Part of #41: the comments of `benilla-formats` (the library, its extract tools, examples and tests) are rewritten to the rule in `docs/METHOD.md`, which is what the code does and the reference fact behind it, in a line. 19,654 comment lines become 7,264.

Fixes #105: the WMO collision comments now name walking's box-query leaf `0x6bca50` and the camera and line-of-sight segment-query leaf `0x6bc700`, in `models/collision.rs`, `examples/wmo_bsp.rs` and `tests/chain.rs`.

- **The mechanical strip.** The citations that were only a private record number go first, and each edit is shown to be a pure removal.
- **Wrong facts corrected.** The rewrite corrects the comments that stated wrong facts. Among them:
  - A placed doodad's material alpha reads file slot 0 on its spawn clock, while the reference reads bone 0's armed sequence, re-rolled every play window. The old text said doodads are armed once at load.
  - The fog end is stored ×36 and scaled once at load (`0x6d6090`). It is not raw.
  - The MCSH bit picks a map doodad's sun scale, 1.0 lit or 0.5 shadowed. 2.5 belongs to an entity's light node.
  - `SpellRec` is the row as stored, column × 4, not a translated copy.
  - A global sequence's clock is anchored at the instance's attach time (`0x714352`).
  - Particle twinkle is a gated size multiplier (`0x7b2adc`).
  - The blob shadow sizes from the Stand box.
  - Data claims are checked against the install: the weapon-trail kits' parameters and alphas, the beam rows' noise, and the maps' `field_16`.
  - Dozens more turned up on the way: renamed or deleted items, docs sitting on the wrong item, stale counts and links.
- **Deviation labels.** "Deviation:" now marks only a choice with a reason. An unbuilt behaviour says so plainly.
- **Verification.** Every file strips to identical code, and `cargo fmt --check` is clean. Four second readers compared every file old against new, restored the facts the rewrite had dropped, and checked each new citation against the reference, the code and the shipped data.

String literals are untouched; they are #92.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-24 19:38:53 +07:00

84 lines
3.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! The M2 light block: `0xd4` bytes a record, the diffuse-colour track at `0x48`.
use benilla_formats::{parse_m2_lights, Chain};
#[test]
fn elwynn_campfire_has_one_warm_point_light() {
let data = benilla_formats::wow_data_or_skip!();
let reader = Chain::open(&data).expect("open vanilla patch chain");
let bytes = reader
.read("World\\Azeroth\\Elwynn\\PassiveDoodads\\Campfire\\ElwynnCampfire.m2")
.expect("read ElwynnCampfire.m2");
let lights = parse_m2_lights(&bytes);
assert_eq!(lights.len(), 1, "campfire has exactly one M2 light");
let l = lights[0];
assert!(
l.is_point(),
"campfire light is type 1 (point), got type {}",
l.light_type
);
let d = l.diffuse_color;
assert!(
(d[0] - 0.71).abs() < 0.03 && (d[1] - 0.20).abs() < 0.03 && d[2] < 0.05,
"campfire diffuse ≈ (0.71, 0.20, 0.00), got {d:?}"
);
}
/// The torch an NPC carries (`ItemDisplayInfo` 12236, item 1906 "Monster - Torch"): a point light
/// on bone 9 up the shaft, at intensity 3, whose visibility track's first key is nonzero: it casts.
#[test]
fn held_torch_casts_one_warm_point_light_up_the_shaft() {
let data = benilla_formats::wow_data_or_skip!();
let reader = Chain::open(&data).expect("open vanilla patch chain");
let bytes = reader
.read("Item\\ObjectComponents\\Weapon\\Club_1H_Torch_A_01.m2")
.expect("read Club_1H_Torch_A_01.m2");
let lights = parse_m2_lights(&bytes);
assert_eq!(lights.len(), 1, "the torch has exactly one M2 light");
let l = lights[0];
assert!(l.casts(), "point + visibility-on: the torch really glows");
assert_eq!(l.bone, 9, "the light hangs on the torch's own bone");
assert!(
(l.position[0] - 0.5765).abs() < 0.01 && l.position[1].abs() < 0.01,
"0.58 yd up the shaft (the head), got {:?}",
l.position
);
let d = l.diffuse_color.map(|c| c * l.diffuse_intensity);
assert!(
(d[0] - 1.40).abs() < 0.01 && (d[1] - 0.871).abs() < 0.01 && (d[2] - 0.40).abs() < 0.01,
"diffuse × intensity ≈ (1.40, 0.87, 0.40) — flame orange, over-driven, got {d:?}"
);
}
/// A point light whose visibility track is a static `0` key never casts (`0x716413`): 11 of the
/// corpus's 85, mostly spell impacts.
#[test]
fn a_static_zero_visibility_key_reads_as_dark() {
let data = benilla_formats::wow_data_or_skip!();
let reader = Chain::open(&data).expect("open vanilla patch chain");
let bytes = reader
.read("Spells\\FlameStrike_ImpactDD_Med_Base.m2")
.expect("read FlameStrike_ImpactDD_Med_Base.m2");
let dark: Vec<_> = parse_m2_lights(&bytes)
.into_iter()
.filter(|l| l.is_point())
.collect();
assert!(
!dark.is_empty(),
"the impact model does author point lights"
);
assert!(
dark.iter().all(|l| l.visibility_off && !l.casts()),
"every one is held dark by its visibility track"
);
}
#[test]
fn too_short_yields_no_lights() {
assert!(parse_m2_lights(&[0u8; 16]).is_empty());
}