fbx_document.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**************************************************************************/
  2. /* fbx_document.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 FBX_DOCUMENT_H
  31. #define FBX_DOCUMENT_H
  32. #include "fbx_state.h"
  33. #include "modules/gltf/gltf_defines.h"
  34. #include "modules/gltf/gltf_document.h"
  35. #include <ufbx.h>
  36. class FBXDocument : public GLTFDocument {
  37. GDCLASS(FBXDocument, GLTFDocument);
  38. public:
  39. enum {
  40. TEXTURE_TYPE_GENERIC = 0,
  41. TEXTURE_TYPE_NORMAL = 1,
  42. };
  43. static Transform3D _as_xform(const ufbx_matrix &p_mat);
  44. static String _as_string(const ufbx_string &p_string);
  45. static Vector3 _as_vec3(const ufbx_vec3 &p_vector);
  46. static String _gen_unique_name(HashSet<String> &unique_names, const String &p_name);
  47. public:
  48. Error append_from_file(String p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, String p_base_path = String()) override;
  49. Error append_from_buffer(PackedByteArray p_bytes, String p_base_path, Ref<GLTFState> p_state, uint32_t p_flags = 0) override;
  50. Error append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags = 0) override;
  51. Node *generate_scene(Ref<GLTFState> p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true) override;
  52. PackedByteArray generate_buffer(Ref<GLTFState> p_state) override;
  53. Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) override;
  54. private:
  55. String _get_texture_path(const String &p_base_directory, const String &p_source_file_path) const;
  56. void _process_uv_set(PackedVector2Array &uv_array);
  57. void _zero_unused_elements(Vector<float> &cur_custom, int start, int end, int num_channels);
  58. Error _parse_scenes(Ref<FBXState> p_state);
  59. Error _parse_nodes(Ref<FBXState> p_state);
  60. String _sanitize_animation_name(const String &p_name);
  61. String _gen_unique_animation_name(Ref<FBXState> p_state, const String &p_name);
  62. Ref<Texture2D> _get_texture(Ref<FBXState> p_state,
  63. const GLTFTextureIndex p_texture, int p_texture_type);
  64. Error _parse_meshes(Ref<FBXState> p_state);
  65. Ref<Image> _parse_image_bytes_into_image(Ref<FBXState> p_state, const Vector<uint8_t> &p_bytes, const String &p_filename, int p_index);
  66. GLTFImageIndex _parse_image_save_image(Ref<FBXState> p_state, const Vector<uint8_t> &p_bytes, const String &p_file_extension, int p_index, Ref<Image> p_image);
  67. Error _parse_images(Ref<FBXState> p_state, const String &p_base_path);
  68. Error _parse_materials(Ref<FBXState> p_state);
  69. Error _parse_skins(Ref<FBXState> p_state);
  70. Error _parse_animations(Ref<FBXState> p_state);
  71. BoneAttachment3D *_generate_bone_attachment(Ref<FBXState> p_state,
  72. Skeleton3D *p_skeleton,
  73. const GLTFNodeIndex p_node_index,
  74. const GLTFNodeIndex p_bone_index);
  75. ImporterMeshInstance3D *_generate_mesh_instance(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index);
  76. Camera3D *_generate_camera(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index);
  77. Light3D *_generate_light(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index);
  78. Node3D *_generate_spatial(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index);
  79. void _assign_node_names(Ref<FBXState> p_state);
  80. Error _parse_cameras(Ref<FBXState> p_state);
  81. Error _parse_lights(Ref<FBXState> p_state);
  82. public:
  83. Error _parse_fbx_state(Ref<FBXState> p_state, const String &p_search_path);
  84. void _process_mesh_instances(Ref<FBXState> p_state, Node *p_scene_root);
  85. void _generate_scene_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
  86. void _generate_skeleton_bone_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root);
  87. void _import_animation(Ref<FBXState> p_state, AnimationPlayer *p_animation_player,
  88. const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks);
  89. Error _parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess> p_file);
  90. };
  91. #endif // FBX_DOCUMENT_H