Merge pull request #96270 from TokageItLab/physical-bone-update
Fix physical bone update without simulating
This commit is contained in:
commit
3c58b64b07
2 changed files with 9 additions and 41 deletions
|
@ -285,11 +285,11 @@ void _pb_start_simulation(const PhysicalBoneSimulator3D *p_simulator, Node *p_no
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalBoneSimulator3D::physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones) {
|
void PhysicalBoneSimulator3D::physical_bones_start_simulation_on(const TypedArray<StringName> &p_bones) {
|
||||||
|
_pose_updated();
|
||||||
|
|
||||||
simulating = true;
|
simulating = true;
|
||||||
_reset_physical_bones_state();
|
_reset_physical_bones_state();
|
||||||
|
|
||||||
_pose_updated();
|
|
||||||
|
|
||||||
Vector<int> sim_bones;
|
Vector<int> sim_bones;
|
||||||
if (p_bones.size() > 0) {
|
if (p_bones.size() > 0) {
|
||||||
sim_bones.resize(p_bones.size());
|
sim_bones.resize(p_bones.size());
|
||||||
|
@ -357,47 +357,16 @@ void PhysicalBoneSimulator3D::_process_modification() {
|
||||||
if (!skeleton) {
|
if (!skeleton) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!enabled) {
|
ERR_FAIL_COND(skeleton->get_bone_count() != bones.size());
|
||||||
for (int i = 0; i < bones.size(); i++) {
|
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
||||||
if (bones[i].physical_bone) {
|
if (!bones[i].physical_bone) {
|
||||||
if (bones[i].physical_bone->is_simulating_physics() == false) {
|
continue;
|
||||||
bones[i].physical_bone->reset_to_rest_position();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
if (bones[i].physical_bone->is_simulating_physics() == false) {
|
||||||
ERR_FAIL_COND(skeleton->get_bone_count() != bones.size());
|
bones[i].physical_bone->reset_to_rest_position();
|
||||||
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
} else if (simulating) {
|
||||||
if (!bones[i].physical_bone) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
skeleton->set_bone_global_pose(i, bones[i].global_pose);
|
skeleton->set_bone_global_pose(i, bones[i].global_pose);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
|
||||||
// The above method is performance heavy and needs to be improved.
|
|
||||||
// Ideally, the processing of set_bone_global_pose within Skeleton3D should be improved,
|
|
||||||
// but the workaround available now is to convert the global pose to a local pose on the SkeletonModifier side.
|
|
||||||
// However, the follow method needs recursive processing for deformations within PhysicalBoneSimulator3D to account for update order.
|
|
||||||
/*
|
|
||||||
ERR_FAIL_COND(skeleton->get_bone_count() != bones.size());
|
|
||||||
LocalVector<Transform3D> local_poses;
|
|
||||||
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
|
||||||
Transform3D pt;
|
|
||||||
if (skeleton->get_bone_parent(i) >= 0) {
|
|
||||||
pt = get_bone_global_pose(skeleton->get_bone_parent(i));
|
|
||||||
}
|
|
||||||
local_poses.push_back(pt.affine_inverse() * bones[i].global_pose);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < skeleton->get_bone_count(); i++) {
|
|
||||||
if (!bones[i].physical_bone) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
skeleton->set_bone_pose_position(i, local_poses[i].origin);
|
|
||||||
skeleton->set_bone_pose_rotation(i, local_poses[i].basis.get_rotation_quaternion());
|
|
||||||
skeleton->set_bone_pose_scale(i, local_poses[i].basis.get_scale());
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@ class PhysicalBoneSimulator3D : public SkeletonModifier3D {
|
||||||
GDCLASS(PhysicalBoneSimulator3D, SkeletonModifier3D);
|
GDCLASS(PhysicalBoneSimulator3D, SkeletonModifier3D);
|
||||||
|
|
||||||
bool simulating = false;
|
bool simulating = false;
|
||||||
bool enabled = true;
|
|
||||||
|
|
||||||
struct SimulatedBone {
|
struct SimulatedBone {
|
||||||
int parent;
|
int parent;
|
||||||
|
|
Loading…
Reference in a new issue