From ee702334a1c7bd19dd8fd7fd57009e393939bab7 Mon Sep 17 00:00:00 2001 From: jfons Date: Wed, 9 Jun 2021 13:06:38 +0200 Subject: [PATCH] Rename get_parent_spatial() to get_parent_node3d() Renames get_parent_spatial() to get_parent_node3d() and changes its implementation. Before it was not returning a correct pointer if the node wasn't added to a SceneTree. Now it uses the same implementation as CanvasItem, which will be correct even for nodes outside a SceneTree. --- doc/classes/Node3D.xml | 2 +- editor/import/resource_importer_scene.cpp | 2 +- scene/3d/node_3d.cpp | 10 +++++++--- scene/3d/node_3d.h | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/doc/classes/Node3D.xml b/doc/classes/Node3D.xml index a6237708c6e..a94cc37bc81 100644 --- a/doc/classes/Node3D.xml +++ b/doc/classes/Node3D.xml @@ -20,7 +20,7 @@ Forces the transform to update. Transform changes in physics are not instant for performance reasons. Transforms are accumulated and then set. Use this if you need an up-to-date transform when doing physics operations. - + diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index b589a6aaa09..ff626edfa00 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -1213,7 +1213,7 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m Node3D *n = src_mesh_node; while (n) { xf = n->get_transform() * xf; - n = n->get_parent_spatial(); + n = n->get_parent_node_3d(); } Vector lightmap_cache; diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp index e96e4df55c6..f1fd80617d8 100644 --- a/scene/3d/node_3d.cpp +++ b/scene/3d/node_3d.cpp @@ -282,8 +282,12 @@ Transform3D Node3D::get_local_gizmo_transform() const { } #endif -Node3D *Node3D::get_parent_spatial() const { - return data.parent; +Node3D *Node3D::get_parent_node_3d() const { + if (data.top_level) { + return nullptr; + } + + return Object::cast_to(get_parent()); } Transform3D Node3D::get_relative_transform(const Node *p_parent) const { @@ -703,7 +707,7 @@ void Node3D::_bind_methods() { 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("get_parent_node_3d"), &Node3D::get_parent_node_3d); ClassDB::bind_method(D_METHOD("set_ignore_transform_notification", "enabled"), &Node3D::set_ignore_transform_notification); ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &Node3D::set_as_top_level); ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &Node3D::is_set_as_top_level); diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h index 09a96bf8cae..4accc95cfae 100644 --- a/scene/3d/node_3d.h +++ b/scene/3d/node_3d.h @@ -118,7 +118,7 @@ public: NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 44, }; - Node3D *get_parent_spatial() const; + Node3D *get_parent_node_3d() const; Ref get_world_3d() const;