Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Blend Shapes Preset Tool [Released]

Discussion in 'Assets and Asset Store' started by kalagaan, Nov 8, 2017.

  1. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498


    BSPT generates templates of blendshapes presets that can be shared between different characters.

    You can easily create facial expressions by combining multiple blend shapes into presets. Each preset is controled by a single parameter. So it's really easy to include the API in your game script.
    You can create different templates with variations using the same expression name, so you can create differences between characters without any line of code, just by changing the template.
    Another advantage is that you don't have to deal with the original blendshapes names, you can use your own naming. If two characters don't have the same blend shapes names, you can unify them with two template files (one for each character) using the same presets names.

    Different blend modes are available :
    Blend, Min, Max, Override.

    The tool is really easy to use, you can modify the presets and see the result in the editor.






    Demo - Doc

    AssetStore links : Basic - Pro

    The pro version includes the source code.
     
    r3ndesigner and wetcircuit like this.
  2. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    The version 1.0.1 has been submitted to the asset store, it should be available soon.
    The preset controller can manage additionnal renderer,
    very usefull for characters with separate meshes (eyes, mouth...)



    The additionnal renderers must have the same blendshape structure (names & order)

     
    Last edited: Nov 8, 2017
    Thanathos, r3ndesigner and wetcircuit like this.
  3. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    The version 1.0.1 is available ;)
     
    Thanathos likes this.
  4. sentar

    sentar

    Joined:
    Feb 27, 2017
    Posts:
    44
    Hi kalagaan,

    I have a quick question for you, Is there a limitations as to what model I can use? Does a model have to have some sort of blendshapes (already set) to use this? Could I (theoretically) grab some random free model off of the asset store and try to apply this to that model?
     
  5. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Hi,
    The model must have blendshapes, BSPT doesn't modify the mesh, it generates some preset templates of the existing blendshapes.
    This is usefull for character with complex face expressions.

    If you want to add blendshapes to a model, you can use PolyMorpher.
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Does this tool allow for negative morphs/blend shapes?
    In 3D it is common to set a negative blend from a defined blend - to get a larger range or allow for a frown from a smile morph/blend.
    Unity does not support negative blend shapes out of the box.
     
  7. witcher101

    witcher101

    Joined:
    Sep 9, 2015
    Posts:
    516
    can this copy blendshapes to other skinrender. Like if i create a char with blendshape which makes char fat. Then i attach a skinned cloth without blendshape in it. Can this copy shape to ckinned cloth to allow cloth to fit with char as it expands in size
     
  8. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    BSPT rely on the unity BlendShape API, so it doesn't allow negative weights. :(
     
    HamFar and theANMATOR2b like this.
  9. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    No, you can't transfer blendShapes from a model to another one.
    You have to create the blendShapes on your cloth model.
    If the blenshapes are the same (name & order), you can use BSPT to synchronize blendshapes weights for the both models.
     
    Last edited: Nov 17, 2017
  10. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @kalagaan ,

    Do you know if Manuel bastioni characters from blender have blendshapes and whether they work with this asset... Would be a big selling point!
     
  11. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Yes, Bastioni lab exports blendshapes :)
    The BSPT demo is made with a Bastioni lab mesh, so the eye controller demo script works with any character generated by the bastioni lab.
    The facial expression system (MBL 1.6.1) is very close to BSPT, It's really cool :p
    I'm using MBL for a character and I'll include a BSPT template with it.
    you can copy (manually) each blendshape weight for each expression preset into BSPT.

    It would be really cool if I could create a blender script for exporting blendshapes into a readable format for BSPT.
    I've never worked with blender script, so I don't know if I could do this easily.
     
    Last edited: Feb 3, 2018
  12. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    @kalagaan ,

    Great news. Will save up and buy. Some presets for Bastioni and Makehuman would really be good...
     
  13. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Bastioni lab expressions are stored into json files, I've written an importer for the BSPT editor ;)
    I'll add it in the next version.
     
  14. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
  15. Duffer123

    Duffer123

    Joined:
    May 24, 2015
    Posts:
    1,215
    Assuming this asset can alter not just facial expressions but body proportions etc ?
     
  16. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    BSPT works with existing blendshapes, Bastioni lab doesn't export body proportions as blendshapes.
     
  17. Gobstar

    Gobstar

    Joined:
    Nov 12, 2015
    Posts:
    7
    The blendshapes created with Blendshape tool are really amazing but for some reason it wont keyframe any animation no matter what I try. Is there a re reason for this?

    It kind makes the asset useless for animation purposes if its difficult to create animation keyframes! :(
     
    nomax5 likes this.
  18. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    I'll push the animation script in the next update.
    Thank you for your review :)
     
    nomax5 likes this.
  19. nomax5

    nomax5

    Joined:
    Jan 27, 2011
    Posts:
    365
    Hey kalagaan,

    Thanks for making the asset I bought it the other day and I'm enjoying playing with it.

    I want to have it working over the network in multiplayer and I thought I'd ask on the forum
    how people would go about doing it?.
    I'm using Manuel Bastioni characters and they will all have the same BSPC

    The setup I have at the moment is if not local player turn a bunch of stuff off character controller camera etc.
    So i need a way to communicate the blendshape data to all the other clients.
    like a blendshape version of the network animator.

    and advice greatly appreciated.

    Roy
     
  20. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Hi Roy,
    The preset weights are stored in the list m_presetState of the BSPC,
    you can share all the weights to the other clients.
     
    nomax5 likes this.
  21. nomax5

    nomax5

    Joined:
    Jan 27, 2011
    Posts:
    365
    Ahh ofcouse they are Doh...
    Thanks matey I'll have a fiddle
     
  22. nomax5

    nomax5

    Joined:
    Jan 27, 2011
    Posts:
    365
    Thinking about it I guess that making all my Blendshape Presets into Animations means that the Network Animator component will take care of the multiplayer networking side?
     
  23. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    That should work :)
    I'll push a new version to the assetstore tomorrow, including a demo scene for the animation script. ;)
    If you want a fix before the assetstore release, please send me an email (contact@kalagaan.com) with your invoice number.
     
  24. nomax5

    nomax5

    Joined:
    Jan 27, 2011
    Posts:
    365
    That is fantastic news !!
    I don't need a fix before then I got plenty of stuff to be getting on with..
     
  25. nomax5

    nomax5

    Joined:
    Jan 27, 2011
    Posts:
    365
    Whoohoo I noticed an update on the Asset store, so I deleted BlendShapePresetTool from my project and reinstalled it.
    Hows does it work?

    I'm quite new to unity animation mecanim etc. and I'm a bit thick.

    I see you have what looks to be the original Female head and now a male head at the side.
    They both have the Head Controller script but the male has an additional Animator conponent with no controller.
    They both have the new Blend Shapes Preset Animator script

    I just want multiplayer belndshapes over the network, so when my local player smiles all the other players see my character smile.

    What do I need to do please?

    Roy
     
  26. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    The animation script is a list of float that can be animated in a Unity animation file.
    have a look to the demo, there's an animation component. The animation file is shared between the characters.

    If you want to share the animation you have to use the network components to share the animation to the other clients, or you could do it with a custom script.
    I don't use the network system, but according to the documentation
    https://docs.unity3d.com/Manual/UNetStateSync.html

    it should look like this :

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5. using Kalagaan.BlendShapesPresetTool;
    6.  
    7. public class BSPTNtworkTest : NetworkBehaviour
    8. {
    9.  
    10.     [SyncVar]
    11.     public float m_preset0_Weight = 0f;
    12.  
    13.     BlendShapesPresetController m_ctrl;
    14.  
    15.     // Use this for initialization
    16.     void Start () {
    17.         m_ctrl = GetComponent<BlendShapesPresetController>();
    18.  
    19.     }
    20.  
    21.     // Update is called once per frame
    22.     void Update () {
    23.         m_ctrl.SetWeight(0, m_preset0_Weight);
    24.  
    25.     }
    26. }
    27.  
    I hope that it will help you.
     
  27. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    Can anyone tell me where I can get a free but realistic-looking (human-like) character to use with this amazing tool? Thanks
     
  28. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Have a look at http://www.manuelbastioni.com
     
    vibedev and HamFar like this.
  29. vibedev

    vibedev

    Joined:
    Nov 1, 2018
    Posts:
    13
    As soon as importing this asset into a Unity project is finished, I get an error message that says: "ExecuteMenuItem target for XR does not exist." Has anyone had the same thing?
     
    HamFar likes this.
  30. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Hello,
    Blend Shape Preset Tool doesn't use "ExecuteMenuItem", you should try to find this function in your project files.
    What is your version of unity?
    Could you try to import the package in an empty project?
     
    HamFar and vibedev like this.
  31. vibedev

    vibedev

    Joined:
    Nov 1, 2018
    Posts:
    13
    Thanks for your quick reply. I am using Unity 2018.2.17f1 on Windows 10 64 bit with a AutoDesk character that uses facial blendshapes. It might be that "ExecuteMenuItem" is used somewhere in my project files, but it was never thrown as error until I imported BSPT.
     
    HamFar likes this.
  32. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    I don't know why BSPT would generate this error, does it throw an error only once?
    You could try to reimport all your project with BSPT, and without BSPT for checking if it's a bug with BSPT.
    If there's still some issues, could you send me the script with the ExecuteItem function?
    I could check what's going on... ;)
     
    HamFar and vibedev like this.
  33. vibedev

    vibedev

    Joined:
    Nov 1, 2018
    Posts:
    13
    You were absolutely right. This had nothing to do with BSPT. My apologies, and thanks for your offer of help. I am experimenting with BSPT these days, so you will probably see some questions from me here :)
     
    HamFar and kalagaan like this.
  34. vibedev

    vibedev

    Joined:
    Nov 1, 2018
    Posts:
    13
    Thanks to the Doc section on how to get started, I was able to create a couple of presets and save them and apply them to my AutoDesk character that has a blendshape-based face with 65 elements in its Skinned Mesh Renderer array, just like the male|female models you have used in the Demo scenes. However, when I drag&drop the templates that you have created (called Demo1 and Demo2) in the reference field of my character, I get an error message (IndexOutOfRangeException: Array index is out of range) which makes me wonder if I would always have to create a preset from scratch? I understand the meaning of the error message, but given that the array size is defined for each template, I do not understand why this error is thrown? In my simple template, I add only 2 presets; in your two demo templates, you have array sizes 11 and 12 respectively. So, why can I not simply use your templates on my character?
     
    HamFar likes this.
  35. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Thank you for your feedback,
    I'll fix that error ;)
    You have to create a new template when you want to use a new character, the template is also based on the number of blendshapes, that's why the array of each preset doesn't match with the blendshapes to modify.
     
    vibedev and HamFar like this.
  36. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    A tiny question: All the 66 Action Units (whose values range from 0 to 1) in the Skinned Mesh Renderer component are either pre-fixed or post-fixed with _h but what does this stand for? By the way, do the 66 regions that can be modified (to create a specific blendshape/configuration) really correspond to facial Action Units?
     
  37. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    BSPT uses the blendshapes existing in the skinnedMeshRenderer, so the naming is defined by the creator of the model.
    So I can't answer your question, each model has is own way to deform the parts of the model (face, body...)
     
    Last edited: Dec 10, 2018
    vibedev and HamFar like this.
  38. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    oh I see. Thanks. So, those names are defined by the artist who used Blender or Maya to create the model...

    I attach the following simple script to my character, but as the definition of the API method dictates, I can only set it to a float value (1 here) which is a sudden change from 0.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Kalagaan
    4. {
    5.     namespace BlendShapesPresetTool
    6.     {
    7.         public class BlendsAPI : MonoBehaviour
    8.         {
    9.             public BlendShapesPresetControllerBase _BSPT;
    10.  
    11.             private void Start()
    12.             {
    13.                 _BSPT.SetWeight("MyPreset1", 1);
    14.             }
    15.     }
    16. }
    So, I am trying to use Lerp to make the transition from 0 to 1 gradual, as is used in the HeadController.cs script, but over there the GetPresetState is used directly, so I thought I should use a StartCoroutine instead.

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. namespace Kalagaan
    4. {
    5.     namespace BlendShapesPresetTool
    6.     {
    7.         public class BlendsAPI : MonoBehaviour
    8.         {
    9.             public BlendShapesPresetControllerBase _BSPT;
    10.            
    11.             private void Start()
    12.             {
    13.                 StartCoroutine( AnimatePresetTemplate("MyPreset1") );
    14.             }
    15.  
    16.             private IEnumerator AnimatePresetTemplate(string presetTemplateName)
    17.             {
    18.                 _BSPT.GetPresetState("MyPreset1").weight = Mathf.Lerp(0f, _BSPT.GetPresetState("MyPreset1").weight, Time.deltaTime* 10);
    19.  
    20.                 yield return null;
    21.             }
    22.     }
    23. }
    But it doesn't work. What am I doing wrong? How can I programmatically (via the API) smoothly change the values, like a slider?
     
  39. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    The first sample should work,
    be carefull that there's no other script that override the value.
    You can test this one on the demo scene (you'll have to disable the demo script before)
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. using UnityEngine;
    4.  
    5. namespace Kalagaan
    6. {
    7.     namespace BlendShapesPresetTool
    8.     {
    9.         public class BlendsAPI : MonoBehaviour
    10.         {
    11.             public BlendShapesPresetControllerBase _BSPT;
    12.  
    13.             private void Update()
    14.             {
    15.                 _BSPT.SetWeight("Smile", Mathf.Abs(Mathf.Sin(Time.time)));
    16.             }
    17.         }
    18.     }
    19. }
     
    HamFar and vibedev like this.
  40. vibedev

    vibedev

    Joined:
    Nov 1, 2018
    Posts:
    13
    Once, I added a new preset by mistake and then tried to delete it via the little cross that appears when you click on the edit preset icon. It seems to delete the new preset on the spot, but the next time you launch the Unity project, the new preset is still there! I have tried it a few times, so I think it might be a little bug :)
     
  41. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    You can fix it by renaming it to 'UNUSED' :p
    Thank you for the feedback, I'll check that ;)
     
    HamFar and vibedev like this.
  42. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    I've fixed it, I'll push a new version on the asset store.
    To fix it 'manually', you can click twice on the edit button of another preset :p
    It will save the template in the project folder.
     
    HamFar and vibedev like this.
  43. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    Thanks for this. I understand why this works by fluctuating the weight of the Smile preset between 0 and 1.

    Can you please help me also understand why neither of the following two commands works instead of the Sin function?
    Code (CSharp):
    1. _BSPT.GetPresetState("MyPreset").weight = Mathf.Lerp(0f, 1f, Time.deltaTime);
    2. _BSPT.SetWeight("MyPreset", Mathf.Lerp(0f, 1f, Time.deltaTime) );
    How do smoothly lerp from one preset to another in the Update() method, in order to create facial expressions?

    Thanks
     
  44. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Here a sample ;)

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Kalagaan.BlendShapesPresetTool;
    4.  
    5. public class BSPTLerp : MonoBehaviour {
    6.  
    7.     public BlendShapesPresetController _BSPT;
    8.     public bool m_smile = true;
    9.     public float m_animationSpeed = 1f;
    10.     float m_weight = 0f;
    11.    
    12.     void Update ()
    13.     {
    14.         if (_BSPT != null)
    15.         {
    16.             m_weight = Mathf.Lerp(m_weight, m_smile ? 1f : 0f, Time.deltaTime * m_animationSpeed);
    17.             _BSPT.SetWeight("Smile", m_weight);
    18.         }
    19.     }
    20. }
     
    vibedev and HamFar like this.
  45. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    Excellent! Thank you so much for your help. :)
     
    kalagaan likes this.
  46. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    Is there a similarly-simple way (i.e. commands) to transition from one preset to another? I am looking at the Demo.cs and HeadController.cs scripts, and I can only understand that an Animation Controller is used to transition between different animations. Is this the case or am I missing something? Thanks
     
  47. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    Here a sample with a list of preset :

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using Kalagaan.BlendShapesPresetTool;
    5.  
    6. public class BSPTPresetSwitch : MonoBehaviour
    7. {
    8.      
    9.     public BlendShapesPresetController _BSPT;
    10.     public float m_animationSpeed = 1f;
    11.  
    12.     public List<string> m_PresetNameLst = new List<string>();
    13.     public List<bool> m_activationLst = new List<bool>();
    14.     List<float> m_weightLst = new List<float>();
    15.  
    16.     private void Start()
    17.     {
    18.         m_activationLst.Clear();
    19.         m_weightLst.Clear();
    20.         for ( int i=0; i< m_PresetNameLst.Count; ++i )
    21.         {
    22.             m_activationLst.Add(false);
    23.             m_weightLst.Add(0);
    24.         }
    25.     }
    26.  
    27.  
    28.     void Update()
    29.     {
    30.         if (_BSPT != null)
    31.         {
    32.             for (int i = 0; i < m_PresetNameLst.Count; ++i)
    33.             {
    34.                 m_weightLst[i] = Mathf.Lerp(m_weightLst[i], m_activationLst[i] ? 1f : 0f, Time.deltaTime * m_animationSpeed);
    35.                 _BSPT.SetWeight(m_PresetNameLst[i], m_weightLst[i]);
    36.             }
    37.         }
    38.     }
    39. }
    you have to enter the list of preset name in the inspector, then you'll have to enable/disable the m_activationLst values to switch between presets ;)
     
    Last edited: Dec 17, 2018
    HamFar and vibedev like this.
  48. HamFar

    HamFar

    Joined:
    Nov 16, 2014
    Posts:
    89
    As seen in the attached image, when I go through blend-shapes activating them one after another, the previous ones that have been disabled still keep changing values, which is understandable when it keeps going down to zero but again they jump back up and continue. What am I doing wrong in the code that they never stop fluctuating?
    Code (CSharp):
    1. public class BlendShapesAPI : MonoBehaviour
    2. {
    3.     private float _weight = 0f;
    4.     public bool _TransitionAnimation = true;
    5.     public float _TransitionAnimationSpeed = 2f;
    6.     public BlendShapesPresetController _BSPC;
    7.     private List<float> _weightsList = new List<float>();
    8.     public List<bool> _ActivationsList = new List<bool>();
    9.     public List<string> _PresetsNamesList = new List<string>();
    10.  
    11.     private void Awake()
    12.     {
    13.         _weightsList.Clear();
    14.         _ActivationsList.Clear();
    15.  
    16.         for (int i = 0; i < _PresetsNamesList.Count; ++i)
    17.         {
    18.             _ActivationsList.Add(false);
    19.             _weightsList.Add(0);
    20.         }
    21.     }
    22.  
    23.     private void Start()
    24.     {
    25.         if (_BSPC != null)
    26.         {
    27.             StartCoroutine( AutoExecuteBlendShapes() );
    28.         }
    29.         else
    30.         {
    31.             throw new ArgumentNullException("BlendShapesPresetController");
    32.         }
    33.     }
    34.  
    35.     private IEnumerator AutoExecuteBlendShapes()
    36.     {  
    37.         yield return new WaitForSeconds(2f);
    38.  
    39.         for (int i = 0; i < _ActivationsList.Count; ++i)
    40.         {
    41.             _ActivationsList[i] = true;
    42.             yield return new WaitForSeconds(2f);
    43.             _ActivationsList[i] = false;
    44.             yield return new WaitForSeconds(2f);
    45.         }
    46.  
    47.         yield return null;
    48.     }
    49.  
    50.     private void Update()
    51.     {
    52.         if (_BSPC != null)
    53.         {
    54.             for (int i = 0; i < _PresetsNamesList.Count; ++i)
    55.             {
    56.                 _weightsList[i] = Mathf.Lerp(_weightsList[i], _ActivationsList[i] ? 1f : 0f, Time.deltaTime * _TransitionAnimationSpeed);
    57.                 _BSPC.SetWeight(_PresetsNamesList[i], _weightsList[i]);
    58.             }
    59.         }
    60.         else
    61.         {
    62.             return;
    63.         }
    64.     }
    65. }
    non_zeros.jpg
     
  49. kalagaan

    kalagaan

    Joined:
    May 27, 2012
    Posts:
    1,498
    The Lerp function reduce the value near 0 (2.8e-43 is really small), you should add a threshold when the value is too small.

    Code (CSharp):
    1.  
    2. if(_weightsList[i]<.01)
    3.   _weightsList[i] = 0f;
    4.  
     
    vibedev and HamFar like this.
  50. vibedev

    vibedev

    Joined:
    Nov 1, 2018
    Posts:
    13
    Hello kalagaan,

    I have an AutoDesk character with 66 facial blendshapes that works well with your amazing tool. However, the character does not blink when I integrate Salsa LipSync and Random Eyes Movement; another amazing tool that I use.

    I found out that it is because I have a BlendSahpesPresetController on the H_DDS_HighRes body of my character that prevents the tool to modify the eyelid blendshape values, but I am confused because I only manipulate the blenshape values of each preset when the user ticks a checkbox to activate a particular preset, so it is normally not in force, but when I disable the BlendSahpesPresetController script, I do observe that the character starts blinking.

    Do you know why this interference occurs even though my pre-configured presets are not active all the time?

    Thanks in advance
     
    HamFar likes this.