diff --git a/dCommon/NifFile.cpp b/dCommon/NifFile.cpp index 017f27ed9..b56241591 100644 --- a/dCommon/NifFile.cpp +++ b/dCommon/NifFile.cpp @@ -337,12 +337,9 @@ namespace { av.name = ReadNet(reader).name; av.flags = reader.U16(); for (auto& value : av.transform.t) value = reader.Float(); - // Matrix33 is stored m11, m21, m31, m12, ... (nif.xml): column by column - std::array stored{}; - for (auto& value : stored) value = reader.Float(); - for (int row = 0; row < 3; row++) { - for (int col = 0; col < 3; col++) av.transform.r[row * 3 + col] = stored[col * 3 + row]; - } + // The rotation is stored row by row, the way Gamebryo keeps it in memory (the client reads the nine floats + // in order), for column vectors: p' = R p + for (auto& value : av.transform.r) value = reader.Float(); av.transform.s = reader.Float(); const auto count = reader.U32(); av.properties = reader.Array(count); diff --git a/dDashboardServer/routes/Scenery.cpp b/dDashboardServer/routes/Scenery.cpp index 7f47833d3..ae9d19a99 100644 --- a/dDashboardServer/routes/Scenery.cpp +++ b/dDashboardServer/routes/Scenery.cpp @@ -279,9 +279,9 @@ namespace { * isn't drawn with newer code. 2: meshes carry their multishader tag; conversions without it drew glom parts with * the LEGO shader. 3: dark textures and the UV set each texture names. 4: the game's shaders draw the models * (manifest "techniques"), vertex colors go to them as stored. 5: an animated material alpha is its highest key. 6: flair tints are bytes over - * 255 (they were over 63). + * 255 (they were over 63). 7: node rotations are read row by row, so models with turned nodes are converted again. */ - constexpr uint32_t FORMAT_VERSION = 6; + constexpr uint32_t FORMAT_VERSION = 7; // A zone's lighting (WorldScene::Lighting) for the viewers' shaders nlohmann::json LightingJson(const WorldScene::Lighting& lighting) { diff --git a/dDashboardServer/static/js/scenery-core.js b/dDashboardServer/static/js/scenery-core.js index 34f40c0c5..f8022806b 100644 --- a/dDashboardServer/static/js/scenery-core.js +++ b/dDashboardServer/static/js/scenery-core.js @@ -183,7 +183,7 @@ export const TECHNIQUE = { * The conversion format (Scenery.cpp FORMAT_VERSION) these views are written for. Manifest URLs carry it, so a * browser never draws with a manifest it kept from an older server (they are cached for up to a day). */ -export const SCENERY_FORMAT = 6; +export const SCENERY_FORMAT = 7; /** A manifest URL asking for SCENERY_FORMAT's manifest (the server ignores the parameter; browsers cache by it). */ export function manifestUrl(url) { diff --git a/docs/Dashboard.md b/docs/Dashboard.md index 7a7ea1de8..4a571eb4e 100644 --- a/docs/Dashboard.md +++ b/docs/Dashboard.md @@ -1530,7 +1530,7 @@ Powerups, Orb, TV Screen and Head Icon effects (drawn as LEGO or unlit), Flair's client's environment textures come from `/api/scenery/env/:name` (`reflection`, `polished`, `brushed`, `brushedNoise`). Placed player models are drawn by the viewer's own lighting. -The views ask for a zone's manifest with the conversion format they're written for (`?format=6`, +The views ask for a zone's manifest with the conversion format they're written for (`?format=7`, `scenery-core.js` `SCENERY_FORMAT`, which follows `Scenery.cpp` `FORMAT_VERSION`), since browsers keep manifests for up to a day. A manifest without `techniques` (an older server's) is drawn with the viewer's own lights and its `textureAlpha` table instead of guessing every shader as LEGO, which laid see-through textures over white vertex diff --git a/tests/dWebTests/NifFileTests.cpp b/tests/dWebTests/NifFileTests.cpp index e1455a3b2..1bffc65c5 100644 --- a/tests/dWebTests/NifFileTests.cpp +++ b/tests/dWebTests/NifFileTests.cpp @@ -78,11 +78,11 @@ namespace { return bytes.Put(0xFFFFFFFF).Put(0).Put(-1); } - // NiAVObject; `rotation` row-major (for column vectors), written the way the file stores it (column by column) + // NiAVObject; `rotation` row-major (for column vectors), written the way the file stores it (row by row) Bytes Av(uint16_t flags, std::array translation, std::array rotation, float scale, std::vector properties) { auto bytes = Net(); bytes.Put(flags).Floats({ translation[0], translation[1], translation[2] }); - for (int col = 0; col < 3; col++) for (int row = 0; row < 3; row++) bytes.Put(rotation[row * 3 + col]); + for (const auto value : rotation) bytes.Put(value); bytes.Put(scale).Put(static_cast(properties.size())); for (const auto p : properties) bytes.Put(p); return bytes.Put(-1); // collision @@ -758,3 +758,21 @@ TEST(NifFileTests, PassesMultishaderTagsDownToMeshes) { std::memcpy(&length, encoded.data(), 4); EXPECT_EQ(nlohmann::json::parse(encoded.substr(4, length))["meshes"][0]["shaderTag"], 30); } + +TEST(NifFileTests, TurnsNodesAsTheClientDoes) { + // The minifigure's skeleton: each bone turned from its parent, so reading the rotations transposed stands it on + // its head (the hair below the hips) + const auto path = ClientRes() / "mesh" / "minifig" / "mf_main_nolod.nif"; + std::ifstream file(path, std::ios::binary); + if (!file) GTEST_SKIP() << "No game client configured"; + const std::string data((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + std::string error; + const auto model = NifFile::Parse(data, 0, error); + ASSERT_TRUE(model) << error; + const auto y = [&model](const std::string& node) { return model->nodes.at(node).translation[1]; }; + EXPECT_GT(y("hair"), y("head")); + EXPECT_GT(y("head"), y("hip_l")); + EXPECT_GT(y("hip_l"), y("knee_l")); + EXPECT_GT(y("knee_l"), y("ankle_l")); + EXPECT_NEAR(y("hair") - y("ankle_l"), 3.8f, 0.2f); +}