Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WeightedMaskMixer feature. #154

Closed
tatoforever opened this issue Sep 10, 2021 · 8 comments
Closed

WeightedMaskMixer feature. #154

tatoforever opened this issue Sep 10, 2021 · 8 comments
Labels
Enhancement New feature or change request Solved A solution is available here (but may not yet be included in the latest release)

Comments

@tatoforever
Copy link

tatoforever commented Sep 10, 2021

Use Case

Hi, I need a way to properly set Humanoid Avatar masks. Instead of the whole trunk (or the whole head) I need to be able to selectivelly check what humanoid bones can affect the mask. We have a set of custom animations for our characters. Such as In-place reloading/shoting. We do have running, walk, strafing, crouching animations that are mixed with shoting/meleeing and reloading animations. The problem is that those animations are meant to be mixed not from the pelvis (otherwise the characters start shottings while swinging their bodies all over the place very weird), but instead from spine2 bone (the equivalent of the upper chest in Humanoid rig). But the mask doesn't allow us to chose individual bones inside the mask, is either the whole trunk or nothing.
As you suggested in this thread, there's a solution to control individual bones mask and weight.

Solution

Implement WeightedMaskMixer in Animancer

Alternatives

There's currently no other known alternative other than create an explosive combination of animations which forces us to be stuck with clunky unwanted mix of masked animations without fine grain control.

@tatoforever tatoforever added the Enhancement New feature or change request label Sep 10, 2021
@KybernetikGames
Copy link
Owner

KybernetikGames commented Sep 11, 2021

I don't have much time to develop new features at the moment, but here's a quick implementation of the weighted mixer sample.

Before you can use it you'll need to make the following changes:

// AnimancerPlayable.cs

// Allow the Layers to be set.
// public LayerList Layers { get; private set; }
public LayerList Layers { get; set; }

// AnimancerPlayable.LayerList.cs

// Remove the sealed keyword.
// public sealed class LayerList : ...
public class LayerList : ...

// Add a new constructor:
            /// <summary>Creates a new <see cref="LayerList"/>.</summary>
            protected LayerList(AnimancerPlayable root)
            {
                Root = root;
                _Layers = new AnimancerLayer[DefaultCapacity];
            }

// Add a safety check in IsAdditive so the Inspector doesn't cause exceptions:
            public bool IsAdditive(int index)
            {
#if UNITY_EDITOR
                if (!LayerMixer.IsValid())
                    return false;
#endif
                return LayerMixer.IsLayerAdditive((uint)index);
            }

Then you can import Animancer Weighted Mask Mixer v1.zip (latest version is further down). The actual implementation is in Assets/Plugins/Animancer/Internal/Mixer States/WeightedMaskLayerList.cs and an example of how to use it is in Assets/Experimental.

It only supports 2 layers and has a few other things that might be inconvenient to use, so please do let me know if you make any changes to it.

@tatoforever
Copy link
Author

Thanks for the heads up. I will integrate it later tonight and will let you know how it goes.

@KybernetikGames
Copy link
Owner

KybernetikGames commented Oct 17, 2021

Animancer v7.2 is now available with the necessary changes to simply add a weighted mask mixer. But I didn't actually add the mixer since it's not really suitable for general use with its current limitations.

If this gets more interest I'll look into it more.

@KybernetikGames KybernetikGames added the Solved A solution is available here (but may not yet be included in the latest release) label Oct 17, 2021
@baroquedub
Copy link

baroquedub commented Feb 24, 2022

For info, you mentioned that;

Animancer v7.2 is now available with the necessary changes to simply add a weighted mask mixer.

But I found this is still needed to be done:

// AnimancerPlayable.cs

// Allow the Layers to be set.
// public LayerList Layers { get; private set; }
public LayerList Layers { get; set; }

and;

#if UNITY_EDITOR
if (!LayerMixer.IsValid())
return false;
#endif
return LayerMixer.IsLayerAdditive((uint)index);

Although you do have the IsAdditive method. Without the #if UNITY_EDITOR directive I was getting spammed with errors in Editor play mode

@KybernetikGames
Copy link
Owner

KybernetikGames commented Feb 24, 2022

Looks like I have actually made some changes to the Weighted Mask Mixer since I first posted it so here's the new version compatible with Animancer v7.2: Animancer Weighted Mask Mixer v2.zip (latest version is further down)

Exposing the Layers setter publicly was a bad idea because there are several other things that also need to be set for it to work, so instead the base LayerList class has an Activate method for inheriting classes to use.

@baroquedub
Copy link

baroquedub commented Feb 24, 2022

Thanks :) I can confirm that the new import now works out of the box. The WeightedMaskMixerExample script has lost
_Layers.Layer1Weight = _Weight;
(at the end of the script) which I think is useful.

I've added it back in using
_Animancer.Layers[1].Weight = _Weight;

Also the new example scene has a gameObject named 'DefaultHumanoid Regular Layers' which has a missing script on it. Not sure if it was intended as another example?

@KybernetikGames
Copy link
Owner

Here's a re-upload with the weight field back in and removed that extra character. Not sure how it go in there, it was something completely unrelated. Animancer Weighted Mask Mixer v2.1.zip

@KybernetikGames
Copy link
Owner

Animancer v7.3 is now available and has those changes in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or change request Solved A solution is available here (but may not yet be included in the latest release)
Projects
None yet
Development

No branches or pull requests

3 participants