2026-02-05 14:58:45 -08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "game/character.hpp"
|
2026-02-21 19:41:21 -08:00
|
|
|
#include <vulkan/vulkan.h>
|
2026-02-22 05:58:45 -08:00
|
|
|
#include <vk_mem_alloc.h>
|
2026-02-05 14:58:45 -08:00
|
|
|
#include <memory>
|
|
|
|
|
#include <cstdint>
|
2026-02-12 14:55:27 -08:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2026-02-05 14:58:45 -08:00
|
|
|
|
|
|
|
|
namespace wowee {
|
|
|
|
|
namespace pipeline { class AssetManager; }
|
|
|
|
|
namespace rendering {
|
|
|
|
|
|
|
|
|
|
class CharacterRenderer;
|
|
|
|
|
class Camera;
|
2026-02-21 19:41:21 -08:00
|
|
|
class VkContext;
|
|
|
|
|
class VkTexture;
|
2026-02-22 05:58:45 -08:00
|
|
|
class VkRenderTarget;
|
2026-02-05 14:58:45 -08:00
|
|
|
|
|
|
|
|
class CharacterPreview {
|
|
|
|
|
public:
|
|
|
|
|
CharacterPreview();
|
|
|
|
|
~CharacterPreview();
|
|
|
|
|
|
|
|
|
|
bool initialize(pipeline::AssetManager* am);
|
|
|
|
|
void shutdown();
|
|
|
|
|
|
|
|
|
|
bool loadCharacter(game::Race race, game::Gender gender,
|
|
|
|
|
uint8_t skin, uint8_t face,
|
|
|
|
|
uint8_t hairStyle, uint8_t hairColor,
|
2026-02-09 17:56:04 -08:00
|
|
|
uint8_t facialHair, bool useFemaleModel = false);
|
2026-02-05 14:58:45 -08:00
|
|
|
|
2026-02-12 14:55:27 -08:00
|
|
|
// Apply equipment overlays/geosets using SMSG_CHAR_ENUM equipment data (ItemDisplayInfo.dbc).
|
|
|
|
|
bool applyEquipment(const std::vector<game::EquipmentItem>& equipment);
|
|
|
|
|
|
2026-02-05 14:58:45 -08:00
|
|
|
void update(float deltaTime);
|
|
|
|
|
void render();
|
|
|
|
|
void rotate(float yawDelta);
|
|
|
|
|
|
2026-02-22 05:58:45 -08:00
|
|
|
// Off-screen composite pass — call from Renderer::beginFrame() before main render pass
|
|
|
|
|
void compositePass(VkCommandBuffer cmd, uint32_t frameIndex);
|
|
|
|
|
|
|
|
|
|
// Mark that the preview needs compositing this frame (call from UI each frame)
|
|
|
|
|
void requestComposite() { compositeRequested_ = true; }
|
|
|
|
|
|
|
|
|
|
// Returns the ImGui texture handle. Returns VK_NULL_HANDLE until the first
|
|
|
|
|
// compositePass has run (image is in UNDEFINED layout before that).
|
|
|
|
|
VkDescriptorSet getTextureId() const { return compositeRendered_ ? imguiTextureId_ : VK_NULL_HANDLE; }
|
2026-02-05 14:58:45 -08:00
|
|
|
int getWidth() const { return fboWidth_; }
|
|
|
|
|
int getHeight() const { return fboHeight_; }
|
|
|
|
|
|
2026-02-06 14:24:38 -08:00
|
|
|
CharacterRenderer* getCharacterRenderer() { return charRenderer_.get(); }
|
|
|
|
|
uint32_t getInstanceId() const { return instanceId_; }
|
|
|
|
|
uint32_t getModelId() const { return PREVIEW_MODEL_ID; }
|
|
|
|
|
bool isModelLoaded() const { return modelLoaded_; }
|
|
|
|
|
|
2026-02-05 14:58:45 -08:00
|
|
|
private:
|
|
|
|
|
void createFBO();
|
|
|
|
|
void destroyFBO();
|
|
|
|
|
|
|
|
|
|
pipeline::AssetManager* assetManager_ = nullptr;
|
2026-02-22 05:58:45 -08:00
|
|
|
VkContext* vkCtx_ = nullptr;
|
2026-02-05 14:58:45 -08:00
|
|
|
std::unique_ptr<CharacterRenderer> charRenderer_;
|
|
|
|
|
std::unique_ptr<Camera> camera_;
|
|
|
|
|
|
2026-02-22 05:58:45 -08:00
|
|
|
// Off-screen render target (color + depth)
|
|
|
|
|
std::unique_ptr<VkRenderTarget> renderTarget_;
|
|
|
|
|
|
|
|
|
|
// Per-frame UBO for preview camera/lighting (double-buffered)
|
|
|
|
|
static constexpr uint32_t MAX_FRAMES = 2;
|
|
|
|
|
VkDescriptorPool previewDescPool_ = VK_NULL_HANDLE;
|
|
|
|
|
VkBuffer previewUBO_[MAX_FRAMES] = {};
|
|
|
|
|
VmaAllocation previewUBOAlloc_[MAX_FRAMES] = {};
|
|
|
|
|
void* previewUBOMapped_[MAX_FRAMES] = {};
|
|
|
|
|
VkDescriptorSet previewPerFrameSet_[MAX_FRAMES] = {};
|
|
|
|
|
|
|
|
|
|
// Dummy 1x1 white texture for shadow map placeholder
|
|
|
|
|
std::unique_ptr<VkTexture> dummyWhiteTex_;
|
|
|
|
|
|
|
|
|
|
// ImGui texture handle for displaying the preview (VkDescriptorSet in Vulkan backend)
|
|
|
|
|
VkDescriptorSet imguiTextureId_ = VK_NULL_HANDLE;
|
|
|
|
|
|
2026-02-05 14:58:45 -08:00
|
|
|
static constexpr int fboWidth_ = 400;
|
|
|
|
|
static constexpr int fboHeight_ = 500;
|
|
|
|
|
|
|
|
|
|
static constexpr uint32_t PREVIEW_MODEL_ID = 9999;
|
|
|
|
|
uint32_t instanceId_ = 0;
|
|
|
|
|
bool modelLoaded_ = false;
|
2026-02-22 05:58:45 -08:00
|
|
|
bool compositeRequested_ = false;
|
|
|
|
|
bool compositeRendered_ = false; // True after first successful compositePass
|
2026-02-05 14:58:45 -08:00
|
|
|
float modelYaw_ = 180.0f;
|
2026-02-12 14:55:27 -08:00
|
|
|
|
|
|
|
|
// Cached info from loadCharacter() for later recompositing.
|
|
|
|
|
game::Race race_ = game::Race::HUMAN;
|
|
|
|
|
game::Gender gender_ = game::Gender::MALE;
|
|
|
|
|
bool useFemaleModel_ = false;
|
|
|
|
|
uint8_t hairStyle_ = 0;
|
|
|
|
|
uint8_t facialHair_ = 0;
|
|
|
|
|
std::string bodySkinPath_;
|
|
|
|
|
std::vector<std::string> baseLayers_; // face + underwear, etc.
|
|
|
|
|
uint32_t skinTextureSlotIndex_ = 0;
|
2026-02-05 14:58:45 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace rendering
|
|
|
|
|
} // namespace wowee
|