Merge pull request #25372 from JFonS/add_gizmo_docs
Minor fixes and documentation for Spatial Gizmos
This commit is contained in:
commit
2ad6212a3f
6 changed files with 98 additions and 13 deletions
|
@ -4,7 +4,7 @@
|
|||
Custom gizmo for editing Spatial objects.
|
||||
</brief_description>
|
||||
<description>
|
||||
Custom gizmo that is used for providing custom visualization and editing (handles) for 3D Spatial objects. These are created by [method EditorSpatialGizmoPlugin.create_gizmo].
|
||||
Custom gizmo that is used for providing custom visualization and editing (handles) for 3D Spatial objects. See [EditorSpatialGizmoPlugin] for more information.
|
||||
</description>
|
||||
<tutorials>
|
||||
</tutorials>
|
||||
|
@ -116,7 +116,30 @@
|
|||
<argument index="0" name="index" type="int">
|
||||
</argument>
|
||||
<description>
|
||||
Get actual value of a handle. This value can be anything and used for eventually undoing the motion when calling [method commit_handle]
|
||||
Get actual value of a handle. This value can be anything and used for eventually undoing the motion when calling [method commit_handle].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_plugin" qualifiers="const">
|
||||
<return type="EditorSpatialGizmoPlugin">
|
||||
</return>
|
||||
<description>
|
||||
Return the [EditorSpatialGizmoPlugin] that owns this gizmo. It's useful to retrieve materials using [method EditorSpatialGizmoPlugin.get_material].
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_spatial_node" qualifiers="const">
|
||||
<return type="Spatial">
|
||||
</return>
|
||||
<description>
|
||||
Returns the Spatial node associated with this gizmo.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_handle_highlighted" qualifiers="virtual">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<argument index="0" name="index" type="int">
|
||||
</argument>
|
||||
<description>
|
||||
Get whether a handle is highlighted or not.
|
||||
</description>
|
||||
</method>
|
||||
<method name="redraw" qualifiers="virtual">
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<class name="EditorSpatialGizmoPlugin" inherits="Resource" category="Core" version="3.1">
|
||||
<brief_description>
|
||||
Used by the editor to define Spatial gizmo types.
|
||||
</brief_description>
|
||||
<description>
|
||||
EditorSpatialGizmoPlugin allows you to define a new type of Gizmo. There are two main ways to do so: extending [EditorSpatialGizmoPlugin] for the simpler gizmos, or creating a new [EditorSpatialGizmo] type. See the tutorial in the documentation for more info.
|
||||
</description>
|
||||
<tutorials>
|
||||
<link>https://docs.godotengine.org/en/latest/tutorials/plugins/editor/spatial_gizmos.html</link>
|
||||
</tutorials>
|
||||
<demos>
|
||||
</demos>
|
||||
|
@ -17,12 +20,14 @@
|
|||
<argument index="1" name="material" type="SpatialMaterial">
|
||||
</argument>
|
||||
<description>
|
||||
Adds a new material to the internal material list for the plugin. It can then be accessed with [method get_material]. Should not be overridden.
|
||||
</description>
|
||||
</method>
|
||||
<method name="can_be_hidden" qualifiers="virtual">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<description>
|
||||
Override this method to define whether the gizmo can be hidden or not. Defaults to true.
|
||||
</description>
|
||||
</method>
|
||||
<method name="commit_handle" qualifiers="virtual">
|
||||
|
@ -37,6 +42,7 @@
|
|||
<argument index="3" name="cancel" type="bool" default="false">
|
||||
</argument>
|
||||
<description>
|
||||
Override this method to commit gizmo handles. Called for this plugin's active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
<method name="create_gizmo" qualifiers="virtual">
|
||||
|
@ -45,6 +51,7 @@
|
|||
<argument index="0" name="spatial" type="Spatial">
|
||||
</argument>
|
||||
<description>
|
||||
Override this method to return a custom [EditorSpatialGizmo] for the spatial nodes of your choice, return [code]null[/code] for the rest of nodes. (See also [method has_gizmo])
|
||||
</description>
|
||||
</method>
|
||||
<method name="create_handle_material">
|
||||
|
@ -55,6 +62,7 @@
|
|||
<argument index="1" name="billboard" type="bool" default="false">
|
||||
</argument>
|
||||
<description>
|
||||
Creates a handle material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorSpatialGizmo.add_handles]. Should not be overridden.
|
||||
</description>
|
||||
</method>
|
||||
<method name="create_icon_material">
|
||||
|
@ -69,6 +77,7 @@
|
|||
<argument index="3" name="color" type="Color" default="Color( 1, 1, 1, 1 )">
|
||||
</argument>
|
||||
<description>
|
||||
Creates an icon material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorSpatialGizmo.add_unscaled_billboard]. Should not be overridden.
|
||||
</description>
|
||||
</method>
|
||||
<method name="create_material">
|
||||
|
@ -85,6 +94,7 @@
|
|||
<argument index="4" name="use_vertex_color" type="bool" default="false">
|
||||
</argument>
|
||||
<description>
|
||||
Creates an unshaded material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with [method get_material] and used in [method EditorSpatialGizmo.add_mesh] and [method EditorSpatialGizmo.add_lines]. Should not be overridden.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_handle_name" qualifiers="virtual">
|
||||
|
@ -95,6 +105,7 @@
|
|||
<argument index="1" name="index" type="int">
|
||||
</argument>
|
||||
<description>
|
||||
Override this method to provide gizmo's handle names. Called for this plugin's active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_handle_value" qualifiers="virtual">
|
||||
|
@ -105,6 +116,7 @@
|
|||
<argument index="1" name="index" type="int">
|
||||
</argument>
|
||||
<description>
|
||||
Get actual value of a handle from gizmo. Called for this plugin's active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_material">
|
||||
|
@ -115,12 +127,14 @@
|
|||
<argument index="1" name="gizmo" type="EditorSpatialGizmo">
|
||||
</argument>
|
||||
<description>
|
||||
Get material from the internal list of materials. If an [EditorSpatialGizmo] is provided it will try to get the corresponding variant (selected and/or editable).
|
||||
</description>
|
||||
</method>
|
||||
<method name="get_name" qualifiers="virtual">
|
||||
<return type="String">
|
||||
</return>
|
||||
<description>
|
||||
Override this method to provide the name that will appear in teh gizmo visibility menu.
|
||||
</description>
|
||||
</method>
|
||||
<method name="has_gizmo" qualifiers="virtual">
|
||||
|
@ -129,9 +143,10 @@
|
|||
<argument index="0" name="spatial" type="Spatial">
|
||||
</argument>
|
||||
<description>
|
||||
Override this method to define which Spatial nodes have a gizmo from this plugin. Whenever a [Spatial] node is added to a scene this method is called, if it returns [code]true[/code] the node gets a generic [EditorSpatialGizmo] assigned and is added to this plugin's list of active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_gizmo_handle_highlighted" qualifiers="virtual">
|
||||
<method name="is_handle_highlighted" qualifiers="virtual">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
|
||||
|
@ -139,12 +154,14 @@
|
|||
<argument index="1" name="index" type="int">
|
||||
</argument>
|
||||
<description>
|
||||
Get whether a handle is highlighted or not. Called for this plugin's active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
<method name="is_selectable_when_hidden" qualifiers="virtual">
|
||||
<return type="bool">
|
||||
</return>
|
||||
<description>
|
||||
Override this method to define whether Spatial with this gizmo should be selecteble even when the gizmo is hidden.
|
||||
</description>
|
||||
</method>
|
||||
<method name="redraw" qualifiers="virtual">
|
||||
|
@ -153,6 +170,7 @@
|
|||
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
|
||||
</argument>
|
||||
<description>
|
||||
Callback to redraw the provided gizmo. Called for this plugin's active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
<method name="set_handle" qualifiers="virtual">
|
||||
|
@ -167,6 +185,7 @@
|
|||
<argument index="3" name="point" type="Vector2">
|
||||
</argument>
|
||||
<description>
|
||||
Update the value of a handle after it has been updated. Called for this plugin's active gizmos.
|
||||
</description>
|
||||
</method>
|
||||
</methods>
|
||||
|
|
|
@ -5732,6 +5732,7 @@ void SpatialEditorPlugin::snap_cursor_to_plane(const Plane &p_plane) {
|
|||
}
|
||||
|
||||
void SpatialEditor::add_gizmo_plugin(Ref<EditorSpatialGizmoPlugin> p_plugin) {
|
||||
ERR_FAIL_NULL(p_plugin.ptr());
|
||||
gizmo_plugins.push_back(p_plugin);
|
||||
_update_gizmos_menu();
|
||||
SpatialEditor::get_singleton()->update_all_gizmos();
|
||||
|
@ -5869,7 +5870,7 @@ Ref<SpatialMaterial> EditorSpatialGizmoPlugin::get_material(const String &p_name
|
|||
ERR_FAIL_COND_V(!materials.has(p_name), Ref<SpatialMaterial>());
|
||||
ERR_FAIL_COND_V(materials[p_name].size() == 0, Ref<SpatialMaterial>());
|
||||
|
||||
if (p_gizmo.is_null()) return materials[p_name][0];
|
||||
if (p_gizmo.is_null() || materials[p_name].size() == 1) return materials[p_name][0];
|
||||
|
||||
int index = (p_gizmo->is_selected() ? 1 : 0) + (p_gizmo->is_editable() ? 2 : 0);
|
||||
|
||||
|
@ -5888,7 +5889,7 @@ String EditorSpatialGizmoPlugin::get_name() const {
|
|||
if (get_script_instance() && get_script_instance()->has_method("get_name")) {
|
||||
return get_script_instance()->call("get_name");
|
||||
}
|
||||
return TTR("Name-less gizmo");
|
||||
return TTR("Nameless gizmo");
|
||||
}
|
||||
|
||||
Ref<EditorSpatialGizmo> EditorSpatialGizmoPlugin::get_gizmo(Spatial *p_spatial) {
|
||||
|
@ -5938,7 +5939,7 @@ void EditorSpatialGizmoPlugin::_bind_methods() {
|
|||
cm.default_arguments.push_back(false);
|
||||
BIND_VMETHOD(cm);
|
||||
|
||||
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_gizmo_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "index")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "index")));
|
||||
|
||||
#undef GIZMO_REF
|
||||
}
|
||||
|
@ -6008,9 +6009,9 @@ void EditorSpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int p_
|
|||
}
|
||||
}
|
||||
|
||||
bool EditorSpatialGizmoPlugin::is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
|
||||
if (get_script_instance() && get_script_instance()->has_method("is_gizmo_handle_highlighted")) {
|
||||
return get_script_instance()->call("is_gizmo_handle_highlighted", p_gizmo, p_idx);
|
||||
bool EditorSpatialGizmoPlugin::is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const {
|
||||
if (get_script_instance() && get_script_instance()->has_method("is_handle_highlighted")) {
|
||||
return get_script_instance()->call("is_handle_highlighted", p_gizmo, p_idx);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ public:
|
|||
void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, bool p_billboard = false, bool p_secondary = false);
|
||||
void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3());
|
||||
|
||||
virtual bool is_handle_highlighted(int p_idx) const;
|
||||
virtual String get_handle_name(int p_idx) const;
|
||||
virtual Variant get_handle_value(int p_idx);
|
||||
virtual void set_handle(int p_idx, Camera *p_camera, const Point2 &p_point);
|
||||
|
@ -117,6 +118,7 @@ public:
|
|||
|
||||
void set_spatial_node(Spatial *p_node);
|
||||
Spatial *get_spatial_node() const { return spatial_node; }
|
||||
EditorSpatialGizmoPlugin *get_plugin() const { return gizmo_plugin; }
|
||||
Vector3 get_handle_pos(int p_idx) const;
|
||||
bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
|
||||
bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal, int *r_gizmo_handle = NULL, bool p_sec_first = false);
|
||||
|
@ -786,7 +788,7 @@ public:
|
|||
virtual Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
|
||||
virtual void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
|
||||
virtual void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
|
||||
virtual bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
|
||||
virtual bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
|
||||
|
||||
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
|
||||
void set_state(int p_state);
|
||||
|
|
|
@ -99,26 +99,63 @@ void EditorSpatialGizmo::clear() {
|
|||
|
||||
void EditorSpatialGizmo::redraw() {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("redraw")) {
|
||||
get_script_instance()->call("redraw");
|
||||
return;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(!gizmo_plugin);
|
||||
gizmo_plugin->redraw(this);
|
||||
}
|
||||
|
||||
String EditorSpatialGizmo::get_handle_name(int p_idx) const {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("get_handle_name")) {
|
||||
return get_script_instance()->call("get_handle_name", p_idx);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(!gizmo_plugin, "");
|
||||
return gizmo_plugin->get_handle_name(this, p_idx);
|
||||
}
|
||||
|
||||
bool EditorSpatialGizmo::is_handle_highlighted(int p_idx) const {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("is_handle_highlighted")) {
|
||||
return get_script_instance()->call("is_handle_highlighted", p_idx);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(!gizmo_plugin, false);
|
||||
return gizmo_plugin->is_handle_highlighted(this, p_idx);
|
||||
}
|
||||
|
||||
Variant EditorSpatialGizmo::get_handle_value(int p_idx) {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("get_handle_value")) {
|
||||
return get_script_instance()->call("get_handle_value", p_idx);
|
||||
}
|
||||
|
||||
ERR_FAIL_COND_V(!gizmo_plugin, Variant());
|
||||
return gizmo_plugin->get_handle_value(this, p_idx);
|
||||
}
|
||||
|
||||
void EditorSpatialGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("set_handle")) {
|
||||
get_script_instance()->call("set_handle", p_idx, p_camera, p_point);
|
||||
return;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(!gizmo_plugin);
|
||||
return gizmo_plugin->set_handle(this, p_idx, p_camera, p_point);
|
||||
}
|
||||
|
||||
void EditorSpatialGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) {
|
||||
|
||||
if (get_script_instance() && get_script_instance()->has_method("commit_handle")) {
|
||||
get_script_instance()->call("commit_handle", p_idx, p_restore, p_cancel);
|
||||
return;
|
||||
}
|
||||
|
||||
ERR_FAIL_COND(!gizmo_plugin);
|
||||
return gizmo_plugin->commit_handle(this, p_idx, p_restore, p_cancel);
|
||||
}
|
||||
|
@ -298,7 +335,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, const Ref
|
|||
for (int i = 0; i < p_handles.size(); i++) {
|
||||
|
||||
Color col(1, 1, 1, 1);
|
||||
if (gizmo_plugin->is_gizmo_handle_highlighted(this, i))
|
||||
if (is_handle_highlighted(i))
|
||||
col = Color(0, 0, 1, 0.9);
|
||||
|
||||
if (SpatialEditor::get_singleton()->get_over_gizmo_handle() != i)
|
||||
|
@ -690,11 +727,14 @@ void EditorSpatialGizmo::_bind_methods() {
|
|||
ClassDB::bind_method(D_METHOD("add_unscaled_billboard", "material", "default_scale"), &EditorSpatialGizmo::add_unscaled_billboard, DEFVAL(1));
|
||||
ClassDB::bind_method(D_METHOD("add_handles", "handles", "material", "billboard", "secondary"), &EditorSpatialGizmo::add_handles, DEFVAL(false), DEFVAL(false));
|
||||
ClassDB::bind_method(D_METHOD("set_spatial_node", "node"), &EditorSpatialGizmo::_set_spatial_node);
|
||||
ClassDB::bind_method(D_METHOD("get_spatial_node"), &EditorSpatialGizmo::get_spatial_node);
|
||||
ClassDB::bind_method(D_METHOD("get_plugin"), &EditorSpatialGizmo::get_plugin);
|
||||
ClassDB::bind_method(D_METHOD("clear"), &EditorSpatialGizmo::clear);
|
||||
ClassDB::bind_method(D_METHOD("set_hidden", "hidden"), &EditorSpatialGizmo::set_hidden);
|
||||
|
||||
BIND_VMETHOD(MethodInfo("redraw"));
|
||||
BIND_VMETHOD(MethodInfo(Variant::STRING, "get_handle_name", PropertyInfo(Variant::INT, "index")));
|
||||
BIND_VMETHOD(MethodInfo(Variant::BOOL, "is_handle_highlighted", PropertyInfo(Variant::INT, "index")));
|
||||
|
||||
MethodInfo hvget(Variant::NIL, "get_handle_value", PropertyInfo(Variant::INT, "index"));
|
||||
hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT;
|
||||
|
@ -2117,7 +2157,7 @@ void SoftBodySpatialGizmoPlugin::commit_handle(EditorSpatialGizmo *p_gizmo, int
|
|||
soft_body->pin_point_toggle(p_idx);
|
||||
}
|
||||
|
||||
bool SoftBodySpatialGizmoPlugin::is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const {
|
||||
bool SoftBodySpatialGizmoPlugin::is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const {
|
||||
SoftBody *soft_body = Object::cast_to<SoftBody>(p_gizmo->get_spatial_node());
|
||||
return soft_body->is_point_pinned(idx);
|
||||
}
|
||||
|
|
|
@ -214,7 +214,7 @@ public:
|
|||
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
|
||||
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
|
||||
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel);
|
||||
bool is_gizmo_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const;
|
||||
bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const;
|
||||
|
||||
SoftBodySpatialGizmoPlugin();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue