|
@@ -4860,7 +4860,7 @@ Error GLTFDocument::_serialize_animations(Ref<GLTFState> p_state) {
|
|
|
t["sampler"] = samplers.size();
|
|
|
Dictionary s;
|
|
|
Vector<real_t> times;
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
{
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
@@ -5902,7 +5902,8 @@ T GLTFDocument::_interpolate_track(const Vector<real_t> &p_times, const Vector<T
|
|
|
ERR_FAIL_V(p_values[0]);
|
|
|
}
|
|
|
|
|
|
-void GLTFDocument::_import_animation(Ref<GLTFState> 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 GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_animation_player, const GLTFAnimationIndex p_index, const bool p_trimming, const bool p_remove_immutable_tracks) {
|
|
|
+ ERR_FAIL_COND(p_state.is_null());
|
|
|
Ref<GLTFAnimation> anim = p_state->animations[p_index];
|
|
|
|
|
|
String anim_name = anim->get_name();
|
|
@@ -5914,7 +5915,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_
|
|
|
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);
|
|
@@ -6081,7 +6082,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const double increment = 1.0 / p_bake_fps;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = anim_start;
|
|
|
|
|
|
Vector3 base_pos;
|
|
@@ -6158,7 +6159,7 @@ void GLTFDocument::_import_animation(Ref<GLTFState> p_state, AnimationPlayer *p_
|
|
|
}
|
|
|
} else {
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / p_bake_fps;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6372,7 +6373,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
p_track.scale_track.times.clear();
|
|
|
p_track.scale_track.values.clear();
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6407,7 +6408,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
p_track.position_track.times.clear();
|
|
|
p_track.position_track.values.clear();
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6442,7 +6443,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
p_track.rotation_track.times.clear();
|
|
|
p_track.rotation_track.values.clear();
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6482,7 +6483,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
p_track.position_track.times.clear();
|
|
|
p_track.position_track.values.clear();
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6515,7 +6516,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
p_track.rotation_track.times.clear();
|
|
|
p_track.rotation_track.values.clear();
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6551,7 +6552,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
p_track.scale_track.times.clear();
|
|
|
p_track.scale_track.values.clear();
|
|
|
// CATMULLROMSPLINE or CUBIC_SPLINE have to be baked, apologies.
|
|
|
- const double increment = 1.0 / BAKE_FPS;
|
|
|
+ const double increment = 1.0 / p_state->get_bake_fps();
|
|
|
double time = 0.0;
|
|
|
bool last = false;
|
|
|
while (true) {
|
|
@@ -6577,14 +6578,14 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
}
|
|
|
}
|
|
|
} else if (track_type == Animation::TYPE_BEZIER) {
|
|
|
- const int32_t keys = anim_end * BAKE_FPS;
|
|
|
+ const int32_t keys = anim_end * p_state->get_bake_fps();
|
|
|
if (path.contains(":scale")) {
|
|
|
if (!p_track.scale_track.times.size()) {
|
|
|
p_track.scale_track.interpolation = gltf_interpolation;
|
|
|
Vector<real_t> new_times;
|
|
|
new_times.resize(keys);
|
|
|
for (int32_t key_i = 0; key_i < keys; key_i++) {
|
|
|
- new_times.write[key_i] = key_i / BAKE_FPS;
|
|
|
+ new_times.write[key_i] = key_i / p_state->get_bake_fps();
|
|
|
}
|
|
|
p_track.scale_track.times = new_times;
|
|
|
|
|
@@ -6597,11 +6598,11 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
for (int32_t key_i = 0; key_i < keys; key_i++) {
|
|
|
Vector3 bezier_track = p_track.scale_track.values[key_i];
|
|
|
if (path.contains(":scale:x")) {
|
|
|
- bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":scale:y")) {
|
|
|
- bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":scale:z")) {
|
|
|
- bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
}
|
|
|
p_track.scale_track.values.write[key_i] = bezier_track;
|
|
|
}
|
|
@@ -6612,7 +6613,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
Vector<real_t> new_times;
|
|
|
new_times.resize(keys);
|
|
|
for (int32_t key_i = 0; key_i < keys; key_i++) {
|
|
|
- new_times.write[key_i] = key_i / BAKE_FPS;
|
|
|
+ new_times.write[key_i] = key_i / p_state->get_bake_fps();
|
|
|
}
|
|
|
p_track.position_track.times = new_times;
|
|
|
|
|
@@ -6622,11 +6623,11 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
for (int32_t key_i = 0; key_i < keys; key_i++) {
|
|
|
Vector3 bezier_track = p_track.position_track.values[key_i];
|
|
|
if (path.contains(":position:x")) {
|
|
|
- bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":position:y")) {
|
|
|
- bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":position:z")) {
|
|
|
- bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
}
|
|
|
p_track.position_track.values.write[key_i] = bezier_track;
|
|
|
}
|
|
@@ -6636,7 +6637,7 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
Vector<real_t> new_times;
|
|
|
new_times.resize(keys);
|
|
|
for (int32_t key_i = 0; key_i < keys; key_i++) {
|
|
|
- new_times.write[key_i] = key_i / BAKE_FPS;
|
|
|
+ new_times.write[key_i] = key_i / p_state->get_bake_fps();
|
|
|
}
|
|
|
p_track.rotation_track.times = new_times;
|
|
|
|
|
@@ -6645,13 +6646,13 @@ GLTFAnimation::Track GLTFDocument::_convert_animation_track(Ref<GLTFState> p_sta
|
|
|
for (int32_t key_i = 0; key_i < keys; key_i++) {
|
|
|
Quaternion bezier_track = p_track.rotation_track.values[key_i];
|
|
|
if (path.contains(":rotation:x")) {
|
|
|
- bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.x = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":rotation:y")) {
|
|
|
- bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.y = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":rotation:z")) {
|
|
|
- bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.z = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
} else if (path.contains(":rotation:w")) {
|
|
|
- bezier_track.w = p_animation->bezier_track_interpolate(p_track_i, key_i / BAKE_FPS);
|
|
|
+ bezier_track.w = p_animation->bezier_track_interpolate(p_track_i, key_i / p_state->get_bake_fps());
|
|
|
}
|
|
|
p_track.rotation_track.values.write[key_i] = bezier_track;
|
|
|
}
|
|
@@ -7305,6 +7306,7 @@ Node *GLTFDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, boo
|
|
|
ERR_FAIL_NULL_V(state, nullptr);
|
|
|
ERR_FAIL_INDEX_V(0, state->root_nodes.size(), nullptr);
|
|
|
Error err = OK;
|
|
|
+ p_state->set_bake_fps(p_bake_fps);
|
|
|
Node *root = _generate_scene_node_tree(state);
|
|
|
ERR_FAIL_NULL_V(root, nullptr);
|
|
|
_process_mesh_instances(state, root);
|
|
@@ -7313,7 +7315,7 @@ Node *GLTFDocument::generate_scene(Ref<GLTFState> p_state, float p_bake_fps, boo
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
for (KeyValue<GLTFNodeIndex, Node *> E : state->scene_nodes) {
|