iBrushC / animextras

An open source Blender addon that adds extra animation functionality.
MIT License
167 stars 24 forks source link

Could this method allow linked rigs to work #14

Open schroef opened 3 years ago

schroef commented 3 years ago

I saw in the video of Luciano that linked meshes/objects dont work yet. I was fiddling a bit around and found this code can get the fCurves of linked data. I have not check if it really works with all your code.

I test this with a simple cube and it does return the keys on a single cube which is linked Ive attached a simple test scene. When you open the linked blend file and run the script, it returns the keys in the linked cube

import bpy

obj = bpy.context.active_object
dObj = bpy.data.objects[obj.name]
actObj = dObj
if hasattr(dObj.instance_collection, "all_objects"):
    fCurves = dObj.instance_collection.all_objects[dObj.name].animation_data.action.fcurves
    # print(hasattr(obj.instance_collection,'all_objects'))
    # print(hasattr(obj.instance_collection,'all_objects'))
    for fc in fCurves:
        for k in fc.keyframe_points:
            print(int(k.co[0]))

Models.zip

schroef commented 3 years ago

I got something working now. I tested a the very simple cube and a more advanced rig from Pierrick aka P2Design.

I got one small issue to tackle when i switch the "in front" On/OFF, i set it to disable Xray because these 2 kind interfere with each other.

Not sure what happens with really heav rigs though. The issue rigs are setup completely different by a lot of artist. This one from p2design as well, it imports all kind of hidden stuff etc. But im still able to clean it.

One thing i do notice is when you switch files, the bgl object somehow seem to be still active. Because when i generate something again, it already draws the meshes with pressing draw.

Simple cube example https://user-images.githubusercontent.com/6923008/115330199-97772680-a161-11eb-870f-90f33650e16d.mp4

A bit more advanced linked rig

https://user-images.githubusercontent.com/6923008/115330240-a8c03300-a161-11eb-8aed-f40457de25bc.mp4

iBrushC commented 3 years ago

This fix looks great! I'll add this in as soon as I can (which may still be some time due to finals approaching). I was thinking that due to the complexity of rigs, I may also add in a manually selectable keying object. All the linked rig issues stem from the fact that poses are only computed between the first and last keyframes which are taken from either the object itself or its armature parent. Thanks again for the amazing code!

schroef commented 3 years ago

Im not sure i follow 100%, but as far as i tested. My code should work, it tried a linked rig, my code makes a duplicate, then makes it local. Some parts stay linked. This all still works, i could still adjust the mesh or the rig. But when that happens you do need clear the onion object and generate again, that all worked fine. You can even do animation with that linked rig, make new actions and keep updating the onion skinning. I changed the code how you update the onion object, this way you can use pose mode and it will still update the onion object. Its kind of a loop around, because when you do have an active mesh with animation data, then it will still update fine.

But im a bit weary of what happens with real production scenes, as i dont have those i really dont know what happens. Basically i set the original object to hidden and then we can work on the duplicated. When i clear the object, everything i duplicated and added in a custom collection gets deleted and it shows the original linked file again. Perhaps Luciano can test this with one of his scenes.

I also tried a local mesh, then link in the rig and keep that linked, even then the onion skinning works. The code still find the animation_data in the parent, which is the rig.

The only thing im not sure of, is what @lucianomunoz wants with Alembic files. Those are mesh cached meshes, they dont container any rig. Im not sure if it would be useful or invest time in something which is basically the same as append a model and add a rig.

PS i just did a pull request, i did rearrange the repo a bit..... oops ;)

This preview is old by the way, it works much better now. I also fixed that in fornt issue, the toggle was bugging the hell out of me and giving me a headache with that Xray options hahaha

Preview 3 https://user-images.githubusercontent.com/6923008/115645666-bf47c500-a2ee-11eb-9d4e-6e6bcc9e8fa2.mp4

Preview 4 https://user-images.githubusercontent.com/6923008/115645635-afc87c00-a2ee-11eb-93d8-f4b93604c52b.mp4

schroef commented 3 years ago

One thing what still happens now and then is that it already draws before pressing the button. That is the same issue that it keeps showing old onion object when you open a new file. I did add a persistent function which clears everything one extra time when you open and close files. But clear action doesnt seem to clear everything correct. The Set_onion action is separated of that.

I think some of the handlers are not cleared or stopped. I tried adding finish action to a persistent function but got some errors now and then. Ill check it again a bit more

PS I remember trying to look into making it update automatically. But that is kinda hard to pull off, dont want it to update on everything you do in the viewport. This is mainly why i added the shortcut. You can simply use this as well when in the viewport. Check the addon settings. It is way faster using the shortcut than to got to the top and press "update" all the time.

I dont think the is a method of retrieving a dephsgraph update and only do updates when its is involved with updating a pose. You wont want that, because it will run the update on every move you make. Thats quite taxing, because it will render all the frames each and every time you move a bone.

You can also hover over the update button and add this to your quick favorites shortcut-settings