Skip to content

Commit 97c472e

Browse files
committed
Merge pull request godotengine#102026 from TokageItLab/fix-save-reset
Add saving flag hack to Skeleton and revert reset timing of animation
2 parents 5f4a0be + cb70853 commit 97c472e

10 files changed

+51
-25
lines changed

editor/editor_node.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,14 +1941,12 @@ void EditorNode::_save_scene(String p_file, int idx) {
19411941
return;
19421942
}
19431943

1944-
List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups;
1945-
_reset_animation_mixers(scene, &anim_backups);
1946-
19471944
scene->propagate_notification(NOTIFICATION_EDITOR_PRE_SAVE);
19481945

19491946
editor_data.apply_changes_in_editors();
19501947
save_default_environment();
1951-
1948+
List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups;
1949+
_reset_animation_mixers(scene, &anim_backups);
19521950
_save_editor_states(p_file, idx);
19531951

19541952
Ref<PackedScene> sdata;

scene/3d/retarget_modifier_3d.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -465,12 +465,6 @@ void RetargetModifier3D::_notification(int p_what) {
465465
case NOTIFICATION_ENTER_TREE: {
466466
_update_child_skeletons();
467467
} break;
468-
#ifdef TOOLS_ENABLED
469-
case NOTIFICATION_EDITOR_PRE_SAVE: {
470-
_reset_child_skeleton_poses();
471-
_force_update_child_skeletons();
472-
} break;
473-
#endif // TOOLS_ENABLED
474468
case NOTIFICATION_EXIT_TREE: {
475469
_reset_child_skeletons();
476470
} break;

scene/3d/retarget_modifier_3d.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ class RetargetModifier3D : public SkeletonModifier3D {
117117
void set_profile(Ref<SkeletonProfile> p_profile);
118118
Ref<SkeletonProfile> get_profile() const;
119119

120+
#ifdef TOOLS_ENABLED
121+
virtual bool is_processed_on_saving() const override { return true; }
122+
#endif
123+
120124
RetargetModifier3D();
121125
virtual ~RetargetModifier3D();
122126
};

scene/3d/skeleton_3d.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,10 @@ void Skeleton3D::_notification(int p_what) {
327327
} break;
328328
#ifdef TOOLS_ENABLED
329329
case NOTIFICATION_EDITOR_PRE_SAVE: {
330-
force_update_all_dirty_bones();
331-
emit_signal(SceneStringName(skeleton_updated));
330+
saving = true;
331+
} break;
332+
case NOTIFICATION_EDITOR_POST_SAVE: {
333+
saving = false;
332334
} break;
333335
#endif // TOOLS_ENABLED
334336
case NOTIFICATION_UPDATE_SKELETON: {
@@ -940,6 +942,13 @@ void Skeleton3D::_make_dirty() {
940942

941943
void Skeleton3D::_update_deferred(UpdateFlag p_update_flag) {
942944
if (is_inside_tree()) {
945+
#ifdef TOOLS_ENABLED
946+
if (saving) {
947+
update_flags |= p_update_flag;
948+
_notification(NOTIFICATION_UPDATE_SKELETON);
949+
return;
950+
}
951+
#endif //TOOLS_ENABLED
943952
if (update_flags == UPDATE_FLAG_NONE && !updating) {
944953
notify_deferred_thread_group(NOTIFICATION_UPDATE_SKELETON); // It must never be called more than once in a single frame.
945954
}
@@ -1165,6 +1174,11 @@ void Skeleton3D::_process_modifiers() {
11651174
if (!mod) {
11661175
continue;
11671176
}
1177+
#ifdef TOOLS_ENABLED
1178+
if (saving && !mod->is_processed_on_saving()) {
1179+
continue;
1180+
}
1181+
#endif //TOOLS_ENABLED
11681182
real_t influence = mod->get_influence();
11691183
if (influence < 1.0) {
11701184
LocalVector<Transform3D> old_poses;

scene/3d/skeleton_3d.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ class SkinReference : public RefCounted {
6666
class Skeleton3D : public Node3D {
6767
GDCLASS(Skeleton3D, Node3D);
6868

69+
#ifdef TOOLS_ENABLED
70+
bool saving = false;
71+
#endif //TOOLS_ENABLED
72+
6973
#ifndef DISABLE_DEPRECATED
7074
bool animate_physical_bones = true;
7175
Node *simulator = nullptr;

scene/3d/skeleton_modifier_3d.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ class SkeletonModifier3D : public Node3D {
9191
static Vector3 get_vector_from_axis(Vector3::Axis p_axis);
9292
static Vector3::Axis get_axis_from_bone_axis(BoneAxis p_axis);
9393

94+
#ifdef TOOLS_ENABLED
95+
virtual bool is_processed_on_saving() const { return false; }
96+
#endif
97+
9498
SkeletonModifier3D();
9599
};
96100

scene/3d/spring_bone_collision_3d.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,3 @@ Vector3 SpringBoneCollision3D::collide(const Transform3D &p_center, float p_bone
180180
Vector3 SpringBoneCollision3D::_collide(const Transform3D &p_center, float p_bone_radius, float p_bone_length, const Vector3 &p_current) const {
181181
return Vector3(0, 0, 0);
182182
}
183-
184-
#ifdef TOOLS_ENABLED
185-
void SpringBoneCollision3D::_notification(int p_what) {
186-
switch (p_what) {
187-
case NOTIFICATION_EDITOR_PRE_SAVE: {
188-
sync_pose();
189-
} break;
190-
}
191-
}
192-
#endif // TOOLS_ENABLED

scene/3d/spring_bone_collision_3d.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ class SpringBoneCollision3D : public Node3D {
4747

4848
void _validate_property(PropertyInfo &p_property) const;
4949
static void _bind_methods();
50-
#ifdef TOOLS_ENABLED
51-
virtual void _notification(int p_what);
52-
#endif // TOOLS_ENABLED
5350

5451
virtual Vector3 _collide(const Transform3D &p_center, float p_bone_radius, float p_bone_length, const Vector3 &p_current) const;
5552

scene/3d/spring_bone_simulator_3d.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,12 @@ void SpringBoneSimulator3D::_notification(int p_what) {
397397
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
398398
update_gizmos();
399399
} break;
400+
case NOTIFICATION_EDITOR_PRE_SAVE: {
401+
saving = true;
402+
} break;
403+
case NOTIFICATION_EDITOR_POST_SAVE: {
404+
saving = false;
405+
} break;
400406
#endif // TOOLS_ENABLED
401407
}
402408
}
@@ -1467,6 +1473,13 @@ void SpringBoneSimulator3D::_process_modification() {
14671473
}
14681474
_find_collisions();
14691475
_process_collisions();
1476+
1477+
#ifdef TOOLS_ENABLED
1478+
if (saving) {
1479+
return; // Collision position has been reset but we don't want to process simulating on saving. Abort.
1480+
}
1481+
#endif //TOOLS_ENABLED
1482+
14701483
double delta = skeleton->get_modifier_callback_mode_process() == Skeleton3D::MODIFIER_CALLBACK_MODE_PROCESS_IDLE ? skeleton->get_process_delta_time() : skeleton->get_physics_process_delta_time();
14711484
for (int i = 0; i < settings.size(); i++) {
14721485
_init_joints(skeleton, settings[i]);

scene/3d/spring_bone_simulator_3d.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
class SpringBoneSimulator3D : public SkeletonModifier3D {
3737
GDCLASS(SpringBoneSimulator3D, SkeletonModifier3D);
3838

39+
#ifdef TOOLS_ENABLED
40+
bool saving = false;
41+
#endif //TOOLS_ENABLED
42+
3943
bool joints_dirty = false;
4044

4145
LocalVector<ObjectID> collisions; // To process collisions for sync position with skeleton.
@@ -273,6 +277,10 @@ class SpringBoneSimulator3D : public SkeletonModifier3D {
273277

274278
// To process manually.
275279
void reset();
280+
281+
#ifdef TOOLS_ENABLED
282+
virtual bool is_processed_on_saving() const override { return true; }
283+
#endif
276284
};
277285

278286
VARIANT_ENUM_CAST(SpringBoneSimulator3D::BoneDirection);

0 commit comments

Comments
 (0)