Merge pull request #90517 from TokageItLab/cache-bones-mod
Static allocation bones copy for SkeletonModifier
This commit is contained in:
commit
a5d4ddc18a
@ -264,6 +264,8 @@ void Skeleton3D::_update_process_order() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bones_backup.resize(bones.size());
|
||||||
|
|
||||||
process_order_dirty = false;
|
process_order_dirty = false;
|
||||||
|
|
||||||
emit_signal("bone_list_changed");
|
emit_signal("bone_list_changed");
|
||||||
@ -310,19 +312,10 @@ void Skeleton3D::_notification(int p_what) {
|
|||||||
|
|
||||||
// Process modifiers.
|
// Process modifiers.
|
||||||
_find_modifiers();
|
_find_modifiers();
|
||||||
LocalVector<Transform3D> current_bone_poses;
|
|
||||||
LocalVector<Vector3> current_pose_positions;
|
|
||||||
LocalVector<Quaternion> current_pose_rotations;
|
|
||||||
LocalVector<Vector3> current_pose_scales;
|
|
||||||
LocalVector<Transform3D> current_bone_global_poses;
|
|
||||||
if (!modifiers.is_empty()) {
|
if (!modifiers.is_empty()) {
|
||||||
// Store unmodified bone poses.
|
// Store unmodified bone poses.
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < bones.size(); i++) {
|
||||||
current_bone_poses.push_back(bones[i].pose_cache);
|
bones_backup[i].save(bones[i]);
|
||||||
current_pose_positions.push_back(bones[i].pose_position);
|
|
||||||
current_pose_rotations.push_back(bones[i].pose_rotation);
|
|
||||||
current_pose_scales.push_back(bones[i].pose_scale);
|
|
||||||
current_bone_global_poses.push_back(bones[i].global_pose);
|
|
||||||
}
|
}
|
||||||
_process_modifiers();
|
_process_modifiers();
|
||||||
}
|
}
|
||||||
@ -388,12 +381,8 @@ void Skeleton3D::_notification(int p_what) {
|
|||||||
|
|
||||||
if (!modifiers.is_empty()) {
|
if (!modifiers.is_empty()) {
|
||||||
// Restore unmodified bone poses.
|
// Restore unmodified bone poses.
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < bones.size(); i++) {
|
||||||
bonesptr[i].pose_cache = current_bone_poses[i];
|
bones_backup[i].restore(bones.write[i]);
|
||||||
bonesptr[i].pose_position = current_pose_positions[i];
|
|
||||||
bonesptr[i].pose_rotation = current_pose_rotations[i];
|
|
||||||
bonesptr[i].pose_scale = current_pose_scales[i];
|
|
||||||
bonesptr[i].global_pose = current_bone_global_poses[i];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,15 +88,15 @@ private:
|
|||||||
struct Bone {
|
struct Bone {
|
||||||
String name;
|
String name;
|
||||||
|
|
||||||
int parent;
|
int parent = -1;
|
||||||
Vector<int> child_bones;
|
Vector<int> child_bones;
|
||||||
|
|
||||||
Transform3D rest;
|
Transform3D rest;
|
||||||
Transform3D global_rest;
|
Transform3D global_rest;
|
||||||
|
|
||||||
bool enabled;
|
bool enabled = true;
|
||||||
Transform3D pose_cache;
|
|
||||||
bool pose_cache_dirty = true;
|
bool pose_cache_dirty = true;
|
||||||
|
Transform3D pose_cache;
|
||||||
Vector3 pose_position;
|
Vector3 pose_position;
|
||||||
Quaternion pose_rotation;
|
Quaternion pose_rotation;
|
||||||
Vector3 pose_scale = Vector3(1, 1, 1);
|
Vector3 pose_scale = Vector3(1, 1, 1);
|
||||||
@ -116,15 +116,29 @@ private:
|
|||||||
bool global_pose_override_reset = false;
|
bool global_pose_override_reset = false;
|
||||||
Transform3D global_pose_override;
|
Transform3D global_pose_override;
|
||||||
#endif // _DISABLE_DEPRECATED
|
#endif // _DISABLE_DEPRECATED
|
||||||
|
};
|
||||||
|
|
||||||
Bone() {
|
struct BonePoseBackup {
|
||||||
parent = -1;
|
Transform3D pose_cache;
|
||||||
child_bones = Vector<int>();
|
Vector3 pose_position;
|
||||||
enabled = true;
|
Quaternion pose_rotation;
|
||||||
#ifndef DISABLE_DEPRECATED
|
Vector3 pose_scale = Vector3(1, 1, 1);
|
||||||
global_pose_override_amount = 0;
|
Transform3D global_pose;
|
||||||
global_pose_override_reset = false;
|
|
||||||
#endif // _DISABLE_DEPRECATED
|
void save(const Bone &p_bone) {
|
||||||
|
pose_cache = p_bone.pose_cache;
|
||||||
|
pose_position = p_bone.pose_position;
|
||||||
|
pose_rotation = p_bone.pose_rotation;
|
||||||
|
pose_scale = p_bone.pose_scale;
|
||||||
|
global_pose = p_bone.global_pose;
|
||||||
|
}
|
||||||
|
|
||||||
|
void restore(Bone &r_bone) {
|
||||||
|
r_bone.pose_cache = pose_cache;
|
||||||
|
r_bone.pose_position = pose_position;
|
||||||
|
r_bone.pose_rotation = pose_rotation;
|
||||||
|
r_bone.pose_scale = pose_scale;
|
||||||
|
r_bone.global_pose = global_pose;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -156,6 +170,7 @@ private:
|
|||||||
void _process_modifiers();
|
void _process_modifiers();
|
||||||
void _process_changed();
|
void _process_changed();
|
||||||
void _make_modifiers_dirty();
|
void _make_modifiers_dirty();
|
||||||
|
LocalVector<BonePoseBackup> bones_backup;
|
||||||
|
|
||||||
#ifndef DISABLE_DEPRECATED
|
#ifndef DISABLE_DEPRECATED
|
||||||
void _add_bone_bind_compat_88791(const String &p_name);
|
void _add_bone_bind_compat_88791(const String &p_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user