editor_scene_import_plugin.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*************************************************************************/
  2. /* editor_scene_import_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef EDITOR_SCENE_IMPORT_PLUGIN_H
  31. #define EDITOR_SCENE_IMPORT_PLUGIN_H
  32. #include "editor/editor_dir_dialog.h"
  33. #include "editor/editor_file_system.h"
  34. #include "editor/editor_import_export.h"
  35. #include "editor/io_plugins/editor_texture_import_plugin.h"
  36. #include "scene/gui/dialogs.h"
  37. #include "scene/gui/file_dialog.h"
  38. #include "scene/gui/label.h"
  39. #include "scene/gui/line_edit.h"
  40. #include "scene/gui/option_button.h"
  41. #include "scene/gui/progress_bar.h"
  42. #include "scene/gui/slider.h"
  43. #include "scene/gui/spin_box.h"
  44. #include "scene/gui/tree.h"
  45. #include "scene/resources/animation.h"
  46. #include "scene/resources/mesh.h"
  47. class EditorNode;
  48. class EditorSceneImportDialog;
  49. class EditorSceneImporter : public Reference {
  50. OBJ_TYPE(EditorSceneImporter, Reference);
  51. public:
  52. enum ImportFlags {
  53. IMPORT_SCENE = 1,
  54. IMPORT_ANIMATION = 2,
  55. IMPORT_ANIMATION_DETECT_LOOP = 4,
  56. IMPORT_ANIMATION_OPTIMIZE = 8,
  57. IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS = 16,
  58. IMPORT_ANIMATION_KEEP_VALUE_TRACKS = 32,
  59. IMPORT_GENERATE_TANGENT_ARRAYS = 256,
  60. IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 512
  61. };
  62. virtual uint32_t get_import_flags() const = 0;
  63. virtual void get_extensions(List<String> *r_extensions) const = 0;
  64. virtual Node *import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err = NULL) = 0;
  65. virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags) = 0;
  66. EditorSceneImporter();
  67. };
  68. /////////////////////////////////////////
  69. //Plugin for post processing scenes or images
  70. class EditorScenePostImport : public Reference {
  71. OBJ_TYPE(EditorScenePostImport, Reference);
  72. protected:
  73. static void _bind_methods();
  74. public:
  75. virtual Node *post_import(Node *p_scene);
  76. EditorScenePostImport();
  77. };
  78. class EditorSceneImportPlugin : public EditorImportPlugin {
  79. OBJ_TYPE(EditorSceneImportPlugin, EditorImportPlugin);
  80. EditorSceneImportDialog *dialog;
  81. Vector<Ref<EditorSceneImporter> > importers;
  82. enum TextureRole {
  83. TEXTURE_ROLE_DEFAULT,
  84. TEXTURE_ROLE_DIFFUSE,
  85. TEXTURE_ROLE_NORMALMAP
  86. };
  87. void _find_resources(const Variant &p_var, Map<Ref<ImageTexture>, TextureRole> &image_map, int p_flags);
  88. Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<Mesh>, Ref<Shape> > &collision_map, uint32_t p_flags, Map<Ref<ImageTexture>, TextureRole> &image_map);
  89. void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all);
  90. void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep);
  91. void _filter_tracks(Node *scene, const String &p_text);
  92. void _optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle);
  93. void _tag_import_paths(Node *p_scene, Node *p_node);
  94. void _find_resources_to_merge(Node *scene, Node *node, bool p_merge_material, Map<String, Ref<Material> > &materials, bool p_merge_anims, Map<String, Ref<Animation> > &merged_anims, Set<Ref<Mesh> > &tested_meshes);
  95. void _merge_found_resources(Node *scene, Node *node, bool p_merge_material, const Map<String, Ref<Material> > &materials, bool p_merge_anims, const Map<String, Ref<Animation> > &merged_anims, Set<Ref<Mesh> > &tested_meshes);
  96. public:
  97. enum SceneFlags {
  98. SCENE_FLAG_CREATE_COLLISIONS = 1 << 0,
  99. SCENE_FLAG_CREATE_PORTALS = 1 << 1,
  100. SCENE_FLAG_CREATE_ROOMS = 1 << 2,
  101. SCENE_FLAG_SIMPLIFY_ROOMS = 1 << 3,
  102. SCENE_FLAG_CREATE_BILLBOARDS = 1 << 4,
  103. SCENE_FLAG_CREATE_IMPOSTORS = 1 << 5,
  104. SCENE_FLAG_CREATE_LODS = 1 << 6,
  105. SCENE_FLAG_CREATE_CARS = 1 << 8,
  106. SCENE_FLAG_CREATE_WHEELS = 1 << 9,
  107. SCENE_FLAG_DETECT_ALPHA = 1 << 15,
  108. SCENE_FLAG_DETECT_VCOLOR = 1 << 16,
  109. SCENE_FLAG_CREATE_NAVMESH = 1 << 17,
  110. SCENE_FLAG_DETECT_LIGHTMAP_LAYER = 1 << 18,
  111. SCENE_FLAG_MERGE_KEEP_MATERIALS = 1 << 20,
  112. SCENE_FLAG_MERGE_KEEP_EXTRA_ANIM_TRACKS = 1 << 21,
  113. SCENE_FLAG_REMOVE_NOIMP = 1 << 24,
  114. SCENE_FLAG_IMPORT_ANIMATIONS = 1 << 25,
  115. SCENE_FLAG_COMPRESS_GEOMETRY = 1 << 26,
  116. SCENE_FLAG_GENERATE_TANGENT_ARRAYS = 1 << 27,
  117. SCENE_FLAG_LINEARIZE_DIFFUSE_TEXTURES = 1 << 28,
  118. SCENE_FLAG_SET_LIGHTMAP_TO_UV2_IF_EXISTS = 1 << 29,
  119. SCENE_FLAG_CONVERT_NORMALMAPS_TO_XY = 1 << 30,
  120. };
  121. virtual String get_name() const;
  122. virtual String get_visible_name() const;
  123. virtual void import_dialog(const String &p_from = "");
  124. virtual Error import(const String &p_path, const Ref<ResourceImportMetadata> &p_from);
  125. Error import1(const Ref<ResourceImportMetadata> &p_from, Node **r_node, List<String> *r_missing = NULL);
  126. Error import2(Node *p_scene, const String &p_path, const Ref<ResourceImportMetadata> &p_from);
  127. void add_importer(const Ref<EditorSceneImporter> &p_importer);
  128. const Vector<Ref<EditorSceneImporter> > &get_importers() { return importers; }
  129. virtual void import_from_drop(const Vector<String> &p_drop, const String &p_dest_path);
  130. EditorSceneImportPlugin(EditorNode *p_editor = NULL);
  131. };
  132. class EditorSceneAnimationImportPlugin : public EditorImportPlugin {
  133. OBJ_TYPE(EditorSceneAnimationImportPlugin, EditorImportPlugin);
  134. public:
  135. enum AnimationFlags {
  136. ANIMATION_DETECT_LOOP = 1,
  137. ANIMATION_KEEP_VALUE_TRACKS = 2,
  138. ANIMATION_OPTIMIZE = 4,
  139. ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS = 8
  140. };
  141. virtual String get_name() const;
  142. virtual String get_visible_name() const;
  143. virtual void import_dialog(const String &p_from = "");
  144. virtual Error import(const String &p_path, const Ref<ResourceImportMetadata> &p_from);
  145. EditorSceneAnimationImportPlugin(EditorNode *p_editor = NULL);
  146. };
  147. #endif // EDITOR_SCENE_IMPORT_PLUGIN_H