2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-03-26 22:49:16 +01:00
|
|
|
/* node_3d.cpp */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 14:16:55 +02:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 02:10:30 +01:00
|
|
|
/*************************************************************************/
|
2020-01-01 11:16:22 +01:00
|
|
|
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
2014-02-10 02:10:30 +01:00
|
|
|
/* */
|
|
|
|
/* 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 22:49:16 +01:00
|
|
|
#include "node_3d.h"
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-09-11 18:13:45 +02:00
|
|
|
#include "core/engine.h"
|
|
|
|
#include "core/message_queue.h"
|
2018-10-29 11:30:28 +01:00
|
|
|
#include "scene/main/scene_tree.h"
|
2020-03-04 02:51:12 +01:00
|
|
|
#include "scene/main/window.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "scene/scene_string_names.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
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
|
|
|
|
a) If above is invalid, don't keep invalidating upwards
|
|
|
|
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
|
|
|
|
a) marking GLOBALs as dirty up all the tree must be done always
|
|
|
|
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 22:49:16 +01:00
|
|
|
Node3DGizmo::Node3DGizmo() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_notify_dirty() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-09 13:18:07 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
|
|
|
|
#else
|
2017-01-13 00:35:46 +01:00
|
|
|
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-09 13:18:07 +02:00
|
|
|
#endif
|
2014-11-06 01:20:42 +01:00
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_update_local_transform() const {
|
2018-04-14 21:53:25 +02:00
|
|
|
data.local_transform.basis.set_euler_scale(data.rotation, data.scale);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty &= ~DIRTY_LOCAL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_propagate_transform_changed(Node3D *p_origin) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!is_inside_tree()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
/*
|
|
|
|
if (data.dirty&DIRTY_GLOBAL)
|
|
|
|
return; //already dirty
|
|
|
|
*/
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
data.children_lock++;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
if (E->get()->data.toplevel_active)
|
|
|
|
continue; //don't propagate to a toplevel
|
|
|
|
E->get()->_propagate_transform_changed(p_origin);
|
|
|
|
}
|
2017-08-09 13:18:07 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if ((data.gizmo.is_valid() || data.notify_transform) && !data.ignore_notification && !xform_change.in_list()) {
|
|
|
|
#else
|
2017-01-13 00:35:46 +01:00
|
|
|
if (data.notify_transform && !data.ignore_notification && !xform_change.in_list()) {
|
2017-08-09 13:18:07 +02:00
|
|
|
#endif
|
2014-11-06 01:20:42 +01:00
|
|
|
get_tree()->xform_change_list.add(&xform_change);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty |= DIRTY_GLOBAL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
data.children_lock--;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_notification(int p_what) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
switch (p_what) {
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_ENTER_TREE: {
|
2020-01-25 06:16:27 +01:00
|
|
|
ERR_FAIL_COND(!get_tree());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Node *p = get_parent();
|
|
|
|
if (p)
|
2020-03-26 22:49:16 +01:00
|
|
|
data.parent = Object::cast_to<Node3D>(p);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (data.parent)
|
2017-03-05 16:44:50 +01:00
|
|
|
data.C = data.parent->data.children.push_back(this);
|
2014-02-10 02:10:30 +01:00
|
|
|
else
|
2017-03-05 16:44:50 +01:00
|
|
|
data.C = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-08-19 01:02:56 +02:00
|
|
|
if (data.toplevel && !Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (data.parent) {
|
|
|
|
data.local_transform = data.parent->get_global_transform() * get_transform();
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty = DIRTY_VECTORS; //global is always dirty upon entering a scene
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
data.toplevel_active = true;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty |= DIRTY_GLOBAL; //global is always dirty upon entering a scene
|
2014-02-10 02:10:30 +01:00
|
|
|
_notify_dirty();
|
|
|
|
|
|
|
|
notification(NOTIFICATION_ENTER_WORLD);
|
|
|
|
|
|
|
|
} break;
|
2014-11-06 01:20:42 +01:00
|
|
|
case NOTIFICATION_EXIT_TREE: {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
notification(NOTIFICATION_EXIT_WORLD, true);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (xform_change.in_list())
|
2014-11-06 01:20:42 +01:00
|
|
|
get_tree()->xform_change_list.remove(&xform_change);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (data.C)
|
|
|
|
data.parent->data.children.erase(data.C);
|
2017-03-05 16:44:50 +01:00
|
|
|
data.parent = NULL;
|
|
|
|
data.C = NULL;
|
|
|
|
data.toplevel_active = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
} break;
|
|
|
|
case NOTIFICATION_ENTER_WORLD: {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.inside_world = true;
|
|
|
|
data.viewport = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
Node *parent = get_parent();
|
2017-03-05 16:44:50 +01:00
|
|
|
while (parent && !data.viewport) {
|
2017-08-24 22:58:51 +02:00
|
|
|
data.viewport = Object::cast_to<Viewport>(parent);
|
2017-03-05 16:44:50 +01:00
|
|
|
parent = parent->get_parent();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND(!data.viewport);
|
|
|
|
|
|
|
|
if (get_script_instance()) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_enter_world, NULL, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
#ifdef TOOLS_ENABLED
|
2019-03-07 13:25:35 +01:00
|
|
|
if (Engine::get_singleton()->is_editor_hint() && get_tree()->is_node_being_edited(this)) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-01-14 12:26:56 +01:00
|
|
|
//get_scene()->call_group(SceneMainLoop::GROUP_CALL_REALTIME,SceneStringNames::get_singleton()->_spatial_editor_group,SceneStringNames::get_singleton()->_request_gizmo,this);
|
2017-03-05 16:44:50 +01:00
|
|
|
get_tree()->call_group_flags(0, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!data.gizmo_disabled) {
|
|
|
|
|
2017-08-26 05:40:45 +02:00
|
|
|
if (data.gizmo.is_valid()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
data.gizmo->create();
|
2018-09-02 22:31:03 +02:00
|
|
|
if (is_visible_in_tree()) {
|
|
|
|
data.gizmo->redraw();
|
2017-08-26 05:40:45 +02:00
|
|
|
}
|
|
|
|
data.gizmo->transform();
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case NOTIFICATION_EXIT_WORLD: {
|
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (data.gizmo.is_valid()) {
|
|
|
|
data.gizmo->free();
|
2018-07-25 00:08:49 +02:00
|
|
|
data.gizmo.unref();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (get_script_instance()) {
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_world, NULL, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.viewport = NULL;
|
|
|
|
data.inside_world = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (data.gizmo.is_valid()) {
|
|
|
|
data.gizmo->transform();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
} break;
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2019-04-09 17:08:36 +02:00
|
|
|
default: {
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_transform(const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.local_transform = p_transform;
|
|
|
|
data.dirty |= DIRTY_VECTORS;
|
2017-04-03 18:34:44 +02:00
|
|
|
_change_notify("translation");
|
|
|
|
_change_notify("rotation");
|
2017-11-10 11:07:52 +01:00
|
|
|
_change_notify("rotation_degrees");
|
2017-04-03 18:34:44 +02:00
|
|
|
_change_notify("scale");
|
2014-02-10 02:10:30 +01:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 03:07:03 +02:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_global_transform(const Transform &p_transform) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
Transform xform =
|
|
|
|
(data.parent && !data.toplevel_active) ?
|
2017-03-05 16:44:50 +01:00
|
|
|
data.parent->get_global_transform().affine_inverse() * p_transform :
|
|
|
|
p_transform;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
set_transform(xform);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Transform Node3D::get_transform() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (data.dirty & DIRTY_LOCAL) {
|
|
|
|
|
|
|
|
_update_local_transform();
|
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return data.local_transform;
|
|
|
|
}
|
2020-03-26 22:49:16 +01:00
|
|
|
Transform Node3D::get_global_transform() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_tree(), Transform());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (data.dirty & DIRTY_GLOBAL) {
|
|
|
|
|
|
|
|
if (data.dirty & DIRTY_LOCAL) {
|
|
|
|
|
|
|
|
_update_local_transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.parent && !data.toplevel_active) {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.global_transform = data.parent->get_global_transform() * data.local_transform;
|
2014-02-10 02:10:30 +01:00
|
|
|
} else {
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.global_transform = data.local_transform;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2018-07-18 18:47:42 +02:00
|
|
|
if (data.disable_scale) {
|
|
|
|
data.global_transform.basis.orthonormalize();
|
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty &= ~DIRTY_GLOBAL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return data.global_transform;
|
|
|
|
}
|
|
|
|
|
2017-10-03 18:49:32 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-03-26 22:49:16 +01:00
|
|
|
Transform Node3D::get_global_gizmo_transform() const {
|
2017-10-03 18:49:32 +02:00
|
|
|
return get_global_transform();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Transform Node3D::get_local_gizmo_transform() const {
|
2017-10-03 18:49:32 +02:00
|
|
|
return get_transform();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D *Node3D::get_parent_spatial() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return data.parent;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Transform Node3D::get_relative_transform(const Node *p_parent) const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_parent == this)
|
2014-02-10 02:10:30 +01:00
|
|
|
return Transform();
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!data.parent, Transform());
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (p_parent == data.parent)
|
2014-02-10 02:10:30 +01:00
|
|
|
return get_transform();
|
|
|
|
else
|
|
|
|
return data.parent->get_relative_transform(p_parent) * get_transform();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_translation(const Vector3 &p_translation) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.local_transform.origin = p_translation;
|
2019-11-30 17:16:19 +01:00
|
|
|
_change_notify("transform");
|
2014-02-10 02:10:30 +01:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 03:07:03 +02:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_rotation(const Vector3 &p_euler_rad) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.rotation = p_euler_rad;
|
|
|
|
data.dirty |= DIRTY_LOCAL;
|
2019-11-30 17:16:19 +01:00
|
|
|
_change_notify("transform");
|
2014-02-10 02:10:30 +01:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 03:07:03 +02:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
2016-05-06 23:38:08 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_rotation_degrees(const Vector3 &p_euler_deg) {
|
2016-05-06 23:38:08 +02:00
|
|
|
|
|
|
|
set_rotation(p_euler_deg * Math_PI / 180.0);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_scale(const Vector3 &p_scale) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.rotation = data.local_transform.basis.get_rotation();
|
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.scale = p_scale;
|
|
|
|
data.dirty |= DIRTY_LOCAL;
|
2019-11-30 17:16:19 +01:00
|
|
|
_change_notify("transform");
|
2014-02-10 02:10:30 +01:00
|
|
|
_propagate_transform_changed(this);
|
2015-09-16 03:07:03 +02:00
|
|
|
if (data.notify_local_transform) {
|
|
|
|
notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 Node3D::get_translation() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return data.local_transform.origin;
|
|
|
|
}
|
2016-05-06 23:38:08 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 Node3D::get_rotation() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.rotation = data.local_transform.basis.get_rotation();
|
2017-01-05 18:31:39 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return data.rotation;
|
|
|
|
}
|
2016-05-06 23:38:08 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 Node3D::get_rotation_degrees() const {
|
2016-05-06 23:38:08 +02:00
|
|
|
|
|
|
|
return get_rotation() * 180.0 / Math_PI;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 Node3D::get_scale() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (data.dirty & DIRTY_VECTORS) {
|
|
|
|
data.scale = data.local_transform.basis.get_scale();
|
|
|
|
data.rotation = data.local_transform.basis.get_rotation();
|
2017-01-05 18:31:39 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty &= ~DIRTY_VECTORS;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return data.scale;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::update_gizmo() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!is_inside_world())
|
|
|
|
return;
|
2018-10-29 11:30:28 +01:00
|
|
|
if (!data.gizmo.is_valid())
|
|
|
|
get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, SceneStringNames::get_singleton()->_spatial_editor_group, SceneStringNames::get_singleton()->_request_gizmo, this);
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!data.gizmo.is_valid())
|
|
|
|
return;
|
|
|
|
if (data.gizmo_dirty)
|
|
|
|
return;
|
2017-03-05 16:44:50 +01:00
|
|
|
data.gizmo_dirty = true;
|
|
|
|
MessageQueue::get_singleton()->push_call(this, "_update_gizmo");
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_gizmo(const Ref<Node3DGizmo> &p_gizmo) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
if (data.gizmo_disabled)
|
|
|
|
return;
|
|
|
|
if (data.gizmo.is_valid() && is_inside_world())
|
|
|
|
data.gizmo->free();
|
2017-03-05 16:44:50 +01:00
|
|
|
data.gizmo = p_gizmo;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (data.gizmo.is_valid() && is_inside_world()) {
|
|
|
|
|
|
|
|
data.gizmo->create();
|
2018-09-02 22:31:03 +02:00
|
|
|
if (is_visible_in_tree()) {
|
|
|
|
data.gizmo->redraw();
|
2017-08-26 05:40:45 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
data.gizmo->transform();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<Node3DGizmo> Node3D::get_gizmo() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
|
|
|
|
return data.gizmo;
|
|
|
|
#else
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
return Ref<Node3DGizmo>();
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_update_gizmo() {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2018-04-29 19:49:26 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-08-26 05:40:45 +02:00
|
|
|
if (!is_inside_world())
|
|
|
|
return;
|
2017-03-05 16:44:50 +01:00
|
|
|
data.gizmo_dirty = false;
|
2014-09-19 23:39:50 +02:00
|
|
|
if (data.gizmo.is_valid()) {
|
2018-09-02 22:31:03 +02:00
|
|
|
if (is_visible_in_tree())
|
|
|
|
data.gizmo->redraw();
|
|
|
|
else
|
|
|
|
data.gizmo->clear();
|
2014-09-19 23:39:50 +02:00
|
|
|
}
|
2018-04-29 19:49:26 +02:00
|
|
|
#endif
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2018-04-29 19:49:26 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_disable_gizmo(bool p_enabled) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.gizmo_disabled = p_enabled;
|
2014-02-10 02:10:30 +01:00
|
|
|
if (!p_enabled && data.gizmo.is_valid())
|
2020-03-26 22:49:16 +01:00
|
|
|
data.gizmo = Ref<Node3DGizmo>();
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_disable_scale(bool p_enabled) {
|
2018-07-18 18:47:42 +02:00
|
|
|
|
|
|
|
data.disable_scale = p_enabled;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool Node3D::is_scale_disabled() const {
|
2018-07-18 18:47:42 +02:00
|
|
|
return data.disable_scale;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_as_toplevel(bool p_enabled) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
if (data.toplevel == p_enabled)
|
2014-02-10 02:10:30 +01:00
|
|
|
return;
|
2017-08-19 01:02:56 +02:00
|
|
|
if (is_inside_tree() && !Engine::get_singleton()->is_editor_hint()) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
if (p_enabled)
|
|
|
|
set_transform(get_global_transform());
|
|
|
|
else if (data.parent)
|
|
|
|
set_transform(data.parent->get_global_transform().affine_inverse() * get_global_transform());
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.toplevel = p_enabled;
|
|
|
|
data.toplevel_active = p_enabled;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
} else {
|
2017-03-05 16:44:50 +01:00
|
|
|
data.toplevel = p_enabled;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool Node3D::is_set_as_toplevel() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
return data.toplevel;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Ref<World> Node3D::get_world() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ERR_FAIL_COND_V(!is_inside_world(), Ref<World>());
|
2019-06-22 14:52:51 +02:00
|
|
|
ERR_FAIL_COND_V(!data.viewport, Ref<World>());
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return data.viewport->find_world();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_propagate_visibility_changed() {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
|
|
|
notification(NOTIFICATION_VISIBILITY_CHANGED);
|
|
|
|
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
|
2017-04-03 18:34:44 +02:00
|
|
|
_change_notify("visible");
|
2014-09-19 23:39:50 +02:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (data.gizmo.is_valid())
|
|
|
|
_update_gizmo();
|
|
|
|
#endif
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
for (List<Node3D *>::Element *E = data.children.front(); E; E = E->next()) {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D *c = E->get();
|
2014-08-14 15:31:38 +02:00
|
|
|
if (!c || !c->data.visible)
|
|
|
|
continue;
|
|
|
|
c->_propagate_visibility_changed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::show() {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
|
|
|
if (data.visible)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.visible = true;
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2014-11-06 01:20:42 +01:00
|
|
|
if (!is_inside_tree())
|
2014-08-14 15:31:38 +02:00
|
|
|
return;
|
|
|
|
|
2017-07-02 17:27:27 +02:00
|
|
|
_propagate_visibility_changed();
|
2014-08-14 15:31:38 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::hide() {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
|
|
|
if (!data.visible)
|
|
|
|
return;
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.visible = false;
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2017-07-02 17:27:27 +02:00
|
|
|
if (!is_inside_tree())
|
|
|
|
return;
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2017-07-02 17:27:27 +02:00
|
|
|
_propagate_visibility_changed();
|
2014-08-14 15:31:38 +02:00
|
|
|
}
|
2017-07-02 17:27:27 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool Node3D::is_visible_in_tree() const {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
const Node3D *s = this;
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
while (s) {
|
2014-08-14 15:31:38 +02:00
|
|
|
if (!s->data.visible) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-03-05 16:44:50 +01:00
|
|
|
s = s->data.parent;
|
2014-08-14 15:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_visible(bool p_visible) {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
|
|
|
if (p_visible)
|
|
|
|
show();
|
|
|
|
else
|
|
|
|
hide();
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool Node3D::is_visible() const {
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2017-01-18 21:49:30 +01:00
|
|
|
return data.visible;
|
2014-08-14 15:31:38 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::rotate_object_local(const Vector3 &p_axis, float p_angle) {
|
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 01:15:20 +01:00
|
|
|
Transform t = get_transform();
|
|
|
|
t.basis.rotate_local(p_axis, p_angle);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::rotate(const Vector3 &p_axis, float p_angle) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01: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 01:15:20 +01:00
|
|
|
t.basis.rotate(p_axis, p_angle);
|
2015-03-22 14:33:58 +01:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::rotate_x(float p_angle) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01: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 01:15:20 +01:00
|
|
|
t.basis.rotate(Vector3(1, 0, 0), p_angle);
|
2015-03-22 14:33:58 +01:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::rotate_y(float p_angle) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01: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 01:15:20 +01:00
|
|
|
t.basis.rotate(Vector3(0, 1, 0), p_angle);
|
2015-03-22 14:33:58 +01:00
|
|
|
set_transform(t);
|
|
|
|
}
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::rotate_z(float p_angle) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01: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 01:15:20 +01:00
|
|
|
t.basis.rotate(Vector3(0, 0, 1), p_angle);
|
2015-03-22 14:33:58 +01:00
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::translate(const Vector3 &p_offset) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform t = get_transform();
|
2015-06-06 14:44:38 +02:00
|
|
|
t.translate(p_offset);
|
2015-03-22 14:33:58 +01:00
|
|
|
set_transform(t);
|
|
|
|
}
|
2015-06-06 14:44:38 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::translate_object_local(const Vector3 &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-27 01:15:20 +01:00
|
|
|
Transform t = get_transform();
|
|
|
|
|
|
|
|
Transform s;
|
|
|
|
s.translate(p_offset);
|
|
|
|
set_transform(t * s);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::scale(const Vector3 &p_ratio) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
Transform t = get_transform();
|
2015-03-22 14:33:58 +01:00
|
|
|
t.basis.scale(p_ratio);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::scale_object_local(const Vector3 &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 01:15:20 +01:00
|
|
|
Transform t = get_transform();
|
|
|
|
t.basis.scale_local(p_scale);
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::global_rotate(const Vector3 &p_axis, float p_angle) {
|
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 01:15:20 +01:00
|
|
|
|
2015-03-22 14:33:58 +01:00
|
|
|
Transform t = get_global_transform();
|
2018-05-17 02:32:35 +02:00
|
|
|
t.basis.rotate(p_axis, p_angle);
|
2015-03-22 14:33:58 +01: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 01:15:20 +01:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::global_scale(const Vector3 &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 01:15:20 +01:00
|
|
|
|
|
|
|
Transform t = get_global_transform();
|
2018-05-17 02:32:35 +02: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 01:15:20 +01:00
|
|
|
set_global_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::global_translate(const Vector3 &p_offset) {
|
2015-03-22 14:33:58 +01:00
|
|
|
Transform t = get_global_transform();
|
2017-03-05 16:44:50 +01:00
|
|
|
t.origin += p_offset;
|
2015-03-22 14:33:58 +01:00
|
|
|
set_global_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::orthonormalize() {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
|
|
|
Transform t = get_transform();
|
|
|
|
t.orthonormalize();
|
|
|
|
set_transform(t);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_identity() {
|
2015-03-22 15:52:07 +01:00
|
|
|
|
|
|
|
set_transform(Transform());
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::look_at(const Vector3 &p_target, const Vector3 &p_up) {
|
2015-03-22 14:33:58 +01:00
|
|
|
|
2019-05-23 14:49:50 +02:00
|
|
|
Vector3 origin(get_global_transform().origin);
|
|
|
|
look_at_from_position(origin, p_target, p_up);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::look_at_from_position(const Vector3 &p_pos, const Vector3 &p_target, const Vector3 &p_up) {
|
2019-05-23 14:49:50 +02:00
|
|
|
|
2019-08-08 22:11:48 +02:00
|
|
|
ERR_FAIL_COND_MSG(p_pos == p_target, "Node origin and target are in the same position, look_at() failed.");
|
|
|
|
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 14:33:58 +01:00
|
|
|
|
|
|
|
Transform lookat;
|
2017-03-05 16:44:50 +01:00
|
|
|
lookat.origin = p_pos;
|
2019-05-23 14:49:50 +02:00
|
|
|
|
2019-10-11 07:22:02 +02: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 01:15:20 +01:00
|
|
|
lookat = lookat.looking_at(p_target, p_up);
|
2015-03-22 14:33:58 +01:00
|
|
|
set_global_transform(lookat);
|
2019-10-11 07:22:02 +02:00
|
|
|
set_scale(original_scale);
|
2015-03-22 14:33:58 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 Node3D::to_local(Vector3 p_global) const {
|
2017-07-23 13:37:26 +02:00
|
|
|
|
|
|
|
return get_global_transform().affine_inverse().xform(p_global);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Vector3 Node3D::to_global(Vector3 p_local) const {
|
2017-07-23 13:37:26 +02:00
|
|
|
|
|
|
|
return get_global_transform().xform(p_local);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_notify_transform(bool p_enable) {
|
2017-03-05 16:44:50 +01:00
|
|
|
data.notify_transform = p_enable;
|
2017-01-13 00:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool Node3D::is_transform_notification_enabled() const {
|
2017-01-13 00:35:46 +01:00
|
|
|
return data.notify_transform;
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::set_notify_local_transform(bool p_enable) {
|
2017-03-05 16:44:50 +01:00
|
|
|
data.notify_local_transform = p_enable;
|
2015-09-16 03:07:03 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
bool Node3D::is_local_transform_notification_enabled() const {
|
2015-09-16 03:07:03 +02:00
|
|
|
return data.notify_local_transform;
|
|
|
|
}
|
2014-08-14 15:31:38 +02:00
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::force_update_transform() {
|
2018-09-07 01:38:16 +02: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);
|
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
void Node3D::_bind_methods() {
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("set_transform", "local"), &Node3D::set_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_transform"), &Node3D::get_transform);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_translation", "translation"), &Node3D::set_translation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_translation"), &Node3D::get_translation);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_rotation", "euler"), &Node3D::set_rotation);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_rotation"), &Node3D::get_rotation);
|
|
|
|
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);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node3D::set_scale);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_scale"), &Node3D::get_scale);
|
|
|
|
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);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_parent_spatial"), &Node3D::get_parent_spatial);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &Node3D::set_as_toplevel);
|
|
|
|
ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &Node3D::is_set_as_toplevel);
|
|
|
|
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);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_world"), &Node3D::get_world);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("force_update_transform"), &Node3D::force_update_transform);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("_update_gizmo"), &Node3D::_update_gizmo);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("update_gizmo"), &Node3D::update_gizmo);
|
|
|
|
ClassDB::bind_method(D_METHOD("set_gizmo", "gizmo"), &Node3D::set_gizmo);
|
|
|
|
ClassDB::bind_method(D_METHOD("get_gizmo"), &Node3D::get_gizmo);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
ClassDB::bind_method(D_METHOD("look_at", "target", "up"), &Node3D::look_at);
|
|
|
|
ClassDB::bind_method(D_METHOD("look_at_from_position", "position", "target", "up"), &Node3D::look_at_from_position);
|
|
|
|
|
|
|
|
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 13:37:26 +02:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_ENTER_WORLD);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_EXIT_WORLD);
|
|
|
|
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-02-12 01:11:37 +01:00
|
|
|
//ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM,"transform/global",PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR ), "set_global_transform", "get_global_transform") ;
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("Transform", "");
|
2018-11-08 15:30:02 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform");
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "translation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_translation", "get_translation");
|
2017-11-10 11:07:52 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation_degrees", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_rotation_degrees", "get_rotation_degrees");
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "rotation", PROPERTY_HINT_NONE, "", 0), "set_rotation", "get_rotation");
|
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "scale", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_scale", "get_scale");
|
2018-08-07 17:19:19 +02:00
|
|
|
ADD_GROUP("Matrix", "");
|
2018-11-08 15:30:02 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM, "transform", PROPERTY_HINT_NONE, ""), "set_transform", "get_transform");
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_GROUP("Visibility", "");
|
2018-11-08 15:30:02 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
|
2020-03-26 22:49:16 +01:00
|
|
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "Node3DGizmo", 0), "set_gizmo", "get_gizmo");
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
ADD_SIGNAL(MethodInfo("visibility_changed"));
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D::Node3D() :
|
2017-12-06 21:36:34 +01:00
|
|
|
xform_change(this) {
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.dirty = DIRTY_NONE;
|
|
|
|
data.children_lock = 0;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
data.ignore_notification = false;
|
|
|
|
data.toplevel = false;
|
|
|
|
data.toplevel_active = false;
|
|
|
|
data.scale = Vector3(1, 1, 1);
|
|
|
|
data.viewport = NULL;
|
|
|
|
data.inside_world = false;
|
|
|
|
data.visible = true;
|
2018-07-18 18:47:42 +02:00
|
|
|
data.disable_scale = false;
|
2017-01-13 00:35:46 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2017-03-05 16:44:50 +01:00
|
|
|
data.gizmo_disabled = false;
|
|
|
|
data.gizmo_dirty = false;
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|
2017-03-05 16:44:50 +01:00
|
|
|
data.notify_local_transform = false;
|
|
|
|
data.notify_transform = false;
|
|
|
|
data.parent = NULL;
|
|
|
|
data.C = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2020-03-26 22:49:16 +01:00
|
|
|
Node3D::~Node3D() {
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|