Spatial¶
Inherited By: ARVRAnchor, ARVRController, ARVROrigin, AudioStreamPlayer3D, BoneAttachment, Camera, CollisionObject, CollisionPolygon, CollisionShape, CullInstance, GridMap, Joint, Listener, LOD, MergeGroup, Navigation, NavigationMeshInstance, Occluder, Path, PathFollow, Portal, Position3D, ProximityGroup, RayCast, RemoteTransform, Room, RoomGroup, RoomManager, ShapeCast, Skeleton, SpringArm, VehicleWheel
Most basic 3D game object, parent of all 3D-related nodes.
Description¶
Most basic 3D game object, with a 3D Transform and visibility settings. All other 3D game objects inherit from Spatial. Use Spatial as a parent node to move, scale, rotate and show/hide children in a 3D project.
Affine operations (rotate, scale, translate) happen in parent's local coordinate system, unless the Spatial object is set as top-level. Affine operations in this coordinate system correspond to direct affine operations on the Spatial's transform. The word local below refers to this coordinate system. The coordinate system that is attached to the Spatial object itself is referred to as object-local coordinate system.
Note: Unless otherwise specified, all methods that have angle parameters must have angles specified as radians. To convert degrees to radians, use @GDScript.deg2rad.
Tutorials¶
Properties¶
|
||
|
||
|
||
|
||
|
||
|
||
|
Methods¶
void |
|
get_parent_spatial ( ) const |
|
get_world ( ) const |
|
void |
global_rotate ( Vector3 axis, float angle ) |
void |
global_scale ( Vector3 scale ) |
void |
global_translate ( Vector3 offset ) |
void |
hide ( ) |
is_local_transform_notification_enabled ( ) const |
|
is_scale_disabled ( ) const |
|
is_set_as_toplevel ( ) const |
|
is_transform_notification_enabled ( ) const |
|
is_visible_in_tree ( ) const |
|
void |
|
void |
look_at_from_position ( Vector3 position, Vector3 target, Vector3 up ) |
void |
orthonormalize ( ) |
void |
|
void |
rotate_object_local ( Vector3 axis, float angle ) |
void |
|
void |
|
void |
|
void |
scale_object_local ( Vector3 scale ) |
void |
set_as_toplevel ( bool enable ) |
void |
set_disable_scale ( bool disable ) |
void |
set_identity ( ) |
void |
set_ignore_transform_notification ( bool enabled ) |
void |
set_notify_local_transform ( bool enable ) |
void |
set_notify_transform ( bool enable ) |
void |
show ( ) |
void |
|
void |
translate_object_local ( Vector3 offset ) |
void |
update_gizmo ( ) |
Signals¶
gameplay_entered ( )
Emitted by portal system gameplay monitor when a node enters the gameplay area.
gameplay_exited ( )
Emitted by portal system gameplay monitor when a node exits the gameplay area.
visibility_changed ( )
Emitted when node visibility changes.
Enumerations¶
enum MergingMode:
MergingMode MERGING_MODE_INHERIT = 0
Inherits merging mode from the node's parent. For the root node, it is equivalent to MERGING_MODE_ON. Default.
MergingMode MERGING_MODE_OFF = 1
Turn off merging in this node and children set to MERGING_MODE_INHERIT.
MergingMode MERGING_MODE_ON = 2
Turn on merging in this node and children set to MERGING_MODE_INHERIT.
Constants¶
NOTIFICATION_TRANSFORM_CHANGED = 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 NOTIFICATION_TRANSFORM_CHANGED to work, users first need to ask for it, with set_notify_transform. The notification is also sent if the node is in the editor context and it has a valid gizmo.
NOTIFICATION_ENTER_WORLD = 41
Spatial nodes receives this notification when they are registered to new World resource.
NOTIFICATION_EXIT_WORLD = 42
Spatial nodes receives this notification when they are unregistered from current World resource.
NOTIFICATION_VISIBILITY_CHANGED = 43
Spatial nodes receives this notification when their visibility changes.
NOTIFICATION_ENTER_GAMEPLAY = 45
Spatial nodes receives this notification if the portal system gameplay monitor detects they have entered the gameplay area.
NOTIFICATION_EXIT_GAMEPLAY = 46
Spatial nodes receives this notification if the portal system gameplay monitor detects they have exited the gameplay area.
Property Descriptions¶
SpatialGizmo gizmo
void set_gizmo ( SpatialGizmo value )
SpatialGizmo get_gizmo ( )
The SpatialGizmo for this node. Used for example in EditorSpatialGizmo as custom visualization and editing handles in Editor.
Vector3 global_position
Global position of this node. This is a forward-compatible alias for global_translation.
Vector3 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).
Note: 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.
Transform global_transform
World space (global) Transform of this node.
Vector3 global_translation
Global position of this node. This is equivalent to global_transform.origin
.
float lod_range = 10.0
Determines the threshold distance at which this node will be shown or hidden when this node is parented by a LOD node.
For example, a first child with a range of 2
will be shown from distance 0 to 2. A second child with a range of 5
will be shown from distance 2 to 7, etc.
MergingMode merging_mode = 0
void set_merging_mode ( MergingMode value )
MergingMode get_merging_mode ( )
The merging mode determines whether merging features of the engine (MergeGroup and RoomManager) will attempt to operate on branches of the scene tree.
The default mode inherited from the scene tree root is MERGING_MODE_ON.
Note: Merging mode determines whether the merging is allowed to be performed. It does not guarantee that merging will occur, which depends on whether there are suitable matching objects.
Vector3 position
Local position of this node. This is a forward-compatible alias for translation.
Vector3 rotation
Rotation part of the local transformation in radians, specified in terms of YXZ-Euler angles in the format (X angle, Y angle, Z angle).
Note: 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.
Vector3 rotation_degrees = Vector3( 0, 0, 0 )
Rotation part of the local transformation in degrees, specified in terms of YXZ-Euler angles in the format (X angle, Y angle, Z angle).
Vector3 scale = Vector3( 1, 1, 1 )
Scale part of the local transformation.
Note: Mixed negative scales in 3D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Redot, the scale values will either be all positive or all negative.
Note: Not all nodes are visually scaled by the scale property. For example, Lights are not visually affected by scale.
Transform transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
Local space Transform of this node, with respect to the parent node.
Vector3 translation = Vector3( 0, 0, 0 )
Local translation of this node.
bool visible = true
If true
, this node is drawn. The node is only visible if all of its ancestors are visible as well (in other words, is_visible_in_tree must return true
).
Method Descriptions¶
void force_update_transform ( )
Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations.
Transform get_global_transform_interpolated ( )
When using physics interpolation, there will be circumstances in which you want to know the interpolated (displayed) transform of a node rather than the standard transform (which may only be accurate to the most recent physics tick).
This is particularly important for frame-based operations that take place in Node._process, rather than Node._physics_process. Examples include Cameras focusing on a node, or finding where to fire lasers from on a frame rather than physics tick.
Note: This function creates an interpolation pump on the Spatial the first time it is called, which can respond to physics interpolation resets. If you get problems with "streaking" when initially following a Spatial, be sure to call get_global_transform_interpolated at least once before resetting the Spatial physics interpolation.
Spatial get_parent_spatial ( ) const
Returns the parent Spatial, or an empty Object if no parent exists or parent is not of type Spatial.
World get_world ( ) const
Returns the current World resource this Spatial node is registered to.
void global_rotate ( Vector3 axis, float angle )
Rotates the global (world) transformation around axis, a unit Vector3, by specified angle in radians. The rotation axis is in global coordinate system.
void global_scale ( Vector3 scale )
Scales the global (world) transformation by the given Vector3 scale factors.
void global_translate ( Vector3 offset )
Moves the global (world) transformation by Vector3 offset. The offset is in global coordinate system.
void hide ( )
Disables rendering of this node. Changes visible to false
.
bool is_local_transform_notification_enabled ( ) const
Returns whether node notifies about its local transformation changes. Spatial will not propagate this by default.
bool is_scale_disabled ( ) const
Returns whether this node uses a scale of (1, 1, 1)
or its local transformation scale.
bool is_set_as_toplevel ( ) const
Returns whether this node is set as Toplevel, that is whether it ignores its parent nodes transformations.
bool is_transform_notification_enabled ( ) const
Returns whether the node notifies about its global and local transformation changes. Spatial will not propagate this by default.
bool is_visible_in_tree ( ) const
Returns true
if the node is present in the SceneTree, its visible property is true
and all its ancestors are also visible. If any ancestor is hidden, this node will not be visible in the scene tree.
void look_at ( Vector3 target, Vector3 up )
Rotates the node so that the local forward axis (-Z) points toward the target
position.
The local up axis (+Y) points as close to the up
vector as possible while staying perpendicular to the local forward axis. The resulting transform is orthogonal, and the scale is preserved. Non-uniform scaling may not work correctly.
The target
position cannot be the same as the node's position, the up
vector cannot be zero, and the direction from the node's position to the target
vector cannot be parallel to the up
vector.
Operations take place in global space.
void look_at_from_position ( Vector3 position, Vector3 target, Vector3 up )
Moves the node to the specified position
, and then rotates itself to point toward the target
as per look_at. Operations take place in global space.
void orthonormalize ( )
Resets this node's transformations (like scale, skew and taper) preserving its rotation and translation by performing Gram-Schmidt orthonormalization on this node's Transform.
void rotate ( Vector3 axis, float angle )
Rotates the local transformation around axis, a unit Vector3, by specified angle in radians.
void rotate_object_local ( Vector3 axis, float angle )
Rotates the local transformation around axis, a unit Vector3, by specified angle in radians. The rotation axis is in object-local coordinate system.
void rotate_x ( float angle )
Rotates the local transformation around the X axis by angle in radians.
void rotate_y ( float angle )
Rotates the local transformation around the Y axis by angle in radians.
void rotate_z ( float angle )
Rotates the local transformation around the Z axis by angle in radians.
void scale_object_local ( Vector3 scale )
Scales the local transformation by given 3D scale factors in object-local coordinate system.
void set_as_toplevel ( bool enable )
Makes the node ignore its parents transformations. Node transformations are only in global space.
void set_disable_scale ( bool disable )
Sets whether the node uses a scale of (1, 1, 1)
or its local transformation scale. Changes to the local transformation scale are preserved.
void set_identity ( )
Reset all transformations for this node (sets its Transform to the identity matrix).
void set_ignore_transform_notification ( bool enabled )
Sets whether the node ignores notification that its transformation (global or local) changed.
void set_notify_local_transform ( bool enable )
Sets whether the node notifies about its local transformation changes. Spatial will not propagate this by default.
void set_notify_transform ( bool enable )
Sets whether the node notifies about its global and local transformation changes. Spatial will not propagate this by default, unless it is in the editor context and it has a valid gizmo.
void show ( )
Enables rendering of this node. Changes visible to true
.
Vector3 to_global ( Vector3 local_point ) const
Transforms local_point
from this node's local space to world space.
Vector3 to_local ( Vector3 global_point ) const
Transforms global_point
from world space to this node's local space.
void translate ( Vector3 offset )
Changes the node's position by the given offset Vector3.
Note that the translation offset
is affected by the node's scale, so if scaled by e.g. (10, 1, 1)
, a translation by an offset of (2, 0, 0)
would actually add 20 (2 * 10
) to the X coordinate.
void translate_object_local ( Vector3 offset )
Changes the node's position by the given offset Vector3 in local space.
void update_gizmo ( )
Updates the SpatialGizmo of this node.