Page 1 of 2 12 LastLast
Results 1 to 20 of 35
  1. #1

    [Addon] ShapeKey Helpers

    Hi everyone!

    Some time ago, I programmed a few Python operators to automate repetitive tasks when working with shape keys in Blender.

    I posted a thread about this addon a while ago, but since the addon has grown more versatile over time, I decided to start a new thread for the sake of clarity (you can find the old thread here: http://blenderartists.org/forum/show...keysplitter%29)

    DOWNLOAD: https://github.com/JanOtt/ShapeKey-H...ive/master.zip

    Anyway, the addon is very simple and consists of three operators, which can be called by pressing 'space' and searching for their respective names.

    Also, thanks to user 'mem', the operators can also be called from the dropdown menu in the shape key section (see image below).



    'Apply Modifiers and Keep Shapekeys':
    This operator is a workaround for applying modifiers (Subdivision Surface, Mirror, Bevel and Edgesplit) to meshes with shape keys on them.
    Normally, when you try to apply, say, a Subsurf modifier to mesh with shape keys, Blender will simply display an error message stating that "Modifier cannot be applied to a mesh with shape keys".
    This operator solves this (using this approach: http://blenderartists.org/forum/showthread.php?290760-SubSurf-applying-in-Objecs-with-Shape-Keys-(to-use-in-BGE)) and creates a new object with all suitable modifiers applied and all shape keys preserved!



    'Split Shapekeys':
    This operator requires that you have two vertex groups in your object, named 'left' and 'right' (see image) and assigned to the left or right side of the mesh. When you run the operator, each shapekey is split according to these two vertex groups, automatically (Example: 'Smile' gets split into 'Smile.L' and 'Smile.R'). Shapekeys, which names already end with '.L', '.R' or '.B' (for both) and the first (Basis) shapekey are ignored. Same as with the first operator, a new object is created, containing all the split shapekeys.




    'Apply Selected Shapekey as Basis':
    This operator replaces the 'Basis' shape key with the currently selected shape key.
    This is very useful if you want to alter the general shape of the mesh after having already created several shape keys (for facial expressions, f.ex.).




    I hope this is useful to some people! If you find any bugs or have any suggestions on how to improve the addon, feel free to send me a message or reply in this thread!

    Cheers and have a good day! (:
    Last edited by J_Ott; 14-Apr-16 at 08:49.



  2. #2
    J_Ott Nice work! This addon help me in my work. Thx!!



  3. #3
    I couldn't get the Apply Modifiers and Keep Shapekeys thing to work. (2.77)

    Using it the shapekey names are copied to the new mesh but the actual data isn't (no difference from basis). If you use it with a shape key selected no shape keys are copied to the new mesh at all.

    Also you may want to check if there actually are shape keys before executing the script with an error message that's clearer what's wrong.

    Edit: Forgot to add some stuff. The original model is not deleted after executing the operator, is this intended?

    Also it seems like it doesn't work with an armature modifier on the mesh, without the modifier it seems to work. Is this supported for use on characters with rigs?



  4. #4
    Originally Posted by Cyaoeu View Post
    I couldn't get the Apply Modifiers and Keep Shapekeys thing to work. (2.77)

    Using it the shapekey names are copied to the new mesh but the actual data isn't (no difference from basis). If you use it with a shape key selected no shape keys are copied to the new mesh at all.

    Also you may want to check if there actually are shape keys before executing the script with an error message that's clearer what's wrong.

    Edit: Forgot to add some stuff. The original model is not deleted after executing the operator, is this intended?

    Also it seems like it doesn't work with an armature modifier on the mesh, without the modifier it seems to work. Is this supported for use on characters with rigs?
    Thank you for your feedback!

    So far, I haven't been able to replicate the first bug you described. What kind of modifiers did you try to apply? So far, only Subsurf, Mirror and (to a lesser degree) Edgesplit and Bevel modifiers are supported.
    If you're ok with it, I'd love to take a look at the blender scene where you tested the addon. Could you maybe send me the .blend file or provide some screenshots?

    Checking the object for shape keys first sounds like a very good idea, I'll try to update the addon as soon as possible.

    The original model not being deleted is intended. In case something goes wrong with one of the operators, the original stays untouched/uncorrupted and you don't lose any progress. That's the idea behing it, at least.

    The 'Apply Modifiers and Keep Shapekeys' operator should ignore any Armature modifiers. So it should work fine on rigged/skinned characters. Same as above, If you could provide me with a .blend file or screenshots, that would be great!



  5. #5
    I think I know why it didn't work, I had pinning enabled (with the basis key selected). That way even if you set the shape key weight to 1.000 nothing changes since you've got the basis shape pinned and so none of the shapes are able to be copied. It seems to work if you remove pinning.



  6. #6
    Originally Posted by Cyaoeu View Post
    I think I know why it didn't work, I had pinning enabled (with the basis key selected). That way even if you set the shape key weight to 1.000 nothing changes since you've got the basis shape pinned and so none of the shapes are able to be copied. It seems to work if you remove pinning.
    Interesting! I never really used pinning in my workflow, so I didn't consider checking for that in the script. Good to know.



  7. #7
    Member Safetyman's Avatar
    Join Date
    Mar 2010
    Location
    Maryland, USA
    Posts
    1,226
    This is a valuable addon! Thanks so much for sharing it with us... it will be extremely useful for me.
    Quicksand has no sense of humor



  8. #8
    Hi J_Ott, thanks for the useful addon!

    I've taken the liberty to add your operators to the shapekey menu (the downward pointing triangle next to the shapekeys list), with a small tooltip description for each. I find it to be a bit more accessible this way.

    I've attached the modified script here. If that's not okay, I'll remove it. You're probably still developing the addon, in which case please consider adding these modifications to the main file.

    Thanks again!

    Edit: Changes now integrated in main file from first post. Plus J_Ott fixed a bug I introduced when adding the menu. So there's no reason to keep my attachment - please use the addon from the original post. Thanks!
    Last edited by mem; 14-Apr-16 at 09:35.



  9. #9
    Originally Posted by mem View Post
    Hi J_Ott, thanks for the useful addon!

    I've taken the liberty to add your operators to the shapekey menu (the downward pointing triangle next to the shapekeys list), with a small tooltip description for each. I find it to be a bit more accessible this way.

    I've attached the modified script here. If that's not okay, I'll remove it. You're probably still developing the addon, in which case please consider adding these modifications to the main file.

    Thanks again!
    Wow! That's a great addition! I'm not really that proficient in scripting Blender addons, so I didn't even think about integrating the operators into the shape key menu.

    I'll get right to updating the addon! Thanks a lot!


    Originally Posted by mem View Post
    Also, I'm having the same problem Cyaoeu had, with "Apply Modifiers and Keep Shapekeys" not working, but I couldn't get it to work even with the pinning turned off - in fact, I didn't use pinning to begin with, so that's not the issue here.

    I'm attaching a blend file - it's just Suzanne with two shapekeys that deform her ears and a subsurf modifier on it. Whenever I choose "Apply Modifiers and Keep Shapekeys" two objects appear: one named the same as the original object, with the suffix "_Applied" added, but with no modifiers actually applied (the subsurf modifier is still there, though), and another object named like the last shapekey, with the subsurf modifier applied, but with no shapekeys on it or any deformations.
    Thanks for the feedback and the .blend file!
    Yes, I encountered the same problem when I just tested your modified version of the addon. This bug is caused because the operator 'Apply Modifiers and Keep Shapekeys' needs to be called in the 3D View, for a few different reasons.

    The good news: It's an easy fix and I've already made the necessary changes to the addon. Everything should work fine now.

    I've updated the download link on the top! Thanks for contributing!



  10. #10
    Here's a script to export a mirrored character with a rig to .fbx for use in game engines. Select the mesh and rig and press run script. It's exported to the blend file folder.

    Code:
    import bpy
    path = bpy.path.abspath('//')
    selected_objects = bpy.context.selected_objects
    armature_name = selected_objects[0].name
    mesh_name = selected_objects[1].name
    mesh_object = selected_objects[1]
    
    bpy.context.scene.objects.active = mesh_object #make sure active object is mesh type (armature = error)
    bpy.ops.object.shape_key_preserver()
            
    bpy.ops.object.select_pattern(pattern=armature_name)
    bpy.ops.object.select_pattern(pattern=mesh_name + "_Applied") #reselect both objects in order to export mesh+armature
    bpy.ops.export_scene.fbx(filepath=str(path + mesh_name + '.fbx'), check_existing=True, axis_forward='-Z', axis_up='Y', filter_glob="*.fbx", version='BIN7400', ui_tab='MAIN', use_selection=True, global_scale=1.0, apply_unit_scale=True, bake_space_transform=False, object_types={'ARMATURE', 'CAMERA', 'EMPTY', 'LAMP', 'MESH', 'OTHER'}, use_mesh_modifiers=False, mesh_smooth_type='OFF', use_mesh_edges=False, use_tspace=False, use_custom_props=False, add_leaf_bones=True, primary_bone_axis='Y', secondary_bone_axis='X', use_armature_deform_only=False, armature_nodetype='NULL', bake_anim=True, bake_anim_use_all_bones=True, bake_anim_use_nla_strips=True, bake_anim_use_all_actions=True, bake_anim_force_startend_keying=True, bake_anim_step=1.0, bake_anim_simplify_factor=1.0, use_anim=True, use_anim_action_all=True, use_default_take=True, use_anim_optimize=True, anim_optimize_precision=6.0, path_mode='AUTO', embed_textures=False, batch_mode='OFF', use_batch_own_dir=True, use_metadata=True)
    It's a bit hacky, you probably don't need all those fbx export parameters and the script assumes the armature is first in the selected object list which may not be true for all files, but you get the idea. It should also be possible to split some shapekeys before exporting if needed.



  11. #11
    Thanks for the additions and the fix! That sure was quick



  12. #12
    Oh man, you are such a life saver, thanks a lot!



  13. #13
    Member Mario Mey's Avatar
    Join Date
    Mar 2010
    Location
    Castelar, Buenos Aires, Argentina
    Posts
    83
    I just used it... It worked correctly!

    I don't understand why some errors were shown in console... about bones parenting? It also said something about other objects, like cameras or other armatures... why?



  14. #14
    Originally Posted by Mario Mey View Post
    I just used it... It worked correctly!

    I don't understand why some errors were shown in console... about bones parenting? It also said something about other objects, like cameras or other armatures... why?
    Hm, strange. But if I understood correctly, the addon works fine despite the error messages?

    Would you mind posting the error message text here, maybe even a screenshot or a .blend file? Then I can take a closer look and determine what's causing the errors.



  15. #15
    Member Mario Mey's Avatar
    Join Date
    Mar 2010
    Location
    Castelar, Buenos Aires, Argentina
    Posts
    83
    I realized that the issue of the bones of other armature is because the new depsgraph (I'm using it). But also, with actual depsgraph, there're some errors... but the job is well done. For the moment, I can show you the log of the same file.

    With actual depsgraph: http://www.pasteall.org/69845
    New depsgraph: http://www.pasteall.org/69846

    "arm.camluces" is another armature
    "voladora2" is a camera, parented to a bone of "arm.camluces".
    Last edited by Mario Mey; 23-May-16 at 13:54.



  16. #16
    Originally Posted by Mario Mey View Post
    I realized that the issue of the bones of other armature is because the new depsgraph (I'm using it). But also, with actual depsgraph, there're some errors... but the job is well done. For the moment, I can show you the log of the same file.

    With actual depsgraph: http://www.pasteall.org/69845
    New depsgraph: http://www.pasteall.org/69846

    "arm.camluces" is another armature
    "voladora2" is a camera, parented to a bone of "arm.camluces".
    I just took a quick look at the error log.



    DM_to_mesh: YEEK! this should be recoded! Shape key loss!: ID 'MEjevita.001'
    This error/warning is actually harmless. At some point in the addons execution, I convert some mesh copies with shapekeys to new mesh objects (using the 'Mesh from Curve/Meta/Surf/Text' operator). For some reason, Blender logs this (redundant) message and I haven't found a way to prevent that.

    So basically that part is working as intended, everything normal here.



    add_relation(8, Bone Parent) - Could not find op_from (ComponentKey(OBarm.camluces, 22, 'voladora2'))

    add_relation(8, Bone Parent) - Failed, but op_to (ComponentKey(OBcam.test, 14, '')) was ok

    I'm not so sure about that part and have not used/tried this new depsgraph yet, so I can only guess here.

    It looks like the depsgraph tries to call an operator called 'add_relation' (that sounds like some kind of parenting object operator to me) but can't find the appropriate object.

    I should mention that my addon does not change the original object/mesh when you call any of its operators but instead creates a copy of the mesh and modifies that copy. So if anything goes wrong during the process, your original mesh is left untouched and you don't lose any progress or end up with a corrupted mesh.

    That also means that any drivers or code in general that references your old mesh will not suddenly also reference the new, resulting mesh copy. That's why the addon does not work with shapekey drivers already set up.

    I'm guessing something similar happens in your case as well. There might be some relation between the bones of arm.camluces and your original mesh, that does not carry over to the new, applied mesh.



  17. #17
    Member Mario Mey's Avatar
    Join Date
    Mar 2010
    Location
    Castelar, Buenos Aires, Argentina
    Posts
    83
    If the code still does the basic stuff that the original code does... I "suppose" that I know how it works! (I did the "approach")

    Yes, I also thought what you said about relations between the mesh and the other armature... but, as I remember, they are not related. It's not so important... the addon does what it was done to do.



  18. #18
    Hi, I have been testing your Addon, and it works pretty well if you want the ShapeKeys just to be copied from one mesh to another with the SubDivision Surface to be applied, or if you have your addons animated in specific frames, just adding a Keyframe on each ShapeKey in the Mesh copied with the Modifier applied, and the copy the animation from the original, like in this case:
    ShapeKeys Animated.PNG

    But what if your ShapeKeys are controlled by Drivers? How con you copy the info of the animated Drivers to the ShapeKeys of the copied file without having to re-do all the conections again in this New Mesh?

    ShapeKeys Animated with Drivers.PNG



  19. #19
    Originally Posted by AJPana12 View Post
    But what if your ShapeKeys are controlled by Drivers? How con you copy the info of the animated Drivers to the ShapeKeys of the copied file without having to re-do all the conections again in this New Mesh?
    As of now, my addon can't copy any drivers from one mesh to another. So unfortunately, you will probably have to re-do all the driver connections.

    I'm sure there's a way to automatically transfer the driver connections in python, but I don't have enough spare time at the moment to look into this topic further.

    I just did a quick test though and it seems like you can easily copy drivers from one property to another:

    - Right-click on purple value, select 'Copy Driver'
    - Select the new mesh/object that you want to copy the driver to
    - Right-click the desired new value and select 'Paste Driver'
    - Make sure to go into 'Graph Editor' -> 'Drivers' and click 'Update Dependencies'

    If you repeat these steps for each of your shape keys, you should be able to copy all the drivers in about 10 minutes or so. It's not a perfect solution but it's better than having to re-do your animations.

    In the future, you should probably make sure that all necessary modifiers are applied and all shape keys are final before you start connecting them to drivers.

    By the way: I've recently learned about this addon [ https://www.youtube.com/watch?v=IFLhvW-lJVM ] and have been using it a lot since then. It automates most of the work associated with setting up shape key drivers. Maybe you'll find it useful as well.



  20. #20
    I can see this becoming incredibly useful to me. I thank you!



Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •