Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/fbx/fbx_document.h
10277 views
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
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(String p_path, Ref<GLTFState> p_state, uint32_t p_flags = 0, String p_base_path = String()) override;
58
Error append_from_buffer(PackedByteArray p_bytes, 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, String p_path, Ref<FileAccess> p_file);
105
};
106
107