hai-vr / av3-animator-as-code

Generate animator layers and animations from a fluent builder syntax. Initially designed for use in VRChat, this is now a generic package that does not require it.
https://docs.hai-vr.dev/docs/products/animator-as-code
MIT License
190 stars 14 forks source link

AvatarMaskBodyPart support for ResolveAvatarMask #8

Open galister opened 2 years ago

galister commented 2 years ago

ResolveAvatarMask is really powerful, but the fact that it does not allow combining AvatarMaskBodyParts with transforms makes it a lot less useful.

My use case being the gesture layer. Say you have left hand, right hand, left ear and right ear layers.

The hand layers can be simply done via VrcAssets() and the ear layers can also be simply done with ResolveAvatarMask.

However, as we know, the first layer of the gesture controller needs to union the masks of all sub-layers, so now we need a mask, which contains the ear transforms, as well as the fingers as AvatarMaskBodyPart.

This PR aims to add a way to easily achieve this without forcing the user to manually create the AvatarMask, while maintaining functionality on existing overloads.

var bodyParts = new[] { AvatarMaskBodyPart.LeftFingers, AvatarMaskBodyPart.RightFingers };
var earTransforms = new[] { leftEar, rightEar };

var firstLayer = aac.CreateMainGestureLayer();
firstLayer.ResolveAvatarMask(earTransforms, bodyParts);
hai-vr commented 2 years ago

This will likely be replaced with layer.WithAvatarMask(...) and aac.CopyAsset(...), where the avatar mask asset must be created by the user (might or might not through another fluent interface).

hai-vr commented 2 years ago

On second thought I think it's small enough to include it.