summaryrefslogtreecommitdiff
path: root/editor
diff options
context:
space:
mode:
Diffstat (limited to 'editor')
-rw-r--r--editor/editor_node.cpp31
-rw-r--r--editor/editor_node.h4
-rw-r--r--editor/import/resource_importer_scene.cpp7
-rw-r--r--editor/import/resource_importer_scene.h8
-rw-r--r--editor/import/scene_import_settings.cpp38
5 files changed, 80 insertions, 8 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp
index 5e8a4e230e..6fcf092834 100644
--- a/editor/editor_node.cpp
+++ b/editor/editor_node.cpp
@@ -3984,6 +3984,15 @@ HashMap<StringName, Variant> EditorNode::get_modified_properties_for_node(Node *
return modified_property_map;
}
+void EditorNode::update_ownership_table_for_addition_node_ancestors(Node *p_current_node, HashMap<Node *, Node *> &p_ownership_table) {
+ p_ownership_table.insert(p_current_node, p_current_node->get_owner());
+
+ for (int i = 0; i < p_current_node->get_child_count(); i++) {
+ Node *child = p_current_node->get_child(i);
+ update_ownership_table_for_addition_node_ancestors(child, p_ownership_table);
+ }
+}
+
void EditorNode::update_diff_data_for_node(
Node *p_edited_scene,
Node *p_root,
@@ -4079,6 +4088,16 @@ void EditorNode::update_diff_data_for_node(
if (node_3d) {
new_additive_node_entry.transform_3d = node_3d->get_relative_transform(node_3d->get_parent());
}
+
+ // Gathers the ownership of all ancestor nodes for later use.
+ HashMap<Node *, Node *> ownership_table;
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+ Node *child = p_node->get_child(i);
+ update_ownership_table_for_addition_node_ancestors(child, ownership_table);
+ }
+
+ new_additive_node_entry.ownership_table = ownership_table;
+
p_addition_list.push_back(new_additive_node_entry);
return;
@@ -6203,6 +6222,18 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins
node_3d->set_transform(additive_node_entry.transform_3d);
}
}
+
+ // Restore the ownership of its ancestors
+ for (KeyValue<Node *, Node *> &E : additive_node_entry.ownership_table) {
+ Node *current_ancestor = E.key;
+ Node *ancestor_owner = E.value;
+
+ if (ancestor_owner == original_node) {
+ ancestor_owner = instantiated_node;
+ }
+
+ current_ancestor->set_owner(ancestor_owner);
+ }
}
// Restore the selection.
diff --git a/editor/editor_node.h b/editor/editor_node.h
index eefe45ca1f..8ad5969249 100644
--- a/editor/editor_node.h
+++ b/editor/editor_node.h
@@ -832,6 +832,8 @@ public:
// Used if the original parent node is lost
Transform2D transform_2d;
Transform3D transform_3d;
+ // Used to keep track of the ownership of all ancestor nodes so they can be restored later.
+ HashMap<Node *, Node *> ownership_table;
};
struct ConnectionWithNodePath {
@@ -846,6 +848,8 @@ public:
List<Node::GroupInfo> groups;
};
+ void update_ownership_table_for_addition_node_ancestors(Node *p_current_node, HashMap<Node *, Node *> &p_ownership_table);
+
void update_diff_data_for_node(
Node *p_edited_scene,
Node *p_root,
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp
index 32c16255dd..0ee86c8ed0 100644
--- a/editor/import/resource_importer_scene.cpp
+++ b/editor/import/resource_importer_scene.cpp
@@ -353,13 +353,12 @@ static String _fixstr(const String &p_what, const String &p_str) {
static void _pre_gen_shape_list(Ref<ImporterMesh> &mesh, Vector<Ref<Shape3D>> &r_shape_list, bool p_convex) {
ERR_FAIL_NULL_MSG(mesh, "Cannot generate shape list with null mesh value");
- ERR_FAIL_NULL_MSG(mesh->get_mesh(), "Cannot generate shape list with null mesh value");
if (!p_convex) {
Ref<ConcavePolygonShape3D> shape = mesh->create_trimesh_shape();
r_shape_list.push_back(shape);
} else {
Vector<Ref<Shape3D>> cd;
- cd.push_back(mesh->get_mesh()->create_convex_shape(true, /*Passing false, otherwise VHACD will be used to simplify (Decompose) the Mesh.*/ false));
+ cd.push_back(mesh->create_convex_shape(true, /*Passing false, otherwise VHACD will be used to simplify (Decompose) the Mesh.*/ false));
if (cd.size()) {
for (int i = 0; i < cd.size(); i++) {
r_shape_list.push_back(cd[i]);
@@ -1230,7 +1229,7 @@ Node *ResourceImporterScene::_post_fix_node(Node *p_node, Node *p_root, HashMap<
shapes = collision_map[m];
} else {
shapes = get_collision_shapes(
- m->get_mesh(),
+ m,
node_settings,
p_applied_root_scale);
}
@@ -1613,7 +1612,7 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "decomposition/normalize_mesh", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), decomposition_default.normalize_mesh));
r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "decomposition/mode", PROPERTY_HINT_ENUM, "Voxel,Tetrahedron", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), static_cast<int>(decomposition_default.mode)));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "decomposition/convexhull_approximation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), decomposition_default.convexhull_approximation));
- r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "decomposition/max_convex_hulls", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), decomposition_default.max_convex_hulls));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "decomposition/max_convex_hulls", PROPERTY_HINT_RANGE, "1,100,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), decomposition_default.max_convex_hulls));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "decomposition/project_hull_vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), decomposition_default.project_hull_vertices));
// Primitives: Box, Sphere, Cylinder, Capsule.
diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h
index a0fb95daa7..520ccd1070 100644
--- a/editor/import/resource_importer_scene.h
+++ b/editor/import/resource_importer_scene.h
@@ -39,6 +39,7 @@
#include "scene/resources/box_shape_3d.h"
#include "scene/resources/capsule_shape_3d.h"
#include "scene/resources/cylinder_shape_3d.h"
+#include "scene/resources/importer_mesh.h"
#include "scene/resources/mesh.h"
#include "scene/resources/shape_3d.h"
#include "scene/resources/sphere_shape_3d.h"
@@ -298,7 +299,7 @@ public:
ResourceImporterScene(bool p_animation_import = false);
template <class M>
- static Vector<Ref<Shape3D>> get_collision_shapes(const Ref<Mesh> &p_mesh, const M &p_options, float p_applied_root_scale);
+ static Vector<Ref<Shape3D>> get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale);
template <class M>
static Transform3D get_collision_shapes_transform(const M &p_options);
@@ -314,7 +315,8 @@ public:
};
template <class M>
-Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<Mesh> &p_mesh, const M &p_options, float p_applied_root_scale) {
+Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<ImporterMesh> &p_mesh, const M &p_options, float p_applied_root_scale) {
+ ERR_FAIL_COND_V(p_mesh.is_null(), Vector<Ref<Shape3D>>());
ShapeType generate_shape_type = SHAPE_TYPE_DECOMPOSE_CONVEX;
if (p_options.has(SNAME("physics/shape_type"))) {
generate_shape_type = (ShapeType)p_options[SNAME("physics/shape_type")].operator int();
@@ -373,7 +375,7 @@ Vector<Ref<Shape3D>> ResourceImporterScene::get_collision_shapes(const Ref<Mesh>
}
if (p_options.has(SNAME("decomposition/max_convex_hulls"))) {
- decomposition_settings.max_convex_hulls = p_options[SNAME("decomposition/max_convex_hulls")];
+ decomposition_settings.max_convex_hulls = MAX(1, (int)p_options[SNAME("decomposition/max_convex_hulls")]);
}
if (p_options.has(SNAME("decomposition/project_hull_vertices"))) {
diff --git a/editor/import/scene_import_settings.cpp b/editor/import/scene_import_settings.cpp
index 348aad1162..a09e0e7408 100644
--- a/editor/import/scene_import_settings.cpp
+++ b/editor/import/scene_import_settings.cpp
@@ -444,9 +444,45 @@ void SceneImportSettings::_update_view_gizmos() {
collider_view->set_visible(show_collider_view);
if (generate_collider) {
// This collider_view doesn't have a mesh so we need to generate a new one.
+ Ref<ImporterMesh> mesh;
+ mesh.instantiate();
+ // ResourceImporterScene::get_collision_shapes() expects ImporterMesh, not Mesh.
+ // TODO: Duplicate code with EditorSceneFormatImporterESCN::import_scene()
+ // Consider making a utility function to convert from Mesh to ImporterMesh.
+ Ref<Mesh> mesh_3d_mesh = mesh_node->get_mesh();
+ Ref<ArrayMesh> array_mesh_3d_mesh = mesh_3d_mesh;
+ if (array_mesh_3d_mesh.is_valid()) {
+ // For the MeshInstance3D nodes, we need to convert the ArrayMesh to an ImporterMesh specially.
+ mesh->set_name(array_mesh_3d_mesh->get_name());
+ for (int32_t blend_i = 0; blend_i < array_mesh_3d_mesh->get_blend_shape_count(); blend_i++) {
+ mesh->add_blend_shape(array_mesh_3d_mesh->get_blend_shape_name(blend_i));
+ }
+ for (int32_t surface_i = 0; surface_i < array_mesh_3d_mesh->get_surface_count(); surface_i++) {
+ mesh->add_surface(array_mesh_3d_mesh->surface_get_primitive_type(surface_i),
+ array_mesh_3d_mesh->surface_get_arrays(surface_i),
+ array_mesh_3d_mesh->surface_get_blend_shape_arrays(surface_i),
+ array_mesh_3d_mesh->surface_get_lods(surface_i),
+ array_mesh_3d_mesh->surface_get_material(surface_i),
+ array_mesh_3d_mesh->surface_get_name(surface_i),
+ array_mesh_3d_mesh->surface_get_format(surface_i));
+ }
+ mesh->set_blend_shape_mode(array_mesh_3d_mesh->get_blend_shape_mode());
+ } else if (mesh_3d_mesh.is_valid()) {
+ // For the MeshInstance3D nodes, we need to convert the Mesh to an ImporterMesh specially.
+ mesh->set_name(mesh_3d_mesh->get_name());
+ for (int32_t surface_i = 0; surface_i < mesh_3d_mesh->get_surface_count(); surface_i++) {
+ mesh->add_surface(mesh_3d_mesh->surface_get_primitive_type(surface_i),
+ mesh_3d_mesh->surface_get_arrays(surface_i),
+ Array(),
+ mesh_3d_mesh->surface_get_lods(surface_i),
+ mesh_3d_mesh->surface_get_material(surface_i),
+ mesh_3d_mesh->surface_get_material(surface_i).is_valid() ? mesh_3d_mesh->surface_get_material(surface_i)->get_name() : String(),
+ mesh_3d_mesh->surface_get_format(surface_i));
+ }
+ }
// Generate the mesh collider.
- Vector<Ref<Shape3D>> shapes = ResourceImporterScene::get_collision_shapes(mesh_node->get_mesh(), e.value.settings, 1.0);
+ Vector<Ref<Shape3D>> shapes = ResourceImporterScene::get_collision_shapes(mesh, e.value.settings, 1.0);
const Transform3D transform = ResourceImporterScene::get_collision_shapes_transform(e.value.settings);
Ref<ArrayMesh> collider_view_mesh;