feat(animation): 452 named constants, 30-phase character animation state machine

Add animation_ids.hpp/cpp with all 452 WoW animation ID constants (anim::STAND,
anim::RUN, anim::FIRE_BOW, ... anim::FLY_BACKWARDS, etc.), nameFromId() O(1)
lookup, and flyVariant() compact 218-element ground→FLY_* resolver.

Expand AnimationController into a full state machine with 20+ named states:
spell cast (directed→omni→cast fallback chain, instant one-shot release),
hit reactions (WOUND/CRIT/DODGE/BLOCK/SHIELD_BLOCK), stun, wounded idle,
stealth animation substitution, loot, fishing channel, sit/sleep/kneel
down→loop→up transitions, sheathe/unsheathe combat enter/exit, ranged weapons
(BOW/GUN/CROSSBOW/THROWN with reload states), game object OPEN/CLOSE/DESTROY,
vehicle enter/exit, mount flight directionals (FLY_LEFT/RIGHT/UP/DOWN/BACKWARDS),
emote state variants, off-hand/pierce/dual-wield alternation, NPC
birth/spawn/drown/rise, sprint aura override, totem idle, NPC greeting/farewell.

Add spell_defines.hpp with SpellEffect (~45 constants) and SpellMissInfo
(12 constants) namespaces; replace all magic numbers in spell_handler.cpp.

Add GAMEOBJECT_BYTES_1 to update field table (all 4 expansion JSONs) and wire
GameObjectStateCallback. Add DBC cross-validation on world entry.

Expand tools/_ANIM_NAMES from ~35 to 452 entries in m2_viewer.py and
asset_pipeline_gui.py. Add tests/test_animation_ids.cpp.

Bug fixes included:
- Stand state 1 was animating READY_2H(27) — fixed to SITTING(97)
- Spell casts ended freeze-frame — add one-shot release animation
- NPC 2H swing probe chain missing ATTACK_2H_LOOSE (polearm/staff)
- Chair sits (states 2/4/5/6) incorrectly played floor-sit transition
- STOP(3) used for all spell casts — replaced with model-aware chain
This commit is contained in:
Paul 2026-04-04 23:02:53 +03:00
parent d54e262048
commit e58f9b4b40
59 changed files with 3903 additions and 483 deletions

View file

@ -15,6 +15,7 @@
* the original WoW Model Viewer (charcontrol.h, REGION_FAC=2).
*/
#include "rendering/character_renderer.hpp"
#include "rendering/animation_ids.hpp"
#include "rendering/vk_context.hpp"
#include "rendering/vk_texture.hpp"
#include "rendering/vk_pipeline.hpp"
@ -34,6 +35,7 @@
#include <cmath>
#include <filesystem>
#include <future>
#include <numeric>
#include <thread>
#include <functional>
#include <unordered_map>
@ -261,7 +263,8 @@ bool CharacterRenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFram
.setVertexInput({charBinding}, charAttrs)
.setTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.setRasterization(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE)
.setDepthTest(true, depthWrite, VK_COMPARE_OP_LESS_OR_EQUAL)
.setDepthTest(true, depthWrite, VK_COMPARE_OP_LESS)
.setDepthBias(0.0f, 0.0f)
.setColorBlendAttachment(blendState)
.setMultisample(samples);
if (alphaToCoverage)
@ -269,7 +272,7 @@ bool CharacterRenderer::initialize(VkContext* ctx, VkDescriptorSetLayout perFram
return builder
.setLayout(pipelineLayout_)
.setRenderPass(mainPass)
.setDynamicStates({VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR})
.setDynamicStates({VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_DEPTH_BIAS})
.build(device, vkCtx_->getPipelineCache());
};
@ -1733,9 +1736,9 @@ void CharacterRenderer::update(float deltaTime, const glm::vec3& cameraPos) {
inst.animationTime -= static_cast<float>(seq.duration);
}
} else {
// One-shot animation finished: return to Stand (0) unless dead
if (inst.currentAnimationId != 1 /*Death*/) {
playAnimation(pair.first, 0, true);
// One-shot animation finished: return to Stand unless dead
if (inst.currentAnimationId != anim::DEATH) {
playAnimation(pair.first, anim::STAND, true);
} else {
// Stay on last frame of death
inst.animationTime = static_cast<float>(seq.duration);
@ -2380,8 +2383,24 @@ void CharacterRenderer::render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet,
return gpuModel.data.materials[b.materialIndex].blendMode;
return 0;
};
// Sort batches by (priorityPlane, materialLayer) so equipment layers
// render in the order the M2 format intends. priorityPlane separates
// overlay effects; materialLayer orders coplanar body parts.
std::vector<size_t> sortedBatchIndices(gpuModel.data.batches.size());
std::iota(sortedBatchIndices.begin(), sortedBatchIndices.end(), 0);
std::stable_sort(sortedBatchIndices.begin(), sortedBatchIndices.end(),
[&](size_t a, size_t b) {
const auto& ba = gpuModel.data.batches[a];
const auto& bb = gpuModel.data.batches[b];
if (ba.priorityPlane != bb.priorityPlane)
return ba.priorityPlane < bb.priorityPlane;
return ba.materialLayer < bb.materialLayer;
});
for (int pass = 0; pass < 2; pass++) {
for (const auto& batch : gpuModel.data.batches) {
for (size_t bi : sortedBatchIndices) {
const auto& batch = gpuModel.data.batches[bi];
uint16_t bm = getBatchBlendMode(batch);
if (pass == 0 && bm != 0) continue; // pass 0: opaque only
if (pass == 1 && bm == 0) continue; // pass 1: non-opaque only
@ -2599,6 +2618,10 @@ void CharacterRenderer::render(VkCommandBuffer cmd, VkDescriptorSet perFrameSet,
vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_GRAPHICS,
pipelineLayout_, 1, 1, &materialSet, 0, nullptr);
// Per-batch depth bias from materialLayer to separate coplanar
// armor pieces (chest/legs/gloves) that share identical depth.
vkCmdSetDepthBias(cmd, static_cast<float>(batch.materialLayer) * 0.5f, 0.0f, 0.0f);
vkCmdDrawIndexed(cmd, batch.indexCount, 1, batch.indexStart, 0, 0);
}
} // end pass loop
@ -3030,8 +3053,8 @@ void CharacterRenderer::moveInstanceTo(uint32_t instanceId, const glm::vec3& des
// Stop at current location.
inst.position = destination;
inst.isMoving = false;
if (inst.currentAnimationId == 4 || inst.currentAnimationId == 5) {
playAnimation(instanceId, 0, true);
if (inst.currentAnimationId == anim::WALK || inst.currentAnimationId == anim::RUN) {
playAnimation(instanceId, anim::STAND, true);
}
return;
}
@ -3509,7 +3532,8 @@ void CharacterRenderer::recreatePipelines() {
.setVertexInput({charBinding}, charAttrs)
.setTopology(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST)
.setRasterization(VK_POLYGON_MODE_FILL, VK_CULL_MODE_NONE)
.setDepthTest(true, depthWrite, VK_COMPARE_OP_LESS_OR_EQUAL)
.setDepthTest(true, depthWrite, VK_COMPARE_OP_LESS)
.setDepthBias(0.0f, 0.0f)
.setColorBlendAttachment(blendState)
.setMultisample(samples);
if (alphaToCoverage)
@ -3517,7 +3541,7 @@ void CharacterRenderer::recreatePipelines() {
return builder
.setLayout(pipelineLayout_)
.setRenderPass(mainPass)
.setDynamicStates({VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR})
.setDynamicStates({VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR, VK_DYNAMIC_STATE_DEPTH_BIAS})
.build(device, vkCtx_->getPipelineCache());
};