Implement M2 texture animation (UV scrolling) for fountain water

Parse M2TextureTransform entries and texture transform lookups from the
M2 binary, then apply per-batch UV offsets in the vertex shader using
the existing animation time base and global sequence durations.
This commit is contained in:
Kelsi 2026-02-06 01:49:27 -08:00
parent 4bb2828b21
commit ad04da31c3
4 changed files with 83 additions and 1 deletions

View file

@ -109,6 +109,13 @@ struct M2Batch {
uint16_t submeshLevel = 0; // Submesh level (0=base, 1+=LOD/alternate mesh)
};
// Texture transform (UV animation) data
struct M2TextureTransform {
M2AnimationTrack translation; // UV translation keyframes
M2AnimationTrack rotation; // UV rotation keyframes (quat)
M2AnimationTrack scale; // UV scale keyframes
};
// Attachment point (bone-anchored position for weapons, effects, etc.)
struct M2Attachment {
uint32_t id; // 0=Head, 1=RightHand, 2=LeftHand, etc.
@ -139,6 +146,10 @@ struct M2Model {
std::vector<M2Texture> textures;
std::vector<uint16_t> textureLookup; // Batch texture index lookup
// Texture transforms (UV animation)
std::vector<M2TextureTransform> textureTransforms;
std::vector<uint16_t> textureTransformLookup;
// Attachment points (for weapon/effect anchoring)
std::vector<M2Attachment> attachments;
std::vector<uint16_t> attachmentLookup; // attachment ID → index

View file

@ -31,6 +31,7 @@ struct M2ModelGPU {
uint32_t indexStart = 0; // offset in indices (not bytes)
uint32_t indexCount = 0;
bool hasAlpha = false;
uint16_t textureAnimIndex = 0xFFFF; // 0xFFFF = no texture animation
};
GLuint vao = 0;
@ -61,6 +62,11 @@ struct M2ModelGPU {
bool hasAnimation = false; // True if any bone has keyframes
bool isSmoke = false; // True for smoke models (UV scroll animation)
bool disableAnimation = false; // Keep foliage/tree doodads visually stable
bool hasTextureAnimation = false; // True if any batch has UV animation
// Texture transform data for UV animation
std::vector<pipeline::M2TextureTransform> textureTransforms;
std::vector<uint16_t> textureTransformLookup;
std::vector<int> idleVariationIndices; // Sequence indices for idle variations (animId 0)
bool isValid() const { return vao != 0 && indexCount > 0; }