2014-02-09 22:10:30 -03:00
|
|
|
/**************************************************************************/
|
2020-03-26 18:49:16 -03:00
|
|
|
/* node_3d.cpp */
|
2014-02-09 22:10:30 -03:00
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-05 00:50:27 +01:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
#include "node_3d.h"
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2024-05-26 19:39:28 +02:00
|
|
|
#include "core/math/transform_interpolator.h"
|
2021-05-09 18:23:20 +02:00
|
|
|
#include "scene/3d/visual_instance_3d.h"
|
2021-08-12 18:05:59 -05:00
|
|
|
#include "scene/main/viewport.h"
|
2022-01-02 15:33:17 +00:00
|
|
|
#include "scene/property_utils.h"
|
2014-02-09 22:10:30 -03:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
possible algorithms:
|
|
|
|
|
|
|
|
Algorithm 1: (current)
|
|
|
|
|
|
|
|
definition of invalidation: global is invalid
|
|
|
|
|
|
|
|
1) If a node sets a LOCAL, it produces an invalidation of everything above
|
2021-10-28 15:43:36 +02:00
|
|
|
. a) If above is invalid, don't keep invalidating upwards
|
2014-02-09 22:10:30 -03:00
|
|
|
2) If a node sets a GLOBAL, it is converted to LOCAL (and forces validation of everything pending below)
|
|
|
|
|
2021-03-12 19:05:16 +05:30
|
|
|
drawback: setting/reading globals is useful and used very often, and using affine inverses is slow
|
2014-02-09 22:10:30 -03:00
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
Algorithm 2: (no longer current)
|
|
|
|
|
|
|
|
definition of invalidation: NONE dirty, LOCAL dirty, GLOBAL dirty
|
|
|
|
|
|
|
|
1) If a node sets a LOCAL, it must climb the tree and set it as GLOBAL dirty
|
2021-10-28 15:43:36 +02:00
|
|
|
. a) marking GLOBALs as dirty up all the tree must be done always
|
2014-02-09 22:10:30 -03:00
|
|
|
2) If a node sets a GLOBAL, it marks local as dirty, and that's all?
|
|
|
|
|
|
|
|
//is clearing the dirty state correct in this case?
|
|
|
|
|
|
|
|
drawback: setting a local down the tree forces many tree walks often
|
|
|
|
|
|
|
|
--
|
|
|
|
|
|
|
|
future: no idea
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
Node3DGizmo::Node3DGizmo() {
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::_notify_dirty() {
|
2017-08-09 08:18:07 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
|
2017-08-09 08:18:07 -03:00
|
|
|
#else
|
2017-01-12 20:35:46 -03:00
|
|
|
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2017-08-09 08:18:07 -03:00
|
|
|
#endif
|
2014-11-05 21:20:42 -03:00
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::_update_local_transform() const {
|
2022-06-25 11:23:24 +02:00
|
|
|
// This function is called when the local transform (data.local_transform) is dirty and the right value is contained in the Euler rotation and scale.
|
|
|
|
data.local_transform.basis.set_euler_scale(data.euler_rotation, data.scale, data.euler_rotation_order);
|
2023-05-17 01:44:41 +02:00
|
|
|
_clear_dirty_bits(DIRTY_LOCAL_TRANSFORM);
|
2022-06-25 11:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::_update_rotation_and_scale() const {
|
|
|
|
// This function is called when the Euler rotation (data.euler_rotation) is dirty and the right value is contained in the local transform
|
|
|
|
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
|
2023-05-17 01:44:41 +02:00
|
|
|
_clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
|
2023-05-12 13:53:15 +02:00
|
|
|
}
|
2022-06-25 11:23:24 +02:00
|
|
|
|
2023-05-12 13:53:15 +02:00
|
|
|
void Node3D::_propagate_transform_changed_deferred() {
|
|
|
|
if (is_inside_tree() && !xform_change.in_list()) {
|
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::_propagate_transform_changed(Node3D *p_origin) {
|
2014-11-05 21:20:42 -03:00
|
|
|
if (!is_inside_tree()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-06-13 10:04:27 +01:00
|
|
|
for (uint32_t n = 0; n < data.node3d_children.size(); n++) {
|
|
|
|
Node3D *s = data.node3d_children[n];
|
|
|
|
|
|
|
|
// Don't propagate to a toplevel.
|
|
|
|
if (!s->data.top_level) {
|
|
|
|
s->_propagate_transform_changed(p_origin);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2025-06-13 10:04:27 +01:00
|
|
|
|
2017-08-09 08:18:07 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
if ((!data.gizmos.is_empty() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
|
2017-08-09 08:18:07 -03:00
|
|
|
#else
|
2017-01-12 20:35:46 -03:00
|
|
|
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
|
2017-08-09 08:18:07 -03:00
|
|
|
#endif
|
2023-05-12 13:53:15 +02:00
|
|
|
if (likely(is_accessible_from_caller_thread())) {
|
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
|
|
|
} else {
|
|
|
|
// This should very rarely happen, but if it does at least make sure the notification is received eventually.
|
2023-12-18 15:46:56 +01:00
|
|
|
callable_mp(this, &Node3D::_propagate_transform_changed_deferred).call_deferred();
|
2023-05-12 13:53:15 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2025-03-14 10:02:43 +00:00
|
|
|
_set_dirty_bits(DIRTY_GLOBAL_TRANSFORM | DIRTY_GLOBAL_INTERPOLATED_TRANSFORM);
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::_notification(int p_what) {
|
2014-02-09 22:10:30 -03:00
|
|
|
switch (p_what) {
|
2025-03-21 16:42:23 +02:00
|
|
|
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
|
|
|
|
RID ae = get_accessibility_element();
|
|
|
|
ERR_FAIL_COND(ae.is_null());
|
|
|
|
|
|
|
|
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_CONTAINER);
|
|
|
|
} break;
|
|
|
|
|
2014-11-05 21:20:42 -03:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2023-08-18 13:32:53 +03:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2023-06-06 14:59:54 +02:00
|
|
|
ERR_FAIL_NULL(get_tree());
|
2014-02-09 22:10:30 -03:00
|
|
|
|
|
|
|
Node *p = get_parent();
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p) {
|
2020-03-26 18:49:16 -03:00
|
|
|
data.parent = Object::cast_to<Node3D>(p);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (data.parent) {
|
2025-06-13 10:04:27 +01:00
|
|
|
data.index_in_parent = data.parent->data.node3d_children.size();
|
|
|
|
data.parent->data.node3d_children.push_back(this);
|
|
|
|
} else if (data.index_in_parent != UINT32_MAX) {
|
|
|
|
data.index_in_parent = UINT32_MAX;
|
|
|
|
ERR_PRINT("Node3D ENTER_TREE detected without EXIT_TREE, recovering.");
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2020-10-01 03:17:33 -04:00
|
|
|
if (data.top_level && !Engine::get_singleton()->is_editor_hint()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
if (data.parent) {
|
2023-11-08 20:40:08 -05:00
|
|
|
if (!data.top_level) {
|
|
|
|
data.local_transform = data.parent->get_global_transform() * get_transform();
|
|
|
|
} else {
|
|
|
|
data.local_transform = get_transform();
|
|
|
|
}
|
2023-05-17 01:44:41 +02:00
|
|
|
_replace_dirty_mask(DIRTY_EULER_ROTATION_AND_SCALE); // As local transform was updated, rot/scale should be dirty.
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-03-14 10:02:43 +00:00
|
|
|
_set_dirty_bits(DIRTY_GLOBAL_TRANSFORM | DIRTY_GLOBAL_INTERPOLATED_TRANSFORM); // Global is always dirty upon entering a scene.
|
2014-02-09 22:10:30 -03:00
|
|
|
_notify_dirty();
|
|
|
|
|
|
|
|
notification(NOTIFICATION_ENTER_WORLD);
|
2021-05-09 18:23:20 +02:00
|
|
|
_update_visibility_parent(true);
|
2025-03-14 10:02:43 +00:00
|
|
|
|
|
|
|
if (is_inside_tree() && get_tree()->is_physics_interpolation_enabled()) {
|
|
|
|
// Always reset FTI when entering tree and update the servers,
|
|
|
|
// both for interpolated and non-interpolated nodes,
|
|
|
|
// to ensure the server xforms are up to date.
|
|
|
|
fti_pump_xform();
|
|
|
|
|
|
|
|
// No need to interpolate as we are doing a reset.
|
|
|
|
data.global_transform_interpolated = get_global_transform();
|
|
|
|
|
|
|
|
// Make sure servers are up to date.
|
|
|
|
fti_update_servers_xform();
|
|
|
|
|
|
|
|
// As well as a reset based on the transform when adding, the user may change
|
|
|
|
// the transform during the first tick / frame, and we want to reset automatically
|
|
|
|
// at the end of the frame / tick (unless the user manually called `reset_physics_interpolation()`).
|
|
|
|
if (is_physics_interpolated()) {
|
|
|
|
get_tree()->get_scene_tree_fti().node_3d_request_reset(this);
|
|
|
|
}
|
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-11-05 21:20:42 -03:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2023-08-18 13:32:53 +03:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
|
|
2025-03-14 10:02:43 +00:00
|
|
|
if (is_inside_tree()) {
|
|
|
|
get_tree()->get_scene_tree_fti().node_3d_notify_delete(this);
|
|
|
|
}
|
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
notification(NOTIFICATION_EXIT_WORLD, true);
|
2020-05-14 16:41:43 +02:00
|
|
|
if (xform_change.in_list()) {
|
2014-11-05 21:20:42 -03:00
|
|
|
get_tree()->xform_change_list.remove(&xform_change);
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2025-06-13 10:04:27 +01:00
|
|
|
|
|
|
|
if (data.parent) {
|
|
|
|
if (data.index_in_parent != UINT32_MAX) {
|
|
|
|
// Aliases
|
|
|
|
uint32_t c = data.index_in_parent;
|
|
|
|
LocalVector<Node3D *> &parent_children = data.parent->data.node3d_children;
|
|
|
|
|
|
|
|
parent_children.remove_at_unordered(c);
|
|
|
|
|
|
|
|
// After unordered remove, we need to inform the moved child
|
|
|
|
// what their new id is in the parent children list.
|
|
|
|
if (parent_children.size() > c) {
|
|
|
|
parent_children[c]->data.index_in_parent = c;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ERR_PRINT("Node3D index_in_parent unset at EXIT_TREE.");
|
|
|
|
}
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2025-06-13 10:04:27 +01:00
|
|
|
data.index_in_parent = UINT32_MAX;
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
data.parent = nullptr;
|
2021-05-09 18:23:20 +02:00
|
|
|
_update_visibility_parent(true);
|
2024-05-26 19:39:28 +02:00
|
|
|
_disable_client_physics_interpolation();
|
2014-02-09 22:10:30 -03:00
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
case NOTIFICATION_ENTER_WORLD: {
|
2023-08-18 13:32:53 +03:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
data.inside_world = true;
|
2020-04-02 01:20:12 +02:00
|
|
|
data.viewport = nullptr;
|
2014-02-09 22:10:30 -03:00
|
|
|
Node *parent = get_parent();
|
|
|
|
while (parent && !data.viewport) {
|
2017-08-24 22:58:51 +02:00
|
|
|
data.viewport = Object::cast_to<Viewport>(parent);
|
2014-02-09 22:10:30 -03:00
|
|
|
parent = parent->get_parent();
|
|
|
|
}
|
|
|
|
|
2023-06-06 14:59:54 +02:00
|
|
|
ERR_FAIL_NULL(data.viewport);
|
2014-02-09 22:10:30 -03:00
|
|
|
|
|
|
|
if (get_script_instance()) {
|
2024-05-14 16:34:59 +02:00
|
|
|
get_script_instance()->call(SNAME("_enter_world"));
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2022-01-04 12:07:36 +01:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2023-11-29 16:54:34 +01:00
|
|
|
if (is_part_of_edited_scene()) {
|
2023-09-04 17:01:33 +02:00
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringName(_spatial_editor_group), SNAME("_request_gizmo_for_id"), get_instance_id());
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} break;
|
2022-02-15 18:06:48 +01:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
case NOTIFICATION_EXIT_WORLD: {
|
2023-08-18 13:32:53 +03:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
clear_gizmos();
|
2014-02-09 22:10:30 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (get_script_instance()) {
|
2024-05-14 16:34:59 +02:00
|
|
|
get_script_instance()->call(SNAME("_exit_world"));
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-04-02 01:20:12 +02:00
|
|
|
data.viewport = nullptr;
|
2014-02-09 22:10:30 -03:00
|
|
|
data.inside_world = false;
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
2023-08-18 13:32:53 +03:00
|
|
|
ERR_THREAD_GUARD;
|
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
for (int i = 0; i < data.gizmos.size(); i++) {
|
|
|
|
data.gizmos.write[i]->transform();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} break;
|
2024-05-26 19:39:28 +02:00
|
|
|
|
|
|
|
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
|
|
|
|
if (data.client_physics_interpolation_data) {
|
|
|
|
data.client_physics_interpolation_data->global_xform_prev = data.client_physics_interpolation_data->global_xform_curr;
|
|
|
|
}
|
2025-03-14 10:02:43 +00:00
|
|
|
|
|
|
|
// In most cases, nodes derived from Node3D will have to already have reset code available for SceneTreeFTI,
|
|
|
|
// so it makes sense for them to reuse this method rather than respond individually to NOTIFICATION_RESET_PHYSICS_INTERPOLATION,
|
|
|
|
// unless they need to perform specific tasks (like changing process modes).
|
|
|
|
fti_pump_xform();
|
|
|
|
fti_pump_property();
|
2025-05-10 11:47:02 +01:00
|
|
|
|
|
|
|
// Detect whether we are using an identity transform.
|
|
|
|
// This is an optimization for faster tree transform concatenation.
|
|
|
|
data.fti_is_identity_xform = data.local_transform == Transform3D();
|
2025-03-14 10:02:43 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_SUSPENDED:
|
|
|
|
case NOTIFICATION_PAUSED: {
|
|
|
|
if (is_physics_interpolated_and_enabled()) {
|
|
|
|
data.local_transform_prev = get_transform();
|
|
|
|
}
|
2024-05-26 19:39:28 +02:00
|
|
|
} break;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
void Node3D::set_basis(const Basis &p_basis) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
set_transform(Transform3D(p_basis, data.local_transform.origin));
|
|
|
|
}
|
|
|
|
void Node3D::set_quaternion(const Quaternion &p_quaternion) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
// We need the scale part, so if these are dirty, update it
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
2023-05-17 01:44:41 +02:00
|
|
|
_clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
|
2022-06-25 11:23:24 +02:00
|
|
|
}
|
|
|
|
data.local_transform.basis = Basis(p_quaternion, data.scale);
|
|
|
|
// Rotscale should not be marked dirty because that would cause precision loss issues with the scale. Instead reconstruct rotation now.
|
|
|
|
data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
|
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
_replace_dirty_mask(DIRTY_NONE);
|
2022-06-25 11:23:24 +02:00
|
|
|
|
|
|
|
_propagate_transform_changed(this);
|
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2025-06-02 10:37:55 +01:00
|
|
|
fti_notify_node_changed();
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
|
|
|
|
2021-07-21 00:13:52 -04:00
|
|
|
Vector3 Node3D::get_global_position() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2021-07-21 00:13:52 -04:00
|
|
|
return get_global_transform().get_origin();
|
|
|
|
}
|
|
|
|
|
2023-08-11 11:41:49 +02:00
|
|
|
Basis Node3D::get_global_basis() const {
|
|
|
|
ERR_READ_THREAD_GUARD_V(Basis());
|
|
|
|
return get_global_transform().get_basis();
|
|
|
|
}
|
|
|
|
|
2021-07-21 00:13:52 -04:00
|
|
|
void Node3D::set_global_position(const Vector3 &p_position) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-07-21 00:13:52 -04:00
|
|
|
Transform3D transform = get_global_transform();
|
|
|
|
transform.set_origin(p_position);
|
|
|
|
set_global_transform(transform);
|
|
|
|
}
|
|
|
|
|
2023-08-11 11:41:49 +02:00
|
|
|
void Node3D::set_global_basis(const Basis &p_basis) {
|
|
|
|
ERR_THREAD_GUARD;
|
|
|
|
Transform3D transform = get_global_transform();
|
|
|
|
transform.set_basis(p_basis);
|
|
|
|
set_global_transform(transform);
|
|
|
|
}
|
|
|
|
|
2021-07-21 00:13:52 -04:00
|
|
|
Vector3 Node3D::get_global_rotation() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2021-07-21 00:13:52 -04:00
|
|
|
return get_global_transform().get_basis().get_euler();
|
|
|
|
}
|
|
|
|
|
2022-12-18 16:58:19 +01:00
|
|
|
Vector3 Node3D::get_global_rotation_degrees() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2022-12-18 16:58:19 +01:00
|
|
|
Vector3 radians = get_global_rotation();
|
|
|
|
return Vector3(Math::rad_to_deg(radians.x), Math::rad_to_deg(radians.y), Math::rad_to_deg(radians.z));
|
|
|
|
}
|
|
|
|
|
2021-07-21 00:13:52 -04:00
|
|
|
void Node3D::set_global_rotation(const Vector3 &p_euler_rad) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-07-21 00:13:52 -04:00
|
|
|
Transform3D transform = get_global_transform();
|
2024-04-12 18:38:35 +02:00
|
|
|
transform.basis = Basis::from_euler(p_euler_rad) * Basis::from_scale(transform.basis.get_scale());
|
2021-07-21 00:13:52 -04:00
|
|
|
set_global_transform(transform);
|
|
|
|
}
|
|
|
|
|
2022-12-18 16:58:19 +01:00
|
|
|
void Node3D::set_global_rotation_degrees(const Vector3 &p_euler_degrees) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-12-18 16:58:19 +01:00
|
|
|
Vector3 radians(Math::deg_to_rad(p_euler_degrees.x), Math::deg_to_rad(p_euler_degrees.y), Math::deg_to_rad(p_euler_degrees.z));
|
|
|
|
set_global_rotation(radians);
|
|
|
|
}
|
|
|
|
|
2025-03-14 10:02:43 +00:00
|
|
|
void Node3D::fti_pump_xform() {
|
|
|
|
data.local_transform_prev = get_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::fti_notify_node_changed(bool p_transform_changed) {
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
get_tree()->get_scene_tree_fti().node_3d_notify_changed(*this, p_transform_changed);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
void Node3D::set_transform(const Transform3D &p_transform) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2014-02-09 22:10:30 -03:00
|
|
|
data.local_transform = p_transform;
|
2023-05-17 01:44:41 +02:00
|
|
|
_replace_dirty_mask(DIRTY_EULER_ROTATION_AND_SCALE); // Make rot/scale dirty.
|
2022-06-25 11:23:24 +02:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-15 22:07:03 -03:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2025-06-02 10:37:55 +01:00
|
|
|
fti_notify_node_changed();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
Basis Node3D::get_basis() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Basis());
|
2021-10-21 13:38:20 -03:00
|
|
|
return get_transform().basis;
|
|
|
|
}
|
2022-06-25 11:23:24 +02:00
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
Quaternion Node3D::get_quaternion() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
return get_transform().basis.get_rotation_quaternion();
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
void Node3D::set_global_transform(const Transform3D &p_transform) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2023-05-29 22:52:53 +02:00
|
|
|
Transform3D xform = (data.parent && !data.top_level)
|
2021-10-28 15:57:41 +02:00
|
|
|
? data.parent->get_global_transform().affine_inverse() * p_transform
|
|
|
|
: p_transform;
|
2014-02-09 22:10:30 -03:00
|
|
|
|
|
|
|
set_transform(xform);
|
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D Node3D::get_transform() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform3D());
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_test_dirty_bits(DIRTY_LOCAL_TRANSFORM)) {
|
2023-05-12 13:53:15 +02:00
|
|
|
// This update can happen if needed over multiple threads.
|
2014-02-09 22:10:30 -03:00
|
|
|
_update_local_transform();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
return data.local_transform;
|
|
|
|
}
|
2023-05-12 13:53:15 +02:00
|
|
|
|
2024-05-26 19:39:28 +02:00
|
|
|
// Return false to timeout and remove from the client interpolation list.
|
|
|
|
bool Node3D::update_client_physics_interpolation_data() {
|
|
|
|
if (!is_inside_tree() || !_is_physics_interpolated_client_side()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_NULL_V(data.client_physics_interpolation_data, false);
|
|
|
|
ClientPhysicsInterpolationData &pid = *data.client_physics_interpolation_data;
|
|
|
|
|
|
|
|
uint64_t tick = Engine::get_singleton()->get_physics_frames();
|
|
|
|
|
|
|
|
// Has this update been done already this tick?
|
|
|
|
// (For instance, get_global_transform_interpolated() could be called multiple times.)
|
|
|
|
if (pid.current_physics_tick != tick) {
|
|
|
|
// Timeout?
|
|
|
|
if (tick >= pid.timeout_physics_tick) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pid.current_physics_tick == (tick - 1)) {
|
|
|
|
// Normal interpolation situation, there is a continuous flow of data
|
|
|
|
// from one tick to the next...
|
|
|
|
pid.global_xform_prev = pid.global_xform_curr;
|
|
|
|
} else {
|
|
|
|
// There has been a gap, we cannot sensibly offer interpolation over
|
|
|
|
// a multitick gap, so we will teleport.
|
|
|
|
pid.global_xform_prev = get_global_transform();
|
|
|
|
}
|
|
|
|
pid.current_physics_tick = tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
pid.global_xform_curr = get_global_transform();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::_disable_client_physics_interpolation() {
|
|
|
|
// Disable any current client side interpolation.
|
|
|
|
// (This can always restart as normal if you later re-attach the node to the SceneTree.)
|
|
|
|
if (data.client_physics_interpolation_data) {
|
|
|
|
memdelete(data.client_physics_interpolation_data);
|
|
|
|
data.client_physics_interpolation_data = nullptr;
|
|
|
|
|
|
|
|
SceneTree *tree = get_tree();
|
|
|
|
if (tree && _client_physics_interpolation_node_3d_list.in_list()) {
|
|
|
|
tree->client_physics_interpolation_remove_node_3d(&_client_physics_interpolation_node_3d_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_set_physics_interpolated_client_side(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform3D Node3D::_get_global_transform_interpolated(real_t p_interpolation_fraction) {
|
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform3D());
|
|
|
|
|
|
|
|
// Set in motion the mechanisms for client side interpolation if not already active.
|
|
|
|
if (!_is_physics_interpolated_client_side()) {
|
|
|
|
_set_physics_interpolated_client_side(true);
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(data.client_physics_interpolation_data != nullptr, Transform3D());
|
|
|
|
data.client_physics_interpolation_data = memnew(ClientPhysicsInterpolationData);
|
|
|
|
data.client_physics_interpolation_data->global_xform_curr = get_global_transform();
|
|
|
|
data.client_physics_interpolation_data->global_xform_prev = data.client_physics_interpolation_data->global_xform_curr;
|
|
|
|
data.client_physics_interpolation_data->current_physics_tick = Engine::get_singleton()->get_physics_frames();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Storing the last tick we requested client interpolation allows us to timeout
|
|
|
|
// and remove client interpolated nodes from the list to save processing.
|
|
|
|
// We use some arbitrary timeout here, but this could potentially be user defined.
|
|
|
|
|
|
|
|
// Note: This timeout has to be larger than the number of ticks in a frame, otherwise the interpolated
|
|
|
|
// data will stop flowing before the next frame is drawn. This should only be relevant at high tick rates.
|
|
|
|
// We could alternatively do this by frames rather than ticks and avoid this problem, but then the behavior
|
|
|
|
// would be machine dependent.
|
|
|
|
data.client_physics_interpolation_data->timeout_physics_tick = Engine::get_singleton()->get_physics_frames() + 256;
|
|
|
|
|
|
|
|
// Make sure data is up to date.
|
|
|
|
update_client_physics_interpolation_data();
|
|
|
|
|
|
|
|
// Interpolate the current data.
|
|
|
|
const Transform3D &xform_curr = data.client_physics_interpolation_data->global_xform_curr;
|
|
|
|
const Transform3D &xform_prev = data.client_physics_interpolation_data->global_xform_prev;
|
|
|
|
|
|
|
|
Transform3D res;
|
|
|
|
TransformInterpolator::interpolate_transform_3d(xform_prev, xform_curr, res, p_interpolation_fraction);
|
|
|
|
|
|
|
|
SceneTree *tree = get_tree();
|
|
|
|
|
|
|
|
// This should not happen, as is_inside_tree() is checked earlier.
|
|
|
|
ERR_FAIL_NULL_V(tree, res);
|
|
|
|
if (!_client_physics_interpolation_node_3d_list.in_list()) {
|
|
|
|
tree->client_physics_interpolation_add_node_3d(&_client_physics_interpolation_node_3d_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2025-06-09 09:31:56 +01:00
|
|
|
// Visible nodes - get_global_transform_interpolated is cheap.
|
|
|
|
// Invisible nodes - get_global_transform_interpolated is expensive, try to avoid.
|
2024-05-26 19:39:28 +02:00
|
|
|
Transform3D Node3D::get_global_transform_interpolated() {
|
2025-03-14 10:02:43 +00:00
|
|
|
#if 1
|
2024-05-26 19:39:28 +02:00
|
|
|
// Pass through if physics interpolation is switched off.
|
|
|
|
// This is a convenience, as it allows you to easy turn off interpolation
|
|
|
|
// without changing any code.
|
2025-06-09 09:31:56 +01:00
|
|
|
if (is_inside_tree() && get_tree()->is_physics_interpolation_enabled() && !Engine::get_singleton()->is_in_physics_frame()) {
|
|
|
|
// Note that with SceneTreeFTI, we may want to calculate interpolated transform for a node
|
|
|
|
// with physics interpolation set to OFF, if it has a parent that is ON.
|
|
|
|
|
|
|
|
// Cheap case.
|
|
|
|
// We already pre-cache the visible_in_tree for VisualInstances, but NOT for Node3Ds, so we have to
|
|
|
|
// deal with non-VIs the slow way.
|
|
|
|
if (Object::cast_to<VisualInstance3D>(this) && _is_vi_visible() && data.fti_global_xform_interp_set) {
|
|
|
|
return data.global_transform_interpolated;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find out if visible in tree.
|
|
|
|
// If not visible in tree, find the FIRST ancestor that is visible in tree.
|
|
|
|
const Node3D *visible_parent = nullptr;
|
|
|
|
const Node3D *s = this;
|
|
|
|
bool visible = true;
|
|
|
|
bool visible_in_tree = true;
|
|
|
|
|
|
|
|
while (s) {
|
|
|
|
if (!s->data.visible) {
|
|
|
|
visible_in_tree = false;
|
|
|
|
visible = false;
|
|
|
|
} else {
|
|
|
|
if (!visible) {
|
|
|
|
visible_parent = s;
|
|
|
|
visible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s = s->data.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simplest case, we can return the interpolated xform calculated by SceneTreeFTI.
|
|
|
|
if (visible_in_tree) {
|
|
|
|
return data.fti_global_xform_interp_set ? data.global_transform_interpolated : get_global_transform();
|
|
|
|
} else if (visible_parent) {
|
|
|
|
// INVISIBLE case. Not visible, but there is a visible ancestor somewhere in the chain.
|
|
|
|
if (_get_scene_tree_depth() < 1) {
|
|
|
|
// This should not happen unless there a problem has been introduced in the scene tree depth code.
|
|
|
|
// Print a non-spammy error and return something reasonable.
|
|
|
|
ERR_PRINT_ONCE("depth is < 1.");
|
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
// The interpolated xform is not already calculated for invisible nodes, but we can calculate this
|
|
|
|
// manually on demand if there is a visible parent.
|
|
|
|
// First create the chain (backwards), from the node up to first visible parent.
|
|
|
|
const Node3D **parents = (const Node3D **)alloca((sizeof(const Node3D *) * _get_scene_tree_depth()));
|
|
|
|
int32_t num_parents = 0;
|
|
|
|
|
|
|
|
s = this;
|
|
|
|
while (s) {
|
|
|
|
if (s == visible_parent) {
|
|
|
|
// Finished.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
parents[num_parents++] = s;
|
|
|
|
s = s->data.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now calculate the interpolated chain forwards.
|
|
|
|
float interpolation_fraction = Engine::get_singleton()->get_physics_interpolation_fraction();
|
|
|
|
|
|
|
|
// Seed the xform with the visible parent.
|
|
|
|
Transform3D xform = visible_parent->data.fti_global_xform_interp_set ? visible_parent->data.global_transform_interpolated : visible_parent->get_global_transform();
|
|
|
|
Transform3D local_interp;
|
|
|
|
|
|
|
|
// Backwards through the list is forwards through the chain through the tree.
|
|
|
|
for (int32_t n = num_parents - 1; n >= 0; n--) {
|
|
|
|
s = parents[n];
|
|
|
|
|
|
|
|
if (s->is_physics_interpolated()) {
|
|
|
|
// Make sure to call `get_transform()` rather than using local_transform directly, because
|
|
|
|
// local_transform may be dirty and need updating from rotation / scale.
|
|
|
|
TransformInterpolator::interpolate_transform_3d(s->data.local_transform_prev, s->get_transform(), local_interp, interpolation_fraction);
|
|
|
|
} else {
|
|
|
|
local_interp = s->get_transform();
|
|
|
|
}
|
|
|
|
xform *= local_interp;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We could save this in case of multiple calls,
|
|
|
|
// but probably not necessary.
|
|
|
|
return xform;
|
|
|
|
}
|
2025-03-14 10:02:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return get_global_transform();
|
|
|
|
#else
|
|
|
|
// OLD METHOD - deprecated since moving to SceneTreeFTI,
|
|
|
|
// but leaving for reference and comparison for debugging.
|
|
|
|
|
2024-05-26 19:39:28 +02:00
|
|
|
if (!is_physics_interpolated_and_enabled()) {
|
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we are in the physics frame, the interpolated global transform is meaningless.
|
|
|
|
// However, there is an exception, we may want to use this as a means of starting off the client
|
|
|
|
// interpolation pump if not already started (when _is_physics_interpolated_client_side() is false).
|
|
|
|
if (Engine::get_singleton()->is_in_physics_frame() && _is_physics_interpolated_client_side()) {
|
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _get_global_transform_interpolated(Engine::get_singleton()->get_physics_interpolation_fraction());
|
2025-03-14 10:02:43 +00:00
|
|
|
#endif
|
2024-05-26 19:39:28 +02:00
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D Node3D::get_global_transform() const {
|
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform3D());
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2023-05-12 13:53:15 +02:00
|
|
|
/* Due to how threads work at scene level, while this global transform won't be able to be changed from outside a thread,
|
|
|
|
* it is possible that multiple threads can access it while it's dirty from previous work. Due to this, we must ensure that
|
|
|
|
* the dirty/update process is thread safe by utilizing atomic copies.
|
|
|
|
*/
|
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
uint32_t dirty = _read_dirty_mask();
|
2023-05-12 13:53:15 +02:00
|
|
|
if (dirty & DIRTY_GLOBAL_TRANSFORM) {
|
|
|
|
if (dirty & DIRTY_LOCAL_TRANSFORM) {
|
|
|
|
_update_local_transform(); // Update local transform atomically.
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:53:15 +02:00
|
|
|
Transform3D new_global;
|
2023-05-29 22:52:53 +02:00
|
|
|
if (data.parent && !data.top_level) {
|
2023-05-12 13:53:15 +02:00
|
|
|
new_global = data.parent->get_global_transform() * data.local_transform;
|
2014-02-09 22:10:30 -03:00
|
|
|
} else {
|
2023-05-12 13:53:15 +02:00
|
|
|
new_global = data.local_transform;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-07-18 13:47:42 -03:00
|
|
|
if (data.disable_scale) {
|
2023-05-12 13:53:15 +02:00
|
|
|
new_global.basis.orthonormalize();
|
2018-07-18 13:47:42 -03:00
|
|
|
}
|
|
|
|
|
2023-05-12 13:53:15 +02:00
|
|
|
data.global_transform = new_global;
|
2023-05-17 01:44:41 +02:00
|
|
|
_clear_dirty_bits(DIRTY_GLOBAL_TRANSFORM);
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
return data.global_transform;
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D Node3D::get_global_gizmo_transform() const {
|
2017-10-03 18:49:32 +02:00
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D Node3D::get_local_gizmo_transform() const {
|
2017-10-03 18:49:32 +02:00
|
|
|
return get_transform();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-09 13:06:38 +02:00
|
|
|
Node3D *Node3D::get_parent_node_3d() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(nullptr); // This can't be changed on threads anyway.
|
2021-06-09 13:06:38 +02:00
|
|
|
if (data.top_level) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Object::cast_to<Node3D>(get_parent());
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D Node3D::get_relative_transform(const Node *p_parent) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Transform3D());
|
2022-01-27 10:34:33 -06:00
|
|
|
if (p_parent == this) {
|
2020-10-17 01:08:21 -04:00
|
|
|
return Transform3D();
|
2022-01-27 10:34:33 -06:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2023-06-06 14:59:54 +02:00
|
|
|
ERR_FAIL_NULL_V(data.parent, Transform3D());
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_parent == data.parent) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return get_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2014-02-09 22:10:30 -03:00
|
|
|
return data.parent->get_relative_transform(p_parent) * get_transform();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-12-08 17:35:30 +00:00
|
|
|
void Node3D::set_position(const Vector3 &p_position) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-06-25 06:17:41 +09:00
|
|
|
data.local_transform.origin = p_position;
|
2014-02-09 22:10:30 -03:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-15 22:07:03 -03:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2025-06-02 10:37:55 +01:00
|
|
|
fti_notify_node_changed();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
void Node3D::set_rotation_edit_mode(RotationEditMode p_mode) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-10-21 13:38:20 -03:00
|
|
|
if (data.rotation_edit_mode == p_mode) {
|
|
|
|
return;
|
|
|
|
}
|
2022-06-25 11:23:24 +02:00
|
|
|
|
|
|
|
bool transform_changed = false;
|
2023-05-17 01:44:41 +02:00
|
|
|
if (data.rotation_edit_mode == ROTATION_EDIT_MODE_BASIS && !_test_dirty_bits(DIRTY_LOCAL_TRANSFORM)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
data.local_transform.orthogonalize();
|
|
|
|
transform_changed = true;
|
|
|
|
}
|
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
data.rotation_edit_mode = p_mode;
|
2021-10-09 19:24:26 +09:00
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
if (p_mode == ROTATION_EDIT_MODE_EULER && _test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
// If going to Euler mode, ensure that vectors are _not_ dirty, else the retrieved value may be wrong.
|
|
|
|
// Otherwise keep what is there, so switching back and forth between modes does not break the vectors.
|
|
|
|
|
|
|
|
_update_rotation_and_scale();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (transform_changed) {
|
|
|
|
_propagate_transform_changed(this);
|
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2021-10-09 19:24:26 +09:00
|
|
|
}
|
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
notify_property_list_changed();
|
|
|
|
}
|
|
|
|
|
|
|
|
Node3D::RotationEditMode Node3D::get_rotation_edit_mode() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(ROTATION_EDIT_MODE_EULER);
|
2021-10-21 13:38:20 -03:00
|
|
|
return data.rotation_edit_mode;
|
|
|
|
}
|
|
|
|
|
2022-10-01 21:53:46 -05:00
|
|
|
void Node3D::set_rotation_order(EulerOrder p_order) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-10-01 21:53:46 -05:00
|
|
|
if (data.euler_rotation_order == p_order) {
|
2021-10-21 13:38:20 -03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-01 21:53:46 -05:00
|
|
|
ERR_FAIL_INDEX(int32_t(p_order), 6);
|
2022-06-25 11:23:24 +02:00
|
|
|
bool transform_changed = false;
|
2021-10-21 13:38:20 -03:00
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
uint32_t dirty = _read_dirty_mask();
|
|
|
|
if ((dirty & DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
_update_rotation_and_scale();
|
2023-05-17 01:44:41 +02:00
|
|
|
} else if ((dirty & DIRTY_LOCAL_TRANSFORM)) {
|
2022-10-01 21:53:46 -05:00
|
|
|
data.euler_rotation = Basis::from_euler(data.euler_rotation, data.euler_rotation_order).get_euler_normalized(p_order);
|
2022-06-25 11:23:24 +02:00
|
|
|
transform_changed = true;
|
2021-10-21 13:38:20 -03:00
|
|
|
} else {
|
2023-05-17 01:44:41 +02:00
|
|
|
_set_dirty_bits(DIRTY_LOCAL_TRANSFORM);
|
2022-06-25 11:23:24 +02:00
|
|
|
transform_changed = true;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
|
|
|
|
2022-10-01 21:53:46 -05:00
|
|
|
data.euler_rotation_order = p_order;
|
2021-10-21 13:38:20 -03:00
|
|
|
|
2022-06-25 11:23:24 +02:00
|
|
|
if (transform_changed) {
|
|
|
|
_propagate_transform_changed(this);
|
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
notify_property_list_changed(); // Will change the rotation property.
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
|
|
|
|
2022-10-01 21:53:46 -05:00
|
|
|
EulerOrder Node3D::get_rotation_order() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(EulerOrder::XYZ);
|
2022-10-01 21:53:46 -05:00
|
|
|
return data.euler_rotation_order;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::set_rotation(const Vector3 &p_euler_rad) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
// Update scale only if rotation and scale are dirty, as rotation will be overridden.
|
2022-06-25 09:44:25 +02:00
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
2023-05-17 01:44:41 +02:00
|
|
|
_clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2022-06-25 11:23:24 +02:00
|
|
|
data.euler_rotation = p_euler_rad;
|
2023-05-17 01:44:41 +02:00
|
|
|
_replace_dirty_mask(DIRTY_LOCAL_TRANSFORM);
|
2014-02-09 22:10:30 -03:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-15 22:07:03 -03:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2025-06-02 10:37:55 +01:00
|
|
|
fti_notify_node_changed();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2016-05-06 23:38:08 +02:00
|
|
|
|
2022-12-18 16:58:19 +01:00
|
|
|
void Node3D::set_rotation_degrees(const Vector3 &p_euler_degrees) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-12-18 16:58:19 +01:00
|
|
|
Vector3 radians(Math::deg_to_rad(p_euler_degrees.x), Math::deg_to_rad(p_euler_degrees.y), Math::deg_to_rad(p_euler_degrees.z));
|
|
|
|
set_rotation(radians);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::set_scale(const Vector3 &p_scale) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
// Update rotation only if rotation and scale are dirty, as scale will be overridden.
|
|
|
|
data.euler_rotation = data.local_transform.basis.get_euler_normalized(data.euler_rotation_order);
|
2023-05-17 01:44:41 +02:00
|
|
|
_clear_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE);
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
data.scale = p_scale;
|
2023-05-17 01:44:41 +02:00
|
|
|
_replace_dirty_mask(DIRTY_LOCAL_TRANSFORM);
|
2014-02-09 22:10:30 -03:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-15 22:07:03 -03:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2025-06-02 10:37:55 +01:00
|
|
|
fti_notify_node_changed();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-12-08 17:35:30 +00:00
|
|
|
Vector3 Node3D::get_position() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2022-06-25 09:44:25 +02:00
|
|
|
return data.local_transform.origin;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2016-05-06 23:38:08 +02:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
Vector3 Node3D::get_rotation() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
_update_rotation_and_scale();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2022-06-25 11:23:24 +02:00
|
|
|
return data.euler_rotation;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2016-05-06 23:38:08 +02:00
|
|
|
|
2022-12-18 16:58:19 +01:00
|
|
|
Vector3 Node3D::get_rotation_degrees() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2022-12-18 16:58:19 +01:00
|
|
|
Vector3 radians = get_rotation();
|
|
|
|
return Vector3(Math::rad_to_deg(radians.x), Math::rad_to_deg(radians.y), Math::rad_to_deg(radians.z));
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
Vector3 Node3D::get_scale() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2023-05-17 01:44:41 +02:00
|
|
|
if (_test_dirty_bits(DIRTY_EULER_ROTATION_AND_SCALE)) {
|
2022-06-25 11:23:24 +02:00
|
|
|
_update_rotation_and_scale();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
return data.scale;
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
void Node3D::update_gizmos() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2014-02-09 22:10:30 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_inside_world()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
|
|
|
|
if (data.gizmos.is_empty()) {
|
2023-09-04 17:01:33 +02:00
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringName(_spatial_editor_group), SNAME("_request_gizmo_for_id"), get_instance_id());
|
2021-06-23 16:49:50 +02:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-10-15 19:04:35 -03:00
|
|
|
if (data.gizmos_dirty) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
data.gizmos_dirty = true;
|
2023-12-18 15:46:56 +01:00
|
|
|
callable_mp(this, &Node3D::_update_gizmos).call_deferred();
|
2021-06-23 16:49:50 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-02-04 17:20:26 +09:00
|
|
|
void Node3D::set_subgizmo_selection(Ref<Node3DGizmo> p_gizmo, int p_id, Transform3D p_transform) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-02-04 17:20:26 +09:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!is_inside_world()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-29 16:54:34 +01:00
|
|
|
if (is_part_of_edited_scene()) {
|
2024-05-14 16:34:59 +02:00
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringName(_spatial_editor_group), SNAME("_set_subgizmo_selection"), this, p_gizmo, p_id, p_transform);
|
2021-02-04 17:20:26 +09:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
void Node3D::clear_subgizmo_selection() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-06-23 16:49:50 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!is_inside_world()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
|
|
|
|
if (data.gizmos.is_empty()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
|
2023-11-29 16:54:34 +01:00
|
|
|
if (is_part_of_edited_scene()) {
|
2024-05-14 16:34:59 +02:00
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_DEFERRED, SceneStringName(_spatial_editor_group), SNAME("_clear_subgizmo_selection"), this);
|
2021-06-23 16:49:50 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
void Node3D::add_gizmo(Ref<Node3DGizmo> p_gizmo) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2014-02-09 22:10:30 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
if (data.gizmos_disabled || p_gizmo.is_null()) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
data.gizmos.push_back(p_gizmo);
|
|
|
|
|
|
|
|
if (p_gizmo.is_valid() && is_inside_world()) {
|
|
|
|
p_gizmo->create();
|
2018-09-02 22:31:03 +02:00
|
|
|
if (is_visible_in_tree()) {
|
2021-06-23 16:49:50 +02:00
|
|
|
p_gizmo->redraw();
|
2017-08-26 00:40:45 -03:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
p_gizmo->transform();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::remove_gizmo(Ref<Node3DGizmo> p_gizmo) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-06-23 16:49:50 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
int idx = data.gizmos.find(p_gizmo);
|
|
|
|
if (idx != -1) {
|
|
|
|
p_gizmo->free();
|
2021-07-03 16:17:03 -06:00
|
|
|
data.gizmos.remove_at(idx);
|
2021-06-23 16:49:50 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::clear_gizmos() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-06-23 16:49:50 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
for (int i = 0; i < data.gizmos.size(); i++) {
|
|
|
|
data.gizmos.write[i]->free();
|
|
|
|
}
|
|
|
|
data.gizmos.clear();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-08-05 20:35:08 +02:00
|
|
|
TypedArray<Node3DGizmo> Node3D::get_gizmos_bind() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD_V(TypedArray<Node3DGizmo>());
|
2022-08-05 20:35:08 +02:00
|
|
|
TypedArray<Node3DGizmo> ret;
|
2021-06-23 16:49:50 +02:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
for (int i = 0; i < data.gizmos.size(); i++) {
|
|
|
|
ret.push_back(Variant(data.gizmos[i].ptr()));
|
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
#endif
|
2021-06-23 16:49:50 +02:00
|
|
|
|
|
|
|
return ret;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
Vector<Ref<Node3DGizmo>> Node3D::get_gizmos() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD_V(Vector<Ref<Node3DGizmo>>());
|
2014-02-09 22:10:30 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
return data.gizmos;
|
2014-02-09 22:10:30 -03:00
|
|
|
#else
|
2021-06-23 16:49:50 +02:00
|
|
|
return Vector<Ref<Node3DGizmo>>();
|
2014-02-09 22:10:30 -03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-05-17 01:44:41 +02:00
|
|
|
void Node3D::_replace_dirty_mask(uint32_t p_mask) const {
|
|
|
|
if (is_group_processing()) {
|
|
|
|
data.dirty.mt.set(p_mask);
|
|
|
|
} else {
|
|
|
|
data.dirty.st = p_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::_set_dirty_bits(uint32_t p_bits) const {
|
|
|
|
if (is_group_processing()) {
|
|
|
|
data.dirty.mt.bit_or(p_bits);
|
|
|
|
} else {
|
|
|
|
data.dirty.st |= p_bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::_clear_dirty_bits(uint32_t p_bits) const {
|
|
|
|
if (is_group_processing()) {
|
|
|
|
data.dirty.mt.bit_and(~p_bits);
|
|
|
|
} else {
|
|
|
|
data.dirty.st &= ~p_bits;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
void Node3D::_update_gizmos() {
|
2018-04-29 19:49:26 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
if (data.gizmos_disabled || !is_inside_world() || !data.gizmos_dirty) {
|
2021-10-15 19:04:35 -03:00
|
|
|
data.gizmos_dirty = false;
|
2017-08-26 00:40:45 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2021-06-23 16:49:50 +02:00
|
|
|
data.gizmos_dirty = false;
|
|
|
|
for (int i = 0; i < data.gizmos.size(); i++) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (is_visible_in_tree()) {
|
2021-06-23 16:49:50 +02:00
|
|
|
data.gizmos.write[i]->redraw();
|
2020-05-14 16:41:43 +02:00
|
|
|
} else {
|
2021-06-23 16:49:50 +02:00
|
|
|
data.gizmos.write[i]->clear();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-09-19 18:39:50 -03:00
|
|
|
}
|
2018-04-29 19:49:26 +02:00
|
|
|
#endif
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
void Node3D::set_disable_gizmos(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-10-21 17:26:51 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
data.gizmos_disabled = p_enabled;
|
|
|
|
if (!p_enabled) {
|
|
|
|
clear_gizmos();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
#endif
|
2021-10-21 17:26:51 +01:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2020-02-17 18:29:14 +01:00
|
|
|
void Node3D::reparent(Node *p_parent, bool p_keep_global_transform) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-02-17 18:29:14 +01:00
|
|
|
if (p_keep_global_transform) {
|
2024-02-29 12:46:07 +01:00
|
|
|
Transform3D temp = get_global_transform();
|
2024-10-05 06:00:39 +09:00
|
|
|
Node::reparent(p_parent, p_keep_global_transform);
|
2020-02-17 18:29:14 +01:00
|
|
|
set_global_transform(temp);
|
2024-02-29 12:46:07 +01:00
|
|
|
} else {
|
2024-10-05 06:00:39 +09:00
|
|
|
Node::reparent(p_parent, p_keep_global_transform);
|
2020-02-17 18:29:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::set_disable_scale(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2018-07-18 13:47:42 -03:00
|
|
|
data.disable_scale = p_enabled;
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
bool Node3D::is_scale_disabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2018-07-18 13:47:42 -03:00
|
|
|
return data.disable_scale;
|
|
|
|
}
|
|
|
|
|
2020-10-01 03:17:33 -04:00
|
|
|
void Node3D::set_as_top_level(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-01 03:17:33 -04:00
|
|
|
if (data.top_level == p_enabled) {
|
2014-02-09 22:10:30 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2023-11-08 20:40:08 -05:00
|
|
|
if (is_inside_tree()) {
|
2020-05-14 16:41:43 +02:00
|
|
|
if (p_enabled) {
|
2014-02-09 22:10:30 -03:00
|
|
|
set_transform(get_global_transform());
|
2020-05-14 16:41:43 +02:00
|
|
|
} else if (data.parent) {
|
2014-02-09 22:10:30 -03:00
|
|
|
set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
2023-05-29 22:52:53 +02:00
|
|
|
data.top_level = p_enabled;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2023-04-16 13:53:27 -03:00
|
|
|
void Node3D::set_as_top_level_keep_local(bool p_enabled) {
|
|
|
|
ERR_THREAD_GUARD;
|
|
|
|
if (data.top_level == p_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
data.top_level = p_enabled;
|
|
|
|
_propagate_transform_changed(this);
|
|
|
|
}
|
|
|
|
|
2020-10-01 03:17:33 -04:00
|
|
|
bool Node3D::is_set_as_top_level() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2020-10-01 03:17:33 -04:00
|
|
|
return data.top_level;
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-04-18 11:00:51 +02:00
|
|
|
Ref<World3D> Node3D::get_world_3d() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Ref<World3D>()); // World3D can only be set from main thread, so it's safe to obtain on threads.
|
2020-03-27 08:44:44 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_world(), Ref<World3D>());
|
2023-06-06 14:59:54 +02:00
|
|
|
ERR_FAIL_NULL_V(data.viewport, Ref<World3D>());
|
2019-06-22 15:52:51 +03:00
|
|
|
|
2020-04-18 11:00:51 +02:00
|
|
|
return data.viewport->find_world_3d();
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::_propagate_visibility_changed() {
|
2014-08-14 10:31:38 -03:00
|
|
|
notification(NOTIFICATION_VISIBILITY_CHANGED);
|
2023-09-04 17:01:33 +02:00
|
|
|
emit_signal(SceneStringName(visibility_changed));
|
2022-01-04 12:07:36 +01:00
|
|
|
|
2014-09-19 18:39:50 -03:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-06-23 16:49:50 +02:00
|
|
|
if (!data.gizmos.is_empty()) {
|
|
|
|
data.gizmos_dirty = true;
|
|
|
|
_update_gizmos();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-09-19 18:39:50 -03:00
|
|
|
#endif
|
2014-08-14 10:31:38 -03:00
|
|
|
|
2025-06-13 10:04:27 +01:00
|
|
|
for (uint32_t n = 0; n < data.node3d_children.size(); n++) {
|
|
|
|
Node3D *s = data.node3d_children[n];
|
|
|
|
|
|
|
|
if (s->data.visible) {
|
|
|
|
s->_propagate_visibility_changed();
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-08-14 10:31:38 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::show() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-01-04 12:07:36 +01:00
|
|
|
set_visible(true);
|
2014-08-14 10:31:38 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::hide() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-01-04 12:07:36 +01:00
|
|
|
set_visible(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::set_visible(bool p_visible) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2022-01-04 12:07:36 +01:00
|
|
|
if (data.visible == p_visible) {
|
2014-08-14 10:31:38 -03:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2014-08-14 10:31:38 -03:00
|
|
|
|
2022-01-04 12:07:36 +01:00
|
|
|
data.visible = p_visible;
|
2014-08-14 10:31:38 -03:00
|
|
|
|
2020-05-14 16:41:43 +02:00
|
|
|
if (!is_inside_tree()) {
|
2017-07-03 00:27:27 +09:00
|
|
|
return;
|
2020-05-14 16:41:43 +02:00
|
|
|
}
|
2017-07-03 00:27:27 +09:00
|
|
|
_propagate_visibility_changed();
|
2014-08-14 10:31:38 -03:00
|
|
|
}
|
2017-07-03 00:27:27 +09:00
|
|
|
|
2022-01-04 12:07:36 +01:00
|
|
|
bool Node3D::is_visible() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2022-01-04 12:07:36 +01:00
|
|
|
return data.visible;
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
bool Node3D::is_visible_in_tree() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false); // Since visibility can only be changed from main thread, this is safe to call.
|
2020-03-26 18:49:16 -03:00
|
|
|
const Node3D *s = this;
|
2014-08-14 10:31:38 -03:00
|
|
|
|
|
|
|
while (s) {
|
|
|
|
if (!s->data.visible) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
s = s->data.parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-29 19:55:54 -05:00
|
|
|
void Node3D::rotate_object_local(const Vector3 &p_axis, real_t p_angle) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
t.basis.rotate_local(p_axis, p_angle);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-29 19:55:54 -05:00
|
|
|
void Node3D::rotate(const Vector3 &p_axis, real_t p_angle) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
t.basis.rotate(p_axis, p_angle);
|
2015-03-22 10:33:58 -03:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-29 19:55:54 -05:00
|
|
|
void Node3D::rotate_x(real_t p_angle) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
t.basis.rotate(Vector3(1, 0, 0), p_angle);
|
2015-03-22 10:33:58 -03:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-29 19:55:54 -05:00
|
|
|
void Node3D::rotate_y(real_t p_angle) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
t.basis.rotate(Vector3(0, 1, 0), p_angle);
|
2015-03-22 10:33:58 -03:00
|
|
|
set_transform(t);
|
|
|
|
}
|
2020-05-14 14:29:06 +02:00
|
|
|
|
2021-01-29 19:55:54 -05:00
|
|
|
void Node3D::rotate_z(real_t p_angle) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
t.basis.rotate(Vector3(0, 0, 1), p_angle);
|
2015-03-22 10:33:58 -03:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::translate(const Vector3 &p_offset) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
2022-07-16 11:47:54 +02:00
|
|
|
t.translate_local(p_offset);
|
2015-03-22 10:33:58 -03:00
|
|
|
set_transform(t);
|
|
|
|
}
|
2015-06-06 09:44:38 -03:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::translate_object_local(const Vector3 &p_offset) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D s;
|
2022-07-16 11:47:54 +02:00
|
|
|
s.translate_local(p_offset);
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
set_transform(t * s);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::scale(const Vector3 &p_ratio) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
2015-03-22 10:33:58 -03:00
|
|
|
t.basis.scale(p_ratio);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::scale_object_local(const Vector3 &p_scale) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
t.basis.scale_local(p_scale);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2021-01-29 19:55:54 -05:00
|
|
|
void Node3D::global_rotate(const Vector3 &p_axis, real_t p_angle) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_global_transform();
|
2018-05-16 20:32:35 -04:00
|
|
|
t.basis.rotate(p_axis, p_angle);
|
2015-03-22 10:33:58 -03:00
|
|
|
set_global_transform(t);
|
|
|
|
}
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::global_scale(const Vector3 &p_scale) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_global_transform();
|
2018-05-16 20:32:35 -04:00
|
|
|
t.basis.scale(p_scale);
|
Restore the behavior of Spatial rotations recently changed in c1153f5.
That change was borne out of a confusion regarding the meaning of "local" in #14569.
Affine transformations in Spatial simply correspond to affine operations of its Transform. Such operations take place in a coordinate system that is defined by the parent Spatial. When there is no parent, they correspond to operations in the global coordinate system.
This coordinate system, which is relative to the parent, has been referred to as the local coordinate system in the docs so far, but this sloppy language has apparently confused some users, making them think that the local coordinate system refers to the one whose axes are "painted" on the Spatial node itself.
To avoid such conceptual conflations and misunderstandings in the future, the parent-relative local system is now referred to as "parent-local", and the object-relative local system is called "object-local" in the docs.
This commit adds the functionality "requested" in #14569, not by changing how rotate/scale/translate works, but by adding new rotate_object_local, scale_object_local and translate_object_local functions. Also, for completeness, there is now global_scale.
This commit also updates another part of the docs regarding the rotation property of Spatial, which also leads to confusion among some users.
2017-12-26 19:15:20 -05:00
|
|
|
set_global_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::global_translate(const Vector3 &p_offset) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_global_transform();
|
2015-03-22 10:33:58 -03:00
|
|
|
t.origin += p_offset;
|
|
|
|
set_global_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::orthonormalize() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
Transform3D t = get_transform();
|
2015-03-22 10:33:58 -03:00
|
|
|
t.orthonormalize();
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::set_identity() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2020-10-17 01:08:21 -04:00
|
|
|
set_transform(Transform3D());
|
2015-03-22 11:52:07 -03:00
|
|
|
}
|
|
|
|
|
2023-04-15 10:01:43 +02:00
|
|
|
void Node3D::look_at(const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-09-29 13:21:15 +02:00
|
|
|
ERR_FAIL_COND_MSG(!is_inside_tree(), "Node not inside tree. Use look_at_from_position() instead.");
|
2021-07-20 23:32:00 -04:00
|
|
|
Vector3 origin = get_global_transform().origin;
|
2023-04-15 10:01:43 +02:00
|
|
|
look_at_from_position(origin, p_target, p_up, p_use_model_front);
|
2019-05-23 09:49:50 -03:00
|
|
|
}
|
|
|
|
|
2023-04-15 10:01:43 +02:00
|
|
|
void Node3D::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up, bool p_use_model_front) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2021-07-20 23:32:00 -04:00
|
|
|
ERR_FAIL_COND_MSG(p_pos.is_equal_approx(p_target), "Node origin and target are in the same position, look_at() failed.");
|
2022-09-01 20:32:33 -04:00
|
|
|
ERR_FAIL_COND_MSG(p_up.is_zero_approx(), "The up vector can't be zero, look_at() failed.");
|
2015-03-22 10:33:58 -03:00
|
|
|
|
2023-04-15 10:01:43 +02:00
|
|
|
Vector3 forward = p_target - p_pos;
|
|
|
|
Basis lookat_basis = Basis::looking_at(forward, p_up, p_use_model_front);
|
2021-07-20 23:32:00 -04:00
|
|
|
Vector3 original_scale = get_scale();
|
2023-04-15 10:01:43 +02:00
|
|
|
set_global_transform(Transform3D(lookat_basis, p_pos));
|
2019-10-11 02:22:02 -03:00
|
|
|
set_scale(original_scale);
|
2015-03-22 10:33:58 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
Vector3 Node3D::to_local(Vector3 p_global) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2017-07-23 14:37:26 +03:00
|
|
|
return get_global_transform().affine_inverse().xform(p_global);
|
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
Vector3 Node3D::to_global(Vector3 p_local) const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(Vector3());
|
2017-07-23 14:37:26 +03:00
|
|
|
return get_global_transform().xform(p_local);
|
|
|
|
}
|
|
|
|
|
2025-04-29 11:44:25 +01:00
|
|
|
void Node3D::_physics_interpolated_changed() {
|
|
|
|
ERR_THREAD_GUARD;
|
|
|
|
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::_set_notify_transform_when_fti_off(bool p_enable) {
|
|
|
|
ERR_THREAD_GUARD;
|
|
|
|
data.notify_transform_when_fti_off = p_enable;
|
|
|
|
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
|
|
|
|
}
|
|
|
|
|
2022-01-04 12:07:36 +01:00
|
|
|
void Node3D::set_notify_transform(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2025-04-29 11:44:25 +01:00
|
|
|
data.notify_transform_requested = p_enabled;
|
|
|
|
data.notify_transform = data.notify_transform_requested || (data.notify_transform_when_fti_off && !is_physics_interpolated_and_enabled());
|
2017-01-12 20:35:46 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
bool Node3D::is_transform_notification_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2017-01-12 20:35:46 -03:00
|
|
|
return data.notify_transform;
|
|
|
|
}
|
|
|
|
|
2022-01-04 12:07:36 +01:00
|
|
|
void Node3D::set_notify_local_transform(bool p_enabled) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2022-01-04 12:07:36 +01:00
|
|
|
data.notify_local_transform = p_enabled;
|
2015-09-15 22:07:03 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
bool Node3D::is_local_transform_notification_enabled() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(false);
|
2015-09-15 22:07:03 -03:00
|
|
|
return data.notify_local_transform;
|
|
|
|
}
|
2014-08-14 10:31:38 -03:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::force_update_transform() {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_THREAD_GUARD;
|
2018-09-06 20:38:16 -03:00
|
|
|
ERR_FAIL_COND(!is_inside_tree());
|
|
|
|
if (!xform_change.in_list()) {
|
|
|
|
return; //nothing to update
|
|
|
|
}
|
|
|
|
get_tree()->xform_change_list.remove(&xform_change);
|
|
|
|
|
|
|
|
notification(NOTIFICATION_TRANSFORM_CHANGED);
|
|
|
|
}
|
|
|
|
|
2021-05-09 18:23:20 +02:00
|
|
|
void Node3D::_update_visibility_parent(bool p_update_root) {
|
|
|
|
RID new_parent;
|
|
|
|
|
|
|
|
if (!visibility_parent_path.is_empty()) {
|
|
|
|
if (!p_update_root) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Node *parent = get_node_or_null(visibility_parent_path);
|
2025-06-11 16:19:23 +02:00
|
|
|
ERR_FAIL_NULL_MSG(parent, "Can't find visibility parent node at path: " + String(visibility_parent_path));
|
2021-05-09 18:23:20 +02:00
|
|
|
ERR_FAIL_COND_MSG(parent == this, "The visibility parent can't be the same node.");
|
|
|
|
GeometryInstance3D *gi = Object::cast_to<GeometryInstance3D>(parent);
|
2025-06-11 16:19:23 +02:00
|
|
|
ERR_FAIL_NULL_MSG(gi, "The visibility parent node must be a GeometryInstance3D, at path: " + String(visibility_parent_path));
|
2021-05-09 18:23:20 +02:00
|
|
|
new_parent = gi ? gi->get_instance() : RID();
|
|
|
|
} else if (data.parent) {
|
|
|
|
new_parent = data.parent->data.visibility_parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (new_parent == data.visibility_parent) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.visibility_parent = new_parent;
|
|
|
|
|
|
|
|
VisualInstance3D *vi = Object::cast_to<VisualInstance3D>(this);
|
|
|
|
if (vi) {
|
|
|
|
RS::get_singleton()->instance_set_visibility_parent(vi->get_instance(), data.visibility_parent);
|
|
|
|
}
|
|
|
|
|
2025-06-13 10:04:27 +01:00
|
|
|
for (Node3D *c : data.node3d_children) {
|
2021-05-09 18:23:20 +02:00
|
|
|
c->_update_visibility_parent(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Node3D::set_visibility_parent(const NodePath &p_path) {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_MAIN_THREAD_GUARD;
|
2021-05-09 18:23:20 +02:00
|
|
|
visibility_parent_path = p_path;
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
_update_visibility_parent(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NodePath Node3D::get_visibility_parent() const {
|
2023-05-12 13:53:15 +02:00
|
|
|
ERR_READ_THREAD_GUARD_V(NodePath());
|
2021-05-09 18:23:20 +02:00
|
|
|
return visibility_parent_path;
|
|
|
|
}
|
|
|
|
|
2022-08-12 23:57:11 +03:00
|
|
|
void Node3D::_validate_property(PropertyInfo &p_property) const {
|
|
|
|
if (data.rotation_edit_mode != ROTATION_EDIT_MODE_BASIS && p_property.name == "basis") {
|
|
|
|
p_property.usage = 0;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
2022-08-12 23:57:11 +03:00
|
|
|
if (data.rotation_edit_mode == ROTATION_EDIT_MODE_BASIS && p_property.name == "scale") {
|
|
|
|
p_property.usage = 0;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
2022-08-12 23:57:11 +03:00
|
|
|
if (data.rotation_edit_mode != ROTATION_EDIT_MODE_QUATERNION && p_property.name == "quaternion") {
|
|
|
|
p_property.usage = 0;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
2022-08-12 23:57:11 +03:00
|
|
|
if (data.rotation_edit_mode != ROTATION_EDIT_MODE_EULER && p_property.name == "rotation") {
|
|
|
|
p_property.usage = 0;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
2022-08-12 23:57:11 +03:00
|
|
|
if (data.rotation_edit_mode != ROTATION_EDIT_MODE_EULER && p_property.name == "rotation_order") {
|
|
|
|
p_property.usage = 0;
|
2021-10-21 13:38:20 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-12 21:43:14 +03:00
|
|
|
bool Node3D::_property_can_revert(const StringName &p_name) const {
|
2024-08-06 00:11:02 +02:00
|
|
|
const String sname = p_name;
|
|
|
|
if (sname == "basis") {
|
2022-01-02 15:33:17 +00:00
|
|
|
return true;
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "scale") {
|
2022-01-02 15:33:17 +00:00
|
|
|
return true;
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "quaternion") {
|
2022-01-02 15:33:17 +00:00
|
|
|
return true;
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "rotation") {
|
2022-01-02 15:33:17 +00:00
|
|
|
return true;
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "position") {
|
2022-01-02 15:33:17 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-12 21:43:14 +03:00
|
|
|
bool Node3D::_property_get_revert(const StringName &p_name, Variant &r_property) const {
|
2022-01-02 15:33:17 +00:00
|
|
|
bool valid = false;
|
|
|
|
|
2024-08-06 00:11:02 +02:00
|
|
|
const String sname = p_name;
|
|
|
|
if (sname == "basis") {
|
2022-01-02 15:33:17 +00:00
|
|
|
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
|
|
|
|
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Transform3D(variant).get_basis();
|
2022-01-02 15:33:17 +00:00
|
|
|
} else {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Basis();
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "scale") {
|
2022-01-02 15:33:17 +00:00
|
|
|
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
|
|
|
|
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Transform3D(variant).get_basis().get_scale();
|
2022-01-02 15:33:17 +00:00
|
|
|
} else {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Vector3(1.0, 1.0, 1.0);
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "quaternion") {
|
2022-01-02 15:33:17 +00:00
|
|
|
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
|
|
|
|
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Quaternion(Transform3D(variant).get_basis().get_rotation_quaternion());
|
2022-01-02 15:33:17 +00:00
|
|
|
} else {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Quaternion();
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "rotation") {
|
2022-01-02 15:33:17 +00:00
|
|
|
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
|
|
|
|
if (valid && variant.get_type() == Variant::Type::TRANSFORM3D) {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Transform3D(variant).get_basis().get_euler_normalized(data.euler_rotation_order);
|
2022-01-02 15:33:17 +00:00
|
|
|
} else {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Vector3();
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
2024-08-06 00:11:02 +02:00
|
|
|
} else if (sname == "position") {
|
2022-01-02 15:33:17 +00:00
|
|
|
Variant variant = PropertyUtils::get_property_default_value(this, "transform", &valid);
|
|
|
|
if (valid) {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Transform3D(variant).get_origin();
|
2022-01-02 15:33:17 +00:00
|
|
|
} else {
|
2022-08-12 21:43:14 +03:00
|
|
|
r_property = Vector3();
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
2022-08-12 21:43:14 +03:00
|
|
|
} else {
|
|
|
|
return false;
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
2022-08-12 21:43:14 +03:00
|
|
|
return true;
|
2022-01-02 15:33:17 +00:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
void Node3D::_bind_methods() {
|
2021-08-29 17:01:07 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform);
|
2020-03-26 18:49:16 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform);
|
2020-12-08 17:35:30 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_position", "position"), &Node3D::set_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_position"), &Node3D::get_position);
|
2022-12-18 16:58:19 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation", "euler_radians"), &Node3D::set_rotation);
|
2020-03-26 18:49:16 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation);
|
2022-12-18 16:58:19 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Node3D::set_rotation_degrees);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Node3D::get_rotation_degrees);
|
2021-10-21 13:38:20 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_order", "order"), &Node3D::set_rotation_order);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation_order"), &Node3D::get_rotation_order);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_edit_mode", "edit_mode"), &Node3D::set_rotation_edit_mode);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation_edit_mode"), &Node3D::get_rotation_edit_mode);
|
2020-03-26 18:49:16 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale);
|
2021-10-21 13:38:20 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_quaternion", "quaternion"), &Node3D::set_quaternion);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_quaternion"), &Node3D::get_quaternion);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_basis", "basis"), &Node3D::set_basis);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_basis"), &Node3D::get_basis);
|
2021-07-21 00:13:52 -04:00
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Node3D::set_global_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform"), &Node3D::get_global_transform);
|
2024-05-26 19:39:28 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform_interpolated"), &Node3D::get_global_transform_interpolated);
|
2021-07-21 00:13:52 -04:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_position", "position"), &Node3D::set_global_position);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_position"), &Node3D::get_global_position);
|
2023-08-11 11:41:49 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_basis", "basis"), &Node3D::set_global_basis);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_basis"), &Node3D::get_global_basis);
|
2022-12-18 16:58:19 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_rotation", "euler_radians"), &Node3D::set_global_rotation);
|
2021-07-21 00:13:52 -04:00
|
|
|
ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node3D::get_global_rotation);
|
2022-12-18 16:58:19 +01:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_rotation_degrees", "euler_degrees"), &Node3D::set_global_rotation_degrees);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_rotation_degrees"), &Node3D::get_global_rotation_degrees);
|
2021-07-21 00:13:52 -04:00
|
|
|
|
2021-06-09 13:06:38 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_parent_node_3d"), &Node3D::get_parent_node_3d);
|
2020-03-26 18:49:16 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification);
|
2020-10-02 17:03:52 -04:00
|
|
|
ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &Node3D::set_as_top_level);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &Node3D::is_set_as_top_level);
|
2020-03-26 18:49:16 -03:00
|
|
|
ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Node3D::set_disable_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Node3D::is_scale_disabled);
|
2020-04-18 11:00:51 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("get_world_3d"), &Node3D::get_world_3d);
|
2020-03-26 18:49:16 -03:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform);
|
|
|
|
|
2021-05-09 18:23:20 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("set_visibility_parent", "path"), &Node3D::set_visibility_parent);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_visibility_parent"), &Node3D::get_visibility_parent);
|
|
|
|
|
2021-06-23 16:49:50 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("update_gizmos"), &Node3D::update_gizmos);
|
|
|
|
ClassDB::bind_method(D_METHOD("add_gizmo", "gizmo"), &Node3D::add_gizmo);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gizmos"), &Node3D::get_gizmos_bind);
|
|
|
|
ClassDB::bind_method(D_METHOD("clear_gizmos"), &Node3D::clear_gizmos);
|
2021-02-04 17:20:26 +09:00
|
|
|
ClassDB::bind_method(D_METHOD("set_subgizmo_selection", "gizmo", "id", "transform"), &Node3D::set_subgizmo_selection);
|
2021-06-23 16:49:50 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("clear_subgizmo_selection"), &Node3D::clear_subgizmo_selection);
|
2020-03-26 18:49:16 -03:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Node3D::set_visible);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_visible"), &Node3D::is_visible);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Node3D::is_visible_in_tree);
|
|
|
|
ClassDB::bind_method(D_METHOD("show"), &Node3D::show);
|
|
|
|
ClassDB::bind_method(D_METHOD("hide"), &Node3D::hide);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Node3D::set_notify_local_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Node3D::is_local_transform_notification_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Node3D::set_notify_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Node3D::is_transform_notification_enabled);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Node3D::rotate);
|
|
|
|
ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Node3D::global_rotate);
|
|
|
|
ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Node3D::global_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Node3D::global_translate);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Node3D::rotate_object_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Node3D::scale_object_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Node3D::translate_object_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Node3D::rotate_x);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Node3D::rotate_y);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Node3D::rotate_z);
|
|
|
|
ClassDB::bind_method(D_METHOD("translate", "offset"), &Node3D::translate);
|
|
|
|
ClassDB::bind_method(D_METHOD("orthonormalize"), &Node3D::orthonormalize);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_identity"), &Node3D::set_identity);
|
|
|
|
|
2023-04-15 10:01:43 +02:00
|
|
|
ClassDB::bind_method(D_METHOD("look_at", "target", "up", "use_model_front"), &Node3D::look_at, DEFVAL(Vector3(0, 1, 0)), DEFVAL(false));
|
|
|
|
ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up", "use_model_front"), &Node3D::look_at_from_position, DEFVAL(Vector3(0, 1, 0)), DEFVAL(false));
|
2020-03-26 18:49:16 -03:00
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Node3D::to_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Node3D::to_global);
|
2017-07-23 14:37:26 +03:00
|
|
|
|
2014-02-09 22:10:30 -03:00
|
|
|
BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_ENTER_WORLD);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_EXIT_WORLD);
|
2014-08-14 10:31:38 -03:00
|
|
|
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
|
2022-09-19 13:43:46 +01:00
|
|
|
BIND_CONSTANT(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2021-10-21 13:38:20 -03:00
|
|
|
BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_EULER);
|
|
|
|
BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_QUATERNION);
|
|
|
|
BIND_ENUM_CONSTANT(ROTATION_EDIT_MODE_BASIS);
|
|
|
|
|
2017-01-04 01:16:14 -03:00
|
|
|
ADD_GROUP("Transform", "");
|
2021-12-02 18:09:19 -06:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "transform", PROPERTY_HINT_NONE, "suffix:m", PROPERTY_USAGE_NO_EDITOR), "set_transform", "get_transform");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM3D, "global_transform", PROPERTY_HINT_NONE, "suffix:m", PROPERTY_USAGE_NONE), "set_global_transform", "get_global_transform");
|
2024-12-19 00:11:39 -08:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "position", PROPERTY_HINT_RANGE, "-99999,99999,or_greater,or_less,hide_slider,suffix:m", PROPERTY_USAGE_EDITOR), "set_position", "get_position");
|
2023-09-23 16:27:01 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_less,or_greater,radians_as_degrees", PROPERTY_USAGE_EDITOR), "set_rotation", "get_rotation");
|
2022-12-18 16:58:19 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_rotation_degrees", "get_rotation_degrees");
|
2022-08-21 16:03:38 +09:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::QUATERNION, "quaternion", PROPERTY_HINT_HIDE_QUATERNION_EDIT, "", PROPERTY_USAGE_EDITOR), "set_quaternion", "get_quaternion");
|
2021-10-21 13:38:20 -03:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BASIS, "basis", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_basis", "get_basis");
|
2022-04-05 02:58:21 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_LINK, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
|
2021-10-21 13:38:20 -03:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_edit_mode", PROPERTY_HINT_ENUM, "Euler,Quaternion,Basis"), "set_rotation_edit_mode", "get_rotation_edit_mode");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::INT, "rotation_order", PROPERTY_HINT_ENUM, "XYZ,XZY,YXZ,YZX,ZXY,ZYX"), "set_rotation_order", "get_rotation_order");
|
2020-10-02 17:03:52 -04:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "top_level"), "set_as_top_level", "is_set_as_top_level");
|
2021-07-21 00:13:52 -04:00
|
|
|
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_position", "get_global_position");
|
2023-08-11 11:41:49 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BASIS, "global_basis", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_basis", "get_global_basis");
|
2021-07-21 00:13:52 -04:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation", "get_global_rotation");
|
2022-12-18 16:58:19 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "set_global_rotation_degrees", "get_global_rotation_degrees");
|
2017-01-04 01:16:14 -03:00
|
|
|
ADD_GROUP("Visibility", "");
|
2018-11-08 11:30:02 -03:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
|
2021-05-09 18:23:20 +02:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "visibility_parent", PROPERTY_HINT_NODE_PATH_VALID_TYPES, "GeometryInstance3D"), "set_visibility_parent", "get_visibility_parent");
|
2014-02-09 22:10:30 -03:00
|
|
|
|
2014-08-14 10:31:38 -03:00
|
|
|
ADD_SIGNAL(MethodInfo("visibility_changed"));
|
2014-02-09 22:10:30 -03:00
|
|
|
}
|
|
|
|
|
2020-03-26 18:49:16 -03:00
|
|
|
Node3D::Node3D() :
|
2024-05-26 19:39:28 +02:00
|
|
|
xform_change(this), _client_physics_interpolation_node_3d_list(this) {
|
|
|
|
// Default member initializer for bitfield is a C++20 extension, so:
|
|
|
|
|
|
|
|
data.top_level = false;
|
|
|
|
data.inside_world = false;
|
|
|
|
|
|
|
|
data.ignore_notification = false;
|
|
|
|
data.notify_local_transform = false;
|
|
|
|
data.notify_transform = false;
|
2025-04-29 11:44:25 +01:00
|
|
|
data.notify_transform_requested = false;
|
|
|
|
data.notify_transform_when_fti_off = false;
|
2024-05-26 19:39:28 +02:00
|
|
|
|
|
|
|
data.visible = true;
|
|
|
|
data.disable_scale = false;
|
|
|
|
data.vi_visible = true;
|
|
|
|
|
2025-03-14 10:02:43 +00:00
|
|
|
data.fti_on_frame_xform_list = false;
|
|
|
|
data.fti_on_frame_property_list = false;
|
|
|
|
data.fti_on_tick_xform_list = false;
|
|
|
|
data.fti_on_tick_property_list = false;
|
|
|
|
data.fti_global_xform_interp_set = false;
|
|
|
|
data.fti_frame_xform_force_update = false;
|
2025-05-10 11:47:02 +01:00
|
|
|
data.fti_is_identity_xform = false;
|
|
|
|
data.fti_processed = false;
|
2025-03-14 10:02:43 +00:00
|
|
|
|
2024-05-26 19:39:28 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
data.gizmos_disabled = false;
|
|
|
|
data.gizmos_dirty = false;
|
|
|
|
data.transform_gizmo_visible = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
Node3D::~Node3D() {
|
|
|
|
_disable_client_physics_interpolation();
|
2025-03-14 10:02:43 +00:00
|
|
|
|
|
|
|
if (is_inside_tree()) {
|
|
|
|
get_tree()->get_scene_tree_fti().node_3d_notify_delete(this);
|
|
|
|
}
|
2024-05-26 19:39:28 +02:00
|
|
|
}
|