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

Physical skeleton improvement and bug fix #28909

Closed
wants to merge 1 commit into from

Conversation

AndreaCatania
Copy link
Contributor

This PR is a rework of the physical bone that aim to fix all the current open issues and also improve the current Physical Bone by adding stability and control.

The current Physical Bone implementation is using the normal rigid bodies and joints, and it works good but it become unstable if the complexity of the skeleton is not trivial, for this reason the Featherstone algorithm got implemented thus allowing to have not only stable body but also full control of it.

When I talk about control I mean that with this PR is not only possible to create ragdoll of not animated body but is also possible control its movement by adding forces like the following:

ezgif com-video-to-gif

This dummy is not animated using the animator, but it's animated controlling the motor of each bone, and the responsible code is simply:

func _process(delta):

	if Input.is_action_just_pressed("push"):

		left_arm.motor_set_rotation_target(Vector3(0, 0, 90))
		right_arm.motor_set_rotation_target(Vector3(0, 0, 90))
		left_forearm.motor_set_position_target(0)
		right_forearm.motor_set_position_target(0)

	elif Input.is_action_just_released("push"):

		left_arm.motor_set_rotation_target(Vector3(0, 0, 0))
		right_arm.motor_set_rotation_target(Vector3(0, 0, 0))
		left_forearm.motor_set_position_target(120)
		right_forearm.motor_set_position_target(120)

You don't have to deal with complex force system, but instead you can control it just by changing motor target and or velocity and some other parameters from the editor.

Thanks to this new PR is now possible to create, the a lot discussed, active ragdoll directly in GDscript, or is possible to create a completely physical walking robot, or simply is possible to have a stable ragdoll with dumpers and springs.

But test it yourself to see the new features, and if you want you can use this project that I've to used to develop this new feature:
Multibody.zip

This PR Fix:
Fixes #28707
Fixes #26618
Fixes #25564
Fixes #24968
Fixes #22823
Fixes #19002

@@ -343,6 +343,7 @@ void btMultiBody::finalizeMultiDof()
m_deltaV.resize(6 + m_dofCount);
m_realBuf.resize(6 + m_dofCount + m_dofCount * m_dofCount + 6 + m_dofCount); //m_dofCount for joint-space vels + m_dofCount^2 for "D" matrices + delta-pos vector (6 base "vels" + joint "vels")
m_vectorBuf.resize(2 * m_dofCount); //two 3-vectors (i.e. one six-vector) for each system dof ("h" matrices)
m_matrixBuf.resize(m_links.size() + 1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this change needed? It should also be PR'ed upstream if it's a bugfix.
Merging that also means that we're no longer compatible with Bullet 2.88 which is the current stable release, so if we can handle this on our end without modifying Bullet for now, that would be best.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope is not possible to manage it internally, I did a PR on the Bullet side also: bulletphysics/bullet3#2236 but in order to be able to use it ASAP I did it in this way

@Zireael07
Copy link
Contributor

@AndreaCatania: I saw you showcase ragdoll/skeleton with this dummy, where can we get the assets? Is it on the asset lib? Getting skeletons working with Blender -> Godot can be tricky, it would be great to have an easily available working sample...

@AndreaCatania
Copy link
Contributor Author

@Zireael07 do you mean that you want to try it by yourself?
If yes, is the attached project not working?
If not, sorry but I didn't understood what you mean, can you please rephrase the question?

@Zireael07
Copy link
Contributor

I mean I could never get the skeleton exported from Blender to work, so if your dummy asset were generally available on the asset lib, it would be easier for people to get started with skeletons in Godot.

It is just a tangential question since I saw you demo'ing various skeleton stuff with always the same dummy, the dummy is therefore guaranteed to work.

@AndreaCatania
Copy link
Contributor Author

Oh ok, To be fair this is where you can download it: https://www.mixamo.com/ and for this precise work I've used the skeleton from this guy: #28707 but yes indeed would be useful to make the skeleton import more easy.

I'll try to look on that in the next days

@mysticfall
Copy link
Contributor

I'm trying to test this branch but getting the following error when I run my project. Could you give me some help to resolve this problem?

E 0:00:02:0315   This multi body can't be removed from non multi body world
  <C Source>     modules/bullet/space_bullet.cpp:518 @ remove_armature()

akien-mga added a commit to AndreaCatania/godot that referenced this pull request Jun 11, 2019
This updates our local copy to commit 5ec8339b6fc491e3f09a34a4516e82787f053fcc.
We need a recent master commit for some new features that we use in Godot
(see godotengine#25543 and godotengine#28909).

To avoid warnings generated by Bullet headers included in our own module,
we include those headers with -isystem on GCC and Clang.

Fixes godotengine#29503.
@akien-mga
Copy link
Member

#29418 is merged so you can rebase on master to fix CI.

@AndreaCatania
Copy link
Contributor Author

Also this get merged bulletphysics/bullet3#2279

This weekend I'll be able to work on this.

@mysticfall you want to active the multi body world in the settings. Check the physics tab in the project settings to active it.

@AndreaCatania
Copy link
Contributor Author

Done!


const PhysicalBone::SliderJointData *sjd(static_cast<const PhysicalBone::SliderJointData *>(physical_bone->get_joint_data()));
JointSpatialGizmoPlugin::CreateSliderJointGizmo(
const PhysicalBone::SphericalJointData *sjd(static_cast<const PhysicalBone::SphericalJointData *>(physical_bone->get_joint_data()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is unused.

sdofjd->axis_data[2].linear_limit_enabled,
case PhysicalBone::JOINT_TYPE_PLANAR: {

const PhysicalBone::PlanarJointData *pjd(static_cast<const PhysicalBone::PlanarJointData *>(physical_bone->get_joint_data()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also unused.

@akien-mga
Copy link
Member

Looks good to me overall. Couple unused variables which produce warnings, and disable_3d build is broken: https://travis-ci.org/godotengine/godot/jobs/545622746

Could you add some details on the changes in the body of the commit log? So that we have some information in git log on what changes are being done and why.

Rework of the physical bone that aim to fix currently open issues and
also improve the current Physical Bone by adding stability and control.

The current Physical Bone implementation was using the normal rigid
bodies and joints, and it worked well but became unstable if the
complexity of the skeleton is not trivial, for this reason the
Featherstone algorithm was implemented to allowing to have not only a
stable body but also full control of it.

It is now not only possible to create ragdolls of non-animated bodies,
but is also possible to control its movement by adding forces with the
`motor_*` methods.
You don't have to deal with complex force systems, but instead you can
control it by simply changing the motor target and/or velocity and some
other parameters from the editor.

It is now possible to create active ragdolls directly from script, or
for example to create a completely physical walking robot, or to have a
stable ragdoll with dumpers and springs.

Fixes godotengine#19002
Fixes godotengine#22823
Fixes godotengine#24968
Fixes godotengine#25564
Fixes godotengine#26618
Fixes godotengine#28707
@akien-mga
Copy link
Member

I force pushed an update to fix compilation warnings and build failure with disable_3d=yes.

I also synced the documentation so that we can see the actual API changes, which are compatibility breaking, so this will be difficult to merge for 3.2, will likely have to wait for 4.0.

I tried it quickly on the 3D platformer demo and the TPS demo, and they both throw a lot of error simply when opening their main scene:

  • TPS demo:
ERROR: free: Invalid ID
   At: servers/physics/physics_server_sw.cpp:1414.
ERROR: shape_create: CylinderShape is not supported in GodotPhysics. Please switch to Bullet in the Project Settings.
   At: servers/physics/physics_server_sw.cpp:77.
ERROR: get: Condition ' !p_rid.is_valid() ' is true. returned: __null
   At: ./core/rid.h:153.
ERROR: shape_set_data: Condition ' !shape ' is true.
   At: servers/physics/physics_server_sw.cpp:107.
ERROR: free: Invalid ID
   At: servers/physics/physics_server_sw.cpp:1414.
ERROR: set_data: Condition ' !d.has("cell_size") ' is true.
   At: servers/physics/shape_sw.cpp:1650.
ERROR: free: Invalid ID
   At: servers/physics/physics_server_sw.cpp:1414.
ERROR: get: Condition ' !p_rid.is_valid() ' is true. returned: __null
   At: ./core/rid.h:153.
ERROR: body_attach_object_instance_id: Condition ' !body ' is true.
   At: servers/physics/physics_server_sw.cpp:679.
ERROR: free: Invalid ID
   At: servers/physics/physics_server_sw.cpp:1414.
ERROR: free: Invalid ID
   At: servers/physics/physics_server_sw.cpp:1414.
  • 3D platformer:
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
WARNING: _notification: AnimationTreePlayer has been deprecated. Use AnimationTree instead.
   At: scene/animation/animation_tree_player.cpp:407.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.
ERROR: remove_armature: This multi body can't be removed from non multi body world
   At: modules/bullet/space_bullet.cpp:518.

@akien-mga akien-mga modified the milestones: 3.2, 4.0 Jul 4, 2019
@akien-mga akien-mga removed the request for review from a team July 4, 2019 13:09
@AndreaCatania
Copy link
Contributor Author

The APIs doesn't changed too much but some things are not compatible since I've also improved a bit the APIs.

However the error that you got are mostly because you have to active the multibody world to use it.

myhalibobo pushed a commit to myhalibobo/godot that referenced this pull request Sep 3, 2019
This updates our local copy to commit 5ec8339b6fc491e3f09a34a4516e82787f053fcc.
We need a recent master commit for some new features that we use in Godot
(see godotengine#25543 and godotengine#28909).

To avoid warnings generated by Bullet headers included in our own module,
we include those headers with -isystem on GCC and Clang.

Fixes godotengine#29503.
@rodolforg
Copy link
Contributor

Won't this PR be able to 3.2 (or 3.1.2)? :'(

@maystey
Copy link

maystey commented Dec 16, 2019

@AndreaCatania I'm having trouble with the motor velocity targets. In all of my testing nothing seems to happen when I set a velocity target (in the inspector or with scripts).

This includes the "Snake" actor in your demo project (I uncommented the line in the script that set the velocity). I increased the max impulse of the chosen physical bone, but still got nothing.

I don't see any errors for this, just no change in the simulation.

@vickylance
Copy link

@AndreaCatania Is this fix by any chance going to be merged for 3.2.2 release?

@Calinou
Copy link
Member

Calinou commented May 12, 2020

@vickylance There are many merge conflicts in this pull request, and 3.2.2 is very close to being released, so I doubt it.

@akien-mga
Copy link
Member

@AndreaCatania What's the status on this PR for master (and possibly a version for 3.2)?

@aaronfranke
Copy link
Member

aaronfranke commented Jun 30, 2020

This PR has not received any new commits from the author for over a year and has many conflicts, closing.

If this is rebased and updated to work with the latest master branch, this can be re-opened or a new PR can be opened.

@AndreaCatania
Copy link
Contributor Author

I'll rebase this work on master. Not sure if it's good to back port the code at this point to 3.2. I'll open another Pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment