2023-01-10 14:26:54 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* spatial.cpp */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* 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-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "spatial.h"
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/engine.h"
|
2021-09-15 11:30:45 +00:00
|
|
|
#include "core/math/transform_interpolator.h"
|
2018-09-11 16:13:45 +00:00
|
|
|
#include "core/message_queue.h"
|
2018-10-29 10:30:28 +00:00
|
|
|
#include "scene/main/scene_tree.h"
|
2017-03-05 15:44:50 +00:00
|
|
|
#include "scene/main/viewport.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/scene_string_names.h"
|
2021-02-04 10:43:08 +00:00
|
|
|
#include "servers/visual_server_callbacks.h"
|
2014-02-10 01:10:30 +00: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 12:15:02 +00:00
|
|
|
. a) If above is invalid, don't keep invalidating upwards
|
2014-02-10 01:10:30 +00:00
|
|
|
2) If a node sets a GLOBAL, it is converted to LOCAL (and forces validation of everything pending below)
|
|
|
|
|
|
|
|
drawback: setting/reading globals is useful and used very very often, and using affine inverses is slow
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
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 12:15:02 +00:00
|
|
|
. a) marking GLOBALs as dirty up all the tree must be done always
|
2014-02-10 01:10:30 +00: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
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
SpatialGizmo::SpatialGizmo() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::_notify_dirty() {
|
2017-08-09 11:18:07 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
|
|
|
|
#else
|
2017-01-12 23:35:46 +00:00
|
|
|
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-09 11:18:07 +00:00
|
|
|
#endif
|
2014-11-06 00:20:42 +00:00
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::_update_local_transform() const {
|
2018-04-14 19:53:25 +00:00
|
|
|
data.local_transform.basis.set_euler_scale(data.rotation, data.scale);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty &= ~DIRTY_LOCAL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
void Spatial::_propagate_transform_changed(Spatial *p_origin) {
|
2014-11-06 00:20:42 +00:00
|
|
|
if (!is_inside_tree()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 11:26:56 +00:00
|
|
|
/*
|
|
|
|
if (data.dirty&DIRTY_GLOBAL)
|
|
|
|
return; //already dirty
|
|
|
|
*/
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
data.children_lock++;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (E->get()->data.toplevel_active) {
|
2014-02-10 01:10:30 +00:00
|
|
|
continue; //don't propagate to a toplevel
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
E->get()->_propagate_transform_changed(p_origin);
|
|
|
|
}
|
2017-08-09 11:18:07 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
|
|
|
|
#else
|
2017-01-12 23:35:46 +00:00
|
|
|
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
|
2017-08-09 11:18:07 +00:00
|
|
|
#endif
|
2014-11-06 00:20:42 +00:00
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty |= DIRTY_GLOBAL;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
data.children_lock--;
|
|
|
|
}
|
|
|
|
|
2021-02-04 10:43:08 +00:00
|
|
|
void Spatial::notification_callback(int p_message_type) {
|
|
|
|
switch (p_message_type) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case VisualServerCallbacks::CALLBACK_NOTIFICATION_ENTER_GAMEPLAY: {
|
|
|
|
notification(NOTIFICATION_ENTER_GAMEPLAY);
|
|
|
|
} break;
|
|
|
|
case VisualServerCallbacks::CALLBACK_NOTIFICATION_EXIT_GAMEPLAY: {
|
|
|
|
notification(NOTIFICATION_EXIT_GAMEPLAY);
|
|
|
|
} break;
|
|
|
|
case VisualServerCallbacks::CALLBACK_SIGNAL_ENTER_GAMEPLAY: {
|
|
|
|
emit_signal("gameplay_entered");
|
|
|
|
} break;
|
|
|
|
case VisualServerCallbacks::CALLBACK_SIGNAL_EXIT_GAMEPLAY: {
|
|
|
|
emit_signal("gameplay_exited");
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Spatial::_notification(int p_what) {
|
2017-03-05 15:44:50 +00:00
|
|
|
switch (p_what) {
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2020-01-25 05:16:27 +00:00
|
|
|
ERR_FAIL_COND(!get_tree());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Node *p = get_parent();
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p) {
|
2017-08-24 20:58:51 +00:00
|
|
|
data.parent = Object::cast_to<Spatial>(p);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (data.parent) {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.C = data.parent->data.children.push_back(this);
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2021-05-04 14:00:45 +00:00
|
|
|
data.C = nullptr;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-08-18 23:02:56 +00:00
|
|
|
if (data.toplevel && !Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
if (data.parent) {
|
|
|
|
data.local_transform = data.parent->get_global_transform() * get_transform();
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty = DIRTY_VECTORS; //global is always dirty upon entering a scene
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
data.toplevel_active = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty |= DIRTY_GLOBAL; //global is always dirty upon entering a scene
|
2014-02-10 01:10:30 +00:00
|
|
|
_notify_dirty();
|
|
|
|
|
|
|
|
notification(NOTIFICATION_ENTER_WORLD);
|
|
|
|
|
|
|
|
} break;
|
2014-11-06 00:20:42 +00:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2017-03-05 15:44:50 +00:00
|
|
|
notification(NOTIFICATION_EXIT_WORLD, true);
|
2021-05-05 10:44:11 +00:00
|
|
|
if (xform_change.in_list()) {
|
2014-11-06 00:20:42 +00:00
|
|
|
get_tree()->xform_change_list.remove(&xform_change);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
|
|
|
if (data.C) {
|
2014-02-10 01:10:30 +00:00
|
|
|
data.parent->data.children.erase(data.C);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2021-05-04 14:00:45 +00:00
|
|
|
data.parent = nullptr;
|
|
|
|
data.C = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
data.toplevel_active = false;
|
2022-02-21 07:34:42 +00:00
|
|
|
_disable_client_physics_interpolation();
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_ENTER_WORLD: {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.inside_world = true;
|
2021-05-04 14:00:45 +00:00
|
|
|
data.viewport = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
Node *parent = get_parent();
|
2017-03-05 15:44:50 +00:00
|
|
|
while (parent && !data.viewport) {
|
2017-08-24 20:58:51 +00:00
|
|
|
data.viewport = Object::cast_to<Viewport>(parent);
|
2017-03-05 15:44:50 +00:00
|
|
|
parent = parent->get_parent();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!data.viewport);
|
|
|
|
|
|
|
|
if (get_script_instance()) {
|
2021-05-04 14:00:45 +00:00
|
|
|
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, nullptr, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#ifdef TOOLS_ENABLED
|
2019-03-07 12:25:35 +00:00
|
|
|
if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
|
2017-01-14 11:26:56 +00:00
|
|
|
//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this);
|
2017-03-05 15:44:50 +00:00
|
|
|
get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!data.gizmo_disabled) {
|
2017-08-26 03:40:45 +00:00
|
|
|
if (data.gizmo.is_valid()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
data.gizmo->create();
|
2018-09-02 20:31:03 +00:00
|
|
|
if (is_visible_in_tree()) {
|
|
|
|
data.gizmo->redraw();
|
2017-08-26 03:40:45 +00:00
|
|
|
}
|
|
|
|
data.gizmo->transform();
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_WORLD: {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (data.gizmo.is_valid()) {
|
|
|
|
data.gizmo->free();
|
2018-07-24 22:08:49 +00:00
|
|
|
data.gizmo.unref();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (get_script_instance()) {
|
2021-05-04 14:00:45 +00:00
|
|
|
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, nullptr, 0);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2021-05-04 14:00:45 +00:00
|
|
|
data.viewport = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
data.inside_world = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (data.gizmo.is_valid()) {
|
|
|
|
data.gizmo->transform();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} break;
|
2021-09-15 11:30:45 +00:00
|
|
|
case NOTIFICATION_RESET_PHYSICS_INTERPOLATION: {
|
2022-02-21 07:34:42 +00:00
|
|
|
if (data.client_physics_interpolation_data) {
|
|
|
|
data.client_physics_interpolation_data->global_xform_prev = data.client_physics_interpolation_data->global_xform_curr;
|
2021-09-15 11:30:45 +00:00
|
|
|
}
|
|
|
|
} break;
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2019-04-09 15:08:36 +00:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-21 04:13:52 +00:00
|
|
|
Vector3 Spatial::get_global_translation() const {
|
|
|
|
return get_global_transform().get_origin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::set_global_translation(const Vector3 &p_translation) {
|
|
|
|
Transform transform = get_global_transform();
|
|
|
|
transform.set_origin(p_translation);
|
|
|
|
set_global_transform(transform);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 Spatial::get_global_rotation() const {
|
|
|
|
return get_global_transform().get_basis().get_euler();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::set_global_rotation(const Vector3 &p_euler_rad) {
|
|
|
|
Transform transform = get_global_transform();
|
|
|
|
Basis new_basis = transform.get_basis();
|
|
|
|
new_basis.set_euler(p_euler_rad);
|
|
|
|
transform.set_basis(new_basis);
|
|
|
|
set_global_transform(transform);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::set_transform(const Transform &p_transform) {
|
|
|
|
data.local_transform = p_transform;
|
|
|
|
data.dirty |= DIRTY_VECTORS;
|
2017-04-03 16:34:44 +00:00
|
|
|
_change_notify("translation");
|
|
|
|
_change_notify("rotation");
|
2017-11-10 10:07:52 +00:00
|
|
|
_change_notify("rotation_degrees");
|
2017-04-03 16:34:44 +00:00
|
|
|
_change_notify("scale");
|
2014-02-10 01:10:30 +00:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 01:07:03 +00:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::set_global_transform(const Transform &p_transform) {
|
2021-01-30 15:17:58 +00:00
|
|
|
Transform xform = (data.parent && !data.toplevel_active) ? data.parent->get_global_transform().affine_inverse() * p_transform : p_transform;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
set_transform(xform);
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform Spatial::get_transform() const {
|
|
|
|
if (data.dirty & DIRTY_LOCAL) {
|
|
|
|
_update_local_transform();
|
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return data.local_transform;
|
|
|
|
}
|
2021-09-15 11:30:45 +00:00
|
|
|
|
2022-02-21 07:34:42 +00:00
|
|
|
// Return false to timeout and remove from the client interpolation list.
|
|
|
|
bool Spatial::update_client_physics_interpolation_data() {
|
|
|
|
if (!is_inside_tree() || !_is_physics_interpolated_client_side()) {
|
|
|
|
return false;
|
2021-09-15 11:30:45 +00:00
|
|
|
}
|
2022-02-21 07:34:42 +00:00
|
|
|
ERR_FAIL_NULL_V(data.client_physics_interpolation_data, false);
|
|
|
|
ClientPhysicsInterpolationData &pid = *data.client_physics_interpolation_data;
|
2021-09-15 11:30:45 +00:00
|
|
|
|
|
|
|
uint64_t tick = Engine::get_singleton()->get_physics_frames();
|
2022-02-21 07:34:42 +00:00
|
|
|
|
|
|
|
// 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();
|
|
|
|
}
|
2021-09-15 11:30:45 +00:00
|
|
|
pid.current_physics_tick = tick;
|
|
|
|
}
|
|
|
|
|
|
|
|
pid.global_xform_curr = get_global_transform();
|
2022-02-21 07:34:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::_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_spatials_list.in_list()) {
|
|
|
|
tree->client_physics_interpolation_remove_spatial(&_client_physics_interpolation_spatials_list);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_set_physics_interpolated_client_side(false);
|
2021-09-15 11:30:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Transform Spatial::_get_global_transform_interpolated(real_t p_interpolation_fraction) {
|
|
|
|
ERR_FAIL_NULL_V(is_inside_tree(), Transform());
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2022-02-21 07:34:42 +00:00
|
|
|
ERR_FAIL_COND_V(data.client_physics_interpolation_data, Transform());
|
|
|
|
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();
|
2021-09-15 11:30:45 +00:00
|
|
|
}
|
|
|
|
|
2022-02-21 07:34:42 +00:00
|
|
|
// 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 behaviour
|
|
|
|
// would be machine dependent.
|
|
|
|
data.client_physics_interpolation_data->timeout_physics_tick = Engine::get_singleton()->get_physics_frames() + 256;
|
|
|
|
|
2021-09-15 11:30:45 +00:00
|
|
|
// make sure data is up to date
|
2022-02-21 07:34:42 +00:00
|
|
|
update_client_physics_interpolation_data();
|
2021-09-15 11:30:45 +00:00
|
|
|
|
|
|
|
// interpolate the current data
|
2022-02-21 07:34:42 +00:00
|
|
|
const Transform &xform_curr = data.client_physics_interpolation_data->global_xform_curr;
|
|
|
|
const Transform &xform_prev = data.client_physics_interpolation_data->global_xform_prev;
|
2021-09-15 11:30:45 +00:00
|
|
|
|
|
|
|
Transform res;
|
|
|
|
TransformInterpolator::interpolate_transform(xform_prev, xform_curr, res, p_interpolation_fraction);
|
2022-02-21 07:34:42 +00:00
|
|
|
|
|
|
|
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_spatials_list.in_list()) {
|
|
|
|
tree->client_physics_interpolation_add_spatial(&_client_physics_interpolation_spatials_list);
|
|
|
|
}
|
|
|
|
|
2021-09-15 11:30:45 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform Spatial::get_global_transform_interpolated() {
|
|
|
|
// 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.
|
2022-02-21 07:34:42 +00:00
|
|
|
if (Engine::get_singleton()->is_in_physics_frame() || !is_physics_interpolated_and_enabled()) {
|
2021-09-15 11:30:45 +00:00
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _get_global_transform_interpolated(Engine::get_singleton()->get_physics_interpolation_fraction());
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform Spatial::get_global_transform() const {
|
2014-11-06 00:20:42 +00:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (data.dirty & DIRTY_GLOBAL) {
|
|
|
|
if (data.dirty & DIRTY_LOCAL) {
|
|
|
|
_update_local_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.parent && !data.toplevel_active) {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.global_transform = data.parent->get_global_transform() * data.local_transform;
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.global_transform = data.local_transform;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2018-07-18 16:47:42 +00:00
|
|
|
if (data.disable_scale) {
|
|
|
|
data.global_transform.basis.orthonormalize();
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty &= ~DIRTY_GLOBAL;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return data.global_transform;
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:49:32 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
Transform Spatial::get_global_gizmo_transform() const {
|
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
Transform Spatial::get_local_gizmo_transform() const {
|
|
|
|
return get_transform();
|
|
|
|
}
|
2021-08-17 12:40:39 +00:00
|
|
|
|
|
|
|
// If not a VisualInstance, use this AABB for the orange box in the editor
|
|
|
|
AABB Spatial::get_fallback_gizmo_aabb() const {
|
|
|
|
return AABB(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4));
|
|
|
|
}
|
|
|
|
|
2017-10-03 16:49:32 +00:00
|
|
|
#endif
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Spatial *Spatial::get_parent_spatial() const {
|
|
|
|
return data.parent;
|
|
|
|
}
|
|
|
|
|
2021-09-15 11:30:45 +00:00
|
|
|
void Spatial::_set_vi_visible(bool p_visible) {
|
|
|
|
data.vi_visible = p_visible;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
Transform Spatial::get_relative_transform(const Node *p_parent) const {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_parent == this) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return Transform();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!data.parent, Transform());
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_parent == data.parent) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return get_transform();
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2014-02-10 01:10:30 +00:00
|
|
|
return data.parent->get_relative_transform(p_parent) * get_transform();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::set_translation(const Vector3 &p_translation) {
|
|
|
|
data.local_transform.origin = p_translation;
|
2019-11-30 16:16:19 +00:00
|
|
|
_change_notify("transform");
|
2014-02-10 01:10:30 +00:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 01:07:03 +00:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::set_rotation(const Vector3 &p_euler_rad) {
|
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.rotation = p_euler_rad;
|
|
|
|
data.dirty |= DIRTY_LOCAL;
|
2019-11-30 16:16:19 +00:00
|
|
|
_change_notify("transform");
|
2014-02-10 01:10:30 +00:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 01:07:03 +00:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2016-05-06 21:38:08 +00:00
|
|
|
|
2017-11-10 10:07:52 +00:00
|
|
|
void Spatial::set_rotation_degrees(const Vector3 &p_euler_deg) {
|
2016-05-06 21:38:08 +00:00
|
|
|
set_rotation(p_euler_deg * Math_PI / 180.0);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::set_scale(const Vector3 &p_scale) {
|
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.rotation = data.local_transform.basis.get_rotation();
|
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.scale = p_scale;
|
|
|
|
data.dirty |= DIRTY_LOCAL;
|
2019-11-30 16:16:19 +00:00
|
|
|
_change_notify("transform");
|
2014-02-10 01:10:30 +00:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 01:07:03 +00:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 Spatial::get_translation() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return data.local_transform.origin;
|
|
|
|
}
|
2016-05-06 21:38:08 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 Spatial::get_rotation() const {
|
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.rotation = data.local_transform.basis.get_rotation();
|
2017-01-05 17:31:39 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data.rotation;
|
|
|
|
}
|
2016-05-06 21:38:08 +00:00
|
|
|
|
2017-11-10 10:07:52 +00:00
|
|
|
Vector3 Spatial::get_rotation_degrees() const {
|
2016-05-06 21:38:08 +00:00
|
|
|
return get_rotation() * 180.0 / Math_PI;
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
Vector3 Spatial::get_scale() const {
|
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.rotation = data.local_transform.basis.get_rotation();
|
2017-01-05 17:31:39 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return data.scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::update_gizmo() {
|
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!is_inside_world()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
|
|
|
if (!data.gizmo.is_valid()) {
|
2018-10-29 10:30:28 +00:00
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
|
|
|
if (!data.gizmo.is_valid()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
|
|
|
if (data.gizmo_dirty) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
data.gizmo_dirty = true;
|
|
|
|
MessageQueue::get_singleton()->push_call(this, "_update_gizmo");
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::set_gizmo(const Ref<SpatialGizmo> &p_gizmo) {
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
2021-05-05 10:44:11 +00:00
|
|
|
if (data.gizmo_disabled) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
|
|
|
if (data.gizmo.is_valid() && is_inside_world()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
data.gizmo->free();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
data.gizmo = p_gizmo;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (data.gizmo.is_valid() && is_inside_world()) {
|
|
|
|
data.gizmo->create();
|
2018-09-02 20:31:03 +00:00
|
|
|
if (is_visible_in_tree()) {
|
|
|
|
data.gizmo->redraw();
|
2017-08-26 03:40:45 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
data.gizmo->transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<SpatialGizmo> Spatial::get_gizmo() const {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
return data.gizmo;
|
|
|
|
#else
|
|
|
|
|
|
|
|
return Ref<SpatialGizmo>();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::_update_gizmo() {
|
2018-04-29 17:49:26 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!is_inside_world()) {
|
2017-08-26 03:40:45 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
data.gizmo_dirty = false;
|
2014-09-19 21:39:50 +00:00
|
|
|
if (data.gizmo.is_valid()) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (is_visible_in_tree()) {
|
2018-09-02 20:31:03 +00:00
|
|
|
data.gizmo->redraw();
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2018-09-02 20:31:03 +00:00
|
|
|
data.gizmo->clear();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-09-19 21:39:50 +00:00
|
|
|
}
|
2018-04-29 17:49:26 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::set_disable_gizmo(bool p_enabled) {
|
2021-10-18 16:58:37 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
data.gizmo_disabled = p_enabled;
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!p_enabled && data.gizmo.is_valid()) {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.gizmo = Ref<SpatialGizmo>();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
2021-10-18 16:58:37 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2018-07-18 16:47:42 +00:00
|
|
|
void Spatial::set_disable_scale(bool p_enabled) {
|
|
|
|
data.disable_scale = p_enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Spatial::is_scale_disabled() const {
|
|
|
|
return data.disable_scale;
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Spatial::set_as_toplevel(bool p_enabled) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (data.toplevel == p_enabled) {
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2017-08-18 23:02:56 +00:00
|
|
|
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_enabled) {
|
2014-02-10 01:10:30 +00:00
|
|
|
set_transform(get_global_transform());
|
2021-05-05 10:44:11 +00:00
|
|
|
} else if (data.parent) {
|
2014-02-10 01:10:30 +00:00
|
|
|
set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.toplevel = p_enabled;
|
|
|
|
data.toplevel_active = p_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.toplevel = p_enabled;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Spatial::is_set_as_toplevel() const {
|
2014-02-10 01:10:30 +00:00
|
|
|
return data.toplevel;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ref<World> Spatial::get_world() const {
|
2017-03-05 15:44:50 +00:00
|
|
|
ERR_FAIL_COND_V(!is_inside_world(), Ref<World>());
|
2019-06-22 12:52:51 +00:00
|
|
|
ERR_FAIL_COND_V(!data.viewport, Ref<World>());
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
return data.viewport->find_world();
|
|
|
|
}
|
|
|
|
|
2014-08-14 13:31:38 +00:00
|
|
|
void Spatial::_propagate_visibility_changed() {
|
|
|
|
notification(NOTIFICATION_VISIBILITY_CHANGED);
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
|
2017-04-03 16:34:44 +00:00
|
|
|
_change_notify("visible");
|
2014-09-19 21:39:50 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-05-05 10:44:11 +00:00
|
|
|
if (data.gizmo.is_valid()) {
|
2014-09-19 21:39:50 +00:00
|
|
|
_update_gizmo();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-09-19 21:39:50 +00:00
|
|
|
#endif
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
for (List<Spatial *>::Element *E = data.children.front(); E; E = E->next()) {
|
|
|
|
Spatial *c = E->get();
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!c || !c->data.visible) {
|
2014-08-14 13:31:38 +00:00
|
|
|
continue;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
c->_propagate_visibility_changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::show() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (data.visible) {
|
2014-08-14 13:31:38 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.visible = true;
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2021-01-30 15:17:58 +00:00
|
|
|
if (!is_inside_tree()) {
|
2014-08-14 13:31:38 +00:00
|
|
|
return;
|
2021-01-30 15:17:58 +00:00
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-07-02 15:27:27 +00:00
|
|
|
_propagate_visibility_changed();
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::hide() {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (!data.visible) {
|
2014-08-14 13:31:38 +00:00
|
|
|
return;
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.visible = false;
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2021-01-30 15:17:58 +00:00
|
|
|
if (!is_inside_tree()) {
|
2017-07-02 15:27:27 +00:00
|
|
|
return;
|
2021-01-30 15:17:58 +00:00
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-07-02 15:27:27 +00:00
|
|
|
_propagate_visibility_changed();
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
2017-07-02 15:27:27 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
bool Spatial::is_visible_in_tree() const {
|
|
|
|
const Spatial *s = this;
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
while (s) {
|
2014-08-14 13:31:38 +00:00
|
|
|
if (!s->data.visible) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-05 15:44:50 +00:00
|
|
|
s = s->data.parent;
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
void Spatial::set_visible(bool p_visible) {
|
2021-05-05 10:44:11 +00:00
|
|
|
if (p_visible) {
|
2014-08-14 13:31:38 +00:00
|
|
|
show();
|
2021-05-05 10:44:11 +00:00
|
|
|
} else {
|
2014-08-14 13:31:38 +00:00
|
|
|
hide();
|
2021-05-05 10:44:11 +00:00
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-13 13:45:50 +00:00
|
|
|
bool Spatial::is_visible() const {
|
2017-01-18 20:49:30 +00:00
|
|
|
return data.visible;
|
2014-08-14 13:31:38 +00:00
|
|
|
}
|
|
|
|
|
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-27 00:15:20 +00:00
|
|
|
void Spatial::rotate_object_local(const Vector3 &p_axis, float p_angle) {
|
|
|
|
Transform t = get_transform();
|
|
|
|
t.basis.rotate_local(p_axis, p_angle);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::rotate(const Vector3 &p_axis, float p_angle) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform 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-27 00:15:20 +00:00
|
|
|
t.basis.rotate(p_axis, p_angle);
|
2015-03-22 13:33:58 +00:00
|
|
|
set_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-27 00:15:20 +00:00
|
|
|
void Spatial::rotate_x(float p_angle) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform 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-27 00:15:20 +00:00
|
|
|
t.basis.rotate(Vector3(1, 0, 0), p_angle);
|
2015-03-22 13:33:58 +00:00
|
|
|
set_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-27 00:15:20 +00:00
|
|
|
void Spatial::rotate_y(float p_angle) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform 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-27 00:15:20 +00:00
|
|
|
t.basis.rotate(Vector3(0, 1, 0), p_angle);
|
2015-03-22 13:33:58 +00:00
|
|
|
set_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-27 00:15:20 +00:00
|
|
|
void Spatial::rotate_z(float p_angle) {
|
2017-03-05 15:44:50 +00:00
|
|
|
Transform 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-27 00:15:20 +00:00
|
|
|
t.basis.rotate(Vector3(0, 0, 1), p_angle);
|
2015-03-22 13:33:58 +00:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::translate(const Vector3 &p_offset) {
|
|
|
|
Transform t = get_transform();
|
2015-06-06 12:44:38 +00:00
|
|
|
t.translate(p_offset);
|
2015-03-22 13:33:58 +00:00
|
|
|
set_transform(t);
|
|
|
|
}
|
2015-06-06 12:44:38 +00:00
|
|
|
|
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-27 00:15:20 +00:00
|
|
|
void Spatial::translate_object_local(const Vector3 &p_offset) {
|
|
|
|
Transform t = get_transform();
|
|
|
|
|
|
|
|
Transform s;
|
|
|
|
s.translate(p_offset);
|
|
|
|
set_transform(t * s);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::scale(const Vector3 &p_ratio) {
|
|
|
|
Transform t = get_transform();
|
2015-03-22 13:33:58 +00:00
|
|
|
t.basis.scale(p_ratio);
|
|
|
|
set_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-27 00:15:20 +00:00
|
|
|
void Spatial::scale_object_local(const Vector3 &p_scale) {
|
|
|
|
Transform t = get_transform();
|
|
|
|
t.basis.scale_local(p_scale);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::global_rotate(const Vector3 &p_axis, float p_angle) {
|
2015-03-22 13:33:58 +00:00
|
|
|
Transform t = get_global_transform();
|
2018-05-17 00:32:35 +00:00
|
|
|
t.basis.rotate(p_axis, p_angle);
|
2015-03-22 13:33:58 +00: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-27 00:15:20 +00:00
|
|
|
|
|
|
|
void Spatial::global_scale(const Vector3 &p_scale) {
|
|
|
|
Transform t = get_global_transform();
|
2018-05-17 00:32:35 +00: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-27 00:15:20 +00:00
|
|
|
set_global_transform(t);
|
|
|
|
}
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
void Spatial::global_translate(const Vector3 &p_offset) {
|
2015-03-22 13:33:58 +00:00
|
|
|
Transform t = get_global_transform();
|
2017-03-05 15:44:50 +00:00
|
|
|
t.origin += p_offset;
|
2015-03-22 13:33:58 +00:00
|
|
|
set_global_transform(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::orthonormalize() {
|
|
|
|
Transform t = get_transform();
|
|
|
|
t.orthonormalize();
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2015-03-22 14:52:07 +00:00
|
|
|
void Spatial::set_identity() {
|
|
|
|
set_transform(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-27 00:15:20 +00:00
|
|
|
void Spatial::look_at(const Vector3 &p_target, const Vector3 &p_up) {
|
2019-05-23 12:49:50 +00:00
|
|
|
Vector3 origin(get_global_transform().origin);
|
|
|
|
look_at_from_position(origin, p_target, p_up);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Spatial::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) {
|
2019-08-08 20:11:48 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_pos == p_target, "Node origin and target are in the same position, look_at() failed.");
|
2022-01-31 02:49:52 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_up == Vector3(), "The up vector can't be zero, look_at() failed.");
|
2019-08-08 20:11:48 +00:00
|
|
|
ERR_FAIL_COND_MSG(p_up.cross(p_target - p_pos) == Vector3(), "Up vector and direction between node origin and target are aligned, look_at() failed.");
|
2015-03-22 13:33:58 +00:00
|
|
|
|
|
|
|
Transform lookat;
|
2017-03-05 15:44:50 +00:00
|
|
|
lookat.origin = p_pos;
|
2019-05-23 12:49:50 +00:00
|
|
|
|
2019-10-11 05:22:02 +00:00
|
|
|
Vector3 original_scale(get_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-27 00:15:20 +00:00
|
|
|
lookat = lookat.looking_at(p_target, p_up);
|
2015-03-22 13:33:58 +00:00
|
|
|
set_global_transform(lookat);
|
2019-10-11 05:22:02 +00:00
|
|
|
set_scale(original_scale);
|
2015-03-22 13:33:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-23 11:37:26 +00:00
|
|
|
Vector3 Spatial::to_local(Vector3 p_global) const {
|
|
|
|
return get_global_transform().affine_inverse().xform(p_global);
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector3 Spatial::to_global(Vector3 p_local) const {
|
|
|
|
return get_global_transform().xform(p_local);
|
|
|
|
}
|
|
|
|
|
2017-01-12 23:35:46 +00:00
|
|
|
void Spatial::set_notify_transform(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.notify_transform = p_enable;
|
2017-01-12 23:35:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Spatial::is_transform_notification_enabled() const {
|
|
|
|
return data.notify_transform;
|
|
|
|
}
|
|
|
|
|
2015-09-16 01:07:03 +00:00
|
|
|
void Spatial::set_notify_local_transform(bool p_enable) {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.notify_local_transform = p_enable;
|
2015-09-16 01:07:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Spatial::is_local_transform_notification_enabled() const {
|
|
|
|
return data.notify_local_transform;
|
|
|
|
}
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2018-09-06 23:38:16 +00:00
|
|
|
void Spatial::force_update_transform() {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void Spatial::_bind_methods() {
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "local"), &Spatial::set_transform);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_transform"), &Spatial::get_transform);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Spatial::set_translation);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_translation"), &Spatial::get_translation);
|
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-27 00:15:20 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Spatial::set_rotation);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation"), &Spatial::get_rotation);
|
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-27 00:15:20 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation_degrees", "euler_degrees"), &Spatial::set_rotation_degrees);
|
2017-11-10 10:07:52 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation_degrees"), &Spatial::get_rotation_degrees);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Spatial::set_scale);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_scale"), &Spatial::get_scale);
|
2021-07-21 04:13:52 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_transform", "global"), &Spatial::set_global_transform);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform"), &Spatial::get_global_transform);
|
2021-07-21 04:13:52 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_global_translation", "translation"), &Spatial::set_global_translation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_translation"), &Spatial::get_global_translation);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_global_rotation", "radians"), &Spatial::set_global_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_global_rotation"), &Spatial::get_global_rotation);
|
|
|
|
|
2021-09-15 11:30:45 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_global_transform_interpolated"), &Spatial::get_global_transform_interpolated);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Spatial::get_parent_spatial);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Spatial::set_ignore_transform_notification);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Spatial::set_as_toplevel);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Spatial::is_set_as_toplevel);
|
2018-07-18 16:47:42 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_disable_scale", "disable"), &Spatial::set_disable_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_scale_disabled"), &Spatial::is_scale_disabled);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("get_world"), &Spatial::get_world);
|
2016-05-06 21:38:08 +00:00
|
|
|
|
2018-09-06 23:38:16 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("force_update_transform"), &Spatial::force_update_transform);
|
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("_update_gizmo"), &Spatial::_update_gizmo);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("update_gizmo"), &Spatial::update_gizmo);
|
2017-08-09 11:19:41 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Spatial::set_gizmo);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gizmo"), &Spatial::get_gizmo);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-07-22 10:11:42 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &Spatial::set_visible);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_visible"), &Spatial::is_visible);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &Spatial::is_visible_in_tree);
|
|
|
|
ClassDB::bind_method(D_METHOD("show"), &Spatial::show);
|
|
|
|
ClassDB::bind_method(D_METHOD("hide"), &Spatial::hide);
|
2014-08-14 13:31:38 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &Spatial::set_notify_local_transform);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &Spatial::is_local_transform_notification_enabled);
|
2015-09-16 01:07:03 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &Spatial::set_notify_transform);
|
2017-02-13 11:47:24 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &Spatial::is_transform_notification_enabled);
|
2017-01-12 23:35:46 +00:00
|
|
|
|
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-27 00:15:20 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("rotate", "axis", "angle"), &Spatial::rotate);
|
|
|
|
ClassDB::bind_method(D_METHOD("global_rotate", "axis", "angle"), &Spatial::global_rotate);
|
|
|
|
ClassDB::bind_method(D_METHOD("global_scale", "scale"), &Spatial::global_scale);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Spatial::global_translate);
|
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-27 00:15:20 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("rotate_object_local", "axis", "angle"), &Spatial::rotate_object_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("scale_object_local", "scale"), &Spatial::scale_object_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("translate_object_local", "offset"), &Spatial::translate_object_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_x", "angle"), &Spatial::rotate_x);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_y", "angle"), &Spatial::rotate_y);
|
|
|
|
ClassDB::bind_method(D_METHOD("rotate_z", "angle"), &Spatial::rotate_z);
|
|
|
|
ClassDB::bind_method(D_METHOD("translate", "offset"), &Spatial::translate);
|
2017-03-05 15:44:50 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("orthonormalize"), &Spatial::orthonormalize);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_identity"), &Spatial::set_identity);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Spatial::look_at);
|
2017-09-10 13:37:49 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Spatial::look_at_from_position);
|
2017-03-05 15:44:50 +00:00
|
|
|
|
2017-07-23 11:37:26 +00:00
|
|
|
ClassDB::bind_method(D_METHOD("to_local", "global_point"), &Spatial::to_local);
|
|
|
|
ClassDB::bind_method(D_METHOD("to_global", "local_point"), &Spatial::to_global);
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_ENTER_WORLD);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_EXIT_WORLD);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
|
2021-02-04 10:43:08 +00:00
|
|
|
BIND_CONSTANT(NOTIFICATION_ENTER_GAMEPLAY);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_EXIT_GAMEPLAY);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Transform", "");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_translation", "get_translation");
|
2017-11-10 10:07:52 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation");
|
2022-04-05 00:58:21 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_LINK, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
|
2021-07-21 04:13:52 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_translation", PROPERTY_HINT_NONE, "", 0), "set_global_translation", "get_global_translation");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "global_rotation", PROPERTY_HINT_NONE, "", 0), "set_global_rotation", "get_global_rotation");
|
|
|
|
|
2018-08-07 15:19:19 +00:00
|
|
|
ADD_GROUP("Matrix", "");
|
2018-11-08 14:30:02 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform");
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_GROUP("Visibility", "");
|
2018-11-08 14:30:02 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
|
2018-01-11 22:35:12 +00:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "SpatialGizmo", 0), "set_gizmo", "get_gizmo");
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("visibility_changed"));
|
2021-02-04 10:43:08 +00:00
|
|
|
ADD_SIGNAL(MethodInfo("gameplay_entered"));
|
|
|
|
ADD_SIGNAL(MethodInfo("gameplay_exited"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-12-06 20:36:34 +00:00
|
|
|
Spatial::Spatial() :
|
2022-02-21 07:34:42 +00:00
|
|
|
xform_change(this), _client_physics_interpolation_spatials_list(this) {
|
2017-03-05 15:44:50 +00:00
|
|
|
data.dirty = DIRTY_NONE;
|
|
|
|
data.children_lock = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
data.ignore_notification = false;
|
|
|
|
data.toplevel = false;
|
|
|
|
data.toplevel_active = false;
|
|
|
|
data.scale = Vector3(1, 1, 1);
|
2021-05-04 14:00:45 +00:00
|
|
|
data.viewport = nullptr;
|
2017-03-05 15:44:50 +00:00
|
|
|
data.inside_world = false;
|
|
|
|
data.visible = true;
|
2018-07-18 16:47:42 +00:00
|
|
|
data.disable_scale = false;
|
2021-09-15 11:30:45 +00:00
|
|
|
data.vi_visible = true;
|
2017-01-12 23:35:46 +00:00
|
|
|
|
2022-02-21 07:34:42 +00:00
|
|
|
data.client_physics_interpolation_data = nullptr;
|
2021-01-30 15:17:58 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-03-05 15:44:50 +00:00
|
|
|
data.gizmo_disabled = false;
|
|
|
|
data.gizmo_dirty = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif
|
2017-03-05 15:44:50 +00:00
|
|
|
data.notify_local_transform = false;
|
|
|
|
data.notify_transform = false;
|
2021-05-04 14:00:45 +00:00
|
|
|
data.parent = nullptr;
|
|
|
|
data.C = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Spatial::~Spatial() {
|
2022-02-21 07:34:42 +00:00
|
|
|
_disable_client_physics_interpolation();
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|