Path: blob/master/editor/import/3d/scene_import_settings.cpp
20878 views
/**************************************************************************/1/* scene_import_settings.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "scene_import_settings.h"3132#include "core/config/project_settings.h"33#include "editor/editor_node.h"34#include "editor/editor_string_names.h"35#include "editor/file_system/editor_file_system.h"36#include "editor/gui/editor_file_dialog.h"37#include "editor/inspector/editor_inspector.h"38#include "editor/scene/3d/skeleton_3d_editor_plugin.h"39#include "editor/settings/editor_settings.h"40#include "editor/themes/editor_scale.h"41#include "scene/3d/importer_mesh_instance_3d.h"42#include "scene/3d/multimesh_instance_3d.h"43#include "scene/animation/animation_player.h"44#include "scene/gui/subviewport_container.h"45#include "scene/main/timer.h"46#include "scene/resources/3d/importer_mesh.h"47#include "scene/resources/sky.h"48#include "scene/resources/surface_tool.h"4950class SceneImportSettingsData : public Object {51GDCLASS(SceneImportSettingsData, Object)52friend class SceneImportSettingsDialog;53HashMap<StringName, Variant> *settings = nullptr;54HashMap<StringName, Variant> current;55HashMap<StringName, Variant> defaults;56List<ResourceImporter::ImportOption> options;57Vector<String> animation_list;5859bool hide_options = false;60String path;6162ResourceImporterScene::InternalImportCategory category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;6364bool _set(const StringName &p_name, const Variant &p_value) {65if (settings) {66if (defaults.has(p_name) && defaults[p_name] == p_value) {67settings->erase(p_name);68} else {69(*settings)[p_name] = p_value;70}7172current[p_name] = p_value;7374// SceneImportSettings must decide if a new collider should be generated or not.75if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE) {76SceneImportSettingsDialog::get_singleton()->request_generate_collider();77}7879ResourceImporterScene *resource_importer_scene = SceneImportSettingsDialog::get_singleton()->get_resource_importer_scene();80if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {81if (resource_importer_scene->get_option_visibility(path, p_name, current)) {82SceneImportSettingsDialog::get_singleton()->update_view();83}84} else {85if (resource_importer_scene->get_internal_option_update_view_required(category, p_name, current)) {86SceneImportSettingsDialog::get_singleton()->update_view();87}88}8990return true;91}92return false;93}9495bool _get(const StringName &p_name, Variant &r_ret) const {96if (settings) {97if (settings->has(p_name)) {98r_ret = (*settings)[p_name];99return true;100}101}102if (defaults.has(p_name)) {103r_ret = defaults[p_name];104return true;105}106return false;107}108109void handle_special_properties(PropertyInfo &r_option) const {110ERR_FAIL_NULL(settings);111if (r_option.name == "rest_pose/load_pose") {112if (!settings->has("rest_pose/load_pose") || int((*settings)["rest_pose/load_pose"]) != 2) {113if (settings->has("rest_pose/external_animation_library")) {114(*settings)["rest_pose/external_animation_library"] = Variant();115}116}117}118if (r_option.name == "rest_pose/selected_animation") {119if (!settings->has("rest_pose/load_pose")) {120return;121}122String hint_string;123124switch (int((*settings)["rest_pose/load_pose"])) {125case 1: {126hint_string = String(",").join(animation_list);127if (animation_list.size() == 1) {128(*settings)["rest_pose/selected_animation"] = animation_list[0];129}130} break;131case 2: {132Object *res = nullptr;133if (settings->has("rest_pose/external_animation_library")) {134res = (*settings)["rest_pose/external_animation_library"];135}136Ref<Animation> anim(res);137Ref<AnimationLibrary> library(res);138if (anim.is_valid()) {139hint_string = anim->get_name();140}141if (library.is_valid()) {142List<StringName> anim_names;143library->get_animation_list(&anim_names);144if (anim_names.size() == 1) {145(*settings)["rest_pose/selected_animation"] = String(anim_names.front()->get());146}147for (StringName anim_name : anim_names) {148hint_string += "," + anim_name; // Include preceding, as a catch-all.149}150}151} break;152default:153break;154}155r_option.hint = PROPERTY_HINT_ENUM;156r_option.hint_string = hint_string;157}158}159160void _get_property_list(List<PropertyInfo> *r_list) const {161if (hide_options) {162return;163}164ResourceImporterScene *resource_importer_scene = SceneImportSettingsDialog::get_singleton()->get_resource_importer_scene();165for (const ResourceImporter::ImportOption &E : options) {166PropertyInfo option = E.option;167if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {168if (resource_importer_scene->get_option_visibility(path, E.option.name, current)) {169handle_special_properties(option);170r_list->push_back(option);171}172} else {173if (resource_importer_scene->get_internal_option_visibility(category, E.option.name, current)) {174handle_special_properties(option);175r_list->push_back(option);176}177}178}179}180};181182bool SceneImportSettingsDialog::_get_current(const StringName &p_name, Variant &r_ret) const {183if (scene_import_settings_data->_get(p_name, r_ret)) {184return true;185}186if (defaults.has(p_name)) {187r_ret = defaults[p_name];188return true;189}190return false;191}192193void SceneImportSettingsDialog::_set_default(const StringName &p_name, const Variant &p_value) {194defaults[p_name] = p_value;195scene_import_settings_data->defaults[p_name] = p_value;196scene_import_settings_data->_set(p_name, p_value);197}198199void SceneImportSettingsDialog::_fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent) {200String import_id;201bool has_import_id = false;202203if (p_material->has_meta("import_id")) {204import_id = p_material->get_meta("import_id");205has_import_id = true;206} else if (!p_material->get_name().is_empty()) {207import_id = p_material->get_name();208has_import_id = true;209} else if (unnamed_material_name_map.has(p_material)) {210import_id = unnamed_material_name_map[p_material];211} else {212import_id = "@MATERIAL:" + itos(material_map.size());213unnamed_material_name_map[p_material] = import_id;214}215216bool created = false;217if (!material_map.has(import_id)) {218MaterialData md;219created = true;220md.has_import_id = has_import_id;221md.material = p_material;222223_load_default_subresource_settings(md.settings, "materials", import_id, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MATERIAL);224225material_map[import_id] = md;226}227228MaterialData &material_data = material_map[import_id];229ERR_FAIL_COND(p_material != material_data.material);230231Variant value;232if (_get_current("materials/extract", value) && (int)value != 0) {233String spath = base_path.get_base_dir();234if (_get_current("materials/extract_path", value)) {235String extpath = value;236if (!extpath.is_empty()) {237spath = extpath;238}239}240241String ext = ResourceImporterScene::material_extension[_get_current("materials/extract_format", value) ? (int)value : 0];242String path = spath.path_join(import_id.validate_filename() + ext);243String uid_path = ResourceUID::path_to_uid(path);244material_data.settings["use_external/enabled"] = true;245material_data.settings["use_external/path"] = uid_path;246material_data.settings["use_external/fallback_path"] = path;247}248249Ref<Texture2D> icon = get_editor_theme_icon(SNAME("StandardMaterial3D"));250251TreeItem *item = p_tree->create_item(p_parent);252if (p_material->get_name().is_empty()) {253item->set_text(0, TTR("<Unnamed Material>"));254} else {255item->set_text(0, p_material->get_name());256}257item->set_icon(0, icon);258259item->set_meta("type", "Material");260item->set_meta("import_id", import_id);261item->set_tooltip_text(0, vformat(TTR("Import ID: %s"), import_id));262item->set_selectable(0, true);263264if (p_tree == scene_tree) {265material_data.scene_node = item;266} else if (p_tree == mesh_tree) {267material_data.mesh_node = item;268} else {269material_data.material_node = item;270}271272if (created) {273_fill_material(material_tree, p_material, material_tree->get_root());274}275}276277void SceneImportSettingsDialog::_fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent) {278String import_id;279280bool has_import_id = false;281if (p_mesh->has_meta("import_id")) {282import_id = p_mesh->get_meta("import_id");283has_import_id = true;284} else if (!p_mesh->get_name().is_empty()) {285import_id = p_mesh->get_name();286has_import_id = true;287} else {288import_id = "@MESH:" + itos(mesh_set.size());289}290291if (!mesh_map.has(import_id)) {292MeshData md;293md.has_import_id = has_import_id;294md.mesh = p_mesh;295296_load_default_subresource_settings(md.settings, "meshes", import_id, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH);297298mesh_map[import_id] = md;299}300301MeshData &mesh_data = mesh_map[import_id];302303Ref<Texture2D> icon = get_editor_theme_icon(SNAME("MeshItem"));304305TreeItem *item = p_tree->create_item(p_parent);306item->set_text(0, p_mesh->get_name());307item->set_icon(0, icon);308309bool created = false;310if (!mesh_set.has(p_mesh)) {311mesh_set.insert(p_mesh);312created = true;313}314315item->set_meta("type", "Mesh");316item->set_meta("import_id", import_id);317item->set_tooltip_text(0, vformat(TTR("Import ID: %s"), import_id));318319item->set_selectable(0, true);320321if (p_tree == scene_tree) {322mesh_data.scene_node = item;323} else {324mesh_data.mesh_node = item;325}326327item->set_collapsed(true);328329for (int i = 0; i < p_mesh->get_surface_count(); i++) {330Ref<Material> mat = p_mesh->surface_get_material(i);331if (mat.is_valid()) {332_fill_material(p_tree, mat, item);333}334}335336if (created) {337_fill_mesh(mesh_tree, p_mesh, mesh_tree->get_root());338}339}340341void SceneImportSettingsDialog::_fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent) {342if (!animation_map.has(p_name)) {343AnimationData ad;344ad.animation = p_anim;345346_load_default_subresource_settings(ad.settings, "animations", p_name, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION);347Animation::LoopMode loop_mode = p_anim->get_loop_mode();348if (!ad.settings.has("settings/loop_mode") && loop_mode != Animation::LoopMode::LOOP_NONE) {349// Update the loop mode to match detected mode (from import hints).350// This is necessary on the first import of a scene, otherwise the351// default (0/NONE) is set when filling out defaults.352ad.settings["settings/loop_mode"] = loop_mode;353}354355animation_map[p_name] = ad;356}357358AnimationData &animation_data = animation_map[p_name];359360Ref<Texture2D> icon = get_editor_theme_icon(SNAME("Animation"));361362TreeItem *item = p_tree->create_item(p_parent);363item->set_text(0, p_name);364item->set_icon(0, icon);365366item->set_meta("type", "Animation");367item->set_meta("import_id", p_name);368369item->set_selectable(0, true);370371animation_data.scene_node = item;372}373374void SceneImportSettingsDialog::_fill_scene(Node *p_node, TreeItem *p_parent_item) {375String import_id;376377if (p_node->has_meta("import_id")) {378import_id = p_node->get_meta("import_id");379} else {380import_id = "PATH:" + String(scene->get_path_to(p_node));381p_node->set_meta("import_id", import_id);382}383384ImporterMeshInstance3D *src_mesh_node = Object::cast_to<ImporterMeshInstance3D>(p_node);385386if (src_mesh_node) {387MeshInstance3D *mesh_node = memnew(MeshInstance3D);388mesh_node->set_name(src_mesh_node->get_name());389mesh_node->set_transform(src_mesh_node->get_transform());390mesh_node->set_skin(src_mesh_node->get_skin());391mesh_node->set_skeleton_path(src_mesh_node->get_skeleton_path());392mesh_node->set_visible(src_mesh_node->is_visible());393if (src_mesh_node->get_mesh().is_valid()) {394Ref<ImporterMesh> editor_mesh = src_mesh_node->get_mesh();395mesh_node->set_mesh(editor_mesh->get_mesh());396}397// Replace the original mesh node in the scene tree with the new one.398if (unlikely(p_node == scene)) {399scene = mesh_node;400}401p_node->replace_by(mesh_node);402memdelete(p_node);403p_node = mesh_node;404}405406String type = p_node->get_class();407408if (!has_theme_icon(type, EditorStringName(EditorIcons))) {409type = "Node3D";410}411412Ref<Texture2D> icon = get_editor_theme_icon(type);413414TreeItem *item = scene_tree->create_item(p_parent_item);415item->set_text(0, p_node->get_name());416417if (p_node == scene) {418icon = get_editor_theme_icon(SNAME("PackedScene"));419item->set_text(0, TTR("Scene"));420}421422item->set_icon(0, icon);423424item->set_meta("type", "Node");425item->set_meta("class", type);426item->set_meta("import_id", import_id);427item->set_tooltip_text(0, vformat(TTR("Type: %s\nImport ID: %s"), type, import_id));428429item->set_selectable(0, true);430431if (!node_map.has(import_id)) {432NodeData nd;433434if (p_node != scene) {435ResourceImporterScene::InternalImportCategory category;436if (src_mesh_node) {437category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;438} else if (Object::cast_to<AnimationPlayer>(p_node)) {439category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;440441animation_player = Object::cast_to<AnimationPlayer>(p_node);442animation_player->connect(SceneStringName(animation_finished), callable_mp(this, &SceneImportSettingsDialog::_animation_finished));443} else if (Object::cast_to<Skeleton3D>(p_node)) {444category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE;445Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);446skeleton->connect(SceneStringName(tree_entered), callable_mp(this, &SceneImportSettingsDialog::_skeleton_tree_entered).bind(skeleton));447skeletons.push_back(skeleton);448} else {449category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;450}451452_load_default_subresource_settings(nd.settings, "nodes", import_id, category);453}454455node_map[import_id] = nd;456}457NodeData &node_data = node_map[import_id];458459node_data.node = p_node;460node_data.scene_node = item;461462AnimationPlayer *anim_node = Object::cast_to<AnimationPlayer>(p_node);463if (anim_node) {464Vector<String> animation_list;465List<StringName> animations;466anim_node->get_animation_list(&animations);467for (const StringName &E : animations) {468_fill_animation(scene_tree, anim_node->get_animation(E), E, item);469animation_list.append(E);470}471if (scene_import_settings_data != nullptr) {472scene_import_settings_data->animation_list = animation_list;473}474}475476for (int i = 0; i < p_node->get_child_count(); i++) {477_fill_scene(p_node->get_child(i), item);478}479Transform3D accum_xform;480Node3D *base = Object::cast_to<Node3D>(p_node);481while (base) {482accum_xform = base->get_transform() * accum_xform;483base = Object::cast_to<Node3D>(base->get_parent());484}485MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node);486if (mesh_node && mesh_node->get_mesh().is_valid()) {487// This controls the display of mesh resources in the import settings dialog tree (the white mesh icon).488// We want to show these icons for any import type that preserves meshes.489if (_resource_importer_scene->get_scene_import_type() != "AnimationLibrary") {490_fill_mesh(scene_tree, mesh_node->get_mesh(), item);491}492493// Add the collider view.494MeshInstance3D *collider_view = memnew(MeshInstance3D);495collider_view->set_name("collider_view");496collider_view->set_visible(false);497mesh_node->add_child(collider_view, true);498collider_view->set_owner(mesh_node);499500AABB aabb = accum_xform.xform(mesh_node->get_mesh()->get_aabb());501502if (first_aabb) {503contents_aabb = aabb;504first_aabb = false;505} else {506contents_aabb.merge_with(aabb);507}508}509MultiMeshInstance3D *multi_mesh_node = Object::cast_to<MultiMeshInstance3D>(p_node);510if (multi_mesh_node && multi_mesh_node->get_multimesh().is_valid()) {511const Ref<MultiMesh> multi_mesh = multi_mesh_node->get_multimesh();512const Ref<Mesh> mm_mesh = multi_mesh->get_mesh();513if (mm_mesh.is_valid()) {514_fill_mesh(scene_tree, mm_mesh, item);515}516const AABB aabb = accum_xform.xform(multi_mesh->get_aabb());517if (first_aabb) {518contents_aabb = aabb;519first_aabb = false;520} else {521contents_aabb.merge_with(aabb);522}523}524525Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);526if (skeleton) {527Ref<ArrayMesh> bones_mesh = Skeleton3DGizmoPlugin::get_bones_mesh(skeleton, -1, true);528529bones_mesh_preview->set_mesh(bones_mesh);530bones_mesh_preview->set_transform(accum_xform * skeleton->get_transform());531532AABB aabb = accum_xform.xform(bones_mesh->get_aabb());533534if (first_aabb) {535contents_aabb = aabb;536first_aabb = false;537} else {538contents_aabb.merge_with(aabb);539}540}541}542543void SceneImportSettingsDialog::_update_scene() {544scene_tree->clear();545material_tree->clear();546mesh_tree->clear();547548// Hidden roots.549material_tree->create_item();550mesh_tree->create_item();551552_fill_scene(scene, nullptr);553}554555void SceneImportSettingsDialog::_update_view_gizmos() {556if (!is_visible()) {557return;558}559const HashMap<StringName, Variant> &main_settings = scene_import_settings_data->current;560bool reshow_settings = false;561if (main_settings.has("nodes/import_as_skeleton_bones")) {562bool new_import_as_skeleton = main_settings["nodes/import_as_skeleton_bones"];563reshow_settings = reshow_settings || (new_import_as_skeleton != previous_import_as_skeleton);564previous_import_as_skeleton = new_import_as_skeleton;565}566if (main_settings.has("animation/import_rest_as_RESET")) {567bool new_rest_as_reset = main_settings["animation/import_rest_as_RESET"];568reshow_settings = reshow_settings || (new_rest_as_reset != previous_rest_as_reset);569previous_rest_as_reset = new_rest_as_reset;570}571if (reshow_settings) {572_re_import();573open_settings(base_path);574return;575}576for (const KeyValue<String, NodeData> &e : node_map) {577// Skip import nodes that aren't MeshInstance3D.578const MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(e.value.node);579if (mesh_node == nullptr || mesh_node->get_mesh().is_null()) {580continue;581}582583// Determine if the mesh collider should be visible.584bool show_collider_view = false;585if (e.value.settings.has(SNAME("generate/physics"))) {586show_collider_view = e.value.settings[SNAME("generate/physics")];587}588589// Get the collider_view MeshInstance3D.590TypedArray<Node> descendants = mesh_node->find_children("collider_view", "MeshInstance3D");591CRASH_COND_MSG(descendants.is_empty(), "This is unreachable, since the collider view is always created even when the collision is not used! If this is triggered there is a bug on the function `_fill_scene`.");592MeshInstance3D *collider_view = Object::cast_to<MeshInstance3D>(descendants[0].operator Object *());593594// Regenerate the physics collider for this MeshInstance3D if either:595// - A regeneration is requested for the selected import node.596// - The collider is being made visible.597if ((generate_collider && e.key == selected_id) || (show_collider_view && !collider_view->is_visible())) {598// This collider_view doesn't have a mesh so we need to generate a new one.599Ref<ImporterMesh> mesh;600mesh.instantiate();601// ResourceImporterScene::get_collision_shapes() expects ImporterMesh, not Mesh.602// TODO: Duplicate code with EditorSceneFormatImporterESCN::import_scene()603// Consider making a utility function to convert from Mesh to ImporterMesh.604Ref<Mesh> mesh_3d_mesh = mesh_node->get_mesh();605Ref<ArrayMesh> array_mesh_3d_mesh = mesh_3d_mesh;606if (array_mesh_3d_mesh.is_valid()) {607// For the MeshInstance3D nodes, we need to convert the ArrayMesh to an ImporterMesh specially.608mesh->set_name(array_mesh_3d_mesh->get_name());609for (int32_t blend_i = 0; blend_i < array_mesh_3d_mesh->get_blend_shape_count(); blend_i++) {610mesh->add_blend_shape(array_mesh_3d_mesh->get_blend_shape_name(blend_i));611}612for (int32_t surface_i = 0; surface_i < array_mesh_3d_mesh->get_surface_count(); surface_i++) {613mesh->add_surface(array_mesh_3d_mesh->surface_get_primitive_type(surface_i),614array_mesh_3d_mesh->surface_get_arrays(surface_i),615array_mesh_3d_mesh->surface_get_blend_shape_arrays(surface_i),616array_mesh_3d_mesh->surface_get_lods(surface_i),617array_mesh_3d_mesh->surface_get_material(surface_i),618array_mesh_3d_mesh->surface_get_name(surface_i),619array_mesh_3d_mesh->surface_get_format(surface_i));620}621mesh->set_blend_shape_mode(array_mesh_3d_mesh->get_blend_shape_mode());622} else if (mesh_3d_mesh.is_valid()) {623// For the MeshInstance3D nodes, we need to convert the Mesh to an ImporterMesh specially.624mesh->set_name(mesh_3d_mesh->get_name());625for (int32_t surface_i = 0; surface_i < mesh_3d_mesh->get_surface_count(); surface_i++) {626mesh->add_surface(mesh_3d_mesh->surface_get_primitive_type(surface_i),627mesh_3d_mesh->surface_get_arrays(surface_i),628Array(),629mesh_3d_mesh->surface_get_lods(surface_i),630mesh_3d_mesh->surface_get_material(surface_i),631mesh_3d_mesh->surface_get_material(surface_i).is_valid() ? mesh_3d_mesh->surface_get_material(surface_i)->get_name() : String(),632mesh_3d_mesh->surface_get_format(surface_i));633}634}635636// Generate the mesh collider.637Vector<Ref<Shape3D>> shapes = ResourceImporterScene::get_collision_shapes(mesh, e.value.settings, 1.0);638const Transform3D transform = ResourceImporterScene::get_collision_shapes_transform(e.value.settings);639640Ref<ArrayMesh> collider_view_mesh;641collider_view_mesh.instantiate();642for (Ref<Shape3D> shape : shapes) {643Ref<ArrayMesh> debug_shape_mesh;644if (shape.is_valid()) {645debug_shape_mesh = shape->get_debug_mesh();646}647if (debug_shape_mesh.is_valid()) {648collider_view_mesh->add_surface_from_arrays(649debug_shape_mesh->surface_get_primitive_type(0),650debug_shape_mesh->surface_get_arrays(0));651652collider_view_mesh->surface_set_material(653collider_view_mesh->get_surface_count() - 1,654collider_mat);655}656}657658collider_view->set_mesh(collider_view_mesh);659collider_view->set_transform(transform);660}661662// Set the collider visibility.663collider_view->set_visible(show_collider_view);664}665666generate_collider = false;667}668669void SceneImportSettingsDialog::_update_camera() {670AABB camera_aabb;671672float rot_x = cam_rot_x;673float rot_y = cam_rot_y;674float zoom = cam_zoom;675676if (selected_type == "Node" || selected_type == "Animation" || selected_type.is_empty()) {677camera_aabb = contents_aabb;678} else {679if (mesh_preview->get_mesh().is_valid()) {680camera_aabb = mesh_preview->get_transform().xform(mesh_preview->get_mesh()->get_aabb());681} else {682camera_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));683}684if (selected_type == "Mesh" && mesh_map.has(selected_id)) {685const MeshData &md = mesh_map[selected_id];686rot_x = md.cam_rot_x;687rot_y = md.cam_rot_y;688zoom = md.cam_zoom;689} else if (selected_type == "Material" && material_map.has(selected_id)) {690const MaterialData &md = material_map[selected_id];691rot_x = md.cam_rot_x;692rot_y = md.cam_rot_y;693zoom = md.cam_zoom;694}695}696697Vector3 center = camera_aabb.get_center();698float camera_size = camera_aabb.get_longest_axis_size();699700camera->set_orthogonal(camera_size * zoom, 0.0001, camera_size * 2);701702Transform3D xf;703xf.basis = Basis(Vector3(0, 1, 0), rot_y) * Basis(Vector3(1, 0, 0), rot_x);704xf.origin = center;705xf.translate_local(0, 0, camera_size);706707camera->set_transform(xf);708}709710void SceneImportSettingsDialog::_load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category) {711if (base_subresource_settings.has(p_type)) {712Dictionary d = base_subresource_settings[p_type];713if (d.has(p_import_id)) {714d = d[p_import_id];715List<ResourceImporterScene::ImportOption> options;716_resource_importer_scene->get_internal_import_options(p_category, &options);717for (const ResourceImporterScene::ImportOption &E : options) {718String key = E.option.name;719if (d.has(key)) {720settings[key] = d[key];721}722}723}724}725}726727void SceneImportSettingsDialog::request_generate_collider() {728generate_collider = true;729}730731void SceneImportSettingsDialog::update_view() {732update_view_timer->start();733}734735void SceneImportSettingsDialog::open_settings(const String &p_path, const String &p_scene_import_type) {736if (scene) {737_cleanup();738memdelete(scene);739scene = nullptr;740}741742scene_import_settings_data->settings = nullptr;743scene_import_settings_data->path = p_path;744745// AnimationLibrary cannot make use of the mesh and material tabs.746const bool disable_mesh_mat_tabs = p_scene_import_type == "AnimationLibrary";747data_mode->set_tab_hidden(1, disable_mesh_mat_tabs);748data_mode->set_tab_hidden(2, disable_mesh_mat_tabs);749if (disable_mesh_mat_tabs) {750data_mode->set_current_tab(0);751}752753// Only show the save data options for PackedScene imports of scenes, not resource imports.754const bool disable_save_mesh_mat = p_scene_import_type != "PackedScene";755action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_EXTRACT_MATERIALS), disable_save_mesh_mat);756action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_CHOOSE_MESH_SAVE_PATHS), disable_save_mesh_mat);757const bool disable_save_anim = disable_save_mesh_mat && p_scene_import_type != "AnimationLibrary";758action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_CHOOSE_ANIMATION_SAVE_PATHS), disable_save_anim);759760base_path = p_path;761762mesh_set.clear();763animation_map.clear();764material_map.clear();765unnamed_material_name_map.clear();766mesh_map.clear();767node_map.clear();768defaults.clear();769770mesh_preview->hide();771772selected_id = "";773selected_type = "";774775cam_rot_x = -Math::PI / 4;776cam_rot_y = -Math::PI / 4;777cam_zoom = 1;778779{780base_subresource_settings.clear();781782Ref<ConfigFile> config;783config.instantiate();784Error err = config->load(p_path + ".import");785if (err == OK) {786Vector<String> keys = config->get_section_keys("params");787for (const String &E : keys) {788Variant value = config->get_value("params", E);789if (E == "_subresources") {790base_subresource_settings = value;791} else {792defaults[E] = value;793}794}795}796}797798// Regardless of p_scene_import_type, use PackedScene for pre_import because we want to see the full thing.799_resource_importer_scene->set_scene_import_type("PackedScene");800scene = _resource_importer_scene->pre_import(p_path, defaults);801_resource_importer_scene->set_scene_import_type(p_scene_import_type);802if (scene == nullptr) {803EditorNode::get_singleton()->show_warning(TTR("Error opening scene"));804return;805}806807first_aabb = true;808809_update_scene();810811base_viewport->add_child(scene);812813inspector->edit(nullptr);814815if (first_aabb) {816contents_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));817first_aabb = false;818}819820const HashMap<StringName, Variant> &main_settings = scene_import_settings_data->current;821if (main_settings.has("nodes/import_as_skeleton_bones")) {822previous_import_as_skeleton = main_settings["nodes/import_as_skeleton_bones"];823}824if (main_settings.has("animation/import_rest_as_RESET")) {825previous_rest_as_reset = main_settings["animation/import_rest_as_RESET"];826}827popup_centered_ratio();828_update_view_gizmos();829_update_camera();830831// Start with the root item (Scene) selected.832scene_tree->get_root()->select(0);833834set_title(vformat(TTR("Advanced Import Settings for %s '%s'"), _resource_importer_scene->get_visible_name(), base_path.get_file()));835}836837SceneImportSettingsDialog *SceneImportSettingsDialog::singleton = nullptr;838839SceneImportSettingsDialog *SceneImportSettingsDialog::get_singleton() {840return singleton;841}842843Node *SceneImportSettingsDialog::get_selected_node() {844if (selected_id == "") {845return nullptr;846}847return node_map[selected_id].node;848}849850void SceneImportSettingsDialog::_select(Tree *p_from, const String &p_type, const String &p_id) {851selecting = true;852scene_import_settings_data->hide_options = false;853// Only AnimationLibrary and actual scenes can make use of the animation and skeleton options.854const bool hide_anim_and_skel_options = _resource_importer_scene->get_scene_import_type() != "PackedScene" && _resource_importer_scene->get_scene_import_type() != "AnimationLibrary";855// Only actual scenes can make use of the node generation options such as generating physics colliders on meshes or setting a script.856const bool hide_node_gen_options = _resource_importer_scene->get_scene_import_type() != "PackedScene";857858bones_mesh_preview->hide();859if (p_type == "Node") {860node_selected->hide(); // Always hide just in case.861mesh_preview->hide();862_reset_animation();863864if (Object::cast_to<Node3D>(scene)) {865Object::cast_to<Node3D>(scene)->show();866}867material_tree->deselect_all();868mesh_tree->deselect_all();869NodeData &nd = node_map[p_id];870871MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(nd.node);872if (mi) {873Ref<Mesh> base_mesh = mi->get_mesh();874if (base_mesh.is_valid()) {875AABB aabb = base_mesh->get_aabb();876Transform3D aabb_xf;877aabb_xf.basis.scale(aabb.size);878aabb_xf.origin = aabb.position;879880aabb_xf = mi->get_global_transform() * aabb_xf;881node_selected->set_transform(aabb_xf);882node_selected->show();883}884}885886if (nd.node == scene) {887scene_import_settings_data->settings = &defaults;888scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;889} else {890scene_import_settings_data->settings = &nd.settings;891if (mi) {892scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;893scene_import_settings_data->hide_options = hide_node_gen_options;894} else if (Object::cast_to<AnimationPlayer>(nd.node)) {895scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;896scene_import_settings_data->hide_options = hide_anim_and_skel_options;897} else if (Object::cast_to<Skeleton3D>(nd.node)) {898scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE;899bones_mesh_preview->show();900scene_import_settings_data->hide_options = hide_anim_and_skel_options;901} else {902scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;903scene_import_settings_data->hide_options = hide_node_gen_options;904}905}906} else if (p_type == "Animation") {907node_selected->hide(); // Always hide just in case.908mesh_preview->hide();909_reset_animation(p_id);910911if (Object::cast_to<Node3D>(scene)) {912Object::cast_to<Node3D>(scene)->show();913}914material_tree->deselect_all();915mesh_tree->deselect_all();916AnimationData &ad = animation_map[p_id];917918scene_import_settings_data->settings = &ad.settings;919scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION;920scene_import_settings_data->hide_options = hide_anim_and_skel_options;921922_animation_update_skeleton_visibility();923} else if (p_type == "Mesh") {924node_selected->hide();925if (Object::cast_to<Node3D>(scene)) {926Object::cast_to<Node3D>(scene)->hide();927}928929MeshData &md = mesh_map[p_id];930if (md.mesh_node != nullptr) {931if (p_from != mesh_tree) {932md.mesh_node->uncollapse_tree();933md.mesh_node->select(0);934mesh_tree->ensure_cursor_is_visible();935}936if (p_from != scene_tree) {937md.scene_node->uncollapse_tree();938md.scene_node->select(0);939scene_tree->ensure_cursor_is_visible();940}941}942943mesh_preview->set_mesh(md.mesh);944mesh_preview->show();945_reset_animation();946947material_tree->deselect_all();948949scene_import_settings_data->settings = &md.settings;950scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH;951} else if (p_type == "Material") {952node_selected->hide();953if (Object::cast_to<Node3D>(scene)) {954Object::cast_to<Node3D>(scene)->hide();955}956957mesh_preview->show();958_reset_animation();959960MaterialData &md = material_map[p_id];961962material_preview->set_material(md.material);963mesh_preview->set_mesh(material_preview);964965if (p_from != mesh_tree) {966md.mesh_node->uncollapse_tree();967md.mesh_node->select(0);968mesh_tree->ensure_cursor_is_visible();969}970if (p_from != scene_tree) {971md.scene_node->uncollapse_tree();972md.scene_node->select(0);973scene_tree->ensure_cursor_is_visible();974}975if (p_from != material_tree) {976md.material_node->uncollapse_tree();977md.material_node->select(0);978material_tree->ensure_cursor_is_visible();979}980981scene_import_settings_data->settings = &md.settings;982scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MATERIAL;983}984985selected_type = p_type;986selected_id = p_id;987988selecting = false;989990_update_camera();991992List<ResourceImporter::ImportOption> options;993994if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {995_resource_importer_scene->get_import_options(base_path, &options);996} else {997_resource_importer_scene->get_internal_import_options(scene_import_settings_data->category, &options);998}9991000scene_import_settings_data->defaults.clear();1001scene_import_settings_data->current.clear();10021003if (scene_import_settings_data->settings) {1004for (const ResourceImporter::ImportOption &E : options) {1005scene_import_settings_data->defaults[E.option.name] = E.default_value;1006// Needed for visibility toggling (fails if something is missing).1007if (scene_import_settings_data->settings->has(E.option.name)) {1008scene_import_settings_data->current[E.option.name] = (*scene_import_settings_data->settings)[E.option.name];1009} else {1010scene_import_settings_data->current[E.option.name] = E.default_value;1011}1012}1013}10141015scene_import_settings_data->options = options;1016inspector->edit(scene_import_settings_data);1017scene_import_settings_data->notify_property_list_changed();1018}10191020void SceneImportSettingsDialog::_inspector_property_edited(const String &p_name) {1021if (p_name == "settings/loop_mode") {1022if (!animation_map.has(selected_id)) {1023return;1024}1025HashMap<StringName, Variant> settings(animation_map[selected_id].settings);1026if (settings.has(p_name)) {1027animation_loop_mode = static_cast<Animation::LoopMode>((int)settings[p_name]);1028} else {1029animation_loop_mode = Animation::LoopMode::LOOP_NONE;1030}1031}1032if ((p_name == "use_external/enabled") || (p_name == "use_external/path") || (p_name == "use_external/fallback_path")) {1033MaterialData &material_data = material_map[selected_id];1034String spath = base_path.get_base_dir();1035Variant value;1036if (_get_current("materials/extract_path", value)) {1037String extpath = value;1038if (!extpath.is_empty()) {1039spath = extpath;1040}1041}1042String opath = material_data.settings.has("use_external/path") ? (String)material_data.settings["use_external/path"] : String();1043if (opath.begins_with("uid://")) {1044opath = ResourceUID::uid_to_path(opath);1045}1046String ext = ResourceImporterScene::material_extension[_get_current("materials/extract_format", value) ? (int)value : 0];1047String npath = spath.path_join(selected_id.validate_filename() + ext);10481049if (!material_data.settings.has("use_external/enabled") || (bool)material_data.settings["use_external/enabled"] == false || opath != npath) {1050if (_get_current("materials/extract", value) && (int)value != 0) {1051print_line("Material settings changed, automatic material extraction disabled.");1052}1053_set_default("materials/extract", 0);1054}1055}1056}10571058void SceneImportSettingsDialog::_reset_bone_transforms() {1059for (Skeleton3D *skeleton : skeletons) {1060skeleton->reset_bone_poses();1061}1062}10631064void SceneImportSettingsDialog::_play_animation() {1065if (animation_player == nullptr) {1066return;1067}1068StringName id = StringName(selected_id);1069if (animation_player->has_animation(id)) {1070if (animation_player->is_playing()) {1071animation_player->pause();1072animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1073set_process(false);1074} else {1075animation_player->play(id);1076animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));1077set_process(true);1078}1079}1080}10811082void SceneImportSettingsDialog::_stop_current_animation() {1083animation_pingpong = false;1084animation_player->stop();1085animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1086animation_slider->set_value_no_signal(0.0);1087set_process(false);1088}10891090void SceneImportSettingsDialog::_reset_animation(const String &p_animation_name) {1091if (p_animation_name.is_empty()) {1092animation_preview->hide();10931094if (animation_player != nullptr && animation_player->is_playing()) {1095animation_player->stop();1096}1097animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));10981099_reset_bone_transforms();1100set_process(false);1101} else {1102_reset_bone_transforms();1103animation_preview->show();11041105animation_loop_mode = Animation::LoopMode::LOOP_NONE;1106animation_pingpong = false;11071108if (animation_map.has(p_animation_name)) {1109HashMap<StringName, Variant> settings(animation_map[p_animation_name].settings);1110if (settings.has("settings/loop_mode")) {1111animation_loop_mode = static_cast<Animation::LoopMode>((int)settings["settings/loop_mode"]);1112}1113}11141115if (animation_player->is_playing() && animation_loop_mode != Animation::LoopMode::LOOP_NONE) {1116animation_player->play(p_animation_name);1117} else {1118animation_player->stop(true);1119animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1120animation_player->set_assigned_animation(p_animation_name);1121animation_player->seek(0.0, true);1122animation_slider->set_value_no_signal(0.0);1123set_process(false);1124}1125}1126}11271128void SceneImportSettingsDialog::_animation_slider_value_changed(double p_value) {1129if (animation_player == nullptr || !animation_map.has(selected_id) || animation_map[selected_id].animation.is_null()) {1130return;1131}1132if (animation_player->is_playing()) {1133animation_player->stop();1134animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1135set_process(false);1136}1137animation_player->seek(p_value * animation_map[selected_id].animation->get_length(), true);1138}11391140void SceneImportSettingsDialog::_skeleton_tree_entered(Skeleton3D *p_skeleton) {1141bones_mesh_preview->set_skeleton_path(p_skeleton->get_path());1142Ref<Skin> skin = p_skeleton->create_skin_from_rest_transforms();1143p_skeleton->register_skin(skin);1144bones_mesh_preview->set_skin(skin);1145}11461147void SceneImportSettingsDialog::_animation_finished(const StringName &p_name) {1148Animation::LoopMode loop_mode = animation_loop_mode;11491150switch (loop_mode) {1151case Animation::LOOP_NONE: {1152animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1153animation_slider->set_value_no_signal(1.0);1154set_process(false);1155} break;1156case Animation::LOOP_LINEAR: {1157animation_player->play(p_name);1158} break;1159case Animation::LOOP_PINGPONG: {1160if (animation_pingpong) {1161animation_player->play(p_name);1162} else {1163animation_player->play_backwards(p_name);1164}1165animation_pingpong = !animation_pingpong;1166} break;1167default: {1168} break;1169}1170}11711172void SceneImportSettingsDialog::_animation_update_skeleton_visibility() {1173if (animation_toggle_skeleton_visibility->is_pressed()) {1174bones_mesh_preview->show();1175} else {1176bones_mesh_preview->hide();1177}1178}11791180void SceneImportSettingsDialog::_material_tree_selected() {1181if (selecting) {1182return;1183}1184TreeItem *item = material_tree->get_selected();1185String type = item->get_meta("type");1186String import_id = item->get_meta("import_id");11871188_select(material_tree, type, import_id);1189}11901191void SceneImportSettingsDialog::_mesh_tree_selected() {1192if (selecting) {1193return;1194}11951196TreeItem *item = mesh_tree->get_selected();1197String type = item->get_meta("type");1198String import_id = item->get_meta("import_id");11991200_select(mesh_tree, type, import_id);1201}12021203void SceneImportSettingsDialog::_scene_tree_selected() {1204if (selecting) {1205return;1206}1207TreeItem *item = scene_tree->get_selected();1208String type = item->get_meta("type");1209String import_id = item->get_meta("import_id");12101211_select(scene_tree, type, import_id);1212}12131214void SceneImportSettingsDialog::_cleanup() {1215skeletons.clear();1216if (animation_player != nullptr) {1217animation_player->disconnect(SceneStringName(animation_finished), callable_mp(this, &SceneImportSettingsDialog::_animation_finished));1218animation_player = nullptr;1219}1220set_process(false);1221}12221223void SceneImportSettingsDialog::_on_light_1_switch_pressed() {1224light1->set_visible(light_1_switch->is_pressed());1225}12261227void SceneImportSettingsDialog::_on_light_2_switch_pressed() {1228light2->set_visible(light_2_switch->is_pressed());1229}12301231void SceneImportSettingsDialog::_on_light_rotate_switch_pressed() {1232bool light_top_level = !light_rotate_switch->is_pressed();1233light1->set_as_top_level_keep_local(light_top_level);1234light2->set_as_top_level_keep_local(light_top_level);1235}12361237void SceneImportSettingsDialog::_viewport_input(const Ref<InputEvent> &p_input) {1238float *rot_x = &cam_rot_x;1239float *rot_y = &cam_rot_y;1240float *zoom = &cam_zoom;12411242if (selected_type == "Mesh" && mesh_map.has(selected_id)) {1243MeshData &md = mesh_map[selected_id];1244rot_x = &md.cam_rot_x;1245rot_y = &md.cam_rot_y;1246zoom = &md.cam_zoom;1247} else if (selected_type == "Material" && material_map.has(selected_id)) {1248MaterialData &md = material_map[selected_id];1249rot_x = &md.cam_rot_x;1250rot_y = &md.cam_rot_y;1251zoom = &md.cam_zoom;1252}1253Ref<InputEventMouseMotion> mm = p_input;1254if (mm.is_valid() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {1255(*rot_x) -= mm->get_relative().y * 0.01 * EDSCALE;1256(*rot_y) -= mm->get_relative().x * 0.01 * EDSCALE;1257(*rot_x) = CLAMP((*rot_x), -Math::PI / 2, Math::PI / 2);1258_update_camera();1259}1260if (mm.is_valid() && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE)) {1261DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CursorShape::CURSOR_ARROW);1262}1263Ref<InputEventMouseButton> mb = p_input;1264if (mb.is_valid() && mb->get_button_index() == MouseButton::WHEEL_DOWN) {1265(*zoom) *= 1.1;1266if ((*zoom) > 10.0) {1267(*zoom) = 10.0;1268}1269_update_camera();1270}1271if (mb.is_valid() && mb->get_button_index() == MouseButton::WHEEL_UP) {1272(*zoom) /= 1.1;1273if ((*zoom) < 0.1) {1274(*zoom) = 0.1;1275}1276_update_camera();1277}1278Ref<InputEventMagnifyGesture> mg = p_input;1279if (mg.is_valid()) {1280real_t mg_factor = mg->get_factor();1281if (mg_factor == 0.0) {1282mg_factor = 1.0;1283}1284(*zoom) /= mg_factor;1285if ((*zoom) < 0.1) {1286(*zoom) = 0.1;1287} else if ((*zoom) > 10.0) {1288(*zoom) = 10.0;1289}1290_update_camera();1291}1292}12931294void SceneImportSettingsDialog::_re_import() {1295HashMap<StringName, Variant> main_settings;12961297main_settings = scene_import_settings_data->current;1298main_settings.erase("_subresources");1299Dictionary nodes;1300Dictionary materials;1301Dictionary meshes;1302Dictionary animations;13031304Dictionary subresources;13051306for (KeyValue<String, NodeData> &E : node_map) {1307if (E.value.settings.size()) {1308Dictionary d;1309for (const KeyValue<StringName, Variant> &F : E.value.settings) {1310d[String(F.key)] = F.value;1311}1312nodes[E.key] = d;1313}1314}1315if (nodes.size()) {1316subresources["nodes"] = nodes;1317}13181319for (KeyValue<String, MaterialData> &E : material_map) {1320if (E.value.settings.size()) {1321Dictionary d;1322for (const KeyValue<StringName, Variant> &F : E.value.settings) {1323d[String(F.key)] = F.value;1324}1325materials[E.key] = d;1326}1327}1328if (materials.size()) {1329subresources["materials"] = materials;1330}13311332for (KeyValue<String, MeshData> &E : mesh_map) {1333if (E.value.settings.size()) {1334Dictionary d;1335for (const KeyValue<StringName, Variant> &F : E.value.settings) {1336d[String(F.key)] = F.value;1337}1338meshes[E.key] = d;1339}1340}1341if (meshes.size()) {1342subresources["meshes"] = meshes;1343}13441345for (KeyValue<String, AnimationData> &E : animation_map) {1346if (E.value.settings.size()) {1347Dictionary d;1348for (const KeyValue<StringName, Variant> &F : E.value.settings) {1349d[String(F.key)] = F.value;1350}1351animations[E.key] = d;1352}1353}1354if (animations.size()) {1355subresources["animations"] = animations;1356}13571358main_settings["_subresources"] = subresources;13591360_cleanup(); // Prevent skeletons and other pointers from pointing to dangling references.1361EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, _resource_importer_scene->get_importer_name(), main_settings);1362}13631364void SceneImportSettingsDialog::_update_theme_item_cache() {1365ConfirmationDialog::_update_theme_item_cache();1366theme_cache.light_1_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight1"));1367theme_cache.light_2_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight2"));1368theme_cache.rotate_icon = get_editor_theme_icon(SNAME("PreviewRotate"));1369}13701371void SceneImportSettingsDialog::_notification(int p_what) {1372switch (p_what) {1373case NOTIFICATION_READY: {1374connect(SceneStringName(confirmed), callable_mp(this, &SceneImportSettingsDialog::_re_import));1375} break;13761377case NOTIFICATION_THEME_CHANGED: {1378if (animation_player != nullptr && animation_player->is_playing()) {1379animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));1380} else {1381animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1382}1383animation_stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));13841385light_1_switch->set_button_icon(theme_cache.light_1_icon);1386light_2_switch->set_button_icon(theme_cache.light_2_icon);1387light_rotate_switch->set_button_icon(theme_cache.rotate_icon);13881389animation_toggle_skeleton_visibility->set_button_icon(get_editor_theme_icon(SNAME("SkeletonPreview")));1390} break;13911392case NOTIFICATION_PROCESS: {1393if (animation_player != nullptr) {1394animation_slider->set_value_no_signal(animation_player->get_current_animation_position() / animation_player->get_current_animation_length());1395}1396} break;13971398case NOTIFICATION_VISIBILITY_CHANGED: {1399if (!is_visible()) {1400_cleanup();1401}1402} break;1403}1404}14051406void SceneImportSettingsDialog::_menu_callback(int p_id) {1407switch (p_id) {1408case ACTION_EXTRACT_MATERIALS: {1409save_path->set_title(TTR("Select folder to extract material resources"));1410external_extension_type->select(0);1411} break;1412case ACTION_CHOOSE_MESH_SAVE_PATHS: {1413save_path->set_title(TTR("Select folder where mesh resources will save on import"));1414external_extension_type->select(1);1415} break;1416case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {1417save_path->set_title(TTR("Select folder where animations will save on import"));1418external_extension_type->select(1);1419} break;1420}14211422save_path->set_current_dir(base_path.get_base_dir());1423current_action = p_id;1424save_path->popup_centered_ratio();1425}14261427void SceneImportSettingsDialog::_save_path_changed(const String &p_path) {1428save_path_item->set_text(1, p_path);14291430if (FileAccess::exists(p_path)) {1431save_path_item->set_text(2, TTR("Warning: File exists"));1432save_path_item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced."));1433save_path_item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));14341435} else {1436save_path_item->set_text(2, TTR("Will create new file"));1437save_path_item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1438}1439}14401441void SceneImportSettingsDialog::_browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button) {1442if (p_button != MouseButton::LEFT) {1443return;1444}14451446TreeItem *item = Object::cast_to<TreeItem>(p_item);14471448String path = item->get_text(1);14491450item_save_path->set_current_file(path);1451save_path_item = item;14521453item_save_path->popup_centered_ratio();1454}14551456void SceneImportSettingsDialog::_save_dir_callback(const String &p_path) {1457external_path_tree->clear();1458TreeItem *root = external_path_tree->create_item();1459save_path_items.clear();14601461switch (current_action) {1462case ACTION_EXTRACT_MATERIALS: {1463for (const KeyValue<String, MaterialData> &E : material_map) {1464MaterialData &md = material_map[E.key];14651466TreeItem *item = external_path_tree->create_item(root);14671468String name = md.material_node->get_text(0);14691470item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);1471item->set_icon(0, get_editor_theme_icon(SNAME("StandardMaterial3D")));1472item->set_text(0, name);14731474if (md.has_import_id) {1475if (md.settings.has("use_external/enabled") && bool(md.settings["use_external/enabled"])) {1476item->set_text(2, TTR("Already External"));1477item->set_tooltip_text(2, TTR("This material already references an external file, no action will be taken.\nDisable the external property for it to be extracted again."));1478} else {1479item->set_metadata(0, E.key);1480item->set_editable(0, true);1481item->set_checked(0, true);1482name = name.validate_filename();1483String path = p_path.path_join(name);1484if (external_extension_type->get_selected() == 0) {1485path += ".tres";1486} else {1487path += ".res";1488}14891490item->set_text(1, path);1491if (FileAccess::exists(path)) {1492item->set_text(2, TTR("Warning: File exists"));1493item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced."));1494item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));14951496} else {1497item->set_text(2, TTR("Will create new file"));1498item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1499}15001501item->add_button(1, get_editor_theme_icon(SNAME("Folder")));1502}15031504} else {1505item->set_text(2, TTR("No import ID"));1506item->set_tooltip_text(2, TTR("Material has no name nor any other way to identify on re-import.\nPlease name it or ensure it is exported with an unique ID."));1507item->set_icon(2, get_editor_theme_icon(SNAME("StatusError")));1508}15091510save_path_items.push_back(item);1511}15121513external_paths->set_title(TTR("Extract Materials to Resource Files"));1514external_paths->set_ok_button_text(TTR("Extract"));1515} break;1516case ACTION_CHOOSE_MESH_SAVE_PATHS: {1517for (const KeyValue<String, MeshData> &E : mesh_map) {1518MeshData &md = mesh_map[E.key];15191520TreeItem *item = external_path_tree->create_item(root);15211522String name = md.mesh_node->get_text(0);15231524item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);1525item->set_icon(0, get_editor_theme_icon(SNAME("MeshItem")));1526item->set_text(0, name);15271528if (md.has_import_id) {1529if (md.settings.has("save_to_file/enabled") && bool(md.settings["save_to_file/enabled"])) {1530item->set_text(2, TTR("Already Saving"));1531item->set_tooltip_text(2, TTR("This mesh already saves to an external resource, no action will be taken."));1532} else {1533item->set_metadata(0, E.key);1534item->set_editable(0, true);1535item->set_checked(0, true);1536name = name.validate_filename();1537String path = p_path.path_join(name);1538if (external_extension_type->get_selected() == 0) {1539path += ".tres";1540} else {1541path += ".res";1542}15431544item->set_text(1, path);1545if (FileAccess::exists(path)) {1546item->set_text(2, TTR("Warning: File exists"));1547item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced on import."));1548item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));15491550} else {1551item->set_text(2, TTR("Will save to new file"));1552item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1553}15541555item->add_button(1, get_editor_theme_icon(SNAME("Folder")));1556}15571558} else {1559item->set_text(2, TTR("No import ID"));1560item->set_tooltip_text(2, TTR("Mesh has no name nor any other way to identify on re-import.\nPlease name it or ensure it is exported with an unique ID."));1561item->set_icon(2, get_editor_theme_icon(SNAME("StatusError")));1562}15631564save_path_items.push_back(item);1565}15661567external_paths->set_title(TTR("Set paths to save meshes as resource files on Reimport"));1568external_paths->set_ok_button_text(TTR("Set Paths"));1569} break;1570case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {1571for (const KeyValue<String, AnimationData> &E : animation_map) {1572AnimationData &ad = animation_map[E.key];15731574TreeItem *item = external_path_tree->create_item(root);15751576String name = ad.scene_node->get_text(0);15771578item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);1579item->set_icon(0, get_editor_theme_icon(SNAME("Animation")));1580item->set_text(0, name);15811582if (ad.settings.has("save_to_file/enabled") && bool(ad.settings["save_to_file/enabled"])) {1583item->set_text(2, TTR("Already Saving"));1584item->set_tooltip_text(2, TTR("This animation already saves to an external resource, no action will be taken."));1585} else {1586item->set_metadata(0, E.key);1587item->set_editable(0, true);1588item->set_checked(0, true);1589name = name.validate_filename();1590String path = p_path.path_join(name);1591if (external_extension_type->get_selected() == 0) {1592path += ".tres";1593} else {1594path += ".res";1595}15961597item->set_text(1, path);1598if (FileAccess::exists(path)) {1599item->set_text(2, TTR("Warning: File exists"));1600item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced on import."));1601item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));16021603} else {1604item->set_text(2, TTR("Will save to new file"));1605item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1606}16071608item->add_button(1, get_editor_theme_icon(SNAME("Folder")));1609}16101611save_path_items.push_back(item);1612}16131614external_paths->set_title(TTR("Set paths to save animations as resource files on Reimport"));1615external_paths->set_ok_button_text(TTR("Set Paths"));16161617} break;1618}16191620external_paths->popup_centered_ratio();1621}16221623void SceneImportSettingsDialog::_save_dir_confirm() {1624for (int i = 0; i < save_path_items.size(); i++) {1625TreeItem *item = save_path_items[i];1626if (!item->is_checked(0)) {1627continue; //ignore1628}1629String path = item->get_text(1);1630String uid_path = path;1631if (path.begins_with("uid://")) {1632path = ResourceUID::uid_to_path(uid_path);1633}1634if (!path.is_resource_file()) {1635continue;1636}16371638String id = item->get_metadata(0);16391640switch (current_action) {1641case ACTION_EXTRACT_MATERIALS: {1642ERR_CONTINUE(!material_map.has(id));1643MaterialData &md = material_map[id];16441645Error err = ResourceSaver::save(md.material, path);1646if (err != OK) {1647EditorNode::get_singleton()->add_io_error(TTR("Can't make material external to file, write error:") + "\n\t" + path);1648continue;1649}1650uid_path = ResourceUID::path_to_uid(path);16511652md.settings["use_external/enabled"] = true;1653md.settings["use_external/path"] = uid_path;1654md.settings["use_external/fallback_path"] = path;16551656} break;1657case ACTION_CHOOSE_MESH_SAVE_PATHS: {1658ERR_CONTINUE(!mesh_map.has(id));1659MeshData &md = mesh_map[id];16601661md.settings["save_to_file/enabled"] = true;1662md.settings["save_to_file/path"] = uid_path;1663md.settings["save_to_file/fallback_path"] = path;1664} break;1665case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {1666ERR_CONTINUE(!animation_map.has(id));1667AnimationData &ad = animation_map[id];16681669ad.settings["save_to_file/enabled"] = true;1670ad.settings["save_to_file/path"] = uid_path;1671ad.settings["save_to_file/fallback_path"] = path;16721673} break;1674}1675}16761677if (current_action == ACTION_EXTRACT_MATERIALS) {1678//as this happens right now, the scene needs to be saved and reimported.1679_re_import();1680open_settings(base_path);1681} else {1682scene_import_settings_data->notify_property_list_changed();1683}1684}16851686SceneImportSettingsDialog::SceneImportSettingsDialog() {1687singleton = this;1688_resource_importer_scene = memnew(ResourceImporterScene("PackedScene"));16891690VBoxContainer *main_vb = memnew(VBoxContainer);1691add_child(main_vb);1692HBoxContainer *menu_hb = memnew(HBoxContainer);1693main_vb->add_child(menu_hb);16941695action_menu = memnew(MenuButton);1696action_menu->set_text(TTR("Actions..."));1697// Style the MenuButton like a regular Button to make it more noticeable.1698action_menu->set_flat(false);1699action_menu->set_focus_mode(Control::FOCUS_ALL);1700menu_hb->add_child(action_menu);17011702action_menu->get_popup()->add_item(TTR("Extract Materials"), ACTION_EXTRACT_MATERIALS);1703action_menu->get_popup()->add_separator();1704action_menu->get_popup()->add_item(TTR("Set Animation Save Paths"), ACTION_CHOOSE_ANIMATION_SAVE_PATHS);1705action_menu->get_popup()->add_item(TTR("Set Mesh Save Paths"), ACTION_CHOOSE_MESH_SAVE_PATHS);17061707action_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &SceneImportSettingsDialog::_menu_callback));17081709tree_split = memnew(HSplitContainer);1710main_vb->add_child(tree_split);1711tree_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);17121713data_mode = memnew(TabContainer);1714tree_split->add_child(data_mode);1715data_mode->set_custom_minimum_size(Size2(300 * EDSCALE, 0));1716data_mode->set_theme_type_variation("TabContainerOdd");17171718property_split = memnew(HSplitContainer);1719tree_split->add_child(property_split);1720property_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);17211722scene_tree = memnew(Tree);1723scene_tree->set_name(TTR("Scene"));1724scene_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1725data_mode->add_child(scene_tree);1726scene_tree->connect("cell_selected", callable_mp(this, &SceneImportSettingsDialog::_scene_tree_selected));17271728mesh_tree = memnew(Tree);1729mesh_tree->set_name(TTR("Meshes"));1730mesh_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1731data_mode->add_child(mesh_tree);1732mesh_tree->set_hide_root(true);1733mesh_tree->connect("cell_selected", callable_mp(this, &SceneImportSettingsDialog::_mesh_tree_selected));17341735material_tree = memnew(Tree);1736material_tree->set_name(TTR("Materials"));1737material_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1738data_mode->add_child(material_tree);1739material_tree->connect("cell_selected", callable_mp(this, &SceneImportSettingsDialog::_material_tree_selected));17401741material_tree->set_hide_root(true);17421743VBoxContainer *vp_vb = memnew(VBoxContainer);1744vp_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);1745vp_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);1746vp_vb->set_anchors_and_offsets_preset(Control::LayoutPreset::PRESET_FULL_RECT);1747property_split->add_child(vp_vb);17481749SubViewportContainer *vp_container = memnew(SubViewportContainer);1750vp_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);1751vp_container->set_custom_minimum_size(Size2(10, 10));1752vp_container->set_stretch(true);1753vp_container->connect(SceneStringName(gui_input), callable_mp(this, &SceneImportSettingsDialog::_viewport_input));1754vp_vb->add_child(vp_container);17551756base_viewport = memnew(SubViewport);1757vp_container->add_child(base_viewport);17581759animation_preview = memnew(PanelContainer);1760animation_preview->set_h_size_flags(Control::SIZE_EXPAND_FILL);1761vp_vb->add_child(animation_preview);1762animation_preview->hide();17631764HBoxContainer *animation_hbox = memnew(HBoxContainer);1765animation_preview->add_child(animation_hbox);17661767animation_play_button = memnew(Button);1768animation_hbox->add_child(animation_play_button);1769animation_play_button->set_flat(true);1770animation_play_button->set_accessibility_name(TTRC("Selected Animation Play/Pause"));1771animation_play_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1772animation_play_button->set_shortcut(ED_SHORTCUT("scene_import_settings/play_selected_animation", TTRC("Selected Animation Play/Pause"), Key::SPACE));1773animation_play_button->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_play_animation));17741775animation_stop_button = memnew(Button);1776animation_hbox->add_child(animation_stop_button);1777animation_stop_button->set_flat(true);1778animation_stop_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1779animation_stop_button->set_tooltip_text(TTR("Selected Animation Stop"));1780animation_stop_button->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_stop_current_animation));17811782animation_slider = memnew(HSlider);1783animation_hbox->add_child(animation_slider);1784animation_slider->set_h_size_flags(Control::SIZE_EXPAND_FILL);1785animation_slider->set_v_size_flags(Control::SIZE_EXPAND_FILL);1786animation_slider->set_max(1.0);1787animation_slider->set_step(1.0 / 100.0);1788animation_slider->set_value_no_signal(0.0);1789animation_slider->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1790animation_slider->set_accessibility_name(TTRC("Animation"));1791animation_slider->connect(SceneStringName(value_changed), callable_mp(this, &SceneImportSettingsDialog::_animation_slider_value_changed));17921793animation_toggle_skeleton_visibility = memnew(Button);1794animation_hbox->add_child(animation_toggle_skeleton_visibility);1795animation_toggle_skeleton_visibility->set_toggle_mode(true);1796animation_toggle_skeleton_visibility->set_theme_type_variation("FlatButton");1797animation_toggle_skeleton_visibility->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1798animation_toggle_skeleton_visibility->set_tooltip_text(TTR("Toggle Animation Skeleton Visibility"));17991800animation_toggle_skeleton_visibility->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_animation_update_skeleton_visibility));18011802base_viewport->set_use_own_world_3d(true);18031804HBoxContainer *viewport_hbox = memnew(HBoxContainer);1805vp_container->add_child(viewport_hbox);1806viewport_hbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);18071808viewport_hbox->add_spacer();18091810VBoxContainer *vb_light = memnew(VBoxContainer);1811vb_light->set_v_size_flags(Control::SIZE_EXPAND_FILL);1812viewport_hbox->add_child(vb_light);18131814light_rotate_switch = memnew(Button);1815light_rotate_switch->set_theme_type_variation("PreviewLightButton");1816light_rotate_switch->set_toggle_mode(true);1817light_rotate_switch->set_pressed(true);1818light_rotate_switch->set_tooltip_text(TTR("Rotate Lights With Model"));1819light_rotate_switch->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_on_light_rotate_switch_pressed));1820vb_light->add_child(light_rotate_switch);18211822light_1_switch = memnew(Button);1823light_1_switch->set_theme_type_variation("PreviewLightButton");1824light_1_switch->set_toggle_mode(true);1825light_1_switch->set_pressed(true);1826light_1_switch->set_tooltip_text(TTR("Primary Light"));1827light_1_switch->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_on_light_1_switch_pressed));1828vb_light->add_child(light_1_switch);18291830light_2_switch = memnew(Button);1831light_2_switch->set_theme_type_variation("PreviewLightButton");1832light_2_switch->set_toggle_mode(true);1833light_2_switch->set_pressed(true);1834light_2_switch->set_tooltip_text(TTR("Secondary Light"));1835light_2_switch->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_on_light_2_switch_pressed));1836vb_light->add_child(light_2_switch);18371838camera = memnew(Camera3D);1839base_viewport->add_child(camera);1840camera->make_current();18411842if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {1843camera_attributes.instantiate();1844camera->set_attributes(camera_attributes);1845}18461847// Use a grayscale gradient sky to avoid skewing the preview towards a specific color,1848// but still allow shaded areas to be easily distinguished (using the ambient and reflected light).1849// This also helps the user orient themselves in the preview, since the bottom of the sky is black1850// and the top of the sky is white.1851procedural_sky_material.instantiate();1852procedural_sky_material->set_sky_top_color(Color(1, 1, 1));1853procedural_sky_material->set_sky_horizon_color(Color(0.5, 0.5, 0.5));1854procedural_sky_material->set_ground_horizon_color(Color(0.5, 0.5, 0.5));1855procedural_sky_material->set_ground_bottom_color(Color(0, 0, 0));1856procedural_sky_material->set_sky_curve(2.0);1857procedural_sky_material->set_ground_curve(0.5);1858// Hide the sun from the sky.1859procedural_sky_material->set_sun_angle_max(0.0);1860sky.instantiate();1861sky->set_material(procedural_sky_material);1862environment.instantiate();1863environment->set_background(Environment::BG_SKY);1864environment->set_sky(sky);1865// A custom FOV must be specified, as an orthogonal camera is used for the preview.1866environment->set_sky_custom_fov(50.0);1867camera->set_environment(environment);18681869light1 = memnew(DirectionalLight3D);1870light1->set_transform(Transform3D(Basis::looking_at(Vector3(-1, -1, -1))));1871light1->set_shadow(true);1872camera->add_child(light1);18731874light2 = memnew(DirectionalLight3D);1875light2->set_transform(Transform3D(Basis::looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))));1876light2->set_color(Color(0.5f, 0.5f, 0.5f));1877camera->add_child(light2);18781879{1880Ref<StandardMaterial3D> selection_mat;1881selection_mat.instantiate();1882selection_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);1883selection_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);1884selection_mat->set_albedo(Color(1, 0.8, 1.0));18851886Ref<SurfaceTool> st;1887st.instantiate();1888st->begin(Mesh::PRIMITIVE_LINES);18891890AABB base_aabb;1891base_aabb.size = Vector3(1, 1, 1);18921893for (int i = 0; i < 12; i++) {1894Vector3 a, b;1895base_aabb.get_edge(i, a, b);18961897st->add_vertex(a);1898st->add_vertex(a.lerp(b, 0.2));1899st->add_vertex(b);1900st->add_vertex(b.lerp(a, 0.2));1901}19021903selection_mesh.instantiate();1904st->commit(selection_mesh);1905selection_mesh->surface_set_material(0, selection_mat);19061907node_selected = memnew(MeshInstance3D);1908node_selected->set_mesh(selection_mesh);1909node_selected->set_cast_shadows_setting(GeometryInstance3D::SHADOW_CASTING_SETTING_OFF);1910base_viewport->add_child(node_selected);1911node_selected->hide();1912}19131914{1915mesh_preview = memnew(MeshInstance3D);1916base_viewport->add_child(mesh_preview);1917mesh_preview->hide();19181919material_preview.instantiate();1920}19211922{1923collider_mat.instantiate();1924collider_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);1925collider_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);1926collider_mat->set_albedo(Color(0.5, 0.5, 1.0));1927}19281929{1930bones_mesh_preview = memnew(MeshInstance3D);1931bones_mesh_preview->set_cast_shadows_setting(GeometryInstance3D::SHADOW_CASTING_SETTING_OFF);1932bones_mesh_preview->set_skeleton_path(NodePath());1933base_viewport->add_child(bones_mesh_preview);1934}19351936inspector = memnew(EditorInspector);1937inspector->set_custom_minimum_size(Size2(300 * EDSCALE, 0));1938inspector->connect(SNAME("property_edited"), callable_mp(this, &SceneImportSettingsDialog::_inspector_property_edited));1939// Display the same tooltips as in the Import dock.1940inspector->set_object_class(ResourceImporterScene::get_class_static());1941inspector->set_use_doc_hints(true);1942inspector->set_theme_type_variation(SNAME("EditorInspectorForeground"));19431944property_split->add_child(inspector);19451946scene_import_settings_data = memnew(SceneImportSettingsData);19471948set_ok_button_text(TTR("Reimport"));1949set_cancel_button_text(TTR("Close"));19501951external_paths = memnew(ConfirmationDialog);1952add_child(external_paths);1953external_path_tree = memnew(Tree);1954external_paths->add_child(external_path_tree);1955external_path_tree->connect("button_clicked", callable_mp(this, &SceneImportSettingsDialog::_browse_save_callback));1956external_paths->connect(SceneStringName(confirmed), callable_mp(this, &SceneImportSettingsDialog::_save_dir_confirm));1957external_path_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1958external_path_tree->set_columns(3);1959external_path_tree->set_column_titles_visible(true);1960external_path_tree->set_column_expand(0, true);1961external_path_tree->set_column_custom_minimum_width(0, 100 * EDSCALE);1962external_path_tree->set_column_title(0, TTR("Resource"));1963external_path_tree->set_column_expand(1, true);1964external_path_tree->set_column_custom_minimum_width(1, 100 * EDSCALE);1965external_path_tree->set_column_title(1, TTR("Path"));1966external_path_tree->set_column_expand(2, false);1967external_path_tree->set_column_custom_minimum_width(2, 200 * EDSCALE);1968external_path_tree->set_column_title(2, TTR("Status"));1969save_path = memnew(EditorFileDialog);1970save_path->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);1971HBoxContainer *extension_hb = memnew(HBoxContainer);1972save_path->get_vbox()->add_child(extension_hb);1973extension_hb->add_spacer();1974extension_hb->add_child(memnew(Label(TTR("Save Extension:"))));1975external_extension_type = memnew(OptionButton);1976extension_hb->add_child(external_extension_type);1977external_extension_type->add_item(TTR("Text: *.tres"));1978external_extension_type->add_item(TTR("Binary: *.res"));1979external_path_tree->set_hide_root(true);1980add_child(save_path);19811982item_save_path = memnew(EditorFileDialog);1983item_save_path->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);1984item_save_path->add_filter("*.tres", TTR("Text Resource"));1985item_save_path->add_filter("*.res", TTR("Binary Resource"));1986add_child(item_save_path);1987item_save_path->connect("file_selected", callable_mp(this, &SceneImportSettingsDialog::_save_path_changed));19881989save_path->connect("dir_selected", callable_mp(this, &SceneImportSettingsDialog::_save_dir_callback));19901991update_view_timer = memnew(Timer);1992update_view_timer->set_wait_time(0.2);1993update_view_timer->set_one_shot(true);1994update_view_timer->connect("timeout", callable_mp(this, &SceneImportSettingsDialog::_update_view_gizmos));1995add_child(update_view_timer);1996}19971998SceneImportSettingsDialog::~SceneImportSettingsDialog() {1999memdelete(scene_import_settings_data);2000memdelete(_resource_importer_scene);2001}200220032004