载入中...
搜索中...
未找到
SpriteStack.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5#include "common/Module.h"
6
7#include <cstdint>
8#include <string>
9#include <vector>
10
11namespace ssq {
12class Class;
13}
14
15namespace eve::graphics {
16class Camera2D;
17class Graphics;
18class Texture;
19}
20namespace eve::image { class ImageData; }
21namespace eve::model3d { class ModelData; }
22
23namespace eve::spritestack {
24
26struct SliceInput {
27 const float *posXYZ = nullptr;
28 const float *nrmXYZ = nullptr;
29 const float *rgb = nullptr;
30 int vertexCount = 0;
31 const uint32_t *indices = nullptr;
32 int indexCount = 0;
33};
34
37 int layerCount = 16;
38 int imageW = 128;
39 int imageH = 128;
40 std::string axis = "y";
41 float thickness = 0.f;
42 float padding = 0.04f;
43 bool shade = true;
44 float tintR = 1.f, tintG = 1.f, tintB = 1.f;
45};
46
48std::vector<image::ImageData *> sliceMeshToLayers(const SliceInput &, const SliceOptions &);
50EVENGINE_API_WORLD std::vector<image::ImageData *> sliceModelToLayers(model3d::ModelData *, const SliceOptions &);
52EVENGINE_API_WORLD std::vector<image::ImageData *> slicePrimitiveToLayers(const std::string &, const SliceOptions &);
53
62public:
64 SpriteStack2D() = default;
65 SpriteStack2D(const SpriteStack2D &) = delete;
67
69 void setLayerCount(int count);
71 int getLayerCount() const;
73 void setLayerTexture(graphics::Texture *texture, int index);
75 graphics::Texture *getLayerTexture(int index) const;
77 void setLayerImage(graphics::Graphics *gfx, image::ImageData *img, int index);
79 void setLayerFile(graphics::Graphics *gfx, const std::string &path, int index);
81 void setLayersFromAtlas(graphics::Graphics *gfx, graphics::Texture *atlas, int layerCount);
83 void setThickness(float thickness);
85 float getThickness() const;
87 void setSize(float width, float height);
89 float getWidth() const;
91 float getHeight() const;
93 void setPosition(float x, float y);
95 void setRotation(float degrees);
97 void setTint(float r, float g, float b, float a = 1.f);
99 void setVisible(bool visible);
101 bool getVisible() const;
103 void setShadowEnabled(bool enabled);
105 bool getShadowEnabled() const;
107 void setShadowOpacity(float opacity);
109 void setShadowOffset(float x, float y);
111 void setOutline(float width, float r = 0.f, float g = 0.f, float b = 0.f);
113 float getOutlineWidth() const;
115 void setOutlineColor(float r, float g, float b);
117 uint64_t getVersion() const { return version_; }
119 void render(graphics::Graphics *gfx) const;
121 void renderWithCamera(graphics::Graphics *gfx, graphics::Camera2D *camera) const;
122
123private:
124 friend class SpriteStackBatch;
125 struct Layer {
126 graphics::Texture *texture = nullptr;
127 float u0 = 0.f, v0 = 0.f, u1 = 1.f, v1 = 1.f;
128 };
130 void bumpVersion() { ++version_; }
131 std::vector<Layer> layers_;
132 int layerCount_ = 0;
133 float thickness_ = 1.f, width_ = 64.f, height_ = 64.f;
134 float x_ = 0.f, y_ = 0.f, rotation_ = 0.f;
135 float tintR_ = 1.f, tintG_ = 1.f, tintB_ = 1.f, tintA_ = 1.f;
136 bool visible_ = true, shadowEnabled_ = false;
137 float shadowOpacity_ = 0.3f, shadowOffsetX_ = 5.f, shadowOffsetY_ = 4.f;
138 float outlineWidth_ = 0.f, outlineR_ = 0.f, outlineG_ = 0.f, outlineB_ = 0.f;
139 uint64_t version_ = 1;
140};
141
144public:
146 void add(SpriteStack2D *stack);
148 void remove(SpriteStack2D *stack);
150 void clear();
152 int getStackCount() const;
154 void render(graphics::Graphics *gfx) const;
156 void renderWithCamera(graphics::Graphics *gfx, graphics::Camera2D *camera) const;
157private:
158 std::vector<SpriteStack2D *> stacks_;
159};
160
163public:
166 SpriteStack() = default;
168 ~SpriteStack() override = default;
170 SpriteStack2D *newStack(graphics::Graphics *gfx);
172 SpriteStackBatch *newBatch(graphics::Graphics *gfx);
174 std::vector<image::ImageData *> slicePrimitive(const std::string &kind, int layerCount,
175 int imageW, int imageH,
176 const std::string &axis, float thickness);
178 std::vector<image::ImageData *> sliceModel(model3d::ModelData *model, int layerCount,
179 int imageW, int imageH, const std::string &axis,
180 float thickness);
181};
182
184void exposeSpriteStackModelBindings(ssq::Class &cls);
185
186} // namespace eve::spritestack
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float degrees
Definition CardTypes.cpp:35
float thickness
Definition CaveMesh.cpp:83
HSQOBJECT cls
Definition ECS.cpp:21
#define EVENGINE_API_WORLD
Definition Export.h:109
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
double r
std::uint32_t height
std::uint32_t width
TokenKind kind
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
std::string path
Definition PlayHost.cpp:110
glm::mat4 model
std::uint32_t count
float opacity
bool visible
uint32_t index
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
Declarative 2D camera (viewport center + zoom).
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
Represents raw pixel data.
Definition ImageData.h:38
CPU-side decoded 3D model (Assimp scene owned via medialoader::ModelScene). Does not upload to GPU — ...
Definition ModelData.h:39
Pure-2D sprite stack made from horizontal RGBA cross-sections.
Definition SpriteStack.h:61
uint64_t getVersion() const
Returns the version.
SpriteStack2D(const SpriteStack2D &)=delete
SpriteStack2D & operator=(const SpriteStack2D &)=delete
SpriteStack2D()=default
Sprite stack 2 d.
Collection of 2D stacks; Graphics performs texture batching.
SpriteStack module: horizontal slice baking plus pure-2D rendering.
SpriteStack()=default
Sprite stack.
~SpriteStack() override=default
Sprite stack.
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
void exposeSpriteStackModelBindings(ssq::Class &cls)
Register sliceModel when SpriteStackModel.cpp is linked (model3d on).
std::vector< image::ImageData * > slicePrimitiveToLayers(const std::string &kind, const SliceOptions &opt)
Slice primitive to layers.
EVENGINE_API_WORLD std::vector< image::ImageData * > sliceModelToLayers(model3d::ModelData *, const SliceOptions &)
Assimp-backed bake; compiled only when the model3d module is linked.
std::vector< image::ImageData * > sliceMeshToLayers(const SliceInput &input, const SliceOptions &opt)
Slice mesh to layers.
EVEngine ECS 集成层:底层实现使用 sunxfancy/ECS.hpp https://github.com/sunxfancy/ECS.hpp
Definition ECS.h:14
bool enabled
CPU triangle-mesh input used to bake horizontal RGBA sprite slices.
Definition SpriteStack.h:26
Options for baking a mesh into equal-sized RGBA sprite layers.
Definition SpriteStack.h:36