Mwni / blender-animation-retargeting

Add-on for Blender that allows the transfer of animations and poses from one armature to another
456 stars 46 forks source link

Seeking Assistance with this Plugin Integration Using in Unity #29

Open chippyeater opened 9 months ago

chippyeater commented 9 months ago

I hope this message finds you well. I am a college student currently working on an undergraduate research project that involves utilizing Unity and Blender software. I am reaching out to you as I have encountered some challenges and would greatly appreciate your guidance.

In our project, we are developing an integrated system, and one of the key functionalities involves transferring human body movements from a video to a skeletal structure. We are using this plugin developed by you, and since our final platform is built on Unity, we need to replicate everything from Blender, including this plugin, in Unity.

For various aspects in Blender, such as bone binding, I have successfully used Python code files (bpy package) that can be directly invoked in Unity. However, I am encountering persistent errors with the plugin. The code segment responsible for calling the plugin works flawlessly in Blender but generates errors in Unity. The specific error messages are: [anim-retarget-addon] set source armature to Armature, [anim-retarget-addon] cleared IK controls, [anim-retarget-addon] cleared drivers.

I am truly in need of your expertise and assistance in resolving this issue. Any guidance or suggestions you can provide would be immensely valuable to our project. If possible, could you please share any insights or solutions you may have regarding this error?

Thank you very much for considering my request, and I sincerely hope to hear back from you soon. Your help would be greatly appreciated.

Best regards

Mwni commented 9 months ago

Interesting approach. How exactly are you running Python, and more so, Blender embedded Python in Unity?

chippyeater commented 9 months ago

I import bpy package in python file, and there's a way to run pyfile in Unity. I used the same code in Blender to make sure these codes are not wrong and then move the pyfile to Unity. In Unity I use C# scripts to run pyfiles and actually these codes are running without Blender context. In fact, I met a lot of problems doing like this but I found bpy so powerful and now I can use bpy in Unity to implement bone rigging. The next step is to retargeting a certain Humanoid animation onto my model, and that's why I'm using your plugin in Unity. However I met this problem and seems no one know what to do. Here's the the screenshot of the error: image Could you help me with that?

Interesting approach. How exactly are you running Python, and more so, Blender embedded Python in Unity?

Mwni commented 9 months ago

It appears that the Unity in-process python API fails to handle the requirements of bpy to execute and bind to the blender.exe binary. The standalone bpy package is not really standalone, it still needs a copy of Blender to run alongside it, although it ships with an integrated binary and runs headless. As you can see in the logs, this Blender binary crashes for some reason. Check what's in blender.crash.txt

Things you could try:

  1. Point bpy to your locally installed Blender binary using bpy.app.binary_path
  2. If that doesn't work, try using the Out-of-process API
chippyeater commented 9 months ago

Thank you so much for replying. I've tried the first tip but failed. The blender just quit and didn't report any errors. I will try the second later and hope it will help.

Mwni commented 9 months ago

The second will definitely work, but you will have to implement client-server communication between your Python script and Unity. It's cumbersome, but that's the standard way to do it.

chippyeater commented 9 months ago

Thank you so much!!!!! It's really exciting to receive your reply because this problem have bothered me for so long.

chippyeater commented 9 months ago

Sorry to bother you again. I've been so busy this week and it's not until today that I have the time to think over this problem. Because the solution of out of process API seems to be built on python2.x and mine is 3.10, so I tried another way of creating a child process for Blender by the command: "blender -b animation.blend --python " + nameOfMyPyfile, but I received an error like this: image And blender crashed after that. Then I tried not to run blender background, which means using this command instead: "blender animation.blend --python " + nameOfMyPyfile. And it turned out successfully. I think maybe the error is because calling the plugin must need to have UI so when I call it background it will return an error related to "icon"? Is there any solution to that? I don't want my poor application running with a blender window comes out suddenly and disappear then. Looking forward to your reply.

Mwni commented 9 months ago

I have ran Blender in the background with this addon successfully before. So this is odd. What is the content of nameOfMyPyfile?

chippyeater commented 9 months ago

This is the part where I use this addon (in my python script) : image I've found the error of "icon" came from "bpy.ops.alignment.apply()" and then the process stopped after that.

Mwni commented 9 months ago

What happens when you run it with an empty script?

chippyeater commented 9 months ago

What does that mean? Nothing will happen I believe. It's not until the code "bpy.ops.alignment.apply()" that the error of "icon" emerge.

Mwni commented 9 months ago

Ah, there we go. The addon tries to display a popup, which obviously won't work in background. You can just set retargeting_context.did_setup_empty_alignment = True beforehand to prevent that.

chippyeater commented 9 months ago

“retargeting_context”? Is that defined in addon already, or I have to define it with bpy.context?

Mwni commented 9 months ago

No that is already defined. Take a look at your code, you are already using it to select the source armature.

chippyeater commented 9 months ago

That's useful! What exactly does this code mean? But I wonder why the error occur again with "bpy.ops.baking.bake()" image

I've checked just before this code that "retargeting_context.did_setup_empty_alignment" was still True. And it doesn't make any sense that the function of "bpy.ops.baking.bake()" was completed before this error occured.

Mwni commented 8 months ago

The bake operator unfortunately also triggers a popup, after a successful bake. Sadly this cannot be bypassed, so unless you find a way for your implementation to tolerate popups, you will have to fork this repo and remove this popup invocation.