Path: blob/master/editor/import/3d/scene_import_settings.cpp
9903 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/animation/animation_player.h"43#include "scene/gui/subviewport_container.h"44#include "scene/resources/3d/importer_mesh.h"45#include "scene/resources/surface_tool.h"4647class SceneImportSettingsData : public Object {48GDCLASS(SceneImportSettingsData, Object)49friend class SceneImportSettingsDialog;50HashMap<StringName, Variant> *settings = nullptr;51HashMap<StringName, Variant> current;52HashMap<StringName, Variant> defaults;53List<ResourceImporter::ImportOption> options;54Vector<String> animation_list;5556bool hide_options = false;57String path;5859ResourceImporterScene::InternalImportCategory category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;6061bool _set(const StringName &p_name, const Variant &p_value) {62if (settings) {63if (defaults.has(p_name) && defaults[p_name] == p_value) {64settings->erase(p_name);65} else {66(*settings)[p_name] = p_value;67}6869current[p_name] = p_value;7071// SceneImportSettings must decide if a new collider should be generated or not.72if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE) {73SceneImportSettingsDialog::get_singleton()->request_generate_collider();74}7576if (SceneImportSettingsDialog::get_singleton()->is_editing_animation()) {77if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {78if (ResourceImporterScene::get_animation_singleton()->get_option_visibility(path, p_name, current)) {79SceneImportSettingsDialog::get_singleton()->update_view();80}81} else {82if (ResourceImporterScene::get_animation_singleton()->get_internal_option_update_view_required(category, p_name, current)) {83SceneImportSettingsDialog::get_singleton()->update_view();84}85}86} else {87if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {88if (ResourceImporterScene::get_scene_singleton()->get_option_visibility(path, p_name, current)) {89SceneImportSettingsDialog::get_singleton()->update_view();90}91} else {92if (ResourceImporterScene::get_scene_singleton()->get_internal_option_update_view_required(category, p_name, current)) {93SceneImportSettingsDialog::get_singleton()->update_view();94}95}96}9798return true;99}100return false;101}102103bool _get(const StringName &p_name, Variant &r_ret) const {104if (settings) {105if (settings->has(p_name)) {106r_ret = (*settings)[p_name];107return true;108}109}110if (defaults.has(p_name)) {111r_ret = defaults[p_name];112return true;113}114return false;115}116117void handle_special_properties(PropertyInfo &r_option) const {118ERR_FAIL_NULL(settings);119if (r_option.name == "rest_pose/load_pose") {120if (!settings->has("rest_pose/load_pose") || int((*settings)["rest_pose/load_pose"]) != 2) {121if (settings->has("rest_pose/external_animation_library")) {122(*settings)["rest_pose/external_animation_library"] = Variant();123}124}125}126if (r_option.name == "rest_pose/selected_animation") {127if (!settings->has("rest_pose/load_pose")) {128return;129}130String hint_string;131132switch (int((*settings)["rest_pose/load_pose"])) {133case 1: {134hint_string = String(",").join(animation_list);135if (animation_list.size() == 1) {136(*settings)["rest_pose/selected_animation"] = animation_list[0];137}138} break;139case 2: {140Object *res = nullptr;141if (settings->has("rest_pose/external_animation_library")) {142res = (*settings)["rest_pose/external_animation_library"];143}144Ref<Animation> anim(res);145Ref<AnimationLibrary> library(res);146if (anim.is_valid()) {147hint_string = anim->get_name();148}149if (library.is_valid()) {150List<StringName> anim_names;151library->get_animation_list(&anim_names);152if (anim_names.size() == 1) {153(*settings)["rest_pose/selected_animation"] = String(anim_names.front()->get());154}155for (StringName anim_name : anim_names) {156hint_string += "," + anim_name; // Include preceding, as a catch-all.157}158}159} break;160default:161break;162}163r_option.hint = PROPERTY_HINT_ENUM;164r_option.hint_string = hint_string;165}166}167168void _get_property_list(List<PropertyInfo> *r_list) const {169if (hide_options) {170return;171}172for (const ResourceImporter::ImportOption &E : options) {173PropertyInfo option = E.option;174if (SceneImportSettingsDialog::get_singleton()->is_editing_animation()) {175if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {176if (ResourceImporterScene::get_animation_singleton()->get_option_visibility(path, E.option.name, current)) {177handle_special_properties(option);178r_list->push_back(option);179}180} else {181if (ResourceImporterScene::get_animation_singleton()->get_internal_option_visibility(category, E.option.name, current)) {182handle_special_properties(option);183r_list->push_back(option);184}185}186} else {187if (category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {188if (ResourceImporterScene::get_scene_singleton()->get_option_visibility(path, E.option.name, current)) {189handle_special_properties(option);190r_list->push_back(option);191}192} else {193if (ResourceImporterScene::get_scene_singleton()->get_internal_option_visibility(category, E.option.name, current)) {194handle_special_properties(option);195r_list->push_back(option);196}197}198}199}200}201};202203bool SceneImportSettingsDialog::_get_current(const StringName &p_name, Variant &r_ret) const {204if (scene_import_settings_data->_get(p_name, r_ret)) {205return true;206}207if (defaults.has(p_name)) {208r_ret = defaults[p_name];209return true;210}211return false;212}213214void SceneImportSettingsDialog::_set_default(const StringName &p_name, const Variant &p_value) {215defaults[p_name] = p_value;216scene_import_settings_data->defaults[p_name] = p_value;217scene_import_settings_data->_set(p_name, p_value);218}219220void SceneImportSettingsDialog::_fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent) {221String import_id;222bool has_import_id = false;223224if (p_material->has_meta("import_id")) {225import_id = p_material->get_meta("import_id");226has_import_id = true;227} else if (!p_material->get_name().is_empty()) {228import_id = p_material->get_name();229has_import_id = true;230} else if (unnamed_material_name_map.has(p_material)) {231import_id = unnamed_material_name_map[p_material];232} else {233import_id = "@MATERIAL:" + itos(material_map.size());234unnamed_material_name_map[p_material] = import_id;235}236237bool created = false;238if (!material_map.has(import_id)) {239MaterialData md;240created = true;241md.has_import_id = has_import_id;242md.material = p_material;243244_load_default_subresource_settings(md.settings, "materials", import_id, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MATERIAL);245246material_map[import_id] = md;247}248249MaterialData &material_data = material_map[import_id];250ERR_FAIL_COND(p_material != material_data.material);251252Variant value;253if (_get_current("materials/extract", value) && (int)value != 0) {254String spath = base_path.get_base_dir();255if (_get_current("materials/extract_path", value)) {256String extpath = value;257if (!extpath.is_empty()) {258spath = extpath;259}260}261262String ext = ResourceImporterScene::material_extension[_get_current("materials/extract_format", value) ? (int)value : 0];263String path = spath.path_join(import_id.validate_filename() + ext);264String uid_path = ResourceUID::path_to_uid(path);265material_data.settings["use_external/enabled"] = true;266material_data.settings["use_external/path"] = uid_path;267material_data.settings["use_external/fallback_path"] = path;268}269270Ref<Texture2D> icon = get_editor_theme_icon(SNAME("StandardMaterial3D"));271272TreeItem *item = p_tree->create_item(p_parent);273if (p_material->get_name().is_empty()) {274item->set_text(0, TTR("<Unnamed Material>"));275} else {276item->set_text(0, p_material->get_name());277}278item->set_icon(0, icon);279280item->set_meta("type", "Material");281item->set_meta("import_id", import_id);282item->set_tooltip_text(0, vformat(TTR("Import ID: %s"), import_id));283item->set_selectable(0, true);284285if (p_tree == scene_tree) {286material_data.scene_node = item;287} else if (p_tree == mesh_tree) {288material_data.mesh_node = item;289} else {290material_data.material_node = item;291}292293if (created) {294_fill_material(material_tree, p_material, material_tree->get_root());295}296}297298void SceneImportSettingsDialog::_fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent) {299String import_id;300301bool has_import_id = false;302if (p_mesh->has_meta("import_id")) {303import_id = p_mesh->get_meta("import_id");304has_import_id = true;305} else if (!p_mesh->get_name().is_empty()) {306import_id = p_mesh->get_name();307has_import_id = true;308} else {309import_id = "@MESH:" + itos(mesh_set.size());310}311312if (!mesh_map.has(import_id)) {313MeshData md;314md.has_import_id = has_import_id;315md.mesh = p_mesh;316317_load_default_subresource_settings(md.settings, "meshes", import_id, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH);318319mesh_map[import_id] = md;320}321322MeshData &mesh_data = mesh_map[import_id];323324Ref<Texture2D> icon = get_editor_theme_icon(SNAME("MeshItem"));325326TreeItem *item = p_tree->create_item(p_parent);327item->set_text(0, p_mesh->get_name());328item->set_icon(0, icon);329330bool created = false;331if (!mesh_set.has(p_mesh)) {332mesh_set.insert(p_mesh);333created = true;334}335336item->set_meta("type", "Mesh");337item->set_meta("import_id", import_id);338item->set_tooltip_text(0, vformat(TTR("Import ID: %s"), import_id));339340item->set_selectable(0, true);341342if (p_tree == scene_tree) {343mesh_data.scene_node = item;344} else {345mesh_data.mesh_node = item;346}347348item->set_collapsed(true);349350for (int i = 0; i < p_mesh->get_surface_count(); i++) {351Ref<Material> mat = p_mesh->surface_get_material(i);352if (mat.is_valid()) {353_fill_material(p_tree, mat, item);354}355}356357if (created) {358_fill_mesh(mesh_tree, p_mesh, mesh_tree->get_root());359}360}361362void SceneImportSettingsDialog::_fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent) {363if (!animation_map.has(p_name)) {364AnimationData ad;365ad.animation = p_anim;366367_load_default_subresource_settings(ad.settings, "animations", p_name, ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION);368369animation_map[p_name] = ad;370}371372AnimationData &animation_data = animation_map[p_name];373374Ref<Texture2D> icon = get_editor_theme_icon(SNAME("Animation"));375376TreeItem *item = p_tree->create_item(p_parent);377item->set_text(0, p_name);378item->set_icon(0, icon);379380item->set_meta("type", "Animation");381item->set_meta("import_id", p_name);382383item->set_selectable(0, true);384385animation_data.scene_node = item;386}387388void SceneImportSettingsDialog::_fill_scene(Node *p_node, TreeItem *p_parent_item) {389String import_id;390391if (p_node->has_meta("import_id")) {392import_id = p_node->get_meta("import_id");393} else {394import_id = "PATH:" + String(scene->get_path_to(p_node));395p_node->set_meta("import_id", import_id);396}397398ImporterMeshInstance3D *src_mesh_node = Object::cast_to<ImporterMeshInstance3D>(p_node);399400if (src_mesh_node) {401MeshInstance3D *mesh_node = memnew(MeshInstance3D);402mesh_node->set_name(src_mesh_node->get_name());403mesh_node->set_transform(src_mesh_node->get_transform());404mesh_node->set_skin(src_mesh_node->get_skin());405mesh_node->set_skeleton_path(src_mesh_node->get_skeleton_path());406mesh_node->set_visible(src_mesh_node->is_visible());407if (src_mesh_node->get_mesh().is_valid()) {408Ref<ImporterMesh> editor_mesh = src_mesh_node->get_mesh();409mesh_node->set_mesh(editor_mesh->get_mesh());410}411// Replace the original mesh node in the scene tree with the new one.412if (unlikely(p_node == scene)) {413scene = mesh_node;414}415p_node->replace_by(mesh_node);416memdelete(p_node);417p_node = mesh_node;418}419420String type = p_node->get_class();421422if (!has_theme_icon(type, EditorStringName(EditorIcons))) {423type = "Node3D";424}425426Ref<Texture2D> icon = get_editor_theme_icon(type);427428TreeItem *item = scene_tree->create_item(p_parent_item);429item->set_text(0, p_node->get_name());430431if (p_node == scene) {432icon = get_editor_theme_icon(SNAME("PackedScene"));433item->set_text(0, TTR("Scene"));434}435436item->set_icon(0, icon);437438item->set_meta("type", "Node");439item->set_meta("class", type);440item->set_meta("import_id", import_id);441item->set_tooltip_text(0, vformat(TTR("Type: %s\nImport ID: %s"), type, import_id));442443item->set_selectable(0, true);444445if (!node_map.has(import_id)) {446NodeData nd;447448if (p_node != scene) {449ResourceImporterScene::InternalImportCategory category;450if (src_mesh_node) {451category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;452} else if (Object::cast_to<AnimationPlayer>(p_node)) {453category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;454455animation_player = Object::cast_to<AnimationPlayer>(p_node);456animation_player->connect(SceneStringName(animation_finished), callable_mp(this, &SceneImportSettingsDialog::_animation_finished));457} else if (Object::cast_to<Skeleton3D>(p_node)) {458category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE;459Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);460skeleton->connect(SceneStringName(tree_entered), callable_mp(this, &SceneImportSettingsDialog::_skeleton_tree_entered).bind(skeleton));461skeletons.push_back(skeleton);462} else {463category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;464}465466_load_default_subresource_settings(nd.settings, "nodes", import_id, category);467}468469node_map[import_id] = nd;470}471NodeData &node_data = node_map[import_id];472473node_data.node = p_node;474node_data.scene_node = item;475476AnimationPlayer *anim_node = Object::cast_to<AnimationPlayer>(p_node);477if (anim_node) {478Vector<String> animation_list;479List<StringName> animations;480anim_node->get_animation_list(&animations);481for (const StringName &E : animations) {482_fill_animation(scene_tree, anim_node->get_animation(E), E, item);483animation_list.append(E);484}485if (scene_import_settings_data != nullptr) {486scene_import_settings_data->animation_list = animation_list;487}488}489490for (int i = 0; i < p_node->get_child_count(); i++) {491_fill_scene(p_node->get_child(i), item);492}493MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(p_node);494if (mesh_node && mesh_node->get_mesh().is_valid()) {495if (!editing_animation) {496_fill_mesh(scene_tree, mesh_node->get_mesh(), item);497}498499// Add the collider view.500MeshInstance3D *collider_view = memnew(MeshInstance3D);501collider_view->set_name("collider_view");502collider_view->set_visible(false);503mesh_node->add_child(collider_view, true);504collider_view->set_owner(mesh_node);505506Transform3D accum_xform;507Node3D *base = mesh_node;508while (base) {509accum_xform = base->get_transform() * accum_xform;510base = Object::cast_to<Node3D>(base->get_parent());511}512513AABB aabb = accum_xform.xform(mesh_node->get_mesh()->get_aabb());514515if (first_aabb) {516contents_aabb = aabb;517first_aabb = false;518} else {519contents_aabb.merge_with(aabb);520}521}522523Skeleton3D *skeleton = Object::cast_to<Skeleton3D>(p_node);524if (skeleton) {525Ref<ArrayMesh> bones_mesh = Skeleton3DGizmoPlugin::get_bones_mesh(skeleton, -1, true);526527bones_mesh_preview->set_mesh(bones_mesh);528529Transform3D accum_xform;530Node3D *base = skeleton;531while (base) {532accum_xform = base->get_transform() * accum_xform;533base = Object::cast_to<Node3D>(base->get_parent());534}535536bones_mesh_preview->set_transform(accum_xform * skeleton->get_transform());537538AABB aabb = accum_xform.xform(bones_mesh->get_aabb());539540if (first_aabb) {541contents_aabb = aabb;542first_aabb = false;543} else {544contents_aabb.merge_with(aabb);545}546}547}548549void SceneImportSettingsDialog::_update_scene() {550scene_tree->clear();551material_tree->clear();552mesh_tree->clear();553554// Hidden roots.555material_tree->create_item();556mesh_tree->create_item();557558_fill_scene(scene, nullptr);559}560561void SceneImportSettingsDialog::_update_view_gizmos() {562if (!is_visible()) {563return;564}565const HashMap<StringName, Variant> &main_settings = scene_import_settings_data->current;566bool reshow_settings = false;567if (main_settings.has("nodes/import_as_skeleton_bones")) {568bool new_import_as_skeleton = main_settings["nodes/import_as_skeleton_bones"];569reshow_settings = reshow_settings || (new_import_as_skeleton != previous_import_as_skeleton);570previous_import_as_skeleton = new_import_as_skeleton;571}572if (main_settings.has("animation/import_rest_as_RESET")) {573bool new_rest_as_reset = main_settings["animation/import_rest_as_RESET"];574reshow_settings = reshow_settings || (new_rest_as_reset != previous_rest_as_reset);575previous_rest_as_reset = new_rest_as_reset;576}577if (reshow_settings) {578_re_import();579open_settings(base_path);580return;581}582for (const KeyValue<String, NodeData> &e : node_map) {583// Skip import nodes that aren't MeshInstance3D.584const MeshInstance3D *mesh_node = Object::cast_to<MeshInstance3D>(e.value.node);585if (mesh_node == nullptr || mesh_node->get_mesh().is_null()) {586continue;587}588589// Determine if the mesh collider should be visible.590bool show_collider_view = false;591if (e.value.settings.has(SNAME("generate/physics"))) {592show_collider_view = e.value.settings[SNAME("generate/physics")];593}594595// Get the collider_view MeshInstance3D.596TypedArray<Node> descendants = mesh_node->find_children("collider_view", "MeshInstance3D");597CRASH_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`.");598MeshInstance3D *collider_view = Object::cast_to<MeshInstance3D>(descendants[0].operator Object *());599600// Regenerate the physics collider for this MeshInstance3D if either:601// - A regeneration is requested for the selected import node.602// - The collider is being made visible.603if ((generate_collider && e.key == selected_id) || (show_collider_view && !collider_view->is_visible())) {604// This collider_view doesn't have a mesh so we need to generate a new one.605Ref<ImporterMesh> mesh;606mesh.instantiate();607// ResourceImporterScene::get_collision_shapes() expects ImporterMesh, not Mesh.608// TODO: Duplicate code with EditorSceneFormatImporterESCN::import_scene()609// Consider making a utility function to convert from Mesh to ImporterMesh.610Ref<Mesh> mesh_3d_mesh = mesh_node->get_mesh();611Ref<ArrayMesh> array_mesh_3d_mesh = mesh_3d_mesh;612if (array_mesh_3d_mesh.is_valid()) {613// For the MeshInstance3D nodes, we need to convert the ArrayMesh to an ImporterMesh specially.614mesh->set_name(array_mesh_3d_mesh->get_name());615for (int32_t blend_i = 0; blend_i < array_mesh_3d_mesh->get_blend_shape_count(); blend_i++) {616mesh->add_blend_shape(array_mesh_3d_mesh->get_blend_shape_name(blend_i));617}618for (int32_t surface_i = 0; surface_i < array_mesh_3d_mesh->get_surface_count(); surface_i++) {619mesh->add_surface(array_mesh_3d_mesh->surface_get_primitive_type(surface_i),620array_mesh_3d_mesh->surface_get_arrays(surface_i),621array_mesh_3d_mesh->surface_get_blend_shape_arrays(surface_i),622array_mesh_3d_mesh->surface_get_lods(surface_i),623array_mesh_3d_mesh->surface_get_material(surface_i),624array_mesh_3d_mesh->surface_get_name(surface_i),625array_mesh_3d_mesh->surface_get_format(surface_i));626}627mesh->set_blend_shape_mode(array_mesh_3d_mesh->get_blend_shape_mode());628} else if (mesh_3d_mesh.is_valid()) {629// For the MeshInstance3D nodes, we need to convert the Mesh to an ImporterMesh specially.630mesh->set_name(mesh_3d_mesh->get_name());631for (int32_t surface_i = 0; surface_i < mesh_3d_mesh->get_surface_count(); surface_i++) {632mesh->add_surface(mesh_3d_mesh->surface_get_primitive_type(surface_i),633mesh_3d_mesh->surface_get_arrays(surface_i),634Array(),635mesh_3d_mesh->surface_get_lods(surface_i),636mesh_3d_mesh->surface_get_material(surface_i),637mesh_3d_mesh->surface_get_material(surface_i).is_valid() ? mesh_3d_mesh->surface_get_material(surface_i)->get_name() : String(),638mesh_3d_mesh->surface_get_format(surface_i));639}640}641642// Generate the mesh collider.643Vector<Ref<Shape3D>> shapes = ResourceImporterScene::get_collision_shapes(mesh, e.value.settings, 1.0);644const Transform3D transform = ResourceImporterScene::get_collision_shapes_transform(e.value.settings);645646Ref<ArrayMesh> collider_view_mesh;647collider_view_mesh.instantiate();648for (Ref<Shape3D> shape : shapes) {649Ref<ArrayMesh> debug_shape_mesh;650if (shape.is_valid()) {651debug_shape_mesh = shape->get_debug_mesh();652}653if (debug_shape_mesh.is_valid()) {654collider_view_mesh->add_surface_from_arrays(655debug_shape_mesh->surface_get_primitive_type(0),656debug_shape_mesh->surface_get_arrays(0));657658collider_view_mesh->surface_set_material(659collider_view_mesh->get_surface_count() - 1,660collider_mat);661}662}663664collider_view->set_mesh(collider_view_mesh);665collider_view->set_transform(transform);666}667668// Set the collider visibility.669collider_view->set_visible(show_collider_view);670}671672generate_collider = false;673}674675void SceneImportSettingsDialog::_update_camera() {676AABB camera_aabb;677678float rot_x = cam_rot_x;679float rot_y = cam_rot_y;680float zoom = cam_zoom;681682if (selected_type == "Node" || selected_type == "Animation" || selected_type.is_empty()) {683camera_aabb = contents_aabb;684} else {685if (mesh_preview->get_mesh().is_valid()) {686camera_aabb = mesh_preview->get_transform().xform(mesh_preview->get_mesh()->get_aabb());687} else {688camera_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));689}690if (selected_type == "Mesh" && mesh_map.has(selected_id)) {691const MeshData &md = mesh_map[selected_id];692rot_x = md.cam_rot_x;693rot_y = md.cam_rot_y;694zoom = md.cam_zoom;695} else if (selected_type == "Material" && material_map.has(selected_id)) {696const MaterialData &md = material_map[selected_id];697rot_x = md.cam_rot_x;698rot_y = md.cam_rot_y;699zoom = md.cam_zoom;700}701}702703Vector3 center = camera_aabb.get_center();704float camera_size = camera_aabb.get_longest_axis_size();705706camera->set_orthogonal(camera_size * zoom, 0.0001, camera_size * 2);707708Transform3D xf;709xf.basis = Basis(Vector3(0, 1, 0), rot_y) * Basis(Vector3(1, 0, 0), rot_x);710xf.origin = center;711xf.translate_local(0, 0, camera_size);712713camera->set_transform(xf);714}715716void SceneImportSettingsDialog::_load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category) {717if (base_subresource_settings.has(p_type)) {718Dictionary d = base_subresource_settings[p_type];719if (d.has(p_import_id)) {720d = d[p_import_id];721List<ResourceImporterScene::ImportOption> options;722if (editing_animation) {723ResourceImporterScene::get_animation_singleton()->get_internal_import_options(p_category, &options);724} else {725ResourceImporterScene::get_scene_singleton()->get_internal_import_options(p_category, &options);726}727for (const ResourceImporterScene::ImportOption &E : options) {728String key = E.option.name;729if (d.has(key)) {730settings[key] = d[key];731}732}733}734}735}736737void SceneImportSettingsDialog::request_generate_collider() {738generate_collider = true;739}740741void SceneImportSettingsDialog::update_view() {742update_view_timer->start();743}744745void SceneImportSettingsDialog::open_settings(const String &p_path, const String &p_scene_import_type) {746if (scene) {747_cleanup();748memdelete(scene);749scene = nullptr;750}751752editing_animation = p_scene_import_type == "AnimationLibrary";753scene_import_settings_data->settings = nullptr;754scene_import_settings_data->path = p_path;755756// Visibility.757data_mode->set_tab_hidden(1, editing_animation);758data_mode->set_tab_hidden(2, editing_animation);759if (editing_animation) {760data_mode->set_current_tab(0);761}762763action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_EXTRACT_MATERIALS), editing_animation);764action_menu->get_popup()->set_item_disabled(action_menu->get_popup()->get_item_id(ACTION_CHOOSE_MESH_SAVE_PATHS), editing_animation);765766base_path = p_path;767768mesh_set.clear();769animation_map.clear();770material_map.clear();771unnamed_material_name_map.clear();772mesh_map.clear();773node_map.clear();774defaults.clear();775776mesh_preview->hide();777778selected_id = "";779selected_type = "";780781cam_rot_x = -Math::PI / 4;782cam_rot_y = -Math::PI / 4;783cam_zoom = 1;784785{786base_subresource_settings.clear();787788Ref<ConfigFile> config;789config.instantiate();790Error err = config->load(p_path + ".import");791if (err == OK) {792Vector<String> keys = config->get_section_keys("params");793for (const String &E : keys) {794Variant value = config->get_value("params", E);795if (E == "_subresources") {796base_subresource_settings = value;797} else {798defaults[E] = value;799}800}801}802}803804scene = ResourceImporterScene::get_scene_singleton()->pre_import(p_path, defaults); // Use the scene singleton here because we want to see the full thing.805if (scene == nullptr) {806EditorNode::get_singleton()->show_warning(TTR("Error opening scene"));807return;808}809810first_aabb = true;811812_update_scene();813814base_viewport->add_child(scene);815816inspector->edit(nullptr);817818if (first_aabb) {819contents_aabb = AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));820first_aabb = false;821}822823const HashMap<StringName, Variant> &main_settings = scene_import_settings_data->current;824if (main_settings.has("nodes/import_as_skeleton_bones")) {825previous_import_as_skeleton = main_settings["nodes/import_as_skeleton_bones"];826}827if (main_settings.has("animation/import_rest_as_RESET")) {828previous_rest_as_reset = main_settings["animation/import_rest_as_RESET"];829}830popup_centered_ratio();831_update_view_gizmos();832_update_camera();833834// Start with the root item (Scene) selected.835scene_tree->get_root()->select(0);836837if (editing_animation) {838set_title(vformat(TTR("Advanced Import Settings for AnimationLibrary '%s'"), base_path.get_file()));839} else {840set_title(vformat(TTR("Advanced Import Settings for Scene '%s'"), base_path.get_file()));841}842}843844SceneImportSettingsDialog *SceneImportSettingsDialog::singleton = nullptr;845846SceneImportSettingsDialog *SceneImportSettingsDialog::get_singleton() {847return singleton;848}849850Node *SceneImportSettingsDialog::get_selected_node() {851if (selected_id == "") {852return nullptr;853}854return node_map[selected_id].node;855}856857void SceneImportSettingsDialog::_select(Tree *p_from, const String &p_type, const String &p_id) {858selecting = true;859scene_import_settings_data->hide_options = false;860861bones_mesh_preview->hide();862if (p_type == "Node") {863node_selected->hide(); // Always hide just in case.864mesh_preview->hide();865_reset_animation();866867if (Object::cast_to<Node3D>(scene)) {868Object::cast_to<Node3D>(scene)->show();869}870material_tree->deselect_all();871mesh_tree->deselect_all();872NodeData &nd = node_map[p_id];873874MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(nd.node);875if (mi) {876Ref<Mesh> base_mesh = mi->get_mesh();877if (base_mesh.is_valid()) {878AABB aabb = base_mesh->get_aabb();879Transform3D aabb_xf;880aabb_xf.basis.scale(aabb.size);881aabb_xf.origin = aabb.position;882883aabb_xf = mi->get_global_transform() * aabb_xf;884node_selected->set_transform(aabb_xf);885node_selected->show();886}887}888889if (nd.node == scene) {890scene_import_settings_data->settings = &defaults;891scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX;892} else {893scene_import_settings_data->settings = &nd.settings;894if (mi) {895scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MESH_3D_NODE;896scene_import_settings_data->hide_options = editing_animation;897} else if (Object::cast_to<AnimationPlayer>(nd.node)) {898scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION_NODE;899} else if (Object::cast_to<Skeleton3D>(nd.node)) {900scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_SKELETON_3D_NODE;901bones_mesh_preview->show();902} else {903scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_NODE;904scene_import_settings_data->hide_options = editing_animation;905}906}907} else if (p_type == "Animation") {908node_selected->hide(); // Always hide just in case.909mesh_preview->hide();910_reset_animation(p_id);911912if (Object::cast_to<Node3D>(scene)) {913Object::cast_to<Node3D>(scene)->show();914}915material_tree->deselect_all();916mesh_tree->deselect_all();917AnimationData &ad = animation_map[p_id];918919scene_import_settings_data->settings = &ad.settings;920scene_import_settings_data->category = ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_ANIMATION;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 (editing_animation) {995if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {996ResourceImporterScene::get_animation_singleton()->get_import_options(base_path, &options);997} else {998ResourceImporterScene::get_animation_singleton()->get_internal_import_options(scene_import_settings_data->category, &options);999}10001001} else {1002if (scene_import_settings_data->category == ResourceImporterScene::INTERNAL_IMPORT_CATEGORY_MAX) {1003ResourceImporterScene::get_scene_singleton()->get_import_options(base_path, &options);1004} else {1005ResourceImporterScene::get_scene_singleton()->get_internal_import_options(scene_import_settings_data->category, &options);1006}1007}10081009scene_import_settings_data->defaults.clear();1010scene_import_settings_data->current.clear();10111012if (scene_import_settings_data->settings) {1013for (const ResourceImporter::ImportOption &E : options) {1014scene_import_settings_data->defaults[E.option.name] = E.default_value;1015// Needed for visibility toggling (fails if something is missing).1016if (scene_import_settings_data->settings->has(E.option.name)) {1017scene_import_settings_data->current[E.option.name] = (*scene_import_settings_data->settings)[E.option.name];1018} else {1019scene_import_settings_data->current[E.option.name] = E.default_value;1020}1021}1022}10231024scene_import_settings_data->options = options;1025inspector->edit(scene_import_settings_data);1026scene_import_settings_data->notify_property_list_changed();1027}10281029void SceneImportSettingsDialog::_inspector_property_edited(const String &p_name) {1030if (p_name == "settings/loop_mode") {1031if (!animation_map.has(selected_id)) {1032return;1033}1034HashMap<StringName, Variant> settings = animation_map[selected_id].settings;1035if (settings.has(p_name)) {1036animation_loop_mode = static_cast<Animation::LoopMode>((int)settings[p_name]);1037} else {1038animation_loop_mode = Animation::LoopMode::LOOP_NONE;1039}1040}1041if ((p_name == "use_external/enabled") || (p_name == "use_external/path") || (p_name == "use_external/fallback_path")) {1042MaterialData &material_data = material_map[selected_id];1043String spath = base_path.get_base_dir();1044Variant value;1045if (_get_current("materials/extract_path", value)) {1046String extpath = value;1047if (!extpath.is_empty()) {1048spath = extpath;1049}1050}1051String opath = material_data.settings.has("use_external/path") ? (String)material_data.settings["use_external/path"] : String();1052if (opath.begins_with("uid://")) {1053opath = ResourceUID::uid_to_path(opath);1054}1055String ext = ResourceImporterScene::material_extension[_get_current("materials/extract_format", value) ? (int)value : 0];1056String npath = spath.path_join(selected_id.validate_filename() + ext);10571058if (!material_data.settings.has("use_external/enabled") || (bool)material_data.settings["use_external/enabled"] == false || opath != npath) {1059if (_get_current("materials/extract", value) && (int)value != 0) {1060print_line("Material settings changed, automatic material extraction disabled.");1061}1062_set_default("materials/extract", 0);1063}1064}1065}10661067void SceneImportSettingsDialog::_reset_bone_transforms() {1068for (Skeleton3D *skeleton : skeletons) {1069skeleton->reset_bone_poses();1070}1071}10721073void SceneImportSettingsDialog::_play_animation() {1074if (animation_player == nullptr) {1075return;1076}1077StringName id = StringName(selected_id);1078if (animation_player->has_animation(id)) {1079if (animation_player->is_playing()) {1080animation_player->pause();1081animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1082set_process(false);1083} else {1084animation_player->play(id);1085animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));1086set_process(true);1087}1088}1089}10901091void SceneImportSettingsDialog::_stop_current_animation() {1092animation_pingpong = false;1093animation_player->stop();1094animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1095animation_slider->set_value_no_signal(0.0);1096set_process(false);1097}10981099void SceneImportSettingsDialog::_reset_animation(const String &p_animation_name) {1100if (p_animation_name.is_empty()) {1101animation_preview->hide();11021103if (animation_player != nullptr && animation_player->is_playing()) {1104animation_player->stop();1105}1106animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));11071108_reset_bone_transforms();1109set_process(false);1110} else {1111_reset_bone_transforms();1112animation_preview->show();11131114animation_loop_mode = Animation::LoopMode::LOOP_NONE;1115animation_pingpong = false;11161117if (animation_map.has(p_animation_name)) {1118HashMap<StringName, Variant> settings = animation_map[p_animation_name].settings;1119if (settings.has("settings/loop_mode")) {1120animation_loop_mode = static_cast<Animation::LoopMode>((int)settings["settings/loop_mode"]);1121}1122}11231124if (animation_player->is_playing() && animation_loop_mode != Animation::LoopMode::LOOP_NONE) {1125animation_player->play(p_animation_name);1126} else {1127animation_player->stop(true);1128animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1129animation_player->set_assigned_animation(p_animation_name);1130animation_player->seek(0.0, true);1131animation_slider->set_value_no_signal(0.0);1132set_process(false);1133}1134}1135}11361137void SceneImportSettingsDialog::_animation_slider_value_changed(double p_value) {1138if (animation_player == nullptr || !animation_map.has(selected_id) || animation_map[selected_id].animation.is_null()) {1139return;1140}1141if (animation_player->is_playing()) {1142animation_player->stop();1143animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1144set_process(false);1145}1146animation_player->seek(p_value * animation_map[selected_id].animation->get_length(), true);1147}11481149void SceneImportSettingsDialog::_skeleton_tree_entered(Skeleton3D *p_skeleton) {1150bones_mesh_preview->set_skeleton_path(p_skeleton->get_path());1151bones_mesh_preview->set_skin(p_skeleton->register_skin(p_skeleton->create_skin_from_rest_transforms()));1152}11531154void SceneImportSettingsDialog::_animation_finished(const StringName &p_name) {1155Animation::LoopMode loop_mode = animation_loop_mode;11561157switch (loop_mode) {1158case Animation::LOOP_NONE: {1159animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1160animation_slider->set_value_no_signal(1.0);1161set_process(false);1162} break;1163case Animation::LOOP_LINEAR: {1164animation_player->play(p_name);1165} break;1166case Animation::LOOP_PINGPONG: {1167if (animation_pingpong) {1168animation_player->play(p_name);1169} else {1170animation_player->play_backwards(p_name);1171}1172animation_pingpong = !animation_pingpong;1173} break;1174default: {1175} break;1176}1177}11781179void SceneImportSettingsDialog::_animation_update_skeleton_visibility() {1180if (animation_toggle_skeleton_visibility->is_pressed()) {1181bones_mesh_preview->show();1182} else {1183bones_mesh_preview->hide();1184}1185}11861187void SceneImportSettingsDialog::_material_tree_selected() {1188if (selecting) {1189return;1190}1191TreeItem *item = material_tree->get_selected();1192String type = item->get_meta("type");1193String import_id = item->get_meta("import_id");11941195_select(material_tree, type, import_id);1196}11971198void SceneImportSettingsDialog::_mesh_tree_selected() {1199if (selecting) {1200return;1201}12021203TreeItem *item = mesh_tree->get_selected();1204String type = item->get_meta("type");1205String import_id = item->get_meta("import_id");12061207_select(mesh_tree, type, import_id);1208}12091210void SceneImportSettingsDialog::_scene_tree_selected() {1211if (selecting) {1212return;1213}1214TreeItem *item = scene_tree->get_selected();1215String type = item->get_meta("type");1216String import_id = item->get_meta("import_id");12171218_select(scene_tree, type, import_id);1219}12201221void SceneImportSettingsDialog::_cleanup() {1222skeletons.clear();1223if (animation_player != nullptr) {1224animation_player->disconnect(SceneStringName(animation_finished), callable_mp(this, &SceneImportSettingsDialog::_animation_finished));1225animation_player = nullptr;1226}1227set_process(false);1228}12291230void SceneImportSettingsDialog::_on_light_1_switch_pressed() {1231light1->set_visible(light_1_switch->is_pressed());1232}12331234void SceneImportSettingsDialog::_on_light_2_switch_pressed() {1235light2->set_visible(light_2_switch->is_pressed());1236}12371238void SceneImportSettingsDialog::_on_light_rotate_switch_pressed() {1239bool light_top_level = !light_rotate_switch->is_pressed();1240light1->set_as_top_level_keep_local(light_top_level);1241light2->set_as_top_level_keep_local(light_top_level);1242}12431244void SceneImportSettingsDialog::_viewport_input(const Ref<InputEvent> &p_input) {1245float *rot_x = &cam_rot_x;1246float *rot_y = &cam_rot_y;1247float *zoom = &cam_zoom;12481249if (selected_type == "Mesh" && mesh_map.has(selected_id)) {1250MeshData &md = mesh_map[selected_id];1251rot_x = &md.cam_rot_x;1252rot_y = &md.cam_rot_y;1253zoom = &md.cam_zoom;1254} else if (selected_type == "Material" && material_map.has(selected_id)) {1255MaterialData &md = material_map[selected_id];1256rot_x = &md.cam_rot_x;1257rot_y = &md.cam_rot_y;1258zoom = &md.cam_zoom;1259}1260Ref<InputEventMouseMotion> mm = p_input;1261if (mm.is_valid() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {1262(*rot_x) -= mm->get_relative().y * 0.01 * EDSCALE;1263(*rot_y) -= mm->get_relative().x * 0.01 * EDSCALE;1264(*rot_x) = CLAMP((*rot_x), -Math::PI / 2, Math::PI / 2);1265_update_camera();1266}1267if (mm.is_valid() && DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_CURSOR_SHAPE)) {1268DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CursorShape::CURSOR_ARROW);1269}1270Ref<InputEventMouseButton> mb = p_input;1271if (mb.is_valid() && mb->get_button_index() == MouseButton::WHEEL_DOWN) {1272(*zoom) *= 1.1;1273if ((*zoom) > 10.0) {1274(*zoom) = 10.0;1275}1276_update_camera();1277}1278if (mb.is_valid() && mb->get_button_index() == MouseButton::WHEEL_UP) {1279(*zoom) /= 1.1;1280if ((*zoom) < 0.1) {1281(*zoom) = 0.1;1282}1283_update_camera();1284}1285Ref<InputEventMagnifyGesture> mg = p_input;1286if (mg.is_valid()) {1287real_t mg_factor = mg->get_factor();1288if (mg_factor == 0.0) {1289mg_factor = 1.0;1290}1291(*zoom) /= mg_factor;1292if ((*zoom) < 0.1) {1293(*zoom) = 0.1;1294} else if ((*zoom) > 10.0) {1295(*zoom) = 10.0;1296}1297_update_camera();1298}1299}13001301void SceneImportSettingsDialog::_re_import() {1302HashMap<StringName, Variant> main_settings;13031304main_settings = scene_import_settings_data->current;1305main_settings.erase("_subresources");1306Dictionary nodes;1307Dictionary materials;1308Dictionary meshes;1309Dictionary animations;13101311Dictionary subresources;13121313for (KeyValue<String, NodeData> &E : node_map) {1314if (E.value.settings.size()) {1315Dictionary d;1316for (const KeyValue<StringName, Variant> &F : E.value.settings) {1317d[String(F.key)] = F.value;1318}1319nodes[E.key] = d;1320}1321}1322if (nodes.size()) {1323subresources["nodes"] = nodes;1324}13251326for (KeyValue<String, MaterialData> &E : material_map) {1327if (E.value.settings.size()) {1328Dictionary d;1329for (const KeyValue<StringName, Variant> &F : E.value.settings) {1330d[String(F.key)] = F.value;1331}1332materials[E.key] = d;1333}1334}1335if (materials.size()) {1336subresources["materials"] = materials;1337}13381339for (KeyValue<String, MeshData> &E : mesh_map) {1340if (E.value.settings.size()) {1341Dictionary d;1342for (const KeyValue<StringName, Variant> &F : E.value.settings) {1343d[String(F.key)] = F.value;1344}1345meshes[E.key] = d;1346}1347}1348if (meshes.size()) {1349subresources["meshes"] = meshes;1350}13511352for (KeyValue<String, AnimationData> &E : animation_map) {1353if (E.value.settings.size()) {1354Dictionary d;1355for (const KeyValue<StringName, Variant> &F : E.value.settings) {1356d[String(F.key)] = F.value;1357}1358animations[E.key] = d;1359}1360}1361if (animations.size()) {1362subresources["animations"] = animations;1363}13641365main_settings["_subresources"] = subresources;13661367_cleanup(); // Prevent skeletons and other pointers from pointing to dangling references.1368EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, editing_animation ? "animation_library" : "scene", main_settings);1369}13701371void SceneImportSettingsDialog::_update_theme_item_cache() {1372ConfirmationDialog::_update_theme_item_cache();1373theme_cache.light_1_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight1"));1374theme_cache.light_2_icon = get_editor_theme_icon(SNAME("MaterialPreviewLight2"));1375theme_cache.rotate_icon = get_editor_theme_icon(SNAME("PreviewRotate"));1376}13771378void SceneImportSettingsDialog::_notification(int p_what) {1379switch (p_what) {1380case NOTIFICATION_READY: {1381connect(SceneStringName(confirmed), callable_mp(this, &SceneImportSettingsDialog::_re_import));1382} break;13831384case NOTIFICATION_THEME_CHANGED: {1385action_menu->begin_bulk_theme_override();1386action_menu->add_theme_style_override(CoreStringName(normal), get_theme_stylebox(CoreStringName(normal), "Button"));1387action_menu->add_theme_style_override(SceneStringName(hover), get_theme_stylebox(SceneStringName(hover), "Button"));1388action_menu->add_theme_style_override(SceneStringName(pressed), get_theme_stylebox(SceneStringName(pressed), "Button"));1389action_menu->end_bulk_theme_override();13901391if (animation_player != nullptr && animation_player->is_playing()) {1392animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("Pause")));1393} else {1394animation_play_button->set_button_icon(get_editor_theme_icon(SNAME("MainPlay")));1395}1396animation_stop_button->set_button_icon(get_editor_theme_icon(SNAME("Stop")));13971398light_1_switch->set_button_icon(theme_cache.light_1_icon);1399light_2_switch->set_button_icon(theme_cache.light_2_icon);1400light_rotate_switch->set_button_icon(theme_cache.rotate_icon);14011402animation_toggle_skeleton_visibility->set_button_icon(get_editor_theme_icon(SNAME("SkeletonPreview")));1403} break;14041405case NOTIFICATION_PROCESS: {1406if (animation_player != nullptr) {1407animation_slider->set_value_no_signal(animation_player->get_current_animation_position() / animation_player->get_current_animation_length());1408}1409} break;14101411case NOTIFICATION_VISIBILITY_CHANGED: {1412if (!is_visible()) {1413_cleanup();1414}1415} break;1416}1417}14181419void SceneImportSettingsDialog::_menu_callback(int p_id) {1420switch (p_id) {1421case ACTION_EXTRACT_MATERIALS: {1422save_path->set_title(TTR("Select folder to extract material resources"));1423external_extension_type->select(0);1424} break;1425case ACTION_CHOOSE_MESH_SAVE_PATHS: {1426save_path->set_title(TTR("Select folder where mesh resources will save on import"));1427external_extension_type->select(1);1428} break;1429case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {1430save_path->set_title(TTR("Select folder where animations will save on import"));1431external_extension_type->select(1);1432} break;1433}14341435save_path->set_current_dir(base_path.get_base_dir());1436current_action = p_id;1437save_path->popup_centered_ratio();1438}14391440void SceneImportSettingsDialog::_save_path_changed(const String &p_path) {1441save_path_item->set_text(1, p_path);14421443if (FileAccess::exists(p_path)) {1444save_path_item->set_text(2, TTR("Warning: File exists"));1445save_path_item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced."));1446save_path_item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));14471448} else {1449save_path_item->set_text(2, TTR("Will create new file"));1450save_path_item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1451}1452}14531454void SceneImportSettingsDialog::_browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button) {1455if (p_button != MouseButton::LEFT) {1456return;1457}14581459TreeItem *item = Object::cast_to<TreeItem>(p_item);14601461String path = item->get_text(1);14621463item_save_path->set_current_file(path);1464save_path_item = item;14651466item_save_path->popup_centered_ratio();1467}14681469void SceneImportSettingsDialog::_save_dir_callback(const String &p_path) {1470external_path_tree->clear();1471TreeItem *root = external_path_tree->create_item();1472save_path_items.clear();14731474switch (current_action) {1475case ACTION_EXTRACT_MATERIALS: {1476for (const KeyValue<String, MaterialData> &E : material_map) {1477MaterialData &md = material_map[E.key];14781479TreeItem *item = external_path_tree->create_item(root);14801481String name = md.material_node->get_text(0);14821483item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);1484item->set_icon(0, get_editor_theme_icon(SNAME("StandardMaterial3D")));1485item->set_text(0, name);14861487if (md.has_import_id) {1488if (md.settings.has("use_external/enabled") && bool(md.settings["use_external/enabled"])) {1489item->set_text(2, TTR("Already External"));1490item->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."));1491} else {1492item->set_metadata(0, E.key);1493item->set_editable(0, true);1494item->set_checked(0, true);1495name = name.validate_filename();1496String path = p_path.path_join(name);1497if (external_extension_type->get_selected() == 0) {1498path += ".tres";1499} else {1500path += ".res";1501}15021503item->set_text(1, path);1504if (FileAccess::exists(path)) {1505item->set_text(2, TTR("Warning: File exists"));1506item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced."));1507item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));15081509} else {1510item->set_text(2, TTR("Will create new file"));1511item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1512}15131514item->add_button(1, get_editor_theme_icon(SNAME("Folder")));1515}15161517} else {1518item->set_text(2, TTR("No import ID"));1519item->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."));1520item->set_icon(2, get_editor_theme_icon(SNAME("StatusError")));1521}15221523save_path_items.push_back(item);1524}15251526external_paths->set_title(TTR("Extract Materials to Resource Files"));1527external_paths->set_ok_button_text(TTR("Extract"));1528} break;1529case ACTION_CHOOSE_MESH_SAVE_PATHS: {1530for (const KeyValue<String, MeshData> &E : mesh_map) {1531MeshData &md = mesh_map[E.key];15321533TreeItem *item = external_path_tree->create_item(root);15341535String name = md.mesh_node->get_text(0);15361537item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);1538item->set_icon(0, get_editor_theme_icon(SNAME("MeshItem")));1539item->set_text(0, name);15401541if (md.has_import_id) {1542if (md.settings.has("save_to_file/enabled") && bool(md.settings["save_to_file/enabled"])) {1543item->set_text(2, TTR("Already Saving"));1544item->set_tooltip_text(2, TTR("This mesh already saves to an external resource, no action will be taken."));1545} else {1546item->set_metadata(0, E.key);1547item->set_editable(0, true);1548item->set_checked(0, true);1549name = name.validate_filename();1550String path = p_path.path_join(name);1551if (external_extension_type->get_selected() == 0) {1552path += ".tres";1553} else {1554path += ".res";1555}15561557item->set_text(1, path);1558if (FileAccess::exists(path)) {1559item->set_text(2, TTR("Warning: File exists"));1560item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced on import."));1561item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));15621563} else {1564item->set_text(2, TTR("Will save to new file"));1565item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1566}15671568item->add_button(1, get_editor_theme_icon(SNAME("Folder")));1569}15701571} else {1572item->set_text(2, TTR("No import ID"));1573item->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."));1574item->set_icon(2, get_editor_theme_icon(SNAME("StatusError")));1575}15761577save_path_items.push_back(item);1578}15791580external_paths->set_title(TTR("Set paths to save meshes as resource files on Reimport"));1581external_paths->set_ok_button_text(TTR("Set Paths"));1582} break;1583case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {1584for (const KeyValue<String, AnimationData> &E : animation_map) {1585AnimationData &ad = animation_map[E.key];15861587TreeItem *item = external_path_tree->create_item(root);15881589String name = ad.scene_node->get_text(0);15901591item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);1592item->set_icon(0, get_editor_theme_icon(SNAME("Animation")));1593item->set_text(0, name);15941595if (ad.settings.has("save_to_file/enabled") && bool(ad.settings["save_to_file/enabled"])) {1596item->set_text(2, TTR("Already Saving"));1597item->set_tooltip_text(2, TTR("This animation already saves to an external resource, no action will be taken."));1598} else {1599item->set_metadata(0, E.key);1600item->set_editable(0, true);1601item->set_checked(0, true);1602name = name.validate_filename();1603String path = p_path.path_join(name);1604if (external_extension_type->get_selected() == 0) {1605path += ".tres";1606} else {1607path += ".res";1608}16091610item->set_text(1, path);1611if (FileAccess::exists(path)) {1612item->set_text(2, TTR("Warning: File exists"));1613item->set_tooltip_text(2, TTR("Existing file with the same name will be replaced on import."));1614item->set_icon(2, get_editor_theme_icon(SNAME("StatusWarning")));16151616} else {1617item->set_text(2, TTR("Will save to new file"));1618item->set_icon(2, get_editor_theme_icon(SNAME("StatusSuccess")));1619}16201621item->add_button(1, get_editor_theme_icon(SNAME("Folder")));1622}16231624save_path_items.push_back(item);1625}16261627external_paths->set_title(TTR("Set paths to save animations as resource files on Reimport"));1628external_paths->set_ok_button_text(TTR("Set Paths"));16291630} break;1631}16321633external_paths->popup_centered_ratio();1634}16351636void SceneImportSettingsDialog::_save_dir_confirm() {1637for (int i = 0; i < save_path_items.size(); i++) {1638TreeItem *item = save_path_items[i];1639if (!item->is_checked(0)) {1640continue; //ignore1641}1642String path = item->get_text(1);1643String uid_path = path;1644if (path.begins_with("uid://")) {1645path = ResourceUID::uid_to_path(uid_path);1646}1647if (!path.is_resource_file()) {1648continue;1649}16501651String id = item->get_metadata(0);16521653switch (current_action) {1654case ACTION_EXTRACT_MATERIALS: {1655ERR_CONTINUE(!material_map.has(id));1656MaterialData &md = material_map[id];16571658Error err = ResourceSaver::save(md.material, path);1659if (err != OK) {1660EditorNode::get_singleton()->add_io_error(TTR("Can't make material external to file, write error:") + "\n\t" + path);1661continue;1662}1663uid_path = ResourceUID::path_to_uid(path);16641665md.settings["use_external/enabled"] = true;1666md.settings["use_external/path"] = uid_path;1667md.settings["use_external/fallback_path"] = path;16681669} break;1670case ACTION_CHOOSE_MESH_SAVE_PATHS: {1671ERR_CONTINUE(!mesh_map.has(id));1672MeshData &md = mesh_map[id];16731674md.settings["save_to_file/enabled"] = true;1675md.settings["save_to_file/path"] = uid_path;1676md.settings["save_to_file/fallback_path"] = path;1677} break;1678case ACTION_CHOOSE_ANIMATION_SAVE_PATHS: {1679ERR_CONTINUE(!animation_map.has(id));1680AnimationData &ad = animation_map[id];16811682ad.settings["save_to_file/enabled"] = true;1683ad.settings["save_to_file/path"] = uid_path;1684ad.settings["save_to_file/fallback_path"] = path;16851686} break;1687}1688}16891690if (current_action == ACTION_EXTRACT_MATERIALS) {1691//as this happens right now, the scene needs to be saved and reimported.1692_re_import();1693open_settings(base_path);1694} else {1695scene_import_settings_data->notify_property_list_changed();1696}1697}16981699SceneImportSettingsDialog::SceneImportSettingsDialog() {1700singleton = this;17011702VBoxContainer *main_vb = memnew(VBoxContainer);1703add_child(main_vb);1704HBoxContainer *menu_hb = memnew(HBoxContainer);1705main_vb->add_child(menu_hb);17061707action_menu = memnew(MenuButton);1708action_menu->set_text(TTR("Actions..."));1709// Style the MenuButton like a regular Button to make it more noticeable.1710action_menu->set_flat(false);1711action_menu->set_focus_mode(Control::FOCUS_ALL);1712menu_hb->add_child(action_menu);17131714action_menu->get_popup()->add_item(TTR("Extract Materials"), ACTION_EXTRACT_MATERIALS);1715action_menu->get_popup()->add_separator();1716action_menu->get_popup()->add_item(TTR("Set Animation Save Paths"), ACTION_CHOOSE_ANIMATION_SAVE_PATHS);1717action_menu->get_popup()->add_item(TTR("Set Mesh Save Paths"), ACTION_CHOOSE_MESH_SAVE_PATHS);17181719action_menu->get_popup()->connect(SceneStringName(id_pressed), callable_mp(this, &SceneImportSettingsDialog::_menu_callback));17201721tree_split = memnew(HSplitContainer);1722main_vb->add_child(tree_split);1723tree_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);17241725data_mode = memnew(TabContainer);1726tree_split->add_child(data_mode);1727data_mode->set_custom_minimum_size(Size2(300 * EDSCALE, 0));1728data_mode->set_theme_type_variation("TabContainerOdd");17291730property_split = memnew(HSplitContainer);1731tree_split->add_child(property_split);1732property_split->set_h_size_flags(Control::SIZE_EXPAND_FILL);17331734scene_tree = memnew(Tree);1735scene_tree->set_name(TTR("Scene"));1736scene_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1737data_mode->add_child(scene_tree);1738scene_tree->connect("cell_selected", callable_mp(this, &SceneImportSettingsDialog::_scene_tree_selected));17391740mesh_tree = memnew(Tree);1741mesh_tree->set_name(TTR("Meshes"));1742mesh_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1743data_mode->add_child(mesh_tree);1744mesh_tree->set_hide_root(true);1745mesh_tree->connect("cell_selected", callable_mp(this, &SceneImportSettingsDialog::_mesh_tree_selected));17461747material_tree = memnew(Tree);1748material_tree->set_name(TTR("Materials"));1749material_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1750data_mode->add_child(material_tree);1751material_tree->connect("cell_selected", callable_mp(this, &SceneImportSettingsDialog::_material_tree_selected));17521753material_tree->set_hide_root(true);17541755VBoxContainer *vp_vb = memnew(VBoxContainer);1756vp_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);1757vp_vb->set_v_size_flags(Control::SIZE_EXPAND_FILL);1758vp_vb->set_anchors_and_offsets_preset(Control::LayoutPreset::PRESET_FULL_RECT);1759property_split->add_child(vp_vb);17601761SubViewportContainer *vp_container = memnew(SubViewportContainer);1762vp_container->set_v_size_flags(Control::SIZE_EXPAND_FILL);1763vp_container->set_custom_minimum_size(Size2(10, 10));1764vp_container->set_stretch(true);1765vp_container->connect(SceneStringName(gui_input), callable_mp(this, &SceneImportSettingsDialog::_viewport_input));1766vp_vb->add_child(vp_container);17671768base_viewport = memnew(SubViewport);1769vp_container->add_child(base_viewport);17701771animation_preview = memnew(PanelContainer);1772animation_preview->set_h_size_flags(Control::SIZE_EXPAND_FILL);1773vp_vb->add_child(animation_preview);1774animation_preview->hide();17751776HBoxContainer *animation_hbox = memnew(HBoxContainer);1777animation_preview->add_child(animation_hbox);17781779animation_play_button = memnew(Button);1780animation_hbox->add_child(animation_play_button);1781animation_play_button->set_flat(true);1782animation_play_button->set_accessibility_name(TTRC("Selected Animation Play/Pause"));1783animation_play_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1784animation_play_button->set_shortcut(ED_SHORTCUT("scene_import_settings/play_selected_animation", TTRC("Selected Animation Play/Pause"), Key::SPACE));1785animation_play_button->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_play_animation));17861787animation_stop_button = memnew(Button);1788animation_hbox->add_child(animation_stop_button);1789animation_stop_button->set_flat(true);1790animation_stop_button->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1791animation_stop_button->set_tooltip_text(TTR("Selected Animation Stop"));1792animation_stop_button->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_stop_current_animation));17931794animation_slider = memnew(HSlider);1795animation_hbox->add_child(animation_slider);1796animation_slider->set_h_size_flags(Control::SIZE_EXPAND_FILL);1797animation_slider->set_v_size_flags(Control::SIZE_EXPAND_FILL);1798animation_slider->set_max(1.0);1799animation_slider->set_step(1.0 / 100.0);1800animation_slider->set_value_no_signal(0.0);1801animation_slider->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1802animation_slider->set_accessibility_name(TTRC("Animation"));1803animation_slider->connect(SceneStringName(value_changed), callable_mp(this, &SceneImportSettingsDialog::_animation_slider_value_changed));18041805animation_toggle_skeleton_visibility = memnew(Button);1806animation_hbox->add_child(animation_toggle_skeleton_visibility);1807animation_toggle_skeleton_visibility->set_toggle_mode(true);1808animation_toggle_skeleton_visibility->set_theme_type_variation("FlatButton");1809animation_toggle_skeleton_visibility->set_focus_mode(Control::FOCUS_ACCESSIBILITY);1810animation_toggle_skeleton_visibility->set_tooltip_text(TTR("Toggle Animation Skeleton Visibility"));18111812animation_toggle_skeleton_visibility->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_animation_update_skeleton_visibility));18131814base_viewport->set_use_own_world_3d(true);18151816HBoxContainer *viewport_hbox = memnew(HBoxContainer);1817vp_container->add_child(viewport_hbox);1818viewport_hbox->set_anchors_and_offsets_preset(Control::PRESET_FULL_RECT, Control::PRESET_MODE_MINSIZE, 2);18191820viewport_hbox->add_spacer();18211822VBoxContainer *vb_light = memnew(VBoxContainer);1823vb_light->set_v_size_flags(Control::SIZE_EXPAND_FILL);1824viewport_hbox->add_child(vb_light);18251826light_rotate_switch = memnew(Button);1827light_rotate_switch->set_theme_type_variation("PreviewLightButton");1828light_rotate_switch->set_toggle_mode(true);1829light_rotate_switch->set_pressed(true);1830light_rotate_switch->set_tooltip_text(TTR("Rotate Lights With Model"));1831light_rotate_switch->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_on_light_rotate_switch_pressed));1832vb_light->add_child(light_rotate_switch);18331834light_1_switch = memnew(Button);1835light_1_switch->set_theme_type_variation("PreviewLightButton");1836light_1_switch->set_toggle_mode(true);1837light_1_switch->set_pressed(true);1838light_1_switch->set_tooltip_text(TTR("Primary Light"));1839light_1_switch->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_on_light_1_switch_pressed));1840vb_light->add_child(light_1_switch);18411842light_2_switch = memnew(Button);1843light_2_switch->set_theme_type_variation("PreviewLightButton");1844light_2_switch->set_toggle_mode(true);1845light_2_switch->set_pressed(true);1846light_2_switch->set_tooltip_text(TTR("Secondary Light"));1847light_2_switch->connect(SceneStringName(pressed), callable_mp(this, &SceneImportSettingsDialog::_on_light_2_switch_pressed));1848vb_light->add_child(light_2_switch);18491850camera = memnew(Camera3D);1851base_viewport->add_child(camera);1852camera->make_current();18531854if (GLOBAL_GET("rendering/lights_and_shadows/use_physical_light_units")) {1855camera_attributes.instantiate();1856camera->set_attributes(camera_attributes);1857}18581859// Use a grayscale gradient sky to avoid skewing the preview towards a specific color,1860// but still allow shaded areas to be easily distinguished (using the ambient and reflected light).1861// This also helps the user orient themselves in the preview, since the bottom of the sky is black1862// and the top of the sky is white.1863procedural_sky_material.instantiate();1864procedural_sky_material->set_sky_top_color(Color(1, 1, 1));1865procedural_sky_material->set_sky_horizon_color(Color(0.5, 0.5, 0.5));1866procedural_sky_material->set_ground_horizon_color(Color(0.5, 0.5, 0.5));1867procedural_sky_material->set_ground_bottom_color(Color(0, 0, 0));1868procedural_sky_material->set_sky_curve(2.0);1869procedural_sky_material->set_ground_curve(0.5);1870// Hide the sun from the sky.1871procedural_sky_material->set_sun_angle_max(0.0);1872sky.instantiate();1873sky->set_material(procedural_sky_material);1874environment.instantiate();1875environment->set_background(Environment::BG_SKY);1876environment->set_sky(sky);1877// A custom FOV must be specified, as an orthogonal camera is used for the preview.1878environment->set_sky_custom_fov(50.0);1879camera->set_environment(environment);18801881light1 = memnew(DirectionalLight3D);1882light1->set_transform(Transform3D(Basis::looking_at(Vector3(-1, -1, -1))));1883light1->set_shadow(true);1884camera->add_child(light1);18851886light2 = memnew(DirectionalLight3D);1887light2->set_transform(Transform3D(Basis::looking_at(Vector3(0, 1, 0), Vector3(0, 0, 1))));1888light2->set_color(Color(0.5f, 0.5f, 0.5f));1889camera->add_child(light2);18901891{1892Ref<StandardMaterial3D> selection_mat;1893selection_mat.instantiate();1894selection_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);1895selection_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);1896selection_mat->set_albedo(Color(1, 0.8, 1.0));18971898Ref<SurfaceTool> st;1899st.instantiate();1900st->begin(Mesh::PRIMITIVE_LINES);19011902AABB base_aabb;1903base_aabb.size = Vector3(1, 1, 1);19041905for (int i = 0; i < 12; i++) {1906Vector3 a, b;1907base_aabb.get_edge(i, a, b);19081909st->add_vertex(a);1910st->add_vertex(a.lerp(b, 0.2));1911st->add_vertex(b);1912st->add_vertex(b.lerp(a, 0.2));1913}19141915selection_mesh.instantiate();1916st->commit(selection_mesh);1917selection_mesh->surface_set_material(0, selection_mat);19181919node_selected = memnew(MeshInstance3D);1920node_selected->set_mesh(selection_mesh);1921node_selected->set_cast_shadows_setting(GeometryInstance3D::SHADOW_CASTING_SETTING_OFF);1922base_viewport->add_child(node_selected);1923node_selected->hide();1924}19251926{1927mesh_preview = memnew(MeshInstance3D);1928base_viewport->add_child(mesh_preview);1929mesh_preview->hide();19301931material_preview.instantiate();1932}19331934{1935collider_mat.instantiate();1936collider_mat->set_shading_mode(StandardMaterial3D::SHADING_MODE_UNSHADED);1937collider_mat->set_flag(StandardMaterial3D::FLAG_DISABLE_FOG, true);1938collider_mat->set_albedo(Color(0.5, 0.5, 1.0));1939}19401941{1942bones_mesh_preview = memnew(MeshInstance3D);1943bones_mesh_preview->set_cast_shadows_setting(GeometryInstance3D::SHADOW_CASTING_SETTING_OFF);1944bones_mesh_preview->set_skeleton_path(NodePath());1945base_viewport->add_child(bones_mesh_preview);1946}19471948inspector = memnew(EditorInspector);1949inspector->set_custom_minimum_size(Size2(300 * EDSCALE, 0));1950inspector->connect(SNAME("property_edited"), callable_mp(this, &SceneImportSettingsDialog::_inspector_property_edited));1951// Display the same tooltips as in the Import dock.1952inspector->set_object_class(ResourceImporterScene::get_class_static());1953inspector->set_use_doc_hints(true);19541955property_split->add_child(inspector);19561957scene_import_settings_data = memnew(SceneImportSettingsData);19581959set_ok_button_text(TTR("Reimport"));1960set_cancel_button_text(TTR("Close"));19611962external_paths = memnew(ConfirmationDialog);1963add_child(external_paths);1964external_path_tree = memnew(Tree);1965external_paths->add_child(external_path_tree);1966external_path_tree->connect("button_clicked", callable_mp(this, &SceneImportSettingsDialog::_browse_save_callback));1967external_paths->connect(SceneStringName(confirmed), callable_mp(this, &SceneImportSettingsDialog::_save_dir_confirm));1968external_path_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);1969external_path_tree->set_columns(3);1970external_path_tree->set_column_titles_visible(true);1971external_path_tree->set_column_expand(0, true);1972external_path_tree->set_column_custom_minimum_width(0, 100 * EDSCALE);1973external_path_tree->set_column_title(0, TTR("Resource"));1974external_path_tree->set_column_expand(1, true);1975external_path_tree->set_column_custom_minimum_width(1, 100 * EDSCALE);1976external_path_tree->set_column_title(1, TTR("Path"));1977external_path_tree->set_column_expand(2, false);1978external_path_tree->set_column_custom_minimum_width(2, 200 * EDSCALE);1979external_path_tree->set_column_title(2, TTR("Status"));1980save_path = memnew(EditorFileDialog);1981save_path->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);1982HBoxContainer *extension_hb = memnew(HBoxContainer);1983save_path->get_vbox()->add_child(extension_hb);1984extension_hb->add_spacer();1985extension_hb->add_child(memnew(Label(TTR("Save Extension:"))));1986external_extension_type = memnew(OptionButton);1987extension_hb->add_child(external_extension_type);1988external_extension_type->add_item(TTR("Text: *.tres"));1989external_extension_type->add_item(TTR("Binary: *.res"));1990external_path_tree->set_hide_root(true);1991add_child(save_path);19921993item_save_path = memnew(EditorFileDialog);1994item_save_path->set_file_mode(EditorFileDialog::FILE_MODE_SAVE_FILE);1995item_save_path->add_filter("*.tres", TTR("Text Resource"));1996item_save_path->add_filter("*.res", TTR("Binary Resource"));1997add_child(item_save_path);1998item_save_path->connect("file_selected", callable_mp(this, &SceneImportSettingsDialog::_save_path_changed));19992000save_path->connect("dir_selected", callable_mp(this, &SceneImportSettingsDialog::_save_dir_callback));20012002update_view_timer = memnew(Timer);2003update_view_timer->set_wait_time(0.2);2004update_view_timer->set_one_shot(true);2005update_view_timer->connect("timeout", callable_mp(this, &SceneImportSettingsDialog::_update_view_gizmos));2006add_child(update_view_timer);2007}20082009SceneImportSettingsDialog::~SceneImportSettingsDialog() {2010memdelete(scene_import_settings_data);2011}201220132014