summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2022-01-04 17:20:13 +0100
committerGitHub <noreply@github.com>2022-01-04 17:20:13 +0100
commitdeefce7bb53afcf77c79732af74f1856210a8cc6 (patch)
tree16d12f68e55c31c130e91258fa3d3d5f305d473a
parenteab30316ee8ca4f8542c192fdde319c40320a2fe (diff)
parent45b8bb745e8074373ecad6b3ca9c482154a57262 (diff)
Merge pull request #56362 from V-Sekai/preview_node_sanitize
Clean preview node of all nodes which are not derived from VisualInstances
-rw-r--r--editor/plugins/node_3d_editor_plugin.cpp32
-rw-r--r--editor/plugins/node_3d_editor_plugin.h3
2 files changed, 35 insertions, 0 deletions
diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp
index 643a409376..c86f6c02cb 100644
--- a/editor/plugins/node_3d_editor_plugin.cpp
+++ b/editor/plugins/node_3d_editor_plugin.cpp
@@ -3988,6 +3988,37 @@ AABB Node3DEditorViewport::_calculate_spatial_bounds(const Node3D *p_parent, boo
return bounds;
}
+Node *Node3DEditorViewport::_sanitize_preview_node(Node *p_node) const {
+ Node3D *node_3d = Object::cast_to<Node3D>(p_node);
+ if (node_3d == nullptr) {
+ Node3D *replacement_node = memnew(Node3D);
+ replacement_node->set_name(p_node->get_name());
+ p_node->replace_by(replacement_node);
+ memdelete(p_node);
+ p_node = replacement_node;
+ } else {
+ VisualInstance3D *visual_instance = Object::cast_to<VisualInstance3D>(node_3d);
+ if (visual_instance == nullptr) {
+ Node3D *replacement_node = memnew(Node3D);
+ replacement_node->set_name(node_3d->get_name());
+ replacement_node->set_visible(node_3d->is_visible());
+ replacement_node->set_transform(node_3d->get_transform());
+ replacement_node->set_rotation_edit_mode(node_3d->get_rotation_edit_mode());
+ replacement_node->set_rotation_order(node_3d->get_rotation_order());
+ replacement_node->set_as_top_level(node_3d->is_set_as_top_level());
+ p_node->replace_by(replacement_node);
+ memdelete(p_node);
+ p_node = replacement_node;
+ }
+ }
+
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+ _sanitize_preview_node(p_node->get_child(i));
+ }
+
+ return p_node;
+}
+
void Node3DEditorViewport::_create_preview(const Vector<String> &files) const {
for (int i = 0; i < files.size(); i++) {
String path = files[i];
@@ -4004,6 +4035,7 @@ void Node3DEditorViewport::_create_preview(const Vector<String> &files) const {
if (scene.is_valid()) {
Node *instance = scene->instantiate();
if (instance) {
+ instance = _sanitize_preview_node(instance);
preview_node->add_child(instance);
}
}
diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h
index da28e6314f..eba3989f9d 100644
--- a/editor/plugins/node_3d_editor_plugin.h
+++ b/editor/plugins/node_3d_editor_plugin.h
@@ -385,6 +385,9 @@ private:
Vector3 _get_instance_position(const Point2 &p_pos) const;
static AABB _calculate_spatial_bounds(const Node3D *p_parent, bool p_exclude_top_level_transform = true);
+
+ Node *_sanitize_preview_node(Node *p_node) const;
+
void _create_preview(const Vector<String> &files) const;
void _remove_preview();
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);