| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "fbx_state.h" |
| 34 |
|
| 35 |
#include "modules/gltf/gltf_defines.h" |
| 36 |
#include "modules/gltf/gltf_document.h" |
| 37 |
|
| 38 |
#include <ufbx.h> |
| 39 |
|
| 40 |
class FBXDocument : public GLTFDocument { |
| 41 |
GDCLASS(FBXDocument, GLTFDocument); |
| 42 |
|
| 43 |
int _naming_version = 2; |
| 44 |
|
| 45 |
public: |
| 46 |
enum { |
| 47 |
TEXTURE_TYPE_GENERIC = 0, |
| 48 |
TEXTURE_TYPE_NORMAL = 1, |
| 49 |
}; |
| 50 |
|
| 51 |
static Transform3D _as_xform(const ufbx_matrix &p_mat); |
| 52 |
static String _as_string(const ufbx_string &p_string); |
| 53 |
static Vector3 _as_vec3(const ufbx_vec3 &p_vector); |
| 54 |
static String _gen_unique_name(HashSet<String> &unique_names, const String &p_name); |
| 55 |
|
| 56 |
public: |
| 57 |
Error append_from_file(const String &p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, const String &p_base_path = String()) override; |
| 58 |
Error append_from_buffer(const PackedByteArray &p_bytes, const String &p_base_path, Ref<GLTFState> p_state, uint32_t p_flags = 0) override; |
| 59 |
Error append_from_scene(Node *p_node, Ref<GLTFState> p_state, uint32_t p_flags = 0) override; |
| 60 |
|
| 61 |
Node *generate_scene(Ref<GLTFState> p_state, float p_bake_fps = 30.0f, bool p_trimming = false, bool p_remove_immutable_tracks = true) override; |
| 62 |
PackedByteArray generate_buffer(Ref<GLTFState> p_state) override; |
| 63 |
Error write_to_filesystem(Ref<GLTFState> p_state, const String &p_path) override; |
| 64 |
|
| 65 |
void set_naming_version(int p_version); |
| 66 |
int get_naming_version() const; |
| 67 |
|
| 68 |
private: |
| 69 |
String _get_texture_path(const String &p_base_directory, const String &p_source_file_path) const; |
| 70 |
void _process_uv_set(PackedVector2Array &uv_array); |
| 71 |
void _zero_unused_elements(Vector<float> &cur_custom, int start, int end, int num_channels); |
| 72 |
Error _parse_scenes(Ref<FBXState> p_state); |
| 73 |
Error _parse_nodes(Ref<FBXState> p_state); |
| 74 |
String _sanitize_animation_name(const String &p_name); |
| 75 |
String _gen_unique_animation_name(Ref<FBXState> p_state, const String &p_name); |
| 76 |
Ref<Texture2D> _get_texture(Ref<FBXState> p_state, |
| 77 |
const GLTFTextureIndex p_texture, int p_texture_type); |
| 78 |
Error _parse_meshes(Ref<FBXState> p_state); |
| 79 |
Ref<Image> _parse_image_bytes_into_image(Ref<FBXState> p_state, const Vector<uint8_t> &p_bytes, const String &p_filename, int p_index); |
| 80 |
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); |
| 81 |
Error _parse_images(Ref<FBXState> p_state, const String &p_base_path); |
| 82 |
Error _parse_materials(Ref<FBXState> p_state); |
| 83 |
Error _parse_skins(Ref<FBXState> p_state); |
| 84 |
Error _parse_animations(Ref<FBXState> p_state); |
| 85 |
BoneAttachment3D *_generate_bone_attachment(Ref<FBXState> p_state, |
| 86 |
Skeleton3D *p_skeleton, |
| 87 |
const GLTFNodeIndex p_node_index, |
| 88 |
const GLTFNodeIndex p_bone_index); |
| 89 |
ImporterMeshInstance3D *_generate_mesh_instance(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index); |
| 90 |
Camera3D *_generate_camera(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index); |
| 91 |
Light3D *_generate_light(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index); |
| 92 |
Node3D *_generate_spatial(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index); |
| 93 |
void _assign_node_names(Ref<FBXState> p_state); |
| 94 |
Error _parse_cameras(Ref<FBXState> p_state); |
| 95 |
Error _parse_lights(Ref<FBXState> p_state); |
| 96 |
|
| 97 |
public: |
| 98 |
Error _parse_fbx_state(Ref<FBXState> p_state, const String &p_search_path); |
| 99 |
void _process_mesh_instances(Ref<FBXState> p_state, Node *p_scene_root); |
| 100 |
void _generate_scene_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root); |
| 101 |
void _generate_skeleton_bone_node(Ref<FBXState> p_state, const GLTFNodeIndex p_node_index, Node *p_scene_parent, Node *p_scene_root); |
| 102 |
void _import_animation(Ref<FBXState> p_state, AnimationPlayer *p_animation_player, |
| 103 |
const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks); |
| 104 |
Error _parse(Ref<FBXState> p_state, const String &p_path, Ref<FileAccess> p_file); |
| 105 |
}; |