Backported from Godot4: Node3D gizmo improvements

* Clean-up of node_3d_editor_plugin.{h,cpp}: removed unused code, fixed some bugs.
* Moved node_3d_editor_gizmos.{h,cpp} to editor/plugins.
* Added support for multiple gizmos per node. This means custom gizmos will no longer override the built-in ones and that multiple gizmos can be used in more complex nodes.
* Added support for handle IDs. When adding handles to a gizmo, an ID can be specified for each one, making it easier to work with gizmos that have a variable number of handles.
* Added support for subgizmos, selectable elements that can be transformed without needing a node of their own. By overriding _subgizmo_intersect_frustum() and/or _subgizmo_intersect_ray() gizmos can define which subgizmos should be selected on a region or click selection. Subgizmo transformations are applied using get/set/commit virtual methods, similar to how handles work.
- JFonS
cfb555a081
- Note: MeshDataResourceEditor is now kind of painful to use, it will be fixed a bit later.
This commit is contained in:
Relintai 2022-08-11 01:24:29 +02:00
parent ed5024d3c3
commit 58539a22b6
44 changed files with 2166 additions and 1376 deletions

View File

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="EditorSpatialGizmo" inherits="SpatialGizmo" version="3.5">
<brief_description>
Custom gizmo for editing Spatial objects.
Gizmo for editing Spatial objects.
</brief_description>
<description>
Custom gizmo that is used for providing custom visualization and editing (handles) for 3D Spatial objects. See [EditorSpatialGizmoPlugin] for more information.
Gizmo that is used for providing custom visualization and editing (handles and subgizmos) for Spatial objects. Can be overridden to create custom gizmos, but for simple gizmos creating a [EditorSpatialGizmoPlugin] is usually recommended.
</description>
<tutorials>
</tutorials>
@ -13,25 +13,26 @@
<return type="void" />
<argument index="0" name="segments" type="PoolVector3Array" />
<description>
Adds the specified [code]segments[/code] to the gizmo's collision shape for picking. Call this function during [method redraw].
Adds the specified [code]segments[/code] to the gizmo's collision shape for picking. Call this method during [method redraw].
</description>
</method>
<method name="add_collision_triangles">
<return type="void" />
<argument index="0" name="triangles" type="TriangleMesh" />
<description>
Adds collision triangles to the gizmo for picking. A [TriangleMesh] can be generated from a regular [Mesh] too. Call this function during [method redraw].
Adds collision triangles to the gizmo for picking. A [TriangleMesh] can be generated from a regular [Mesh] too. Call this method during [method redraw].
</description>
</method>
<method name="add_handles">
<return type="void" />
<argument index="0" name="handles" type="PoolVector3Array" />
<argument index="1" name="material" type="Material" />
<argument index="2" name="billboard" type="bool" default="false" />
<argument index="3" name="secondary" type="bool" default="false" />
<argument index="2" name="ids" type="PoolIntArray">
<argument index="3" name="billboard" type="bool" default="false" />
<argument index="4" name="secondary" type="bool" default="false" />
<description>
Adds a list of handles (points) which can be used to deform the object being edited.
There are virtual functions which will be called upon editing of these handles. Call this function during [method redraw].
Adds a list of handles (points) which can be used to edit the properties of the gizmo's Spatial. The [code]ids[/code] argument can be used to specify a custom identifier for each handle, if an empty [code]Array[/code] is passed, the ids will be assigned automatically from the [code]handles[/code] argument order.
There are virtual methods which will be called upon editing of these handles. Call this method during [method _redraw].
</description>
</method>
<method name="add_lines">
@ -41,17 +42,17 @@
<argument index="2" name="billboard" type="bool" default="false" />
<argument index="3" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )" />
<description>
Adds lines to the gizmo (as sets of 2 points), with a given material. The lines are used for visualizing the gizmo. Call this function during [method redraw].
Adds lines to the gizmo (as sets of 2 points), with a given material. The lines are used for visualizing the gizmo. Call this method during [method redraw].
</description>
</method>
<method name="add_mesh">
<return type="void" />
<argument index="0" name="mesh" type="Mesh" />
<argument index="1" name="billboard" type="bool" default="false" />
<argument index="2" name="skeleton" type="SkinReference" default="null" />
<argument index="3" name="material" type="Material" default="null" />
<argument index="1" name="material" type="Material" default="null" />
<argument index="2" name="transform" type="Transform" default="Transform(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0)" />
<argument index="3" name="skeleton" type="SkinReference" default="null" />
<description>
Adds a mesh to the gizmo with the specified [code]billboard[/code] state, [code]skeleton[/code] and [code]material[/code]. If [code]billboard[/code] is [code]true[/code], the mesh will rotate to always face the camera. Call this function during [method redraw].
Adds a mesh to the gizmo with the specified [code]material[/code], local [code]transform[/code] and [code]skeleton[/code]. Call this method during [method _redraw].
</description>
</method>
<method name="add_unscaled_billboard">
@ -60,7 +61,7 @@
<argument index="1" name="default_scale" type="float" default="1" />
<argument index="2" name="modulate" type="Color" default="Color( 1, 1, 1, 1 )" />
<description>
Adds an unscaled billboard for visualization. Call this function during [method redraw].
Adds an unscaled billboard for visualization and selection. Call this method during [method _redraw].
</description>
</method>
<method name="clear">
@ -71,27 +72,50 @@
</method>
<method name="commit_handle" qualifiers="virtual">
<return type="void" />
<argument index="0" name="index" type="int" />
<argument index="0" name="id" type="int" />
<argument index="1" name="restore" type="Variant" />
<argument index="2" name="cancel" type="bool" default="false" />
<description>
Commit a handle being edited (handles must have been previously added by [method add_handles]).
If the [code]cancel[/code] parameter is [code]true[/code], an option to restore the edited value to the original is provided.
Override this method to commit a handle being edited (handles must have been previously added by [method add_handles]). This usually means creating an [UndoRedo] action for the change, using the current handle value as "do" and the [code]restore[/code] argument as "undo".
If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] value should be directly set, without any [UndoRedo] action.
</description>
</method>
<method name="commit_subgizmos" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="ids" type="PoolIntArray">
</argument>
<argument index="1" name="restore" type="Array">
</argument>
<argument index="2" name="cancel" type="bool" default="false">
</argument>
<description>
Override this method to commit a group of subgizmos being edited (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). This usually means creating an [UndoRedo] action for the change, using the current transforms as "do" and the [code]restore[/code] transforms as "undo".
If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] transforms should be directly set, without any [UndoRedo] action.
</description>
</method>
<method name="get_handle_name" qualifiers="virtual">
<return type="String" />
<argument index="0" name="index" type="int" />
<argument index="0" name="id" type="int" />
<description>
Gets the name of an edited handle (handles must have been previously added by [method add_handles]).
Override this method to return the name of an edited handle (handles must have been previously added by [method add_handles]).
Handles can be named for reference to the user when editing.
</description>
</method>
<method name="get_handle_value" qualifiers="virtual">
<return type="Variant" />
<argument index="0" name="index" type="int" />
<argument index="0" name="id" type="int" />
<description>
Gets actual value of a handle. This value can be anything and used for eventually undoing the motion when calling [method commit_handle].
Override this method to return the current value of a handle. This value will be requested at the start of an edit and used as the [code]restore[/code] argument in [method _commit_handle].
</description>
</method>
<method name="get_subgizmo_transform" qualifiers="virtual">
<return type="Transform">
</return>
<argument index="0" name="id" type="int">
</argument>
<description>
Override this method to return the current transform of a subgizmo. This transform will be requested at the start of an edit and used as the [code]restore[/code] argument in [method _commit_subgizmos].
</description>
</method>
<method name="get_plugin" qualifiers="const">
@ -108,25 +132,73 @@
</method>
<method name="is_handle_highlighted" qualifiers="virtual">
<return type="bool" />
<argument index="0" name="index" type="int" />
<argument index="0" name="id" type="int" />
<description>
Returns [code]true[/code] if the handle at index [code]index[/code] is highlighted by being hovered with the mouse.
Override this method to return [code]true[/code] whenever the given handle should be highlighted in the editor.
</description>
</method>
<method name="redraw" qualifiers="virtual">
<return type="void" />
<description>
This function is called when the [Spatial] this gizmo refers to changes (the [method Spatial.update_gizmo] is called).
Override this method to add all the gizmo elements whenever a gizmo update is requested. It's common to call [method clear] at the beginning of this method and then add visual elements depending on the node's properties.
</description>
</method>
<method name="set_handle" qualifiers="virtual">
<return type="void" />
<argument index="0" name="index" type="int" />
<argument index="0" name="id" type="int" />
<argument index="1" name="camera" type="Camera" />
<argument index="2" name="point" type="Vector2" />
<description>
This function is used when the user drags a gizmo handle (previously added with [method add_handles]) in screen coordinates.
The [Camera] is also provided so screen coordinates can be converted to raycasts.
Override this method to update the node properties when the user drags a gizmo handle (previously added with [method add_handles]). The provided [code]point[/code] is the mouse position in screen coordinates and the [code]camera[/code] can be used to convert it to raycasts.
</description>
</method>
<method name="set_subgizmo_transform" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="id" type="int">
</argument>
<argument index="1" name="transform" type="Transform">
</argument>
<description>
Override this method to update the node properties during subgizmo editing (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). The [code]transform[/code] is given in the Spatial's local coordinate system.
</description>
</method>
<method name="subgizmos_intersect_frustum" qualifiers="virtual">
<return type="PoolIntArray">
</return>
<argument index="0" name="camera" type="Camera">
</argument>
<argument index="1" name="frustum" type="Array">
</argument>
<description>
Override this method to allow selecting subgizmos using mouse drag box selection. Given a [code]camera[/code] and a [code]frustum[/code], this method should return which subgizmos are contained within the frustum. The [code]frustum[/code] argument consists of an [code]Array[/code] with all the [code]Plane[/code]s that make up the selection frustum. The returned value should contain a list of unique subgizmo identifiers, which can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos].
</description>
</method>
<method name="subgizmos_intersect_ray" qualifiers="virtual">
<return type="int">
</return>
<argument index="0" name="camera" type="Camera">
</argument>
<argument index="1" name="point" type="Vector2">
</argument>
<description>
Override this method to allow selecting subgizmos using mouse clicks. Given a [code]camera[/code] and a [code]point[/code] in screen coordinates, this method should return which subgizmo should be selected. The returned value should be a unique subgizmo identifier, which can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos].
</description>
</method>
<method name="get_subgizmo_selection" qualifiers="const">
<return type="PoolIntArray">
</return>
<description>
Returns a list of the currently selected subgizmos. Can be used to highlight selected elements during [method _redraw].
</description>
</method>
<method name="is_subgizmo_selected" qualifiers="const">
<return type="bool">
</return>
<argument index="0" name="arg0" type="int">
</argument>
<description>
Returns [code]true[/code] if the given subgizmo is currently selected. Can be used to highlight selected elements during [method _redraw].
</description>
</method>
<method name="set_hidden">

View File

@ -22,17 +22,34 @@
<method name="can_be_hidden" qualifiers="virtual">
<return type="bool" />
<description>
Override this method to define whether the gizmo can be hidden or not. Returns [code]true[/code] if not overridden.
Override this method to define whether the gizmos handled by this plugin can be hidden or not. Returns [code]true[/code] if not overridden.
</description>
</method>
<method name="commit_handle" qualifiers="virtual">
<return type="void" />
<argument index="0" name="gizmo" type="EditorSpatialGizmo" />
<argument index="1" name="index" type="int" />
<argument index="1" name="id" type="int" />
<argument index="2" name="restore" type="Variant" />
<argument index="3" name="cancel" type="bool" default="false" />
<description>
Override this method to commit gizmo handles. Called for this plugin's active gizmos.
Override this method to commit a handle being edited (handles must have been previously added by [method EditorSpatialGizmo.add_handles] during [method _redraw]). This usually means creating an [UndoRedo] action for the change, using the current handle value as "do" and the [code]restore[/code] argument as "undo".
If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] value should be directly set, without any [UndoRedo] action. Called for this plugin's active gizmos.
</description>
</method>
<method name="commit_subgizmos" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="ids" type="PoolIntArray">
</argument>
<argument index="2" name="restore" type="Array">
</argument>
<argument index="3" name="cancel" type="bool" default="false">
</argument>
<description>
Override this method to commit a group of subgizmos being edited (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). This usually means creating an [UndoRedo] action for the change, using the current transforms as "do" and the [code]restore[/code] transforms as "undo".
If the [code]cancel[/code] argument is [code]true[/code], the [code]restore[/code] transforms should be directly set, without any [UndoRedo] action. Called for this plugin's active gizmos.
</description>
</method>
<method name="create_gizmo" qualifiers="virtual">
@ -76,7 +93,7 @@
<method name="get_handle_name" qualifiers="virtual">
<return type="String" />
<argument index="0" name="gizmo" type="EditorSpatialGizmo" />
<argument index="1" name="index" type="int" />
<argument index="1" name="id" type="int" />
<description>
Override this method to provide gizmo's handle names. Called for this plugin's active gizmos.
</description>
@ -84,9 +101,9 @@
<method name="get_handle_value" qualifiers="virtual">
<return type="Variant" />
<argument index="0" name="gizmo" type="EditorSpatialGizmo" />
<argument index="1" name="index" type="int" />
<argument index="1" name="id" type="int" />
<description>
Gets actual value of a handle from gizmo. Called for this plugin's active gizmos.
Override this method to return the current value of a handle. This value will be requested at the start of an edit and used as the [code]restore[/code] argument in [method _commit_handle]. Called for this plugin's active gizmos.
</description>
</method>
<method name="get_material">
@ -106,8 +123,19 @@
<method name="get_priority" qualifiers="virtual">
<return type="int" />
<description>
Override this method to set the gizmo's priority. Higher values correspond to higher priority. If a gizmo with higher priority conflicts with another gizmo, only the gizmo with higher priority will be used.
All built-in editor gizmos return a priority of [code]-1[/code]. If not overridden, this method will return [code]0[/code], which means custom gizmos will automatically override built-in gizmos.
Override this method to set the gizmo's priority. Gizmos with higher priority will have precedence when processing inputs like handles or subgizmos selection.
All built-in editor gizmos return a priority of [code]-1[/code]. If not overridden, this method will return [code]0[/code], which means custom gizmos will automatically get higher priority than built-in gizmos.
</description>
</method>
<method name="_get_subgizmo_transform" qualifiers="virtual">
<return type="Transform">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="id" type="int">
</argument>
<description>
Override this method to return the current transform of a subgizmo. This transform will be requested at the start of an edit and used in the [code]restore[/code] argument in [method _commit_subgizmos]. Called for this plugin's active gizmos.
</description>
</method>
<method name="has_gizmo" qualifiers="virtual">
@ -120,9 +148,9 @@
<method name="is_handle_highlighted" qualifiers="virtual">
<return type="bool" />
<argument index="0" name="gizmo" type="EditorSpatialGizmo" />
<argument index="1" name="index" type="int" />
<argument index="1" name="id" type="int" />
<description>
Gets whether a handle is highlighted or not. Called for this plugin's active gizmos.
Override this method to return [code]true[/code] whenever to given handle should be highlighted in the editor. Called for this plugin's active gizmos.
</description>
</method>
<method name="is_selectable_when_hidden" qualifiers="virtual">
@ -135,17 +163,56 @@
<return type="void" />
<argument index="0" name="gizmo" type="EditorSpatialGizmo" />
<description>
Callback to redraw the provided gizmo. Called for this plugin's active gizmos.
Override this method to add all the gizmo elements whenever a gizmo update is requested. It's common to call [method EditorSpatialGizmo.clear] at the beginning of this method and then add visual elements depending on the node's properties.
</description>
</method>
<method name="set_handle" qualifiers="virtual">
<return type="void" />
<argument index="0" name="gizmo" type="EditorSpatialGizmo" />
<argument index="1" name="index" type="int" />
<argument index="1" name="id" type="int" />
<argument index="2" name="camera" type="Camera" />
<argument index="3" name="point" type="Vector2" />
<description>
Update the value of a handle after it has been updated. Called for this plugin's active gizmos.
Override this method to update the node's properties when the user drags a gizmo handle (previously added with [method EditorSpatialGizmo.add_handles]). The provided [code]point[/code] is the mouse position in screen coordinates and the [code]camera[/code] can be used to convert it to raycasts. Called for this plugin's active gizmos.
</description>
</method>
<method name="_set_subgizmo_transform" qualifiers="virtual">
<return type="void">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="id" type="int">
</argument>
<argument index="2" name="transform" type="Transform">
</argument>
<description>
Override this method to update the node properties during subgizmo editing (see [method _subgizmos_intersect_ray] and [method _subgizmos_intersect_frustum]). The [code]transform[/code] is given in the Spatial's local coordinate system. Called for this plugin's active gizmos.
</description>
</method>
<method name="_subgizmos_intersect_frustum" qualifiers="virtual">
<return type="PoolIntArray">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="camera" type="Camera">
</argument>
<argument index="2" name="frustum" type="Array">
</argument>
<description>
Override this method to allow selecting subgizmos using mouse drag box selection. Given a [code]camera[/code] and a [code]frustum[/code], this method should return which subgizmos are contained within the frustum. The [code]frustum[/code] argument consists of an [code]Array[/code] with all the [code]Plane[/code]s that make up the selection frustum. The returned value should contain a list of unique subgizmo identifiers, these identifiers can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos]. Called for this plugin's active gizmos.
</description>
</method>
<method name="_subgizmos_intersect_ray" qualifiers="virtual">
<return type="int">
</return>
<argument index="0" name="gizmo" type="EditorSpatialGizmo">
</argument>
<argument index="1" name="camera" type="Camera">
</argument>
<argument index="2" name="point" type="Vector2">
</argument>
<description>
Override this method to allow selecting subgizmos using mouse clicks. Given a [code]camera[/code] and a [code]point[/code] in screen coordinates, this method should return which subgizmo should be selected. The returned value should be a unique subgizmo identifier, which can have any non-negative value and will be used in other virtual methods like [method _get_subgizmo_transform] or [method _commit_subgizmos]. Called for this plugin's active gizmos.
</description>
</method>
</methods>

View File

@ -13,6 +13,29 @@
<link title="All 3D Demos">https://github.com/godotengine/godot-demo-projects/tree/master/3d</link>
</tutorials>
<methods>
<method name="add_gizmo">
<return type="void">
</return>
<argument index="0" name="gizmo" type="SpatialGizmo">
</argument>
<description>
Attach a gizmo to this [code]Spatial[/code].
</description>
</method>
<method name="clear_gizmos">
<return type="void">
</return>
<description>
Clear all gizmos attached to this [code]Spatial[/code].
</description>
</method>
<method name="clear_subgizmo_selection">
<return type="void">
</return>
<description>
Clears subgizmo selection for this node in the editor. Useful when subgizmo IDs become invalid after a property change.
</description>
</method>
<method name="force_update_transform">
<return type="void" />
<description>
@ -26,6 +49,13 @@
This is particularly important for frame-based operations that take place in [method Node._process], rather than [method Node._physics_process]. Examples include [Camera]s focusing on a node, or finding where to fire lasers from on a frame rather than physics tick.
</description>
</method>
<method name="get_gizmos" qualifiers="const">
<return type="Array">
</return>
<description>
Returns all the gizmos attached to this [code]Spatial[/code].
</description>
</method>
<method name="get_parent_spatial" qualifiers="const">
<return type="Spatial" />
<description>
@ -242,17 +272,14 @@
Changes the node's position by the given offset [Vector3] in local space.
</description>
</method>
<method name="update_gizmo">
<method name="update_gizmos">
<return type="void" />
<description>
Updates the [SpatialGizmo] of this node.
Updates all the [SpatialGizmo]s attached to this node.
</description>
</method>
</methods>
<members>
<member name="gizmo" type="SpatialGizmo" setter="set_gizmo" getter="get_gizmo">
The [SpatialGizmo] for this node. Used for example in [EditorSpatialGizmo] as custom visualization and editing handles in Editor.
</member>
<member name="global_rotation" type="Vector3" setter="set_global_rotation" getter="get_global_rotation">
Rotation part of the global transformation in radians, specified in terms of YXZ-Euler angles in the format (X angle, Y angle, Z angle).
[b]Note:[/b] In the mathematical sense, rotation is a matrix and not a vector. The three Euler angles, which are the three independent parameters of the Euler-angle parametrization of the rotation matrix, are stored in a [Vector3] data structure not because the rotation is a vector, but only because [Vector3] exists as a convenient data-structure to store 3 floating-point numbers. Therefore, applying affine operations on the rotation "vector" is not meaningful.
@ -304,7 +331,7 @@
<constants>
<constant name="NOTIFICATION_TRANSFORM_CHANGED" value="2000">
Spatial nodes receives this notification when their global transform changes. This means that either the current or a parent node changed its transform.
In order for [constant NOTIFICATION_TRANSFORM_CHANGED] to work, users first need to ask for it, with [method set_notify_transform]. The notification is also sent if the node is in the editor context and it has a valid gizmo.
In order for [constant NOTIFICATION_TRANSFORM_CHANGED] to work, users first need to ask for it, with [method set_notify_transform]. The notification is also sent if the node is in the editor context and it has at least one valid gizmo.
</constant>
<constant name="NOTIFICATION_ENTER_WORLD" value="41">
Spatial nodes receives this notification when they are registered to new [World] resource.

View File

@ -301,7 +301,7 @@ void PathSpatialGizmo::redraw() {
add_handles(handles, handles_material);
}
if (sec_handles.size()) {
add_handles(sec_handles, handles_material, false, true);
add_handles(sec_handles, handles_material, Vector<int>(), false, true);
}
}
}

View File

@ -258,7 +258,7 @@ void OccluderEditorPlugin::_center() {
undo_redo->add_undo_method(_occluder, "set_transform", old_local_xform);
undo_redo->commit_action();
_occluder->update_gizmo();
_occluder->update_gizmos();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -30,16 +30,15 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "scene/gui/control.h"
#include "editor/editor_plugin.h"
#include "scene/3d/spatial.h"
#include "scene/gui/box_container.h"
#include "scene/gui/container.h"
#include "scene/3d/spatial.h"
#include "editor/editor_plugin.h"
#include "scene/gui/control.h"
#include "scene/3d/skeleton.h"
#include "scene/gui/spin_box.h"
#include "core/reference.h"
#include "core/color.h"
#include "core/dictionary.h"
#include "core/error_macros.h"
@ -52,6 +51,7 @@
#include "core/math/vector3.h"
#include "core/object.h"
#include "core/object_id.h"
#include "core/reference.h"
#include "core/resource.h"
#include "core/rid.h"
#include "core/typedefs.h"
@ -60,6 +60,8 @@
#include "core/vector.h"
#include "editor/editor_scale.h"
#include "editor/spatial_editor_gizmos.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
#include "scene/resources/texture.h"
@ -67,6 +69,7 @@
class Camera;
class SpatialEditor;
class EditorSpatialGizmoPlugin;
class EditorSpatialGizmo;
class ViewportContainer;
class SpatialEditorViewport;
class Environment;
@ -96,96 +99,6 @@ class VSplitContainer;
class Viewport;
class SpinBox;
class EditorSpatialGizmo : public SpatialGizmo {
GDCLASS(EditorSpatialGizmo, SpatialGizmo);
bool selected;
bool instanced;
public:
void set_selected(bool p_selected) { selected = p_selected; }
bool is_selected() const { return selected; }
struct Instance {
RID instance;
Ref<Mesh> mesh;
Ref<Material> material;
Ref<SkinReference> skin_reference;
RID skeleton;
bool billboard;
bool unscaled;
bool can_intersect;
bool extra_margin;
Instance();
~Instance();
void create_instance(Spatial *p_base, bool p_hidden = false);
};
Vector<Vector3> collision_segments;
Ref<TriangleMesh> collision_mesh;
struct Handle {
Vector3 pos;
bool billboard;
};
Vector<Vector3> handles;
Vector<Vector3> secondary_handles;
float selectable_icon_size;
bool billboard_handle;
bool valid;
bool hidden;
Spatial *base;
Vector<Instance> instances;
Spatial *spatial_node;
EditorSpatialGizmoPlugin *gizmo_plugin;
void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Spatial>(p_node)); }
protected:
static void _bind_methods();
public:
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
void add_mesh(const Ref<Mesh> &p_mesh, bool p_billboard = false, const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>(), const Ref<Material> &p_material = Ref<Material>());
void add_collision_segments(const Vector<Vector3> &p_lines);
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1));
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);
virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
void set_spatial_node(Spatial *p_node);
Spatial *get_spatial_node() const { return spatial_node; }
Ref<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 = nullptr, bool p_sec_first = false);
virtual void clear();
virtual void create();
virtual void transform();
virtual void redraw();
virtual void free();
virtual bool is_editable() const;
void set_hidden(bool p_hidden);
void set_plugin(EditorSpatialGizmoPlugin *p_plugin);
EditorSpatialGizmo();
~EditorSpatialGizmo();
};
class ViewportRotationControl : public Control {
GDCLASS(ViewportRotationControl, Control);
@ -339,17 +252,15 @@ private:
struct _RayResult {
Spatial *item;
float depth;
int handle;
_FORCE_INLINE_ bool operator<(const _RayResult &p_rr) const { return depth < p_rr.depth; }
};
void _update_name();
void _compute_edit(const Point2 &p_point);
void _clear_selected();
void _select_clicked(bool p_append, bool p_single, bool p_allow_locked = false);
void _select(Node *p_node, bool p_append, bool p_single);
ObjectID _select_ray(const Point2 &p_pos, bool p_append, bool &r_includes_current, int *r_gizmo_handle = nullptr, bool p_alt_select = false);
void _find_items_at_pos(const Point2 &p_pos, bool &r_includes_current, Vector<_RayResult> &results, bool p_alt_select = false);
void _select_clicked(bool p_allow_locked);
ObjectID _select_ray(const Point2 &p_pos);
void _find_items_at_pos(const Point2 &p_pos, Vector<_RayResult> &r_results, bool p_include_locked);
Vector3 _get_ray_pos(const Vector2 &p_pos) const;
Vector3 _get_ray(const Vector2 &p_pos) const;
Point2 _point_to_screen(const Vector3 &p_point);
@ -361,7 +272,8 @@ private:
Vector3 _get_screen_to_space(const Vector3 &p_vector3);
void _select_region();
bool _gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false);
bool _transform_gizmo_select(const Vector2 &p_screenpos, bool p_highlight_only = false);
void _transform_gizmo_apply(Spatial *p_node, const Transform &p_transform, bool p_local);
void _nav_pan(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative);
void _nav_zoom(Ref<InputEventWithModifiers> p_event, const Vector2 &p_relative);
@ -374,7 +286,6 @@ private:
ObjectID clicked;
Vector<_RayResult> selection_results;
bool clicked_includes_current;
bool clicked_wants_append;
bool selection_in_progress = false;
@ -418,15 +329,12 @@ public:
Vector3 click_ray;
Vector3 click_ray_pos;
Vector3 center;
Vector3 orig_gizmo_pos;
int edited_gizmo;
Point2 mouse_pos;
Point2 original_mouse_pos;
bool snap;
Ref<EditorSpatialGizmo> gizmo;
int gizmo_handle;
Variant gizmo_initial_value;
Vector3 gizmo_initial_pos;
} _edit;
private:
@ -514,6 +422,8 @@ private:
void _project_settings_changed();
Transform _compute_transform(TransformMode p_mode, const Transform &p_original, const Transform &p_original_local, Vector3 p_motion, double p_extra, bool p_local);
protected:
void _notification(int p_what);
static void _bind_methods();
@ -564,6 +474,8 @@ public:
RID sbox_instance_offset;
RID sbox_instance_xray;
RID sbox_instance_xray_offset;
Ref<EditorSpatialGizmo> gizmo;
Map<int, Transform> subgizmos; // map ID -> initial transform
SpatialEditorSelectedItem() {
sp = nullptr;
@ -687,7 +599,9 @@ private:
Ref<SpatialMaterial> plane_gizmo_color_hl[3];
Ref<ShaderMaterial> rotate_gizmo_color_hl[3];
int over_gizmo_handle;
Ref<SpatialGizmo> current_hover_gizmo;
int current_hover_gizmo_handle;
float snap_translate_value;
float snap_rotate_value;
float snap_scale_value;
@ -763,7 +677,6 @@ private:
LineEdit *snap_translate;
LineEdit *snap_rotate;
LineEdit *snap_scale;
PanelContainer *menu_panel;
LineEdit *xform_translate[3];
LineEdit *xform_rotate[3];
@ -814,6 +727,7 @@ private:
Spatial *selected;
void _request_gizmo(Object *p_obj);
void _clear_subgizmo_selection(Object *p_obj = nullptr);
static SpatialEditor *singleton;
@ -823,8 +737,7 @@ private:
void _register_all_gizmos();
bool is_any_freelook_active() const;
void _selection_changed();
void _refresh_menu_icons();
protected:
@ -891,10 +804,16 @@ public:
VSplitContainer *get_shader_split();
Spatial *get_selected() { return selected; }
Spatial *get_single_selected_node() { return selected; }
bool is_current_selected_gizmo(const EditorSpatialGizmo *p_gizmo);
bool is_subgizmo_selected(int p_id);
Vector<int> get_subgizmo_selection();
int get_over_gizmo_handle() const { return over_gizmo_handle; }
void set_over_gizmo_handle(int idx) { over_gizmo_handle = idx; }
Ref<EditorSpatialGizmo> get_current_hover_gizmo() const { return current_hover_gizmo; }
void set_current_hover_gizmo(Ref<EditorSpatialGizmo> p_gizmo) { current_hover_gizmo = p_gizmo; }
void set_current_hover_gizmo_handle(int p_id) { current_hover_gizmo_handle = p_id; }
int get_current_hover_gizmo_handle() const { return current_hover_gizmo_handle; }
void set_can_preview(Camera *p_preview);
void set_message(String p_message, float p_time = 5);
@ -962,50 +881,4 @@ public:
~SpatialEditorPlugin();
};
class EditorSpatialGizmoPlugin : public Resource {
GDCLASS(EditorSpatialGizmoPlugin, Resource);
public:
static const int VISIBLE = 0;
static const int HIDDEN = 1;
static const int ON_TOP = 2;
protected:
int current_state;
List<EditorSpatialGizmo *> current_gizmos;
HashMap<String, Vector<Ref<SpatialMaterial>>> materials;
static void _bind_methods();
virtual bool has_gizmo(Spatial *p_spatial);
virtual Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
public:
void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false);
void create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1));
void create_handle_material(const String &p_name, bool p_billboard = false, const Ref<Texture> &p_icon = nullptr);
void add_material(const String &p_name, Ref<SpatialMaterial> p_material);
Ref<SpatialMaterial> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>());
virtual String get_name() const;
virtual int get_priority() const;
virtual bool can_be_hidden() const;
virtual bool is_selectable_when_hidden() const;
virtual void redraw(EditorSpatialGizmo *p_gizmo);
virtual String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
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_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
void set_state(int p_state);
int get_state() const;
void unregister_gizmo(EditorSpatialGizmo *p_gizmo);
EditorSpatialGizmoPlugin();
virtual ~EditorSpatialGizmoPlugin();
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,8 @@
#include "core/math/vector2.h"
#include "core/math/vector3.h"
#include "core/object.h"
#include "core/ordered_hash_map.h"
#include "core/pool_vector.h"
#include "core/reference.h"
#include "core/ustring.h"
#include "core/variant.h"
@ -49,21 +51,166 @@ class Camera;
class Spatial;
class Timer;
class Transform;
template <class T>
class PoolVector;
class Timer;
class EditorSpatialGizmo : public SpatialGizmo {
GDCLASS(EditorSpatialGizmo, SpatialGizmo);
public:
struct Instance {
RID instance;
Ref<Mesh> mesh;
Ref<Material> material;
Ref<SkinReference> skin_reference;
bool extra_margin;
Transform xform;
Instance();
~Instance();
void create_instance(Spatial *p_base, bool p_hidden = false);
};
bool selected;
Vector<Vector3> collision_segments;
Ref<TriangleMesh> collision_mesh;
Vector<Vector3> handles;
Vector<int> handle_ids;
Vector<Vector3> secondary_handles;
Vector<int> secondary_handle_ids;
float selectable_icon_size;
bool billboard_handle;
bool valid;
bool hidden;
Vector<Instance> instances;
Spatial *spatial_node;
void _set_spatial_node(Node *p_node) { set_spatial_node(Object::cast_to<Spatial>(p_node)); }
protected:
static void _bind_methods();
EditorSpatialGizmoPlugin *gizmo_plugin;
public:
void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1));
void add_mesh(const Ref<ArrayMesh> &p_mesh, const Ref<Material> &p_material = Ref<Material>(), const Transform &p_xform = Transform(), const Ref<SkinReference> &p_skin_reference = Ref<SkinReference>());
void add_collision_segments(const Vector<Vector3> &p_lines);
void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh);
void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1, const Color &p_modulate = Color(1, 1, 1));
void add_handles(const Vector<Vector3> &p_handles, const Ref<Material> &p_material, const Vector<int> &p_ids = Vector<int>(), bool p_billboard = false, bool p_secondary = false);
void add_solid_box(Ref<Material> &p_material, Vector3 p_size, Vector3 p_position = Vector3(), const Transform &p_xform = Transform());
virtual bool is_handle_highlighted(int p_id) const;
virtual String get_handle_name(int p_id) const;
virtual Variant get_handle_value(int p_id);
virtual void set_handle(int p_id, Camera *p_camera, const Point2 &p_point);
virtual void commit_handle(int p_id, const Variant &p_restore, bool p_cancel = false);
virtual int subgizmos_intersect_ray(Camera *p_camera, const Vector2 &p_point) const;
virtual Vector<int> subgizmos_intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum) const;
virtual Transform get_subgizmo_transform(int p_id) const;
virtual void set_subgizmo_transform(int p_id, Transform p_transform) const;
virtual void commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform> &p_restore, bool p_cancel = false) const;
void set_selected(bool p_selected) { selected = p_selected; }
bool is_selected() const { return selected; }
void set_spatial_node(Spatial *p_node);
Spatial *get_spatial_node() const { return spatial_node; }
Ref<EditorSpatialGizmoPlugin> get_plugin() const { return gizmo_plugin; }
bool intersect_frustum(const Camera *p_camera, const Vector<Plane> &p_frustum);
void handles_intersect_ray(Camera *p_camera, const Vector2 &p_point, bool p_shift_pressed, int &r_id);
bool intersect_ray(Camera *p_camera, const Point2 &p_point, Vector3 &r_pos, Vector3 &r_normal);
bool is_subgizmo_selected(int p_id) const;
Vector<int> get_subgizmo_selection() const;
virtual void clear();
virtual void create();
virtual void transform();
virtual void redraw();
virtual void free();
virtual bool is_editable() const;
void set_hidden(bool p_hidden);
void set_plugin(EditorSpatialGizmoPlugin *p_plugin);
EditorSpatialGizmo();
~EditorSpatialGizmo();
};
class EditorSpatialGizmoPlugin : public Resource {
GDCLASS(EditorSpatialGizmoPlugin, Resource);
public:
static const int VISIBLE = 0;
static const int HIDDEN = 1;
static const int ON_TOP = 2;
protected:
int current_state;
List<EditorSpatialGizmo *> current_gizmos;
HashMap<String, Vector<Ref<SpatialMaterial>>> materials;
static void _bind_methods();
virtual bool has_gizmo(Spatial *p_spatial);
virtual Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
public:
void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false);
void create_icon_material(const String &p_name, const Ref<Texture> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1));
void create_handle_material(const String &p_name, bool p_billboard = false, const Ref<Texture> &p_icon = nullptr);
void add_material(const String &p_name, Ref<SpatialMaterial> p_material);
Ref<SpatialMaterial> get_material(const String &p_name, const Ref<EditorSpatialGizmo> &p_gizmo = Ref<EditorSpatialGizmo>());
virtual String get_gizmo_name() const;
virtual int get_priority() const;
virtual bool can_be_hidden() const;
virtual bool is_selectable_when_hidden() const;
virtual void redraw(EditorSpatialGizmo *p_gizmo);
virtual bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_id) const;
virtual String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
virtual Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
virtual void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
virtual void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
virtual int subgizmos_intersect_ray(const EditorSpatialGizmo *p_gizmo, Camera *p_camera, const Vector2 &p_point) const;
virtual Vector<int> subgizmos_intersect_frustum(const EditorSpatialGizmo *p_gizmo, const Camera *p_camera, const Vector<Plane> &p_frustum) const;
virtual Transform get_subgizmo_transform(const EditorSpatialGizmo *p_gizmo, int p_id) const;
virtual void set_subgizmo_transform(const EditorSpatialGizmo *p_gizmo, int p_id, Transform p_transform) const;
virtual void commit_subgizmos(const EditorSpatialGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform> &p_restore, bool p_cancel = false) const;
Ref<EditorSpatialGizmo> get_gizmo(Spatial *p_spatial);
void set_state(int p_state);
int get_state() const;
void unregister_gizmo(EditorSpatialGizmo *p_gizmo);
EditorSpatialGizmoPlugin();
virtual ~EditorSpatialGizmoPlugin();
};
class LightSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
GDCLASS(LightSpatialGizmoPlugin, EditorSpatialGizmoPlugin);
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
void redraw(EditorSpatialGizmo *p_gizmo);
LightSpatialGizmoPlugin();
@ -74,13 +221,13 @@ class AudioStreamPlayer3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
void redraw(EditorSpatialGizmo *p_gizmo);
AudioStreamPlayer3DSpatialGizmoPlugin();
@ -91,7 +238,7 @@ class ListenerSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -104,13 +251,13 @@ class CameraSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
void redraw(EditorSpatialGizmo *p_gizmo);
CameraSpatialGizmoPlugin();
@ -121,7 +268,7 @@ class MeshInstanceSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
bool can_be_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -134,7 +281,7 @@ class Sprite3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
bool can_be_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -147,7 +294,7 @@ class Label3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
bool can_be_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -163,7 +310,7 @@ class Position3DSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -175,7 +322,7 @@ class PhysicalBoneSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -187,7 +334,7 @@ class RayCastSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -199,7 +346,7 @@ class SpringArmSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -211,7 +358,7 @@ class VehicleWheelSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -223,14 +370,14 @@ class SoftBodySpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
bool is_selectable_when_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
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);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel);
bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int idx) const;
SoftBodySpatialGizmoPlugin();
@ -241,14 +388,14 @@ class VisibilityNotifierGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
VisibilityNotifierGizmoPlugin();
};
@ -258,7 +405,7 @@ class CPUParticlesGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
bool is_selectable_when_hidden() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -270,14 +417,14 @@ class ReflectionProbeGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
ReflectionProbeGizmoPlugin();
};
@ -287,7 +434,7 @@ class CollisionObjectGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -299,14 +446,14 @@ class CollisionShapeSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_idx) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_idx) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_idx, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_idx, const Variant &p_restore, bool p_cancel = false);
String get_handle_name(const EditorSpatialGizmo *p_gizmo, int p_id) const;
Variant get_handle_value(EditorSpatialGizmo *p_gizmo, int p_id) const;
void set_handle(EditorSpatialGizmo *p_gizmo, int p_id, Camera *p_camera, const Point2 &p_point);
void commit_handle(EditorSpatialGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel = false);
CollisionShapeSpatialGizmoPlugin();
};
@ -316,7 +463,7 @@ class CollisionPolygonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
CollisionPolygonSpatialGizmoPlugin();
@ -334,7 +481,7 @@ class NavigationMeshSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -369,7 +516,7 @@ protected:
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);
@ -415,10 +562,10 @@ class RoomSpatialGizmo : public EditorSpatialGizmo {
Room *_room = nullptr;
public:
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);
virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
virtual String get_handle_name(int p_id) const;
virtual Variant get_handle_value(int p_id);
virtual void set_handle(int p_id, Camera *p_camera, const Point2 &p_point);
virtual void commit_handle(int p_id, const Variant &p_restore, bool p_cancel = false);
virtual void redraw();
RoomSpatialGizmo(Room *p_room = nullptr);
@ -429,7 +576,7 @@ class RoomGizmoPlugin : public EditorSpatialGizmoPlugin {
protected:
virtual bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
@ -447,10 +594,10 @@ class PortalSpatialGizmo : public EditorSpatialGizmo {
Color _color_portal_back;
public:
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);
virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
virtual String get_handle_name(int p_id) const;
virtual Variant get_handle_value(int p_id);
virtual void set_handle(int p_id, Camera *p_camera, const Point2 &p_point);
virtual void commit_handle(int p_id, const Variant &p_restore, bool p_cancel = false);
virtual void redraw();
PortalSpatialGizmo(Portal *p_portal = nullptr);
@ -461,7 +608,7 @@ class PortalGizmoPlugin : public EditorSpatialGizmoPlugin {
protected:
virtual bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);
@ -493,10 +640,10 @@ class OccluderSpatialGizmo : public EditorSpatialGizmo {
void _redraw_poly(bool p_hole, const Vector<Vector2> &p_pts, const PoolVector<Vector2> &p_pts_raw);
public:
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);
virtual void commit_handle(int p_idx, const Variant &p_restore, bool p_cancel = false);
virtual String get_handle_name(int p_id) const;
virtual Variant get_handle_value(int p_id);
virtual void set_handle(int p_id, Camera *p_camera, const Point2 &p_point);
virtual void commit_handle(int p_id, const Variant &p_restore, bool p_cancel = false);
virtual void redraw();
OccluderSpatialGizmo(Occluder *p_occluder = nullptr);
@ -507,7 +654,7 @@ class OccluderGizmoPlugin : public EditorSpatialGizmoPlugin {
protected:
virtual bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
Ref<EditorSpatialGizmo> create_gizmo(Spatial *p_spatial);

View File

@ -39,8 +39,8 @@ void MDIEdPlugin::edit(Object *object) {
if (mdi) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = mdi->get_gizmo();
Ref<MDIGizmo> c = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(mdi);
Ref<MDIGizmo> c = get_gizmo_from(current_mesh_data_instance);
if (g.is_valid() && c.is_valid()) {
g->transfer_state_from(c);
@ -68,57 +68,57 @@ String MDIEdPlugin::get_name() const {
void MDIEdPlugin::set_translate() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_translate();
}
}
void MDIEdPlugin::set_scale() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_scale();
}
}
void MDIEdPlugin::set_rotate() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_rotate();
}
}
void MDIEdPlugin::set_axis_x(bool on) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_axis_x(on);
}
}
void MDIEdPlugin::set_axis_y(bool on) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_axis_y(on);
}
}
void MDIEdPlugin::set_axis_z(bool on) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_axis_z(on);
}
}
void MDIEdPlugin::set_selection_mode_vertex() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_selection_mode_vertex();
}
}
void MDIEdPlugin::set_selection_mode_edge() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_selection_mode_edge();
}
}
void MDIEdPlugin::set_selection_mode_face() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_selection_mode_face();
}
}
@ -137,7 +137,7 @@ bool MDIEdPlugin::forward_spatial_gui_input(int index, Camera *camera, const Ref
}
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
if (g.is_valid() && g->forward_spatial_gui_input(index, camera, p_event)) {
return true;
}
@ -148,217 +148,231 @@ bool MDIEdPlugin::forward_spatial_gui_input(int index, Camera *camera, const Ref
void MDIEdPlugin::add_box() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->add_box();
}
}
void MDIEdPlugin::add_triangle() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->add_triangle();
}
}
void MDIEdPlugin::add_quad() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->add_quad();
}
}
void MDIEdPlugin::add_triangle_at() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->add_triangle_at();
}
}
void MDIEdPlugin::add_quad_at() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->add_quad_at();
}
}
void MDIEdPlugin::split() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->split();
}
}
void MDIEdPlugin::disconnect_action() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->disconnect_action();
}
}
void MDIEdPlugin::create_face() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->create_face();
}
}
void MDIEdPlugin::delete_selected() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->delete_selected();
}
}
void MDIEdPlugin::generate_normals() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->generate_normals();
}
}
void MDIEdPlugin::remove_doubles() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->remove_doubles();
}
}
void MDIEdPlugin::merge_optimize() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->merge_optimize();
}
}
void MDIEdPlugin::generate_tangents() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->generate_tangents();
}
}
void MDIEdPlugin::connect_to_first_selected() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->connect_to_first_selected();
}
}
void MDIEdPlugin::connect_to_avg() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->connect_to_avg();
}
}
void MDIEdPlugin::connect_to_last_selected() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->connect_to_last_selected();
}
}
void MDIEdPlugin::mark_seam() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->mark_seam();
}
}
void MDIEdPlugin::unmark_seam() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->unmark_seam();
}
}
void MDIEdPlugin::apply_seam() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->apply_seam();
}
}
void MDIEdPlugin::uv_unwrap() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->uv_unwrap();
}
}
void MDIEdPlugin::set_pivot_averaged() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_pivot_averaged();
}
}
void MDIEdPlugin::set_pivot_mdi_origin() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_translate();
}
}
void MDIEdPlugin::set_pivot_world_origin() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->set_pivot_world_origin();
}
}
void MDIEdPlugin::visual_indicator_outline_set(bool on) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->visual_indicator_outline_set(on);
}
}
void MDIEdPlugin::visual_indicator_seam_set(bool on) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->visual_indicator_seam_set(on);
}
}
void MDIEdPlugin::visual_indicator_handle_set(bool on) {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->visual_indicator_handle_set(on);
}
}
void MDIEdPlugin::select_all() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->select_all();
}
}
void MDIEdPlugin::handle_selection_type_front() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->handle_selection_type_front();
}
}
void MDIEdPlugin::handle_selection_type_back() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->handle_selection_type_back();
}
}
void MDIEdPlugin::handle_selection_type_all() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->handle_selection_type_all();
}
}
void MDIEdPlugin::extrude() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->extrude();
}
}
void MDIEdPlugin::clean_mesh() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->clean_mesh();
}
}
void MDIEdPlugin::flip_selected_faces() {
if (current_mesh_data_instance) {
Ref<MDIGizmo> g = current_mesh_data_instance->get_gizmo();
Ref<MDIGizmo> g = get_gizmo_from(current_mesh_data_instance);
g->flip_selected_faces();
}
}
Ref<MDIGizmo> MDIEdPlugin::get_gizmo_from(MeshDataInstance *mdi) {
Vector<Ref<SpatialGizmo>> gizmos = mdi->get_gizmos();
for (int i = 0; i < gizmos.size(); ++i) {
Ref<SpatialGizmo> g = gizmos[i];
if (g.is_valid()) {
return g;
}
}
return Ref<SpatialGizmo>();
}
MDIEdPlugin::MDIEdPlugin(EditorNode *p_node) {
editor = p_node;

View File

@ -111,6 +111,8 @@ public:
void flip_selected_faces();
Ref<MDIGizmo> get_gizmo_from(MeshDataInstance *mdi);
MDIEdPlugin(EditorNode *p_node);
~MDIEdPlugin();

View File

@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/spatial_editor_gizmos.h"
#include "core/math/basis.h"
#include "core/math/transform.h"

View File

@ -26,7 +26,7 @@ SOFTWARE.
#include "mdi_ed_plugin.h"
#include "mdi_gizmo.h"
String MDIGizmoPlugin::get_name() const {
String MDIGizmoPlugin::get_gizmo_name() const {
return "MDIGizmo";
}
int MDIGizmoPlugin::get_priority() const {

View File

@ -23,7 +23,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/spatial_editor_gizmos.h"
class MDIEdPlugin;
@ -32,7 +32,7 @@ class MDIGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
void _init();
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
bool is_handle_highlighted(const EditorSpatialGizmo *p_gizmo, int p_idx) const;

View File

@ -68,7 +68,7 @@ void NavigationMeshEditor::_bake_pressed() {
NavigationMeshGenerator::get_singleton()->clear(node->get_navigation_mesh());
NavigationMeshGenerator::get_singleton()->bake(node->get_navigation_mesh(), node);
node->update_gizmo();
node->update_gizmos();
}
void NavigationMeshEditor::_clear_pressed() {
@ -80,7 +80,7 @@ void NavigationMeshEditor::_clear_pressed() {
bake_info->set_text("");
if (node) {
node->update_gizmo();
node->update_gizmos();
}
}

View File

@ -1607,7 +1607,7 @@ void ModuleEditorInspectorPluginSkeleton::parse_begin(Object *p_object) {
}
void ModuleEditorInspectorPluginSkeleton::set_rest_mode_toggled(const bool p_pressed) {
if (SpatialEditor::get_singleton()->get_selected()->get_class() == "Skeleton" && skel_editor) {
if (SpatialEditor::get_singleton()->get_single_selected_node()->get_class() == "Skeleton" && skel_editor) {
skel_editor->set_rest_mode_toggled(p_pressed);
}
}

View File

@ -34,7 +34,7 @@
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_plugin.h"
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/spatial_editor_gizmos.h"
#include "scene/3d/camera.h"
#include "scene/3d/mesh_instance.h"
#include "scene/3d/skeleton.h"

View File

@ -71,7 +71,7 @@ bool ModuleSkeletonSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) {
return Object::cast_to<Skeleton>(p_spatial) != NULL;
}
String ModuleSkeletonSpatialGizmoPlugin::get_name() const {
String ModuleSkeletonSpatialGizmoPlugin::get_gizmo_name() const {
return "Skeleton";
}
@ -265,5 +265,5 @@ void ModuleSkeletonSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) {
}
Ref<ArrayMesh> m = surface_tool->commit();
p_gizmo->add_mesh(m, false, skel->register_skin(Ref<Skin>()));
p_gizmo->add_mesh(m, Ref<Material>(), Transform(), skel->register_skin(Ref<Skin>()));
}

View File

@ -30,7 +30,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "editor/plugins/spatial_editor_plugin.h"
#include "editor/spatial_editor_gizmos.h"
#include "scene/3d/camera.h"
#include "core/local_vector.h"
@ -46,7 +46,7 @@ class ModuleSkeletonSpatialGizmoPlugin : public EditorSpatialGizmoPlugin {
public:
bool has_gizmo(Spatial *p_spatial);
String get_name() const;
String get_gizmo_name() const;
int get_priority() const;
void redraw(EditorSpatialGizmo *p_gizmo);

View File

@ -807,7 +807,7 @@ uint32_t AudioStreamPlayer3D::get_area_mask() const {
void AudioStreamPlayer3D::set_emission_angle_enabled(bool p_enable) {
emission_angle_enabled = p_enable;
update_gizmo();
update_gizmos();
}
bool AudioStreamPlayer3D::is_emission_angle_enabled() const {
@ -817,7 +817,7 @@ bool AudioStreamPlayer3D::is_emission_angle_enabled() const {
void AudioStreamPlayer3D::set_emission_angle(float p_angle) {
ERR_FAIL_COND(p_angle < 0 || p_angle > 90);
emission_angle = p_angle;
update_gizmo();
update_gizmos();
_change_notify("emission_angle");
}

View File

@ -186,7 +186,7 @@ void Camera::set_perspective(float p_fovy_degrees, float p_z_near, float p_z_far
mode = PROJECTION_PERSPECTIVE;
VisualServer::get_singleton()->camera_set_perspective(camera, fov, near, far);
update_gizmo();
update_gizmos();
force_change = false;
}
void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
@ -202,7 +202,7 @@ void Camera::set_orthogonal(float p_size, float p_z_near, float p_z_far) {
force_change = false;
VisualServer::get_singleton()->camera_set_orthogonal(camera, size, near, far);
update_gizmo();
update_gizmos();
}
void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p_z_far) {
@ -219,7 +219,7 @@ void Camera::set_frustum(float p_size, Vector2 p_offset, float p_z_near, float p
force_change = false;
VisualServer::get_singleton()->camera_set_frustum(camera, size, frustum_offset, near, far);
update_gizmo();
update_gizmos();
}
void Camera::set_projection(Camera::Projection p_mode) {
@ -773,7 +773,7 @@ void ClippedCamera::_notification(int p_what) {
}
if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
update_gizmo();
update_gizmos();
}
}

View File

@ -123,7 +123,7 @@ void CollisionPolygon::set_polygon(const Vector<Point2> &p_polygon) {
_build_polygon();
}
update_configuration_warning();
update_gizmo();
update_gizmos();
}
Vector<Point2> CollisionPolygon::get_polygon() const {
@ -137,7 +137,7 @@ AABB CollisionPolygon::get_item_rect() const {
void CollisionPolygon::set_depth(float p_depth) {
depth = p_depth;
_build_polygon();
update_gizmo();
update_gizmos();
}
float CollisionPolygon::get_depth() const {
@ -146,7 +146,7 @@ float CollisionPolygon::get_depth() const {
void CollisionPolygon::set_disabled(bool p_disabled) {
disabled = p_disabled;
update_gizmo();
update_gizmos();
if (parent) {
parent->shape_owner_set_disabled(owner_id, p_disabled);

View File

@ -104,7 +104,7 @@ void CollisionShape::_notification(int p_what) {
}
void CollisionShape::resource_changed(RES res) {
update_gizmo();
update_gizmos();
}
String CollisionShape::get_configuration_warning() const {
@ -168,7 +168,7 @@ void CollisionShape::set_shape(const Ref<Shape> &p_shape) {
if (!shape.is_null()) {
shape->register_owner(this);
}
update_gizmo();
update_gizmos();
if (parent) {
parent->shape_owner_clear_shapes(owner_id);
if (shape.is_valid()) {
@ -189,7 +189,7 @@ Ref<Shape> CollisionShape::get_shape() const {
void CollisionShape::set_disabled(bool p_disabled) {
disabled = p_disabled;
update_gizmo();
update_gizmos();
if (parent) {
parent->shape_owner_set_disabled(owner_id, p_disabled);
}

View File

@ -379,7 +379,7 @@ void Label3D::_im_update() {
_shape();
triangle_mesh.unref();
update_gizmo();
update_gizmos();
pending_update = false;
}

View File

@ -41,7 +41,7 @@ void Light::set_param(Param p_param, float p_value) {
VS::get_singleton()->light_set_param(light, VS::LightParam(p_param), p_value);
if (p_param == PARAM_SPOT_ANGLE || p_param == PARAM_RANGE) {
update_gizmo();
update_gizmos();
if (p_param == PARAM_SPOT_ANGLE) {
_change_notify("spot_angle");
@ -90,7 +90,7 @@ void Light::set_color(const Color &p_color) {
color = p_color;
VS::get_singleton()->light_set_color(light, p_color);
// The gizmo color depends on the light color, so update it.
update_gizmo();
update_gizmos();
}
Color Light::get_color() const {
return color;

View File

@ -149,7 +149,7 @@ void MeshInstance::set_mesh(const Ref<Mesh> &p_mesh) {
set_base(RID());
}
update_gizmo();
update_gizmos();
_change_notify();
}

View File

@ -67,7 +67,7 @@ void NavigationMeshInstance::set_enabled(bool p_enabled) {
}
}
update_gizmo();
update_gizmos();
}
bool NavigationMeshInstance::is_enabled() const {
@ -194,7 +194,7 @@ void NavigationMeshInstance::set_navigation_mesh(const Ref<NavigationMesh> &p_na
emit_signal("navigation_mesh_changed");
update_gizmo();
update_gizmos();
update_configuration_warning();
}
@ -294,7 +294,7 @@ void NavigationMeshInstance::_bind_methods() {
}
void NavigationMeshInstance::_changed_callback(Object *p_changed, const char *p_prop) {
update_gizmo();
update_gizmos();
update_configuration_warning();
}

View File

@ -37,7 +37,7 @@
#include "servers/visual_server.h"
void Occluder::resource_changed(RES res) {
update_gizmo();
update_gizmos();
}
void Occluder::set_shape(const Ref<OccluderShape> &p_shape) {
@ -58,7 +58,7 @@ void Occluder::set_shape(const Ref<OccluderShape> &p_shape) {
}
}
update_gizmo();
update_gizmos();
update_configuration_warning();
}
Ref<OccluderShape> Occluder::get_shape() const {
@ -151,7 +151,7 @@ void Occluder::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
if (PortalOcclusionCuller::_redraw_gizmo) {
PortalOcclusionCuller::_redraw_gizmo = false;
update_gizmo();
update_gizmos();
}
} break;
}

View File

@ -39,7 +39,7 @@ void Path::_notification(int p_what) {
void Path::_curve_changed() {
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
update_gizmo();
update_gizmos();
}
if (is_inside_tree()) {
emit_signal("curve_changed");

View File

@ -2267,9 +2267,7 @@ bool PhysicalBone::_set(const StringName &p_name, const Variant &p_value) {
if (joint_data) {
if (joint_data->_set(p_name, p_value, joint)) {
#ifdef TOOLS_ENABLED
if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
}
update_gizmos();
#endif
return true;
}
@ -2600,9 +2598,7 @@ void PhysicalBone::set_joint_type(JointType p_joint_type) {
#ifdef TOOLS_ENABLED
_change_notify();
if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
}
update_gizmos();
#endif
}
@ -2620,9 +2616,7 @@ void PhysicalBone::set_joint_offset(const Transform &p_offset) {
set_ignore_transform_notification(false);
#ifdef TOOLS_ENABLED
if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
}
update_gizmos();
#endif
}
@ -2641,9 +2635,7 @@ void PhysicalBone::set_body_offset(const Transform &p_offset) {
set_ignore_transform_notification(false);
#ifdef TOOLS_ENABLED
if (get_gizmo().is_valid()) {
get_gizmo()->redraw();
}
update_gizmos();
#endif
}

View File

@ -371,7 +371,7 @@ void HingeJoint::set_param(Param p_param, float p_value) {
PhysicsServer::get_singleton()->hinge_joint_set_param(get_joint(), PhysicsServer::HingeJointParam(p_param), p_value);
}
update_gizmo();
update_gizmos();
}
float HingeJoint::get_param(Param p_param) const {
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
@ -385,7 +385,7 @@ void HingeJoint::set_flag(Flag p_flag, bool p_value) {
PhysicsServer::get_singleton()->hinge_joint_set_flag(get_joint(), PhysicsServer::HingeJointFlag(p_flag), p_value);
}
update_gizmo();
update_gizmos();
}
bool HingeJoint::get_flag(Flag p_flag) const {
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
@ -519,7 +519,7 @@ void SliderJoint::set_param(Param p_param, float p_value) {
if (get_joint().is_valid()) {
PhysicsServer::get_singleton()->slider_joint_set_param(get_joint(), PhysicsServer::SliderJointParam(p_param), p_value);
}
update_gizmo();
update_gizmos();
}
float SliderJoint::get_param(Param p_param) const {
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
@ -625,7 +625,7 @@ void ConeTwistJoint::set_param(Param p_param, float p_value) {
PhysicsServer::get_singleton()->cone_twist_joint_set_param(get_joint(), PhysicsServer::ConeTwistJointParam(p_param), p_value);
}
update_gizmo();
update_gizmos();
}
float ConeTwistJoint::get_param(Param p_param) const {
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
@ -881,7 +881,7 @@ void Generic6DOFJoint::set_param_x(Param p_param, float p_value) {
PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
}
update_gizmo();
update_gizmos();
}
float Generic6DOFJoint::get_param_x(Param p_param) const {
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
@ -894,7 +894,7 @@ void Generic6DOFJoint::set_param_y(Param p_param, float p_value) {
if (get_joint().is_valid()) {
PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
}
update_gizmo();
update_gizmos();
}
float Generic6DOFJoint::get_param_y(Param p_param) const {
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
@ -907,7 +907,7 @@ void Generic6DOFJoint::set_param_z(Param p_param, float p_value) {
if (get_joint().is_valid()) {
PhysicsServer::get_singleton()->generic_6dof_joint_set_param(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisParam(p_param), p_value);
}
update_gizmo();
update_gizmos();
}
float Generic6DOFJoint::get_param_z(Param p_param) const {
ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
@ -920,7 +920,7 @@ void Generic6DOFJoint::set_flag_x(Flag p_flag, bool p_enabled) {
if (get_joint().is_valid()) {
PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_X, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
}
update_gizmo();
update_gizmos();
}
bool Generic6DOFJoint::get_flag_x(Flag p_flag) const {
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
@ -933,7 +933,7 @@ void Generic6DOFJoint::set_flag_y(Flag p_flag, bool p_enabled) {
if (get_joint().is_valid()) {
PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Y, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
}
update_gizmo();
update_gizmos();
}
bool Generic6DOFJoint::get_flag_y(Flag p_flag) const {
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);
@ -946,7 +946,7 @@ void Generic6DOFJoint::set_flag_z(Flag p_flag, bool p_enabled) {
if (get_joint().is_valid()) {
PhysicsServer::get_singleton()->generic_6dof_joint_set_flag(get_joint(), Vector3::AXIS_Z, PhysicsServer::G6DOFJointAxisFlag(p_flag), p_enabled);
}
update_gizmo();
update_gizmos();
}
bool Generic6DOFJoint::get_flag_z(Flag p_flag) const {
ERR_FAIL_INDEX_V(p_flag, FLAG_MAX, false);

View File

@ -123,7 +123,7 @@ void Portal::set_point(int p_idx, const Vector2 &p_point) {
_pts_local_raw.set(p_idx, p_point);
_sanitize_points();
update_gizmo();
update_gizmos();
}
void Portal::set_points(const PoolVector<Vector2> &p_points) {
@ -132,7 +132,7 @@ void Portal::set_points(const PoolVector<Vector2> &p_points) {
if (is_inside_tree()) {
portal_update();
update_gizmo();
update_gizmos();
}
}
@ -170,7 +170,7 @@ void Portal::_notification(int p_what) {
// we can't calculate world points until we have entered the tree
portal_update();
update_gizmo();
update_gizmos();
} break;
case NOTIFICATION_EXIT_WORLD: {
@ -188,7 +188,7 @@ void Portal::_notification(int p_what) {
// and needs 'resyncing' to the global scale of the portal node.
// We really only need to do this when Z scale is changed, but it is easier codewise
// to always change it, unless we have evidence this is a performance problem.
update_gizmo();
update_gizmos();
} break;
}
}
@ -204,7 +204,7 @@ bool Portal::get_portal_active() const {
void Portal::set_use_default_margin(bool p_use) {
_use_default_margin = p_use;
update_gizmo();
update_gizmos();
}
bool Portal::get_use_default_margin() const {
@ -216,7 +216,7 @@ void Portal::set_portal_margin(real_t p_margin) {
if (!_use_default_margin) {
// give visual feedback in the editor for the portal margin zone
update_gizmo();
update_gizmos();
}
}
@ -343,7 +343,7 @@ void Portal::flip() {
_sanitize_points();
portal_update();
update_gizmo();
update_gizmos();
}
bool Portal::create_from_mesh_instance(const MeshInstance *p_mi) {

View File

@ -40,7 +40,7 @@
void RayCast::set_cast_to(const Vector3 &p_point) {
cast_to = p_point;
update_gizmo();
update_gizmos();
if (Engine::get_singleton()->is_editor_hint()) {
if (is_inside_tree()) {
@ -102,7 +102,7 @@ Vector3 RayCast::get_collision_normal() const {
void RayCast::set_enabled(bool p_enabled) {
enabled = p_enabled;
update_gizmo();
update_gizmos();
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(p_enabled);
@ -373,7 +373,7 @@ void RayCast::_update_debug_shape_vertices() {
void RayCast::set_debug_shape_thickness(const int p_debug_shape_thickness) {
debug_shape_thickness = p_debug_shape_thickness;
update_gizmo();
update_gizmos();
if (Engine::get_singleton()->is_editor_hint()) {
if (is_inside_tree()) {

View File

@ -94,7 +94,7 @@ void ReflectionProbe::set_extents(const Vector3 &p_extents) {
VS::get_singleton()->reflection_probe_set_extents(probe, extents);
VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
_change_notify("extents");
update_gizmo();
update_gizmos();
}
Vector3 ReflectionProbe::get_extents() const {
return extents;
@ -112,7 +112,7 @@ void ReflectionProbe::set_origin_offset(const Vector3 &p_extents) {
VS::get_singleton()->reflection_probe_set_origin_offset(probe, origin_offset);
_change_notify("origin_offset");
update_gizmo();
update_gizmos();
}
Vector3 ReflectionProbe::get_origin_offset() const {
return origin_offset;

View File

@ -412,7 +412,7 @@ void RoomManager::_update_portal_gizmos(Spatial *p_node) {
Portal *portal = Object::cast_to<Portal>(p_node);
if (portal) {
portal->update_gizmo();
portal->update_gizmos();
}
// recurse
@ -856,7 +856,7 @@ void RoomManager::_third_pass_rooms(const LocalVector<Portal *> &p_portals) {
if (!_convert_room_hull_final(room, p_portals)) {
found_errors = true;
}
room->update_gizmo();
room->update_gizmos();
room->update_configuration_warning();
}
@ -1028,7 +1028,7 @@ void RoomManager::_autolink_portals(Spatial *p_roomlist, LocalVector<Portal *> &
#ifdef TOOLS_ENABLED
portal->_warning_autolink_failed = true;
portal->update_gizmo();
portal->update_gizmos();
#endif
}
} // for portal
@ -1190,7 +1190,7 @@ void RoomManager::_check_portal_for_warnings(Portal *p_portal, const AABB &p_roo
p_portal->_warning_autolink_failed = false;
if (changed) {
p_portal->update_gizmo();
p_portal->update_gizmos();
}
#endif
}
@ -1620,7 +1620,7 @@ bool RoomManager::_room_regenerate_bound(Room *p_room) {
}
p_room->_bound_mesh_data = md;
p_room->update_gizmo();
p_room->update_gizmos();
return true;
}
@ -1963,7 +1963,7 @@ void RoomManager::_update_gizmos_recursive(Node *p_node) {
Portal *portal = Object::cast_to<Portal>(p_node);
if (portal) {
portal->update_gizmo();
portal->update_gizmos();
}
for (int n = 0; n < p_node->get_child_count(); n++) {

View File

@ -490,7 +490,7 @@ void Skeleton::add_bone(const String &p_name) {
process_order_dirty = true;
version++;
_make_dirty();
update_gizmo();
update_gizmos();
}
int Skeleton::find_bone(const String &p_name) const {
for (int i = 0; i < bones.size(); i++) {
@ -1373,7 +1373,7 @@ Skeleton::~Skeleton() {
void Skeleton::set_selected_bone(int p_bone) {
selected_bone = p_bone;
update_gizmo();
update_gizmos();
return;
}
@ -1445,5 +1445,5 @@ void Skeleton::remove_bone(const int p_bone_idx) {
property_list_changed_notify();
_make_dirty();
update_gizmo();
update_gizmos();
}

View File

@ -78,7 +78,7 @@ SpatialGizmo::SpatialGizmo() {
void Spatial::_notify_dirty() {
#ifdef TOOLS_ENABLED
if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
if ((!data.gizmos.empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
#else
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
@ -111,7 +111,7 @@ void Spatial::_propagate_transform_changed(Spatial *p_origin) {
E->get()->_propagate_transform_changed(p_origin);
}
#ifdef TOOLS_ENABLED
if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
if ((!data.gizmos.empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
#else
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
#endif
@ -200,15 +200,16 @@ void Spatial::_notification(int p_what) {
}
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this);
get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
if (!data.gizmo_disabled) {
if (data.gizmo.is_valid()) {
data.gizmo->create();
if (!data.gizmos_disabled) {
for (int i = 0; i < data.gizmos.size(); i++) {
data.gizmos.write[i]->create();
if (is_visible_in_tree()) {
data.gizmo->redraw();
data.gizmos.write[i]->redraw();
}
data.gizmo->transform();
data.gizmos.write[i]->transform();
}
}
}
@ -217,10 +218,7 @@ void Spatial::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_WORLD: {
#ifdef TOOLS_ENABLED
if (data.gizmo.is_valid()) {
data.gizmo->free();
data.gizmo.unref();
}
clear_gizmos();
#endif
if (get_script_instance()) {
@ -234,8 +232,8 @@ void Spatial::_notification(int p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
#ifdef TOOLS_ENABLED
if (data.gizmo.is_valid()) {
data.gizmo->transform();
for (int i = 0; i < data.gizmos.size(); i++) {
data.gizmos.write[i]->transform();
}
#endif
} break;
@ -539,77 +537,121 @@ Vector3 Spatial::get_scale() const {
return data.scale;
}
void Spatial::update_gizmo() {
void Spatial::update_gizmos() {
#ifdef TOOLS_ENABLED
if (!is_inside_world()) {
return;
}
if (!data.gizmo.is_valid()) {
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
}
if (!data.gizmo.is_valid()) {
if (data.gizmos.empty()) {
return;
}
if (data.gizmo_dirty) {
return;
}
data.gizmo_dirty = true;
MessageQueue::get_singleton()->push_call(this, "_update_gizmo");
data.gizmos_dirty = true;
MessageQueue::get_singleton()->push_call(this, "_update_gizmos");
#endif
}
void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) {
void Spatial::clear_subgizmo_selection() {
#ifdef TOOLS_ENABLED
if (data.gizmo_disabled) {
if (!is_inside_world()) {
return;
}
if (data.gizmo.is_valid() && is_inside_world()) {
data.gizmo->free();
if (data.gizmos.empty()) {
return;
}
data.gizmo = p_gizmo;
if (data.gizmo.is_valid() && is_inside_world()) {
data.gizmo->create();
if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_clear_subgizmo_selection, this);
}
#endif
}
void Spatial::add_gizmo(Ref<SpatialGizmo> p_gizmo) {
#ifdef TOOLS_ENABLED
if (data.gizmos_disabled || p_gizmo.is_null()) {
return;
}
data.gizmos.push_back(p_gizmo);
if (p_gizmo.is_valid() && is_inside_world()) {
p_gizmo->create();
if (is_visible_in_tree()) {
data.gizmo->redraw();
p_gizmo->redraw();
}
data.gizmo->transform();
p_gizmo->transform();
}
#endif
}
Ref<SpatialGizmo> Spatial::get_gizmo() const {
void Spatial::remove_gizmo(Ref<SpatialGizmo> p_gizmo) {
#ifdef TOOLS_ENABLED
return data.gizmo;
int idx = data.gizmos.find(p_gizmo);
if (idx != -1) {
p_gizmo->free();
data.gizmos.remove(idx);
}
#endif
}
void Spatial::clear_gizmos() {
#ifdef TOOLS_ENABLED
for (int i = 0; i < data.gizmos.size(); i++) {
data.gizmos.write[i]->free();
}
data.gizmos.clear();
#endif
}
Vector<Variant> Spatial::get_gizmos_bind() const {
Vector<Variant> ret;
#ifdef TOOLS_ENABLED
for (int i = 0; i < data.gizmos.size(); i++) {
ret.push_back(data.gizmos[i].get_ref_ptr());
}
#endif
return ret;
}
Vector<Ref<SpatialGizmo>> Spatial::get_gizmos() const {
#ifdef TOOLS_ENABLED
return data.gizmos;
#else
return Ref<SpatialGizmo>();
return Vector<Ref<SpatialGizmo>>();
#endif
}
void Spatial::_update_gizmo() {
void Spatial::_update_gizmos() {
#ifdef TOOLS_ENABLED
if (!is_inside_world()) {
if (data.gizmos_disabled || !is_inside_world() || !data.gizmos_dirty) {
return;
}
data.gizmo_dirty = false;
if (data.gizmo.is_valid()) {
data.gizmos_dirty = false;
for (int i = 0; i < data.gizmos.size(); i++) {
if (is_visible_in_tree()) {
data.gizmo->redraw();
data.gizmos.write[i]->redraw();
} else {
data.gizmo->clear();
data.gizmos.write[i]->clear();
}
}
#endif
}
void Spatial::set_disable_gizmo(bool p_enabled) {
void Spatial::set_disable_gizmos(bool p_enabled) {
#ifdef TOOLS_ENABLED
data.gizmo_disabled = p_enabled;
if (!p_enabled && data.gizmo.is_valid()) {
data.gizmo = Ref<SpatialGizmo>();
data.gizmos_disabled = p_enabled;
if (!p_enabled) {
clear_gizmos();
}
#endif
}
@ -656,9 +698,11 @@ void Spatial::_propagate_visibility_changed() {
notification(NOTIFICATION_VISIBILITY_CHANGED);
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
_change_notify("visible");
#ifdef TOOLS_ENABLED
if (data.gizmo.is_valid()) {
_update_gizmo();
if (!data.gizmos.empty()) {
data.gizmos_dirty = true;
_update_gizmos();
}
#endif
@ -890,11 +934,13 @@ void Spatial::_bind_methods() {
ClassDB::bind_method(D_METHOD("force_update_transform"), &Spatial::force_update_transform);
ClassDB::bind_method(D_METHOD("_update_gizmo"), &Spatial::_update_gizmo);
ClassDB::bind_method(D_METHOD("_update_gizmos"), &Spatial::_update_gizmos);
ClassDB::bind_method(D_METHOD("update_gizmo"), &Spatial::update_gizmo);
ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Spatial::set_gizmo);
ClassDB::bind_method(D_METHOD("get_gizmo"), &Spatial::get_gizmo);
ClassDB::bind_method(D_METHOD("update_gizmos"), &Spatial::update_gizmos);
ClassDB::bind_method(D_METHOD("add_gizmo", "gizmo"), &Spatial::add_gizmo);
ClassDB::bind_method(D_METHOD("get_gizmos"), &Spatial::get_gizmos_bind);
ClassDB::bind_method(D_METHOD("clear_gizmos"), &Spatial::clear_gizmos);
ClassDB::bind_method(D_METHOD("clear_subgizmo_selection"), &Spatial::clear_subgizmo_selection);
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Spatial::set_visible);
ClassDB::bind_method(D_METHOD("is_visible"), &Spatial::is_visible);
@ -948,7 +994,6 @@ void Spatial::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform");
ADD_GROUP("Visibility", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo");
ADD_SIGNAL(MethodInfo("visibility_changed"));
ADD_SIGNAL(MethodInfo("gameplay_entered"));
@ -973,8 +1018,8 @@ Spatial::Spatial() :
data.client_physics_interpolation_data = nullptr;
#ifdef TOOLS_ENABLED
data.gizmo_disabled = false;
data.gizmo_dirty = false;
data.gizmos_disabled = false;
data.gizmos_dirty = false;
#endif
data.notify_local_transform = false;
data.notify_transform = false;

View File

@ -107,14 +107,14 @@ class Spatial : public Node {
ClientPhysicsInterpolationData *client_physics_interpolation_data;
#ifdef TOOLS_ENABLED
Ref<SpatialGizmo> gizmo;
bool gizmo_disabled : 1;
bool gizmo_dirty : 1;
Vector<Ref<SpatialGizmo>> gizmos;
bool gizmos_disabled : 1;
bool gizmos_dirty : 1;
#endif
} data;
void _update_gizmo();
void _update_gizmos();
void _notify_dirty();
void _propagate_transform_changed(Spatial *p_origin);
@ -189,10 +189,14 @@ public:
void set_disable_scale(bool p_enabled);
bool is_scale_disabled() const;
void set_disable_gizmo(bool p_enabled);
void update_gizmo();
void set_gizmo(const Ref<SpatialGizmo> &p_gizmo);
Ref<SpatialGizmo> get_gizmo() const;
void set_disable_gizmos(bool p_enabled);
void update_gizmos();
void clear_subgizmo_selection();
Vector<Ref<SpatialGizmo>> get_gizmos() const;
Vector<Variant> get_gizmos_bind() const;
void add_gizmo(Ref<SpatialGizmo> p_gizmo);
void remove_gizmo(Ref<SpatialGizmo> p_gizmo);
void clear_gizmos();
_FORCE_INLINE_ bool is_inside_world() const {
return data.inside_world;

View File

@ -92,7 +92,7 @@ float SpringArm::get_length() const {
void SpringArm::set_length(float p_length) {
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_collisions_hint())) {
update_gizmo();
update_gizmos();
}
spring_length = p_length;

View File

@ -183,7 +183,7 @@ void SpriteBase3D::_queue_update() {
}
triangle_mesh.unref();
update_gizmo();
update_gizmos();
pending_update = true;
call_deferred(SceneStringNames::get_singleton()->_im_update);

View File

@ -150,7 +150,7 @@ void VehicleWheel::_update(PhysicsDirectBodyState *s) {
void VehicleWheel::set_radius(float p_radius) {
m_wheelRadius = p_radius;
update_gizmo();
update_gizmos();
}
float VehicleWheel::get_radius() const {
@ -159,7 +159,7 @@ float VehicleWheel::get_radius() const {
void VehicleWheel::set_suspension_rest_length(float p_length) {
m_suspensionRestLength = p_length;
update_gizmo();
update_gizmos();
}
float VehicleWheel::get_suspension_rest_length() const {
return m_suspensionRestLength;

View File

@ -105,7 +105,7 @@ void VisibilityNotifier::set_aabb(const AABB &p_aabb) {
}
_change_notify("aabb");
update_gizmo();
update_gizmos();
}
AABB VisibilityNotifier::get_aabb() const {

View File

@ -142,6 +142,7 @@ SceneStringNames::SceneStringNames() {
_spatial_editor_group = StaticCString::create("_spatial_editor_group");
_request_gizmo = StaticCString::create("_request_gizmo");
_clear_subgizmo_selection = StaticCString::create("_clear_subgizmo_selection");
offset = StaticCString::create("offset");
unit_offset = StaticCString::create("unit_offset");

View File

@ -160,6 +160,7 @@ public:
StringName _spatial_editor_group;
StringName _request_gizmo;
StringName _clear_subgizmo_selection;
StringName offset;
StringName unit_offset;