feat(动画): 添加角色动作合成纹理功能
实现角色动作的离屏渲染合成功能,支持获取合成纹理及其相关信息: 1. 新增CanvasActor用于离屏渲染 2. 新增RenderTexture封装FBO和纹理 3. 扩展Renderer支持离屏渲染到纹理 4. 为CharacterAnimation添加合成纹理生成逻辑 5. 在调试界面添加合成纹理预览功能
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "character/CharacterDataLoader.h"
|
||||
#include "character/CharacterEquipmentManager.h"
|
||||
#include <frostbite2D/2d/actor.h>
|
||||
#include <frostbite2D/2d/canvas_actor.h>
|
||||
#include <frostbite2D/animation/animation.h>
|
||||
#include <frostbite2D/base/RefPtr.h>
|
||||
#include <functional>
|
||||
@@ -21,9 +22,20 @@ public:
|
||||
using ActionFrameFlagCallback = std::function<void(int)>;
|
||||
using ActionEndCallback = std::function<void()>;
|
||||
|
||||
struct CompositeFrameInfo {
|
||||
bool valid = false;
|
||||
Rect localBounds;
|
||||
Vec2 originInTexture = Vec2::Zero();
|
||||
Vec2 groundAnchorInTexture = Vec2::Zero();
|
||||
int width = 1;
|
||||
int height = 1;
|
||||
};
|
||||
|
||||
bool Init(CharacterObject* parent,
|
||||
const character::CharacterConfig& config,
|
||||
const CharacterEquipmentManager& equipmentManager);
|
||||
void Update(float deltaTime) override;
|
||||
void Render() override;
|
||||
|
||||
bool SetAction(const std::string& actionName);
|
||||
void SetDirection(int direction);
|
||||
@@ -39,6 +51,12 @@ public:
|
||||
animation::AniFrame GetCurrentFrameInfo() const;
|
||||
void SetActionFrameFlagCallback(ActionFrameFlagCallback callback);
|
||||
void SetActionEndCallback(ActionEndCallback callback);
|
||||
bool HasCompositeTexture() const;
|
||||
Ptr<Texture> GetCompositeTexture() const;
|
||||
Vec2 GetCompositeTextureSize() const;
|
||||
Vec2 GetCompositeOriginInTexture() const;
|
||||
Vec2 GetCompositeGroundAnchorInTexture() const;
|
||||
uint64 GetCompositeVersion() const { return compositeVersion_; }
|
||||
|
||||
private:
|
||||
static std::string FormatImgPath(std::string path, Animation::ReplaceData data);
|
||||
@@ -46,6 +64,15 @@ private:
|
||||
Animation* GetCurrentPrimaryAnimation() const;
|
||||
void RefreshRuntimeCallbacks();
|
||||
bool shouldSkipMissingAnimation(const std::string& aniPath);
|
||||
void BuildCompositeActionFrames();
|
||||
CompositeFrameInfo ComputeCompositeFrameInfo(const std::vector<RefPtr<Animation>>& animations,
|
||||
int direction) const;
|
||||
CompositeFrameInfo GetCurrentCompositeFrameInfo() const;
|
||||
uint64 CaptureCurrentRenderSignature() const;
|
||||
void MarkCompositeDirty();
|
||||
void UpdateCompositeCamera();
|
||||
void RefreshCompositeTextureIfNeeded();
|
||||
void RenderCurrentActionToCompositeCanvas();
|
||||
|
||||
void CreateAnimationBySlot(const std::string& actionName,
|
||||
const std::string& slotName,
|
||||
@@ -61,6 +88,11 @@ private:
|
||||
ActionEndCallback actionEndCallback_;
|
||||
std::unordered_set<std::string> missingAnimationPaths_;
|
||||
size_t skippedMissingAnimationCount_ = 0;
|
||||
RefPtr<CanvasActor> compositeCanvas_ = nullptr;
|
||||
std::map<std::string, CompositeFrameInfo> compositeFrameInfoByAction_;
|
||||
bool compositeDirty_ = true;
|
||||
uint64 compositeVersion_ = 0;
|
||||
uint64 lastCompositeSignature_ = 0;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
|
||||
Reference in New Issue
Block a user