Skip to content

Commit

Permalink
Backport Label3D node implementation and Sprite*3D material render pr…
Browse files Browse the repository at this point in the history
…iority.
  • Loading branch information
bruvzg committed May 23, 2022
1 parent 241c267 commit dc6d8d6
Show file tree
Hide file tree
Showing 20 changed files with 2,011 additions and 27 deletions.
45 changes: 45 additions & 0 deletions doc/classes/Font.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,51 @@
Returns the size of a character, optionally taking kerning into account if the next character is provided. Note that the height returned is the font height (see [method get_height]) and has no relation to the glyph height.
</description>
</method>
<method name="get_char_texture" qualifiers="const">
<return type="RID" />
<argument index="0" name="char" type="int" />
<argument index="1" name="next" type="int" default="0" />
<argument index="2" name="outline" type="bool" default="false" />
<description>
Returns resource id of the cache texture containing the char.
</description>
</method>
<method name="get_char_texture_size" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="char" type="int" />
<argument index="1" name="next" type="int" default="0" />
<argument index="2" name="outline" type="bool" default="false" />
<description>
Returns size of the cache texture containing the char.
</description>
</method>
<method name="get_char_tx_offset" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="char" type="int" />
<argument index="1" name="next" type="int" default="0" />
<argument index="2" name="outline" type="bool" default="false" />
<description>
Returns char offset from the baseline.
</description>
</method>
<method name="get_char_tx_size" qualifiers="const">
<return type="Vector2" />
<argument index="0" name="char" type="int" />
<argument index="1" name="next" type="int" default="0" />
<argument index="2" name="outline" type="bool" default="false" />
<description>
Returns size of the char.
</description>
</method>
<method name="get_char_tx_uv_rect" qualifiers="const">
<return type="Rect2" />
<argument index="0" name="char" type="int" />
<argument index="1" name="next" type="int" default="0" />
<argument index="2" name="outline" type="bool" default="false" />
<description>
Returns rectangle in the cache texture containing the char.
</description>
</method>
<method name="get_descent" qualifiers="const">
<return type="float" />
<description>
Expand Down
156 changes: 156 additions & 0 deletions doc/classes/Label3D.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="Label3D" inherits="GeometryInstance" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Displays plain text in a 3D world.
</brief_description>
<description>
Label3D displays plain text in a 3D world. It gives you control over the horizontal and vertical alignment.
</description>
<tutorials>
</tutorials>
<methods>
<method name="generate_triangle_mesh" qualifiers="const">
<return type="TriangleMesh" />
<description>
Returns a [TriangleMesh] with the label's vertices following its current configuration (such as its [member pixel_size]).
</description>
</method>
<method name="get_draw_flag" qualifiers="const">
<return type="bool" />
<argument index="0" name="flag" type="int" enum="Label3D.DrawFlags" />
<description>
Returns the value of the specified flag.
</description>
</method>
<method name="set_draw_flag">
<return type="void" />
<argument index="0" name="flag" type="int" enum="Label3D.DrawFlags" />
<argument index="1" name="enabled" type="bool" />
<description>
If [code]true[/code], the specified flag will be enabled. See [enum Label3D.DrawFlags] for a list of flags.
</description>
</method>
</methods>
<members>
<member name="alpha_cut" type="int" setter="set_alpha_cut_mode" getter="get_alpha_cut_mode" enum="Label3D.AlphaCutMode" default="0">
The alpha cutting mode to use for the sprite. See [enum AlphaCutMode] for possible values.
</member>
<member name="alpha_scissor_threshold" type="float" setter="set_alpha_scissor_threshold" getter="get_alpha_scissor_threshold" default="0.5">
Threshold at which the alpha scissor will discard values.
</member>
<member name="autowrap" type="bool" setter="set_autowrap" getter="get_autowrap" default="false">
If [code]true[/code], wraps the text to the [member width].
</member>
<member name="billboard" type="int" setter="set_billboard_mode" getter="get_billboard_mode" enum="SpatialMaterial.BillboardMode" default="0">
The billboard mode to use for the label. See [enum SpatialMaterial.BillboardMode] for possible values.
</member>
<member name="double_sided" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="true">
If [code]true[/code], text can be seen from the back as well, if [code]false[/code], it is invisible when looking at it from behind.
</member>
<member name="fixed_size" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="false">
If [code]true[/code], the label is rendered at the same size regardless of distance.
</member>
<member name="font" type="Font" setter="set_font" getter="get_font">
[Font] used for the [Label3D]'s text.
</member>
<member name="horizontal_alignment" type="int" setter="set_horizontal_alignment" getter="get_horizontal_alignment" enum="Label3D.Align" default="1">
Controls the text's horizontal alignment. Supports left, center, right. Set it to one of the [enum Align] constants.
</member>
<member name="line_spacing" type="float" setter="set_line_spacing" getter="get_line_spacing" default="0.0">
Vertical space between lines in multiline [Label3D].
</member>
<member name="modulate" type="Color" setter="set_modulate" getter="get_modulate" default="Color( 1, 1, 1, 1 )">
Text [Color] of the [Label3D].
</member>
<member name="no_depth_test" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="false">
If [code]true[/code], depth testing is disabled and the object will be drawn in render order.
</member>
<member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2( 0, 0 )">
The text drawing offset (in pixels).
</member>
<member name="outline_modulate" type="Color" setter="set_outline_modulate" getter="get_outline_modulate" default="Color( 0, 0, 0, 1 )">
The tint of [Font]'s outline.
</member>
<member name="outline_render_priority" type="int" setter="set_outline_render_priority" getter="get_outline_render_priority" default="-1">
Sets the render priority for the text outline. Higher priority objects will be sorted in front of lower priority objects.
[b]Node:[/b] This only applies if [member alpha_cut] is set to [constant ALPHA_CUT_DISABLED] (default value).
[b]Note:[/b] This only applies to sorting of transparent objects. This will not impact how transparent objects are sorted relative to opaque objects. This is because opaque objects are not sorted, while transparent objects are sorted from back to front (subject to priority).
</member>
<member name="pixel_size" type="float" setter="set_pixel_size" getter="get_pixel_size" default="0.01">
The size of one pixel's width on the label to scale it in 3D.
</member>
<member name="render_priority" type="int" setter="set_render_priority" getter="get_render_priority" default="0">
Sets the render priority for the text. Higher priority objects will be sorted in front of lower priority objects.
[b]Node:[/b] This only applies if [member alpha_cut] is set to [constant ALPHA_CUT_DISABLED] (default value).
[b]Note:[/b] This only applies to sorting of transparent objects. This will not impact how transparent objects are sorted relative to opaque objects. This is because opaque objects are not sorted, while transparent objects are sorted from back to front (subject to priority).
</member>
<member name="shaded" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="false">
If [code]true[/code], the [Light] in the [Environment] has effects on the label.
</member>
<member name="text" type="String" setter="set_text" getter="get_text" default="&quot;&quot;">
The text to display on screen.
</member>
<member name="uppercase" type="bool" setter="set_uppercase" getter="is_uppercase" default="false">
If [code]true[/code], all the text displays as UPPERCASE.
</member>
<member name="vertical_alignment" type="int" setter="set_vertical_alignment" getter="get_vertical_alignment" enum="Label3D.VAlign" default="1">
Controls the text's vertical alignment. Supports top, center, bottom. Set it to one of the [enum VAlign] constants.
</member>
<member name="width" type="float" setter="set_width" getter="get_width" default="500.0">
Text width (in pixels), used for autowrap and fill alignment.
</member>
</members>
<constants>
<constant name="FLAG_SHADED" value="0" enum="DrawFlags">
If set, lights in the environment affect the label.
</constant>
<constant name="FLAG_DOUBLE_SIDED" value="1" enum="DrawFlags">
If set, text can be seen from the back as well. If not, the texture is invisible when looking at it from behind.
</constant>
<constant name="FLAG_DISABLE_DEPTH_TEST" value="2" enum="DrawFlags">
Disables the depth test, so this object is drawn on top of all others. However, objects drawn after it in the draw order may cover it.
</constant>
<constant name="FLAG_FIXED_SIZE" value="3" enum="DrawFlags">
Label is scaled by depth so that it always appears the same size on screen.
</constant>
<constant name="FLAG_MAX" value="4" enum="DrawFlags">
Represents the size of the [enum DrawFlags] enum.
</constant>
<constant name="ALPHA_CUT_DISABLED" value="0" enum="AlphaCutMode">
This mode performs standard alpha blending. It can display translucent areas, but transparency sorting issues may be visible when multiple transparent materials are overlapping.
</constant>
<constant name="ALPHA_CUT_DISCARD" value="1" enum="AlphaCutMode">
This mode only allows fully transparent or fully opaque pixels. This mode is also known as [i]alpha testing[/i] or [i]1-bit transparency[/i].
[b]Note:[/b] This mode might have issues with anti-aliased fonts and outlines, try adjusting [member alpha_scissor_threshold] or using SDF font.
[b]Note:[/b] When using text with overlapping glyphs (e.g., cursive scripts), this mode might have transparency sorting issues between the main text and the outline.
</constant>
<constant name="ALPHA_CUT_OPAQUE_PREPASS" value="2" enum="AlphaCutMode">
This mode draws fully opaque pixels in the depth prepass. This is slower than [constant ALPHA_CUT_DISABLED] or [constant ALPHA_CUT_DISCARD], but it allows displaying translucent areas and smooth edges while using proper sorting.
[b]Note:[/b] When using text with overlapping glyphs (e.g., cursive scripts), this mode might have transparency sorting issues between the main text and the outline.
</constant>
<constant name="ALIGN_LEFT" value="0" enum="Align">
Align rows to the left (default).
</constant>
<constant name="ALIGN_CENTER" value="1" enum="Align">
Align rows centered.
</constant>
<constant name="ALIGN_RIGHT" value="2" enum="Align">
Align rows to the right.
</constant>
<constant name="ALIGN_FILL" value="3" enum="Align">
Expand row whitespaces to fit the width.
</constant>
<constant name="VALIGN_TOP" value="0" enum="VAlign">
Align the whole text to the top.
</constant>
<constant name="VALIGN_CENTER" value="1" enum="VAlign">
Align the whole text to the center.
</constant>
<constant name="VALIGN_BOTTOM" value="2" enum="VAlign">
Align the whole text to the bottom.
</constant>
<constant name="VALIGN_FILL" value="3" enum="VAlign">
Align the whole text by spreading the rows.
</constant>
</constants>
</class>
8 changes: 7 additions & 1 deletion doc/classes/SpatialMaterial.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@
<member name="flags_albedo_tex_force_srgb" type="bool" setter="set_flag" getter="get_flag" default="false">
Forces a conversion of the [member albedo_texture] from sRGB space to linear space.
</member>
<member name="flags_albedo_tex_msdf" type="bool" setter="set_flag" getter="get_flag" default="false">
Enables signed distance field rendering shader.
</member>
<member name="flags_disable_ambient_light" type="bool" setter="set_flag" getter="get_flag" default="false">
If [code]true[/code], the object receives no ambient light.
</member>
Expand Down Expand Up @@ -570,7 +573,10 @@
<constant name="FLAG_USE_SHADOW_TO_OPACITY" value="18" enum="Flags">
Enables the shadow to opacity feature.
</constant>
<constant name="FLAG_MAX" value="19" enum="Flags">
<constant name="FLAG_ALBEDO_TEXTURE_SDF" value="19" enum="Flags">
Enables signed distance field rendering shader.
</constant>
<constant name="FLAG_MAX" value="20" enum="Flags">
Represents the size of the [enum Flags] enum.
</constant>
<constant name="DIFFUSE_BURLEY" value="0" enum="DiffuseMode">
Expand Down
19 changes: 18 additions & 1 deletion doc/classes/SpriteBase3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<member name="double_sided" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="true">
If [code]true[/code], texture can be seen from the back as well, if [code]false[/code], it is invisible when looking at it from behind.
</member>
<member name="fixed_size" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="false">
If [code]true[/code], the label is rendered at the same size regardless of distance.
</member>
<member name="flip_h" type="bool" setter="set_flip_h" getter="is_flipped_h" default="false">
If [code]true[/code], texture is flipped horizontally.
</member>
Expand All @@ -60,6 +63,9 @@
A color value used to [i]multiply[/i] the texture's colors. Can be used for mood-coloring or to simulate the color of light.
[b]Note:[/b] If a [member GeometryInstance.material_override] is defined on the [SpriteBase3D], the material override must be configured to take vertex colors into account for albedo. Otherwise, the color defined in [member modulate] will be ignored. For a [SpatialMaterial], [member SpatialMaterial.vertex_color_use_as_albedo] must be [code]true[/code]. For a [ShaderMaterial], [code]ALBEDO *= COLOR.rgb;[/code] must be inserted in the shader's [code]fragment()[/code] function.
</member>
<member name="no_depth_test" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="false">
If [code]true[/code], depth testing is disabled and the object will be drawn in render order.
</member>
<member name="offset" type="Vector2" setter="set_offset" getter="get_offset" default="Vector2( 0, 0 )">
The texture's drawing offset.
</member>
Expand All @@ -70,6 +76,11 @@
<member name="pixel_size" type="float" setter="set_pixel_size" getter="get_pixel_size" default="0.01">
The size of one pixel's width on the sprite to scale it in 3D.
</member>
<member name="render_priority" type="int" setter="set_render_priority" getter="get_render_priority" default="0">
Sets the render priority for the sprite. Higher priority objects will be sorted in front of lower priority objects.
[b]Node:[/b] This only applies if [member alpha_cut] is set to [constant ALPHA_CUT_DISABLED] (default value).
[b]Note:[/b] This only applies to sorting of transparent objects. This will not impact how transparent objects are sorted relative to opaque objects. This is because opaque objects are not sorted, while transparent objects are sorted from back to front (subject to priority).
</member>
<member name="shaded" type="bool" setter="set_draw_flag" getter="get_draw_flag" default="false">
If [code]true[/code], the [Light] in the [Environment] has effects on the sprite.
</member>
Expand All @@ -87,7 +98,13 @@
<constant name="FLAG_DOUBLE_SIDED" value="2" enum="DrawFlags">
If set, texture can be seen from the back as well, if not, it is invisible when looking at it from behind.
</constant>
<constant name="FLAG_MAX" value="3" enum="DrawFlags">
<constant name="FLAG_DISABLE_DEPTH_TEST" value="3" enum="DrawFlags">
Disables the depth test, so this object is drawn on top of all others. However, objects drawn after it in the draw order may cover it.
</constant>
<constant name="FLAG_FIXED_SIZE" value="4" enum="DrawFlags">
Sprite is scaled by depth so that it always appears the same size on screen.
</constant>
<constant name="FLAG_MAX" value="5" enum="DrawFlags">
Represents the size of the [enum DrawFlags] enum.
</constant>
<constant name="ALPHA_CUT_DISABLED" value="0" enum="AlphaCutMode">
Expand Down
1 change: 1 addition & 0 deletions editor/icons/icon_label_3d.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions editor/plugins/spatial_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6488,6 +6488,7 @@ void SpatialEditor::_register_all_gizmos() {
add_gizmo_plugin(Ref<MeshInstanceSpatialGizmoPlugin>(memnew(MeshInstanceSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<SoftBodySpatialGizmoPlugin>(memnew(SoftBodySpatialGizmoPlugin)));
add_gizmo_plugin(Ref<Sprite3DSpatialGizmoPlugin>(memnew(Sprite3DSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<Label3DSpatialGizmoPlugin>(memnew(Label3DSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<SkeletonSpatialGizmoPlugin>(memnew(SkeletonSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<Position3DSpatialGizmoPlugin>(memnew(Position3DSpatialGizmoPlugin)));
add_gizmo_plugin(Ref<RayCastSpatialGizmoPlugin>(memnew(RayCastSpatialGizmoPlugin)));
Expand Down
33 changes: 33 additions & 0 deletions editor/spatial_editor_gizmos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "scene/3d/collision_shape.h"
#include "scene/3d/cpu_particles.h"
#include "scene/3d/gi_probe.h"
#include "scene/3d/label_3d.h"
#include "scene/3d/light.h"
#include "scene/3d/listener.h"
#include "scene/3d/mesh_instance.h"
Expand Down Expand Up @@ -1563,6 +1564,38 @@ void Sprite3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {

///

Label3DSpatialGizmoPlugin::Label3DSpatialGizmoPlugin() {
}

bool Label3DSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return Object::cast_to<Label3D>(p_spatial) != nullptr;
}

String Label3DSpatialGizmoPlugin::get_name() const {
return "Label3D";
}

int Label3DSpatialGizmoPlugin::get_priority() const {
return -1;
}

bool Label3DSpatialGizmoPlugin::can_be_hidden() const {
return false;
}

void Label3DSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
Label3D *label = Object::cast_to<Label3D>(p_gizmo->get_spatial_node());

p_gizmo->clear();

Ref<TriangleMesh> tm = label->generate_triangle_mesh();
if (tm.is_valid()) {
p_gizmo->add_collision_triangles(tm);
}
}

///

Position3DSpatialGizmoPlugin::Position3DSpatialGizmoPlugin() {
pos3d_mesh = Ref<ArrayMesh>(memnew(ArrayMesh));
cursor_points = Vector<Vector3>();
Expand Down
13 changes: 13 additions & 0 deletions editor/spatial_editor_gizmos.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ class Sprite3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
Sprite3DSpatialGizmoPlugin();
};

class Label3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(Label3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);

public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
int get_priority() const;
bool can_be_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);

Label3DSpatialGizmoPlugin();
};

class Position3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(Position3DSpatialGizmoPlugin, EditorSpatialGizmoPlugin);

Expand Down
Loading

0 comments on commit dc6d8d6

Please sign in to comment.