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; } }