mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-04 10:31:50 +00:00
Merge pull request #888 from MihailRis/3d-text-font-property
3d text font property
This commit is contained in:
commit
6b580d23c6
6 changed files with 39 additions and 12 deletions
|
|
@ -4,14 +4,15 @@
|
|||
|
||||
The appearance of 3D text, is configured via a table, like [particles](particles.md). All fields are optional.
|
||||
|
||||
| Field | Description | Default |
|
||||
| --------------- | ---------------------------- | ---------------- |
|
||||
| display | Display format | static_billboard |
|
||||
| color | Text color | {1, 1, 1, 1} |
|
||||
| scale | Text scale | 1 |
|
||||
| render_distance | Text rendering distance | 32 |
|
||||
| xray_opacity | Visibility through obstacles | 0 |
|
||||
| perspective | Perspective coefficient | 1 |
|
||||
| Field | Description | Default |
|
||||
| --------------- | ---------------------------------------- | ---------------- |
|
||||
| display | Display format | static_billboard |
|
||||
| color | Text color | {1, 1, 1, 1} |
|
||||
| scale | Text scale | 1 |
|
||||
| render_distance | Text rendering distance | 32 |
|
||||
| xray_opacity | Visibility through obstacles | 0 |
|
||||
| perspective | Perspective coefficient | 1 |
|
||||
| font | Font. If absent, the default one is used | "" |
|
||||
|
||||
Available display formats:
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
| render_distance | Дистанция отрисовки текста | 32 |
|
||||
| xray_opacity | Коэффициент видимости через препятствия (просвечивание) | 0 |
|
||||
| perspective | Коэффициент перспективы | 1 |
|
||||
| font | Шрифт. При отсутствии используется основной | "" |
|
||||
|
||||
Доступные форматы отображения:
|
||||
|
||||
|
|
|
|||
|
|
@ -162,6 +162,8 @@ static inline void draw_text(
|
|||
const FontStylesScheme* styles,
|
||||
size_t styleMapOffset
|
||||
) {
|
||||
bool is3d = std::is_same<Batch, Batch3D>();
|
||||
|
||||
static FontStylesScheme defStyles {{{}}, {0}};
|
||||
|
||||
if (styles == nullptr) {
|
||||
|
|
@ -194,13 +196,26 @@ static inline void draw_text(
|
|||
float advance = baseAdvance;
|
||||
if (auto glyph = font.getGlyph(c)) {
|
||||
yOffset = glyph->yOffset;
|
||||
advance = glyph->xAdvance;
|
||||
advance = glyph->xAdvance /
|
||||
static_cast<float>(font.getLineHeight()) * 2.0f *
|
||||
baseAdvance;
|
||||
}
|
||||
uint charpage = c >> 8;
|
||||
if (charpage == page){
|
||||
batch.texture(font.getPage(charpage));
|
||||
draw_glyph(
|
||||
batch, pos, glm::vec2(x, y - yOffset / static_cast<float>(font.getLineHeight())), c, right, up, interval, style
|
||||
batch,
|
||||
pos,
|
||||
glm::vec2(
|
||||
x,
|
||||
y - yOffset * (is3d ? -1 : 1) /
|
||||
static_cast<float>(font.getLineHeight())
|
||||
),
|
||||
c,
|
||||
right,
|
||||
up,
|
||||
interval,
|
||||
style
|
||||
);
|
||||
}
|
||||
else if (charpage > page && charpage < next){
|
||||
|
|
|
|||
|
|
@ -58,7 +58,10 @@ void TextsRenderer::renderNote(
|
|||
}
|
||||
opacity = preset.xrayOpacity;
|
||||
}
|
||||
auto& font = assets.require<Font>(FONT_DEFAULT);
|
||||
|
||||
auto specifiedFont = assets.get<Font>(preset.font);
|
||||
auto& font =
|
||||
specifiedFont ? *specifiedFont : assets.require<Font>(FONT_DEFAULT);
|
||||
|
||||
glm::vec3 xvec = note.getAxisX();
|
||||
glm::vec3 yvec = note.getAxisY();
|
||||
|
|
@ -76,7 +79,10 @@ void TextsRenderer::renderNote(
|
|||
yvec = camera.up;
|
||||
}
|
||||
float scale =
|
||||
(1.0f - preset.perspective) * glm::pow(glm::distance(camera.position, pos), 1.0f-preset.perspective);
|
||||
(1.0f - preset.perspective) *
|
||||
glm::pow(
|
||||
glm::distance(camera.position, pos), 1.0f - preset.perspective
|
||||
);
|
||||
xvec *= 1.0f + scale;
|
||||
yvec *= 1.0f + scale;
|
||||
}
|
||||
|
|
@ -118,6 +124,7 @@ void TextsRenderer::renderNote(
|
|||
}
|
||||
auto color = preset.color;
|
||||
batch.setColor(glm::vec4(color.r, color.g, color.b, color.a * opacity));
|
||||
|
||||
font.draw(
|
||||
batch,
|
||||
text,
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ dv::value NotePreset::serialize() const {
|
|||
{"render_distance", renderDistance},
|
||||
{"xray_opacity", xrayOpacity},
|
||||
{"perspective", perspective},
|
||||
{"font", font},
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -27,4 +28,5 @@ void NotePreset::deserialize(const dv::value& src) {
|
|||
src.at("render_distance").get(renderDistance);
|
||||
src.at("xray_opacity").get(xrayOpacity);
|
||||
src.at("perspective").get(perspective);
|
||||
src.at("font").get(font);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ struct NotePreset : public Serializable {
|
|||
float renderDistance = 32.0f;
|
||||
float xrayOpacity = 0.0f;
|
||||
float perspective = 1.0f;
|
||||
std::string font {};
|
||||
|
||||
dv::value serialize() const override;
|
||||
void deserialize(const dv::value& src) override;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue