Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add saving flag hack to Skeleton and revert reset timing of animation #102026

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1913,14 +1913,12 @@ void EditorNode::_save_scene(String p_file, int idx) {
return;
}

List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups;
_reset_animation_mixers(scene, &anim_backups);

scene->propagate_notification(NOTIFICATION_EDITOR_PRE_SAVE);

editor_data.apply_changes_in_editors();
save_default_environment();

List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups;
_reset_animation_mixers(scene, &anim_backups);
_save_editor_states(p_file, idx);

Ref<PackedScene> sdata;
Expand Down
6 changes: 0 additions & 6 deletions scene/3d/retarget_modifier_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,6 @@ void RetargetModifier3D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_child_skeletons();
} break;
#ifdef TOOLS_ENABLED
case NOTIFICATION_EDITOR_PRE_SAVE: {
_reset_child_skeleton_poses();
_force_update_child_skeletons();
} break;
#endif // TOOLS_ENABLED
case NOTIFICATION_EXIT_TREE: {
_reset_child_skeletons();
} break;
Expand Down
4 changes: 4 additions & 0 deletions scene/3d/retarget_modifier_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class RetargetModifier3D : public SkeletonModifier3D {
void set_profile(Ref<SkeletonProfile> p_profile);
Ref<SkeletonProfile> get_profile() const;

#ifdef TOOLS_ENABLED
virtual bool is_processed_on_saving() const override { return true; }
#endif

RetargetModifier3D();
virtual ~RetargetModifier3D();
};
Expand Down
18 changes: 16 additions & 2 deletions scene/3d/skeleton_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ void Skeleton3D::_notification(int p_what) {
} break;
#ifdef TOOLS_ENABLED
case NOTIFICATION_EDITOR_PRE_SAVE: {
force_update_all_dirty_bones();
emit_signal(SceneStringName(skeleton_updated));
saving = true;
} break;
case NOTIFICATION_EDITOR_POST_SAVE: {
saving = false;
} break;
#endif // TOOLS_ENABLED
case NOTIFICATION_UPDATE_SKELETON: {
Expand Down Expand Up @@ -940,6 +942,13 @@ void Skeleton3D::_make_dirty() {

void Skeleton3D::_update_deferred(UpdateFlag p_update_flag) {
if (is_inside_tree()) {
#ifdef TOOLS_ENABLED
if (saving) {
update_flags |= p_update_flag;
_notification(NOTIFICATION_UPDATE_SKELETON);
return;
}
#endif //TOOLS_ENABLED
if (update_flags == UPDATE_FLAG_NONE && !updating) {
notify_deferred_thread_group(NOTIFICATION_UPDATE_SKELETON); // It must never be called more than once in a single frame.
}
Expand Down Expand Up @@ -1165,6 +1174,11 @@ void Skeleton3D::_process_modifiers() {
if (!mod) {
continue;
}
#ifdef TOOLS_ENABLED
if (saving && !mod->is_processed_on_saving()) {
continue;
}
#endif //TOOLS_ENABLED
real_t influence = mod->get_influence();
if (influence < 1.0) {
LocalVector<Transform3D> old_poses;
Expand Down
4 changes: 4 additions & 0 deletions scene/3d/skeleton_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ class SkinReference : public RefCounted {
class Skeleton3D : public Node3D {
GDCLASS(Skeleton3D, Node3D);

#ifdef TOOLS_ENABLED
bool saving = false;
#endif //TOOLS_ENABLED

#ifndef DISABLE_DEPRECATED
bool animate_physical_bones = true;
Node *simulator = nullptr;
Expand Down
4 changes: 4 additions & 0 deletions scene/3d/skeleton_modifier_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ class SkeletonModifier3D : public Node3D {
static Vector3 get_vector_from_axis(Vector3::Axis p_axis);
static Vector3::Axis get_axis_from_bone_axis(BoneAxis p_axis);

#ifdef TOOLS_ENABLED
virtual bool is_processed_on_saving() const { return false; }
#endif

SkeletonModifier3D();
};

Expand Down
10 changes: 0 additions & 10 deletions scene/3d/spring_bone_collision_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,3 @@ Vector3 SpringBoneCollision3D::collide(const Transform3D &p_center, float p_bone
Vector3 SpringBoneCollision3D::_collide(const Transform3D &p_center, float p_bone_radius, float p_bone_length, const Vector3 &p_current) const {
return Vector3(0, 0, 0);
}

#ifdef TOOLS_ENABLED
void SpringBoneCollision3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_EDITOR_PRE_SAVE: {
sync_pose();
} break;
}
}
#endif // TOOLS_ENABLED
3 changes: 0 additions & 3 deletions scene/3d/spring_bone_collision_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@ class SpringBoneCollision3D : public Node3D {

void _validate_property(PropertyInfo &p_property) const;
static void _bind_methods();
#ifdef TOOLS_ENABLED
virtual void _notification(int p_what);
#endif // TOOLS_ENABLED

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

Expand Down
13 changes: 13 additions & 0 deletions scene/3d/spring_bone_simulator_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,12 @@ void SpringBoneSimulator3D::_notification(int p_what) {
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
update_gizmos();
} break;
case NOTIFICATION_EDITOR_PRE_SAVE: {
saving = true;
} break;
case NOTIFICATION_EDITOR_POST_SAVE: {
saving = false;
} break;
#endif // TOOLS_ENABLED
}
}
Expand Down Expand Up @@ -1467,6 +1473,13 @@ void SpringBoneSimulator3D::_process_modification() {
}
_find_collisions();
_process_collisions();

#ifdef TOOLS_ENABLED
if (saving) {
return; // Collision position has been reset but we don't want to process simulating on saving. Abort.
}
#endif //TOOLS_ENABLED

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();
for (int i = 0; i < settings.size(); i++) {
_init_joints(skeleton, settings[i]);
Expand Down
8 changes: 8 additions & 0 deletions scene/3d/spring_bone_simulator_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
class SpringBoneSimulator3D : public SkeletonModifier3D {
GDCLASS(SpringBoneSimulator3D, SkeletonModifier3D);

#ifdef TOOLS_ENABLED
bool saving = false;
#endif //TOOLS_ENABLED

bool joints_dirty = false;

LocalVector<ObjectID> collisions; // To process collisions for sync position with skeleton.
Expand Down Expand Up @@ -274,6 +278,10 @@ class SpringBoneSimulator3D : public SkeletonModifier3D {

// To process manually.
void reset();

#ifdef TOOLS_ENABLED
virtual bool is_processed_on_saving() const override { return true; }
#endif
};

VARIANT_ENUM_CAST(SpringBoneSimulator3D::BoneDirection);
Expand Down