Merge pull request #56364 from V-Sekai/preview_node_sanitize_3_x
Clean preview node of all nodes which are not derived from VisualInstances [3.x]
This commit is contained in:
commit
791f454b17
2 changed files with 33 additions and 0 deletions
|
@ -3684,6 +3684,35 @@ AABB SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, b
|
||||||
return bounds;
|
return bounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node *SpatialEditorViewport::_sanitize_preview_node(Node *p_node) const {
|
||||||
|
Spatial *spatial = Object::cast_to<Spatial>(p_node);
|
||||||
|
if (spatial == nullptr) {
|
||||||
|
Spatial *replacement_node = memnew(Spatial);
|
||||||
|
replacement_node->set_name(p_node->get_name());
|
||||||
|
p_node->replace_by(replacement_node);
|
||||||
|
memdelete(p_node);
|
||||||
|
p_node = replacement_node;
|
||||||
|
} else {
|
||||||
|
VisualInstance *visual_instance = Object::cast_to<VisualInstance>(spatial);
|
||||||
|
if (visual_instance == nullptr) {
|
||||||
|
Spatial *replacement_node = memnew(Spatial);
|
||||||
|
replacement_node->set_name(spatial->get_name());
|
||||||
|
replacement_node->set_visible(spatial->is_visible());
|
||||||
|
replacement_node->set_transform(spatial->get_transform());
|
||||||
|
replacement_node->set_as_toplevel(spatial->is_set_as_toplevel());
|
||||||
|
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 SpatialEditorViewport::_create_preview(const Vector<String> &files) const {
|
void SpatialEditorViewport::_create_preview(const Vector<String> &files) const {
|
||||||
for (int i = 0; i < files.size(); i++) {
|
for (int i = 0; i < files.size(); i++) {
|
||||||
String path = files[i];
|
String path = files[i];
|
||||||
|
@ -3700,6 +3729,7 @@ void SpatialEditorViewport::_create_preview(const Vector<String> &files) const {
|
||||||
if (scene.is_valid()) {
|
if (scene.is_valid()) {
|
||||||
Node *instance = scene->instance();
|
Node *instance = scene->instance();
|
||||||
if (instance) {
|
if (instance) {
|
||||||
|
instance = _sanitize_preview_node(instance);
|
||||||
preview_node->add_child(instance);
|
preview_node->add_child(instance);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -446,6 +446,9 @@ private:
|
||||||
|
|
||||||
Vector3 _get_instance_position(const Point2 &p_pos) const;
|
Vector3 _get_instance_position(const Point2 &p_pos) const;
|
||||||
static AABB _calculate_spatial_bounds(const Spatial *p_parent, bool p_exclude_toplevel_transform = true);
|
static AABB _calculate_spatial_bounds(const Spatial *p_parent, bool p_exclude_toplevel_transform = true);
|
||||||
|
|
||||||
|
Node *_sanitize_preview_node(Node *p_node) const;
|
||||||
|
|
||||||
void _create_preview(const Vector<String> &files) const;
|
void _create_preview(const Vector<String> &files) const;
|
||||||
void _remove_preview();
|
void _remove_preview();
|
||||||
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
|
bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node);
|
||||||
|
|
Loading…
Reference in a new issue