editor_scene_importer_fbxconv.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*************************************************************************/
  2. /* editor_scene_importer_fbxconv.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_IMPORTER_FBXCONV_H
  31. #define EDITOR_SCENE_IMPORTER_FBXCONV_H
  32. #include "editor/io_plugins/editor_scene_import_plugin.h"
  33. #include "scene/3d/skeleton.h"
  34. class EditorSceneImporterFBXConv : public EditorSceneImporter {
  35. OBJ_TYPE(EditorSceneImporterFBXConv, EditorSceneImporter);
  36. struct BoneInfo {
  37. Skeleton *skeleton;
  38. Transform rest;
  39. int index;
  40. bool has_anim_chan;
  41. bool has_rest;
  42. Dictionary node;
  43. BoneInfo() {
  44. has_rest = false;
  45. skeleton = NULL;
  46. index = -1;
  47. has_anim_chan = false;
  48. }
  49. };
  50. struct SurfaceInfo {
  51. Array array;
  52. Mesh::PrimitiveType primitive;
  53. };
  54. struct State {
  55. Node *scene;
  56. Array meshes;
  57. Array materials;
  58. Array nodes;
  59. Array animations;
  60. Map<String, BoneInfo> bones;
  61. Map<String, Skeleton *> skeletons;
  62. Map<String, Ref<Mesh> > mesh_cache;
  63. Map<String, SurfaceInfo> surface_cache;
  64. Map<String, Ref<Material> > material_cache;
  65. Map<String, Ref<Texture> > texture_cache;
  66. List<String> *missing_deps;
  67. String base_path;
  68. bool import_animations;
  69. };
  70. String _id(const String &p_id) const;
  71. Transform _get_transform_mixed(const Dictionary &d, const Dictionary &dbase);
  72. Transform _get_transform(const Dictionary &d);
  73. Color _get_color(const Array &a);
  74. void _detect_bones_in_nodes(State &state, const Array &p_nodes);
  75. void _detect_bones(State &state);
  76. Error _parse_bones(State &state, const Array &p_bones, Skeleton *p_skeleton);
  77. void _parse_skeletons(const String &p_name, State &state, const Array &p_nodes, Skeleton *p_skeleton = NULL, int p_parent = -1);
  78. void _add_surface(State &state, Ref<Mesh> &m, const Dictionary &part);
  79. Error _parse_nodes(State &state, const Array &p_nodes, Node *p_base);
  80. Error _parse_animations(State &state);
  81. void _parse_materials(State &state);
  82. void _parse_surfaces(State &state);
  83. Error _parse_json(State &state, const String &p_path);
  84. Error _parse_fbx(State &state, const String &p_path);
  85. public:
  86. virtual uint32_t get_import_flags() const;
  87. virtual void get_extensions(List<String> *r_extensions) const;
  88. virtual Node *import_scene(const String &p_path, uint32_t p_flags, List<String> *r_missing_deps = NULL, Error *r_err = NULL);
  89. virtual Ref<Animation> import_animation(const String &p_path, uint32_t p_flags);
  90. EditorSceneImporterFBXConv();
  91. };
  92. #endif // EDITOR_SCENE_IMPORTER_FBXCONV_H