diff options
Diffstat (limited to 'modules/fbx')
21 files changed, 197 insertions, 266 deletions
diff --git a/modules/fbx/data/fbx_mesh_data.cpp b/modules/fbx/data/fbx_mesh_data.cpp index dcea476275..e1eacc68b3 100644 --- a/modules/fbx/data/fbx_mesh_data.cpp +++ b/modules/fbx/data/fbx_mesh_data.cpp @@ -31,6 +31,7 @@ #include "fbx_mesh_data.h" #include "core/templates/local_vector.h" +#include "scene/resources/importer_mesh.h" #include "scene/resources/mesh.h" #include "scene/resources/surface_tool.h" @@ -101,7 +102,7 @@ HashMap<int, Vector2> collect_uv(const Vector<VertexData<Vector2>> *p_data, Hash return collection; } -EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &state, const FBXDocParser::MeshGeometry *p_mesh_geometry, const FBXDocParser::Model *model, bool use_compression) { +ImporterMeshInstance3D *FBXMeshData::create_fbx_mesh(const ImportState &state, const FBXDocParser::MeshGeometry *p_mesh_geometry, const FBXDocParser::Model *model, bool use_compression) { mesh_geometry = p_mesh_geometry; // todo: make this just use a uint64_t FBX ID this is a copy of our original materials unfortunately. const std::vector<const FBXDocParser::Material *> &material_lookup = model->GetMaterials(); @@ -344,7 +345,7 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s } // Phase 6. Compose the mesh and return it. - Ref<EditorSceneImporterMesh> mesh; + Ref<ImporterMesh> mesh; mesh.instantiate(); // Add blend shape info. @@ -356,7 +357,6 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s mesh->set_blend_shape_mode(Mesh::BLEND_SHAPE_MODE_NORMALIZED); // Add surfaces. - int in_mesh_surface_id = 0; for (const SurfaceId *surface_id = surfaces.next(nullptr); surface_id != nullptr; surface_id = surfaces.next(surface_id)) { SurfaceData *surface = surfaces.getptr(*surface_id); @@ -376,11 +376,9 @@ EditorSceneImporterMeshNode3D *FBXMeshData::create_fbx_mesh(const ImportState &s } else { mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, mesh_array, blend_shapes); } - - in_mesh_surface_id += 1; } - EditorSceneImporterMeshNode3D *godot_mesh = memnew(EditorSceneImporterMeshNode3D); + ImporterMeshInstance3D *godot_mesh = memnew(ImporterMeshInstance3D); godot_mesh->set_mesh(mesh); const String name = ImportUtils::FBXNodeToName(model->Name()); godot_mesh->set_name(name); // hurry up compiling >.< diff --git a/modules/fbx/data/fbx_mesh_data.h b/modules/fbx/data/fbx_mesh_data.h index 24db4a5469..eec7f38cd6 100644 --- a/modules/fbx/data/fbx_mesh_data.h +++ b/modules/fbx/data/fbx_mesh_data.h @@ -35,7 +35,7 @@ #include "core/templates/local_vector.h" #include "core/templates/ordered_hash_map.h" #include "editor/import/resource_importer_scene.h" -#include "editor/import/scene_importer_mesh_node_3d.h" +#include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/mesh_instance_3d.h" #include "scene/resources/surface_tool.h" @@ -98,7 +98,7 @@ struct FBXMeshData : RefCounted { // translate fbx mesh data from document context to FBX Mesh Geometry Context bool valid_weight_indexes = false; - EditorSceneImporterMeshNode3D *create_fbx_mesh(const ImportState &state, const FBXDocParser::MeshGeometry *p_mesh_geometry, const FBXDocParser::Model *model, bool use_compression); + ImporterMeshInstance3D *create_fbx_mesh(const ImportState &state, const FBXDocParser::MeshGeometry *p_mesh_geometry, const FBXDocParser::Model *model, bool use_compression); void gen_weight_info(Ref<SurfaceTool> st, int vertex_id) const; @@ -107,7 +107,7 @@ struct FBXMeshData : RefCounted { int max_weight_count = 0; uint64_t armature_id = 0; bool valid_armature_id = false; - EditorSceneImporterMeshNode3D *godot_mesh_instance = nullptr; + ImporterMeshInstance3D *godot_mesh_instance = nullptr; private: void sanitize_vertex_weights(const ImportState &state); diff --git a/modules/fbx/data/fbx_skeleton.cpp b/modules/fbx/data/fbx_skeleton.cpp index 1ac4922acf..11eed2576f 100644 --- a/modules/fbx/data/fbx_skeleton.cpp +++ b/modules/fbx/data/fbx_skeleton.cpp @@ -98,12 +98,19 @@ void FBXSkeleton::init_skeleton(const ImportState &state) { ERR_FAIL_COND_MSG(skeleton->get_bone_count() != bone_count, "Not all bones got added, is the file corrupted?"); - for (Map<int, Ref<FBXBone>>::Element *bone_element = bone_map.front(); bone_element; bone_element = bone_element->next()) { - const Ref<FBXBone> bone = bone_element->value(); - int bone_index = bone_element->key(); + for (const KeyValue<int, Ref<FBXBone>> &bone_element : bone_map) { + const Ref<FBXBone> bone = bone_element.value; + int bone_index = bone_element.key; print_verbose("working on bone: " + itos(bone_index) + " bone name:" + bone->bone_name); skeleton->set_bone_rest(bone->godot_bone_id, get_unscaled_transform(bone->node->pivot_transform->LocalTransform, state.scale)); + { + Transform3D base_xform = bone->node->pivot_transform->LocalTransform; + + skeleton->set_bone_pose_position(bone_index, base_xform.origin); + skeleton->set_bone_pose_rotation(bone_index, base_xform.basis.get_rotation_quaternion()); + skeleton->set_bone_pose_scale(bone_index, base_xform.basis.get_scale()); + } // lookup parent ID if (bone->valid_parent && state.fbx_bone_map.has(bone->parent_bone_id)) { diff --git a/modules/fbx/doc_classes/EditorSceneImporterFBX.xml b/modules/fbx/doc_classes/EditorSceneImporterFBX.xml deleted file mode 100644 index da1a68c27c..0000000000 --- a/modules/fbx/doc_classes/EditorSceneImporterFBX.xml +++ /dev/null @@ -1,36 +0,0 @@ -<?xml version="1.0" encoding="UTF-8" ?> -<class name="EditorSceneImporterFBX" inherits="EditorSceneImporter" version="4.0"> - <brief_description> - FBX 3D asset importer. - </brief_description> - <description> - This is an FBX 3D asset importer with full support for most FBX features. - If exporting a FBX scene from Autodesk Maya, use these FBX export settings: - [codeblock] - - Smoothing Groups - - Smooth Mesh - - Triangluate (for meshes with blend shapes) - - Bake Animation - - Resample All - - Deformed Models - - Skins - - Blend Shapes - - Curve Filters - - Constant Key Reducer - - Auto Tangents Only - - *Do not check* Constraints (as it will break the file) - - Can check Embed Media (embeds textures into the exported FBX file) - - Note that when importing embedded media, the texture and mesh will be a single immutable file. - - You will have to re-export then re-import the FBX if the texture has changed. - - Units: Centimeters - - Up Axis: Y - - Binary format in FBX 2017 - [/codeblock] - </description> - <tutorials> - </tutorials> - <methods> - </methods> - <constants> - </constants> -</class> diff --git a/modules/fbx/editor_scene_importer_fbx.cpp b/modules/fbx/editor_scene_importer_fbx.cpp index e3f36ef3e3..b11c145599 100644 --- a/modules/fbx/editor_scene_importer_fbx.cpp +++ b/modules/fbx/editor_scene_importer_fbx.cpp @@ -40,9 +40,9 @@ #include "editor/editor_log.h" #include "editor/editor_node.h" #include "editor/import/resource_importer_scene.h" -#include "editor/import/scene_importer_mesh_node_3d.h" #include "scene/3d/bone_attachment_3d.h" #include "scene/3d/camera_3d.h" +#include "scene/3d/importer_mesh_instance_3d.h" #include "scene/3d/light_3d.h" #include "scene/main/node.h" #include "scene/resources/material.h" @@ -56,7 +56,7 @@ #include <string> -void EditorSceneImporterFBX::get_extensions(List<String> *r_extensions) const { +void EditorSceneFormatImporterFBX::get_extensions(List<String> *r_extensions) const { // register FBX as the one and only format for FBX importing const String import_setting_string = "filesystem/import/fbx/"; const String fbx_str = "fbx"; @@ -65,7 +65,7 @@ void EditorSceneImporterFBX::get_extensions(List<String> *r_extensions) const { _register_project_setting_import(fbx_str, import_setting_string, exts, r_extensions, true); } -void EditorSceneImporterFBX::_register_project_setting_import(const String generic, +void EditorSceneFormatImporterFBX::_register_project_setting_import(const String generic, const String import_setting_string, const Vector<String> &exts, List<String> *r_extensions, @@ -79,11 +79,11 @@ void EditorSceneImporterFBX::_register_project_setting_import(const String gener } } -uint32_t EditorSceneImporterFBX::get_import_flags() const { +uint32_t EditorSceneFormatImporterFBX::get_import_flags() const { return IMPORT_SCENE; } -Node3D *EditorSceneImporterFBX::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, +Node3D *EditorSceneFormatImporterFBX::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) { // done for performance when re-importing lots of files when testing importer in verbose only! if (OS::get_singleton()->is_stdout_verbose()) { @@ -232,7 +232,7 @@ Node3D *EditorSceneImporterFBX::import_scene(const String &p_path, uint32_t p_fl } template <class T> -struct EditorSceneImporterAssetImportInterpolate { +struct EditorSceneFormatImporterAssetImportInterpolate { T lerp(const T &a, const T &b, float c) const { return a + (b - a) * c; } @@ -258,7 +258,7 @@ struct EditorSceneImporterAssetImportInterpolate { //thank you for existing, partial specialization template <> -struct EditorSceneImporterAssetImportInterpolate<Quaternion> { +struct EditorSceneFormatImporterAssetImportInterpolate<Quaternion> { Quaternion lerp(const Quaternion &a, const Quaternion &b, float c) const { ERR_FAIL_COND_V(!a.is_normalized(), Quaternion()); ERR_FAIL_COND_V(!b.is_normalized(), Quaternion()); @@ -282,7 +282,7 @@ struct EditorSceneImporterAssetImportInterpolate<Quaternion> { }; template <class T> -T EditorSceneImporterFBX::_interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, float p_time, +T EditorSceneFormatImporterFBX::_interpolate_track(const Vector<float> &p_times, const Vector<T> &p_values, float p_time, AssetImportAnimation::Interpolation p_interp) { //could use binary search, worth it? int idx = -1; @@ -293,7 +293,7 @@ T EditorSceneImporterFBX::_interpolate_track(const Vector<float> &p_times, const idx++; } - EditorSceneImporterAssetImportInterpolate<T> interp; + EditorSceneFormatImporterAssetImportInterpolate<T> interp; switch (p_interp) { case AssetImportAnimation::INTERP_LINEAR: { @@ -352,7 +352,7 @@ T EditorSceneImporterFBX::_interpolate_track(const Vector<float> &p_times, const ERR_FAIL_V(p_values[0]); } -Node3D *EditorSceneImporterFBX::_generate_scene( +Node3D *EditorSceneFormatImporterFBX::_generate_scene( const String &p_path, const FBXDocParser::Document *p_document, const uint32_t p_flags, @@ -567,8 +567,8 @@ Node3D *EditorSceneImporterFBX::_generate_scene( // this means that the nodes from maya kLocators will be preserved as bones // in the same rig without having to match this across skeletons and merge by detection // we can just merge and undo any parent transforms - for (Map<uint64_t, Ref<FBXBone>>::Element *bone_element = state.fbx_bone_map.front(); bone_element; bone_element = bone_element->next()) { - Ref<FBXBone> bone = bone_element->value(); + for (KeyValue<uint64_t, Ref<FBXBone>> &bone_element : state.fbx_bone_map) { + Ref<FBXBone> bone = bone_element.value; Ref<FBXSkeleton> fbx_skeleton_inst; uint64_t armature_id = bone->armature_id; @@ -609,8 +609,8 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } // setup skeleton instances if required :) - for (Map<uint64_t, Ref<FBXSkeleton>>::Element *skeleton_node = state.skeleton_map.front(); skeleton_node; skeleton_node = skeleton_node->next()) { - Ref<FBXSkeleton> &skeleton = skeleton_node->value(); + for (KeyValue<uint64_t, Ref<FBXSkeleton>> &skeleton_node : state.skeleton_map) { + Ref<FBXSkeleton> &skeleton = skeleton_node.value; skeleton->init_skeleton(state); ERR_CONTINUE_MSG(skeleton->fbx_node.is_null(), "invalid fbx target map, missing skeleton"); @@ -627,7 +627,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( node_element; node_element = node_element->next()) { Ref<FBXNode> fbx_node = node_element->get(); - EditorSceneImporterMeshNode3D *mesh_node = nullptr; + ImporterMeshInstance3D *mesh_node = nullptr; Ref<FBXMeshData> mesh_data_precached; // check for valid geometry @@ -699,9 +699,9 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } } - for (Map<uint64_t, Ref<FBXMeshData>>::Element *mesh_data = state.renderer_mesh_data.front(); mesh_data; mesh_data = mesh_data->next()) { - const uint64_t mesh_id = mesh_data->key(); - Ref<FBXMeshData> mesh = mesh_data->value(); + for (KeyValue<uint64_t, Ref<FBXMeshData>> &mesh_data : state.renderer_mesh_data) { + const uint64_t mesh_id = mesh_data.key; + Ref<FBXMeshData> mesh = mesh_data.value; const FBXDocParser::MeshGeometry *mesh_geometry = p_document->GetObject(mesh_id)->Get<FBXDocParser::MeshGeometry>(); @@ -765,10 +765,10 @@ Node3D *EditorSceneImporterFBX::_generate_scene( } // mesh data iteration for populating skeleton mapping - for (Map<uint64_t, Ref<FBXMeshData>>::Element *mesh_data = state.renderer_mesh_data.front(); mesh_data; mesh_data = mesh_data->next()) { - Ref<FBXMeshData> mesh = mesh_data->value(); - const uint64_t mesh_id = mesh_data->key(); - EditorSceneImporterMeshNode3D *mesh_instance = mesh->godot_mesh_instance; + for (KeyValue<uint64_t, Ref<FBXMeshData>> &mesh_data : state.renderer_mesh_data) { + Ref<FBXMeshData> mesh = mesh_data.value; + const uint64_t mesh_id = mesh_data.key; + ImporterMeshInstance3D *mesh_instance = mesh->godot_mesh_instance; const int mesh_weights = mesh->max_weight_count; Ref<FBXSkeleton> skeleton; const bool valid_armature = mesh->valid_armature_id; @@ -843,7 +843,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( if (state.animation_player == nullptr) { print_verbose("Creating animation player"); state.animation_player = memnew(AnimationPlayer); - state.root->add_child(state.animation_player); + state.root->add_child(state.animation_player, true); state.animation_player->set_owner(state.root_owner); } @@ -1004,16 +1004,14 @@ Node3D *EditorSceneImporterFBX::_generate_scene( // target id, [ track name, [time index, vector] ] //std::map<uint64_t, std::map<StringName, FBXTrack > > AnimCurveNodes; - for (Map<uint64_t, Map<StringName, FBXTrack>>::Element *track = AnimCurveNodes.front(); track; track = track->next()) { + for (KeyValue<uint64_t, Map<StringName, FBXTrack>> &track : AnimCurveNodes) { // 5 tracks // current track index // track count is 5 // track count is 5. // next track id is 5. - const uint64_t target_id = track->key(); - int track_idx = animation->add_track(Animation::TYPE_TRANSFORM3D); + const uint64_t target_id = track.key; - // animation->track_set_path(track_idx, node_path); Ref<FBXBone> bone; // note we must not run the below code if the entry doesn't exist, it will create dummy entries which is very bad. @@ -1037,22 +1035,21 @@ Node3D *EditorSceneImporterFBX::_generate_scene( // if this is a skeleton mapped track we can just set the path for the track. // todo: implement node paths here at some + NodePath track_path; if (state.fbx_bone_map.size() > 0 && state.fbx_bone_map.has(target_id)) { if (bone->fbx_skeleton.is_valid() && bone.is_valid()) { Ref<FBXSkeleton> fbx_skeleton = bone->fbx_skeleton; String bone_path = state.root->get_path_to(fbx_skeleton->skeleton); bone_path += ":" + fbx_skeleton->skeleton->get_bone_name(bone->godot_bone_id); print_verbose("[doc] track bone path: " + bone_path); - NodePath path = bone_path; - animation->track_set_path(track_idx, path); + track_path = bone_path; } } else if (state.fbx_target_map.has(target_id)) { //print_verbose("[doc] we have a valid target for a node animation"); Ref<FBXNode> target_node = state.fbx_target_map[target_id]; if (target_node.is_valid() && target_node->godot_node != nullptr) { String node_path = state.root->get_path_to(target_node->godot_node); - NodePath path = node_path; - animation->track_set_path(track_idx, path); + track_path = node_path; //print_verbose("[doc] node animation path: " + node_path); } } else { @@ -1072,7 +1069,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( const FBXDocParser::Model *model = target_node->fbx_model; const FBXDocParser::PropertyTable *props = dynamic_cast<const FBXDocParser::PropertyTable *>(model); - Map<StringName, FBXTrack> &track_data = track->value(); + Map<StringName, FBXTrack> &track_data = track.value; FBXTrack &translation_keys = track_data[StringName("T")]; FBXTrack &rotation_keys = track_data[StringName("R")]; FBXTrack &scale_keys = track_data[StringName("S")]; @@ -1186,6 +1183,30 @@ Node3D *EditorSceneImporterFBX::_generate_scene( const Vector3 def_scale = scale_keys.has_default ? scale_keys.default_value : bone_rest.basis.get_scale(); print_verbose("track defaults: p(" + def_pos + ") s(" + def_scale + ") r(" + def_rot + ")"); + int position_idx = -1; + if (pos_values.size()) { + position_idx = animation->get_track_count(); + animation->add_track(Animation::TYPE_POSITION_3D); + animation->track_set_path(position_idx, track_path); + animation->track_set_imported(position_idx, true); + } + + int rotation_idx = -1; + if (pos_values.size()) { + rotation_idx = animation->get_track_count(); + animation->add_track(Animation::TYPE_ROTATION_3D); + animation->track_set_path(rotation_idx, track_path); + animation->track_set_imported(rotation_idx, true); + } + + int scale_idx = -1; + if (pos_values.size()) { + scale_idx = animation->get_track_count(); + animation->add_track(Animation::TYPE_SCALE_3D); + animation->track_set_path(scale_idx, track_path); + animation->track_set_imported(scale_idx, true); + } + while (true) { Vector3 pos = def_pos; Quaternion rot = def_rot; @@ -1206,21 +1227,15 @@ Node3D *EditorSceneImporterFBX::_generate_scene( AssetImportAnimation::INTERP_LINEAR); } - // node animations must also include pivots - if (skeleton_bone >= 0) { - Transform3D xform = Transform3D(); - xform.basis.set_quaternion_scale(rot, scale); - xform.origin = pos; - const Transform3D t = bone_rest.affine_inverse() * xform; - - // populate this again - rot = t.basis.get_rotation_quaternion(); - rot.normalize(); - scale = t.basis.get_scale(); - pos = t.origin; + if (position_idx >= 0) { + animation->position_track_insert_key(position_idx, time, pos); + } + if (rotation_idx >= 0) { + animation->rotation_track_insert_key(rotation_idx, time, rot); + } + if (scale_idx >= 0) { + animation->scale_track_insert_key(scale_idx, time, scale); } - - animation->transform_track_insert_key(track_idx, time, pos, rot, scale); if (last) { break; @@ -1259,15 +1274,15 @@ Node3D *EditorSceneImporterFBX::_generate_scene( state.fbx_target_map.clear(); state.fbx_node_list.clear(); - for (Map<uint64_t, Ref<FBXBone>>::Element *element = state.fbx_bone_map.front(); element; element = element->next()) { - Ref<FBXBone> bone = element->value(); + for (KeyValue<uint64_t, Ref<FBXBone>> &element : state.fbx_bone_map) { + Ref<FBXBone> bone = element.value; bone->parent_bone.unref(); bone->node.unref(); bone->fbx_skeleton.unref(); } - for (Map<uint64_t, Ref<FBXSkeleton>>::Element *element = state.skeleton_map.front(); element; element = element->next()) { - Ref<FBXSkeleton> skel = element->value(); + for (KeyValue<uint64_t, Ref<FBXSkeleton>> &element : state.skeleton_map) { + Ref<FBXSkeleton> skel = element.value; skel->fbx_node.unref(); skel->skeleton_bones.clear(); } @@ -1279,7 +1294,7 @@ Node3D *EditorSceneImporterFBX::_generate_scene( return scene_root; } -void EditorSceneImporterFBX::BuildDocumentBones(Ref<FBXBone> p_parent_bone, +void EditorSceneFormatImporterFBX::BuildDocumentBones(Ref<FBXBone> p_parent_bone, ImportState &state, const FBXDocParser::Document *p_doc, uint64_t p_id) { const std::vector<const FBXDocParser::Connection *> &conns = p_doc->GetConnectionsByDestinationSequenced(p_id, "Model"); @@ -1368,7 +1383,7 @@ void EditorSceneImporterFBX::BuildDocumentBones(Ref<FBXBone> p_parent_bone, } } -void EditorSceneImporterFBX::BuildDocumentNodes( +void EditorSceneFormatImporterFBX::BuildDocumentNodes( Ref<PivotTransform> parent_transform, ImportState &state, const FBXDocParser::Document *p_doc, diff --git a/modules/fbx/editor_scene_importer_fbx.h b/modules/fbx/editor_scene_importer_fbx.h index 4a3b78480b..7845e079c2 100644 --- a/modules/fbx/editor_scene_importer_fbx.h +++ b/modules/fbx/editor_scene_importer_fbx.h @@ -57,9 +57,9 @@ #define CONVERT_FBX_TIME(time) static_cast<double>(time) / 46186158000LL -class EditorSceneImporterFBX : public EditorSceneImporter { +class EditorSceneFormatImporterFBX : public EditorSceneFormatImporter { private: - GDCLASS(EditorSceneImporterFBX, EditorSceneImporter); + GDCLASS(EditorSceneFormatImporterFBX, EditorSceneFormatImporter); struct AssetImportAnimation { enum Interpolation { @@ -122,8 +122,8 @@ private: void _register_project_setting_import(const String generic, const String import_setting_string, const Vector<String> &exts, List<String> *r_extensions, const bool p_enabled) const; public: - EditorSceneImporterFBX() {} - ~EditorSceneImporterFBX() {} + EditorSceneFormatImporterFBX() {} + ~EditorSceneFormatImporterFBX() {} virtual void get_extensions(List<String> *r_extensions) const override; virtual uint32_t get_import_flags() const override; diff --git a/modules/fbx/fbx_parser/FBXBinaryTokenizer.cpp b/modules/fbx/fbx_parser/FBXBinaryTokenizer.cpp index 1eee10b251..d6abcbb00a 100644 --- a/modules/fbx/fbx_parser/FBXBinaryTokenizer.cpp +++ b/modules/fbx/fbx_parser/FBXBinaryTokenizer.cpp @@ -82,46 +82,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <stdint.h> namespace FBXDocParser { -//enum Flag -//{ -// e_unknown_0 = 1 << 0, -// e_unknown_1 = 1 << 1, -// e_unknown_2 = 1 << 2, -// e_unknown_3 = 1 << 3, -// e_unknown_4 = 1 << 4, -// e_unknown_5 = 1 << 5, -// e_unknown_6 = 1 << 6, -// e_unknown_7 = 1 << 7, -// e_unknown_8 = 1 << 8, -// e_unknown_9 = 1 << 9, -// e_unknown_10 = 1 << 10, -// e_unknown_11 = 1 << 11, -// e_unknown_12 = 1 << 12, -// e_unknown_13 = 1 << 13, -// e_unknown_14 = 1 << 14, -// e_unknown_15 = 1 << 15, -// e_unknown_16 = 1 << 16, -// e_unknown_17 = 1 << 17, -// e_unknown_18 = 1 << 18, -// e_unknown_19 = 1 << 19, -// e_unknown_20 = 1 << 20, -// e_unknown_21 = 1 << 21, -// e_unknown_22 = 1 << 22, -// e_unknown_23 = 1 << 23, -// e_flag_field_size_64_bit = 1 << 24, // Not sure what is -// e_unknown_25 = 1 << 25, -// e_unknown_26 = 1 << 26, -// e_unknown_27 = 1 << 27, -// e_unknown_28 = 1 << 28, -// e_unknown_29 = 1 << 29, -// e_unknown_30 = 1 << 30, -// e_unknown_31 = 1 << 31 -//}; -// -//bool check_flag(uint32_t flags, Flag to_check) -//{ -// return (flags & to_check) != 0; -//} // ------------------------------------------------------------------------------------------------ Token::Token(const char *sbegin, const char *send, TokenType type, size_t offset) : sbegin(sbegin), @@ -458,12 +418,6 @@ void TokenizeBinary(TokenList &output_tokens, const char *input, size_t length, //TokenizeError("file is too short",0); } - //uint32_t offset = 0x15; - /* const char* cursor = input + 0x15; - const uint32_t flags = ReadWord(input, cursor, input + length); - const uint8_t padding_0 = ReadByte(input, cursor, input + length); // unused - const uint8_t padding_1 = ReadByte(input, cursor, input + length); // unused*/ - if (strncmp(input, "Kaydara FBX Binary", 18)) { TokenizeError("magic bytes not found", 0); } diff --git a/modules/fbx/fbx_parser/FBXCommon.h b/modules/fbx/fbx_parser/FBXCommon.h index 641d6d351e..611bf22d3b 100644 --- a/modules/fbx/fbx_parser/FBXCommon.h +++ b/modules/fbx/fbx_parser/FBXCommon.h @@ -70,8 +70,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /** @file FBXCommon.h -* Some useful constants and enums for dealing with FBX files. -*/ + * Some useful constants and enums for dealing with FBX files. + */ #ifndef FBX_COMMON_H #define FBX_COMMON_H diff --git a/modules/fbx/fbx_parser/FBXDocument.h b/modules/fbx/fbx_parser/FBXDocument.h index 885ff8fca4..539d633331 100644 --- a/modules/fbx/fbx_parser/FBXDocument.h +++ b/modules/fbx/fbx_parser/FBXDocument.h @@ -706,13 +706,13 @@ public: virtual ~AnimationCurve(); /** get list of keyframe positions (time). - * Invariant: |GetKeys()| > 0 */ + * Invariant: |GetKeys()| > 0 */ const KeyTimeList &GetKeys() const { return keys; } /** get list of keyframe values. - * Invariant: |GetKeys()| == |GetValues()| && |GetKeys()| > 0*/ + * Invariant: |GetKeys()| == |GetValues()| && |GetKeys()| > 0*/ const KeyValueList &GetValues() const { return values; } @@ -750,8 +750,8 @@ typedef std::weak_ptr<AnimationCurveNode> AnimationCurveNodeWeakPtr; class AnimationCurveNode : public Object { public: /* the optional white list specifies a list of property names for which the caller - wants animations for. If the curve node does not match one of these, std::range_error - will be thrown. */ + wants animations for. If the curve node does not match one of these, std::range_error + will be thrown. */ AnimationCurveNode(uint64_t id, const ElementPtr element, const std::string &name, const Document &doc, const char *const *target_prop_whitelist = nullptr, size_t whitelist_size = 0); @@ -760,8 +760,8 @@ public: const AnimationMap &Curves() const; /** Object the curve is assigned to, this can be nullptr if the - * target object has no DOM representation or could not - * be read for other reasons.*/ + * target object has no DOM representation or could not + * be read for other reasons.*/ Object *Target() const { return target; } @@ -799,8 +799,8 @@ public: virtual ~AnimationLayer(); /* the optional white list specifies a list of property names for which the caller - wants animations for. Curves not matching this list will not be added to the - animation layer. */ + wants animations for. Curves not matching this list will not be added to the + animation layer. */ const AnimationCurveNodeList Nodes(const char *const *target_prop_whitelist = nullptr, size_t whitelist_size = 0) const; private: @@ -891,15 +891,15 @@ public: virtual ~Cluster(); /** get the list of deformer weights associated with this cluster. - * Use #GetIndices() to get the associated vertices. Both arrays - * have the same size (and may also be empty). */ + * Use #GetIndices() to get the associated vertices. Both arrays + * have the same size (and may also be empty). */ const std::vector<float> &GetWeights() const { return weights; } /** get indices into the vertex data of the geometry associated - * with this cluster. Use #GetWeights() to get the associated weights. - * Both arrays have the same size (and may also be empty). */ + * with this cluster. Use #GetWeights() to get the associated weights. + * Both arrays have the same size (and may also be empty). */ const std::vector<unsigned int> &GetIndices() const { return indices; } @@ -998,7 +998,7 @@ public: LazyObject *LazyDestinationObject() const; /** return the name of the property the connection is attached to. - * this is an empty string for object to object (OO) connections. */ + * this is an empty string for object to object (OO) connections. */ const std::string &PropertyName() const { return prop; } diff --git a/modules/fbx/fbx_parser/FBXDocumentUtil.h b/modules/fbx/fbx_parser/FBXDocumentUtil.h index ba86191c4a..0489ce10ce 100644 --- a/modules/fbx/fbx_parser/FBXDocumentUtil.h +++ b/modules/fbx/fbx_parser/FBXDocumentUtil.h @@ -107,12 +107,12 @@ const T *ProcessSimpleConnection(const Connection &con, const char **propNameOut = nullptr) { if (is_object_property_conn && !con.PropertyName().length()) { DOMWarning("expected incoming " + std::string(name) + - " link to be an object-object connection, ignoring", + " link to be an object-object connection, ignoring", element); return nullptr; } else if (!is_object_property_conn && con.PropertyName().length()) { DOMWarning("expected incoming " + std::string(name) + - " link to be an object-property connection, ignoring", + " link to be an object-property connection, ignoring", element); return nullptr; } diff --git a/modules/fbx/fbx_parser/FBXImportSettings.h b/modules/fbx/fbx_parser/FBXImportSettings.h index b016db174b..bc22386957 100644 --- a/modules/fbx/fbx_parser/FBXImportSettings.h +++ b/modules/fbx/fbx_parser/FBXImportSettings.h @@ -81,29 +81,29 @@ namespace FBXDocParser { /** FBX import settings, parts of which are publicly accessible via their corresponding AI_CONFIG constants */ struct ImportSettings { /** enable strict mode: - * - only accept fbx 2012, 2013 files - * - on the slightest error, give up. - * - * Basically, strict mode means that the fbx file will actually - * be validated.*/ + * - only accept fbx 2012, 2013 files + * - on the slightest error, give up. + * + * Basically, strict mode means that the fbx file will actually + * be validated.*/ bool strictMode = true; /** specifies whether all geometry layers are read and scanned for - * usable data channels. The FBX spec indicates that many readers - * will only read the first channel and that this is in some way - * the recommended way- in reality, however, it happens a lot that - * vertex data is spread among multiple layers.*/ + * usable data channels. The FBX spec indicates that many readers + * will only read the first channel and that this is in some way + * the recommended way- in reality, however, it happens a lot that + * vertex data is spread among multiple layers.*/ bool readAllLayers = true; /** specifies whether all materials are read, or only those that - * are referenced by at least one mesh. Reading all materials - * may make FBX reading a lot slower since all objects - * need to be processed. - * This bit is ignored unless readMaterials=true.*/ + * are referenced by at least one mesh. Reading all materials + * may make FBX reading a lot slower since all objects + * need to be processed. + * This bit is ignored unless readMaterials=true.*/ bool readAllMaterials = true; /** import materials (true) or skip them and assign a default - * material.*/ + * material.*/ bool readMaterials = true; /** import embedded textures?*/ @@ -116,35 +116,35 @@ struct ImportSettings { bool readLights = true; /** import animations (i.e. animation curves, the node - * skeleton is always imported).*/ + * skeleton is always imported).*/ bool readAnimations = true; /** read bones (vertex weights and deform info).*/ bool readWeights = true; /** preserve transformation pivots and offsets. Since these can - * not directly be represented in assimp, additional dummy - * nodes will be generated. Note that settings this to false - * can make animation import a lot slower. - * - * The naming scheme for the generated nodes is: - * <OriginalName>_$AssimpFbx$_<TransformName> - * - * where <TransformName> is one of - * RotationPivot - * RotationOffset - * PreRotation - * PostRotation - * ScalingPivot - * ScalingOffset - * Translation - * Scaling - * Rotation - **/ + * not directly be represented in assimp, additional dummy + * nodes will be generated. Note that settings this to false + * can make animation import a lot slower. + * + * The naming scheme for the generated nodes is: + * <OriginalName>_$AssimpFbx$_<TransformName> + * + * where <TransformName> is one of + * RotationPivot + * RotationOffset + * PreRotation + * PostRotation + * ScalingPivot + * ScalingOffset + * Translation + * Scaling + * Rotation + **/ bool preservePivots = true; /** do not import animation curves that specify a constant - * values matching the corresponding node transformation.*/ + * values matching the corresponding node transformation.*/ bool optimizeEmptyAnimationCurves = true; /** use legacy naming for embedded textures eg: (*0, *1, *2).*/ diff --git a/modules/fbx/fbx_parser/FBXMeshGeometry.h b/modules/fbx/fbx_parser/FBXMeshGeometry.h index c9b25f008d..26fc1914d1 100644 --- a/modules/fbx/fbx_parser/FBXMeshGeometry.h +++ b/modules/fbx/fbx_parser/FBXMeshGeometry.h @@ -226,7 +226,7 @@ public: const std::vector<Vector3> &GetVertices() const; /** Get a list of all vertex normals or an empty array if - * no normals are specified. */ + * no normals are specified. */ const std::vector<Vector3> &GetNormals() const; /** Return list of vertex indices. */ @@ -238,8 +238,8 @@ private: std::vector<unsigned int> m_indices; }; /** -* DOM class for FBX geometry of type "Line" -*/ + * DOM class for FBX geometry of type "Line" + */ class LineGeometry : public Geometry { public: /** The class constructor */ diff --git a/modules/fbx/fbx_parser/FBXParser.cpp b/modules/fbx/fbx_parser/FBXParser.cpp index d9ef025a16..dbc9a0e46d 100644 --- a/modules/fbx/fbx_parser/FBXParser.cpp +++ b/modules/fbx/fbx_parser/FBXParser.cpp @@ -660,13 +660,6 @@ void ParseVectorDataArray(std::vector<Vector3> &out, const ElementPtr el) { static_cast<real_t>(d[1]), static_cast<real_t>(d[2]))); } - // for debugging - /*for ( size_t i = 0; i < out.size(); i++ ) { - aiVector3D vec3( out[ i ] ); - std::stringstream stream; - stream << " vec3.x = " << vec3.x << " vec3.y = " << vec3.y << " vec3.z = " << vec3.z << std::endl; - DefaultLogger::get()->info( stream.str() ); - }*/ } else if (type == 'f') { const float *f = reinterpret_cast<const float *>(&buff[0]); for (unsigned int i = 0; i < count3; ++i, f += 3) { diff --git a/modules/fbx/fbx_parser/FBXParser.h b/modules/fbx/fbx_parser/FBXParser.h index 93836c2205..27db18bf8a 100644 --- a/modules/fbx/fbx_parser/FBXParser.h +++ b/modules/fbx/fbx_parser/FBXParser.h @@ -187,7 +187,7 @@ private: class Parser { public: /** Parse given a token list. Does not take ownership of the tokens - - * the objects must persist during the entire parser lifetime */ + * the objects must persist during the entire parser lifetime */ Parser(const TokenList &tokens, bool is_binary); ~Parser(); diff --git a/modules/fbx/fbx_parser/FBXProperties.cpp b/modules/fbx/fbx_parser/FBXProperties.cpp index 37717e9109..b8c0f685ac 100644 --- a/modules/fbx/fbx_parser/FBXProperties.cpp +++ b/modules/fbx/fbx_parser/FBXProperties.cpp @@ -114,12 +114,12 @@ PropertyPtr ReadTypedProperty(const ElementPtr element) { } else if (!strcmp(cs, "KTime")) { return new TypedProperty<int64_t>(ParseTokenAsInt64(tok[4])); } else if (!strcmp(cs, "Vector3D") || - !strcmp(cs, "ColorRGB") || - !strcmp(cs, "Vector") || - !strcmp(cs, "Color") || - !strcmp(cs, "Lcl Translation") || - !strcmp(cs, "Lcl Rotation") || - !strcmp(cs, "Lcl Scaling")) { + !strcmp(cs, "ColorRGB") || + !strcmp(cs, "Vector") || + !strcmp(cs, "Color") || + !strcmp(cs, "Lcl Translation") || + !strcmp(cs, "Lcl Rotation") || + !strcmp(cs, "Lcl Scaling")) { return new TypedProperty<Vector3>(Vector3( ParseTokenAsFloat(tok[4]), ParseTokenAsFloat(tok[5]), diff --git a/modules/fbx/fbx_parser/FBXUtil.cpp b/modules/fbx/fbx_parser/FBXUtil.cpp index 1f14a69099..df46bd85c7 100644 --- a/modules/fbx/fbx_parser/FBXUtil.cpp +++ b/modules/fbx/fbx_parser/FBXUtil.cpp @@ -169,10 +169,10 @@ char EncodeBase64(char byte) { } /** Encodes a block of 4 bytes to base64 encoding -* @param bytes Bytes to encode. -* @param out_string String to write encoded values to. -* @param string_pos Position in out_string. -*/ + * @param bytes Bytes to encode. + * @param out_string String to write encoded values to. + * @param string_pos Position in out_string. + */ void EncodeByteBlock(const char *bytes, std::string &out_string, size_t string_pos) { char b0 = (bytes[0] & 0xFC) >> 2; char b1 = (bytes[0] & 0x03) << 4 | ((bytes[1] & 0xF0) >> 4); diff --git a/modules/fbx/fbx_parser/FBXUtil.h b/modules/fbx/fbx_parser/FBXUtil.h index efc131831b..dab2a4201e 100644 --- a/modules/fbx/fbx_parser/FBXUtil.h +++ b/modules/fbx/fbx_parser/FBXUtil.h @@ -87,34 +87,34 @@ namespace Util { const char *TokenTypeString(TokenType t); /** Decode a single Base64-encoded character. -* -* @param ch Character to decode (from base64 to binary). -* @return decoded byte value*/ + * + * @param ch Character to decode (from base64 to binary). + * @return decoded byte value*/ uint8_t DecodeBase64(char ch); /** Compute decoded size of a Base64-encoded string -* -* @param in Characters to decode. -* @param inLength Number of characters to decode. -* @return size of the decoded data (number of bytes)*/ + * + * @param in Characters to decode. + * @param inLength Number of characters to decode. + * @return size of the decoded data (number of bytes)*/ size_t ComputeDecodedSizeBase64(const char *in, size_t inLength); /** Decode a Base64-encoded string -* -* @param in Characters to decode. -* @param inLength Number of characters to decode. -* @param out Pointer where we will store the decoded data. -* @param maxOutLength Size of output buffer. -* @return size of the decoded data (number of bytes)*/ + * + * @param in Characters to decode. + * @param inLength Number of characters to decode. + * @param out Pointer where we will store the decoded data. + * @param maxOutLength Size of output buffer. + * @return size of the decoded data (number of bytes)*/ size_t DecodeBase64(const char *in, size_t inLength, uint8_t *out, size_t maxOutLength); char EncodeBase64(char byte); /** Encode bytes in base64-encoding -* -* @param data Binary data to encode. -* @param inLength Number of bytes to encode. -* @return base64-encoded string*/ + * + * @param data Binary data to encode. + * @param inLength Number of bytes to encode. + * @return base64-encoded string*/ std::string EncodeBase64(const char *data, size_t length); } // namespace Util } // namespace FBXDocParser diff --git a/modules/fbx/register_types.cpp b/modules/fbx/register_types.cpp index a75da8f3a9..d5e520a060 100644 --- a/modules/fbx/register_types.cpp +++ b/modules/fbx/register_types.cpp @@ -35,7 +35,7 @@ #ifdef TOOLS_ENABLED static void _editor_init() { - Ref<EditorSceneImporterFBX> import_fbx; + Ref<EditorSceneFormatImporterFBX> import_fbx; import_fbx.instantiate(); ResourceImporterScene::get_singleton()->add_importer(import_fbx); } @@ -46,7 +46,7 @@ void register_fbx_types() { ClassDB::APIType prev_api = ClassDB::get_current_api(); ClassDB::set_current_api(ClassDB::API_EDITOR); - GDREGISTER_CLASS(EditorSceneImporterFBX); + GDREGISTER_CLASS(EditorSceneFormatImporterFBX); ClassDB::set_current_api(prev_api); diff --git a/modules/fbx/tools/import_utils.cpp b/modules/fbx/tools/import_utils.cpp index 66b0153308..bb95d120af 100644 --- a/modules/fbx/tools/import_utils.cpp +++ b/modules/fbx/tools/import_utils.cpp @@ -45,27 +45,27 @@ Basis ImportUtils::EulerToBasis(FBXDocParser::Model::RotOrder mode, const Vector // by simply invert its order: https://www.cs.utexas.edu/~theshark/courses/cs354/lectures/cs354-14.pdf switch (mode) { case FBXDocParser::Model::RotOrder_EulerXYZ: - ret.set_euler_zyx(p_rotation); + ret.set_euler(p_rotation, Basis::EULER_ORDER_XYZ); break; case FBXDocParser::Model::RotOrder_EulerXZY: - ret.set_euler_yzx(p_rotation); + ret.set_euler(p_rotation, Basis::EULER_ORDER_XZY); break; case FBXDocParser::Model::RotOrder_EulerYZX: - ret.set_euler_xzy(p_rotation); + ret.set_euler(p_rotation, Basis::EULER_ORDER_YZX); break; case FBXDocParser::Model::RotOrder_EulerYXZ: - ret.set_euler_zxy(p_rotation); + ret.set_euler(p_rotation, Basis::EULER_ORDER_YXZ); break; case FBXDocParser::Model::RotOrder_EulerZXY: - ret.set_euler_yxz(p_rotation); + ret.set_euler(p_rotation, Basis::EULER_ORDER_ZXY); break; case FBXDocParser::Model::RotOrder_EulerZYX: - ret.set_euler_xyz(p_rotation); + ret.set_euler(p_rotation, Basis::EULER_ORDER_ZYX); break; case FBXDocParser::Model::RotOrder_SphericXYZ: @@ -89,22 +89,22 @@ Vector3 ImportUtils::BasisToEuler(FBXDocParser::Model::RotOrder mode, const Basi // by simply invert its order: https://www.cs.utexas.edu/~theshark/courses/cs354/lectures/cs354-14.pdf switch (mode) { case FBXDocParser::Model::RotOrder_EulerXYZ: - return p_rotation.get_euler_zyx(); + return p_rotation.get_euler(Basis::EULER_ORDER_XYZ); case FBXDocParser::Model::RotOrder_EulerXZY: - return p_rotation.get_euler_yzx(); + return p_rotation.get_euler(Basis::EULER_ORDER_XZY); case FBXDocParser::Model::RotOrder_EulerYZX: - return p_rotation.get_euler_xzy(); + return p_rotation.get_euler(Basis::EULER_ORDER_YZX); case FBXDocParser::Model::RotOrder_EulerYXZ: - return p_rotation.get_euler_zxy(); + return p_rotation.get_euler(Basis::EULER_ORDER_YXZ); case FBXDocParser::Model::RotOrder_EulerZXY: - return p_rotation.get_euler_yxz(); + return p_rotation.get_euler(Basis::EULER_ORDER_ZXY); case FBXDocParser::Model::RotOrder_EulerZYX: - return p_rotation.get_euler_xyz(); + return p_rotation.get_euler(Basis::EULER_ORDER_ZYX); case FBXDocParser::Model::RotOrder_SphericXYZ: // TODO diff --git a/modules/fbx/tools/import_utils.h b/modules/fbx/tools/import_utils.h index fbe7dbd82f..88c71fb87e 100644 --- a/modules/fbx/tools/import_utils.h +++ b/modules/fbx/tools/import_utils.h @@ -43,7 +43,7 @@ /** * Import Utils * Conversion tools / glue code to convert from FBX to Godot -*/ + */ class ImportUtils { public: /// Convert a vector from degrees to radians. @@ -201,7 +201,7 @@ public: }; /** Get fbx fps for time mode meta data - */ + */ static float get_fbx_fps(int32_t time_mode) { switch (time_mode) { case AssetImportFbx::TIME_MODE_DEFAULT: @@ -258,13 +258,13 @@ public: } /** - * Find hardcoded textures from assimp which could be in many different directories - */ + * Find hardcoded textures from assimp which could be in many different directories + */ /** - * set_texture_mapping_mode - * Helper to check the mapping mode of the texture (repeat, clamp and mirror) - */ + * set_texture_mapping_mode + * Helper to check the mapping mode of the texture (repeat, clamp and mirror) + */ // static void set_texture_mapping_mode(aiTextureMapMode *map_mode, Ref<ImageTexture> texture) { // ERR_FAIL_COND(texture.is_null()); // ERR_FAIL_COND(map_mode == nullptr); @@ -282,9 +282,9 @@ public: // } /** - * Load or load from cache image :) - * We need to upgrade this in the later version :) should not be hard - */ + * Load or load from cache image :) + * We need to upgrade this in the later version :) should not be hard + */ //static Ref<Image> load_image(ImportState &state, const aiScene *p_scene, String p_path){ // Map<String, Ref<Image> >::Element *match = state.path_to_image_cache.find(p_path); diff --git a/modules/fbx/tools/validation_tools.h b/modules/fbx/tools/validation_tools.h index 906a721045..12d644ee94 100644 --- a/modules/fbx/tools/validation_tools.h +++ b/modules/fbx/tools/validation_tools.h @@ -53,9 +53,9 @@ protected: String csv_header = "file_path, error message, extra data\n"; massive_log_file += csv_header; - for (Map<String, LocalVector<String>>::Element *element = validation_entries.front(); element; element = element->next()) { - for (unsigned int x = 0; x < element->value().size(); x++) { - const String &line_entry = element->key() + ", " + element->value()[x].c_escape() + "\n"; + for (const KeyValue<String, LocalVector<String>> &element : validation_entries) { + for (unsigned int x = 0; x < element.value.size(); x++) { + const String &line_entry = element.key + ", " + element.value[x].c_escape() + "\n"; massive_log_file += line_entry; } } |