summaryrefslogtreecommitdiffstats
path: root/modules/fbx/fbx_document.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'modules/fbx/fbx_document.cpp')
-rw-r--r--modules/fbx/fbx_document.cpp32
1 files changed, 14 insertions, 18 deletions
diff --git a/modules/fbx/fbx_document.cpp b/modules/fbx/fbx_document.cpp
index 1361e871de..ce097092fb 100644
--- a/modules/fbx/fbx_document.cpp
+++ b/modules/fbx/fbx_document.cpp
@@ -288,14 +288,8 @@ String FBXDocument::_gen_unique_name(HashSet<String> &unique_names, const String
}
String FBXDocument::_sanitize_animation_name(const String &p_name) {
- // Animations disallow the normal node invalid characters as well as "," and "["
- // (See animation/animation_player.cpp::add_animation)
-
- // TODO: Consider adding invalid_characters or a validate_animation_name to animation_player to mirror Node.
String anim_name = p_name.validate_node_name();
- anim_name = anim_name.replace(",", "");
- anim_name = anim_name.replace("[", "");
- return anim_name;
+ return AnimationLibrary::validate_library_name(anim_name);
}
String FBXDocument::_gen_unique_animation_name(Ref<FBXState> p_state, const String &p_name) {
@@ -875,7 +869,7 @@ Error FBXDocument::_parse_meshes(Ref<FBXState> p_state) {
const int material = int(fbx_material->typed_id);
ERR_FAIL_INDEX_V(material, p_state->materials.size(), ERR_FILE_CORRUPT);
Ref<Material> mat3d = p_state->materials[material];
- ERR_FAIL_NULL_V(mat3d, ERR_FILE_CORRUPT);
+ ERR_FAIL_COND_V(mat3d.is_null(), ERR_FILE_CORRUPT);
Ref<BaseMaterial3D> base_material = mat3d;
if (has_vertex_color && base_material.is_valid()) {
@@ -891,7 +885,7 @@ Error FBXDocument::_parse_meshes(Ref<FBXState> p_state) {
}
mat = mat3d;
}
- ERR_FAIL_NULL_V(mat, ERR_FILE_CORRUPT);
+ ERR_FAIL_COND_V(mat.is_null(), ERR_FILE_CORRUPT);
mat_name = mat->get_name();
}
import_mesh->add_surface(primitive, array, morphs,
@@ -1056,7 +1050,7 @@ GLTFImageIndex FBXDocument::_parse_image_save_image(Ref<FBXState> p_state, const
}
Error FBXDocument::_parse_images(Ref<FBXState> p_state, const String &p_base_path) {
- ERR_FAIL_NULL_V(p_state, ERR_INVALID_PARAMETER);
+ ERR_FAIL_COND_V(p_state.is_null(), ERR_INVALID_PARAMETER);
const ufbx_scene *fbx_scene = p_state->scene.get();
for (int texture_i = 0; texture_i < static_cast<int>(fbx_scene->texture_files.count); texture_i++) {
@@ -1381,6 +1375,10 @@ Error FBXDocument::_parse_animations(Ref<FBXState> p_state) {
additional_data["time_end"] = fbx_anim_stack->time_end;
animation->set_additional_data("GODOT_animation_time_begin_time_end", additional_data);
ufbx_bake_opts opts = {};
+ opts.resample_rate = p_state->get_bake_fps();
+ opts.minimum_sample_rate = p_state->get_bake_fps();
+ opts.max_keyframe_segments = 1024;
+
ufbx_error error;
ufbx_unique_ptr<ufbx_baked_anim> fbx_baked_anim{ ufbx_bake_anim(fbx_scene, fbx_anim_stack->anim, &opts, &error) };
if (!fbx_baked_anim) {
@@ -1759,7 +1757,7 @@ void FBXDocument::_generate_skeleton_bone_node(Ref<FBXState> p_state, const GLTF
}
}
-void FBXDocument::_import_animation(Ref<FBXState> p_state, AnimationPlayer *p_animation_player, const GLTFAnimationIndex p_index, const float p_bake_fps, const bool p_trimming, const bool p_remove_immutable_tracks) {
+void FBXDocument::_import_animation(Ref<FBXState> p_state, AnimationPlayer *p_animation_player, const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks) {
Ref<GLTFAnimation> anim = p_state->animations[p_index];
String anim_name = anim->get_name();
@@ -1771,7 +1769,7 @@ void FBXDocument::_import_animation(Ref<FBXState> p_state, AnimationPlayer *p_an
Ref<Animation> animation;
animation.instantiate();
animation->set_name(anim_name);
- animation->set_step(1.0 / p_bake_fps);
+ animation->set_step(1.0 / p_state->get_bake_fps());
if (anim->get_loop()) {
animation->set_loop_mode(Animation::LOOP_LINEAR);
@@ -2013,6 +2011,7 @@ void FBXDocument::_process_mesh_instances(Ref<FBXState> p_state, Node *p_scene_r
ERR_CONTINUE_MSG(skeleton == nullptr, vformat("Unable to find Skeleton for node %d skin %d", node_i, skin_i));
mi->get_parent()->remove_child(mi);
+ mi->set_owner(nullptr);
skeleton->add_child(mi, true);
mi->set_owner(skeleton->get_owner());
@@ -2110,14 +2109,11 @@ Error FBXDocument::_parse(Ref<FBXState> p_state, String p_path, Ref<FileAccess>
return OK;
}
-void FBXDocument::_bind_methods() {
-}
-
Node *FBXDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool p_trimming, bool p_remove_immutable_tracks) {
Ref<FBXState> state = p_state;
ERR_FAIL_COND_V(state.is_null(), nullptr);
- ERR_FAIL_NULL_V(state, nullptr);
ERR_FAIL_INDEX_V(0, state->root_nodes.size(), nullptr);
+ p_state->set_bake_fps(p_bake_fps);
GLTFNodeIndex fbx_root = state->root_nodes.write[0];
Node *fbx_root_node = state->get_scene_node(fbx_root);
Node *root = fbx_root_node;
@@ -2131,7 +2127,7 @@ Node *FBXDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, bool
root->add_child(ap, true);
ap->set_owner(root);
for (int i = 0; i < state->animations.size(); i++) {
- _import_animation(state, ap, i, p_bake_fps, p_trimming, p_remove_immutable_tracks);
+ _import_animation(state, ap, i, p_trimming, p_remove_immutable_tracks);
}
}
ERR_FAIL_NULL_V(root, nullptr);
@@ -2243,7 +2239,7 @@ Error FBXDocument::append_from_file(String p_path, Ref<GLTFState> p_state, uint3
Error err;
Ref<FileAccess> file = FileAccess::open(p_path, FileAccess::READ, &err);
ERR_FAIL_COND_V(err != OK, ERR_FILE_CANT_OPEN);
- ERR_FAIL_NULL_V(file, ERR_FILE_CANT_OPEN);
+ ERR_FAIL_COND_V(file.is_null(), ERR_FILE_CANT_OPEN);
String base_path = p_base_path;
if (base_path.is_empty()) {
base_path = p_path.get_base_dir();