From 3e3d18512ed48a2016cbca562ffc5c556b3a81c4 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 12 Nov 2026 09:46:21 +0000 Subject: [PATCH] Decompile fn_01727 (SampleModelTexture) Batch #18030 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_01727 SampleModelTexture: logic confirmed by peer review Peer-reviewed-by: Yommy, KWDev, bibinir Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/Models/ModelNode.h | 2 +- .../Contents/Models/ModelTextureAnimation.cpp | 38 +++++++++---------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/Source/Contents/Models/ModelNode.h b/Source/Contents/Models/ModelNode.h index 0f81720a3..409be9ce8 100644 --- a/Source/Contents/Models/ModelNode.h +++ b/Source/Contents/Models/ModelNode.h @@ -12,7 +12,7 @@ struct ModelTextureTransform { /* 0000 */ float values[5] = {0, 0, 1, 1, 0}; }; -void SampleModelTexture(const ModelTextureChannels& channels, float frame, ModelTextureTransform& output); +void SampleModelTexture(ModelTextureChannels& channels, float frame, ModelTextureTransform& output); class C3dNode { public: diff --git a/Source/Contents/Models/ModelTextureAnimation.cpp b/Source/Contents/Models/ModelTextureAnimation.cpp index 54cc6d758..c9aaea08f 100644 --- a/Source/Contents/Models/ModelTextureAnimation.cpp +++ b/Source/Contents/Models/ModelTextureAnimation.cpp @@ -3,34 +3,30 @@ // OFFSET: 0x00540EA0 // FUNCTION: fn_01727 -void SampleModelTexture(const ModelTextureChannels& channels, float frame, ModelTextureTransform& output) { +void SampleModelTexture(ModelTextureChannels& channels, float frame, ModelTextureTransform& output) { + float* targets[5] = {&output.values[0], &output.values[1], &output.values[2], &output.values[3], &output.values[4]}; + for (int channel = 0; channel < 5; ++channel) { - const auto found = channels.find(channel); - - if (found == channels.end()) { - continue; - } - - const auto& keys = found->second; - const int last = keys.back().frame; - - if (frame >= static_cast(last)) { - output.values[channel] = keys.back().value; + if (channels.find(channel) == channels.end()) { continue; } + std::vector& keys = channels[channel]; unsigned next = 1; + if (frame < static_cast(keys.back().frame)) { + const unsigned count = keys.size(); + for (; next < count; ++next) { + if (frame < static_cast(keys[next].frame)) { + break; + } + } - while (next < keys.size() && !(static_cast(keys[next].frame) > frame)) { - ++next; + const int previous = keys[next - 1].frame; + const float amount = (frame - static_cast(previous)) / static_cast(keys[next].frame - previous); + *targets[channel] = (1.0f - amount) * keys[next - 1].value + amount * keys[next].value; + } else { + *targets[channel] = keys.back().value; } - - const int previous = keys[next - 1].frame; - const int difference = keys[next].frame - keys[next - 1].frame; - const float amount = (frame - static_cast(previous)) / static_cast(difference); - const float first = (1.0f - amount) * keys[next - 1].value; - const float second = amount * keys[next].value; - output.values[channel] = first + second; } }