载入中...
搜索中...
未找到
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 <cstdint>
28#include <string>
29#include <vector>
30
31namespace eve::graphics {
32class Camera3D;
33class Graphics;
34class Mesh;
35class Renderable3D;
36class Texture;
37} // namespace eve::graphics
38namespace eve::map { class TileLayer; }
39
40namespace eve::hd2d {
41
57public:
59 TileMap3D() = default;
60 TileMap3D(const TileMap3D &) = delete;
61 TileMap3D &operator=(const TileMap3D &) = delete;
62
64 void setSideDepth(float depth);
66 float getSideDepth() const;
68 void setHeightScale(float scale);
70 float getHeightScale() const;
72 void setWallUV(float u0, float v0, float u1, float v1);
74 void setTint(float r, float g, float b, float a = 1.f);
75
83
90
92 int getTileCount() const { return tileCount_; }
93
94private:
95 float sideDepth_ = 6.f;
96 float heightScale_ = 1.f;
97 float wallU0_ = 0.f, wallV0_ = 0.f, wallU1_ = 0.05f, wallV1_ = 0.05f;
98 float tintR_ = 1.f, tintG_ = 1.f, tintB_ = 1.f, tintA_ = 1.f;
99 int tileCount_ = 0;
100};
101
118public:
122 ~Sprite3D();
123 Sprite3D(const Sprite3D &) = delete;
124 Sprite3D &operator=(const Sprite3D &) = delete;
125
127 void setTexture(graphics::Texture *texture);
129 graphics::Texture *getTexture() const;
130
132 void setFrame(float u0, float v0, float u1, float v1);
134 void getFrame(float &u0, float &v0, float &u1, float &v1) const;
136 void setFlipX(bool flip);
138 void setFlipY(bool flip);
139
141 void setFrameGrid(int columns, int rows);
143 int getFrameGridColumns() const;
145 int getFrameGridRows() const;
147 void setFrameIndex(int index);
149 int getFrameIndex() const;
151 int getFrameCount() const;
158 void play(int start, int end, float fps);
160 void stop();
162 bool isPlaying() const;
170 void update(float dt);
171
182 void setCamera(graphics::Camera3D *camera);
183
196 void setPivot(float x, float y);
198 void setPosition(float x, float y, float z);
200 float getPositionX() const;
202 float getPositionY() const;
204 float getPositionZ() const;
206 void setSize(float width, float height);
208 float getWidth() const;
210 float getHeight() const;
212 void setTint(float r, float g, float b, float a = 1.f);
214 void setVisible(bool visible);
216 bool getVisible() const;
217
222 void setAlphaCutoff(float cutoff);
224 float getAlphaCutoff() const;
229 void setDepthWrite(bool enabled);
231 bool getDepthWrite() const;
233 void setDoubleSided(bool enabled);
235 bool getDoubleSided() const;
240 void setBillboardMode(const std::string &mode);
242 std::string getBillboardMode() const;
243
245 graphics::Mesh *quadMesh() const { return quad_; }
246
247private:
248 friend class Hd2D;
249 struct Anim {
250 int start = 0, end = 0;
251 float fps = 12.f;
252 float clock = 0.f;
253 bool playing = false;
254 };
255
256 void buildQuad(graphics::Graphics *gfx);
257 void updateFrameUv();
258 void orientToCamera();
259 void syncMaterial();
260
261 graphics::Graphics *gfx_ = nullptr;
262 graphics::Texture *texture_ = nullptr;
263 graphics::Mesh *quad_ = nullptr;
264 graphics::Renderable3D *renderable_ = nullptr;
265 graphics::Camera3D *camera_ = nullptr;
266
267 // frame UV
268 float u0_ = 0.f, v0_ = 0.f, u1_ = 1.f, v1_ = 1.f;
269 bool flipX_ = false, flipY_ = false;
270
271 // grid
272 int gridCols_ = 1, gridRows_ = 1;
273 int frameIndex_ = 0;
274 Anim anim_;
275
276 // placement
277 float x_ = 0.f, y_ = 0.f, z_ = 0.f;
278 float width_ = 1.f, height_ = 1.f;
279 float pivotX_ = 0.5f, pivotY_ = 0.5f;
280 float tintR_ = 1.f, tintG_ = 1.f, tintB_ = 1.f, tintA_ = 1.f;
281 bool visible_ = true;
282 float alphaCutoff_ = 0.5f;
283 bool depthWrite_ = true;
284 bool doubleSided_ = true;
285 bool yawBillboard_ = false;
286};
287
296public:
298 Hd2dLook() = default;
299
301 void setFocusDistance(float distance);
303 float getFocusDistance() const { return focusDistance_; }
305 void setMaxBlur(float blurPx);
307 float getMaxBlur() const { return maxBlurPx_; }
309 void setFocusRange(float range);
311 float getFocusRange() const { return focusRange_; }
313 void setBloomIntensity(float intensity);
315 float getBloomIntensity() const { return bloomIntensity_; }
317 void setBloomThreshold(float threshold);
319 float getBloomThreshold() const { return bloomThreshold_; }
320
327 void apply(graphics::Camera3D *camera) const;
328
336 void applyPixelSampler(graphics::Graphics *gfx, graphics::Texture *texture) const;
337
339 static Hd2dLook miniature();
341 static Hd2dLook soft();
342
343private:
344 float focusDistance_ = 18.f;
345 float maxBlurPx_ = 5.f;
346 float focusRange_ = 14.f;
347 float bloomIntensity_ = 0.35f;
348 float bloomThreshold_ = 1.2f;
349};
350
355public:
360 ~Hd2D() override;
361
363 TileMap3D *newTileMap3D();
365 Sprite3D *newSprite(graphics::Graphics *gfx);
371 Hd2dLook *newLook();
377 Hd2dLook *newMiniatureLook();
378};
379
380} // namespace eve::hd2d
double z
double y
double x
Duration start
#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
double dt
Texture * texture
TileLayer * layer
size_t end
int columns
bool visible
std::uint32_t depth
uint32_t index
EVENGINE_API_FOUNDATION public API.
Definition Module.h:48
EVENGINE_API_BACKENDS public API.
GPU mesh handle (+ optional CPU morph targets).
Definition Mesh.h:26
EVENGINE_API_BACKENDS public API.
GPU texture created via Graphics::newTexture. Owns GPU resources through an opaque backend handle.
Definition Texture.h:15
HD-2D module: tilemap-to-3D extrusion + 2D sprites as 3D billboards.
Definition Hd2d.h:354
~Hd2D() override
Hd 2 d.
HD-2D presentation look inspired by HD2DURP (DOF + bloom + pixel sampling).
Definition Hd2d.h:295
float getFocusRange() const
Returns the focus range.
Definition Hd2d.h:311
float getMaxBlur() const
Returns the max blur.
Definition Hd2d.h:307
Hd2dLook()=default
Hd 2 d look.
float getBloomThreshold() const
Returns the bloom threshold.
Definition Hd2d.h:319
float getBloomIntensity() const
Returns the bloom intensity.
Definition Hd2d.h:315
float getFocusDistance() const
Returns the focus distance.
Definition Hd2d.h:303
Camera-facing 2D sprite billboard rendered inside the 3D scene.
Definition Hd2d.h:117
Sprite3D(const Sprite3D &)=delete
graphics::Mesh * quadMesh() const
Quad mesh.
Definition Hd2d.h:245
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:56
int getTileCount() const
Number of box tiles baked by the last build.
Definition Hd2d.h:92
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:33
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
放置世界:格子占用(多通道)+ 地形语义 + 已放置建筑实例。 行为由 PlacementSystem 提供;本类暴露便于脚本绑定的薄封装方法。 坐标换算统一走 eve::grid(支持 rectang...
bool enabled