Path: blob/master/editor/import/3d/scene_import_settings.h
9903 views
/**************************************************************************/1/* scene_import_settings.h */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#pragma once3132#include "editor/import/3d/resource_importer_scene.h"33#include "scene/3d/camera_3d.h"34#include "scene/3d/light_3d.h"35#include "scene/3d/mesh_instance_3d.h"36#include "scene/3d/skeleton_3d.h"37#include "scene/gui/dialogs.h"38#include "scene/gui/menu_button.h"39#include "scene/gui/option_button.h"40#include "scene/gui/panel_container.h"41#include "scene/gui/slider.h"42#include "scene/gui/split_container.h"43#include "scene/gui/tab_container.h"44#include "scene/gui/tree.h"45#include "scene/resources/3d/primitive_meshes.h"46#include "scene/resources/3d/sky_material.h"4748class EditorFileDialog;49class EditorInspector;50class SceneImportSettingsData;5152class SceneImportSettingsDialog : public ConfirmationDialog {53GDCLASS(SceneImportSettingsDialog, ConfirmationDialog)5455static SceneImportSettingsDialog *singleton;5657enum Actions {58ACTION_EXTRACT_MATERIALS,59ACTION_CHOOSE_MESH_SAVE_PATHS,60ACTION_CHOOSE_ANIMATION_SAVE_PATHS,61};6263Node *scene = nullptr;6465HSplitContainer *tree_split = nullptr;66HSplitContainer *property_split = nullptr;67TabContainer *data_mode = nullptr;68Tree *scene_tree = nullptr;69Tree *mesh_tree = nullptr;70Tree *material_tree = nullptr;7172EditorInspector *inspector = nullptr;7374SubViewport *base_viewport = nullptr;7576Camera3D *camera = nullptr;77Ref<CameraAttributesPractical> camera_attributes;78Ref<Environment> environment;79Ref<Sky> sky;80Ref<ProceduralSkyMaterial> procedural_sky_material;81bool first_aabb = false;82AABB contents_aabb;8384Button *light_1_switch = nullptr;85Button *light_2_switch = nullptr;86Button *light_rotate_switch = nullptr;8788struct ThemeCache {89Ref<Texture2D> light_1_icon;90Ref<Texture2D> light_2_icon;91Ref<Texture2D> rotate_icon;92} theme_cache;9394DirectionalLight3D *light1 = nullptr;95DirectionalLight3D *light2 = nullptr;96Ref<ArrayMesh> selection_mesh;97MeshInstance3D *node_selected = nullptr;9899MeshInstance3D *mesh_preview = nullptr;100Ref<SphereMesh> material_preview;101102AnimationPlayer *animation_player = nullptr;103List<Skeleton3D *> skeletons;104PanelContainer *animation_preview = nullptr;105HSlider *animation_slider = nullptr;106Button *animation_play_button = nullptr;107Button *animation_stop_button = nullptr;108Button *animation_toggle_skeleton_visibility = nullptr;109Animation::LoopMode animation_loop_mode = Animation::LOOP_NONE;110bool animation_pingpong = false;111bool previous_import_as_skeleton = false;112bool previous_rest_as_reset = false;113MeshInstance3D *bones_mesh_preview = nullptr;114115Ref<StandardMaterial3D> collider_mat;116117float cam_rot_x = 0.0f;118float cam_rot_y = 0.0f;119float cam_zoom = 0.0f;120121void _update_scene();122123struct MaterialData {124bool has_import_id;125Ref<Material> material;126TreeItem *scene_node = nullptr;127TreeItem *mesh_node = nullptr;128TreeItem *material_node = nullptr;129130float cam_rot_x = -Math::PI / 4;131float cam_rot_y = -Math::PI / 4;132float cam_zoom = 1;133134HashMap<StringName, Variant> settings;135};136HashMap<String, MaterialData> material_map;137HashMap<Ref<Material>, String> unnamed_material_name_map;138139struct MeshData {140bool has_import_id;141Ref<Mesh> mesh;142TreeItem *scene_node = nullptr;143TreeItem *mesh_node = nullptr;144145float cam_rot_x = -Math::PI / 4;146float cam_rot_y = -Math::PI / 4;147float cam_zoom = 1;148HashMap<StringName, Variant> settings;149};150HashMap<String, MeshData> mesh_map;151152struct AnimationData {153Ref<Animation> animation;154TreeItem *scene_node = nullptr;155HashMap<StringName, Variant> settings;156};157HashMap<String, AnimationData> animation_map;158159struct NodeData {160Node *node = nullptr;161TreeItem *scene_node = nullptr;162HashMap<StringName, Variant> settings;163};164HashMap<String, NodeData> node_map;165166bool _get_current(const StringName &p_name, Variant &r_ret) const;167void _set_default(const StringName &p_name, const Variant &p_value);168void _fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent);169void _fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent);170void _fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent);171void _fill_scene(Node *p_node, TreeItem *p_parent_item);172173HashSet<Ref<Mesh>> mesh_set;174175String selected_type;176String selected_id;177178bool selecting = false;179180void _update_view_gizmos();181void _update_camera();182void _select(Tree *p_from, const String &p_type, const String &p_id);183void _inspector_property_edited(const String &p_name);184void _reset_bone_transforms();185void _play_animation();186void _stop_current_animation();187void _reset_animation(const String &p_animation_name = "");188void _animation_slider_value_changed(double p_value);189void _animation_finished(const StringName &p_name);190void _animation_update_skeleton_visibility();191void _material_tree_selected();192void _mesh_tree_selected();193void _scene_tree_selected();194void _skeleton_tree_entered(Skeleton3D *p_skeleton);195void _cleanup();196void _on_light_1_switch_pressed();197void _on_light_2_switch_pressed();198void _on_light_rotate_switch_pressed();199200void _viewport_input(const Ref<InputEvent> &p_input);201202HashMap<StringName, Variant> defaults;203204SceneImportSettingsData *scene_import_settings_data = nullptr;205206void _re_import();207208String base_path;209210MenuButton *action_menu = nullptr;211212ConfirmationDialog *external_paths = nullptr;213Tree *external_path_tree = nullptr;214EditorFileDialog *save_path = nullptr;215OptionButton *external_extension_type = nullptr;216217EditorFileDialog *item_save_path = nullptr;218219void _menu_callback(int p_id);220void _save_dir_callback(const String &p_path);221222int current_action = 0;223224Vector<TreeItem *> save_path_items;225226TreeItem *save_path_item = nullptr;227void _save_path_changed(const String &p_path);228void _browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button);229void _save_dir_confirm();230231Dictionary base_subresource_settings;232233void _load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);234235bool editing_animation = false;236bool generate_collider = false;237238Timer *update_view_timer = nullptr;239240protected:241virtual void _update_theme_item_cache() override;242void _notification(int p_what);243244public:245bool is_editing_animation() const { return editing_animation; }246void request_generate_collider();247void update_view();248void open_settings(const String &p_path, const String &p_scene_import_type = "PackedScene");249static SceneImportSettingsDialog *get_singleton();250Node *get_selected_node();251SceneImportSettingsDialog();252~SceneImportSettingsDialog();253};254255256