Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Testo 3D
Introduzione
In un progetto, può capitare che ci sia bisogno di creare del testo come parte di una scena 3D e non solo nell'HUD. Godot offre due metodi per farlo: il nodo Label3D e la risorsa TextMesh per un nodo MeshInstance3D.
Inoltre, Godot permette di posizionare i nodi Control in base alla posizione di un punto 3D sulla telecamera. Questo può servire da alternativa al testo 3D "vero" in situazioni in cui Label3D e TextMesh non sono flessibili abbastanza.
Vedi anche
È possibile vedere il testo 3D in azione attraverso il progetto demo 3D Labels and Texts.
Questa pagina non spiega come visualizzare una scena per GUI in un ambiente 3D. Per informazioni su come fare ciò, consulta il progetto demo GUI in 3D.
Label3D
Label3D si comporta come un nodo Label, ma nello spazio 3D. A differenza del nodo Label, questo nodo Label3D non eredita le proprietà di un tema di GUI. Tuttavia, il suo aspetto rimane personalizzabile e utilizza la stessa sotto-risorsa di font dei nodi Control (e include supporto per renderizzare i font MSDF).
Vantaggi
Label3D è più veloce da generare rispetto a TextMesh. Sebbene entrambi utilizzino un meccanismo di caching per renderizzare i nuovi glifi una sola volta, Label3D sarà comunque più veloce da (ri)generare, soprattutto per testi lunghi. Questo può evitare scatti durante il gioco sulle CPU di fascia bassa o sui dispositivi mobili.
Label3D può utilizzare font bitmap e font dinamici (con e senza MSDF o mipmap). Sotto questo aspetto, ciò lo rende più flessibile rispetto a TextMesh, soprattutto per renderizzare font con contorni auto-intersecanti o font colorati (emoji).
Vedi anche
See Utilizzare i font for guidelines on configuring font imports.
Limitazioni
By default, Label3D has limited interaction with a 3D environment. It can be occluded by geometry and lit by light sources if the Shaded flag is enabled. However, it will not cast shadows even if Cast Shadow is set to On in the Label3D's GeometryInstance3D properties. This is because the node internally generates a quad mesh (one glyph per quad) with transparent textures and has the same limitations as Sprite3D. Transparency sorting issues can also become apparent when several Label3Ds overlap, especially if they have outlines.
This can be mitigated by setting the Label3D's transparency mode to Alpha Cut, at the cost of less smooth text rendering. The Opaque Pre-Pass transparency mode can preserve text smoothness while allowing the Label3D to cast shadows, but some transparency sorting issues will remain.
See Transparency sorting section in the 3D rendering limitations page for more information.
Text rendering quality can also suffer when the Label3D is viewed at a distance. To improve text rendering quality, enable mipmaps on the font or switch the font to use MSDF rendering.
TextMesh
The TextMesh resource has similarities to Label3D. They both display text in a 3D scene, and will use the same font subresource. However, instead of generating transparent quads, TextMesh generates 3D geometry that represents the glyphs' contours and has the properties of a mesh. As a result, a TextMesh is shaded by default and automatically casts shadows onto the environment. A TextMesh can also have a material applied to it (including custom shaders).
Here is an example of a texture and how it's applied to the mesh. You can use the texture below as a reference for the generated mesh's UV map:
Vantaggi
TextMesh has a few advantages over Label3D:
TextMesh can use a texture to modify text color on a per-side basis.
TextMesh geometry can have actual depth to it, giving glyphs a 3D look.
TextMesh can use custom shaders, unlike Label3D.
Limitazioni
Ci sono alcune limitazioni per TextMesh:
No built-in outline support, unlike Label3D. This can be simulated using custom shaders though.
Sono supportati solo i font dinamici (
.ttf,.otf,.woff,.woff2). I font bitmap nei formati.fnto.fontnon sono supportati.I font con contorni che si intersecano tra loro non appariranno correttamente. Se si riscontrano problemi di rendering con font scaricati da siti web come Google Fonts, provare a scaricare il font dal sito web ufficiale dell'autore.
L'antialiasing nel rendering di testo richiede di abilitare di un metodo di antialiasing sull'intera scena, come MSAA, FXAA e antialiasing temporale (TAA). Se nessun metodo di antialiasing è abilitato, il testo apparirà granuloso, soprattutto a distanza. Consultare Antialiasing 3D per ulteriori informazioni.
Nodo Label proiettato (o qualsiasi altro Control)
There is a last solution that is more complex to set up, but provides the most
flexibility: projecting a 2D node onto 3D space. This can be achieved using the
return value of unproject_position
method on a Camera3D node in a script's _process() function. This return value
should then be used to set the position property of a Control node.
Consultare la demo waypoint 3D per un esempio di questo.
Vantaggi
Any Control node can be used, including Label, RichTextLabel or even nodes such as Button. This allows for powerful formatting and GUI interaction.
The script-based approach allows for complete freedom in positioning. For example, this makes it considerably easier to pin Controls to the screen's edges when they go off-screen (for in-game 3D markers).
Control theming is obeyed. This allows for easier customization that globally applies to the project.
Limitazioni
Projected Controls cannot be occluded by 3D geometry in any way. You can use a RayCast to fully hide the control if its target position is occluded by a collider, but this doesn't allow for partially hiding the control behind a wall.
Changing text size depending on distance by adjusting the Control's
scaleproperty is possible, but it needs to be done manually. Label3D and TextMesh automatically take care of this, at the cost of less flexibility (can't set a minimum/maximum text size in pixels).Handling resolution and aspect ratio changes must be taken into account in the script, which can be challenging.
Dovrei usare Label3D, TextMesh o un Control proiettato?
Nella maggior parte dei casi, Label3D è consigliato perché è più facile da configurare e offre una maggiore qualità di rendering (soprattutto se l'antialiasing 3D è disabilitato).
Per casi d'uso avanzati, TextMesh è più flessibile in quanto consente di stilizzare il testo con shader personalizzati. Gli shader personalizzati consentono di modificare la geometria finale, ad esempio curvando il testo lungo una superficie. Poiché il testo è una geometria 3D vera e propria, può facoltativamente avere profondità e contribuire anche all'illuminazione globale.
Se c'è bisogno di funzionalità come BBCode o supporto dei temi di Control, utilizzare un nodo RichTextLabel proiettato è l'unica opzione.