-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Stroke font text gizmos #22732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Stroke font text gizmos #22732
Conversation
|
Agreed on monospace preference. What are the requirements when selecting a new font candidate for this? |
Not much really, just have to choose a font and embed the font data. There are some hershey font collections online: Need to go bed though, I'll have a look into it tomorrow evening. |
Added new example 3d_text_gizmos
Completed 3d_text_gizmos example
Objective
Lightweight immediate mode stroke fonts text gizmo implementation.
Fixes #16490
Solution
New
bevy_gizmosmoduletextcontaining functionstextandtext_2dimplemented forGizmoBuffer.The
textfunction has parameters:isometry: Into<Isometry3d>: defines the translation and rotation of the text.text: &str: the text to be drawn.size: f32: the height of the glyphs.anchor: Vec2: anchor point relative to the center of the text.color: Into<Color>: the color of the text.text_2dis the same, except the isometry isInto<Isometry2d>.The glyph set is limited to ASCII characters from 33 to 126.
The text rendering uses the Simplex Hershey font:
https://en.wikipedia.org/wiki/Hershey_fonts
https://paulbourke.net/dataformats/hershey/
The static font data is in the bevy_gizmos::text_font module.
Hershey fonts are public domain and don't require any attribution.
The text geometry isn't retained but since it's so simple, it's still much faster than the retained Cosmic Text version I wrote initially. That might not be the case if it's used to display whole pages of text, but this isn't intended for that.
Glyphs are drawn using linestrips.
I think this would be better with a monospaced font but it's using a proportional font atm.
Only left-to-right, left justified text is supported.
I left out line height and justify options, they are trivial to add but I'm not sure if we need them. Maybe they could be added to the gizmo config later. Could make a case for moving the
sizeparameter to the config as well.Testing
Example displaying text gizmos rotating in 3d
Example displaying all the glyphs from the text gizmos font:
Larger example with lots of text and an FPS counter:
Showcase