V-Sekai / godot-vrm

Importer/Exporter for VRM avatars and MToon shader. Available for Godot 4.1+ and 3.2+ in the Asset Library.
https://godotengine.org/asset-library/asset/2031
Other
282 stars 24 forks source link

How to make a vrm avatar make a real pose ? (It is not an issue but more like a suggestion) #25

Closed cyberpsyche closed 1 year ago

cyberpsyche commented 2 years ago

It is not an issue but more like a suggestion. I could import a VRM model in a godot project based on the gorgeous vrm addon, but besides some pre-defined "blink" expressions I do not know how to make the avatar do an actual pose. Is there a code example or a manuscript to teach us how to really use the vrm model in godot ? Where can the godot-vrm users find it ?

Thanks very much!

fire commented 2 years ago

Since you asked, let us spend some time writing a summary of our current work on making the avatar do an actual pose.

Will post as soon as we can.

cyberpsyche commented 2 years ago

Very glad to hear that. Thank you !

cyberpsyche commented 2 years ago

@fire Hi fire, is there any progress on this topic ?? I hope this post is not annoying you or interrupting your ongoing project, but since several weeks past, I wonder when and how can we do something really interesting based on your vrm model control api. Thanks again!

fire commented 2 years ago

Over the last weeks we and the Godot Engine team merged several prs.

We are working on VRM posing.

fire commented 2 years ago

https://github.com/vss-project/vss and https://github.com/you-win/openseeface-gd

Also we did some work with the vss and openseeface-gd projects.

cyberpsyche commented 2 years ago

Awesome !!!

I have already noticed the openseeface-gd project, but the vrm add-on in that project is not identical to godot-vrm project, and openseeface-gd is only control the head bone of a vrm model. I wonder is there a demo project to utilize all the potentials of godot-vrm with control all the bones of a vrm model. Also I wonder that could we control the fingers of a vrm model ?

fire commented 2 years ago

We updated Godot VRM to the new Godot Engine 4 that allows importing VRMs from the game instead of the editor.

Other things directly related to animation are in the development pipeline.

fire commented 2 years ago

The 4.0 code now uses gltf document extensions.

There are two in-progress approach to retargeting:

  1. forward kinematics retargeting
  2. inverse kinematics retarging

There is an improved statemachine pr. https://github.com/godotengine/godot/pull/61196

fire commented 2 years ago

I have also made a proof of concept mediapipe to osc binary.

https://github.com/V-Sekai/mediapipe

Unsolved problem to convert mediapipe skeleton to vrm skeleton.

fbcosentino commented 2 years ago

Is there a way to apply animation to the skeleton externally?

I tried the following:

animation names and bone names are correctly identified and the model does animate (with springbones working as well), but animations are completely broken, looks like transforms work in a different way?

fbcosentino commented 2 years ago

animation names and bone names are correctly identified and the model does animate (with springbones working as well), but animations are completely broken, looks like transforms work in a different way?

It seems it's related to rest pose. Testing with an animation where the first frame is already transformed (that is, not starting in rest position) importing from glb works fine as it knows the rest pose. Importing as vrm the first frame is taken as reference for rest and transforms are applied adding to that.

Tested with an animation where the first frame had all bone transforms reset, and transferring the AnimationPlayer glb->vrm worked fine

fire commented 1 year ago

We wrote a blog entry for this https://godotengine.org/article/animation-retargeting-in-godot-4-0

Let me know if this helps

icynic commented 1 year ago

I've noticed that the sample model of AliciaSolid has good physics in godot engine. But other models I downloaded from the Internet don't have physics at all. Is it because the GDscript of the secondary node? If so, how did it do that? Can I implement physics for other models in the same way, or maybe by using spring bones?

fire commented 1 year ago

This is a good question.

We use vrm spring bones.

They're also described here. https://github.com/godotengine/godot-proposals/issues/5605

fbcosentino commented 1 year ago

If you have a model with no physics and you want to add the spring bones yourself, you can use blender with the VRM plugin: https://vrm-addon-for-blender.info/en/

It's a bit cumbersome so you're going to have to spend some time reading about how collision works with VRM spring bones, as you need a. add spring bone information to the bones you want physics (e.g. hair, clothes) and b. you need colliders so clothes and hair don't go into the body etc

The bright side is you can start with any model in any format (fbx, glTF, etc) and will be able to export VRM working in Godot - you don't need to start with a VRM model itself.

icynic commented 1 year ago

Thanks for your suggestions. And sorry for my negligence. My problem has been solved.

fire commented 1 year ago

Let me know if anything is pending to do here.

cyberpsyche commented 1 year ago

@fire Hi Fire, if I have a godot-vrm model in a Godot 4 scene, how to let the VRM model make a motion by gdscript? For example, if I want make the VRM model raise left arm or blink its right eye or open its mouth to say "AEIOU", how to do it?

I tried this code :

var vrm_model = $Godette_vrm_v4
var skeleton = vrm_model.get_node("GeneralSkeleton")
print(skeleton.get_bone_names())

But the editor prompt a error message for "nonexistent function get_bone_names()" .

How to pick up a specific bone via gdscript ?

Thanks.

fire commented 1 year ago

I don’t godot has ever had a get bone names. Godot Skeleton has a get bone count and you can use that index to get a bone name. use find bones to get an index from name? What tutorial are you using?

cyberpsyche commented 1 year ago

I can't find a up-to-date tutorial on the internet. So I asked ChatGPT :P

Is there an appropriate tutorial or a demo project you could suggest?

And if I want to apply a VMD file to the godot-vrm model, how can I do it? Where can I find a demo project for this ?

Thanks!

fire commented 1 year ago

We had a working demo of vmd to vrm playback in godot 3 but it broke https://github.com/V-Sekai/godot-miku-miku-dance-vrm-vsekai/tree/master.

No estimates on the feature completion timeline.

lyuma commented 1 year ago

@cyberpsyche ah, you're on Godot 4, right? Well, you're in luck. Godot 4 includes Animation retargeting, and this VRM importer is compatible with Godot's humanoid format! So an imported VRM comes ready to accept any humanoid animation Godot can import.

So you could take any animation in fbx (requires a mesh) or gltf format, and on the left panel where it says Import As scene, select AnimationLibrary. https://docs.godotengine.org/en/stable/tutorials/assets_pipeline/retargeting_3d_skeletons.html

For converting from VMD, if the importers in godot are not working, you could consider using a Blender conversion and export to FBX. The process will be the same as you might find in tutorials for Unity or VRChat, where the end result is ideally a gltf (or fbx)

fire commented 1 year ago

You'll need to change the structure of the PMX character with the hips joints to be compatible with VRM. I don't have the exact method on hand.

cyberpsyche commented 1 year ago

Thanks @lyuma and @fire, ultimately I could bind a .fbx motion file to an imported VRM model. It's great to see the VRM character to perform a motion (except the arms and legs will occasionally penetrate the clothes).

I wonder how to make a VRM model to do some 'innate' actions , for example, to blink eyes or open mouth for emulation to say "AEIOU" words while do the .fbx motion animation. After all, let the VRM model do a long time dance motion without even blinking his/her eyes once seems very weird. How can I do this just via GDScript, not by using an animation file in Godot 4?

lyuma commented 1 year ago

I have since implemented blend shape and bone animations for eyes and mouth, into the AnimationPlayer. So to implement this, it will be necessary to add a few BlendSpace2D (for the eye animations) or BlendTree + Add3 node (for the mouth / facial expressions).

Or, perform the animation by hand in code by reading the tracks from the AnimationPlayer to see which keyframes are being set.

Anyway, since Godot's animation system has greatly improved in 4.x, I think it is finally time to close this issue. I would encourage people using Godot 3 to consider moving to Godot 4.