载入中...
搜索中...
未找到
Hd2d.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4
5// HD-2D module: renders 2D tilemaps and 2D sprite characters inside the 3D
6// scene. Both techniques layer on top of the existing graphics 3D pipeline
7// (GBuffer + CSM shadows):
8//
9// * TileMap3D -- extrudes a map::TileLayer into a 3D relief mesh. Every
10// non-empty tile becomes a box whose top face shows the
11// tile's atlas region and whose side walls extrude down to
12// the configured depth (or to the per-tile elevation read
13// from tile metadata). Handed to a graphics::Renderable3D so
14// it picks up depth, shadows and GBuffer automatically.
15// * Sprite3D -- a camera-facing billboard quad in the 3D world carrying a
16// 2D texture (a character / animation frame). It is an ECS
17// graphics::Renderable3D oriented toward the camera each
18// frame (screen-aligned billboard), so it composites
19// into the forward pass and casts shadows like any mesh.
20// Supports a sprite-sheet frame grid so existing 2D
21// animations play in 3D.
22//
23// Script binding: eve.Hd2d (slot hd2d). See module_manifest.cmake.
24
25#include "common/Module.h"
26
27#include <glm/mat4x4.hpp>
28
29#include <cstdint>
30#include <string>
31#include <vector>
32
33namespace eve::graphics {
34class Camera3D;
35class Graphics;
36class Mesh;
37class Renderable3D;
38class Texture;
39} // namespace eve::graphics
40namespace eve::map { class TileLayer; }
41
42namespace eve::hd2d {
43
59public:
61 TileMap3D() = default;
62 TileMap3D(const TileMap3D &) = delete;
63 TileMap3D &operator=(const TileMap3D &) = delete;
64
66 void setSideDepth(float depth);
68 float getSideDepth() const;
70 void setHeightScale(float scale);
72 float getHeightScale() const;
74 void setWallUV(float u0, float v0, float u1, float v1);
76 void setTint(float r, float g, float b, float a = 1.f);
77
85
92
94 int getTileCount() const { return tileCount_; }
95
96private:
97 float sideDepth_ = 6.f;
98 float heightScale_ = 1.f;
99 float wallU0_ = 0.f, wallV0_ = 0.f, wallU1_ = 0.05f, wallV1_ = 0.05f;
100 float tintR_ = 1.f, tintG_ = 1.f, tintB_ = 1.f, tintA_ = 1.f;
101 int tileCount_ = 0;
102};
103
120public:
124 ~Sprite3D();
125 Sprite3D(const Sprite3D &) = delete;
126 Sprite3D &operator=(const Sprite3D &) = delete;
127
129 void setTexture(graphics::Texture *texture);
131 graphics::Texture *getTexture() const;
132
134 void setFrame(float u0, float v0, float u1, float v1);
136 void getFrame(float &u0, float &v0, float &u1, float &v1) const;
138 void setFlipX(bool flip);
140 void setFlipY(bool flip);
141
143 void setFrameGrid(int columns, int rows);
145 int getFrameGridColumns() const;
147 int getFrameGridRows() const;
149 void setFrameIndex(int index);
151 int getFrameIndex() const;
153 int getFrameCount() const;
160 void play(int start, int end, float fps);
162 void stop();
164 bool isPlaying() const;
172 void update(float dt);
173
184 void setCamera(graphics::Camera3D *camera);
185
198 void setPivot(float x, float y);
200 void setPosition(float x, float y, float z);
202 float getPositionX() const;
204 float getPositionY() const;
206 float getPositionZ() const;
208 void setSize(float width, float height);
210 float getWidth() const;
212 float getHeight() const;
214 void setTint(float r, float g, float b, float a = 1.f);
216 void setVisible(bool visible);
218 bool getVisible() const;
219
224 void setAlphaCutoff(float cutoff);
226 float getAlphaCutoff() const;
231 void setDepthWrite(bool enabled);
233 bool getDepthWrite() const;
235 void setDoubleSided(bool enabled);
237 bool getDoubleSided() const;
242 void setBillboardMode(const std::string &mode);
244 std::string getBillboardMode() const;
245
247 graphics::Mesh *quadMesh() const { return quad_; }
248
249private:
250 friend class Hd2D;
251 struct Anim {
252 int start = 0, end = 0;
253 float fps = 12.f;
254 float clock = 0.f;
255 bool playing = false;
256 };
257
258 void buildQuad(graphics::Graphics *gfx);
259 void updateFrameUv();
260 void orientToCamera();
261 void syncMaterial();
262
263 graphics::Graphics *gfx_ = nullptr;
264 graphics::Texture *texture_ = nullptr;
265 graphics::Mesh *quad_ = nullptr;
266 graphics::Renderable3D *renderable_ = nullptr;
267 graphics::Camera3D *camera_ = nullptr;
268
269 // frame UV
270 float u0_ = 0.f, v0_ = 0.f, u1_ = 1.f, v1_ = 1.f;
271 bool flipX_ = false, flipY_ = false;
272
273 // grid
274 int gridCols_ = 1, gridRows_ = 1;
275 int frameIndex_ = 0;
276 Anim anim_;
277
278 // placement
279 float x_ = 0.f, y_ = 0.f, z_ = 0.f;
280 float width_ = 1.f, height_ = 1.f;
281 float pivotX_ = 0.5f, pivotY_ = 0.5f;
282 float tintR_ = 1.f, tintG_ = 1.f, tintB_ = 1.f, tintA_ = 1.f;
283 bool visible_ = true;
284 float alphaCutoff_ = 0.5f;
285 bool depthWrite_ = true;
286 bool doubleSided_ = true;
287 bool yawBillboard_ = false;
288};
289
298public:
300 Hd2dLook() = default;
301
303 void setFocusDistance(float distance);
305 float getFocusDistance() const { return focusDistance_; }
307 void setMaxBlur(float blurPx);
309 float getMaxBlur() const { return maxBlurPx_; }
311 void setFocusRange(float range);
313 float getFocusRange() const { return focusRange_; }
315 void setBloomIntensity(float intensity);
317 float getBloomIntensity() const { return bloomIntensity_; }
319 void setBloomThreshold(float threshold);
321 float getBloomThreshold() const { return bloomThreshold_; }
322
329 void apply(graphics::Camera3D *camera) const;
330
338 void applyPixelSampler(graphics::Graphics *gfx, graphics::Texture *texture) const;
339
341 static Hd2dLook miniature();
343 static Hd2dLook soft();
344
345private:
346 float focusDistance_ = 18.f;
347 float maxBlurPx_ = 5.f;
348 float focusRange_ = 14.f;
349 float bloomIntensity_ = 0.35f;
350 float bloomThreshold_ = 1.2f;
351};
352
357public:
362 ~Hd2D() override;
363
365 TileMap3D *newTileMap3D();
367 Sprite3D *newSprite(graphics::Graphics *gfx);
373 Hd2dLook *newLook();
379 Hd2dLook *newMiniatureLook();
380};
381
382} // namespace eve::hd2d
Duration start
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_DOMAINS
Definition Export.h:110
int rows
tensor::Graph g
Definition GpuGraph.cpp:7
float camera[2]
float soft[4]
double r
std::uint32_t height
std::uint32_t width
Range range
std::array< float, 3 > scale
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
float distance
TileLayer * layer
int columns
bool visible
uint32_t index
std::uint32_t depth
EVENGINE_API_FOUNDATION public API.
Definition Module.h:46
EVENGINE_API_BACKENDS public API.
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:25
EVENGINE_API_BACKENDS public API.
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:18
HD-2D module: tilemap-to-3D extrusion + 2D sprites as 3D billboards.
Definition Hd2d.h:356
~Hd2D() override
Hd 2 d.
HD-2D presentation look inspired by HD2DURP (DOF + bloom + pixel sampling).
Definition Hd2d.h:297
float getFocusRange() const
Returns the focus range.
Definition Hd2d.h:313
float getMaxBlur() const
Returns the max blur.
Definition Hd2d.h:309
Hd2dLook()=default
Hd 2 d look.
float getBloomThreshold() const
Returns the bloom threshold.
Definition Hd2d.h:321
float getBloomIntensity() const
Returns the bloom intensity.
Definition Hd2d.h:317
float getFocusDistance() const
Returns the focus distance.
Definition Hd2d.h:305
Camera-facing 2D sprite billboard rendered inside the 3D scene.
Definition Hd2d.h:119
Sprite3D(const Sprite3D &)=delete
graphics::Mesh * quadMesh() const
Quad mesh.
Definition Hd2d.h:247
Sprite3D & operator=(const Sprite3D &)=delete
Sprite3D()
Sprite 3 d.
Extrudes a 2D tile layer into a 3D terrain mesh (HD-2D ground).
Definition Hd2d.h:58
int getTileCount() const
Number of box tiles baked by the last build.
Definition Hd2d.h:94
TileMap3D()=default
Tile map 3 d.
TileMap3D(const TileMap3D &)=delete
TileMap3D & operator=(const TileMap3D &)=delete
ECS tile layer entity. Script mutates tile GIDs / tileset / draw; TileRenderSystem batch-draws atlas ...
Definition TileLayer.h:32
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
放置世界:格子占用(多通道)+ 地形语义 + 已放置建筑实例。 行为由 PlacementSystem 提供;本类暴露便于脚本绑定的薄封装方法。 坐标换算统一走 eve::grid(支持 rectang...
bool enabled