EditorNode3DGizmoPlugin
A class used by the editor to define Node3D gizmo types.
EditorNode3DGizmoPlugin.swift:14class EditorNode3DGizmoPlugin
EditorNode3DGizmoPlugin
allows you to define a new type of Gizmo. There are two main ways to do so: extending EditorNode3DGizmoPlugin
for the simpler gizmos, or creating a new EditorNode3DGizmo
type. See the tutorial in the documentation for more info.
To use EditorNode3DGizmoPlugin
, register it using the addNode3dGizmoPlugin(_:)
method first.
Superclasses
class Resource
Base class for serializable objects.
Citizens in SwiftGodot
Conformances
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable<ID>
A class of types whose instances hold the value of an entity with stable identity.
protocol VariantRepresentable
Types that conform to VariantRepresentable can be stored directly in
Variant
with no conversion. These include all of the Variant types from Godot (for exampleGString
,Rect
,Plane
), Godot objects (those that subclass SwiftGodot.Object) as well as the built-in Swift types UInt8, Int64 and Double.protocol VariantStorable
Types that conform to VariantStorable can be stored in a Variant and can be extracted back out of a Variant.
Type members
Instance members
func addMaterial(name: String, material: StandardMaterial3D?
) Adds a new material to the internal material list for the plugin. It can then be accessed with
getMaterial(name:gizmo:)
. Should not be overridden.func createHandleMaterial(name: String, billboard: Bool, texture: Texture2D?
) Creates a handle material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with
getMaterial(name:gizmo:)
and used inaddHandles(_:material:ids:billboard:secondary:)
. Should not be overridden.func createIconMaterial(name: String, texture: Texture2D?, onTop: Bool, color: Color
) Creates an icon material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with
getMaterial(name:gizmo:)
and used inaddUnscaledBillboard(material:defaultScale:modulate:)
. Should not be overridden.func createMaterial(name: String, color: Color, billboard: Bool, onTop: Bool, useVertexColor: Bool
) Creates an unshaded material with its variants (selected and/or editable) and adds them to the internal material list. They can then be accessed with
getMaterial(name:gizmo:)
and used inaddMesh(_:material:transform:skeleton:)
andaddLines(_:material:billboard:modulate:)
. Should not be overridden.func getMaterial(name: String, gizmo: EditorNode3DGizmo?
) -> StandardMaterial3D? Gets material from the internal list of materials. If an
EditorNode3DGizmo
is provided, it will try to get the corresponding variant (selected and/or editable).
Show implementation details (17)
Hide implementation details
func _canBeHidden(
) -> Bool Override this method to define whether the gizmos handled by this plugin can be hidden or not. Returns
true
if not overridden.func _commitHandle(gizmo: EditorNode3DGizmo?, handleId: Int32, secondary: Bool, restore: Variant, cancel: Bool
) Override this method to commit a handle being edited (handles must have been previously added by
addHandles(_:material:ids:billboard:secondary:)
during_redraw(gizmo:)
). This usually means creating anUndoRedo
action for the change, using the current handle value as “do” and therestore
argument as “undo”.func _commitSubgizmos(gizmo: EditorNode3DGizmo?, ids: PackedInt32Array, restores: VariantCollection<Transform3D>, cancel: Bool
) Override this method to commit a group of subgizmos being edited (see
_subgizmosIntersectRay(gizmo:camera:screenPos:)
and_subgizmosIntersectFrustum(gizmo:camera:frustumPlanes:)
). This usually means creating anUndoRedo
action for the change, using the current transforms as “do” and therestores
transforms as “undo”.func _createGizmo(forNode3d: Node3D?
) -> EditorNode3DGizmo? Override this method to return a custom
EditorNode3DGizmo
for the spatial nodes of your choice, returnnull
for the rest of nodes. See also_hasGizmo(forNode3d:)
.func _getGizmoName(
) -> String Override this method to provide the name that will appear in the gizmo visibility menu.
func _getHandleName(gizmo: EditorNode3DGizmo?, handleId: Int32, secondary: Bool
) -> String Override this method to provide gizmo’s handle names. The
secondary
argument istrue
when the requested handle is secondary (seeaddHandles(_:material:ids:billboard:secondary:)
for more information). Called for this plugin’s active gizmos.func _getHandleValue(gizmo: EditorNode3DGizmo?, handleId: Int32, secondary: Bool
) -> Variant 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
restore
argument in_commitHandle(gizmo:handleId:secondary:restore:cancel:)
.func _getPriority(
) -> Int32 Override this method to set the gizmo’s priority. Gizmos with higher priority will have precedence when processing inputs like handles or subgizmos selection.
func _getSubgizmoTransform(gizmo: EditorNode3DGizmo?, subgizmoId: Int32
) -> Transform3D Override this method to return the current transform of a subgizmo. As with all subgizmo methods, the transform should be in local space respect to the gizmo’s Node3D. This transform will be requested at the start of an edit and used in the
restore
argument in_commitSubgizmos(gizmo:ids:restores:cancel:)
. Called for this plugin’s active gizmos.func _hasGizmo(forNode3d: Node3D?
) -> Bool Override this method to define which Node3D nodes have a gizmo from this plugin. Whenever a
Node3D
node is added to a scene this method is called, if it returnstrue
the node gets a genericEditorNode3DGizmo
assigned and is added to this plugin’s list of active gizmos.func _isHandleHighlighted(gizmo: EditorNode3DGizmo?, handleId: Int32, secondary: Bool
) -> Bool Override this method to return
true
whenever to given handle should be highlighted in the editor. Thesecondary
argument istrue
when the requested handle is secondary (seeaddHandles(_:material:ids:billboard:secondary:)
for more information). Called for this plugin’s active gizmos.func _isSelectableWhenHidden(
) -> Bool Override this method to define whether Node3D with this gizmo should be selectable even when the gizmo is hidden.
func _redraw(gizmo: EditorNode3DGizmo?
) Override this method to add all the gizmo elements whenever a gizmo update is requested. It’s common to call
clear
at the beginning of this method and then add visual elements depending on the node’s properties.func _setHandle(gizmo: EditorNode3DGizmo?, handleId: Int32, secondary: Bool, camera: Camera3D?, screenPos: Vector2
) Override this method to update the node’s properties when the user drags a gizmo handle (previously added with
addHandles(_:material:ids:billboard:secondary:)
). The providedscreenPos
is the mouse position in screen coordinates and thecamera
can be used to convert it to raycasts.func _setSubgizmoTransform(gizmo: EditorNode3DGizmo?, subgizmoId: Int32, transform: Transform3D
) Override this method to update the node properties during subgizmo editing (see
_subgizmosIntersectRay(gizmo:camera:screenPos:)
and_subgizmosIntersectFrustum(gizmo:camera:frustumPlanes:)
). Thetransform
is given in the Node3D’s local coordinate system. Called for this plugin’s active gizmos.func _subgizmosIntersectFrustum(gizmo: EditorNode3DGizmo?, camera: Camera3D?, frustumPlanes: VariantCollection<Plane>
) -> PackedInt32Array Override this method to allow selecting subgizmos using mouse drag box selection. Given a
camera
andfrustumPlanes
, this method should return which subgizmos are contained within the frustums. ThefrustumPlanes
argument consists of an array with all thePlane
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_getSubgizmoTransform(gizmo:subgizmoId:)
or_commitSubgizmos(gizmo:ids:restores:cancel:)
. Called for this plugin’s active gizmos.func _subgizmosIntersectRay(gizmo: EditorNode3DGizmo?, camera: Camera3D?, screenPos: Vector2
) -> Int32 Override this method to allow selecting subgizmos using mouse clicks. Given a
camera
and ascreenPos
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_getSubgizmoTransform(gizmo:subgizmoId:)
or_commitSubgizmos(gizmo:ids:restores:cancel:)
. Called for this plugin’s active gizmos.