Browse Source

Merge pull request #102026 from TokageItLab/fix-save-reset

Add saving flag hack to Skeleton and revert reset timing of animation
Thaddeus Crews 6 months ago
parent
commit
97c472e43f

+ 2 - 4
editor/editor_node.cpp

@@ -1941,14 +1941,12 @@ void EditorNode::_save_scene(String p_file, int idx) {
 		return;
 		return;
 	}
 	}
 
 
-	List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups;
-	_reset_animation_mixers(scene, &anim_backups);
-
 	scene->propagate_notification(NOTIFICATION_EDITOR_PRE_SAVE);
 	scene->propagate_notification(NOTIFICATION_EDITOR_PRE_SAVE);
 
 
 	editor_data.apply_changes_in_editors();
 	editor_data.apply_changes_in_editors();
 	save_default_environment();
 	save_default_environment();
-
+	List<Pair<AnimationMixer *, Ref<AnimatedValuesBackup>>> anim_backups;
+	_reset_animation_mixers(scene, &anim_backups);
 	_save_editor_states(p_file, idx);
 	_save_editor_states(p_file, idx);
 
 
 	Ref<PackedScene> sdata;
 	Ref<PackedScene> sdata;

+ 0 - 6
scene/3d/retarget_modifier_3d.cpp

@@ -465,12 +465,6 @@ void RetargetModifier3D::_notification(int p_what) {
 		case NOTIFICATION_ENTER_TREE: {
 		case NOTIFICATION_ENTER_TREE: {
 			_update_child_skeletons();
 			_update_child_skeletons();
 		} break;
 		} 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: {
 		case NOTIFICATION_EXIT_TREE: {
 			_reset_child_skeletons();
 			_reset_child_skeletons();
 		} break;
 		} break;

+ 4 - 0
scene/3d/retarget_modifier_3d.h

@@ -117,6 +117,10 @@ public:
 	void set_profile(Ref<SkeletonProfile> p_profile);
 	void set_profile(Ref<SkeletonProfile> p_profile);
 	Ref<SkeletonProfile> get_profile() const;
 	Ref<SkeletonProfile> get_profile() const;
 
 
+#ifdef TOOLS_ENABLED
+	virtual bool is_processed_on_saving() const override { return true; }
+#endif
+
 	RetargetModifier3D();
 	RetargetModifier3D();
 	virtual ~RetargetModifier3D();
 	virtual ~RetargetModifier3D();
 };
 };

+ 16 - 2
scene/3d/skeleton_3d.cpp

@@ -327,8 +327,10 @@ void Skeleton3D::_notification(int p_what) {
 		} break;
 		} break;
 #ifdef TOOLS_ENABLED
 #ifdef TOOLS_ENABLED
 		case NOTIFICATION_EDITOR_PRE_SAVE: {
 		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;
 		} break;
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED
 		case NOTIFICATION_UPDATE_SKELETON: {
 		case NOTIFICATION_UPDATE_SKELETON: {
@@ -940,6 +942,13 @@ void Skeleton3D::_make_dirty() {
 
 
 void Skeleton3D::_update_deferred(UpdateFlag p_update_flag) {
 void Skeleton3D::_update_deferred(UpdateFlag p_update_flag) {
 	if (is_inside_tree()) {
 	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) {
 		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.
 			notify_deferred_thread_group(NOTIFICATION_UPDATE_SKELETON); // It must never be called more than once in a single frame.
 		}
 		}
@@ -1165,6 +1174,11 @@ void Skeleton3D::_process_modifiers() {
 		if (!mod) {
 		if (!mod) {
 			continue;
 			continue;
 		}
 		}
+#ifdef TOOLS_ENABLED
+		if (saving && !mod->is_processed_on_saving()) {
+			continue;
+		}
+#endif //TOOLS_ENABLED
 		real_t influence = mod->get_influence();
 		real_t influence = mod->get_influence();
 		if (influence < 1.0) {
 		if (influence < 1.0) {
 			LocalVector<Transform3D> old_poses;
 			LocalVector<Transform3D> old_poses;

+ 4 - 0
scene/3d/skeleton_3d.h

@@ -66,6 +66,10 @@ public:
 class Skeleton3D : public Node3D {
 class Skeleton3D : public Node3D {
 	GDCLASS(Skeleton3D, Node3D);
 	GDCLASS(Skeleton3D, Node3D);
 
 
+#ifdef TOOLS_ENABLED
+	bool saving = false;
+#endif //TOOLS_ENABLED
+
 #ifndef DISABLE_DEPRECATED
 #ifndef DISABLE_DEPRECATED
 	bool animate_physical_bones = true;
 	bool animate_physical_bones = true;
 	Node *simulator = nullptr;
 	Node *simulator = nullptr;

+ 4 - 0
scene/3d/skeleton_modifier_3d.h

@@ -91,6 +91,10 @@ public:
 	static Vector3 get_vector_from_axis(Vector3::Axis p_axis);
 	static Vector3 get_vector_from_axis(Vector3::Axis p_axis);
 	static Vector3::Axis get_axis_from_bone_axis(BoneAxis 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();
 	SkeletonModifier3D();
 };
 };
 
 

+ 0 - 10
scene/3d/spring_bone_collision_3d.cpp

@@ -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 {
 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);
 	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

+ 0 - 3
scene/3d/spring_bone_collision_3d.h

@@ -47,9 +47,6 @@ protected:
 
 
 	void _validate_property(PropertyInfo &p_property) const;
 	void _validate_property(PropertyInfo &p_property) const;
 	static void _bind_methods();
 	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;
 	virtual Vector3 _collide(const Transform3D &p_center, float p_bone_radius, float p_bone_length, const Vector3 &p_current) const;
 
 

+ 13 - 0
scene/3d/spring_bone_simulator_3d.cpp

@@ -397,6 +397,12 @@ void SpringBoneSimulator3D::_notification(int p_what) {
 		case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
 		case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
 			update_gizmos();
 			update_gizmos();
 		} break;
 		} break;
+		case NOTIFICATION_EDITOR_PRE_SAVE: {
+			saving = true;
+		} break;
+		case NOTIFICATION_EDITOR_POST_SAVE: {
+			saving = false;
+		} break;
 #endif // TOOLS_ENABLED
 #endif // TOOLS_ENABLED
 	}
 	}
 }
 }
@@ -1467,6 +1473,13 @@ void SpringBoneSimulator3D::_process_modification() {
 	}
 	}
 	_find_collisions();
 	_find_collisions();
 	_process_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();
 	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++) {
 	for (int i = 0; i < settings.size(); i++) {
 		_init_joints(skeleton, settings[i]);
 		_init_joints(skeleton, settings[i]);

+ 8 - 0
scene/3d/spring_bone_simulator_3d.h

@@ -36,6 +36,10 @@
 class SpringBoneSimulator3D : public SkeletonModifier3D {
 class SpringBoneSimulator3D : public SkeletonModifier3D {
 	GDCLASS(SpringBoneSimulator3D, SkeletonModifier3D);
 	GDCLASS(SpringBoneSimulator3D, SkeletonModifier3D);
 
 
+#ifdef TOOLS_ENABLED
+	bool saving = false;
+#endif //TOOLS_ENABLED
+
 	bool joints_dirty = false;
 	bool joints_dirty = false;
 
 
 	LocalVector<ObjectID> collisions; // To process collisions for sync position with skeleton.
 	LocalVector<ObjectID> collisions; // To process collisions for sync position with skeleton.
@@ -273,6 +277,10 @@ public:
 
 
 	// To process manually.
 	// To process manually.
 	void reset();
 	void reset();
+
+#ifdef TOOLS_ENABLED
+	virtual bool is_processed_on_saving() const override { return true; }
+#endif
 };
 };
 
 
 VARIANT_ENUM_CAST(SpringBoneSimulator3D::BoneDirection);
 VARIANT_ENUM_CAST(SpringBoneSimulator3D::BoneDirection);