resource_importer_scene.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*************************************************************************/
  2. /* resource_importer_scene.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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 RESOURCEIMPORTERSCENE_H
  31. #define RESOURCEIMPORTERSCENE_H
  32. #include "core/io/resource_import.h"
  33. #include "scene/resources/animation.h"
  34. #include "scene/resources/mesh.h"
  35. #include "scene/resources/shape.h"
  36. class Material;
  37. class EditorSceneImporter : public Reference {
  38. GDCLASS(EditorSceneImporter, Reference);
  39. protected:
  40. static void _bind_methods();
  41. Node *import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
  42. Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps);
  43. public:
  44. enum ImportFlags {
  45. IMPORT_SCENE = 1,
  46. IMPORT_ANIMATION = 2,
  47. IMPORT_ANIMATION_DETECT_LOOP = 4,
  48. IMPORT_ANIMATION_OPTIMIZE = 8,
  49. IMPORT_ANIMATION_FORCE_ALL_TRACKS_IN_ALL_CLIPS = 16,
  50. IMPORT_ANIMATION_KEEP_VALUE_TRACKS = 32,
  51. IMPORT_GENERATE_TANGENT_ARRAYS = 256,
  52. IMPORT_FAIL_ON_MISSING_DEPENDENCIES = 512,
  53. IMPORT_MATERIALS_IN_INSTANCES = 1024,
  54. IMPORT_USE_COMPRESSION = 2048
  55. };
  56. virtual uint32_t get_import_flags() const;
  57. virtual void get_extensions(List<String> *r_extensions) const;
  58. 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);
  59. virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps);
  60. EditorSceneImporter() {}
  61. };
  62. class EditorScenePostImport : public Reference {
  63. GDCLASS(EditorScenePostImport, Reference);
  64. String source_folder;
  65. String source_file;
  66. protected:
  67. static void _bind_methods();
  68. public:
  69. String get_source_folder() const;
  70. String get_source_file() const;
  71. virtual Node *post_import(Node *p_scene);
  72. virtual void init(const String &p_scene_folder, const String &p_scene_path);
  73. EditorScenePostImport();
  74. };
  75. class ResourceImporterScene : public ResourceImporter {
  76. GDCLASS(ResourceImporterScene, ResourceImporter)
  77. Set<Ref<EditorSceneImporter> > importers;
  78. static ResourceImporterScene *singleton;
  79. enum Presets {
  80. PRESET_SEPARATE_MATERIALS,
  81. PRESET_SEPARATE_MESHES,
  82. PRESET_SEPARATE_ANIMATIONS,
  83. PRESET_SINGLE_SCENE,
  84. PRESET_SEPARATE_MESHES_AND_MATERIALS,
  85. PRESET_SEPARATE_MESHES_AND_ANIMATIONS,
  86. PRESET_SEPARATE_MATERIALS_AND_ANIMATIONS,
  87. PRESET_SEPARATE_MESHES_MATERIALS_AND_ANIMATIONS,
  88. PRESET_MULTIPLE_SCENES,
  89. PRESET_MULTIPLE_SCENES_AND_MATERIALS,
  90. PRESET_MAX
  91. };
  92. enum LightBakeMode {
  93. LIGHT_BAKE_DISABLED,
  94. LIGHT_BAKE_ENABLE,
  95. LIGHT_BAKE_LIGHTMAPS
  96. };
  97. void _replace_owner(Node *p_node, Node *p_scene, Node *p_new_owner);
  98. public:
  99. static ResourceImporterScene *get_singleton() { return singleton; }
  100. const Set<Ref<EditorSceneImporter> > &get_importers() const { return importers; }
  101. void add_importer(Ref<EditorSceneImporter> p_importer) { importers.insert(p_importer); }
  102. void remove_importer(Ref<EditorSceneImporter> p_importer) { importers.erase(p_importer); }
  103. virtual String get_importer_name() const;
  104. virtual String get_visible_name() const;
  105. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  106. virtual String get_save_extension() const;
  107. virtual String get_resource_type() const;
  108. virtual int get_preset_count() const;
  109. virtual String get_preset_name(int p_idx) const;
  110. virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const;
  111. virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const;
  112. virtual int get_import_order() const { return 100; } //after everything
  113. void _find_meshes(Node *p_node, Map<Ref<ArrayMesh>, Transform> &meshes);
  114. void _make_external_resources(Node *p_node, const String &p_base_path, bool p_make_animations, bool p_keep_animations, bool p_make_materials, bool p_keep_materials, bool p_make_meshes, Map<Ref<Animation>, Ref<Animation> > &p_animations, Map<Ref<Material>, Ref<Material> > &p_materials, Map<Ref<ArrayMesh>, Ref<ArrayMesh> > &p_meshes);
  115. Node *_fix_node(Node *p_node, Node *p_root, Map<Ref<ArrayMesh>, Ref<Shape> > &collision_map, LightBakeMode p_light_bake_mode);
  116. void _create_clips(Node *scene, const Array &p_clips, bool p_bake_all);
  117. void _filter_anim_tracks(Ref<Animation> anim, Set<String> &keep);
  118. void _filter_tracks(Node *scene, const String &p_text);
  119. void _optimize_animations(Node *scene, float p_max_lin_error, float p_max_ang_error, float p_max_angle);
  120. virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL);
  121. Node *import_scene_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps);
  122. Ref<Animation> import_animation_from_other_importer(EditorSceneImporter *p_exception, const String &p_path, uint32_t p_flags, int p_bake_fps);
  123. ResourceImporterScene();
  124. };
  125. class EditorSceneImporterESCN : public EditorSceneImporter {
  126. GDCLASS(EditorSceneImporterESCN, EditorSceneImporter);
  127. public:
  128. virtual uint32_t get_import_flags() const;
  129. virtual void get_extensions(List<String> *r_extensions) const;
  130. 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);
  131. virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps);
  132. };
  133. #endif // RESOURCEIMPORTERSCENE_H