Path: blob/master/editor/import/3d/scene_import_settings.h
21679 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;51class Timer;5253class SceneImportSettingsDialog : public ConfirmationDialog {54GDCLASS(SceneImportSettingsDialog, ConfirmationDialog)5556static SceneImportSettingsDialog *singleton;5758enum Actions {59ACTION_EXTRACT_MATERIALS,60ACTION_CHOOSE_MESH_SAVE_PATHS,61ACTION_CHOOSE_ANIMATION_SAVE_PATHS,62};6364Node *scene = nullptr;6566HSplitContainer *tree_split = nullptr;67HSplitContainer *property_split = nullptr;68TabContainer *data_mode = nullptr;69Tree *scene_tree = nullptr;70Tree *mesh_tree = nullptr;71Tree *material_tree = nullptr;7273EditorInspector *inspector = nullptr;7475SubViewport *base_viewport = nullptr;7677Camera3D *camera = nullptr;78Ref<CameraAttributesPractical> camera_attributes;79Ref<Environment> environment;80Ref<Sky> sky;81Ref<ProceduralSkyMaterial> procedural_sky_material;82bool first_aabb = false;83AABB contents_aabb;8485Button *light_1_switch = nullptr;86Button *light_2_switch = nullptr;87Button *light_rotate_switch = nullptr;8889struct ThemeCache {90Ref<Texture2D> light_1_icon;91Ref<Texture2D> light_2_icon;92Ref<Texture2D> rotate_icon;93} theme_cache;9495DirectionalLight3D *light1 = nullptr;96DirectionalLight3D *light2 = nullptr;97Ref<ArrayMesh> selection_mesh;98MeshInstance3D *node_selected = nullptr;99100MeshInstance3D *mesh_preview = nullptr;101Ref<SphereMesh> material_preview;102103AnimationPlayer *animation_player = nullptr;104List<Skeleton3D *> skeletons;105PanelContainer *animation_preview = nullptr;106HSlider *animation_slider = nullptr;107Button *animation_play_button = nullptr;108Button *animation_stop_button = nullptr;109Button *animation_toggle_skeleton_visibility = nullptr;110Animation::LoopMode animation_loop_mode = Animation::LOOP_NONE;111bool animation_pingpong = false;112bool previous_import_as_skeleton = false;113bool previous_rest_as_reset = false;114MeshInstance3D *bones_mesh_preview = nullptr;115116Ref<StandardMaterial3D> collider_mat;117118float cam_rot_x = 0.0f;119float cam_rot_y = 0.0f;120float cam_zoom = 0.0f;121122void _update_scene();123124struct MaterialData {125bool has_import_id;126Ref<Material> material;127TreeItem *scene_node = nullptr;128TreeItem *mesh_node = nullptr;129TreeItem *material_node = nullptr;130131float cam_rot_x = -Math::PI / 4;132float cam_rot_y = -Math::PI / 4;133float cam_zoom = 1;134135HashMap<StringName, Variant> settings;136};137HashMap<String, MaterialData> material_map;138HashMap<Ref<Material>, String> unnamed_material_name_map;139140struct MeshData {141bool has_import_id;142Ref<Mesh> mesh;143TreeItem *scene_node = nullptr;144TreeItem *mesh_node = nullptr;145146float cam_rot_x = -Math::PI / 4;147float cam_rot_y = -Math::PI / 4;148float cam_zoom = 1;149HashMap<StringName, Variant> settings;150};151HashMap<String, MeshData> mesh_map;152153struct AnimationData {154Ref<Animation> animation;155TreeItem *scene_node = nullptr;156HashMap<StringName, Variant> settings;157};158HashMap<String, AnimationData> animation_map;159160struct NodeData {161Node *node = nullptr;162TreeItem *scene_node = nullptr;163HashMap<StringName, Variant> settings;164};165HashMap<String, NodeData> node_map;166167bool _get_current(const StringName &p_name, Variant &r_ret) const;168void _set_default(const StringName &p_name, const Variant &p_value);169void _fill_material(Tree *p_tree, const Ref<Material> &p_material, TreeItem *p_parent);170void _fill_mesh(Tree *p_tree, const Ref<Mesh> &p_mesh, TreeItem *p_parent);171void _fill_animation(Tree *p_tree, const Ref<Animation> &p_anim, const String &p_name, TreeItem *p_parent);172void _fill_scene(Node *p_node, TreeItem *p_parent_item);173174HashSet<Ref<Mesh>> mesh_set;175176String selected_type;177String selected_id;178179bool selecting = false;180181void _update_view_gizmos();182void _update_camera();183void _select(Tree *p_from, const String &p_type, const String &p_id);184void _inspector_property_edited(const String &p_name);185void _reset_bone_transforms();186void _play_animation();187void _stop_current_animation();188void _reset_animation(const String &p_animation_name = "");189void _animation_slider_value_changed(double p_value);190void _animation_finished(const StringName &p_name);191void _animation_update_skeleton_visibility();192void _material_tree_selected();193void _mesh_tree_selected();194void _scene_tree_selected();195void _skeleton_tree_entered(Skeleton3D *p_skeleton);196void _cleanup();197void _on_light_1_switch_pressed();198void _on_light_2_switch_pressed();199void _on_light_rotate_switch_pressed();200201void _viewport_input(const Ref<InputEvent> &p_input);202203HashMap<StringName, Variant> defaults;204205SceneImportSettingsData *scene_import_settings_data = nullptr;206ResourceImporterScene *_resource_importer_scene = nullptr;207208void _re_import();209void _project_settings_changed();210211String base_path;212213MenuButton *action_menu = nullptr;214215ConfirmationDialog *external_paths = nullptr;216Tree *external_path_tree = nullptr;217EditorFileDialog *save_path = nullptr;218OptionButton *external_extension_type = nullptr;219220EditorFileDialog *item_save_path = nullptr;221222void _menu_callback(int p_id);223void _save_dir_callback(const String &p_path);224225int current_action = 0;226227Vector<TreeItem *> save_path_items;228229TreeItem *save_path_item = nullptr;230void _save_path_changed(const String &p_path);231void _browse_save_callback(Object *p_item, int p_column, int p_id, MouseButton p_button);232void _save_dir_confirm();233234Dictionary base_subresource_settings;235236void _load_default_subresource_settings(HashMap<StringName, Variant> &settings, const String &p_type, const String &p_import_id, ResourceImporterScene::InternalImportCategory p_category);237238bool generate_collider = false;239240Timer *update_view_timer = nullptr;241242protected:243virtual void _update_theme_item_cache() override;244void _notification(int p_what);245246public:247ResourceImporterScene *get_resource_importer_scene() const { return _resource_importer_scene; }248void request_generate_collider();249void update_view();250void open_settings(const String &p_path, const String &p_scene_import_type = "PackedScene");251static SceneImportSettingsDialog *get_singleton();252Node *get_selected_node();253SceneImportSettingsDialog();254~SceneImportSettingsDialog();255};256257258